# PostProcessing TraditionalForm output to append a vertical bar?

This simple task is giving me trouble. Suppose I'd like to take the output from

TraditionalForm[Integrate[x^2,x]]


and post-process it to append a vertical bar like

$${x^3\over 3}\Bigg|_0^1$$

or a set of left & right brackets like

$$\left[\frac{x^3}{3}\right]_0^1$$

I am trying to figure out the best way to approach this problem. Is to convert the output to a string and then use StringJoin?

-
I thought there is answer for the above here mathematica.stackexchange.com/questions/30459/… (by @Jens). May be I overlooking something in the details... –  Nasser Aug 14 '13 at 23:36
Based on the time stamps, I believe I posted my question just a little before Jens posted that answer there (or certainly before I saw it). –  JohnD Aug 15 '13 at 0:18
sure, I did not look at times, just wanted to bring your attention that there is an answer there that might be what you wanted. –  Nasser Aug 15 '13 at 0:22

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$$

-
Thanks for your remark, I should stop posting in the middle of the night :) –  Kuba Aug 15 '13 at 7:50