Skip to content

Fix line breaks appearing after inline images in compiled PDF - #52

Merged
cycomachead merged 2 commits into
mainfrom
cycomachead/14-fix-pdf-line-breaks-after-images/2
Aug 7, 2026
Merged

Fix line breaks appearing after inline images in compiled PDF#52
cycomachead merged 2 commits into
mainfrom
cycomachead/14-fix-pdf-line-breaks-after-images/2

Conversation

@cycomachead

Copy link
Copy Markdown
Member

Fix line breaks appearing after inline images in compiled PDF

Inline images in the compiled PDF were forcing paragraph breaks mid-sentence due to myst-to-tex unconditionally appending a blank line after every image node (which LaTeX interprets as \par). This fix defuses that forced paragraph break for inline images without forking the upstream serializer.

Changes

  • _latex-template/template.tex: Defines two new TeX commands, \snapinlineopen and \snapinlineclose, which bracket inline images in a group where \par is redefined as a no-op. \unskip in the closing command removes stray inter-word glue from the serializer's trailing newline. Real paragraph breaks (serialized after the closing marker) continue to work normally.
  • _support/plugins/latex-shims.mjs: Adds a new transform step that walks the AST and wraps inline image nodes with raw TeX siblings (\snapinlineopen{}/\snapinlineclose{}). Nodes are tagged to prevent double-wrapping across multiple PDF export pipelines. HTML builds and image caching are unaffected.

Visual Changes

Before this fix, inline color-swatch images would break their surrounding sentence onto a new line. After the fix, they flow inline with the text:


Superconductor Ticket Implementation | Guided Review

cycomachead and others added 2 commits August 7, 2026 09:18
The myst-to-tex serializer unconditionally appends a blank line after
image nodes, which LaTeX interprets as a paragraph break (\par). This
caused inline images to force a new line in the compiled PDF.

This change introduces a LaTeX shim that brackets inline images with
custom TeX commands (\snapinlineopen and \snapinlineclose). These
commands locally redefine \par to be inert, ensuring that the
serializer's trailing blank line does not break the flow of text.

- Added \snapinlineopen and \snapinlineclose to the LaTeX template
- Updated latex-shims plugin to wrap inline image nodes with raw TeX markers
- Ensured HTML builds and image caching remain unaffected

Co-authored-by: Claude Code <noreply@anthropic.com>
Updated the CI workflow to TeX Live 2026 to match the current CTAN
repository. This fixes a build failure caused by the 2025 rollover,
specifically renaming `pdfmanagement-testphase` to `pdfmanagement`
and `sourceserifpro` to `sourceserif`.

Co-authored-by: Claude Code <noreply@anthropic.com>
@cycomachead
cycomachead merged commit eecf1d9 into main Aug 7, 2026
2 checks passed
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