Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is it possible to typeset systems of equations in Mathematica, and if so, how can I do it using a big left bracket as one could in LaTeX with \left\{ ... \.?

I know this is possible using the Piecewise, but is there a special command for this?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

You can implement your own environment like Piecewise

Equations /: MakeBoxes[Equations[eqs_], TraditionalForm] := 
     RowBox[{"\[Piecewise]", GridBox[{MakeBoxes[#, TraditionalForm]} & /@ {##} & @@ eqs]}]

TeXForm[expr] is equivalent to TeXForm[TraditinalForm[expr]] so I define custom formatting for TraditinalForm of my function Equations

eqs = {2 x + 3 y == 6, 4 x + 9 y == 15}

Equations[eqs] // TraditionalForm

enter image description here

Equations[eqs] // TeXForm
\begin{cases}
   2 x+3 y=6 \\
   4 x+9 y=15
\end{cases}

$\begin{cases} 2 x+3 y=6 \\ 4 x+9 y=15 \end{cases}$

Equations also works with another definition of the system of equations

eqs = 2 x + 3 y == 6 && 4 x + 9 y == 15

Equations[eqs] // TeXForm

$\begin{cases} 2 x+3 y=6 \\ 4 x+9 y=15 \end{cases}$

Update: you can easily modify Equations to produce aligned equations

Equations /: 
 MakeBoxes[Equations[eqs_, Alignment -> True], TraditionalForm] := RowBox[{"\[Piecewise]", 
   MakeBoxes[#, TraditionalForm] &@ Grid[{#1, "=", #2} & @@@ {##} & @@ eqs, 
     Alignment -> {{Right, Center, Left}}]}]

eqs = {2 x == 6, 4 x + 9 y == 15, z == 5}

Equations[eqs, Alignment -> True] // TraditionalForm

enter image description here

share|improve this answer
    
Thank you for your good answer! Though, I have never encountered the symbol /: before, could you point me to what it means? Thanks! –  Gabriel Oct 10 '13 at 21:02
    
@Gabriel /: with := is TagSetDelayed‌​. See also What the @#%^&*?! do all those funny signs mean? –  ybeltukov Oct 10 '13 at 21:05
add comment

I interpreted the question as requiring this to be done in text cells for typesetting rather than for input/output. The way to do this in a text cell is to start with the parenthesis on the left then add some grid boxes via Insert > Table/Matrix

enter image description here

From here you want to change the SpanMaxSize option via either the option inspector or add the option directly to the cell: SpanMaxSize->Infinity

enter image description here

enter image description here

Alternatively you could use \[Piecewise] instead of "{"

Next add some equations:

enter image description here

The problem now is that the equations are not aligned. I'm assuming here that you would want them aligned on the "=" sign. So place the cursor next to the "=" in each equation and type Esc am Esc or alternatively \[AlignmentMarker]. So you now have alignment markers in all equations. The final step is to tell your grid to align at the alignment marker. In most usages of \[AlignmentMarker] can you do this easily via the menu Format > TextAlignment > On AlignmentMarker. However in this case I could only get this to align via setting GridBoxOptions for the cell in the option inspector and setting GridBoxAlignment to align at the \[AlignmentMarker].

enter image description here

If I was doing this regularly I would create a specific style (which could include equation numbering) in my stylesheet with the appropriate GridBoxOptions set as well as SpanMaxSize->Infinity.

Cell[StyleData["Eqn",StyleDefinitions->"Text"],
SpanMaxSize->Infinity,
 GridBoxOptions->{GridBoxAlignment->{"Columns" -> {{"\[AlignmentMarker]"}}, "Rows" -> {{"\[AlignmentMarker]"}}}}]
share|improve this answer
    
There really should be a built-in much easier way to create such aligned, multi-line displays! –  murray Oct 11 '13 at 16:09
    
@murray this is actually very easy if you are not using gridboxes. –  Mike Honeychurch Oct 12 '13 at 0:11
    
Compare the ease of creating multi-line alignment in TeX by just inserting & within the alignment environment, on the one hand, with the verbosity required in Mathematica to type \[AlignmentMarker] or even its keyboard shortcut equivalent, on the other hand. –  murray Oct 12 '13 at 14:13
    
And contrast the ease in TeX of creating a multi-line spanning brace, by typing \left\{ and \right., on the one hand, with the above-mentioned methods for doing the same thing in Mathematica. –  murray Oct 12 '13 at 14:17
    
@murray a matter of personal preference. I don't find typing Esc am Esc to be a big deal. Also this method keeps the equation "together" whereas the accepted answer splits the equation into 3 columns with "=" the centre column. –  Mike Honeychurch Oct 12 '13 at 21:58
show 1 more comment

It depends upon the place you want it in. The answers above assumed by default that you need them in an output cell. I utilize Mathematica (among other purposes) to write documents and heavily use such cell as DisplayFormula and DisplayFormulaNumbered. In these cases you may employ instruments collected in the Writing Assistant.

As soon as your cursor is in the DisplayFormula or DisplayFormulaNumbered cell go to Menu/Palette/Wtiting Assistant/Typesetting And chose the button entitled "Piecewise defined function" on this tab. This will insert into your cell the left curly bracket embracing 2x2 slots to fill in. If you need to have three of them, mark one of the slots and press the button entitled "Column" in the same tab. You will see the title of the button, if you place the cursor over the button, and the tab name after you collapse the tab.

There is one drawback in this approach: the symbols have a somewhat smaller appearance. If this is not acceptable you might increase their size manually. Mark the corresponding formula, go to Menu/Format/Size and play with the sizes.

The alternative approach has been discussed here some time ago. Unfortunately I do not recall who proposed for this purpose a solution: the brackets that automatically stretch. Below find a slightly modified version of the palette proposed in that discussion:

    CreatePalette[
 Column[{Style[
    Grid[Join[
      Partition[
       Map[PasteButton[
          Style[RawBoxes@
            RowBox@Insert[#, "\[SelectionPlaceholder]", 2], 
           FontSize -> 14, SpanMaxSize -> Infinity]] &, 
        Most@Tuples[{{"[", "{", "(", ""}, {"]", "}", ")", ""}}]], 4]],
      Spacings -> {0, 0}]]}], WindowTitle -> "Brackets"]

After evaluating this code a palette will appear. By pressing the corresponding button in the palette one creates a slot with the left (ot right, or both) curly bracket (or another bracket). Place cursor into the slot and go to Menu/Palette/Wtiting Assistant/Typesetting and choose the button "Column" few times until you get a required structure.

share|improve this answer
    
The only advantage I see in using that palette over the "standard" method proposed by @Mike Honeychurch is that it automatically takes care of the SpanMaxSize specification. But it still doesn't help with aligning on equal signs, or anything else, in the successive rows. –  murray Oct 11 '13 at 16:21
    
@murray This palette is not the all-problems-solution, but a good-to-know one. I find it helpful. –  Alexei Boulbitch Oct 14 '13 at 7:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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