How can I define a custom listing environment?
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}
Just use the provided \lstnewenvironment
command.
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\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}