LATEX

Markus Kuhn CTAN lion drawing by Duane Bibby

Computer Laboratory, University of Cambridge

https://www.cl.cam.ac.uk/teaching/1920/TeX+MATLAB/

-slides-2up.pdf 2019-11-25 11:24 d9ebfb5 1

LATEX – a document formatter

LATEX: a macro package for the TEX(τχ, “tech”) typesetting system I excellent facilities for mathematical notation I de-facto standard for preparing scientific publications in mathematical, physical, computing and engineering disciplines

History: Donald Knuth (Stanford CS) developed TEX in mid 1970s in SAIL to typeset his “Art of Computer Programming” books, reimplemented it in Pascal in the mid 1980s (WEB, literate programming), was later ported to C. Leslie Lamport (SRI, DEC) wrote LATEX in early 1980s. Both now community maintained as TEX Live open-source distribution. Classic processing steps: Modern alternative: g1.eps g2.eps g1.pdf g2.jpg @@R © @@R © latex dvips ps2pdf pdflatex f. f.dvi f.ps f.pdf f.tex f.pdf −→ −→ −→ −→

These slides: prepared using the LATEX beamer class.

2 LATEX – resources Recommended introduction Leslie Lamport: LATEX – a document preparation system. 2nd ed., Addison-Wesley, 1994. (CL library) Installation Debian Linux: apt-get install texlive macOS: http://www.tug.org/mactex/ Windows: https://miktex.org/ http://www.tug.org/protext/ More documentation Online tutorials: https://www.latex-project.org/help/ TEX Frequently Asked Questions list: https://texfaq.org/ For advanced users: Mittelbach, et al.: The LATEX Companion. 2nd ed., Addison-Wesley, 2004. 3

LATEX – features and benefits

I Most popular mathematical typesetting language (subset imitations now also in: Word, MathJax, MediaWiki, etc.) I Encourages logical markup helps to maintain consistent style ⇒ I Plain-text source easy to collaborate via version-control systems ⇒ I Command-line tool easy to automate build (make) ⇒ I Use any plain-text editor you like (Emacs, vi, TeXworks, Word, etc.) I Robust for large, complex documents (PhD thesis, books, etc.) I Highly extensible (a Turing-complete macro programming language) vast collection of add-on packages for special 1 e4 e5 2 Nf3 Nc6 3 Bb5 typesetting⇒ needs (figures, logic proofs, pseudo 8 rZblkans 7 opopZpop code, circuit diagrams, flow charts, chemical for- 6 0ZnZ0Z0Z mulae, slides, chess positions, etc.) 5 ZBZ0o0Z0 \usepackage[skaknew]{skak} 4 0Z0ZPZ0Z \newgame 3 Z0Z0ZNZ0 \mainline{1.e4 e5 2. Nf3 Nc6 3.Bb5} 2 POPO0OPO \showboard 1 SNAQJ0ZR I Computer Modern, etc. free font families a b c d e f g h ⇒ Mature, free, portable, open source, used by many science publishers I 4 LATEX example

\documentclass[12pt]{article} \setlength{\textwidth}{75mm} TEX – a summary \begin{document} \title{\TeX\ -- a summary} Markus G. Kuhn \author{Markus G.~Kuhn} \date{11 October 2019} 11 October 2019 \maketitle \thispagestyle{empty}

\section{Introduction} 1 Introduction

