Questions tagged [lthooks]
{lthooks} is the hook management system built into the LaTeX kernel. Questions tagged {lthooks} are about their behaviour and usage.
44
questions
6
votes
1
answer
105
views
Replacing `\everypar` with a hook
This snippet uses \obeylines and \everypar to add a number at the start of paragraphs and and \hfill. How can I replace the everypar since it not recommended to be used any longer, now that we have ...
0
votes
0
answers
35
views
Make the instructions added to a given hook in the end applied in a different order
Let's suppose that, in the source file of a class, different instructions are added to the same hook (e.g. begindocument/end) in different (potentially distant) places, and in a certain order. Is ...
7
votes
2
answers
246
views
How to use AddToHook add code for a env after the beginning code
The code \AddToHook{env/myenv/begin} will run the code after the env group but before the beginning code is executed. How to run some code after the being code is executed?
See the following example
\...
2
votes
0
answers
82
views
How should I have diagnosed this? Figuring out when to insert code into hooks to alter third party package behaviour
This question seems very confused to me, so I'm not sure you will be able to make sense of it.
I know how to solve this problem (now). What I would like to know is how I should have diagnosed and ...
3
votes
2
answers
75
views
How to use hook to change \parskip in minipage?
I try to use a hook to change the \parskip in the minipage environment. But my code doesn't work.
Here is an MWE.
\documentclass{article}
\AddToHook{env/minipage/begin}{\setlength{\parskip}{2em}}
\...
6
votes
1
answer
243
views
Current best practice re. cross-references to last page
I am/was using pageslts, which I know is not supposed to be compatible with current LaTeX. As far as I understand, there is no alternative offering the same functionality, but I'd like to at least ...
0
votes
0
answers
46
views
Using package hooks with hyperref to avoid package conflicts
By now only a small number of packages, need to be loaded after hyperref. Consider the code below, that creates a clist with such packages algorithm,1algorithmic,arydshln and chappg. So far the code ...
2
votes
1
answer
68
views
Set value for macro at the beginning of each page
I am trying to set the value of a macro at the beginning of each page using shipout hooks. Consider the following example:
\documentclass{article}
\ExplSyntaxOn
\tl_new:N \g_mymodule_test_tl
\...
0
votes
0
answers
61
views
Track all macro calls inside input .tex file (via luatex?)
If we have an input .tex file, how to find all macro invocations in it?
\documentclass{article}
\newcommand{\samplemacro}{This is a sample macro.}
\begin{document}
\samplemacro
\begin{itemize}
\...
5
votes
1
answer
150
views
\AddToHook{begindocument/end}{⟨code⟩}\begin{document} not equivalent to \begin{document}⟨code⟩?
(This a follow up of this question about indentation of paragraphs with the standalone class.)
The following MCE gives the expected result (indented paragraphs):
\documentclass[varwidth]{standalone}
\...
8
votes
1
answer
189
views
What is the recommended way to use \everypar now that LaTeX has hooks?
Now that LaTeX has hooks, there is a recommendation to use the hooks interface for everypar? How should this be done in l3 programs?
\documentclass{article}
\ExplSyntaxOn
\newcounter{eplinenumber}
\...
0
votes
1
answer
53
views
Correct way to remove spaces when adding hooks to environment
Please see addendum before reading the question. I have not deleted or made major edits to it so as not to invalidate @cfr's answer.
I'm trying to add some hooks to a theorem environment, and I ...
3
votes
1
answer
94
views
Test if a user command is at the end of the document
Is there any chance for a command \testcommand to test if it is the last user command before \end{document}? Since there are still hooks at enddocument, this seems a little bit tricky.
I am thinking ...
3
votes
1
answer
168
views
Adding to package hook after it's been loaded
It was my understanding of kernel hooks that adding to a hook only affects instances that follow that addition. This seems true for in-document hooks. For example, with
\begin{quote}
some text
\end{...
2
votes
1
answer
48
views
How to test if a hook with certain label exists
The lthooks documentation says:
But how should one know in advance if the hook with this given label exists or not? In my package I wish to clear the code with a given label in a hook before adding ...
3
votes
1
answer
184
views
Using lthooks to locally hook into command
Following a previous question of mine, as an exercise I'm trying to mimic the behavior of thmtools with amsthm using l3keys and lthooks. Now I am stuck on the hooks part. thmtools defines prehead, ...
2
votes
1
answer
67
views
ltpara's new hook management and scrlayer-scrpage (for automatic paragraph counting, etc)
I have read that one should not use \everypar but rather \AddToHook{para/begin} for automatic paragraph enumeration and related operations. In principle, this works fine (mwe without counting, just ...
3
votes
1
answer
118
views
Understanding \RemoveFromHook with label
I've realized my answer to this question about removing the effect of \tcolorboxenvironment is not ideal because it removes all content from the hooks env/<envname>/before and env/<envname>...
1
vote
1
answer
49
views
\ShowHook, but only the code for a specific label
\ShowHook and its L3 counterpart \hook_show:n provided by lthooks are documented to print in the terminal a number of pieces of information about a given hook, including "the code chunks (and ...
3
votes
1
answer
172
views
Cannot add to "after" hook of sectioning command
It seems one cannot add to the "after" hook of a sectioning command. For example the document
\documentclass{article}
\AddToHook{cmd/section/after}{\bfseries}
\begin{document}
abc
\section{...
1
vote
0
answers
36
views
Why does \AddToHook{enddocument} create an extra page with the standalone class?
As shown in the following MWE, \AddToHook{enddocument} creates an extra page with the standalone class (with varwidth option), compared to the article class. Why, and is there a workaround?
% \...
3
votes
1
answer
58
views
\RemoveFromHook not working as expected if code placed in package file
In my answer to this question, something occurred that I don't understand about the hook system. If the code that adds a hook is directly in the main tex file (\tcolorboxenvironment in this example), ...
3
votes
1
answer
139
views
\AtBeginDocument and packages
Here is a very puzzling behaviour of the (Lua)LaTeX compiler. In the situation below, the output depends on whether some code in put in a package or directly in the main file; asking for an extra \...
91
votes
7
answers
5k
views
Important improvements of LaTeX over the last ten years (2013-2022)
We haven't had this question since many years (2016, 2014, 2010), but especially the question from 2014 has been viewed for more than 50k times, so it seems we should provide an up-to-date answer once ...
3
votes
1
answer
163
views
Caption Spacing Wrong do to Polyglossia
Consider the following example:
% lualatex test.tex
\DocumentMetadata{}
\documentclass[a4paper]{article}
\usepackage{polyglossia}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
...
3
votes
1
answer
242
views
Access to the complete \ShipoutBox (LaTeX hooks)
The following small sample document shows the manipulation of the \ShipoutBox (mirroring as an example) using a LaTeX hook. The background is not mirrored as it is not yet part of the box. This is an ...
2
votes
0
answers
3k
views
EuropeCV fails with LaTeX2e pre-release because of loading hyperref in \AtBeginDocument
Below is a minimal example that compiles successfully with stable TeX Live 2022 pdflatex but fails with the latest (and expected to be released in a couple days I think) pdflatex-dev:
\documentclass[...
4
votes
1
answer
344
views
Execute \clearpage before a section only if a certain amount of lines are already filled
I use:
\AddToHook{cmd/section/before}{\clearpage}
to start a new page before a new section. Is there a possibility to only execute this, if more than X percentage of the page is already filled?
So ...
1
vote
1
answer
119
views
Gregoriotex interferes badly with fancyhdr, how to solve this?
This is a sequel to this question. But it addresses a different problem.
When the above mentioned question was posed about a year ago, I had not noticed it. By accident I saw it last week, and as it ...
0
votes
2
answers
144
views
Passing nested argument specifier to hook
Consider a macro that
declares some other document command, but by accepting their body as an own argument (simple indirection)
also adds the invocation of itself to some hook
as in
\...
5
votes
1
answer
300
views
Command hooks vs package hooks, which is better?
In designing hook interfaces for my package. I found out that I have two methods of defining hooks:
\documentclass{article}
\begin{document}
\section*{Method 1: Use Command Hooks}
\...
8
votes
1
answer
384
views
How to reset/clear a hook (or: how to print a background picture only once)
I'd like to add a picture in the background of a single page, but if I use \AddToHook it appears on every page of the document. If I want to clear it after it appears on that specific page (so only ...
0
votes
0
answers
148
views
how to execute commands with env hooks depending of document part?
Consider test case:
\documentclass{report}
\usepackage{appendix}
\title{Title}\author{}\date{}
\newcommand\hooktest{this shouldn't be printed}
\AddToHook{begindocument/before}{
\renewcommand\...
0
votes
0
answers
70
views
Last page in \AddToHook{enddocument/end} not displayed
The following MWE gives only two pages, the third one not being displayed. Why?
\documentclass{article}
\ExplSyntaxOn
\AddToHook{enddocument/end}{
1
\newpage
2
\newpage
3
}
\ExplSyntaxOff
\...
26
votes
1
answer
3k
views
'Generic hook <name> is deprecated' warning after update
I have had a warning for a few days (since I updated MiKTeX):
LaTeX hooks Warning: Generic hook
(hooks) 'file/after/translations-basic-dictionary-french.trsl' is
(hooks) ...
2
votes
1
answer
257
views
Adding a comand hook to \appendix with cleveref
I'm trying to set a hook to the \appendix command using the new hook management system. However, when cleveref is loaded, the hook fails with error "Illegal parameter number in definition of \...
5
votes
2
answers
639
views
How can I use LaTeX hooks in historical versions of TeX Live?
At the end of 2020, LaTeX added support for a general hook management system. The system allows me to execute \maketitle at the beginning of a document if I am in the preamble, or immediately if I am ...
3
votes
1
answer
98
views
\AtBeginEnvironment{tikzcd} hasn't any effect
Several babel modules (e.g. the ngerman one) make active the " character, and this is the source of troubles with the tikz-cd package and the tikz' babel library may be not enough (see e.g. this ...
1
vote
0
answers
200
views
How to require a LaTeX version that provides the new hooks management system?
A class of mine is loading the biblatex package if the user uses a given option. For this, the class used to rely on \AtEndPreamble{\RequirePackage{biblatex}} and I guess it used to work nicely. It ...
9
votes
1
answer
382
views
file/after hook executed twice with listings and LaTeX 2020-10-01 PL3
This morning after an update to LaTeX 2020-10-01 PL3 my test suite failed with a mysterious error.
The error could be traced back to a not-so-minimal WE of the following form
\documentclass{scrartcl}
\...
1
vote
2
answers
79
views
How to hook in \input{foo/bar} and not \input{bar}?
Consider the following root document that imports two different files named bar and uses the file/before/... hook.
\documentclass{minimal}
\begin{document}
\ExplSyntaxOn
\AddToHook { file/before/bar } ...
8
votes
1
answer
296
views
Wrapping the document environment into another environment fails since LaTeX Update of October 2020
Since the last LaTeX Update, wrapping \document into another environment fails, possibly because of the new hook management system.
The following used to work:
\documentclass{article}
\newenvironment{...
9
votes
1
answer
676
views
\renewenvironment and environment hooks
This question refers to the hook system of LaTeX 2e introduced in October 2020 (lthooks).
How does \renewenvironment interact with its hooks?
Are the hooks cleared or does the code already added to ...
3
votes
1
answer
735
views
Removing the content of a LaTeX hook (using lthooks)
In a special case (new version of the document class leaflet) I use the new LaTeX hook shipout/before to save the finished pages in box registers without output. In the next step they are combined and ...