You cannot create a new lstlisting
environment via \newenvironment
. You need to use \lstnewenvironment
. See the listings
documentation, section 4.5 Environments (p 42).
\documentclass{article}
\usepackage{listings,xcolor}
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{turqusnumbers}{rgb}{0.17,0.57,0.69}
\definecolor{redstrings}{rgb}{0.5,0,0}
\lstdefinelanguage{FSharp}
{morekeywords={let, new, match, with, rec, open, module, namespace, type, of, member, and, for, in, do, begin, end, fun, function, try, mutable, if, then, else},
keywordstyle=\color{bluekeywords},
sensitive=false,
morecomment=[l][\color{greencomments}]{///},
morecomment=[l][\color{greencomments}]{//},
morecomment=[s][\color{greencomments}]{{(*}{*)}},
morestring=[b]",
stringstyle=\color{redstrings}
}
\lstnewenvironment{fslisting}
{
\lstset{
language=FSharp,
basicstyle=\ttfamily,
breaklines=true,
columns=fullflexible}
}
{
}
\begin{document}
\begin{fslisting}
type 'a Process = 'a Signal IObservable
\end{fslisting}
\end{document}
I'm not sure why but you can't use \begin{align}
and \end{align}
in the definition of a new environment; you have to use the "lower-level" macros \align
and \endalign
instead. Edit: as pointed by alexwlchan in his comment, you can find more details about that in section 6 of Technical notes on the amsmath
package.
Here I've used the equivalent of an align*
environment (see Herbert's answer to Define a custom align, and align* environment).
Note that you will get an error if you try to reset your grammarcounter
at each chapter in the article
class, because the latter doesn't have chapters; \section
is the most high-level sectioning command in the article
class. Did you mean
\numberwithin{grammarcounter}{section}
instead?
\documentclass{article}
\usepackage{amsmath}
\newcounter{grammarcounter}[section]
\makeatletter
\newenvironment{grammar}
{%
\refstepcounter{grammarcounter}
\start@align\@ne\st@rredtrue\m@ne
\tag{$\Gamma_{\thegrammarcounter}$}
}{%
\endalign
}
\makeatother
\begin{document}
\section{Foo}
\begin{grammar}
\label{gr:label}
E &::= E + E \\
E &::= a \\
E &::= b
\end{grammar}
\begin{grammar}
\label{gr:label2}
E &::= E + E \\
E &::= a \\
E &::= b
\end{grammar}
\end{document}
Best Answer
One purpose of organizing an environment in that way is to allow flexibility in the input.
You don't need to define the commands inside the environment; a frequently used strategy is the following:
In this way the order one specifies the data in the environment is irrelevant. Let's see a couple of examples
Of course you have to adjust the definition of
cvsection
to suit your needs.