Advanced Fonts with XeLaTeX
If you and your group have any questions, or get stuck as you work through this in-class exercise, please ask the instructor for assistance. Have fun!
XeLaTeX is an alternative compiler to regular LaTeX that supports Unicode text and other modern font formats.
Let’s create a new project for this activity in Overleaf.
-
Create a new project in Overleaf and choose the first one (Blank paper)
-
Change compiler. Click the top left Menu button, scroll down to Settings, click the drop down next to Compiler, then select XeLaTeX.
-
Replace the original text with the following to set up your title page:
\documentclass[pdf]{article} \usepackage{fontspec} \setmainfont{Times New Roman} \setsansfont{Arial} \setmonofont[Color={4CA6A6}] {Courier New} %4CA6A6 is the hex code for teal. \title{Fun with Fonts} \author{Your name here} \date{\today} \begin{document} \maketitle \end{document}
- Change the font
- Add text in a different font by typing it inside curly brackets. Copy and paste the below line between your
\maketitle
and\end{document}
statements.This is the default font, Times New Roman. \sffamily Here is some text in Arial, a sans serif family font. \ttfamily Here is some teal text in Courier New, a mono font. \rmfamily Set back to times new roman
- Add text in a different font by typing it inside curly brackets. Copy and paste the below line between your
- Add a font package for Japanese, Chinese, or Korean
- Add
\usepackage{xeCJK}
to the top of the file with the other\usepackage
statements. - Add
\setCJKmainfont{IPAMincho}
below the other font statements - Go to Google Translate and translate a phrase from English to Japanese
- Copy the Japanese translation into your overleaf document.
- Re-compile - you should now see the Japanese text in the pdf.
- Add
- Add a font from outside Overleaf
- Go to Google Fonts and download the Asap font family files by clicking the Download Family button on the top right.
- Click the top left folder icon to make a new folder in Overleaf. Name the folder AsapFontFiles. Note: the folder name is case sensitive!
- Upload the font files into your new folder using the Upload button on the top left.
- Copy and paste into your document:
\setsansfont{Asap}[ Path=./AsapFontFiles/, Scale=0.9, Extension = .ttf, UprightFont=*-Regular, BoldFont=*-Bold, ItalicFont=*-Italic, BoldItalicFont=*-BoldItalic ]
- Try writing some text in the Asap font:
\sffamily Now we can type in asap! The Quick Brown Fox Jumps Over the Lazy Dog
- Add a Unicode font
- In the top of the document, replace
\setmainfont{Times New Roman}
with\setmainfont{Doulos SIL}
- Doulos SIL is a Unicode font family. Now you can use unicode characters in your LaTeX document!
- Type some IPA (International Phonetic Alphabet) characters using this browser IPA keyboard and this reference guide, then copy and paste them into your Overleaf document.
- If you have a unicode keyboard installed on your computer, you can type directly in your Overleaf document.
- Type out these SENĆOŦEN words using the SENĆOŦEN Keyboard, then copy-paste them into a table like the image below.
- Hint: use ‘ to add top accent, - for dash accent and = for low line accent.
- In the top of the document, replace
- OPTIONAL: Using Tipa, a phonetic alphabet font
- Tipa is an older way to use IPA symbols in LaTeX before unicode was supported - you can skip this part of the activity if you like.
- Make a new folder called TipaFontFiles
- Download the tipa font files
- Tipa has a lot of different font options, but to keep things simple upload roman (tipa8), bold (tipab10), italic (tipasl8), and bold italic (tipasb10) to your new folder.
- Copy and paste:
\setsansfont{tipa}[ Path=./TipaFontFiles/, Scale=0.9, Extension = .pfb, UprightFont=*8, BoldFont=*b10, ItalicFont=*sl8, BoldItalicFont=*sb10 ]
- Use pages 14 and 36-56 of the Tipa manual to type up some phonetic symbols.
- Try to write out the IPA pronunciation for Lekwungen:
- Solution:
\sffamily l@\textvbaraccent{k}\textsuperscript{w}@N@n
- If you want more resources, here are some helpful links:
- More help on XeLaTeX
- More help on font commands
Congratulations - now you can use fonts with XeLaTeX!
NEXT STEP: Earn a Workshop Badge