Documenter.jl
Documenter.jl copied to clipboard
[TeX] Escape `$` in equation
md: "echo `$(nothing)`
"
```echo `$(nothing)` ```
tex:
-
\(echo `$(nothing)`\)
should be:
-
\(echo `\$(nothing)`\)
Related code: https://github.com/JuliaDocs/Documenter.jl/blob/cd57c41ab1ff8a8dacf5c21a7d8363b777a6ad9a/src/Writers/LaTeXWriter.jl#L683-L687
TODO:
- [ ] Add a test case
Background: https://github.com/JuliaLang/julia/issues/45034#issuecomment-1107826259
Can you clarify what your input was? For me the latex output of
echo `$(nothing)`
is
echo \texttt{\$(nothing)}
which looks correct?
I think it was trying to incorporate HISTORY.md into the manual, and it has some $
in there. I see @inkydragon mentioned this in the background above.
https://github.com/JuliaLang/julia/blob/master/HISTORY.md#standard-library-changes-5
Duplicate of #1020?
md input:
julia/HISTORY.md # Line1509 at master · JuliaLang/julia
``echo `$(nothing)` ``
Markdown.parse("`` `\$(nothing)` ``") |> s -> latex(stdout, s)
# $`$(nothing)`$
Maybe I've found a work around:
Markdown.parse("``` `\$(nothing)` ```") |> s -> latex(stdout, s)
# \texttt{`\$(nothing)`}
Duplicate of #1020?
It does seem to be an issue related to the $
symbol, but maybe a little different?
Markdown can parse the input normally. However, the $
in the formula needs to be further escaped.
Markdown.parse("`` `\$(nothing)` ``") |> typeof
# Markdown.MD
Ah, yes, I believe you're right that this is not a duplicate of that issue, but an escaping issue. That said the double-backtick version
``echo `$(nothing)` ``
is not actually intended, since that implies an equation. But echo `$(nothing)`
is clearly code, so should be triple-backticked, as you mentioned.
I am not sure if we should actually do anything here. The problem here is that the user has provided invalid LaTeX, and the correct solution is to fix the source (in this case, to use the correct backticks; but in a different case, if you actually want a dollar sign in your equation, you need to escape it accordingly).
Maybe in an ideal world we could somehow check each small LaTeX snippet, to make sure that it is valid, and then print a more helpful error to the user, but I don't have a good idea how to actually even do something like that.
By the way, I noticed that the last CI for the nightly PDF crashed. It's probably due to this escaping issue?
I thought we are not yet including HISTORY.md in the pdf.
I am not sure if we should actually do anything here.
I agree. Close in favor of https://github.com/JuliaDocs/Documenter.jl/issues/1697?