korsbo / Latexify.jl

Convert julia objects to LaTeX equations, arrays or other environments.
MIT License
544 stars 55 forks source link

Double supperscript in latex expression #265

Closed pabloemontes closed 1 year ago

pabloemontes commented 1 year ago

I am trying to work with symbolic vectors and tensors using the Einstein notation. I want to have variables that have a superscript, for example v⁰, v¹, v², v³. My problem arises when manipulating expressions that involve powers of these variables. I would like to end up with a latex expression of the form ${v^a}^2$ or $(v^{a})^2$, with $a = 0, 1, 2, 3$.

However, the following doesn't work:

´´´ using Latexify ex = :(v⁰^2) latexify(ex) ´´´

since I get the error ParseError: KaTeX parse error: Double superscript at position 4: v^0^̲{2}. This is because the latex expression ends up being v^0^2, which has a double superscript, and gives a latex render error. Is there a way to force it to write (v^0)^2, or {v^0}^2?

gustaphe commented 1 year ago

This is really tricky to do right. But there is a keyword argument safescripts, so latexify(ex; safescripts=true) == L"$v{^0}^{2}$" might do what you want. Just as long as you don't expect the code to be semantically meaningful :)

pabloemontes commented 1 year ago

This is really tricky to do right. But there is a keyword argument safescripts, so latexify(ex; safescripts=true) == L"$v{^0}^{2}$" might do what you want. Just as long as you don't expect the code to be semantically meaningful :)

Thanks for the answer, this is what I was looking for.