summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-codelist.html
blob: 3c949593ab1f615593673557355e164f6b23dea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<head>
<title>UK TeX FAQ -- question label codelist</title>
</head><body>
<h3>Code listings in LaTeX</h3>
<p/>&lsquo;Pretty&rsquo; code listings are sometimes considered worthwhile by the
&ldquo;ordinary&rdquo; programmer, but they have a serious place in
the typesetting of dissertations by computer science and other
students who are expected to write programs.  Simple verbatim listings
of programs are commonly useful, as well.
<p/>  <a href="FAQ-verbfile.html">Verbatim listings</a> are dealt with elsewhere,

as is the problem of 
<a href="FAQ-algorithms.html">typesetting algorithm specifications</a>.
<p/>The <i>listings</i> package is widely regarded as the best bet for
formatted output (it is capable of parsing program source, within the
package itself), but there are several well-established packages that
rely on a pre-compiler of some sort.  You may use <i>listings</i>
to typeset snippets that you include within your source:
<blockquote>
<pre>
\usepackage{listings}
\lstset{language=C}
...
\begin{document}
\begin{lstlisting}
#include &lt;stdio.h&gt;

int main(int argc, char ** argv)
{
  printf("Hello world!\n");
  return 0;
}
\end{lstlisting}
\end{document}
</pre>
</blockquote><p>
or you can have it typeset whole files:
<blockquote>
<pre>
\usepackage{listings}
\lstset{language=C}
...
\begin{document}
\lstinputlisting{main.c}
\end{document}
</pre>
</blockquote><p>
These very simple examples may be decorated in a huge variety of ways,
and of course there are other languages in the package&rsquo;s vocabulary
than just <i>C</i>...
<p/>Most people, advising others on (La)TeX lists, seem to regard
<i>listings</i> as the be-all and end-all on this topic.  But there
<em>are</em> alternatives, which may be worth considering, in some
situations.
<p/><i>Highlight</i> is attractive if you need more than one output
format for your program: as well as (La)TeX output,
<i>highlight</i> will produce (X)HTML, RTF
and XSL-FO representations of your program listing.
Documentation is available on the 
<a href="http://www.andre-simon.de/"><i>highlight</a> project site</i>.
<p/>The <i>lgrind</i> system is another well-established pre-compiler,
with all the facilities one might need and a wide repertoire of
languages; it is derived from the very long-established
<i>tgrind</i>, whose output is based on Plain TeX
<p/>The <i>tiny_c2l</i> system is more recent: users are encouraged to
generate their own driver files for languages it doesn&rsquo;t already deal
with.
<p/>The <i>C++2LaTeX</i> system comes with strong recommendations for
use with C and C++.
<p/>An extremely simple system is <i>c2latex</i>, for which you write
LaTeX source in your C program comments.  The program then
converts your program into a LaTeX document for processing.  The
program (implicitly) claims to be &ldquo;self-documenting&rdquo;.
<dl>
<dt><tt><i>c2latex</i></tt><dd><a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/c2latex.zip">support/c2latex</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/c2latex/">browse the directory</a>)
<dt><tt><i>C++2LaTeX</i></tt><dd><a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/C++2LaTeX-1_1pl1.zip">support/C++2LaTeX-1_1pl1</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/C++2LaTeX-1_1pl1/">browse the directory</a>)
<dt><tt><i>highlight</i></tt><dd><a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/highlight.zip">support/highlight</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/highlight/">browse the directory</a>)
<dt><tt><i>lgrind</i></tt><dd><a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/lgrind.zip">support/lgrind</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/lgrind/">browse the directory</a>)
<dt><tt><i>listings.sty</i></tt><dd><a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/macros/latex/contrib/listings.zip">macros/latex/contrib/listings</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/macros/latex/contrib/listings/">browse the directory</a>)
<dt><tt><i>tgrind</i></tt><dd><a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/tgrind.zip">support/tgrind</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/tgrind/">browse the directory</a>)
<dt><tt><i>tiny_c2l</i></tt><dd><a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/tiny_c2l.zip">support/tiny_c2l</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/support/tiny_c2l/">browse the directory</a>)
</dl>
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=codelist">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=codelist</a>
</body>