Skip to content

Do not escape dollar signs delimiting inline math in LaTeX export - #808

Merged
jacebrowning merged 2 commits into
doorstop-dev:developfrom
Sanjays2402:fix/latex-inline-math-escaping
Jul 30, 2026
Merged

Do not escape dollar signs delimiting inline math in LaTeX export#808
jacebrowning merged 2 commits into
doorstop-dev:developfrom
Sanjays2402:fix/latex-inline-math-escaping

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #776

Inline math written as $e=mc^2$ is exported as \$e=mc^2\$, which breaks the LaTeX compile. _latex_convert() escapes every dollar sign, and the publisher only bypasses it for display math ($$...$$).

_latex_convert_with_inline_math() splits a line on unescaped dollar signs and converts only the non-math segments, so a complete inline math environment is left alone. Lines with an unpaired $, or an already-escaped \$, keep the previous escaping behaviour.

The added regression test in test_publisher_latex.py fails without the fix and passes with it; the rest of the publisher suite is unchanged.

Inline math written as $e=mc^2$ was published as \$e=mc^2\$, because
_latex_convert escapes every dollar sign and the publisher only bypassed
it for display math ($$...$$). The escaped delimiters break the LaTeX
compile.

Add _latex_convert_with_inline_math, which splits a line on unescaped
dollar signs and converts only the non-math segments, leaving a complete
inline math environment untouched. Lines with an unpaired dollar sign, or
with an already-escaped \$, keep the previous escaping behaviour.

Adds a regression test in test_publisher_latex.py covering both the
inline math and the unpaired dollar sign cases.
@jacebrowning

Copy link
Copy Markdown
Member

@Sanjays2402 thanks, we just need the code to be formatted.

@Sanjays2402

Copy link
Copy Markdown
Contributor Author

Formatted in b6cbfae - black wanted the generator expression in _latex_convert_with_inline_math on one line. isort and black are both clean now, and pytest doorstop/core/publishers/tests/test_publisher_latex.py is 21 passed.

@jacebrowning
jacebrowning merged commit 710f1ac into doorstop-dev:develop Jul 30, 2026
13 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.

LaTeX Export: Inline HTML not handled correctly as $ gets escaped

2 participants