[comp.text] Typesetting programming languages in LaTeX

spqr@ecs.soton.ac.uk (Sebastian Rahtz) (02/21/90)

>>>>> On 20 Feb 90 02:03:14 GMT, barrett@jhunix.HCF.JHU.EDU (Dan Barrett) said:

 > 	For the computer programming courses I teach, I make a lot of
 > handouts that contain code in C, Pascal, LISP, etc.  I would like to
 > have a nice way to typeset these languages in LaTeX.

 > 	The major problems are:

 > 	o	Not interpreting symbols of the language as LaTeX symbols;
 > 	o	Handling TAB's.

 > For the time being, I use the "verbatim" environment.  However, it doesn't
 > understand TAB characters; I have to substitute 8 space characters for
 > my TAB's (and this isn't always correct).
well, a few random points strike me:
 a) there is often a `detabbing' program on Unix systems which
    resolves TAB characters into appropriate places
 b) where do you stand on code being in typewriter font? if you are
    not wedded to that, have you tried the `trgind' system of
    prettifying code?
 c) if you don't need / { and } in your code (!), you could use the
    `alltt' environment
 d) note sure what you mean by
 > 	o	Not interpreting symbols of the language as LaTeX symbols;
    if you can do what you want with a verbatim environment which
    permits an escape character to get TeX symbols, then I can supply
    one

there are many other thoughts, of course. but mainly dependent on the
answer to b) above
--
Sebastian Rahtz                        S.Rahtz@uk.ac.soton.ecs (JANET)
Computer Science                       S.Rahtz@ecs.soton.ac.uk (Bitnet)
Southampton S09 5NH, UK                S.Rahtz@sot-ecs.uucp    (uucp)

shaig@shum.huji.ac.il (Shai Guday) (02/27/90)

In article <4285@jhunix.HCF.JHU.EDU> barrett@jhunix.HCF.JHU.EDU (Dan Barrett) wr
ites:
%
% For the computer programming courses I teach, I make a lot of
%handouts that contain code in C, Pascal, LISP, etc.  I would like to
%have a nice way to typeset these languages in LaTeX.

One solution that might be appropriate for a full page of code
is to use one of the code printing programs such as vgrind, cprint,
or pps. This would be best in those cases where the code segment of
the handout does not need further LaTeX text but can be "standalone".

If the code should be embedded in LaTeX then I am currently working
on a "C" program using lex to parse "C" code, set special words
in boldface, and numbers to italics. The LaTeX .sty file for the
above is already complete.

% The major problems are:
%
% o Not interpreting symbols of the language as LaTeX symbols;

The reason for the use of lex.

% o Handling TAB's.
%
%For the time being, I use the "verbatim" environment.  However, it doesn't
%understand TAB characters; I have to substitute 8 space characters for
%my TAB's (and this isn't always correct).

You must understand that LaTeX does not use, by default, fixed width fonts.
A series of spaces following word might terminate farther right than
the same series following another word.

To get around this, I am using a "pre-tabbed" environment for my code
segments which allows me to tab easily.

%I would appreciate suggestions.  SOMEBODY else must be doing this better.

% //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
%  Dan Barrett, Department of Computer Science      Johns Hopkins University
%  INTERNET:   barrett@cs.jhu.edu
%  COMPUSERVE: >internet:barrett@cs.jhu.edu   UUCP:   barrett@jhunix.UUCP
% \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////////////////