16
$\begingroup$

What's the cell option (or other technique) to use to stretch the curly brace that one typically uses in traditional math to group several displayed equations? Like this:

Mathematica graphics

And is there any better way of getting the vertical alignments of the equations that simply inserting a 3-column table?

$\endgroup$
6
  • 1
    $\begingroup$ You could try using Piecewise (ESC pw ESC). It doesn't look exactly the same though. $\endgroup$
    – Szabolcs
    Mar 11, 2013 at 21:08
  • $\begingroup$ I know there is some such option -- something to do with "span" I think -- but I cannot find it now in Option Inspector. I even recall that somebody at WRI wrote to MathGroup about this several years ago. $\endgroup$
    – murray
    Mar 11, 2013 at 21:13
  • 3
    $\begingroup$ I found the option: SpanMaxSize. If you change its value from the default Automatic to Infinity, then the opening brace will be stretched so as to enclose all the rows of the table. $\endgroup$
    – murray
    Mar 11, 2013 at 21:56
  • 1
    $\begingroup$ @murray Your approach works very well when used in a Style wrapper for a FormBox containing the brace. This should be an answer. $\endgroup$
    – Jens
    Mar 11, 2013 at 23:40
  • $\begingroup$ @Jens: I didn't actually us a Style wrapper for a FormBox (I hate programming using boxes!) Rather, I used the option for the entire cell. For my purposes that sufficed, although I can envision others where it would be too crude an approach. $\endgroup$
    – murray
    Mar 12, 2013 at 4:18

5 Answers 5

15
$\begingroup$

Here is one of my personal examples:

enter image description here

How I did it:

  • Ctrl 9 (inline cell); doesn't work on/as the first case/letter of a Text cell (needs at leas a space)
  • esc pw esc
  • copy paste inside the pw element the output of something like Grid[{{a}, {b}, {c}}, Alignment -> Left]
  • substitute the content a, b, c with your content

Then you can reuse it... (I have an entire book written with these structures)

Your example, with the same technique:

enter image description here

You can obviously tweak it a lot with Spacings, ItemSize, Style, etc

And you can even go to the extreme of:

  • Ctrl 9
  • esc pw esc
  • write inside the pw element Grid[{{HoldForm[x-1=t]},{HoldForm[y=1-t^2]}},Alignment->"="]
  • select the Grid[...], and choose evaluate in place (from the context menu)

enter image description here

...and editing it holds the alignment specification to the "=" sign!

And for the slightly extra extension of the brackets:

enter image description here

It is also possible to simulate an align to different characters, although the only way I found is a little messier. There are invisible characters available in Mathematica. Be careful because they are... well... invisible. This means that you can mess things if they end up in the middle of computations... I'm going to demonstrate the technique with the esc am esc (aka \[AlignmentMarker]).

