I want to print font names (full name, ps name, file name, etc) using LuaTeX's font table. It works fine previously, but recently I encountered an error message from luaotfload

Here is a minimal working example,

% \setmainfont{Minion Pro}

  local str = font.fonts[font.current()].fullname
  tex.sprint(-2, str)

This example, when compiled with LuaTeX works fine. The output PDF has the string LMRoman10-Regular, which is the default font. However, if I do not comment out the setmainfont line, that is, I load the Minion Pro font, then I got the following error message,

error: ...3/texmf-dist/tex/luatex/luaotfload/luaotfload-merged.lua:7656: attempt to perform arithmetic on local 'factor' (a nil value)
\newpage ...k \@nobreakfalse \everypar {}\fi \par 
                                                  \vfil \penalty -\@M 

The relevant line in luaotfload-merged.lua and around is,

function injections.setkern(current,factor,rlmode,x,tfmchr)
  local dx=factor*x
  if dx~=0 then
    local bound=#kerns+1
    kerns[bound]={ rlmode,dx }
    return dx,bound
    return 0,0

When I replace the tex.sprint line with inspect, the console displays correctly Minion Pro Regular.

Does anyone has any idea what is going on here?

I am using an up-to-date TeXLive 2013 installation.


Indexing the font.fonts table can cause the data structures that have been layed out by the font loader to be overwritten. Safe access to those fonts is provided by font.getfont(). If you want to retrieve other fonts like e.g. TFM/OFM or virtual fonts, then you will have to write a wrapper like so:

local fontdata = fonts.hashes.identifiers
local my_getfont = function (id)
  local f = fontdata[id]
  if f then
    return f
  return font.fonts[id]

Where fonts.hashes.identifiers is where the fontloader keeps the font it initializes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.