In LaTeX, you can typeset expressions containing unbalanced brackets, by balancing them with an invisible delimiter \left. or \right.. Some such notations are common in calculus; for example, the two common notations for applying an expression at two points:

$$\int_a^b x^2 \mathrm{d} x = \left. \frac{x^3}{3} \right]_a^b \equiv \left. \frac{x^3}{3} \right|_a^b $$

Applying a function at one point:

$$\left. \frac{\partial f}{\partial x} \right| _{x=0}$$

The alternative notation for an open interval endpoint:

$$\left[a,b\right) \equiv \left[a, b\right[$$

But in the Mathematica symbol list, I don't see any invisible brackets. If you simply leave out the delimiter, it results in an unmatched bracket, messing up the formatting if you have multiple such expressions in the same cell.

How do you typeset such expressions in Mathematica? (This is in display formulas; it doesn't have to be evaluatable.)

  • $\begingroup$ You're not evaluating these, right? Aren't these solely for typesetting? In that case, does it really matter if the brackets are not matched? I don't use these fancy typesetting options, so I don't know... $\endgroup$
    – rm -rf
    Commented Nov 15, 2012 at 22:01
  • $\begingroup$ as per @rm-rf comments, if it is just for typesetting, not for evaluation, you can switch of the unmatched bracket syntax highlighting so that it looks "normal" $\endgroup$ Commented Nov 15, 2012 at 22:06
  • 1
    $\begingroup$ @rm-rf: It breaks Ctrl-. selection, and if you have several right-brackets on one line, e.g. $f[x]]_{x=1}=g[x]]_{x=1}=h[x]]_{x=1}$, the brackets will get progressively bigger. $\endgroup$ Commented Nov 15, 2012 at 22:08
  • $\begingroup$ I suspect the indication of @rojo on this answer can be translated to this context(?) $\endgroup$
    – chris
    Commented Nov 15, 2012 at 22:18
  • $\begingroup$ The ScriptSizeMultiplier option is probably controlling the expanding brackets. $\endgroup$ Commented Nov 15, 2012 at 22:19

4 Answers 4


See this answer to question (101070) for the basic approach to enable the typesetting you desire for evaluating a function at one or two points. The interval typesetting is a bit trickier, but the basic idea is to give the bracket a SyntaxForm option. As a simple example, compare:

RawBoxes @ RowBox[{"[", FractionBox["x","3"], "["}]

enter image description here


RawBoxes @ RowBox[{"[", FractionBox["x","3"], TagBox["[", #&, SyntaxForm->"]"]}]

enter image description here

The latter example shows the desired spanning behavior. Of course, it is not evaluatable. To make it evaluatable, one can use a TemplateBox. Here is an input alias making use of a TemplateBox:

CurrentValue[EvaluationNotebook[], {InputAliases, "oc"}] = TemplateBox[
    DisplayFunction -> (
            StyleBox["[", SpanMaxSize->Infinity],
            StyleBox[TagBox["[", #&, SyntaxForm->"]"], SpanMaxSize->Infinity]

Here is an animation showing the alias in action:

enter image description here


If the problem is the size of the brackets after e.g. g[x] then you can split the inline cells. See before and after shots below

enter image description here

Just to be clear, the second example in the screen grab is two inline cells side by side:

enter image description here

  • $\begingroup$ It may work for some cases, but I hope there's some more convincing workaround. Some part of the equation has to be in a different "nesting level". And what if this sum was already inside some x+(...)? $\endgroup$
    – Rojo
    Commented Nov 15, 2012 at 23:30
  • $\begingroup$ @Rojo I don't know if it is possible to define different nesting levels within an inline cell therefore this seems like an option. $\endgroup$ Commented Nov 15, 2012 at 23:33
  • $\begingroup$ @Rojo I think we're talking apples and oranges. I know you can have nested inline cells. I understood your comment to be about different nesting options within a single inline cell. $\endgroup$ Commented Nov 15, 2012 at 23:46
  • $\begingroup$ Wouldn't this approach imply that you have to start a new inline cell for every invisible opening bracket that you would like to insert? If you're in an inline cell, getting out of it and starting a new one doesn't seem to cover all cases, such as x+(...]). If I'm misunderstanding something I'll probably get back to this later and not bug you and the answer with long comments $\endgroup$
    – Rojo
    Commented Nov 15, 2012 at 23:58
  • $\begingroup$ @Rojo whether you have to have multiple adjacent inline cells depends on the nature of the equation. In the grabs above there are several unmatched brackets but only two inline cells. So it depends on the location of these unmatched brackets. yes x+(...]) is a problem. $\endgroup$ Commented Nov 16, 2012 at 0:20

If I understood the question, this is a question on the automatic formatting of an expression you are trying to type in, on how the FE automatically groups it into boxes.

So, for example

       RowBox[{RowBox[{"f", "(", FractionBox["x", "6"], ")"}], "]"}], 
       RowBox[{"x", "=", "1"}]], "=", RowBox[{"g", "[", "x", "]"}]}], 
    "]"}], RowBox[{"x", "=", "1"}]]

is not the same as this

    RowBox[{RowBox[{"f", "(", FractionBox["x", "6"], ")"}], "]"}], 
    RowBox[{"x", "=", "1"}]], "=", 
   SubscriptBox[RowBox[{RowBox[{"g", "(", "x", ")"}], "]"}], 
    RowBox[{"x", "=", "1"}]]}]

In those cases where the automatic grouping isn't appropriate, I don't see an easy fix so far to fix it without interrupting the typing flow.

An input alias such as the following would allow you to insert the desired box structure. The invisible TagBox is important so that the front end doesn't regroup automatically

PrependTo[CurrentValue[InputNotebook[], InputAliases], 
 "app2p" -> 
     SubsuperscriptBox["]", "\[Placeholder]", "\[Placeholder]"]}], 

As all input aliases, it works by typing the keyword between Esc. In this case, the keyword is app2p

A more general solution of this sort is to define an input alias to insert only the invisible tag box

   PrependTo[CurrentValue[InputNotebook[], InputAliases], 
     "tb" ->  TagBox["\[SelectionPlaceholder]", "tb"]]

You just have to remember that there's an invisible box and exit it when appropriate

  • $\begingroup$ @MechanicalSnail, added an edit $\endgroup$
    – Rojo
    Commented Nov 16, 2012 at 12:38

I don't get the described problems when using inline math in a text cell (using Ctrl-(), nor when I copy this math to an empty space. I get this:

enter image description here

  • 2
    $\begingroup$ The brackets after g[x] and h[x] shouldn't be as big as those grouping fraction boxes if everything was fine I believe $\endgroup$
    – Rojo
    Commented Nov 15, 2012 at 22:34
  • $\begingroup$ @Rojo if that is the case then the expression could be split into multiple inline cells. $\endgroup$ Commented Nov 15, 2012 at 22:55
  • $\begingroup$ @MikeHoneychurch, yes, but that feels like a compromise to me. Inline cells inside inline cells toggle the style from text to expression cells I think $\endgroup$
    – Rojo
    Commented Nov 15, 2012 at 23:10
  • $\begingroup$ @Rojo see my screen grabs. These are not inline inside inline. these are adjacent inline cells. i.e. you step out of the inline cell and create another one next to it. $\endgroup$ Commented Nov 15, 2012 at 23:16

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.