Questions tagged [hooks]
{hooks} are macros (or placeholders) stored at specific locations inside other macros that can be redefined to the user's specifications, thereby "hooking into" the macro at that specific point.
141 questions
5
votes
2
answers
177
views
Why does \AtBeginDocument have a different effect from within a class file than from without?
Consider the following MWE, where I use a custom class test which loads the libertinus fonts and sets up selecting StylisticSet=2 in order to obtain a more harmonious italic J, as proposed in this ...
2
votes
1
answer
99
views
Is there a reason to choose multiple local `\newcommand`s over multiple local `\let`s to a global command?
For context, I want a/some function(s) to only be defined in certain environments. I found (after much failed bodging on my part) the delightful function \AddToHook so I can use
\AddToHook{env/myenv/...
1
vote
1
answer
68
views
How to correctly set the bounding boxes when creating boxes using the `shipout/before` hook?
I want to assemble some boxes onto the page through which text should flow. I know that there are already some packages that solve this, but I would like to better understand the underlying logic of ...
2
votes
1
answer
76
views
Incorrect AddToHook time with color switch in new chapter?
Description:
I make a colorful ornament line style switch with new chapters:
First Chapter: red
Second Chapter: blue
Third Chapter: red
Fourth Chapter: blue
I manage to use hook as below, but it ...
10
votes
1
answer
156
views
The catcode of return (^^M) in shipout hook is 9 (instead of 5)
After the June update of TeX Live, the catcode of `return' (^^M) in the shipout hook changes from 5 to 9. Is this intentional behavior or a bug? If intentional, what is the purpose of this? Here is an ...
6
votes
2
answers
178
views
Using \pgfornament in shipout hook causes an error
The following MWE worked perfectly in the past with TeX Live.
\documentclass{article}
\usepackage{pgfornament}
\AddToHook{shipout/foreground}{\pgfornament[anchor=north west]{31}}
\begin{document}
text
...
0
votes
0
answers
36
views
Default options for displayed listing
If I specify some settings for a every display style listing via \lst@AddToHook{\lstset{...}}, it will be impossible to overwrite this setting by passing local options to the listing.
\documentclass{...
3
votes
2
answers
147
views
\AddToHookNext for beamer frame
I'm trying to locally change some frame settings in beamer. For example, the code
\documentclass{beamer}
\begin{document}
\AddToHookNext{env/frame/before}{\bfseries}
\AddToHookNext{env/frame/after}{\...
3
votes
2
answers
189
views
Increase bottom margin on first twocol page, automatically restore on next page
I would like to change the bottom margin on the first page of a two-column article (that can sit somewhere in the document, so is not necessarily the first page of the document) without inserting a ...
3
votes
2
answers
126
views
Error "Illegal mode change in hook 'para/before'"
I am trying to output some material (e.g., a character) at the begin of every paragraph. That is, if the paragraph begins with the letter 'A', then there should be first my material (e.g. the letter '...
6
votes
1
answer
123
views
How to insert one blank page after every current page in the [limited area] of document?
Setup
Windows11; TeXLive2024; WinEdt11; PDFLaTeX.
The statement of my problem
I intended to apply this method to insert one blank page after every current page of document partially(locally).
As is ...
5
votes
2
answers
200
views
Is it possible to make \AddToHook{cmd/caption/before} work with the caption package?
In the following, I'm adding a label to a caption thanks to \AddToHook{cmd/caption/before}. This works well, except if the caption package is used:
LaTeX Warning: Reference `foo1' on page 1 undefined ...
-1
votes
1
answer
191
views
LaTeX hooks have broken working code [closed]
This is an MWE distilled from a quite big system where the error messages are even more cryptic.
MWE:
\documentclass{article}
\usepackage{MyStyle}
\begin{document}
\PopDefaultHookLabel
Case 0:
%\...
1
vote
2
answers
152
views
Non-locality of itemize fumbling with \par
For reasons, I have code that puts a hook in cmd/par/after (for this MWE, this will be the stupid \vskip 2cm). I know that many parts of LaTeX interact and redefine \par and this can break hooks, as I ...
0
votes
1
answer
96
views
\@setpar and hook execution order
I have a command that typesets source code, and the text it produces ends with \par. For simplicity, let say we have
\NewDocumentCommand{\commandFromAPackage}{}{line1\par line2\par}
Sometimes, I ...