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

?

topskip
  • 37,020

3 Answers3

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}
Ulrike Fischer
  • 327,261
  • 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 '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
  • The obvious suspects are fonts with underscores in their name so setting its catcode to e.g. 12 should help. – Ulrike Fischer Mar 25 '11 at 08: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 '11 at 13:22
  • thanks for your answer. I hoped that there is an extra query tool. I'll ponder about this...... – topskip Mar 30 '11 at 13:24
  • In TeX Live 2013, I can't find a file otfl-names.lua, in Windows or Linux. The luatex-cache folder contains context, and nothing else. Maybe that file only exists for LuaLaTeX? – LarsH Nov 04 '13 at 16:32
  • 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.) – Ulrike Fischer Nov 04 '13 at 16:40
  • @UlrikeFischer: Thanks, but I don't see that file either, neither on Windows nor on Linux. – LarsH Nov 04 '13 at 16:45
  • @LarsH: Did you actually run once luaotfload-tool -u (e.g. by compiling a document which needs the database)? – Ulrike Fischer Nov 04 '13 at 16:52
  • @UlrikeFischer: I compiled a ConTeXt LuaTeX document that attempts to access fonts (using the Simplefonts module). Does that qualify? Can I just run luaotfload-tool -u by hand? I tried, but can't find such a file... – LarsH Nov 04 '13 at 16:56
  • @LarsH That's not a file but a script/a executable and you can simply run it on the command line. And it is part of the luaotfload package so it is latex specific and you need a latex document which uses fontspec to trigger the tool. The context cache file for font infos is (imho) the file called names.tma. – Ulrike Fischer Nov 04 '13 at 17:14
  • @UlrikeFischer: Thanks for your response. Running luaotfload-tool on the command line gives me "command not found". I guess that's because I only have the ConTeXt scheme installed, not LaTeX. I just looked for names.tma, and found one under ~/.texlive2013. Will let you know how that goes! – LarsH Nov 04 '13 at 18:36
  • @UlrikeFischer: did you tried the myfonts=dofile(fonts.names.path.path) for TL13/14? –  Jun 04 '14 at 16:53
  • @Herbert: I must have tried it when I added the comment. But inbetween luaotfload has again changed (one really needs an official interface). I will add an edit to my answer. – Ulrike Fischer Jun 04 '14 at 17:41
  • 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 05 '14 at 21:17
  • I get the same error as @Mico, is there a workaround for this? – Emmet May 18 '15 at 07:17
  • It seems to be bugged for TeXLive2015 as well (same error than @mico). – b4stien Jun 22 '15 at 11:41
  • 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 04 '17 at 19:38
  • When I run this with TeXLive 2019 on my system (Devuan 3.0), I get: String contains an invalid utf-8 sequence. l.17553 apiphon�ttique. Is there some way to make lualatex ignore/skip this invalid sequence? Or parse what is probably an é? – einpoklum Jun 22 '21 at 18:13
  • With MiKTeX 22.8.28 and latest versions of all packages, I get ```("C:/Program Files/MiKTeX/tex/latex/base/ts1cmr.fd")cannot open C:/Users/me/AppData/Local/MiKTeX/luatex-cache/generic/names/luaotfload-names.luc: No such file or directory stack traceback: [C]: in function 'dofile' [\directlua]:1: in main chunk. \luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }

    l.24 \end{luacode}

    ?```

    – მამუკა ჯიბლაძე Sep 01 '22 at 17:21
  • @მამუკაჯიბლაძე use luafindfont as suggested in another answer. – Ulrike Fischer Sep 01 '22 at 17:36
  • This gives me Looking for font "*" ...pData\Roaming\MiKTeX\scripts/luafindfont\luafindfont.lua:180: attempt to concatenate a nil value (field '?') – მამუკა ჯიბლაძე Sep 01 '22 at 17:44
  • 1
    Actually I now managed to successfully run the script from your answer! I found a file named luaotfload-names.luc.gz and when I gunzipped it the script worked successfully. – მამუკა ჯიბლაძე Sep 01 '22 at 17:47
  • @მამუკაჯიბლაძე locate luaotfload-names.luc says luaotfload-names.luc.gz isn't unzipped with TL 2023 but it is with TL 2019 and 2021, and I actually don't see what command I did run to make the latter unzipped (I certainly didn't do that manually). – Denis Bitouzé Jun 20 '23 at 12:46
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.

Kurt Pfeifle
  • 3,791
topskip
  • 37,020
  • 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 04 '13 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"

user187802
  • 16,850