Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tvwerkhoven
Created August 2, 2011 08:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tvwerkhoven/1119851 to your computer and use it in GitHub Desktop.
Save tvwerkhoven/1119851 to your computer and use it in GitHub Desktop.
XeTeX cheatsheet
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
% File: cheatsheet.tex -- cheatsheet for various XeTeX typesetting features
% Author: Tim van Werkhoven (t.i.m.vanwerkhoven@gmail.com, 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
% http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
% Creative Commons, 444 Castro Street, Suite 900, Mountain View, California,
% 94041, USA.
%\documentclass{article}
\documentclass{book}
%%% 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.
% http://mirror.math.ku.edu/tex-archive/macros/latex/contrib/fontspec/fontspec.pdf
\usepackage[no-math]{fontspec}
\usepackage{xunicode}
%\usepackage{xltxtra}
% Load colors with names
\usepackage[usenames]{color}
% For headers
\usepackage{fancyhdr}
% Setup page size specifically
%\usepackage[twoside,paperheight=240mm,paperwidth=170mm,centering,height=186mm,width=120mm,outermargin=45mm]{geometry}
%\usepackage[xetex,twoside,paperheight=240mm,paperwidth=170mm,centering]{geometry}
\usepackage[xetex,twoside]{geometry}
% for source code stuff
\usepackage{listings}
% shows various LaTeX layout settings http://ftp.snt.utwente.nl/pub/software/tex/macros/latex/contrib/layouts/
\usepackage{layouts}
\usepackage{layout}
% supersedes babel, http://www.ctan.org/tex-archive/macros/xetex/latex/polyglossia
\usepackage{polyglossia}
% tiny package useful for spaces after commands
\usepackage{xspace}
% change font style of section headers http://www.ctan.org/tex-archive/macros/latex/contrib/sectsty/
\usepackage{sectsty}
% fancy verbatim http://ctan.org/tex-archive/macros/latex/contrib/fancyvrb
\usepackage{fancyvrb}
% footnotes stuff http://www.ctan.org/tex-archive/macros/latex/contrib/footmisc
\usepackage[side]{footmisc}
%%% Hyperref setup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hypersetup{
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}
\setmonofont[Scale=0.6]{Monaco}
% Math fonts aren't easy. Fontspec can only do so much (see http://www.ctan.org/tex-archive/macros/xetex/latex/fontspec). Another option is loading specific packages for math fonts, (see ftp://tug.ctan.org/pub/tex-archive/info/Free_Math_Font_Survey/survey.html and http://www.tug.org/pipermail/xetex/2008-March/009073.html) or sfmath for sans serif fonts (see http://dtrx.de/od/tex/sfmath.html).
% Using fontspec:
%\setmathrm{Arial}
%\setmathsf{Arial}
%\setmathtt{Arial}
%\setboldmathrm[BoldFont={Optima ExtraBlack}]{Optima Bold}
% With sfmath:
% \usepackage[cm]{sfmath}
% With specific packages
%\usepackage[garamond]{mathdesign}
\usepackage{eulervm}
%\usepackage[math]{kurier}
%\usepackage{cmbright}
% A somewhat satisfactory solution seems to be using unicode-math in combination with math-compatible open type fonts such as the STIX fonts (see http://www.charlietanksley.net/philtex/the-unicode-math-package-for-xelatex-and-the-stix-fonts/ and http://tex.stackexchange.com/questions/720/is-it-already-possible-to-use-the-stix-fonts and http://typophile.com/node/71171)
%\usepackage{unicode-math}
%\setmainfont{XITS}
%\setmathfont{XITS Math}
%\usepackage[math-style=ISO]{unicode-math}
% Problem: \setmathfont{} gives a bug when used in combination with amsmath...
%\setmathfont{STIXGeneral}
%\setmathfont[range=\mathit/{latin,Latin}]{Adobe Garamond Pro}
%\setmathfont[range=\mathit/{greek,Greek}]{Linux Libertine O}
%\usepackage{amsmath}
%\setmathfont{Asana-Math.otf}
%\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}%
\newfontfamily\marginfontt[Color=Red]{Fontin}
\newcommand{\marginfont}{\marginfontt\fontsize{8pt}{8pt}\selectfont}
% Set default languages
\setdefaultlanguage{british}
\setotherlanguage{dutch}
\setotherlanguage{latin}
%%% Page layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sloppy % don't care too much about a lot of
% space in sentences
\setlength{\parindent}{0ex}
\setlength{\parskip}{1ex}
\geometry{includeheadfoot,includemp,papersize={170mm,240mm},total={124mm,185mm}, outermargin=10mm, innermargin=15mm}
%\geometry{paper=a4paper, layout=a4paper}
%\setlength{\hoffset}{}
%\addtolength{\hoffset}{0.5in}
%\addtolength{\textwidth}{-1in}
%\setlength{\marginparwidth}{200pt}
%\setlength{\marginparwidth}{3cm}
% We use this number to scale the images made in Illustrator
\newcommand{\imgscale}{0.7}
% We use this number to scale the images made with gnuplot
\newcommand{\plotscale}{1}
% Some path-shortcuts
\newcommand{\imgpath}{../img/}
\newcommand{\plotpath}{../plots/}
%%% Section and Chapter layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newfontface\chaptertitfont{Frutiger LT Std 75 Black}
\newfontface\chapterfont{Frutiger LT Std 46 Light Italic}
\renewcommand{\@makechapterhead}[1]{%
\vspace*{100\p@}%
{\parindent \z@ \raggedright \chapterfont \fontsize{100}{140} \selectfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\huge\bfseries \@chapapp\space \thechapter
\par\nobreak
\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries \chaptertitfont #1\par\nobreak
\hrule
\vskip 40\p@
}}
%%% Custom commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some command abbreviations
\newcommand{\tsup}[1]{\textsuperscript{#1}}
\newcommand{\tsub}[1]{\textsubscript{#1}}
\newcommand{\rn}{\ensuremath{r}\tsub{0}\xspace}
\newcommand{\FOAM}{FOAM\xspace}
\renewcommand{\vec}[1]{\ensuremath{\boldsymbol{#1}}}%
\newcommand{\mat}[1]{\ensuremath{\mathbf{#1}}}%
%%% Begin document %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\thispagestyle{empty}
\sectionfont{\sectionrule{3ex}{3pt}{-1ex}{1pt}}
\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: http://tex.stackexchange.com/questions/24043/sub-and-superscripting-together-in-text-mode
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)
\begin{latin}
\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.
\end{latin}
}
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\\
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Math}
{
\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}
\begin{equation}
\label{eqn:residualrmsptt}
\sigma_{\varphi, 3}^2 = 0.134 \left ( \frac{d}{\rn} \right )^{5/3}.
\end{equation}
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
\begin{equation}
\label{eqn:residualrmsptt2}
\sigma_{\varphi, 3}^2 = \sin 0.335 \exp \left ( \frac{D}{\rn} \right )^{5/3} \int N^{-5/6},
\end{equation}
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
%\begin{align}
%& ⊢ ∀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)
%\end{align}
%%% Equation %%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Numerals}
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}
\begin{verbatim}
% see http://www.ctan.org/tex-archive/macros/xetex/latex/xltxtra/xltxtra.pdf
%\usepackage{xltxtra}
\usepackage{xunicode} %handle unicode
\usepackage{xltxtra} %XeTeX extras
\usepackage[math]{fontspec} %use OTF/TTF fonts
%\usepackage{fontspec} % loaded by xltxtra
\setmainfont{Cambria}
\setmonofont{Monaco}
\setsansfont{Minion Pro}
%\usepackage{xunicode} % loaded by xltxtra
%\usepackage{metalogo} % loaded by xltxtra
%\usepackage{fixltx2e} % loaded by xltxtra
\end{verbatim}
\subsection{Fancy verbatim}
\begin{Verbatim}[numbers=left, framerule=1pt]
% see http://www.ctan.org/tex-archive/macros/xetex/latex/xltxtra/xltxtra.pdf
\usepackage{xltxtra}
%\usepackage{fontspec} % loaded by xltxtra
\setmainfont{Cambria}
\setmonofont{Monaco}
\setsansfont{Minion Pro}
%\usepackage{xunicode} % loaded by xltxtra
%\usepackage{metalogo} % loaded by xltxtra
%\usepackage{fixltx2e} % loaded by xltxtr
\end{Verbatim}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\section{Text layouts}
\currentparagraph
\begin{figure}
\caption{Paragraphs in this document}
\paragraphdesign
\end{figure}
\begin{figure}
\listdiagram
\caption{List parameters}
\end{figure}
\begin{thebibliography}{Dillo 83}
\bibitem[Knud 66]{kn:gus} D. E. Knudson. \emph{1996 World Gnus Almanac.}
\currentlist
\begin{figure}
\listdesign
\caption{Bibliography list}
\end{figure}
\end{thebibliography}
\section{Page layouts}
\layout
\currentpage
\begin{figure}
\oddpagelayoutfalse
\twocolumnlayoutfalse
\pagediagram
\caption{oddpagelayoutfalse, twocolumnlayoutfalse, pagediagram}
\end{figure}
\currentpage
\begin{figure}
\oddpagelayouttrue
\twocolumnlayoutfalse
\pagediagram
\caption{\oddpagelayouttrue, twocolumnlayoutfalse, pagediagram}
\end{figure}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment