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
99 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
  • 2,615
2 votes
1 answer
51 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
91 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{<}{|}...
matteo339's user avatar
1 vote
1 answer
128 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,093
1 vote
1 answer
43 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
  • 13.2k
2 votes
1 answer
60 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
  • 2,615
3 votes
1 answer
52 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
  • 2,615
2 votes
1 answer
58 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
  • 173
3 votes
1 answer
71 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
0 answers
62 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
  • 7,826
11 votes
1 answer
298 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
  • 581
2 votes
0 answers
72 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
68 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,093
1 vote
0 answers
83 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
130 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
  • 7,826
4 votes
1 answer
179 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
102 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
267 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
  • 7,826
5 votes
1 answer
171 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
  • 7,826
5 votes
1 answer
244 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
  • 10.5k
1 vote
0 answers
74 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
32 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
  • 350
2 votes
0 answers
45 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
6 votes
1 answer
181 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
104 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
25 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,281
2 votes
1 answer
193 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
  • 13.2k
2 votes
0 answers
82 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
538 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,206
2 votes
2 answers
58 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,026
1 vote
1 answer
265 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
144 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
194 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,452
5 votes
1 answer
185 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
1 vote
0 answers
182 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 ...
Denis Bitouzé's user avatar
1 vote
0 answers
2k views

Package hooks Error: Extra \PopDefaultHookLabel

Recently I moved from Mac to Windows and when I compile the document class nle.cls in Windows, which can be downloaded from this link (it is a journal template), I get lots of errors. I did not have ...
Mila's user avatar
  • 365
0 votes
0 answers
58 views

How can I insert commands when entering into mathmode and when exiting from mathmode?

I want to insert \special's when entering into mathmode and when exiting from mathmode. I wrote the following source code with everyhook.sty: \documentclass{amsart} \usepackage{everyhook} \newcommand{\...
user232282's user avatar
4 votes
2 answers
119 views

Display number of sections at the beginning of a chapter

My goal is to display the number of sections the chapter contains, at the beginning of every chapter. Currently, my idea is to store in the aux file the value of the section counter at the end of ...
Nathan.Eilisha Shiraini's user avatar
1 vote
1 answer
103 views

How to redefine \\ command inside a tabular using expl3?

When i try to redefine \\ inside a tabular,my redefining not works. I understood,what probably after hook \AtBeginEnvironment something redefine my \\ command,but i dont know,how to fix it. Help me ...
Aleksandr Kozlovskiy's user avatar
0 votes
1 answer
793 views

\src@load@hook undefined error after Miktex update and using

I know it is normal practice to place a MWE, however in this case, I hope by just stating the error, you can help me down some path I can take to resolve this issue. I have been using Harvey Sheppard'...
Joe's user avatar
  • 9,024
9 votes
1 answer
560 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 ...
gernot's user avatar
  • 48.3k
3 votes
1 answer
587 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 ...
rolfn's user avatar
  • 939
1 vote
0 answers
216 views

CTeX recent update causing problem: \ctex_gadd_hook:Nn \CJKhook { \ctex_set_ignorespaces: }

It was fine by 17th Sep and the file would compile using PDFLaTeX to produce PDF. \documentclass[12pt, a4paper]{ctexrep} \usepackage{amsmath} \usepackage{adjustbox} % uses graphicx \usepackage[top=1....
CasperYC's user avatar
  • 649
0 votes
1 answer
93 views

Re-defining `\\`

EDIT: The original version of this was a foolish question; @egreg points out that I was thinking of {amsmath}'s matrix environment. I'm sure that this has been asked before, but it's hard to search ...
LSpice's user avatar
  • 1,394
2 votes
1 answer
222 views

\AtEndPreamble hook breaks hyperref with bibliography

In the past I used \usepackage{hyperref} within the \AtEndPreamble{} hook, without problems. At least I think so. However, recently the hook breaks the links to my bibliograpy. Is that a bug or am I ...
Robert Seifert's user avatar
5 votes
1 answer
98 views

How to work with members of sequence during iteration with expl3?

I have several environments before and after which I want to insert identical code. I want to do this using expl3 because in my opinion it is the best solution. But my solution does not work because ##...
Aleksandr Kozlovskiy's user avatar
2 votes
1 answer
93 views

Hooking an environment inside `document` environment

I am making a beamer-document that is basically a one-page frame. Since don't want to explicitly call the frame inside the environment, I how \begin{frame}[t] at the beginning of the document and \end{...
lfba's user avatar
  • 721
4 votes
4 answers
323 views

Add material to a macro with parameter

I'm trying to define a macro \addtohook that adds material to another macro \hook, similar to LaTeX's \addto@hook, but where \hook takes a parameter. So if \hook is empty at start, after a series of \...
siracusa's user avatar
  • 13.3k
5 votes
1 answer
792 views

How to run a command before compiling (hook script) in latexmk?

I use latexmk to compile a project. It should run some bash commands before starting to compile. I tried to add $compiling_cmd="date >> /tmp/compiled.log"; to the local .latexmkrc file. But ...
Jonas Stein's user avatar
  • 8,699
0 votes
1 answer
142 views

Automatically drawing frames around document elements with LaTeX

I wonder how to draw frames around various elements in LaTeX (or LuaLaTeX if needed)? I would like to get frames around every text paragraph, and/or every equation, every image, every header, every ...
FabPop's user avatar
  • 343