{etoolbox} is a package which provides several macros which take advantage of the {e-tex} extension of (La)TeX.

learn more… | top users | synonyms

27
votes
2answers
325 views

What's the difference between the various methods for producing for loops?

I've been wondering about the various methods available for looping over a comma separated list and the like. In particular, I was wondering about their various strengths and weaknesses. In other ...
24
votes
3answers
2k views

How can I use \patchcmd with commands with optional arguments?

This question led to a new package: xpatch This is likely a simple question, but I'm getting stuck on the small details. I have an internal command, defined by a package as ...
19
votes
2answers
225 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 ...
18
votes
3answers
624 views

Should LaTeX counters always be modified globally?

In this answer, egreg states that "LaTeX counters should always be modified globally". However, the etoolbox package provides the \defcounter macro which will assign a value to a previously ...
17
votes
6answers
2k views

Checking if a number is a multiple of 4

Using etoolbox, ifthen, or another form of conditional checking, how can I check if a value is a multiple of 4? E.g. if the number is 4, 8, 12, 16, etc., then it returns "true".
17
votes
6answers
962 views

Placing many conditionals in a series

I frequently need to do something like this: IF x < 1, DO a ELSE IF x < 2, DO b ELSE IF x < 3, DO c ELSE, DO d Using etoolbox, I end up nesting a lot of ifnumless, like this: ...
17
votes
2answers
1k views

Difference between \newbool and \newtoggle from etoolbox package

Paul Gaborit's answer to How to detect if option provided via \tikzset uses \newbool to define a new boolean \booltrue to set a boolean, and \ifbool to perform a conditional operation all from ...
16
votes
4answers
2k views

Making switch/case with etoolbox's \ifdefequal

I've got a define such as \def\doctype{SomeString}. \doctype can take on one of five values. I want to do something like a switch statement in a programming language, i.e. (pseudocode): switch ...
16
votes
2answers
138 views

Does etoolbox's \ifboolexpr use lazy evaluation?

