Screenshot

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},
commentstyle=\color{Green}%
}
}
\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},
commentstyle=\color{Green}%
}
}
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},
commentstyle=\color{Green}%
}
}
\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},
commentstyle=\color{Green}%
}
}
\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{}. For electronic version I like using many colors. But for printed version, I will reduce the number of colors later. – Display Name Jan 10 '11 at 10:49\lstinputlisting[style={styleA,styleB}]{}? – Display Name Jan 10 '11 at 13:52\lstinputlisting[style=common,style=styleB]{}and it works. :-) – Display Name Jan 10 '11 at 16:04[tabsize=4cm,tabsize=2cm], the values are overwritten – Jan 10 '11 at 16:12