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

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

\documentclass[preview,border=12pt,multi]{standalone}
\usepackage{filecontents}

\begin{filecontents*}{template.tex}
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{pgffor}
\usepackage{amsmath}
\usepackage{mathrsfs}
\begin{document}
\foreach \x in {1,...,26}{\char\numexpr\x+64\relax\char\numexpr\x+96\relax\space}
\begin{align*}
\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
\end{align*}
\end{document}
\end{filecontents*}

\usepackage{graphicx}
\usepackage{pgffor}

\begin{document}
\foreach \x in {bera,palatino,mathpazo,helvet,libertine}
{%
\dojob{\x}%
\preview
\section{\x}
\includegraphics{template-\x}
\endpreview
}
\end{document}


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?

-
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? –  cyanide-based food Nov 25 '13 at 19:39
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. –  Ulrike Fischer Nov 25 '13 at 20:50
@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 Nov 25 '13 at 22:01
@Sigur: Who said it becomes funny? It will be fun not funny. –  cyanide-based food Nov 25 '13 at 22:20
+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.. –  texenthusiast Nov 25 '13 at 22:52

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'

#!/bin/sh
pkg_list='mathpple lmodern'
for pkg in "$pkg_list"; do env TEXINPUTS="main:$pkg:." tex -jobname $pkg galley.tex done  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: #!/bin/sh for pkg in "$@"; do
install -d $pkg printf '\\usepackge{%s}\n'$pkg > $pkg/fontsetup.tex done  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? :-) – cyanide-based food Nov 29 '13 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. – Michael Grünewald Nov 29 '13 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! :-) – Michael Grünewald Nov 29 '13 at 21:55 Yes. I love doing "crazy" (chaos oriented) ideas. :-) – cyanide-based food Nov 29 '13 at 22:07 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. - +1 for your link. You deserve an up-vote. – cyanide-based food Nov 27 '13 at 20:48 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: \documentclass{article} \usepackage{\myfont} \begin{document} Hello, Marienplatz! \end{document}  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 etc.  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 do FONT=basename "$F" .ttf
xelatex "\def\myfont{$FONT}\input{handout.tex}" mv handout.pdf "$FONT".pdf
done


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 Dec 3 '13 at 22:06
I hope I've made partial amends now. –  alexis Dec 3 '13 at 22:08
I think I need a solution that works on Windows. :-) But +1 for your effort. –  cyanide-based food Dec 3 '13 at 22:18
Do you have the command fc-list in your TeX distribution? –  alexis Dec 3 '13 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. –  texenthusiast Dec 3 '13 at 22:26