[Tex/LaTex] Modify locally the “array” environment for Equation Systems

arraysenvironmentslyxmath-modespacing

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,

enter image description here

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

enter image description here

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
}

Best Answer

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}

enter image description here