You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Given that code or rules can be added to a hook even if it doesn’t physically exist
yet, means that a querying its existence has no real use case (in contrast to other variables
that can only be update if they have already been declared). For that reason only the
test for emptiness has a public interface.
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:
\newcommand\abc{}
\renewtcolorbox{abc}{}
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 \NewHooks.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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