diff --git a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx index 15b1e2d3a5..fc5543c089 100644 --- a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx +++ b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-context.tsx @@ -16,7 +16,7 @@ type FigureModalState = { helpShown: boolean sourcePickerShown: boolean getPath?: () => Promise - width: number + width: number | undefined includeCaption: boolean includeLabel: boolean error?: string diff --git a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-options.tsx b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-options.tsx index 342c93ebd6..2422559bff 100644 --- a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-options.tsx +++ b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal-options.tsx @@ -71,7 +71,7 @@ export const FigureModalFigureOptions: FC = () => { dispatch({ width: parseFloat(value) })} - defaultValue={width === 1 ? '1.0' : width.toString()} + defaultValue={width === 1 ? '1.0' : width?.toString()} disabled={hasComplexGraphicsArgument} > diff --git a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx index d9f9dd5071..9c0f387a27 100644 --- a/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx +++ b/services/web/frontend/js/features/source-editor/components/figure-modal/figure-modal.tsx @@ -97,12 +97,12 @@ const FigureModalContent = () => { } updateExistingFigure({ name: figure.file.path, - hasComplexGraphicsArgument: - figure.unknownGraphicsArguments !== undefined, + // The empty string should *not* be a complex argument + hasComplexGraphicsArgument: Boolean(figure.unknownGraphicsArguments), }) dispatch({ source: FigureModalSource.EDIT_FIGURE, - width: figure.width ?? 0.5, + width: figure.width, includeCaption: figure.caption !== null, includeLabel: figure.label !== null, }) @@ -166,9 +166,9 @@ const FigureModalContent = () => { insert: '', }) } - if (!figure.unknownGraphicsArguments) { + if (!figure.unknownGraphicsArguments && width) { // We understood the arguments, and should update the width - if (figure.graphicsCommandArguments) { + if (figure.graphicsCommandArguments !== null) { changes.push({ from: figure.graphicsCommandArguments.from, to: figure.graphicsCommandArguments.to, @@ -191,7 +191,9 @@ const FigureModalContent = () => { view.dispatch( view.state.changeByRange(range => { const { pos, suffix } = ensureEmptyLine(view.state, range) - const graphicxCommand = `\\includegraphics[width=${width}\\linewidth]{${path}}` + const widthArgument = + width !== undefined ? `[width=${width}\\linewidth]` : '' + const graphicxCommand = `\\includegraphics${widthArgument}{${path}}` const changes: ChangeSpec = view.state.changes({ insert: `\\begin{figure}\n\\centering\n${graphicxCommand}${captionCommand}${labelCommand}${ labelCommand || captionCommand ? '\n' : '' // Add an extra newline if we've added a caption or label diff --git a/services/web/frontend/js/features/source-editor/utils/tree-operations/environments.ts b/services/web/frontend/js/features/source-editor/utils/tree-operations/environments.ts index 2a95b6f13a..7087486fd5 100644 --- a/services/web/frontend/js/features/source-editor/utils/tree-operations/environments.ts +++ b/services/web/frontend/js/features/source-editor/utils/tree-operations/environments.ts @@ -337,11 +337,7 @@ export function parseFigureData( if (error) { return null } - if ( - graphicsCommand === undefined || - file === undefined || - (width === undefined && unknownGraphicsArguments === undefined) - ) { + if (graphicsCommand === undefined || file === undefined) { return null } return new FigureData({