summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/tagpdfdocu-patches.sty
blob: 2032895ec2adc8a0337321f9dac904ad15000bf8 (plain)
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
\RequirePackage{expl3}[2018/06/14]
%\RequirePackage[enable-debug]{expl3}[2018/06/14]
\RequirePackage{xpatch}
\ProvidesExplPackage {tagpdfdocu-patches} {2019/10/15} {0.70}
 {patches/commands for the tagpdf documentation}

% to do : marginnote, perhaps the description macros ...
% to do: footnotes!
% printbibliography?

\newbibmacro*{begentry}{\tagstructbegin{tag=BibEntry}\tagmcbegin{tag=BibEntry}}
\newbibmacro*{finentry}{\finentry\tagmcend\tagstructend}

% hyperref
\@ifpackageloaded{hyperref}{%
\pdfstringdefDisableCommands{
 \let\tagstructbegin\@gobble
 \let\tagmcbegin\@gobble
 \let\tagmcend\relax
 \let\tagstructend\relax
}}{}

%%%%%
% Paragraphs
%%%%%

% we need a command which simply starts a paragraph \TagP^,
% a "continuation" variant which closes the previous paragraph (\TagP),
% and a final end.

\NewDocumentCommand\TagP{t{^}}
 {
  \tag_mc_if_in:T { \tag_mc_end: }
  \IfBooleanF{#1}
  {
    \tag_struct_end:
  }
  \tag_struct_begin:n{tag=P}
  \tag_mc_begin:n{tag=P}
 }
% close a mc and one structure

\NewDocumentCommand\TagPend{}
 {
  \tag_mc_if_in:T { \tag_mc_end: }
  \tag_struct_end:
 }


%%%%%
% maketitle
%%%%%
\tagpdfsetup{ add-new-tag=Title/H1 }

%%%%%
% tableofcontents
%%%%%

%Marking the toc entries
%around the whole entry so only structure:
\newcommand\tagscrtocentry[1]{\tag_struct_begin:n{tag=TOCI}#1\tag_struct_end:}

%leaf so structure and mc:
\newcommand\tagscrtocpagenumber[1]{%
 \tag_struct_begin:n{tag=Reference}%
 \tag_mc_begin:n{tag=Reference}%
 #1%
 \tag_mc_end:
 \tag_struct_end:}


\DeclareTOCStyleEntry[
   entryformat=\tagscrtocentry,
   pagenumberformat=\tagscrtocpagenumber]{tocline}{section}
\DeclareTOCStyleEntry[
   entryformat=\tagscrtocentry,
   pagenumberformat=\tagscrtocpagenumber]{tocline}{subsection}
\DeclareTOCStyleEntry[
   entryformat=\tagscrtocentry,
   pagenumberformat=\tagscrtocpagenumber]{tocline}{subsubsection}
\DeclareTOCStyleEntry[
   entryformat=\tagscrtocentry,
   pagenumberformat=\tagscrtocpagenumber]{tocline}{paragraph}



\renewcommand{\addtocentrydefault}[3]{%
 \Ifstr{#3}{}{}
   {%\
   \Ifstr{#2}{}
    {%
     \addcontentsline{toc}{#1}
      {%
       \protect\nonumberline
       \tagstructbegin{tag=P}%
       \tagmcbegin{tag=P}%
        #3%
       \tagmcend
       \tagstructend
      }%
    }%
    {%
    \addcontentsline{toc}{#1}{%
     \tagstructbegin{tag=Lbl}%
     \tagmcbegin{tag=Lbl}%
     \protect\numberline{#2}%
     \tagmcend\tagstructend
     \tagstructbegin{tag=P}%
     \tagmcbegin{tag=P}%
      #3%
     \tagmcend
     \tagstructend
     }%
    }%
   }}%

% the dots must be marked too

\renewcommand*{\TOCLineLeaderFill}[1][.]{
  \leaders\hbox{$\m@th
    \mkern \@dotsep mu\hbox{\tag_mc_begin:n{artifact}#1\tag_mc_end:}\mkern \@dotsep
    mu$}\hfill
}

%%%%%%%%%
% Sectioning commands
%%%%%%%%

\prop_new:N    \g_tag_section_level_prop
\prop_gput:Nnn \g_tag_section_level_prop {section}{H1}
\prop_gput:Nnn \g_tag_section_level_prop {subsection}{H2}
\prop_gput:Nnn \g_tag_section_level_prop {subsubsection}{H3}
\prop_gput:Nnn \g_tag_section_level_prop {paragraph}{H4}



%unnumbered sections level give an empty mc, need to think about it.
\renewcommand{\sectionlinesformat}[4]
 {
  \@hangfrom
   {\hskip #2
    \tagstructbegin{tag=\prop_item:Nn\g_tag_section_level_prop{#1}}
    \tl_if_empty:nF{#3}
    {
     \tag_mc_begin:n    {tag=\prop_item:Nn\g_tag_section_level_prop{#1}}
     #3
     \tag_mc_end:
    }
   }
   {\tag_mc_begin:n    {tag=\prop_item:Nn\g_tag_section_level_prop{#1}}
    #4
    \tag_mc_end:\tagstructend}%
 }

%minisec is simply P, H6 doesn't work ....
\cs_new:Nn \__tag_docu_tag_minisec:n
{
  \tag_struct_begin:n {tag=P}
  \tag_mc_begin:n{tag=P}
  #1
  \tag_mc_end:
  \tag_struct_end:
}

\addtokomafont{minisec}{\__tag_docu_tag_minisec:n}

\AfterTOCHead{\tag_struct_begin:n{tag=TOC}}
\AfterStartingTOC{\tag_struct_end:} %end TOC

%% list

\newcommand\tag@enit@format@preset[1]{%
  \tagstructbegin{tag=LI}%
  \tagstructbegin{tag=Lbl}%
  \tagmcbegin{tag=Lbl}%
  #1%
  \tagmcend
  \tagstructend %end Lbl
  \tagstructbegin{tag=LBody}}

\newcommand\meti{% end of \item
 \tagstructend %end of LBody
 \tagstructend %end of LI
}

\newcommand\Pmeti{% end of \item
 \TagPend      %end of P
 \tagstructend %end of LBody
 \tagstructend %end of LI
}

\ExplSyntaxOff
\xpatchcmd\enit@preset{\@firstofone}{\tag@enit@format@preset}{}{\fail}
\ExplSyntaxOn
\setlist{
    before*=\tagstructbegin{tag=L},
    after*={\tagstructend}}

% keys that overwrite \enit@format must be patched, eg like the follow
% the font key should be patched in a similar way
\enitkv@key{}{format}{% new enumitem don't use first argument
  \def\enit@format{%
   \tagstructbegin{tag=LI}%
   \tagstructbegin{tag=Lbl}%
   \tagmcbegin{tag=Lbl}%
   #1\tagmcend}}

 %%% hooks for links
 %%% attention, to get the order right, it is necessary currently to start a new
 %%% mc after a link! I'm not sure if this can/group be included in the hooks
 %%% grouping is a bit tricky ...
%\cs_if_exist:NT\hook_put_left:nnn
%{
% \hook_put_left:nnn
% { pdf }
% { annot/Link/URI_begin }
% {
%   \tag_struct_begin:n{tag=Link}
%   \tag_mc_begin:n{tag=Link}
% }

\cs_generate_variant:Nn \pdfannot_dict_put:nnn {nnx}
\hook_gput_code:nnn
  {pdfannot/link/URI/before}
  {tagpdf}
  {
    \tag_struct_begin:n{tag=Link}
    \tag_mc_begin:n{tag=Link}
    \pdfannot_dict_put:nnx
    {link/URI}
    { StructParent }
    { \int_use:N\c@g__tag_parenttree_obj_int }
  }

%\hook_put_right:nnn
% { pdf }
% { annot/Link/URI_end }
% {
%  \__tag_struct_finish_link:
%   \tag_mc_end:
%   \tag_struct_end:
% }
\hook_gput_code:nnn
  {pdfannot/link/URI/after}
  {tagpdf}
  {
    \__tag_struct_finish_link:
    \tag_mc_end:
    \tag_struct_end:
  }

%\hook_put_left:nnn
% { pdf }
% { annot/Link/GoTo_begin }
% {
%   \tag_struct_begin:n{tag=Link}
%   \tag_mc_begin:n{tag=Link}
% }

\hook_gput_code:nnn
  {pdfannot/link/GoTo/before}
  {tagpdf}
  {
    \tag_struct_begin:n{tag=Link}
    \tag_mc_begin:n{tag=Link}
    \pdfannot_dict_put:nnx
    {link/GoTo}
    { StructParent }
    { \int_use:N\c@g__tag_parenttree_obj_int }
  }




%\hook_put_right:nnn
% { pdf }
% { annot/link/GoTo_end }
% {
%  \__tag_struct_finish_link:
%  \tag_mc_end:
%  \tag_struct_end:
% }

\hook_gput_code:nnn
  {pdfannot/link/GoTo/after}
  {tagpdf}
  {
    \__tag_struct_finish_link:
    \tag_mc_end:
    \tag_struct_end:
  }
% "alternative descriptions " for PAX3. How to get better text here??
\pdfannot_dict_put:nnx
 {link/URI}
 { Contents }
 { (url) }

\pdfannot_dict_put:nnx
 {link/GoTo}
 { Contents }
 { (ref) }

\endinput