[OS X TeX] Colored words
Aaron Jackson
jackson at msrce.howard.edu
Tue Feb 22 01:21:52 CET 2005
On Feb 21, 2005, at 5:03 PM, Alain Schremmer wrote:
> Aaron Jackson wrote:
>
>> Strange.
>
> Not strange at all:
> What happened is that when I copy-pasted your code onto a new TeXshop,
> I didn't realize that, somehow, a space had gotten in front of "green"
> and that the console was indeed complaining about ' green'.
> Thus, my fault and I apologize.
>
> I still have a few problems.
>
> - I would rather not have the line numbers since the reader won't see
> them in the file they will create.
Just delete the following lines:
\newlength{\xleftmargin}
\settowidth{\xleftmargin}{\textbf{99999}}% width of 5 digits in the
current font.
\newlength{\numbersep}
\settowidth{\numbersep}{\textbf{99}}% width of 2 digits in the current
font.
and the following from \lstset
numbers=left, stepnumber=1, numberstyle=\normalsize,
numbersep=\numbersep, xleftmargin=\xleftmargin
> - In the listing, $ does not show green.
I don't know how to do that without muching around with latex code.
That is, in order to print out a green $ you would have to do something
like (not complete file and not fully tested):
\newcommand{\green}[1]{\textcolor{green}{#1}}
\usepackage{listings}
\lstloadlanguages{{[latex]TeX}}
\lstset{language={[latex]TeX}, keywordstyle=\color{blue},
texcsstyle=*{\color{blue}}, commentstyle=\color{red},
showstringspaces=false, showspaces=false, showtabs=false,
columns=fullflexible tabsize=4, fontadjust, basewidth=1ex, breaklines,
moretexcs={numbersep,xleftmargin,
color,textcolor,mysyntaxp,mysyntax,lstset,lstloadlanguages,lstinputlisti
ng, lstinline}, escapeinside=`'}%you can change theses characters to
whatever you like.
...
\begin{lstlisting}
`\green{\$}'f(x) = ax^2 +bx +c`\green{\$}'
\textbf`\green{\{}\textsf{test}\green{\}}'
\end{lstlisting}
...
I guess you could also do something like:
\newcommand{\green}[1]{\textcolor{green}{#1}}
\newcommand{\gop}{\green{\{}}
\newcommand{\gcp}{\green{\}}
\newcommand{\gds}{\green{\$}}
\newcommand{\arg}[1]{\gop\textsf{#1}\gcp}
\usepackage{listings}
\lstloadlanguages{{[latex]TeX}}
\lstset{language={[latex]TeX}, keywordstyle=\color{blue},
texcsstyle=*{\color{blue}}, commentstyle=\color{red},
showstringspaces=false, showspaces=false, showtabs=false,
columns=fullflexible tabsize=4, fontadjust, basewidth=1ex, breaklines,
moretexcs={numbersep,xleftmargin,
color,textcolor,mysyntaxp,mysyntax,lstset,lstloadlanguages,lstinputlisti
ng, lstinline}, escapeinside=`'}%you can change theses characters to
whatever you like.
...
\begin{lstlisting}
`\gds'f(x) = ax^2 +bx +c`\gds'
\textbf`\arg{test}'
\end{lstlisting}
...
Which makes it a bit cleaner I guess. However, it kind of defeats the
notion of typesetting real source code...
> - How do I show $f(x) = ax^2 +bx +c$? (Verbatim of course shows $
> in black.)
As a type set formula in a listing or as the latex code inline? For
the former, set mathescape=true in \lstset. For the latter, you can
use \lstinline, i.e.
\lstinline!$f(x) = ax^2 +bx +c$!
Add lstinline to the moretexcs list if you ever want it to be
recognized as a key word.
> Other than that this is fantastic. (Even *{\color{blue}} works.)
Good. I don't think that listings was ever written with this exact use
in mind, but it isn't too far away.
--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
& FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>
More information about the macostex-archives
mailing list