questioning "querying [a hook's] existence has no real use case" #1256
mbertucci47
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Apologies if this is the wrong place to ask, but it seemed more appropriate than an issue or TeX.SX.
The documentation for lthooks says
However I am running into a use case where it would be nice to know if a hook has already been declared (the content of the internal conditional
\__hook_if_declared:nTF
), and would appreciate some guidance as to whether it is a misuse of hooks or a genuine use case.The use case is
\new...
-type command that sets up a hook and also needs a\renew...
or\declare...
counterpart. If I know that a command is defined with my specific\new...
command, then I can just not do\NewHook
in\renew...
. However there are situations where a command/environment is defined with e.g.\newcommand
so to overwrite this with\renew...
the hooks still need to be defined. Here something like\ProvideHook
would be useful.Here's a toy example where I use
\__hook_if_declared:nTF
just to show the desired behavior, fully knowing using internals is a bad idea. The command\newhooktheorem
should define a theorem with a hook after the heading, and\renewhooktheorem
should overwrite an existing csname whether or not it was defined with\newhooktheorem
,\newtheorem
,\newcommand
, etc.You might say that
\renewhooktheorem
should only overwrite csnames defined with\newhooktheorem
, however needing\renew...
even for commands defined a different way is the behavior of, for example, tcolorbox. To overwrite\abc
below, you need\renewtcolorbox
:Additionally, the most common situation I can think of where
\renewhooktheorem
would be useful is if a class (thesis class, Beamer, etc.) predefines a bunch of theorems that the user wants to overwrite.While I understand the reasoning that hooks can be added to before they are declared so existence is not a useful check, this is a situation where I just need to check existence so as not to get an error with multiple
\NewHook
s.Beta Was this translation helpful? Give feedback.
All reactions