# Double superscript. error from Maple latex code after updating

All my files no longer compile after running my program due to such errors now

  Double superscript. \left(-x^{2}+1\right) y^{\prime}^{2}


I have not updated TeXlive recently. Last time I updated it was about 5-7 weeks ago or so.

I did update Maple yesterday and then run my program which generates Latex by Maple.

Now when I try to compile the generated latex, I get the above errors. I am not sure what happened. I do know for sure if it is Maple's latex() which causes this or the update in TL I did which is the cause.

Here is a MWE

\documentclass[12pt]{book}
\usepackage{breqn}
\usepackage{amsmath}
\begin{document}

\begin{dmath*}
\left(-x^{2}+1\right) y^{\prime}^{2} = 1-y^{2}
\end{dmath*}

\end{document}


it seems lualatex complains about y^{\prime}^{2}

>lualatex foo.tex
This is LuaHBTeX, Version 1.15.1 (TeX Live 2023/dev)
restricted system commands enabled.
(./foo.tex
LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2022-12-17>
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/book.cls
Document Class: book 2022/07/02 v1.4n Standard LaTeX document class
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/bk12.clo))
(/usr/local/texlive/2022/texmf-dist/tex/latex/breqn/breqn.sty
(/usr/local/texlive/2022/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2022/texmf-dist/tex/latex/l3backend/l3backend-luatex.def))
(/usr/local/texlive/2022/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the ?' option.
(/usr/local/texlive/2022/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2022/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2022/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2022/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2022/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2022/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2022/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2022/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2022/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2022/texmf-dist/tex/latex/graphics-def/luatex.def)))
(/usr/local/texlive/2022/texmf-dist/tex/latex/breqn/flexisym.sty
(/usr/local/texlive/2022/texmf-dist/tex/latex/breqn/cmbase.sym)
(/usr/local/texlive/2022/texmf-dist/tex/latex/breqn/mathstyle.sty))
(/usr/local/texlive/2022/texmf-dist/tex/latex/tools/calc.sty)) (./foo.aux)
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd)
(/usr/local/texlive/2022/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
) (/usr/local/texlive/2022/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(/usr/local/texlive/2022/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
! Double superscript.

l.12 \left(-x^{2}+1\right) y^{\prime}^{2}
= 1-y^{2}
?


Here is the Maple code using its latex() command to generate the above

interface(version)
Standard Worksheet Interface, Maple 2022.2, Windows 10, October
latex:-Settings(useimaginaryunit=i,
usecolor = false,
powersoftrigonometricfunctions= mixed, ## computernotation,
leavespaceafterfunctionname = true,
cacheresults = false,
spaceaftersqrt = true,
linelength=10000
);
Typesetting:-Unsuppress('all'); #always do this.
Typesetting:-Settings(prime=x,'typesetprime'=true); #this says to use y'(x) instead of dy/dx
Typesetting:-Suppress(y(x)); # this says to use y' and not y'(x)
ode:=(-x^2+1)*diff(y(x),x)^2 = 1-y(x)^2;
latex(ode)


gives

\left(-x^{2}+1\right) y^{\prime}^{2} = 1-y^{2}


Here is also screen shot of the above

So you see I am using exactly the code generated by Maple as is. The program copies the latex to a file and the compiles it.

My question is: is this a Maple latex() command issue I should report to Maplesoft to fix? I do not know if this is how the latex was generated before I did an update to Maple last night or not. I will try to find out.

Meanwhile is there something I can do to workaround this without editing the actual latex generated by may be by adding something to the preamble? I can't edit the latex as it is all auto-generated by I can edit the preamble and add macros there to work around problems.

Update

I looked at an old latex generated by Maple before the update I did last night, and this is what it generated for the same equation

 \left(-x^{2}+1\right) \left(y^{\prime}\right)^{2} = 1-y^{2}


compare to the current version which is

 \left(-x^{2}+1\right) y^{\prime}^{2} = 1-y^{2}


So it is Maple's fault. the first version above compiles OK and gives

So it seems like something changed in Maple's latex generated. I will report to Maplesoft.

• y^{\prime}^{2} has always been a tex error this is unrelated to any tex update so it's a bug in maple code (either yours or maplesoft's so not really on topic) Jan 29 at 21:53
• @DavidCarlisle is it off topic to ask for a workaround? if so, do you want me to delete this question? Jan 29 at 21:58
• no, but there really is no tex work around for such a syntax error other than fixing the input. I guess @Mico will show a luatex callback Lua gsub edit, but I'd do a one of fix wit sed or perl rather than have lua re-edit on every run Jan 29 at 22:04

I suggest you replace

\left(-x^{2}+1\right) y^{\prime}^{2} = 1-y^{2}


with

\left(-x^{2}+1\right) {y^{\prime}}^{2} = 1-y^{2}


or, better still,

(-x^{2}+1) {y'}^{2} = 1-y^{2}


Addendum to address the OP's follow-up query. If I understand your comment correctly, you're looking for a method that replaces y^{\prime}^{2} "on the fly" with {y'}^{2}. Since it looks like you're using LuaLaTeX [good choice!], this method could consist of setting up a Lua function which uses Lua's built-in string functions and making it act like a pre-processor on the input stream.

% !TEX TS-program = lualatex
\documentclass{article}

%% copy the remainder of this preamble into your preamble
\usepackage{luacode} % for \luaexec macro

%% Lua-side code: Define a Lua function
\luaexec{
function FixMaple ( s )
return ( s:gsub ( "y\%^{\\prime}\%^{2}" , "{y'}^2" ) )
end
}

%% LaTeX-side code: Macros to activate and de-activate the Lua function
\newcommand\FixMapleOn{%
"process_input_buffer", FixMaple, "FixMaple" )}}
\newcommand\FixMapleOff{%
\directlua{luatexbase.remove_from_callback(
"process_input_buffer", "FixMaple" )}}

\begin{document}
\FixMapleOn % activate the Lua function
$\left(-x^{2}+1\right) y^{\prime}^{2} = 1-y^{2}$
\end{document}

• Thanks Mico, but as I said in my question, this is auto-generated latex. I can't edit the latex. I have 10's of thousands of latex files. I can add something to preamble if you suggest a macro. so do you think the latex generated is wrong so I report it? Jan 29 at 21:41
• @Nasser - y^{\prime}^{2} is clearly wrong. If you can report this issue to whoever is in charge of maintaining the faulty code, by all means go ahead and do so.
– Mico
Jan 29 at 21:43
• OK, but is there a way to make a macro that will automatically change y^{\prime}^{....} to {y^{\prime}}^{...}` in the meanwhile? if not, that is ok. I will report this to Maple. Jan 29 at 21:45
• @Mico I sense an input buffer callback addendum coming:-) Jan 29 at 21:54
• +1 for proving me right:-) Jan 29 at 22:07