Skip to content

eqn writer: escape " and \ in quoted text - #298

Merged
jgm merged 1 commit into
jgm:masterfrom
dylanpulver:eqn-escape-quoted-text
Sep 4, 2026
Merged

jgm merged 1 commit into
jgm:masterfrom
dylanpulver:eqn-escape-quoted-text

Conversation

@dylanpulver

Copy link
Copy Markdown
Contributor

writeEqn wraps text in the double quotes eqn uses for literal text, but passed the content through unescaped: a " ends the string early, a \ starts a troff escape. pandoc 3.9.0.2 + groff 1.24.1:

$ echo 'Formula: $\text{say "hi"}$' | pandoc -t ms
Formula: @roman "say "hi""@   -> renders "Formula: say hi", quotes gone
$ echo 'Formula: $\text{a\textbackslash b}$' | pandoc -t ms
Formula: @roman "a\b"@        -> troff error, renders "a60"

Adds quoteText (" -> \", \ -> \[rs]) at the three sites that already emit quotes: EText, EMathOperator, and EDelimited's Left separators. Starmath and typst already guard here (escapeQuotes, needsEscape '"').

Eleven eqn goldens changed because they recorded the broken output: ms-16 had roman ""string"" = ..., and complex3 had a "\" delimiter that makes eqn abort with newline before end of quoted text. Every change is one of the two escapes, nothing else.

Scope limit: unquoted output (EIdentifier, ENumber, bare ESymbol) can still emit a raw ". Left alone, since quoting it would change how it is typeset.

Ran cabal v2-test: 3154/3154, no new warnings, on GHC 9.14.1 (outside your CI matrix). Against master's Eqn.hs the new 297.test plus 11 goldens fail; escaping only " still fails 10. Roundtrip suite is 943/1683 before and after.

AI-assisted, reviewed and verified by me; trailer form follows 05b23da.

The writer wraps text in the double quotes eqn uses for literal text but
emitted the content unescaped, so a `"` ended the string early and a `\`
began a troff escape sequence.

Closes jgm#297.

Co-Authored-By: Claude <noreply@anthropic.com>
@jgm

jgm commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Looks good, thank you.

@jgm
jgm merged commit a7451e2 into jgm:master Sep 4, 2026
5 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.

2 participants