Debian Codegraph @

texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty

raw
1 %%
2 %% This is file `tagpdf-mc-code-generic.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% tagpdf-mc-generic.dtx (with options: `generic')
8 %%
9 %% Copyright (C) 2019-2025 Ulrike Fischer
10 %%
11 %% It may be distributed and/or modified under the conditions of
12 %% the LaTeX Project Public License (LPPL), either version 1.3c of
13 %% this license or (at your option) any later version. The latest
14 %% version of this license is in the file:
15 %%
16 %% https://www.latex-project.org/lppl.txt
17 %%
18 %% This file is part of the "tagpdf bundle" (The Work in LPPL)
19 %% and all files in that bundle must be distributed together.
20 %%
21 %% File: tagpdf-mc-generic.dtx
22 \ProvidesExplPackage {tagpdf-mc-code-generic} {2026-05-17} {1.0c}
23 {part of tagpdf - code related to marking chunks - generic mode}
24 \tl_new:N \l__tag_mc_ref_abspage_tl
25 \tl_new:N \l__tag_mc_tmpa_tl
26
27 \newmarks \g__tag_mc_marks
28 \seq_new:N \g__tag_mc_main_marks_seq
29 \seq_new:N \g__tag_mc_footnote_marks_seq
30 \seq_new:N \g__tag_mc_multicol_marks_seq
31 \cs_new_protected:Npn \tag_mc_new_stream:n #1
32 {
33 \seq_new:c { g__tag_mc_multicol_#1_seq }
34 }
35 \seq_new:N \l__tag_mc_firstmarks_seq
36 \seq_new:N \l__tag_mc_botmarks_seq
37 \cs_new_protected:Npn \__tag_mc_begin_marks:nn #1 #2 %#1 tag, #2 label
38 {
39 \tex_marks:D \g__tag_mc_marks
40 {
41 b-, %first of begin pair
42 \int_use:N\c@g__tag_MCID_abs_int, %mc-num
43 \g__tag_struct_stack_current_tl, %structure num
44 #1, %tag
45 \bool_if:NT \l__tag_mc_key_stash_bool{stash}, % stash info
46 #2, %label
47 }
48 \tex_marks:D \g__tag_mc_marks
49 {
50 b+, % second of begin pair
51 \int_use:N\c@g__tag_MCID_abs_int, %mc-num
52 \g__tag_struct_stack_current_tl, %structure num
53 #1, %tag
54 \bool_if:NT \l__tag_mc_key_stash_bool{stash}, % stash info
55 #2, %label
56 }
57 }
58 \cs_generate_variant:Nn \__tag_mc_begin_marks:nn {oo}
59 \cs_new_protected:Npn \__tag_mc_artifact_begin_marks:n #1 %#1 type
60 {
61 \tex_marks:D \g__tag_mc_marks
62 {
63 b-, %first of begin pair
64 \int_use:N\c@g__tag_MCID_abs_int, %mc-num
65 -1, %structure num
66 #1 %type
67 }
68 \tex_marks:D \g__tag_mc_marks
69 {
70 b+, %first of begin pair
71 \int_use:N\c@g__tag_MCID_abs_int, %mc-num
72 -1, %structure num
73 #1 %Type
74 }
75 }
76
77 \cs_new_protected:Npn \__tag_mc_end_marks:
78 {
79 \tex_marks:D \g__tag_mc_marks
80 {
81 e-, %first of end pair
82 \int_use:N\c@g__tag_MCID_abs_int, %mc-num
83 \g__tag_struct_stack_current_tl, %structure num
84 }
85 \tex_marks:D \g__tag_mc_marks
86 {
87 e+, %second of end pair
88 \int_use:N\c@g__tag_MCID_abs_int, %mc-num
89 \g__tag_struct_stack_current_tl, %structure num
90 }
91 }
92 \cs_new_protected:Npn \__tag_mc_disable_marks:
93 {
94 \cs_set_eq:NN \__tag_mc_begin_marks:nn \use_none:nn
95 \cs_set_eq:NN \__tag_mc_artifact_begin_marks:n \use_none:n
96 \cs_set_eq:NN \__tag_mc_end_marks: \prg_do_nothing:
97 }
98 \cs_new_protected:Npn \__tag_mc_get_marks:
99 {
100 \exp_args:NNe
101 \seq_set_from_clist:Nn \l__tag_mc_firstmarks_seq
102 { \tex_firstmarks:D \g__tag_mc_marks }
103 \exp_args:NNe
104 \seq_set_from_clist:Nn \l__tag_mc_botmarks_seq
105 { \tex_botmarks:D \g__tag_mc_marks }
106 }
107 \cs_new_protected:Npn \__tag_mc_store:nnn #1 #2 #3 %#1 mc-prev, #2 mc-num #3 structure-num
108 {
109 %\prop_show:N \g__tag_struct_cont_mc_prop
110 \prop_get:NnNTF \g__tag_struct_cont_mc_prop {#1} \l__tag_tmpa_tl
111 {
112 \prop_gput:Nne \g__tag_struct_cont_mc_prop {#1}{ \l__tag_tmpa_tl \__tag_struct_mcid_dict:n {#2}}
113 }
114 {
115 \prop_gput:Nne \g__tag_struct_cont_mc_prop {#1}{ \__tag_struct_mcid_dict:n {#2}}
116 }
117 \prop_gput:Nee \g__tag_mc_parenttree_prop
118 {#2}
119 {#3}
120 }
121 \cs_generate_variant:Nn \__tag_mc_store:nnn {eee}
122 \cs_new_protected:Npn \__tag_mc_insert_extra_tmb:n #1 % #1 stream: e.g. main or footnote
123 {
124 \__tag_check_typeout_v:n {=>~ first~ \seq_use:Nn \l__tag_mc_firstmarks_seq {,~}}
125 \__tag_check_typeout_v:n {=>~ bot~ \seq_use:Nn \l__tag_mc_botmarks_seq {,~}}
126 \__tag_check_if_mc_tmb_missing:TF
127 {
128 \__tag_check_typeout_v:n {=>~ TMB~ ~ missing~ --~ inserted}
129 %test if artifact
130 \int_compare:nNnTF { \seq_item:cn { g__tag_mc_#1_marks_seq } {3} } = {-1}
131 {
132 \tl_set:Ne \l__tag_tmpa_tl { \seq_item:cn { g__tag_mc_#1_marks_seq } {4} }
133 \__tag_mc_handle_artifact:N \l__tag_tmpa_tl
134 }
135 {
136 \exp_args:Ne
137 \__tag_mc_bdc_mcid:n
138 {
139 \seq_item:cn { g__tag_mc_#1_marks_seq } {4}
140 }
141 \str_if_eq:eeTF
142 {
143 \seq_item:cn { g__tag_mc_#1_marks_seq } {5}
144 }
145 {}
146 {
147 %store
148 \__tag_mc_store:eee
149 {
150 \seq_item:cn { g__tag_mc_#1_marks_seq } {2}
151 }
152 { \int_eval:n{\c@g__tag_MCID_abs_int} }
153 {
154 \seq_item:cn { g__tag_mc_#1_marks_seq } {3}
155 }
156 }
157 {
158 %stashed -> warning!!
159 }
160 }
161 }
162 {
163 \__tag_check_typeout_v:n {=>~ TMB~ not~ missing}
164 }
165 }
166
167 \cs_new_protected:Npn \__tag_mc_insert_extra_tme:n #1 % #1 stream, eg. main or footnote
168 {
169 \__tag_check_if_mc_tme_missing:TF
170 {
171 \__tag_check_typeout_v:n {=>~ TME~ ~ missing~ --~ inserted}
172 \__tag_mc_emc:
173 \seq_gset_eq:cN
174 { g__tag_mc_#1_marks_seq }
175 \l__tag_mc_botmarks_seq
176 }
177 {
178 \__tag_check_typeout_v:n {=>~ TME~ not~ missing}
179 }
180 }
181 \cs_new_protected:Npn\__tag_add_missing_mcs:Nn #1 #2 {
182 \vbadness \@M
183 \vfuzz \c_max_dim
184 \vbox_set_to_ht:Nnn #1 { \box_ht:N #1 } {
185 \hbox_set:Nn \l__tag_tmpa_box { \__tag_mc_insert_extra_tmb:n {#2} }
186 \hbox_set:Nn \l__tag_tmpb_box { \__tag_mc_insert_extra_tme:n {#2} }
187 \int_compare:nNnT {\l__tag_loglevel_int} > { 0 }
188 {
189 \seq_log:c { g__tag_mc_#2_marks_seq}
190 }
191 \box_set_ht:Nn \l__tag_tmpa_box \c_zero_dim
192 \box_set_dp:Nn \l__tag_tmpa_box \c_zero_dim
193 \box_set_ht:Nn \l__tag_tmpb_box \c_zero_dim
194 \box_set_dp:Nn \l__tag_tmpb_box { \box_dp:N #1 }
195 \boxmaxdepth \@maxdepth
196 \box_use_drop:N \l__tag_tmpa_box
197 \vbox_unpack_drop:N #1
198 \tex_kern:D -\box_dp:N \l__tag_tmpb_box
199 \nointerlineskip
200 \box_use_drop:N \l__tag_tmpb_box
201 }
202 }
203
204 \cs_new_protected:Npn \__tag_add_missing_mcs_to_stream:Nn #1#2
205 {
206 \__tag_check_if_active_mc:T {
207 \vbadness\maxdimen
208 \box_set_eq:NN \l__tag_tmpa_box #1
209 \vbox_set_split_to_ht:NNn \l__tag_tmpa_box \l__tag_tmpa_box \c_max_dim
210 \exp_args:NNe
211 \seq_set_from_clist:Nn \l__tag_mc_firstmarks_seq
212 { \tex_splitfirstmarks:D \g__tag_mc_marks }
213 \seq_if_empty:NTF \l__tag_mc_firstmarks_seq
214 {
215 \__tag_check_typeout_v:n
216 {
217 No~ marks~ so~ use~ saved~ bot~ mark:~
218 \seq_use:cn {g__tag_mc_#2_marks_seq} {,~} \iow_newline:
219 }
220 \seq_set_eq:Nc \l__tag_mc_firstmarks_seq {g__tag_mc_#2_marks_seq}
221 \seq_set_eq:NN \l__tag_mc_botmarks_seq \l__tag_mc_firstmarks_seq
222 }
223 {
224 \__tag_check_typeout_v:n
225 {
226 Pick~ up~ new~ bot~ mark!
227 }
228 \exp_args:NNe
229 \seq_set_from_clist:Nn \l__tag_mc_botmarks_seq
230 { \tex_splitbotmarks:D \g__tag_mc_marks }
231 }
232 \__tag_add_missing_mcs:Nn #1 {#2}
233 %%
234 \seq_gset_eq:cN {g__tag_mc_#2_marks_seq} \l__tag_mc_botmarks_seq
235 %%
236 }
237 }
238 \cs_set_eq:NN \tag_mc_add_missing_to_stream:Nn \__tag_add_missing_mcs_to_stream:Nn
239 \prg_new_conditional:Nnn \__tag_mc_if_in: {p,T,F,TF}
240 {
241 \bool_if:NTF \g__tag_in_mc_bool
242 { \prg_return_true: }
243 { \prg_return_false: }
244 }
245
246 \prg_new_eq_conditional:NNn \tag_mc_if_in: \__tag_mc_if_in: {p,T,F,TF}
247 \cs_set_eq:NN \__tag_mc_bmc:n \pdf_bmc:n
248 \cs_set_eq:NN \__tag_mc_emc: \pdf_emc:
249 \cs_set_eq:NN \__tag_mc_bdc:nn \pdf_bdc:nn
250 \cs_set_eq:NN \__tag_mc_bdc_shipout:ee \pdf_bdc_shipout:ee
251 \hook_gput_code:nnn {shipout/before}{tagpdf}{ \flag_clear:n { __tag/mcid } }
252 \cs_set_protected:Npn \__tag_mc_bdc_mcid:nn #1 #2
253 {
254 \int_gincr:N \c@g__tag_MCID_abs_int
255 \__tag_property_record:eo
256 {
257 mcid-\int_use:N \c@g__tag_MCID_abs_int
258 }
259 { \c__tag_property_mc_clist }
260 \__tag_mc_bdc_shipout:ee
261 {#1}
262 {
263 /MCID~\flag_height:n { __tag/mcid }
264 \flag_raise:n { __tag/mcid }~ #2
265 }
266 }
267 \cs_new_protected:Npn \__tag_mc_bdc_mcid:n #1
268 {
269 \__tag_mc_bdc_mcid:nn {#1} {}
270 }
271
272 \cs_new_protected:Npn \__tag_mc_handle_mcid:nn #1 #2 %#1 tag, #2 properties
273 {
274 \__tag_mc_bdc_mcid:nn {#1} {#2}
275 }
276
277 \cs_generate_variant:Nn \__tag_mc_handle_mcid:nn {oo}
278
279 \cs_new_protected:Npn \__tag_mc_handle_stash:n #1 %1 mcidnum
280 {
281 \__tag_check_mc_used:n {#1}
282 \__tag_struct_kid_mc_gput_right:nn
283 { \g__tag_struct_stack_current_tl }
284 {#1}
285 \prop_gput:Nee \g__tag_mc_parenttree_prop
286 {#1}
287 { \g__tag_struct_stack_current_tl }
288 }
289 \cs_generate_variant:Nn \__tag_mc_handle_stash:n { e }
290
291 \cs_new_protected:Npn \__tag_mc_bmc_artifact:
292 {
293 \__tag_mc_bmc:n {Artifact}
294 }
295 \cs_new_protected:Npn \__tag_mc_bmc_artifact:n #1
296 {
297 \__tag_mc_bdc:nn {Artifact}{/Type/#1}
298 }
299 \cs_new_protected:Npn \__tag_mc_handle_artifact:N #1
300 % #1 is a var containing the artifact type
301 {
302 \int_gincr:N \c@g__tag_MCID_abs_int
303 \tl_if_empty:NTF #1
304 { \__tag_mc_bmc_artifact: }
305 { \exp_args:No\__tag_mc_bmc_artifact:n {#1} }
306 }
307
308 \cs_new:Nn \__tag_get_data_mc_tag: { \g__tag_mc_key_tag_tl }
309 \cs_set_protected:Npn \tag_mc_begin:n #1 %#1 keyval
310 {
311 \__tag_check_if_active_mc:T
312 {
313 \group_begin: %hm
314 \__tag_check_mc_if_nested:
315 \bool_gset_true:N \g__tag_in_mc_bool
316 \tl_set_eq:NN \l__tag_mc_key_tag_tl \g__tag_struct_tag_tl
317 \tl_gset_eq:NN\g__tag_mc_key_tag_tl \g__tag_struct_tag_tl
318 \tl_if_empty:NTF\l__tag_mc_lang_tl
319 {
320 \keys_set:nn { __tag / mc }{ #1 }
321 }
322 {
323 \keys_set:nn { __tag / mc }{ lang=\l__tag_mc_lang_tl, #1 }
324 }
325 \bool_if:NTF \l__tag_mc_artifact_bool
326 { %handle artifact
327 \__tag_mc_handle_artifact:N \l__tag_mc_artifact_type_tl
328 \exp_args:No
329 \__tag_mc_artifact_begin_marks:n { \l__tag_mc_artifact_type_tl }
330 }
331 { %handle mcid type
332 \__tag_check_mc_tag:N \l__tag_mc_key_tag_tl
333 \__tag_mc_handle_mcid:oo
334 { \l__tag_mc_key_tag_tl }
335 { \l__tag_mc_key_properties_tl }
336 \__tag_mc_begin_marks:oo{\l__tag_mc_key_tag_tl}{\l__tag_mc_key_label_tl}
337 \tl_if_empty:NF {\l__tag_mc_key_label_tl}
338 {
339 \__tag_mc_handle_mc_label:e { \l__tag_mc_key_label_tl }
340 }
341 \bool_if:NF \l__tag_mc_key_stash_bool
342 {
343 \socket_use:nn{tag/check/parent-child}
344 {
345 \__tag_mc_check_parent_child:o
346 { \g__tag_struct_stack_current_tl }
347 }
348 \__tag_mc_handle_stash:e { \int_use:N \c@g__tag_MCID_abs_int }
349
350 }
351 }
352 \group_end:
353 }
354 }
355 \cs_set_protected:Nn \tag_mc_end:
356 {
357 \__tag_check_if_active_mc:T
358 {
359 \__tag_check_mc_if_open:
360 \bool_gset_false:N \g__tag_in_mc_bool
361 \tl_gset:Nn \g__tag_mc_key_tag_tl { }
362 \__tag_mc_emc:
363 \__tag_mc_end_marks:
364 }
365 }
366
367 \keys_define:nn { __tag / mc }
368 {
369 tag .code:n = % the name (H,P,Span) etc
370 {
371 \tl_set:Ne \l__tag_mc_key_tag_tl { #1 }
372 \tl_gset:Ne \g__tag_mc_key_tag_tl { #1 }
373 },
374 raw .code:n =
375 {
376 \tl_put_right:Ne \l__tag_mc_key_properties_tl { #1 }
377 },
378 alt .code:n = % Alt property
379 {
380 \str_set_convert:Noon
381 \l__tag_tmpa_str
382 { #1 }
383 { default }
384 { utf16/hex }
385 \tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< }
386 \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ }
387 },
388 alttext .meta:n = {alt=#1},
389 lang .code:n = % Lang property
390 {
391 \tl_put_right:Ne \l__tag_mc_key_properties_tl { /Lang~(#1) }
392 },
393 actualtext .code:n = % ActualText property
394 {
395 \tl_if_empty:oF{#1}
396 {
397 \str_set_convert:Noon
398 \l__tag_tmpa_str
399 { #1 }
400 { default }
401 { utf16/hex }
402 \tl_put_right:Nn \l__tag_mc_key_properties_tl { /ActualText~< }
403 \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ }
404 }
405 },
406 label .tl_set:N = \l__tag_mc_key_label_tl,
407 artifact .code:n =
408 {
409 \exp_args:Nne
410 \keys_set:nn
411 { __tag / mc }
412 { __artifact-bool, __artifact-type=#1 }
413 },
414 artifact .default:n = {notype}
415 }
416 %%
417 %%
418 %% End of file `tagpdf-mc-code-generic.sty'.