Debian Codegraph @

texmf-dist/source/generic/pdftexcmds/pdftexcmds.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: pdftexcmds.dtx
4 % Version: 2020-06-27 v0.33
5 % Info: Utility functions of pdfTeX for LuaTeX
6 %
7 % Copyright (C)
8 % 2007, 2009-2011 Heiko Oberdiek
9 % 2016-2020 Oberdiek Package Support Group
10 %
11 % This work may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either
13 % version 1.3c of this license or (at your option) any later
14 % version. This version of this license is in
15 % https://www.latex-project.org/lppl/lppl-1-3c.txt
16 % and the latest version of this license is in
17 % https://www.latex-project.org/lppl.txt
18 % and version 1.3 or later is part of all distributions of
19 % LaTeX version 2005/12/01 or later.
20 %
21 % This work has the LPPL maintenance status "maintained".
22 %
23 % The Current Maintainers of this work are
24 % Heiko Oberdiek and the Oberdiek Package Support Group
25 % https://github.com/ho-tex/pdftexcmds/issues
26 %
27 % The Base Interpreter refers to any `TeX-Format',
28 % because some files are installed in TDS:tex/generic//.
29 %
30 % This work consists of the main source file pdftexcmds.dtx
31 % and the derived files
32 % pdftexcmds.sty, pdftexcmds.pdf, pdftexcmds.ins, pdftexcmds.drv,
33 % pdftexcmds.bib, pdftexcmds-test1.tex, pdftexcmds-test2.tex,
34 % pdftexcmds-test-shell.tex, pdftexcmds-test-escape.tex,
35 % pdftexcmds.lua.
36 %
37 % Distribution:
38 % CTAN:macros/latex/contrib/pdftexcmds/pdftexcmds.dtx
39 % CTAN:macros/latex/contrib/pdftexcmds/pdftexcmds.pdf
40 %
41 % Unpacking:
42 % (a) If pdftexcmds.ins is present:
43 % tex pdftexcmds.ins
44 % (b) Without pdftexcmds.ins:
45 % tex pdftexcmds.dtx
46 % (c) If you insist on using LaTeX
47 % latex \let\install=y\input{pdftexcmds.dtx}
48 % (quote the arguments according to the demands of your shell)
49 %
50 % Documentation:
51 % (a) If pdftexcmds.drv is present:
52 % latex pdftexcmds.drv
53 % (b) Without pdftexcmds.drv:
54 % latex pdftexcmds.dtx; ...
55 % The class ltxdoc loads the configuration file ltxdoc.cfg
56 % if available. Here you can specify further options, e.g.
57 % use A4 as paper format:
58 % \PassOptionsToClass{a4paper}{article}
59 %
60 % Programm calls to get the documentation (example):
61 % pdflatex pdftexcmds.dtx
62 % bibtex pdftexcmds.aux
63 % makeindex -s gind.ist pdftexcmds.idx
64 % pdflatex pdftexcmds.dtx
65 % makeindex -s gind.ist pdftexcmds.idx
66 % pdflatex pdftexcmds.dtx
67 %
68 % Installation:
69 % TDS:tex/generic/pdftexcmds/pdftexcmds.sty
70 % TDS:tex/generic/pdftexcmds/pdftexcmds.lua
71 % TDS:doc/latex/pdftexcmds/pdftexcmds.pdf
72 % TDS:source/latex/pdftexcmds/pdftexcmds.dtx
73 %
74 %<*ignore>
75 \begingroup
76 \catcode123=1 %
77 \catcode125=2 %
78 \def\x{LaTeX2e}%
79 \expandafter\endgroup
80 \ifcase 0\ifx\install y1\fi\expandafter
81 \ifx\csname processbatchFile\endcsname\relax\else1\fi
82 \ifx\fmtname\x\else 1\fi\relax
83 \else\csname fi\endcsname
84 %</ignore>
85 %<*install>
86 \input docstrip.tex
87 \Msg{************************************************************************}
88 \Msg{* Installation}
89 \Msg{* Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO)}
90 \Msg{************************************************************************}
91
92 \keepsilent
93 \askforoverwritefalse
94
95 \let\MetaPrefix\relax
96 \preamble
97
98 This is a generated file.
99
100 Project: pdftexcmds
101 Version: 2020-06-27 v0.33
102
103 Copyright (C)
104 2007, 2009-2011 Heiko Oberdiek
105 2016-2019 Oberdiek Package Support Group
106
107 This work may be distributed and/or modified under the
108 conditions of the LaTeX Project Public License, either
109 version 1.3c of this license or (at your option) any later
110 version. This version of this license is in
111 https://www.latex-project.org/lppl/lppl-1-3c.txt
112 and the latest version of this license is in
113 https://www.latex-project.org/lppl.txt
114 and version 1.3 or later is part of all distributions of
115 LaTeX version 2005/12/01 or later.
116
117 This work has the LPPL maintenance status "maintained".
118
119 The Current Maintainers of this work are
120 Heiko Oberdiek and the Oberdiek Package Support Group
121 https://github.com/ho-tex/pdftexcmds/issues
122
123
124 The Base Interpreter refers to any `TeX-Format',
125 because some files are installed in TDS:tex/generic//.
126
127 This work consists of the main source file pdftexcmds.dtx
128 and the derived files
129 pdftexcmds.sty, pdftexcmds.pdf, pdftexcmds.ins, pdftexcmds.drv,
130 pdftexcmds.lua.
131
132 \endpreamble
133 \let\MetaPrefix\DoubleperCent
134
135 \generate{%
136 \file{pdftexcmds.ins}{\from{pdftexcmds.dtx}{install}}%
137 \file{pdftexcmds.drv}{\from{pdftexcmds.dtx}{driver}}%
138 \nopreamble
139 \nopostamble
140 \file{pdftexcmds.bib}{\from{pdftexcmds.dtx}{bib}}%
141 \usepreamble\defaultpreamble
142 \usepostamble\defaultpostamble
143 \usedir{tex/generic/pdftexcmds}%
144 \file{pdftexcmds.sty}{\from{pdftexcmds.dtx}{package}}%
145 % \usedir{doc/latex/pdftexcmds/test}%
146 % \file{pdftexcmds-test1.tex}{\from{pdftexcmds.dtx}{test1}}%
147 % \file{pdftexcmds-test2.tex}{\from{pdftexcmds.dtx}{test2}}%
148 % \file{pdftexcmds-test-shell.tex}{\from{pdftexcmds.dtx}{test-shell}}%
149 % \file{pdftexcmds-test-escape.tex}{\from{pdftexcmds.dtx}{test-escape}}%
150 }
151 \def\MetaPrefix{-- }
152 \def\defaultpostamble{%
153 \MetaPrefix^^J%
154 \MetaPrefix\space End of File `\outFileName'.%
155 }
156 \def\currentpostamble{\defaultpostamble}%
157 \generate{%
158 \usedir{tex/generic/pdftexcmds}%
159 \file{pdftexcmds.lua}{\from{pdftexcmds.dtx}{lua}}%
160 }
161
162 \catcode32=13\relax% active space
163 \let =\space%
164 \Msg{************************************************************************}
165 \Msg{*}
166 \Msg{* To finish the installation you have to move the following}
167 \Msg{* files into a directory searched by TeX:}
168 \Msg{*}
169 \Msg{* pdftexcmds.sty}
170 \Msg{* pdftexcmds.lua}
171 \Msg{*}
172 \Msg{* To produce the documentation run the file `pdftexcmds.drv'}
173 \Msg{* through LaTeX.}
174 \Msg{*}
175 \Msg{* Happy TeXing!}
176 \Msg{*}
177 \Msg{************************************************************************}
178
179 \endbatchfile
180 %</install>
181 %<*bib>
182 @online{AndyThomas:Analog,
183 author={Thomas, Andy},
184 title={Analog of {\texttt{\csname textbackslash\endcsname}pdfelapsedtime} for
185 {\hologo{LuaTeX}} and {\hologo{XeTeX}}},
186 url={http://tex.stackexchange.com/a/32531},
187 urldate={2011-11-29},
188 }
189 %</bib>
190 %<*ignore>
191 \fi
192 %</ignore>
193 %<*driver>
194 \NeedsTeXFormat{LaTeX2e}
195 \ProvidesFile{pdftexcmds.drv}%
196 [2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO)]%
197 \documentclass{ltxdoc}
198 \usepackage{holtxdoc}[2011/11/22]
199 \usepackage{paralist}
200 \usepackage{csquotes}
201 \usepackage[
202 backend=biber,
203 alldates=iso,
204 ]{biblatex}[2011/11/13]
205 \addbibresource{oberdiek-source.bib}
206 \addbibresource{pdftexcmds.bib}
207 \begin{document}
208 \DocInput{pdftexcmds.dtx}%
209 \end{document}
210 %</driver>
211 % \fi
212 %
213 %
214 %
215 % \GetFileInfo{pdftexcmds.drv}
216 %
217 % \title{The \xpackage{pdftexcmds} package}
218 % \date{2020-06-27 v0.33}
219 % \author{Heiko Oberdiek\thanks
220 % {Please report any issues at \url{https://github.com/ho-tex/pdftexcmds/issues}}}
221 %
222 % \maketitle
223 %
224 % \begin{abstract}
225 % \hologo{LuaTeX} provides most of the commands of \hologo{pdfTeX} 1.40. However
226 % a number of utility functions are removed. This package tries to fill
227 % the gap and implements some of the missing primitive using Lua.
228 % \end{abstract}
229 %
230 % \tableofcontents
231 %
232 % \def\csi#1{\texttt{\textbackslash\textit{#1}}}
233 %
234 % \section{Documentation}
235 %
236 % Some primitives of \hologo{pdfTeX} \cite{pdftex-manual}
237 % are not defined by \hologo{LuaTeX} \cite{luatex-manual}.
238 % This package implements macro based solutions using Lua code
239 % for the following missing \hologo{pdfTeX} primitives;
240 % \begin{compactitem}
241 % \item \cs{pdfstrcmp}
242 % \item \cs{pdfunescapehex}
243 % \item \cs{pdfescapehex}
244 % \item \cs{pdfescapename}
245 % \item \cs{pdfescapestring}
246 % \item \cs{pdffilesize}
247 % \item \cs{pdffilemoddate}
248 % \item \cs{pdffiledump}
249 % \item \cs{pdfmdfivesum}
250 % \item \cs{pdfresettimer}
251 % \item \cs{pdfelapsedtime}
252 % \item |\immediate\write18|
253 % \end{compactitem}
254 % The original names of the primitives cannot be used:
255 % \begin{itemize}
256 % \item
257 % The syntax for their arguments cannot easily
258 % simulated by macros. The primitives using key words
259 % such as |file| (\cs{pdfmdfivesum}) or |offset| and |length|
260 % (\cs{pdffiledump}) and uses \meta{general text} for the other
261 % arguments. Using token registers assignments, \meta{general text} could
262 % be catched. However, the simulated primitives are expandable
263 % and register assignments would destroy this important property.
264 % (\meta{general text} allows something like |\expandafter\bgroup ...}|.)
265 % \item
266 % The original primitives can be expanded using one expansion step.
267 % The new macros need two expansion steps because of the additional
268 % macro expansion. Example:
269 % \begin{quote}
270 % |\expandafter\foo\pdffilemoddate{file}|\\
271 % vs.\\
272 % |\expandafter\expandafter\expandafter|\\
273 % |\foo\pdf@filemoddate{file}|
274 % \end{quote}
275 % \end{itemize}
276 %
277 % \hologo{LuaTeX} isn't stable yet and thus the status of this package is
278 % \emph{experimental}. Feedback is welcome.
279 %
280 % \subsection{General principles}
281 %
282 % \begin{description}
283 % \item[Naming convention:]
284 % Usually this package defines a macro |\pdf@|\meta{cmd} if
285 % \hologo{pdfTeX} provides |\pdf|\meta{cmd}.
286 % \item[Arguments:] The order of arguments in |\pdf@|\meta{cmd}
287 % is the same as for the corresponding primitive of \hologo{pdfTeX}.
288 % The arguments are ordinary undelimited \hologo{TeX} arguments,
289 % no \meta{general text} and without additional keywords.
290 % \item[Expandibility:]
291 % The macro |\pdf@|\meta{cmd} is expandable if the
292 % corresponding \hologo{pdfTeX} primitive has this property.
293 % Exact two expansion steps are necessary (first is the macro
294 % expansion) except for \cs{pdf@primitive} and \cs{pdf@ifprimitive}.
295 % The latter ones are not macros, but have the direct meaning of the
296 % primitive.
297 % \item[Without \hologo{LuaTeX}:]
298 % The macros |\pdf@|\meta{cmd} are mapped to the commands
299 % of \hologo{pdfTeX} if they are available. Otherwise they are undefined.
300 % \item[Availability:]
301 % The macros that the packages provides are undefined, if
302 % the necessary primitives are not found and cannot be
303 % implemented by Lua.
304 % \end{description}
305 %
306 % \subsection{Macros}
307 %
308 % \subsubsection[Strings]{Strings \cite[``7.15 Strings'']{pdftex-manual}}
309 %
310 % \begin{declcs}{pdf@strcmp} \M{stringA} \M{stringB}
311 % \end{declcs}
312 % Same as |\pdfstrcmp{|\meta{stringA}|}{|\meta{stringB}|}|.
313 %
314 % \begin{declcs}{pdf@unescapehex} \M{string}
315 % \end{declcs}
316 % Same as |\pdfunescapehex{|\meta{string}|}|.
317 % The argument is a byte string given in hexadecimal notation.
318 % The result are character tokens from 0 until 255 with
319 % catcode 12 and the space with catcode 10.
320 %
321 % \begin{declcs}{pdf@escapehex} \M{string}\\
322 % \cs{pdf@escapestring} \M{string}\\
323 % \cs{pdf@escapename} \M{string}
324 % \end{declcs}
325 % Same as the primitives of \hologo{pdfTeX}. However \hologo{pdfTeX} does not
326 % know about characters with codes 256 and larger. Thus the
327 % string is treated as byte string, characters with more than
328 % eight bits are ignored.
329 %
330 % \subsubsection[Files]{Files \cite[``7.18 Files'']{pdftex-manual}}
331 %
332 % \begin{declcs}{pdf@filesize} \M{filename}
333 % \end{declcs}
334 % Same as |\pdffilesize{|\meta{filename}|}|.
335 %
336 % \begin{declcs}{pdf@filemoddate} \M{filename}
337 % \end{declcs}
338 % Same as |\pdffilemoddate{|\meta{filename}|}|.
339 %
340 % \begin{declcs}{pdf@filedump} \M{offset} \M{length} \M{filename}
341 % \end{declcs}
342 % Same as |\pdffiledump offset| \meta{offset} |length| \meta{length}
343 % |{|\meta{filename}|}|. Both \meta{offset} and \meta{length} must
344 % not be empty, but must be a valid \hologo{TeX} number.
345 %
346 % \begin{declcs}{pdf@mdfivesum} \M{string}
347 % \end{declcs}
348 % Same as |\pdfmdfivesum{|\meta{string}|}|. Keyword |file| is supported
349 % by macro \cs{pdf@filemdfivesum}.
350 %
351 % \begin{declcs}{pdf@filemdfivesum} \M{filename}
352 % \end{declcs}
353 % Same as |\pdfmdfivesum file{|\meta{filename}|}|.
354 %
355 % \subsubsection[Timekeeping]{Timekeeping \cite[``7.17 Timekeeping'']{pdftex-manual}}
356 %
357 % The timekeeping macros are based on Andy Thomas' work \cite{AndyThomas:Analog}.
358 %
359 % \begin{declcs}{pdf@resettimer}
360 % \end{declcs}
361 % Same as \cs{pdfresettimer}, it resets the internal timer.
362 %
363 % \begin{declcs}{pdf@elapsedtime}
364 % \end{declcs}
365 % Same as \cs{pdfelapsedtime}. It behaves like a read-only integer.
366 % For printing purposes it can be prefixed by \cs{the} or \cs{number}.
367 % It measures the time in scaled seconds (seconds multiplied with 65536)
368 % since the latest call of \cs{pdf@resettimer} or start of
369 % program/package. The resolution, the shortest time interval that
370 % can be measured, depends on the program and system.
371 % \begin{itemize}
372 % \item \hologo{pdfTeX} with |gettimeofday|: $\ge$ 1/65536\,s
373 % \item \hologo{pdfTeX} with |ftime|: $\ge$ 1\,ms
374 % \item \hologo{pdfTeX} with |time|: $\ge$ 1\,s
375 % \item \hologo{LuaTeX}: $\ge$ 10\,ms\\
376 % (|os.clock()| returns a float number with two decimal digits in
377 % \hologo{LuaTeX} beta-0.70.1-2011061416 (rev 4277)).
378 % \end{itemize}
379 %
380 % \subsubsection[Miscellaneous]{Miscellaneous \cite[``7.21 Miscellaneous'']{pdftex-manual}}
381 %
382 % \begin{declcs}{pdf@draftmode}
383 % \end{declcs}
384 % If the \TeX\ compiler knows \cs{pdfdraftmode} or \cs{draftmode}
385 % (\hologo{pdfTeX},
386 % \hologo{LuaTeX}), then \cs{pdf@draftmode} returns, whether
387 % this mode is enabled. The result is an implicit number:
388 % one means the draft mode is available and enabled.
389 % If the value is zero, then the mode is not active or
390 % \cs{pdfdraftmode} is not available.
391 % An explicit number is yielded by \cs{number}\cs{pdf@draftmode}.
392 % The macro cannot
393 % be used to change the mode, see \cs{pdf@setdraftmode}.
394 %
395 % \begin{declcs}{pdf@ifdraftmode} \M{true} \M{false}
396 % \end{declcs}
397 % If \cs{pdfdraftmode} is available and enabled, \meta{true} is
398 % called, otherwise \meta{false} is executed.
399 %
400 % \begin{declcs}{pdf@setdraftmode} \M{value}
401 % \end{declcs}
402 % Macro \cs{pdf@setdraftmode} expects the number zero or one as
403 % \meta{value}. Zero deactivates the mode and one enables the draft mode.
404 % The macro does not have an effect, if the feature \cs{pdfdraftmode} is not
405 % available.
406 %
407 % \begin{declcs}{pdf@shellescape}
408 % \end{declcs}
409 % Same as |\pdfshellescape|. It is or expands to |1| if external
410 % commands can be executed and |0| otherwise. In \hologo{pdfTeX} external
411 % commands must be enabled first by command line option or
412 % configuration option. In \hologo{LuaTeX} option |--safer| disables
413 % the execution of external commands.
414 %
415 % In \hologo{LuaTeX} before 0.68.0 \cs{pdf@shellescape} is not
416 % available due to a bug in |os.execute()|. The argumentless form
417 % crashes in some circumstances with segmentation fault.
418 % (It is fixed in version 0.68.0 or revision 4167 of \hologo{LuaTeX}.
419 % and packported to some version of 0.67.0).
420 %
421 % Hints for usage:
422 % \begin{itemize}
423 % \item Before its use \cs{pdf@shellescape} should be tested,
424 % whether it is available. Example with package \xpackage{ltxcmds}
425 % (loaded by package \xpackage{pdftexcmds}):
426 %\begin{quote}
427 %\begin{verbatim}
428 %\ltx@IfUndefined{pdf@shellescape}{%
429 % % \pdf@shellescape is undefined
430 %}{%
431 % % \pdf@shellescape is available
432 %}
433 %\end{verbatim}
434 %\end{quote}
435 % Use \cs{ltx@ifundefined} in expandable contexts.
436 % \item \cs{pdf@shellescape} might be a numerical constant,
437 % expands to the primitive, or expands to a plain number.
438 % Therefore use it in contexts where these differences does not matter.
439 % \item Use in comparisons, e.g.:
440 % \begin{quote}
441 % |\ifnum\pdf@shellescape=0 ...|
442 % \end{quote}
443 % \item Print the number: |\number\pdf@shellescape|
444 % \end{itemize}
445 %
446 % \begin{declcs}{pdf@system} \M{cmdline}
447 % \end{declcs}
448 % It is a wrapper for |\immediate\write18| in \hologo{pdfTeX} or
449 % |os.execute| in \hologo{LuaTeX}.
450 %
451 % In theory |os.execute|
452 % returns a status number. But its meaning is quite
453 % undefined. Are there some reliable properties?
454 % Does it make sense to provide an user interface to
455 % this status exit code?
456 %
457 % \begin{declcs}{pdf@primitive} \csi{cmd}
458 % \end{declcs}
459 % Same as \cs{pdfprimitive} in \hologo{pdfTeX} or \hologo{LuaTeX}.
460 % In \hologo{XeTeX} the
461 % primitive is called \cs{primitive}. Despite the current definition
462 % of the command \csi{cmd}, it's meaning as primitive is used.
463 %
464 % \begin{declcs}{pdf@ifprimitive} \csi{cmd}
465 % \end{declcs}
466 % Same as \cs{ifpdfprimitive} in \hologo{pdfTeX} or
467 % \hologo{LuaTeX}. \hologo{XeTeX} calls
468 % it \cs{ifprimitive}. It is a switch that checks if the command
469 % \csi{cmd} has it's primitive meaning.
470 %
471 % \subsubsection{Additional macro: \cs{pdf@isprimitive}}
472 %
473 % \begin{declcs}{pdf@isprimitive} \csi{cmd1} \csi{cmd2} \M{true} \M{false}
474 % \end{declcs}
475 % If \csi{cmd1} has the primitive meaning given by the primitive name
476 % of \csi{cmd2}, then the argument \meta{true} is executed, otherwise
477 % \meta{false}. The macro \cs{pdf@isprimitive} is expandable.
478 % Internally it checks the result of \cs{meaning} and is therefore
479 % available for all \hologo{TeX} variants, even the original \hologo{TeX}.
480 % Example with \hologo{LaTeX}:
481 %\begin{quote}
482 %\begin{verbatim}
483 %\makeatletter
484 %\pdf@isprimitive{@@input}{input}{%
485 % \typeout{\string\@@input\space is original\string\input}%
486 %}{%
487 % \typeout{Oops, \string\@@input\space is not the %
488 % original\string\input}%
489 %}
490 %\end{verbatim}
491 %\end{quote}
492 %
493 % \subsubsection{Experimental}
494 %
495 % \begin{declcs}{pdf@unescapehexnative} \M{string}\\
496 % \cs{pdf@escapehexnative} \M{string}\\
497 % \cs{pdf@escapenamenative} \M{string}\\
498 % \cs{pdf@mdfivesumnative} \M{string}
499 % \end{declcs}
500 % The variants without |native| in the macro name are supposed to
501 % be compatible with \hologo{pdfTeX}. However characters with more than
502 % eight bits are not supported and are ignored. If \hologo{LuaTeX} is
503 % running, then its UTF-8 coded strings are used. Thus the full
504 % unicode character range is supported. However the result
505 % differs from \hologo{pdfTeX} for characters with eight or more bits.
506 %
507 % \begin{declcs}{pdf@pipe} \M{cmdline}
508 % \end{declcs}
509 % It calls \meta{cmdline} and returns the output of the external
510 % program in the usual manner as byte string (catcode 12, space with
511 % catcode 10). The Lua documentation says, that the used |io.popen|
512 % may not be available on all platforms. Then macro \cs{pdf@pipe}
513 % is undefined.
514 %
515 % \StopEventually{
516 % }
517 %
518 % \section{Implementation}
519 %
520 % \begin{macrocode}
521 %<*package>
522 % \end{macrocode}
523 %
524 % \subsection{Reload check and package identification}
525 % Reload check, especially if the package is not used with \LaTeX.
526 % \begin{macrocode}
527 \begingroup\catcode61\catcode48\catcode32=10\relax%
528 \catcode13=5 % ^^M
529 \endlinechar=13 %
530 \catcode35=6 % #
531 \catcode39=12 % '
532 \catcode44=12 % ,
533 \catcode45=12 % -
534 \catcode46=12 % .
535 \catcode58=12 % :
536 \catcode64=11 % @
537 \catcode123=1 % {
538 \catcode125=2 % }
539 \expandafter\let\expandafter\x\csname [email protected]\endcsname
540 \ifx\x\relax % plain-TeX, first loading
541 \else
542 \def\empty{}%
543 \ifx\x\empty % LaTeX, first loading,
544 % variable is initialized, but \ProvidesPackage not yet seen
545 \else
546 \expandafter\ifx\csname PackageInfo\endcsname\relax
547 \def\x#1#2{%
548 \immediate\write-1{Package #1 Info: #2.}%
549 }%
550 \else
551 \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
552 \fi
553 \x{pdftexcmds}{The package is already loaded}%
554 \aftergroup\endinput
555 \fi
556 \fi
557 \endgroup%
558 % \end{macrocode}
559 % Package identification:
560 % \begin{macrocode}
561 \begingroup\catcode61\catcode48\catcode32=10\relax%
562 \catcode13=5 % ^^M
563 \endlinechar=13 %
564 \catcode35=6 % #
565 \catcode39=12 % '
566 \catcode40=12 % (
567 \catcode41=12 % )
568 \catcode44=12 % ,
569 \catcode45=12 % -
570 \catcode46=12 % .
571 \catcode47=12 % /
572 \catcode58=12 % :
573 \catcode64=11 % @
574 \catcode91=12 % [
575 \catcode93=12 % ]
576 \catcode123=1 % {
577 \catcode125=2 % }
578 \expandafter\ifx\csname ProvidesPackage\endcsname\relax
579 \def\x#1#2#3[#4]{\endgroup
580 \immediate\write-1{Package: #3 #4}%
581 \xdef#1{#4}%
582 }%
583 \else
584 \def\x#1#2[#3]{\endgroup
585 #2[{#3}]%
586 \ifx#1\@undefined
587 \xdef#1{#3}%
588 \fi
589 \ifx#1\relax
590 \xdef#1{#3}%
591 \fi
592 }%
593 \fi
594 \expandafter\x\csname [email protected]\endcsname
595 \ProvidesPackage{pdftexcmds}%
596 [2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO)]%
597 % \end{macrocode}
598 %
599 % \subsection{Catcodes}
600 %
601 % \begin{macrocode}
602 \begingroup\catcode61\catcode48\catcode32=10\relax%
603 \catcode13=5 % ^^M
604 \endlinechar=13 %
605 \catcode123=1 % {
606 \catcode125=2 % }
607 \catcode64=11 % @
608 \def\x{\endgroup
609 \expandafter\edef\csname pdftexcmds@AtEnd\endcsname{%
610 \endlinechar=\the\endlinechar\relax
611 \catcode13=\the\catcode13\relax
612 \catcode32=\the\catcode32\relax
613 \catcode35=\the\catcode35\relax
614 \catcode61=\the\catcode61\relax
615 \catcode64=\the\catcode64\relax
616 \catcode123=\the\catcode123\relax
617 \catcode125=\the\catcode125\relax
618 }%
619 }%
620 \x\catcode61\catcode48\catcode32=10\relax%
621 \catcode13=5 % ^^M
622 \endlinechar=13 %
623 \catcode35=6 % #
624 \catcode64=11 % @
625 \catcode123=1 % {
626 \catcode125=2 % }
627 \def\TMP@EnsureCode#1#2{%
628 \edef\pdftexcmds@AtEnd{%
629 \pdftexcmds@AtEnd
630 \catcode#1=\the\catcode#1\relax
631 }%
632 \catcode#1=#2\relax
633 }
634 \TMP@EnsureCode{0}{12}%
635 \TMP@EnsureCode{1}{12}%
636 \TMP@EnsureCode{2}{12}%
637 \TMP@EnsureCode{10}{12}% ^^J
638 \TMP@EnsureCode{33}{12}% !
639 \TMP@EnsureCode{34}{12}% "
640 \TMP@EnsureCode{38}{4}% &
641 \TMP@EnsureCode{39}{12}% '
642 \TMP@EnsureCode{40}{12}% (
643 \TMP@EnsureCode{41}{12}% )
644 \TMP@EnsureCode{42}{12}% *
645 \TMP@EnsureCode{43}{12}% +
646 \TMP@EnsureCode{44}{12}% ,
647 \TMP@EnsureCode{45}{12}% -
648 \TMP@EnsureCode{46}{12}% .
649 \TMP@EnsureCode{47}{12}% /
650 \TMP@EnsureCode{58}{12}% :
651 \TMP@EnsureCode{60}{12}% <
652 \TMP@EnsureCode{62}{12}% >
653 \TMP@EnsureCode{91}{12}% [
654 \TMP@EnsureCode{93}{12}% ]
655 \TMP@EnsureCode{94}{7}% ^ (superscript)
656 \TMP@EnsureCode{95}{12}% _ (other)
657 \TMP@EnsureCode{96}{12}% `
658 \TMP@EnsureCode{126}{12}% ~ (other)
659 \edef\pdftexcmds@AtEnd{%
660 \pdftexcmds@AtEnd
661 \escapechar=\number\escapechar\relax
662 \noexpand\endinput
663 }
664 \escapechar=92 %
665 % \end{macrocode}
666 %
667 % \subsection{Load packages}
668 %
669 % \begin{macrocode}
670 \begingroup\expandafter\expandafter\expandafter\endgroup
671 \expandafter\ifx\csname RequirePackage\endcsname\relax
672 \def\TMP@RequirePackage#1[#2]{%
673 \begingroup\expandafter\expandafter\expandafter\endgroup
674 \expandafter\ifx\csname ver@#1.sty\endcsname\relax
675 \input #1.sty\relax
676 \fi
677 }%
678 \TMP@RequirePackage{infwarerr}[2007/09/09]%
679 \TMP@RequirePackage{iftex}[2019/11/07]%%
680 \TMP@RequirePackage{ltxcmds}[2010/12/02]%
681 \else
682 \RequirePackage{infwarerr}[2007/09/09]%
683 \RequirePackage{iftex}[2019/11/07]%
684 \RequirePackage{ltxcmds}[2010/12/02]%
685 \fi
686 % \end{macrocode}
687 %
688 % \subsection{Without \hologo{LuaTeX}}
689 %
690 % \begin{macrocode}
691 \ifluatex
692 \ifcsname catcodetable@string\endcsname\else\input{ltluatex}\fi
693 \else
694 \def\pdftexcmds@nopdftex{%
695 \let\pdftexcmds@nopdftex\relax
696 }%
697 \def\pdftexcmds@temp#1{%
698 \begingroup\expandafter\expandafter\expandafter\endgroup
699 \expandafter\ifx\csname
700 \expandafter\ifx\csname pdf#1\endcsname\relax\else pdf\fi#1\endcsname\relax
701 \pdftexcmds@nopdftex
702 \else
703 \expandafter\def\csname pdf@#1\expandafter\endcsname
704 \expandafter{%
705 \csname\expandafter\ifx\csname pdf#1\endcsname\relax\else pdf\fi#1\endcsname
706 }%
707 \fi
708 }%
709 \pdftexcmds@temp{strcmp}%
710 \pdftexcmds@temp{escapehex}%
711 \let\pdf@escapehexnative\pdf@escapehex
712 \pdftexcmds@temp{unescapehex}%
713 \let\pdf@unescapehexnative\pdf@unescapehex
714 \pdftexcmds@temp{escapestring}%
715 \pdftexcmds@temp{escapename}%
716 \pdftexcmds@temp{filesize}%
717 \pdftexcmds@temp{filemoddate}%
718 \begingroup\expandafter\expandafter\expandafter\endgroup
719 \expandafter\ifx\csname pdfshellescape\endcsname\relax
720 \pdftexcmds@nopdftex
721 \ltx@IfUndefined{pdftexversion}{%
722 }{%
723 \ifnum\pdftexversion>120 % 1.21a supports \ifeof18
724 \ifeof18 %
725 \chardef\pdf@shellescape=0 %
726 \else
727 \chardef\pdf@shellescape=1 %
728 \fi
729 \fi
730 }%
731 \else
732 \def\pdf@shellescape{%
733 \pdfshellescape
734 }%
735 \fi
736 \begingroup\expandafter\expandafter\expandafter\endgroup
737 \expandafter\ifx\csname pdffiledump\endcsname\relax
738 \pdftexcmds@nopdftex
739 \else
740 \def\pdf@filedump#1#2#3{%
741 \pdffiledump offset#1 length#2{#3}%
742 }%
743 \fi
744 % \end{macrocode}
745 % \begin{macrocode}
746 \begingroup\expandafter\expandafter\expandafter\endgroup
747 \expandafter\ifx\csname pdfmdfivesum\endcsname\relax
748 \begingroup\expandafter\expandafter\expandafter\endgroup
749 \expandafter\ifx\csname mdfivesum\endcsname\relax
750 \pdftexcmds@nopdftex
751 \else
752 \def\pdf@mdfivesum#{\mdfivesum}%
753 \let\pdf@mdfivesumnative\pdf@mdfivesum
754 \def\pdf@filemdfivesum#{\mdfivesum file}%
755 \fi
756 \else
757 \def\pdf@mdfivesum#{\pdfmdfivesum}%
758 \let\pdf@mdfivesumnative\pdf@mdfivesum
759 \def\pdf@filemdfivesum#{\pdfmdfivesum file}%
760 \fi
761 % \end{macrocode}
762 % \begin{macrocode}
763 \def\pdf@system#{%
764 \immediate\write18%
765 }%
766 \def\pdftexcmds@temp#1{%
767 \begingroup\expandafter\expandafter\expandafter\endgroup
768 \expandafter\ifx\csname
769 \expandafter\ifx\csname pdf#1\endcsname\relax\else pdf\fi#1\endcsname\relax
770 \pdftexcmds@nopdftex
771 \else
772 \begingroup\expandafter\expandafter\expandafter\endgroup
773 \expandafter\let\csname pdf@#1\expandafter\endcsname
774 \csname\expandafter\ifx\csname pdf#1\endcsname\relax\else pdf\fi#1\endcsname
775 \fi
776 }%
777 \pdftexcmds@temp{resettimer}%
778 \pdftexcmds@temp{elapsedtime}%
779 \fi
780 % \end{macrocode}
781 %
782 % \subsection{\cs{pdf@primitive}, \cs{pdf@ifprimitive}}
783 %
784 % Since version 1.40.0 \hologo{pdfTeX} has \cs{pdfprimitive} and
785 % \cs{ifpdfprimitive}. And \cs{pdfprimitive} was fixed in
786 % version 1.40.4.
787 %
788 % \hologo{XeTeX} provides them under the name \cs{primitive} and
789 % \cs{ifprimitive}. \hologo{LuaTeX} knows both name variants,
790 % but they have possibly to be enabled first (|tex.enableprimitives|).
791 %
792 % Depending on the format TeX Live uses a prefix |luatex|.
793 %
794 % Caution: \cs{let} must be used for the definition of
795 % the macros, especially because of \cs{ifpdfprimitive}.
796 %
797 % \subsubsection{Using \hologo{LuaTeX}'s \texttt{tex.enableprimitives}}
798 %
799 % \begin{macrocode}
800 \ifluatex
801 % \end{macrocode}
802 % \begin{macro}{\pdftexcmds@directlua}
803 % \begin{macrocode}
804 \ifnum\luatexversion<36 %
805 \def\pdftexcmds@directlua{\directlua0 }%
806 \else
807 \let\pdftexcmds@directlua\directlua
808 \fi
809 % \end{macrocode}
810 % \end{macro}
811 %
812 % \begin{macrocode}
813 \begingroup
814 \newlinechar=10 %
815 \endlinechar=\newlinechar
816 \pdftexcmds@directlua{%
817 if tex.enableprimitives then
818 tex.enableprimitives(
819 'pdf@',
820 {'primitive', 'ifprimitive', 'pdfdraftmode','draftmode'}
821 )
822 tex.enableprimitives('', {'luaescapestring'})
823 end
824 }%
825 \endgroup %
826 % \end{macrocode}
827 %
828 % \begin{macrocode}
829 \fi
830 % \end{macrocode}
831 %
832 % \subsubsection{Trying various names to find the primitives}
833 %
834 % \begin{macro}{\pdftexcmds@strip@prefix}
835 % \begin{macrocode}
836 \def\pdftexcmds@strip@prefix#1>{}
837 % \end{macrocode}
838 % \end{macro}
839 % \begin{macrocode}
840 \def\pdftexcmds@temp#1#2#3{%
841 \begingroup\expandafter\expandafter\expandafter\endgroup
842 \expandafter\ifx\csname pdf@#1\endcsname\relax
843 \begingroup
844 \def\x{#3}%
845 \edef\x{\expandafter\pdftexcmds@strip@prefix\meaning\x}%
846 \escapechar=-1 %
847 \edef\y{\expandafter\meaning\csname#2\endcsname}%
848 \expandafter\endgroup
849 \ifx\x\y
850 \expandafter\let\csname pdf@#1\expandafter\endcsname
851 \csname #2\endcsname
852 \fi
853 \fi
854 }
855 % \end{macrocode}
856 %
857 % \begin{macro}{\pdf@primitive}
858 % \begin{macrocode}
859 \pdftexcmds@temp{primitive}{pdfprimitive}{pdfprimitive}% pdfTeX, oldLuaTeX
860 \pdftexcmds@temp{primitive}{primitive}{primitive}% XeTeX, luatex
861 \pdftexcmds@temp{primitive}{luatexprimitive}{pdfprimitive}% oldLuaTeX
862 \pdftexcmds@temp{primitive}{luatexpdfprimitive}{pdfprimitive}% oldLuaTeX
863 % \end{macrocode}
864 % \end{macro}
865 % \begin{macro}{\pdf@ifprimitive}
866 % \begin{macrocode}
867 \pdftexcmds@temp{ifprimitive}{ifpdfprimitive}{ifpdfprimitive}% pdfTeX, oldLuaTeX
868 \pdftexcmds@temp{ifprimitive}{ifprimitive}{ifprimitive}% XeTeX, luatex
869 \pdftexcmds@temp{ifprimitive}{luatexifprimitive}{ifpdfprimitive}% oldLuaTeX
870 \pdftexcmds@temp{ifprimitive}{luatexifpdfprimitive}{ifpdfprimitive}% oldLuaTeX
871 % \end{macrocode}
872 % \end{macro}
873 %
874 % Disable broken \cs{pdfprimitive}.
875 % \begin{macrocode}
876 \ifluatex\else
877 \begingroup
878 \expandafter\ifx\csname pdf@primitive\endcsname\relax
879 \else
880 \expandafter\ifx\csname pdftexversion\endcsname\relax
881 \else
882 \ifnum\pdftexversion=140 %
883 \expandafter\ifx\csname pdftexrevision\endcsname\relax
884 \else
885 \ifnum\pdftexrevision<4 %
886 \endgroup
887 \let\pdf@primitive\@undefined
888 \@PackageInfoNoLine{pdftexcmds}{%
889 \string\pdf@primitive\space disabled, %
890 because\MessageBreak
891 \string\pdfprimitive\space is broken until pdfTeX 1.40.4%
892 }%
893 \begingroup
894 \fi
895 \fi
896 \fi
897 \fi
898 \fi
899 \endgroup
900 \fi
901 % \end{macrocode}
902 %
903 % \subsubsection{Result}
904 %
905 % \begin{macrocode}
906 \begingroup
907 \@PackageInfoNoLine{pdftexcmds}{%
908 \string\pdf@primitive\space is %
909 \expandafter\ifx\csname pdf@primitive\endcsname\relax not \fi
910 available%
911 }%
912 \@PackageInfoNoLine{pdftexcmds}{%
913 \string\pdf@ifprimitive\space is %
914 \expandafter\ifx\csname pdf@ifprimitive\endcsname\relax not \fi
915 available%
916 }%
917 \endgroup
918 % \end{macrocode}
919 %
920 % \subsection{\hologo{XeTeX}}
921 %
922 % Look for primitives \cs{shellescape}, \cs{strcmp}.
923 % \begin{macrocode}
924 \def\pdftexcmds@temp#1{%
925 \begingroup\expandafter\expandafter\expandafter\endgroup
926 \expandafter\ifx\csname pdf@#1\endcsname\relax
927 \begingroup
928 \escapechar=-1 %
929 \edef\x{\expandafter\meaning\csname#1\endcsname}%
930 \def\y{#1}%
931 \def\z##1->{}%
932 \edef\y{\expandafter\z\meaning\y}%
933 \expandafter\endgroup
934 \ifx\x\y
935 \expandafter\def\csname pdf@#1\expandafter\endcsname
936 \expandafter{%
937 \csname#1\endcsname
938 }%
939 \fi
940 \fi
941 }%
942 \pdftexcmds@temp{shellescape}%
943 \pdftexcmds@temp{strcmp}%
944 % \end{macrocode}
945 %
946 % \subsection{\cs{pdf@isprimitive}}
947 %
948 % \begin{macrocode}
949 \def\pdf@isprimitive{%
950 \begingroup\expandafter\expandafter\expandafter\endgroup
951 \expandafter\ifx\csname pdf@strcmp\endcsname\relax
952 \long\def\pdf@isprimitive##1{%
953 \expandafter\pdftexcmds@isprimitive\expandafter{\meaning##1}%
954 }%
955 \long\def\pdftexcmds@isprimitive##1##2{%
956 \expandafter\pdftexcmds@@isprimitive\expandafter{\string##2}{##1}%
957 }%
958 \def\pdftexcmds@@isprimitive##1##2{%
959 \ifnum0\pdftexcmds@equal##1\delimiter##2\delimiter=1 %
960 \expandafter\ltx@firstoftwo
961 \else
962 \expandafter\ltx@secondoftwo
963 \fi
964 }%
965 \def\pdftexcmds@equal##1##2\delimiter##3##4\delimiter{%
966 \ifx##1##3%
967 \ifx\relax##2##4\relax
968 1%
969 \else
970 \ifx\relax##2\relax
971 \else
972 \ifx\relax##4\relax
973 \else
974 \pdftexcmds@equalcont{##2}{##4}%
975 \fi
976 \fi
977 \fi
978 \fi
979 }%
980 \def\pdftexcmds@equalcont##1{%
981 \def\pdftexcmds@equalcont####1####2##1##1##1##1{%
982 ##1##1##1##1%
983 \pdftexcmds@equal####1\delimiter####2\delimiter
984 }%
985 }%
986 \expandafter\pdftexcmds@equalcont\csname fi\endcsname
987 \else
988 \long\def\pdf@isprimitive##1##2{%
989 \ifnum\pdf@strcmp{\meaning##1}{\string##2}=0 %
990 \expandafter\ltx@firstoftwo
991 \else
992 \expandafter\ltx@secondoftwo
993 \fi
994 }%
995 \fi
996 }
997 \ifluatex
998 \ifx\pdfdraftmode\@undefined
999 \let\pdfdraftmode\draftmode
1000 \fi
1001 \else
1002 \pdf@isprimitive
1003 \fi
1004 % \end{macrocode}
1005 %
1006 % \subsection{\cs{pdf@draftmode}}
1007 %
1008 %
1009 % \begin{macrocode}
1010 \let\pdftexcmds@temp\ltx@zero %
1011 \ltx@IfUndefined{pdfdraftmode}{%
1012 \@PackageInfoNoLine{pdftexcmds}{\ltx@backslashchar pdfdraftmode not found}%
1013 }{%
1014 \ifpdf
1015 \let\pdftexcmds@temp\ltx@one
1016 \@PackageInfoNoLine{pdftexcmds}{\ltx@backslashchar pdfdraftmode found}%
1017 \else
1018 \@PackageInfoNoLine{pdftexcmds}{%
1019 \ltx@backslashchar pdfdraftmode is ignored in DVI mode%
1020 }%
1021 \fi
1022 }
1023 \ifcase\pdftexcmds@temp
1024 % \end{macrocode}
1025 % \begin{macro}{\pdf@draftmode}
1026 % \begin{macrocode}
1027 \let\pdf@draftmode\ltx@zero
1028 % \end{macrocode}
1029 % \end{macro}
1030 % \begin{macro}{\pdf@ifdraftmode}
1031 % \begin{macrocode}
1032 \let\pdf@ifdraftmode\ltx@secondoftwo
1033 % \end{macrocode}
1034 % \end{macro}
1035 % \begin{macro}{\pdftexcmds@setdraftmode}
1036 % \begin{macrocode}
1037 \def\pdftexcmds@setdraftmode#1{}%
1038 % \end{macrocode}
1039 % \end{macro}
1040 % \begin{macrocode}
1041 \else
1042 % \end{macrocode}
1043 % \begin{macro}{\pdftexcmds@draftmode}
1044 % \begin{macrocode}
1045 \let\pdftexcmds@draftmode\pdfdraftmode
1046 % \end{macrocode}
1047 % \end{macro}
1048 % \begin{macro}{\pdf@ifdraftmode}
1049 % \begin{macrocode}
1050 \def\pdf@ifdraftmode{%
1051 \ifnum\pdftexcmds@draftmode=\ltx@one
1052 \expandafter\ltx@firstoftwo
1053 \else
1054 \expandafter\ltx@secondoftwo
1055 \fi
1056 }%
1057 % \end{macrocode}
1058 % \end{macro}
1059 % \begin{macro}{\pdf@draftmode}
1060 % \begin{macrocode}
1061 \def\pdf@draftmode{%
1062 \ifnum\pdftexcmds@draftmode=\ltx@one
1063 \expandafter\ltx@one
1064 \else
1065 \expandafter\ltx@zero
1066 \fi
1067 }%
1068 % \end{macrocode}
1069 % \end{macro}
1070 % \begin{macro}{\pdftexcmds@setdraftmode}
1071 % \begin{macrocode}
1072 \def\pdftexcmds@setdraftmode#1{%
1073 \pdftexcmds@draftmode=#1\relax
1074 }%
1075 % \end{macrocode}
1076 % \end{macro}
1077 % \begin{macrocode}
1078 \fi
1079 % \end{macrocode}
1080 % \begin{macro}{\pdf@setdraftmode}
1081 % \begin{macrocode}
1082 \def\pdf@setdraftmode#1{%
1083 \begingroup
1084 \count\ltx@cclv=#1\relax
1085 \edef\x{\endgroup
1086 \noexpand\pdftexcmds@@setdraftmode{\the\count\ltx@cclv}%
1087 }%
1088 \x
1089 }
1090 % \end{macrocode}
1091 % \end{macro}
1092 % \begin{macro}{\pdftexcmds@@setdraftmode}
1093 % \begin{macrocode}
1094 \def\pdftexcmds@@setdraftmode#1{%
1095 \ifcase#1 %
1096 \pdftexcmds@setdraftmode{#1}%
1097 \or
1098 \pdftexcmds@setdraftmode{#1}%
1099 \else
1100 \@PackageWarning{pdftexcmds}{%
1101 \string\pdf@setdraftmode: Ignoring\MessageBreak
1102 invalid value `#1'%
1103 }%
1104 \fi
1105 }
1106 % \end{macrocode}
1107 % \end{macro}
1108 %
1109 % \subsection{Load Lua module}
1110 %
1111 % \begin{macrocode}
1112 \ifluatex
1113 \else
1114 \expandafter\pdftexcmds@AtEnd
1115 \fi%
1116 % \end{macrocode}
1117 %
1118 % \begin{macrocode}
1119 \pdftexcmds@directlua{%
1120 require("pdftexcmds")%
1121 }
1122 \ifnum\luatexversion>37 %
1123 \ifnum0%
1124 \pdftexcmds@directlua{%
1125 if status.ini_version then %
1126 tex.write("1")%
1127 end%
1128 }>0 %
1129 \everyjob\expandafter{%
1130 \the\everyjob
1131 \pdftexcmds@directlua{%
1132 require("pdftexcmds")%
1133 }%
1134 }%
1135 \fi
1136 \fi
1137 \begingroup
1138 \def\x{2020-06-27 v0.33}%
1139 \ltx@onelevel@sanitize\x
1140 \edef\y{%
1141 \pdftexcmds@directlua{%
1142 if oberdiek.pdftexcmds.getversion then %
1143 oberdiek.pdftexcmds.getversion()%
1144 end%
1145 }%
1146 }%
1147 \ifx\x\y
1148 \else
1149 \@PackageError{pdftexcmds}{%
1150 Wrong version of lua module.\MessageBreak
1151 Package version: \x\MessageBreak
1152 Lua module: \y
1153 }\@ehc
1154 \fi
1155 \endgroup
1156 % \end{macrocode}
1157 %
1158 % \subsection{Lua functions}
1159 %
1160 % \subsubsection{Helper macros}
1161 %
1162 % \begin{macro}{\pdftexcmds@toks}
1163 % \begin{macrocode}
1164 \begingroup\expandafter\expandafter\expandafter\endgroup
1165 \expandafter\ifx\csname newtoks\endcsname\relax
1166 \toksdef\pdftexcmds@toks=0 %
1167 \else
1168 \csname newtoks\endcsname\pdftexcmds@toks
1169 \fi
1170 % \end{macrocode}
1171 % \end{macro}
1172 %
1173 % \begin{macro}{\pdftexcmds@Patch}
1174 % \begin{macrocode}
1175 \def\pdftexcmds@Patch{0}
1176 \ifnum\luatexversion>40 %
1177 \ifnum\luatexversion<66 %
1178 \def\pdftexcmds@Patch{1}%
1179 \fi
1180 \fi
1181 % \end{macrocode}
1182 % \end{macro}
1183 % \begin{macrocode}
1184 \ifcase\pdftexcmds@Patch
1185 \catcode`\&=14 %
1186 \else
1187 \catcode`\&=9 %
1188 % \end{macrocode}
1189 % \begin{macro}{\pdftexcmds@PatchDecode}
1190 % \begin{macrocode}
1191 \def\pdftexcmds@PatchDecode#1\@nil{%
1192 \pdftexcmds@DecodeA#1^^A^^A\@nil{}%
1193 }%
1194 % \end{macrocode}
1195 % \end{macro}
1196 % \begin{macro}{\pdftexcmds@DecodeA}
1197 % \begin{macrocode}
1198 \def\pdftexcmds@DecodeA#1^^A^^A#2\@nil#3{%
1199 \ifx\relax#2\relax
1200 \ltx@ReturnAfterElseFi{%
1201 \pdftexcmds@DecodeB#3#1^^A^^B\@nil{}%
1202 }%
1203 \else
1204 \ltx@ReturnAfterFi{%
1205 \pdftexcmds@DecodeA#2\@nil{#3#1^^@}%
1206 }%
1207 \fi
1208 }%
1209 % \end{macrocode}
1210 % \end{macro}
1211 % \begin{macro}{\pdftexcmds@DecodeB}
1212 % \begin{macrocode}
1213 \def\pdftexcmds@DecodeB#1^^A^^B#2\@nil#3{%
1214 \ifx\relax#2\relax%
1215 \ltx@ReturnAfterElseFi{%
1216 \ltx@zero
1217 #3#1%
1218 }%
1219 \else
1220 \ltx@ReturnAfterFi{%
1221 \pdftexcmds@DecodeB#2\@nil{#3#1^^A}%
1222 }%
1223 \fi
1224 }%
1225 % \end{macrocode}
1226 % \end{macro}
1227 % \begin{macrocode}
1228 \fi
1229 % \end{macrocode}
1230 %
1231 % \begin{macrocode}
1232 \ifnum\luatexversion<36 %
1233 \else
1234 \catcode`\0=9 %
1235 \fi
1236 % \end{macrocode}
1237 %
1238 % \subsubsection[Strings]{Strings \cite[``7.15 Strings'']{pdftex-manual}}
1239 %
1240 % \begin{macro}{\pdf@strcmp}
1241 % \begin{macrocode}
1242 \long\def\pdf@strcmp#1#2{%
1243 \directlua0{%
1244 oberdiek.pdftexcmds.strcmp("\luaescapestring{#1}",%
1245 "\luaescapestring{#2}")%
1246 }%
1247 }%
1248 % \end{macrocode}
1249 % \end{macro}
1250 % \begin{macrocode}
1251 \pdf@isprimitive
1252 % \end{macrocode}
1253 % \begin{macro}{\pdf@escapehex}
1254 % \begin{macrocode}
1255 \long\def\pdf@escapehex#1{%
1256 \directlua0{%
1257 oberdiek.pdftexcmds.escapehex("\luaescapestring{#1}", "byte")%
1258 }%
1259 }%
1260 % \end{macrocode}
1261 % \end{macro}
1262 % \begin{macro}{\pdf@escapehexnative}
1263 % \begin{macrocode}
1264 \long\def\pdf@escapehexnative#1{%
1265 \directlua0{%
1266 oberdiek.pdftexcmds.escapehex("\luaescapestring{#1}")%
1267 }%
1268 }%
1269 % \end{macrocode}
1270 % \end{macro}
1271 % \begin{macro}{\pdf@unescapehex}
1272 % \begin{macrocode}
1273 \def\pdf@unescapehex#1{%
1274 & \romannumeral\expandafter\pdftexcmds@PatchDecode
1275 \the\expandafter\pdftexcmds@toks
1276 \directlua0{%
1277 oberdiek.pdftexcmds.toks="pdftexcmds@toks"%
1278 oberdiek.pdftexcmds.unescapehex("\luaescapestring{#1}", "byte", \pdftexcmds@Patch)%
1279 }%
1280 & \@nil
1281 }%
1282 % \end{macrocode}
1283 % \end{macro}
1284 % \begin{macro}{\pdf@unescapehexnative}
1285 % \begin{macrocode}
1286 \def\pdf@unescapehexnative#1{%
1287 & \romannumeral\expandafter\pdftexcmds@PatchDecode
1288 \the\expandafter\pdftexcmds@toks
1289 \directlua0{%
1290 oberdiek.pdftexcmds.toks="pdftexcmds@toks"%
1291 oberdiek.pdftexcmds.unescapehex("\luaescapestring{#1}", \pdftexcmds@Patch)%
1292 }%
1293 & \@nil
1294 }%
1295 % \end{macrocode}
1296 % \end{macro}
1297 % \begin{macro}{\pdf@escapestring}
1298 % \begin{macrocode}
1299 \long\def\pdf@escapestring#1{%
1300 \directlua0{%
1301 oberdiek.pdftexcmds.escapestring("\luaescapestring{#1}")%
1302 }%
1303 }
1304 % \end{macrocode}
1305 % \end{macro}
1306 % \begin{macro}{\pdf@escapename}
1307 % \begin{macrocode}
1308 \long\def\pdf@escapename#1{%
1309 \directlua0{%
1310 oberdiek.pdftexcmds.escapename("\luaescapestring{#1}", "byte")%
1311 }%
1312 }
1313 % \end{macrocode}
1314 % \end{macro}
1315 % \begin{macro}{\pdf@escapenamenative}
1316 % \begin{macrocode}
1317 \long\def\pdf@escapenamenative#1{%
1318 \directlua0{%
1319 oberdiek.pdftexcmds.escapename("\luaescapestring{#1}")%
1320 }%
1321 }
1322 % \end{macrocode}
1323 % \end{macro}
1324 %
1325 % \subsubsection[Files]{Files \cite[``7.18 Files'']{pdftex-manual}}
1326 %
1327 % \begin{macro}{\pdf@filesize}
1328 % \begin{macrocode}
1329 \def\pdf@filesize#1{%
1330 \directlua0{%
1331 oberdiek.pdftexcmds.filesize("\luaescapestring{#1}")%
1332 }%
1333 }
1334 % \end{macrocode}
1335 % \end{macro}
1336 % \begin{macro}{\pdf@filemoddate}
1337 % \begin{macrocode}
1338 \def\pdf@filemoddate#1{%
1339 \directlua0{%
1340 oberdiek.pdftexcmds.filemoddate("\luaescapestring{#1}")%
1341 }%
1342 }
1343 % \end{macrocode}
1344 % \end{macro}
1345 % \begin{macro}{\pdf@filedump}
1346 % \begin{macrocode}
1347 \def\pdf@filedump#1#2#3{%
1348 \directlua0{%
1349 oberdiek.pdftexcmds.filedump("\luaescapestring{\number#1}",%
1350 "\luaescapestring{\number#2}",%
1351 "\luaescapestring{#3}")%
1352 }%
1353 }%
1354 % \end{macrocode}
1355 % \end{macro}
1356 % \begin{macro}{\pdf@mdfivesum}
1357 % \begin{macrocode}
1358 \long\def\pdf@mdfivesum#1{%
1359 \directlua0{%
1360 oberdiek.pdftexcmds.mdfivesum("\luaescapestring{#1}", "byte")%
1361 }%
1362 }%
1363 % \end{macrocode}
1364 % \end{macro}
1365 % \begin{macro}{\pdf@mdfivesumnative}
1366 % \begin{macrocode}
1367 \long\def\pdf@mdfivesumnative#1{%
1368 \directlua0{%
1369 oberdiek.pdftexcmds.mdfivesum("\luaescapestring{#1}")%
1370 }%
1371 }%
1372 % \end{macrocode}
1373 % \end{macro}
1374 % \begin{macro}{\pdf@filemdfivesum}
1375 % \begin{macrocode}
1376 \def\pdf@filemdfivesum#1{%
1377 \directlua0{%
1378 oberdiek.pdftexcmds.filemdfivesum("\luaescapestring{#1}")%
1379 }%
1380 }%
1381 % \end{macrocode}
1382 % \end{macro}
1383 %
1384 % \subsubsection[Timekeeping]{Timekeeping \cite[``7.17 Timekeeping'']{pdftex-manual}}
1385 %
1386 % \begin{macro}{\protected}
1387 % \begin{macrocode}
1388 \let\pdftexcmds@temp=Y%
1389 \begingroup\expandafter\expandafter\expandafter\endgroup
1390 \expandafter\ifx\csname protected\endcsname\relax
1391 \pdftexcmds@directlua0{%
1392 if tex.enableprimitives then %
1393 tex.enableprimitives('', {'protected'})%
1394 end%
1395 }%
1396 \fi
1397 \begingroup\expandafter\expandafter\expandafter\endgroup
1398 \expandafter\ifx\csname protected\endcsname\relax
1399 \let\pdftexcmds@temp=N%
1400 \fi
1401 % \end{macrocode}
1402 % \end{macro}
1403 % \begin{macro}{\numexpr}
1404 % \begin{macrocode}
1405 \begingroup\expandafter\expandafter\expandafter\endgroup
1406 \expandafter\ifx\csname numexpr\endcsname\relax
1407 \pdftexcmds@directlua0{%
1408 if tex.enableprimitives then %
1409 tex.enableprimitives('', {'numexpr'})%
1410 end%
1411 }%
1412 \fi
1413 \begingroup\expandafter\expandafter\expandafter\endgroup
1414 \expandafter\ifx\csname numexpr\endcsname\relax
1415 \let\pdftexcmds@temp=N%
1416 \fi
1417 % \end{macrocode}
1418 % \end{macro}
1419 %
1420 % \begin{macrocode}
1421 \ifx\pdftexcmds@temp N%
1422 \@PackageWarningNoLine{pdftexcmds}{%
1423 Definitions of \ltx@backslashchar pdf@resettimer and%
1424 \MessageBreak
1425 \ltx@backslashchar pdf@elapsedtime are skipped, because%
1426 \MessageBreak
1427 e-TeX's \ltx@backslashchar protected or %
1428 \ltx@backslashchar numexpr are missing%
1429 }%
1430 \else
1431 % \end{macrocode}
1432 %
1433 % \begin{macro}{\pdf@resettimer}
1434 % \begin{macrocode}
1435 \protected\def\pdf@resettimer{%
1436 \pdftexcmds@directlua0{%
1437 oberdiek.pdftexcmds.resettimer()%
1438 }%
1439 }%
1440 % \end{macrocode}
1441 % \end{macro}
1442 %
1443 % \begin{macro}{\pdf@elapsedtime}
1444 % \begin{macrocode}
1445 \protected\def\pdf@elapsedtime{%
1446 \numexpr
1447 \pdftexcmds@directlua0{%
1448 oberdiek.pdftexcmds.elapsedtime()%
1449 }%
1450 \relax
1451 }%
1452 % \end{macrocode}
1453 % \end{macro}
1454 % \begin{macrocode}
1455 \fi
1456 % \end{macrocode}
1457 %
1458 % \subsubsection{Shell escape}
1459 %
1460 % \begin{macro}{\pdf@shellescape}
1461 %
1462 % \begin{macrocode}
1463 \ifnum\luatexversion<68 %
1464 \else
1465 \protected\edef\pdf@shellescape{%
1466 \numexpr\directlua{tex.sprint(%
1467 \number\catcodetable@string,status.shell_escape)}\relax}
1468 \fi
1469 % \end{macrocode}
1470 % \end{macro}
1471 %
1472 % \begin{macro}{\pdf@system}
1473 % \begin{macrocode}
1474 \def\pdf@system#1{%
1475 \directlua0{%
1476 oberdiek.pdftexcmds.system("\luaescapestring{#1}")%
1477 }%
1478 }
1479 % \end{macrocode}
1480 % \end{macro}
1481 %
1482 % \begin{macro}{\pdf@lastsystemstatus}
1483 % \begin{macrocode}
1484 \def\pdf@lastsystemstatus{%
1485 \directlua0{%
1486 oberdiek.pdftexcmds.lastsystemstatus()%
1487 }%
1488 }
1489 % \end{macrocode}
1490 % \end{macro}
1491 % \begin{macro}{\pdf@lastsystemexit}
1492 % \begin{macrocode}
1493 \def\pdf@lastsystemexit{%
1494 \directlua0{%
1495 oberdiek.pdftexcmds.lastsystemexit()%
1496 }%
1497 }
1498 % \end{macrocode}
1499 % \end{macro}
1500 %
1501 % \begin{macrocode}
1502 \catcode`\0=12 %
1503 % \end{macrocode}
1504 %
1505 % \begin{macro}{\pdf@pipe}
1506 % Check availability of |io.popen| first.
1507 % \begin{macrocode}
1508 \ifnum0%
1509 \pdftexcmds@directlua{%
1510 if io.popen then %
1511 tex.write("1")%
1512 end%
1513 }%
1514 =1 %
1515 \def\pdf@pipe#1{%
1516 & \romannumeral\expandafter\pdftexcmds@PatchDecode
1517 \the\expandafter\pdftexcmds@toks
1518 \pdftexcmds@directlua{%
1519 oberdiek.pdftexcmds.toks="pdftexcmds@toks"%
1520 oberdiek.pdftexcmds.pipe("\luaescapestring{#1}", \pdftexcmds@Patch)%
1521 }%
1522 & \@nil
1523 }%
1524 \fi
1525 % \end{macrocode}
1526 % \end{macro}
1527 %
1528 % \begin{macrocode}
1529 \pdftexcmds@AtEnd%
1530 %</package>
1531 % \end{macrocode}
1532 %
1533 % \subsection{Lua module}
1534 %
1535 % \begin{macrocode}
1536 %<*lua>
1537 % \end{macrocode}
1538 %
1539 % \begin{macrocode}
1540 oberdiek = oberdiek or {}
1541 local pdftexcmds = oberdiek.pdftexcmds or {}
1542 oberdiek.pdftexcmds = pdftexcmds
1543 local systemexitstatus
1544 function pdftexcmds.getversion()
1545 tex.write("2020-06-27 v0.33")
1546 end
1547 % \end{macrocode}
1548 %
1549 % \subsubsection[Strings]{Strings \cite[``7.15 Strings'']{pdftex-manual}}
1550 %
1551 % \begin{macrocode}
1552 function pdftexcmds.strcmp(A, B)
1553 if A == B then
1554 tex.write("0")
1555 elseif A < B then
1556 tex.write("-1")
1557 else
1558 tex.write("1")
1559 end
1560 end
1561 local function utf8_to_byte(str)
1562 local i = 0
1563 local n = string.len(str)
1564 local t = {}
1565 while i < n do
1566 i = i + 1
1567 local a = string.byte(str, i)
1568 if a < 128 then
1569 table.insert(t, string.char(a))
1570 else
1571 if a >= 192 and i < n then
1572 i = i + 1
1573 local b = string.byte(str, i)
1574 if b < 128 or b >= 192 then
1575 i = i - 1
1576 elseif a == 194 then
1577 table.insert(t, string.char(b))
1578 elseif a == 195 then
1579 table.insert(t, string.char(b + 64))
1580 end
1581 end
1582 end
1583 end
1584 return table.concat(t)
1585 end
1586 function pdftexcmds.escapehex(str, mode)
1587 if mode == "byte" then
1588 str = utf8_to_byte(str)
1589 end
1590 tex.write((string.gsub(str, ".",
1591 function (ch)
1592 return string.format("%02X", string.byte(ch))
1593 end
1594 )))
1595 end
1596 % \end{macrocode}
1597 % See procedure |unescapehex| in file \xfile{utils.c} of \hologo{pdfTeX}.
1598 % Caution: |tex.write| ignores leading spaces.
1599 % \begin{macrocode}
1600 function pdftexcmds.unescapehex(str, mode, patch)
1601 local a = 0
1602 local first = true
1603 local result = {}
1604 for i = 1, string.len(str), 1 do
1605 local ch = string.byte(str, i)
1606 if ch >= 48 and ch <= 57 then
1607 ch = ch - 48
1608 elseif ch >= 65 and ch <= 70 then
1609 ch = ch - 55
1610 elseif ch >= 97 and ch <= 102 then
1611 ch = ch - 87
1612 else
1613 ch = nil
1614 end
1615 if ch then
1616 if first then
1617 a = ch * 16
1618 first = false
1619 else
1620 table.insert(result, a + ch)
1621 first = true
1622 end
1623 end
1624 end
1625 if not first then
1626 table.insert(result, a)
1627 end
1628 if patch == 1 then
1629 local temp = {}
1630 for i, a in ipairs(result) do
1631 if a == 0 then
1632 table.insert(temp, 1)
1633 table.insert(temp, 1)
1634 else
1635 if a == 1 then
1636 table.insert(temp, 1)
1637 table.insert(temp, 2)
1638 else
1639 table.insert(temp, a)
1640 end
1641 end
1642 end
1643 result = temp
1644 end
1645 if mode == "byte" then
1646 local utf8 = {}
1647 for i, a in ipairs(result) do
1648 if a < 128 then
1649 table.insert(utf8, a)
1650 else
1651 if a < 192 then
1652 table.insert(utf8, 194)
1653 a = a - 128
1654 else
1655 table.insert(utf8, 195)
1656 a = a - 192
1657 end
1658 table.insert(utf8, a + 128)
1659 end
1660 end
1661 result = utf8
1662 end
1663 % \end{macrocode}
1664 % this next line added for current luatex; this is the only
1665 % change in the file. eroux, 28apr13. (v 0.21)
1666 % \begin{macrocode}
1667 local unpack = _G["unpack"] or table.unpack
1668 tex.settoks(pdftexcmds.toks, string.char(unpack(result)))
1669 end
1670 % \end{macrocode}
1671 % See procedure |escapestring| in file \xfile{utils.c} of \hologo{pdfTeX}.
1672 % \begin{macrocode}
1673 function pdftexcmds.escapestring(str, mode)
1674 if mode == "byte" then
1675 str = utf8_to_byte(str)
1676 end
1677 tex.write((string.gsub(str, ".",
1678 function (ch)
1679 local b = string.byte(ch)
1680 if b < 33 or b > 126 then
1681 return string.format("\\%.3o", b)
1682 end
1683 if b == 40 or b == 41 or b == 92 then
1684 return "\\" .. ch
1685 end
1686 % \end{macrocode}
1687 % Lua 5.1 returns the match in case of return value |nil|.
1688 % \begin{macrocode}
1689 return nil
1690 end
1691 )))
1692 end
1693 % \end{macrocode}
1694 % See procedure |escapename| in file \xfile{utils.c} of \hologo{pdfTeX}.
1695 % \begin{macrocode}
1696 function pdftexcmds.escapename(str, mode)
1697 if mode == "byte" then
1698 str = utf8_to_byte(str)
1699 end
1700 tex.write((string.gsub(str, ".",
1701 function (ch)
1702 local b = string.byte(ch)
1703 if b == 0 then
1704 % \end{macrocode}
1705 % In Lua 5.0 |nil| could be used for the empty string,
1706 % But |nil| returns the match in Lua 5.1, thus we use
1707 % the empty string explicitly.
1708 % \begin{macrocode}
1709 return ""
1710 end
1711 if b <= 32 or b >= 127
1712 or b == 35 or b == 37 or b == 40 or b == 41
1713 or b == 47 or b == 60 or b == 62 or b == 91
1714 or b == 93 or b == 123 or b == 125 then
1715 return string.format("#%.2X", b)
1716 else
1717 % \end{macrocode}
1718 % Lua 5.1 returns the match in case of return value |nil|.
1719 % \begin{macrocode}
1720 return nil
1721 end
1722 end
1723 )))
1724 end
1725 % \end{macrocode}
1726 %
1727 % \subsubsection[Files]{Files \cite[``7.18 Files'']{pdftex-manual}}
1728 %
1729 % \begin{macrocode}
1730 function pdftexcmds.filesize(filename)
1731 local foundfile = kpse.find_file(filename, "tex", true)
1732 if foundfile then
1733 local size = lfs.attributes(foundfile, "size")
1734 if size then
1735 tex.write(size)
1736 end
1737 end
1738 end
1739 % \end{macrocode}
1740 % See procedure |makepdftime| in file \xfile{utils.c} of \hologo{pdfTeX}.
1741 % \begin{macrocode}
1742 function pdftexcmds.filemoddate(filename)
1743 local foundfile = kpse.find_file(filename, "tex", true)
1744 if foundfile then
1745 local date = lfs.attributes(foundfile, "modification")
1746 if date then
1747 local d = os.date("*t", date)
1748 if d.sec >= 60 then
1749 d.sec = 59
1750 end
1751 local u = os.date("!*t", date)
1752 local off = 60 * (d.hour - u.hour) + d.min - u.min
1753 if d.year ~= u.year then
1754 if d.year > u.year then
1755 off = off + 1440
1756 else
1757 off = off - 1440
1758 end
1759 elseif d.yday ~= u.yday then
1760 if d.yday > u.yday then
1761 off = off + 1440
1762 else
1763 off = off - 1440
1764 end
1765 end
1766 local timezone
1767 if off == 0 then
1768 timezone = "Z"
1769 else
1770 local hours = math.floor(off / 60)
1771 local mins = math.abs(off - hours * 60)
1772 timezone = string.format("%+03d'%02d'", hours, mins)
1773 end
1774 tex.write(string.format("D:%04d%02d%02d%02d%02d%02d%s",
1775 d.year, d.month, d.day, d.hour, d.min, d.sec, timezone))
1776 end
1777 end
1778 end
1779 function pdftexcmds.filedump(offset, length, filename)
1780 length = tonumber(length)
1781 if length and length > 0 then
1782 local foundfile = kpse.find_file(filename, "tex", true)
1783 if foundfile then
1784 offset = tonumber(offset)
1785 if not offset then
1786 offset = 0
1787 end
1788 local filehandle = io.open(foundfile, "rb")
1789 if filehandle then
1790 if offset > 0 then
1791 filehandle:seek("set", offset)
1792 end
1793 local dump = filehandle:read(length)
1794 pdftexcmds.escapehex(dump)
1795 filehandle:close()
1796 end
1797 end
1798 end
1799 end
1800 function pdftexcmds.mdfivesum(str, mode)
1801 if mode == "byte" then
1802 str = utf8_to_byte(str)
1803 end
1804 pdftexcmds.escapehex(md5.sum(str))
1805 end
1806 function pdftexcmds.filemdfivesum(filename)
1807 local foundfile = kpse.find_file(filename, "tex", true)
1808 if foundfile then
1809 local filehandle = io.open(foundfile, "rb")
1810 if filehandle then
1811 local contents = filehandle:read("*a")
1812 pdftexcmds.escapehex(md5.sum(contents))
1813 filehandle:close()
1814 end
1815 end
1816 end
1817 % \end{macrocode}
1818 %
1819 % \subsubsection[Timekeeping]{Timekeeping \cite[``7.17 Timekeeping'']{pdftex-manual}}
1820 %
1821 % The functions for timekeeping are based on
1822 % Andy Thomas' work \cite{AndyThomas:Analog}.
1823 % Changes:
1824 % \begin{itemize}
1825 % \item Overflow check is added.
1826 % \item |string.format| is used to avoid exponential number
1827 % representation for sure.
1828 % \item |tex.write| is used instead of |tex.print| to get
1829 % tokens with catcode 12 and without appended \cs{endlinechar}.
1830 % \end{itemize}
1831 % \begin{macrocode}
1832 local basetime = 0
1833 function pdftexcmds.resettimer()
1834 basetime = os.clock()
1835 end
1836 function pdftexcmds.elapsedtime()
1837 local val = (os.clock() - basetime) * 65536 + .5
1838 if val > 2147483647 then
1839 val = 2147483647
1840 end
1841 tex.write(string.format("%d", math.floor(val)))
1842 end
1843 % \end{macrocode}
1844 %
1845 % \subsubsection[Miscellaneous]{Miscellaneous \cite[``7.21 Miscellaneous'']{pdftex-manual}}
1846 %
1847 % \begin{macrocode}
1848 function pdftexcmds.shellescape()
1849 if os.execute then
1850 if status
1851 and status.luatex_version
1852 and status.luatex_version >= 68 then
1853 tex.write(os.execute())
1854 else
1855 local result = os.execute()
1856 if result == 0 then
1857 tex.write("0")
1858 else
1859 if result == nil then
1860 tex.write("0")
1861 else
1862 tex.write("1")
1863 end
1864 end
1865 end
1866 else
1867 tex.write("0")
1868 end
1869 end
1870 function pdftexcmds.system(cmdline)
1871 systemexitstatus = nil
1872 texio.write_nl("log", "system(" .. cmdline .. ") ")
1873 if os.execute then
1874 texio.write("log", "executed.")
1875 systemexitstatus = os.execute(cmdline)
1876 else
1877 texio.write("log", "disabled.")
1878 end
1879 end
1880 function pdftexcmds.lastsystemstatus()
1881 local result = tonumber(systemexitstatus)
1882 if result then
1883 local x = math.floor(result / 256)
1884 tex.write(result - 256 * math.floor(result / 256))
1885 end
1886 end
1887 function pdftexcmds.lastsystemexit()
1888 local result = tonumber(systemexitstatus)
1889 if result then
1890 tex.write(math.floor(result / 256))
1891 end
1892 end
1893 function pdftexcmds.pipe(cmdline, patch)
1894 local result
1895 systemexitstatus = nil
1896 texio.write_nl("log", "pipe(" .. cmdline ..") ")
1897 if io.popen then
1898 texio.write("log", "executed.")
1899 local handle = io.popen(cmdline, "r")
1900 if handle then
1901 result = handle:read("*a")
1902 handle:close()
1903 end
1904 else
1905 texio.write("log", "disabled.")
1906 end
1907 if result then
1908 if patch == 1 then
1909 local temp = {}
1910 for i, a in ipairs(result) do
1911 if a == 0 then
1912 table.insert(temp, 1)
1913 table.insert(temp, 1)
1914 else
1915 if a == 1 then
1916 table.insert(temp, 1)
1917 table.insert(temp, 2)
1918 else
1919 table.insert(temp, a)
1920 end
1921 end
1922 end
1923 result = temp
1924 end
1925 tex.settoks(pdftexcmds.toks, result)
1926 else
1927 tex.settoks(pdftexcmds.toks, "")
1928 end
1929 end
1930 % \end{macrocode}
1931 % \begin{macrocode}
1932 %</lua>
1933 % \end{macrocode}
1934 % \section{Installation}
1935 %
1936 % \subsection{Download}
1937 %
1938 % \paragraph{Package.} This package is available on
1939 % CTAN\footnote{\CTANpkg{pdftexcmds}}:
1940 % \begin{description}
1941 % \item[\CTAN{macros/latex/contrib/pdftexcmds/pdftexcmds.dtx}] The source file.
1942 % \item[\CTAN{macros/latex/contrib/pdftexcmds/pdftexcmds.pdf}] Documentation.
1943 % \end{description}
1944 %
1945 % \subsection{Package installation}
1946 %
1947 % \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
1948 % \docstrip\ archive. The files are extracted by running the
1949 % \xfile{.dtx} through \plainTeX:
1950 % \begin{quote}
1951 % \verb|tex pdftexcmds.dtx|
1952 % \end{quote}
1953 %
1954 % \paragraph{TDS.} Now the different files must be moved into
1955 % the different directories in your installation TDS tree
1956 % (also known as \xfile{texmf} tree):
1957 % \begin{quote}
1958 % \def\t{^^A
1959 % \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
1960 % pdftexcmds.sty & tex/generic/pdftexcmds/pdftexcmds.sty\\
1961 % pdftexcmds.lua & tex/generic/pdftexcmds/pdftexcmds.lua\\
1962 % pdftexcmds.pdf & doc/latex/pdftexcmds/pdftexcmds.pdf\\
1963 % pdftexcmds.dtx & source/latex/pdftexcmds/pdftexcmds.dtx\\
1964 % \end{tabular}^^A
1965 % }^^A
1966 % \sbox0{\t}^^A
1967 % \ifdim\wd0>\linewidth
1968 % \begingroup
1969 % \advance\linewidth by\leftmargin
1970 % \advance\linewidth by\rightmargin
1971 % \edef\x{\endgroup
1972 % \def\noexpand\lw{\the\linewidth}^^A
1973 % }\x
1974 % \def\lwbox{^^A
1975 % \leavevmode
1976 % \hbox to \linewidth{^^A
1977 % \kern-\leftmargin\relax
1978 % \hss
1979 % \usebox0
1980 % \hss
1981 % \kern-\rightmargin\relax
1982 % }^^A
1983 % }^^A
1984 % \ifdim\wd0>\lw
1985 % \sbox0{\small\t}^^A
1986 % \ifdim\wd0>\linewidth
1987 % \ifdim\wd0>\lw
1988 % \sbox0{\footnotesize\t}^^A
1989 % \ifdim\wd0>\linewidth
1990 % \ifdim\wd0>\lw
1991 % \sbox0{\scriptsize\t}^^A
1992 % \ifdim\wd0>\linewidth
1993 % \ifdim\wd0>\lw
1994 % \sbox0{\tiny\t}^^A
1995 % \ifdim\wd0>\linewidth
1996 % \lwbox
1997 % \else
1998 % \usebox0
1999 % \fi
2000 % \else
2001 % \lwbox
2002 % \fi
2003 % \else
2004 % \usebox0
2005 % \fi
2006 % \else
2007 % \lwbox
2008 % \fi
2009 % \else
2010 % \usebox0
2011 % \fi
2012 % \else
2013 % \lwbox
2014 % \fi
2015 % \else
2016 % \usebox0
2017 % \fi
2018 % \else
2019 % \lwbox
2020 % \fi
2021 % \else
2022 % \usebox0
2023 % \fi
2024 % \end{quote}
2025 % If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
2026 % TDS installing feature, then some files can already be in the right
2027 % place, see the documentation of \docstrip.
2028 %
2029 % \subsection{Refresh file name databases}
2030 %
2031 % If your \TeX~distribution
2032 % (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh
2033 % these. For example, \TeX\,Live\ users run \verb|texhash| or
2034 % \verb|mktexlsr|.
2035 %
2036 % \subsection{Some details for the interested}
2037 %
2038 % \paragraph{Unpacking with \LaTeX.}
2039 % The \xfile{.dtx} chooses its action depending on the format:
2040 % \begin{description}
2041 % \item[\plainTeX:] Run \docstrip\ and extract the files.
2042 % \item[\LaTeX:] Generate the documentation.
2043 % \end{description}
2044 % If you insist on using \LaTeX\ for \docstrip\ (really,
2045 % \docstrip\ does not need \LaTeX), then inform the autodetect routine
2046 % about your intention:
2047 % \begin{quote}
2048 % \verb|latex \let\install=y\input{pdftexcmds.dtx}|
2049 % \end{quote}
2050 % Do not forget to quote the argument according to the demands
2051 % of your shell.
2052 %
2053 % \paragraph{Generating the documentation.}
2054 % You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
2055 % the documentation. The process can be configured by the
2056 % configuration file \xfile{ltxdoc.cfg}. For instance, put this
2057 % line into this file, if you want to have A4 as paper format:
2058 % \begin{quote}
2059 % \verb|\PassOptionsToClass{a4paper}{article}|
2060 % \end{quote}
2061 % An example follows how to generate the
2062 % documentation with pdf\LaTeX:
2063 % \begin{quote}
2064 %\begin{verbatim}
2065 %pdflatex pdftexcmds.dtx
2066 %bibtex pdftexcmds.aux
2067 %makeindex -s gind.ist pdftexcmds.idx
2068 %pdflatex pdftexcmds.dtx
2069 %makeindex -s gind.ist pdftexcmds.idx
2070 %pdflatex pdftexcmds.dtx
2071 %\end{verbatim}
2072 % \end{quote}
2073 %
2074 % \printbibliography[
2075 % heading=bibnumbered,
2076 % ]
2077 %
2078 % \begin{History}
2079 % \begin{Version}{2007/11/11 v0.1}
2080 % \item
2081 % First version.
2082 % \end{Version}
2083 % \begin{Version}{2007/11/12 v0.2}
2084 % \item
2085 % Short description fixed.
2086 % \end{Version}
2087 % \begin{Version}{2007/12/12 v0.3}
2088 % \item
2089 % Organization of Lua code as module.
2090 % \end{Version}
2091 % \begin{Version}{2009/04/10 v0.4}
2092 % \item
2093 % Adaptation for syntax change of \cs{directlua} in
2094 % \hologo{LuaTeX} 0.36.
2095 % \end{Version}
2096 % \begin{Version}{2009/09/22 v0.5}
2097 % \item
2098 % \cs{pdf@primitive}, \cs{pdf@ifprimitive} added.
2099 % \item
2100 % \hologo{XeTeX}'s variants are detected for
2101 % \cs{pdf@shellescape}, \cs{pdf@strcmp}, \cs{pdf@primitive},
2102 % \cs{pdf@ifprimitive}.
2103 % \end{Version}
2104 % \begin{Version}{2009/09/23 v0.6}
2105 % \item
2106 % Macro \cs{pdf@isprimitive} added.
2107 % \end{Version}
2108 % \begin{Version}{2009/12/12 v0.7}
2109 % \item
2110 % Short info shortened.
2111 % \end{Version}
2112 % \begin{Version}{2010/03/01 v0.8}
2113 % \item
2114 % Required date for package \xpackage{ifluatex} updated.
2115 % \end{Version}
2116 % \begin{Version}{2010/04/01 v0.9}
2117 % \item
2118 % Use \cs{ifeof18} for defining \cs{pdf@shellescape} between
2119 % \hologo{pdfTeX} 1.21a (inclusive) and 1.30.0 (exclusive).
2120 % \end{Version}
2121 % \begin{Version}{2010/11/04 v0.10}
2122 % \item
2123 % \cs{pdf@draftmode}, \cs{pdf@ifdraftmode} and
2124 % \cs{pdf@setdraftmode} added.
2125 % \end{Version}
2126 % \begin{Version}{2010/11/11 v0.11}
2127 % \item
2128 % Missing \cs{RequirePackage} for package \xpackage{ifpdf} added.
2129 % \end{Version}
2130 % \begin{Version}{2011/01/30 v0.12}
2131 % \item
2132 % Already loaded package files are not input in \hologo{plainTeX}.
2133 % \end{Version}
2134 % \begin{Version}{2011/03/04 v0.13}
2135 % \item
2136 % Improved Lua function \texttt{shellescape} that also
2137 % uses the result of \texttt{os.execute()} (thanks to Philipp Stephani).
2138 % \end{Version}
2139 % \begin{Version}{2011/04/10 v0.14}
2140 % \item
2141 % Version check of loaded module added.
2142 % \item
2143 % Patch for bug in \hologo{LuaTeX} between 0.40.6 and 0.65 that
2144 % is fixed in revision 4096.
2145 % \end{Version}
2146 % \begin{Version}{2011/04/16 v0.15}
2147 % \item
2148 % \hologo{LuaTeX}: \cs{pdf@shellescape} is only supported
2149 % for version 0.70.0 and higher due to a bug, \texttt{os.execute()}
2150 % crashes in some circumstances. Fixed in \hologo{LuaTeX}
2151 % beta-0.70.0, revision 4167.
2152 % \end{Version}
2153 % \begin{Version}{2011/04/22 v0.16}
2154 % \item
2155 % Previous fix was not working due to a wrong catcode of digit
2156 % zero (due to easily support the old \cs{directlua0}).
2157 % The version border is lowered to 0.68, because some
2158 % beta-0.67.0 seems also to work.
2159 % \end{Version}
2160 % \begin{Version}{2011/06/29 v0.17}
2161 % \item
2162 % Documentation addition to \cs{pdf@shellescape}.
2163 % \end{Version}
2164 % \begin{Version}{2011/07/01 v0.18}
2165 % \item
2166 % Add Lua module loading in \cs{everyjob} for \hologo{iniTeX}
2167 % (\hologo{LuaTeX} only).
2168 % \end{Version}
2169 % \begin{Version}{2011/07/28 v0.19}
2170 % \item
2171 % Missing space in an info message added (Martin M\"unch).
2172 % \end{Version}
2173 % \begin{Version}{2011/11/29 v0.20}
2174 % \item
2175 % \cs{pdf@resettimer} and \cs{pdf@elapsedtime} added
2176 % (thanks Andy Thomas).
2177 % \end{Version}
2178 % \begin{Version}{2016/05/10 v0.21}
2179 % \item
2180 % local unpack added
2181 % (thanks \'{E}lie Roux).
2182 % \end{Version}
2183 % \begin{Version}{2016/05/21 v0.22}
2184 % \item
2185 % adjust \cs{textbackslas}h usage in bib file for biber bug.
2186 % \end{Version}
2187 % \begin{Version}{2016/10/02 v0.23}
2188 % \item
2189 % add file.close to lua filehandles (github pull request).
2190 % \end{Version}
2191 % \begin{Version}{2017/01/29 v0.24}
2192 % \item
2193 % Avoid loading luatex-loader for current luatex. (Use
2194 % pdftexcmds.lua not oberdiek.pdftexcmds.lua to simplify file
2195 % search with standard require)
2196 % \end{Version}
2197 % \begin{Version}{2017/03/19 v0.25}
2198 % \item
2199 % New \cs{pdf@shellescape} for Lua\TeX, see github issue 20.
2200 % \end{Version}
2201 % \begin{Version}{2018/01/21 v0.26}
2202 % \item
2203 % use rb not r mode for file open github issue 34.
2204 % \end{Version}
2205 % \begin{Version}{2018/01/30 v0.27}
2206 % \item
2207 % \cs{pdf@mdfivesum} for \hologo{XeTeX}
2208 % \end{Version}
2209 % \begin{Version}{2018/09/07 v0.28}
2210 % \item
2211 % Fix catcode regime in luatex sprint for \cs{pdf@shellescape} GH issue 45
2212 % \end{Version}
2213 % \begin{Version}{2018/09/10 v0.29}
2214 % \item
2215 % Actually do the fix described above in the code, not just document it.
2216 % \end{Version}
2217 % \begin{Version}{2019/07/25 v0.30}
2218 % \item
2219 % Remove uses of module function, see PR70
2220 % \end{Version}
2221 % \begin{Version}{2019/11/24 v0.31}
2222 % \item
2223 % Use \xpackage{iftex} directly rather than \xpackage{ifluatex} and \xpackage{ifpdf} wrappers.
2224 % \item detect \verb|\filmoddate| and other \hologo{XeTeX} commands.
2225 % \item Adjust \cs{pdf@escapestring} in \hologo{LuaTeX} to produce
2226 % the same as in \hologo{pdfTeX} in the 8bit
2227 % range and not drop all non ascii characters.
2228 % \end{Version}
2229 % \begin{Version}{2020-06-04 v0.32}
2230 % \item Updated pdftexcmds.elapsedtime to lua 5.3 (issue 4).
2231 % \end{Version}
2232 % \begin{Version}{2020-06-24 v0.33}
2233 % \item avoid that \cs{pdfelapsedtime} and \cs{pdfresettimer} are set to \cs{relax}
2234 % when using xelatex (issue 5).
2235 % \item load ltluatex when using plain so that the catcode tables are
2236 % available.
2237 % \end{Version}
2238 % \end{History}
2239 %
2240 % \PrintIndex
2241 %
2242 % \Finale
2243 \endinput