Mathematical formul\ae\ such as Mathematical formulæ such as eiπ = 1 $e^{i\pi} = -1$ or even or even − \[ \Phi(z) = \frac{1}{\sqrt{2\pi}} x 1 1 x2 \int_0^x e^{-\frac12 x^2} \] Φ(z)= e− 2 were a real `pain' to typeset until √2π Z0 \textsc{Knuth}'s text formatter \TeX\ became available \cite{Knuth86}. were a real ‘pain’ to typeset until Knuth’s text formatter TEX became available [1]. \begin{thebibliography}{9} \bibitem{Knuth86}Donald E. Knuth: The \TeX book. Ad\-dison-Wesley, 1986. References \end{thebibliography} [1] Donald E. Knuth: The TEXbook. Ad- \end{document} dison-Wesley, 1986.

5

TEXworks GUI IDE

TEXworks is a LATEX editor that shows source text and PDF output side by side and makes it easy to navigate between them:

6 TEX input syntax

I TEX reads plain-text *.tex files (e.g., prepared with emacs) I no distinction is made between space character and line feed I multiple spaces are treated like a single space I empty lines act as paragraph separator (just like the \par command) I command, macro and variable names start with a backslash (\), followed by either a sequence of letters or a single non-letter character (uppercase/lowercase is significant). Correct: \par, \item, \pagethree, \LaTeX, \+, \\, \3 Wrong: \page33, \<> I space and line-feed characters are ignored if they follow a command/macro/variable name consisting of letters. Use \ to add an explicit space (e.g., \TeX\ syntax TEX syntax). ⇒

7

Characters with special semantics

In *.tex input files, the following are meta characters (part of syntax): # $ % & ~ _ ^ \ { } #$%& ˆ can be included in regular text using the macros {} \# \$ \% \& \_ \^ \{ \} Otherwise: % starts a comment # macro parameter ~ no-break space & tabulator mark $ delimits inline equations \ macro prefix, \\ line separator ^ superscript _ subscript (in math mode) { begin group } end group Comments: All characters between (and including) a % and the next line feed will be ignored. Append % at the end of a line to avoid interpretation of the subsequent line feed as a space. One could also insert \ and ˜ as \textbackslash and \textasciitilde. But this is rarely ever done. The ASCII characters \ ˜`{} are not typically used in regular text. They are common in computing-related strings (identifiers, source code, path names, URLs, etc.), for which it is customary to use a fixed-width typewriter font. There use the verbatim environment or the macro \verb+...+, which typeset all ASCII characters in typewriter font, or \url{...} for URLs. 8 Grouping

The curly braces { and } serve two purposes in TEX: I Lexical scope: a { saves current state on a stack and } restores it, therefore state changes (e.g., font switch, variable assignment) inside a { ... } group last only until the }: This is a {\bfseries bold} statement.

This is a bold⇓ statement. I Commands and macros read for each argument either a single character or a group enclosed by { and }: Typeset \textbf M in \textbf{boldface}.

Typeset M ⇓in boldface.

LATEX macros can have optional arguments, which are enclosed by [ ... ]: \makebox[80mm][c]{this is centered in a box 80 mm wide}

9

Changing font style manually

Declaring shape, series, family (each independently): \mdseries Medium series \upshape Upright shape \bfseries Boldface series \itshape Italic shape \rmfamily Roman family \slshape Slanted shape \sffamily Sans-serif family \scshape Small caps shape \ttfamily Typewriter family \normalfont Normal style Corresponding commands that change the style only for their argument: \textmd{text} \mdseries \textup{text} \upshape \textbf{text} \bfseries \textit{text} \itshape \textrm{text} \rmfamily \textsl{text} \slshape \textsf{text} \sffamily \textsc{text} \scshape \texttt{text} \ttfamily \textnormal{text} \normalfont Change type size: \tiny \small \large \huge \scriptsize \normalsize \Large \Huge \footnotesize \LARGE For style consistency: use such low-level font commands only exceptionally (e.g., title pages, special notations). Otherwise leave any font adjustments to higher-level semantic commands such as \emph{text} or \section{heading}. 10 Typewriting versus typesetting

The ASCII (ISO 646) 7-bit character set has only 94 graphic characters: !"#$%&'()*+,-./0123456789:;<=>? @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ `abcdefghijklmnopqrstuvwxyz{|}~ They were chosen to cover the character repertoire of US typewriters and teletype printers. The standards committee added a few more symbols ([\]{|}_) in the hope that they will be useful for programming. TEX defines a number of shortcuts and macros to access the much larger set of of “typographic” characters used by book printers. These typographic characters still cannot be found on standard PC keyboard layouts, which were designed for 7-bit ASCII.

11

0000 C0 Controls and Basic Latin0080 C1007F Controls and Latin-1 Supplement2000 00FF General Punctuation 206F

000 001 002 003 004 005 006 007 008 009 00A 00B 00C 00D 00E 00F 200 201 202 203 204 205 206

