LaTeX/Fonts

From Wikibooks, open books for an open world
Jump to: navigation, search

In order to select a font other than the default typeface in Latex environment, it is necessary to include some commands in the preamble of the document.

For example:

 \usepackage[T1]{fontenc}
 \usepackage[light,math]{iwona}

Important: note that this only works for fonts that are already prepared for use with LaTeX. If what you have is a ttf font or similar, you will have to convert it and make it available to LaTeX. See the external links section below for some useful resources.

Contents

[edit] Example

Below is an example found at the Google discussion group latexlovers. The example demonstrates how to select different fonts in a simple document.

\documentclass{book}
 
\begin{document}
 
 % using default font  (\familydefault = \rmdefault = Computer Modern Roman)
 Lorem ipsum dolor sit amet, consectitur adipiscing elit.
 
 \renewcommand*\rmdefault{ppl}\normalfont\upshape
 Lorem ipsum dolor sit amet, consectitur adipiscing elit. % using Palatino font
 
 \renewcommand*\rmdefault{iwona}\normalfont\upshape
 Lorem ipsum dolor sit amet, consectitur adipiscing elit. % using Iwona font
 
\end{document}

[edit] XeTeX

If you use the XeTeX or LuaTeX engine and the fontspec package, you'll be able to use any font installed in the system effortlessly. XeTeX also allows using OpenType technology of modern fonts like specifying alternate glyphs and optical size variants. XeTeX also uses Unicode by default, which might be helpful for font issues.

To use the fonts, simply load the fontspec package and set the font:

\documentclass{article}
 
\usepackage{fontspec}
\setmainfont{Arial}
 
\begin{document}
Lorem ipsum...
\end{document}

Then compile the document with XeLateX or LuaLaTeX. Note that you can only generate .pdf files, and that you need a sufficiently new TeX distribution (TeX Live 2009 should work for XeTeX and Tex Live 2010 for LuaTeX). Also you should NOT load the inputenc or fontenc package. To make support both pdflatex and XeTeX you can use the \ifxetex macro from the ifxetex package.

\documentclass{article}
\usepackage{ifxetex}
 
\ifxetex
  \usepackage{fontspec}
  \usepackage{xunicode}
  \defaultfontfeatures{Mapping=tex-text} % To support LaTeX quoting style
  \setromanfont{Hoefler Text}
\else
  \usepackage[utf8]{inputenc}
  \usepackage[T1]{fontenc}
\fi
 
\begin{document}
Lorem ipsum...
\end{document}

[edit] Useful websites

[edit] TrueType (ttf) fonts


Previous: Colors Index Next: Mathematics
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export