4
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ I thought there is answer for the above here mathematica.stackexchange.com/questions/30459/… (by @Jens). May be I overlooking something in the details... $\endgroup$
    – Nasser
    Commented Aug 14, 2013 at 23:36
  • $\begingroup$ 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). $\endgroup$
    – JohnD
    Commented Aug 15, 2013 at 0:18
  • 1
    $\begingroup$ 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. $\endgroup$
    – Nasser
    Commented Aug 15, 2013 at 0:22

1 Answer 1

3
$\begingroup$

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]}]
 ]

displayform

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]

sub super

You get the final desired output by adding the TraditionalForm again, as mentioned above:

TraditionalForm[%]

$$\left.\frac{x^3}{3}\right|_1^2$$

$\endgroup$
1
  • $\begingroup$ Thanks for your remark, I should stop posting in the middle of the night :) $\endgroup$
    – Kuba
    Commented Aug 15, 2013 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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