enter image description here

Inspired by my question How to create a PDF presentation for each available Beamer theme automatically?, now I want to compile my input file for each available LaTeX font package installed in my machine.

Listing each font name in \foreach as follows does not seem a good idea as it will not accommodate all available packages as well as it is not up-to-date.

% the file name of this code is inputfile.tex
% compile it with pdflatex -shell-escape inputfile.tex


\foreach \x in {1,...,26}{\char\numexpr\x+64\relax\char\numexpr\x+96\relax\space}
\sin (\alpha \pm\beta) &=\sin\alpha \cos \beta \pm \cos\alpha \sin\beta\\
\mathscr{L}\left\{f(t)\right\} &= F(s)\\
\vec{F} &= m\frac{\textrm{d}\vec{v}(t)}{\textrm{d}t}\\
\int_a^b f(x)\, \textrm{d}x &= F(b) -F(a)\\
\vec \nabla \cdot \vec \nabla \times A &= \vec\nabla  \times  \nabla U


\def\dojob#1{\immediate\write18{pdflatex -jobname=template-#1 "\def\noexpand\loadfont{#1} \noexpand\input{template}"}}

\foreach \x in {bera,palatino,mathpazo,helvet,libertine}

enter image description here

A list of all installed packages (the list includes not only font packages but also other packages) can be done easily with this method How to print the list of packages installed on TeX Live to a file?. However, I have no idea to filter the list and remove the non-font packages.

How to compile the same input file for each of LaTeX font packages installed in our machine?

  • 7
    I want to distribute my lecture notes to my students where each of them gets a copy with a unique font. Does it seem to be fun? Commented Nov 25, 2013 at 19:39
  • 1
    That's imho not possible without a lot of manual work. "font packages" don't have an identifiable structure like beamer themes. You could try to get a sensible list from the fd-files, but there no guarantee that the corresponding fonts exist and will still miss some fonts. Commented Nov 25, 2013 at 20:50
  • 1
    @DonutE.Knot, I respect your opinion but IMHO it does not seem to be funny. What is the reason to change the font for each student?
    – Sigur
    Commented Nov 25, 2013 at 22:01
  • 3
    @Sigur: Who said it becomes funny? It will be fun not funny. Commented Nov 25, 2013 at 22:20
  • 2
    +1 Although no exact idea, but this kind of automation can be done easily by Unix Power tools(shell,sed,awk,grep) or perl since TeX engines can be called any number of times,files can be parsed and rewritten with new set of fonts to get multiple .pdf's similar to Herbert example in Linked Q. Scripting has infinite power in Unix and even on windows with cygwin etc.. Commented Nov 25, 2013 at 22:52

3 Answers 3


Here is my solution, assuming you have access to a UNIX¹ system with a TeX installation.

Inside the working directory of your project

  1. Create a main subdirectory holding the files of your document.
  2. Edit the preamble of your document, so that it includes a statement input{fontsetup}.
  3. For each font package you want to test, create a subdirectory holding a single file fontsetup.tex responsible for setting up the font you want.
  4. In your directory project, create a build.sh shell script that you will run to produce your outputs, as described below.

The build.sh script may look like, where I assume your main document file is galley.tex and that your packages are 'lmodern mathpple'

pkg_list='mathpple lmodern'
for pkg in "$pkg_list"; do
  env TEXINPUTS="main:$pkg:." tex -jobname $pkg galley.tex

Depending on your system, you may replace the pkg_list assignment by

pkg_list=`find . -type d \( -name main -prune -o -print \)`

which saves you the trouble from maintaining the list.

Now you still have to prepare directories for each package you want to test—and update the pkg_list variable. To help you create the following fontsetup.sh script in your project directory:

for pkg in "$@"; do
   install -d $pkg
   printf '\\usepackge{%s}\n' $pkg > $pkg/fontsetup.tex

Give the execute bit to the scripts and give it a try with

$ ./fontsetup.sh mathpple lmodern
$ ./build.sh

The first command creates a directory for each package and a canonical fontsetup.tex file. The second command processes each package.

