MWE as follows:
\documentclass{article}
\begin{document}
\NewMirroredHookPair{cmd,test,begin}{cmd,test,end}
\def\testcmd{%
\UseHook{cmd,test,begin}
\def\TTTa{TTTa-val} % only '\gdef' can use '\\\TTTa'
% \TTTa % ---> works well.
\\ \TTTa % ---> error: ! Undefined control sequence. <recently read> \TTTa
\UseHook{cmd,test,end}
}
\AddToHook{cmd,test,begin}{\fbox{BEGIN}\begin{tabular}{c}}
\AddToHook{cmd,test,end}{\end{tabular}\fbox{END}}
TEST: \testcmd
\end{document}
The above code can not compile, the error log is:
This is pdfTeX, Version 3.141592653-2.6-1.40.27 (TeX Live 2026/dev/Arch Linux) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2024-11-01> patch level 2
L3 programming layer <2025-01-18>
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2024/06/29 v1.4n Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def) (./test.aux)
! Undefined control sequence.
<recently read> \TTTa
l.52 TEST: \testcmd
?
But if i:
- use
\TTTainside\testcmd, it compiles. - remove these 2
\AddToHookabouttabular, then both\TTTaand\\\TTTacan be used. - replace
\def\TTTaby\gdef\TTTa, then both\TTTaand\\\TTTacan be used.
I'd like to use \\\TTTa together with \def\TTTa and these two tabular hooks. How can I achieve this ? Is it possible ?
longtableto replicate a comlex contentsline style frometocpackage. The part before '\\' corresponds to the contents line title, which use\multicolumn.