[XeTeX] using open type fonts for fancyvrb verbatim environments

Ulrike Fischer news3 at nililand.de
Fri Mar 11 09:30:49 CET 2011


Am Thu, 10 Mar 2011 14:40:12 +0000 (UTC) schrieb Ed Morehouse:

> I'm trying to use an OTF font for text within a fancyvrb Verbatim environment
> but can't figure out how to make it work.  Here's a small example to give an
> idea of what I'm trying to do:
> 
> 
> \documentclass{article}
> \usepackage{fancyvrb}
> \usepackage{fontspec}
> \newfontfamily \codefont{XITS Math}
> 
> \begin{document}
>   \begin{Verbatim}[fontfamily=codefont]
>     ∀ α ∈ ℕ . ∃ β ∈ ℕ . β > α
>   \end{Verbatim}
> \end{document}
> 
> 
> This produces the warning:
> 
> LaTeX Font Warning: Font shape `EU1/codefont/m/n' undefined
> (Font)              using `EU1/lmr/m/n' instead on input line 7.
> 
> [1] (./minimal.aux)
> 
> LaTeX Font Warning: Some font shapes were not available, defaults substituted.
> 
> 
> I also tried using "XITSMath" directly as the fontfamily argument, to no avail.

fontspec adds a number to the family name to be able to load the
same font with different features. So you would have to use eg
XITSMath(0). But looking at the fancyvrb code it is probably better
to define like for the predefined "tt" and "helvetica" a key word
which switch to the font:

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{fontspec}

\newfontfamily \codefont{XITS Math}
\makeatletter
\@namedef{FV at fontfamily@code}{%
  \def\FV at FontScanPrep{}%
  \def\FV at FontFamily{\codefont}}
\makeatletter

\begin{document}
  \begin{Verbatim}[fontfamily=XITSMath(0)]
   abc
  \end{Verbatim}

  \begin{Verbatim}[fontfamily=code]
   abc
  \end{Verbatim}
\end{document}




-- 
Ulrike Fischer 



More information about the XeTeX mailing list