# TraditionalForm-like typesetting in Jupyter notebook

One of the nice thing about running Mathematica codes in the front-end, is that one can attach custom typesetting rules to the user-defined symbols. Then, setting the format type of new output cells to TraditionalForm provides you with a nice output similar to what one sees in papers and textbooks.

Suppose that someone wants to use my package (that comes with extensive typesetting rules) with the free Wolfram Engine, where the front-end is a Jupyter notebook. As far as I can see, no typesetting is displayed by default.

As a minimal working example, consider the following code.

cf /: MakeBoxes[cf[i_], TraditionalForm] := SubscriptBox["c", i];
SubscriptBox["g", "W"];
TemplateBox[{OverscriptBox[ToBoxes[x], "\[RightArrow]"]}, "Abs"];
SuperscriptBox[
TemplateBox[{OverscriptBox[ToBoxes[x], "\[RightArrow]"]}, "Abs"],
ToBoxes[n]] /; OddQ[n];
SuperscriptBox[OverscriptBox[ToBoxes[x], "\[RightArrow]"],
ToBoxes[n]] /; EvenQ[n];


In Mathematica, for

SMP["g_W"] (cf[1] myvec[v] + cf[2] myvec[v]^2 + cf[3] myvec[v]^3)


I get the expected typesetted output, but in Jupyter this is not the case.

Is there something that can be tweaked in the notebook configuration or in the package source code, to get the typesetting working?

• Where is TraditionalForm set for In[17]?
– Kuba
Jun 3 '19 at 11:59
• I have not tried this, but please try adding //StandardForm or //TraditionalForm Jun 3 '19 at 11:59
• Actually, you are only defining it for TraditionalForm, so use //TraditionalForm Jun 3 '19 at 12:00
• WOW, with TraditionalForm it just works! Sorry guys, I always have my format type of new output cells set to TraditionalForm in Mathematica, so I didn't think that it is StandardForm in Jupyter by default, although it is quite logical. BTW, is there a way to make Jupyter always output TraditionalForm by default?
– vsht
Jun 3 '19 at 12:19
• SetOptions[$Output, FormatType -> TraditionalForm]? ( try it, I don't know, I have not used WE yet) – Kuba Jun 3 '19 at 12:53 ## 1 Answer I'd just use StandardForm because the loop WE-Jupyter is tricky to hook to. I guess this solution won't work once WLforJupyter is out of beta stage but anyway: toOut = toOutImage @* TraditionalForm; toOut /: (toOut = _) := Null;  It is not a joke :) ### Explanation toOut and toOutImage are symbols that are originally defined within the loop that handles communication between the Kernel and Jupyter notebook. Kernel sends evaluated response but Jupyter does not understand MMA Box language so it needs to be something else. Currently it is implemented that it is either a plain text, an image or an embedded iFrame with contents deployed to cloud. WLforJupyter loop makes a choice that it should be e.g. an image and does toOut = toOutImage @ evaluationResults So the trick is to set toOut (1st line) and prevent it from being reset (2nd line). :) • Nice workaround, although it seems that the number of terms is limited. While this works Sum[c[i],{i,1,7670}], increasing the number to 7675 returns $Failed. Using Shallow helps, though, cf. Shallow[Sum[c[i],{i,1,10000}]]. At the moment I think that your idea is the best thing one can come up with, so I accept it as an answer.
– vsht
Jun 5 '19 at 13:34
• @vsht does it return \$Failed before applying the trick? If so that is probably something to report.
– Kuba
Jun 5 '19 at 14:14
• It seems to be related only to the output (also without your trick), the kernel evaluates the expression just fine. I created an issue on GitHub for that here. I also opened another issue regarding TraditionalForm as the default cell output type, mentioning this question and your workaround.
– vsht
Jun 6 '19 at 16:22
• It’s crazy that gifs don’t work in the cloud
– M.R.
Jun 6 '19 at 18:38