/
hyperref-generic.dtx
3606 lines (3519 loc) · 105 KB
/
hyperref-generic.dtx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
%% File: hyperref-generic.dtx
%
% Copyright (C) 2020 The LaTeX3 Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% http://www.latex-project.org/lppl.txt
%
% This file is part of the "pdfresources bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% The released version of this bundle is available from CTAN.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
% https://github.com/latex3/pdfresources
%
% for those people who are interested.
%
%<*driver>
\documentclass[full]{l3doc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% \title{^^A
% The \pkg{hyperref-generic} package \\ A generic driver for hyperref ^^A
% }
%
% \author{^^A
% The \LaTeX3 Project\thanks
% {^^A
% E-mail:
% \href{mailto:latex-team@latex-project.org}
% {latex-team@latex-project.org}^^A
% }^^A
% }
%
% \date{Released XXXX-XX-XX}
%
% \maketitle
% This package generates a generic driver for \pkg{hyperref} meant to be used
% with the new LaTeX PDF management code. Currently---until \pkg{hyperref} has been
% adapted to use this driver it has to be loaded with
% \begin{verbatim}
% \usepackage[customdriver=hgeneric-experimental]{hyperref}
% \end{verbatim}
% Both the name of the driver and the loading method will change.
%
% The generic driver can be used with pdflatex, lualatex, xelatex, latex with
% dvipdfmx, latex with dvips+ps2pdf. latex with dvips+distiller could work too
% but is untested.
%
% The driver requires the new PDF management code, so document wanting to use it should
% start like this
% \begin{verbatim}
% \RequirePackage{pdfmanagement} %loads the code
% \DeclareDocumentMetadata % activates it
% {
% % options
% % e.g. pdf version, backend:
% % pdfversion=1.7,
% % backend = dvipdfmx
% }
% \end{verbatim}
%
% \section{Differences}
% The new driver tries to be compatible with the current \pkg{hyperref} drivers
% but there are nevertheless differences. Some of them due to the still experimental
% status of the driver, others are design decision: one part of the project is
% to clean up and modernize the code.
%
% \subsection{Bookmark code}
% The driver doesn't contain code to handle bookmarks/outlines. Instead it forces
% the loading of the \pkg{bookmark} package. Currently this is done at the end of the preamble
% so if commands from \pkg{bookmark} are needed in the preamble the document
% still has to load it manually but this is subject to change.
%
% \subsection{PDF strings}
%
% \pkg{hyperref} use a command called \cs{pdfstringdef} to convert text input into
% something that both makes sense and is valid in a PDF string, e.g. in the bookmarks
% or in the info dictionary or as form field values.
%
% As the handling of the outlines are delegated to the \pkg{bookmark} package, they
% will for now still use \cs{pdfstringdef}, but all other strings produced by
% this driver will use a new method based on \cs{text_purify:n} and
% \cs{str_set_convert:Nnnn}. For normal text
% it shouldn't matter, but a variety of commands and math are handled differently.
% Like with \cs{pdfstringdef} they are a number of ways to adjust the outcome of
% \cs{text_purify:n}. These are described in the expl3 documentation interface3.pdf.
%
% Important differences here are
% \begin{itemize}
% \item \emph{This new method requires that files are utf8-encoded}
% (at least if non-ascii chars are used in for PDF strings).
% \item \emph{All} robust commands are removed, unless an equivalent has been
% declared.
% \item Currently the new method is much more silent: it doesn't warn like
% \pkg{hyperref} if it removes commands.
% \end{itemize}
% \subsection{Package options from hyperref}
% Only a few package options are recognized by the new driver currently
% as \pkg{hyperref} hasn't been adapted yet.
%
% Such options should be set with \cs{hypersetup} after
% the package has been loaded. This can also be the case for options which normally
% don't work in \cs{hypersetup}.
%
% Options that still must be set as package options are
% \begin{itemize}
% \item |pdfpagelabels| (a boolean)
% \end{itemize}
%
% \subsection{Draftmode}
% pdftex and other engines knows a
% draftmode and hyperref honors this in some places. The new
% driver ignores this, for example |pagelabels| are always created.
%
% \subsection{Dropped options}
% A number of options are ignored by this driver
% \begin{description}
% \item[pdfversion] The pdfversion should be set in \cs{DeclareDocumentMetadata}
% \item[breaklinks] The option does nothing sensible anyway (apart from triggering
% a warning). Currently with latex+dvips links can not be broken. But there is work
% in progress to change this.
% \item[unicode] This is always true.
% \item[pdfa] If this option is set to true \pkg{hyperref} normally checks and sets
% a small number of requirements for the PDF standard PDF/A.
% The key is ignored with this driver. Instead the wanted standard should be declared
% in \cs{DeclareDocumentMetadata}:
% \begin{verbatim}
% \DeclareDocumentMetadata{standard=A-2b}
% \end{verbatim}
% Currently |A-1b|, |A-2b|, |A-3b| can be set.
% The support for various requirements is still incomplete, but the parts that
% \pkg{hyperref} already checked are implemented:
% \begin{itemize}
% \item The |/F| key is added to links and Print is activated, Hidden, Invisible,
% NoView are deactivated.
% \item |/NeedAppearances| is suppressed
% \item Pushbuttons, which use the action |/S/JavaScript| are suppressed
% \item Resetbuttons, which use the action |/S/ResetForm| are suppressed Resetbutton
% \item In widget annotations, the /AA dictionary is suppressed.
% \end{itemize}
% \end{description}
% \subsection{Destinations}
% Destinations (sometimes call anchors in the \pkg{hyperref} documentation)
% are the places a link jumped too. Unlike the name may suggest they don't described
% an exact location in the PDF. Instead a destination contains a reference to
% a page along with an instruction how to display this page.
% The normally used \enquote{XYZ \textit{top left zoom}} for example instructs
% the viewer to show the page with the given \textit{zoom} and
% the top left corner at the \textit{top left} coordinates---which then gives
% the impression that there is an anchor at this position.
%
% From these instructions two |Fit| and |FitB| are absolute. All
% others take one (|FitH|, |FitV|, |FitBH|, |FitBV|)
% or more (|XYZ|, |FitR|) arguments. These arguments are normally
% coordinates, |XYZ| takes also a zoom factor. The coordinates are
% absolute coordinates in bp relative to the lower left corner
% of the PDF.
%
% With pdftex almost all instructions
% don't take an argument: The needed coordinate is instead calculated from the location
% the \cs{pdfdest} command is issued. So to get a specific coordinate one has to
% move the command to the right place. E.g.
% \begin{verbatim}
% \AddToHookNext{shipout/background}
% {\put(0,-\pdfpageheight+100bp){\pdfdest name{destA} FitH\relax}}
% \end{verbatim}
%
% Exceptions are the |XYZ| instruction, where pdftex accepts a keyword
% |zoom| followed by a zoom factor, and the |FitR| instruction
% which understands the keywords |width|, |height| and |depth|
% followed by a dimension, which is then used to calculate a rectangle relative to the
% current location. If no keywords are given the dimensions are taken from the surrounding
% box---which can also lead to zero sized areas.
%
% The manual of \pkg{hyperref} gives a bit the impression as if this
% coordinates can be set manually by the user but as described above this is
% mostly wrong: It is for normal destination only possible with a dvi-backend like
% dvips which make use of pdfmark.def. pdftex and luatex can use manual coordinates
% only for |pdfstartview| and |pdfremotestartview|
% As dvips was the first driver of \pkg{hyperref} the option |pdfview| was at first
% developed for it and then adapted to pdftex. But this had the effect that the handling
% of the option |pdfview| is inconsequent across the backend and engines:
% For example with |pdfview=FitH 100| pdftex ignores the
% number and calculates on its own, while dvips sets the coordinate to the absolute
% 100. The zoom factor of XYZ is not supported by the pdftex driver at all, and
% |FitR| only partially.
%
% The generic driver consolidate this but tries to stay compatible with the other
% drivers as far as possible.
% It also takes into account the |pdfview| and |pdfstartview| and |pdfremotestartview|
% have different requirements: While for the first relative coordinates are fine,
% for the two others absolute coordinates are more sensible.
%
% So with this driver the options
% |pdfview|, |pdfstartview| and |pdfremotestartview| take
% the following options:
% \begin{itemize}
% \item |Fit|, |FitB|, |FitH|, |FitV|,
% |FitBH|, |FitBV| which can be followed by a positive integer (separated by a space) or the
% keyword |null|.
% The number can be gives as a \meta{dimension expression} surrounded with
% \cs{hypercalcbp}. The driver redefines this command to use
% \cs{dim_to_decimal_in_bp:n}.
% \begin{itemize}
% \item |pdfview| will ignore the integer and any other arguments and calculate
% the expected coordinates as described above for pdftex with all
% supported engines and backends.
% \item |pdfstartview| and |pdfremotestartview| will pass the optional
% number or keyword after expansion as absolute coordinate. If needed they will
% extend them with |null|
% \end{itemize}
%
% \item |XYZ|. This can be followed (separated by spaces) by up to three
% positive integers or keywords |null| which are then taken as \textit{top left zoom}
% in this order. \textit{zoom} is a factor, so e.g. 0.5 will give a scaling of 50\%.
% \begin{itemize}
% \item |pdfview| will use the last value as \textit{zoom}, ignore all other values
% and calculate the expected coordinates as described above for pdftex with all
% supported engines and backends (this means it is possible to use |XYZ 2| to
% set a zoom of 200\%, it is not necessary to fill in dummy values.)
% \item |pdfstartview| and |pdfremotestartview| will pass the optional
% numbers or keyword after expansion as absolute coordinates and zoom.
% If needed they will extend them with |null|.
% \end{itemize}
% This new behaviour is in part incompatible with previous handling with the dvips driver.
%
%
% \item |FitR|.
% If no argument (separated by spaces) follows then
% |pdfview| will use with pdftex and luatex
% the automatic calculation of the coordinates from the encompassing box. With
% dvips and (x)dvipdfmx it will fall back to |Fit|.
% |pdfstartview| and |pdfremotestartview| will fallback to |Fit| too.
%
% If arguments (separated by spaces) follow they should be
% four numbers representing \texttt{left bottom right top}.
% \begin{itemize}\item
% |pdfview| will use the values to calculate coordinates relative to the current
% location. So |0 -100 200 400| will give a \enquote{box} of width 200bp,
% height 400bp and depth 100dp that the destination should encompass.
% Missing numbers will be set to 0. But one should be aware that is it is quite
% unpredicable how viewers which support |FitR| handles zero sizes.
%
% \item |pdfstartview| and |pdfremotestartview| will pass
% the values as absolute coordinates.
% \end{itemize}
% \end{itemize}
%
%
%^^A %% This is an adapted version of hluatex.def
%^^A %% meant to test the use of the commands
%^^A %% from pdfmanagement.sty
%^^A %%
%^^A %% drivers are loaded in line 4745 in hyperref.sty in a \Hy@AtEndOfPackage command.
%^^A %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%^^A %% list of new internal commands
%^^A %% __hyp_link_goto_begin:nw : start command for links to internal destination
%^^A %% replaces \find@pdflink
%^^A %% __hyp_link_goto_end:
%^^A %% __hyp_destination:n : sets an anchor, replaces \new@pdflink
%^^A %% \__hyp_PageLabels_gpush: : puts pagelabels in the catalog, used on every storing
%^^A %% PDF String (text)
%^^A %% *\@@_text_pdfstring:nnN : replaces Hy@pstringdef, converts #1 to pdfstring in encoding #2
%^^A %% and stores in N
%^^A %% Build with:
%^^A %% *\@@_text_purify:nN
%^^A %% *\@@_text_cleanup:N
%^^A %% *\@@_text_convert:nN
%^^A %%
%^^A %% Destinations (dest)
%^^A %% \l_@@_dest_box
%^^A %%
%^^A %% References (ref)
%^^A %% *\@@_ref_label:nn
%^^A %% *\@@_ref_if_exist:nn
%^^A %% *\@@_ref_check:nn
%^^A %% % helps to display key list messages
%^^A %% \@@_clist_display:n
%^^A %%
%^^A %% \__hyp_info_generate_addons: what did this do??
%^^A %%
%^^A %% \g__hyp_AcroForm_CoFields_prop
%^^A %% \g__hyp_AcroForm_Fields_prop
%^^A %%
%^^A %% \g_@@_dest_pdfstartpage_tl ,
%^^A %% \g_@@_dest_pdfstartview_tl ,
%^^A %% \l_@@_dest_pdfremotestartview_tl ,
%^^A
%^^A %% Constants
%^^A %% *\c_@@_map_annot_hyp_prop
%^^A %% *\c_@@_dest_undefined_tl
%^^A %% Temp variables
%^^A %% \l_@@_tmpa_seq
%^^A %% \l_@@_tmpa_box
%^^A %% \l_@@_tmpa_tl
%^^A %% \l_@@_tmpa_str
%^^A %% \l_@@_tmpa_int
%^^A %%
%^^A %% \l_@@_dest_name_tmpa_tl
%^^A %% \l_@@_uri_tmpa_tl
%^^A %% \l_@@_filename_tmpa_tl
%^^A %% \l_@@_para_tmpa_tl
%^^A %% \l_@@_text_tmpa_str
%^^A %% \g_@@_text_tmpa_str
%^^A %% \l_@@_CheckmarkYes_tl
%^^A %% \l_@@_CheckmarkOff_tl
%^^A %% \l_@@_RadioYes_tl
%^^A
%^^A %% \l_@@_dest_pdfview_tl
%^^A %% list of commands which probably will have to change
%^^A %% \Hy@EXPsetpdfborder
%^^A %% \Hy@EXPsetpdfhighlight
%^^A %% \Hy@EXPsetbordercolor
%^^A % % \hypupdateattribute
% \begin{macrocode}
%<*package>
%<@@=hyp>
% \end{macrocode}
% \begin{macrocode}
\ProvidesFile{hgeneric-experimental.def}
[2020/12/26 v0.71 %
Hyperref driver for luaTeX]
\RequirePackage{etoolbox} %why?
\RequirePackage{l3color}
% \end{macrocode}
%
% \section{messages}
% Redirect the message name:
% \begin{macrocode}
\ExplSyntaxOn
\prop_gput:Nnn \g_msg_module_name_prop { hyp }{ hyperref }
% \end{macrocode}
% At first a message for the testing of the resource management
% \begin{macrocode}
\msg_new:nnnn
{ hyp }
{ missing-resource-management }
{ The~PDF~resource~management~is~required~for~this~hyperref~driver! }
{
Activate~it~with \\
\tl_to_str:n{\RequirePackage{pdfmanagement}}\\
\tl_to_str:n{\DeclareDocumentMetadata{<options>}}\\
before~\tl_to_str:n{\documentclass}
}
% \end{macrocode}
% The pdfversion should be set in \cs{DeclareDocumentMetadata}
% \begin{macrocode}
\msg_new:nnnn
{ hyp }
{ pdfversion-disabled }
{
This~hyperref~driver~ignores~the~pdfversion~key!\\
Set~the~pdfversion~in~\token_to_str:N \DeclareDocumentMetadata
}
{
For example:\\
\tl_to_str:n
{
\DeclareDocumentMetadata { pdfversion=1.7 }
}
}
% \end{macrocode}
% pdf/A messages for fields, this will probably be moved to an external package
% \begin{macrocode}
\msg_new:nnn
{ hyp }
{ pdfa-no-push-button }
{ PDF/A:~Push~button~with~JavaScript~is~prohibited }
\msg_new:nnn
{ hyp }
{ pdfa-no-reset-button }
{ PDF/A:~Reset~action~is~prohibited }
% \end{macrocode}
% A message if the destination name is empty.
% \begin{macrocode}
\msg_new:nnn
{ hyp }
{ empty-destination-name }
{
Empty~destination~name,\\
using~`#1'
}
% \end{macrocode}
% A message if the destination check fails
% \begin{macrocode}
\msg_new:nnn
{ hyp }
{ invalid-destination-value }
{
Invalid~value~`#1'~of~`#2' \\
is~replaced~by~`Fit'~\msg_line_context:.
}
% \end{macrocode}
% Some options or values should not be used in older pdf versions
% \begin{macrocode}
\msg_new:nnn
{ hyp }
{ ignore-deprecated-or-unknown-option-in-pdf-version }
{
Option~`#1'~is~unknown~or~deprecated~in\\
pdf~version~#2.~Ignored.
}
\msg_new:nnn
{ hyp }
{ ignore-deprecated-or-unknown-value-in-pdf-version }
{
Value~`#1'~is~unknown~or~deprecated~in\\
pdf~version~#2.~Ignored.
}
\msg_new:nnn
{ hyp }
{ replace-deprecated-or-unknown-value-in-pdf-version }
{
Value~`#1'~is~unknown~or~deprecated~in\\
pdf~version~#2. Value~`#3'~is used instead.
}
% \end{macrocode}
% During development not all standard hyperref keys are known, this issues a warning
% for now:
% \begin{macrocode}
\msg_new:nnn
{ hyp }
{ unknown-key }
{
unknown~key~#2~of~module~’#1’~set~to~’#3’.
}
% \end{macrocode}
% There are a lot choice keys. This defines messages which shows the valid
% choices if a faulty one has been used:
% \begin{macrocode}
\cs_new:Npn \@@_clist_display:n #1 {*~#1\\}
\msg_new:nnn
{ hyp }
{ unknown-choice }
{
Value~'#3'~is~invalid~for~key~'#1'.\\
The~key~accepts~only~the~choices\\
\clist_map_function:nN { #2 }\@@_clist_display:n
}
\msg_new:nnn
{ hyp }
{ unknown-choice+empty }
{
Value~'#3'~is~invalid~for~key~'#1'.\\
The~key~accepts~only~the~choices\\
\clist_map_function:nN { #2 }\@@_clist_display:n
An~empty~value~removes~the~setting.
}
\msg_new:nnn
{ hyp }
{ no-bool }
{
Value~'#2'~is~invalid~for~key~'#1'.\\
The~key~accepts~only~the~choices\\
*~true\\
*~false \\
*~and~an~empty~value~which~removes~the~setting.\\
No~value~is~equivalent~to~using~`true`.
}
\ExplSyntaxOff
% \end{macrocode}
% \section{Overwriting/providing commands from hyperref}
% hyperref checks driver version, we need to suppress this during the development
% \begin{macrocode}
\chardef\Hy@VersionChecked=1 %don't check the version!
\ExplSyntaxOn
% \end{macrocode}
%
% We define a better (expandable) version of \cs{hypercalcbp}
% \begin{macro}{\hypercalcbp}
% \begin{macrocode}
\cs_set_eq:NN \hypercalcbp \dim_to_decimal_in_bp:n
% \end{macrocode}
% \end{macro}
% This is used as default file extension, should probably go into hyperref.
% \begin{macrocode}
\providecommand*{\XR@ext}{pdf} %
% \end{macrocode}
%
% This command must be provided for now, but they are unused by the driver:
% \begin{macrocode}
\tl_new:N\@pdfborder
\tl_new:N\@pdfborderstyle
% \end{macrocode}
%
% We force unicode as option. As bookmarks are still using \cs{pdfstringdef}
% we also need to load puenc.def.
% \begin{macrocode}
\HyPsd@LoadUnicode
\Hy@unicodetrue
\let\HyPsd@pdfencoding\HyPsd@pdfencoding@unicode
\Hy@DisableOption{unicode}
% \end{macrocode}
% The pdfversion should be set in \cs{DeclareDocumentMetadata} but we must
% copy it to the \pkg{hyperref} command:
% \begin{macrocode}
\cs_set_eq:NN \Hy@pdfminorversion \pdf_version_minor:
\cs_set_eq:NN \Hy@pdfmajorversion \pdf_version_major:
% \end{macrocode}
% \begin{macrocode}
\legacy_if:nT { Hy@ocgcolorlinks }
{
\pdf_version_compare:NnT < {1.5}
{
\msg_warning:nnnx
{ hyp }
{ ignore-deprecated-or-unknown-option-in-pdf-version }
{ ocgcolorlinks } { \pdf_version_major:.\pdf_version_minor: }
\Hy@ocgcolorlinksfalse
\Hy@DisableOption{ocgcolorlinks}
}
}
\legacy_if:nT { Hy@setpdfversion }
{
\msg_warning:nn { hyp }{ pdfversion-disabled }
}
\Hy@DisableOption{pdfversion}
% \end{macrocode}
% \section{Checks}
% The driver can not work properly if the pdfmanagement is not active,
% as keys need to write to the catalog and to info. But annotations
% and outlines should work.
% So should this be a fatal error?
% Should there be a difference between missing and inactive management?
% TODO
% \begin{macrocode}
\bool_lazy_and:nnF
{ \cs_if_exist_p:N \pdfmanagement_if_active_p: }{ \pdfmanagement_if_active_p: }
{ \msg_error:nn { hyp}{ missing-resource-management } }
% \end{macrocode}
% Outlines/bookmarks require the bookmark package.
% \begin{macrocode}
\AddToHook{begindocument/before}{\RequirePackage{bookmark}}
% \end{macrocode}
%
% \section{Reference and label commands}
% The code uses the l3ref-tmp package which
% must have been loaded as pdfmanagement is a requirement.
% The commands use after the module prefix always |_ref|.
%
% At first a label command which add the space commands from LaTeX:
% \begin{macrocode}
%
\cs_new_protected:Npn \@@_ref_label:nn #1 #2 %label/attributes
{
\@bsphack
\ref_label:nn{#1}{#2}
\@esphack
}
\cs_generate_variant:Nn \@@_ref_label:nn {en}
% \end{macrocode}
% This provides a condition which tests if a label/attribute combination is known
% \begin{macrocode}
\prg_new_eq_conditional:NNn \@@_ref_if_exist:nn \ref_if_exist:nn { p , T , F, TF }
\prg_generate_conditional_variant:Nnn \@@_ref_if_exist:nn {en} { p , T , F, TF }
% \end{macrocode}
% This checks if the label/attribute is known and issues a warning if not.
% It then also triggers the standard rerun message.
% \begin{macrocode}
\cs_new_protected:Npn \@@_ref_check:nn #1 #2 %label/attribute
{
\@@_ref_if_exist:nnF {#1}{#2}
{
\protect\G@refundefinedtrue
\@latex@warning
{
Reference~`\tl_to_str:n {#1}'~with~attribute~`\tl_to_str:n {#2}'~
on~page~\thepage~\space undefined
}
}
}
\cs_generate_variant:Nn \@@_ref_check:nn {en}
% \end{macrocode}
% This retrieves a value, it is a simple wrapper around the \cs{ref_value:nn}
% \begin{macrocode}
\cs_new:Npn \@@_ref_value:nn #1 #2
{
\ref_value:nn{#1}{#2}
}
\cs_generate_variant:Nn \@@_ref_value:nn {en}
% \end{macrocode}
%
% \section{Variables}
% \subsection{Private temporary variables}
% At first a few generic tmp variables
% \begin{variable}
% {
% \l_@@_tmpa_tl,
% \l_@@_tmpa_seq,
% \l_@@_tmpa_int,
% \l_@@_tmpa_box,
% \l_@@_tmpa_str,
% }
% \begin{macrocode}
\box_new:N \l_@@_tmpa_box
\tl_new:N \l_@@_tmpa_tl
\seq_new:N \l_@@_tmpa_seq
\int_new:N \l_@@_tmpa_int
\str_new:N \l_@@_tmpa_str
% \end{macrocode}
% \end{variable}
%
% A number of more specific tmp variables. These will perhaps disappear or change.
% \begin{variable}
% {
% \l_@@_dest_name_tmpa_tl,
% \l_@@_uri_tmpa_tl,
% \l_@@_filename_tmpa_tl,
% \l_@@_para_tmpa_tl
% \l_@@_text_tmpa_str
% \g_@@_text_tmpa_str
% }
% TODO: document and check use!
% \begin{macrocode}
\tl_new:N \l_@@_dest_name_tmpa_tl
\tl_new:N \l_@@_uri_tmpa_tl
\tl_new:N \l_@@_filename_tmpa_tl
\tl_new:N \l_@@_para_tmpa_tl
\str_new:N \l_@@_text_tmpa_str
\str_new:N \g_@@_text_tmpa_str
% \end{macrocode}
% \end{variable}
%
% \subsection{Constants}
% \begin{variable}
% { \c_@@_dest_undefined_tl }
% This variable is used if a destination name is empty.
% \begin{macrocode}
\tl_const:Nn \c_@@_dest_undefined_tl {UNDEFINED}
% \end{macrocode}
% \end{variable}
% \begin{variable}
% {
% \c_@@_map_annot_hyp_prop,
% \c_@@_map_hyp_annot_prop,
% }
% This constants holds the link types managed by hyperref
% along with a mapping from annot names to hyperref names and back.
% \begin{macrocode}
\prop_const_from_keyval:Nn \c_@@_map_annot_hyp_prop
{
URI = url,
GoTo = link,
GoToR = file,
Named = menu,
Launch= run
}
\prop_const_from_keyval:Nn \c_@@_map_hyp_annot_prop
{
url = URI,
link = GoTo,
file = GoToR,
menu = Named,
run = Launch
}
% \end{macrocode}
% \end{variable}
% \subsection{Variables}
% \begin{variable}
% {
% \g_@@_dest_pdfstartpage_tl ,
% \g_@@_dest_pdfstartview_tl ,
% \l_@@_dest_pdfremotestartview_tl ,
% }
% The first holds the (absolute) start page number,
% the other the startview instruction for the current and remote files.
% The instruction is in \enquote{PDF format} but without the leading slash!
% \begin{macrocode}
\tl_new:N \g_@@_dest_pdfstartpage_tl
\tl_new:N \g_@@_dest_pdfstartview_tl
\tl_new:N \l_@@_dest_pdfremotestartview_tl
% \end{macrocode}
% \end{variable}
%
% It is still unclear which str convert option is the best in the various
% places, so we use a variable to allow tests and perhaps external configuration.
% The \enquote{print} type should always have the delimiters.
% \begin{variable}
% {
% \l_@@_text_enc_uri_print_tl,
% \l_@@_text_enc_info_print_tl,
% \l_@@_text_enc_dest_tl,
% \l_@@_text_enc_dest_print_tl,
% \l_@@_text_enc_file_print_tl,
% \l_@@_text_enc_para_print_tl
% }
% \begin{macrocode}
\tl_new:N \l_@@_text_enc_uri_print_tl
\tl_new:N \l_@@_text_enc_info_print_tl
\tl_new:N \l_@@_text_enc_dest_tl
\tl_new:N \l_@@_text_enc_dest_print_tl
\tl_new:N \l_@@_text_enc_file_print_tl
\tl_new:N \l_@@_text_enc_para_print_tl
\tl_set:Nn \l_@@_text_enc_uri_print_tl {utf8/URIpdf-print}
\tl_set:Nn \l_@@_text_enc_info_print_tl {utf16/hex-print}
\tl_set:Nn \l_@@_text_enc_dest_tl {utf8/string}
\tl_set:Nn \l_@@_text_enc_dest_print_tl {utf8/string-print}
\tl_set:Nn \l_@@_text_enc_file_print_tl {utf8/string-print}
\tl_set:Nn \l_@@_text_enc_para_print_tl {utf8/string-print}
% \end{macrocode}
% \end{variable}
% \begin{variable}{\l_@@_dest_pdfview_tl}
% This hold the destination instructions in a format suitable for
% \cs{pdf_destination:nn}. The special value |fitrbox| indicates a boxed destination.
% \begin{macrocode}
\tl_new:N \l_@@_dest_pdfview_tl
% \end{macrocode}
% \end{variable}
%
% \subsection{Boxes}
% \begin{variable}{\l_@@_dest_box}
% This holds an (empty) box which is used to get the width for FitR destinations.
% \begin{macrocode}
\box_new:N \l_@@_dest_box
% \end{macrocode}
% \end{variable}
% \subsection{Regex}
% \begin{variable}{\c_@@_dest_startview_regex}
% This regex is used to extract the right arguments
% pdfstartview and pdfremotestartview. Their values is filled up with |null|
% and then the start extracted.
% \begin{macrocode}
\regex_const:Nn \c_@@_dest_startview_regex
{
\A\ *
(?:
(?:XYZ (?:\ +(?:(?:\d+|\d*\.\d+)|null)){3}\ )
|
(?:Fit\b|FitB\b)
|
(?:(?:FitH|FitV|FitBH|FitBV)(?:\ +(?:\d+|\d*\.\d+)|\ +null){1})
|
(?:FitR (?:\ +\d+|\ +\d*\.\d+){4}\ )
)
}
% \end{macrocode}
% \end{variable}
%
% \subsection{PDF dictionaries}
% \begin{variable}{l_@@_page/Trans}
% This dictionary is used for page transitions.
% \begin{macrocode}
\pdfdict_new:n {l_@@_page/Trans}
\pdfdict_put:nnn {l_@@_page/Trans}{Type}{/Trans}
% \end{macrocode}
% \end{variable}
% \section{PDF string conversion}
%
% This defines a command which is used to replace
% \cs{pdfstringdef}. This is probably temporary and will be adjusted or
% replaced if some more generic PDF string command/module exists.
% All commands here use the \enquote{submodule} name \texttt{text}.
% At first a hook for user additions:
% \begin{macrocode}
\hook_new:n {hyp/text/pdfstring}
% \end{macrocode}
% The first step to convert input in a PDF string is to purify it, that means
% to remove/expand commands. As the whole process is not expandable anyway we
% can use a protected command. The \enquote{output} is a string:
% \begin{macro}{\@@_text_purify:nN}
% \begin{macrocode}
\cs_new_protected:Npn \@@_text_purify:nN #1 #2 %#1 input, #2 str command
{
\str_set:Nx #2 {\text_purify:n { #1 } }
}
% \end{macrocode}
% \end{macro}
% The second step is to cleanup the output of the first step. This is a dummy
% currently. The argument should be a string variable.
% \begin{macro}{\@@_text_cleanup:N}
% \begin{macrocode}
\cs_new_protected:Npn \@@_text_cleanup:N #1
{
}
% \end{macrocode}
% \end{macro}
% The last step converts the string to a PDF encoding. As we have at least two
% targets (hex and literal) there is an argument. The conversion assumes
% utf8 input, it is based on cs{pdf_text_convert:nnN} in l3pdftools.
%
% \#2 is str variable,
% \#1 should be one of
% \begin{tabular}{ll}
% utf8/string-print & \texttt{(lit)} (utf8/string)\\
% utf8/string & \texttt{lit} (utf8/string)\\
% utf8/URIpdf-print & \texttt{(percent encoded url)}\\
% utf8/URIpdf & \texttt{percent encoded url}\\
% utf16/hex-print & \texttt{<HEX>} (utf16/hex)\\
% utf16/hex & \texttt{HEX} (utf16/hex)\\
% utf16/string_print & \texttt{(lit)} (utf16/string)\\
% utf16/string-lit & \texttt{lit} (utf16/string)
% \end{tabular}
% \begin{macro}{ \@@_text_convert:nN }
% \begin{macrocode}
\cs_new_protected:Npn \@@_text_convert:nN #1 #2
{
\pdf_text_convert:nVN { #1 } #2 #2
}
% \end{macrocode}
% \end{macro}
% This command combines everything.
% |#1|=input, |#2|= handler shortcut |#3|= output str variable
% The commands uses a group to locally set \cs{Hy@pdfstringtrue}
% so that \cs{texorpdfstring} works and other local settings can be done.
%
% \begin{macro}{ \@@_text_pdfstring:nnN }
% \begin{macrocode}
\cs_new_protected:Npn \@@_text_pdfstring:nnN #1 #2 #3
{
\group_begin:
\Hy@pdfstringtrue
\hook_use:n {hyp/text/pdfstring}
\@@_text_purify:nN { #1 } \l_@@_text_tmpa_str
\@@_text_cleanup:N \l_@@_text_tmpa_str
\@@_text_convert:nN { #2 } \l_@@_text_tmpa_str
\str_gset_eq:NN \g_@@_text_tmpa_str\l_@@_text_tmpa_str
\group_end:
\str_set_eq:NN #3 \g_@@_text_tmpa_str
}
\cs_generate_variant:Nn \@@_text_pdfstring:nnN {xnN,onN,xoN,ooN,noN}
% \end{macrocode}
% \end{macro}
% !!! temporary until all instances are gone
%^^A TODO check if the redefinition of |~| is needed (probably not)
%^^A \edef~{\string~}%
%^^A \char_set_catcode_other:N \~
%^^A \char_set_active_eq:NN \~ \c_tilde_str
%^^A \char_set_catcode_active:N \~
% \begin{macrocode}
\cs_new_protected:Npn\Hy@pstringdef #1 #2
{ \@@_text_pdfstring:xnN {#2} {utf8/string}#1 }
% \end{macrocode}
% This is a special version for info keys:
% \begin{macro}{ \@@_text_pdfstring_info:nN }
% \begin{macrocode}
\cs_new_protected:Npn \@@_text_pdfstring_info:nN #1 #2
{
\@@_text_pdfstring:noN { #1 }{ \l_@@_text_enc_info_print_tl } #2
}
% \end{macrocode}
% \end{macro}
% \section{Pagelabels}
% Page labels are representations of the page numbers in the PDF viewer. If the hyperref
% options |pdfpagelabels| is true (the default) roman numbers are e.g. shown as
% \enquote{ii (2/58)}. To do this the page ranges must be collected, if possible a prefix
% and the numbering of the counter must be identified and then written
% to the catalog.
%
% The current implementation in hyperref/hyperref drivers:
% \begin{description}
% \item[xetex:] hxetex.def, line 80-110\\
% |\HyPL@StorePageLabel| writes to the aux-file
% at begin document (after reading the aux)
% |\HyPL@SetPageLabels| is called (defined in hyperref.sty after the driver
% loading)
% which calls |\Hy@PutCatalog{/PageLabels<</Nums[\HyPL@Labels]>>}|
% \item[dvips:] identical to xetex, line 60 to 90 in pdfmark.def
% \item[dvipdfm:] identical to xetex
% \item[pdftex:] |\HyPL@StorePageLabel| stores in |\HyPL@Labels| in the first compilation
% In |\AtVeryEndDocument| |\HyPL@SetPageLabels| is called.
% \item[luatex] identical to pdftex
% \end{description}
%
% The code in \pkg{hyperref} inspects |\thepage| and tries to figure out
% the numbering system and the prefix. E.g. A-\arabic{page} is correctly split.
% If the counter can not be identified \pkg{hyperref} generates only /P entries with the
% whole content.
%
% The new implementation makes use of the pdf management: The relevant entry in the
% catalog is continuously updated and pushed out at the end of the document.
% This works (hopefully \ldots) with all drivers.
%
% We do not try to avoid the (in hyperref's wording)
% \enquote{useless} pagelabel entry
% |/PageLabels <</Nums[0<</S/D>>]>>|
% (but it would be possible), we also don't test for empty |\thepage|,
% \pkg{hyperref} seems to handle this fine and the pdf is valid.
%
% The code has to define |\Hy@PutCatalog| as we can't yet
% change code in hyperref. The switch for draftmode has been removed.
%
% \begin{macro}
% {
% \@@_PageLabels_gpush:,
% \Hy@PutCatalog,
% \HyPL@StorePageLabel
% }
% \begin{macrocode}
\cs_new_protected:Npn\@@_PageLabels_gpush:
{
\pdfmanagement_add:nnx {Catalog} {PageLabels}{<</Nums[\HyPL@Labels]>>}
}
\def\Hy@PutCatalog #1 {}
\legacy_if:nT { Hy@pdfpagelabels }
{
\cs_set_protected:Npn \HyPL@StorePageLabel #1
{
\tl_gput_right:Nx \HyPL@Labels { \the\Hy@abspage<<#1>> }
\@@_PageLabels_gpush:
}
}
% \end{macrocode}
% \end{macro}
% \section {Core Hyperref Commands}
% Every hyperref has to define eight core command:
% \begin{verbatim}
% \hyper@anchor
% \hyper@anchorstart
% \hyper@anchorend
% \hyper@link
% \hyper@linkstart
% \hyper@linkend
% \hyper@linkfile
% \hyper@linkurl
% \end{verbatim}
% \subsection{ Anchors / destinations}
% The first three commands are needed for \enquote{anchors}. At first
% the internal commands to create a destination. It uses
% |\Hy@WrapperDef| to make it babel safe, it is not clear if this is
% still need, but we leave if for now.
% \begin{macro}{ \@@_destination:n }
% \begin{macrocode}
\Hy@WrapperDef \@@_destination:n #1 % #1 is a destination name.
{
\mode_if_horizontal:T { \@savsf\spacefactor }
\Hy@SaveLastskip %defined in hyperref
\Hy@VerboseAnchor{#1} %defined in hyperref, for debugging
\@@_text_pdfstring:xoN
{ \HyperDestNameFilter{#1} }
{ \l_@@_text_enc_dest_tl }
\l_@@_tmpa_tl
\tl_if_eq:NnTF \l_@@_dest_pdfview_tl {fitrbox}
{
\vbox_to_zero:n
{
\smash
{
\hbox_to_zero:n
{
\exp_args:NV
\pdf_destination_box:nn
{ \l_@@_tmpa_tl }
{ \box_use:N \l_@@_dest_box }
\hss
}
}
}
}
{
\exp_args:NV
\pdf_destination:nf
{ \l_@@_tmpa_tl }
{ \l_@@_dest_pdfview_tl }
}
\Hy@RestoreLastskip %defined in hyperref
\mode_if_horizontal:T { \spacefactor\@savsf }
}
% \end{macrocode}
% \end{macro}
% This are the three destinations commands. They are modelled along the
% xetex version. It is not quite clear if really all three
% are needed for the backends supported by this driver, but changing the hyperref
% code would be difficult.
% \begin{macro}
% {
% \hyper@anchor,
% \hyper@anchorstart,
% \hyper@anchorend
% }
% \begin{macrocode}
\cs_new_protected:Npn \hyper@anchor #1
{