# Typeset unbalanced brackets

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

$$\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.)

-
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... – rm -rf Nov 15 '12 at 22:01
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" – Mike Honeychurch Nov 15 '12 at 22:06
@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. – Mechanical snail Nov 15 '12 at 22:08
I suspect the indication of @rojo on this answer can be translated to this context(?) – chris Nov 15 '12 at 22:18
The ScriptSizeMultiplier option is probably controlling the expanding brackets. – Mike Honeychurch Nov 15 '12 at 22:19
show 1 more comment

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

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

is not the same as this

RawBoxes@RowBox[{SubscriptBox[
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" ->
TagBox[RowBox[{"\[SelectionPlaceholder]",
SubsuperscriptBox["]", "\[Placeholder]", "\[Placeholder]"]}],
"app2p"]]

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

-
 @MechanicalSnail, added an edit – Rojo Nov 16 '12 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:

-
The brackets after g[x] and h[x] shouldn't be as big as those grouping fraction boxes if everything was fine I believe – Rojo Nov 15 '12 at 22:34
@Rojo if that is the case then the expression could be split into multiple inline cells. – Mike Honeychurch Nov 15 '12 at 22:55
@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 – Rojo Nov 15 '12 at 23:10
@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. – Mike Honeychurch Nov 15 '12 at 23:16

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

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

-
 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+(...)? – Rojo Nov 15 '12 at 23:30 @Rojo I don't know if it is possible to define different nesting levels within an inline cell therefore this seems like an option. – Mike Honeychurch Nov 15 '12 at 23:33 @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. – Mike Honeychurch Nov 15 '12 at 23:46 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 – Rojo Nov 15 '12 at 23:58 @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. – Mike Honeychurch Nov 16 '12 at 0:20