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?
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
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
/:
with :=
is TagSetDelayed. See also What the @#%^&*?! do all those funny signs mean?
$\endgroup$
Oct 10, 2013 at 21:05
DisplayForm@RowBox[{StyleBox["{", SpanMaxSize -> Infinity], Column[eqs, Alignment -> "\[Equal]"]}]
$\endgroup$
Feb 2, 2015 at 10:28
TranditionalForm
as well as TeXForm
.
$\endgroup$
Feb 2, 2015 at 12:17
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
From here you want to change the SpanMaxSize
option via either the option inspector or add the option directly to the cell: SpanMaxSize->Infinity
Alternatively you could use \[Piecewise]
instead of "{"
Next add some equations:
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]
.
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]"}}}}]
&
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.
$\endgroup$
\left\{
and \right.
, on the one hand, with the above-mentioned methods for doing the same thing in Mathematica.
$\endgroup$
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.
$\endgroup$
Oct 12, 2013 at 21:58
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.
SpanMaxSize
specification. But it still doesn't help with aligning on equal signs, or anything else, in the successive rows.
$\endgroup$