Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [patching]

{patching} is for questions about patching the definition of macros.

107
votes
4answers
31k views

Can I redefine a command to contain itself?

I'd like to "add to" an existing command by writing something like \renewcommand{\somecommand}{\begin{something}\somecommand\end{something}} but (not surprisingly) I get errors about being "too ...
58
votes
2answers
12k views

Please tutor the usage of patchcmd and xpatch

I understand that the patchcmd package provides a command \patchcommand that can be used to add material at the beginning and/or end of the replacement text of an existing macro. It works for macros ...
33
votes
2answers
3k views

Reliable code for automatic \noindent after specific environments?

This question led to a new package: noindentafter There are a number of environments which I never want to follow up with an indented paragraph. itemize, enumerate, theorem, definition, etc. I know ...
28
votes
5answers
2k views

How does one append material to a token list?

Several times, the floatrow package uses \newtoks which (according to this website) means that a token register is allocated. An example code snippet is \@ifdefinable\FR@everyfloat{\newtoks\FR@...
26
votes
3answers
5k views

Modifying .sty files?

Yesterday I did some changes in the layout of my TeX document. I couldn't accomplish the changes until I opened the .sty files and modified some of their code. I am sure this is not the best idea. For ...
20
votes
2answers
644 views

Is there an easy way to patch commands containing ^^J?

I'm currently looking at various questions related to multicol and try giving answers to some of them. Often enough the answer would involve patching \balance@columns or similar macros and in that ...
19
votes
1answer
2k views

biblatex: Is it possible to patch macros created with \newbibmacro?

This question led to a new feature in a package: xpatch The etoolbox package provides various tools that "are useful to hook into or modify existing code" (etoolbox manual, section 3.4). The most ...
18
votes
1answer
345 views

Patching commands in LaTeX3

Is there some facility in the LaTeX3 kernel to modify existing commands like etoolbox's \preto \appto and \patchcmd do?
16
votes
1answer
2k views

How to patch a package

I have a document that uses symbols both from the marvosym package as well as the eurosym package. There are two commands that clash and I get an error message (due to \newcommand being used and ...
11
votes
2answers
515 views

Patching commands to remove surrounding whitespace

I'm using the todonotes package to add little margin notes to my text, however writing Hello\todo{test} World! removes the interword space as is already pointed out in this question. So I tried \...
11
votes
2answers
3k views

What is the right way to redefine macros defined by babel?

If I want to use the babel package and redefine a macro such as \contentsname, what is the right way to go about this? Just putting \renewcommand in the preamble doesn't work. This sort of works \...
10
votes
3answers
2k views

error when patching with etoolbox \apptocmd: “the patching command seems to be nested in the argument to some other command”

The \apptocmd command from etoolbox is giving me an error I don't understand. I know how to work around the error in this particular case, but I'd like to understand what it's complaining about so ...
10
votes
2answers
2k views

How to redefine or patch the '\newcommand' command?

The Problem There are several packages I would like to write which require me to redefine the \newcommand (\renewcommand, etc.) command so I can track or change the commands that authors subsequently ...
10
votes
1answer
119 views

Using expanded macro as search pattern for \patchcmd

Is there any way to use the value of an expanded macro as the search pattern for etoolbox's \patchcmd (or xpatch's \xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of ...
9
votes
3answers
8k views

Separation space between tableofcontents items in beamer

In beamer, I guess, the separation space between the items from tableofcontents is stretchable: Can you set it to a fixed value? e.g. to equal the value used in the itemize environment. Partial ...
9
votes
2answers
1k views

How to append code to a section?

In my scrartcl document I want to change the spacing between sections and the first paragraph. Since I am using the parskip package, the parskip is set to a non-zero value. The \section command uses \...
9
votes
2answers
770 views

Using conditionals to ignore command does not work

I am trying to pdflatex a file but I get the following error: ! Incomplete \iffalse; all text was ignored after line [...]. The source of the error is a patch I used from here: Allowframebreaks ...
9
votes
1answer
466 views

Is there a workaround for this limitation of \patchcmd?

The \patchcmd command of the well-known etoolbox package has a minor limitation: Patching seems to fail whenever \patchcmd is used in the argument of another command and the search/replacement texts ...
8
votes
3answers
2k views

How to patch a floating environment so that the patched command floats

I'm using etoolbox to patch some environments. I want to use \AtBeginEnvironment{table}{\marginpar{foo}} to put something in the margin by the float. But the marginpar is typeset where the environment ...
7
votes
3answers
5k views

Change line spacing for normal text, but not in tabular or verse

\usepackage{setspace} \doublespacing I used above two lines to change the spacing in my document. This changes the spacing of the entire document. My requirement is to change the line spacing in ...
7
votes
2answers
164 views

Trouble with patchcmd and double #

I need to patch the following macro from gloss-greek.ldf (polyglossia): \def\greek@numbers{% \let\latin@alph\@alph% \let\latin@Alph\@Alph% \if@greek@numerals \def\greek@alph##1{\...
7
votes
1answer
142 views

Disable changebar command in the header

I want to add changebars to toc-entries. It actually works fine but I had to disable the command in the \mark commands (so that changebar settles and stops the "rerun" messages in the log-file). The ...
6
votes
1answer
184 views

Does LaTeX3 have something for patching (or appending code to) commands?

Item #12 of https://tex.stackexchange.com/a/148734/18401 suggests that LaTeX3 maybe has something for patching (or appending code to) commands, à la etoolbox or xpatch. Is it the case?
6
votes
1answer
290 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} ...
6
votes
1answer
557 views

Add dot to the end of section numbering in PDF bookmarks

I have dots at the end of section, subsection, etc. titles using the secdot package. And I'd like to insert a dot at the end of each section number in the PDF bookmarks too (I'm using hyperref). Here ...
6
votes
1answer
313 views

Using ted (or another package) instead of etoolbox for patching commands in memoir?

Another question related to my university's odd ToC style requirements. Regular chapters in the ToC need to have all-caps titles, and appendices need regular-case titles. I have a perfectly elegant ...
6
votes
1answer
243 views

How to patch a command from leipzig.sty

As shown in Issues with leipzig and glossaries used together, there is a problem when using the package leipzig with the glossaries package since the leipzig package relies on deprecated commands from ...
5
votes
2answers
347 views

Patching an essential LaTeX command, such as \usepackage

This is in the category of "things that work, but make me nervous." I use a very complicated, custom document class with LuaLaTeX. But my question can easily be illustrated with this generic MWE: \...
5
votes
1answer
282 views

Why a patch that works for align environment doesn't work for flalign environment?

I'm trying to Add a marginal note when a page break occurs in the middle of a multi-line equation, using the nice method provided by egreg in its answer to my question: Disable fleqn option for ...
5
votes
1answer
328 views

Hooking into the header/footer mechanism

I have a switch I'd like to turn off for the headers and footers but keep on for the main body text. What commands actually tell TeX to write the headers and footers after the body text has been set ...
4
votes
2answers
206 views

Error using `\verb` as the replace string on `\xpatchcmd`

On this code: \documentclass{article} \usepackage{catchfilebetweentags,regexpatch,verbatim} \tracingpatches \tracingxpatches \newcommand{\test}{testone (testtwo)} \begin{document} \xpatchcmd*{\test}{(...
4
votes
1answer
503 views

How to “shallow” \renewenvironment of \itemize?

I want to patch exactly the outer level of \itemize, whereas the following MWE (expectedly) patches all of them: \documentclass{article} \begin{document} \setlength{\fboxsep}{0pt} \let\saveditemize=...
4
votes
1answer
267 views

xpatchcmd with placeholders

Is there an alternative to \xpatchcmd from the xpatch package which supports placeholders as in this virtual example: \newcommand{\mycommand}{this is important \foo this is not \bar but this is} \...
4
votes
3answers
260 views

How can I write <section counter value>:<section title>:<page>:<file>:<line> to the log whenever (and whereever) a macro is called?

I am working on context-based log entries. Each time a selected (patched) macro is called, it should provide its contents along with a meaningful log entry. "Meaningful" log entry defined: The ...
4
votes
1answer
844 views

How can I redefine verbatim to wrap lines (add break before or after spaces)?

Before continuing, I would like to inform readers that I know it is generally discouraged to reimplement functionality that packages already support. Automatically wrap the text in verbatim has an ...
3
votes
4answers
155 views

(x)patch a command the name of which is in another macro

I want to patch some command in a numbered list based on the current level (enumi, enumii, ...). Basically, I want to replace, in a command the name of which is stored in a macro, a macro the name of ...
3
votes
2answers
555 views

How to patch with \xpretocmd and \xapptocmd a command by applying to it a macro with argument?

Suppose I'd like to patch a very complicated macro, say \autocite. For this, xpatch package is my friend. If the patch consists in applying a modal command which doesn't take arguments, such as \...
3
votes
2answers
948 views

Chapter number in left right margin

I would like to move the chapter number in the right margin (a bit like in the classicthesistheme) but all I tried just results in errors, it would be nice if some could have a look. My MWE is using ...
3
votes
1answer
165 views

Patching a command with an optional argument or declared with \DeclareRobustCommand

To re-define a command to contain itself (patching in TeX parlance) you usually use \let. This answer by @egreg says: Never use \let on commands defined with \DeclareRobustCommand or commands ...
3
votes
2answers
743 views

Make a PDF bookmark point towards title

I've been using the bookmark package to add custom PDF bookmarks to my thesis. More specifically, I started using this package because I didn't want the the ToC, LoF and LoT to appear in the ToC, but ...
3
votes
1answer
1k views

Metropolis is not working

I tried to use the metropolis beamer theme, but I got the following error ! Package beamerfontthememetropolis Error: Patching section title failed. See the beamerfontthememetropolis package ...
3
votes
1answer
202 views

Can I use patchcmd to modify definitions in book.cls?

Below are the commands for \paragraph and \subparagraph in book.cls. \newcommand\paragraph{\@startsection{paragraph}{4}{\z@}% {3.25ex \@plus1ex \@minus.2ex}...
3
votes
1answer
538 views

file ended while scanning use of \path

MWE: \documentclass{article} \usepackage[obeyspaces]{url} \usepackage{xcolor,letltxmacro,booktabs,longtable,tabu} \LetLtxMacro{\oldpath}{\path} \renewcommand{\path}[1]{\color{gray}{\oldpath{#1}}} \...
3
votes
2answers
66 views

Strange result with patch of \overarc

Triying to use a patch for \overarc from this answer https://tex.stackexchange.com/a/409106/54817 I got this result \documentclass{article} %\usepackage{fix-cm} \usepackage{arcs} \usepackage{...
3
votes
1answer
219 views

Including section in an environment

I am trying to adapt touhami's solution to How to print out only statements (theorems, lemmata, etc) from a tex file? so that I can also print the section titles. My first guess would have been to ...
3
votes
1answer
905 views

Patch \insertshorttitle in beamer

In this answer @cfr showed me how to preserve short title color in beamer while allowing hyperlinks to work. His solution was to modify the \insertshorttitle command (defined in beamerbasetitle.sty) ...
3
votes
1answer
52 views

Patch starred environment and use it as nested environment in a new environment

For every (most?) environment \begin{X}...\end{X} there exists the macros \X and \endX that can be used inside the \newenvironment command. I.e, one can write something like this \newenvironment{Y}{\...
3
votes
1answer
311 views

How to patch a starred environment

I would like to translate my approach to center all figure environments to figure* environments. How? \documentclass[peerreview]{ieeetran} \usepackage{xpatch} % \def\figure{\def\@floatboxreset{\reset@...
3
votes
0answers
121 views

pdfx and biblatex attempt to patch the same things? [closed]

The below MWE gives errors. Moving the line \usepackage{pdfx} below the biblatex package (right before \begin{document}) will currently not give explicit errors, but “it is best if pdfx is the first ...
2
votes
2answers
70 views

moderncv package does not recognize \it command

The moderncv package does not recognize \it command. Sure we can use \textit instead. The problem is that BibTeX generated files may contain \it commands ... So, edition of the bbl file is required ...