[Tex/LaTex] Package for changing font with each letter

fonts

I want to write a text in which each letter uses a different font. It is rather short. I guess I could make it letter by letter, selecting the font I want for each of them.

Are there easier ways?

Best Answer

Right, I'm sure that this could be vastly improved. In particular, it doesn't like spaces and it doesn't like being fed an argument (so using the lipsum package to demonstrate it didn't work). Of course, the kerning is completely messed up, but then I'd be amazed at a solution that got that right!

alt text

It uses the fontspec package, and for some reason unknown to me, to use the proper names of the fonts required me to use lualatex instead of xelatex.

Without further ado, here's the code:

\documentclass{article}

\usepackage{fontspec}
\pagestyle{empty}

\newfontfamily\fonta{TeX Gyre Bonum}
\newfontfamily\fontb{TeX Gyre Adventor}
\newfontfamily\fontc{TeX Gyre Chorus}
\newfontfamily\fontd{TeX Gyre Heros}
\newfontfamily\fonte{TeX Gyre Pagella}
\newfontfamily\fontf{TeX Gyre Schola}
\newfontfamily\fontg{TeX Gyre Termes}
\newfontfamily\fonth{GFS Artemisia}
\newfontfamily\fonti{GFS Bodoni}
\newfontfamily\fontj{Iwona}
\newfontfamily\fontk{GFS Didot}
\newfontfamily\fontl{GFS Neohellenic}
\newfontfamily\fontm{Kurier}
\newfontfamily\fontn{Free Mono}
\newfontfamily\fonto{Free Sans}
\newfontfamily\fontp{Free Serif}
\newfontfamily\fontq{Inconsolata}
\newfontfamily\fonts{Linux Libertine O}
\newfontfamily\fontt{Cyklop}
\newfontfamily\fontu{Old Standard}
\newfontfamily\fontv{Antykwa Poltawskiego}
\newfontfamily\fontw{STIX General}
\newfontfamily\fontx{Punknova}
\newfontfamily\fonty{Semafor}
\newfontfamily\fontz{UM Typewriter}

\makeatletter
\edef\my@relax{\relax}
\newcommand{\do@font}[1]{%
  \edef\my@arg{#1}%
  \ifx\my@arg\my@relax
  \else
  \@ifundefined{font#1}{}{%
    \csname font#1\endcsname}%
  \my@arg
  \expandafter\do@font
  \fi}

\newcommand{\dofont}[1]{%
  \edef\my@arg{#1}%
  \expandafter\do@font\my@arg\relax}
\makeatother

\begin{document}
\Large
\dofont{the quick brown fox jumped over the lazy dog}

\dofont{abcdefghijklmnopqrstuvwxyz}

\end{document}

All the fonts are ones that I found in my TeXLive2010 distribution.

Related Question