我想重新定義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}
我不知道你的替代者該做什麼。