# How do I get a list of all available fonts for luaotfload?

luaotfload uses an internal database that gets updated with mkluatexfontdb. So it knows about a lot of fonts installed on my computer. How can I query this database? Something like

luatexfontdb --list-fonts-on-my-computer-that-are-in-your-database


?

-
No, there aren't, it is on the, not written, todo list, but don't hold your breath. – Khaled Hosny Mar 31 '11 at 16:25

You could open the database in your editor. It is called otfl-names.lua and should be in one of your texmf-trees in \luatex-cache\generic\names.

It is also not very difficult to make lists based on otfl-names.lua. E.g.

## Old version (Texlive 2013?)

\documentclass{article}
\begin{document}
\begin{luacode}
myfonts=dofile(fonts.names.path.localdir..'/otfl-names.lua')

for i,v in ipairs(myfonts.mappings) do
tex.print(-2, v.familyname)
tex.print(', ')
tex.print(-2, v.fontname)
tex.print('\\par')
end

\end{luacode}

\end{document}


Edit in may 2013: With a newer luaotfload (as the one in TL2013 (pretest) one should exchange the myfonts line by this one as the name of the database as changed:

 myfonts=dofile(fonts.names.path.path)


# Edit for Texlive 2014

I tried again in TL 2014 (june 2014). Now the names file is in a .luc and the access name has changed again. I also added some "if exist code" to avoid error if a table entry doesn't exist for a font:

\documentclass{article}
\usepackage{luacode}
\begin{document}
\begin{luacode}
myfonts=dofile(fonts.names.path.index.luc)

tex.sprint(fonts.names.path.index.luc)

---[[
for i,v in ipairs(myfonts.mappings) do
if v.familyname then
tex.print('\\par')
tex.print(-2, v.familyname)
end
if v.fontname then
tex.print(', ')
tex.print(-2, v.fontname)
end
tex.print('\\par')
end
--]]

\end{luacode}

\end{document}


# Edit for TeXlive 2015 / MiKTeX in july 2015

The code do get the names file has to be adapted again. Now this here seems to work.

\documentclass{article}
\usepackage{luacode}
\begin{document}
\begin{luacode}

---[[
for i,v in ipairs(myfonts.mappings) do
if v.familyname then
tex.print('\\par')
tex.print(-2, v.familyname)
end
if v.fontname then
tex.print(', ')
tex.print(-2, v.fontname)
end
tex.print('\\par')
end
--]]

\end{luacode}

\end{document}

-
I think this is the best way to generate a font list at the moment, as there seems to be no tool like fc-list doing this job yet - see this newsgroup entry. – diabonas Mar 24 '11 at 16:31
On my Windows box with MiKTex 2.9, this code triggered warnings about missing math mode delimiters, causing lualatex to insert four $ characters . Wrapping the string printed by tex.print within a verbatim block silenced that warning, although I don't spot which fonts triggered it. – RBerteig Mar 24 '11 at 22:02 @RBerteig, @Ulrike: You can use something like tex.tprint({-2, v.familyname, ', ', v.fontname},{-1, '\\par'}) to get rid of the catcodes problem. – topskip Mar 30 '11 at 13:22 @LarsH The name has changed. It is now called luaotfload-names.lua. And it is in texmf-var. (I didn't test if the code above still work. It is quite possible that the structure of the tables has changed too.) – Ulrike Fischer Nov 4 '13 at 16:40 I'm afraid your update for TeXLive2014 bombs on a system running MacTeX2014. Error message: ! LuaTeX error [\directlua]:1: attempt to index field 'path' (a nil value) stack traceback: [\directlua]:1: in main chunk, \luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }. – Mico Oct 5 '14 at 21:17 Based on Ulrike's answer: Because I don't want to create a TeX document every time I need the font list, here is a simple script for that: #!/usr/bin/env texlua kpse.set_program_name("listluatexfonts") cachefile = kpse.expand_var("$TEXMFVAR")  .. "/luatex-cache/generic/names/otfl-names.lua"
fontlist = dofile(cachefile)
assert(fontlist,"Could not load font name database")

local tmp = {}

for _,font in ipairs(fontlist.mappings) do
tmp[#tmp + 1] = font.fontname
end
table.sort(tmp)

for _,fontname in ipairs(tmp) do
print(fontname)
end


call it with

./listluatexfonts


## Update:

Replace the cachefile name for TexLive 2014:

cachefile  = kpse.expand_var("\$TEXMFVAR")  .. "/luatex-cache/generic/names/luaotfload-names.luc"


This one worked for me.

-
Can anyone tell how to do this with TeXLive 2013? There doesn't appear to be a generic directory under luatex-cache anymore... at least not in my installation. – LarsH Sep 20 '13 at 18:58
OK, those folders may be specific to LuaLaTeX. See comment discussion with Ulrike. – LarsH Nov 4 '13 at 18:59