Fix line breaks appearing after inline images in compiled PDF#49
Open
cycomachead wants to merge 1 commit into
Open
Fix line breaks appearing after inline images in compiled PDF#49cycomachead wants to merge 1 commit into
cycomachead wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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\snapinlineparhookmacro 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\snapinlineparhookbefore 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 awalkWithParenthelper to safely traverse and mutate the AST.Root Cause
myst-to-tex's image handler unconditionally emits\n\nafter 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