{conditionals} is about macros like \if and \ifx that may execute other macros depending on whether certain conditions are true or not. Popular packages are {etoolbox} and {ifthen}.

learn more… | top users | synonyms (1)

18
votes
2answers
827 views

Check if an entry is cited multiple times

I am trying to find out whether it is currently possible to have a test in Biblatex that tests at the very first time an entry is cited whether the same entry will be cited more than once in the ...
14
votes
3answers
510 views

Detect which text “mode” (normal, italic, bold, etc.) is currently in use?

In my document, I'm often setting upper case words and abbreviations in small caps because it avoids breaking the flow (which upper case words does). Also, many words (like CUDA, for instance) are ...
5
votes
1answer
315 views

Counters for use in array/tabular cells

The following practical example \documentclass{article} \usepackage{array}% http://ctan.org/pkg/array \newcounter{tabcol}\newcounter{tabrow} \newcolumntype{C}{>{\stepcounter{tabcol}}c} ...
20
votes
2answers
361 views

How can I detect if I'm inside or outside of a float environment?

I am trying to detect whether I am inside or outside a float. I know the way how caption works. It uses the internal \@captype. But in the example below you see that this test failed by using ...
16
votes
2answers
787 views

Automatically remove page number if document has only one page (but not if two)

I write a lot of documents (agreements) based on memoir with the article option. Normal pagestyleis plain (page number centered in the footer). Sometimes a document is only one page long, and a page ...
16
votes
3answers
456 views

What's the use of the @compatibility condition?

All of the standard LaTeX document classes (article, book and report) declare some basic functionality and parameters based on the condition @compatibility. Here's an extract from from article.cls ...
11
votes
1answer
190 views

How can I check if the current code is inside a tikzpicture?

I read the answer for this question (inside a environment) but I would like to know if there is something more specific. LaTeX keeps the current environment in the macro \@currenvir but how do the ...
8
votes
2answers
378 views

How to check if a column type is defined?

Column types for tables can be defined and overwritten with \newcolumntype. I would like to know if a column type is already defined for an example which shall only be executed in the case where the ...
5
votes
2answers
372 views

String test, with complicated arguments

I have a command \mycom{} which takes 1 argument. The command should perform a test on the argument and do something accordingly. For simple arguments, I can use \ifthenelse, but I need to consider ...
4
votes
1answer
187 views

How do I use \ifcommandkey , or how do I check if a key was given?

I'm trying to create a keycommand with optional arguments, but I can't get it to work. I looked at Comparing an argument to a string when argument is a result of a command with etoolbox and although ...
34
votes
3answers
4k views

Difference between \if and \ifx

I try to understand the subtleties of TeX programming, but it is not always easy. For example, in the following code : \def\first{abc} \def\second{abc} \ifx\first\second OK!\else false \fi I ...
25
votes
2answers
14k views

Conditionally hidden slides in beamer

When creating a presentation, I sometimes create extra slides that contain additional information, a more thorough explanation, or an extra plot pertaining to certain parts of my talk. These extra ...
24
votes
1answer
1k views

What is an \if?

I'm reading TeX by Topic, but in little chunks (rather than from first page to last) and just read the stuff on conditionals. I want to be sure that I understand what's going on when TeX starts ...
20
votes
2answers
3k views

What does \begingroup\expandafter…\endgroup do?

I often see code of the following form in package implementations (this example is from the LaTeX3 sources): \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname ...
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 ...
7
votes
3answers
1k views

How to use the exact same file for handout and presentation modes in beamer

I want to use the exact same file for my beamer presentation and handout. I do not like the need to comment out lines in order to create the handout or presentation (my current solution), nor do I ...
17
votes
5answers
916 views

Combining \ifxetex and \ifluatex with the logical OR operation

I want to write in the preamble of a LaTeX document code that should be take into account by different compilers when the document is typeset. There are fragments that should be used: only by ...
11
votes
3answers
920 views

Choosing styles conditionally in TikZ

I want to create a series of images that visualise a recursion tree as walked on by an algorithm. That means that different styles are applied to nodes depending on the step the algorithm is in, such ...
25
votes
4answers
2k views

Test success of write18

For the new version of my package and class standalone I like to call external programs: further (pdf)latex runs to optionally compile included standalone files, and to convert the resulting PDF to ...
19
votes
3answers
4k views

What is the difference between \ifx\somecommand\undefined and \ifdefined\somecommand\else?

What is the difference between \ifx\cyrdash\undefined and \ifdefined\cyrdash\else? \cyrdash is any macro.
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".
16
votes
1answer
3k views

Can I test if a file exists? [duplicate]

Can I somehow test if a file exists? And can I use this to do only things when it exists? I like to do something like if(exist('members.csv')) { do something }
15
votes
5answers
4k views

new command with cases / conditionals / 'if… then's

Suppose I want to define a command, say, \tree with, say, two arguments. I would like \tree to do different things depending on what my first argument is. For example, if #1 = a, then return ...
15
votes
2answers
1k views

Doing something only when the draft option is on?

I would like to do some stuff that is only enabled when the draft option is given in \documentclass[draft]{article}. How would I go about doing this?
14
votes
1answer
853 views

How to determine whether a list of figures is empty?

I want to check whether the document has any figures so as to decide whether or not to have a list of figures. Is this possible? Feasible without doing something like parsing the lof file? Note that ...
13
votes
4answers
293 views

How do you test whether a known key value has been set in pgfkeys

