Debian Codegraph @

texmf-dist/source/latex/pdfmanagement/l3pdftools.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3pdftools.dtx
4 %
5 % Copyright (C) 2018-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % http://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "LaTeX PDF management bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/pdfresources
22 %
23 % for those people who are interested.
24 %
25 %<*driver>
26 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
27 \documentclass[full]{l3doc}
28 \usepackage{latex-lab-testphase-l3doc}
29 \usepackage{array,booktabs}
30 \hypersetup{pdfauthor=The LaTeX Project,pdftitle=l3pdftools (LaTeX PDF management bundle)}
31
32 \providecommand\potentialclash{\noindent\llap{\dbend\ }}
33 \begin{document}
34 \DocInput{\jobname.dtx}
35 \end{document}
36 %</driver>
37 % \fi
38 %
39 % \title{^^A
40 % The \pkg{l3pdftools} module\\ temporary collection of pdf related commands ^^A
41 % \\ LaTeX PDF management bundle
42 % }
43 %
44 % \author{^^A
45 % The \LaTeX{} Project\thanks
46 % {^^A
47 % E-mail:
48 % \href{mailto:[email protected]}
49 % {[email protected]}^^A
50 % }^^A
51 % }
52 %
53 % \date{Version 0.97c, released 2026-05-26}
54 %
55 % \maketitle
56 % \begin{documentation}
57 %
58 % \section{\pkg{l3pdftools} documentation}
59 %
60 % This module collects a number of candidate commands for the l3pdf module
61 %
62 % \begin{function}[added=2026-02-18]
63 % {\pdf_purify:nN}
64 % \begin{syntax}
65 % \cs{pdf_purify:nN} \Arg{content} \Arg{tl var}
66 % \end{syntax}
67 %
68 % This command calls \cs{text_purify:n} for \meta{content} and stores the result
69 % in \meta{tl var}. It performs first various setups to make the conversion suitable
70 % for a PDF context, most importantly for the bookmarks. Beside other
71 % it executes the hyperref command \cs{pdfstringdefPreHook}, that means that it knows the
72 % exceptions added by \cs{pdfstringdefDisableCommands}. It also sets \cs{Hy@pdfstringtrue},
73 % this means that if the content uses \cs{texorpdfstring} the pdf branch is used.
74 %
75 % At the begin the command calls the hook \texttt{pdf/purify/setup} which can be used to
76 % add more definitions and exceptions.
77 %
78 % While the implementation is quite different the command has a similar purpose as
79 % \cs{pdfstringdef}. The most notable difference from a user viewpoint is that it doesn't directly
80 % encode the result as a PDF string, typically a call of \cs{pdf_purify:nN}
81 % should be followed with a call of \cs{pdf_string_from_unicode:nnN}.
82 %
83 %
84 % \end{function}
85 %
86 % \begin{function}[EXP,added=2021-02-14]
87 % {\pdf_name_from_unicode_e:n,\pdf_name_from_unicode_e:V}
88 % \begin{syntax}
89 % \cs{pdf_name_from_unicode_e:n} \Arg{content}
90 % \end{syntax}
91 % This converts \meta{content} to a format suitable for a PDF Name.
92 % The output depends on the backend: For almost all backends
93 % it will first expand the content with \cs{text_expand:n} and
94 % then escape it in the way needed in a PDF Name with
95 % \cs{str_convert_pdfname:e}, and at last prepend a slash before.
96 % Typically such names use only ascii,
97 % but non-ascii is supported, but should be utf8 encoded. For example\\
98 % |\pdf_name_from_unicode_e:n {A~B\c_percent_str C\c_hash_str D€}}|\\
99 % will output |/A#20B#25C#23D#E2#82#AC|.
100 %
101 % With dvips it will expand the content with \cs{text_expand:n} and then wrap it
102 % in a |cvn| operation (\enquote{convert to name}).
103 % So the example above will output |(A B%C#D€) cvn| to
104 % the postscript. The content should not contain unbalanced parentheses with dvips.
105 %
106 % \end{function}
107 % \begin{function}[added=2020-07-04]
108 % {\pdf_string_from_unicode:nnN,\pdf_string_from_unicode:nVN}
109 % \begin{syntax}
110 % \cs{pdf_string_from_unicode:nnN} \Arg{format} \Arg{content} \meta{tl var}
111 % \end{syntax}
112 % This converts \meta{content} following the rules defined by \meta{format} and stores
113 % the result in \meta{tlvar}. The assignment is done locally.
114 % Non-ascii input should be utf8 encoded.
115 % Currently the following formats exist:
116 % \begin{description}
117 % \item[utf8/string-raw]
118 % this converts with \cs{str_set_convert:Nnnn} into utf8/string.
119 % \item[utf8/string]
120 % this converts into utf8/string and adds parentheses around the result.%
121 % \item[utf8/URI-raw]
122 % this converts with \cs{str_set_convert:Nnnn} into utf8/url and
123 % then replaces reserved and digits back from the percent encoding. Parentheses
124 % are escaped.
125 % \item[utf8/URI]
126 % this converts into utf8/URI and adds parentheses around the result.%
127 % \item[utf16/string-raw]
128 % this converts with \cs{str_set_convert:Nnnn} into utf16/string.
129 % \item[utf16/string]
130 % this converts into utf16/string and adds parentheses around the result.
131 % \item[utf16/hex-raw]
132 % this converts into utf16/hex
133 % \item[utf16/hex]
134 % this converts into utf16/hex and adds bracket around the result.
135 % \end{description}
136 % \end{function}
137 %
138 % \subsection{BDC operator / Properties resource}
139 % \begin{NOTE}{UF}
140 % we need a switch for the case that the resource should be added to
141 % xform resource instead of a page resources, see pdfbase.sty
142 % - xdvipdfmx: looks fine, the resource is added to the xform resource automatically
143 % - pdftex should now work okay too
144 % \end{NOTE}
145 % Entries to the /Properties dictionary in the page resources can
146 % be added with dvips only through side-effects: if a BDC-mark is created
147 % dvips/ghostscript will automatically create the necessary objects and names.
148 % To get a sensible abstraction the code does for some of the following
149 % command the same for the other backends if the
150 % core management code has been activated. This means that the behaviour
151 % of the command is different then. The \cs{pdf_bdcobject:..} should only be used
152 % if the management is active.
153 %
154 %
155 % \begin{function}[updated = 2024-10-23]
156 % {
157 % \pdf_bdc:nn, \pdf_bdc:ee
158 % }
159 % \begin{syntax}
160 % \cs{pdf_bdc:nn} \Arg{tag} \Arg{dictionary content}
161 % \end{syntax}
162 % This command adds a BDC marked content operator to the current page stream.
163 % \meta{tag} is the tag of this operator (without the leading slash),
164 % \meta{dictionary content} is the content of the second argument.
165 % With the exception of the dvips backend,
166 % the dictionary content is added inline in the stream. Such an inline BDC
167 % is typically better for ActualText additions as some PDF reader ignore
168 % entries given in properties.
169 % \end{function}
170 %
171 % \begin{function}[added = 2023-08-18]
172 % {
173 % \pdf_bdc_shipout:ee
174 % }
175 % \begin{syntax}
176 % \cs{pdf_bdc_shipout:ee} \Arg{tag} \Arg{dictionary content}
177 % \end{syntax}
178 % This command adds a BDC marked content operator to the current page stream.
179 % \meta{tag} is the tag of this operator (without the leading slash),
180 % \meta{dictionary content} is the content of the second argument.
181 %
182 % Differently to \cs{pdf_bdc:ee} the arguments are not expanded when the
183 % command is \emph{used}, but only at \emph{shipout}.
184 % This requires new engines which
185 % allow to use the keyword \texttt{shipout} with the primitive
186 % \cs{special} and \cs{pdfliteral}. Also similar to \cs{pdf_bdc:ee}
187 % the content of \meta{dictionary content} is added inline in the stream
188 % with most engines (not on the dvips + ps2pdf route).
189 % This means that this command can also be used if such an inline dictionary is preferred.
190 %
191 % The command requires current engines and
192 % is not defined if an too old engine is detected!
193 %
194 % \end{function}
195 %
196 % \begin{function}[added = 2020-07-03]
197 % {
198 % \pdf_bdcobject:nn
199 % }
200 % \begin{syntax}
201 % \cs{pdf_bdcobject:nn} \Arg{tag} \Arg{object name}
202 % \end{syntax}
203 % This command adds a BDC marked content operator to the current page stream.
204 % \meta{tag} is the tag of this operator (without the leading slash),
205 % \meta{object name} is a the name of an dictionary object reserved with
206 % \cs{pdf_object_new:n} and filled with \cs{pdf_object_write:nnn} with
207 % the properties of the BDC. Reusing a predefined object can save space
208 % but the command works correctly
209 % only if the resources management has been activated and should be used only
210 % if this can be ensured.
211 % \end{function}
212 % \begin{function}[updated = 2020-07-03]
213 % {
214 % \pdf_bdcobject:n
215 % }
216 % \begin{syntax}
217 % \cs{pdf_bdcobject:n} \Arg{tag}
218 % \end{syntax}
219 % This command adds a BDC marked content operator to the current page stream.
220 % \meta{tag} is the tag of this operator (without the leading slash).
221 % As object this commands uses the last anonymous dictionary object created with
222 % \cs{pdf_object_unnamed_write:nn}. It lies in the responsibility of the user that the last
223 % object is the wanted one. Like with \cs{pdf_bdcobject:nn} the command works correctly
224 % only if the resources management has been activated and should be used only
225 % if this can be ensured.
226 % \end{function}
227 % \begin{function}[added = 2019-10-17]
228 % {
229 % \pdf_bmc:n
230 % }
231 % \begin{syntax}
232 % \cs{pdf_bmc:n} \Arg{tag}
233 % \end{syntax}
234 % This command created a BMC marked content operator. The argument is the
235 % tag without the leading slash. It can be e.g. used for simple artifact
236 % markers.
237 % \end{function}
238 % \begin{function}[added = 2019-06-30]
239 % {
240 % \pdf_emc:
241 % }
242 % \begin{syntax}
243 % \cs{pdf_emc:}
244 % \end{syntax}
245 % This command closes the BDC marked content operator opened with \cs{pdf_bdc:nn}.
246 % It should be on the same page as the bdc-command.
247 %
248 % \begin{verbatim}
249 % \pdf_object_new:n {module/objA}
250 % \pdf_object_write:nnn {module/objA}{dict}{/Type/Artifact}
251 % \pdf_bdc:nn {Span}{module/objA}
252 % text
253 % \pdf_emc:
254 % \end{verbatim}
255 % \end{function}
256 %
257 %
258 % \end{documentation}
259 %
260 % \begin{implementation}
261 %
262 % \section{\pkg{l3pdftools} implementation}
263 %
264 % \begin{macrocode}
265 %<*header>
266 \ProvidesExplPackage{l3pdftools}{2026-05-26}{0.97c}
267 {candidate commands for l3pdf---LaTeX PDF management bundle}
268 %</header>
269 % \end{macrocode}
270 %
271 % \begin{macrocode}
272 %<@@=pdf>
273 %<*package>
274 % \end{macrocode}
275 % \subsection{Conversions and export functions}
276 % \begin{macro}{\pdf_name_from_unicode_e:n,\pdf_name_from_unicode_e:V}
277 % \begin{macrocode}
278 \cs_generate_variant:Nn \str_convert_pdfname:n { e }
279
280 \cs_new:Npn \pdf_name_from_unicode_e:n #1
281 {
282 \__kernel_pdf_name_from_unicode_e:n { #1 }
283 }
284
285 \cs_generate_variant:Nn \pdf_name_from_unicode_e:n {V}
286 % \end{macrocode}
287 % \end{macro}
288 %
289 % The convert command must use a different value the source encoding
290 % depending on the engines. Until the PR in str-convert is active we add the alias here
291 % too
292 % \begin{macrocode}
293 \bool_lazy_any:nTF
294 {
295 \sys_if_engine_luatex_p:
296 \sys_if_engine_xetex_p:
297 }
298 {
299 \prop_gput:Nnn \g__str_alias_prop { default } { }
300 }
301 {
302 \prop_gput:Nnn \g__str_alias_prop { default } { utf8 }
303 }
304 % \end{macrocode}
305 % \begin{macro}{\pdf_string_from_unicode:nnN}
306 % \begin{macrocode}
307 \msg_new:nnn {pdfmanagement}{ unknown-convert}
308 {
309 Unknown~string~conversion~method~'#1'!
310 }
311 \cs_new:Npn \pdf_string_from_unicode:nnN #1 #2 #3
312 {
313 \cs_if_exist_use:cF { @@_string_from_unicode_#1:nN }
314 {
315 \msg_error:nnn { pdf } { unknown-convert } {#1}
316 \use_none:nn
317 }
318 { #2 } #3
319 }
320
321 \cs_generate_variant:Nn \pdf_string_from_unicode:nnN {nVN}
322 % \end{macrocode}
323 % \end{macro}
324 % Most converter are simply wrapper around the str-convert commands and so
325 % use the same names, with the addition raw if no delimiters are added.
326 % The exception is the one for url's: it reverts most of the percent encodings
327 % and escapes the parentheses.
328 % That's why its name is URI instead of url. The current code is probably quite
329 % slow and will need a replacement.
330 % \begin{macro}{ @@_string_from_unicode_utf8/string-raw:nN }
331 % \begin{macro}{ @@_string_from_unicode_utf8/string:nN }
332 % \begin{macro}{ @@_string_from_unicode_utf8/URI-raw:nN }
333 % \begin{macro}{ @@_string_from_unicode_utf8/URI:nN }
334 % \begin{macro}{ @@_string_from_unicode_utf16/string-raw:nN }
335 % \begin{macro}{ @@_string_from_unicode_utf16/string:nN }
336 % \begin{macro}{ @@_string_from_unicode_utf16/hex-raw:nN }
337 % \begin{macro}{ @@_string_from_unicode_utf16/hex:nN }
338 % \begin{macrocode}
339 %% TODO Names need a review when it is clear which converters
340 %% are actually needed
341 %% string conversions and printing
342 %% we assume here that the text purify step has been done. The input is
343 %% a list of (utf8) chars.
344 %% str convert, not expandable.
345 % filespec (attachment view) tests:
346 % utf8: gr\303\274\303\237e.txt
347 % %doesn't work, umlaut wrong,
348 % utf8 with BOM \357\273\277gr\303\274\303\237e.txt
349 % %doesn't work, umlaut wrong, bom visible
350 % utf16 with BE: (FEFF)
351 % \376\377\000g\000r\000\374\000\337\000e\000.\000t\000x\000t %works
352 % xetex converts to <feff0067007200fc00df0065002e007400780074>
353 % utf16 with BE / HEX: <FEFF0067007200FC00DF0065002E007400780074> works
354
355 % bookmarks: as pdfoutline uses () currently only utf16 with BE is usable.
356 % check if one can use HEX too when directly writing the object
357 % ==========
358 % uri: utf16BE/string seems not to work, hex neither
359 % utf8/string works but not on macos,
360 % so a specific utf8/url variant is needed
361 % ==========
362 % "input" is utf8 for pdftex, empty (native) for unicode engine
363 % commands to output literal strings (...)
364
365 \cs_new_protected:cpn { @@_string_from_unicode_utf8/string-raw:nN } #1 #2
366 {
367 \str_set_convert:Nnnn #2
368 { #1 }
369 { default }
370 {utf8/string}
371 }
372
373 \cs_new_protected:cpn { @@_string_from_unicode_utf8/string:nN } #1 #2
374 {
375 \use:c { @@_string_from_unicode_utf8/string-raw:nN } { #1 } #2
376 \str_put_left:Nn #2 {(}
377 \str_put_right:Nn #2 {)}
378 }
379 % special url command:
380 \cs_new_protected:cpx { @@_string_from_unicode_utf8/URI-raw:nN } #1 #2
381 {
382 \exp_not:N \str_set_convert:Nnnn #2
383 { #1 }
384 { default }
385 {utf8/url}
386 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3A} {:}
387 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2F} {/}
388 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 23} {\c_hash_str}
389 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 5B} {[}
390 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 5D} {]}
391 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 40} {\c_atsign_str}
392 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 21} {!}
393 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 24} {\c_dollar_str}
394 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 26} {\c_ampersand_str}
395 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 27} {'}
396 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2A} {*}
397 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2B} {+}
398 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2C} {,}
399 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3B} {;}
400 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3D} {=}
401 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3F} {?}
402 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 30} {0}
403 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 31} {1}
404 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 32} {2}
405 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 33} {3}
406 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 34} {4}
407 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 35} {5}
408 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 36} {6}
409 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 37} {7}
410 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 38} {8}
411 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 39} {9}
412 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 28} {\c_backslash_str(}
413 \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 29} {\c_backslash_str)}
414 }
415
416 \cs_new_protected:cpn { @@_string_from_unicode_utf8/URI:nN } #1 #2
417 {
418 \use:c { @@_string_from_unicode_utf8/URI-raw:nN } {#1} #2
419 \str_put_left:Nn #2 {(}
420 \str_put_right:Nn #2 {)}
421 }
422 % with utf16 with BE marker
423 \cs_new_protected:cpn { @@_string_from_unicode_utf16/string-raw:nN } #1 #2
424 {
425 \str_set_convert:Nnnn #2
426 { #1 }
427 { default }
428 {utf16/string}
429 }
430
431 \cs_new_protected:cpn { @@_string_from_unicode_utf16/string:nN } #1 #2
432 {
433 \use:c { @@_string_from_unicode_utf16/string-raw:nN } {#1} #2
434 \str_put_left:Nn #2 {(}
435 \str_put_right:Nn #2 {)}
436 }
437
438 \cs_new_protected:cpn { @@_string_from_unicode_utf16/hex-raw:nN } #1 #2
439 {
440 \str_set_convert:Nnnn #2
441 { #1 }
442 { default }
443 {utf16/hex}
444 }
445
446 \cs_new_protected:cpn { @@_string_from_unicode_utf16/hex:nN } #1 #2
447 {
448 \use:c { @@_string_from_unicode_utf16/hex-raw:nN } {#1} #2
449 \str_put_left:Nn #2 {<}
450 \str_put_right:Nn #2 {>}
451 }
452
453 % \end{macrocode}
454 % \end{macro}
455 % \end{macro}
456 % \end{macro}
457 % \end{macro}
458 % \end{macro}
459 % \end{macro}
460 % \end{macro}
461 % \end{macro}
462 %
463 % \subsection{A \cs{pdfstringdef} replacement}
464 %
465 % The following definitions are intended to replace the \cs{pdfstringdef} command of hyperref.
466 % Like \cs{pdfstringdef} they take an input which can contain various \LaTeX-commands,
467 % sets up a number of sensible replacements and then outputs into a variable something
468 % that can be used in a PDF string.
469 %
470 % \subsubsection{TeX or PDF?}
471 % We need a \enquote{TeX or PDF} command, we use for now the conditional and definition
472 % of hyperref but this should perhaps be changed.
473 % \begin{macrocode}
474 \newif\ifHy@pdfstring
475 \def\texorpdfstring{%
476 \ifHy@pdfstring
477 \expandafter\@secondoftwo
478 \else
479 \expandafter\@firstoftwo
480 \fi
481 }
482 % \end{macrocode}
483 %
484 % \subsubsection{The main conversion command}
485 %
486 % \subsubsection{Converting text}
487 % The title text of the bookmark and other strings must be converted to strings
488 % suitable for a PDF. With hyperref one can use |\pdfstringdef| but
489 % we also provide a native version. This follows the implementation
490 % in the generic hyperref driver, the hyperref driver should in the end use this
491 % implementation too.
492 %
493 % The conversion has to do two things: purifying the input and then converting it
494 % into a PDF string. |\pdfstringdef| does both together but we split up the task.
495 % This allows to post process the purified text, it also allows to use more than one
496 % conversion command.
497 %
498 % \begin{variable}{\l_@@_purify_tmpa_tl,\g_@@_purify_tmpa_str}
499 % Temporary variables
500 % \begin{macrocode}
501 \tl_new:N\l_@@_purify_tmpa_tl
502 \str_new:N\g_@@_purify_tmpa_str
503 % \end{macrocode}
504 % \end{variable}
505 %
506 % A socket which should contain the setup definitions.
507 % A different plug should at the end call the hook \texttt{pdf/purify/setup}
508 % (if user settings should be used too).
509 % \begin{macrocode}
510 \socket_new:nn{pdf/purify/setup}{0}
511 \socket_new_plug:nnn { pdf/purify/setup } { kernel}
512 {
513 \@@_purify_equivalents:
514 \hook_use:n {pdf/purify/setup}
515 }
516 \socket_assign_plug:nn { pdf/purify/setup } { kernel}
517 % \end{macrocode}
518 % The hook inside the setup socket. By default it contains the hyperref
519 % hook:
520 % \begin{macrocode}
521 \hook_new:n{pdf/purify/setup}
522 \providecommand\pdfstringdefPreHook{}
523 \hook_gput_code:nnn{pdf/purify/setup}{pdf}{\pdfstringdefPreHook}
524 % \end{macrocode}
525 %
526 % A socket which should contain the code to expand/purify the content.
527 % The arguments are the content and a string variable for the result.
528 % \begin{macrocode}
529 \socket_new:nn {pdf/purify} {2}
530 \socket_new_plug:nnn {pdf/purify} {kernel}
531 {
532 % \end{macrocode}
533 % Note: currently \cs{text_expand:n} does not remove a \cs{protect} command
534 % and does not expand a following token even if it has a declared replacement.
535 % But in PDF strings we want to expand as much as possible, and
536 % e.g. should be able to remove/format the |\numberline| command in a bookmark.
537 % \begin{macrocode}
538 \str_set:Ne #2 {\text_purify:n { #1 } }
539 }
540 \socket_assign_plug:nn{pdf/purify}{kernel}
541 % \end{macrocode}
542 % A hook for final cleanup, currently it contains nothing.
543 % It gets as argument a string variable and so can adapt that.
544 % \begin{macrocode}
545 \hook_new_with_args:nn {pdf/purify/after}{1}
546 % \end{macrocode}
547 %
548 % \begin{macro}{\pdf_purify:nN,\@@_purify:nN}
549 % \cs{pdf_purify:nN} runs all the purifying steps but does
550 % not convert to a PDF string. It is meant to produce input for
551 % commands doing the conversion later.
552 % \begin{macrocode}
553 \cs_new_protected:Npn \@@_purify:nN #1 #2 %#1 content #2 str-var
554 {
555 \group_begin:
556 \socket_use:n {pdf/purify/setup}
557 \socket_use:nnn {pdf/purify} {#1} {#2}
558 \hook_use:nnw {pdf/purify/after} {1} {#2}
559 \str_gset_eq:NN \g_@@_purify_tmpa_str #2
560 \group_end:
561 \str_set_eq:NN #2 \g_@@_purify_tmpa_str
562 }
563 \cs_set_eq:NN \pdf_purify:nN\@@_purify:nN
564 % \end{macrocode}
565 % \end{macro}
566 %
567 % \subsubsection{Setup: replacement definition for pdf strings}
568 % Similar to |\pdfstringdef| we need to declare various equivalents
569 % \begin{macrocode}
570 \cs_new_protected:Npn \@@_purify_equivalents:
571 {
572 \Hy@pdfstringtrue
573 \text_declare_expand_equivalent:Nn\MakeUppercase{\@@_purify_makeuppercase:n}
574 \text_declare_expand_equivalent:Nn\MakeLowercase{\@@_purify_makelowercase:n}
575 \cs_set:Npn\dots{…} %U+2026
576 \cs_set:Npn\ldots{…}
577 \cs_set:Npn\P{¶}
578 \cs_set:Npn\TeX{TeX}
579 \cs_set:Npn\LaTeX{LaTeX}
580 \cs_set:Npn\LaTeXe{LaTeX2ε}
581 \cs_set:Npn\SliTeX{Sli\TeX}%
582 \cs_set:Npn\MF{Metafont}%
583 \cs_set:Npn\MP{Metapost}%
584 \cs_set_eq:NN\phantom\use_none:n
585 \cs_set_eq:NN\vphantom\use_none:n
586 \cs_set_eq:NN\hphantom\use_none:n
587 \cs_set_eq:NN\mathversion\use_none:n
588 % \ding ?
589 % \Cube ?
590 % \begin ?
591 % \end ?
592 % \end{macrocode}
593 % Font commands.
594 % \begin{macrocode}
595 \cs_set_eq:NN\emph\use_i:n
596 \cs_set_eq:NN\em\prg_do_nothing:
597 \cs_set_eq:NN\textnormal\use_i:n
598 \cs_set_eq:NN\textrm\use_i:n
599 \cs_set_eq:NN\textsf\use_i:n
600 \cs_set_eq:NN\texttt\use_i:n
601 \cs_set_eq:NN\textbf\use_i:n
602 \cs_set_eq:NN\textmd\use_i:n
603 \cs_set_eq:NN\textit\use_i:n
604 \cs_set_eq:NN\textsc\use_i:n
605 \cs_set_eq:NN\textsl\use_i:n
606 \cs_set_eq:NN\textup\use_i:n
607 \cs_set_eq:NN\normalfont\prg_do_nothing:
608 \cs_set_eq:NN\rmfamily\prg_do_nothing:
609 \cs_set_eq:NN\sffamily\prg_do_nothing:
610 \cs_set_eq:NN\ttfamily\prg_do_nothing:
611 \cs_set_eq:NN\bfseries\prg_do_nothing:
612 \cs_set_eq:NN\mdseries\prg_do_nothing:
613 \cs_set_eq:NN\itshape\prg_do_nothing:
614 \cs_set_eq:NN\scshape\prg_do_nothing:
615 \cs_set_eq:NN\slshape\prg_do_nothing:
616 \cs_set_eq:NN\upshape\prg_do_nothing:
617 \cs_set_eq:NN\Huge\prg_do_nothing:
618 \cs_set_eq:NN\LARGE\prg_do_nothing:
619 \cs_set_eq:NN\Large\prg_do_nothing:
620 \cs_set_eq:NN\footnotesize\prg_do_nothing:
621 \cs_set_eq:NN\huge\prg_do_nothing:
622 \cs_set_eq:NN\large\prg_do_nothing:
623 \cs_set_eq:NN\normalsize\prg_do_nothing:
624 \cs_set_eq:NN\scriptsize\prg_do_nothing:
625 \cs_set_eq:NN\small\prg_do_nothing:
626 \cs_set_eq:NN\tiny\prg_do_nothing:
627 % \end{macrocode}
628 % Spaces
629 % \begin{macrocode}
630 \cs_set_eq:NN\quad\space
631 \cs_set_eq:NN\qquad\space
632 \cs_set_eq:NN\hspace\@@_purify_hspace:w
633 % \end{macrocode}
634 % Colors. This handles only a few commands.
635 % But pdfstringdef ignores color completely, so probably not
636 % a practical problem.
637 % \begin{macrocode}
638 \cs_set_eq:NN\textcolor\use_ii:nn
639 \cs_set_eq:NN\color \@gobble@om
640 \cs_set_eq:NN\label \@gobble@om
641 \cs_set_eq:NN\index \@gobble@som
642 \cs_set_eq:NN\glossary \@gobble@om
643 \cs_set_eq:NN\ref\@@_purify_ref:w
644 \cs_set_eq:NN\pageref\@@_purify_pageref:w
645 \cs_set_eq:NN\nameref\@@_purify_nameref:w
646 \cs_set_eq:NN\autoref\HyPsd@autoref
647 \let\@mkboth\@gobbletwo
648 % what to do with all the \textxxx commands?
649 \text_declare_expand_equivalent:Nn\textparagraph{¶}
650 \text_declare_expand_equivalent:Nn\textdollar{\$}
651 }
652 % \end{macrocode}
653 %
654 % Replacements for reference commands
655 % \begin{macrocode}
656 \cs_new:Npn\@@_purify_nameref:n #1
657 {\cs_if_exist:cTF {r@#1}{\tl_item:cn{r@#1}{3}}{0}}
658 \DeclareExpandableDocumentCommand\@@_purify_ref:w{sm}{\@kernel@ref@exp{#2}}
659 \DeclareExpandableDocumentCommand\@@_purify_pageref:w{sm}{\@kernel@pageref@exp{#2}}
660 \DeclareExpandableDocumentCommand\@@_purify_nameref:w{sm}{\@@_purify_nameref:n{#2}}
661 %
662 % \end{macrocode}
663 % Replacements for uppercase and lowercase command
664 % \begin{macrocode}
665 \cs_new:Npn \@@_purify_makeuppercase:n #1
666 {\use:e
667 {\exp_args:Ne
668 \text_uppercase:nn{\BCPdata { casing }}{#1}
669 }
670 }
671 \cs_new:Npn \@@_purify_makelowercase:n #1
672 {\use:e
673 {\exp_args:Ne
674 \text_lowercase:nn{\BCPdata { casing }}{#1}
675 }
676 }
677 % \end{macrocode}
678 % Replacement for hspace:
679 % \begin{macrocode}
680 \NewExpandableDocumentCommand\@@_purify_hspace:w{sm}
681 {
682 \dim_compare:nNnT{#2}>{0pt}{\space}
683 }
684 % \end{macrocode}
685 %
686 % \subsection{BDC operator commands}
687 % \begin{macro}{\pdf_bdc:nn,\pdf_bdc:ee}
688 % \begin{macro}{\pdf_bdc_property:nn}
689 % \begin{macro}{\pdf_bdc_shipout:ee}
690 % \begin{macro}{\pdf_bdcobject:nn}
691 % \begin{macro}{\pdf_bdcobject:n}
692 % \begin{macro}{\pdf_bmc:n}
693 % \begin{macro}{\pdf_emc:}
694 % \begin{macrocode}
695 \cs_new_protected:Npn \pdf_bdc:nn #1 #2 { \@@_backend_bdc:nn { #1 }{ #2 } }
696 \cs_generate_variant:Nn \pdf_bdc:nn {ee}
697
698 \cs_new_protected:Npn \pdf_bdc_property:nn #1 #2
699 { \@@_backend_bdc_contobj:nn { #1 }{ #2 } }
700 \cs_new_protected:Npn \pdf_bdc_shipout:ee #1 #2
701 {
702 \@@_backend_bdc_shipout:ee { #1 }{ #2 }
703 \cs_gset_eq:NN \pdf_bdc_shipout:ee \@@_backend_bdc_shipout:ee
704 }
705 \cs_new_protected:Npn \pdf_bdcobject:nn #1 #2 { \@@_backend_bdcobject:nn { #1 }{ #2 } }
706 \cs_new_protected:Npn \pdf_bdcobject:n #1 { \@@_backend_bdcobject:n { #1 } }
707 \cs_new_protected:Npn \pdf_bmc:n #1 { \@@_backend_bmc:n { #1 } }
708 \cs_new_protected:Npn \pdf_emc: { \@@_backend_emc: }
709 % \end{macrocode}
710 % \end{macro}
711 % \end{macro}
712 % \end{macro}
713 % \end{macro}
714 % \end{macro}
715 % \end{macro}
716 % \end{macro}
717 % \begin{macrocode}
718 %</package>
719 % \end{macrocode}
720 %
721 % \end{implementation}
722 %
723 % \PrintIndex