XeLaTeX
Even though LaTeX provides an extensive set of fonts, you may want to use an an external font you really like and you have already installed system-wide, this is possible with XƎTeX. XeTeX is a TeX typesetting engine using Unicode and supporting modern font technologies such as OpenType (OTF), TrueType (TTF), Graphite, and Apple Advanced Typography (AAT). The corresponding compilers are xetex
and xelatex
.
Introduction
Times New Roman is one of the most used fonts, if you have this font installed in your system you can use it in your LaTeX document.
\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\title{Sample font document}
\author{Hubert Farnsworth}
\date{this month, 2014}
\begin{document}
\maketitle
This an \textit{example} of document compiled
with \textbf{xelatex} compiler. LuaLaTeX should
work fine also.
\end{document}
In this example the document uses the popular Times New Roman font, this font is set by \usemainfont{Times New Roman}
. The package fontspec must be imported for this to work.
Setting fonts for different LaTeX elements
Different elements in a LaTeX document are formatted with different fonts, for example in a verbatim environment the text is displayed using a typewriter style. Different font styles can be set for each context:
\documentclass[12pt]{article}
\usepackage{fontspec}
%This would work on a standard latex installation, (your local computer)
%-----------------------------------------------------------------------
\setromanfont{Times New Roman}
\setsansfont{Arial}
\setmonofont[Color={0019D4}]{Courier New}
%-----------------------------------------------------------------------
\title{Sample font ocument}
\author{Hubert Farnsworth}
\date{this month, 2014}
\begin{document}
\maketitle
This an \textit{example} of document compiled with
\textbf{xelatex} compiler. If you have to write
some code
\begin{verbatim}
usually this environment is used to display code
<html>
<head> </head>
<body>
<h1> Hello World</h1>
</body>
</html>
\end{verbatim}
{\sffamily This is a sample text in \textbf{Sans Serif Font Typeface}}
\end{document
In the previous example three different fonts are used, the next lines determine the elements that will use this fonts:
\setromanfont{Times New Roman}
- This is the normal font used in most of the document, Times New Roman in the example.
\setsansfont{Arial}
- The elements that require a sans font, explicitly declared by the
\ssfamily
in the example, will be typeset with Arial font.
\setmonofont{Courier New}
- Everithing that must be formatted with a Typewritter font in your document will use the Courier New font. This command has an extra optional parameter inside braces:
Color={0019D4}
- This sets the colour of the text in hex html format. Especially useful when making a presentation.
You can use the fonts installed in your system, see the reference guide for a list of font-directories for different operating systems. There are a large number of fonts installed on Overleaf too, which you can use with the above syntax.
Fonts in Overleaf
If you want to use your own fonts on Overleaf you must upload them first, and then configure your document to be compiled with XƎLaTeX. To render the example of the previous section add the next to the preamble:
\usepackage{fontspec}
% Times New Roman
\setromanfont[
BoldFont=timesbd.ttf,
ItalicFont=timesi.ttf,
BoldItalicFont=timesbi.ttf,
]{times.ttf}
% Arial
\setsansfont[
BoldFont=arialbd.ttf,
ItalicFont=ariali.ttf,
BoldItalicFont=arialbi.ttf
]{arial.ttf}
% Courier New
\setmonofont[Scale=0.90,
BoldFont=courbd.ttf,
ItalicFont=couri.ttf,
BoldItalicFont=courbi.ttf,
Color={0019D4}
]{cour.ttf}
The file names end with a .tff extension because they are True Type fonts, other fonts are also supported. Check also the Google WebFonts collection for many free fonts.
Reference guide
Fonts directories
Depending on your operating system you can find font files (.otf/.ttf) in the following directory:
- Mac OS X: /Library/Fonts
- Windows: Windows/Fonts
- Linux: /usr/share/fonts/ (some user-installed fonts can be in /usr/local/share/fonts/ or ~/.fonts/)
If you want to find your fonts by name, open Fonts module in your Control Panel / System Settings application or see fonts list in your Word or Libre/Open Office suite.
Further reading
For more information see:
- Bold, italics and underlining
- Font sizes, families, and styles
- Font typefaces
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Multiple columns
- Management in a large project
- Multi-file LaTeX projects
- International language support
- Choosing a LaTeX Compiler
- List of OTF and TTF fonts installed on Overleaf
- Google's fonts collection
fontspec
package manual- Using your favourite fonts with ShareLaTeX (now Overleaf) from the former ShareLaTeX blog
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Debugging Compilation timeout errors
- How-to guides
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Fractions and Binomials
- Aligning Equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management in LaTeX
- Bibliography management with biblatex
- Biblatex bibliography styles
- Biblatex citation styles
- Bibliography management with natbib
- Natbib bibliography styles
- Natbib citation styles
- Bibliography management with bibtex
- Bibtex bibliography styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections and equations
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typing exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class
- Tips