Here is how you can add an optional argument to you \SysOfEq
command:

\documentclass[10pt,a4paper]{article}
\usepackage{systeme}% http://ctan.org/pkg/systeme
\makeatletter
\def\SYS@makesyspreamble@i#1{%
\ifnum#1<\SYS@preamblenum
\SYS@addtotok\SYS@systempreamble{\hfil$##$&\hfil$##$&}%
\expandafter\SYS@makesyspreamble@i\expandafter{\number\numexpr#1+ \@ne\expandafter}%
\else
\SYS@addtotok\SYS@systempreamble{\hfil$##$&$##$&\hfil$##$\null}%
\ifSYS@extracol
\SYS@addtotok\SYS@systempreamble{&\SYS@extracolstart##\SYS@extracolend \hfil\null}%
\fi
\SYS@addtotok\SYS@systempreamble{\cr\SYS@strutup}%
\fi
}
\makeatother
\begin{document}
\newcommand*{\SysOfEq}[2][0pt]{
\syslineskipcoeff{1.2}\setlength{\tabskip}{\dimexpr3pt+#1\relax}
\systeme{#2}}
\[
\syslineskipcoeff{1.2}\setlength{\tabskip}{3pt}
\systeme{
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
\[
\SysOfEq{%
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
\[
\SysOfEq[1cm]{%
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
\end{document}
This allows for a single optional argument that has a default spacing of 3pt
(if not specified) or "3pt
+ input" if it is specified.
A little background on \newcommand
, which was used to produce \SysOfEq
:
\newcommand{<cmd>}[<nargs>][<opt>]{<definition>}
<cmd>
is the command that you want to define. This should be undefined at the time you call \newcommand
, otherwise you will receive a
LaTeX Error: Command \SysOfEq
already defined.
error (here I tried to define \SysOfEq
and it was already defined). In those cases, you need to use \renewcommand
(or \providecommand
in LaTeX2e) with the same argument definitions. <nargs>
refers to the number of arguments <cmd>
should take. This can be anything from 1 to 9. Note that this specification is optional, so you can create a command that takes 0 arguments if you leave out <nargs>
. If you did specify <nargs>
, then you can specify <opt>
(again optional, so it's not necessary). Whatever you specify in <opt>
will be the default value to the first argument which is necessarily optional. This first argument will be referred to in <definition>
as #1
, while subsequent (mandatory) arguments will be referred to as #2
...#9
or however many you specified in <nargs>
.
From the above discussion you can see that wherever I refer to #1
, it means the optional argument that you specify. Wherever I refer to #2
, it implies what I specify after that - in this case you system of equations.
Using \newcommand
in this way is the standard way to define commands (or control sequences) in LaTeX and it allows for a single optional argument. If you want a more advanced way of defining commands (including intermixed optional/mandatory arguments), you can use the interface provided by xparse
- see @Gonzalo's answer for this.
When writing a macro that has many possible modifications to it, optional arguments are always great, since you can use them at your leisure. However, without knowing what the argument order is and which ones are optional/mandatory, it could be difficult to maintain. Symbolic references to options is a better option when it comes to this. As such, a key-value pair approach would work well. To this end, consider reading How to create a command with key values?
Here is a view on such an approach:

\documentclass[10pt,a4paper]{article}
\usepackage{keyval}% http://ctan.org/pkg/keyval
\usepackage{systeme}% http://ctan.org/pkg/systeme
\makeatletter
\def\SYS@makesyspreamble@i#1{%
\ifnum#1<\SYS@preamblenum
\SYS@addtotok\SYS@systempreamble{\hfil$##$&\hfil$##$&}%
\expandafter\SYS@makesyspreamble@i\expandafter{\number\numexpr#1+ \@ne\expandafter}%
\else
\SYS@addtotok\SYS@systempreamble{\hfil$##$&$##$&\hfil$##$\null}%
\ifSYS@extracol
\SYS@addtotok\SYS@systempreamble{&\SYS@extracolstart##\SYS@extracolend \hfil\null}%
\fi
\SYS@addtotok\SYS@systempreamble{\cr\SYS@strutup}%
\fi
}
% ========= KEY DEFINITIONS =========
\newlength{\sys@width}%
\define@key{systeme}{vskip}{\def\sys@vskip{#1}}
\define@key{systeme}{width}{\setlength{\sys@width}{#1}}
% ========= KEY DEFAULTS =========
\setkeys{systeme}{vskip=1.2,width=0pt}%
\newcommand*{\SysOfEq}[2][,]{%
\setkeys{systeme}{#1}% Set new keys
\syslineskipcoeff{\sys@vskip}\setlength{\tabskip}{\dimexpr3pt+\sys@width\relax}% Use keys
\systeme{#2}}% Typeset system
\makeatother
\begin{document}
\[
\syslineskipcoeff{1.2}\setlength{\tabskip}{3pt}
\systeme{
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
\[
\SysOfEq{%
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
\[
\SysOfEq[width=1cm]{%
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
\[
\SysOfEq[width=5pt,vskip=2]{%
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
\end{document}
The key-value definitions are provided by the keyval
package.
When TeX reads arguments, then TeX only checks for matching curly braces (characters with catcode 1 and 2). Square brackets are not special in this sense. The first ]
that is not hidden inside curly braces is taken as the end of the optional argument. Therefore an additional set of braces is the usual solution:
\foo[{\bar[...]}]{...}
It is only a bug, if this does not work, e.g. if the definition passes optional arguments to other commands:
\def\foo#1#2{\bar[#1]{#2}}
This should be
\def\foo#1#2{\bar[{#1}]{#2}}
Then #1
may contain square brackets, especially ]
.
Best Answer
EDIT: TH.'s answer is much simpler. The one below should depend less on the details of the implementation of
\VerbatimEnvironment
, but that's the only good thing about it.I propose the following code. The idea is to make a new environment (which I called
Row
, renaming the oldRow
tooldRow
) check for an optional argument "by hand", and write the relevant thing to a file. Then the file (\jobname.row
) is read so thatfancyvrb
can happily set the relevant catcodes.All this can probably be done using
\scantokens
, but I am still quite confused about newlines inside\scantokens
.I also added
*#1*
to your definition of the environment: this way, we can check what is going on with the optional argument.