1

Even though I have not detected the side effect, I am still worrying I might do a bad practice here.

Is there a hidden side effect when doing the following?

\documentclass[cmyk]{article}
\usepackage{xcolor}
\usepackage{listings}

\lstdefinestyle{Common}
{       
    language={[LaTeX]TeX},
    linewidth=0.5\linewidth%
}


\lstdefinestyle{A}
{
    style=Common,
  backgroundcolor=\color{yellow!50}%      
}

\lstdefinestyle{B}
{
    style=Common,
  backgroundcolor=\color{green!50}%   
}

\begin{document}

\begin{lstlisting}[style=A]
This is \fbox{style A}.
\end{lstlisting}

\begin{lstlisting}[style=B]
This is \fbox{style B}.
\end{lstlisting}

\end{document}
1

You can use keywords several times in one definition, the last one in the series is only valid. However, I do not think that your way is a good practice ...

  • Why do you think it is not a good practice? My book explains LaTeX, PSTricks, and C#. They use some common attributes so I put the common attributes into a single style called Common. Each also has a set of unique attributes, so I define a separate style for it. – xport Jan 13 '11 at 10:59
  • @xport: I meant that it is a better practice to define new styles without using the keyword style itself in this new definition. But this is apersonal decision, no more no less – user2478 Jan 13 '11 at 11:15
  • OK. Thanks. If there is no bad effect, I will insist on using it. :-) – xport Jan 13 '11 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.