This question connected with question about tagging of sections. I found solution,how to do it,but i dont know,how create/redefine document command,if command is argument of some other command. When i try to redefine it,i get an error:

LaTeX3 Error: First argument of '\RenewDocumentCommand' must be a command.

Help me please fix this. Also i have some doubts:

1. Should i use [{##2}] or simple [##2] for the second argument.
2. should i use {##3} or simple ##3 for third argument? Thanks everybody for any help.

```
\RequirePackage[patches]{pdfresources}
\DeclareDocumentMetadata{pdfversion=2.0}
\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}
\RenewDocumentCommand #1{s o m}{
\tagstructbegin{tag=#2}
\tagmcbegin{tag=#2}
\use:x{
\exp_not:c {orig@#1}
\IfValueT {##1} { ##1 }
\IfValueT {##2} { [{##2}]}
{##3}
}

\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}

```