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

Invalid Latex output for double subscript #313

Open
karlwessel opened this issue Oct 7, 2024 · 6 comments
Open

Invalid Latex output for double subscript #313

karlwessel opened this issue Oct 7, 2024 · 6 comments

Comments

@karlwessel
Copy link

The LaTeX-output of latexify for something with double subscripts does not compile. For example:

julia> using Latexify

julia> latexify(:(x[1:2][1]); index = :subscript)
L"$x_{:\left( 1, 2 \right)}_{1}$"

The returned Latex does not compile correctly: see http://www.texrendr.com/?eqn=x_%7B%3A%5Cleft(%201%2C%202%20%5Cright)%7D_%7B1%7D.

This issue comes up in ModelingToolkit when indexing sub-arrays (see JuliaSymbolics/Symbolics.jl#1288).

@gustaphe
Copy link
Collaborator

gustaphe commented Oct 8, 2024

Ooh. Tricky one. We could fix it so this outputs the same as @latexify x[1:2, 1], but would that be correct?
Note that after this is sorted, you will run into #315 .

@karlwessel
Copy link
Author

I would just add parenthesis around the output for the inner expression, so that Latex knows to what the indices refer:

${x_{:\left( 1, 2 \right)}}_{1}$

@gustaphe
Copy link
Collaborator

I misread your comment, but I agreed with the version I read so, my suggestion is

$$\left( x_{1} \right)_{1}$$

See PR #316.

@karlwessel
Copy link
Author

Yes, the new output with PR #316 looks good:

julia> latexify(:(x[1:2][1]); index = :subscript)

L"$\left( x_{:\left( 1, 2 \right)} \right)_{1}$"

Renders as $\left( x_{:\left( 1, 2 \right)} \right)_{1}$.

Thank you!

@karlwessel
Copy link
Author

Btw: a similar problem exist when using a variable name that already contains a subscript:

latexify(:(x₁[2]); index = :subscript)
L"$x_1_{2}$"

And similar with superscripts:

latexify(:(x²^2))
L"$x^2^{2}$"

I didn't check if PR #316 also fixes those.

@gustaphe
Copy link
Collaborator

That's a separate issue. Not sure I think they are worth the effort, but if you open an issue for it, some kind soul might turn up with a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants