Skip to content

Instantly share code, notes, and snippets.

@hmenke
Last active July 1, 2019 05:01
Show Gist options
  • Save hmenke/3fb6d6d9d16ea0c7385bc7797c83b737 to your computer and use it in GitHub Desktop.
Save hmenke/3fb6d6d9d16ea0c7385bc7797c83b737 to your computer and use it in GitHub Desktop.
luafontid
function token.scan_limited_int(max, name)
local cur_val = token.scan_int()
if (cur_val < 0) or (cur_val > max) then
local hlp, msg
if not name then
hlp = string.format("Since I expected to read a number between 0 and %d,", max)
msg = string.format("Bad number (%d)", cur_val)
else
hlp = string.format("A %s must be between 0 and %d.", name, max)
msg = string.format("Bad %s (%d)", name, cur_val)
end
tex.error(msg, { hlp, "I changed this one to zero." })
cur_val = 0
end
return cur_val
end
function token.scan_math_family_int()
return token.scan_limited_int(255, "math family")
end
function token.scan_font_ident()
local cur_cmd, cur_chr, f
repeat
local next = token.scan_token()
cur_cmd = next.cmdname
cur_chr = next.mode
until not (cur_cmd == "spacer")
if cur_cmd == "def_font" or cur_cmd == "letterspace_font" or cur_cmd == "copy_font" then
f = font.current()
elseif cur_cmd == "set_font" then
f = cur_chr
-- set_font_touched(f, 1)
elseif cur_cmd == "def_family" then
local m = cur_chr
local cur_val = token.scan_math_family_int()
f = node.family_font(cur_val, m)
-- set_font_touched(f, 1)
else
tex.error("Missing font identifier", {
"I was looking for a control sequence whose",
"current meaning has been defined by \\font."
})
f = 0 -- is 0 always nullfont?
end
return f
end
\directlua{dofile("test.lua")}
\directlua{
local t = lua.get_functions_table()
t[\string#t + 1] = function() tex.sprint(token.scan_font_ident()) end
token.set_lua("luafontid", \string#t)
}
\message{\luafontid\font}
\message{\fontid\font}
\message{\luafontid\nullfont}
\message{\fontid\nullfont}
\message{\luafontid\tenit}
\message{\fontid\tenit}
\message{\luafontid\textfont2}
\message{\fontid\textfont2}
\bye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment