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
1 vote
1 answer
23 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{} ...
user avatar
  • 222
1 vote
0 answers
44 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 ...
user avatar
  • 11
3 votes
1 answer
109 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 ...
user avatar
  • 6,246
4 votes
1 answer
79 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 ...
user avatar
0 votes
1 answer
58 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 ...
user avatar
3 votes
1 answer
228 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 ...
user avatar
  • 6,246
5 votes
1 answer
73 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 ...
user avatar
  • 6,246
5 votes
1 answer
169 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} \...
user avatar
  • 8,650
1 vote
0 answers
57 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 ...
user avatar
0 votes
0 answers
29 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 ...
user avatar
  • 328
1 vote
0 answers
40 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/...
user avatar
6 votes
1 answer
94 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 ...
user avatar
0 votes
0 answers
44 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\...
user avatar
21 votes
1 answer
2k 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) ...
user avatar
  • 589
2 votes
1 answer
117 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 \...
user avatar
  • 11.3k
2 votes
0 answers
59 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 ...
user avatar
5 votes
2 answers
308 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 ...
user avatar
  • 1,089
2 votes
2 answers
45 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} $\...
user avatar
  • 987
1 vote
1 answer
124 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 ...
user avatar
3 votes
1 answer
70 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. ...
user avatar
  • 344
0 votes
1 answer
107 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 ...
user avatar
  • 1,373
5 votes
1 answer
165 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 ...
user avatar
  • 51
1 vote
0 answers
133 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 ...
user avatar
1 vote
0 answers
1k 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 ...
user avatar
  • 335
0 votes
0 answers
54 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{\...
user avatar
4 votes
2 answers
81 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 ...
user avatar
1 vote
1 answer
78 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 ...
user avatar
0 votes
1 answer
563 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'...
user avatar
  • 8,674
9 votes
1 answer
379 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 ...
user avatar
  • 44.9k
3 votes
1 answer
359 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 ...
user avatar
  • 847
1 vote
0 answers
207 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....
user avatar
  • 515
0 votes
1 answer
91 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 ...
user avatar
  • 1,140
1 vote
1 answer
126 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 ...
user avatar
5 votes
1 answer
83 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 ##...
user avatar
2 votes
1 answer
67 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{...
user avatar
  • 701
4 votes
3 answers
259 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 \...
user avatar
  • 12.9k
3 votes
1 answer
462 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 ...
user avatar
  • 8,069
0 votes
1 answer
77 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 ...
user avatar
  • 333
1 vote
1 answer
35 views

\AtEndOfEveryFile is executed in \begin{itemize}

I was quite surprised that the \AtEndOfEveryFile hook defined by the filehook package is executed in \begin{itemize}. Is this behaviour intended? If not, how and where do I file a bug report? \...
user avatar
  • 5,697
3 votes
1 answer
197 views

ConTeXt: What are alternatives and rendering setups?

I've seen the alternative keyword used throughout ConTeXt: \setuppagenumbering[alternative=doublesided] \setupheads[alternative=inmargin] \setuplist[section][alternative=d] I assumed that it was ...
user avatar
  • 769
2 votes
2 answers
141 views

Extra space at the end of the document added by PGF

As seen in this answer to my previous question “Extra vertical space at end of last column when loading adjustbox (only luatex)”, loading the package pgf causes the following to be added at the end of ...
user avatar
  • 1,527
7 votes
1 answer
859 views

Add command at the beginning of all frames

I need to add a command \setRTL from the bidi package to write right-to-left text, at the beginning of every frame. Another answer does not solve the issue; any suggestions? \documentclass{beamer} ...
user avatar
  • 16k
0 votes
1 answer
86 views

Hooks for many hypotheses or conclusions

Good morning! How can I do this? Thank's a lot!!! EDIT The below answer has this problem:
user avatar
1 vote
0 answers
142 views

KOMA-Script list of hooks [closed]

I'm currently trying to find the chapter name with KOMA-Script and probably need a hook for that. Is there a list with all the available hooks? Does anyone have better suggestions to do this? Thank ...
user avatar
  • 11
1 vote
2 answers
2k views

How to check successful compilation in PDFLaTeX?

I want to develop a pre-commit hook for my LaTeX Git repository. I need the hook to suppress the commit in case the compilation finishes unsuccessfully (missing packages OR missing source files OR ...
user avatar
  • 227
12 votes
1 answer
207 views

What is the (relevant!) difference between \file_input:n and \input? Or has something else changed?

A while ago I answered a question with code which attempts to set the name of an externalised image, produced with TikZ's external library, to something based on the name of the input file. That ...
user avatar
  • 184k
0 votes
2 answers
470 views

Add a command to every display mode math equation

Is it possible to have a hook in every display math mode, before and after the formula? For example: if I would like to make every display formula 50% smaller, I would ask the hook on entering the $$ ...
user avatar
  • 1,770
3 votes
1 answer
1k views

Conditional \if \fi using hooks \AtBeginDocument and \AtEndDocument

I wonder if there's a way in LaTeX to create a conditional in the whole document from the preamble? Something similar to this sample (which obviously does not work): \documentclass{article} \...
user avatar
  • 319
2 votes
0 answers
106 views

Collecting and analyzing data presented in tables

I have data presented in tabular environments and I want to process it, in LaTeX, in ways that require for multiple cells to be analyzed together. That's in addition to typesetting the cells ...
user avatar
19 votes
1 answer
1k views

What is exactly a hook in etoolbox

I understand well the \apptocmd and related tools of etoolbox package. However, I still not understand what \appto<hook>{<code>} and related do, even reading three time the handbook ? ...
user avatar
  • 10.7k