Print tokens literally with string

\string<token> was unsupported, so documenting a control sequence expanded it
instead of printing it. The expand loop now reads the following token and emits
its characters without expansion; backslash and braces are replaced by
private-use placeholders that the renderer maps back to the real characters, so
the printed text cannot be re-tokenised and expanded by a later pass.

A preview test defines \foo, prints \string\foo, \string{ and \string}, and
checks the literal "\foo and { and }." with no expansion of \foo and no
warnings.
This commit is contained in:
gloamxun committed 2026-10-27 01:16:30 +08:00
1 parent 57424015de
commit 47dcdfec47
4 files changed
+54 -3

No files matched your search

+3
View File
@@ -392,6 +392,9 @@ fn is_math_letter(character: char) -> bool {
fn character_text(character: char) -> String {
match character {
'\u{E023}' => "\\".to_owned(),
'\u{E024}' => "{".to_owned(),
'\u{E025}' => "}".to_owned(),
'\u{FB00}' => "ff".to_owned(),
'\u{FB01}' => "fi".to_owned(),
'\u{FB02}' => "fl".to_owned(),