2

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 \TTTa inside \testcmd, it compiles.
  • remove these 2 \AddToHook about tabular, then both \TTTa and \\\TTTa can be used.
  • replace \def\TTTa by \gdef\TTTa, then both \TTTa and \\\TTTa can 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 ?

2
  • why do you want a tabular with an empty first row? Commented Sep 15 at 15:32
  • @DavidCarlisle I am using longtable to replicate a comlex contentsline style from etoc package. The part before '\\' corresponds to the contents line title, which use \multicolumn. Commented Sep 15 at 15:40

1 Answer 1

5

this is not really related to hooks.

Every alignment cell is a group, so if you want the definition to be visible in all cells (and made with a non global definition) ensure the definition is before the alignment starts.

\documentclass{article}

\begin{document}
\NewMirroredHookPair{cmd,test,begin}{cmd,test,end}
\def\testcmd{{% extra group
  \def\TTTa{TTTa-val}% only '\gdef' can use '\\\TTTa' don't have space before %
  \UseHook{cmd,test,begin}% dont forget %
  % \TTTa  % ---> works well.
  \\ \TTTa % ---> error: ! Undefined control sequence. <recently read> \TTTa 
  \UseHook{cmd,test,end}% dont forget %
}}
\AddToHook{cmd,test,begin}{\fbox{BEGIN}\begin{tabular}{c}}
\AddToHook{cmd,test,end}{\end{tabular}\fbox{END}}
TEST: \testcmd
\end{document}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.