Debian Codegraph @

texmf-dist/source/latex/fixtounicode/fixtounicode.dtx

raw
1 % \iffalse meta-comment
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % fixtounicode.dtx
4 % Additions and changes Copyright (C) 2025-2026 Clea F. Rees.
5 % Code from skeleton.dtx Copyright (C) 2015-2024 Scott Pakin (see below).
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3c
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % https://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2008-05-04 or later.
14 %
15 % This work has the LPPL maintenance status 'muaintained'.
16 %
17 % The Current Maintainer of this work is Clea F. Rees.
18 %
19 % This work consists of all files listed in manifest.txt.
20 %
21 % The file fixtounicode.dtx is a derived work under the terms of the
22 % LPPL. It is based on version 2.4 of skeleton.dtx which is part of
23 % dtxtut by Scott Pakin. A copy of dtxtut, including the
24 % unmodified version of skeleton.dtx is available from
25 % https://www.ctan.org/pkg/dtxtut and released under the LPPL.
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 % \fi
28 %
29 % \iffalse
30 %<*driver>
31 \RequirePackage{svn-prov}
32 % ref. ateb Max Chernoff: https://tex.stackexchange.com/a/723294/
33 \def\MyMakePrivateLetters{\makeatletter\ExplSyntaxOn\endlinechar13}
34 \ExplSyntaxOff
35 \ProvidesFileSVN{$Id: fixtounicode.dtx 11683 2026-02-24 03:57:46Z cfrees $}[v0.1.1 \revinfo][\filename: \filebase]
36 \DefineFileInfoSVN[fixtounicodedoc]
37 \documentclass[10pt,british]{ltxdoc}
38 % l3doc loads fancyvrb
39 % fancyvrb overwrites svn-prov's macros without warning
40 % restore \fileversion \filerev in case we're using l3doc
41 \GetFileInfoSVN{fixtounicodedoc}
42 \usepackage{fixtounicode}
43 \EnableCrossrefs
44 \CodelineIndex
45 \RecordChanges
46 % \OnlyDescription
47 \DoNotIndex{\verb,\ProvidesPackageSVN,\NeedsTeXFormat,\ProcessKeyOptions}
48 \usepackage{babel}
49 \usepackage{fancyhdr}
50 \usepackage[tt={monowidth,tabular,lining}]{cfr-lm}
51 \usepackage[plain]{fancyref}
52 \usepackage{enumitem}
53 \usepackage{booktabs}
54 \usepackage{xcolor}
55 \usepackage{xurl}
56 \urlstyle{sf}
57 \usepackage{microtype}
58 \usepackage[a4paper,headheight=14pt,marginparwidth=45mm,hmarginratio=4:1,vscale=.8,hscale=.7,verbose]{geometry} % use 14pt for 11pt text, 15pt for 12pt text
59 % addaswyd o fixtounicode.tex
60 \newlength\tewadjust
61 \newlength\fixtounicodedocoffset
62 \AddToHook {begindocument/end}[.]
63 {%
64 \setlength\tewadjust{\dimexpr\marginparwidth+\marginparsep-\paperwidth+\textwidth+\oddsidemargin+1in\relax}%
65 \setlength\fixtounicodedocoffset{\dimexpr\marginparwidth+\marginparsep\relax}%
66 \newgeometry{hscale=0.8}%
67 \savegeometry{safonol}%
68 \restoregeometry
69 \pagestyle{fancymarg}%
70 }
71 \usepackage{csquotes}
72 \MakeAutoQuote{โ€˜}{โ€™}
73 \MakeAutoQuote*{โ€œ}{โ€}
74 % sicrhau hyperindex=false: llwytho CYN bookmark
75 \usepackage{hypdoc}% ateb Ulrike Fischer: https://tex.stackexchange.com/a/695555/
76 \usepackage{bookmark}
77 \hypersetup{%
78 colorlinks=true,
79 citecolor={moss},
80 extension=pdf,
81 linkcolor={strawberry},
82 linktocpage=true,
83 pdfcreator={TeX},
84 pdfproducer={pdfeTeX},
85 urlcolor={blueberry}%
86 }
87 \NewDocElement[%
88 idxtype=key,
89 idxgroup=l3keys,
90 printtype=\textit{key},
91 ]{Key}{key}
92 \NewDocElement[%
93 macrolike=true,
94 idxtype=fn.,
95 idxgroup=expl3 functions,
96 printtype=\textit{fn.},
97 ]{Fn}{fn}
98 \NewDocElement[%
99 idxtype=opt.,
100 idxgroup=options,
101 printtype=\textit{opt.},
102 ]{Opt}{option}
103 \NewDocElement[%
104 idxtype=pkg.,
105 idxgroup=packages,
106 printtype=\textit{pkg.},
107 ]{Pkg}{package}
108 \NewDocElement[%
109 macrolike=true,
110 idxtype=var.,
111 idxgroup=expl3 variable,
112 printtype=\textit{var.},
113 ]{Var}{var}
114 % ^^A \NewDocElement[%
115 % ^^A printtype=\textdagger,
116 % ^^A idxtype=,
117 % ^^A idxgroup=,
118 % ^^A macrolike,
119 % ^^A ]{DMacro}{dmacro}
120 \NewDocumentCommand \val { m }
121 {%
122 {\ttfamily =\,\meta{#1}}%
123 }
124 \ExplSyntaxOn
125 \NewDocumentCommand \vals { m }
126 {
127 {
128 \ttfamily = \,
129 \clist_use:nn { #1 } { \textbar }
130 }
131 }
132 \keys_define:nn { fixtounicode / doc }
133 {
134 unknown .code:n = {
135 \cs_if_free:cT { \l_keys_key_str }
136 {
137 \tl_gset:cn { \l_keys_key_str } { #1 }
138 }
139 },
140 }
141 \NewDocumentCommand \fixtounicodedocset { +m }
142 {
143 \keys_set:nn { fixtounicode / doc } { #1 }
144 }
145 \ExplSyntaxOff
146 \fixtounicodedocset{%
147 bug={\href{https://codeberg.org/cfr/nfssext/issues}{\textsc{bugtracker}}},
148 codeberg={\href{https://codeberg.org/cfr/nfssext}{\textsc{codeberg}}},
149 github={\href{https://github.com/cfr42/nfssext}{\textsc{github}}},
150 ctan={\href{https://ctan.org/}{\textsc{ctan}}},
151 }
152 \newcommand*{\lpack}[1]{\textsf{#1}}
153 \newcommand*{\fgroup}[1]{\textsf{#1}}
154 \newcommand*{\fname}[1]{\textsf{#1}}
155 \newcommand*{\file}[1]{\texttt{#1}}
156 \title{\filebase}
157 \author{Clea F. Rees\thanks{%
158 Bug tracker:
159 \href{https://codeberg.org/cfr/nfssext/issues}{\url{codeberg.org/cfr/nfssext/issues}}
160 \textbar{} Code:
161 \href{https://codeberg.org/cfr/nfssext}{\url{codeberg.org/cfr/nfssext}}
162 \textbar{} Mirror:
163 \href{https://github.com/cfr42/nfssext}{\url{github.com/cfr42/nfssext}}%
164 }}
165 \date{\fileversion~\filedate}
166 \newcommand*\twmarg{%
167 \restoregeometry
168 \pagestyle{fancymarg}%
169 }
170 \newcommand*\twreg{%
171 \loadgeometry{safonol}%
172 \pagestyle{fancyreg}%
173 }
174 \pagestyle{fancy}
175 \fancyhf{}%
176 % ^^A \fancyhf[rh]{\itshape\filetoday}
177 % ^^A \fancyhf[ch]{\itshape Support for Latin Modern}
178 % ^^A\fancyhf[lf]{\itshape\fileversion}
179 \fancypagestyle{fancymarg}{%
180 \pagestyle{fancyreg}%
181 \fancyheadoffset[LO,RE]{\fixtounicodedocoffset}%
182 }
183 \fancypagestyle{fancyreg}{%
184 \fancyhf{}%
185 \fancyhf[lh]{\itshape\filebase}%
186 \fancyhf[rh]{\itshape\fileversion}%
187 \fancyhf[cf]{\itshape--- \thepage~/~\lastpage{} ---}%
188 \fancyheadoffset{0pt}%
189 }
190
191 \ExplSyntaxOn
192 \hook_gput_code:nnn {shipout/lastpage} {.}
193 {
194 \property_record:nn {t:lastpage}{abspage,page,pagenum}
195 }
196 \cs_new_protected_nopar:Npn \lastpage
197 {
198 \property_ref:nn {t:lastpage}{page}
199 }
200 \cs_new_eq:NN \OrigMakePrivateLetters \MakePrivateLetters
201 \ExplSyntaxOff
202 \setcounter{IndexColumns}{2}
203 \definecolor{strawberry}{rgb}{1.000,0.000,0.502}
204 \definecolor{blueberry}{rgb}{0.000,0.000,1.000}
205 \definecolor{moss}{rgb}{0.000,0.502,0.251}
206 \begin{document}
207 \let\MakePrivateLetters\MyMakePrivateLetters
208 \DocInput{\filename}
209 \end{document}
210 %</driver>
211 % \fi
212 %
213 % \changes{v0.1.1}{2026-02-24}{First public release.}
214 %
215 % \maketitle\thispagestyle{empty}
216 % \pdfinfo{%
217 % /Creator (TeX)
218 % /Producer (pdfTeX)
219 % /Author (Clea F. Rees)
220 % /Title (fixtounicode)
221 % /Subject (TeX)
222 % /Keywords (TeX,LaTeX,Clea,Rees)}
223 % \setlength{\parindent}{0pt}
224 % \setlength{\parskip}{0.5em}
225 %
226 %
227 % \begin{abstract}
228 % \noindent\lpack{fixtounicode} provides interfaces for adding โ€˜tounicodeโ€™ mappings to type1 and/or \TeX{} fonts which lack them.
229 % \lpack{expl3} and \LaTeXe{} interfaces are provided, the former being designed primarily to support type1 symbol packages.
230 % \end{abstract}
231 %
232 % \tableofcontents
233 %
234 % \section{Usage}\label{sec:usage}
235 %
236 % \DescribePkg{fixtounicode}\cs{usepackage}\oarg{package options}\marg{fixtounicode}
237 %
238 % loads the package with \meta{package options}.
239 %
240 % Available options:
241 %
242 % \DescribeOpt{debug}\vals{true,false}
243 %
244 % Load debugging code, which generates more verbose console and log messages.
245 %
246 % \DescribeOpt{dingbats}\vals{true,false}
247 %
248 % Enable support for Zapf Dingbats if compiling with lua\TeX{}.
249 % This option is not really specific to Dingbats, but that is probably the best known case.
250 % Enabling this option when compiling with lua\TeX{} 1.24 or later will load the Unicode code points known to pdf\TeX{} (unless \textsc{dvi} output is enabled).
251 %
252 % The option does nother if a different or older engine is used.
253 % For pdf\TeX, it is unnecessary; the mappings are enabled by default.
254 % For other engines and older lua\TeX, the mappings would either be silently ignored (lua\TeX) or raise errors (e.g.~luaTeX in \textsc{dvi} mode).
255 %
256 %
257 % \DescribeMacro{\fixtounicode}\marg{comma-separated list of key-values}
258 %
259 % Add \texttt{tounicode} mappings for \TeX{}/type1 fonts which lack them.
260 %
261 % Supported keys:
262 % \begin{description}[font=\ttfamily]
263 % \item[default] Default code point.
264 % \item[glyphs] Comma-separated list of glyph names.
265 % For use with \texttt{unicodes}.
266 % \item[mappings] Key-value list of glyph to Unicode mappings.
267 % pdf\TeX{} and Lua\TeX{} 1.24 and later.
268 % Probably unsuitable for package code.
269 % \item[pfb] Type1 font.
270 % \item[tfm] TFM.
271 % \item[unicodes] Comma-separated list of code points.
272 % For use with \texttt{glyphs}.
273 % \end{description}
274 %
275 % For example, the following adds mappings for three of \pkg{marvosym}'s symbols.
276 % \typeout{Clangers}
277 % \iffalse
278 %<*verb>
279 % \fi
280 % ^^A Indentation of code is **required** here, but don't ask me why ...
281 % \begin{verbatim}
282 \usepackage{fixtounicode}
283 \fixtounicode{%
284 tfm = umvs,
285 mappings = {%
286 Coffeecup = 26BD,
287 Radioactivity = 2615,
288 Football = 2622,
289 },
290 }
291 \usepackage{marvosym}
292 % \end{verbatim}
293 % \iffalse
294 %</verb>
295 % \fi
296 % \typeout{Bagpuss}
297 %
298 % When the corresponding symbols are used in the document,
299 % \iffalse
300 %<*verb>
301 % \fi
302 % \begin{verbatim}
303 \Coffeecup\quad
304 \Radioactivity\quad
305 \Football
306 % \end{verbatim}
307 % \iffalse
308 %</verb>
309 % \fi
310 % the result is a \textsc{pdf} with the specified Unicode code points.
311 % This means that copy-paste works correctly, provided the viewing application supports Unicode, screen-reading software has the relevant semantic data and conversions to text etc.\ work as expected.
312 %
313 % Packages which need to define sets of mappings should use either \texttt{glyphs} and \texttt{unicodes} or the \pkg{expl3} functions in \fref{sec:pi}.
314 % \texttt{mappings} is intended for specific corrections or additions at the document level.
315 %
316 % \section{Programming interface}\label{sec:pi}
317 %
318 % \DescribeMacro{\fixtounicode_tounicode:nnNN} \marg{\textsc{tfm}}\marg{\textsc{pfb}}\meta{sequence 1}\meta{sequence 2}\par
319 % \DescribeMacro{\fixtounicode_tounicode:nNN} \marg{font name}\meta{sequence 1}\meta{sequence 2}
320 %
321 % where \meta{\textsc{tfm}} and \meta{\textsc{pfb}} are the names of the \textsc{tfm} and \textsc{pfb} without extensions, \meta{sequence 1} is the name of a sequence variable containing glyph names and \meta{sequence 2} is the name of a sequence variable containing the corresponding Unicode code points.
322 % \verb|\fixtounicode_tounicode:nNN| is a convenience wrapper for the common case in which \meta{\textsc{tfm}} and \meta{\textsc{pfb}} are the same.
323 % In that case \meta{font name} is their common name, without extension.
324 %
325 % \DescribeMacro{\fixtounicode_tounicode:nnnn} \marg{\textsc{tfm}}\marg{\textsc{pfb}}\marg{sequence 1}\marg{sequence 2}\par
326 % \DescribeMacro{\fixtounicode_tounicode:nnn} \marg{font name}\marg{sequence 1}\marg{sequence 2}
327 %
328 % Wrappers around \verb|\fixtounicode_tounicode:nnNN| and \verb|\fixtounicode_tounicode:nNN| which accept is comma-separated lists of glyph names and code points in place of variables.
329 % These versions simply set sequence variables from the comma-separated lists and pass their names to the underlying functions.
330 %
331 % \MaybeStop{%
332 % \renewcommand*\glossaryname{Changes}%
333 % \PrintChanges
334 % \PrintIndex
335 % }
336 %
337 % \section{Implementation}\label{sec:imp}
338 %
339 % You do not need to read the remainder of this document in order to install or use the package.
340 %
341 %<*sty>
342 %<@@=fixtounicode>
343 % \begin{macrocode}
344 \GetIdInfo $Id: fixtounicode.dtx 11683 2026-02-24 03:57:46Z cfrees $
345 {Fix missing tounicode values in TeX fonts}
346 \ProvidesExplPackage{\ExplFileName}
347 {\ExplFileDate}{v0.1.1 \ExplFileVersion}{\ExplFileDescription}
348 % \end{macrocode}
349 % \iffalse
350 % ^^A Paid รข defnyddio \GetFileInfoSVN*/\GetFileInfoSVN{} yn y fan hon!!
351 % \fi
352 % \begin{key}{debug,dingbats}
353 % Keys.
354 % \begin{macrocode}
355 \keys_define:nn { fixtounicode }
356 {
357 debug .bool_set:N = \l_@@_debug_bool,
358 debug .initial:n = false,
359 debug .default:n = true,
360 dingbats .bool_set:N = \l_@@_dingbats_bool,
361 dingbats .default:n = true,
362 dingbats .initial:n = false,
363 }
364 % \end{macrocode}
365 % \end{key}
366 % \begin{macrocode}
367 \ProcessKeyOptions[fixtounicode]
368 % \end{macrocode}
369 % \begin{var}{\l_@@_glyphtounicode_seq,\l_@@_tounicode_seq,\l_@@_glyphs_seq,\l_@@_unicode_seq,\l_@@_engine_seq,\l_@@_luatex_has_fix_bool}
370 % Variables.
371 % \begin{macrocode}
372 \seq_new:N \l_@@_glyphtounicode_seq
373 \seq_new:N \l_@@_tounicode_seq
374 \seq_new:N \l_@@_glyphs_seq
375 \seq_new:N \l_@@_unicodes_seq
376 \seq_new:N \g_@@_engine_seq
377 \bool_new:N \g_@@_luatex_has_fix_bool
378 % \end{macrocode}
379 % \end{var}
380 % Format variant.
381 % \begin{macrocode}
382 \cs_generate_variant:Nn \seq_set_item:Nnn { NnV }
383 % \end{macrocode}
384 % \begin{fn}{\@@_debug:n,\@@_debug:N}
385 % \kern0pt
386 % \begin{macrocode}
387 \bool_if:NTF \l_@@_debug_bool
388 {
389 \cs_new_protected:Npn \@@_debug:n #1
390 {
391 \iow_term:n {
392 [fixtounicode~debug]::~#1
393 }
394 }
395 \cs_new_protected:Npn \@@_debug:N #1
396 {
397 \@@_debug_aux:eV { \cs_to_str:N #1 } #1
398 }
399 \cs_new_protected:Npn \@@_debug_aux:nn #1#2
400 {
401 \@@_debug:n { #1~->~#2 }
402 }
403 \cs_generate_variant:Nn \@@_debug_aux:nn {eV}
404 \sys_if_engine_luatex:T
405 {
406 \lua_now:n { fixtounicode_debug = true }
407 }
408 }{
409 \cs_new_eq:NN \@@_debug:n \use_none:n
410 \cs_new_eq:NN \@@_debug:N \use_none:n
411 }
412 % \end{macrocode}
413 % \end{fn}
414 % If the Lua\TeX{} version is less than 1.24, set \texttt{dev} to \texttt{false}; o/w \texttt{true}.
415 % \begin{macrocode}
416 \sys_if_engine_luatex:T
417 {
418 \@@_debug:n {Engine~is~LuaTeX.}
419 \bool_set_true:N \l_@@_luatex_has_fix_bool
420 \seq_gset_split:NnV \g_@@_engine_seq {.} \c_sys_engine_version_str
421 \int_compare:nNnTF { \seq_item:Nn \g_@@_engine_seq {1} } < {1}
422 {
423 \@@_debug:n {
424 LuaTeX~version~0~or~less:
425 ~you~get~out~too~much.
426 ~Stay~home~and~update!
427 }
428 \bool_set_false:N \l_@@_luatex_has_fix_bool
429 } {
430 \int_compare:nNnT { \seq_item:Nn \g_@@_engine_seq {2} } < {24}
431 {
432 \@@_debug:n {
433 LuaTeX~minor~version~less~than~24.
434 ~I'll~do~my~best,~but~binary~too~old~for~full~support.
435 }
436 \bool_set_false:N \l_@@_luatex_has_fix_bool
437 }
438 }
439 \@@_debug:N \l_@@_luatex_has_fix_bool
440 }
441 % \end{macrocode}
442 % This is not good at all \dots.
443 % \begin{macrocode}
444 \sys_ensure_backend:
445 % \end{macrocode}
446 % \begin{macro}{\pdfglyphtounicode}
447 % Lua\TeX{} only, from the manual.
448 % \begin{macrocode}
449 \bool_lazy_and:nnT
450 { \sys_if_engine_luatex_p: }
451 { \sys_if_output_pdf_p: }
452 {
453 \protected\def\pdfglyphtounicode {\pdfextension glyphtounicode }
454 \lua_now:n { pdf.setgentounicode(1) }
455 \bool_if:NT \l_@@_luatex_has_fix_bool { \input glyphtounicode.tex\relax }
456 \bool_if:NT \l_@@_dingbats_bool
457 {
458 \input glyphtounicode.tex \relax
459 }
460 }
461 % \end{macrocode}
462 % \end{macro}
463 % \begin{macrocode}
464 \msg_new:nnn { fixtounicode } { mapping }
465 {
466 \msg_info_text:n { fixtounicode } :: ~
467 Mapping~#1~->~#2~\msg_line_context:
468 }
469 \msg_new:nnn { fixtounicode } { limitations }
470 {
471 \msg_warning_text:n { fixtounicode } :: ~
472 Sorry,~use~of~#1~is~not~supported~on~#2~\msg_line_context:. ~
473 #3
474 }
475 \msg_new:nnn { fixtounicode } { file-awol }
476 {
477 \msg_error_text:n { fixtounicode } :: ~
478 #1~not~found~on~\msg_line_context:
479 }
480 % \end{macrocode}
481 % \begin{fn}{\@@_tounicode:nnNN,
482 % \@@_tounicode:nNN,
483 % \@@_tounicode_pair:nn,
484 % \@@_tounicode:VVNN
485 % }
486 % Engine-specific functions for mappings.
487 % If we're using pdf\TeX{}, things are straightforward: we simply use the \texttt{tfm:} syntax for the primitive \cs{pdfglyphtounicode}.
488 % If we're using Lua\TeX{}, things are complicated.
489 % For newer releases (2026), the macro \cs{pdfglyphtounicode} defined above will accept \texttt{tfm:}.
490 % Otherwise, we could apply values directly to the \texttt{tfm}, but that will only work for the newer releases (which don't need it), so we apply them to the type1 \texttt{pfb} for now, using a workaround from Max Chernoff.
491 % \begin{macrocode}
492 \cs_new_protected_nopar:Npn \@@_tounicode_pair:nn #1#2 {}
493 \bool_if:nT
494 {
495 \bool_lazy_and_p:nn
496 {
497 \bool_lazy_or_p:nn {\sys_if_engine_pdftex_p:}
498 {
499 \bool_lazy_and_p:nn
500 {\sys_if_engine_luatex_p:}
501 {\l_@@_luatex_has_fix_bool}
502 }
503 } {\sys_if_output_pdf_p:}
504 } {
505 \@@_debug:n {
506 TFM~specific~tounicode~mappings~supported.
507 ~Enabling~support~for~glyph~names.
508 }
509 \cs_new_protected_nopar:Npn \@@_tounicode:nNN #1#2#3
510 {
511 \cs_set_nopar:Npn \@@_tounicode_pair:nn ##1##2
512 {
513 % \end{macrocode}
514 % TFM-specific mapping.
515 %
516 % pdf\TeX{} manual page 33.
517 % \begin{macrocode}
518 \pdfglyphtounicode { tfm:#1/##1 } { ##2 }
519 \msg_info:nnnn {fixtounicode} {mapping} {tfm:#1/##1} {##2}
520 }
521 \seq_set_eq:NN \l_@@_glyphtounicode_seq #2
522 \seq_set_eq:NN \l_@@_tounicode_seq #3
523 \seq_map_pairwise_function:NNN \l_@@_glyphtounicode_seq
524 \l_@@_tounicode_seq \@@_tounicode_pair:nn
525 }
526 \cs_new_protected_nopar:Npn \@@_tounicode:nnNN #1#2#3#4
527 {
528 \@@_tounicode:nNN { #1 } #3 #4
529 }
530 }
531 % \end{macrocode}
532 % For Lua\TeX{} without the \texttt{dev} option, we use the workaround mentioned above.
533 % This deals with a limitation in the engine (lack of support for the \texttt{tfm:} syntax in \cs{pdfextension tounicode}) and a bug (failure to recognise any \texttt{tounicode} mappings specified for \texttt{tfm}s).
534 % \begin{macrocode}
535 \bool_lazy_all:nT
536 {
537 {\sys_if_engine_luatex_p:}
538 {! \l_@@_luatex_has_fix_bool}
539 {\sys_if_output_pdf_p:}
540 } {
541 \@@_debug:n {
542 TFM~specific~tounicode~mappings~unsupported:~LuaHBTeX~too~old.~
543 Enabling~workaround.~
544 Note~glyph~names~unsupported.~
545 Support~requires~indices.
546 }
547 \lua_load_module:n { fixtounicode }
548 \cs_set_nopar:Npn \@@_tounicode_pair:nn #1#2
549 {
550 \lua_now:n {
551 table.insert(fixtounicodeTab,tonumber("#2",16))
552 }
553 }
554 \cs_new_protected_nopar:Npn \@@_tounicode:nnNN #1#2#3#4
555 {
556 \@@_debug:n {
557 Trying~to~add~tounicode~mappings~for~old~LuaTeX.~
558 Fingers~crossed!
559 }
560 \@@_debug:n {TFM:~#1;~PFB:~#2;}
561 \@@_debug:N #3
562 \@@_debug:N #4
563 \lua_now:n { fixtounicodeTab = {} }
564 \seq_set_eq:NN \l_@@_glyphtounicode_seq #3
565 \seq_set_eq:NN \l_@@_tounicode_seq #4
566 \seq_map_pairwise_function:NNN \l_@@_glyphtounicode_seq
567 \l_@@_tounicode_seq \@@_tounicode_pair:nn
568 \lua_now:e {
569 fixtounicode.tounicodes("#1","#2",fixtounicodeTab)
570 }
571 }
572 \cs_new_protected_nopar:Npn \@@_tounicode:nNN #1#2#3
573 {
574 \@@_tounicode:nnNN { #1 } { #1 } #2 #3
575 }
576 }
577 % \end{macrocode}
578 % On all other engines, the functions are noop.
579 % \begin{macrocode}
580 \sys_if_output_dvi:T
581 {
582 \@@_debug:n {
583 tounicode~mappings~unsupported~for~DVI.~
584 Installing~noop~functions.~
585 }
586 \cs_new_eq:NN \@@_tounicode:nnNN \use_none:nnnn
587 \cs_new_eq:NN \@@_tounicode:nNN \use_none:nnn
588 }
589 \cs_generate_variant:Nn \@@_tounicode:nnNN { VVNN }
590 % \end{macrocode}
591 % \end{fn}
592 % \begin{fn}{\fixtounicode_tounicode:nnNN,
593 % \fixtounicode_tounicode:nNN,
594 % \fixtounicode_tounicode:nnnn,
595 % \fixtounicode_tounicode:nnn
596 % }
597 % Public expl3.
598 % \begin{macrocode}
599 \cs_new_eq:NN \fixtounicode_tounicode:nnNN \@@_tounicode:nnNN
600 \cs_new_eq:NN \fixtounicode_tounicode:nNN \@@_tounicode:nNN
601 \cs_new_protected_nopar:Npn \fixtounicode_tounicode:nnnn #1#2#3#4
602 {
603 \seq_set_split:Nnn \l_@@_glyphs_seq { , } { #3 }
604 \seq_set_split:Nnn \l_@@_unicodes_seq { , } { #4 }
605 \@@_tounicode:nnNN { #1 } { #2 }
606 \l_@@_glyphs_seq \l_@@_unicodes_seq
607 }
608 \cs_new_protected_nopar:Npn \fixtounicode_tounicode:nnn #1#2#3
609 {
610 \seq_set_split:Nnn \l_@@_glyphs_seq { , } { #2 }
611 \seq_set_split:Nnn \l_@@_unicodes_seq { , } { #3 }
612 \@@_tounicode:nnNN { #1 } { #1 }
613 \l_@@_glyphs_seq \l_@@_unicodes_seq
614 }
615 % \end{macrocode}
616 % \end{fn}
617 % \begin{key}{%
618 % default,
619 % glyphs,
620 % mappings,
621 % ^^A mappings~by~index,
622 % pfb,
623 % tfm,
624 % unicodes,
625 % }
626 % Keys.
627 % \begin{macrocode}
628 \keys_define:nn { fixtounicode }
629 {
630 default .tl_set:N = \l_@@_default_tl,
631 default .initial:n = 2FFFF,
632 default .default:V = \c_empty_tl,
633 glyphs .clist_set:N = \l_@@_glyphs_clist,
634 glyphs .value_required:n = true,
635 mappings .code:n = {
636 \prop_put_from_keyval:Nn \l_@@_mappings_prop { #1 }
637 },
638 % \end{macrocode}
639 % ^^A mappings ~ by ~ index .code:n = {
640 % ^^A \prop_put_from_keyval:Nn \l_@@_mappings_ind_prop { #1 }
641 % ^^A },
642 % \begin{macrocode}
643 pfb .tl_set:N = \l_@@_pfb_tl,
644 pfb .initial:V = \c_empty_tl,
645 tfm .tl_set:N = \l_@@_tfm_tl,
646 tfm .initial:V = \c_empty_tl,
647 unicodes .clist_set:N = \l_@@_unicodes_clist,
648 unicodes .value_required:n = true,
649 }
650 % \end{macrocode}
651 % \end{key}
652 % \begin{macrocode}
653 \prop_new:N \l_@@_mappings_prop
654 % \end{macrocode}
655 % ^^A \prop_new:N \l_@@_mappings_ind_prop
656 % \begin{fn}{\@@_tounicode:}
657 % Generic interface.
658 % \begin{macrocode}
659 \cs_new_protected:Npn \@@_tounicode:
660 {
661 \tl_if_empty:NT \l_@@_tfm_tl
662 {
663 \tl_if_empty:NTF \l_@@_pfb_tl
664 {
665 \msg_error:nnnV {fixtounicode} {file-awol} \l_@@_pfb_tl
666 }{
667 \tl_set_eq:NN \l_@@_tfm_tl \l_@@_pfb_tl
668 }
669 }
670 \tl_if_empty:NT \l_@@_pfb_tl
671 {
672 \tl_set_eq:NN \l_@@_pfb_tl \l_@@_tfm_tl
673 }
674 \seq_set_from_clist:NN \l_@@_glyphs_seq \l_@@_glyphs_clist
675 \seq_set_from_clist:NN \l_@@_unicodes_seq \l_@@_unicodes_clist
676 \seq_map_indexed_inline:Nn \l_@@_unicodes_seq
677 {
678 \tl_if_eq:VnTF \c_empty_tl { ##2 }
679 {
680 \seq_set_item:NnV \l_@@_unicodes_seq { ##1 } \l_@@_default_tl
681 } {
682 \tl_if_eq:nnT { ##2 } { 0 }
683 {
684 \seq_set_item:NnV \l_@@_unicodes_seq { ##1 } \l_@@_default_tl
685 }
686 }
687 }
688 % \end{macrocode}
689 % We now use any key-value mappings set \emph{via} the \texttt{mappings} key.
690 % This is intended for cases where only a few mappings are needed from a particular font.
691 % Font support packages providing mappings for symbol fonts should preferably use the public \lpack{expl3} functions or, failing that, the keys \texttt{glyphs} and \texttt{unicodes} as I expect the implementation of \texttt{mappings} to be significantly slower.
692 %
693 % Note that this method is \textbf{NOT} currently supported on Lua\TeX{}.
694 % To test on Lua\TeX{}, install a development binary, (re)generate appropriate formats and load this package with the \texttt{dev} option.
695 % Note the binary should probably \textbf{not} be used for real documents.
696 %
697 % For \TeX{} Live, the 2026 pretest contains a version of Lua\TeX{} which supports this functionality, so it is no longer necessary to download a separate binary or regenerate formats.
698 %
699 % On pdf\TeX{} this method should work just fine.
700 % \begin{macrocode}
701 \prop_if_empty:NF \l_@@_mappings_prop
702 {
703 \bool_lazy_and:nnTF
704 { \sys_if_engine_luatex_p: }
705 { ! \l_@@_luatex_has_fix_bool }
706 {
707 \msg_warning:nnnnn { fixtounicode } { limitations }
708 { key ~ mappings }
709 { this~version~of~LuaTeX }
710 { Please~update~your~TeX~distribution. ~
711 If~you~cannot~update,~use~the~keys~glyphs~and~unicodes~
712 or~equivalent~expl3~functions. ~
713 Alternatively,~compile~with~pdfTeX. ~
714 }
715 }{
716 \prop_map_inline:Nn \l_@@_mappings_prop
717 {
718 \seq_put_right:Nn \l_@@_glyphs_seq { ##1 }
719 \seq_put_right:Nn \l_@@_unicodes_seq { ##2 }
720 }
721 }
722 }
723 % \end{macrocode}
724 % ^^A We now use any key-value mappings set \emph{via} the \texttt{mappings by index} key.
725 % ^^A Again, this is intended for cases where only a few mappings are needed from a particular font.
726 %
727 % ^^A This method is \textbf{ONLY} supported on \textbf{CURRENT or OLDER} Lua\TeX{}.
728 % ^^A \textbf{It will not work with LuaTeX{} from \TeX{} Live 2026 pretest or later and should NOT be used in package code.}
729 % ^^A \begin{macrocode}
730 % ^^A \prop_if_empty:NF \l_@@_mappings_ind_prop
731 % ^^A {
732 % ^^A \bool_lazy_and:nnTF { \sys_if_engine_luatex_p: } { ! \l_@@_luatex_has_fix_bool }
733 % ^^A {
734 % ^^A \prop_map_inline:Nn \l_@@_mappings_prop
735 % ^^A {
736 % ^^A \seq_set_item:NnnTF \l_@@_glyphs_seq { ##1 } { ##1 }
737 % ^^A {
738 % ^^A \seq_set_item:Nnn \l_@@_unicodes_seq { ##1 } { ##2 }
739 % ^^A } {
740 % ^^A \int_step_inline:nnn { \seq_count:N \l_@@_glyphs_seq } { ##1 -1 }
741 % ^^A {
742 % ^^A \seq_put_right:Nn \l_@@_glyphs_seq { ####1 }
743 % ^^A \seq_put_right:NV \l_@@_unicodes_seq \l_@@_default_tl
744 % ^^A }
745 % ^^A \int_put_right:Nn \l__fixtounicodes_glyphs_seq { ##1 }
746 % ^^A \int_put_right:Nn \l__fixtounicodes_unicodes_seq { ##2 }
747 % ^^A }
748 % ^^A }
749 % ^^A } {
750 % ^^A \msg_warning:nnnnn { fixtounicode } { limitations }
751 % ^^A { key~mappings }
752 % ^^A { pdfTeX~or~new~versions~of~LuaTeX }
753 % ^^A { Use~glyph~names~with~the~key~mappings,~the~keys~glyphs~and~unicodes~or~equivalent~expl3~functions. }
754 % ^^A }
755 % ^^A }
756 % \begin{macrocode}
757 \@@_tounicode:VVNN \l_@@_tfm_tl \l_@@_pfb_tl
758 \l_@@_glyphs_seq \l_@@_unicodes_seq
759 }
760 % \end{macrocode}
761 % \end{fn}
762 % \begin{macro}{\fixtounicode}
763 % 2e syntax.
764 % \begin{macrocode}
765 \NewDocumentCommand \fixtounicode { +m }
766 {
767 \group_begin:
768 \keys_set:nn { fixtounicode } { #1 }
769 \@@_tounicode:
770 \group_end:
771 }
772 % \end{macrocode}
773 % \end{macro}
774 %</sty>
775 %
776 % \twreg
777 %
778 %\Finale