feat(parser): Recognize commands nested in \text{...} - #64
Open
gjtorikian wants to merge 4 commits into
Open
Conversation
Previously `\text{...}` took its argument as a single opaque
string, so `\text{Hello \LaTeX}` rendered the control sequence
as literal source rather than typesetting it, and `\textbf`,
`\emph`, `$...$`, and the escaped specials inside text were
all silently dropped or mangled.
This implements the design accepted on issue carloskiki#29: \text bodies
re-enter the parser through a text-mode path (driven by a new
`text_mode` flag on ParserState and Instruction::SubGroup) and
emit a Grouping::Text wrapper; embedded `$...$` switches back
via Grouping::InlineMath. Font commands route through the
existing StateChange::Font machinery so the renderer can pick
up mathvariant on <mtext>.
Closes carloskiki#29
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
The text-mode test helper allocated a Storage with Box::leak so the parser's borrowed events could outlive the helper. That made LeakSanitizer and Miri reject every test in this file. Switch to a caller-owned Storage and add cases for the spacing commands, symbol commands, comment handling, single-token arguments, and the inline-math lexer's escape paths so codecov patch coverage clears the project threshold.
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.
\text{...}now re-parses its body in a dedicated text-mode path instead of treating it as a single opaque string, so nested control sequences (\LaTeX,\textbf,\emph, escaped specials, accents, etc.) typeset correctly and$...$switches back into math via the newGrouping::InlineMath.This PR also introduces
Grouping::Text/Grouping::InlineMathand atext_modeflag onParserStateandInstruction::SubGroupso the existing iterator loop can drive both modes from the same stack without duplicating script-handling logic.Text-mode font commands are routed through the existing
StateChange::Font(...)machinery; the MathML renderer now emitsmathvariant="..."on<mtext>so\textbf/\textit/\emphare visibly distinct.until_unescaped_dollaris a lexer helper that respects brace nesting and%comments, so$...$inside\textis scanned safely and reports a parser error on a missing closing$.Closes #29