Skip to content

Fix line breaks appearing after inline images in compiled PDF#49

Open
cycomachead wants to merge 1 commit into
mainfrom
cycomachead/ai/14/1
Open

Fix line breaks appearing after inline images in compiled PDF#49
cycomachead wants to merge 1 commit into
mainfrom
cycomachead/ai/14/1

Conversation

@cycomachead
Copy link
Copy Markdown
Member

Fix unwanted line breaks after inline images in compiled PDF

Inline images in the compiled PDF were causing paragraph breaks, resulting in unwanted line breaks mid-sentence. This fix suppresses those breaks for inline images that have following content in the same paragraph.

Changes

  • _latex-template/template.tex: Added a \snapinlineparhook macro that installs a one-shot redefinition of \par, swallowing the next paragraph break (and trailing space) so the surrounding paragraph continues uninterrupted.
  • _support/plugins/latex-shims.mjs: Added a new AST transform step that inserts \snapinlineparhook before each inline image that has content following it in the same parent. Inline images at the end of their parent are left untouched so legitimate paragraph breaks are preserved. Also added a walkWithParent helper to safely traverse and mutate the AST.

Root Cause

myst-to-tex's image handler unconditionally emits \n\n after every \includegraphics, which LaTeX interprets as \par, breaking the paragraph after every inline image. Since the handler can't be overridden from a plugin, the fix intercepts at the AST level before rendering.

Visual Changes

Page 63 — inline image now flows correctly within the paragraph


Superconductor Ticket Implementation | Guided Review

Modified the LaTeX template and shim plugin to suppress paragraph breaks
caused by myst-to-tex's image handler. A new TeX macro swallows the
trailing \par for inline images that are followed by other content,
ensuring text flows correctly around icons and small images.

Co-authored-by: Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant