File: oregan1.html

package info (click to toggle)
lg-issue106 1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,780 kB
  • ctags: 124
  • sloc: xml: 2,834; sh: 78; makefile: 34
file content (633 lines) | stat: -rw-r--r-- 17,736 bytes parent folder | download
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

<html>
<head>
<link href="../lg.css" rel="stylesheet" type="text/css" media="screen, projection"  />
<link rel="shortcut icon" href="../favicon.ico" />
<title>Front and Back: Kile and LaTeX LG #106</title>

<style type="text/css" media="screen, projection">
<!--

-->
</style>


</head>

<body>


<img src="../gx/2003/newlogo-blank-200-gold2.jpg" id="logo" alt="Linux Gazette"/>
<p id="fun">...making Linux just a little more fun!</p>


<div class="content articlecontent">

<div id="previousnexttop">
<A HREF="oregan.html" >&lt;-- prev</A> | <A HREF="oregan2.html" >next --&gt;</A>
</div>



<h1>Front and Back: Kile and LaTeX</h1>
<p id="by"><b>By <A HREF="../authors/oregan.html">Jimmy O'Regan</A></b></p>

<p>
<h3>Introduction</h3>

<p><a href="http://www.latex-project.org/">LaTeX</a> is a document
preparation system based on Donald Knuth's TeX. LaTeX provides the
facilities needed to typeset articles, books, and other documents.
<a href="http://kile.sourceforge.net/">Kile</a> is a KDE-based
environment for editing LaTeX documents, which simplifies the
process and provides easy access to commonly used commands and
tags.</p>

<p>As well as offering short cuts to the various commands used to
convert LaTeX documents, and to launch the viewers for these
formats, Kile provides an output window, so you can view an errors
which may have been present in your document, and an embedded
Konsole window, so you can easily launch any other commands you
wish without switching windows.</p>

<p>TeX is used by so many of the various documentation tools
available for Linux that LaTeX is worth learning, if for no other
reason than it's available almost everywhere. TeX (and, by
extension, LaTeX) still has the best rendering available for
mathematics, so if you ever plan to typeset a complicated formula,
you would do well to learn it. LaTeX is being used by Project
Gutenberg for mathematical books, and a subset of TeX's math syntax
is used by Wikipedia.</p>

<p>If you've written HTML before, basic LaTeX shouldn't be too hard
to grasp. For example, <i>text in italics</i> is written like this
in HTML: <code>&lt;i&gt;text in italics&lt;/i&gt;</code>; and like
this in LaTeX: <code>\textit{text in italics}</code>.</p>

<h3>Coming Clean</h3>

<p>Now, there isn't much to be said about using Kile. Kile
<em>is</em> useful - it certainly saves a lot of time to be able to
select the tags you want from a menu. It also saves time to use the
document creation toolbar - the commands these tools invoke can be
summarized, left to right (see below), as follows: 
<br>
<img src="misc/oregan/kile-doctools.png" alt="Tool icons"></p>

<ol>
<li><tt>latex <i>filename</i>.tex</tt></li>
<li><tt>kdvi <i>filename</i>.dvi</tt></li>
<li><tt>dvips <i>filename</i>.dvi -o <i>filename</i>.ps</tt></li>
<li><tt>kghostview <i>filename</i>.ps</tt></li>
<li><tt>pdflatex <i>filename</i>.tex</tt></li>
<li><tt>kpdf <i>filename</i>.pdf</tt></li>
</ol>

<p>Note that Kile uses <tt>pdflatex</tt>. This, in my opinion, is
not the best way to generate a PDF file from LaTeX. In my
experience, <tt>pdflatex</tt> has failed to include images. My
preferred way to generate PDF files (using an <a href=
"misc/oregan/sk.tex.txt">article about SuperKaramba</a> that I
never got around to finishing as an example) is:</p>

<pre class="code">
latex sk.tex
dvips sk.dvi -o sk.ps
ps2pdf sk.ps sk.pdf
</pre>

<h3>Starting a New Document</h3>

<p>Kile is a KDE application, so starting a new document is done
the same way as with any other KDE application:
<code>File-&gt;New</code>, or <code>Ctrl-N</code>. Kile offers a
choice of "Empty Document", "Article", "Book", "Letter", or
"Report". I'll presume you want to use "Article" - I'll be using
(parts of) this article as an example - but it shouldn't be too
difficult to use the other templates.</p>

<pre class="code">
\documentclass[a4paper,10pt]{article}


%opening
\title{}
\author{}

\begin{document}

\maketitle

\begin{abstract}

\end{abstract}

\section{}

\end{document}
</pre>

<p>Not too scary, I'm sure you'll agree! Most basic commands have
the same formula: <code>\command{parameter}</code>. There are some
differences, like <code>\maketitle</code>, but it's true for most
of the common commands. Filling this out looks like this:</p>

<pre class="code">
\documentclass[a4paper,10pt]{article}
\usepackage{hyperref}

%opening
\title{Front and Back: Kile and LaTeX}
\author{Jimmy O'Regan}

\begin{document}

\maketitle

\begin{abstract}
Kile is a user-friendly frontend to \LaTeX{}. This article discusses using 
Kile, and using \LaTeX{} without it.
\end{abstract}

\section{Introduction}

\href{http://www.latex-project.org/}{\LaTeX{}} is a document preparation 
system based on Donald Knuth's \TeX{}. \LaTeX{} provides the facilities needed 
to write articles, books, and other documents. 
\href{http://kile.sourceforge.net}{Kile} is a KDE-based environment for editing 
LaTeX documents, which simplifies the process and provides easy access to 
commonly used commands and tags. 
</pre>

<p>Note the <code>\usepackage{hyperref}</code> line: this tells
LaTeX to use the hyperref package, which adds some extra commands
for Web links (I use it for the <code>\href{}{}</code> command).
One difference between HTML and LaTeX is that LaTeX does not
require a command for a new paragraph; you simply leave a blank
line between paragraphs, and LaTeX figures it out. LaTeX has a
number of special characters which HTML doesn't: most of these can
be used by escaping them with a backslash ('\'), but the backslash
itself must be inserted as <code>$\backslash$</code>, because a
double backslash ('\\') is used to force a line break. Here is a
table of some common HTML tags and their LaTeX equivalents:</p>

<table>
<tr>
<th></th>
<th>HTML</th>
<th>LaTeX</th>
</tr>

<tr>
<th>Italics</th>
<td>&lt;i&gt;Italics&lt;/i&gt;</td>
<td>\textit{Italics}</td>
</tr>

<tr>
<th>Bold</th>
<td>&lt;b&gt;Bold&lt;/b&gt;</td>
<td>\textbf{Bold}</td>
</tr>

<tr>
<th>Typewriter</th>
<td>&lt;tt&gt;Type&lt;/tt&gt;</td>
<td>\texttt{Type}</td>
</tr>

<tr>
<th>Hyperlink</th>
<td>&lt;a href="http://"&gt;text&lt;/a&gt;</td>
<td>\href{text}{http://}</td>
</tr>

<tr>
<th>Heading</th>
<td>&lt;h1&gt;Heading&lt;/h1&gt;</td>
<td>\section{Heading}</td>
</tr>

<tr>
<th>Subheading</th>
<td>&lt;h2&gt;Subheading&lt;/h2&gt;</td>
<td>\subsection{Subheading}</td>
</tr>

<tr>
<th>&lt;</th>
<td>&amp;lt;</td>
<td>$&lt;$</td>
</tr>

<tr>
<th>&gt;</th>
<td>&amp;gt;</td>
<td>$&gt;$</td>
</tr>

<tr>
<th>&amp;</th>
<td>&amp;amp;</td>
<td>\&amp;</td>
</tr>
</table>

<h3>Environments</h3>

<p>More complicated things in LaTeX are done in different
environments - these commands look like this:</p>

<pre>
\begin{environment}
...
\end{environment}
</pre>

<p>Kile helpfully fills in the <code>\end{}</code> part for you
automatically, after a blank line. It's a small time saver, but it
is useful.</p>

<p> Most of these environments can have a <code>\label{}</code>
tag attached, which allows you to set a description which "follows" 
the environment. <a href="misc/oregan/feedreader.tex.txt">This
file</a> contains an example of the use of the label tag, attached
to a <tt>verbatim</tt> environment.</p>

<p>Different lists are available as environments, for example;
<code>&lt;ol&gt;</code> in HTML translates to
<code>\begin{enumerate}</code>, and <code>&lt;ul&gt;</code>
translates to <code>\begin{itemize}</code>. The <code>\item</code>
tag is used in place of <code>&lt;li&gt;</code>. This list:</p>

<ol>
<li>First</li>

<li>Second</li>
</ol>

<p>Looks like this:</p>

<pre class="code">
\begin{enumerate}
\item First
\item Second
\end{enumerate}
</pre>

<p>Another common HTML equivalent is the "verbatim" environment in
place of the &lt;pre&gt; tag. The "verbatim" environment is
different to HTML's "pre" tag though; HTML elements must be
escaped, whereas in the "verbatim" environment all processing stops
until the <code>\end{verbatim}</code> tag, so nothing need be
escaped.</p>

<h3>Things not available in HTML</h3>

<p>Because LaTeX is a document preparation system, it has quite a
few commands which have no equivalents in HTML, but which are
useful for creating documents such as books. Tags such as
<code>\chapter{}</code> are self explanatory; one thing which might
provide a little confusion is the use of footnotes.</p>

<p>While in the paragraph environment, a footnote can be inserted
by simply adding <code>\footnote{Text of footnote}</code>. In other
environments, however, you have to use the
<code>\footnotemark</code> tag while inside the environment,
followed by the <code>\footnotetext{Text of the footnote}</code>
when you're outside of that environment. So, if you wanted to add a
footnote inside a footnote (if you're a Terry Pratchett fan, you'll
understand!), it would look like this:</p>

<pre class="code">
Here you would have your text, as usual\footnote{Or as unusual\footnotemark}. 
You can then continue your paragraph text.

\footnotetext{At least I hope you find footnotes within footnotes unusual}
</pre>

<p>(<a href="misc/oregan/rdf.tex.txt">This file</a>, a version
of my RDF article from last month, contains an example of the
use of a footnote).</p>

<h3>Non-English Symbols</h3>

<p>LaTeX supports most modern languages. The most commonly needed
symbols (in my part of the world, at least) are the letters of the
Greek alphabet, and the various symbols used in the Latin alphabet,
such as the umlaut or acute.</p>

<p>Kile helpfully provides a sidepane for Greek, and another with
many of the Latin symbols. Here's another table of some symbols,
with their <a href=
"http://www.htmlhelp.com/reference/html40/entities/">HTML</a> and
LaTeX equivalents:</p>

<table>
<tr>
<th></th>
<th>HTML</th>
<th>LaTeX</th>
</tr>

<tr>
<th>&alpha;</th>
<td>&amp;alpha;</td>
<td>\alpha</td>
</tr>

<tr>
<th>&auml;</th>
<td>&amp;auml;</td>
<td>\"a</td>
</tr>

<tr>
<th>&eacute;</th>
<td>&amp;eacute;</td>
<td>\'e</td>
</tr>

<tr>
<th>&AElig;</th>
<td>&amp;AElig;</td>
<td>\AE{}</td>
</tr>

<tr>
<th>&Ccedil;</th>
<td>&amp;Ccedil;</td>
<td>\c{C}</td>
</tr>

<tr>
<th>&ugrave;</th>
<td>&amp;ugrave;</td>
<td>\`u</td>
</tr>

<tr>
<th>&ocirc;</th>
<td>&amp;ocirc;</td>
<td>\^o</td>
</tr>

<tr>
<th>&ntilde;</th>
<td>&amp;ntilde;</td>
<td>\~n</td>
</tr>

<tr>
<th>&szlig;</th>
<td>&amp;szlig;</td>
<td>\ss{}</td>
</tr>

<tr>
<th>&oelig;</th>
<td>&amp;oelig;</td>
<td>\oe{}</td>
</tr>

<tr>
<th>&aring;</th>
<td>&amp;ring;</td>
<td>\aa{}</td>
</tr>

<tr>
<th>&oslash;</th>
<td>&amp;oslash;</td>
<td>\o{}</td>
</tr>
</table>

<p>I sometimes proofread for <a href="http://pgdp.net">Distributed
Proofreaders</a>, where from time to time there are books which use
odd things such as an AE ligature with an acute
(<code>\'\AE{}</code>). One book that was recently posted is <a
href=
"http://www.gutenberg.net/dirs/1/3/3/2/13320/13320-h/13320-h.htm">JUAN
MASILI &Oacute; Ang pinuno n~g tulis&aacute;n</a>, which is in old
Tagalog. Old Tagalog uses a g with a tilde. HTML doesn't support
this, but LaTeX does: <code>\~g</code>. There are many, many
strange characters available for use in LaTeX - so many, that I'm
not going to go looking for them all (well... that, and
laziness).</p>

<h3>Tables</h3>

<p>It's probably better to show an example of a table than to try
to talk about it too much:</p>

<pre class="code">
\begin{tabular}{rcl}
1 &amp; 2 &amp; 3 \\
4 &amp; 5 &amp; 6
\end{tabular}
</pre>

<p>The <code>{rcl}</code> means that there are three columns in
this table, the first is <b>r</b>ight aligned, second is
<b>c</b>entred, and the third is <b>l</b>eft aligned. Each column
is separated with an ampersand (<code>&amp;</code>); each row is
separated with a newline (<code>\\</code>). The row and column
separation used in tables is also used in similar environments,
such as matrices and equations, so it's important to know how to
use tables if you want to typeset complicated equations in LaTeX.</p>

<p>Let's look at part of the first table, formatted for LaTeX:</p>

<pre class="code">
\begin{tabular}{cll}
&amp; HTML &amp; \LaTeX{} \\
Italics &amp; $&lt;$i$&gt;$ &amp; $\backslash$textit\{Italics\} \\
Bold &amp; $&lt;$b$&gt;$Bold$&lt;$/b$&gt;$ &amp; $\backslash$textbf\{Bold\} \\
Hyperlink &amp; $&lt;$a href="http://"$&gt;$text$&lt;$/a$&gt;$ &amp; $\backslash$href\{text\}\{http://\} \\
$&lt;$ &amp; \&amp;lt; &amp; \$$&lt;$\$ \\
$&gt;$ &amp; \&amp;gt; &amp; \$$&gt;$\$ \\
\&amp; &amp; \&amp;amp; &amp; $\backslash$\&amp;
\end{tabular}
</pre>

<p>(And maybe now you see why I didn't redo this whole article as
an example, as I had originally intended!)</p>

<h3>Mathematics</h3>

<p>I mentioned that LaTeX is <i>the</i> typesetting system for
mathematics... I also don't want to get into it too deeply, as typesetting
mathematical equations in LaTeX is a topic worthy of a book, not an article.</p>

<p>In general, simple maths can be included by enclosing them within
dollar signs:</p>

<pre class="code">
$2 + 2 = 4$
</pre>

This might explain why certain things, such as the "less than"
(&lt;) and "greater than" (&gt;) symbols need to be surrounded by
dollar signs. LaTeX also allows you to use the "proper"
multiplication and division symbols: 

<pre class="code">
$x = 2 \times 3 \div y$
</pre>

Lets look at an image and the LaTeX used to generate it:

<p><img src="misc/oregan/tmath1.png" alt="Formula"></p>

<pre class="code">
\left(\frac{a}{b}\right)^2 = \frac{a}{b} \times \frac{a}{b} = \frac{a^2}{b^2}
</pre>

<p>Here we have large parentheses (<code>\left(</code>,
<code>\right)</code>), fractions (<code>\frac{}{}</code>), and
simple superscripts (<code>a^2</code>). To use more than a single
character in a superscript or subscript (<code>_</code>), they are
enclosed with braces: <code>a^{13 + 2}_{4 - 6}</code>. (This
example is taken from <a href=
"http://www.gutenberg.net/1/3/3/0/13309/">A First Book in
Algebra</a>, which was recently posted to Project Gutenberg. If you
want to learn about typesetting mathematics with LaTeX, have a look at the
source of this book).</p>

<p>Let's look at a simple array. As I mentioned earlier, many of
the mathematical environments are special cases of tables:</p>

<pre class="code">
\begin{array}{cc}
3 &amp; 4 \\ 
4 &amp; 5
\end{array} 
</pre>

<p>Another example is an equation array, which is used to align a
formula, normally to the 'equals' symbol (the convention is to
write this as <code>&amp;=&amp;</code>, to show the alignment more
clearly):</p>

<pre class="code">
\begin{eqnarray}
a &amp;=&amp; 5 + 6 \\
b + 6 - 3 &amp;=&amp; 2 - a
\end{eqnarray}
</pre>

<p>This is almost the same as this table, except the equation is
centred, and each line is numbered:</p>

<pre class="code">
\begin{tabular}{rcl}
a &amp;=&amp; 5 + 6 \\
b + 6 - 3 &amp;=&amp; 2 - a
\end{tabular}
</pre>

<h3>Conclusion</h3>

<p>LaTeX is a powerful text formatting language, and I've barely
covered the tip of the iceberg in this article. Kile is a great
tool to assist your use of LaTeX (though I've hardly covered it at
all) - it can really save you time remembering which environment
you need by offering them from a menu, and for those new to LaTeX,
it can be a godsend.</p>

<p>If you don't want to edit LaTeX by yourself, there are tools
available which will generate LaTeX from other formats. 
<a href="http://html2latex.sourceforge.net/">html2latex</a>, for
example, converts HTML to LaTeX, and <a 
href="http://wiki.auf-trag.de/">this site</a> converts Wikipedia
articles to LaTeX. (<a 
href="misc/oregan/wikipedia.tex.txt">Example</a>).</p>

</p>


<!-- *** BEGIN author bio *** -->
<P>&nbsp;
<P>
<!-- *** BEGIN bio *** -->
<hr>
<P>
<img ALIGN="LEFT" ALT="[BIO]" SRC="../gx/authors/oregan.jpg" class="bio">
<em>
Jimmy has been using computers from the tender age of seven, when his father 
inherited an Amstrad PCW8256. After a few brief flirtations with an Atari ST
and numerous versions of DOS and Windows, Jimmy was introduced to Linux in 1998
and hasn't looked back.

<P> Jimmy is a father of one, a techno-savvy seven year-old called Mark. In
the spare time he enjoys outside of his personal circle of Hell, working in a
factory, Jimmy likes to play guitar and edit Wikipedia.
</em>
<br CLEAR="all">
<!-- *** END bio *** -->

<!-- *** END author bio *** -->

<div id="articlefooter">

<p>
Copyright &copy; 2004, Jimmy O'Regan. Released under the
<a href="http://linuxgazette.net/copying.html">Open Publication license</a>
</p>

<p>
Published in Issue 106 of Linux Gazette, September 2004
</p>

</div>


<div id="previousnextbottom">
<A HREF="oregan.html" >&lt;-- prev</A> | <A HREF="oregan2.html" >next --&gt;</A>
</div>


</div>






<div id="navigation">

<a href="../index.html">Home</a>
<a href="../faq/index.html">FAQ</a>
<a href="../lg_index.html">Site Map</a>
<a href="../mirrors.html">Mirrors</a>
<a href="../mirrors.html">Translations</a>
<a href="../search.html">Search</a>
<a href="../archives.html">Archives</a>
<a href="../authors/index.html">Authors</a>
<a href="../contact.html">Contact Us</a>

</div>



<div id="breadcrumbs">

<a href="../index.html">Home</a> &gt; 
<a href="index.html">September 2004 (#106)</a> &gt; 
Article

</div>





<img src="../gx/2003/sit3-shine.7-2.gif" id="tux" alt="Tux"/>




</body>
</html>