# Scenario

I want to define two sets of settings for \lstinputlisting--One setting for CSharp A and the other one for CSharp B. They are different only in the color settings.

\def\CSharpSettingsA%
{%
\lstset%
{%
language={[Sharp]C},
literate={ï}{}0{»}{}0{¿}{}0,
backgroundcolor=\color{White},
basicstyle=\scriptsize\color{Black}\ttfamily,
keywordstyle=\color{Orange},
identifierstyle=\color{Cyan},
stringstyle=\color{Red},
}
}

\def\CSharpSettingsB%
{%
\lstset%
{%
language={[Sharp]C},
literate={ï}{}0{»}{}0{¿}{}0,
backgroundcolor=\color{Black},
basicstyle=\scriptsize\color{White}\ttfamily,
keywordstyle=\color{Orange},
identifierstyle=\color{Cyan},
stringstyle=\color{Red},
}
}


There is a common setting as well.

\lstset%
{%
breaklines=true,
tabsize=2,
showstringspaces=false,
aboveskip=0pt,
belowskip=0pt%
}


NOTE: because each set contains many key-value pairs, it is not good idea to pass those key-value pairs directly to the optional argument of \lstinputlisting.

In the preamble, I define two commands as follows:

\newcommand{\InputCSharpA}[1]{{\CSharpSettingsA\lstinputlisting{#1}}}
\newcommand{\InputCSharpB}[1]{{\CSharpSettingsB\lstinputlisting{#1}}}


And in the document body, I switch between them as follows:

\begin{document}
\InputCSharpA{CSharp/MyCode/Program.cs}

\InputCSharpB{CSharp/MyCode/Program.cs}
\end{document}


# Question

Without defining a newcommand for each setting, is it possible to pass the set of settings to the optional argument of lstinputlisting ?

Such as \lstinputlisting[key=CSharpSettingsA]{} for example.

# Complete Minimal Code

\documentclass[dvipsnames]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{xcolor}

\usepackage{listings}
\lstset%
{%
breaklines=true,
tabsize=2,
showstringspaces=false,
aboveskip=0pt,
belowskip=0pt%
}

\def\CSharpSettingsA%
{%
\lstset%
{%
language={[Sharp]C},
literate={ï}{}0{»}{}0{¿}{}0,
backgroundcolor=\color{White},
basicstyle=\scriptsize\color{Black}\ttfamily,
keywordstyle=\color{Orange},
identifierstyle=\color{Cyan},
stringstyle=\color{Red},
}
}

\def\CSharpSettingsB%
{%
\lstset%
{%
language={[Sharp]C},
literate={ï}{}0{»}{}0{¿}{}0,
backgroundcolor=\color{Black},
basicstyle=\scriptsize\color{White}\ttfamily,
keywordstyle=\color{Orange},
identifierstyle=\color{Cyan},
stringstyle=\color{Red},
}
}

\newcommand{\InputCSharpA}[1]{{\CSharpSettingsA\lstinputlisting{#1}}}
\newcommand{\InputCSharpB}[1]{{\CSharpSettingsB\lstinputlisting{#1}}}

\begin{document}
\InputCSharpA{CSharp/MyCode/Program.cs}

\InputCSharpB{CSharp/MyCode/Program.cs}
\end{document}

-

\lstdefinestyle{styleA}{...}
\begin{lstlisting}[style=styleA]
...
\end{lststyle}


and by the way: if you will make your listings more readable, use less colors ...

-
@Herbert, thanks for informing \lstdefinestyle{}. For electronic version I like using many colors. But for printed version, I will reduce the number of colors later. –  xport Jan 10 '11 at 10:49
@xsport: I were talking about electronic versions when I refer to less colors. –  Herbert Jan 10 '11 at 11:35
@Herbert: Can we use two or more defined styles at the same time such as \lstinputlisting[style={styleA,styleB}]{} ? –  xport Jan 10 '11 at 13:52
@xport: no, not possible –  Herbert Jan 10 '11 at 14:18
@xport: sure, it is the same as [tabsize=4cm,tabsize=2cm], the values are overwritten –  Herbert Jan 10 '11 at 16:12