[Tex/LaTex] Font table for OpenType/TrueType fonts

fonts

How to print a font table for an OpenType/TrueType font? Can I use the fonttable package?

A font table should have all glyphs in a font. Like the following (from The TeXBook):
enter image description here

Update:

I have created a rather complicated font table for Fira Math based on @egreg's answer. You may find it in specimen.tex. It has the following features:

  • Automatically count the glyphs in the fonts/unicode block;
  • Fallback to other fonts for the non-existing glyphs (here I use GNU Unifont);
  • Highlight for Unicode Reserved Code Points and Control Codes.

At the end of the specimen, there is a section for the non-Unicode glyphs as well.

enter image description here

Best Answer

\documentclass[11pt]{article}
\usepackage{fontspec}

\usepackage{luacode}
\usepackage{longtable,array,xcolor,listings}
\begin{luacode*} 
function print_glyphs(maxCols,maxChars) 
  local id = font.current()         -- geht Font ID
  local fnt = font.getfont(id)
  local col = 1
  local maxU4 = 15*(16^3+16^2+16+1)
  a = {}
  for k, v in pairs(fnt.characters) do
    a [#a + 1] = k
  end
  table.sort(a)
  for i, k in ipairs(a) do
    if i >= maxChars then break end
    if col == 1 then
      if k > maxU4 then
        tex.sprint(string.format("U+%06x", k))
      else
        tex.sprint(string.format("U+%04x", k))
      end
      tex.sprint("&") 
    end
    if (i) then
      tex.sprint(string.format([[\char%i]], k))
    else
     tex.sprint("~")
    end
    if col == maxCols then              -- Line finished?
      tex.sprint([[\\\cline{2-]] .. maxCols+1 .. "} ")  -- Yes
      col = 1                           -- newline
    else
      tex.sprint("&")                   -- no, Print &
      col = col + 1                     -- next column
    end
  end
end
\end{luacode*}


\begin{document}
Latin Modern

\color{black!20}

\begin{longtable}{>{\color{black!50}\ttfamily\footnotesize}r|
                  *{10}{>{\color{black}}p{1.5em}|}}
\cline{2-11}
\endhead

%\directlua{print_glyphs(10,1360)} \\ \cline{2-11}
\directlua{print_glyphs(10,65463)} \\ \cline{2-11}
\end{longtable}

\end{document}

enter image description here

Related Question