# Modify locally the “array” environment for Equation Systems

When I started to use LyX 2.0.6 I noticed that when an Equation System is needed, there are two options available to typeset it: using the appropriate command on the Math Line cases,

or manually defining a left aligned matrix (array envir. in LaTeX code) delimited by a left curly brace,

The result on the PDF is obivously different for the horizontal spacing because the first system thends to shifted on the left to compensate the space left blank by the second argument; but for the second method, the result is a simple centered system delimited by a half-mile-away braket. (Sorry if I couldn't show you the driect output).

Here is the basic MWE as the file is exported into normal LaTeX:

\documentclass{article}
%
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
%
\begin{document}
%
Cases environment:
$\begin{cases} x^{n}+y^{n}=z^{n}\\ x^{m}+y^{m}=z^{m} \end{cases}$
\par
Defined array environment:
$\left\{% \begin{array}{l} x^{n}+y^{n}=z^{n}\\ x^{m}+y^{m}=z^{m} \end{array}% \right.$
Only array environment:
$\begin{array}{ccc} a & b & c \\ a & b & c \\ a & b & c \\ a & b & c \end{array}$
%
\end{document}


Since I want to use only the second method, to correct the position of the left braket I added this lines to the preamble:

\usepackage{etoolbox}
\AtBeginEnvironment{array}{%    % this isn't applied to "matrices" and "cases"
\addtolength{\arraycolsep}{-3.5pt}
\renewcommand{\arraystretch}{1.1}%
}


And this works fine for my purposes, but I want to use the array environment apart from this case, and as I do, the columns in the third example in the MWE result shrinked (the code I put works even if there isn't any equation system).

So in a document where the array is needed for both purposes, it works well for system but not alone by itself.

Then my question is: Is there any macro/formatting trickery that permits to have the array environment following my code only if the character before is \left{?

As I noticed, this behaviour would be similar to the function of \@ifnextchar, because if the next character is \left{ then my code would apply, and otherwise don't, like this:

\usepackage{etoolbox}
\BeforeBeginEnvironment{array}{%
% if "\left\{" inserted do A, otherwise B
}


## 2 Answers

You want to avoid the \tabcolsep altogether; note also the correction for the null delimiter. You can use an optional argument to enlarge the leading in special cases.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}

\newenvironment{system}[1][1.1]
{\renewcommand{\arraystretch}{#1}
\left\{\begin{array}{@{}l@{}}}
{\end{array}\right.\kern-\nulldelimiterspace}

\begin{document}
A centered formula for showing the center:
$\int_{-\infty}^{\infty}e^{-x^2}\,dx=\sqrt{\pi}$
The new \texttt{system} environment:
$\begin{system} x^{n}+y^{n}=z^{n}\\ x^{m}+y^{m}=z^{m} \end{system}$
Predefined \texttt{array} environment:
$\left\{% \begin{array}{l} x^{n}+y^{n}=z^{n}\\ x^{m}+y^{m}=z^{m} \end{array}% \right.$
A \texttt{system} environment with the optional argument:
$\begin{system}[1.5] x^{n}+y^{n}=z^{n}\\ x^{m}+y^{m}=z^{m} \end{system}$
\end{document}


• Well, clearly a grazie for the spacing correction, as I'll totally have to use later in my dissertation; but I'd like to know in the first place if there is some macro that can be inserted inside the LyX preamble to obtain two behaviours of array – TheVal Sep 12 '13 at 21:11
• @AndreaL. Just don't use LyX, why should you? My feeling is that it makes things more complicated, rather than easier. – egreg Sep 12 '13 at 21:12
• As I thought initially, I began to familiarize with pure LaTeX (as the many examples posted worked out only without LyX), but I'd say I chose it as nothing more than a front-end. – TheVal Sep 12 '13 at 21:13
• @AndreaL. I don't understand what you're trying to do; define two different environments: distinct objects need distinct markup. – egreg Sep 13 '13 at 9:42
• What I'm trying to do is define a command that inside the \BeforeBeginEnvironment of array reads if there is a \left\{ or not: if yes it does apply my modifications to arraycolsep, if not it does nothing. Is it now a bit clearer? – TheVal Sep 13 '13 at 9:47

## The cases environment

This is one solution that after this time came to my mind, so I'll be able to use LyX with the cases environment defined as the more advanced dcases by re-defining cases using mathtools:

\documentclass{article}
%
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
%
\usepackage{mathtools}
\renewenvironment{cases}{%
\begin{dcases}%
}{%
\end{dcases}%\kern-\nulldelimiterspace%
}
%
\begin{document}
A centered formula for showing the center:
$\int_{-\infty}^{\infty}e^{-x^2}\,dx=\sqrt{\pi}$
The new defined \texttt{cases} environment:
$\begin{cases} \int x^{n}+y^{n}=z^{n}\\ x^{m}+y^{m}=z^{m} \end{cases}$
Second method for \texttt{array} environment:
$\left\{% \begin{array}{l} \int x^{n}+y^{n}=z^{n}\\ x^{m}+y^{m}=z^{m} \end{array}% \right.$
%
\end{document}


The only thing that keeps me from inserting this lines inside my package LyXbasic is if this code does make some messing up with other math declarations.

So when inside LyX is typed this:

The output is as follows:

The difference in typesetting can be easily observed by a great improvement not only inside the pure LaTeX code but also "below" the command inside LyX.

## The array environment

In order to modify correctly the array environment it has to be added this lines of code before the single environment:

\BeforeBeginEnvironment{array}{%
\let\{\lbrace%
\hskip-\arraycolsep%
}
\AfterEndEnvironment{array}{%
\kern-\nulldelimiterspace%
}


So if the single MWE is being added there will be a behaviour similar to @{}l using \hskip-\arraycolsep

$\left\{ \begin{array}{l} x^n+y^n=z^n \\ x^m+y^m=z^m \end{array} \right.$
$\begin{array}{ccc} a & b & c \\ a & b & c \\ a & b & c \\ a & b & c \end{array}$


The output is as follows:

So now the common arraycolsep is not changed over the columns, but only aside the left delimiter.