0    0 @ P ` p 0    ° À Ð à ð 0  ‐ † ‰ ⁀ ⁐  0000 0010 0020 0030 0040 0050 0060 0070 0080 0090 00A0 00B0 00C0 00D0 00E0 00F0 2000 2010 2020 2030 2040 2050 2060

1   ! 1 A Q a q 1   ¡ ± Á Ñ á ñ 1   ‡ ‱ ⁁ ⁑  0001 0011 0021 0031 0041 0051 0061 0071 0081 0091 00A1 00B1 00C1 00D1 00E1 00F1 2001 2011 2021 2031 2041 2051 2061

2   " 2 B R b r 2   ¢ ² Â Ò â ò 2  ‒ • ′ ⁂ ⁒  0002 0012 0022 0032 0042 0052 0062 0072 0082 0092 00A2 00B2 00C2 00D2 00E2 00F2 2002 2012 2022 2032 2042 2052 2062

3   # 3 C S c s 3   £ ³ Ã Ó ã ó 3  – ‣ ″ ⁃ ⁓  0003 0013 0023 0033 0043 0053 0063 0073 0083 0093 00A3 00B3 00C3 00D3 00E3 00F3 2003 2013 2023 2033 2043 2053 2063

4   $ 4 D T d t 4   ¤ ´ Ä Ô ä ô 4  — ․ ‴ ⁄ ⁔  0004 0014 0024 0034 0044 0054 0064 0074 0084 0094 00A4 00B4 00C4 00D4 00E4 00F4 2004 2014 2024 2034 2044 2054 2064

5   % 5 E U e u 5   ¥ μ Å Õ å õ 5  ― ‥ ‵ ⁅ ⁕ 0005 0015 0025 0035 0045 0055 0065 0075 0085 0095 00A5 00B5 00C5 00D5 00E5 00F5 2005 2015 2025 2035 2045 2055

6   & 6 F V f v 6   ¦ ¶ Æ Ö æ ö 6  ‖ … ‶ ⁆ ⁖  0006 0016 0026 0036 0046 0056 0066 0076 0086 0096 00A6 00B6 00C6 00D6 00E6 00F6 2006 2016 2026 2036 2046 2056 2066

7   ' 7 G W g w 7   § · Ç × ç ÷ 7  ‗ ‧ ‷ ⁇ ⁗  0007 0017 0027 0037 0047 0057 0067 0077 0087 0097 00A7 00B7 00C7 00D7 00E7 00F7 2007 2017 2027 2037 2047 2057 2067

8   ( 8 H X h x 8   ¨ ¸ È Ø è ø 8  ‘  ‸ ⁈ ⁘  0008 0018 0028 0038 0048 0058 0068 0078 0088 0098 00A8 00B8 00C8 00D8 00E8 00F8 2008 2018 2028 2038 2048 2058 2068

9   ) 9 I Y i y 9   © ¹ É Ù é ù 9  ’  ‹ ⁉ ⁙  0009 0019 0029 0039 0049 0059 0069 0079 0089 0099 00A9 00B9 00C9 00D9 00E9 00F9 2009 2019 2029 2039 2049 2059 2069

A   * : J Z j z A   ª º Ê Ú ê ú A  ‚  › ⁊ ⁚  000A 001A 002A 003A 004A 005A 006A 007A 008A 009A 00AA 00BA 00CA 00DA 00EA 00FA 200A 201A 202A 203A 204A 205A 206A

B   + ; K [ k { B   « » Ë Û ë û B  ‛  ※ ⁋ ⁛  000B 001B 002B 003B 004B 005B 006B 007B 008B 009B 00AB 00BB 00CB 00DB 00EB 00FB 200B 201B 202B 203B 204B 205B 206B

C   , < L \ l | C   ¬ ¼ Ì Ü ì ü C  “  ‼ ⁌ ⁜  000C 001C 002C 003C 004C 005C 006C 007C 008C 009C 00AC 00BC 00CC 00DC 00EC 00FC 200C 201C 202C 203C 204C 205C 206C

D   - = M ] m } D    ½ Í Ý í ý D  ”  ‽ ⁍ ⁝  000D 001D 002D 003D 004D 005D 006D 007D 008D 009D 00AD 00BD 00CD 00DD 00ED 00FD 200D 201D 202D 203D 204D 205D 206D

E   . > N ^ n ~ E   ® ¾ Î Þ î þ E  „  ‾ ⁎ ⁞  000E 001E 002E 003E 004E 005E 006E 007E 008E 009E 00AE 00BE 00CE 00DE 00EE 00FE 200E 201E 202E 203E 204E 205E 206E

F   / ? O _ o  F   ¯ ¿ Ï ß ï ÿ F  ‟  ‿ ⁏   000F 001F 002F 003F 004F 005F 006F 007F 008F 009F 00AF 00BF 00CF 00DF 00EF 00FF 200F 201F 202F 203F 204F 205F 206F The Unicode Standard 9.0, Unicode Inc., http://www.unicode.org/charts/ The Unicode Standard 12.1, CopyrightThe Unicode © 1991-2019 Standard Unicode, 12.1, Copyright Inc. All rights © 1991-2019 reserved. Unicode, Inc. All rights reserved.The Unicode Standard 12.1, Copyright © 1991-2019 Unicode, Inc. All rights reserved. 12 Dashes ASCII provides only a single combined hyphen-minus character, but typesetters distinguish carefully between several dash characters:

- - hyphen U+002D ⇒ -- – en dash U+2013 ⇒ --- — em dash U+2014 ⇒ $-$ minus U+2212 ⇒ − The hyphen (-) is the shortest of these and is used to combine separate words or split words across line-breaks. The en dash (–) is often used to denote a range of numbers (as in pages 64–128), or – as in this example – as a punctuation dash. The em dash is used—like this—as a punctuation dash, often without surrounding space, especially in US typography. The minus ( ) is a mathematical operator, whose shape matches the plus (+), unlike− the hyphen or dashes. Compare: -+, –+, —+, +. −

13

Quotation marks Typewriters and ASCII offer only undirectional 'single' and "double" quotation marks, while typesetters use ‘curly’ and “directed” variants.

TEX input files use the single quotation mark (') and the grave accent (`) to encode these, as well the mathematical ‘prime’ marker and the French accents:

` ‘ left quote U+2018 ⇒ ' ’ right quote U+2019 ⇒ `` “ left doublequote U+201C ⇒ '' ” right doublequote U+201D ⇒ 0 $'$ prime U+2032 ⇒ \'u ´u acute accent U+00B4 ⇒ \`u `u grave accent U+0060 ⇒ The apostrophe (it’s) is identical to the right single quotation mark. In some older terminal fonts (especially of US origin), the ` and ' characters have a compromise shape somewhere between the quotation marks ‘’ and the accents `´.

14 Non-ASCII Symbols

¡ !` A˚ \AA ¶ \P ¿ ?` ø \o „ \dag œ \oe Ø \O \ddag Œ \OE l \l © \copyright æ \ae L \L £ \pounds Æ \AE ß \ss ... \ldots ˚a \aa § \S

Combining characters

´o \'o ¯o \=o oo \t{oo} `o \`o ˙o \.o ¸o \c{o} ˆo \^o ˘o \u{o} o. \d{o} ¨o \"o ˇo \v{o} o \b{o} ¯ ˜o \~o ˝o \H{o}

15

Space – the final frontier Traditional English typesetting inserts a larger space at the end of a sentence. TEX believes any space after a period terminates a sentence, unless it is preceded by an uppercase letter. Parenthesis are ignored. This works often: J. F. Kennedy’s U.S. budget. Look! But not always: E.g. NASA. Dr. K. Smith et al. agree. To correct failures of this heuristic, use ~ no-break space \ ⇒ force normal space \@ ⇒ following punctuation ends sentence ⇒ as in E.g.\ NASA\@. Dr.~K. Smith et al.\ agree.

E.g. NASA. Dr. K.⇓ Smith et al. agree. Or disable the distinction of spaces with \frenchspacing.

16 Structure of a LATEX document First select a document class and its options, e.g. with \documentclass[12pt,a4paper]{article} Standard classes: article, report, book, letter, slides.

Publishers often provide authors with their own class as a *.cls file. Appendix A of The LATEX Companion explains how to write new class files. A popular class for presentation slides: beamer Environment: group delimited by \begin{name} and \end{name}, e.g. \begin{document} ... \end{document} Common environments: abstract, center, verbatim, itemize, enumerate, quote, tabular, equation,... Mark headings with \section{...} \subsubsection{...} \subsection{...} \paragraph{...} and LATEX will take care of font sizes, numbering, and table of contents. 17

LATEX list environments \begin{itemize} Mammals \item Mammals • \begin{itemize} – Dogs \item Dogs – Ponys \item Ponys Insects \end{itemize} • \item Insects + . . . \item[+] \ldots \end{itemize} \begin{enumerate} 0. Fruits \setcounter{enumi}{-1} \item Fruits (a) Apples \begin{enumerate} (b) Cucumbers \item Apples \item Cucumbers\label{c} 1. Veggies (see also 0b) \end{enumerate} 2. . . . \item Veggies (see also \ref{c}) \item \ldots \end{enumerate}

Package enumitem adds many configuration options to these environments. (texdoc enumitem) 18 Verbatim text: quoting source code

Lines of source code: the verbatim environment disables all meta characters, uses a typewriter font and preserves space and line feed: \begin{verbatim} $initial = substr($record->{'name'}, 0, 1); \end{verbatim} Do not indent a verbatim block (prints all whitespace). Keep \end{verbatim} on its own line. Source code with math mode: alltt (\usepackage{alltt}) is similar to verbatim, but keeps the meta characters \{}, so you can still switch fonts and typeset mathematical expressions: \begin{alltt} for i := 1, . . . , n 2 for \(i:=1,\ldots,n\) print xi print \(x\sb{i}\sp{2}\) \end{alltt} Inline strings: use \verb+text+ to quote text inside a paragraph, where + is any character that does not occur in text. This also disables meta characters, preserves whitespace, and switches to a typewriter font. You can’t use \verb in command arguments, use \texttt{text} there instead. The \verb*+text+ variant prints spaces as . Fix single quotation mark: \usepackage{upquote}. 19

Tweaking and extending LATEX

LATEX behaviour can be changed by overwriting predefined variables and macros. This can be done

I in the preamble (between the \documentclass{... } and \begin{document} lines) ⇒ for the entire document I anywhere in the document ⇒ the effect will last only until the end of the current group (i.e., the next } or \end{... })

Packages

A huge collection of extension packages exists for LATEX. Some merely define additional macros and environments, others rewrite parts of LATEX’s internal machinery. For example, adding to the preamble \usepackage{hyperref} loads all the macros and settings defined in the hyperref.sty package. hyperref adds new marcros, such as \url{... } for typesetting URLs, but also automatically turns every reference to a page, section, or bibliographic entry into a hyperlink. Documentation: texdoc packagename e.g. texdoc geometry

20 Example: changing page layout geometry

Adjust margins manually, via numerous length variables: \setlength{\oddsidemargin}{-0.4mm} % 25 mm left margin \setlength{\evensidemargin}{\oddsidemargin} \setlength{\textwidth}{160mm} % 25 mm right margin \setlength{\topmargin}{-5.4mm} % 20 mm top margin \setlength{\headheight}{5mm} \setlength{\headsep}{5mm} \setlength{\footskip}{10mm} \setlength{\textheight}{237mm} % 20 mm bottom margin More comfortable: \usepackage[vmargin=20mm,hmargin=25mm]{geometry} The geometry.sty package automatically recalculates any dimensions not specified.

Make paragraphs not indented at the first line, but spaced apart slightly: \setlength{\parindent}{0mm} \setlength{\parskip}{\medskipamount} Or just: \usepackage{parskip}

21

Mathematical typesetting

In TEX, mathematical formulas are formatted in a completely different mode from that used for normal text.

Inline formulas such as an ($a_n$) that appear as part of a normal paragraph have to be surrounded with $... $ or \(... \), while \[... \] produces a displayed formula, such as

Fn = Fn−1 + Fn−2 \[ F_n = F_{n-1} + F_{n-2} \]

In math mode

I space characters are ignored; TEX adds its own space around operators based on heuristics; manually add thinspace with “\,” I a special math italic font is used, with different inter-character spacing, designed for single-letter variables concatenated in products I many additional macros for special symbols are defined Math italic is very different and not suitable for writing words or units! Use \mathrm{... } around words, as in $v_\mathrm{diff}$ → vdiff . Macros for common function symbols (constants: upright font!):

max{log2(cos x)} $\max_{x\in\mathbb{R}}\{\log_2(\cos x)\}$ x∈R

Macros for neatly aligning multiple equations: \usepackage{amsmath}, see texdoc amsldoc. 22 Mathematical symbols

Greek letters

Γ \Gamma δ \delta π \pi ∆ \Delta  \epsilon $ \varpi Θ \Theta ε \varepsilon ρ \rho Λ \Lambda ζ \zeta % \varrho Ξ \Xi η \eta σ \sigma Π \Pi θ \theta ς \varsigma Σ \Sigma ϑ \vartheta τ \tau Υ \Upsilon ι \iota υ \upsilon Φ \Phi κ \kappa φ \phi Ψ \Psi λ \lambda ϕ \varphi Ω \Omega µ \mu χ \chi α \alpha ν \nu ψ \psi β \beta ξ \xi ω \omega γ \gamma o o

23

Mathematical symbols

Binary operators

\pm C \lhd \oplus ± \mp \cap ⊕ \ominus ∓ \setminus ∩ \cup \otimes \ \cdot ∪ \uplus ⊗ \oslash · \times ] \sqcap \odot × \ast u \sqcup \dagger ?∗ \star t \wr † \ddagger \diamond o \bigcirc ‡ \amalg  \circ \rhd q \unlhd ◦ B E \bullet \vee D \unrhd • \div ∨ \wedge ÷ ∧ / \triangleleft \bigtriangleup . \triangleright 4 \bigtriangledown 5

24 Mathematical symbols

Relations

\leq \geq \equiv ≤ \prec ≥ \succ ≡ \sim ≺ \preceq \succeq ∼ \simeq  \ll  \gg ' \asymp  \subset  \supset  \approx ⊂ ⊃ ≈ \subseteq \supseteq ∼= \cong ⊆ \sqsubseteq ⊇ \sqsupseteq ./ \bowtie v \in w \ni \propto ∈ \vdash 3 \dashv ∝= \models . ^` \smile a \mid |= \doteq _ \frown | \parallel \perp k ⊥ @ \sqsubset A \sqsupset on \Join < \not< = \not= > \not> 6 \not\leq 6 \not\geq 6 \not\equiv 6≤ \not\prec 6≥ \not\succ ...6≡ 6≺ 6 25

Mathematical symbols

Arrows

\leftarrow \Longleftrightarrow ← \Leftarrow ⇐⇒ \longmapsto ⇐ \rightarrow 7−→, \hookrightarrow → \Rightarrow *→ \rightharpoonup ⇒ \leftrightarrow + \rightharpoondown ↔ \Leftrightarrow \leadsto ⇔ \mapsto \uparrow 7→- \hookleftarrow ↑ \Uparrow ←( \leftharpoonup ⇑ \downarrow ) \leftharpoondown ↓ \Downarrow ⇓ \rightleftharpoons \updownarrow \longleftarrow l \Updownarrow ←−= \Longleftarrow m \nearrow ⇐ \longrightarrow % \searrow =−→ \Longrightarrow & \swarrow ⇒ \longleftrightarrow . \nwarrow ←→ - 26 Mathematical symbols

\aleph \prime \forall ℵ 0 ∀ ~ \hbar \emptyset \exists ı \imath ∅ \nabla ∃ \neg  \jmath √∇ \surd ¬[ \flat ` \ell \top \ \natural ℘ \wp > \bot ] \sharp \Re ⊥ \| \clubsuit < k ♣ \Im ∠ \angle \diamondsuit =∂ \partial \triangle ♦ \heartsuit \infty 4 \backslash ♥ \spadesuit ∞ \ ♠  \Box ♦ \Diamond . . ... \ldots \cdots . \vdots .. \ddots ···

Use \ldots in a, b, . . . , z, but \cdots in a + b + + z. Never write ... ···

27

Large operators and delimiters

\sum \bigcap \bigodot \prod \bigcup \bigotimes P \coprod T \bigsqcup J \bigoplus Q \int S \bigvee N \biguplus ` \oint F \bigwedge L R W U n−1 n−1 TheseH appear smaller inlineV than in displayed equations: 0 vs 0 [ \lbrack ] \rbrack Q Y \lfloor \rfloor b \lceil c \rceil d \lbrace e \rbrace { \langle } \rangle [[h [\![ ]]i ]\!] \langle\!\langle \rangle\!\rangle hh ii \left( and \right) grow delimiters to the height of what they enclose: ∞ xi \left( \sum_{i=0}^\infty x^i \right) i=0 ! X 28 Mathematical symbols

Alternative names

= \ne \{ \owns \vert =6 \neq { \} 3 \land | \Vert 6 \le } \to ∧ \lor k ≤ \ge → \gets ∨ \lnot ≥ ← ¬ Stacking things b a a^{b} ab a_{b}

a b \overline{a-b} a b \overbrace{a-b} − − a b \underline{a-b} az }| {b \underbrace{a-b}_c − − c =\left\{\begin{array}{cl} 2 | {z } 22 = a , a 0 a^{2^{2^2}}, & a \ge 0 \\ 1 ≥ -\frac{1}{a}, & a < 0 ( a , a < 0 − \end{array}\right. 29

Including graphics

DVI only supports characters and filled rectangles, but dvips and pdftex also understand embedded “special” instructions that provide more. Embedded PostScript (EPS) vector graphics: Normal PostScript files (*.ps) produce a sequence of pages. An EPS file describes only an image and is meant to be included into a PostScript page. EPS files lack instructions to output paper, but define a rectangular “bounding box”, using special %%BoundingBox: comments. Load the graphicx extension of LATEX by adding \usepackage{graphicx} to the preamble. Then write \includegraphics{filename.eps} wherever you want to include the graphics file into your text. In pdflatex, the graphicx package allows you to include graphics from PDF (vector graphics), JPEG (photos) and PNG (bitmap) files: \includegraphics{filename.pdf} 30 Postscript/PDF graphics facilities

Applying coordinate transforms: The graphicx package provides access to the geometric transform capabilities of the PostScript and PDF languages: \scalebox{0.8}{\includegraphics{diagram.pdf}} \includegraphics[height=60mm]{screenshot.png} \includegraphics[width=0.9\linewidth]{photo.jpg} \resizebox{190mm}{60mm}{becomes 19 cm $\times$ 6 cm large} \resizebox{190mm}{!}{this becomes 19 cm wide} \rotatebox{180}{this is upside down!}

Changingcolours: The color package also uses Postscript/PDF special commands: This text is \textcolor{red}{printed in red} if ... This text is printed in red if you include \usepackage{color}. Default: \definecolor{red}{rgb}{1,0,0}

31

Figures and references

Larger diagrams interfere with page breaking. They are best placed into a figure environment, such that LATEX can move them around. Example: \begin{figure} \includegraphics[width=0.6\linewidth]{photo.jpg} \caption{This photograph shows the experimental setup.} \label{fig:expsetup} \end{figure} The automatically assigned figure number can be quoted as in: See also Figure~\ref{fig:expsetup} (page~\pageref{fig:expsetup}). The \label{...} command can also be used after \section{...}, \subsection{...}, etc. and inside \begin{equation} ... \end{equation} to assign symbolic names to section and equation numbers, which can then be resolved via \ref{...} or \pageref{...}. No need to manually renumber figures, sections, or equations!

32 Build tools for LATEX

To make sure \label references and tables of contents use the correct numbers, it may be necessary to call latex twice. It will output “Rerun to get cross-references right” in this case. The following implicit Makefile rule takes care of this: .DELETE_ON_ERROR:

%.pdf %.aux %.idx: %.tex pdflatex $< while grep 'Rerun to get ' $*.log ; do pdflatex $< ; done

An alternative is the “latexmk” tool, which automatically determines dependencies (e.g. from \includegraphics) and recompiles LATEX documents where file modification timestamps indicate that this is necessary.

33

Graphics editor xfig

I Its *.fig files have a simple plain-text format that can be edited manually, script generated, and leads to useful diffs. I Can export *.eps or *.pdf files I Can also produce figures in which LATEX is used to fill in all the text. This provides math mode, macros, symbols, references, fonts that match the main text, etc. Ask xfig to export a *.pstex + *.pstex_t file pair. The *.pstex file lacks the text parts of the figure. The *.pstex_t file contains LATEX commands that first load the *.pstex image, and then add all the text in the figure. Select the “special text” mode in xfig to enable LATEX metacharacters. Use \include{*.pstex_t} to add such a figure in your document. (PDF equivalent: *.pdftex + *.pdftex_t) I Command-line export tool (e.g., for Makefile): fig2dev %.eps: %.fig fig2dev -L eps $< $@ %.pstex %.pstex_t: %.fig fig2dev -L pstex_t -p $*.pstex $< $*.pstex_t fig2dev -L pstex $< $*.pstex %.pdftex %.pdftex_t: %.fig fig2dev -L pdftex_t -p $*.pdftex $< $*.pdftex_t fig2dev -L pdftex $< $*.pdftex Other graphics tools: TikZ, pnmtops, Inkscape, MATLAB, R, gnuplot, Python+matplotlib 34 Bibliographic references

Academic writing: detailed references to prior work I to support arguments I to document familiarity with the field I to help newcomers to the field I to give due academic credit I to join the bibliometric graph of the field (recommendation systems) I to trigger notifications to cited authors (e.g. Google Scholar alerts) A bibliographic reference needs to contain all information needed to help readers (and increasingly search engines!) to unambiguously identify and locate the text referred to. Minimum: First two authors, full title, date, indication of type of publication (usually implicitly via other details).

Inter-library loan required many details: names and location of publishers or the volume, issue and page numbers in printed journals. Today, most readers retrieve scientific publications (with the exception of books) digitally, so online identifiers such as URIs or DOIs are more important instead.

Many URLs (e.g., to author’s home pages, “grey literature”) do not last long, but can still later be retrieved via archival services (e.g., archive.org). Therefore: accompany URLs with the date on which you accessed them. Try to HTTP redirect your own URLs when moving web space.

35

Bibliographic references – styles

Four widely used styles: I short-title – most common in books on humanities, e.g. “Hart, Hart’s Rules, p. 52” I author-date – most common in science and social science, e.g. “Goossens (1997)” or “(Goossens, 1997b)”. I author-number – follows the name of the author(s) with a per-author number (rare with LaTeX), e.g. “Goossens (2)” I number-only – all publications sequentially numbered in bibliography, made popular by LATEX, now very widely used in computer science, e.g. “[67]”. Collect full references at the end of the document (bibliography), each chapter, or page of first mention (footnotes). With number-only bibliography: for important work, include author(s) name and year in first mention in the text. Avoid abusing numerical references like a noun (bad: “as shown by [17]”, nice: “as Knuth showed in 1988 [17]”). When referencing books, also include a chapter or page number.

36 Bibliographic references – manual approach

LATEX can also manage numerical references to a bibliography. Append near the end of your document (usually after conclusions and before appendices) your list of bibliographic items, assigning each an alphanumeric identifier: \begin{thebibliography}{9}

\bibitem{Lamport94} Leslie Lamport: \LaTeX\ -- A document preparation system : User's guide and reference manual. Addison-Wesley, 1994.

\bibitem{Companion} Frank Mittelbach, Michael Goossens: The \LaTeX\ Companion. Second edition, Addison Wesley, 2004.

\bibitem{Dup98} Lyn Dupre: BUGS in Writing: A guide to debugging your prose. 2nd edition, Addison Wesley, 1998.

\end{thebibliography} Then refer to these in the text using \cite: Finer details on the use of en~dashes are explained by Lamport~\cite{Lamport94} or Dupre~\cite[page~134]{Dup98}. \cite can take an optional note in [], e.g. for a page or section number. \bibitem can take an optional label in []. \begin{thebibliography}{99} needs a “widest label” as an argument to plan indentation. 37

Automatic compilation of references with BibTEX Consider using BibTeX if you

I expect to write several publications, .tex .bib sharing many references, each .bst formatted to different house styles; LAT X I want number-only references sorted in E order of first reference; .aux I want automatic author-year references BibT X (use package natbib) E I want to use a reference database LATEX .bbl Provide .bib bibliographic database files and .blg a .bst bibliographic style file (often provided .aux by publisher). Load these as in \bibliography{articles,group-refs} LATEX \bibliographystyle{unsrt} Details: .pdf Lamport, Section 4.3 and Appendix B. LATEX Companion, Chapter 12. 38 Example *.bib file entry

@TechReport{UCAM-CL-TR-123, author = {Herbert, John}, title = {Case Study of the {Cambridge Fast Ring ECL} Chip using {HOL}}, year = 1988, month = feb, institution = {University of Cambridge, Computer Laboratory}, number = {UCAM-CL-TR-123} } Important: Many U.S. publishers’ house styles use “title case” for publication titles, where most words (other than short articles and prepositions) start with a capital letter. This form of emphasis is not appropriate for bibliographic references, therefore many BibTEX styles convert titles to lowercase. Protect names (proper nouns) and acronyms in titles from automatic lowercase-ification by surrounding them with {...}. Title case: Case Study of the Cambridge Fast Ring ECL Chip using HOL Sentence case: Case study of the Cambridge Fast Ring ECL chip using HOL Bad-BibTEX case: Case study of the cambridge fast ring ecl chip using hol 39

Exercise 1: Copy file example.tex from slide 7, run “pdflatex example” twice (why?), and then “okular example.pdf &” (Linux) to see the output.

Exercise 2: Read pages 1–64 of the LATEX book, then write your CV with LATEX, convert the result into PDF, and put it onto your homepage. For information on how to set up homepages locally: https://www.srcf.net/

Exercise 3: In a job interview for a position as a subeditor of a technical journal, your skills in spotting typographic mistakes made by LATEX beginners are tested with this example text:

The -7 dB loss (±2dB) shown on pp. 7-9 can be attributed to the f(t)= sin(2πft)signal , where t is the the time and f =48Khz is the ”sampling frequency”.

Can you spot all 14 mistakes? Write down both the probable original incorrect LATEX source text, as well as a corrected version.

40