Skip to main content

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.

Filter by
Sorted by
Tagged with
3 votes
1 answer
111 views

How to make this hook works in TikZ?

Question What do I need to change to make myhook work? Objective create a dia(gram) in TikZ, where coordinates depend on parameters (options) and resulting coordinates can be accessed or used (here: (...
MS-SPO's user avatar
  • 13.8k
2 votes
1 answer
46 views

SVG package and \AddToHook

I've just noticed a weird behavior of the SVG package when combined with Hook. If I run the following code, which just write a simple text to each page of a document \documentclass{article} \AddToHook{...
Laurent Jacques's user avatar
2 votes
1 answer
116 views

Is it possible to modify a \cs_new_protected:Nn function using hooks?

A user of one of my classes exceptionally wants to modify something that is hard-coded in a \cs_new_protected:Nn function. I can give her the means to redefine this function using \cs_set_protected:Nn ...
Denis Bitouzé's user avatar
0 votes
1 answer
53 views

Add a hook to the argument of a command based on its other arguments [closed]

Take \textcolor{#3}{#4} as a simple example. However, the actual command contains asterisked and optional arguments. If the argument #3 is green or blue, then \textcolor{#3}{#4} should produce ...
Inverted Pastry's user avatar
0 votes
0 answers
34 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 ...
Denis Bitouzé's user avatar
5 votes
1 answer
66 views

Changing page fonts using hooks in class

I am trying to understand how to work with hooks in classes to change the font (size, color, etc.) for the first page of a chapter, and then switch to another style in the chapter pages following the ...
drl's user avatar
  • 464
2 votes
0 answers
78 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 ...
cfr's user avatar
  • 208k
2 votes
1 answer
62 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 \...
Jinwen's user avatar
  • 8,618
2 votes
1 answer
52 views

Trigger code in para/begin hook for a precise paragraph

I made a simple system of multiple levels paragraph counters using the para/begin hook: \documentclass{article} \usepackage{lipsum} \usepackage{expl3} \usepackage{xparse} \usepackage{fancyhdr} \...
Antony Geedies's user avatar
2 votes
0 answers
100 views

Pass body of arbitrary environment to hooked command

I'd like to inject a command into an arbitrary environment that uses the environment body as an argument. Desired behavior \begin{AnyEnvironment}{MandatoryEnvArg}[OptionalEnvArg] ... \end{...
steve's user avatar
  • 2,256
4 votes
1 answer
72 views

Delay macro execution to when the container float is placed

I need an absolutely-positioned textblock* and a float to appear together on the same page. When the textblock* is written inside the figure, it is executed rightaway and thus seen on the page where ...
hschmauder's user avatar
3 votes
1 answer
58 views

Circuitikz adjust label baseline position with european resistors using hooks or custom components

I'm trying to figure out a way to position labels inside european resistors. I'm aware of the answer here, but I think the solution is a bit too complicated to use. I have figured out the following ...
ttsc's user avatar
  • 415
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 ...
Jinwen's user avatar
  • 8,618
3 votes
1 answer
124 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{...
mbert's user avatar
  • 4,541
1 vote
1 answer
71 views

\begin and \end in file hooks causing errors

With my package jwjournal, the whole document is put into an environment named jwjournal which does some regex replacement to the text. However, if the text is input via \input or \include, then the ...
Jinwen's user avatar
  • 8,618
2 votes
1 answer
47 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 ...
Jinwen's user avatar
  • 8,618
3 votes
1 answer
169 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, ...
mbert's user avatar
  • 4,541
2 votes
1 answer
66 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 ...
Felix Emanuel's user avatar
2 votes
1 answer
109 views

Problem with 'memoir' v3.8 and 'csquotes'

With the latest update of memoir (v.3.8) I detect an error if I also load csquotes and defines active quotes in the following way: \documentclass{memoir} \usepackage{csquotes} \MakeBlockQuote{<}{|}...
matteofg's user avatar
  • 175
1 vote
1 answer
140 views

Add a latex code before and after every \newtheorem

I define a few theorems with amsthm's \newtheorem, and I want to prepend and append an hrule for each one of them. Currently I do it with \AddToHook{env/〈env name〉/before}{hrule code} and \AddToHook{...
tush's user avatar
  • 1,147
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 ...
gusbrs's user avatar
  • 14k
3 votes
1 answer
158 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{...
mbert's user avatar
  • 4,541
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), ...
mbert's user avatar
  • 4,541
3 votes
1 answer
151 views

Wrapping environment in another environment with hooks

This problem is distilled from an environment that needs to use its body either wrapped in a minipage or not. Furthermore, this environment is to be automatically wrapped around all uses of another ...
melisgl's user avatar
  • 183
3 votes
1 answer
106 views

acro's \printacronyms fails for nested acronyms if inserted thanks to the \AtEndDocument hook

In the following MCE example, the acro's list of the acronyms \printacronyms is inserted, not in the document body, but in the preamble thanks to the hook \AtEndDocument and that works like a charm: \...
Denis Bitouzé's user avatar
1 vote
1 answer
111 views

Add text color to "proof" environment without adding extra vertical space

Consider the following MWE, in which I'm trying to change the text color of the environment proof via the hook env/proof/begin. However, the use of \color would give extra vertical space when ...
Jinwen's user avatar
  • 8,618
13 votes
1 answer
440 views

What's the difference between \AtBeginDocument and \AddToHook{env/document/begin}?

Here is an MWE: \documentclass{article} \usepackage{lipsum} \AtBeginDocument{\linespread{1}\fontsize{12bp}{23bp}\selectfont} % \AddToHook{env/document/begin}{\linespread{1}\fontsize{12bp}{23bp}\...
xdyy's user avatar
  • 590
4 votes
0 answers
117 views

Use shipout hooks to manipulate global state

I think that the recently introduced hook interface is an exciting extension of the interactions with LaTeX internals. They motivated me to resume my efforts to convince LaTeX to process page contents ...
H. Weirauch's user avatar
1 vote
1 answer
86 views

AddToHook for polyglossia to change chapter name doesn't work

I want to change the chaptername from פרק (polyglossia's default) to חלק. Because the .tex file is created with LyX, and since the LyX editor adds the \usepackage{polyglossia} \setdefaultlanguage{} ...
tush's user avatar
  • 1,147
1 vote
0 answers
111 views

Wrap text around an image (logo) placed in every page

I'm trying to help out the founders of a new open access journal called Seeds of Science to translate their article template from Word to LaTex. The top of every page should look like this: My rough ...
eparra's user avatar
  • 11
3 votes
1 answer
172 views

Fail to add hook to a command when there is an extra group

Consider the following example. The code is trying to append something after \mytest. Strangely, when there is an extra group, the \hook_gput_code:nnn does not work. There is no error message, just ...
Jinwen's user avatar
  • 8,618
4 votes
1 answer
324 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 ...
TrizZm4ster's user avatar
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 ...
Pieter van Oostrum's user avatar
4 votes
1 answer
306 views

Why cannot hooks be added to command names with underscore?

Consider the following example, which tries to add some code to a command's hook. If I replace g__mytest_tl to simply mytest then everything works fine. Does this mean that the hook system do not ...
Jinwen's user avatar
  • 8,618
5 votes
1 answer
246 views

What is the expl3 equivalent of \AddToHook?

While writing a package, when encountering commands like \selectlanguage that do not work inside the preamble, I've learned to put them inside \AddToHook{begindocument}{...}, so that if it is called ...
Jinwen's user avatar
  • 8,618
5 votes
1 answer
294 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} \...
L.J.R.'s user avatar
  • 11.3k
1 vote
0 answers
84 views

Naming conventions for private hooks in packages using lthooks

In some package, I use a lot of hooks (using the lthooks package) that are however not intended to be used as a hook by other packages / users. Only certain code makes sense there, and I use hooks ...
Maximilian Keßler's user avatar
0 votes
0 answers
35 views

Memoir: generic hook is deprecated [duplicate]

Since a couple of months, I get the following warnings when using the memoir class. Generic hook 'package/before/framed' is deprecated. Generic hook 'package/before/float' is deprecated. Is this ...
Safron's user avatar
  • 360
2 votes
0 answers
46 views

How to use Silence package to silence hooks warning [duplicate]

When I run the following .tex source file through latex: \documentclass[11pt,twoside,article]{memoir} \begin{document} Hi \end{document} I get the following warning: ... (/usr/local/texlive/...
Curious Yogurt's user avatar
7 votes
1 answer
354 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 ...
Marius Hofert's user avatar
0 votes
0 answers
147 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\...
Alex Shevchenko's user avatar
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) ...
Didier's user avatar
  • 1,323
2 votes
1 answer
246 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 \...
gusbrs's user avatar
  • 14k
2 votes
0 answers
104 views

Automatic Paragraph Numbers [2021, Using LaTeX's 2020's New Hook Management]

This is a 2021 follow-up question to my question from 2015. I want to add to every text paragraph an number automatically (see original question). In 2015, user @Fran warned me regarding the solution ...
Dr. Manuel Kuehner's user avatar
5 votes
2 answers
632 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 ...
Witiko's user avatar
  • 1,006
2 votes
2 answers
67 views

Different behavior of \gcd analogs within babel russian and serbianc?

Consider the following two analog MWEs: 1. \documentclass{article} \usepackage[T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage[russian]{babel} %\let\gcd\NOD \listfiles \begin{document} $\...
ivankokan's user avatar
  • 1,076
1 vote
1 answer
358 views

With ltshipout, how to make some `picture` environment's content visible both if the pages are colored and only on the first page?

The following MCE shows that, if the pages are colored, a picture environment's content is: visible with \AddToHook{shipout/background} and \AddToHook{shipout/foreground} (but) on all pages, not ...
Denis Bitouzé's user avatar
3 votes
1 answer
161 views

Future variable reference

For a document I am working on I would like to achieve something along the following lines: In the beginning of the document, a summary of the most important parts mentioned in the document are given. ...
G. de Man's user avatar
  • 364
0 votes
1 answer
328 views

Lastpage and \enddocumenthook: extra page created

Here is a MWE that on my Mac (MacTeX, several months old) produces the expected one page of output (as also happen on earlier versions of MikTeX), but on the latest version of MikTeX (21.1) produces ...
rbrignall's user avatar
  • 1,574
5 votes
1 answer
196 views

storebox not working as expected since texlive 2020

I have to include page-specific content multiple times per page (DM codes to be specific) in a LaTeX document. To that end I use a combination of storebox and everypage such that content is typeset ...
moepi's user avatar
  • 51