Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

[TeX] Escape `$` in equation

Open inkydragon opened this issue 2 years ago • 7 comments

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

inkydragon avatar Apr 24 '22 15:04 inkydragon

Can you clarify what your input was? For me the latex output of

echo `$(nothing)`

is

echo \texttt{\$(nothing)}

which looks correct?

fredrikekre avatar Apr 24 '22 16:04 fredrikekre

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

ViralBShah avatar Apr 24 '22 22:04 ViralBShah

Duplicate of #1020?

mortenpi avatar Apr 25 '22 01:04 mortenpi

md input:

image

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

inkydragon avatar Apr 25 '22 01:04 inkydragon

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.

mortenpi avatar Apr 25 '22 02:04 mortenpi

By the way, I noticed that the last CI for the nightly PDF crashed. It's probably due to this escaping issue?

mortenpi avatar Apr 25 '22 02:04 mortenpi

I thought we are not yet including HISTORY.md in the pdf.

ViralBShah avatar Apr 25 '22 10:04 ViralBShah

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?

odow avatar Sep 30 '22 03:09 odow