开发者

How to get a list of all available (TTF-) Fonts with XeTeX?

Very neat that I can use any available TrueType font on my Windows machine with MikTex and XeTeX.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[]{article}
\usepackage{xltxtra,fontspec,xunicode}
\defaultfontfeatures{Scale=MatchLowercase}
\title{Fonttest}   
\begin{document} 
  \section{Section Title} {
    \setromanfont{Palatino Linotype}
      The quick brown fox jumps over the lazy dog.
  }
  \section{Section Title} {
    \setromanfont{ProggyCleanTTSZBP}
      The quick brown fox jumps over the lazy dog.
  }
\e开发者_StackOverflow中文版nd{document}

Is there a way to automatically generate a font test page for every available font? So that I do not have to type a test page for every available font by hand?

Actually, I do not even know how to get to the Long Font Name required for \setromanfont -- short of typing it from the screen. The Windows directory only lists the file names, obviously. Maybe this can be done in TeX itself, but I could manage it with a Python script or such like.


fc-list  | cut -d\  -f2-99 | cut -d: -f1 | sort -u


A two-step-approach

1. Building list of available fonts

For this one can use albatross, a command line tool included in tex distributions like texlive. It is designed to find fonts which include certain glyphs, e.g. if you want to typeset a text in English, you can use something like

 albatross -b 3 T h e

(replace T h e with whatever glyphs your font should be able to typeset)

This will give you a list of font names

2. Producing a test page

You can take the list of font names produced in step 1 and let latex iterate over them

% !TeX TS-program = xelatex

\documentclass{article}

\usepackage{pgffor}
\usepackage{fontspec}
\newcommand{\testphrase}{The quick brown fox jumps over the lazy dog.}

\begin{document}

\foreach \x in {
  Adobe Caslon Pro, 
  Adobe Garamond Pro,
  % many more fonts here
  Zapfino}{
  \section{\x}
  \begingroup
    \setmainfont{\x}
    \testphrase
  \endgroup
}
\end{document}

How to get a list of all available (TTF-) Fonts with XeTeX?


Not a worked out answer, but an idea. All you have to do is iterate over all installed font families, for which an API function exists: EnumFontFamiliesEx.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