6
$\begingroup$

I find strange behavior of TeXUtilities by @jkuczm which I do not understand how to fix.

I find I have to call TeXForm two times for it to start working. Here is a MWE

This will install the package.

Import["https://raw.githubusercontent.com/jkuczm/MathematicaTeXUtilities/master/BootstrapInstall.m"]

If you do not want to install it, just use it one time, the command is

Import["https://raw.githubusercontent.com/jkuczm/MathematicaTeXUtilities/master/NoInstall.m"]

And now

 Needs["TeXUtilities`"]

 EllipticF;
 Unprotect[EllipticF];
 Format[EllipticF, TeXForm] = TeXVerbatim@"\\operatorname{EllipticF}";
 Protect[EllipticF];

 result1 = EllipticF[ArcSin[x], (-1)^(1/3)]
 TeXForm[result1]
 (*it does NOT work*)
 TeXForm[result1]
 (*Now it works!*)

Here is screen shot

Mathematica graphics

Notice how the EllipticF did not change to \operatorname{EllipticF} first time. Only on second call it changed.

I think this might be due to caching. But do not know to work around it.

Can this be made to work on first call, without having to call it 2 times?

Version 11.3 on windows 7.

reference is-it-possible-to-change-customize-some-conversions-done-by-texform

why-changing-the-order-of-format-causes-error

Update April 3, 2018

Adding information requested below. Using screen shot, since much better in this case to show the output. Now I get kernel errors when I added the commands as mentioned in comment. Not sure what it going on. I put the notebook also here

Mathematica graphics

Mathematica graphics

$\endgroup$
3
  • 1
    $\begingroup$ I don't have 11.3 to check what precisely is happening in your situation. If you could add FormatValues@EllipticF line: between EllipticF; and Unprotect[EllipticF]; lines, between Protect[EllipticF]; and result1 = EllipticF[ArcSin[x], (-1)^(1/3)] lines, and between two TeXForm calls, then we could know more about what is happening. I suspect that, as in linked question, it's an issue with autoloading, not directly related to TeXUtilities. $\endgroup$
    – jkuczm
    Apr 3, 2018 at 13:17
  • $\begingroup$ What works for me in version 11.0 is evaluating EllipticF[x, m] // TeXForm before any Format assignments, so that all relevant FormatValues are pre-loaded. Then assigning format with arguments Format[HoldPattern@EllipticF[a_, b_], TeXForm] := TeXVerbatim["\\operatorname{EllipticF}"][a, b]. Since formatting works differently than standard evaluation, there is no distinction between format OwnValues and DownValues. First format value that matches is used, so if there's formatting for whole EllipticF[x, m] expression then specialized formatting for EllipticF head is not used. $\endgroup$
    – jkuczm
    Apr 3, 2018 at 13:18
  • $\begingroup$ Thanks @jkuczm for looking at this. I added the command you requested., Now I get kernel error messages. Before, there is no kernel error messages. I also put link to the notebook if you want to look at it. I do not understand any of this myself. $\endgroup$
    – Nasser
    Apr 3, 2018 at 15:48

1 Answer 1

4
$\begingroup$

There are two problems in code from OP.

First problem is auto-loading of EllipticF format values. It seems there are two stages of this auto-loading. First, formatting with BoxForm`BoxFormAutoLoad[...] as RHS is set, then, when TraditionalForm formatting of EllipticF is used, BoxForm`BoxFormAutoLoad loads proper formatting. Both stages should be triggered by forcing TraditionalForm formatting of EllipticF[...] expression e.g. by evaluating EllipticF[x, m] // TeXForm, before assigning any new formatting to EllipticF.

Second problem is that, after successful auto-loading, EllipticF has defined formatting for EllipticF[a, b] expression, which will be used before any attempt of formatting parts of expression, including its head. That's why formatting for whole expression, not only its head, should be defined.

Putting it together:

Import@"https://raw.githubusercontent.com/jkuczm/MathematicaTeXUtilities/master/NoInstall.m"

EllipticF[x, m] // TeXForm
(* F(x|m) *)

Unprotect[EllipticF];
Format[HoldPattern@EllipticF[x_, m_], TeXForm] :=
    TeXVerbatim["\\operatorname{EllipticF}"][x, m];
Protect[EllipticF];

result1 = EllipticF[ArcSin[x], (-1)^(1/3)];
result1 // TeXForm
(* \operatorname{EllipticF}\left(\sin ^{-1}(x),\sqrt[3]{-1}\right) *)
$\endgroup$
1
  • $\begingroup$ Thanks,. The above seems to work. No errors in 11.3. I need to test it on my main build to make sure. You might want to also modify your answer here is-it-possible-to-change-customize-some-conversions-done-by-texform to make it like the above. As I was using your answer there to show the issue in my question. This way, if someone sees the old answer, they will not have same problem again. $\endgroup$
    – Nasser
    Apr 4, 2018 at 19:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.