-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeX renderer does not handle inline code with vertical bars correctly #149
Comments
I'm happy to create a pull request to fix this issue once it's confirmed to be a bug (and if my suggestion of choosing the delimiter dynamically is acceptable). |
@joel-coffman, thanks for your report and suggestion. I can confirm both, so I will be happy if you create a PR for this. In fact, I've stumbled upon this nearly 1 year ago while doing a code review here, but apparently, the fix hasn't been realized so far. |
The LaTeX renderer uses `\verb` for inline code, but the delimiter is always a vertical bar, which produces incorrect output when the inline code also contains a vertical bar (e.g., `example | pipe`). Rather than using a single static character (i.e., a vertical bar), this change modifies render_inline_code to search for a non-letter delimiter that does not appear in the inline code. If no such delimiter can be found, a RuntimeError is raised to avoid incorrect output. Note that the list of possible delimiters is not exhaustive. For example, numbers (0, 1, 2, etc.) are all valid delimiters for \verb but are omitted from the search. Fixes #149
This change uses string.punctuation and string.digits to exhaustively search for delimiters suitable for inline code -- i.e., a delimiter that does not appear in the inline code. To preserve existing behavior, the vertical bar (`|`) is always used first followed by other delimiters that are commonly used (`!`, `"`, `'`, and `=`) [1]. Some delimiters may look weird (e.g., a brace as in `\verb{a|b{`, which is technically valid) [2], but using these delimiters is preferable to raising an error when no valid delimiter is found (even though one might exist). Users may override the default set of delimiters by specifying the renderer's `verb_delimiters` manually, which allows braces, brackets, etc. to be omitted. References #149 [1] https://tex.stackexchange.com/q/203585 [2] https://tex.stackexchange.com/a/387691
Inline code that contains a vertical bar is not handled correctly by the LaTeX renderer. For example,
where the verbatim content ends at the first vertical bar, which omits " pipe|" from the inline code.
Because
\verb
delimits its argument using any non-letter symbol (I think that statement is correct), a different delimiter should be chosen that does not appear in the inline code. For example,!
could be used in this example so the output would be\verb!example | pipe!
. Obviously, this change would require searching the token to find a safe delimiter, as no delimiter can be chosen in advance that is guaranteed to work in all cases.The text was updated successfully, but these errors were encountered: