1
$\begingroup$

My goal is to write usage messages in the same style as Mathematica's built-in ones, such as List::usage. This involves a mess of StyleBox commands:

"\!\(\*RowBox[{\"{\", RowBox[{SubscriptBox[StyleBox[\"e\", \"TI\"],
StyleBox[\"1\", \"TR\"]], \",\", SubscriptBox[StyleBox[\"e\", \"TI\"],
StyleBox[\"2\", \"TR\"]], \",\", StyleBox[\"\[Ellipsis]\", \"TR\"]}],
\"}\"}]\) is a list of elements. "

Rather than figuring out the styles "TI", "TR" appropriate for each situation, I determined that using TraditionalForm does a good job of emulating it (perhaps T in "TI" and "TR" stands for Traditional?).

To get boxes into a string one can use the \!\(...\) syntax or the \*... syntax, so for instance, I can get a FractionBox of a over b by doing

"\*" <> ToString[ToBoxes[a/b]]

Better, "\*" <> ToString[ToBoxes[a/b,TraditionalForm],InputForm] (the use of InputForm makes Mathematica escape some strings as needed in more complicated expressions). The TraditionalForm only makes a and b be italicized, but does not put it in the font that a/b//TraditionalForm gives.

After digging a bit, the question boils down to why

"\*FormBox[FractionBox[a,b],TraditionalForm]"

"\*FormBox[FractionBox[a,b],TraditionalForm]" // TraditionalForm

give different outputs (different fonts), and how to get the second output, hopefully without having to understand the precise styles used by TraditionalForm.

$\endgroup$
  • $\begingroup$ TR stands for Times Regular; TI for TimesItalic $\endgroup$ – m_goldberg Jun 21 '16 at 18:16
  • $\begingroup$ @m_goldberg Thanks. $\endgroup$ – Bruno Le Floch Jun 21 '16 at 20:05

Your Answer

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

Browse other questions tagged or ask your own question.