4

I'm writing some notes on linear algebra and to ease my work I've decided to use the systeme package. When I discovered that systeme has no built-in feature of writing systems of equations with dots and non-numeric coefficients, I've decided to use the fix suggested in this answer.

I need to write the full process of row-reduction of a specific system of equations, and I've done it before using the cases environment inside an align* environment. But the cases environment won't align the coefficients as desired, although each system is just where I wanted it to be. The fix suggested in this post yields an error when used inside the align* environment. What can I do?

A test sample for the error:

\documentclass{article}

\usepackage{amsmath}
\usepackage{xstring}

\def\typesystem#1{%
    \begingroup\expandarg
    \baselineskip=1.5\baselineskip% 1.5 to enlarge vertical space between lines
    \StrSubstitute{\noexpand#1}+{&+&}[\tempsystem]%
    \StrSubstitute\tempsystem={&=&}[\tempsystem]%
    \StrSubstitute\tempsystem,{\noexpand\cr}[\tempsystem]%
    \vcenter{\halign{&$\hfil\strut##$&${}##{}$\cr\tempsystem\crcr}}%
    \endgroup
}

\begin{document}

\begin{align*}
    \left\{\typesystem{3x + 2y = 1, x - 3y = 2}\right.
\end{align*}

\end{document}

It yields:

! Argument of \@xs@next has an extra }.
<inserted text> 
                \par 
l.20 \end{align*}

My situation in which each system is where it's desired but the coefficients inside them are not aligned (using align* and cases):

enter image description here

2
  • welcome to tex.sx. i'm a bit puzzled as to what, exactly, you would like to be lined up. is it that (for example) all the "case braces" on the right-hand side should be in line vertically, or that all instances of x_1 on the left side should end at the same horizontal point (and similarly within the cases on the right-hand side), or a combination of all these things? or something else? i'm thinking that alignat* might be more appropriate here, at least with regard to the three cases on the right-hand side. Aug 12, 2016 at 15:44
  • @barbarabeeton thanks! Ideally, I would like everything lined up - the arrows having all the same length, the case braces in line vertically and all instances of the variables (even when they are missing) to end at the same horizontal point. But if only the last one is achievable (or at least without much manual whitespace tweaking), that's fine for me. I'll have to write lots of systems, some of them with dots and non-numeric coefficients, so efficiency comes first here. Aug 12, 2016 at 15:51

2 Answers 2

3

I'd stay with systeme as the code for \typesystem is very faulty.

Anyway, an additional pair of braces will do:

\documentclass{article}
\usepackage{amsmath,xstring}

\newcommand\typesystem[1]{%
    \begingroup\expandarg
    \linespread{1.5}\selectfont
    \StrSubstitute{\noexpand#1}+{&+&}[\tempsystem]%
    \StrSubstitute\tempsystem-{&-&}[\tempsystem]%
    \StrSubstitute\tempsystem={&=&}[\tempsystem]%
    \StrSubstitute\tempsystem{\noexpand\missing}{{}&&}[\tempsystem]%
    \StrSubstitute\tempsystem,{\noexpand\cr}[\tempsystem]%
    \left\{\vcenter{\halign{&$\hfil\strut##$&${}##{}$\cr\tempsystem\crcr}}\right.%
    \endgroup
}
\newcommand\minus{{-}}
\newcommand{\missing}{}

\begin{document}
\begin{alignat*}{2}
{\typesystem{
  2x_1 - x_2 - x_3 = 1,
  4x_1 - 3x_2 + x_3 = 0,
  \minus x_1 + x_2 + 2x_3 = \minus2
}}
&& {}\xrightarrow{L_2\rightarrow L_2 - 2L_1}{}
&{\typesystem{
  2x_1 - x_2 - x_3 = 1,
{} - x_2 + 3x_3 = \minus2,
  \minus x_1 + x_2 + 2x_3 = \minus2
}}
\\
&& {}\xrightarrow{L_1\leftrightarrow L_3}{}
&{\typesystem{
  \minus x_1 +x_2 +2x_3 = \minus2,
{} - x_2 +3x_3 = \minus2,
  2x_1 -x_2 -x_3 = 1
}}
\\
&& {}\xrightarrow{L_3\rightarrow L_3 + 2L_1}{}
&{\typesystem{
  \minus x_1 +x_2 +2x_3 = \minus2,
{}  - x_2 +3x_3 = \minus2,
\missing  x_2 +3x_3 = \minus3
}}
\end{alignat*}

\end{document}

enter image description here

With systeme:

\documentclass{article}
\usepackage{amsmath,systeme}

\begin{document}
\begin{alignat*}{2}
\systeme{
  2x_1 - x_2 - x_3 = 1,
  4x_1 - 3x_2 + x_3 = 0,
  -x_1 + x_2 + 2x_3 = -2
}
&& {}\xrightarrow{L_2\rightarrow L_2 - 2L_1}{}
&\systeme{
  2x_1 - x_2 - x_3 = 1,
  -x_2 + 3x_3 = -2,
  -x_1 + x_2 + 2x_3 = -2
}
\\
&& {}\xrightarrow{L_1\leftrightarrow L_3}{}
&\systeme{
  -x_1 +x_2 +2x_3 = -2,
  -x_2 +3x_3 = -2,
  2x_1 -x_2 -x_3 = 1
}
\\
&& {}\xrightarrow{L_3\rightarrow L_3 + 2L_1}{}
&\systeme{
  -x_1 +x_2 +2x_3 = -2,
  -x_2 +3x_3 = -2,
  x_2 +3x_3 = -3
}
\end{alignat*}

\end{document}

enter image description here

5
  • it is probably overkill, but wouldn't phantom minus signs be appropriate in the right-hand side for the non-negative equalities? Aug 12, 2016 at 19:25
  • @barbarabeeton I think that \typesystem is inadequate anyway, so I didn't bother too much. A better definition of \minus is \newcommand{\minus}{{-}}, which I edited in.
    – egreg
    Aug 12, 2016 at 19:26
  • uh, i was actually referring to the example with \systeme, since you had explicitly deprecated \typesystem. (i did read your explanations.) Aug 12, 2016 at 19:43
  • @barbarabeeton Oh, I misread your comment. There's an answer of mine for getting right alignment in the right-hand side: tex.stackexchange.com/a/247078/4427
    – egreg
    Aug 12, 2016 at 20:00
  • that's a nice one! mention it in your answer. Aug 12, 2016 at 20:08
2

Here is a tabstackengine alternative for presenting systems of equations. However, because we are using a space as the term separator, the syntax is rigid and one cannot freely throw in stray blank spaces. In general, things to remember are:

  1. if one wants the operators (+, -, =) to line up, then they can not attached to either term (i.e., must form their own column); If right alignment of the terms is all that is required, without operator alignment, then operators can be placed next to leading or trailing terms as long as you are consistent in the syntax across all equations of the system;

  2. {} is used as a placeholder for an empty term;

  3. In order to achieve this syntax, leading minus signs will be treated as a binary operation, unless presented as {-};

  4. stray spaces are a no-no, including leading and trailing spaces, as well as those surrounding the comma , equation separator.

Here is the MWE.

In response to barbara's comment, here is what the result looks like if I group the leading minus signs as {-} instead of -, to prevent them from being treated as binary operators. Additionally, to show flexibility of the solution, the inter-line baselineskip can be set in the preamble, e.g., \setstackgap{L}{1.2\normalbaselineskip}

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabstackengine}
\def\typesystem#1#2{\savestack{#1}{\setstackEOL{,}\setstackTAB{ }
  $\left\{\ensurestackMath{\tabbedCenterstack[r]{#2}}\right.$}}
\TABbinary
\stackMath
\setstackgap{S}{12pt}
\setstackgap{L}{1.2\normalbaselineskip}
\begin{document}
\typesystem{\systemA}{2x_1  - x_2  - x_3  =    1,4x_1 - 3x_2 +  x_3 =    0,{-}x_1 + x_2 + 2x_3 = {-2}}
\typesystem{\systemB}{2x_1  - x_2  - x_3  =    1,{}   - x_2  + 3x_3 = {-}2,{-}x_1 + x_2 + 2x_3 = {-2}}
\typesystem{\systemC}{{-}x_1 + x_2 + 2x_3 = {-2},{}   - x_2  + 3x_3 = {-}2,2x_1   - x_2 - x_3  =  1}
\typesystem{\systemD}{{-}x_1 +x_2  +2x_3  = {-2},{}   -x_2   +3x_3  = {-}2,{} x_2 +3x_3        = {-3}}
\typesystem{\systemE}{{-}x_1 +x_2  +2x_3  = {-2},{}   -x_2   +3x_3  = {-}2,{} {}  +6x_3        = {-5}}

\systemA\quad
\alignShortunderstack{%
  \xrightarrow{L_2\rightarrow L_2 - 2L_1}&\systemB\\
  \xrightarrow{L_1\leftrightarrow L_3}&\systemC\\
  \xrightarrow{L_3\rightarrow L_3 + 2L_1}&\systemD\\
  \xrightarrow{L_3\rightarrow L_3 + L_2}&\systemE
}
\end{document}

enter image description here

10
  • Thanks for the suggestion! I gave it a try, and it also works fine with dots (vdots included). I couldn't make it work straight away with non-numerical coefficients, but I'll lookup it's documentation to see what may be done. Aug 12, 2016 at 16:35
  • @HenriqueAugustoSouza Since I am the package author, I would be happy to look further, if I can understand the requirements better. Aug 12, 2016 at 17:00
  • @HenriqueAugustoSouza Please see my revision. Aug 12, 2016 at 17:07
  • small quibble ... the space between the braces and what follows looks too "generous" to me. Aug 12, 2016 at 17:42
  • @barbarabeeton As I said in my answer (point 3), leading minus signs are treated as binary, unless grouped separately as {-}. See addendum. Aug 12, 2016 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .