300 likes | 525 Views
Tips and Tricks for. James Montgomery with contributions from many other users Research School of Computer Science Australian National University. View brief explanation. How LaTeX works (logical structure). Your . tex document. pdfLaTeX. XeTeX. . frontend. frontend.
E N D
Tips and Tricks for James Montgomery with contributions from many other users Research School of Computer Science Australian National University View brief explanation
How LaTeX works (logical structure) Your .tex document pdfLaTeX XeTeX ... frontend frontend frontend document structure typesetting
Boxes: How TeX typesets TeX tries to make things look ‘good’, so avoids ‘windows’ (last line of paragraph on next page) and ‘orphans’ (headings at end of page) Floating environments (tables, figures, etc.) are boxes that cannot be split \mbox command can prevent contents from breaking
How LaTeX ‘works’ .cls .tex .aux .toc .bib .out .sty .sty .bbl .sty Lots and lots of files latex pdflatex xelatex etc. .eps, .pdf ...
LaTeXprocessing steps Section 1 See Section on page . Knuth created TeX in 1978 . But Davenport is responsible for , which has given us much joy . >pdflatexdoc.tex >pdflatexdoc.tex >bibtex doc >pdflatexdoc.tex >pdflatexdoc.tex .tex .aux .bib .bbl 2 3 ? ? [?] [2] [1] [?] References [1] L. Davenport. etc. [2] D. Knuth, etc. Note: This has one more step than is necessary
Workflows Use source control Use an editor with syntax highlighting and code completion Git SVN • Emacs (with AUCTeX) • Lyx • TeXnicCenter( only) • TeXlipse • TeXShop(in MacTeX on ) • Vim (with Vim-LaTeX) svn-multi to include SVN version data in drafts • It’s code, so when things don’t work, debug • \iffalse (or %comment) • Create a \comment{...} command
Working with others ... \input{james} \input{mark} \input{steve} ... Option 1:Break up the document intro.tex method.tex results.tex doc.tex james.tex mark.tex steve.tex doc.tex doc.tex Option 2:Agree to work on different parts(and let source control handle merging) Margin notes using any convenient package todonotes marginal notes and figure placeholders
Inside your document Style Tables Title Ann Author Heading 1 This is a sample document, illustrating key features The contents don’t matter, only that the key elements of a document be present. As Equation 1 shows, authors like to include equations. (1) Authors also include figures, tables, algorithms and code listings. Algorithm 1 COBOL := 1 while true add 1 to COBOL end Table 1. Has a caption Math Graphics creation & figures Arranging floats Col 1 Col 2 Col 3 — — — — — — — — — — — — — — — Figure 1. Has a caption Bibliographies Algorithms & code listings References Knuth, D. E. (1984) The TeXbook. Addison-Wesley. Lamport, L. (1994). LaTeX: A Document Preparation System. Addison-Wesley. Skip over these
Math Many LaTeX editors provide menus of symbols Early on, have a cheat sheet handy ntheorem predefined theorem & proof environments amsmath, amsfonts, amssymb theorems, better math fonts & symbols mathtools fixes some things in amsmath; adds new functionality return
Tables can be hard Use an editor for complex tables e.g. LaTable on Windows Use \begin{table*}...\end{table*}to make a table span columns in two-column papers. excel2latex VBA add-in for converting Excel data to LaTeX tables An over-engineered table; avoid all this if possible \begin{table}[t] \caption{Best combinations of $\alpha$ and $\gamma$ by problem from BBOB} \label{tab:bbob_results} \centering \begin{tabular}{@{}c@{\ \ }c@{\ \ }c@{\quad}c@{\quad}c@{\quad}c@{\quad}c@{\ \ }c@{\ }r@{\ }r@{}} \hline & & \multicolumn{2}{c}{Standard DE} & \multicolumn{2}{c}{Modified DE} & \multicolumn{2}{c}{Param.} & \\ Set & fn & mean & stdev & mean & stdev & $\alpha$ & $\gamma$ & \%-diff & \textit{t}-test \\ \hline & 1 & 0.00e+0 & 0.00e+0 & & & & & & \\%0.00e+0 & 0.00e+0 & 0.04 & 3 & 0\% & --- \\ & 2 & 6.44e+1 & 2.93e+2 & 8.12e-6 & 4.68e-6 & 0.1 & 2 & 100\% & 15\% \\ 1 & 3 & 2.29e+1 & 1.09e+1 & 1.42e+1 & 5.96e+0 & 0.1 & 3 & \textbf{38\%} & \textbf{0\%} \\ & 4 & 2.62e+1 & 8.33e+0 & 1.90e+1 & 6.08e+0 & 0.04 & 1 & \textbf{28\%} & \textbf{0\%} \\ & 5 & 2.16e+0 & 8.59e+0 & 0.00e+0 & 0.00e+0 & 0.1 & 1 & 100\% & 11\% \\ \hline
lcr @{sep} p{width} \begin{tabular}{ } width In p{width}, width must be unit of distance, including mm, cm, m, in, or even printing measures like ‘ex’ and ‘em’. @{sep} replaces default gap with sep, which can be text or spaces. left centre right Text in this cell will be wrapped and justified. booktabs better spacing of lines around table contents colortbl control cell background colour & line colour And for styling:
More tricks with tables Table 1. This caption should not be legible Table 2. Now this is just silly multirow support multi-row cells longtable allows tables to split over pages lscape rotate part of document 90 rotating rotate part of documentby any angle
Captions and labels List of Tables Table 1. Brief Table 2. Succinct Table 3. Laconic v Table 1. Described in full, with lots of explanation. paper2.tex paper1.tex thesis.tex Make labels (i.e., \label) in papers unique across papers. This will make it easier when creating chapters from those papers. \caption[Short caption for list of tables]{Long, descriptive caption to appear with table} Works with \section commands, too return
Graphics creation Use vector graphics formats where possible; will print better and (generally) be smaller Create graphics in multiple formats if possible (EPS, PDF, JPG) Inkscape is one optionAdd textext plug-in to include LaTeX generated content Gnuplot can produce a variety of high quality charts and graphs PDFs are suitable when using pdfLaTeX
Figures (a) Box (b) Arrow Figure 1. Shared caption for (a) and (b) \begin{figure} \centering \subfloat[Box]{ \includegraphics{subfigure1} \label{fig:subfig1} } \subfloat[Arrow]{ \includegraphics{subfigure2} \label{fig:subfig2} } \label{fig:bothfigures} \caption{Shared caption for \subref{fig:subfig1} and \subref{fig:subfig2}} \end{figure} subfig separate captions for sub-figures graphicx support for loading image files into document figure* to span columns If you reallywant separate figures side by side then use the minipage environment return
Algorithms and code programcollatz; varn : integer; begin n := Readln; whilen <> 1 do begin if not odd(n) then n := n / 2 else n := n * 3 + 1; end; end; Algorithm 1. Collatz n := from user while n 1 do if n is even then n := n / 2 else n := n * 3 + 1 end end algorithm floating algorithm environment like figure or table algorithmic formatting algorithms, keywords, etc. listings syntax highlighting for different languages xcolor defining and using colour + + return
Positioning floats – Error 404 • The content here was going to be so low-level that it’s been left out. It would have included tricks like • Moving where table of figure appears in TeX source (consider a separate file and \input to make this easier) • Forcing the float onto its own page (with other floats) with [p] placement specifier • Using \clearfloats return
BibTeX According to \citet{smi90}, that is \citet*{jon90}, or even \citep{jon90}. Use a tool to maintain your BibTeX databases. For example, JabRef or BibDesk (on Mac) natbib alternative cite commands According to Smith et al. (1990), that is Smith, Jones, and Johns (1990), or even (Smith et al. 1990). Unless you are an expert in the programming language Forth, don’t edit BibTeX style files (.bst); look for one that suits your needs return
Basic styling fancyhdr fine-grained control over header and footer content fullpageor geometry easy smaller margins orcontrol over margins savetrees reduce space usage; but doesn’t look as nice
More styling Balancing Columns Standard LaTeX font sizes are not always sufficient \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge flushend balance columns at the end of a paper relsize scale fonts with finer control; useful in tables. return
like your thesis Large documents \documentclass[a4paper]{book} % packages etc. \input{macros} \begin{document} \frontmatter % title page, TOC, etc. \mainmatter \includeonly{chapter 1} \include{chapter1} \include{chapter2} ... \appendix \include{appendix1} ... \backmatter %bibliography etc. .bib .sty appendix1.tex chapter1.tex chapter2.tex macros.tex Your abbreviations and other handy utilities Note: This is not a complete skeleton document
Useful packages Chapter 1 Some Illustrative Text This chapter is only here to illustrate that the cleveref package can generate the entire text for a cross-reference such as in Section 1. cleverref must be loaded last. Similarly, hyperrefmakes cross-reference numbers hyperlinks, as in Section 2 on page 3. The xr package allows for inter-document cross-references (see Chapter 2), if those documents are compiled separately. xr inter-document cross-references; useful if compiling chapters separately hyperref hyperlinks in PDFs cleveref generates all text for cross-references, not just number setspace set line spread as needed anuthesis ANU-specific styling See the source With some command trickery you can compile chapters separately or as part of whole document. See appendix.
Other uses for LaTeX • In PowerPoint: ‘TeX4PPT’ • Older, but easy installhttp://users.ecs.soton.ac.uk/srg/softwaretools/presentation/TeX4PPT/ • Newer, slightly fiddly install, works betterhttps://sites.google.com/site/tex4ppt/ • Instead of PowerPoint: • Packages like beamer
Further reading and seeking help The Not So Short Introduction to LATEX2ε (1995–2011) by TobiOetiker & contributorshttp://tobi.oetiker.ch/lshort/ Math into Latex (2000) by George GrätzerMany free copies available on the web TeX Stack Exchange http://tex.stackexchange.com/ CTAN for package documentationhttp://www.ctan.org www www
Appendix Things to look out for in the future • New front ends to LaTeX with native support for Unicode (so no more \"a for ä) and other features: • XeTeX • LuaTeX