\tableofcontents でエラーなしで \section を再定義する方法

\tableofcontents でエラーなしで \section を再定義する方法

セクションを再定義して \tableofcontents を使用すると、エラーが発生することに気付きました:

! LaTeX エラー: 何かが間違っています。おそらく \item が欠落しています。

この問題を解決するために助けてください。ご協力くださった皆様に心より感謝いたします。

\documentclass{article}
\usepackage{tagpdf}
\tagpdfsetup{tabsorder=structure,uncompress,activate-all,add-new-tag=Title/P,interwordspace=true}
\ExplSyntaxOn
\makeatletter
\prop_gset_from_keyval:Nn{\g__sections_prop}{chapter=H1,section=H2,subsection=H3,subsubsection=H4}
\prop_map_inline:Nn \g__sections_prop{
\cs_set_eq:cc{orig@#1}{#1}
\cs_gset_protected:cpn{#1}##1{
\tagstructbegin{tag=#2}
\tagmcbegin{tag=#2}
\use:c{orig@#1}{##1x}
\tagmcend
\tagstructend
}
}
\makeatother
\ExplSyntaxOff
\author{Alexandr Kozlovskiy}
\title{test}
\begin{document}
\tagstructbegin{tag=Document}
\tagstructbegin{tag=Title}
\tagmcbegin{tag=Title}
\maketitle
\tableofcontents
\tagmcend
\tagstructend
\section{test}
\tagstructbegin{tag=P}
\tagmcbegin{tag=P}
new test
\tagmcend
\tagstructend

\section{new test}

\tagstructbegin{tag=P}
\tagmcbegin{tag=P}
new test again
\tagmcend
\tagstructend
\tagstructend
\end{document}

関連情報