This auto-generated latex from sagemath software generates error Double subscript
I wanted to report this to sagemath, but wanted to check first why this is showing up
Inside sagemath on Linux, I type
sage: var('_C0 _C1 _C2 _C3 _C4 _C5 _C6 _C7 _C8 _C9 a b c d e f g h k p q x y ');
sage: integrand=(_C3*x^2-_C4)*(3*_C3*x^2+3*_C4+x)/x/((_C3*x^2+_C0*x+_C4)/(_C3*x^2+_C1*x+_C4))^(1/2)/(_C3^2*x^4+2*_C3*_C4*x^2+_C4^2-x^2);
sage: latex(integrand)
\frac{{\left(3 \, _{C_{3}} x^{2} + 3 \, _{C_{4}} + x\right)} {\left(_{C_{3}} x^{2} - _{C_{4}}\right)}}{{\left(_{C_{3}}^{2} x^{4} + 2 \, _{C_{3}} _{C_{4}} x^{2} + _{C_{4}}^{2} - x^{2}\right)} x \sqrt{\frac{_{C_{3}} x^{2} + _{C_{0}} x + _{C_{4}}}{_{C_{3}} x^{2} + _{C_{1}} x + _{C_{4}}}}}
Then I copy the above latex and compile it
\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\[
\frac{{\left(3 \, _{C_{3}} x^{2} + 3 \, _{C_{4}} + x\right)} {\left(_{C_{3}} x^{2} - _{C_{4}}\right)}}{{\left(_{C_{3}}^{2} x^{4} + 2 \, _{C_{3}} _{C_{4}} x^{2} + _{C_{4}}^{2} - x^{2}\right)} x \sqrt{\frac{_{C_{3}} x^{2} + _{C_{0}} x + _{C_{4}}}{_{C_{3}} x^{2} + _{C_{1}} x + _{C_{4}}}}}
\]
\end{document}
Using lualatex foo2.tex
gives
(./foo2.aux) (/usr/local/texlive/2021/texmf-dist/tex/latex/base/ts1cmr.fd)
! Double subscript.
<argument> {\left (_{C_{3}}^{2} x^{4} + 2 \, _{C_{3}} _
{C_{4}} x^{2} + _{C_{4}}^{2} - x^{2
l.10 ...}}{_{C_{3}} x^{2} + _{C_{1}} x + _{C_{4}}}}}
?
My question is: Do you think this is an error in sagemath latex generation, where it should have been more smart in handling the input? Since the input is valid code inside sagemath itself, and can be processed. It is only when generating the Latex representation I get this error.
How should the latex generated be to avoid this error?
reference
why-am-i-getting-a-double-subscript-error
Using This is LuaHBTeX, Version 1.13.2 (TeX Live 2021)
Update
As recommend by answer below, a feature ticket was added to sagemath to improve the latex it generated
...+ 2 \, _{C_{3}} _{C_{4}}
which seems to originate from this section of your input:+2*_C3*_C4
. But I don't know sagemath. Does the underscore signify something special in the sagemath input? If that is your choice in variable naming, you have chosen poorly, given the special meaning of_
in TeX_C
works OK as symbol inside sagemath and can be used as any other variable. The problem comes when generating Latex. I agree that underscore in start of variable name is not recommended. But this is how the input is at this time. My question is really, if the Latex generated is faulty itself and if I should report this as sagemath error or if there is something else going on._{C_{4}
to{_{C_{4}}
(adding extra braces), it compiles but does not produce a reasonable looking output. All C variables are presented in subscript form, so that, at the beginning of the denominator, the_{C_{3}}^{2}
typesets with the2
above theC_{3}
(properly set in LaTeX, but meaningless as math). The real issue here is not sagetex, unless they FORCE you to use the underscore in variable names. You say it is autogenerated, but someone, somewhere, chose to use underscores as part of variable names. Big mistake._
in start of their variable names to avoid any such issue in first place and will not then report this to sagemath as bad Latex.\_
when converting it to LaTeX. That way it would not present as a subscript, but as a leading underscore. Not a bug report, per se, but more of a feature request.