| 1 |
%% |
| 2 |
%% This is file `tagpdf-mc-code-lua.sty', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% tagpdf-mc-luacode.dtx (with options: `luamode') |
| 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-luacode.dtx |
| 22 |
\ProvidesExplPackage {tagpdf-mc-code-lua} {2026-05-17} {1.0c} |
| 23 |
{tagpdf - mc code only for the luamode } |
| 24 |
\hook_gput_code:nnn{begindocument}{tagpdf/mc} |
| 25 |
{ |
| 26 |
\bool_if:NT\g__tag_active_space_bool |
| 27 |
{ |
| 28 |
\lua_now:e |
| 29 |
{ |
| 30 |
if~luatexbase.callbacktypes.pre_shipout_filter~then~ |
| 31 |
luatexbase.add_to_callback("pre_shipout_filter", function(TAGBOX)~ |
| 32 |
ltx.__tag.func.space_chars_shipout(TAGBOX)~return~true~ |
| 33 |
end, "tagpdf")~ |
| 34 |
if~luatexbase.declare_callback_rule~then~ |
| 35 |
luatexbase.declare_callback_rule("pre_shipout_filter", "luaotfload.dvi", "after", "tagpdf") |
| 36 |
end~ |
| 37 |
end |
| 38 |
} |
| 39 |
\lua_now:e |
| 40 |
{ |
| 41 |
if~luatexbase.callbacktypes.pre_shipout_filter~then~ |
| 42 |
token.get_next()~ |
| 43 |
end |
| 44 |
}\@secondoftwo\@gobble |
| 45 |
{ |
| 46 |
\hook_gput_code:nnn{shipout/before}{tagpdf/lua} |
| 47 |
{ |
| 48 |
\lua_now:e |
| 49 |
{ ltx.__tag.func.space_chars_shipout (tex.box["ShipoutBox"]) } |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
\bool_if:NT\g__tag_active_mc_bool |
| 54 |
{ |
| 55 |
\lua_now:e |
| 56 |
{ |
| 57 |
if~luatexbase.callbacktypes.pre_shipout_filter~then~ |
| 58 |
luatexbase.add_to_callback("pre_shipout_filter", function(TAGBOX)~ |
| 59 |
ltx.__tag.func.mark_shipout(TAGBOX)~return~true~ |
| 60 |
end, "tagpdf")~ |
| 61 |
end |
| 62 |
} |
| 63 |
\lua_now:e |
| 64 |
{ |
| 65 |
if~luatexbase.callbacktypes.pre_shipout_filter~then~ |
| 66 |
token.get_next()~ |
| 67 |
end |
| 68 |
}\@secondoftwo\@gobble |
| 69 |
{ |
| 70 |
\hook_gput_code:nnn{shipout/before}{tagpdf/lua} |
| 71 |
{ |
| 72 |
\lua_now:e |
| 73 |
{ ltx.__tag.func.mark_shipout (tex.box["ShipoutBox"]) } |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
\cs_new_protected:Npn \__tag_add_missing_mcs_to_stream:Nn #1#2 {} |
| 79 |
\cs_set_eq:NN \tag_mc_add_missing_to_stream:Nn \__tag_add_missing_mcs_to_stream:Nn |
| 80 |
\cs_new_protected:Npn \tag_mc_new_stream:n #1 {} |
| 81 |
\prg_new_conditional:Nnn \__tag_mc_if_in: {p,T,F,TF} |
| 82 |
{ |
| 83 |
\int_compare:nNnTF |
| 84 |
{ -2147483647 } |
| 85 |
= |
| 86 |
{\lua_now:e |
| 87 |
{ |
| 88 |
tex.print(\int_use:N \c_document_cctab,tex.getattribute(luatexbase.attributes.g__tag_mc_type_attr)) |
| 89 |
} |
| 90 |
} |
| 91 |
{ \prg_return_false: } |
| 92 |
{ \prg_return_true: } |
| 93 |
} |
| 94 |
|
| 95 |
\prg_new_eq_conditional:NNn \tag_mc_if_in: \__tag_mc_if_in: {p,T,F,TF} |
| 96 |
\cs_new:Nn \__tag_mc_lua_set_mc_type_attr:n % #1 is a tag name |
| 97 |
{ |
| 98 |
%TODO ltx.__tag.func.get_num_from("#1") seems not to return a suitable number?? |
| 99 |
\tl_set:Ne\l__tag_tmpa_tl{\lua_now:e{ltx.__tag.func.output_num_from ("#1")} } |
| 100 |
\lua_now:e |
| 101 |
{ |
| 102 |
tex.setattribute |
| 103 |
( |
| 104 |
"global", |
| 105 |
luatexbase.attributes.g__tag_mc_type_attr, |
| 106 |
\l__tag_tmpa_tl |
| 107 |
) |
| 108 |
} |
| 109 |
\lua_now:e |
| 110 |
{ |
| 111 |
tex.setattribute |
| 112 |
( |
| 113 |
"global", |
| 114 |
luatexbase.attributes.g__tag_mc_cnt_attr, |
| 115 |
\__tag_get_mc_abs_cnt: |
| 116 |
) |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
\cs_generate_variant:Nn\__tag_mc_lua_set_mc_type_attr:n { o } |
| 121 |
|
| 122 |
\cs_new:Nn \__tag_mc_lua_unset_mc_type_attr: |
| 123 |
{ |
| 124 |
\lua_now:e |
| 125 |
{ |
| 126 |
tex.setattribute |
| 127 |
( |
| 128 |
"global", |
| 129 |
luatexbase.attributes.g__tag_mc_type_attr, |
| 130 |
-2147483647 |
| 131 |
) |
| 132 |
} |
| 133 |
\lua_now:e |
| 134 |
{ |
| 135 |
tex.setattribute |
| 136 |
( |
| 137 |
"global", |
| 138 |
luatexbase.attributes.g__tag_mc_cnt_attr, |
| 139 |
-2147483647 |
| 140 |
) |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
\cs_new:Nn \__tag_mc_insert_mcid_kids:n |
| 145 |
{ |
| 146 |
\lua_now:e { ltx.__tag.func.mc_insert_kids (#1,0) } |
| 147 |
} |
| 148 |
|
| 149 |
\cs_new:Nn \__tag_mc_insert_mcid_single_kids:n |
| 150 |
{ |
| 151 |
\lua_now:e {ltx.__tag.func.mc_insert_kids (#1,1) } |
| 152 |
} |
| 153 |
\cs_new_protected:Npn \__tag_mc_handle_stash:n #1 %1 mcidnum |
| 154 |
{ |
| 155 |
\__tag_check_mc_used:n { #1 } |
| 156 |
\seq_gput_right:cn % Don't fill a lua table due to the command in the item, |
| 157 |
% so use the kernel command |
| 158 |
{ g__tag_struct_kids_\g__tag_struct_stack_current_tl _seq } |
| 159 |
{ |
| 160 |
\__tag_mc_insert_mcid_kids:n {#1}% |
| 161 |
} |
| 162 |
\lua_now:e |
| 163 |
{ |
| 164 |
ltx.__tag.func.store_struct_mcabs |
| 165 |
( |
| 166 |
\g__tag_struct_stack_current_tl,#1 |
| 167 |
) |
| 168 |
} |
| 169 |
} |
| 170 |
\cs_generate_variant:Nn \__tag_mc_handle_stash:n { e } |
| 171 |
\cs_set_protected:Nn \tag_mc_begin:n |
| 172 |
{ |
| 173 |
\__tag_check_if_active_mc:T |
| 174 |
{ |
| 175 |
\group_begin: |
| 176 |
%\__tag_check_mc_if_nested: |
| 177 |
\bool_gset_true:N \g__tag_in_mc_bool |
| 178 |
\bool_set_false:N\l__tag_mc_artifact_bool |
| 179 |
\tl_clear:N \l__tag_mc_key_properties_tl |
| 180 |
\int_gincr:N \c@g__tag_MCID_abs_int |
| 181 |
\tl_set_eq:NN \l__tag_mc_key_tag_tl \g__tag_struct_tag_tl |
| 182 |
\tl_gset_eq:NN\g__tag_mc_key_tag_tl \g__tag_struct_tag_tl |
| 183 |
\lua_now:e |
| 184 |
{ |
| 185 |
ltx.__tag.func.store_mc_data(\__tag_get_mc_abs_cnt:,"tag","\g__tag_struct_tag_tl") |
| 186 |
} |
| 187 |
\tl_if_empty:NTF\l__tag_mc_lang_tl |
| 188 |
{ |
| 189 |
\keys_set:nn { __tag / mc }{ label={}, #1 } |
| 190 |
} |
| 191 |
{ |
| 192 |
\keys_set:nn { __tag / mc }{ label={},lang=\l__tag_mc_lang_tl, #1 } |
| 193 |
} |
| 194 |
%check that a tag or artifact has been used |
| 195 |
\__tag_check_mc_tag:N \l__tag_mc_key_tag_tl |
| 196 |
%set the attributes: |
| 197 |
\__tag_mc_lua_set_mc_type_attr:o { \l__tag_mc_key_tag_tl } |
| 198 |
\bool_if:NF \l__tag_mc_artifact_bool |
| 199 |
{ % store the absolute num name in a label: |
| 200 |
\tl_if_empty:NF {\l__tag_mc_key_label_tl} |
| 201 |
{ |
| 202 |
\__tag_mc_handle_mc_label:e { \l__tag_mc_key_label_tl } |
| 203 |
} |
| 204 |
% if not stashed record the absolute number |
| 205 |
\bool_if:NF \l__tag_mc_key_stash_bool |
| 206 |
{ |
| 207 |
\socket_use:nn{tag/check/parent-child} |
| 208 |
{ |
| 209 |
\__tag_mc_check_parent_child:o |
| 210 |
{ \g__tag_struct_stack_current_tl } |
| 211 |
} |
| 212 |
\__tag_mc_handle_stash:e { \__tag_get_mc_abs_cnt: } |
| 213 |
} |
| 214 |
} |
| 215 |
\group_end: |
| 216 |
} |
| 217 |
} |
| 218 |
\cs_set_protected:Nn \tag_mc_end: |
| 219 |
{ |
| 220 |
\__tag_check_if_active_mc:T |
| 221 |
{ |
| 222 |
%\__tag_check_mc_if_open: |
| 223 |
\bool_gset_false:N \g__tag_in_mc_bool |
| 224 |
\bool_set_false:N\l__tag_mc_artifact_bool |
| 225 |
\__tag_mc_lua_unset_mc_type_attr: |
| 226 |
\tl_set:Nn \l__tag_mc_key_tag_tl { } |
| 227 |
\tl_gset:Nn \g__tag_mc_key_tag_tl { } |
| 228 |
} |
| 229 |
} |
| 230 |
\cs_set_protected:Npn \tag_mc_reset_box:N #1 |
| 231 |
{ |
| 232 |
\lua_now:e |
| 233 |
{ |
| 234 |
local~type=tex.getattribute(luatexbase.attributes.g__tag_mc_type_attr) |
| 235 |
local~mc=tex.getattribute(luatexbase.attributes.g__tag_mc_cnt_attr) |
| 236 |
ltx.__tag.func.update_mc_attributes(tex.getbox(\int_use:N #1),mc,type) |
| 237 |
} |
| 238 |
} |
| 239 |
\cs_new:Npn \__tag_get_data_mc_tag: { \g__tag_mc_key_tag_tl } |
| 240 |
|
| 241 |
\keys_define:nn { __tag / mc } |
| 242 |
{ |
| 243 |
tag .code:n = % |
| 244 |
{ |
| 245 |
\tl_set:Ne \l__tag_mc_key_tag_tl { #1 } |
| 246 |
\tl_gset:Ne \g__tag_mc_key_tag_tl { #1 } |
| 247 |
\lua_now:e |
| 248 |
{ |
| 249 |
ltx.__tag.func.store_mc_data(\__tag_get_mc_abs_cnt:,"tag","#1") |
| 250 |
} |
| 251 |
}, |
| 252 |
raw .code:n = |
| 253 |
{ |
| 254 |
\tl_put_right:Ne \l__tag_mc_key_properties_tl { #1 } |
| 255 |
\lua_now:e |
| 256 |
{ |
| 257 |
ltx.__tag.func.store_mc_data(\__tag_get_mc_abs_cnt:,"raw","#1") |
| 258 |
} |
| 259 |
}, |
| 260 |
alt .code:n = % Alt property |
| 261 |
{ |
| 262 |
\tl_if_empty:oF{#1} |
| 263 |
{ |
| 264 |
\str_set_convert:Noon |
| 265 |
\l__tag_tmpa_str |
| 266 |
{ #1 } |
| 267 |
{ default } |
| 268 |
{ utf16/hex } |
| 269 |
\tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } |
| 270 |
\tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } |
| 271 |
\lua_now:e |
| 272 |
{ |
| 273 |
ltx.__tag.func.store_mc_data |
| 274 |
( |
| 275 |
\__tag_get_mc_abs_cnt:,"alt","/Alt~<\str_use:N \l__tag_tmpa_str>" |
| 276 |
) |
| 277 |
} |
| 278 |
} |
| 279 |
}, |
| 280 |
lang .code:n = % Lang property |
| 281 |
{ |
| 282 |
\tl_if_empty:oF{#1} |
| 283 |
{ |
| 284 |
\tl_put_right:Ne \l__tag_mc_key_properties_tl { /Lang~(#1) } |
| 285 |
\lua_now:e |
| 286 |
{ |
| 287 |
ltx.__tag.func.store_mc_data |
| 288 |
( |
| 289 |
\__tag_get_mc_abs_cnt:,"lang","/Lang~(#1)" |
| 290 |
) |
| 291 |
} |
| 292 |
} |
| 293 |
}, |
| 294 |
alttext .meta:n = {alt=#1}, |
| 295 |
actualtext .code:n = % Alt property |
| 296 |
{ |
| 297 |
\tl_if_empty:oF{#1} |
| 298 |
{ |
| 299 |
\str_set_convert:Noon |
| 300 |
\l__tag_tmpa_str |
| 301 |
{ #1 } |
| 302 |
{ default } |
| 303 |
{ utf16/hex } |
| 304 |
\tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } |
| 305 |
\tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } |
| 306 |
\lua_now:e |
| 307 |
{ |
| 308 |
ltx.__tag.func.store_mc_data |
| 309 |
( |
| 310 |
\__tag_get_mc_abs_cnt:, |
| 311 |
"actualtext", |
| 312 |
"/ActualText~<\str_use:N \l__tag_tmpa_str>" |
| 313 |
) |
| 314 |
} |
| 315 |
} |
| 316 |
}, |
| 317 |
label .code:n = |
| 318 |
{ |
| 319 |
\tl_set:Nn\l__tag_mc_key_label_tl { #1 } |
| 320 |
\lua_now:e |
| 321 |
{ |
| 322 |
ltx.__tag.func.store_mc_data |
| 323 |
( |
| 324 |
\__tag_get_mc_abs_cnt:,"label","#1" |
| 325 |
) |
| 326 |
} |
| 327 |
}, |
| 328 |
__artifact-store .code:n = |
| 329 |
{ |
| 330 |
\lua_now:e |
| 331 |
{ |
| 332 |
ltx.__tag.func.store_mc_data |
| 333 |
( |
| 334 |
\__tag_get_mc_abs_cnt:,"artifact","#1" |
| 335 |
) |
| 336 |
} |
| 337 |
}, |
| 338 |
artifact .code:n = |
| 339 |
{ |
| 340 |
\exp_args:Nne |
| 341 |
\keys_set:nn |
| 342 |
{ __tag / mc} |
| 343 |
{ __artifact-bool, __artifact-type=#1, tag=Artifact } |
| 344 |
\exp_args:Nne |
| 345 |
\keys_set:nn |
| 346 |
{ __tag / mc } |
| 347 |
{ __artifact-store=\l__tag_mc_artifact_type_tl } |
| 348 |
}, |
| 349 |
artifact .default:n = { notype } |
| 350 |
} |
| 351 |
|
| 352 |
%% |
| 353 |
%% |
| 354 |
%% End of file `tagpdf-mc-code-lua.sty'. |