Skip to content
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

Closed
joel-coffman opened this issue Jul 4, 2022 · 2 comments · Fixed by #150
Closed

LaTeX renderer does not handle inline code with vertical bars correctly #149

joel-coffman opened this issue Jul 4, 2022 · 2 comments · Fixed by #150
Labels

Comments

@joel-coffman
Copy link
Contributor

joel-coffman commented Jul 4, 2022

Inline code that contains a vertical bar is not handled correctly by the LaTeX renderer. For example,

$ mistletoe --renderer mistletoe.latex_renderer.LaTeXRenderer
mistletoe [version 0.8.2] (interactive)
Type Ctrl-D to complete input, or Ctrl-C to exit.
Using renderer: LaTeXRenderer
>>> `example | pipe`
... ^D
\documentclass{article}
\begin{document}

\verb|example | pipe|
\end{document}

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.

@joel-coffman
Copy link
Contributor Author

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).

@pbodnar pbodnar added the bug label Jul 5, 2022
@pbodnar
Copy link
Collaborator

pbodnar commented Jul 5, 2022

@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.

pbodnar pushed a commit that referenced this issue Jul 26, 2022
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
pbodnar pushed a commit that referenced this issue Jul 26, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants