Repository navigation
Fix as_latex_escaped: correct RGB channel order and backslash escaping - #702
Merged
Merged
Conversation
keith-hall
reviewed
Jul 12, 2026
Move the escaping into a `write_latex_escaped` helper that searches for
the next `\`, `{` or `}` and copies the text between matches in one go,
rather than pushing every char individually. Text containing none of
those characters is now appended with a single copy.
Also assert the exact output in the test, and cover text with no special
characters, multi-byte characters and a style change.
Author
|
Good idea. It now searches for the next |
keith-hall
approved these changes
Aug 11, 2026
keith-hall
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, looks good. I'm a little unsure of when best to merge it, please bear with me. We are in the middle of supporting newer sublime-syntax features etc and I wonder about conflicts with #627 also
Author
|
627 already has the RGB channel order, but it still maps |
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.
Fixes two bugs in
as_latex_escaped(src/util.rs):Swapped color channels. The
\textcolor[RGB]{...}directive was emitted with the green and blue components transposed (style.foreground.r, style.foreground.b, style.foreground.g), so colors came out wrong.Broken backslash escaping. A literal backslash in the text was escaped to
\\, which is a line break inside thecommandchars=\\\{\}Verbatim environment rather than a literal backslash, and the sequential.replace()loop could re-process characters it had just introduced. Escaping is now done in a single pass over the input, mapping\→\textbackslash{},{→\{,}→\}, which produces LaTeX that compiles.For input
a\b{c}with foregroundRGB(10,20,30)the output is now\textcolor[RGB]{10,20,30}{a\textbackslash{}b\{c\}}.Test
Added
test_as_latex_escaped, which builds aStylewith a known foreground color and text containing a backslash and braces, and asserts the channel order,\textbackslash{}, escaped braces, and the absence of a bare\\.Closes #472.