Using the .code handler to my keys and a private macro, I can easily test whether a key has been set when using pgfkeys. For example: \documentclass{article} \newcounter{mytestenvcounter} ...
13
votes
2answers
707 views

Is a TeX macro defined?

I am looking for a way in TeX to check if a macro was defined. Currently I use a rather tangled way. I exploit a sort of side effect when comparing two macros via \ifx; this command returns: true, ...
12
votes
2answers
463 views

How to detect if option provided via \tikzset

I would like to be able to detect if a particular option has been provided via a \tikzset and issue a message based on that. The MWE yields: But once the conditional works (just a comment for ...
11
votes
5answers
1k views

Teach me how to use \loop…\repeat constructs, etc

The following code snippet is a part of the solution given here: \def\IncludeOutput#1{ \parskip=2mm \def\examplename{#1} \pdfximage{\Directory/\examplename.pdf}% ...
8
votes
3answers
233 views

Detecting which version of the LaTeX format is in use

ltxcmds provides \ltx@ifpackagelater, \ltx@ifclasslater, \ltx@iffilelater and there is \@ifpackagelater - but is there any "if TeX later" or some other way to (automatically) get the used TeX version ...
22
votes
6answers
5k views

What is \iffalse for?

So this is something I've wondered about for a while. What use is a conditional that always evaluates to false? I guess it's a neat way to "hide code from LaTeX" but apart from that, is it ever ...
18
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 ...
13
votes
1answer
373 views

Create Two PDF versions of Classroom slides from Single LaTeX file: Teacher and Student

Is there a way to create a single document that will process a LaTeX file in two different ways (different preambles) and produce two different outputs. Specifically, I want to produce a set of ...
10
votes
2answers
580 views

biblatex: is there a command analogous to \ifciteseen but within one page?

Biblatex is loaded as \usepackage[style=numeric-comp,hyperref=true]{biblatex} \ExecuteBibliographyOptions{citetracker=true,sorting=none,firstinits=true} I am looking for an if-command, which would ...
8
votes
2answers
380 views

Custom ToC — Put vspace only below chapters that have sections in them

I’m using the titletoc package in the book class. Currently, my chapter entries are configured like this (I left out the unimportant parameters for simplicity): \titlecontents{chapter}[0pc] ...
7
votes
2answers
153 views

How to use the total page count in a conditional expression?

I would like to have different footer or page style depending on whether the document has one or more pages. I am not very experienced with TeX programming, so the answers about "Comparing an argument ...
7
votes
2answers
514 views

Expand command read from file

I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
4
votes
3answers
600 views

Create odd-numbered answers, or all answers

I'm starting with a clean slate creating a solutions manual. I would like the ability, by setting a switch, to produce only the solutions for the odd-numbered problems, or those for all problems, in ...
21
votes
2answers
413 views

Show footnotes on odd pages only

I'm writing my thesis using the scrbook-class. Is it possible to display footnotes only on the odd (right) pages? This should mean that \footnote{something} should be collected on even pages and ...
15
votes
3answers
1k views

Implementing switch cases

I'd like to have command built around a switch-case environment in LaTeX, much like the example below: \documentclass{article} \usepackage{xstring} \newcommand{\dothis}[1]{% \IfStrEqCase{#1}{{a}{so ...
11
votes
4answers
1k views

How to make a “condition” in a macro?

I would like to make a macro with two parameters which return a text. For instance, I want \M{1}{5} to return [1,5], and \M{2}{2} to return [2] (because the two arguments are the same). So I need to ...
9
votes
1answer
1k views

Bibliographies when using subfiles

I am writing my Ph.D. thesis in XeLaTeX with Biblatex, and there are times when I need to compile individual chapters, and times when I need to compile the entire document, so I use subfiles, which ...
9
votes
1answer
224 views

Is there a macro telling which OS we're using?

I got some LaTeX documents that I have to compile them under different TeX Live, such as MacTeX or TeX Live. But in different OS, the font seems different too, for example, while in Windows, I prefer ...
9
votes
1answer
573 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 ...
8
votes
1answer
2k views

Using ifthenelse in pgfmath

Following questions on constructing functions on the forum, I tried to build some myself. I can't seem to get the ifthenelse function in TikZ/PGF to work. Here is an example: ...
7
votes
4answers
321 views

How to detect and condition based on hostname

How do I construct a conditional statement based on the hostname of the compiling computer in LaTeX? For example: \ifhostname{mymachine} \dostuff \else \dootherstuff \fi Why: I am working with ...
7
votes
1answer
747 views

Conditional compilation of beamer slides

I'm preparing a beamer slideshow, and I will have to print slides. I would rather use landscape mode slides, but it is possible that I need to use portrait mode ones. Sadly, I won't know until a few ...
5
votes
5answers
205 views

new command with cases?

This has been answered here for text outputs with the use of \IfEqCase from the xstring package. But if I want to use the output as a value to set a parameter in a function, it fails. Here is my MWE: ...
4
votes
2answers
503 views

How to configure theorems depending on the document class?

I would like to have \newtheorem{teo}{Teorema}[chapter] if the book class is loaded but \newtheorem{teo}{Teorema}[section] if the article class is loaded. Can I do this with some sort of ...
12
votes
2answers
500 views

How to tell when to use pdflatex, latex, and xelatex for any given tex file?

I'm writing an automatic compiling pipeline that should be able to compile any given tex file into a pdf. The diversity of the input tex files mainly shows up in what format of figures they use and ...