26

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

?

1
  • 2
    No, there aren't, it is on the, not written, todo list, but don't hold your breath. Mar 31, 2011 at 16:25

3 Answers 3

30

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}
\usepackage{luacode,luaotfload}
\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}
\usepackage{luaotfload}
\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}
\usepackage{luaotfload}
\begin{document}
\begin{luacode}
myfonts=dofile(config.luaotfload.paths.index_path_luc)

tex.sprint(config.luaotfload.paths.index_path_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}
25
  • 1
    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, 2011 at 16:31
  • 1
    @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, 2011 at 13:22
  • 1
    @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.) Nov 4, 2013 at 16:40
  • 2
    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, 2014 at 21:17
  • 1
    This is awesome answer and last code works for MiKTeX 2.9 64-bit as well. Does anybody know how to tune it to show example text using the listed font? I have never got into lua...
    – Crowley
    Jan 4, 2017 at 19:38
15

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.

2
  • 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, 2013 at 18:58
  • OK, those folders may be specific to LuaLaTeX. See comment discussion with Ulrike.
    – LarsH
    Nov 4, 2013 at 18:59
5
 luafindfont -n "*"

lists all fonts which can be used by xelatex/ lualatex without a special path setting. -n is "no symbolic names column"

4
  • As commented to another answer, with MiKTeX 22.8.28 (under Windows 11) I get Looking for font "*" ...pData\Roaming\MiKTeX\scripts/luafindfont\luafindfont.lua:180: attempt to concatenate a nil value (field '?') Sep 1, 2022 at 17:56
  • Please run luafindfont -v times and send me the output to [email protected]
    – user187802
    Sep 1, 2022 at 18:45
  • ok, I see the problem ...
    – user187802
    Sep 2, 2022 at 6:13
  • 1
    and on CTAN is an update which will be part of MiKTeX/TeXLive in the next few days
    – user187802
    Sep 2, 2022 at 11:37

You must log in to answer this question.

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