summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/first-latex-doc/first-latex-doc.tex
blob: 4162980678eb48cd3648a6e4da1f9e2cd0ab0838 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
\documentclass{article}

\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{color}
\definecolor{bg}{rgb}{0.89, 0.95, 0.71} % background e3f3b4
\definecolor{ac}{rgb}{0.50, 0.18, 0.41} % accent c491b6
\definecolor{rc}{rgb}{0.77, 0.57, 0.71} % rule 7f2f69
\usepackage{listings}
\lstset{
       basicstyle=\small\ttfamily,
       xleftmargin=1em,
       }
\lstdefinestyle{latex}{language=TeX,
                       backgroundcolor=\color{bg},
                       basicstyle=\small\ttfamily,
                       frame=leftline,
                       xleftmargin=1.4em, 
                       framexleftmargin=.8em}
\lstdefinestyle{cmdline}{
                         }
\usepackage{url}
\usepackage[pdftex, 
            bookmarks, 
            colorlinks=true, 
            plainpages = false,
            pdfpagemode = UseNone,
            pdfstartview = FitH, 
            citecolor = ac, urlcolor = ac, filecolor = ac]{hyperref}

\setlength{\parskip}{0.75ex}
\makeatletter % from emma pease at csli.stanford.edu
% \@startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE} 
%            optional * [ALTHEADING]{HEADING}
%    Generic command to start a section.  
%    NAME       : e.g., 'subsection'
%    LEVEL      : a number, denoting depth of section -- e.g., chapter=1,
%                 section = 2, etc.  A section number will be printed if
%                 and only if LEVEL < or = the value of the secnumdepth
%                 counter.
%    INDENT     : Indentation of heading from left margin
%    BEFORESKIP : Absolute value = skip to leave above the heading.  
%                 If negative, then paragraph indent of text following 
%                 heading is suppressed.
%    AFTERSKIP  : if positive, then skip to leave below heading,
%                       else - skip to leave to right of run-in heading.
%    STYLE      : commands to set style
%  If '*' missing, then increments the counter.  If it is present, then
%  there should be no [ALTHEADING] argument.  A sectioning command
%  is normally defined to \@startsection + its first six arguments.
\def\section{\@startsection {section}{1}{\z@}{-2.5ex plus -.6ex minus 
    -.2ex}{1.0ex plus .15ex}{\hspace*{-3em}\Large\bf\color{ac}}}
\def\subsection{\@startsection{subsection}{2}{\z@}{-1.5ex plus -.3ex minus 
   -.1ex}{.3ex plus .1ex}{\hspace*{-2.5em}\bf\large\color{ac}}}
\makeatother
\setcounter{secnumdepth}{0}

\newlength{\rulelength}
\setlength{\rulelength}{\linewidth}
\addtolength{\rulelength}{9.5em}
\title{Getting something out of \LaTeX{}}
\author{Jim Hef{}feron}

\pagestyle{empty}
\begin{document}
\thispagestyle{empty}
% \maketitle
\setlength{\unitlength}{1in}
\begin{picture}(0,0)(0,0)
  \put(-0.5,-.84){\mbox{\color{bg}\rule{2.32in}{1.15in}}}
\end{picture}
\makeatletter
\vspace*{3ex}
\par\noindent{\hspace*{-1.5em}\LARGE\bf \@title}
\vspace*{-1.2ex}
\par\noindent{\textcolor{rc}{\hspace*{-1.5em}\rule{\rulelength}{1.05pt}}}
\vspace*{-.5ex}
\par\noindent{\hspace*{-1.5em}\large \@author}
\vspace*{5ex}
\makeatother

This is for people considering using \LaTeX{}.
This is not a tutorial.
Instead, 
it takes you through making a first document.
If this quick taste leaves you wanting more
then you are ready to go through a tutorial.

Because this is a just a taste, we will skip many things.
And for those things that we discuss, we will see only one way to do them.
For instance, in the first section there are a number of ways to get 
the software but we will just name one.
This approach has the disadvantage of leaving you without a full idea
of what the system entails, 
but has the advantage that in a couple of hours 
you should finish with some idea of whether
\LaTeX{} is a tool that can help you.

  



\section{Get the software}

\LaTeX{} is the way that we will use the \TeX{} suite of 
programs.
So you must download those programs (if you don't already have them).
Here we will stick with downloads that are free.

If your computer system is Windows then go to the  
\href{http://www.miktex.org}{MiK\TeX} site.
Click on the link under ``Download'' and follow the directions.
If you have a Unix-like system, such as Linux, then go to the
\href{http://www.tug.org/texlive/}{\TeX{} Live}
site and click on the ``Downloads'' link.
If you have a Macintosh then use the 
\href{http://www.tug.org/mactex/}{Mac\TeX} site
(this is a version of \TeX{}~Live, with some Mac-specific add-ons).

All three downloads are large, but all three install easily (of course,
you must follow the on-screen directions; in particular on 
a Unix-like system you will need to alter your \texttt{PATH}).
They come with an immense amount of stuff.
But here we are just trying \LaTeX{} out so we will skip past lots of things.




\subsection{Use an editor}

We don't write \LaTeX{} with a word processor.
A word processor combines many of the jobs that must be done to 
produce a document, such as entering and moving the text, formatting it
into paragraphs, producing a PDF file, etc.
In a \TeX{}-based system those jobs are done separately.

Instead, we write \LaTeX{} with an editor, 
a program that is specialized at moving text around in a computer file.
There are many editors,
including some specifically for writing \LaTeX{}, but
our documents are small so almost any editor will do. 
Just to give a couple of names:
on a Windows system you can use Notepad,
while on a Unix-like system or a Mac you can use Emacs.





\section{Get it to work}

With an editor, you can write a first document.
Make a new directory
named \nolinkurl{latex-first}  
(your system might use the term ``folder'').
Open a terminal window and in that window, change into that directory
(possibly you would use the command \verb!cd latex-first!).

Move back to your editor window.
Open the new file
\nolinkurl{latex-first.tex}
in the \nolinkurl{latex-first} directory. 
Enter the text below, line for line, as it is written
(without spaces on the left margin).
\begin{lstlisting}[style=latex]
\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}
Hello world!
\end{document}
\end{lstlisting}
Many of those things are boilerplate~--- lines that I put into every
\LaTeX{} file that I open.
We'll ignore what they mean for a while to focus on getting
output.

Save that file.
Go back to your terminal window and enter this command.
\begin{center}
\verb!pdflatex latex-first!
\end{center}
If that worked then you should see perhaps forty lines of text, 
starting with something like 
\begin{lstlisting}
This is pdfTeXk, Version 3.1415926-1.40.9 (Web2C 7.5.7)
 %&-line parsing enabled.
entering extended mode
\end{lstlisting}
and ending with something like this.
\begin{lstlisting}
Output written on latex-first.pdf (1 page, 6195 bytes).
Transcript written on latex-first.log.
\end{lstlisting}
If you had errors, see the subsection below.

You can view the output \nolinkurl{latex-first.pdf} with
whatever program your system uses to view PDF files.
\begin{center}
  \includegraphics[scale=.35]{latex-first.png}
\end{center}

\subsection{Handle errors}

You have to be careful to type the lines as written.
Some seemingly small typing changes give large changes in the
result, including causing a document to not be processable.
So that you can be sure there isn't a typing discrepancy, 
this document comes bundled with a source of
\nolinkurl{latex-first.tex} that you can run.

If your run ends with a question mark, then you can type `\verb!x!' and
then hit `Enter' to get out.
You will still be able to see any error message that the system prints.

\LaTeX's error messages can be hard to understand.
If you know someone with some experience, of course that's great.
If not, I've had good luck with putting the error message into a 
search engine.






\section{Get more out}

The first document is short so that it has fewer parts to go wrong.
But we've already seen some basics.
The file you type mixes text and commands.
The commands for \LaTeX{}, such as \verb!\begin{document}!,
start with a backslash
and sometimes have arguments contained in curly braces
(or, we'll see below, sometimes square brackets).

The document we've made starts out with margins, typeface, etc., specified 
in the class \verb!article!.
We've modified the behavior in small ways by bringing in some
packages such as \verb!graphicx!, which will allow us to include
graphic files.
 
For the next step,
we'll make a longer and more complex document.
Start the same way:
make a new directory
named \nolinkurl{latex-second},
open a terminal window, and change into the new directory.

Move back to your editor window.
Open a new file
\nolinkurl{latex_second.tex}
in the \nolinkurl{latex-second} directory. 
Enter the text below.
\begin{lstlisting}[style=latex]
\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}

\begin{document}
This is some preamble text that you enter yourself.

Below is a command that will automatically generate seven paragraphs
of text that is commonly used for examples in this field.

\lipsum[1-7]
\end{document}
\end{lstlisting}
Save that file and run
\verb!pdflatex latex_second!.
Your system's PDF reader should show something like this.
\begin{center}
  \includegraphics[scale=.35]{latex-second-a.png}
\end{center}

If you have used a word processor then you will have noticed the 
difference between that tool and running \LaTeX{}.
Here the program  does not move the text around as we type it,
rather we tell \LaTeX{} what we want and then it does that.
This applies to the commands that we see below.
For instance,
we tell \LaTeX{} to make a section and the system 
handles the font changes, vertical space, etc.

In your editor, change the file \nolinkurl{latex-second.tex} to say this.
\begin{lstlisting}[style=latex]
\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}

\begin{document}
This is some preamble text that you enter yourself.

\section{Text for the first section}
\lipsum[1]

\subsection{Text for a subsection of the first section}
\lipsum[2-3]

\subsection{Another subsection of the first section}
\lipsum[4-5]

\section{The second section}
\lipsum[6]

\subsection{Title of the first subsection of the second section}
\lipsum[7]
\end{document}
\end{lstlisting}
Here is the resulting output.
\begin{center}
  \includegraphics[scale=.35]{latex-second-b.png}
\end{center}
Note that numbering of the sections and subsections is done automatically.
How to change how they look is beyond this document, but the point is that
the system generates those for you.

With those, we can illustrate cross-references.
Change the document's text to this.
\begin{lstlisting}[style=latex]
\begin{document}
This is some preamble text that you enter yourself.

\section{Text for the first section}
\lipsum[1]

\subsection{Text for a subsection of the first section}
\lipsum[2-3]
\label{labelone}

\subsection{Another subsection of the first section}
\lipsum[4-5]
\label{labeltwo}

\section{The second section}
\lipsum[6]

Refer again to \ref{labelone}.
Note also the discussion on page \pageref{labeltwo}

\subsection{Title of the first subsection of the second section}
\lipsum[7]
\end{document}
\end{lstlisting}
Run 
\verb!pdflatex latex-second!
and look at the PDF file.
Notice that the references that we just entered didn't work~--- they appear
as question marks.
As \LaTeX{} runs it saves labels to a file.
So, when you run a file with a first-time label it has not yet been saved.
The solution is to run \verb!pdflatex latex-second! again.
The result looks like this.
\begin{center}
  \includegraphics[scale=.35]{latex-second-c.png}
\end{center}
(When you are writing a real document, because you are fixing typos, etc.,
you end up running \LaTeX{} a number of times anyway, so having to
rerun the command isn't an issue in practice.)

We'll finish by adding footnotes, a
table of contents, and a bibliography.
Edit \nolinkurl{latex-second.tex} to say this. 
\begin{lstlisting}[style=latex]
\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}

\title{Test document}
\author{Your name \\ \url{you@example.com}}
\date{2009-Oct-12}
\begin{document}
\maketitle
\tableofcontents
\newpage

This is some preamble text that you enter 
yourself.\footnote{First footnote.}\footnote{Second footnote.}

\section{Text for the first section}
\lipsum[1]

\subsection{Text for a subsection of the first section}
\lipsum[2-3]
\label{labelone}

\subsection{Another subsection of the first section}
\lipsum[4-5]
\label{labeltwo}

\section{The second section}
\lipsum[6]

Refer again to \ref{labelone}.\cite{ConcreteMath}
Note also the discussion on page \pageref{labeltwo}

\subsection{Title of the first subsection of the second section}
\lipsum[7]

\begin{thebibliography}{9}
\bibitem{ConcreteMath}
Ronald L. Graham, Donald E. Knuth, and Oren Patashnik, 
\textit{Concrete mathematics}, 
Addison-Wesley, Reading, MA, 1995.
\end{thebibliography}
\end{document}
\end{lstlisting}
Run \verb!pdflatex latex-second!  
(in the \verb!\begin{thebibliography}{9}! line, 
the \verb!9! tells \LaTeX{} that
the widest reference has one digit).  

Try changing the margins by altering the second
line to \verb!\usepackage[margin=1in]{geometry}!.
You can also experiment with the headings by changing the \verb!fancyhdr! 
line to this.
\begin{lstlisting}[style=latex]
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{\today}
\chead{}
\rhead{Test document}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\end{lstlisting}


\section{Get math}

Many people interested in \LaTeX{} 
want to include mathematics.
The examples below are from \cite{ConcreteMath}.
(We'll stop giving the complete listings of the input files,
and we'll stop showing screenshots to instead just give the output directly.)

Add this text, for instance before the bibliography.
\begin{lstlisting}[style=latex]
There are $\binom{2n+1}{n}$ sequences with $n$ occurrences of 
$-1$ and $n+1$ occurrences of $+1$, and Raney's lemma
tells us that exactly $1/(2n+1)$ of these sequences have all
partial sums positive.
\end{lstlisting} % page 360
It produces this output.
\begin{center}
\begin{minipage}{0.8\textwidth}
There are $\binom{2n+1}{n}$ sequences with $n$ occurrences of 
$-1$ and $n+1$ occurrences of $+1$, and Raney's lemma
tells us that exactly $1/(2n+1)$ of these sequences have all
partial sums positive.
\end{minipage}
\end{center}
This input
\begin{lstlisting}[style=latex]
Elementary calculus suffices to evaluate $C$ if we are clever enough
to look at the double integral
\begin{equation*}
  C^2
  =\int_{-\infty}^{+\infty} e^{-x^2} \mathrm{d}x
   \int_{-\infty}^{+\infty} e^{-y^2} \mathrm{d}y\;.
\end{equation*}
\end{lstlisting} % page 485
gives this.
\begin{center}
\begin{minipage}{0.8\textwidth}
Elementary calculus suffices to evaluate $C$ if we are clever enough
to look at the double integral
\begin{equation*}
  C^2
  =\int_{-\infty}^{+\infty} e^{-x^2} \mathrm{d}x
   \int_{-\infty}^{+\infty} e^{-y^2} \mathrm{d}y\;.
\end{equation*}
\end{minipage}
\end{center}
And this source
\begin{lstlisting}[style=latex]
Solve the following recurrence for $n,k\geq 0$:
\begin{align*}
  Q_{n,0} &= 1
  \quad Q_{0,k} = [k=0];  \\
  Q_{n,k} &= Q_{n-1,k}+Q_{n-1,k-1}+\binom{n}{k}, \quad\text{for $n,k>0$.}
\end{align*}
\end{lstlisting} % page 250
produces this result.
\begin{center}
\begin{minipage}{0.8\textwidth}
Solve the following recurrence for $n,k\geq 0$:
\begin{align*}
  Q_{n,0} &= 1
  \quad Q_{0,k} = [k=0];  \\
  Q_{n,k} &= Q_{n-1,k}+Q_{n-1,k-1}+\binom{n}{k}, \quad\text{for $n,k>0$.}
\end{align*}
\end{minipage}
\end{center}
The \verb!\usepackage{ams...! line in our source files
allow us to use the American Math Society's packages.
For example, the \texttt{align*} above is available because we
used \texttt{amsmath}.

We also have access to the AMS's symbols. 
A simple example is that we can get $\mathbb{Z}$ with the command
\verb!$\mathbb{Z}$!.
One more example shows a long arrow, and some other useful commands
\begin{lstlisting}[style=latex]
Therefore
\begin{equation*}
a\equiv b\pmod{m}
\qquad\Longleftrightarrow\qquad
a\equiv b \pmod{p^{m_p}}\quad\text{for all $p$}  
\end{equation*}
if the prime factorization of $m$ is $\prod_p p^{m_p}$.
\end{lstlisting} % page 126 
that produce this.
\begin{center}
\begin{minipage}{0.8\textwidth}
Therefore
\begin{equation*}
a\equiv b\pmod{m}
\qquad\Longleftrightarrow\qquad
a\equiv b \pmod{p^{m_p}}\quad\text{for all $p$}  
\end{equation*}
if the prime factorization of $m$ is $\prod_p p^{m_p}$.
\end{minipage}
\end{center}
(The
\href{http://mirror.ctan.org/info/symbols/comprehensive/symbols-letter.pdf}{\textit{Comprehensive \LaTeX{} Symbols List}} 
shows the widely-available symbols.)

The \verb!amsthm! package gives us access to theorem environments,
but those go beyond the scope of this document.



\section{Got it?}
You now have a feel for \LaTeX.
To go on, 
see the tutorial
\href{http://mirrors.ctan.org/info/lshort}{\textit{The Not-So-Short Guide to \LaTeX  2e}}
or the 
\href{http://www.tug.org.in/tutorials.html}{Indian \TeX{} Users Group's tutorial}.

If what you've seen seems very different from what you are used to,
and you'd like an overview of the advantages of \LaTeX{},
see
\href{http://www.tug.org/TUGboat/Articles/tb22-1-2/tb70heff.pdf}{Why \TeX?}.

When you take up \LaTeX{} for real-life documents, you need
to choose a good editing program. 
In particular, people often use systems where the editor is integrated with
other components such as an output view, a spell checker that works
with \LaTeX{}, etc.
For advice, ask \LaTeX{} users that you know or click around on the Internet, 
for instance on
\href{http://groups.google.com/group/comp.text.tex/topics?gvc=2}{\url{comp.text.tex}}.
(For what it is worth, I use \verb!emacs! with the AUC\TeX{} add-on.  
On the Macintosh, many people use
\href{http://www.uoregon.edu/~koch/texshop/}{\TeX Shop}.
A cross-platform editor, developed for the \TeX{} Users Group
with the goal of simplicity, is 
\href{http://www.tug.org/texworks/}{\TeX{}works}.)


\begin{thebibliography}{9}
\bibitem{ConcreteMath}
Ronald L. Graham, Donald E. Knuth, and Oren Patashnik, 
\textit{Concrete mathematics}, 
Addison-Wesley, Reading, MA, 1995.
\end{thebibliography}


\section{Author}
\begin{raggedright}
Jim Hef{}feron  \\
Saint Michael's College \\
\today \\
\nolinkurl{ftpmaint@tug.ctan.org}
\end{raggedright}

\end{document}