Another problem with this technique is that, since there is an invisible thing in the middle of the expression, the parser complains about it. So, I entered everything as strings (there's probably a better way of avoiding it). But, entering everything as string, brakes special characters formating during evaluation in place... But everything ends up working after editing it. Here is a way of doing:

  • Ctrl 9
  • esc pw esc
  • write inside the pw element Column[{Null,Grid[{{"test\[AlignmentMarker]=b"},{"bigger test\[AlignmentMarker]>b"}},Alignment->"\[AlignmentMarker]"],Null},ItemSize->{Automatic,{0.1,{02.},0.1}}]
  • select the Column[...], and choose evaluate in place (from the context menu)

enter image description here

  • edit to your needs (including the erasing of the "'s, but, while editing, don't erase your markers!)

enter image description here

$\endgroup$
3
  • $\begingroup$ I selected this as the answer because it seems to "kill two birds with one stone": to extend the brace and to align things on the equal sign. It even works to align on the equal sign when you have merely a series of equalities broken across lines (with nothing preceding the = on succeeding lines). However, it will not work if you have inequalities as well as qualities on the several lines; apparently Alignment won't let you specify more than a single character on which to align in a Grid. (I would love to be proved wrong here.) $\endgroup$
    – murray
    Mar 12, 2013 at 15:27
  • $\begingroup$ @murray I just added a way of aligning to different characters (not exactly true, but I think it gives what you want) $\endgroup$
    – P. Fonseca
    Mar 12, 2013 at 20:26
  • $\begingroup$ "Ctrl 9 (inline cell); doesn't work on/as the first case/letter of a Text cell (needs at least a space)" Which version were you using? This seems to be a fixed bug. I tested in v8.0.4, v9.0.1, v12.3.1, win 10, space is not needed before pressing Ctrl+9. $\endgroup$
    – xzczd
    Mar 2, 2022 at 5:57
17
$\begingroup$

I would use a formatting function like this:

Format[bracket[obj_]] :=
  Style[DisplayForm @ RowBox[{"{", obj}], SpanMaxSize -> Infinity]

Or with MakeBoxes, which may be preferable:

MakeBoxes[bracket[obj_], fmt_] :=
  StyleBox[RowBox[{"{", obj ~ToBoxes~ fmt}], SpanMaxSize -> Infinity]

(You don't need both definitions at the same time.)

Then it will left-bracket whatever expression you give it:

Grid[Binomial ~Array~ {5, 5}] // bracket

Mathematica graphics

{"one", "two", "three"} // Column // bracket

Mathematica graphics

Plot[Sinc[x], {x, 0, 10}] // bracket

Mathematica graphics


As a separate answer to the second part of your question you can use the Alignment option.
This works with both Strings and held expressions:

Column[{"x = 1+t", "two = 1-t^2", "three = 1+t^3"}, Alignment -> "="]

Column[
 HoldForm /@ Unevaluated@{x = 1 + t, two = 1 - t^2, three = 1 + t^3}, 
 Alignment -> "="
]

Mathematica graphics

Combined with bracket:

% // bracket

Mathematica graphics

$\endgroup$
7
  • $\begingroup$ Nice. Is it possible, perhaps by some minor tweak or use of an alignment marker, to align the equal sign of equations of varying lengths? $\endgroup$
    – DavidC
    Mar 12, 2013 at 2:31
  • $\begingroup$ @David I guess I should add something about that to my answer, but I saw it as a side matter. $\endgroup$
    – Mr.Wizard
    Mar 12, 2013 at 2:36
  • $\begingroup$ This answer, like some others, requires what seems to be an inordinate amount of coding for what ought to be a simple, straightforward text-entry issue about very basic mathematical typesetting. (Makes one wonder how much the Mathematical front-end designers really know about mathematical typesetting.) $\endgroup$
    – murray
    Mar 12, 2013 at 15:30
  • $\begingroup$ Also, the alignment part of this answer won't handle the situation where you have some equalities and some inequalities. Any decent mathematical typesetting ought to allow alignment on characters that vary from one line to the next! $\endgroup$
    – murray
    Mar 12, 2013 at 17:23
  • $\begingroup$ @murray Just insert \[AlignmentMarker] before the character you want to align on and it works: try this Column[{"x \[AlignmentMarker]= 1+t", "two \[AlignmentMarker]< 1-t^2", "three \[AlignmentMarker]\[NotEqual] 1+t^3"}, Alignment -> "\[AlignmentMarker]"] $\endgroup$ Mar 13, 2013 at 21:44
16
$\begingroup$

For convenient typesetting, I would use a palette in this case:

CreatePalette[
 Column[{
   "Extensible Brackets",
   Style[
    Grid[
     Join[
      Partition[
       Map[PasteButton[
          Style[RawBoxes@
            RowBox@Insert[#, "\[SelectionPlaceholder]", 2], 
           SpanMaxSize -> Infinity]] &, 
        Most@Tuples[{{"[", "{", ""}, {"]", "}", ""}}]
        ], 4],
      Map[
       PasteButton[
         RawBoxes[#]] &, {{UnderscriptBox["\[SelectionPlaceholder]", 
          "︸"], UnderscriptBox["\[SelectionPlaceholder]", "︶"], 
         UnderscriptBox["\[SelectionPlaceholder]", "\[UnderBracket]"],
          UnderscriptBox["\[SelectionPlaceholder]", "_"]},
        {OverscriptBox["\[SelectionPlaceholder]", "︷"], 
         OverscriptBox["\[SelectionPlaceholder]", "︵"], 
         OverscriptBox["\[SelectionPlaceholder]", "\[OverBracket]"], 
         OverscriptBox["\[SelectionPlaceholder]", "_"]}}, {2}]
      ]
     , Spacings -> {0, 0}], FontSize -> 8]
   }]
 ]

palette

All of these templates show some combination of delimiters that can be extended, either vertically or horizontally. To use the vertical unbalanced delimiters, you should normally first make sure that you're in a TraditionalForm environment so that the parser doesn't try to balance the brackets. This is based on my interpretation that you want to use these braces purely in typesetting and not as a function such as Piecewise.

As for the vertical alignment, a palette can also help with that. Have a look at the plain Row and Column templates in the Basic Math Assistant palette, for example.

Usage examples

Typesetting vertically stretched delimiters would realistically happen mostly in a DisplayFormula environment. This is what you see here (numbered equations):

usage

To get these forms, just press the corresponding template button in the palette and then enter the column into the black square indicating the placeholder. Alternatively, highlight an existing column and press the button to apply the delimiters.

Likewise, you can do these things in a text cell by opening an inline cell as one always does for equations, and then proceeding as above:

text cell

$\endgroup$
3
  • $\begingroup$ It looks alright in DisplayFormula style. (I don't know why I didn't try that.) +1 $\endgroup$
    – Mr.Wizard
    Mar 12, 2013 at 5:26
  • $\begingroup$ I added a picture showing that it also works in an inline cell. Hope that clarifies it. $\endgroup$
    – Jens
    Mar 12, 2013 at 5:30
  • $\begingroup$ Side note: we can also SetOptions[StyleBox, SpanMaxSize -> Infinity] since v9.0.1. (Yeah, this doesn't even work in v8, maybe a bug. ) $\endgroup$
    – xzczd
    Mar 2, 2022 at 6:30
4
$\begingroup$

There are probably easier ways to do this, but nothing comes to mind at the moment:

CellPrint@
  Cell[
   BoxData[
    FormBox[
      GridBox[
      {
       {"\[Piecewise]", 
        GridBox[
         {
          {RowBox[{"x", "\[AlignmentMarker]=", "1", "+", "t"}]},
          {RowBox[{"y", "\[AlignmentMarker]=", "1", "-", SuperscriptBox["t", "2"]}]}
          },
         GridBoxAlignment -> {"Columns" -> {{"\[AlignmentMarker]"}}},
         GridBoxSpacings -> {"Rows" -> {Offset[0.2], {Offset[0.84]}, Offset[0.2]}}]
        }
       }, 
      GridBoxSpacings -> {"Rows" -> {Offset[0.2], {Offset[0.4]}, Offset[0.2]}}], 
      TraditionalForm
     ]
    ], "Output"
  ]
]

Mathematica graphics

Note that the alignment marker will become invisible once you have typed it. See also ref:Structural Elements And Keyboard Characters.

$\endgroup$
0
0
$\begingroup$

I have used Grid and the Piecewise symbol as follows:

TraditionalForm@
Grid[{{"Parametric equations = ", 
    Style[TraditionalForm@"\[Piecewise]", 
    FontSize -> 36], TraditionalForm[x == 1 + t], 
    0 < t < 1}, {SpanFromAbove, 
    SpanFromAbove, TraditionalForm[y == 1 + t^2], t >= 0}}, 
    Alignment -> {{Center, Center, Left, Center}, Center}]

which gives the following result:

enter image description here

Ideally I'd improve this in the following ways:

  1. Find a way to make the bracket less bold.
  2. Find a way to make the Grid's Alignment option align on the = character. For some reason this does not behave as I would expect. have
$\endgroup$
4
  • $\begingroup$ That answer won't meet my needs in that it hard-codes the font size of the brace-- which means that magnifying the notebook won't work properly resize the brace. $\endgroup$
    – murray
    Mar 12, 2013 at 17:20
  • $\begingroup$ @murray Using magnifications should change the size of everything. Could you link an image of what you're seeing? $\endgroup$
    – Mr.Wizard
    Mar 15, 2013 at 0:57
  • $\begingroup$ As an alternative, you can try the following: instead of using FontSize -> 36 to size the brace, you can use SpanMinSize -> 2, which spans the brace to twice the font size. The resulting brace looks more appealing, but it may also not scale up in the way you wish. @murray $\endgroup$ Mar 15, 2013 at 8:07
  • $\begingroup$ @Mr.Wizard: You're correct, that changing the magnification does change the brace's size, too, even when the FontSize is hard-coded. However, if I switch from Working screen environment to Presentation screen environment, the brace does not stretch to enclose the full height of the lines. $\endgroup$
    – murray
    Mar 15, 2013 at 13:50

Your Answer

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

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