Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
XeTeX cheatsheet
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
% File: cheatsheet.tex -- cheatsheet for various XeTeX typesetting features
% Author: Tim van Werkhoven (, 2011)
% I keep this file as a scrap book of various tricks in LaTeX/XeTeX that I
% picked up from various places. I try to refer to places where I found the
% TeX code when possible, and refer to documentation as much as possible as
% well. Feel free to use this cheatsheet for your own purposes.
% This work is licensed under the Creative Commons Attribution-NonCommercial-
% ShareAlike 3.0 Unported License. To view a copy of this license, visit
% or send a letter to
% Creative Commons, 444 Castro Street, Suite 900, Mountain View, California,
% 94041, USA.
%%% Load packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For clickable URLS/references/etc. within the PDF document
\usepackage[dvipdfm, colorlinks, breaklinks]{hyperref}
% Some improvements for xetex and latex. Loads fixltx2e, metalogo, xunicode, fontspec.
% Load colors with names
% For headers
% Setup page size specifically
% for source code stuff
% shows various LaTeX layout settings
% supersedes babel,
% tiny package useful for spaces after commands
% change font style of section headers
% fancy verbatim
% footnotes stuff
%%% Hyperref setup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pdfauthor = {Tim van Werkhoven},
pdftitle = {Title goes here},
pdfsubject = {Subject goes here},
pdfkeywords = {Keywords, go, here},
pdfcreator = {XeLaTeX with hyperref package},
pdfproducer = {pdfLaTeX},
colorlinks = false,
linkcolor = red, % color of internal links
citecolor = green, % color of links to bibliography
filecolor = magenta, % color of file links
urlcolor = blue, % color of external links
%%% Set Font options %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\defaultfontfeatures{Mapping=tex-text, Fractions=Diagonal}
% Choose default fonts
\setmainfont[Numbers={OldStyle}]{Garamond Premier Pro}
\setsansfont[Scale=MatchLowercase]{Helvetica Neue}
% Math fonts aren't easy. Fontspec can only do so much (see Another option is loading specific packages for math fonts, (see and or sfmath for sans serif fonts (see
% Using fontspec:
%\setboldmathrm[BoldFont={Optima ExtraBlack}]{Optima Bold}
% With sfmath:
% \usepackage[cm]{sfmath}
% With specific packages
% A somewhat satisfactory solution seems to be using unicode-math in combination with math-compatible open type fonts such as the STIX fonts (see and and
%\setmathfont{XITS Math}
% Problem: \setmathfont{} gives a bug when used in combination with amsmath...
%\setmathfont[range=\mathit/{latin,Latin}]{Adobe Garamond Pro}
%\setmathfont[range=\mathit/{greek,Greek}]{Linux Libertine O}
%\setmathfont[range=\mathit/{greek,Greek,latin,Latin}]{Adobe Garamond Pro}
% This is how you can define custom temporary font styles
\newcommand{\fontold}[1]{\fontspec[Alternate=1,Ligatures={Common, Rare}, Swashes={LineInitial, LineFinal}]{Hoefler Text}\fontsize{24pt}{30pt}\selectfont #1}%
\newcommand{\smallprint}[1]{\fontspec{Adobe Garamond Pro}\fontsize{10pt}{13pt}\color{Gray}\selectfont #1}%
% Set default languages
%%% Page layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sloppy % don't care too much about a lot of
% space in sentences
\geometry{includeheadfoot,includemp,papersize={170mm,240mm},total={124mm,185mm}, outermargin=10mm, innermargin=15mm}
%\geometry{paper=a4paper, layout=a4paper}
% We use this number to scale the images made in Illustrator
% We use this number to scale the images made with gnuplot
% Some path-shortcuts
%%% Section and Chapter layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newfontface\chaptertitfont{Frutiger LT Std 75 Black}
\newfontface\chapterfont{Frutiger LT Std 46 Light Italic}
{\parindent \z@ \raggedright \chapterfont \fontsize{100}{140} \selectfont
\ifnum \c@secnumdepth >\m@ne
\huge\bfseries \@chapapp\space \thechapter
\vskip 20\p@
\Huge \bfseries \chaptertitfont #1\par\nobreak
\vskip 40\p@
%%% Custom commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some command abbreviations
%%% Begin document %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{XeTeX \LaTeX\ cheatsheet}
\section{Legacy syntax}
These are both em-dashes, one set in the \LaTeX\ shortcut triple-dash, the other using the proper Unicode character. The same things holds for the quotes.
When he goes---``Hello World!''\marginpar{en-dash: –}\\*
She replies—“Hello dear!”\footnote{This footnote goes to the side. They can be very long and will span multiple lines if necessary.}
No fraction 1/2, fraction: 1⁄2 \marginpar{fraction slash:\ ⁄}
{\sffamily No fraction 1/2, fraction: 1⁄2} \marginpar{\textbackslash sffamily}
% See also:
Here we go with superscript 1\tsup{st} 2\tsup{nd} \tsup{12}\tsub{6}C $\int^{1}_{2}$
\section{Font styles \& ligatures}
% Set hyphenation to Latin for this part (using polyglossia)
\fontspec[Ligatures={Common, Rare},Fractions=Diagonal, Alternate=0]{Hoefler Text Italic}
\fontsize{18pt}{18pt}\selectfont Q\marginpar{Hoefler Text Italic 12/18pt}
\fontsize{12pt}{18pt}\selectfont {\scshape uesto è strano assai!} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Here we match the sans-serif fontsize to the roman font size:\\*
{\sffamily Sed massa libero}\marginpar{sffamily}%
, sagittis at vulputate et, suscipit ut sem.
Small caps and uppercase small caps respectively for TeX Gyre Adventor:\\
\fontspec[Letters=SmallCaps]{TeX Gyre Adventor} THIS SENTENCE no verb \hspace{2em}\marginpar{SmallCaps/\\ UppercaseSmallCaps}
\fontspec[Letters=UppercaseSmallCaps]{TeX Gyre Adventor} THIS SENTENCE no verb\\
Adobe Garamond Pro uppercase with default and forced uppercase letters:\\
\fontspec{Adobe Garamond Pro} UPPER-case EXAMPLE \hspace{2em}
\addfontfeature{Letters=Uppercase} UPPER-case EXAMPLE\\
TeX Gyre Bonum with numbers Lining and SlashedZero features:\\
\fontspec[Numbers=Lining]{TeX Gyre Bonum} 0123456789\hspace{2em}\marginpar{TeX Gyre Bonum\\Lining, SlashedZero}
\fontspec[Numbers=SlashedZero]{TeX Gyre Bonum} 0123456789 \\
\fontspec{Hoefler Text}\selectfont Without Contextual Swashes \hspace{2em}\marginpar{Contextuals=Swash}
\fontspec[Contextuals=Swash]{Hoefler Text}\selectfont With Contextual Swashes; cf. WCS\\
Small print for Adobe Garamond Pro (8pt 2pt leading):\\
\fontspec{Adobe Garamond Pro}\fontsize{8pt}{10pt}\selectfont This is small print
Alternate characters for Garamond Premier Pro:\\
\fontspec[Alternate=1]{Garamond Premier Pro} Sed massa libero, sagittis at vulputate
Titlingcaps in second example:\\
\fontspec{Garamond Premier Pro}\selectfont TITLING CAPS \hspace{2em}
\addfontfeature{Style=TitlingCaps}\selectfont TITLING CAPS\\
\fontspec[Fractions=Diagonal]{Skia} \marginpar{Fractions=Diagonal, Skia}
Note: these are different slashes, the former is a proper fraction slash, the other a regular slash. Note how XeTeX
interprets the former slash properly to make a fraction:
Fraction \& 12345⁄212345 \& 12345/1234
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
\marginpar{Math mode}
\sigma_{\varphi, 3}^2 = 0.134 \left ( \frac{d}{\rn} \right )^{5/3}.
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
\sigma_{\varphi, 3}^2 = \sin 0.335 \exp \left ( \frac{D}{\rn} \right )^{5/3} \int N^{-5/6},
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
%& ⊢ ∀x[(Fx ∨ Gx) → \mathord{∼}Hx] \\
%& ⊨ ¬∃y∀x[x∈y ↔ x∉x] \\
%& ⊭ x ∩ (y ∪ z) ≠ (x ∩ y) ∪ (x ∩ z) \\
%& ⊢ ⟦α⟧ = ℵ₀ → α ≇ ℘(α) \\
%& ⌜ψ[(℩x)φx]⌝ ≝
% ⌜(∃x)[φx ∧ (∀z)(φz ⊃ x=z) ∧ ψx]⌝ \\
%& ⊢ (P ⥽ Q) ⥽ (□P ⥽ ◇Q)
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
Two types of numerals, `lowercase' or oldstyle fit better with lowercase text, the other look more like capitals.
\fontspec[Numbers={OldStyle}]{Hoefler Text}Old style: 1234567\\
\fontspec[Numbers={Lining}]{Hoefler Text}Lining: 1234567
\section{Verbatim, source code}
\subsection{Regular verbatim}
% see
\usepackage{xunicode} %handle unicode
\usepackage{xltxtra} %XeTeX extras
\usepackage[math]{fontspec} %use OTF/TTF fonts
%\usepackage{fontspec} % loaded by xltxtra
\setsansfont{Minion Pro}
%\usepackage{xunicode} % loaded by xltxtra
%\usepackage{metalogo} % loaded by xltxtra
%\usepackage{fixltx2e} % loaded by xltxtra
\subsection{Fancy verbatim}
\begin{Verbatim}[numbers=left, framerule=1pt]
% see
%\usepackage{fontspec} % loaded by xltxtra
\setsansfont{Minion Pro}
%\usepackage{xunicode} % loaded by xltxtra
%\usepackage{metalogo} % loaded by xltxtra
%\usepackage{fixltx2e} % loaded by xltxtr
\section{Text layouts}
\caption{Paragraphs in this document}
\caption{List parameters}
\begin{thebibliography}{Dillo 83}
\bibitem[Knud 66]{kn:gus} D. E. Knudson. \emph{1996 World Gnus Almanac.}
\caption{Bibliography list}
\section{Page layouts}
\caption{oddpagelayoutfalse, twocolumnlayoutfalse, pagediagram}
\caption{\oddpagelayouttrue, twocolumnlayoutfalse, pagediagram}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment