diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/latex-lab/latex-lab-math.ltx')
-rw-r--r-- | Master/texmf-dist/tex/latex/latex-lab/latex-lab-math.ltx | 719 |
1 files changed, 553 insertions, 166 deletions
diff --git a/Master/texmf-dist/tex/latex/latex-lab/latex-lab-math.ltx b/Master/texmf-dist/tex/latex/latex-lab/latex-lab-math.ltx index 1ced324bb10..343a184d379 100644 --- a/Master/texmf-dist/tex/latex/latex-lab/latex-lab-math.ltx +++ b/Master/texmf-dist/tex/latex/latex-lab/latex-lab-math.ltx @@ -33,24 +33,476 @@ %% %% %% File: latex-lab-math.dtx -\def\ltlabmathdate{2023-09-11} -\def\ltlabmathversion{0.5c} +\def\ltlabmathdate{2024-04-16} +\def\ltlabmathversion{0.5j} \ProvidesFile{latex-lab-math.ltx} [\ltlabmathdate\space v\ltlabmathversion\space Grab all the math(s) and tag it (experiments)] \AddToHook{begindocument/before}{\RequirePackage{latex-lab-testphase-block}} \ExplSyntaxOn -\tl_gput_right:Nn \@kernel@before@begindocument - { \RequirePackage { amsmath } } +\AddToHook{begindocument/before}{ \RequirePackage { amsmath } } \bool_new:N \l__math_collected_bool +\bool_new:N \l__math_fakemath_bool \tl_new:N \g__math_grabbed_env_tl \tl_new:N \g__math_grabbed_math_tl +\tl_new:N \l__math_tmpa_tl +\skip_new:N \l__math_tmpa_skip +\tl_new:N \l__math_content_alt_tl +\tl_new:N \l__math_content_actual_tl +\tl_new:N \l__math_content_AF_source_tl +\tl_new:N \l__math_content_AF_source_tmpa_tl +\tl_new:N \l__math_content_AF_mathml_tl +\cs_new_protected:Npn \__tag_tool_close_P: + { + \tag_if_active:T + { + \tag_mc_end: %end P-chunk, should perhaps be \tag_mc_end_push: ... + \__tag_gincr_para_end_int: + \__tag_check_para_end_show:nn{red}{} %debug: show para + \tag_struct_end: + } + } +\tl_new:N\l__math_attribute_class_tl +\tagpdfsetup + {role/new-attribute = {inline} {/O /Layout /Placement/Inline}, + role/new-attribute = {display} {/O /Layout /Placement/Block}, + } +\bool_new:N\l__tag_math_texsource_AF_bool +\bool_new:N\l__tag_math_texsource_pane_bool +\bool_new:N\l__tag_math_mathml_AF_bool +\bool_new:N\g__tag_math_mathml_AF_bool +\bool_new:N\l__tag_math_mathml_pane_bool +\bool_new:N\l__tag_math_alt_bool +\int_new:N\g__math_mathml_total_int +\int_new:N\g__math_mathml_int +\int_new:N\g__math_math_total_int +\int_new:N\g__math_mathml_AF_found_int +\int_new:N\g__math_mathml_AF_attached_int +\clist_new:N\l__tag_math_mathml_files_clist +\clist_put_right:Ne\l__tag_math_mathml_files_clist {\c_sys_jobname_str-mathml} + +\cs_new_protected:Npn \__math_AF_mml:nnnn #1 #2 #3 #4 + { + \int_gincr:N \g__math_mathml_total_int + \tl_if_exist:cF { g__math_mathml_#3_tl } + { + \int_gincr:N \g__math_mathml_int + \pdfdict_put:nne {l_pdffile/Filespec} {Desc}{(mathml-#1)} + \pdffile_embed_stream:nnN {#4}{mathml-#1.xml}\l__math_tmpa_tl + \bool_if:NT \l__tag_math_mathml_pane_bool + {\pdfmanagement_add:nne {Catalog/Names}{EmbeddedFiles}{\l__math_tmpa_tl}} + \tl_new:c{g__math_mathml_#3_tl} + \tl_gset_eq:cN{g__math_mathml_#3_tl}\l__math_tmpa_tl + } + } +\cs_new_protected:Npn \__math_AF_html_reader:w#1</h2>#2<p>#3</p>#4<p>#5</p>#6<math{ + \begingroup + \char_set_catcode_other:N\{ + \char_set_catcode_other:N\} + \char_set_catcode_other:N\# + \char_set_catcode_other:N\% + \__math_AF_html_reader_verb:w{#1}{#3}{#5}<math +} +\cs_new_protected:Npn\__math_AF_html_reader_verb:w#1#2#3#4~</div>{ + \endgroup + \__math_AF_mml:nnnn{#1}{#2}{#3}{#4} + } + +\socket_new:nn {tagsupport/math/mathml/write}{0} +\socket_new_plug:nnn{tagsupport/math/mathml/write}{On} + { + \str_set:NV\l__math_tmpa_str\l__math_content_AF_source_tl + \str_replace_all:Nnn\l__math_tmpa_str{&}{&} + \str_replace_all:Nnn\l__math_tmpa_str{<}{<} + \iow_now:Ne \g__math_writedummy_iow + { + \iow_newline: + <div> + \iow_newline: + <h2>\c_backslash_str mml\c_space_tl \int_use:N \g__math_math_total_int </h2> + \iow_newline: + <p>\l__math_tmpa_str</p> + \iow_newline: + <p>\l__math_content_hash_tl </p> + \iow_newline: + <math></math> + \iow_newline: + </div> + \iow_newline: + } + } + +\keys_define:nn { __tag / setup } + { + math/mathml/write-dummy .code:n = + { + \bool_gset_true:N \g__tag_math_mathml_AF_bool + \tl_if_exist:NF\g__math_writedummy_iow + { + \iow_new:N \g__math_writedummy_iow + \iow_open:Nn \g__math_writedummy_iow + { + \c_sys_jobname_str-mathml-dummy.html + } + \iow_now:Ne \g__math_writedummy_iow + { + <!DOCTYPE~html> + \iow_newline: + <html> + } + \AssignSocketPlug {tagsupport/math/mathml/write}{On} + \AddToHook{enddocument/afterlastpage} + { + \iow_now:Nn \g__math_writedummy_iow {</html>} + \iow_close:N \g__math_writedummy_iow + } + } + }, + math/mathml/write-dummy .usage:n=preamble + } +\box_new:N\l__math_tmpa_box +\cs_new_protected:Npn \__math_AF_process_mathml_files: + { + \hbox_set:Nn \l__math_tmpa_box + { + \pdfdict_put:nnn { l_pdffile/Filespec }{AFRelationship} { /Supplement } + \pdfdict_put:nne + { l_pdffile }{Subtype} + { \pdf_name_from_unicode_e:n{application/mathml+xml} } + \char_set_catcode_other:N \# + \cs_set_eq:NN\mml \__math_AF_html_reader:w + \clist_map_inline:Nn \l__tag_math_mathml_files_clist + { + \file_if_exist:nTF {##1.html} + { + \typeout{Info:~reading~mathml~file~##1} + \file_input:n {##1.html} + \bool_gset_true:N\g__tag_math_mathml_AF_bool + } + { + \typeout{Info:~mathml~file~##1~does~not~exist}%info message + } + } + } + \bool_if:NT\g__tag_math_mathml_AF_bool + { + \typeout{Info:~Activating~mathml~support} + \AssignSocketPlug{tagsupport/math/struct/begin}{test-mathml} + \AssignSocketPlug{tagsupport/math/struct/end}{test-mathml} + \AssignSocketPlug{tagsupport/math/substruct/begin}{single} + \AssignSocketPlug{tagsupport/math/substruct/end}{single} + \AddToHook{enddocument/info} + { + \iow_term:n{MathML~statistic} + \iow_term:n{================} + \iow_term:e{==>~\int_use:N\g__math_mathml_total_int\c_space_tl + MathML~fragments~read} + \iow_term:e{==>~\int_use:N\g__math_mathml_int\c_space_tl + different~MathML~fragments} + \iow_term:e{==>~\int_use:N\g__math_math_total_int\c_space_tl + math~fragments~found} + \iow_term:e{==>~\int_use:N\g__math_mathml_AF_found_int\c_space_tl + fitting~MathML~AF~found} + \iow_term:e{==>~\int_use:N\g__math_mathml_AF_attached_int\c_space_tl + MathML~AF~attached} + } + } + } +\AddToHook{begindocument}{\__math_AF_process_mathml_files:} +\int_new:N \l__math_mathstyle_int +\int_new:N \g__math_mathchoice_int +\property_new:nnnn{mathstyle}{now}{-1}{\int_use:N \l__math_mathstyle_int } +\cs_new_protected:Npn \__math_tag_if_mathstyle:nn #1 #2 + %#1 refers to label + %#2 is a number for the mathstyle (typically 0,2,4,6) + { + \int_set:Nn \l__math_mathstyle_int {#2} + \property_record:nn {#1} { mathstyle } + \int_compare:nNnTF { \property_ref:nn {#1}{ mathstyle} } = { #2 } + { \tag_start: }{ \tag_stop: } + } +\cs_generate_variant:Nn \__math_tag_if_mathstyle:nn {en} +\keys_define:nn { __tag / setup } + { + math/mathml/sources .clist_set:N = \l__tag_math_mathml_files_clist, + math/alt/use .bool_set:N = \l__tag_math_alt_bool, + viewer/pane/mathml .bool_set:N = \l__tag_math_mathml_pane_bool, + viewer/pane/mathml .initial:n = true, + viewer/pane/mathsource .bool_set:N = \l__tag_math_texsource_pane_bool, + math/mathml/AF .bool_set:N = \l__tag_math_mathml_AF_bool, + math/mathml/AF .initial:n = true, + math/tex/AF .bool_set:N = \l__tag_math_texsource_AF_bool, + math/tex/AF .initial:n = true + } +\socket_new:nn {tagsupport/math/inline/begin}{0} +\socket_new:nn {tagsupport/math/inline/end}{0} +\socket_new:nn {tagsupport/math/inline/formula/begin}{1} % +\socket_new:nn {tagsupport/math/inline/formula/end}{0} +\socket_new_plug:nnn + {tagsupport/math/inline/begin} + {MC} + {\tag_mc_end_push:} +\socket_new_plug:nnn + {tagsupport/math/inline/end} + {MC} + {\tag_mc_begin_pop:n{}} +\socket_new_plug:nnn + {tagsupport/math/inline/formula/begin} + {default} + { + \socket_use:n{tagsupport/math/content} + \socket_use:n{tagsupport/math/struct/begin} + % inner formula if multiple parts (not really implemented yet) + \socket_use:n{tagsupport/math/substruct/begin} + #1 + \socket_use:n{tagsupport/math/end} + } +\socket_new_plug:nnn + {tagsupport/math/inline/formula/end} + {default} + { + \socket_use:n{tagsupport/math/substruct/end} + \socket_use:n{tagsupport/math/struct/end} + } +\socket_new:nn {tagsupport/math/display/begin}{0} +\socket_new:nn {tagsupport/math/display/end}{0} +\socket_new:nn {tagsupport/math/display/formula/begin}{1} % +\socket_new:nn {tagsupport/math/display/formula/end}{0} + +\socket_new_plug:nnn + {tagsupport/math/display/begin} + {default} + { \__tag_tool_close_P: } +\socket_new_plug:nnn + {tagsupport/math/display/end} + {default} + { + } + +\socket_new_plug:nnn + {tagsupport/math/display/formula/begin} + {default} + { + \socket_use:n{tagsupport/math/content} + \socket_use:n{tagsupport/math/struct/begin} + \socket_use:n{tagsupport/math/substruct/begin} + #1 + \socket_use:n{tagsupport/math/end} + } +\socket_new_plug:nnn + {tagsupport/math/display/formula/end} + {default} + { + \socket_use:n{tagsupport/math/substruct/end} + \socket_use:n{tagsupport/math/struct/end} + } +\tl_new:N\l__math_content_template_tl +\tl_set:Nn \l__math_content_template_tl + { + LaTeX~ formula~ starts~ + \exp_not:N\begin{\g__math_grabbed_env_tl} + \c_space_tl + \exp_not:V\g__math_grabbed_math_tl + \c_space_tl + \exp_not:N\end{\g__math_grabbed_env_tl} + \c_space_tl LaTeX~ formula~ ends~ + } + +\tl_new:N\l__math_texsource_template_tl +\tl_const:Nn\c__math_inline_env_tl {math} +\tl_set:Nn \l__math_texsource_template_tl + { + \tl_if_eq:NNTF\g__math_grabbed_env_tl\c__math_inline_env_tl + { + $ + \exp_not:V\g__math_grabbed_math_tl + $ + } + { + \exp_not:N\begin{\g__math_grabbed_env_tl} + \exp_not:V\g__math_grabbed_math_tl + \exp_not:N\end{\g__math_grabbed_env_tl} + } + } + +\socket_new:nn {tagsupport/math/content}{0} +\socket_new_plug:nnn + {tagsupport/math/content} + {actual+source} + { + \tl_set:Ne\l__math_content_actual_tl + { + \l__math_content_template_tl + } + \tl_set:Ne \l__math_content_AF_source_tl + { + \l__math_texsource_template_tl + } + \tl_set:Nn \l__math_content_AF_mathml_tl {} + \tl_set:Nn \l__math_content_alt_tl {} + } +\socket_new_plug:nnn + {tagsupport/math/content} + {alt+source} + { + \tl_set:Ne\l__math_content_alt_tl + { + \l__math_content_template_tl + } + \tl_set:Ne \l__math_content_AF_source_tl + { + \l__math_texsource_template_tl + } + \tl_set:Nn \l__math_content_AF_mathml_tl {} + \tl_set:Nn \l__math_content_actual_tl {} + } +\socket_assign_plug:nn {tagsupport/math/content}{alt+source} +\socket_new:nn {tagsupport/math/struct/begin}{0} +\socket_new:nn {tagsupport/math/struct/end}{0} +\socket_new_plug:nnn + {tagsupport/math/struct/begin} + {default} + { + \bool_if:NTF\l__tag_math_texsource_AF_bool + { \tl_set_eq:NN \l__math_content_AF_source_tmpa_tl \l__math_content_AF_source_tl } + { \tl_clear:N \l__math_content_AF_source_tmpa_tl } + \tag_struct_begin:n + { + tag=Formula, + texsource = \l__math_content_AF_source_tmpa_tl, + title-o = \g__math_grabbed_env_tl, + actualtext = \l__math_content_actual_tl, + alt = \l__math_content_alt_tl + } + } +\socket_new_plug:nnn + {tagsupport/math/struct/end} + {default} + { \tag_struct_end: } + +\socket_assign_plug:nn {tagsupport/math/struct/begin}{default} +\socket_assign_plug:nn {tagsupport/math/struct/end}{default} +\cs_generate_variant:Nn \str_mdfive_hash:n {o} +\tl_new:N\l__math_content_hash_tl +\tl_new:N\l__math_grabbed_math_tl +\socket_new_plug:nnn + {tagsupport/math/struct/begin} + {test-mathml} + { + \int_gincr:N\g__math_math_total_int + \tl_set:Ne\l__math_content_hash_tl + {\str_mdfive_hash:o { \l__math_content_AF_source_tl }} + \tl_set_eq:NN\l__math_grabbed_math_tl\g__math_grabbed_math_tl + \tl_if_eq:NnTF\g__math_grabbed_env_tl {math} + { + \tl_set:Nn\l__math_attribute_class_tl{inline} + } + { + \tl_set:Nn\l__math_attribute_class_tl{display} + } + \bool_if:NF\l__tag_math_alt_bool + { \tl_set:Nn \l__math_content_alt_tl{} } + \tl_if_exist:cTF { g__math_mathml_ \l__math_content_hash_tl _tl } + { + \int_gincr:N\g__math_mathml_AF_found_int + \bool_if:NTF \l__tag_math_mathml_AF_bool + { + \int_gincr:N\g__math_mathml_AF_attached_int + \typeout {Inserting~mathml~with~Hash~\l__math_content_hash_tl} + } + { + \typeout {Ignoring~mathml~with~Hash~\l__math_content_hash_tl} + } + } + { + \typeout{WARNING:~mathml~missing~for~hash~\l__math_content_hash_tl} + } + \socket_use:n {tagsupport/math/mathml/write} % write hash if request + \bool_if:NTF\l__tag_math_texsource_AF_bool + { \tl_set_eq:NN \l__math_content_AF_source_tmpa_tl \l__math_content_AF_source_tl } + { \tl_clear:N \l__math_content_AF_source_tmpa_tl } + \tag_struct_begin:n + { + tag=Formula, + attribute-class=\l__math_attribute_class_tl, % + AFref = + \bool_if:NT\l__tag_math_mathml_AF_bool + { + \cs_if_exist_use:c {g__math_mathml_ \l__math_content_hash_tl _tl} + }, + texsource = \l__math_content_AF_source_tmpa_tl, % should be after mathml AF! + title-o = \g__math_grabbed_env_tl, % + alt = \l__math_content_alt_tl + } + } +\socket_new_plug:nnn + {tagsupport/math/struct/end} + {test-mathml} + { + \tag_struct_end: + } +\socket_new:nn {tagsupport/math/substruct/begin}{0} +\socket_new:nn {tagsupport/math/substruct/end}{0} +\socket_new_plug:nnn + {tagsupport/math/substruct/begin} + {default} + { \grabaformulapartandstart } +\socket_new_plug:nnn + {tagsupport/math/substruct/end} + {default} + { + \tagmcend + \if@subformulas + \tagstructend + \fi + } +\socket_assign_plug:nn {tagsupport/math/substruct/begin}{default} +\socket_assign_plug:nn {tagsupport/math/substruct/end}{default} + +\socket_new_plug:nnn + {tagsupport/math/substruct/begin} + {single} + { + \typeout{====>subpart~splitting~deactivated} + \typeout{====>grabbed~math=\meaning\g__math_grabbed_math_tl} + \tag_mc_begin:n{} + } +\socket_new_plug:nnn + {tagsupport/math/substruct/end} + {single} + { \tag_mc_end:} +\socket_new:nn {tagsupport/math/end}{0} + +\cs_new_protected:Npn \__tag_math_disable: + { + \socket_assign_plug:nn {tagsupport/math/inline/begin}{noop} + \socket_assign_plug:nn {tagsupport/math/inline/end}{noop} + \socket_assign_plug:nn {tagsupport/math/inline/formula/begin}{identity} + \socket_assign_plug:nn {tagsupport/math/inline/formula/end}{noop} + \socket_assign_plug:nn {tagsupport/math/display/begin}{noop} + \socket_assign_plug:nn {tagsupport/math/display/end}{noop} + \socket_assign_plug:nn {tagsupport/math/display/formula/begin}{identity} + \socket_assign_plug:nn {tagsupport/math/display/formula/end}{noop} + } +\cs_new_protected:Npn \__tag_math_enable: + { + \socket_assign_plug:nn {tagsupport/math/inline/begin}{MC} + \socket_assign_plug:nn {tagsupport/math/inline/end}{MC} + \socket_assign_plug:nn {tagsupport/math/inline/formula/begin}{default} + \socket_assign_plug:nn {tagsupport/math/inline/formula/end}{default} + \socket_assign_plug:nn {tagsupport/math/display/begin}{default} + \socket_assign_plug:nn {tagsupport/math/display/end}{default} + \socket_assign_plug:nn {tagsupport/math/display/formula/begin}{default} + \socket_assign_plug:nn {tagsupport/math/display/formula/end}{default} + } +\AtBeginDocument{\tag_if_active:T{\__tag_math_enable: }} \cs_new_protected:Npn \__math_process:nn #1#2 { \legacy_if:nF { measuring@ } { - \tl_if_in:nnF {#2} { \m@th } + \tl_if_in:nnTF {#2} { \m@th } + { \bool_set_true:N\l__math_fakemath_bool } { \tl_trim_spaces_apply:nN {#2} \__math_process_auxi:nn {#1} } } } @@ -70,62 +522,39 @@ \tl_if_blank:nF {#1} { \__math_process:nn { math } {#1} % $ - \legacy_if:nTF { measuring@ } - { #1 $ } - { - \tl_if_in:nnTF {#1} { \m@th } - { #1 $ } - { - \tagmcend %end P-chunk, in code: \tag_mc_end_push: - \@kernel@math@begin - #1 $ - \@kernel@math@end - \tagmcbegin{} % restart P-chunk (whatsits in pdftex) - } - } + \bool_lazy_or:nnTF + {\legacy_if_p:n { measuring@ }} + { \l__math_fakemath_bool } + { #1 $ } + { + \tag_socket_use:n {math/inline/begin} %end P-MC + \tag_socket_use:nn {math/inline/formula/begin}{#1} + $ + \tag_socket_use:n {math/inline/formula/end} + \tag_socket_use:n {math/inline/end} % restart P-MC + } } } - -\skip_new:N \l__math_tmpa_skip - \cs_new_protected:Npn \__math_grab_dollardollar:w % $$ #1 $$ { \tl_if_blank:nF {#1} { - \__math_tag_dollardollar_display:nn { equation* }{#1} - #1 + \__math_process:nn { equation* } {#1} + \socket_use:n {tagsupport/math/display/begin} + \socket_use:nn{tagsupport/math/display/formula/begin}{#1} $$ } } -\cs_new_protected:Npn \@kernel@close@P { - \tag_if_active:T - { - \tagmcend %end P-chunk, should perhaps be \tag_mc_end_push: ... - \int_gincr:N \g__tag_para_end_int - \bool_if:NT \l__tag_para_show_bool - { \tag_mc_begin:n{artifact} - \rlap{\color_select:n{red}\tiny\ \int_use:N\g__tag_para_end_int} - \tag_mc_end: - } - \tag_struct_end: - } -} - -\cs_new_protected:Npn \__math_tag_dollardollar_display:nn #1#2 { - \__math_process:nn {#1} {#2} - \@kernel@close@P - \@kernel@math@begin -%% -} - -\cs_new_protected:Npn \__math_tag_dollardollar_display_end: { - \tagpdfparaOff - \para_raw_end: - \tagpdfparaOn - \l__math_tmpa_skip \lastskip - \@kernel@math@end - \penalty \postdisplaypenalty +\cs_new_protected:Npn \__math_tag_dollardollar_display_end: + { + % \typeout{== tag dollarldollar display end} + % \ShowTagging{struct-stack} + \para_raw_end: + \tagpdfparaOn + \l__math_tmpa_skip \lastskip + \socket_use:n{tagsupport/math/display/formula/end} + \penalty \postdisplaypenalty \skip_vertical:n { -\l__math_tmpa_skip * 2 } \@doendpe % this has no \end{...} to take care of it } @@ -135,7 +564,6 @@ { \tl_if_blank:nF {#1} { - \__math_process:nn { math } {#1} $ #1 $ } \bool_set_false:N \l__math_collected_bool @@ -162,7 +590,7 @@ \keys_set:nn { __math } {#2} \cs_gset_eq:cc { __math_env_ #1 _begin: } {#1} \cs_gset_eq:cc { __math_env_ #1 _end: } { end #1 } - \ExpandArgs { nnx } \RenewDocumentEnvironment {#1} { b } + \ExpandArgs { nne } \RenewDocumentEnvironment {#1} { b } { \exp_not:N \bool_if:NTF \exp_not:N \l__math_collected_bool { @@ -171,28 +599,19 @@ \cs_if_exist:cTF { __math_env #1 _aux: } { \exp_not:c { __math_env #1 _aux: } - ####1 \exp_not:N \__math_env_end: {#1} + ##1 \exp_not:N \__math_env_end: {#1} } - { \exp_not:N \__math_process:nn {#1} {####1} } + { \exp_not:N \__math_process:nn {#1} {##1} } \exp_not:n { \@kernel@math@registered@begin } \bool_set_true:N \exp_not:N \l__math_collected_bool } \exp_not:c { __math_env_ #1 _begin: } - ####1 + ##1 \exp_not:c { __math_env_ #1 _end: } } - { - } - } - -\cs_set_protected:Npn \__cs_tmp:w #1 - { - \group_begin: - \exp_args:No \__cs_generate_internal_variant:n - { \tl_to_str:n {#1} } - \group_end: + { + } } -\__cs_tmp:w { nnxx } \cs_new_protected:Npn \math_register_halign_env:nn #1#2 { @@ -200,7 +619,7 @@ \keys_set:nn { __math } {#2} \cs_gset_eq:cc { __math_env_ #1 _begin: } {#1} \cs_gset_eq:cc { __math_env_ #1 _end: } { end #1 } - \ExpandArgs { nnxx } \RenewDocumentEnvironment {#1} { b } + \ExpandArgs { nnee } \RenewDocumentEnvironment {#1} { b } { \exp_not:N \bool_if:NTF \exp_not:N \l__math_collected_bool { @@ -209,27 +628,26 @@ \cs_if_exist:cTF { __math_env #1 _aux: } { \exp_not:c { __math_env #1 _aux: } - ####1 \exp_not:N \__math_env_end: {#1} + ##1 \exp_not:N \__math_env_end: {#1} } - { \exp_not:N \__math_process:nn {#1} {####1} } + { \exp_not:N \__math_process:nn {#1} {##1} } \exp_not:n { \@kernel@math@registered@begin } \bool_set_true:N \exp_not:N \l__math_collected_bool } \exp_not:c { __math_env_ #1 _begin: } - ####1 + ##1 + } + { + \exp_not:c { __math_env_ #1 _end: } } - { - \exp_not:c { __math_env_ #1 _end: } - } } - \cs_new_protected:Npn \math_register_odd_env:nn #1#2 { \tl_set:Nn \l__math_env_name_tl {#1} \keys_set:nn { __math } {#2} \cs_gset_eq:cc { __math_env_ #1 _begin: } {#1} \cs_gset_eq:cc { __math_env_ #1 _end: } { end #1 } - \ExpandArgs { nnxx } \RenewDocumentEnvironment {#1} { b } + \ExpandArgs { nnee } \RenewDocumentEnvironment {#1} { b } { \exp_not:N \bool_if:NTF \exp_not:N \l__math_collected_bool { @@ -238,14 +656,14 @@ \cs_if_exist:cTF { __math_env #1 _aux: } { \exp_not:c { __math_env #1 _aux: } - ####1 \exp_not:N \__math_env_end: {#1} + ##1 \exp_not:N \__math_env_end: {#1} } - { \exp_not:N \__math_process:nn {#1} {####1} } + { \exp_not:N \__math_process:nn {#1} {##1} } \exp_not:n { \@kernel@math@registered@begin } \bool_set_true:N \exp_not:N \l__math_collected_bool } \exp_not:c { __math_env_ #1 _begin: } - ####1 + ##1 } { \exp_not:c { __math_env_ #1 _end: } @@ -257,27 +675,31 @@ \cs_new:Npn \@kernel@math@registered@begin { \mode_if_vertical:TF { - \exp_args:Noo\str_if_eq:nnF \g__tag_struct_tag_tl { \l__tag_para_main_tag_tl } % needs correction! + \tag_if_active:T + { + \exp_args:Noo\str_if_eq:nnF \g__tag_struct_tag_tl { \l__tag_para_main_tag_tl } % needs correction! { \__block_beginpar_vmode: } % needs correction! + } } { - \@kernel@close@P + \__tag_tool_close_P: } - \@kernel@math@begin + \socket_use:nn{tagsupport/math/display/formula/begin}{} \tagpdfparaOff } \cs_new:Npn \@kernel@math@registered@end { \para_raw_end: \tagpdfparaOn - \@kernel@math@end + \socket_use:n{tagsupport/math/display/formula/end} \@endpetrue } \cs_new_protected:Npn \math_register_env:n #1 { \math_register_env:nn {#1} { } } + \NewDocumentCommand \RegisterMathEnvironment { O{} m } { \math_register_env:nn {#2} {#1} } \cs_new_protected:Npn \__math_env_forward:w #1 \__math_env_end: #2 @@ -311,47 +733,15 @@ { \cs_gset_protected:Npn \[ % \] { - \bool_if:NTF \l__math_collected_bool - { \begin { equation* } } - { \__math_grab_eqn:w } + \__math_grab_eqn:w + % \bool_if:NTF \l__math_collected_bool } % \[ \cs_gset_protected:Npn \] { - \bool_if:NTF \l__math_collected_bool - { \end{ equation* } } - { \@badmath } + \@badmath } } -\tl_new:N\tmpmathcontent - -\def\@kernel@math@begin { - \tl_gset:Nx\tmpmathcontent - { - LaTeX~ formula~ starts~ - \exp_not:N\begin{\g__math_grabbed_env_tl} - \space - \exp_not:V\g__math_grabbed_math_tl - \space - \exp_not:N\end{\g__math_grabbed_env_tl} - \space LaTeX~ formula~ ends~ - } - \tagstructbegin{tag=Formula, - AFinline-o=\tmpmathcontent, - title-o=\g__math_grabbed_env_tl, - actualtext=\tmpmathcontent - } - \grabaformulapartandstart -} -\def\@kernel@math@end { - \tagmcend - \if@subformulas - \tagstructend - \else - \fi - \tagstructend -} - \exp_args:No \tex_everymath:D { \tex_the:D \tex_everymath:D @@ -379,18 +769,34 @@ } \math_register_env:n { eqnarray } \math_register_env:n { eqnarray* } -\clist_map_inline:nn - { tabular } - { - \AddToHook{ env / #1 / begin } - { \bool_set_true:N \l__math_collected_bool } - } +\RequirePackage{array} +\tl_if_in:NnT\@tabular{$} + { + \def\@tabular{% + \leavevmode + \UseTaggingSocket{tbl/hmode/begin}% + \hbox \bgroup + \bool_set_true:N \l__math_collected_bool + $ + \bool_set_false:N \l__math_collected_bool + \col@sep\tabcolsep \let\d@llarbegin\begingroup + \let\d@llarend\endgroup + \@tabarray} + } \cs_new_eq:NN \__math_m@th: \m@th \cs_gset_protected:Npn \m@th { \bool_set_true:N \l__math_collected_bool \__math_m@th: } +\tl_gput_right:Nn\@kernel@before@begindocument + { + \bool_set_true:N\l__math_collected_bool + } +\tl_gput_right:Nn\@kernel@after@begindocument + { + \bool_set_false:N\l__math_collected_bool + } \tl_gput_right:Nn \@kernel@before@begindocument { \renewenvironment{gather*}{% @@ -467,6 +873,8 @@ \def\measuring@true{\let\ifmeasuring@\iftrue\tag_stop:} \math_register_halign_env:nn {align}{} \math_register_halign_env:nn {align*}{} + \math_register_halign_env:nn {alignat}{} + \math_register_halign_env:nn {alignat*}{} \math_register_halign_env:nn {flalign}{} \math_register_halign_env:nn {flalign*}{} \math_register_halign_env:nn {gather}{} @@ -487,26 +895,6 @@ \tagmcend \tagstructend \tagmcbegin{}% \fi } - \def\intertext@{% - \def\intertext##1{% - \ifvmode\else\\\@empty\fi - \noalign{% - \penalty\postdisplaypenalty\vskip-\belowdisplayskip - \vbox{ - \ifmeasuring@\tag_stop:\fi - \normalbaselines - \ifdim\linewidth=\columnwidth - \else \parshape\@ne \@totalleftmargin \linewidth - \fi - \tag_mc_end_push: - \tagpdfsetup{paratag=P}% - \tagpdfparaOn - \noindent\ignorespaces##1\par - \tag_mc_begin_pop:n{}}% - \penalty\predisplaypenalty\vskip\abovedisplayskip% - }% - } - } \@namedef{math@cr @ @ @ gather}{% \ifst@rred\nonumber\fi &\relax @@ -538,6 +926,11 @@ \restore@math@cr } +\cs_new:Npn \__math_split_at_nl:NN #1#2 { + \tl_set:Nf \l__math_tmpa_tl { + \exp_after:wN \__math_split_at_nl_first:w #1 \\ \q_nil \\ \s_stop } + \exp_after:wN \__math_split_at_nl_aux:nnNN \l__math_tmpa_tl #1 #2 +} \cs_new:Npn \__math_split_at_nl_first:w #1 \\ #2 \\ #3 \s_stop { \quark_if_nil:nTF {#2} @@ -547,8 +940,15 @@ #2 \\ #3 \s_stop } } -\cs_new:Npn \__math_split_chk_if_begin:ww #1 \begin #2 #3 \s_mark - #4 \\ \q_nil \\ \s_stop + +\cs_new_protected:Npn \__math_split_at_nl_aux:nnNN #1 #2 #3 #4 + { + \tl_gset:Nn #4 {#1} + \tl_gset:Nn #3 {#2} + } + +\cs_new:Npn \__math_split_chk_if_begin:ww + #1 \begin #2 #3 \s_mark #4 \\ \q_nil \\ \s_stop { \quark_if_nil:nTF {#2} { {#1} {#4} } @@ -558,7 +958,9 @@ { } { 1 } } } + \cs_new:Npn \__math_split_cleanup_begin_q_nil:w #1 \begin \q_nil {#1} + \cs_new:Npn \__math_split_collect_one_end:w #1 \end #2 #3 \s_stop #4 #5 { \exp_args:Nf \__math_split_check_count_begins:nnnn @@ -567,14 +969,16 @@ } \cs_new:Npn \__math_split_count_begins:n #1 { \int_eval:n { 0 \__math_split_count_begins:w #1 \begin \q_nil } } + \cs_new:Npn \__math_split_count_begins:w #1 \begin #2 { \quark_if_nil:nF {#2} { +1 \__math_split_count_begins:w } } + \cs_new:Npn \__math_split_check_count_begins:nnnn #1 #2 #3 #4 { \int_compare:nNnTF {#1} = {#2} { \exp_last_unbraced:Nf \__math_split_final_cleanup:nn - { \split:n { \__math_split_guard:n {#3} #4 } } + { \__math_split:n { \__math_split_guard:n {#3} #4 } } } { \exp_args:No \use_ii_i:nn @@ -594,28 +998,10 @@ { \exp_end: { #4 #1 } } { \__math_split_final_cleanup:w #3 \s_mark { #4 #1 #2 } } } -\NewDocumentCommand \splitnl { mm +m } - { - \tl_set:Nf \l_tmpa_tl { \split:n {#3} } - \show \l_tmpa_tl - \exp_after:wN \__splitnl_aux:nnNN \l_tmpa_tl #1 #2 - } -\cs_new:Npn \split:n #1 { +\cs_new:Npn \__math_split:n #1 { \__math_split_at_nl_first:w #1 \\ \q_nil \\ \s_stop } -\cs_new:Npn \__math_split_at_nl:NN #1#2 { - \tl_set:Nf \l_tmpa_tl { - \exp_after:wN \__math_split_at_nl_first:w #1 \\ \q_nil \\ \s_stop } - \exp_after:wN \__math_split_at_nl_aux:nnNN \l_tmpa_tl #1 #2 -} - -\cs_new_protected:Npn \__math_split_at_nl_aux:nnNN #1 #2 #3 #4 - { - \tl_gset:Nn #4 {#1} - \tl_gset:Nn #3 {#2} -} - \newif\if@subformulas \tl_new:N \result @@ -634,6 +1020,7 @@ \global\@subformulastrue \edef\resulttitle{\g__math_grabbed_env_tl\space (part)} \tagstructbegin{tag=Formula, + alt = subformula, title-o=\resulttitle } } |