I get lots of error from using TeXForm in 12.3.1 on some solutions that contain DifferentialRoot
written in the new HolonomicBoxes
that WRI is now using.
But my attempts to use Quiet[Check[]]
in order to at least capture this error and replace the Latex with some message saying it failed to convert are not working.
What is the correct way to do this? Here is a MWE
ClearAll[y, x];
ode = (2*x + 1)*y''[x] - 2*(2*x^2 - 1)*y'[x] - 4*(x + 1)*y[x] == 0;
sol = DSolve[ode, y[x], x]
TeXForm[sol]
The message is TeXForm::unspt
. So I tried
result = Quiet[Check[TeXForm[sol], "FAILED", TeXForm::unspt]]
But this did not work. I still the same output in result
with the beep. I was expecting result
to say "FAILED".
I then tried
result = Quiet[Check[TeXForm[sol], "FAILED"]]
And this also did not work. I then tried
TeXForm[InputForm@sol]
Now the error message went away, but the Latex generated do not compile, as it contains lots of $\unicode{f818}
stuff, which Latex compiler does not like.
\text{$\{\{$y[x] -$>$ DifferentialRoot[Function[$\{\unicode{f818}$, $\unicode{f817}\}$, $\{$(-4 -
4*$\unicode{f817}$)*$\unicode{f818}$[$\unicode{f817}$] + (2 -
4*$\unicode{f817}{}^{\wedge}$2)*Derivative[1][$\unicode{f818}$][$\unicode{f817}$] + (1 +
2*$\unicode{f817}$)*Derivative[2][$\unicode{f818}$][$\unicode{f817}$] == 0, $\unicode{f818}$[0] ==
C[1], Derivative[1][$\unicode{f818}$][0] == C[2]$\}$]][x]$\}\}$
And I really do not want my Latex all as \text
anyway.
I simply would like to trap this error when the program is running and replace the Latex with simple say \text{unable to compile}
instead.
But I do not know how to catch it. Trapping and handling error in Mathematica is the hardest thing for me as it is too complicated to figure the right way to do it.
Any suggestions?
12.3.1
Reference catch-mathematica-warnings-errors-without-displaying-them
Reference how-to-implement-try-catch-end-try-in-mathematica-in-the-most-simple-way
Check
andQuiet
won't work, because it is done after the execution of your code. You could setBoxForm`$NewHolonomicBoxes = False
but that doesn't seem to be what you ask for. Or you could useConvert`TeX`ExpressionToTeX[sol]
, but again you get no error. $\endgroup$TeXForm[InputForm@sol]
which contains all those\unicode{f818}
stuff which does not compile with lualatex. So I thought better to get the error and catch it so I can avoid all this Latex. Now what I do is check if the ode solution hasDifferentialRoot
in it, and just do not callTeXForm
at all. This is the best solution for now. And it is working. screen shot !Mathematica graphics $\endgroup$MakeBoxes[#, StandardForm] &@TeXForm[sol]
. SoCheck
works on it:Check[MakeBoxes[#, StandardForm] &@TeXForm[sol], Null]
$\endgroup$