13
$\begingroup$

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

$\endgroup$
6
  • $\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

3
$\begingroup$

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

with:

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[
    {"\[SelectionPlaceholder]"},
    "OCInterval",
    DisplayFunction -> (
        RowBox[{
            StyleBox["[", SpanMaxSize->Infinity],
            #,
            StyleBox[TagBox["[", #&, SyntaxForm->"]"], SpanMaxSize->Infinity]
        }]&
    )
];

Here is an animation showing the alias in action:

enter image description here

$\endgroup$
2
$\begingroup$

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

$\endgroup$
5
  • $\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
1
$\begingroup$

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

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

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

$\endgroup$
4
  • 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

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