summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-codelist.html
blob: a46e27bda885eea550b37097152a372e5a40bca6 (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
85
86
87
88
89
90
91
92
93
94
<head>
<title>UK TeX FAQ -- question label codelist</title>
</head><body>
<h3>Code listings in LaTeX</h3>
<p/>&#8216;Pretty&#8217; code listings are sometimes considered worthwhile by the
&#8220;ordinary&#8221; 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 &#60;stdio.h&#62;

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&#8217;s vocabulary
than just <i>C</i>&#8230;
<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>minted</i> package is a relatively recent addition.  It
requires that documents be pre-processed using an external
(<i>python</i>) script,
<a href="http://pygments.org/"><i>Pygments</a></i>.
<i>Pygments</i>, in turn, needs a &#8220;lexer&#8221; that knows the
language you want to process; lots of these are available, for the
more commonly-used languages, and there is advice on &#8220;rolling your
own&#8221; on the 
&#60;a href=&#8217;http://pygments.org/docs/lexerdevelopment/&#8217;&#62;<i>Pygments</i> site&#60;/a&#62;
<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&#8217;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 &#8220;self-documenting&#8221;.
<dl>
<dt><tt><i>c2latex</i></tt><dd><a href="http://mirror.ctan.org/support/c2latex.zip">support/c2latex</a> (or <a href="http://mirror.ctan.org/support/c2latex/">browse the directory</a>)
<dt><tt><i>C++2LaTeX</i></tt><dd><a href="http://mirror.ctan.org/support/C++2LaTeX-1_1pl1.zip">support/C++2LaTeX-1_1pl1</a> (or <a href="http://mirror.ctan.org/support/C++2LaTeX-1_1pl1/">browse the directory</a>)
<dt><tt><i>highlight</i></tt><dd><a href="http://mirror.ctan.org/support/highlight.zip">support/highlight</a> (or <a href="http://mirror.ctan.org/support/highlight/">browse the directory</a>)
<dt><tt><i>lgrind</i></tt><dd><a href="http://mirror.ctan.org/support/lgrind.zip">support/lgrind</a> (or <a href="http://mirror.ctan.org/support/lgrind/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/lgrind.html">catalogue entry</a>
<dt><tt><i>listings.sty</i></tt><dd><a href="http://mirror.ctan.org/macros/latex/contrib/listings.zip">macros/latex/contrib/listings</a> (or <a href="http://mirror.ctan.org/macros/latex/contrib/listings/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/listings.html">catalogue entry</a>
<dt><tt><i>minted.sty</i></tt><dd><a href="http://mirror.ctan.org/macros/latex/contrib/minted.zip">macros/latex/contrib/minted</a> (or <a href="http://mirror.ctan.org/macros/latex/contrib/minted/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/minted.html">catalogue entry</a>
<dt><tt><i>tgrind</i></tt><dd><a href="http://mirror.ctan.org/support/tgrind.zip">support/tgrind</a> (or <a href="http://mirror.ctan.org/support/tgrind/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/tgrind.html">catalogue entry</a>
<dt><tt><i>tiny_c2l</i></tt><dd><a href="http://mirror.ctan.org/support/tiny_c2l.zip">support/tiny_c2l</a> (or <a href="http://mirror.ctan.org/support/tiny_c2l/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/tinyc2l.html">catalogue entry</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>