这是在 LuaTeX 中访问特定字符和如何访问 fleurons?
使用 TeX Live 2012,我编译了以下文件并得到了图像中的输出:
\documentclass[12pt]{book}
\usepackage{fontspec}
\setmainfont[Numbers=OldStyle]{Garamond Premiere Pro Regular}
\def\fontchar#1{\directlua{fonts.otf.char("#1")}}
\begin{document}
\begin{center}
\begin{tabular}{lc}
bullet.01 & \fontchar{bullet.01}\\
bullet.02 & \fontchar{bullet.02}\\
bullet.03 & \fontchar{bullet.03}\\
bullet.04 & \fontchar{bullet.04}\\
bullet.05 & \fontchar{bullet.05}\\
bullet.06 & \fontchar{bullet.06}\\
bullet.07 & \fontchar{bullet.07}\\
bullet.08 & \fontchar{bullet.08}\\
bullet.09 & \fontchar{bullet.09}\\
bullet.10 & \fontchar{bullet.10}\\
bullet.11 & \fontchar{bullet.11}\\
bullet.12 & \fontchar{bullet.12}\\
bullet.13 & \fontchar{bullet.13}\\
bullet.14 & \fontchar{bullet.14}
\end{tabular}
\end{center}
\end{document}
使用 TeX Live 2013 编译同一个文件会产生以下错误消息:
ERROR: LuaTeX error [string "\directlua "]:1: attempt to index field 'otf' (a nil val
--- TeX said ---
ue)
stack traceback:
[string "\directlua "]:1: in main chunk.
\fontchar #1^^@-\directlua {fonts.otf.char("#1")}
l.14 bullet.01 & \fontchar{bullet.01}
\\
--- HELP ---
From the .log file...
The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.
我也尝试过这种方法:
\documentclass[12pt]{book}
\usepackage{fontspec}
\setmainfont[Numbers=OldStyle]{Garamond Premiere Pro Regular}
\begin{document}
\begin{center}
\begin{tabular}{lc}
bullet.01 & \symbol{\string"051A}\\
bullet.02 & \symbol{\string"051B}\\
bullet.03 & \symbol{\string"051C}\\
bullet.04 & \symbol{\string"051D}\\
bullet.05 & \symbol{\string"051E}\\
bullet.06 & \symbol{\string"051F}\\
bullet.07 & \symbol{\string"0520}\\
bullet.08 & \symbol{\string"0521}\\
bullet.09 & \symbol{\string"0522}\\
bullet.10 & \symbol{\string"0523}\\
bullet.11 & \symbol{\string"0524}\\
bullet.12 & \symbol{\string"0525}\\
bullet.13 & \symbol{\string"0526}\\
bullet.14 & \symbol{\string"0527}
\end{tabular}
\end{center}
\end{document}
这并没有产生任何错误或警告,但 PDF 输出中没有出现任何装饰物。
鉴于 TeX Live 2013 中的变化,我应该如何调整我的源代码?
答案1
功能fonts.otf.char()
消失了
很久以前
并被不属于字体加载器分发版的 Context 特定实现所取代。不过,Luaotfload 添加了一组辅助代码,允许重新创建其功能:
\documentclass{scrartcl}
\usepackage{luaotfload,luacode}
\begin{luacode}
documentdata = documentdata or { }
local stringformat = string.format
local texsprint = tex.sprint
local slot_of_name = luaotfload.aux.slot_of_name
documentdata.fontchar = function (chr)
local chr = slot_of_name(font.current(), chr, false)
if chr and type(chr) == "number" then
texsprint
(stringformat ([[\char"%X]], chr))
end
end
\end{luacode}
\def\fontchar#1{\directlua{documentdata.fontchar "#1"}}
\font\mainfont="file:GaramondPremrPro.otf" at 20pt
\begin{document}
\def\bulletrow#1{bullet.#1&\fontchar{bullet.#1}\\}
\mainfont
\begin{tabular}{lc}
\bulletrow{01}
\bulletrow{02}
\bulletrow{03}
\bulletrow{04}
\bulletrow{05}
\bulletrow{06}
\bulletrow{07}
\bulletrow{08}
\bulletrow{09}
\bulletrow{10}
\bulletrow{11}
\bulletrow{12}
\bulletrow{13}
\bulletrow{14}
\end{tabular}
\end{document}
% vim:ft=tex:sw=2:ts=2:expandtab
结果: