5
$\begingroup$

I am trying the solution given in is-it-possible-to-change-customize-some-conversions-done-by-texform which works very well except changing the order of the Format command causes an error on some symbols.

I do not know if this is Mathematica own issue with the command Format or if it is related to the package I am using.

First I installed the nice package MathematicaTeXUtilities using the command

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

Here is MWE. Using the following order, with fresh kernel, show no error

Needs["TeXUtilities`"]
Unprotect[Hypergeometric1F1,HypergeometricU];
Format[ Hypergeometric1F1, TeXForm] = TeXVerbatim@"\\operatorname{Hypergeometric1F1}";
Format[ HypergeometricU, TeXForm] = TeXVerbatim@"\\operatorname{HypergeometricU}";
Protect[Hypergeometric1F1,HypergeometricU];

Now, changed the order of Format command, and using fresh kernel (must restart the kernel to see the error), an error message shows up

Needs["TeXUtilities`"]
Unprotect[Hypergeometric1F1,HypergeometricU];
Format[ HypergeometricU, TeXForm] = TeXVerbatim@"\\operatorname{HypergeometricU}";
Format[ Hypergeometric1F1, TeXForm] = TeXVerbatim@"\\operatorname{Hypergeometric1F1}";
Protect[Hypergeometric1F1,HypergeometricU];

Mathematica graphics

I thought at first that the order of symbols in Protect has to match the order of Format commands. But this does not make sense. And I found by trial and error a case where the errors show up even when the order or Protect match order of Format. Here it is (fresh kernel)

Needs["TeXUtilities`"]
Unprotect[HypergeometricU,LaguerreL,HermiteH,Hypergeometric1F1,Erf,Erfc];
Format[ HypergeometricU, TeXForm] = TeXVerbatim@"\\operatorname{HypergeometricU}"
Format[ LaguerreL, TeXForm] = TeXVerbatim@"\\operatorname{LaguerreL}"
Format[ HermiteH, TeXForm] = TeXVerbatim@"\\operatorname{HermiteH}"
Format[ Hypergeometric1F1, TeXForm] = TeXVerbatim@"\\operatorname{Hypergeometric1F1}"
Format[ Erfc, TeXForm] = TeXVerbatim@"\\operatorname{Erfc}"
Format[ Erf, TeXForm] = TeXVerbatim@"\\operatorname{Erf}"
Protect[HypergeometricU,LaguerreL,HermiteH,Hypergeometric1F1,Erf,Erfc];

Mathematica graphics

So I am not sure what is going on now. Any ideas?

As a workaround, now I Format them one by one, instead of the batch mode and error went away

Needs["TeXUtilities`"]

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

Unprotect[HypergeometricU];
Format[ HypergeometricU, TeXForm] = TeXVerbatim@"\\operatorname{HypergeometricU}";
Protect[HypergeometricU];
$\endgroup$
0
2
$\begingroup$

Many System` symbols autoload when they are used. This is what is happening in your example. For instance, from a fresh kernel:

OwnValues @ HypergeometricU

{HoldPattern[HypergeometricU] :> System`Dump`AutoLoad[Hold[HypergeometricU], Hold[HypergeometricPFQ, HypergeometricPFQRegularized, HypergeometricU], "SpecialFunctions`HypergeometricPFQ`"] /; System`Dump`TestLoad}

This means that when HypergeometricU is evaluated, System`Dump`AutoLoad is called. Note the second argument, namely Hold[HypergeometricPFQ, HypergeometricPFQRegularized, HypergeometricU]. These symbols get protected during autoloading. So, this is what is happening during your example:

Unprotect[HypergeometricU,LaguerreL,HermiteH,Hypergeometric1F1,Erf,Erfc];

HypergeometricU gets unprotected

Format[ HypergeometricU, TeXForm] = TeXVerbatim@"\\operatorname{HypergeometricU}"

First, HypergeometricU is evaluated (Format has no Hold* attributes). Then, the TeXForm Format is stored. Since HypergeometricU is evaluated, it autoloads, and during this process, HypergeometricPFQ, HypergeometricPFQRegularized, HypergeometricU all get protected.

Format[ Hypergeometric1F1, TeXForm] = TeXVerbatim@"\\operatorname{Hypergeometric1F1}"

Since Hypergeometric1F1 is now Protected, you get a Message, and no Format is stored.

$\endgroup$
1
  • $\begingroup$ Great answer! So I guess the takeaway is to always make sure system functions are pre-loaded before messing with their attributes. Now that I knew to look for autoload, found related discussion here. (+1) $\endgroup$ – John Joseph M. Carrasco Aug 19 '17 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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