In other words, is bool{testB} evaluated at all in this example code? \newbool{testA} \newbool{testB} \booltrue{testA} \booltrue{testB} \ifboolexpr{ bool{testA} or bool{testB} }{OK}{Something's ...
15
votes
1answer
834 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 ...
13
votes
3answers
539 views

Get n-th element of a list (with etoolbox, or not)

I'm defining a list and I need to obtain the n-th element of this list. I was surprised that etoolbox doesn't provide a way to obtain it. The way I found to obtain the n-th element is along these ...
13
votes
1answer
384 views

Help automating calendar creation

I'm doing calendars for all the family, and I have a problem automating the process. I'm using the calendar tikz library. I need to include the moon phase in the calendar. I can do it with this code ...
12
votes
2answers
223 views

Patching arguments inside a macro

Consider the following example of a patch using etoolbox and a dummy macro \abc: \documentclass{article} \usepackage{etoolbox}% http://ctan.org/pkg/etoolbox \newcommand{\abc}[2]{#1\ #2}% Magic ...
11
votes
3answers
305 views

Understanding etoolbox \ifdefempty and \ifdefvoid

I am trying to understand the etoolbox \ifdefempty and \ifdefvoid macros. The documentation says that \ifdefempty Expands to true if the control sequence is defined and is a parameterless macro ...
11
votes
2answers
102 views

how to disable/enable etoolbox global command effect at different locations in a document?

I am not able to figure how to do this, and I did look at the etoolbox documentation The problem is simple to explain: I use etoolbox to append a \clearpage before any \section in a large document ...
11
votes
1answer
204 views

Problems with mathtools package

The following code produces an error. If the mathtools package is removed, it works. Why? \documentclass{report} \usepackage{mathtools} \usepackage{etoolbox} \newbool{shorttoc} \makeatletter ...
11
votes
1answer
3k views

Comparing an argument to a string when argument is a result of a command with etoolbox

I've got an example like that: \documentclass{article} \usepackage{etoolbox} \newcommand{\ab}{a} \newcommand{\aORb}[1]{% \ifstrequal{#1}{a}{"a" was given}{not a}, % ...
11
votes
2answers
177 views

How to process a list and ignore spaces?

This question is part of a new package: metrix. Typeset metric/prosodic symbols standalone and above syllables. I’m wrinting a new package and I need to process a list (using etoolbox at the ...
11
votes
2answers
170 views

How to create a macro “environmentally-dependent”

Yesterday I was reading the etoolbox documentation where there are defined some new document commands such as: \Before<Begin/End>Environment{<envir>}{<code>} % ...
11
votes
1answer
126 views

Save an etoolbox list to a file … and read it after

I have a problem. I would like : to construct an etoolbox list to save this list in a temp file to read this list from this file at the next run to use this file. For any reason, I can't see the ...
11
votes
1answer
200 views

Using etoolbox to automatically generate input for \xymatrix

I'd like to make a command \exactseq such that, for example, \exactseq{A,f,B,g,C} corresponds to \xymatrix{A \ar[r]^{f} & B \ar[r]^{g} & C} and such that this works for inputs of ...
10
votes
5answers
2k views

How to test if a number is negative

Is there an easy way to test if a number is negative? I don't need a general solution, but it does need to be able to handle a floating point value. I was using this solution from tex.ac.uk until I ...
10
votes
1answer
94 views

Extra space due to \patchcmd

It seems that \patchcmd from etoolbox adds three unwanted spaces, as shown below: \documentclass{minimal} \usepackage{etoolbox} \begin{document} \tracingall% 3 spaces in ...
10
votes
1answer
188 views

Is \AfterEndPreamble really executing code after any \AtBeginDocument code?

The babel package loads the (last) language at begin document, thanks to an \AtBeginDocument command (lines 12.256 and 12.257 of its kernel): \AtBeginDocument{% ...
9
votes
5answers
431 views

How can I undo an etoolbox patch?

Suppose I patch an environment using an etoolbox command such as \AtBeginEnvironment or \AfterEndEnvironment, etc. How can I undo these changes at a later stage? \documentclass{article} ...
9
votes
3answers
1k views

Extract number from string and compare problem

I try to extract the year, month and day from a string and write different text depending on the given date. I thought I could use xstring and etoolbox, but I can'st get it to work. Here's the code ...
9
votes
2answers
2k views

Checking if two conditionals are met

I am using the etoolbox package to check some variables. I can use \ifnumless{a}{b}{True}{False} to check if "a" is less than "b" and output "True" if true and "False" if false". How can I check if ...
9
votes
3answers
289 views

Create macro with several options

I struggle to create a macro that can take several options. What I want to create is for \mycommand[up,middle]{Macro} to output Macro with 'up' and 'middle' specified. Using etoolbox in the MWE below ...
9
votes
2answers
510 views

Why using a backslash in command definitions?

I want to know the reasoning behind the (La)TeX inferface for defining commands with leading backslashes. I see why a backslash has to be used to call (expand) a command (macro), but I do not ...
9
votes
1answer
518 views

Hiding section titles when the section is empty

I have created a macro like this: \newcommand{\showsection}[2]{ \ifstrequal{#2}{}{}{\section{#1} #2} } It should be used like this in the document: \showsection{Books}{ Do you know any ...
9
votes
2answers
108 views

Ease the handling of labels

I want to ease the handling of labels in my document, and I want to show the label for a section if define a "variable". Currently I'm doing it like this Setting the up the "variable": ...
9
votes
1answer
307 views

Macro to automatically save section name of previous section and next section

EDIT: I've edited the code that reproduces the anomalies, but I'll work on the code to more accurately depict the problem later on the day. Weird spacing in index Index doesn't appear in footlinks / ...
9
votes
2answers
124 views

Provide boolean from two arguments case insensitives

In most publications scientific names are abbreviated except the first time. Moreover, the names must be in italics and only the first letter of the generic name should be upper-case. The biocon ...
8
votes
3answers
362 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 ...
8
votes
4answers
213 views

Special macro definition (2opt, 1mand)

How can you define a macro \cmd in TeX primitives using two optional arguments (and a mandatory one) that fulfills the property that calling \cmd[opt]{mand} is equivalent to \cmd[][opt]{mand}. Yet, I ...
8
votes
3answers
533 views

\expandafter, \csname issue related to test for macro being defined

Just when I think I starting to understand \expandafter I run into this problem where I am trying to test if \ConditionG, \ConditionH, etc are defined in a loop. I tried all the combinations I could ...
8
votes
2answers
114 views

Getting \let definitions from inside a group, inside a loop

I have the following nested loop situation: \begingroup \def\do##1{% \begingroup \def\do####1{% \csletcs{somemacro@##1@####1}{someothermacro@##1@####1}}% ...
8
votes
2answers
469 views

Patch tabular environment with colorbox

I'm trying to quickly add a colored background using colorbox to all tables as shown in this answer. While I could just update all the TeX by hand, I am trying to patch the tabular environment to ...
8
votes
2answers
383 views

Trouble changing font size in figure legends

I'm trying to set the font size smaller in the legends for all of my figures and tables. The way I was trying to do this was using \AtBeginEnvironment but that doesn't seem to do anything at all. This ...
8
votes
2answers
160 views

Append \centering to \begin{subfigure} (from subcaption package)

How can I append \centering to \begin{subfigure} (from subcaption package)? I tried using the etoolbox , but for some reason it won't work for the subfigure enviroment (only working for the figure ...
8
votes
1answer
153 views

On pitfalls of robust commands

These days, I’m more and more defining robust commands, e.g., using \newrobustcmd (etoolbox package) or \NewDocumentCommand (xparse package). Robust commands seem advantageous to me in many respects ...
8
votes
1answer
279 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 ...
7
votes
3answers
517 views

Defining 3*(2^4) complex macro at once

An Automata can be 1- or 2- ways, With Several Heads or a Single head Deterministic or Non-deterministic With a stack or not That makes 2^4 = 16 possibilities. However, for each combination, I'd ...
7
votes
2answers
175 views

Incompatibility between etoolbox and hyperref

I tried to compile Werner's second answer from Automatically number inequalities with the hyperref package. However, the first run will give me the error below: Runaway argument? {\@firstoffive }\fi ...
7
votes
2answers
402 views

Auto-generating tables using etoolbox

I have a particular problem which I am trying to solve using etoolbox, but I can't figure out how. What I'm trying to do is to auto-generate a table based on information from a previous table. This is ...
7
votes
1answer
72 views

\apptocmd into a conditional—why it does not work?

Why the following MWE does not work while if I comment the conditional it works? \documentclass{beamer} \makeatletter \@ifclassloaded{beamer}{ \usepackage{bookmark} \usepackage{etoolbox} ...
7
votes
2answers
246 views

Incompatibility between etextools and etoolbox command \dolistloop (\forlistloop)?

The following code uses the etoolbox package to convert a list a,b,c into an internal list (called \mylist) and then typesets that with colons: a:b:c:. However, when I load the etextools package (by ...
7
votes
2answers
328 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 ...
7
votes
1answer
155 views

Getting a random sublist from a given list

The etoolbox package provides macros to handle list, which can be useful to package/class writers, however it miss macros to get random sublists. So I want to define the following macros: ...
7
votes
1answer
125 views

I'm confused about how expansion is happening here

I was really pleased that I could come up with a means of building the contents of a tabular environment using \foreach \x in {...} {...} structure. But I was curious about what exactly it would take ...