LaTeX: Difference between revisions
(250 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Links == |
|||
;Related pages on this wiki |
|||
* [[LaTeX writing tips]]<br>Style, layout, mathematical writing tips |
|||
* [[JsMath]] |
|||
* [[MathJax]] |
|||
* [[KaTeX]] |
|||
;Personal pages |
|||
* [http://tex.stackexchange.com/users/46965/fuujuhi fuujuhi on StackExchange — TeX] |
|||
;External references |
|||
* Manuals: |
|||
** [ftp://ftp.ams.org/pub/tex/doc/amsmath/short-math-guide.pdf short-math-guide.pdf] ([[Media:Short-math-guide.pdf|local copy]]) |
|||
** [http://tobi.oetiker.ch/lshort/lshort.pdf The Not So Short Introduction to LaTeX 2e] |
|||
** [http://www.informit.com/store/product.aspx?isbn=0201362996 The LaTeX Companion, 2e ed] (bought as e-book) |
|||
** [http://www.stdout.org/~winston/latex/latexsheet-a4.pdf LaTeX cheat sheet] |
|||
** [https://latexref.xyz/ LaTeX2e unofficial reference manual] |
|||
** [http://tug.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf The '''beamer''' user guide] (also in package {{deb|texlive-latex-recommended-doc}}, file {{file|beameruserguide.pdf}}). |
|||
* Wiki |
|||
** [http://en.wikibooks.org/wiki/LaTeX/Introduction LaTeX WikiBook] |
|||
*** [https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions Floats, Figures and Captions] |
|||
*** [http://en.wikibooks.org/wiki/LaTeX/Page_Layout Page Layout] |
|||
* Tips |
|||
** [http://bliss.biology.yale.edu/~zasha/latex.html Nice styles] |
|||
** [http://bliss.biology.yale.edu/~zasha/latexexample/index.html Creating .EPS with VISIO] |
|||
** [http://en.wikibooks.org/wiki/LaTeX/Importing_Graphics Importing Graphics] (<tt>\includegraphics, \usepackage{graphicx}</tt>) |
|||
** [http://www.tug.org/pracjourn/2005-4/mertz/mertz.pdf Beamer by Example (TUG)] (<tt>\onslide, \only</tt>) |
|||
** [http://en.wikibooks.org/wiki/LaTeX/Presentations LaTeX/Presentations] |
|||
** [http://deic.uab.es/~iblanes/beamer_gallery/ Beamer gallery] — list of available themes for presentation, with screenshots. |
|||
** [http://www.math.ens.fr/~millien/tdlatex/conseils_latex.pdf Conseils pour bien taper un document LaTeX (conseils_latex.pdf)] — Good tips for math typesetting in LaTeX ({{red|'''TODO'''}}). |
|||
* Symbols: |
|||
** '''[http://detexify.kirelabs.org/classify.html Detexify{{e|2}} - LaTeX symbol classifier]''' (Draw the symbol to find it!) |
|||
** [http://shapecatcher.com/ shapecatcher.com - unicode character recognition] |
|||
** [http://www.tex.ac.uk/tex-archive/info/symbols/comprehensive/symbols-a4.pdf The Comprehensive LaTeX Symbol List] (5913 symbols,file {{file|symbols-a4.pdf}}) |
|||
** [http://ctan.org/pkg/unicode-math unicode-math package] (see {{file|unimath-symbols.pdf}}, also in LaTeX documentation) |
|||
** See [[Unicode]] page |
|||
* Graphics: |
|||
** [http://www.geogebra.org/cms/en/ GeoGebra] — an extremely powerful tool to draw geometry figures.<br>Can export in many formats, including PSTricks, PGF/TikZ, PNG, ... |
|||
;Tools |
|||
* TexMaker |
|||
* Overleaf (online editor) |
|||
* ShareLatex (online editor). |
|||
* PDF viewer |
|||
: See [[Linux Software]] |
|||
* [https://github.com/susam/texme#texme TeXMe] ([https://susam.github.io/texme/examples/demo.html demo]) — A self-rendering Markdown + MathJax documents |
|||
== Install == |
|||
=== Any Linux === |
|||
See [http://tug.org/texlive/acquire-netinstall.html TeXLive]. |
|||
=== Ubuntu === |
|||
See [https://help.ubuntu.com/community/LaTeX Ubuntu reference page] or [http://www.tug.org/texlive/debian.html TUG Debian/Ubuntu reference page]. |
|||
; Complete install |
|||
Use [http://www.latex-community.org/forum/viewtopic.php?f=12&t=23749 this guide] to install the complete and latest TexLive on Ubuntu (~4GB) |
|||
'''{{red|DO NOT FORGET}}''' to disable any filtering proxies! Because it will reject packages containing <code>ad*</code>. |
|||
<source lang=bash> |
|||
git clone https://github.com/scottkosty/install-tl-ubuntu.git |
|||
cd install-tl-ubuntu |
|||
sudo ./install-tl-ubuntu |
|||
# OR |
|||
sudo ./install-tl-ubuntu -q http://www.ctan.org/tex-archive # to force a repository |
|||
</source> |
|||
After installation, the script will create a fake package <code>texlive-local</code> that will provide all texlive packages such that <code>apt</code> will not install them afterwards if another package depends on any of them. However on Ubuntu 14.04, we must also ''hold'' the package manually: |
|||
<source lang=bash> |
|||
dpkg --get-selections \* > selection |
|||
vi selection # Find 'texlive-local', and change 'install' to 'hold' |
|||
sudo dpkg --set-selections < selection |
|||
dpkg -l | grep texlive # Check that package is held (prefix must be 'hi', not 'ii') |
|||
</source> |
|||
; Partial install |
|||
Choose an official repository |
|||
* Trusty 14.04 — Default version on is ''TexLive 2013 (2013.20140215-1) |
|||
* Precise 12.04 — Default version on is ''TexLive 2009''. |
|||
* Precise 12.04 — Install this [https://launchpad.net/~texlive-backports/+archive/ppa/ texlive backports ppa] provides ''TexLive 2012'' (see [http://askubuntu.com/questions/163682/how-do-i-install-the-latest-tex-live-2012]) |
|||
<source lang=bash> |
|||
sudo add-apt-repository ppa:texlive-backports/ppa |
|||
</source> |
|||
Install at least the following minimum packages and extra packages: |
|||
<source lang="bash"> |
|||
# texlive2html - To support TeX to HTML conversion |
|||
# texlive-xetex - To install XeTeX |
|||
sudo apt install texlive texlive2html texlive-xetex |
|||
sudo apt install texlive-plain-extra texlive-science texlive-latex-extra texlive-publishers texlive-fonts-extra cm-super latexmk |
|||
</source> |
|||
; Configuration / troubleshoot |
|||
* Update ''pdftex.map'' in the user profile (see [http://tex.stackexchange.com/questions/31388/getting-strange-error-with-miktex-when-trying-to-use-kpfonts-package]): |
|||
<source lang=bash> |
|||
updmap # Update user's pdftex.map |
|||
</source> |
|||
=== Debian === |
|||
On Debian Bullseye, I used: |
|||
<source lang="bash"> |
|||
sudo apt install texlive texlive-xetex texlive-extra-utils texlive-fonts-extra texlive-lang-french \ |
|||
texlive-pstricks texlive-publishers texlive-science cm-super latexmk texlive-lang-english |
|||
</source> |
|||
On Debian Buster, to install the same set of package as TexLive 2015: |
|||
<source lang="bash"> |
|||
sudo apt install texlive texlive-xetex texlive-extra-utils texlive-fonts-extra texlive-generic-recommended \ |
|||
texlive-lang-french texlive-plain-extra texlive-pstricks texlive-publishers texlive-science cm-super latexmk |
|||
</source> |
|||
=== On Windows === |
|||
* Install '''Miktex 2.9''' or later. |
|||
* Package ''minted'' requires Pygments, see [http://tex.stackexchange.com/questions/108661/how-to-use-minted-under-miktex-and-windows-7]. |
|||
** Install Python 2.7.x |
|||
** Install Python pip |
|||
** Add <code>C:\Python27\Scripts</code> to PATH |
|||
** Start 'cmd.exe', and install pygments: |
|||
pip install pygments |
|||
* Package {{file|IEEEtrantools.sty}} must be installed manually, see [http://tex.stackexchange.com/questions/28198/using-ieeetrantools] |
|||
** Download [http://mirrors.ctan.org/macros/latex/contrib/IEEEtran/tools/IEEEtrantools.sty IEEEtrantools.sty] into {{file|C:\Program Files\MiKTeX 2.9\tex\latex\IEEEtran\IEEEtrantools.sty}} |
|||
** Start "MiKTeX 2.9\Maintenance (Admin)\Settings (Admin)". Inside this program click the button "Refresh FNDB". |
|||
== Invocation == |
|||
Basic commands for '''LaTeX''' documents (using ''TeXlive'' under Linux or ''MikTeX'' under Windows): |
|||
<source lang="bash"> |
|||
pdflatex <file.tex> # Convert a .tex file directly to pdf format |
|||
latex <file.tex> # Convert a .tex file to .dvi file |
|||
dvips <file.dvi> # Convert a .dvi file to .ps |
|||
dvipdfm -p a4 <filetex> # Convert a .dvi file to .pdf (using a4 paper) |
|||
</source> |
|||
For '''TeX''' documents: |
|||
<source lang="bash"> |
|||
pdftex <file.tex> # Convert a .tex directly into .pdf |
|||
tex <file.tex> # Convert a .tex into .dvi |
|||
</source> |
|||
For '''XeLaTex''' documents (with [http://www.bibtex.org/Using/ BibTex] entries): |
|||
<source lang=bash> |
|||
xelatex <file.tex> # Generate the .aux file needed by BibTex |
|||
bibtex <file.aux> # Process bib entries |
|||
xelatex <file.tex> # 1st pass will generate .pdf w/o references |
|||
xelatex <file.tex> # 2nd pass will generate .pdf w/ references |
|||
</source> |
|||
Alternative to ''bibtext'': |
|||
* [http://www.ctan.org/pkg/biblatex biblatex] (optionally with the back-end ''biber'') |
|||
== Packages == |
|||
=== Miscellaneous packages === |
|||
* '''eledmac''' — Typeset scholarly editions (when lots of footnotes, endnotes are used). |
|||
* '''alltt''' — define environment <code>alltt</code>, which is like <code>verbatim</code> but where <code>\ { }</code> keep their usual meaning. |
|||
* '''longtable''' — Like <code>tabular</code> but produces table that can be broken over several pages. |
|||
* '''adjustbox''' — The package provides several macros to adjust boxed content (similar to <code>\includegraphics[width=...,height=...,keepaspectratio]</code>). See also comment in [http://tex.stackexchange.com/questions/17380/best-figure-size-adjustment-when-dealing-with-different-image-sizes]). |
|||
=== algorithmicx, algorithmic2e (algorithms)=== |
|||
(See [https://en.wikibooks.org/wiki/LaTeX/Algorithms LaTeX wikibooks] for a comparison of algorithm typesetting packages). |
|||
'''algorithmicx''' (manual {{file|[http://mirrors.ctan.org/macros/latex/contrib/algorithmicx/algorithmicx.pdf algorithmicx.pdf]}}, debian {{deb|texlive-science}}) is a package to typeset algorithms either in pseudo-code or in real language (''Pascal'' and ''C'' for now). |
|||
There are 2 pseudocode layouts. The layout <code>algcompatible</code> is fully compatible with older package ''algorithmic'', except for the following differences: |
|||
* Include package ''algorithmicx'' and ''algcompatible'' instead of ''algorithmic'': |
|||
<source lang=latex> |
|||
\usepackage{algorithmicx} |
|||
\usepackage{algcompatible} |
|||
</source> |
|||
* No <code>\RETURN</code> statement. This can be defined as |
|||
<source lang=latex> |
|||
\algloopdefx{RETURN}[0]{\textbf{return} \ } |
|||
% Alternate definition: |
|||
% \newcommand{\RETURN}{\State \textbf{return} \ } |
|||
</source> |
|||
* With ''algorithmic'', empty lines were obtained with <code>\\ ~ \\</code>. There is a dedicated command in ''algorithmicx'': |
|||
<source lang=latex> |
|||
\Statex % Insert empty un-numbered line |
|||
</source> |
|||
Otherwise it is recommended to use layout ''algpseudocode'', which uses the same commands but with a different letter case and allows defining new commands. Below is a summary of available commands. |
|||
{| class=wikitable width=100% |
|||
|- valign=top |
|||
<div style="column-width:25em;"> |
|||
<source lang=latex> |
|||
\begin{algorithmic}[1] |
|||
\State $sum\gets 0$ |
|||
\Statex |
|||
\textbf{return} $sum$\Comment{The sum is $sum$} |
|||
\end{algorithmic} |
|||
</source> |
|||
<source lang=latex> |
|||
\For{<text>} |
|||
<body> |
|||
\EndFor |
|||
</source> |
|||
<source lang=latex> |
|||
\ForAll{<text>} |
|||
<body> |
|||
\EndFor |
|||
</source> |
|||
<source lang=latex> |
|||
\While{<text>} |
|||
<body> |
|||
\EndWhile |
|||
</source> |
|||
<source lang=latex> |
|||
\Repeat |
|||
<body> |
|||
\Until{<text>} |
|||
</source> |
|||
<source lang=latex> |
|||
\If{<text>} |
|||
<body> |
|||
\ElsIf{<text>} |
|||
<body> |
|||
\Else |
|||
<body> |
|||
\EndIf |
|||
</source> |
|||
<source lang=latex> |
|||
\Procedure{<name>}{<params>} |
|||
<body> |
|||
\EndProcedure |
|||
</source> |
|||
<source lang=latex> |
|||
\Function{<name>}{<params>} |
|||
<body> |
|||
\EndFunction |
|||
</source> |
|||
<source lang=latex> |
|||
\Loop |
|||
<body> |
|||
\EndLoop |
|||
</source> |
|||
<source lang=latex> |
|||
\Require something |
|||
\Ensure something |
|||
\Statex |
|||
\State \Call{Create}{10} |
|||
</source> |
|||
Save, restore algorithms: |
|||
<source lang=latex> |
|||
\algstore{<savename>} |
|||
\algstore*{<savename>} |
|||
\algrestore{<savename>} |
|||
\algrestore*{<savename>} |
|||
</source> |
|||
</div> |
|||
|} |
|||
'''algorithmic2e''' (manual {{file|[http://mirror.ctan.org/tex-archive/macros/latex/contrib/algorithm2e/doc/algorithm2e.pdf algorithm2e.pdf]}}) is yet another package, which as of 2013, seems to be the most frequently used package bundle [https://en.wikibooks.org/wiki/LaTeX/Algorithms]. It has a nice option to draw vertical lines for delimiting blocks, but looks more complicated and harder to read. |
|||
;algorithmic |
|||
* Yet another package, default for IEEE ([http://ftp.snt.utwente.nl/pub/software/tex/macros/latex/contrib/algorithms/algorithms.pdf documentation]). |
|||
* See {{file|algorithmic.sty}} to define new items. For instance: |
|||
<source lang=latex> |
|||
% Define new commands similar to \ENSURE or \REQUIRE (i.e. not indented) |
|||
\newcommand{\algorithmicinterface}{\textbf{Interface:}} |
|||
\newcommand{\algorithmicinstantiation}{\textbf{Instantiation}} |
|||
\newcommand{\INTERFACE}{\item[\algorithmicinterface]} |
|||
\newcommand{\INSTANTIATION}{\item[\algorithmicinstantiation]} |
|||
% Define some handy one-liner (TODO: Might need to rework those |
|||
\newcommand{\STATEFOR}[2]{{\STATE \textbf{for} {#1} \textbf{do} {#2}}} |
|||
\newcommand{\STATEIF}[2]{{\STATE \textbf{if} {#1} \textbf{then} {#2}}} |
|||
\newcommand{\STATEIFELSE}[3]{{\STATE \textbf{if} {#1} \textbf{then} {#2} \textbf{else} {#3}}} |
|||
\newcommand{\STATERETURN}{{\textbf{return }}} |
|||
</source> |
|||
=== authblk === |
|||
Use the {{deb|authblk}} package to display the author affiliation using a footnote system in class <code>article</code>. |
|||
For instance: |
|||
<source lang=latex> |
|||
\documentclass[11pt]{article} |
|||
\usepackage{authblk} |
|||
\author{Firstname Name} |
|||
\author{Firstname Name} |
|||
\affil{Company A} |
|||
\author{Firstname Name} |
|||
\affil{Company B} |
|||
\title{...} |
|||
\date{...} |
|||
\begin{document} |
|||
\maketitle |
|||
\end{document} |
|||
</source> |
|||
In XeLaTeX, we need to patch {{deb|authblk}} when using the {{deb|xltxtra}} package with fonts that have [https://en.wikipedia.org/wiki/Superior_letter ''superior'' glyphs] (for instance ''Palatino Linotype'' or ''Minion Pro''): |
|||
<source lang=latex> |
|||
\usepackage{xltxtra} |
|||
\usepackage[noblocks]{authblk} |
|||
\setmainfont{Minion Pro} |
|||
% We patch authblk to keep superscript from xltxtra package |
|||
% See http://tex.stackexchange.com/questions/168095 |
|||
\makeatletter |
|||
\renewcommand\AB@authnote[1]{\textsuperscript{#1}} |
|||
\renewcommand\AB@affilnote[1]{\textsuperscript{#1}} |
|||
\makeatother |
|||
</source> |
|||
=== caption === |
|||
Use the '''[http://www.ctan.org/tex-archive/macros/latex2e/contrib/caption caption]''' package (manual {{file|[http://mirrors.ctan.org/macros/latex/contrib/caption/caption-eng.pdf caption-eng.pdf]}}}}) to format captions: |
|||
<source lang=latex> |
|||
\usepackage[margin=10pt,textfont=it,labelfont=bf,labelsep=endash]{caption} |
|||
</source> |
|||
There are also other caption packages: |
|||
* '''ccaption''' (continued captions) |
|||
* '''mcaption''' (margin captions) |
|||
=== cleveref, varioref (smart references) === |
|||
The '''[http://www.ctan.org/pkg/cleveref cleveref]''' (manual {{file|[http://mirrors.ctan.org/macros/latex/contrib/cleveref/cleveref.pdf cleveref.pdf]}}, debian {{deb|texlive-latex-extra}}) package enhances LaTeX cross-referencing features, allowing the format of references to be determined automatically according to the type of reference. |
|||
From the manual: |
|||
* The ''cleveref'' package must be loaded '''after all''' other packages that don't specifically support it (see manual, §13). Also note that all <code>\newtheorem</code> definitions '''must be placed after''' the cleveref package is loaded. |
|||
<source lang=latex> |
|||
% Load cleveref as last package! |
|||
\usepackage{cleveref} |
|||
\usepackage[capitalise]{cleveref} % Always capitalize labels |
|||
\usepackage[noabbrev]{cleveref} % Never use abbreviations in labels |
|||
\newtheorem{theorem}{Theorem} % These must come AFTER loading cleveref |
|||
\newtheorem{myclaim}{Claim} |
|||
</source> |
|||
* Most frequently used commands: |
|||
<source lang=latex> |
|||
\cref{label} % Insert a reference, including label |
|||
\Cref{label} % ... idem, but at the beginning of a sentence |
|||
\crefrange{label1}{label2} % Insert a range of references |
|||
\Crefrange{label1}{label2} % ... idem, but at the beginning of a sentence |
|||
</source> |
|||
* Don't use ''cleveref'' with <code>eqnarray</code>. Use ''amsmath'' better alternatives. |
|||
* ''cleveref'' conflicts with ''algorithmic'' package, so use ''algorithmicx'' package instead. Unfortunately this is not possible with IEEE publication since ''algorithmic'' is included by default. |
|||
=== float === |
|||
Better controls on float + custom style. See [http://www.ctan.org/pkg/float]. |
|||
=== listings, minted (source listings) === |
|||
* Reference: [http://stackoverflow.com/questions/1966425/source-code-highlighting-in-latex#1985330] |
|||
'''[http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings listings]''' is the old-fashioned way to insert code listings in LaTeX. |
|||
'''minted''' (manual {{file|[http://minted.googlecode.com/files/minted.pdf minted.pdf]}}, debian {{deb|texlive-latex-extra}}) is a package that facilitates expressive syntax highlighting using the powerful ''Pygments'' library. It requires : |
|||
<source lang=bash> |
|||
sudo apt-get install python-setuptools |
|||
sudo easy_install Pygments |
|||
</source> |
|||
All .tex files using ''minted'' must be compiled with option <code>-shell-escape</code>: |
|||
<source lang=bash> |
|||
xelatex -shell-escape myfile.tex |
|||
</source> |
|||
Some minimal examples (see manual for more): |
|||
<source lang=latex> |
|||
\begin{minted}{python} |
|||
def boring(args = None): |
|||
pass |
|||
\end{minted} |
|||
\mint{python}|import this| |
|||
% Use ''listing'' environment when adding a caption / label |
|||
\begin{listing}[htb] % Use [H] to force listing HERE |
|||
\mint{cl}/(car (cons 1 ’(2)))/ |
|||
\caption{Example of a listing.} |
|||
\label{lst:example} |
|||
\end{listing} |
|||
Listing \ref{lst:example} contains an example of a listing. |
|||
</source> |
|||
=== MnSymbol === |
|||
Use package '''MnSymbol''' (manual {{file|MnSymbol.pdf}}) to get access to many more symbols (from [http://www.tex.ac.uk/tex-archive/info/symbols/comprehensive/symbols-a4.pdf]). |
|||
The package is incompatible with packages ''amssymb'' and ''amsfonts''. A solution is to load ''MnSymbol'' after these package (see manual; see also [http://tex.stackexchange.com/questions/17370/how-to-use-mnsymbol-along-with-other-packages] for another solution): |
|||
<source lang=latex> |
|||
\documentclass[a4paper,twoside,11pt]{report} |
|||
\usepackage{amssymb} |
|||
\usepackage{amsfonts, amsmath, amsthm} |
|||
\usepackage{MnSymbol} |
|||
%... |
|||
</source> |
|||
=== soul === |
|||
Use package '''soul''' (manual {{file|[http://www.tex.ac.uk/tex-archive/macros/latex/contrib/soul/soul.pdf soul.pdf]}}, debian {{deb|texlive-plain-extra}}) to highlight, underline, hyphenate texts, or use small caps and change kerning, letter spacing. See manual for details. |
|||
LaTeX example: |
|||
<source lang="latex"> |
|||
\documentclass[a4paper]{article} |
|||
\usepackage{color,soul} |
|||
\begin{document} |
|||
Some normal text.\par |
|||
\hl{Some highlighted text.}\par |
|||
Some more normal text. |
|||
\end{document} |
|||
</source> |
|||
TeX example (requires ''color'' package from CTAN, see manual): |
|||
<source lang="latex"> |
|||
\input color |
|||
\input soul.sty |
|||
\pdfoutput=1 |
|||
\pdfpagewidth=21cm |
|||
\pdfpageheight=29.7cm |
|||
Some text here\par |
|||
\hl{Some highlighted text now}\par |
|||
Some more text\par |
|||
\bye |
|||
</source> |
|||
Troubleshooting <tt>Reconstruction error</tt>: |
|||
<source lang="latex"> |
|||
\hl{match of next brace, bracket, comment, \tt\#define} % WRONG |
|||
\hl{match of next brace, bracket, comment, \tt \#define} % CORRECT |
|||
\hl{/$s$\enter\ ?$s$\enter} % WRONG |
|||
\hl{{/$s$\enter} {?$s$\enter}} % CORRECT |
|||
\hl{These are {\it italic words} and these not} % WRONG |
|||
\hl{These are \it italic words \rm and these not} % CORRECT |
|||
</source> |
|||
=== ulem === |
|||
Package '''ulem''' is an alternative to ''soul'', and is more recent according to [http://tex.stackexchange.com/questions/23711/strikethrough-text this comment]. ulem stands for ''underlinded emphasized'', but this feature can be disabled with option <code>normalem</code>. |
|||
To strike text through: |
|||
<source lang=latex> |
|||
\usepackage[normalem]{ulem} % Use normalem to keep standard \emph text |
|||
\sout{Hello World} |
|||
</source> |
|||
=== subcaption === |
|||
Use package '''subcaption''' (debian {{deb|texlive-latex-recommended}}) to easily place figures side-by-side [http://blog.pengyifan.com/the-best-way-to-place-figures-side-by-side-in-latex/],[https://tug.org/TUGboat/tb34-1/tb106thurnherr.pdf]. Each sub-caption can have their own caption that are typeset with a specific sub-caption style. Alternatively, one can use <code>minipage</code> environment as well, but it does not align figures and captions appear like ordinary captions. |
|||
Note that packages '''subfig''' and '''subfigures''' are ''deprecated''. |
|||
{| width=100% class=wikitable |
|||
| |
|||
<source lang=latex> |
|||
\usepackage{subcaption} |
|||
... |
|||
\begin{figure} |
|||
\centering |
|||
\begin{subfigure}[b]{0.4textwidth} |
|||
\centering |
|||
\includegraphics[width=textwidth]{1.png} |
|||
\caption{Picture 1} |
|||
\label{fig:1} |
|||
\end{subfigure} |
|||
\begin{subfigure}[b]{0.4textwidth} |
|||
\centering |
|||
\includegraphics[width=textwidth]{2.png} |
|||
\caption{Picture 2} |
|||
\label{fig:2} |
|||
\end{subfigure} |
|||
\end{figure} |
|||
</source> |
|||
| |
|||
<source lang=latex> |
|||
\begin{figure} |
|||
\centering |
|||
\begin{minipage}[b]{0.4textwidth} |
|||
\centering |
|||
\includegraphics[width=textwidth]{1.png} |
|||
\caption{Picture 1} |
|||
\label{fig:1} |
|||
\end{subfigure} |
|||
\begin{minipage}[b]{0.4textwidth} |
|||
\centering |
|||
\includegraphics[width=textwidth]{2.png} |
|||
\caption{Picture 2} |
|||
\label{fig:2} |
|||
\end{subfigure} |
|||
\end{figure} |
|||
</source> |
|||
|} |
|||
== Font, Font Packages, and Managing Fonts == |
|||
;My font selection - beamer |
|||
<source lang=latex> |
|||
\defaultfontfeatures{Mapping=tex-text} |
|||
\setprimaryfont{Calibri} |
|||
\setallmonofonts[Scale=0.90]{Museo Slab}%{Calibri} %[Scale=0.8] % Also call \setmonofont |
|||
\setallsansfonts{Calibri} % Also call \setsansfont |
|||
</source> |
|||
;Some fonts |
|||
* [http://www.tex.ac.uk/cgi-bin/texfaq2html?label=psfchoice List of TeX fonts] |
|||
* '''Computer Modern''' (package ???) |
|||
:The original TeX font designed in MetaFont. Now exists in scalable version in Type 1, TrueType and OpenType (see also debian package ''cm-super''). |
|||
* [http://www.tug.dk/FontCatalogue/lmodern/ '''Latin Modern'''] (package ''lmodern'') |
|||
:The Latin Modern fonts are enhanced versions of the Computer Modern fonts. They have enhanced metrics and glyph coverage. |
|||
* '''[http://www.tug.dk/FontCatalogue/utopia/ Utopia]''' (package ''fourier'') |
|||
<source lang=latex> |
|||
%\usepackage[T1]{fontenc} |
|||
%\usepackage[adobe-utopia]{mathdesign} |
|||
\usepackage{fourier} |
|||
</source> |
|||
* '''Palatino Linotype''' |
|||
* '''Minion Pro''' (available via Adobe Reader) |
|||
* Blackboard sans-serif fonts: Use package '''dsfont''' [http://tex.stackexchange.com/questions/60014/traditional-german-sans-serif-and-serif-blackboard-bold-symbols] |
|||
<source lang=latex> |
|||
\usepackage[sans]{dsfont} |
|||
\mathds{A} |
|||
</source> |
|||
* '''Calibri''' and '''Andale Mono''' |
|||
\setmainfont{Calibri} |
|||
\setmonofont[Scale=0.86]{Andale Mono} |
|||
;Fonts on LaTeX |
|||
* If LaTeX complains about fonts, maybe you need to update the pdftex.map: |
|||
updmap |
|||
* In document, it seems good to select ''Type 1'' encoding, whatever it means. However this seems automatic in recent TexLive version: |
|||
<source lang=latex> |
|||
\usepackage[T1]{fontenc} |
|||
</source> |
|||
;Fonts on XeLaTeX |
|||
* Change fonts with package <tt>fontspec</tt> and commands like <code>\setmainfont</code> and <code>\setmonofont</code>. |
|||
* The <tt>xunicode</tt> package provides additional mapping between LaTeX accents and the selected font. |
|||
* The <tt>xltxtra</tt> package provides some fixes relating to fonts. |
|||
* Also nice, use the <tt>microtype</tt> package: |
|||
\usepackage[final,expansion=true,protrusion=true,spacing=true,kerning=true]{microtype} |
|||
;Some references and font troubleshooting links: |
|||
* See {{file|fntguide.pdf}}. |
|||
* Which LaTeX font packages contain real small caps and work with the “microtype” package? [http://tex.stackexchange.com/questions/30830/which-latex-font-packages-contain-real-small-caps-and-work-with-the-microtype], |
|||
* Why do I suddenly get an auto expansion error? [http://tex.stackexchange.com/questions/135275/why-do-i-suddenly-get-an-auto-expansion-error] |
|||
* pdfTeX error (font expansion): auto expansion is only possible with scalable [http://tex.stackexchange.com/questions/10706/pdftex-error-font-expansion-auto-expansion-is-only-possible-with-scalable] |
|||
;Deprecated |
|||
<code>\sf</code>, <code>\bf</code>, <code>\it</code> are '''deprecated'''. Prefer text alternatives like <code>\textbf</code> (see [http://tex.stackexchange.com/questions/98279/does-boldface-sans-serif-not-work]) |
|||
== Reference == |
== Reference == |
||
=== Syntax - Basic === |
|||
* Cheat sheet: [ftp://ftp.ams.org/pub/tex/doc/amsmath/short-math-guide.pdf] |
|||
;Links |
|||
** Or local copy: [[File:Short-math-guide.pdf]] |
|||
: <code>[http://tex.stackexchange.com/questions/649/how-do-magic-dots-work-in-amsmath \dots]</code> |
|||
{|class=wikitable width=100% |
|||
|- |
|||
|width=15%|Special characters |
|||
|<source lang=latex> |
|||
\# \$ \% \^{} \& \_ \{ \} \~{} \textbackslash |
|||
</source> |
|||
|- |
|||
|LaTeX Commands |
|||
|<source lang=latex> |
|||
\TeX{} and % space (tx to {}) |
|||
\TeX{}nicians and % NO space |
|||
\TeX perts. % NO space |
|||
</source> |
|||
|- |
|||
|Document class |
|||
|<source lang=latex> |
|||
\documentclass[options]{class} % See manual for reference |
|||
</source> |
|||
|- |
|||
|Packages |
|||
|<source lang=latex> |
|||
\usepackage[options]{package} % See manual for list of packages |
|||
</source> |
|||
|- |
|||
|Page style |
|||
|<source lang=latex> |
|||
\pagestyle{style} % plain, headings, empty |
|||
\thispagestyle{style} % for current page only |
|||
</source> |
|||
|- |
|||
|Colors |
|||
|<source lang=latex> |
|||
\usepackage[usenames,dvipsnames,svgnames]{xcolor}% before tikz or tkz |
|||
\definecolor{Maroon}{rgb}{0.5,0.0,0.0}%{.80,.80,.95} |
|||
\definecolor{fondpaille}{cmyk}{0,0,0.1,0} |
|||
\pagecolor{fondpaille} % Setup default background color |
|||
\color{Maroon} % Setup default foreground color |
|||
</source> |
|||
|- |
|||
|Big project |
|||
|<source lang=latex> |
|||
\include{filename} % Insert content of file - LaTeX starts a new page |
|||
\includeonly{filename,...} % (in preamble) restrict list of included files |
|||
\input{filename} % Simply includes the file |
|||
</source> |
|||
|- |
|||
|Breaks |
|||
|<source lang=latex> |
|||
Supercalifragilist% |
|||
icexpialidocious % Use % to break lines without inserting space in output (here single word) |
|||
\\ % Start a new line without starting a new paragraph |
|||
\newline % idem |
|||
\\* % idem, but prohibits page break after forced line break |
|||
\newpage % |
|||
\linebreak[n] % Suggest LaTeX where to break (or not) page (n=0..4) |
|||
\nolinebreak[n] % |
|||
\pagebreak[n] % |
|||
\nopagebreak[n] % |
|||
\sloppy % Tell LaTeX to relax its layout standards |
|||
\fussy % Reset to default layout behaviour |
|||
</source> |
|||
<code>\sloppy</code> might be used to fix "''overfull hbox''" message and line sticking out on the right of paragraphs (although usually result is not really good). Use option '''<code>draft</code>''' in document class to identify these issues more easily |
|||
|- |
|||
|Hyphenation |
|||
|<source lang=latex> |
|||
\hyphenation{FORTRAN Hy-phen-a-tion} % Instruct LaTex where (and not) insert hyphens |
|||
su\-per\-cal\-i\-frag % Instruct hyphen locally (handy for accented words) |
|||
\mbox{0116 291 2319} % Content of \mbox is kept togetter |
|||
\fbox{0116 291 2319} % Idem, with surrounding box |
|||
input/output % Slash / prevents hyphenation |
|||
input\slash output % ... so use \slash instead |
|||
</source> |
|||
|- |
|||
|Special characters and symbols |
|||
|<source lang=latex> |
|||
`x' % single quotation marks |
|||
``quote'' % double quotation marks |
|||
daughter-in-law % 'hyphen' dash |
|||
pages 13--67 % 'en-dash' |
|||
yes---or no? % 'em-dash' |
|||
$0$, $1$ and $-1$ % 'minus' sign |
|||
http://www.clever.edu/$\sim$demo % tilde for url (better than \~{}) |
|||
5MB/s % slash, but hyphenation disabled |
|||
read\slash write % slash, with hyphenation allowed |
|||
$-30\,^{\circ}\mathrm{C}$ % degree symbol |
|||
30 \textcelsius{} % idem, easier (with package 'textcomp') |
|||
\texteuro, \euro, € % various ways to get euro sign (see manual for variants) |
|||
\ldots \cdots % ellipsis (low dots), centered dots |
|||
\dotsc \dotsb \dotsm \dotsi \dotso% semantics dots, for: commas, binary ops, multiply, integrals, other |
|||
\dots % SMART dots, from amsmath (same as above, but auto-guess) |
|||
not shelfful, but shelf\mbox{}ful % use \mbox{} to prevent ligatures |
|||
H\^otel na\"\ive \'el\`eve % some example of accents (see manual for more) |
|||
</source> |
|||
|- |
|||
|International support |
|||
|<source lang=latex> |
|||
\usepackage[utf8]{inputenc} % Enable utf-8 (see also XeLaTeX) |
|||
% French support |
|||
M\up{me}, D\up{r}, 1\ier{}... % See manual for more |
|||
</source> |
|||
|- |
|||
|Spacing |
|||
|<source lang=latex> |
|||
Not\ expandable space % non-expandable space |
|||
Mr.~Smith % Idem + non-breakable |
|||
I like BASIC\@. What about you? % Indicate . is end of sentence |
|||
</source> |
|||
|- |
|||
|Titles, Chapters, Sections |
|||
|<source lang=latex> |
|||
\chapter[Shorter title]{...} % For 'report' or 'book' class |
|||
\part{...} % Does not influence section / chapter numbering |
|||
\appendix{...} % Like chapters, using letters for numbering |
|||
\section{...} |
|||
\section*{...} % unnumbered section, not in TOC |
|||
\subsection{...} |
|||
\subsubsection{...} |
|||
\paragraph{...} |
|||
\subparagraph{...} |
|||
\tableofcontents |
|||
\title{...} \author{...} \date{...} |
|||
\maketitle |
|||
</source> |
|||
|- |
|||
|Cross References |
|||
|<source lang=latex> |
|||
\label{sec:this} |
|||
See section~\ref{sec:this} |
|||
See page~\pageref{sec:this} |
|||
As in equation~\eqref{eq:this} |
|||
</source> |
|||
|- |
|||
|Footnotes |
|||
|<source lang=latex> |
|||
\footnote{text} % after word or sentence (i.e. after comma or dot) |
|||
</source> |
|||
|- |
|||
|Emphasized Words |
|||
|<source lang=latex> |
|||
\underline{text} |
|||
\emph{text} |
|||
</source> |
|||
|- |
|||
|Subscript and superscript |
|||
|<source lang=latex> |
|||
\usepackage{xltxtra} |
|||
CO\textsubscript{2} |
|||
4\textsuperscript{th} |
|||
</source> |
|||
|- |
|||
|Environments |
|||
|<source lang=latex> |
|||
\begin{itemize} |
|||
\item one |
|||
\item[-] two with a dash |
|||
\end{itemize} |
|||
\begin{enumerate} |
|||
\item first |
|||
\item second |
|||
\end{itemize} |
|||
\begin{description} |
|||
\item[One] one |
|||
\item[Second] second |
|||
\end{description} |
|||
\begin{flushleft} \end{flushleft} % Can also be used as \flushleft, \flushright... |
|||
\begin{flushright} \end{flushright} |
|||
\begin{center} \end{center} |
|||
</source> |
|||
|- |
|||
|Miscellaneous |
|||
|<source lang=latex> |
|||
/verb|\verb+...+| allows verbatim text % but does NOT work in macro arguments |
|||
... |
|||
\begin{frame}[fragile] |
|||
In beamer, frame must be /verb|[fragile]| |
|||
\end{frame} |
|||
\usepackage{graphicx} % Rotation |
|||
My rotated \rotatebox{90}{text} |
|||
</source> |
|||
|- |
|||
|Beamer |
|||
|<source lang=latex> |
|||
/alert{Some text.} |
|||
% Change the font size for one frame |
|||
\begin{frame}{} |
|||
\fontsize{10pt}{12.0}\selectfont % \fontsize{<font size>}{<value for \baselineskip>}\selectfont |
|||
\end{frame} |
|||
</source> |
|||
|- |
|||
|Colors |
|||
|<source lang=latex> |
|||
\usepackage{xcolor} |
|||
\definecolor{bashstring}{RGB}{186,33,33} |
|||
\textcolor{bashstring}{my string} |
|||
{\color{bashstring}mystring} % declaration, within a TeX group |
|||
{\color{bashstring}\verb+also work with verbatim+} % declaration mandatory with \verb |
|||
</source> |
|||
|} |
|||
=== Syntax - Tables === |
|||
<source lang="latex"> |
|||
\begin{table} |
|||
\caption{\label{t:mylabel}Some description} |
|||
\begin{center} |
|||
\begin{tabular}{|p{6.5cm}|p{6.5cm}|} |
|||
\hline |
|||
\multicolumn{2}{|l|}{\textbf{Multicolumn line}} \\ |
|||
\hline |
|||
Top left & Top right \\ |
|||
Bottom left & Bottom right \\ |
|||
\hline |
|||
\hline |
|||
\end{tabular} |
|||
\end{center} |
|||
\end{table} |
|||
\begin{tabular}{|r|l|} |
|||
\hline |
|||
7C0 & hexadecimal \\ |
|||
3700 & octal \\ \cline{2-2} |
|||
11111000000 & binary \\ |
|||
\hline \hline |
|||
1984 & decimal \\ |
|||
\hline |
|||
\end{tabular} |
|||
\begin{tabular}{|p{4.7cm}|} |
|||
\hline |
|||
Welcome to Boxy’s paragraph. |
|||
We sincerely hope you’ll |
|||
all enjoy the show.\\ |
|||
\hline |
|||
\end{tabular} |
|||
\begin{tabular}{@{} l @{}} |
|||
\hline |
|||
no leading space\\ |
|||
\hline |
|||
\end{tabular} |
|||
\begin{tabular}{l} |
|||
\hline |
|||
leading space left and right\\ |
|||
\hline |
|||
\end{tabular} |
|||
\begin{tabular}{c r @{.} l} |
|||
Pi expression |
|||
& |
|||
\multicolumn{2}{c}{Value} \\ |
|||
\hline |
|||
$\pi$ |
|||
& 3&1416 \\ |
|||
$\pi^{\pi}$ |
|||
& 36&46 |
|||
\\ |
|||
$(\pi^{\pi})^{\pi}$ & 80662&7 \\ |
|||
\end{tabular} |
|||
\begin{tabular}{|c|c|} |
|||
\hline |
|||
\multicolumn{2}{|c|}{Ene} \\ |
|||
\hline |
|||
Mene & Muh! \\ |
|||
\hline |
|||
\end{tabular} |
|||
{\renewcommand{\arraystretch}{1.5} |
|||
\renewcommand{\tabcolsep}{0.2cm} |
|||
\begin{tabular}{|l|} |
|||
\hline |
|||
less cramped\\\hline |
|||
table layout\\\hline |
|||
\end{tabular}} |
|||
\begin{tabular}{|c|} |
|||
\hline |
|||
% \rule{1pt}{4ex}Pitprop \ldots\\ |
|||
\rule{0pt}{4ex}Pitprop \ldots\\ |
|||
\hline |
|||
\rule{0pt}{4ex}Strut\\ |
|||
\hline |
|||
\end{tabular} |
|||
</source> |
|||
=== Syntax - Mathematics === |
|||
;Fractions |
|||
{| class=wikitable width=100% |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
\frac{1}{\sqrt{2}+\frac{1}{\sqrt{2}+\frac{1}{\sqrt{2}+\dotsb}}} % Standard fraction |
|||
</source> |
|||
| |
|||
:<math>\frac{1}{\sqrt{2}+\frac{1}{\sqrt{2}+\frac{1}{\sqrt{2}+\dotsb}}}</math> |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
\cfrac{1}{\sqrt{2}+ |
|||
\cfrac{1}{\sqrt{2}+ |
|||
\cfrac{1}{\sqrt{2}+\dotsb |
|||
}}} % Continued fraction |
|||
</source> |
|||
| |
|||
:<math>\cfrac{1}{\sqrt{2}+ |
|||
\cfrac{1}{\sqrt{2}+ |
|||
\cfrac{1}{\sqrt{2}+\dotsb |
|||
}}} % Continued fraction</math> |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
\tfrac{1}{2} % Tiny fraction, like in textstyle |
|||
</source> |
|||
| |
|||
:<math>\tfrac{1}{2} % Tiny fraction, like in textstyle</math> |
|||
|} |
|||
;Multiline and multiple equations |
|||
{| class=wikitable width=100% |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
% Multiline -- Easiest is to use multiline, best is to use IEEEeqnarray |
|||
\begin{multline} |
|||
a + b + c + d + e + f + g + h + i |
|||
\\ |
|||
= j + k + l + m + n |
|||
\end{multline} |
|||
</source> |
|||
| |
|||
:<math>\begin{multline} |
|||
a + b + c + d + e + f + g + h + i |
|||
\\ |
|||
= j + k + l + m + n |
|||
\end{multline}</math> |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
% Multiple equations - Easiest is to use \begin{align} if NO line too long |
|||
\begin{align} |
|||
a & = b + c \\ |
|||
& = d + e |
|||
\end{align} |
|||
</source> |
|||
| |
|||
:<math>\begin{align} |
|||
a & = b + c \\ |
|||
& = d + e |
|||
\end{align}</math> |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
% Multiple equations - ... but best is to use IEEEeqnarray (AVOID \begin{eqnarray} !!!) |
|||
% See also commands (\begin{IEEEeqnarray*}, \IEEEyesnumber, \IEEEyessubnumber) |
|||
% ... also to group several blocks of equations beside each other |
|||
% (source: The not so short introduction to LaTeX) |
|||
\usepackage[retainorgcmds]{IEEEtrantools} |
|||
\begin{IEEEeqnarray}{rCl} |
|||
a & = & b + c |
|||
\\ |
|||
& = & d + e + f + g + h + i + j + k \nonumber\\ |
|||
&& +\: l + m + n + o |
|||
\\ |
|||
& = & p + q + r + s |
|||
\end{IEEEeqnarray} |
|||
</source> |
|||
| |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
\begin{IEEEeqnarray}{rCl} |
|||
\IEEEeqnarraymulticol{3}{l}{ |
|||
a + b + c + d + e + f + g + h |
|||
}\nonumber\\ \quad |
|||
& = & i + j |
|||
\\ |
|||
& = & k + l + m |
|||
\end{IEEEeqnarray} |
|||
</source> |
|||
| |
|||
|} |
|||
;Operators |
|||
References: Big-O [http://tex.stackexchange.com/questions/30872/command-for-big-omega], negative-space fix [http://tex.stackexchange.com/questions/40829/equation-using-left-brackets-inserts-unwanted-space], operator [http://www.latex-community.org/know-how/latex/51-latex-math-science/207-defining-operators-like-sin-log-etc] |
|||
{| class=wikitable width=100% |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
\usepackage{amsmath} |
|||
\operatorname{sgn} x |
|||
\DeclareMathOperator{\sgn}{sgn} % DO NOT define new op with \newcommand, but this |
|||
\DeclareMathOperator*{\esssup}{ess\,sup} % Starred, with subscript like \sum |
|||
</source> |
|||
| |
|||
:<math>\operatorname{sgn} x |
|||
\quad |
|||
\DeclareMathOperator{\sgn}{sgn} |
|||
\sgn x |
|||
\quad |
|||
\DeclareMathOperator*{\esssup}{ess\,sup} |
|||
\esssup_{x\in [0,1]}f(x)</math> |
|||
|- |
|||
|<source lang=latex> |
|||
\newcommand{\BigO}[1]{\ensuremath{\operatorname{O}\bigl(#1\bigr)}} % Simple big-O |
|||
\newcommand{\BigO}[1]{\ensuremath{\operatorname{O}\!\left(#1\right)}} % scaling () |
|||
\newcommand{\BigO}[1]{\ensuremath{\operatorname{\mathcal{O}}\!\left(#1\right)}} % alternate |
|||
</source> |
|||
| |
|||
:<math>\operatorname{O}\bigl(n^2\bigr) |
|||
\quad |
|||
\operatorname{O}\!\left(n^2\right) |
|||
\quad |
|||
\operatorname{\mathcal{O}}\!\left(n^2\right) |
|||
</math> |
|||
|} |
|||
;Cases |
|||
{| class=wikitable width=100% |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
|x| = |
|||
\begin{cases} |
|||
0 & \text{if $x \lt 0$,} \\ % Note the use of \text and $...$ |
|||
x & \text{if $x > 0$.} |
|||
\end{cases} |
|||
</source> |
|||
| |
|||
:<math>|x| = |
|||
\begin{cases} |
|||
0 & \text{if $x \lt 0$,} \\ % Note the use of \text and $...$ |
|||
x & \text{if $x > 0$.} |
|||
\end{cases}</math> |
|||
|} |
|||
;Matrices |
|||
{| class=wikitable width=100% |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} % instead of using array |
|||
</source> |
|||
| |
|||
:<math>\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} % instead of using array</math> |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
$\left( \begin{smallmatrix}1 & 0 \\ 0 & -1\end{smallmatrix} \right)$ % small matrix for inline |
|||
</source> |
|||
| |
|||
:<math> \left( \begin{smallmatrix}1 & 0 \\ 0 & -1\end{smallmatrix} \right) </math> |
|||
|} |
|||
;Sums |
|||
{| class=wikitable width=100% |
|||
|- |
|||
|width=75%|<source lang=latex> |
|||
\sum^n_{\substack{0<i<n \\ % Use \substack for multiline indices |
|||
j\subseteq i}} |
|||
P(i,j) = Q(i,j) |
|||
</source> |
|||
| |
|||
:<math>\sum^n_{\substack{0<i<n \\ |
|||
j\subseteq i}} |
|||
P(i,j) = Q(i,j)</math> |
|||
|} |
|||
=== Advanced Scripting === |
|||
These are features typically only used in package. |
|||
{| class=wikitable width=100% |
|||
|- |
|||
|Enable <code>@</code> as a standard letter (see [http://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do]) |
|||
|<source lang=latex> |
|||
\makeatletter |
|||
% ... |
|||
\makeatother |
|||
</source> |
|||
|- |
|||
|Test if a given class is loaded |
|||
| |
|||
Requires <code>@</code> as a standard letter |
|||
<source lang=latex> |
|||
\@ifclassloaded{<someclass>} |
|||
{<true code>} |
|||
{<false coode>}% |
|||
</source> |
|||
|} |
|||
=== Dimensions & Page Layout === |
|||
;References |
|||
* See [http://en.wikibooks.org/wiki/LaTeX/Page_Layout Page layout] on WikiBooks. |
|||
Frequently-used dimensions: |
|||
{| class=wikitable |
|||
|- |
|||
<code>\textheight</code>||Height of the page body |
|||
|- |
|||
<code>\textwidth</code>||Width of the page body |
|||
|- |
|||
<code>\linewidth</code>||width in current environment |
|||
|} |
|||
;Useful packages |
|||
* {{deb|geometry}} — lets you customize the page size even with classes that do not support the options. |
|||
* {{deb|layout}} — To print from a LaTeX document itself the current page layout and dimensions. |
|||
* {{deb|showframe}} — To render a frame marking the margins of a document you are currently working on. |
|||
== Symbols == |
|||
Some frequently used symbols |
|||
{| class=wikitable |
|||
|- |
|||
|$$\bot$$||<code>\bot</code>||perpendicular (orthogonal) sign |
|||
|- |
|||
|$$\parallel$$||<code>\parallel</code>||parallel sign |
|||
|} |
|||
== XeLaTeX == |
|||
{| class=wikitable |
|||
|- |
|||
!LaTeX |
|||
!XeLaTeX |
|||
|- |
|||
|<source lang=latex> |
|||
\usepackage{inputenc} |
|||
\usepackage{fontenc} |
|||
\usepackage{textcomp} |
|||
\usepackage[languageA]{babel} |
|||
</source> |
|||
| |
|||
Save file as ''utf-8'' |
|||
<source lang=latex> |
|||
\usepackage{polyglossia} |
|||
\setdefaultlanguage[babelshorthands]{languageA} |
|||
\usepackage[Ligatures=TeX]{fontspec} % To enable --, ---, '', ``, !`, ?`, ,,, <<, >> |
|||
</source> |
|||
|} |
|||
== Templates == |
|||
=== Smallest === |
|||
<source lang=latex> |
|||
%UTF-8 encoding “Нelłó worlð!” |
|||
\documentclass{article} |
|||
\begin{document} |
|||
Small is beautiful. |
|||
\end{document} |
|||
</source> |
|||
* <code>\documentclass[options]{class}</code> takes optional paramters ''options'', and a mandatory document ''class''. See manual for reference. |
|||
=== 3-columns === |
|||
Example of 3-column document, minimum margin, no page numbering (see [http://en.wikibooks.org/wiki/LaTeX/Page_Layout]) |
|||
<source lang="latex"> |
|||
%UTF-8 encoding “Нelłó worlð!” |
|||
\documentclass[a4paper]{article} |
|||
% Specify paper size univocally (for pdf output) |
|||
\special{papersize=210mm,297mm} |
|||
% Set minimum margin using package geometry |
|||
\usepackage[a4paper,landscape,top=1cm, bottom=1cm, left=0.5cm, right=1cm]{geometry} |
|||
% To support 3-column document, color and highlighting |
|||
\usepackage{multicol,color,soul} |
|||
% Remove any footer / header (page numbers...) |
|||
\pagestyle{empty} |
|||
\begin{document} |
|||
\begin{multicols}{3} |
|||
Some text here\par |
|||
Some more text there\par |
|||
And not anymore\par |
|||
\end{multicols} |
|||
\end{document} |
|||
</source> |
|||
=== Realistic Journal Article === |
|||
<source lang=latex> |
|||
%UTF-8 encoding “Нelłó worlð!” |
|||
\documentclass[a4paper,11pt]{article} |
|||
% define the title |
|||
\author{H.~Partl} |
|||
\title{Minimalism} |
|||
\begin{document} |
|||
% generates the title |
|||
\maketitle |
|||
% insert the table of contents |
|||
\tableofcontents |
|||
\section{Some Interesting Words} |
|||
Well, and here begins my lovely article. |
|||
\section{Good Bye World} |
|||
\ldots{} and here it ends. |
|||
\end{document} |
|||
</source> |
|||
=== Beamer and XeTeX === |
|||
To change the default font in the document with XeTeX, use the fontspec package. The xunicode package provides additional mapping between LaTeX accents and the selected font. A third package, xltxtra provides some fixes relating to fonts. [http://www.woggie.net/2008/07/16/beamer-pdftex-and-xetex/] |
|||
<source lang=latex> |
|||
\documentclass[xetex,mathserif,serif]{beamer} |
|||
\usepackage{fontspec} |
|||
\usepackage{xunicode} %Unicode extras! |
|||
\usepackage{xltxtra} %Fixes |
|||
\setmainfont{Calibri} |
|||
\setmonofont[Scale=0.86]{Andale Mono} |
|||
</source> |
|||
Also nice, use the ''microtype'' package: |
|||
<source lang=latex> |
|||
\usepackage[final,expansion=true,protrusion=true,spacing=true,kerning=true]{microtype} |
|||
</source> |
|||
== Layout and Typesetting == |
|||
Moved to [[LaTeX writing tips]] |
|||
== Conventions and Examples == |
|||
Moved to [[LaTeX writing tips]] |
|||
== Tips / How-to == |
|||
=== Quick debug === |
|||
* Check syntax rapidly by using package ''syntonly'': |
|||
<source lang=latex> |
|||
\usepackage{syntonly} |
|||
\syntaxonly % Comment out this line to produce pages |
|||
</source> |
|||
* Add <code>draft</code> to document class to identify layout issues easily: |
|||
<source lang=latex> |
|||
\documentclass[draft]{article} |
|||
</source> |
|||
=== Remove sub-sections from header in beamer presentation === |
|||
Simplest is to use another outer theme (here <code>infolines</code>): |
|||
<source lang=latex> |
|||
\documentclass{beamer} |
|||
\mode<presentation> |
|||
{ |
|||
\usetheme{Antibes} |
|||
% \usetheme{Hannover} |
|||
\setbeamercovered{transparent} |
|||
% \usefonttheme{structuresmallcapsserif} |
|||
% \usefonttheme{structurebold} |
|||
\usecolortheme{beaver} |
|||
% tree is default outertheme - but infolines is more compact |
|||
% \useoutertheme{tree} |
|||
\useoutertheme{infolines} |
|||
} |
|||
% slidenumbering |
|||
\setbeamertemplate{footline}[frame number] |
|||
\setbeamertemplate{sidebar right}{} |
|||
</source> |
|||
=== Change vertical alignment === |
|||
Simply use the '''<code>[t]</code>''' or '''<code>[c]</code>''' modifier (top / center). For frames: |
|||
<source lang=latex> |
|||
\begin{frame}[t]{The seven permutation army} |
|||
% Top-aligned frame |
|||
\end{frame} |
|||
</source> |
|||
For columns: |
|||
<source lang=latex> |
|||
\begin{columns}[t] |
|||
\begin{column}{0.35\linewidth} |
|||
% 1st top-aligned column |
|||
\end{column} |
|||
\begin{column}{0.65\linewidth} |
|||
% 2nd top-aligned column |
|||
\end{column} |
|||
\end{columns} |
|||
</source> |
|||
=== How to format BibTex entries and cite sources === |
|||
;References |
|||
* Bibtex package, see example file {{file|xampl.bib}} (entries <code>@INBOOK</code>, <code>@BOOK</code>...). |
|||
* Available entry types, and mandatory fields (see [https://en.wikipedia.org/wiki/BibTeX WP:BibTeX]) |
|||
* '''[https://cryptobib.di.ens.fr/ CryptoBib]''' — CryptoBib is a BibTeX database containing papers related to Cryptography, with manually checked entries and uniform BibTeX data. |
|||
;Examples |
|||
Example of bibtex file (extension {{file|.bib}}). |
|||
<source lang=bibtex> |
|||
%UTF-8 (ûτf—8) |
|||
@PREAMBLE{ "\newcommand{\noopsort}[1]{} " |
|||
# "\newcommand{\printfirst}[2]{#1} " |
|||
# "\newcommand{\singleletter}[1]{#1} " |
|||
# "\newcommand{\switchargs}[2]{#2#1} " } |
|||
@STRING{EUROCRYPT = "Advances in Cryptology --- EUROCRYPT"} |
|||
@INPROCEEDINGS{BeRo96pss, |
|||
author = {Mihir Bellare and Phillip Rogaway}, |
|||
title = {The Exact Security of Digital Signatures --- How to Sign with {RSA} and {R}abin}, |
|||
editor = {U. Maurer}, |
|||
booktitle = EUROCRYPT # {'96}, |
|||
volume = 1070, |
|||
series = LNCS, |
|||
pages = {399--416}, |
|||
year = 1996, |
|||
publisher = SPRINGER, |
|||
} |
|||
% Edited year to make sure this entry comes after pkcs1 |
|||
@MISC{RSA93pkcs3, |
|||
author = {{RSA Laboratories}}, |
|||
title = {Public-Key Cryptography Standards ({PKCS}) \#3: {D}iffie-{H}ellman Key-Agreement Standard Version 1.4}, |
|||
month = nov, |
|||
year = "{\noopsort{9999}}1993", |
|||
} |
|||
@MISC{wikipedia:combinadic, |
|||
author = {Wikipedia}, |
|||
title = {Combinatorial number system --- Wikipedia{,} The Free Encyclopedia}, |
|||
year = {2013}, |
|||
howpublished = {\url{https://en.wikipedia.org/wiki/Combinadic}}, |
|||
note = {[Online; accessed 18-June-2014]} |
|||
} |
|||
</source> |
|||
Example of citation: |
|||
<source lang=latex> |
|||
\bibliographystyle{amsplain} |
|||
\providecommand{\shortcite}[1]{\cite{#1}} % For compatibility with other packages |
|||
This as been shown by Bellare and Rogaway~cite{BeRo96pss}. |
|||
This results is a well-known fact~cite{wikipedia:combinadic}. |
|||
\hbadness 10000 % To avoid warning in bibtex entries with urls |
|||
\bibliography{ext,ours} |
|||
</source> |
|||
;Recommendations |
|||
* [http://www.ece.ucdavis.edu/~jowens/biberrors.html Common Errors in Bibliographies — John Owens] |
|||
*;Authors: Make the names in the bibliography match what is printed on the paper. For hyphenated names with the second half uncapitalized (Wu-chun Feng, Wen-mei Hwu), put the hyphen and second half in brackets: <code>Wu-{chun} Feng, Wen{-mei} Hwu</code>. |
|||
*;Capitalization in titles: Follow capitalization as printed on the paper. The bib style should enforce capitalization, not your bibliography. Properly bracket <code>{}</code> words in titles that must be capitalized. |
|||
*;Months: Include the month of publication in your bibliographies. |
|||
*;Pages: Always include pages if pages are available. |
|||
* Search article in [http://citeseerx.ist.psu.edu/index CiteSeerX], and if found, copy bibtex entry. |
|||
* For wikipedia article ''xxx'', use the special wikipedia page<code>Special:Cite/xxx</code> that generates automatically a bibtex entry(eg. [https://en.wikipedia.org/wiki/Special:Cite/Continued_fraction Special:Cite/Continued_fraction]) |
|||
* The simplest solution for URLs is to use the <code>howpublished</code> field [http://www.tex.ac.uk/cgi-bin/texfaq2html?label=citeURL] [http://tex.stackexchange.com/questions/35977/how-to-add-a-url-to-a-latex-bibtex-file]. |
|||
<source lang=latex> |
|||
howpublished = {\url{http://en.wikipedia.org/wiki/RSA\_(cryptosystem)}}, |
|||
</source> |
|||
:Other alternative are to use more modern styles with support of url and <code>url</code> field, or use ''biblatex''. |
|||
* Use curly brackets <code>{}</code> when necessary: keep word together in ''author'' field <code>author = {{RSA Laboratories}}</code> ,protect uppercase words <code>{UPPERCASE}</code>, capitalise all significant words, to allow for bibliography styles that want this [http://tex.stackexchange.com/questions/10772/bibtex-loses-capitals-when-creating-bbl-file] |
|||
<source lang=latex> |
|||
author = {{RSA Laboratories}} |
|||
title = {Pascal, {C}, {Java}: {Were} they all Conceived in {ETH}?} |
|||
</source> |
|||
When citing sources: |
|||
* Don't use bracketed numbers as word: |
|||
<source lang=latex> |
|||
Foo showed that bar~\cite{Foo:2000:BAR} |
|||
Foo showed that bar~\shortcite{Foo:2000:BAR} % +++ BETTER - Avoid name repeat |
|||
In \cite{Foo:2000:BAR}, Foo shows that bar. % !!! BAD |
|||
</source> |
|||
:This requires to add in your document, in case the bibtex style does not support it |
|||
<source lang=latex> |
|||
\providecommand{\shortcite}[1]{\cite{#1}} |
|||
</source> |
|||
* Use <code>~</code> to prevent break before citation and group several citations together using a ''comma'': |
|||
<source lang=latex> |
|||
text text text~\cite{Foo:2000:BAR} |
|||
\cite{AuthorOne:2000:ABC,AuthorTwo:2002:DEF} |
|||
\cite{AuthorOne:2000:ABC}\cite{AuthorTwo:2002:DEF} % !!! BAD !!! |
|||
</source> |
|||
* Convert '''.ris''' to '''.bib''' — Install package ''cb2bib'' and ''bibutils'', then |
|||
/usr/share/cb2bib/c2btools/ris2bib 1996-EUROCRYPT-016.ris output.bib |
|||
* Use <code>{\noopsort{XXX}}</code> to override default sort odering, e.g. in <code>author</code> or <code>year</code> field (see <tt>xampl.bib</tt>). For instance, here we don't change author name but use the fact that year is used as 2nd sort key to make sure second entry comes after the first entry: |
|||
<source lang=bibtex> |
|||
@preamble{ "\newcommand{\noopsort}[1]{} " } |
|||
@MISC{RSA12pkcs1, |
|||
author = {{RSA Laboratories}}, |
|||
title = {Public-Key Cryptography Standards ({PKCS}) \#1: {RSA} Cryptography Specifications Version 2.2}, |
|||
year = {2012}, |
|||
} |
|||
@MISC{RSA93pkcs3, |
|||
author = {{RSA Laboratories}}, |
|||
title = {Public-Key Cryptography Standards ({PKCS}) \#3: {D}iffie-{H}ellman Key-Agreement Standard Version 1.4}, |
|||
year = "{\noopsort{9999}}1993", |
|||
} |
|||
</source> |
|||
An alternative solution is to use <code>\setbox0=\hbox{XXX}</code>: |
|||
<source lang=bibtex> |
|||
@MISC{RSA93pkcs3, |
|||
author = {{RSA Laboratories}}, |
|||
title = {Public-Key Cryptography Standards ({PKCS}) \#3: {D}iffie-{H}ellman Key-Agreement Standard Version 1.4}, |
|||
year = {\setbox0=\hbox{9999}1993}, |
|||
} |
|||
</source> |
|||
;Software |
|||
:'''[https://apps.ubuntu.com/cat/applications/natty/referencer/ Referencer]''' — a GNOME application to organise documents or references, and ultimately generate a BibTeX bibliography file. |
|||
=== Source code listing === |
|||
See package '''minted''' or '''listings''' above. |
|||
=== Fix horizontal alignment === |
|||
* Use <code>\rlap</code> and <code>\phantom</code>. Note that <code>\rlap</code> does not work in math mode, so we apply a workaround (better solution [http://math.arizona.edu/~aprl/publications/mathclap/perlis_mathclap_24Jun2003.pdf here]) |
|||
<source lang=latex> |
|||
$\crtCp \gets \rsacipher \bmod \rsap$ |
|||
{\rlap{$\crtCq$}}$\phantom{\crtCp} \gets \rsacipher \bmod \rsaq$ |
|||
</source> |
|||
* Use <code>\array</code>, and play with <code>[pos]</code> option for vertical alignment in the paragraph, and <code>@{}</code> to suppress inter-column space: |
|||
<source lang=latex> |
|||
$\begin{array}[t]{@{}r@{}l} |
|||
\crtCp &\ \gets \rsacipher \bmod \rsap \\ |
|||
\crtCq &\ \gets \rsacipher \bmod \rsaq |
|||
\end{array}$ |
|||
</source> |
|||
* Fix unwanted space when using <code>\left ... \right</code>. Insert negative space <code>\!</code> (see [http://tex.stackexchange.com/questions/40829/equation-using-left-brackets-inserts-unwanted-space] for better solution) |
|||
<source lang=latex> |
|||
\newcommand{\BigO}[1]{\ensuremath{\operatorname{O}\!\left(#1\right)}} |
|||
</source> |
|||
=== Find LaTeX symbols === |
|||
See the [[{{PAGENAME}}#Links|Links]] section. |
|||
For instance, Detexify{{e|2}} or shapecatcher.com recognize symbols drawn with the mouse. There are also extensive symbol lists. |
|||
=== Force big floats after current page === |
|||
Say you have a document with lots of big figures or listings that you put in ''floats''. LaTeX usual behavior with such big floats appears quite frustrating, and usually pushes these floats up to the end of current chapter / section. |
|||
The solution ''apparently'' is to always give all placement specifier <code>[htbp]</code>, which let LaTeX chooses the best option. If this does not work, one can force LaTeX with <code>[p!]</code>: |
|||
<source lang=latex> |
|||
\begin{listing}[htbp] |
|||
%\begin{listing}[p!] % To force float to next page |
|||
\begin{minted}{python} |
|||
... |
|||
\end{minted} |
|||
\end{listing} |
|||
</source> |
|||
Another solution would be to use package {{deb|afterpage}} [http://mintaka.sdsu.edu/GF/bibliog/latex/floats.html], but I sometimes get error about ''lost floats'' (see [http://tex.stackexchange.com/questions/162670/ this question]): |
|||
... Float(s) lost |
|||
... This may be a LaTeX bug. |
|||
<source lang=latex> |
|||
% In preamble: |
|||
\usepackage{afterpage} |
|||
% Before the float, ask to call \clearpage after current page: |
|||
\afterpage{\clearpage} |
|||
\begin{listing}[htbp] % We let LaTeX choose best placement (not necessarily next page) |
|||
\begin{minted}{python} |
|||
... |
|||
\end{minted} |
|||
\end{listing} |
|||
</source> |
|||
=== Add vertical space between tables === |
|||
Use <code>\par\vspace{2em}</code> (see also [http://tex.stackexchange.com/questions/38893/cant-generate-vertical-space-between-tables], but <code>/newline</code> does not work). This combination is the most stable and doesn't require empty lines: |
|||
<source lang=latex> |
|||
\begin{tabular}{c|l} |
|||
%... |
|||
\end{tabular} |
|||
\par\vspace{2em} |
|||
\begin{tabular}{c|l} |
|||
%... |
|||
\end{tabular} |
|||
</source> |
|||
=== Syntax / style checker for LaTeX === |
|||
Use package {{deb|chktex}} or {{deb|lacheck}}. |
|||
=== Define minipage width === |
|||
<source lang=latex> |
|||
\begin{minipage}{\linewidth} % Use current line width as minipage width |
|||
% ... |
|||
\captionof{table}[short]{Long} |
|||
\end{minipage} |
|||
</source> |
|||
Several options [http://tex.stackexchange.com/questions/124323/tabularx-within-the-enumerate-environment]: |
|||
* Use <code>\textwidth</code>, which stays constant. |
|||
* Use <code>\linewidth</code>, which adapts to surrounding environment (like <code>enumerate</code> or <code>itemize</code> |
|||
=== Fix Overfull \hbox === |
|||
* Use <code>sloppy</code> or better, <code>\begin{sloppypar}...\end{sloppypar}</code> to tell LaTeX to temporarily relax metrics regarding maximum interword / intercharacter spacing... |
|||
* Use <code>\noindent</code> and comments <code>%</code> to prevent LaTex from inserting space that would create overflow. For insance: |
|||
{| width=100% |
|||
This overflows. |
|||
|<source lang=latex> |
|||
\begin{minipage}{.40\linewidth} |
|||
Hello, |
|||
\end{minipage} |
|||
\hfill |
|||
\begin{minipage}{.60\linewidth} |
|||
World! |
|||
\end{minipage} |
|||
</source> |
|||
| |
|||
This doesn't. |
|||
|<source lang=latex> |
|||
\noindent\begin{minipage}{.40\linewidth} |
|||
Hello, |
|||
\end{minipage}% don't let LaTeX insert space here |
|||
\hfill |
|||
\begin{minipage}{.60\linewidth} |
|||
World! |
|||
\end{minipage} |
|||
</source> |
|||
|} |
|||
=== Mute Overfull \vbox warning (beamer) === |
|||
We can use negative <code>vpspace</code> to silence the <code>Overfull vbox</code> warning: |
|||
<source lang="latex"> |
|||
\begin{frame}{Title} |
|||
\begin{columns}%[b]%[t] |
|||
\begin{column}{0.5\textwidth} |
|||
\begin{itemize} |
|||
\item Some text |
|||
\end{itemize} |
|||
\end{column} |
|||
\begin{column}{0.5\textwidth} |
|||
\center \includegraphics[height=0.8\textheight]{img.pdf} |
|||
\footnotesize A picture |
|||
\vspace*{-20pt} % Mute the overfull vbox warning |
|||
\end{column} |
|||
\end{columns} |
|||
\end{frame} |
|||
</source> |
|||
By adding the <code>vspace</code> after the last line, it will not change the layout. |
|||
=== Place figure side-by-side === |
|||
See [[#subcaption|package subcaption]]. |
|||
=== Drawing on top of an image === |
|||
Using {{deb|tikz}} (see [http://tex.stackexchange.com/questions/9559/drawing-on-an-image-with-tikz]). Use a <code>scope</code> such that <code>(0,0)</code> is bottom left of the picture, and <code>(1,1)</code> is top right. |
|||
<source lang=latex> |
|||
\begin{tikzpicture} |
|||
\node[anchor=south west,inner sep=0] (image) at (0,0) |
|||
{\includegraphics[width=0.9\textwidth]{matrix-ranking.png}}; |
|||
\begin{scope}[x={(image.south east)},y={(image.north west)}] |
|||
% This draw a grid with label |
|||
\draw[help lines,densely dotted,xstep=.02,ystep=.02] (0,0) grid (1,1); |
|||
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1); |
|||
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; } |
|||
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; } |
|||
% Use the grid above to draw at desired place |
|||
\draw[green,line width=3pt] (0.4,0.5) rectangle ++(0.2,0.1); |
|||
\end{scope} |
|||
\end{tikzpicture} |
|||
</source> |
|||
Another option is to use package {{deb|overpic}}. |
|||
<source lang=latex> |
|||
\usepackage[percent]{overpic} |
|||
\begin{overpic}[scale=.25]{golfer.ps} |
|||
\put(5,45){\huge \LaTeX} |
|||
\put(55,10){\includegraphics[scale=.07] {golfer.ps}} |
|||
\end{overpic} |
|||
</source> |
|||
=== Preventing page breaks between lines / Handling widows and orphans === |
|||
See [http://www.tex.ac.uk/cgi-bin/texfaq2html?label=nopagebrk http://www.tex.ac.uk/cgi-bin/texfaq2html?label=nopagebrk]. |
|||
* Use environment <code>samepage</code> |
|||
* Enclose all relevant stuff in a <code>\parbox</code> or <code>minipage</code>. |
|||
* ... (use <code>\raggedbottom</code>...) |
|||
To handle orphans (single line at bottom of the page) / widows (top of the page) [http://tex.stackexchange.com/questions/4152/how-do-i-prevent-widow-orphan-lines]: |
|||
<source lang=latex> |
|||
\widowpenalty10000 |
|||
\clubpenalty10000 |
|||
</source> |
|||
Other tricks: |
|||
* Use <code>sloppypar</code> (see [http://handyfloss.wordpress.com/category/latex-for-non-masochists/page/2/]). |
|||
=== Find files in texlive distribution === |
|||
kpsewhich latex.ltx |
|||
=== Get documentation on package === |
|||
texdoc source2e |
|||
=== Add line breaks in table cell === |
|||
* Define the command [http://tex.stackexchange.com/questions/2441/how-to-add-a-forced-line-break-inside-a-table-cell] |
|||
<source lang=latex> |
|||
\newcommand{\specialcell}[2][c]{% |
|||
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}} |
|||
</source> |
|||
Use it as follows: |
|||
<source lang=latex> |
|||
Foo bar & \specialcell{Foo\\bar} & Foo bar \\ % vertically centered |
|||
Foo bar & \specialcell[t]{Foo\\bar} & Foo bar \\ % aligned with top rule |
|||
Foo bar & \specialcell[b]{Foo\\bar} & Foo bar \\ % aligned with bottom rule |
|||
</source> |
|||
* Alternatively, use <code>\shortstack</code> [http://tex.stackexchange.com/questions/38924/newline-in-a-table-cell-which-is-centered] |
|||
<source lang=latex> |
|||
\documentclass{article} |
|||
\begin{document} |
|||
\begin{tabular}{ccc} |
|||
one & two & three \\ |
|||
one & two & \shortstack{a \\ bb \\ c}\\ |
|||
\end{tabular} |
|||
\end{document} |
|||
</source> |
|||
* Use <code>\newline</code> [http://tex.stackexchange.com/questions/485/how-to-break-a-line-in-a-table] |
|||
<source lang=latex> |
|||
\begin{tabular}{|p{3cm}|p{3cm}|} |
|||
first line |
|||
\newline second line & still on first line \\ |
|||
\end{tabular} |
|||
</source> |
|||
* Use <code>\parbox</code>, but this does not look convenient |
|||
<source lang=latex> |
|||
\begin{tabular}{ll} |
|||
one line& \parbox[t]{5cm}{another\\column}\\ |
|||
second line here& and here |
|||
\end{tabular} |
|||
</source> |
|||
* Other solutions: use <code>\makecell</code> [http://tex.stackexchange.com/questions/38924/newline-in-a-table-cell-which-is-centered] |
|||
=== Avoid TeX commands === |
|||
* Don't use <code>$$</code> in LaTeX, it is a plain TeX command. |
|||
=== Circled numbers and letters === |
|||
Use the following command [http://tex.stackexchange.com/questions/7032/good-way-to-make-textcircled-numbers]: |
|||
<source lang=latex> |
|||
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{ |
|||
\node[shape=circle,draw,inner sep=1pt] (char) {#1};}} |
|||
</source> |
|||
For instance: |
|||
<source lang=latex> |
|||
The answer is $\circled{12}$. |
|||
</source> |
|||
Adapt blank separation as necessary (<code>sep=1pt</code>). |
|||
=== Highlight differences between two versions === |
|||
Use CTAN package [http://www.ctan.org/tex-archive/support/latexdiff/ latexdiff] (also in Debian/Ubuntu repositories): |
|||
<source lang=bash> |
|||
latexdiff paper-old.tex paper-new.tex > paper.tex |
|||
</source> |
|||
See manpages for more options. |
|||
When LaTeX files are in a git repository, the most advanced solution is to use [https://gitlab.com/git-latexdiff/git-latexdiff git-latexdiff] [https://tex.stackexchange.com/questions/1325/using-latexdiff-with-git SE]... But doesn't work great with XeLaTeX or advanced TEX setup. |
|||
This is a simple script: |
|||
<source lang="bash"> |
|||
#! /bin/bash |
|||
latexdiffthis() |
|||
{ |
|||
git checkout HEAD -- $1 |
|||
git show HEAD^:$1 > $1.HEAD~1 |
|||
latexdiff $1.HEAD~1 $1 | sponge $1 |
|||
rm $1.HEAD~1 |
|||
} |
|||
latexdiffthis ./Xoodyak-submission.tex |
|||
latexdiffthis ../Xoodyak-macros.tex |
|||
latexdiffthis ../XoodyakUsage.tex |
|||
</source> |
|||
=== Layout a tabular === |
|||
* [https://tex.stackexchange.com/questions/37236/when-i-use-shrink-i-lose-vertical-centering-how-do-i-get-my-stuff-shrunk-and Stackexchange]. |
|||
Available stuff: |
|||
* Use <code>\\[1.5ex]</code> at the end of a line to increase vertical space |
|||
<source lang="latex"> |
|||
Disgust & & &.34 (.01) & & .23 (.07) & .25 (.05) & .19 (.13) \\[1.5ex] |
|||
$R^2$ & .12 & .11 & .11 & .20 & .17 & .17 & .22 \\ |
|||
</source> |
|||
* Add separating line of various size |
|||
<source lang="latex"> |
|||
\toprule |
|||
\bottomrule |
|||
\midrule |
|||
\midrule[\heavyrulewidth] |
|||
</source> |
|||
* Use <code>tabular*</code> to get a table that occupies the full <code>\textwidth</code> |
|||
* Use <code>\setlength{\tabcolsep}{4.45pt}</code> to change the default column separation |
|||
;An example |
|||
<source lang="latex"> |
|||
\documentclass{beamer} |
|||
\usepackage{booktabs} |
|||
\setlength{\tabcolsep}{4.45pt} |
|||
\begin{document} |
|||
\scriptsize |
|||
\begin{frame}{Correlations between Harm, Unfairness and Disgust} |
|||
\begin{tabular*}{\textwidth}{@{}l@{\extracolsep{\fill}}*{7}{l}@{}} |
|||
\multicolumn{8}{@{}p{\textwidth}}{\textbf{Table 3.} All possible regressions |
|||
of harm, unfairness, and disgust predicting punishment} \\ |
|||
\midrule[\heavyrulewidth] |
|||
& M1 & M2 & M3 & M4 & M5 & M6 & M7 \\ |
|||
\midrule |
|||
Harm & .35 (.01) & & & .20 (.15) & & .24 (.07) & .14 (.31) \\ |
|||
Unfairness & & .41 (.01) & & .31 (.02) & .34 (.01) & & .28 (.04) \\ |
|||
Disgust & & &.34 (.01) & & .23 (.07) & .25 (.05) & .19 (.13) \\[1.5ex] |
|||
$R^2$ & .12 & .11 & .11 & .20 & .17 & .17 & .22 \\ |
|||
\midrule[\heavyrulewidth] |
|||
\multicolumn{8}{@{}l}{Note: Standardized beta coefficients, |
|||
with p values in parentheses} \\ |
|||
\end{tabular*} |
|||
\end{frame} |
|||
\end{document} |
|||
</source> |
|||
== Beamer == |
|||
* http://tug.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf (or debian package {{deb|texlive-latex-recommended-doc}}) |
|||
=== Minimal example === |
|||
Minimal example using theme <code>metropolis</code> [https://github.com/matze/mtheme]. |
|||
<source lang="latex"> |
|||
\documentclass{beamer} |
|||
\usetheme{metropolis} % Use metropolis theme |
|||
\title{A minimal example} |
|||
\date{\today} |
|||
\author{Matthias Vogelgesang} |
|||
\institute{Centre for Modern Beamer Themes} |
|||
\begin{document} |
|||
\maketitle |
|||
\section{First Section} |
|||
\begin{frame}{First Frame} |
|||
Hello, world! |
|||
\end{frame} |
|||
\end{document} |
|||
</source> |
|||
=== Tips === |
|||
==== List all available Beamer themes ==== |
|||
<source lang="bash"> |
|||
locate -br "beamertheme.*sty" |
|||
# /usr/share/texlive/texmf-dist/tex/latex/beamer/beamerthemeAnnArbor.sty |
|||
# /usr/share/texlive/texmf-dist/tex/latex/beamer/beamerthemeAntibes.sty |
|||
# /usr/share/texlive/texmf-dist/tex/latex/beamer/beamerthemeBergen.sty |
|||
</source> |
|||
==== How to show background image in just one frame? ==== |
|||
Set the background image with <code>\usebackgroundtemplate</code>. Restrict it to a single frame by enclosing it withing '''braces'''. |
|||
<source lang="latex"> |
|||
{ |
|||
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{back.png}} |
|||
\begin{frame}{Title} |
|||
Content |
|||
\end{frame} |
|||
} |
|||
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{image.png}} |
|||
</source> |
|||
==== Silent overfull vbox ==== |
|||
Seeing a warning like: |
|||
;Overfull \vbox (9.41396pt too high) has occurred while ... |
|||
An easy way to acknowledge and silent the deviation is to add [https://tex.stackexchange.com/questions/24314/overfull-vbox-with-beamercolorbox]: |
|||
<source lang="latex"> |
|||
\vspace*{-9.41396pt} % Silent overfull vbox |
|||
</source> |
|||
==== Shrink content to fit on a slide ==== |
|||
There are several methods [https://tex.stackexchange.com/questions/37236/when-i-use-shrink-i-lose-vertical-centering-how-do-i-get-my-stuff-shrunk-and], [https://tex.stackexchange.com/questions/78514/content-doesnt-fit-in-one-slide]: |
|||
* Use <code>[shrink]</code> to fit automatically, or with some number <code>[shrink=20]</code> for manual shrinking: |
|||
<source lang="latex"> |
|||
\begin{frame}[shrink=20]{Title} |
|||
\lipsum[2]\lipsum[3] |
|||
\end{frame} |
|||
</source> |
|||
:Problem is that usually the vertical / horizontal centering is lost, and shrinking must be manually adapted for best result. |
|||
* Use <code>minipage</code> with <code>c</code> to force centering: |
|||
<source lang="latex"> |
|||
\begin{frame}[shrink=35]{Title} |
|||
\begin{minipage}[c][1.3\paperheight][c]{\textwidth} |
|||
\centering |
|||
\lipsum[2]\lipsum[3] |
|||
\end{minipage} |
|||
\end{frame} |
|||
</source> |
|||
* Use <code>\resizebox</code> from <code>graphicx</code> package: |
|||
<source lang="latex"> |
|||
\usepackage{graphicx} % loaded by beamer, but included here for explicitness |
|||
\begin{frame}{Title} |
|||
\begin{center} |
|||
\resizebox{\textwidth}{!}{% |
|||
\lipsum[2]\lipsum[3]% |
|||
} |
|||
\end{center} |
|||
\end{frame} |
|||
</source> |
|||
* Use <code>\scalebox</code> from <code>graphicx</code> package: |
|||
<source lang="latex"> |
|||
\usepackage{graphicx} |
|||
\begin{frame}{Title} |
|||
\centering\scalebox{0.7}{ |
|||
\lipsum[2]\lipsum[3] |
|||
\end{frame} |
|||
</source> |
|||
* If resize a tabular, there are several parameters that can be played with. |
|||
==== Hide page number of some frame ==== |
|||
We can create a group with <code>\begingroup ... \endgroup</code> and change the <code>footline</code> [https://www.iditect.com/how-to/54916411.html]: |
|||
<source lang="latex"> |
|||
\documentclass{beamer} |
|||
\setbeamertemplate{footline}[frame number] |
|||
\begin{document} |
|||
\begin{frame} |
|||
normal frame |
|||
\end{frame} |
|||
\begingroup |
|||
\setbeamertemplate{footline}{} |
|||
\begin{frame} |
|||
without footline |
|||
\end{frame} |
|||
\endgroup |
|||
\begin{frame} |
|||
normal frame |
|||
\end{frame} |
|||
\end{document} |
|||
</source> |
|||
==== Use <code>\pause</code> to preserve list valign ==== |
|||
Using <code>\pause</code> will tell Beamer to preserve the vectical alignment of list items during animation. |
|||
==== Hide fragile content on a slide ==== |
|||
Use <code>\begin{onlyenv}<1></code> to hide fragile content in a frame (eg minted, verbatim...): [https://tex.stackexchange.com/questions/371427/minted-in-beamer-overlays] |
|||
<source lang="latex"> |
|||
\documentclass{beamer} |
|||
\usepackage{minted} |
|||
\begin{document} |
|||
\begin{frame}[fragile] |
|||
\begin{onlyenv}<2> |
|||
\begin{minted}{agda} |
|||
test |
|||
\end{minted} |
|||
\end{onlyenv} |
|||
\end{frame} |
|||
\end{document} |
|||
</source> |
|||
== Troubleshoot == |
|||
;LaTeX Error: Cannot determine size of graphic (no BoundingBox) |
|||
: LaTeX does not find the BoundingBox information which is necessary to produce the {{file|.dvi}} file. A way to fix this is either to edit the graphic to add the bounding box information, or to use '''pdflatex''' to produce directly a {{file|.pdf}} file. |
|||
;Missing table of content (file *.toc not found) |
|||
: This happens when the command <tt>\tableofcontents</tt> is used in the document, but LaTeX did not produce yet a table of content file. The {{file|.toc}} file is produced at the first invocation. To solve this, just run LaTex a second time: |
|||
<source lang=bash> |
|||
pdflatex mypresentation.tex # produce a pdf without toc, and a toc file |
|||
pdflatex mypresentation.tex # produce a pdf with toc generated in the previous pass |
|||
</source> |
|||
;"seac" character deprecated in Type 2 charstring |
|||
:We get the following error from XeTeX. |
|||
** WARNING ** "seac" character deprecated in Type 2 charstring. |
|||
** ERROR ** Type2 Charstring Parser: Parsing charstring failed: (status=-1, stack=5) |
|||
Output file removed. |
|||
:This happens when using OpenType fonts (OTF) with accented characters (even '''i''' counts as accented!). |
|||
:The possible fixes are either to use another font, convert the font to TTF, or fix the buggy OTF. |
|||
;Command \sups already defined. |
|||
:Occurs when compiling with <code>xelatex</code>. See file {{file|/usr/share/texmf/tex/latex/tipa/tipa.sty}}, line 478. |
|||
:This is apparently a conflict between ''tipa'' and ''fontspec'' in TeXLive2012 (TeXLive2009 seems ok, see [http://tex.stackexchange.com/questions/101632/tipa-suppress-tonestembar-no-longer-works-in-fontspec]) |
|||
;"Underfull \hbox (badness 10000) in paragraph at lines X--Y" in bibliography with url |
|||
* Add code below to preamble. This LaTeX to allow huge badness when using sloppy command (from [http://tex.stackexchange.com/questions/10924/underfull-hbox-in-bibliography]) |
|||
<source lang=latex> |
|||
\usepackage{etoolbox} |
|||
\apptocmd{\sloppy}{\hbadness 10000\relax}{}{} % To avoid warning in bibtex entries with urls |
|||
</source> |
|||
* Alternatively, simply increase <code>hbadness</code> before bibliography section: |
|||
<source lang=latex> |
|||
\hbadness 10000 % To avoid warning in bibtex entries with urls |
|||
\bibliography{ext} |
|||
</source> |
|||
;"Missing elsarticle.cls" |
|||
* Install package '''texlive-publishers''' to get ''elsarticle.cls'' (since TeXLive 2012 — was part of ''texlive-latex-extra'' in TeXLive 2009). |
|||
;"auto expansion is only possible with scalable fonts" (when using ''microtype'' and ''fourier'' (aka utopia) package) |
|||
* We get the following message when compiling with <code>pdflatex</code>: |
|||
[1{/home/beq06659/.texmf-var/fonts/map/pdftex/updmap/pdftex.map} |
|||
! pdfTeX error (font expansion): auto expansion is only possible with scalable |
|||
fonts. |
|||
\AtBegShi@Output ...ipout \box \AtBeginShipoutBox |
|||
\fi \fi |
|||
l.105 |
|||
* The error is because ''pdftex.map'' is located in user's profile and is not up-to-date [http://tex.stackexchange.com/questions/31388/getting-strange-error-with-miktex-when-trying-to-use-kpfonts-package]. '''Update pdftex.map with''': |
|||
<source lang=bash> |
|||
updmap # Update pdftex.map |
|||
</source> |
|||
;hyperref — Failed to convert input string to UTF16 |
|||
We get this warning when using package ''hyperref'', with option <code>unicode</code>: |
|||
** WARNING ** Failed to convert input string to UTF16... |
|||
The solution is to add option <code>pdfencoding=auto</code> [http://tex.stackexchange.com/questions/66722/tex-live-2012-xelatex-moderncv-error-failed-to-convert-input-string-to-utf1]: |
|||
<source lang=latex> |
|||
\usepackage[unicode=true,pdfencoding=auto]{hyperref} |
|||
</source> |
|||
; Package hyperref — Warning: Token not allowed in a PDF string (Unicode): removing `\\' |
|||
* We get this with <code>\author[X, Y]{X \\ Y}</code>. The solution is to use <code>\texorpdfstring{ \\ }{}</code> [https://tex.stackexchange.com/questions/10555/hyperref-warning-token-not-allowed-in-a-pdf-string]. |
|||
;Float(s) lost... This may be a LaTeX bug. |
|||
We can get this message when using package ''minted'' and ''afterpage''. It seems to happen when we insert a float right after the first paragraph on a page. The bug seems related to both ''minted'' and ''afterpage'' because removing any of these package fixes the bug (note that the bug occurs even if the float does not use ''minted''). |
|||
<source lang=latex> |
|||
\afterpage{\clearpage} |
|||
\begin{figure}[htpb] |
|||
abracadabra |
|||
\end{figure} |
|||
</source> |
|||
There is no fix I know of. The only workaround is to move the figure up or down in the text so that it is no longer inserted after the first paragraph on a page. |
|||
Note that a better option seems to remove <code>afterpage</code>, and set the placement specifier correctly instead. |
|||
;Extra '\fi' with <code>IEEEeqnarray</code> - with package cleveref / IEEEtrantools |
|||
* Bug is due to cleveref still using deprecated function of IEEEtrantools (<code>\if@IEEEissubequation</code> and <code>\if@IEEElastlinewassubequation</code>) |
|||
* A temp fix |
|||
<source lang=latex> |
|||
\makeatletter |
|||
\newif\if@IEEEissubequation |
|||
\@IEEEissubequationfalse |
|||
\makeatother |
|||
\usepackage[capitalize,noabbrev]{cleveref} |
|||
</source> |
|||
;{{red|1=Never use <code>_</code> in a filename (e.g. <code>\includegraphics</code>)}} |
|||
* LaTeX will take <code>_</code> as subscript character, and will produce strange errors. |
|||
;Package babel Error - Unknown option `francais'. Either you misspelled it or the language definition file french.ldf was not found |
|||
<source lang=latex> |
|||
\usepackage[francais]{babel} |
|||
</source> |
|||
* Install package {{deb|texlive-lang-french}}. |
|||
;Overfull \vbox (9.41396pt too high) has occurred while ... |
|||
* This occurs when the content exceed the available vertical space. An easy way to acknowledge and silent the deviation is to add [https://tex.stackexchange.com/questions/24314/overfull-vbox-with-beamercolorbox] |
|||
<source lang="latex"> |
|||
\vspace*{-9.41396pt} % Silent overfull vbox |
|||
</source> |
|||
;beamer.tex|| LaTeX Font Warning Font shape 'TU/ppl/m/n' undefined using 'TU/lmr/m/n' instead on input line ... |
|||
* Error was due to using <code>\mathrm{AES}</code> in a formula. |
|||
* The solution was simply to use <code>\text{AES}</code> (might require package {{deb|amsmath}}) |
|||
== Graphics in LaTeX == |
|||
=== Insert graphics in LaTeX === |
|||
Use the command <code>includegraphics</code>: from package {{deb|graphicx}}. Ideally, graphics dimensions are given relative to current <code>\linewidth</code> and <code>\textheight</code>. Usually graphics are inserted in a <code>figure</code> environment. |
|||
<source lang=latex> |
|||
\begin{figure}[htpb] |
|||
% Insert a graphics with given max width and height, but keeping aspect ratio |
|||
\includegraphics[width=\linewidth,height=\textheight,keepaspectratio]{picture} |
|||
\end{figure} |
|||
</source> |
|||
=== Optimize === |
|||
* Export graphics as '''PDF''' and '''PNG''', and put both in the same folder. |
|||
* Import graphics with <code>includegraphics</code>, but '''omit''' extension. |
|||
* In image format preference, choose '''PNG''' for fast rendering, or '''PDF''' for quality rendering. |
|||
=== {{pgftikz}} === |
|||
{{pgftikz}} is a graphical interpreter that produces high-quality graphics. See page [[PGF/TikZ]]. |
|||
=== Asymptote === |
|||
[http://asymptote.sourceforge.net/ Asymptote] is a powerful descriptive vector graphics language that provides a natural coordinate-based framework for technical drawing. |
|||
=== Visio 2010 and later === |
|||
Starting from ''Visio 2010'', we can save any drawing directly in PDF. However they must be on separate page, and margin must be set to 0 [http://support.microsoft.com/kb/980530]: |
|||
# On the '''File''' tab, click '''Options''', and then in the navigation pane, click '''Customize Ribbon'''. |
|||
# In the '''Main Tabs''' pane, click to select the '''Developer''' check box, and then click '''OK'''. |
|||
# On the '''Developer''' tab, click '''Show ShapeSheet''', and then click '''Page'''. |
|||
# In the '''Print Properties''' section of the '''ShapeSheet''', set the following values to '''0''': |
|||
#* '''PageLeftMargin''' |
|||
#* '''PageRightMargin''' |
|||
#* '''PageTopMargin''' |
|||
#* '''PageBottomMargin''' |
|||
# On the '''Design''' tab, click '''Size''' and then '''Fit to drawing'''. |
|||
# On the '''File''' tab, select '''Save As''', and select '''.pdf''' as file type. |
|||
=== Visio 2007 === |
|||
# Go to menu '''File → Page Setup''' |
|||
#* Go to '''Page Size''' panel |
|||
#* Select '''Size to fit drawing contents''' |
|||
# Go to menu '''File → Publish as PDF or XPS''' |
|||
=== Visio (alternatives) === |
|||
== |
==== Method 1: Using OpenOffice Draw ==== |
||
=== Method 1: Using OpenOffice Draw === |
|||
This procedure creates from a '''Visio''' drawing, a '''PDF''' file that has the correct page dimension in order to be directly imported in a LaTeX document. This procedure requires to have '''OpenOffice Draw''' installed. |
This procedure creates from a '''Visio''' drawing, a '''PDF''' file that has the correct page dimension in order to be directly imported in a LaTeX document. This procedure requires to have '''OpenOffice Draw''' installed. |
||
* In Visio, '''File → Save As''', select type '''Enhanced Metafile (.emf)''', enter a file name, click '''Save'''. |
* In Visio, '''File → Save As''', select type '''Enhanced Metafile (.emf)''', enter a file name, click '''Save'''. |
||
Line 15: | Line 2,008: | ||
epstopdf <filename.eps> |
epstopdf <filename.eps> |
||
</source> |
</source> |
||
which will create a file |
which will create a file {{file|<filename.pdf>}} with the correct page size. |
||
;Limitations |
;Limitations |
||
:Some line formats are not correctly rendered by ''OpenOffice Draw'' when exporting to '''EPS''' format. |
:Some line formats are not correctly rendered by ''OpenOffice Draw'' when exporting to '''EPS''' format. |
||
=== Method 2: Using Custom PostScript Page Size === |
==== Method 2: Using Custom PostScript Page Size ==== |
||
This procedure can be used to solve problem in the 1st method where some line formats are not correctly rendered in the EPS. This procedure requires to have a PDF printer installed, such as [http://www.primopdf.com/ PrimoPDF]. |
This procedure can be used to solve problem in the 1st method where some line formats are not correctly rendered in the EPS. This procedure requires to have a PDF printer installed, such as [http://www.primopdf.com/ PrimoPDF]. |
||
* In Visio, select the drawing to print, and '''copy-paste it into a new document'''. |
* In Visio, select the drawing to print, and '''copy-paste it into a new document'''. |
||
Line 40: | Line 2,033: | ||
;Limitations |
;Limitations |
||
:Sometimes text police are rasterized. |
:Sometimes text police are rasterized. |
||
==== Method 3: Using Postscript printer and Perl script ==== |
|||
This method is explained [http://bliss.biology.yale.edu/~zasha/latexexample/index.html here]. |
|||
* Install the [http://www.adobe.com/support/downloads/product.jsp?product=44&platform=Windows Adobe Generic Postscript Driver]. |
|||
* Configure the printer to use EPS, i.e. right click on the printer → Printer Preferences... → click Advanced button → open Document Options → PostScript Options → Under PostScript Output Option, select "Encapsulated PostScript (EPS)". |
|||
* In Visio, print your drawing to the postscript printer. |
|||
* The bounding box is incorrectly set to the page size. To fix it, use the perl script [http://bliss.biology.yale.edu/~zasha/latexexample/TightBoundingBox.pl TightBoundingBox.pl], also copied below (requires <tt>gs</tt> command from cygwin). |
|||
{{pl2|{{hiddenSourceFile||TightBoundingBox.pl|content=<source lang="perl"> |
|||
# usage: perl TightBoundingBox.pl <file.eps> |
|||
# calculates a tight bounding box (using the 'gs' command) and sets that bounding box into <file.eps>. This is useful where file.eps was created from Visio by printing to the Adobe Generic Postscript Printer into <file.eps> |
|||
$inputFileName=$ARGV[0]; |
|||
# first, find bbox dimensions |
|||
$bbox=""; |
|||
#-sOutputFile=temp_file.bbox |
|||
open(GS,"gs -dNOPAUSE -dBATCH -sDEVICE=bbox -sOutputFile=- $inputFileName 2>&1 |"); |
|||
while (<GS>) { |
|||
chop; |
|||
if (/^\%\%BoundingBox: (.*)/) { |
|||
$bbox=$1; |
|||
} |
|||
} |
|||
close(GS); |
|||
#print $bbox; |
|||
# now substitute this into file |
|||
$tempFileName="temp_file.eps"; |
|||
system "cat $inputFileName | tr -d \"\r\" > $tempFileName"; |
|||
open(IN,"$tempFileName"); |
|||
#open(OUT,">t2.eps"); # don't clobber the input, just for testing |
|||
open(OUT,">$inputFileName"); |
|||
while (<IN>) { |
|||
chop; |
|||
$gotBbox=0; |
|||
if (/^\%\%(.*)BoundingBox: .*/) { |
|||
print OUT "%%"."$1BoundingBox: $bbox\n"; |
|||
} |
|||
else { |
|||
print OUT "$_\n"; |
|||
} |
|||
} |
|||
close(IN); |
|||
close(OUT); |
|||
</source> |
|||
}} }} |
|||
==== Other methods ==== |
|||
* Give a try to '''metafile2eps''', a tool from LyX to convert EMF to EPS [http://aklassapart.wordpress.com/2011/09/28/visio-diagrams-in-latex-exporting-to-eps/] |
|||
=== Inkscape === |
|||
; Importing Inkscape + LaTeX |
|||
See [http://www.ctan.org/tex-archive/info/svg-inkscape SVG-Inkscape], in particular the guide to include [http://mirrors.ctan.org/info/svg-inkscape/InkscapePDFLaTeX.pdf Inkscape graphics with LaTeX]. |
|||
=== Draw.io === |
|||
;Export PDF |
|||
# Select '''File''', '''Export As''', '''PDF...''' |
|||
# Select '''Crop''', and optionally '''Selection Only'''. |
|||
== Exporting / editng LaTeX equations == |
|||
There are many editors out there. The best one however seems to be '''[http://klatexformula.sourceforge.net/ KLatexFormula]. |
|||
* Windows / Linux support |
|||
* Instant rendering |
|||
* Drag & drop support |
|||
* Can reopen equations saved in PNG format |
|||
Alternatives: |
|||
* Latexeqedit — limited to 300dpi, slow rendering, only PNG, cannot re-open |
|||
* Latexee — very slow |
|||
* EqualX &mdahs; no export, only for building the formula |
|||
== References == |
|||
<references/> |
Latest revision as of 10:45, 24 April 2023
Links
- Related pages on this wiki
- LaTeX writing tips
Style, layout, mathematical writing tips - JsMath
- MathJax
- KaTeX
- Personal pages
- External references
- Manuals:
- short-math-guide.pdf (local copy)
- The Not So Short Introduction to LaTeX 2e
- The LaTeX Companion, 2e ed (bought as e-book)
- LaTeX cheat sheet
- LaTeX2e unofficial reference manual
- The beamer user guide (also in package texlive-latex-recommended-doc, file beameruserguide.pdf).
- Wiki
- Tips
- Nice styles
- Creating .EPS with VISIO
- Importing Graphics (\includegraphics, \usepackage{graphicx})
- Beamer by Example (TUG) (\onslide, \only)
- LaTeX/Presentations
- Beamer gallery — list of available themes for presentation, with screenshots.
- Conseils pour bien taper un document LaTeX (conseils_latex.pdf) — Good tips for math typesetting in LaTeX (TODO).
- Symbols:
- Detexify2 - LaTeX symbol classifier (Draw the symbol to find it!)
- shapecatcher.com - unicode character recognition
- The Comprehensive LaTeX Symbol List (5913 symbols,file symbols-a4.pdf)
- unicode-math package (see unimath-symbols.pdf, also in LaTeX documentation)
- See Unicode page
- Graphics:
- GeoGebra — an extremely powerful tool to draw geometry figures.
Can export in many formats, including PSTricks, PGF/TikZ, PNG, ...
- GeoGebra — an extremely powerful tool to draw geometry figures.
- Tools
- TexMaker
- Overleaf (online editor)
- ShareLatex (online editor).
- PDF viewer
- See Linux Software
Install
Any Linux
See TeXLive.
Ubuntu
See Ubuntu reference page or TUG Debian/Ubuntu reference page.
- Complete install
Use this guide to install the complete and latest TexLive on Ubuntu (~4GB)
DO NOT FORGET to disable any filtering proxies! Because it will reject packages containing ad*
.
git clone https://github.com/scottkosty/install-tl-ubuntu.git
cd install-tl-ubuntu
sudo ./install-tl-ubuntu
# OR
sudo ./install-tl-ubuntu -q http://www.ctan.org/tex-archive # to force a repository
After installation, the script will create a fake package texlive-local
that will provide all texlive packages such that apt
will not install them afterwards if another package depends on any of them. However on Ubuntu 14.04, we must also hold the package manually:
dpkg --get-selections \* > selection
vi selection # Find 'texlive-local', and change 'install' to 'hold'
sudo dpkg --set-selections < selection
dpkg -l | grep texlive # Check that package is held (prefix must be 'hi', not 'ii')
- Partial install
Choose an official repository
- Trusty 14.04 — Default version on is TexLive 2013 (2013.20140215-1)
- Precise 12.04 — Default version on is TexLive 2009.
- Precise 12.04 — Install this texlive backports ppa provides TexLive 2012 (see [1])
sudo add-apt-repository ppa:texlive-backports/ppa
Install at least the following minimum packages and extra packages:
# texlive2html - To support TeX to HTML conversion
# texlive-xetex - To install XeTeX
sudo apt install texlive texlive2html texlive-xetex
sudo apt install texlive-plain-extra texlive-science texlive-latex-extra texlive-publishers texlive-fonts-extra cm-super latexmk
- Configuration / troubleshoot
- Update pdftex.map in the user profile (see [2]):
updmap # Update user's pdftex.map
Debian
On Debian Bullseye, I used:
sudo apt install texlive texlive-xetex texlive-extra-utils texlive-fonts-extra texlive-lang-french \
texlive-pstricks texlive-publishers texlive-science cm-super latexmk texlive-lang-english
On Debian Buster, to install the same set of package as TexLive 2015:
sudo apt install texlive texlive-xetex texlive-extra-utils texlive-fonts-extra texlive-generic-recommended \
texlive-lang-french texlive-plain-extra texlive-pstricks texlive-publishers texlive-science cm-super latexmk
On Windows
- Install Miktex 2.9 or later.
- Package minted requires Pygments, see [3].
- Install Python 2.7.x
- Install Python pip
- Add
C:\Python27\Scripts
to PATH - Start 'cmd.exe', and install pygments:
pip install pygments
- Package IEEEtrantools.sty must be installed manually, see [4]
- Download IEEEtrantools.sty into C:\Program Files\MiKTeX 2.9\tex\latex\IEEEtran\IEEEtrantools.sty
- Start "MiKTeX 2.9\Maintenance (Admin)\Settings (Admin)". Inside this program click the button "Refresh FNDB".
Invocation
Basic commands for LaTeX documents (using TeXlive under Linux or MikTeX under Windows):
pdflatex <file.tex> # Convert a .tex file directly to pdf format
latex <file.tex> # Convert a .tex file to .dvi file
dvips <file.dvi> # Convert a .dvi file to .ps
dvipdfm -p a4 <filetex> # Convert a .dvi file to .pdf (using a4 paper)
For TeX documents:
pdftex <file.tex> # Convert a .tex directly into .pdf
tex <file.tex> # Convert a .tex into .dvi
For XeLaTex documents (with BibTex entries):
xelatex <file.tex> # Generate the .aux file needed by BibTex
bibtex <file.aux> # Process bib entries
xelatex <file.tex> # 1st pass will generate .pdf w/o references
xelatex <file.tex> # 2nd pass will generate .pdf w/ references
Alternative to bibtext:
- biblatex (optionally with the back-end biber)
Packages
Miscellaneous packages
- eledmac — Typeset scholarly editions (when lots of footnotes, endnotes are used).
- alltt — define environment
alltt
, which is likeverbatim
but where\ { }
keep their usual meaning. - longtable — Like
tabular
but produces table that can be broken over several pages. - adjustbox — The package provides several macros to adjust boxed content (similar to
\includegraphics[width=...,height=...,keepaspectratio]
). See also comment in [5]).
algorithmicx, algorithmic2e (algorithms)
(See LaTeX wikibooks for a comparison of algorithm typesetting packages).
algorithmicx (manual algorithmicx.pdf, debian texlive-science) is a package to typeset algorithms either in pseudo-code or in real language (Pascal and C for now).
There are 2 pseudocode layouts. The layout algcompatible
is fully compatible with older package algorithmic, except for the following differences:
- Include package algorithmicx and algcompatible instead of algorithmic:
\usepackage{algorithmicx}
\usepackage{algcompatible}
- No
\RETURN
statement. This can be defined as
\algloopdefx{RETURN}[0]{\textbf{return} \ }
% Alternate definition:
% \newcommand{\RETURN}{\State \textbf{return} \ }
- With algorithmic, empty lines were obtained with
\\ ~ \\
. There is a dedicated command in algorithmicx:
\Statex % Insert empty un-numbered line
Otherwise it is recommended to use layout algpseudocode, which uses the same commands but with a different letter case and allows defining new commands. Below is a summary of available commands.
\begin{algorithmic}[1]
\State $sum\gets 0$
\Statex
\textbf{return} $sum$\Comment{The sum is $sum$}
\end{algorithmic}
\For{<text>}
<body>
\EndFor
\ForAll{<text>}
<body>
\EndFor
\While{<text>}
<body>
\EndWhile
\Repeat
<body>
\Until{<text>}
\If{<text>}
<body>
\ElsIf{<text>}
<body>
\Else
<body>
\EndIf
\Procedure{<name>}{<params>}
<body>
\EndProcedure
\Function{<name>}{<params>}
<body>
\EndFunction
\Loop
<body>
\EndLoop
\Require something
\Ensure something
\Statex
\State \Call{Create}{10}
Save, restore algorithms:
\algstore{<savename>}
\algstore*{<savename>}
\algrestore{<savename>}
\algrestore*{<savename>}
algorithmic2e (manual algorithm2e.pdf) is yet another package, which as of 2013, seems to be the most frequently used package bundle [6]. It has a nice option to draw vertical lines for delimiting blocks, but looks more complicated and harder to read.
- algorithmic
- Yet another package, default for IEEE (documentation).
- See algorithmic.sty to define new items. For instance:
% Define new commands similar to \ENSURE or \REQUIRE (i.e. not indented)
\newcommand{\algorithmicinterface}{\textbf{Interface:}}
\newcommand{\algorithmicinstantiation}{\textbf{Instantiation}}
\newcommand{\INTERFACE}{\item[\algorithmicinterface]}
\newcommand{\INSTANTIATION}{\item[\algorithmicinstantiation]}
% Define some handy one-liner (TODO: Might need to rework those
\newcommand{\STATEFOR}[2]{{\STATE \textbf{for} {#1} \textbf{do} {#2}}}
\newcommand{\STATEIF}[2]{{\STATE \textbf{if} {#1} \textbf{then} {#2}}}
\newcommand{\STATEIFELSE}[3]{{\STATE \textbf{if} {#1} \textbf{then} {#2} \textbf{else} {#3}}}
\newcommand{\STATERETURN}{{\textbf{return }}}
authblk
Use the authblk package to display the author affiliation using a footnote system in class article
.
For instance:
\documentclass[11pt]{article}
\usepackage{authblk}
\author{Firstname Name}
\author{Firstname Name}
\affil{Company A}
\author{Firstname Name}
\affil{Company B}
\title{...}
\date{...}
\begin{document}
\maketitle
\end{document}
In XeLaTeX, we need to patch authblk when using the xltxtra package with fonts that have superior glyphs (for instance Palatino Linotype or Minion Pro):
\usepackage{xltxtra}
\usepackage[noblocks]{authblk}
\setmainfont{Minion Pro}
% We patch authblk to keep superscript from xltxtra package
% See http://tex.stackexchange.com/questions/168095
\makeatletter
\renewcommand\AB@authnote[1]{\textsuperscript{#1}}
\renewcommand\AB@affilnote[1]{\textsuperscript{#1}}
\makeatother
Use the caption package (manual caption-eng.pdf}}) to format captions:
\usepackage[margin=10pt,textfont=it,labelfont=bf,labelsep=endash]{caption}
There are also other caption packages:
- ccaption (continued captions)
- mcaption (margin captions)
cleveref, varioref (smart references)
The cleveref (manual cleveref.pdf, debian texlive-latex-extra) package enhances LaTeX cross-referencing features, allowing the format of references to be determined automatically according to the type of reference.
From the manual:
- The cleveref package must be loaded after all other packages that don't specifically support it (see manual, §13). Also note that all
\newtheorem
definitions must be placed after the cleveref package is loaded.
% Load cleveref as last package!
\usepackage{cleveref}
\usepackage[capitalise]{cleveref} % Always capitalize labels
\usepackage[noabbrev]{cleveref} % Never use abbreviations in labels
\newtheorem{theorem}{Theorem} % These must come AFTER loading cleveref
\newtheorem{myclaim}{Claim}
- Most frequently used commands:
\cref{label} % Insert a reference, including label
\Cref{label} % ... idem, but at the beginning of a sentence
\crefrange{label1}{label2} % Insert a range of references
\Crefrange{label1}{label2} % ... idem, but at the beginning of a sentence
- Don't use cleveref with
eqnarray
. Use amsmath better alternatives. - cleveref conflicts with algorithmic package, so use algorithmicx package instead. Unfortunately this is not possible with IEEE publication since algorithmic is included by default.
float
Better controls on float + custom style. See [7].
listings, minted (source listings)
- Reference: [8]
listings is the old-fashioned way to insert code listings in LaTeX.
minted (manual minted.pdf, debian texlive-latex-extra) is a package that facilitates expressive syntax highlighting using the powerful Pygments library. It requires :
sudo apt-get install python-setuptools
sudo easy_install Pygments
All .tex files using minted must be compiled with option -shell-escape
:
xelatex -shell-escape myfile.tex
Some minimal examples (see manual for more):
\begin{minted}{python}
def boring(args = None):
pass
\end{minted}
\mint{python}|import this|
% Use ''listing'' environment when adding a caption / label
\begin{listing}[htb] % Use [H] to force listing HERE
\mint{cl}/(car (cons 1 ’(2)))/
\caption{Example of a listing.}
\label{lst:example}
\end{listing}
Listing \ref{lst:example} contains an example of a listing.
MnSymbol
Use package MnSymbol (manual MnSymbol.pdf) to get access to many more symbols (from [9]).
The package is incompatible with packages amssymb and amsfonts. A solution is to load MnSymbol after these package (see manual; see also [10] for another solution):
\documentclass[a4paper,twoside,11pt]{report}
\usepackage{amssymb}
\usepackage{amsfonts, amsmath, amsthm}
\usepackage{MnSymbol}
%...
soul
Use package soul (manual soul.pdf, debian texlive-plain-extra) to highlight, underline, hyphenate texts, or use small caps and change kerning, letter spacing. See manual for details.
LaTeX example:
\documentclass[a4paper]{article}
\usepackage{color,soul}
\begin{document}
Some normal text.\par
\hl{Some highlighted text.}\par
Some more normal text.
\end{document}
TeX example (requires color package from CTAN, see manual):
\input color
\input soul.sty
\pdfoutput=1
\pdfpagewidth=21cm
\pdfpageheight=29.7cm
Some text here\par
\hl{Some highlighted text now}\par
Some more text\par
\bye
Troubleshooting Reconstruction error:
\hl{match of next brace, bracket, comment, \tt\#define} % WRONG
\hl{match of next brace, bracket, comment, \tt \#define} % CORRECT
\hl{/$s$\enter\ ?$s$\enter} % WRONG
\hl{{/$s$\enter} {?$s$\enter}} % CORRECT
\hl{These are {\it italic words} and these not} % WRONG
\hl{These are \it italic words \rm and these not} % CORRECT
ulem
Package ulem is an alternative to soul, and is more recent according to this comment. ulem stands for underlinded emphasized, but this feature can be disabled with option normalem
.
To strike text through:
\usepackage[normalem]{ulem} % Use normalem to keep standard \emph text
\sout{Hello World}
Use package subcaption (debian texlive-latex-recommended) to easily place figures side-by-side [11],[12]. Each sub-caption can have their own caption that are typeset with a specific sub-caption style. Alternatively, one can use minipage
environment as well, but it does not align figures and captions appear like ordinary captions.
Note that packages subfig and subfigures are deprecated.
\usepackage{subcaption}
...
\begin{figure}
\centering
\begin{subfigure}[b]{0.4textwidth}
\centering
\includegraphics[width=textwidth]{1.png}
\caption{Picture 1}
\label{fig:1}
\end{subfigure}
\begin{subfigure}[b]{0.4textwidth}
\centering
\includegraphics[width=textwidth]{2.png}
\caption{Picture 2}
\label{fig:2}
\end{subfigure}
\end{figure}
|
\begin{figure}
\centering
\begin{minipage}[b]{0.4textwidth}
\centering
\includegraphics[width=textwidth]{1.png}
\caption{Picture 1}
\label{fig:1}
\end{subfigure}
\begin{minipage}[b]{0.4textwidth}
\centering
\includegraphics[width=textwidth]{2.png}
\caption{Picture 2}
\label{fig:2}
\end{subfigure}
\end{figure}
|
Font, Font Packages, and Managing Fonts
- My font selection - beamer
\defaultfontfeatures{Mapping=tex-text}
\setprimaryfont{Calibri}
\setallmonofonts[Scale=0.90]{Museo Slab}%{Calibri} %[Scale=0.8] % Also call \setmonofont
\setallsansfonts{Calibri} % Also call \setsansfont
- Some fonts
- List of TeX fonts
- Computer Modern (package ???)
- The original TeX font designed in MetaFont. Now exists in scalable version in Type 1, TrueType and OpenType (see also debian package cm-super).
- Latin Modern (package lmodern)
- The Latin Modern fonts are enhanced versions of the Computer Modern fonts. They have enhanced metrics and glyph coverage.
- Utopia (package fourier)
%\usepackage[T1]{fontenc}
%\usepackage[adobe-utopia]{mathdesign}
\usepackage{fourier}
- Palatino Linotype
- Minion Pro (available via Adobe Reader)
- Blackboard sans-serif fonts: Use package dsfont [13]
\usepackage[sans]{dsfont}
\mathds{A}
- Calibri and Andale Mono
\setmainfont{Calibri} \setmonofont[Scale=0.86]{Andale Mono}
- Fonts on LaTeX
- If LaTeX complains about fonts, maybe you need to update the pdftex.map:
updmap
- In document, it seems good to select Type 1 encoding, whatever it means. However this seems automatic in recent TexLive version:
\usepackage[T1]{fontenc}
- Fonts on XeLaTeX
- Change fonts with package fontspec and commands like
\setmainfont
and\setmonofont
. - The xunicode package provides additional mapping between LaTeX accents and the selected font.
- The xltxtra package provides some fixes relating to fonts.
- Also nice, use the microtype package:
\usepackage[final,expansion=true,protrusion=true,spacing=true,kerning=true]{microtype}
- Some references and font troubleshooting links
- See fntguide.pdf.
- Which LaTeX font packages contain real small caps and work with the “microtype” package? [14],
- Why do I suddenly get an auto expansion error? [15]
- pdfTeX error (font expansion): auto expansion is only possible with scalable [16]
- Deprecated
\sf
, \bf
, \it
are deprecated. Prefer text alternatives like \textbf
(see [17])
Reference
Syntax - Basic
- Links
\dots
Special characters | \# \$ \% \^{} \& \_ \{ \} \~{} \textbackslash
|
LaTeX Commands | \TeX{} and % space (tx to {})
\TeX{}nicians and % NO space
\TeX perts. % NO space
|
Document class | \documentclass[options]{class} % See manual for reference
|
Packages | \usepackage[options]{package} % See manual for list of packages
|
Page style | \pagestyle{style} % plain, headings, empty
\thispagestyle{style} % for current page only
|
Colors | \usepackage[usenames,dvipsnames,svgnames]{xcolor}% before tikz or tkz
\definecolor{Maroon}{rgb}{0.5,0.0,0.0}%{.80,.80,.95}
\definecolor{fondpaille}{cmyk}{0,0,0.1,0}
\pagecolor{fondpaille} % Setup default background color
\color{Maroon} % Setup default foreground color
|
Big project | \include{filename} % Insert content of file - LaTeX starts a new page
\includeonly{filename,...} % (in preamble) restrict list of included files
\input{filename} % Simply includes the file
|
Breaks | Supercalifragilist%
icexpialidocious % Use % to break lines without inserting space in output (here single word)
\\ % Start a new line without starting a new paragraph
\newline % idem
\\* % idem, but prohibits page break after forced line break
\newpage %
\linebreak[n] % Suggest LaTeX where to break (or not) page (n=0..4)
\nolinebreak[n] %
\pagebreak[n] %
\nopagebreak[n] %
\sloppy % Tell LaTeX to relax its layout standards
\fussy % Reset to default layout behaviour
|
Hyphenation | \hyphenation{FORTRAN Hy-phen-a-tion} % Instruct LaTex where (and not) insert hyphens
su\-per\-cal\-i\-frag % Instruct hyphen locally (handy for accented words)
\mbox{0116 291 2319} % Content of \mbox is kept togetter
\fbox{0116 291 2319} % Idem, with surrounding box
input/output % Slash / prevents hyphenation
input\slash output % ... so use \slash instead
|
Special characters and symbols | `x' % single quotation marks
``quote'' % double quotation marks
daughter-in-law % 'hyphen' dash
pages 13--67 % 'en-dash'
yes---or no? % 'em-dash'
$0$, $1$ and $-1$ % 'minus' sign
http://www.clever.edu/$\sim$demo % tilde for url (better than \~{})
5MB/s % slash, but hyphenation disabled
read\slash write % slash, with hyphenation allowed
$-30\,^{\circ}\mathrm{C}$ % degree symbol
30 \textcelsius{} % idem, easier (with package 'textcomp')
\texteuro, \euro, € % various ways to get euro sign (see manual for variants)
\ldots \cdots % ellipsis (low dots), centered dots
\dotsc \dotsb \dotsm \dotsi \dotso% semantics dots, for: commas, binary ops, multiply, integrals, other
\dots % SMART dots, from amsmath (same as above, but auto-guess)
not shelfful, but shelf\mbox{}ful % use \mbox{} to prevent ligatures
H\^otel na\"\ive \'el\`eve % some example of accents (see manual for more)
|
International support | \usepackage[utf8]{inputenc} % Enable utf-8 (see also XeLaTeX)
% French support
M\up{me}, D\up{r}, 1\ier{}... % See manual for more
|
Spacing | Not\ expandable space % non-expandable space
Mr.~Smith % Idem + non-breakable
I like BASIC\@. What about you? % Indicate . is end of sentence
|
Titles, Chapters, Sections | \chapter[Shorter title]{...} % For 'report' or 'book' class
\part{...} % Does not influence section / chapter numbering
\appendix{...} % Like chapters, using letters for numbering
\section{...}
\section*{...} % unnumbered section, not in TOC
\subsection{...}
\subsubsection{...}
\paragraph{...}
\subparagraph{...}
\tableofcontents
\title{...} \author{...} \date{...}
\maketitle
|
Cross References | \label{sec:this}
See section~\ref{sec:this}
See page~\pageref{sec:this}
As in equation~\eqref{eq:this}
|
Footnotes | \footnote{text} % after word or sentence (i.e. after comma or dot)
|
Emphasized Words | \underline{text}
\emph{text}
|
Subscript and superscript | \usepackage{xltxtra}
CO\textsubscript{2}
4\textsuperscript{th}
|
Environments | \begin{itemize}
\item one
\item[-] two with a dash
\end{itemize}
\begin{enumerate}
\item first
\item second
\end{itemize}
\begin{description}
\item[One] one
\item[Second] second
\end{description}
\begin{flushleft} \end{flushleft} % Can also be used as \flushleft, \flushright...
\begin{flushright} \end{flushright}
\begin{center} \end{center}
|
Miscellaneous | /verb|\verb+...+| allows verbatim text % but does NOT work in macro arguments
...
\begin{frame}[fragile]
In beamer, frame must be /verb|[fragile]|
\end{frame}
\usepackage{graphicx} % Rotation
My rotated \rotatebox{90}{text}
|
Beamer | /alert{Some text.}
% Change the font size for one frame
\begin{frame}{}
\fontsize{10pt}{12.0}\selectfont % \fontsize{<font size>}{<value for \baselineskip>}\selectfont
\end{frame}
|
Colors | \usepackage{xcolor}
\definecolor{bashstring}{RGB}{186,33,33}
\textcolor{bashstring}{my string}
{\color{bashstring}mystring} % declaration, within a TeX group
{\color{bashstring}\verb+also work with verbatim+} % declaration mandatory with \verb
|
Syntax - Tables
\begin{table}
\caption{\label{t:mylabel}Some description}
\begin{center}
\begin{tabular}{|p{6.5cm}|p{6.5cm}|}
\hline
\multicolumn{2}{|l|}{\textbf{Multicolumn line}} \\
\hline
Top left & Top right \\
Bottom left & Bottom right \\
\hline
\hline
\end{tabular}
\end{center}
\end{table}
\begin{tabular}{|r|l|}
\hline
7C0 & hexadecimal \\
3700 & octal \\ \cline{2-2}
11111000000 & binary \\
\hline \hline
1984 & decimal \\
\hline
\end{tabular}
\begin{tabular}{|p{4.7cm}|}
\hline
Welcome to Boxy’s paragraph.
We sincerely hope you’ll
all enjoy the show.\\
\hline
\end{tabular}
\begin{tabular}{@{} l @{}}
\hline
no leading space\\
\hline
\end{tabular}
\begin{tabular}{l}
\hline
leading space left and right\\
\hline
\end{tabular}
\begin{tabular}{c r @{.} l}
Pi expression
&
\multicolumn{2}{c}{Value} \\
\hline
$\pi$
& 3&1416 \\
$\pi^{\pi}$
& 36&46
\\
$(\pi^{\pi})^{\pi}$ & 80662&7 \\
\end{tabular}
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{Ene} \\
\hline
Mene & Muh! \\
\hline
\end{tabular}
{\renewcommand{\arraystretch}{1.5}
\renewcommand{\tabcolsep}{0.2cm}
\begin{tabular}{|l|}
\hline
less cramped\\\hline
table layout\\\hline
\end{tabular}}
\begin{tabular}{|c|}
\hline
% \rule{1pt}{4ex}Pitprop \ldots\\
\rule{0pt}{4ex}Pitprop \ldots\\
\hline
\rule{0pt}{4ex}Strut\\
\hline
\end{tabular}
Syntax - Mathematics
- Fractions
\frac{1}{\sqrt{2}+\frac{1}{\sqrt{2}+\frac{1}{\sqrt{2}+\dotsb}}} % Standard fraction
|
|
\cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+\dotsb
}}} % Continued fraction
|
\cfrac{1}{\sqrt{2}+ \cfrac{1}{\sqrt{2}+\dotsb }}} % Continued fraction</math> |
\tfrac{1}{2} % Tiny fraction, like in textstyle
|
|
- Multiline and multiple equations
% Multiline -- Easiest is to use multiline, best is to use IEEEeqnarray
\begin{multline}
a + b + c + d + e + f + g + h + i
\\
= j + k + l + m + n
\end{multline}
|
a + b + c + d + e + f + g + h + i \\ = j + k + l + m + n \end{multline}</math> |
% Multiple equations - Easiest is to use \begin{align} if NO line too long
\begin{align}
a & = b + c \\
& = d + e
\end{align}
|
a & = b + c \\ & = d + e \end{align}</math> |
% Multiple equations - ... but best is to use IEEEeqnarray (AVOID \begin{eqnarray} !!!)
% See also commands (\begin{IEEEeqnarray*}, \IEEEyesnumber, \IEEEyessubnumber)
% ... also to group several blocks of equations beside each other
% (source: The not so short introduction to LaTeX)
\usepackage[retainorgcmds]{IEEEtrantools}
\begin{IEEEeqnarray}{rCl}
a & = & b + c
\\
& = & d + e + f + g + h + i + j + k \nonumber\\
&& +\: l + m + n + o
\\
& = & p + q + r + s
\end{IEEEeqnarray}
|
|
\begin{IEEEeqnarray}{rCl}
\IEEEeqnarraymulticol{3}{l}{
a + b + c + d + e + f + g + h
}\nonumber\\ \quad
& = & i + j
\\
& = & k + l + m
\end{IEEEeqnarray}
|
- Operators
References: Big-O [18], negative-space fix [19], operator [20]
\usepackage{amsmath}
\operatorname{sgn} x
\DeclareMathOperator{\sgn}{sgn} % DO NOT define new op with \newcommand, but this
\DeclareMathOperator*{\esssup}{ess\,sup} % Starred, with subscript like \sum
|
\quad \DeclareMathOperator{\sgn}{sgn} \sgn x \quad \DeclareMathOperator*{\esssup}{ess\,sup} \esssup_{x\in [0,1]}f(x)</math> |
\newcommand{\BigO}[1]{\ensuremath{\operatorname{O}\bigl(#1\bigr)}} % Simple big-O
\newcommand{\BigO}[1]{\ensuremath{\operatorname{O}\!\left(#1\right)}} % scaling ()
\newcommand{\BigO}[1]{\ensuremath{\operatorname{\mathcal{O}}\!\left(#1\right)}} % alternate
|
\quad \operatorname{O}\!\left(n^2\right) \quad \operatorname{\mathcal{O}}\!\left(n^2\right) </math> |
- Cases
|x| =
\begin{cases}
0 & \text{if $x \lt 0$,} \\ % Note the use of \text and $...$
x & \text{if $x > 0$.}
\end{cases}
|
\begin{cases} 0 & \text{if $x \lt 0$,} \\ % Note the use of \text and $...$ x & \text{if $x > 0$.} \end{cases}</math> |
- Matrices
\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} % instead of using array
|
|
$\left( \begin{smallmatrix}1 & 0 \\ 0 & -1\end{smallmatrix} \right)$ % small matrix for inline
|
|
- Sums
\sum^n_{\substack{0<i<n \\ % Use \substack for multiline indices
j\subseteq i}}
P(i,j) = Q(i,j)
|
j\subseteq i}} P(i,j) = Q(i,j)</math> |
Advanced Scripting
These are features typically only used in package.
Enable @ as a standard letter (see [21])
|
\makeatletter
% ...
\makeatother
|
Test if a given class is loaded |
Requires \@ifclassloaded{<someclass>}
{<true code>}
{<false coode>}%
|
Dimensions & Page Layout
- References
- See Page layout on WikiBooks.
Frequently-used dimensions:
\textheight
||Height of the page body
\textwidth
||Width of the page body
\linewidth
||width in current environment
- Useful packages
- geometry — lets you customize the page size even with classes that do not support the options.
- layout — To print from a LaTeX document itself the current page layout and dimensions.
- showframe — To render a frame marking the margins of a document you are currently working on.
Symbols
Some frequently used symbols
$$\bot$$ | \bot |
perpendicular (orthogonal) sign |
$$\parallel$$ | \parallel |
parallel sign |
XeLaTeX
LaTeX | XeLaTeX |
---|---|
\usepackage{inputenc}
\usepackage{fontenc}
\usepackage{textcomp}
\usepackage[languageA]{babel}
|
Save file as utf-8 \usepackage{polyglossia}
\setdefaultlanguage[babelshorthands]{languageA}
\usepackage[Ligatures=TeX]{fontspec} % To enable --, ---, '', ``, !`, ?`, ,,, <<, >>
|
Templates
Smallest
%UTF-8 encoding “Нelłó worlð!”
\documentclass{article}
\begin{document}
Small is beautiful.
\end{document}
\documentclass[options]{class}
takes optional paramters options, and a mandatory document class. See manual for reference.
3-columns
Example of 3-column document, minimum margin, no page numbering (see [22])
%UTF-8 encoding “Нelłó worlð!”
\documentclass[a4paper]{article}
% Specify paper size univocally (for pdf output)
\special{papersize=210mm,297mm}
% Set minimum margin using package geometry
\usepackage[a4paper,landscape,top=1cm, bottom=1cm, left=0.5cm, right=1cm]{geometry}
% To support 3-column document, color and highlighting
\usepackage{multicol,color,soul}
% Remove any footer / header (page numbers...)
\pagestyle{empty}
\begin{document}
\begin{multicols}{3}
Some text here\par
Some more text there\par
And not anymore\par
\end{multicols}
\end{document}
Realistic Journal Article
%UTF-8 encoding “Нelłó worlð!”
\documentclass[a4paper,11pt]{article}
% define the title
\author{H.~Partl}
\title{Minimalism}
\begin{document}
% generates the title
\maketitle
% insert the table of contents
\tableofcontents
\section{Some Interesting Words}
Well, and here begins my lovely article.
\section{Good Bye World}
\ldots{} and here it ends.
\end{document}
Beamer and XeTeX
To change the default font in the document with XeTeX, use the fontspec package. The xunicode package provides additional mapping between LaTeX accents and the selected font. A third package, xltxtra provides some fixes relating to fonts. [23]
\documentclass[xetex,mathserif,serif]{beamer}
\usepackage{fontspec}
\usepackage{xunicode} %Unicode extras!
\usepackage{xltxtra} %Fixes
\setmainfont{Calibri}
\setmonofont[Scale=0.86]{Andale Mono}
Also nice, use the microtype package:
\usepackage[final,expansion=true,protrusion=true,spacing=true,kerning=true]{microtype}
Layout and Typesetting
Moved to LaTeX writing tips
Conventions and Examples
Moved to LaTeX writing tips
Tips / How-to
Quick debug
- Check syntax rapidly by using package syntonly:
\usepackage{syntonly}
\syntaxonly % Comment out this line to produce pages
- Add
draft
to document class to identify layout issues easily:
\documentclass[draft]{article}
Remove sub-sections from header in beamer presentation
Simplest is to use another outer theme (here infolines
):
\documentclass{beamer}
\mode<presentation>
{
\usetheme{Antibes}
% \usetheme{Hannover}
\setbeamercovered{transparent}
% \usefonttheme{structuresmallcapsserif}
% \usefonttheme{structurebold}
\usecolortheme{beaver}
% tree is default outertheme - but infolines is more compact
% \useoutertheme{tree}
\useoutertheme{infolines}
}
% slidenumbering
\setbeamertemplate{footline}[frame number]
\setbeamertemplate{sidebar right}{}
Change vertical alignment
Simply use the [t]
or [c]
modifier (top / center). For frames:
\begin{frame}[t]{The seven permutation army}
% Top-aligned frame
\end{frame}
For columns:
\begin{columns}[t]
\begin{column}{0.35\linewidth}
% 1st top-aligned column
\end{column}
\begin{column}{0.65\linewidth}
% 2nd top-aligned column
\end{column}
\end{columns}
How to format BibTex entries and cite sources
- References
- Bibtex package, see example file xampl.bib (entries
@INBOOK
,@BOOK
...). - Available entry types, and mandatory fields (see WP:BibTeX)
- CryptoBib — CryptoBib is a BibTeX database containing papers related to Cryptography, with manually checked entries and uniform BibTeX data.
- Examples
Example of bibtex file (extension .bib).
%UTF-8 (ûτf—8)
@PREAMBLE{ "\newcommand{\noopsort}[1]{} "
# "\newcommand{\printfirst}[2]{#1} "
# "\newcommand{\singleletter}[1]{#1} "
# "\newcommand{\switchargs}[2]{#2#1} " }
@STRING{EUROCRYPT = "Advances in Cryptology --- EUROCRYPT"}
@INPROCEEDINGS{BeRo96pss,
author = {Mihir Bellare and Phillip Rogaway},
title = {The Exact Security of Digital Signatures --- How to Sign with {RSA} and {R}abin},
editor = {U. Maurer},
booktitle = EUROCRYPT # {'96},
volume = 1070,
series = LNCS,
pages = {399--416},
year = 1996,
publisher = SPRINGER,
}
% Edited year to make sure this entry comes after pkcs1
@MISC{RSA93pkcs3,
author = {{RSA Laboratories}},
title = {Public-Key Cryptography Standards ({PKCS}) \#3: {D}iffie-{H}ellman Key-Agreement Standard Version 1.4},
month = nov,
year = "{\noopsort{9999}}1993",
}
@MISC{wikipedia:combinadic,
author = {Wikipedia},
title = {Combinatorial number system --- Wikipedia{,} The Free Encyclopedia},
year = {2013},
howpublished = {\url{https://en.wikipedia.org/wiki/Combinadic}},
note = {[Online; accessed 18-June-2014]}
}
Example of citation:
\bibliographystyle{amsplain}
\providecommand{\shortcite}[1]{\cite{#1}} % For compatibility with other packages
This as been shown by Bellare and Rogaway~cite{BeRo96pss}.
This results is a well-known fact~cite{wikipedia:combinadic}.
\hbadness 10000 % To avoid warning in bibtex entries with urls
\bibliography{ext,ours}
- Recommendations
- Common Errors in Bibliographies — John Owens
- Authors
- Make the names in the bibliography match what is printed on the paper. For hyphenated names with the second half uncapitalized (Wu-chun Feng, Wen-mei Hwu), put the hyphen and second half in brackets:
Wu-{chun} Feng, Wen{-mei} Hwu
. - Capitalization in titles
- Follow capitalization as printed on the paper. The bib style should enforce capitalization, not your bibliography. Properly bracket
{}
words in titles that must be capitalized. - Months
- Include the month of publication in your bibliographies.
- Pages
- Always include pages if pages are available.
- Search article in CiteSeerX, and if found, copy bibtex entry.
- For wikipedia article xxx, use the special wikipedia page
Special:Cite/xxx
that generates automatically a bibtex entry(eg. Special:Cite/Continued_fraction) - The simplest solution for URLs is to use the
howpublished
field [24] [25].
howpublished = {\url{http://en.wikipedia.org/wiki/RSA\_(cryptosystem)}},
- Other alternative are to use more modern styles with support of url and
url
field, or use biblatex.
- Use curly brackets
{}
when necessary: keep word together in author fieldauthor = Template:RSA Laboratories
,protect uppercase words{UPPERCASE}
, capitalise all significant words, to allow for bibliography styles that want this [26]
author = {{RSA Laboratories}}
title = {Pascal, {C}, {Java}: {Were} they all Conceived in {ETH}?}
When citing sources:
- Don't use bracketed numbers as word:
Foo showed that bar~\cite{Foo:2000:BAR}
Foo showed that bar~\shortcite{Foo:2000:BAR} % +++ BETTER - Avoid name repeat
In \cite{Foo:2000:BAR}, Foo shows that bar. % !!! BAD
- This requires to add in your document, in case the bibtex style does not support it
\providecommand{\shortcite}[1]{\cite{#1}}
- Use
~
to prevent break before citation and group several citations together using a comma:
text text text~\cite{Foo:2000:BAR}
\cite{AuthorOne:2000:ABC,AuthorTwo:2002:DEF}
\cite{AuthorOne:2000:ABC}\cite{AuthorTwo:2002:DEF} % !!! BAD !!!
- Convert .ris to .bib — Install package cb2bib and bibutils, then
/usr/share/cb2bib/c2btools/ris2bib 1996-EUROCRYPT-016.ris output.bib
- Use
{\noopsort{XXX}}
to override default sort odering, e.g. inauthor
oryear
field (see xampl.bib). For instance, here we don't change author name but use the fact that year is used as 2nd sort key to make sure second entry comes after the first entry:
@preamble{ "\newcommand{\noopsort}[1]{} " }
@MISC{RSA12pkcs1,
author = {{RSA Laboratories}},
title = {Public-Key Cryptography Standards ({PKCS}) \#1: {RSA} Cryptography Specifications Version 2.2},
year = {2012},
}
@MISC{RSA93pkcs3,
author = {{RSA Laboratories}},
title = {Public-Key Cryptography Standards ({PKCS}) \#3: {D}iffie-{H}ellman Key-Agreement Standard Version 1.4},
year = "{\noopsort{9999}}1993",
}
An alternative solution is to use \setbox0=\hbox{XXX}
:
@MISC{RSA93pkcs3,
author = {{RSA Laboratories}},
title = {Public-Key Cryptography Standards ({PKCS}) \#3: {D}iffie-{H}ellman Key-Agreement Standard Version 1.4},
year = {\setbox0=\hbox{9999}1993},
}
- Software
- Referencer — a GNOME application to organise documents or references, and ultimately generate a BibTeX bibliography file.
Source code listing
See package minted or listings above.
Fix horizontal alignment
- Use
\rlap
and\phantom
. Note that\rlap
does not work in math mode, so we apply a workaround (better solution here)
$\crtCp \gets \rsacipher \bmod \rsap$
{\rlap{$\crtCq$}}$\phantom{\crtCp} \gets \rsacipher \bmod \rsaq$
- Use
\array
, and play with[pos]
option for vertical alignment in the paragraph, and@{}
to suppress inter-column space:
$\begin{array}[t]{@{}r@{}l}
\crtCp &\ \gets \rsacipher \bmod \rsap \\
\crtCq &\ \gets \rsacipher \bmod \rsaq
\end{array}$
- Fix unwanted space when using
\left ... \right
. Insert negative space\!
(see [27] for better solution)
\newcommand{\BigO}[1]{\ensuremath{\operatorname{O}\!\left(#1\right)}}
Find LaTeX symbols
See the Links section.
For instance, Detexify2 or shapecatcher.com recognize symbols drawn with the mouse. There are also extensive symbol lists.
Force big floats after current page
Say you have a document with lots of big figures or listings that you put in floats. LaTeX usual behavior with such big floats appears quite frustrating, and usually pushes these floats up to the end of current chapter / section.
The solution apparently is to always give all placement specifier [htbp]
, which let LaTeX chooses the best option. If this does not work, one can force LaTeX with [p!]
:
\begin{listing}[htbp]
%\begin{listing}[p!] % To force float to next page
\begin{minted}{python}
...
\end{minted}
\end{listing}
Another solution would be to use package afterpage [28], but I sometimes get error about lost floats (see this question):
... Float(s) lost ... This may be a LaTeX bug.
% In preamble:
\usepackage{afterpage}
% Before the float, ask to call \clearpage after current page:
\afterpage{\clearpage}
\begin{listing}[htbp] % We let LaTeX choose best placement (not necessarily next page)
\begin{minted}{python}
...
\end{minted}
\end{listing}
Add vertical space between tables
Use \par\vspace{2em}
(see also [29], but /newline
does not work). This combination is the most stable and doesn't require empty lines:
\begin{tabular}{c|l}
%...
\end{tabular}
\par\vspace{2em}
\begin{tabular}{c|l}
%...
\end{tabular}
Syntax / style checker for LaTeX
Use package chktex or lacheck.
Define minipage width
\begin{minipage}{\linewidth} % Use current line width as minipage width
% ...
\captionof{table}[short]{Long}
\end{minipage}
Several options [30]:
- Use
\textwidth
, which stays constant. - Use
\linewidth
, which adapts to surrounding environment (likeenumerate
oritemize
Fix Overfull \hbox
- Use
sloppy
or better,\begin{sloppypar}...\end{sloppypar}
to tell LaTeX to temporarily relax metrics regarding maximum interword / intercharacter spacing... - Use
\noindent
and comments%
to prevent LaTex from inserting space that would create overflow. For insance:
\begin{minipage}{.40\linewidth}
Hello,
\end{minipage}
\hfill
\begin{minipage}{.60\linewidth}
World!
\end{minipage}
|
This doesn't. |
\noindent\begin{minipage}{.40\linewidth}
Hello,
\end{minipage}% don't let LaTeX insert space here
\hfill
\begin{minipage}{.60\linewidth}
World!
\end{minipage}
|
Mute Overfull \vbox warning (beamer)
We can use negative vpspace
to silence the Overfull vbox
warning:
\begin{frame}{Title}
\begin{columns}%[b]%[t]
\begin{column}{0.5\textwidth}
\begin{itemize}
\item Some text
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\center \includegraphics[height=0.8\textheight]{img.pdf}
\footnotesize A picture
\vspace*{-20pt} % Mute the overfull vbox warning
\end{column}
\end{columns}
\end{frame}
By adding the vspace
after the last line, it will not change the layout.
Place figure side-by-side
See package subcaption.
Drawing on top of an image
Using tikz (see [31]). Use a scope
such that (0,0)
is bottom left of the picture, and (1,1)
is top right.
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0)
{\includegraphics[width=0.9\textwidth]{matrix-ranking.png}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
% This draw a grid with label
\draw[help lines,densely dotted,xstep=.02,ystep=.02] (0,0) grid (1,1);
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
% Use the grid above to draw at desired place
\draw[green,line width=3pt] (0.4,0.5) rectangle ++(0.2,0.1);
\end{scope}
\end{tikzpicture}
Another option is to use package overpic.
\usepackage[percent]{overpic}
\begin{overpic}[scale=.25]{golfer.ps}
\put(5,45){\huge \LaTeX}
\put(55,10){\includegraphics[scale=.07] {golfer.ps}}
\end{overpic}
Preventing page breaks between lines / Handling widows and orphans
See http://www.tex.ac.uk/cgi-bin/texfaq2html?label=nopagebrk.
- Use environment
samepage
- Enclose all relevant stuff in a
\parbox
orminipage
. - ... (use
\raggedbottom
...)
To handle orphans (single line at bottom of the page) / widows (top of the page) [32]:
\widowpenalty10000
\clubpenalty10000
Other tricks:
- Use
sloppypar
(see [33]).
Find files in texlive distribution
kpsewhich latex.ltx
Get documentation on package
texdoc source2e
Add line breaks in table cell
- Define the command [34]
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
Use it as follows:
Foo bar & \specialcell{Foo\\bar} & Foo bar \\ % vertically centered
Foo bar & \specialcell[t]{Foo\\bar} & Foo bar \\ % aligned with top rule
Foo bar & \specialcell[b]{Foo\\bar} & Foo bar \\ % aligned with bottom rule
- Alternatively, use
\shortstack
[35]
\documentclass{article}
\begin{document}
\begin{tabular}{ccc}
one & two & three \\
one & two & \shortstack{a \\ bb \\ c}\\
\end{tabular}
\end{document}
- Use
\newline
[36]
\begin{tabular}{|p{3cm}|p{3cm}|}
first line
\newline second line & still on first line \\
\end{tabular}
- Use
\parbox
, but this does not look convenient
\begin{tabular}{ll}
one line& \parbox[t]{5cm}{another\\column}\\
second line here& and here
\end{tabular}
- Other solutions: use
\makecell
[37]
Avoid TeX commands
- Don't use
$$
in LaTeX, it is a plain TeX command.
Circled numbers and letters
Use the following command [38]:
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=1pt] (char) {#1};}}
For instance:
The answer is $\circled{12}$.
Adapt blank separation as necessary (sep=1pt
).
Highlight differences between two versions
Use CTAN package latexdiff (also in Debian/Ubuntu repositories):
latexdiff paper-old.tex paper-new.tex > paper.tex
See manpages for more options.
When LaTeX files are in a git repository, the most advanced solution is to use git-latexdiff SE... But doesn't work great with XeLaTeX or advanced TEX setup.
This is a simple script:
#! /bin/bash
latexdiffthis()
{
git checkout HEAD -- $1
git show HEAD^:$1 > $1.HEAD~1
latexdiff $1.HEAD~1 $1 | sponge $1
rm $1.HEAD~1
}
latexdiffthis ./Xoodyak-submission.tex
latexdiffthis ../Xoodyak-macros.tex
latexdiffthis ../XoodyakUsage.tex
Layout a tabular
Available stuff:
- Use
\\[1.5ex]
at the end of a line to increase vertical space
Disgust & & &.34 (.01) & & .23 (.07) & .25 (.05) & .19 (.13) \\[1.5ex]
$R^2$ & .12 & .11 & .11 & .20 & .17 & .17 & .22 \\
- Add separating line of various size
\toprule
\bottomrule
\midrule
\midrule[\heavyrulewidth]
- Use
tabular*
to get a table that occupies the full\textwidth
- Use
\setlength{\tabcolsep}{4.45pt}
to change the default column separation
- An example
\documentclass{beamer}
\usepackage{booktabs}
\setlength{\tabcolsep}{4.45pt}
\begin{document}
\scriptsize
\begin{frame}{Correlations between Harm, Unfairness and Disgust}
\begin{tabular*}{\textwidth}{@{}l@{\extracolsep{\fill}}*{7}{l}@{}}
\multicolumn{8}{@{}p{\textwidth}}{\textbf{Table 3.} All possible regressions
of harm, unfairness, and disgust predicting punishment} \\
\midrule[\heavyrulewidth]
& M1 & M2 & M3 & M4 & M5 & M6 & M7 \\
\midrule
Harm & .35 (.01) & & & .20 (.15) & & .24 (.07) & .14 (.31) \\
Unfairness & & .41 (.01) & & .31 (.02) & .34 (.01) & & .28 (.04) \\
Disgust & & &.34 (.01) & & .23 (.07) & .25 (.05) & .19 (.13) \\[1.5ex]
$R^2$ & .12 & .11 & .11 & .20 & .17 & .17 & .22 \\
\midrule[\heavyrulewidth]
\multicolumn{8}{@{}l}{Note: Standardized beta coefficients,
with p values in parentheses} \\
\end{tabular*}
\end{frame}
\end{document}
Beamer
- http://tug.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf (or debian package texlive-latex-recommended-doc)
Minimal example
Minimal example using theme metropolis
[39].
\documentclass{beamer}
\usetheme{metropolis} % Use metropolis theme
\title{A minimal example}
\date{\today}
\author{Matthias Vogelgesang}
\institute{Centre for Modern Beamer Themes}
\begin{document}
\maketitle
\section{First Section}
\begin{frame}{First Frame}
Hello, world!
\end{frame}
\end{document}
Tips
List all available Beamer themes
locate -br "beamertheme.*sty"
# /usr/share/texlive/texmf-dist/tex/latex/beamer/beamerthemeAnnArbor.sty
# /usr/share/texlive/texmf-dist/tex/latex/beamer/beamerthemeAntibes.sty
# /usr/share/texlive/texmf-dist/tex/latex/beamer/beamerthemeBergen.sty
How to show background image in just one frame?
Set the background image with \usebackgroundtemplate
. Restrict it to a single frame by enclosing it withing braces.
{
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{back.png}}
\begin{frame}{Title}
Content
\end{frame}
}
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{image.png}}
Silent overfull vbox
Seeing a warning like:
;Overfull \vbox (9.41396pt too high) has occurred while ...
An easy way to acknowledge and silent the deviation is to add [40]:
\vspace*{-9.41396pt} % Silent overfull vbox
Shrink content to fit on a slide
There are several methods [41], [42]:
- Use
[shrink]
to fit automatically, or with some number[shrink=20]
for manual shrinking:
\begin{frame}[shrink=20]{Title}
\lipsum[2]\lipsum[3]
\end{frame}
- Problem is that usually the vertical / horizontal centering is lost, and shrinking must be manually adapted for best result.
- Use
minipage
withc
to force centering:
\begin{frame}[shrink=35]{Title}
\begin{minipage}[c][1.3\paperheight][c]{\textwidth}
\centering
\lipsum[2]\lipsum[3]
\end{minipage}
\end{frame}
- Use
\resizebox
fromgraphicx
package:
\usepackage{graphicx} % loaded by beamer, but included here for explicitness
\begin{frame}{Title}
\begin{center}
\resizebox{\textwidth}{!}{%
\lipsum[2]\lipsum[3]%
}
\end{center}
\end{frame}
- Use
\scalebox
fromgraphicx
package:
\usepackage{graphicx}
\begin{frame}{Title}
\centering\scalebox{0.7}{
\lipsum[2]\lipsum[3]
\end{frame}
- If resize a tabular, there are several parameters that can be played with.
Hide page number of some frame
We can create a group with \begingroup ... \endgroup
and change the footline
[43]:
\documentclass{beamer}
\setbeamertemplate{footline}[frame number]
\begin{document}
\begin{frame}
normal frame
\end{frame}
\begingroup
\setbeamertemplate{footline}{}
\begin{frame}
without footline
\end{frame}
\endgroup
\begin{frame}
normal frame
\end{frame}
\end{document}
Use \pause
to preserve list valign
Using \pause
will tell Beamer to preserve the vectical alignment of list items during animation.
Hide fragile content on a slide
Use \begin{onlyenv}<1>
to hide fragile content in a frame (eg minted, verbatim...): [44]
\documentclass{beamer}
\usepackage{minted}
\begin{document}
\begin{frame}[fragile]
\begin{onlyenv}<2>
\begin{minted}{agda}
test
\end{minted}
\end{onlyenv}
\end{frame}
\end{document}
Troubleshoot
- LaTeX Error
- Cannot determine size of graphic (no BoundingBox)
- LaTeX does not find the BoundingBox information which is necessary to produce the .dvi file. A way to fix this is either to edit the graphic to add the bounding box information, or to use pdflatex to produce directly a .pdf file.
- Missing table of content (file *.toc not found)
- This happens when the command \tableofcontents is used in the document, but LaTeX did not produce yet a table of content file. The .toc file is produced at the first invocation. To solve this, just run LaTex a second time:
pdflatex mypresentation.tex # produce a pdf without toc, and a toc file
pdflatex mypresentation.tex # produce a pdf with toc generated in the previous pass
- "seac" character deprecated in Type 2 charstring
- We get the following error from XeTeX.
** WARNING ** "seac" character deprecated in Type 2 charstring. ** ERROR ** Type2 Charstring Parser: Parsing charstring failed: (status=-1, stack=5) Output file removed.
- This happens when using OpenType fonts (OTF) with accented characters (even i counts as accented!).
- The possible fixes are either to use another font, convert the font to TTF, or fix the buggy OTF.
- Command \sups already defined.
- Occurs when compiling with
xelatex
. See file /usr/share/texmf/tex/latex/tipa/tipa.sty, line 478. - This is apparently a conflict between tipa and fontspec in TeXLive2012 (TeXLive2009 seems ok, see [45])
- "Underfull \hbox (badness 10000) in paragraph at lines X--Y" in bibliography with url
- Add code below to preamble. This LaTeX to allow huge badness when using sloppy command (from [46])
\usepackage{etoolbox}
\apptocmd{\sloppy}{\hbadness 10000\relax}{}{} % To avoid warning in bibtex entries with urls
- Alternatively, simply increase
hbadness
before bibliography section:
\hbadness 10000 % To avoid warning in bibtex entries with urls
\bibliography{ext}
- "Missing elsarticle.cls"
- Install package texlive-publishers to get elsarticle.cls (since TeXLive 2012 — was part of texlive-latex-extra in TeXLive 2009).
- "auto expansion is only possible with scalable fonts" (when using microtype and fourier (aka utopia) package)
- We get the following message when compiling with
pdflatex
:
[1{/home/beq06659/.texmf-var/fonts/map/pdftex/updmap/pdftex.map} ! pdfTeX error (font expansion): auto expansion is only possible with scalable fonts. \AtBegShi@Output ...ipout \box \AtBeginShipoutBox \fi \fi l.105
- The error is because pdftex.map is located in user's profile and is not up-to-date [47]. Update pdftex.map with:
updmap # Update pdftex.map
- hyperref — Failed to convert input string to UTF16
We get this warning when using package hyperref, with option unicode
:
** WARNING ** Failed to convert input string to UTF16...
The solution is to add option pdfencoding=auto
[48]:
\usepackage[unicode=true,pdfencoding=auto]{hyperref}
- Package hyperref — Warning
- Token not allowed in a PDF string (Unicode): removing `\\'
- We get this with
\author[X, Y]{X \\ Y}
. The solution is to use\texorpdfstring{ \\ }{}
[49].
- Float(s) lost... This may be a LaTeX bug.
We can get this message when using package minted and afterpage. It seems to happen when we insert a float right after the first paragraph on a page. The bug seems related to both minted and afterpage because removing any of these package fixes the bug (note that the bug occurs even if the float does not use minted).
\afterpage{\clearpage}
\begin{figure}[htpb]
abracadabra
\end{figure}
There is no fix I know of. The only workaround is to move the figure up or down in the text so that it is no longer inserted after the first paragraph on a page.
Note that a better option seems to remove afterpage
, and set the placement specifier correctly instead.
- Extra '\fi' with
IEEEeqnarray
- with package cleveref / IEEEtrantools
- Bug is due to cleveref still using deprecated function of IEEEtrantools (
\if@IEEEissubequation
and\if@IEEElastlinewassubequation
) - A temp fix
\makeatletter
\newif\if@IEEEissubequation
\@IEEEissubequationfalse
\makeatother
\usepackage[capitalize,noabbrev]{cleveref}
- Never use
_
in a filename (e.g.\includegraphics
)
- LaTeX will take
_
as subscript character, and will produce strange errors.
- Package babel Error - Unknown option `francais'. Either you misspelled it or the language definition file french.ldf was not found
\usepackage[francais]{babel}
- Install package texlive-lang-french.
- Overfull \vbox (9.41396pt too high) has occurred while ...
- This occurs when the content exceed the available vertical space. An easy way to acknowledge and silent the deviation is to add [50]
\vspace*{-9.41396pt} % Silent overfull vbox
- beamer.tex|| LaTeX Font Warning Font shape 'TU/ppl/m/n' undefined using 'TU/lmr/m/n' instead on input line ...
- Error was due to using
\mathrm{AES}
in a formula. - The solution was simply to use
\text{AES}
(might require package amsmath)
Graphics in LaTeX
Insert graphics in LaTeX
Use the command includegraphics
: from package graphicx. Ideally, graphics dimensions are given relative to current \linewidth
and \textheight
. Usually graphics are inserted in a figure
environment.
\begin{figure}[htpb]
% Insert a graphics with given max width and height, but keeping aspect ratio
\includegraphics[width=\linewidth,height=\textheight,keepaspectratio]{picture}
\end{figure}
Optimize
- Export graphics as PDF and PNG, and put both in the same folder.
- Import graphics with
includegraphics
, but omit extension. - In image format preference, choose PNG for fast rendering, or PDF for quality rendering.
PGF/TikZ
PGF/TikZ is a graphical interpreter that produces high-quality graphics. See page PGF/TikZ.
Asymptote
Asymptote is a powerful descriptive vector graphics language that provides a natural coordinate-based framework for technical drawing.
Visio 2010 and later
Starting from Visio 2010, we can save any drawing directly in PDF. However they must be on separate page, and margin must be set to 0 [51]:
- On the File tab, click Options, and then in the navigation pane, click Customize Ribbon.
- In the Main Tabs pane, click to select the Developer check box, and then click OK.
- On the Developer tab, click Show ShapeSheet, and then click Page.
- In the Print Properties section of the ShapeSheet, set the following values to 0:
- PageLeftMargin
- PageRightMargin
- PageTopMargin
- PageBottomMargin
- On the Design tab, click Size and then Fit to drawing.
- On the File tab, select Save As, and select .pdf as file type.
Visio 2007
- Go to menu File → Page Setup
- Go to Page Size panel
- Select Size to fit drawing contents
- Go to menu File → Publish as PDF or XPS
Visio (alternatives)
Method 1: Using OpenOffice Draw
This procedure creates from a Visio drawing, a PDF file that has the correct page dimension in order to be directly imported in a LaTeX document. This procedure requires to have OpenOffice Draw installed.
- In Visio, File → Save As, select type Enhanced Metafile (.emf), enter a file name, click Save.
- (Using intermediate .emf is less convenient but gives better results than Paste Special as GDI object, which sometimes modify the pasted object)
- In OpenOffice Draw, Open the newly saved file, Select the drawing with the mouse, and then go to menu File → Export.
- Check the box Selection, select format EPS - Encapsulated PostScript (.eps), save the file.
- Press OK, to accept all default options (no preview, Level 2, Grayscale, no compression)
- In a shell, type the LaTeX command
epstopdf <filename.eps>
which will create a file <filename.pdf> with the correct page size.
- Limitations
- Some line formats are not correctly rendered by OpenOffice Draw when exporting to EPS format.
Method 2: Using Custom PostScript Page Size
This procedure can be used to solve problem in the 1st method where some line formats are not correctly rendered in the EPS. This procedure requires to have a PDF printer installed, such as PrimoPDF.
- In Visio, select the drawing to print, and copy-paste it into a new document.
- Go to menu File → Page Setup
- Go to Page Size panel
- Select Size to fit drawing contents, and note the page size as computed by Visio
- Go to Print Setup panel
- Click on Printer Paper Setup
- Click on Printer...
- Select the PDF printer, and click on Properties...
- Click on Advanced...
- For Paper size, select PostScript Custom Page Size, then click on Edit Custom Page Size
- Select unit Millimeter, and then in Width and Height, enter the same size as computed by Visio, plus 1 or 2mm.
- Click Ok buttons until back in the Print Setup dialog. Set Left, Right, Top and Bottom margin to be 0mm, and select Center horizontally and Center vertically.
- If necessary, move the drawing so that it fits perfectly in the middle of the page.
- Print the document.
The result is a PDF document with the best output quality and the correct dimension.
- Limitations
- Sometimes text police are rasterized.
Method 3: Using Postscript printer and Perl script
This method is explained here.
- Install the Adobe Generic Postscript Driver.
- Configure the printer to use EPS, i.e. right click on the printer → Printer Preferences... → click Advanced button → open Document Options → PostScript Options → Under PostScript Output Option, select "Encapsulated PostScript (EPS)".
- In Visio, print your drawing to the postscript printer.
- The bounding box is incorrectly set to the page size. To fix it, use the perl script TightBoundingBox.pl, also copied below (requires gs command from cygwin).
# usage: perl TightBoundingBox.pl <file.eps>
# calculates a tight bounding box (using the 'gs' command) and sets that bounding box into <file.eps>. This is useful where file.eps was created from Visio by printing to the Adobe Generic Postscript Printer into <file.eps>
$inputFileName=$ARGV[0];
# first, find bbox dimensions
$bbox="";
#-sOutputFile=temp_file.bbox
open(GS,"gs -dNOPAUSE -dBATCH -sDEVICE=bbox -sOutputFile=- $inputFileName 2>&1 |");
while (<GS>) {
chop;
if (/^\%\%BoundingBox: (.*)/) {
$bbox=$1;
}
}
close(GS);
#print $bbox;
# now substitute this into file
$tempFileName="temp_file.eps";
system "cat $inputFileName | tr -d \"\r\" > $tempFileName";
open(IN,"$tempFileName");
#open(OUT,">t2.eps"); # don't clobber the input, just for testing
open(OUT,">$inputFileName");
while (<IN>) {
chop;
$gotBbox=0;
if (/^\%\%(.*)BoundingBox: .*/) {
print OUT "%%"."$1BoundingBox: $bbox\n";
}
else {
print OUT "$_\n";
}
}
close(IN);
close(OUT);
Other methods
- Give a try to metafile2eps, a tool from LyX to convert EMF to EPS [52]
Inkscape
- Importing Inkscape + LaTeX
See SVG-Inkscape, in particular the guide to include Inkscape graphics with LaTeX.
Draw.io
- Export PDF
- Select File, Export As, PDF...
- Select Crop, and optionally Selection Only.
Exporting / editng LaTeX equations
There are many editors out there. The best one however seems to be KLatexFormula.
- Windows / Linux support
- Instant rendering
- Drag & drop support
- Can reopen equations saved in PNG format
Alternatives:
- Latexeqedit — limited to 300dpi, slow rendering, only PNG, cannot re-open
- Latexee — very slow
- EqualX &mdahs; no export, only for building the formula