alignat 环境中的实际文本与 expl3 不正确

alignat 环境中的实际文本与 expl3 不正确

我想重新定义alignat环境以自动标记公式并将此公式作为标记 P 的实际文本插入。它工作正常,但为什么如果我打开expl3语法,我会得到实际文本xs_StrFindGrou。第二个问题是,如何删除所有额外的命令以将公式设置为段落的实际文本,而不使用xstring包而只使用expl3功能?谢谢大家的帮助。

\documentclass{article}
\usepackage{tagpdf,amsmath,xstring}
\tagpdfsetup{tabsorder=structure,uncompress,activate-all,interwordspace=true,tagunmarked=false}
\tagpdfifpdftexT
 {
    \pdfcompresslevel=0
  %set language / can also be done with hyperref
  \pdfcatalog{/Lang (en-US)}
  \usepackage[T1]{fontenc}
  \input glyphtounicode
  \pdfgentounicode=1
 }
\tagpdfifluatexT
 {
   %set language / can also be done with hyperref
  \pdfextension catalog{/Lang (en-US)}
  \usepackage{fontspec}
  \newfontface\zerowidthfont{freeserif}
}
\pagestyle{empty}
\ExplSyntaxOn
\makeatletter
\long\def\doactualtext#1{
\def\@mltext{\detokenize\expandafter{#1}}
\def\@mltexttmp{}
\StrBehind[5]{\@mltext}{ }[\@mltexttmp]
\StrGobbleRight{\@mltexttmp}{1}[\@mltext]
\tagstructbegin{tag=P,actualtext-o=\detokenize\expandafter{\@mltext}}
 \tagmcbegin{tag=P}
#1
\tagmcend
\tagstructend
}
\renewenvironment{alignat}{
\collect@body\doactualtext\space
\start@align
\z@\st@rredfalse
}{
\endalign
}
\makeatother
\ExplSyntaxOn
\begin{document}
\tagstructbegin{tag=Document}
\begin{alignat}
10xy^2+15x^2y-5xy7 & =  5\left(2xy^2+3x^2y-xy7\right) = \\
   & = 5x\left(2y^2+3xy-y7\right) = \\
   & = 5xy\left(2y+3x-7\right)
\end{alignat}
%\tagstructend Why i get an error,that there is no structure on the stack?
\end{document}

答案1

您会从 \tagstructend 收到错误,因为amsmath 命令会两次处理#1您后面的部分。您可以使用来在测量步骤中抑制此错误。\doactualtext\ifmeasuring@

由于您没有用波浪号替换空格,因此您获得了错误的替代文本。

\documentclass{article}
\usepackage{tagpdf,amsmath,xstring}
\tagpdfsetup{tabsorder=structure,uncompress,activate-all,interwordspace=true,tagunmarked=false}
\tagpdfifpdftexT
 {
    \pdfcompresslevel=0
  %set language / can also be done with hyperref
  \pdfcatalog{/Lang (en-US)}
  \usepackage[T1]{fontenc}
  \input glyphtounicode
  \pdfgentounicode=1
 }
\tagpdfifluatexT
 {
   %set language / can also be done with hyperref
  \pdfextension catalog{/Lang (en-US)}
  \usepackage{fontspec}
  \newfontface\zerowidthfont{freeserif}
}
\pagestyle{empty}
\ExplSyntaxOn
\makeatletter
\long\def\doactualtext#1{
\def\@mltext{\detokenize\expandafter{#1}}
\def\@mltexttmp{}
\StrBehind[5]{\@mltext}{~}[\@mltexttmp]
\StrGobbleRight{\@mltexttmp}{1}[\@mltext]
\tagstructbegin{tag=P,actualtext-o=\detokenize\expandafter{\@mltext}}
 \tagmcbegin{tag=P}
#1
\ifmeasuring@\else
\tagmcend
\tagstructend
\fi
}
\renewenvironment{alignat}{
\collect@body\doactualtext\space
\start@align
\z@\st@rredfalse
}{
\endalign
}
\makeatother
\ExplSyntaxOn
\begin{document}
\tagstructbegin{tag=Document}
\begin{alignat}
10xy^2+15x^2y-5xy7 & =  5\left(2xy^2+3x^2y-xy7\right) = \\
   & = 5x\left(2y^2+3xy-y7\right) = \\
   & = 5xy\left(2y+3x-7\right)
\end{alignat}
\tagstructend 
\end{document}

我不知道你的替代者应该做什么。

相关内容