In practice, I think it's inevitable that we'll have to work with box forms (which aren't that hard, but rather low-level functions) if you plan to typeset structures that aren't valid Mathematica expressions. The vertical right bracketing bar is one example for this. Also, square brackets in StandardForm
would be translated to round brackets in TraditionalForm
if you supply them to Mathematica as an expression. So it doesn't usually lead to robust results if you construct fake but valid expressions that happen to look like what you need. You have to construct the box structures yourself.
First, you want to preserve the two-dimensional structure of the integral, so I use DisplayForm
:
t = TraditionalForm[Integrate[x^2, x]];
DisplayForm[
RowBox[{ToBoxes[t],
StyleBox["\[RightBracketingBar]", SpanMinSize -> 2]}]
]
This is a type of display that by default doesn't render the content in TraditionalForm
, even though we already specified it in t
. So we have to add that again later. The super and subscripts can be added to this in a "less low-level" way, because they don't conflict with Mathematica syntax. So instead of having another RowBox
or some other ...Box
, I wrap the last object simply in Subsuperscript
, and then combine it (if necessary) with other objects in a Row
, Column
or Grid
:
Subsuperscript[
DisplayForm[
RowBox[{ToBoxes[t],
StyleBox["\[RightBracketingBar]", SpanMinSize -> 2]}]
], 1, 2]
You get the final desired output by adding the TraditionalForm
again, as mentioned above:
TraditionalForm[%]
$$\left.\frac{x^3}{3}\right|_1^2$$