6

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

Nasser
  • 143,286
  • 11
  • 154
  • 359
  • 1
    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. – jkuczm Apr 03 '18 at 13:17
  • 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. – jkuczm Apr 03 '18 at 13:18
  • 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. – Nasser Apr 03 '18 at 15:48

1 Answers1

4

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) *)
jkuczm
  • 15,078
  • 2
  • 53
  • 84