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

[TeX] Escape $ in equation #1804

Closed
1 task
inkydragon opened this issue Apr 24, 2022 · 8 comments
Closed
1 task

[TeX] Escape $ in equation #1804

inkydragon opened this issue Apr 24, 2022 · 8 comments
Labels
Format: LaTeX Related to the LaTeX / PDF output

Comments

@inkydragon
Copy link
Contributor

inkydragon commented Apr 24, 2022

md: "echo `$(nothing)` "

```echo `$(nothing)` ```

tex:

  • \(echo `$(nothing)`\)

should be:

  • \(echo `\$(nothing)`\)

Related code:

function latexinline(io, math::Markdown.LaTeX)
# Handle MathJax and TeX inconsistency since the first wants `\LaTeX` wrapped
# in math delims, whereas actual TeX fails when that is done.
math.formula == "\\LaTeX" ? _print(io, math.formula) : _print(io, "\\(", math.formula, "\\)")
end

TODO:

  • Add a test case

Background: JuliaLang/julia#45034 (comment)

@fredrikekre
Copy link
Member

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

echo `$(nothing)`

is

echo \texttt{\$(nothing)}

which looks correct?

@ViralBShah
Copy link
Contributor

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

@mortenpi
Copy link
Member

Duplicate of #1020?

@inkydragon
Copy link
Contributor Author

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

@mortenpi
Copy link
Member

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
Copy link
Member

mortenpi commented Apr 25, 2022

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

@ViralBShah
Copy link
Contributor

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

@odow odow added the Format: LaTeX Related to the LaTeX / PDF output label Sep 16, 2022
@odow
Copy link
Collaborator

odow commented Sep 30, 2022

I am not sure if we should actually do anything here.

I agree. Close in favor of #1697?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Format: LaTeX Related to the LaTeX / PDF output
Projects
None yet
Development

No branches or pull requests

5 participants