On 4/12/2025 11:59 PM, Matthew Bertucci wrote:
Hello,
While looking into what it would take to make some LaTeX symbol packages
PDF/UA compatible, it was pointed out to me that luatex's \pdfextension
glyphtounicode does not accept the tfm:<tfmname>/ prefix for glyph names
that is documented in the pdftex manual. This prevents individual font
packages from defining their own Unicode mappings without overwriting
the glyph mappings for all fonts. Here's an example using
OrnementsADF.tfm that has U+2B98 in the "parenleft" slot that produces
the correct mapping with pdftex but the undesired parenleft mapping
(U+0028) with luatex.
\ifcsname pdfglyphtounicode\endcsname
\else
\def\pdfgentounicode{\pdfvariable gentounicode}
\def\pdfglyphtounicode {\pdfextension glyphtounicode}
\fi
\pdfgentounicode=1
\font\ADFornaments=OrnementsADF at 10pt
\pdfglyphtounicode{tfm:OrnementsADF/parenleft}{2B98}
\ADFornaments\char1
\bye
If the tfm:OrnementsADF/ prefix is removed, the mapping is correct, but
this would apply to all fonts. Is this just unsupported in luatex? If
so, would it be possible to add or emulate the functionality?
\directlua {
local n = \fontid\font
local f = font.getfont(n)
local c = f.characters[65]
if c then
local u = c.tounicode
c.tounicode = "0042"
font.addcharacters(n, { characters = { [65] = c } })
f = font.getfont(n)
c = f.characters[65]
print(u,c.tounicode)
end
}
\def\luaglyphtounicode#1#2%
{\directlua {
local n = \fontid\font
local c = font.getfont(n).characters[\number#1]
if c then
c.tounicode = "#2"
font.addcharacters(n, { characters = { [\number#1] = c } })
end
}}
% This needs to be done before the font is used!
\luaglyphtounicode{66}{0043}
AB % BC
\bye
I could make a nicer interface but as these are small fonts it is not
that important. We can actually add a simple helper function to the
engine that removes the timing restriction (kind of trivial) but we have
a while before texlive 2016 pops up.
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------