Latex - Stuff Every Writer Should Know
Basics
- more advanced stuff can be found in Latex - Stuff for Advanced Writers
- Korrekturlesen: German checklist for proofreading
- a tiny LaTeX template I put together, showing all you need to know to get started
Help
If you want to open the documentation of some package you do not need google, just run
texdoc NAME
in a terminal (Linux) or DOS-prompt (Windows)
Sündenregister
A good starting point is the list of obsolete packages/hacks: Latex Sündenregister
Splitting of your Thesis
You better not try to write your whole thesis in one single tex-file. It helps a lot to split it into several files (e.g. one header file + one file per chapter).
\input{File}
Units of length used in Latex
- em The width of the letter M in the current font
- ex The height of the letter x in the current font
- cm Centimetres
- mm Millimeters
- in Inches
- pt Points (1in = 72.27pt)
- pc Picas (1pc = 12pt)
Furthermore \textwidth and \textheight can be usefull
Text
Language
\usepackage[ngerman]{babel}
Umlaute
%\usepackage[latin1]{inputenc} % Umlaute (Windows) \usepackage[utf8]{inputenc} % Umlaute (Linux)
When writing in German this might be useful:
\usepackage[T1]{fontenc} % Worttrennung von Worten mit Umlauten möglich
Page Borders
\usepackage{geometry} \geometry{left=3cm,textwidth=15cm,top=3cm,textheight=23.5cm} % A4: 21cm x 29.7cm
Paragraph separator: vertical space instead of horizontal offset
By default Latex separates paragraphs (indicated by an empty line in the source code) not by a vertical offset as it might be expected (and what is the standard in German language) but by inserting a horizontal offset before the first word of the new paragraph (as it is common in novels). In order to change this behavior to the "German" way do the following:
% Separate paragraphs by an empty line instead of intending the line \setlength{\parskip}{2ex plus0.5ex minus0.3ex} \setlength{\parindent}{0pt}
Nicer way using KOMA documentclass
\documentclass[ ,parskip=half- % false, full, half, with -+* behind as modifier ]{scrbook} % KOMA: scrartcl, srcreprt, srcbook, scrlttr2
Abbreviations
When using abbreviations (like e.g., et al. etc. z.B. ...) Latex treats the "." as end of sentence and inserts larger space. This is compensated by "\ " or \xspace
asdf e.g.\ asdf asdf e.g.\xspace asdf
I advice defining a newcommand for each commonly used abbreviation
\newcommand{\eg}[0]{\mbox{e.g.}\xspace} % lat: exempli gratia ; EN: for example ; DE: zum Beispiel, z.B. asdf \eg asdf
Gänsefüßchen
DE: "`asdf"' (requires \usepackage[ngerman]{babel}) EN: ``asdf
Hyphenation (Silbentrennung)
\hyphenation{ % tells Latex where it is allowed to split a word (or not) ein % = do not split this word! Größen-ver-tei-lung Ins-ti-tut mag-ne-tisch }
Reduce Hyphenation:
\lefthyphenmin=4 \righthyphenmin=4
require at least 4 chars before and after hyphenation
Prevent Overfull Lines
see l2tabu.pdf
\tolerance 1414 \hbadness 1414 \emergencystretch 1.5em \hfuzz 0.3pt \widowpenalty=10000 \vfuzz \hfuzz \raggedbottom
Math
Comma vs. Point
Latex handles commas different from (decimal) points. After a comma a little space in inserted. Compare the following in Latex:
$1234.5678$ $1234,5678$
In the web you find several workarounds for this problem, but they might easily generate new problems when interacting with other packages, so it might be safer to use only dots instead. If you do so, you should put a note at the beginning of your thesis, telling that you do not stick to the German standard due to technical issues.
Words in Subscripts
When writing words in subscripts use \text{} to prevent the letters from being printed in italics like variables:
- Use this: $E_\text{Photon}$ (looks similar to this: <math>E_\mbox{Photon}</math>)
- And not this: $E_{Photon}$ (looks similar to this: <math>E_{Photon}</math>)
Symbols
Detexify is a nice web tool that allows you to draw a symbol and than suggests which latex symbol you are looking for
MathBin
MathB.in allows to generate and share latex math snippets, interesting when discussing some stuff via email etc..
Variables and Units
Variables are typeset in italics (DE: kursiv) units not!
There is a small space between number and unit (achieved by "\,")
The length L=10cm % wrong The length $L=10cm$ % wrong The length $L=10$cm % better The length $L=10\,$cm % correct but too complicated
In equations or longer math expressions the following can be used
\usepackage{amsmath} ... The length $L=10\,\text{cm}$ % same as above
The package siunitx is quite some help
\usepackage[noload={abbr}]{siunitx} ... $L=\SI{10}{\centi\meter}$ % same result as above, but nicer % or even shorter: \usepackage[load={abbr}]{siunitx} % this time we load the abbreviations like \cm -> \centi\meter ... $L=\SI{10}{\cm}$ % same result as above
This suggests defining custom commands for commonly used units like
\newcommand{\ucm} [1] {\SI{#1}{\centi\meter}} The length $L=\ucm{10}$ % gives the same as above and is very compact, yeah! (ucm for UnitCentiMeter)
For a more advanced hack see variable+number+unit
Update 2017 by Karla R.
Page Borders (\usepackage{geometry})
Das geometry paket sollte man als unbedarfter Nutzer nicht benutzen, da es die diffizile Seitengeometrie plump mit einfachen Werten überschreibt. Stattdessen arbeitet man lieber in den optionalen Argumenten für die Komaklassen mit den Variablen DIV und BOR (Dokumentation in den Komadokumentationen).
Create your own personal Bibtex style
Mittlerweile gibt es das Paket biblatex (Biber), welches statt bibtex verwendet werden sollte. Es funktioniert ein stückweit anders. Ich hab mit beiden gearbeitet und finde biblatex tatsächlich angenehmer zu benutzen.
Reuse old equation number
Wenn man eine Gleichung mit einer eigenen Nummerierung (Tag) versieht, um z.B. eine vorher verwendete Gleichung erneut zu nennen, ist es sinnvoll, die automatische Nummerierung in der Gleichung auszuschalten. Also lieber \begin{align*} bla... oder die Zeile mit einer \nonumber versehen.
Nicer Tables – insbesondere mit Zahlen
Hier gibt es eine sehr elegante Lösung, und zwar mit dem Paket booktabs (was ich sehr empfehlen kann für alle Tabellen, insbesondere gut ist auch die Dokumentation zum Paket). Das sieht dann so aus:
\begin{tabular}{lS} % S für Zahlen (weitere Optionen sind in der Dokumentation, entweder von booktabs oder siunitx zu finden) \toprule parameter & {value} \\ % value hat eine Klammer, dann erkennt Latex den Wert an, auch wenn es kein Zahlenwert ist. \midrule a & 2.4e19 \\ b & 1 \\ c & 3.45612 \\ d & 605410.154 \\ \bottomrule \end{tabular}
Latex setzt alle Punkte untereinander. Zugegeben, in der Tabelle sieht das jetzt echt unruhig aus, aber im Normalfall hat man ja nicht vier Zeilen mit vier so unterschiedlichen Zahlenformaten.
Es geht auch ohne manuelle Setzung des Zählers mittels: \begin{tabular} … \footnotemark … \end{tabular} \footnotetext{hier steht der Text}. Ich glaube mich zu erinnern, dass der footnotetext nach der footnotemark stehen sollte, damit der Zähler richtig zählt. Vielleicht is das auch das Problem in deinem Beispiel, da kommt ja auch der Text vor dem Verweis.