version 3, including all changes.
.
Rev |
Author |
# |
Line |
2 |
AristotlePagaltzis |
1 |
This is a short worked example on how to write and build a [LaTeX] document. ''Note that this is not a primer on the language!'' You should get hold of the [Not so short Introduction to Latex|http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf] for a more complete introduction. |
1 |
DanielLawson |
2 |
|
2 |
AristotlePagaltzis |
3 |
!! Writing your <tt>.tex</tt> file |
1 |
DanielLawson |
4 |
|
2 |
AristotlePagaltzis |
5 |
Because this is just a trivial example on how to use [LaTeX], not on how to actually write [LaTeX] documents, my example <tt>.tex</tt> file won't contain a lot. [LaTeX] can do plenty more than I'm demonstrating below -- make sure you read the better references mentioned above. |
1 |
DanielLawson |
6 |
|
2 |
AristotlePagaltzis |
7 |
Edit a file called <tt>example.tex</tt>, and put the following text in it: |
1 |
DanielLawson |
8 |
|
2 |
AristotlePagaltzis |
9 |
<verbatim> |
|
|
10 |
\documentclass[12pt,a4paper]{report} |
|
|
11 |
\pagenumbering{roman} |
1 |
DanielLawson |
12 |
|
|
|
13 |
|
2 |
AristotlePagaltzis |
14 |
\title{Latex Example} |
|
|
15 |
\author{Daniel Lawson} |
|
|
16 |
\date{\today} |
1 |
DanielLawson |
17 |
|
2 |
AristotlePagaltzis |
18 |
\begin{document} |
1 |
DanielLawson |
19 |
|
|
|
20 |
|
2 |
AristotlePagaltzis |
21 |
\maketitle |
1 |
DanielLawson |
22 |
|
2 |
AristotlePagaltzis |
23 |
\begin{abstract} |
1 |
DanielLawson |
24 |
|
2 |
AristotlePagaltzis |
25 |
\end{abstract} |
1 |
DanielLawson |
26 |
|
2 |
AristotlePagaltzis |
27 |
\tableofcontents |
1 |
DanielLawson |
28 |
|
2 |
AristotlePagaltzis |
29 |
\newpage |
1 |
DanielLawson |
30 |
|
2 |
AristotlePagaltzis |
31 |
\section{Introduction} |
1 |
DanielLawson |
32 |
|
2 |
AristotlePagaltzis |
33 |
This is a quick introduction to using Latex. |
1 |
DanielLawson |
34 |
|
2 |
AristotlePagaltzis |
35 |
\subsection{Example} |
1 |
DanielLawson |
36 |
|
2 |
AristotlePagaltzis |
37 |
Here is a subsection. |
1 |
DanielLawson |
38 |
|
2 |
AristotlePagaltzis |
39 |
\section{Conclusion} |
1 |
DanielLawson |
40 |
|
2 |
AristotlePagaltzis |
41 |
In conclusion, this example doesn't show a lot. Go read the Not So Short Introduction to \LaTeX for more information. |
1 |
DanielLawson |
42 |
|
2 |
AristotlePagaltzis |
43 |
\end{document} |
|
|
44 |
</verbatim> |
1 |
DanielLawson |
45 |
|
|
|
46 |
!! Building it |
|
|
47 |
|
2 |
AristotlePagaltzis |
48 |
Seeing as we're not doing anything complicated with [LaTeX], we only need to parse the file once. If you were doing more complicated things, such as including a bibliography, you'd need to run a few more programs. See LatexMakefiles on more tips for that. |
1 |
DanielLawson |
49 |
|
2 |
AristotlePagaltzis |
50 |
Run <tt>latex example.tex</tt> in the directory you saved your <tt>example.tex</tt> in earlier. |
1 |
DanielLawson |
51 |
|
|
|
52 |
<verbatim> |
|
|
53 |
$ latex example.tex |
|
|
54 |
This is TeX, Version 3.14159 (Web2C 7.3.7) |
|
|
55 |
(./example.tex |
|
|
56 |
LaTeX2e <2001/06/01> |
|
|
57 |
Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, n |
|
|
58 |
ohyphenation, loaded. |
|
|
59 |
(/usr/share/texmf/tex/latex/base/report.cls |
|
|
60 |
Document Class: report 2001/04/21 v1.4e Standard LaTeX document class |
|
|
61 |
(/usr/share/texmf/tex/latex/base/size12.clo)) |
|
|
62 |
No file example.aux. |
|
|
63 |
[1] [1] |
|
|
64 |
No file example.toc. |
|
|
65 |
[1] [2] (./example.aux) ) |
|
|
66 |
Output written on example.dvi (4 pages, 1180 bytes). |
|
|
67 |
Transcript written on example.log. |
|
|
68 |
</verbatim> |
|
|
69 |
|
2 |
AristotlePagaltzis |
70 |
This completed successfully, outputting some extra files created by [LaTeX] on the way -- the <tt>.aux</tt> and <tt>.toc</tt> files are used for internal references. The <tt>.dvi</tt> file is the first output file. |
1 |
DanielLawson |
71 |
|
|
|
72 |
You can view this with a program called xdvi: |
|
|
73 |
|
|
|
74 |
<verbatim> |
|
|
75 |
xdvi example.dvi |
|
|
76 |
</verbatim> |
|
|
77 |
|
|
|
78 |
!! Making it useful |
|
|
79 |
|
2 |
AristotlePagaltzis |
80 |
DVI is a __D__e__v__ice __I__ndependent format, which in theory makes it really useful. However, it tends to be harder to view in Certain OperatingSystem~s. Instead, you should convert your <tt>.dvi</tt> to a PostScript or [PDF] file: |
1 |
DanielLawson |
81 |
|
|
|
82 |
<verbatim> |
|
|
83 |
$ dvips example.dvi -o example.ps |
|
|
84 |
This is dvips(k) 5.86e Copyright 2001 Radical Eye Software (www.radicaleye.com) |
|
|
85 |
' TeX output 2004.12.16:1220' -> example.ps |
|
|
86 |
$ dvipdf example.dvi example.pdf |
|
|
87 |
$ ls *ps *pdf |
|
|
88 |
example.pdf example.ps |
|
|
89 |
<texc.pro>. [1] [1] [1] [2] |
2 |
AristotlePagaltzis |
90 |
</verbatim> |
1 |
DanielLawson |
91 |
|
2 |
AristotlePagaltzis |
92 |
You can now view these with a PostScript or [PDF] viewer, such as GhostView or AcrobatReader. |
3 |
JimCheetham |
93 |
|
|
|
94 |
---- |
|
|
95 |
|
|
|
96 |
!!! Dates and times |
|
|
97 |
|
|
|
98 |
The ~LaTeX command <code>\today</code> prints the date that the document is processed in a format determined by your language settings. There is a time record, but this gives the number of minutes since midnight and this isn't particularly useful in itself. |
|
|
99 |
|
|
|
100 |
!! Solutions |
|
|
101 |
|
|
|
102 |
There are a number of ways to include the current time in your document. In order of potential usefulness they are: |
|
|
103 |
|
|
|
104 |
! Using the <code>datetime</code> package |
|
|
105 |
|
|
|
106 |
The [datetime|http://www.ctan.org/tex-archive/macros/latex/contrib/datetime/] package provides commands for not only easily reformatting the date but for printing the time in several formats. |
|
|
107 |
|
|
|
108 |
! Inserting your own time calculation code in the document |
|
|
109 |
|
|
|
110 |
The most satisfying approach for a coder. Programming in ~TeX is an interesting challenge. The following code (included in a ~LaTeX file preamble) can be used to print the time in 24-hour format: |
|
|
111 |
|
|
|
112 |
<pre> |
|
|
113 |
\newcount\c@HOUR |
|
|
114 |
\newcount\c@FINALHOUR |
|
|
115 |
\newcount\c@MINUTE |
|
|
116 |
\newcount\c@HOURSINMINUTES |
|
|
117 |
\newcount\@INTVAL |
|
|
118 |
|
|
|
119 |
\newcommand{\twodigit}~[1]{\@INTVAL=#1\relax\ifnum\@INTVAL<10 0\fi\the\@INTVAL} |
|
|
120 |
|
|
|
121 |
\c@FINALHOUR=\time\divide\c@FINALHOUR by 60\relax |
|
|
122 |
\c@HOUR=\time\divide\c@HOUR by 60\relax |
|
|
123 |
\c@HOURSINMINUTES=\c@HOUR\multiply\c@HOURSINMINUTES by 60\relax |
|
|
124 |
\c@MINUTE=\time\advance\c@MINUTE by -\c@HOURSINMINUTES\relax |
|
|
125 |
\def\THEHOUR{\the\c@FINALHOUR} |
|
|
126 |
\def\THEMINUTES{\the\c@MINUTE} |
|
|
127 |
|
|
|
128 |
% time in HH:MM (24 hour clock) |
|
|
129 |
\newcommand\rightnow{\twodigit{\THEHOUR}:\twodigit{\THEMINUTES}} |
|
|
130 |
</pre> |
|
|
131 |
|
|
|
132 |
Anywhere in the document <code>\rightnow</code> may be used to print the time the document was assembled (or more correctly, the time on the system clock when the document assembly began). |
|
|
133 |
|
|
|
134 |
! Modifying the source <code>.tex</code> file when processing the file. |
|
|
135 |
|
|
|
136 |
Calling an editor like <code>awk</code> or <code>sed</code> to pre-process the source file is potentially popular with command-line geeks, but is rather clunky and has the feeling of a kludge about it. Not recommended. |