wtorek, 6 marca 2012

Simple application of fontspec package

The document body font is Times New Roman-like. Sans serif font is Helvetica-like. Both regular and condensed variant of sans serif is used. With fontspec package it can be obtained with:


\RequirePackage{ifxetex} %%
\ifxetex %% xetex
\RequirePackage{fontspec}
\usepackage{polyglossia} \setdefaultlanguage{polish}
\setmainfont{TeX Gyre Termes}
\setsansfont{TeX Gyre Heros}
\defaultfontfeatures{Mapping=tex-text}
\newfontfamily\PM@SansCondensed{TeX Gyre Heros Cn} %%
\usepackage{xunicode,xltxtra}
\else %% conventional TeX
\RequirePackage{tgtermes,txfonts,qtxmath} %% txfonts
\def\PM@SansCondensed{\fontfamily{qhvc}}
\fi

With the help of \ifxetex command from ifxetex package the code above works when compiled both with xetex as well as conventional pdflatex.

The example below illustrates how \PM@SectionFont can be used to switch to condensed variant of sans serif:


\renewcommand{\section}{\@startsection{section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\reset@font
\PM@SectionFont
\raggedright}}

Finally, a few words how to configure system (a Linux one, BTW strictly speaking MS Windows is not a system) to work with OpenType fonts.

Providing the TeX Gyre fonts package is installed (with tlmgr in case of TeXLive for example) all .otf files are located in ~/2011/texmf-dist/fonts/opentype/public/tex-gyre (where ~ denotes the root of TeXlive distribution).

To add all TeX Gyre fonts to system resources it suffice to create /etc/fonts/local.conf with the following content:


<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<!-- /etc/fonts/local.conf file for local customizations -->
<fontconfig>
<!-- Font directory list -->

<dir>/usr/local/texlive/2011/texmf-dist/fonts/opentype/public/tex-gyre</dir>

</fontconfig>

Or similar, if root of TeXlive distribution is not /usr/local/.

Now run as root


fc-cache

Check if everything is OK:


fc-list | grep -i Heros

Information on TeX Gyre Heros should be displayed on screen:


TeX Gyre Heros Cn:style=Bold
TeX Gyre Heros Cn:style=Bold Italic
TeX Gyre Heros:style=Regular
TeX Gyre Heros Cn:style=Regular
TeX Gyre Heros:style=Bold Italic
TeX Gyre Heros:style=Italic
TeX Gyre Heros Cn:style=Italic
TeX Gyre Heros:style=Bold

Brak komentarzy:

Prześlij komentarz