tlove-me-some-latex.txt - monochromatic - monochromatic blog: http://blog.z3bra.org
HTML git clone git://z3bra.org/monochromatic
DIR Log
DIR Files
DIR Refs
---
tlove-me-some-latex.txt (11147B)
---
1 # Love me some LaTeX
2
3 06 December, 2013
4
5
6 I am now in my last year of engineering school, and this imply that
7 I will have to write a report for the last 3 years I spent in my
8 company, as an apprentice. As a fellow Linux user, I don't want to
9 use that fucking text processor. I love my vim
10 setup, and I want to use it to write that report.
11
12 ## Introduction
13
14 So i came to [LaTeX](http://www.latex-project.org/).
15 Latex (side note: I will not write "LaTeX" everytime in this post.
16 I'm too lazy for that) is a kind of markup language that you can use
17 to write scientific reports, or anything you want in fact.
18
19 It is intelligent in the sense that, you don't have to bother about
20 the formatting on the document, latex will do that for you, and
21 probably better than you. So you can just **focus on what your
22 are typing**.
23
24 Seems interresting huh? So basically, what does it look like? Here's
25 a simple document (download/view it [HERE](http://pub.z3bra.org/monochromatic/misc/la.pdf))
26
27 la.tex
28
29 \documentclass[9pt]{report} % Start of document
30
31 \usepackage[utf8]{inputenc} % Write text unsing UTF-8 encoding
32 \usepackage{graphicx} % Use graphics for diagrams and such
33
34 \title{\LaTeX exemple}
35 \author{z3bra, the cool guy}
36 \date{\today}
37
38 \begin{document}
39
40 \maketitle
41 \tableofcontents
42 \listoftables
43 \listoffigures
44 \newpage
45
46 \chapter{Introduction}
47
48 \section{\LaTeX is fun}
49 Bla bla, latex is cool, and not only in bed.
50 See that explanatory figure to figure out why:
51
52 \begin{figure}[h!]
53 \centering
54 \includegraphics[width=\textwidth]{figure}
55 \caption{Figure caption}
56 \label{fig:figure}
57 \end{figure}
58
59 that might not be the good figure. Anyway...
60
61 \subsection{Love?}
62 Do you love me some \LaTeX?
63
64 \subsection{Llorem ipsum}
65 My money's in that office, right? If she start giving me some bullshit about it
66 ain't there, and we got to go someplace else and get it, I'm gonna shoot you in
67 the head then and there. Then I'm gonna shoot that bitch in the kneecaps, find
68 out where my goddamn money is. She gonna tell me too. Hey, look at me when I'm
69 talking to you, motherfucker. You listen: we go in there, and that nigga Winston
70 or anybody else is in there, you the first motherfucker to get shot. You
71 understand?
72
73 Now that there is the Tec-9, a crappy spray gun from South Miami. This gun is
74 advertised as the most popular gun in American crime. Do you believe that shit?
75 It actually says that in the little book that comes with it: the most popular
76 gun in American crime. Like they're actually proud of that shit.
77
78 Now that we know who you are, I know who I am. I'm not a mistake! It all makes
79 sense! In a comic, you know how you can tell who the arch-villain's going to be?
80 He's the exact opposite of the hero. And most times they're friends, like you
81 and me! I should've known way back when... You know why, David? Because of the
82 kids. They called me Mr Glass.
83
84 \appendix
85 \chapter{Appendix}
86
87 \section{Oh! A table!}
88 \begin{table}[h!]
89 \begin{tabular}{ | l | l | p{5cm} | }
90 % pretty that shit with !column -t -s \& -o \&
91 \hline
92 COLUMN & COLUMN 3 HEADER & DESCRIPTION \\ \hline \hline
93 column & name of something & Description of that, eeh \\ \hline
94 column & name of something & Description of that, eeh \\ \hline
95 column & name of something & Description of that, eeh \\ \hline
96 column & name of something & Description of that, eeh \\ \hline
97 column & name of something & Description of that, eeh \\ \hline
98 column & name of something & Description of that, eeh \\ \hline \hline
99 FOOTER & NAME OF FOOTER & WHO CARES WHAT'S HERE? \\ \hline
100 \end{tabular}
101 \caption{Exemple of a table}
102 \label{tab:table}
103 \end{table}
104
105 \end{document}
106 % vim: ft=tex tw=80 cc=81 nowrap fdm=marker :
107
108
109 Wooow ! That's so many tags for such a simple thing!
110 In fact, once you get used to those tags, they are no more a
111 problem. Also, The more text you have, the less you'll see the tags.
112
113
114 So, now you know HOW latex looks like. But you don't know HOW to
115 write it, and what to do with that file.
116 Don't worry, that ain't difficult.
117
118
119 ## Writing latex
120
121 Latex files basically looks like any source file. First come the
122 definitions, and then the source (document) itself.
123 The definitions are importants because that will tell latex HOW to
124 create the document.
125
126 Latex tags are only a \ followed by a command. If that keyword needs
127 an argument, that argument is given within {}. If that command needs
128 an option, that option is given within []. Seems hard ? It is not.
129 Take a look at this:
130
131 \command[option]{argument}
132 % comments are from % 'til EOL
133
134 Do you get it now ? Then, move on.
135
136 The simplest header would be:
137
138 \documentclass{report}
139
140
141 This will tell to latex that you want to write a report. Latex knows
142 what a report is, so it will apply a set of rules (margin, font
143 size, numerotation of chapters/section, and so on). So you will ONLY
144 have to rewrite the rules you don't like, or that are missing.
145 I'll not cover that in this post, because there are too many way
146 to do so, and you are tall enough to find infos by yourself
147 ;). Latex has a huge wiki, which is
148 great. Use it!
149
150
151 Now, the body. Here to, I will give you the most basic body (eg, not
152 covering figures, or table. The wiki is better than me to that).
153 So, the most simple body is the following:
154
155 \begin{document}
156
157 \chapter{First chapter}
158
159 \section{\LaTeX is fun}
160 My money's in that office, right? If she start giving me some bullshit about it
161 ain't there, and we got to go someplace else and get it, I'm gonna shoot you in
162 the head then and there. Then I'm gonna shoot that bitch in the kneecaps, find
163 out where my goddamn money is. She gonna tell me too. Hey, look at me when I'm
164 talking to you, motherfucker. You listen: we go in there, and that nigga Winston
165 or anybody else is in there, you the first motherfucker to get shot. You
166 understand?
167
168 \section{Middle section}
169 Now that there is the Tec-9, a crappy spray gun from South Miami. This gun is
170 advertised as the most popular gun in American crime. Do you believe that shit?
171 It actually says that in the little book that comes with it: the most popular
172 gun in American crime. Like they're actually proud of that shit.
173
174
175 \chapter{Last chapter}
176
177 \section{Last section}
178 Now that we know who you are, I know who I am. I'm not a mistake! It all makes
179 sense! In a comic, you know how you can tell who the arch-villain's going to be?
180 He's the exact opposite of the hero. And most times they're friends, like you
181 and me! I should've known way back when... You know why, David? Because of the
182 kids. They called me Mr Glass.
183
184 \end{document}
185
186
187 You're still there ? Fine. Now, what should we do with that file ?
188
189
190 ## Compilation
191
192 Yeah, you read it right. You compile a Latex file, because it has to
193 generate many other files in order to understand your whole
194 document.
195 It will have to count yur chapters, sections, subsection, and so on.
196 Then, create a output file which will be formatted, and correctly
197 numeroted, linked to your figures, tables, etc..
198
199
200 So, how does it works ? Taht's easy, just call `latex` on your file to have it
201 compiled.
202
203 latex file.tex
204
205 This command will create a **dvi** file. If you want
206 another format, you you be able to use any other tool to convert it
207 to the fomat you want:
208
209 dvips file.dvi
210 dvipdf file.dvi
211
212 This will create two files: `file.ps`, and `file.pdf` (U DONT SAY?!), that you
213 will be able to view in your prefered PDF viewer. (I suggest
214 [zathura](http://pwmt.org/projects/zathura/), which is able to reload
215 automatically your file if the timestamp have changed)
216
217
218 I here someone in the audience whispering:
219 <q>But, That's a pain !</q>. You are not wrong ! That's why my
220 favorite tool comes to the rescue: `make`.
221 Yes ! Each time you hear or read the word _compilation_, you
222 should instantly think _Makefile_. That's what I did, and it
223 has saved me a lot of time!
224 I could leave it to you as an exercise, but I know that some of you
225 are just lazy. So here is the makefile I came with:
226
227 # File name
228 BASE = la
229
230 # How to view output files
231 VIEWER = zathura
232
233 # Files used for diagrams (umlet file)
234 uxffiles=$(wildcard fig/*.uxf)
235
236 # Those files, with the correct extension for LaTeX
237 figures=$(patsubst %.uxf,%.eps,${uxffiles})
238
239 .SUFFIXES:
240 .SUFFIXES:.ps .pdf .dvi .tex .uxf .eps .toc .lof .lot
241
242 .PHONY: default all dvi ps pdf eps view view-ps view-pdf clean mrproper
243
244 # What should 'make' run by default ?
245 default: ps
246
247 # build everything
248 all: ps pdf view-ps
249
250 # The output files
251 dvi: ${BASE}.dvi
252 ps: ${BASE}.ps
253 pdf: ${BASE}.pdf
254 eps: ${figures}
255
256 # Default view
257 view: view-ps
258
259 # --- DVI ---------------------------------------
260 ${BASE}.dvi: ${figures} ${BASE}.toc ${BASE}.tex
261 @echo "TEX ${BASE}.tex"
262 @latex ${BASE}.tex >/dev/null
263
264 # --- TOC ---------------------------------------
265 ${BASE}.toc: ${figures} ${BASE}.tex
266 @echo "TOC ${BASE}.tex"
267 @latex -draftmode ${BASE}.tex >/dev/null
268
269 # --- EPS ---------------------------------
270 .uxf.eps:
271 @echo "EPS $<"
272 @umlet -action=convert -format=eps -filename=$< >/dev/null
273
274 # --- PS ----------------------------------------
275 .dvi.ps:
276 @echo "PS $<"
277 @dvips -q $<
278
279 # --- PDF ---------------------------------------
280 .dvi.pdf:
281 @echo "PDF $<"
282 @dvipdf -q $<
283
284 # --- OTHER -------------------------------------
285 view-%: ${BASE}.%
286 ${VIEWER} $<
287
288 clean:
289 rm -f *.aux
290 rm -f *.log
291 rm -f *.dvi
292 rm -f *.lof
293 rm -f *.lot
294 rm -f *.toc
295
296 mrproper: clean
297 rm -f fig/*.eps
298 rm -f *.pdf
299 rm -f *.ps
300
301 Easy to use!
302
303 make [dvi|ps|pdf|eps] # build either the dvi/ps/pdf files, or the eps files
304 make [view-ps|view-pdf] # calls ${VIEWER} on either the ps or pdf file
305
306 Maybe... To get the "eps" part, see the [tips section](#tips)
307
308 ## Enjoy !
309
310 There you go, you are now ready to write your own latex documents,
311 and browser the web to find help about what is not explained in
312 this post (there is **A LOT** things about latex..)
313
314 <h3 id='tips'>Tips</h3>
315
316 Before leaving you, here are just a few tips, from my experience
317 with latex (particularly images).
318
319 * Read other documents, there are goldmine out there, and that
320 will help you a lot
321 * Write the skeleton of your file BEFORE the text itself, so you
322 can focus on what you type.
323 * DVI format only support EPS files to render figures, now you're
324 warned..
325 * [UMLet](http://umlet.com/) is a great tool to create
326 diagrams and such. It also include a cli routine to export files
327 to format like pdf/jpg/eps (see the Makefile above)
328 * Latex can also write letter! That's cool isn't it?