Lualatex: Font table with examples
This improves Caramdir's answer to make the table easier to read:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Latin Modern Mono Light}
\usepackage{luacode}
\usepackage[margin=18mm]{geometry}
\parindent=0pt
\usepackage{longtable,makecell}
\renewcommand\arraystretch{2}
\begin{document}
\begin{luacode}
myfonts=dofile(fonts.names.path.localdir..'/otfl-names.lua') -- TeX Live 2012 or earlier
-- myfonts=dofile(fonts.names.path.path) -- TeX Live 2013
teststring = "Sphinx of black quartz, judge my vow."
tex.print("\\begin{longtable}{ll}\\hline")
for i,v in ipairs(myfonts.mappings) do
-- Stop early for testing purposes.
if i > 20 then break end
tex.print('\\makecell[l]{\\bfseries')
tex.print(-2, v.familyname)
tex.print('\\\\[-1ex] \\scriptsize')
tex.print(-2, v.fontname)
tex.print('} & \\LARGE\\fontspec{' .. v.fontname .. '}')
tex.print(-2, teststring)
tex.print('\\\\ \\hline')
end
tex.print("\\end{longtable}")
\end{luacode}
\end{document}
This works for me—as long as there are no fonts with underscores or other offending characters. For the general case, use the optional first argument of tex.print
to avoid any troubles: setting it to -2
assigns catcode 12 (other) to all characters except spaces (that way TeX doesn't see \
, _
, etc. as special characters). See the LuaTeX manual (texdoc luatex
) for details.
\documentclass[10pt,a4paper]{article}
\usepackage{fontspec}
\usepackage{luacode,luaotfload,luatextra}
\usepackage[margin=18mm]{geometry}
\begin{document}
\begin{luacode}
myfonts=dofile(fonts.names.path.localdir..'/otfl-names.lua')
for i,v in ipairs(myfonts.mappings) do
tex.print('\\setmainfont{' .. v.fontname .. '}')
tex.sprint(-2, v.familyname..', '..v.fontname) --Prints everything with catcode 12.
tex.sprint('\\par')
if i > 50 then break end --Stop early for testing purposes.
end
\end{luacode}
\end{document}
Running this without the early breaking line will take rather long and some fonts might cause problems (e.g., in my case MnSymbol9.otf
caused the pdf to be corrupt and ocrb5.otf
caused fontspec
to fail).