[OS X TeX] Colored words
Aaron Jackson
jackson at msrce.howard.edu
Sun Feb 20 02:27:08 CET 2005
On Feb 19, 2005, at 6:42 PM, Alain Schremmer wrote:
> Maarten Sneep wrote:
>
>> On 20 feb 2005, at 0:09, Alain Schremmer wrote:
>>
>>> I read the documentation which I found indeed better than
>>> Companion2ed.
>>>
>>> The "pretty printing [I] am trying to do" is reproducing TeXShop's
>>> source file. (I finally got hooked by my own petard and had to agree
>>> to write … the intro to LaTeX that I would have liked to have last
>>> year.) For instance, I would like to be able to write stuff like
>>
>>
>> I think it would be easier to use the listings package, which will
>> allow you to pretty print various programming languages, including
>> LaTeX. Adapting it to your needs is easy, and assigning colours to
>> keywords is trivial (it is right there in the documentation).
>> Changing the fonts to helvetica, or whatever is also easy.
>>
>> Oh, and I've set the typeface of TeXShop to Lucida Grandde, but maybe
>> that is something you shouldn't try to replicate.
>>
>> Maarten
>
> Thanks, I will try it but, in Companion2ed, it looks forbidding. I
> will get the documentation.
If it helps, the following is a minimum example of what I use to print
out C code. It sets the left margin to be 5 digits wide and then uses
three digits worth for line numbers, which appear on every line, and a
two digit space before the code line. This means that I can only have
a 999 line listing with these settings.
You most likely only need to change the C references to tex, or
something similar, in order to use it as is. Then just tweek until you
get what you want...
Aaron
P.S. helloworld.c not included.
\documentclass[11pt]{article}
%%
%% For computer code listings
%%
\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.
%%
\usepackage{listings}
\lstloadlanguages{C}
\lstset{language=C, basicstyle=\normalsize,
keywordstyle=\slshape\bfseries, commentstyle=\itshape,
stringstyle=\ttfamily, showstringspaces=false, showspaces=false,
showtabs=false, columns=fullflexible, numbers=left, stepnumber=1,
numberstyle=\normalsize, numbersep=\numbersep,
xleftmargin=\xleftmargin, tabsize=4, fontadjust, basewidth=1ex,
breaklines}
\begin{document}
\lstinputlisting{helloworld.c}
\end{document}
--------------------- 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