diff options
Diffstat (limited to 'macros/latex/contrib/tagpdf/tagpdf.dtx')
-rw-r--r-- | macros/latex/contrib/tagpdf/tagpdf.dtx | 298 |
1 files changed, 256 insertions, 42 deletions
diff --git a/macros/latex/contrib/tagpdf/tagpdf.dtx b/macros/latex/contrib/tagpdf/tagpdf.dtx index 145b150971..ba473d7022 100644 --- a/macros/latex/contrib/tagpdf/tagpdf.dtx +++ b/macros/latex/contrib/tagpdf/tagpdf.dtx @@ -27,7 +27,7 @@ % \begin{macrocode} %<@@=tag> %<*package> -\ProvidesExplPackage {tagpdf} {2021/02/23} {0.80} +\ProvidesExplPackage {tagpdf} {2021/05/14} {0.81} { A package to experiment with pdf tagging } \bool_if:nF @@ -122,9 +122,9 @@ \ref_attribute_gset:nnnn {tagstructobj} {}{now} { \exp_args:Ne - \pdf_object_if_exist:nT {c__tag_struct_ \int_use:N \c@g__tag_struct_abs_int _obj} + \pdf_object_if_exist:nT {@@/struct/\int_use:N \c@g__tag_struct_abs_int} { - \pdf_object_ref:e{c__tag_struct_ \int_use:N \c@g_@@_struct_abs_int _obj} + \pdf_object_ref:e{@@/struct/\int_use:N \c@g_@@_struct_abs_int} } } % replace by abspage?? @@ -208,6 +208,11 @@ \pdfmanagement_remove:nn {Page} {Tabs}, tabsorder .initial:n = structure, uncompress .code:n = {\pdf_uncompress: }, + global-mc .code:n = + { + \cs_set_eq:NN\@@_attribute_set:Nn \@@_attribute_gset:Nn + \cs_set_eq:NN\@@_attribute_unset:N\@@_attribute_gunset:N + } } %need to think about the right place ... %\AtBeginDocument @@ -217,6 +222,10 @@ { \pdfmanagement_add:nnn { Catalog / MarkInfo } { Marked } { true } } + \keys_define:nn { @@ / setup } + { + global-mc .code:n={} + } } % escape commands are a bit engine specific so have been moved to the backend files. % commands to escape strings so that they can be safely used in pdf @@ -326,9 +335,12 @@ % % \begin{macrocode} %<*user> -\ProvidesExplPackage {tagpdf-user} {2021/02/23} {0.80} +\ProvidesExplPackage {tagpdf-user} {2021/05/14} {0.81} {tagpdf - user commands} +% \end{macrocode} +% \begin{macro}{\tagpdfsetup} +% \begin{macrocode} \NewDocumentCommand \tagpdfsetup { m } { \keys_set:nn { @@ / setup } { #1 } @@ -337,8 +349,12 @@ \cs_set_eq:NN\tagpdfifluatexTF \sys_if_engine_luatex:TF \cs_set_eq:NN\tagpdfifluatexT \sys_if_engine_luatex:T \cs_set_eq:NN\tagpdfifpdftexT \sys_if_engine_pdftex:T - -%%% stop tagging +% \end{macrocode} +% \end{macro} +% We need a command to stop tagging in some places. +% +% \begin{macro}{ \tag_stop_group_begin:, \tag_stop_group_end: } +% \begin{macrocode} \bool_new:N \l_@@_stop_bool \prg_new_conditional:Nnn \@@_if_stop: {p,T,F,TF} @@ -359,13 +375,6 @@ \cs_set_eq:NN \tag_struct_begin:n \use_none:n \cs_set_eq:NN \tag_struct_end: \prg_do_nothing: \cs_set_eq:NN \tag_struct_use:n \use_none:n - %deprecated - \cs_set_eq:NN \uftag_mc_begin:n \tag_mc_begin:n - \cs_set_eq:NN \uftag_mc_end: \tag_mc_end: - \cs_set_eq:NN \uftag_mc_use:n \tag_mc_use:n - \cs_set_eq:NN \uftag_struct_begin:n \tag_struct_begin:n - \cs_set_eq:NN \uftag_struct_end: \tag_struct_end: - \cs_set_eq:NN \uftag_struct_use:n \tag_struct_use:n } \cs_new_protected:Npn \tag_stop_group_begin: @@ -375,23 +384,34 @@ } \cs_set_eq:NN \tag_stop_group_end: \group_end: - - -%%% a generic command to retrieve data - +% \end{macrocode} +% \end{macro} +% We need a command to stop tagging in some places. +% +% \begin{macro}{ \tagpdfget, \tag_get:n } +% This is a generic command to retrieve data. Currently +% the only sensible value for the argument is |mc_tag| +% \begin{macrocode} \cs_new:Npn \tagpdfget #1 { \use:c {@@_get_data_#1: } } \cs_new:Npn \tag_get:n #1 { \use:c {@@_get_data_#1: } } -%deprecated: -\cs_new:Npn \uftag_get:n #1 { \use:c {@@_get_data_#1: } } - -%%%% mc related user commands +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\tagmcifinTF} +% This is a test if an mc is open or not. It is mostly of +% importance for pdflatex as lualatex doesn't mind much if a mc tag is not +% correctly closed. +% \begin{macrocode} \NewDocumentCommand \tagmcifinTF { m m } { \@@_mc_if_in:TF { #1 } { #2 } } - - +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{tagmcartifact} +% \begin{macrocode} \NewDocumentEnvironment{tagmcartifact}{m} { \tag_mc_artifact_group_begin:n { #1}\ignorespaces @@ -400,6 +420,11 @@ \tag_mc_artifact_group_end: } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\tagmcbegin,\tagmcend,\tagmcuse } +% \begin{macrocode} \NewDocumentCommand \tagmcbegin { m } { \tag_mc_begin:n {#1}\ignorespaces @@ -408,7 +433,7 @@ \NewDocumentCommand \tagmcend { } { - \unskip % this unskip appears to mess up some spacing; can we do this in another way? + \if_mode_horizontal: \unskip \fi: % \tag_mc_end: } @@ -417,9 +442,13 @@ \tag_mc_use:n {#1} } - -%%%% structure related commands - +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\tagstructbegin,\tagstructend,\tagstructuse } +% +% These are structure related user commands +% \begin{macrocode} \NewDocumentCommand \tagstructbegin { m } { \tag_struct_begin:n {#1} @@ -435,9 +464,14 @@ \tag_struct_use:n {#1} } - - -%%%% debug/show commands +% \end{macrocode} +% \end{macro} +% +% \section{Debugging} +% +% \begin{macro}{\showtagpdfmcdata,\showtagpdfattributes } +% This commands are lua only +% \begin{macrocode} \NewDocumentCommand\showtagpdfmcdata { O {\@@_tag_get_mc_abs_cnt:} } { \bool_if:NT \g_@@_mode_lua_bool @@ -473,6 +507,15 @@ } } +\NewDocumentCommand\showtagstack {} + { + \seq_show:N \g_@@_struct_tag_stack_seq + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ } +% \begin{macrocode} \sys_if_engine_luatex:T { \NewDocumentCommand\pdffakespace { } @@ -480,19 +523,190 @@ \@@_fakespace: } } +% \end{macrocode} +% \end{macro} +% \section{Paratagging} +% The following are some simple commands to enable/disable paratagging. +% Probably one should add some checks if we are already in a paragraph. +% \begin{macrocode} +\bool_new:N \l_@@_para_bool +\bool_new:N \l_@@_para_show_bool +\int_new:N \g_@@_para_int + +\keys_define:nn { @@ / setup } + { + paratagging .bool_set:N = \l_@@_para_bool, + paratagging-show .bool_set:N = \l_@@_para_show_bool, + } + +\AddToHook{para/begin} + { + \int_gincr:N \g_@@_para_int + \bool_if:NT \l__tag_para_bool + { + \tag_struct_begin:n {tag=P} + \bool_if:NT \l_@@_para_show_bool + { \tag_mc_begin:n{artifact} + \llap{\color_select:n{red}\tiny\int_use:N\g_@@_para_int\ } + \tag_mc_end: + } + \tag_mc_begin:n {tag=P} + } + } +\AddToHook{para/end} + { + \bool_if:NT \l__tag_para_bool + { + \tag_mc_end: + \bool_if:NT \l_@@_para_show_bool + { \tag_mc_begin:n{artifact} + \rlap{\color_select:n{red}\tiny\ \int_use:N\g_@@_para_int} + \tag_mc_end: + } + \tag_struct_end: + } + } + + +\newcommand\tagpdfparaOn {\bool_set_true:N \l__tag_para_bool} +\newcommand\tagpdfparaOff{\bool_set_false:N \l__tag_para_bool} -%</user> % \end{macrocode} -% +% \section{Links} +% We need to close and reopen mc-chunks around links. +% With luatex the push/pop command must be outside groups, +% so we add also code to the generic commands in the hyperref driver. % \begin{macrocode} -%<*deprecated> -% \uftag_get:n -% \uftag_mc_if_in: -% \uftag_mc_begin:n -% \uftag_mc_end: -% \uftag_mc_use:n -% \uftag_struct_begin:n -% \uftag_struct_end: -% \uftag_finish_structure: -%</deprecated> +\cs_generate_variant:Nn \pdfannot_dict_put:nnn {nnx} +\hook_gput_code:nnn + {pdfannot/link/URI/before} + {tagpdf} + { + \bool_if:NT \g_@@_active_struct_bool + { + \tag_mc_end_push: + \tag_struct_begin:n { tag=Link } + \tag_mc_begin:n { tag=Link } + \pdfannot_dict_put:nnx + { link/URI } + { StructParent } + { \int_use:N\c@g_@@_parenttree_obj_int } + } + } + +\hook_gput_code:nnn + {pdfannot/link/URI/after} + {tagpdf} + { + \bool_if:NT \g_@@_active_struct_bool + { + \@@_struct_finish_link: + \tag_mc_end: + \tag_struct_end: + \tag_mc_begin_pop:n{} + } + } + +\hook_gput_code:nnn + {pdfannot/link/GoTo/before} + {tagpdf} + { + \bool_if:NT \g_@@_active_struct_bool + { + \tag_mc_end_push: + \tag_struct_begin:n{tag=Link} + \tag_mc_begin:n{tag=Link} + \pdfannot_dict_put:nnx + { link/GoTo } + { StructParent } + { \int_use:N\c@g_@@_parenttree_obj_int } + } + } + +\hook_gput_code:nnn + {pdfannot/link/GoTo/after} + {tagpdf} + { + \bool_if:NT \g_@@_active_struct_bool + { + \@@_struct_finish_link: + \tag_mc_end: + \tag_struct_end: + \tag_mc_begin_pop:n{} + } + } + +\hook_gput_code:nnn + {cmd/url/before} + {tagpdf} + {\tag_mc_end_push:} + +\hook_gput_code:nnn + {cmd/url/after} + {tagpdf} + {\tag_mc_begin_pop:n{}} + +\hook_gput_code:nnn + {cmd/href/before} + {tagpdf} + {\tag_mc_end_push:} + +\hook_gput_code:nnn + {cmd/href/after} + {tagpdf} + {\tag_mc_begin_pop:n{}} + +\hook_gput_code:nnn + {cmd/hrefurl/before} + {tagpdf} + {\tag_mc_end_push:} + +\hook_gput_code:nnn + {cmd/hrefurl/after} + {tagpdf} + {\tag_mc_begin_pop:n{}} + +%this will go when references are improved +\hook_gput_code:nnn + {cmd/T@ref/before} + {tagpdf} + {\tag_mc_end_push:} + +\hook_gput_code:nnn + {cmd/T@ref/after} + {tagpdf} + {\tag_mc_begin_pop:n{}} + +\hook_gput_code:nnn + {cmd/T@pageref/before} + {tagpdf} + {\tag_mc_end_push:} + +\hook_gput_code:nnn + {cmd/T@pageref/after} + {tagpdf} + {\tag_mc_begin_pop:n{}} + +\hook_gput_code:nnn + {cmd/T@nameref/before} + {tagpdf} + {\tag_mc_end_push:} + +\hook_gput_code:nnn + {cmd/T@nameref/after} + {tagpdf} + {\tag_mc_begin_pop:n{}} +% "alternative descriptions " for PAX3. How to get better text here?? +\pdfannot_dict_put:nnn + { link/URI } + { Contents } + { (url) } + +\pdfannot_dict_put:nnn + { link/GoTo } + { Contents } + { (ref) } + % \end{macrocode} +%</user> +% |