22 votes
Accepted

Modifying an existing environment, but keeping the name

In LaTeX, the \begin{foo} and \end{foo} actually call the commands \foo and \endfoo. So one way to achieve what you want is to simply redefine \quote: \documentclass{article} \usepackage[margin=1....
JP-Ellis's user avatar
  • 8,919
22 votes
Accepted

"Patch failed" in EMNLP Style Template

In your local copy of the package, just delete the line \patchcmd\@combinedblfloats{\box\@outputbox}{\unvbox\@outputbox}{}{\errmessage{\noexpand patch failed}} and you will get the intended result, ...
David Carlisle's user avatar
17 votes
Accepted

etoolbox: AtBeginEnvironment is not At Begin Environment

The etoolbox package redefines \begin so that \@beforebegin@<envname>@hook is executed a group is started the usual bookkeeping is performed (setting \@currenvir, for instance) \@begin@<...
egreg's user avatar
  • 1.1m
17 votes

How do I limit the scope of etoolbox environment patching?

Update The 2020-10-01 release of LaTeX added a new hook mechanism to the LaTeX kernel. etoolbox now makes use of that new hook mechanism. This means that the answer provided below no longer works. All ...
moewe's user avatar
  • 175k
15 votes
Accepted

What is exactly a hook in etoolbox

The definition of \appto is % etoolbox.sty, line 891: \newrobustcmd{\appto}[2]{% \ifundef{#1} {\edef#1{\unexpanded{#2}}} {\edef#1{\expandonce#1\unexpanded{#2}}}} The first argument should ...
egreg's user avatar
  • 1.1m
12 votes

How to make table less cramped

Experiment with Mico's solution: The fractions can be made less ragged, if the fraction bars have equal lengths. All numerators and denominators have one or two digits. The macro \mytwofrac extends ...
Heiko Oberdiek's user avatar
11 votes

How to use patchcmd to insert \clearpage before \chapter to avoid breaking page

With a KOMA-Script class you can use \RedeclareSectionCommand to set style=section for the chapter headings. So there is no need to patch anything. \documentclass{scrbook}[2015/10/03] \...
esdd's user avatar
  • 85.3k
11 votes
Accepted

\renewcommand or \patchcmd (from etoolbox)?

There is no hard-and-fast rule. There are cases where \patchcmd won't work, but you can always use one of the more sophisticated patching options in that case. Generally, if you want to design what \...
cfr's user avatar
  • 196k
11 votes

recursive list type like definition in LaTeX

Here is an alternative solution which does not need to iterate the list twice. After the first element, the \do is replaced by \mydo: \documentclass{article} \usepackage{etoolbox} \newcommand*{\...
Thomas F. Sturm's user avatar
11 votes
Accepted

Remove extra space generated by a LaTeX command

Add % at the end of the lines. \documentclass{article} \usepackage{etoolbox} \newcommand{\defineSpecies}[2]{\csdef{spec@#1}{#2}} \newrobustcmd{\spec}[1]{% \ifcsname spec@#1\endcsname \csuse{...
Simon Dispa's user avatar
  • 38.9k
10 votes
Accepted

Declare option other than documentclass

Better: use the structure of LaTeX 2ε by creating a personal package. Put this in a usrdefn.sty file (that you can keep in the current directory, or better, in the standard places): \NeedsTeXFormat{...
Rmano's user avatar
  • 40.3k
10 votes
Accepted

How to make table less cramped

Here's a solution that uses an array environment instead of a tabular environment and creates 6 separate left-aligned columns whose contents are automatically in display-math mode. \documentclass{...
Mico's user avatar
  • 502k
10 votes
Accepted

Add command at the beginning of all frames

You cannot directly hook into the begin of Beamer's frame environment with the usual etoolbox \AtBeginEnvironment, as hinted at elsewhere. Replacing your \AtBeginEnvironment with \...
Coby Viner's user avatar
  • 1,939
10 votes
Accepted

Expanding macro defined by \csdef to define a style via \tikzset

You can use expanded instead of expand once in your MWE: \tikzset{Node Options/.style/.expanded=\csuse{My Node Option}}%% ????
corporal's user avatar
  • 741
9 votes
Accepted

what does csnumgdef do?

\csnumgdef, from the etoolbox package (for you, loaded by biblatex) is defined as: \newrobustcmd*{\csnumgdef}[1]{% \expandafter\numgdef\csname#1\endcsname} in terms of \numgdef which, in turn, is ...
Phelype Oleinik's user avatar
8 votes
Accepted

How to use patchcmd to insert \clearpage before \chapter to avoid breaking page

First, you have a syntax error in the \patchcmd line, because you're missing a brace pair: \patchcmd{<macro>}{<search>}{<replace>}{<success>}{<failure>} This has no ...
egreg's user avatar
  • 1.1m
8 votes

Interaction of \BeforeBeginEnvironment and \NewEnviron

\tcblower is a very special marker which ends an environment (the content box of the upper part) and begins another environment (the content box of the lower part). Therefore, all environments and TeX ...
Thomas F. Sturm's user avatar
8 votes

recursive list type like definition in LaTeX

A fully expandable version: \documentclass{article} \makeatletter \newcommand{\ocamllist}[1]{\left[\ocaml@list#1,,\@nil} \def\ocaml@list#1,#2,#3\@nil{% \if\relax\detokenize{#2}\relax \...
egreg's user avatar
  • 1.1m
8 votes

recursive list type like definition in LaTeX

May be I have not understood the problem, but instead of getting dizzy counting the items of the list and so... why not just take the argument as one string where you must replace the commas by ...
Fran's user avatar
  • 80k
8 votes
Accepted

How to convert Roman into Arabic numeral

\expandafter\rmntonum{\test} expands to \rmntonum{\test} since \expandafter applies to { (skipping over \rmntonum, as the name implies). What you're after is \expandafter\rmntonum\expandafter{\test} ...
Werner's user avatar
  • 601k
8 votes

Test if \author{} macro is empty

If you redefine the user command \author and the internal command \@author, you can make them do what you want them to. You can set them up in a way that you can test. A simple example is below, ...
musarithmia's user avatar
  • 12.4k
8 votes

Expanding macro defined by \csdef to define a style via \tikzset

\csuse{...} is not quite the same as \csname...\endcsname: % etoolbox.sty, line 883: \newcommand*{\csuse}[1]{% \ifcsname#1\endcsname \csname#1\expandafter\endcsname \fi} If you expand once ...
egreg's user avatar
  • 1.1m
8 votes
Accepted

LaTeX, etoolbox and counters

Use \listxadd to expand the value: \documentclass{minimal} \usepackage{etoolbox} %COMMAND FOUND ON INTERNET AND WORKS % \printlist[<sep>]{<list macro>} \newcommand{\printlist}[2][,]{{% ...
Ulrike Fischer's user avatar
8 votes

etoolbox do with macro as parameter

The call \myTable{\variable} passes a list of length one. You need to access at the value of \variable before \myTable does its job. So, as the other answer suggests is right, although there's no need ...
egreg's user avatar
  • 1.1m
7 votes
Accepted

Using expanded macro as search pattern for \patchcmd

You want to expand mychoice before calling \selectpet so: \expandafter\selectpet\expandafter{\mychoice}
David Carlisle's user avatar
7 votes
Accepted

Loading packages in custom class based on option

The command \ifthenelse is in the ifthen package. If you want to check whether a boolean bool is true you can use the command \ifthenelse{\boolean{bool}}{}{}. Also I think that you have to declare the ...
Christian's user avatar
  • 1,012
7 votes
Accepted

Why won't my boolean work correctly?

You are setting it false too soon, but you can just use the grouping to set it back automatically: \documentclass{article} \usepackage{etoolbox} \newbool{intype} \newcommand{\type}[1]{% \ifbool{...
David Carlisle's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible