> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/fonts/03-xelatex.md).

# Supporting modern fonts with XƎLaTeX

## Introduction

[XeTeX](https://tug.org/xetex/) is a typesetting engine derived from Donald Knuth's original TeX software. However, unlike Knuth's original program, XeTeX natively reads (inputs) UTF-8 encoded Unicode text and, with assistance from its built-in [HarfBuzz](https://harfbuzz.github.io/) shaping engine, supports modern font formats such as [OpenType (OTF)](https://docs.microsoft.com/en-us/typography/opentype/) and [SIL's Graphite font technology](https://scripts.sil.org/cms/scripts/page.php?site_id=projects\&item_id=graphite_home). The corresponding LaTeX [compiler](/latex/more-topics/08-choosing-a-latex-compiler.md) on Overleaf is called `xelatex`. Anyone interested to better understand the evolution of different TeX engines may wish to read the Overleaf article [What's in a Name: A Guide to the Many Flavours of TeX](/latex/in-depth-articles/55-what-s-in-a-name-a-guide-to-the-many-flavours-of-tex.md).

## The basics: Times New Roman

Times New Roman is a commonly-used font and here's an example of its use on Overleaf via the XeLaTeX compiler. In this example, the document font is set using `\usemainfont{Times New Roman}`, where the command `\usemainfont{...}` is provided by the package `fontspec`.

```latex
\documentclass[12pt]{article}
\usepackage{fontspec}

\setmainfont{Times New Roman}
\title{Sample font document}
\author{Overleaf}
\date{\today}

\begin{document}
\maketitle

This is an \textit{example} of a document compiled
with \textbf{XeLaTeX}. LuaLaTeX should also work too.

\end{document}
```

[Open Times New Roman example using XeLaTeX in Overleaf](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Times+New+Roman+%28via+XeLaTeX%29\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%7Bfontspec%7D%0A+%0A%5Csetmainfont%7BTimes+New+Roman%7D%0A%5Ctitle%7BSample+font+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7B%5Ctoday%7D%0A+++%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A+++++%0AThis+is+an+%5Ctextit%7Bexample%7D+of+a+document+compiled+%0Awith+%5Ctextbf%7BXeLaTeX%7D.+LuaLaTeX+should+also+work+too.%0A%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![XeLaTeXOverleaf.png](/files/d3ze7oA9gXr2oQMyLS9j)

You can also [use LuaLaTeX to run the same code](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Times+New+Roman+%28via+LuaLaTeX%29\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%7Bfontspec%7D%0A+%0A%5Csetmainfont%7BTimes+New+Roman%7D%0A%5Ctitle%7BSample+font+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7B%5Ctoday%7D%0A+++%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A+++++%0AThis+is+an+%5Ctextit%7Bexample%7D+of+a+document+compiled+%0Awith+%5Ctextbf%7BLuaLaTeX%7D.%0A%0A%5Cend%7Bdocument%7D) .

## 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:

```latex
\documentclass[12pt]{article}
\usepackage{fontspec}

%-----------------------------------------------------------------------
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont[Color={0019D4}]{Courier New}
%-----------------------------------------------------------------------

\title{Sample font document}
\author{Overleaf}
\date{\today}
\begin{document}

\maketitle

This an \textit{example} of document compiled with the
\textbf{XeLaTeX} compiler. If you have to write some code you can
use the \texttt{verbatim} environment:

    \begin{verbatim}
    Usually this environment is used to display code,
    so here's a simple C program.

    #include <stdio.h>
    #define NUMYAYS 10

    int main()
    {
        int i;
        for (i = 0; i <= NUMYAYS; i++)
        {
            printf("Yay! Overleaf is Awesome!\n");
        }
        return 0;
    }
    \end{verbatim}
    {\sffamily This is a sample text in \textbf{Sans Serif Font Typeface}}

\end{document}
```

[To see the result, open this XeLaTeX example on Overleaf](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Document+formatted+with+different+fonts\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%7Bfontspec%7D%0A%0A%25-----------------------------------------------------------------------%0A%5Csetmainfont%7BTimes+New+Roman%7D%0A%5Csetsansfont%7BArial%7D%0A%5Csetmonofont%5BColor%3D%7B0019D4%7D%5D%7BCourier+New%7D%0A%25-----------------------------------------------------------------------%0A%0A%5Ctitle%7BSample+font+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7B%5Ctoday%7D%0A%5Cbegin%7Bdocument%7D%0A++++%0A%5Cmaketitle%0A+++++%0AThis+an+%5Ctextit%7Bexample%7D+of+document+compiled+with+the++%0A%5Ctextbf%7BXeLaTeX%7D+compiler.+If+you+have+to+write+some+code+you+can+%0Ause+the+%5Ctexttt%7Bverbatim%7D+environment%3A%0A%0A++++%5Cbegin%7Bverbatim%7D%0A++++Usually+this+environment+is+used+to+display+code%2C+%0A++++so+here%27s+a+simple+C+program.%0A%0A++++%23include+%3Cstdio.h%3E%0A++++%23define+NUMYAYS+10%0A++++++%0A++++int+main%28%29%0A++++%7B%0A++++++++int+i%3B+++%0A++++++++for+%28i+%3D+0%3B+i+%3C%3D+NUMYAYS%3B+i%2B%2B%29+%0A++++++++%7B%0A++++++++++++printf%28%22Yay%21+Overleaf+is+Awesome%21%5Cn%22%29%3B%0A++++++++%7D%0A++++++++return+0%3B%0A++++%7D%0A++++%5Cend%7Bverbatim%7D%0A++++%7B%5Csffamily+This+is+a+sample+text+in+%5Ctextbf%7BSans+Serif+Font+Typeface%7D%7D%0A+++++++%0A%5Cend%7Bdocument%7D)

In the previous example three different fonts are used, the next lines determine the elements that will use this fonts:

**\setmainfont{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}**

Everything to be formatted with a monospaced (typewriter-like) font will use the Courier New font. This command has an extra optional parameter inside braces:

**Color={0019D4}**

This sets the colour of the text, using a Color= value using the hexadecimal HTML format. Selective and careful use of text colour can be useful when making a presentation.

## Fonts in Overleaf

There are [a large number of fonts installed on Overleaf](/latex/questions-and-answers/85-which-otf-or-ttf-fonts-are-supported-via-fontspec.md) which you can use in your project, most easily via `fontspec`. The following examples show the use of fonts included on Overleaf's servers, such as Google Noto, together with fonts that you need to upload from [Google Fonts](https://fonts.google.com/).

### Fonts installed on Overleaf's servers: Google Noto fonts

Because [TeX Live](https://www.tug.org/texlive/)—which is used by Overleaf—includes the [Google Noto fonts](https://www.google.com/get/noto/) you can use them, via the `fontspec` package, within Overleaf projects compiled using the XeLaTeX or LuaLaTeX compilers. Here is a sample project which uses the [`noto` package](https://ctan.org/pkg/noto?lang=en) to configure your document for typesetting with the NotoSerif, NotoSans and NotoSansMono font families. Documentation on the `noto` package can be found in its [readme file on CTAN](http://mirrors.ctan.org/fonts/noto/README).

```latex
\documentclass{article}
\usepackage{xcolor}
\usepackage{noto}
\usepackage{hyperref}
\title{Using Google Noto fonts}
\author{Overleaf}
\date{April 2021}

\begin{document}

\maketitle

\section{Introduction}
This example project uses the \href{https://ctan.org/pkg/noto?lang=en}{\color{blue}\texttt{noto}} package to typeset your document using Google's Noto fonts\footnote{\url{https://www.google.com/get/noto/}}:
\begin{itemize}
\item \verb|\textbf{bold}| produces \textbf{bold}
\item \verb|\textit{italic}| produces \textit{italic}
\item \verb|\textbf{\textit{bold italic}}| produces \textbf{\textit{bold italic}}
\item \verb|\emph{emphasis}| produces \emph{emphasis}
\item \verb|\textbf{\emph{bold italic}}| produces \textbf{\emph{bold italic}}
\end{itemize}

\subsection{Monospaced fonts}
You can use Noto's monospaced fonts for \texttt{regular} and \texttt{\textbf{bold}} monospaced text.

\subsection{Sans serif fonts}
Here is some \textsf{text is typeset in a sans serif font} together with \textbf{\textsf{text typeset in bold sans serif}}.

\section{Further reading}
Documentation for the \texttt{noto} package can be found in its \href{http://mirrors.ctan.org/fonts/noto/README}{\color{blue}\texttt{readme} file on CTAN}.

\end{document}
```

[Open this XeLaTeX example on Overleaf to explore the Noto fonts](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Using+Google+Noto+fonts\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bxcolor%7D%0A%5Cusepackage%7Bnoto%7D%0A%5Cusepackage%7Bhyperref%7D%0A%5Ctitle%7BUsing+Google+Noto+fonts%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BApril+2021%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cmaketitle%0A%0A%5Csection%7BIntroduction%7D%0AThis+example+project+uses+the+%5Chref%7Bhttps%3A%2F%2Fctan.org%2Fpkg%2Fnoto%3Flang%3Den%7D%7B%5Ccolor%7Bblue%7D%5Ctexttt%7Bnoto%7D%7D+package+to+typeset+your+document+using+Google%27s+Noto+fonts%5Cfootnote%7B%5Curl%7Bhttps%3A%2F%2Fwww.google.com%2Fget%2Fnoto%2F%7D%7D%3A%0A%5Cbegin%7Bitemize%7D%0A%5Citem+%5Cverb%7C%5Ctextbf%7Bbold%7D%7C+produces+%5Ctextbf%7Bbold%7D%0A%5Citem+%5Cverb%7C%5Ctextit%7Bitalic%7D%7C+produces+%5Ctextit%7Bitalic%7D%0A%5Citem+%5Cverb%7C%5Ctextbf%7B%5Ctextit%7Bbold+italic%7D%7D%7C+produces+%5Ctextbf%7B%5Ctextit%7Bbold+italic%7D%7D%0A%5Citem+%5Cverb%7C%5Cemph%7Bemphasis%7D%7C+produces+%5Cemph%7Bemphasis%7D%0A%5Citem+%5Cverb%7C%5Ctextbf%7B%5Cemph%7Bbold+italic%7D%7D%7C+produces+%5Ctextbf%7B%5Cemph%7Bbold+italic%7D%7D%0A%5Cend%7Bitemize%7D%0A%0A%5Csubsection%7BMonospaced+fonts%7D%0AYou+can+use+Noto%27s+monospaced+fonts+for+%5Ctexttt%7Bregular%7D+and+%5Ctexttt%7B%5Ctextbf%7Bbold%7D%7D+monospaced+text.%0A%0A%5Csubsection%7BSans+serif+fonts%7D%0AHere+is+some+%5Ctextsf%7Btext+is+typeset+in+a+sans+serif+font%7D+together+with+%5Ctextbf%7B%5Ctextsf%7Btext+typeset+in+bold+sans+serif%7D%7D.%0A%0A%5Csection%7BFurther+reading%7D%0ADocumentation+for+the+%5Ctexttt%7Bnoto%7D+package+can+be+found+in+its+%5Chref%7Bhttp%3A%2F%2Fmirrors.ctan.org%2Ffonts%2Fnoto%2FREADME%7D%7B%5Ccolor%7Bblue%7D%5Ctexttt%7Breadme%7D+file+on+CTAN%7D.%0A%0A%5Cend%7Bdocument%7D)

![Using Google Noto fonts to typeset a LaTeX document](/files/j8Pv5lsAkgbUn9dM0Uk7)

### Using fonts not installed on Overleaf's servers: Google Fonts example

To use OpenType fonts which are not installed on Overleaf's servers, you must first upload the font files to your Overleaf project—provided the font licenses permit this. Once the OpenType fonts are uploaded, set the project compiler to XƎLaTeX (or LuaLaTeX) and use `fontspec` to configure your fonts.

The example project outlined below shows how to create folders, upload fonts and configure them with `fontspec`. For our example we'll use the following selection of fonts from [Google Fonts](https://fonts.google.com/):

* Serif font: [Brygada1918](https://fonts.google.com/specimen/Brygada+1918)
* Sans serif font: [Asap](https://fonts.google.com/specimen/Asap)
* Monospace font: [JetBrains Mono](https://fonts.google.com/specimen/JetBrains+Mono)

Note: We are not suggesting this example provides a typographically harmonious combination of type styles, it merely shows how to upload, configure and use fonts of your choice.

For each typeface you need to download the font family from Google Fonts:

![GoogleDownload.png](/files/t8rPPzNCsN1l4emWvjOt)

Note: Some Google fonts are avalable as "static" OpenType fonts and so-called "variable" OpenType fonts. If the downloaded ZIP file has a folder called "static" you should upload the fonts in that folder, not the variable-font versions:

![OpenTypeStatic.png](/files/Vk2dOwjSQNlVnNXHbzd9)

Next, you need to upload the font files to your project but because font families contain multiple font files you may wish to create individual Overleaf project folders to contain the files—using one folder per font family. The following video shows how to do that. Later, we'll need to instruct XƎLaTeX where to find your project's fonts—because they aren't pre-installed on Overleaf's servers.

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/4lQFkZ1Ni1FHFdHJUJSNH4/4aee7c5bafeb021a6f21b4637d0fe6ec/UploadingGoogleFonts.mp4>" %}

### Configuring fontspec to use the fonts

After uploading the font-family files into Overleaf project folders we can configure them for use via `fontspec`. In the following LaTeX code, note how we have used the `Path` parameter to tell `fontspec` that the font files are located in a local folder within our project's file system:

```latex
\setmainfont{Brygada1918}[
    Path=./BrygadaFontFiles/,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]

\setsansfont{Asap}[
    Path=./AsapFontFiles/,
    Scale=0.9,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]

\setmonofont{JetBrainsMono}[
    Path=./JetbrainsFontFiles/,
    Scale=0.85,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]
```

![FontSpecPathUpdated.png](/files/Tg9iEvbQI0d6wrHJyAEF)

[Open XeLaTeX and Google Fonts demo on Overleaf](https://www.overleaf.com/project/new/template/31226?id=835225587\&templateName=XeLaTeX+font+demo+with+Google+Fonts\&latexEngine=xelatex\&texImage=texlive-full%3A2022.1\&mainFile=)

The [`fontspec` package](https://ctan.org/pkg/fontspec?lang=en) provides a wealth of options for configuring OpenType fonts for use with LuaLaTeX or XƎLaTeX—its [excellent documentation](http://mirrors.ctan.org/macros/unicodetex/latex/fontspec/fontspec.pdf) contains numerous examples which you can explore to fine-tune the design and typesetting of your documents.

## Further reading

For more information see:

* [Bold, italics and underlining](/latex/latex-basics/03-bold-italics-and-underlining.md)
* [Font sizes, families, and styles](/latex/fonts/01-font-sizes-families-and-styles.md)
* [Font typefaces](/latex/fonts/02-font-typefaces.md)
* [Paragraph formatting](/latex/formatting/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [Line breaks and blank spaces](/latex/formatting/05-line-breaks-and-blank-spaces.md)
* [Text alignment](/latex/formatting/06-text-alignment.md)
* [Multiple columns](/latex/formatting/09-multiple-columns.md)
* [Management in a large project](/latex/document-structure/07-management-in-a-large-project.md)
* [Multi-file LaTeX projects](/latex/document-structure/08-multi-file-latex-projects.md)
* [International language support](/latex/languages/03-international-language-support.md)
* [Choosing a LaTeX Compiler](/latex/more-topics/08-choosing-a-latex-compiler.md)
* [List of OTF and TTF fonts installed on Overleaf](/latex/questions-and-answers/85-which-otf-or-ttf-fonts-are-supported-via-fontspec.md)
* [Google's fonts collection](http://www.google.com/fonts/)
* [`fontspec` package manual](http://tug.ctan.org/tex-archive/macros/latex/contrib/fontspec/fontspec.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/fonts/03-xelatex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