Having a different file for each font package is nice, because it allows you to add font-specific customisations.

¹ I mean FreeBSD of course!

  • Plus one: How about Windows version as Unix is not my interest right now? :-) Commented Nov 29, 2013 at 21:44
  • It is nice to learn Unix, because after this you can start to let the computer work for you—and this is what computer are for, aren't they? If you know any programming language you can use on windows, you can adapt the scripts above. Commented Nov 29, 2013 at 21:50
  • @DonutE.Knot By the way I find your idea giving exam sheets to your students, each with a different font, actually very funny! :-) Commented Nov 29, 2013 at 21:55
  • 4
    Yes. I love doing "crazy" (chaos oriented) ideas. :-) Commented Nov 29, 2013 at 22:07
  • @kissmyarmpit: On windows, it's easy! In the text editor, select with the mouse the text you want to be repeated. Ctrl-C, ctrl-v, enter, ctrl-v. Change to the application that lists the font names. Double-click on the font name. Then alt-tab back to the text editor. Put the mouse pointer over the place you are supposed to write the font name. Left-click (if do not have a left-handed mouse setting). Ctrl-v. Repeat for each font you want. After all that, click on the appropriate button to generate the PDF. Click on "open pdf". :-P Commented Feb 9, 2018 at 15:11

I have not enough reputation for a comment, even though this is meant as one and not an answer.

Probably, this question and the answers might be helpful for you: What fonts are installed on my box?

Note, that one answer states, that all fonts on this page should be available on a complete LaTeX-Install. But if you want to use some system fonts, this list might not be complete.


Really this should be done with a simple shell script or other Unix tool that generates a simple wrapper document, which loads your text. But here's a more TeX-centric solution. It has the benefit that you can use just one LaTeX document, which is not generated or modified programmatically.

A little-used feature of (La)TeX is that its argument can be a sequence of TeX commands instead of a filename. So, write your document so that the font is given by a macro, undefined in the document itself. Then every invocation can define the macro to be a different font.

The document:


Hello, Marienplatz!

From the Unix, Windows or VM/CMS command line:

% pdflatex "\def\myfont{palatino}\input{handout.tex}"
% mv handout.pdf palatino.pdf
% pdflatex "\def\myfont{times}\input{handout.tex}"
% mv handout.pdf times.pdf

Addendum: Indeed the above requires you to know and insert the font names manually, so it's not really what you're after. You only asked for Latex font packages, but would you settle for using all system fonts? Here's a little bash script for OS X, that'll generate versions for all installed truetype fonts:

for F in /Library/Fonts/*.ttf
   FONT=`basename "$F" .ttf`
   xelatex "\def\myfont{$FONT}\input{handout.tex}"
   mv handout.pdf "$FONT".pdf

Repeat for .otf and .ttc, if you have that many students. (Since this uses XeLaTeX, replace \usepackage{\myfont} with \setmainfont{\myfont} in handout.tex)

Edit 2: And here is a Windows version, using the command fc-list from this question to list usable fonts:

FOR /F %F IN ('fc-list :outline -f "%{family}\n"') DO 
   xelatex "\def\myfont{%F}\input{handout.tex}"; move handout.pdf %F.pdf

You are welcome.

  • Apologies, if you are interested in non-latex solutions! (Or do I still misunderstand which part I misparsed?)
    – alexis
    Commented Dec 3, 2013 at 22:06
  • I hope I've made partial amends now.
    – alexis
    Commented Dec 3, 2013 at 22:08
  • I think I need a solution that works on Windows. :-) But +1 for your effort. Commented Dec 3, 2013 at 22:18
  • Do you have the command fc-list in your TeX distribution?
    – alexis
    Commented Dec 3, 2013 at 22:21
  • @DonutE.Knot Windows might have PowerShell Scripting (similar to Unix shell script I suppose), I have no idea whether anyone can adapt the current answers to a PowerShell script. Otherwise Cygwin is the best bet. Commented Dec 3, 2013 at 22:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .