2
$\begingroup$

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]

Mathematica graphics

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

$\endgroup$
3
  • 2
    $\begingroup$ The message is generated when the FE typesets the output. So Check and Quiet won't work, because it is done after the execution of your code. You could set BoxForm`$NewHolonomicBoxes = False but that doesn't seem to be what you ask for. Or you could use Convert`TeX`ExpressionToTeX[sol], but again you get no error. $\endgroup$
    – Michael E2
    Commented Nov 28, 2021 at 2:04
  • $\begingroup$ Thanks @MichaelE2 I actually tried this also before, but it does not do what I want, since the output gives similar result as when doing 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 has DifferentialRoot in it, and just do not call TeXForm at all. This is the best solution for now. And it is working. screen shot !Mathematica graphics $\endgroup$
    – Nasser
    Commented Nov 28, 2021 at 2:09
  • $\begingroup$ This gives the error (but twice for some reason -- once in the kernel, once in the FE?): MakeBoxes[#, StandardForm] &@TeXForm[sol]. So Check works on it: Check[MakeBoxes[#, StandardForm] &@TeXForm[sol], Null] $\endgroup$
    – Michael E2
    Commented Nov 28, 2021 at 2:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.