{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)

2
votes
0answers
15 views

\ifbeamer@anotherslide and \ifbeamer@localanotherslide in beamerbasedecode.sty

At the beginning of the source file beamerbasedecode.sty of beamer class, two switches are defined: \newif\ifbeamer@anotherslide \newif\ifbeamer@localanotherslide By reading beamerbasedecode.sty ...
8
votes
2answers
218 views

If statements and variables

I need some help understanding if statements. How do I make the following pseudocode in LaTeX. \newcommand{\@leader}{} \newcommand{\leader}[1]{\renewcommand\@leader{#1}} \newcommand{\donow}{ ...
3
votes
3answers
60 views

\pagestyle{plain} between chapters without page number after titlepage?

I've found numerous posts about removing the header/footer on the blank pages between chapters, and they work fine with one big exception... I need a \pagestyle{plain} (i.e. single centered pg#) at ...
1
vote
2answers
41 views

How to test whether report has been called with “draft” option

How can I test within a document, whether or not the initial \documentclass[a4paper,11pt,twoside,fleqn,draft]{report} includes the "draft" option? My naive attempt \newif\ifmydraft \mydraftfalse ...
0
votes
1answer
49 views

Switch between different output versions compiled from the same LaTeX source

For programming in C, it is quite common to switch between creating debug- and release-versions by passing a command line argument to the compiler. I would like to have something similar for ...
4
votes
2answers
129 views

LaTeX “Variables” - \@varname

I'm currently in the process of writing my first document class file (a personalized resume class), and I want to get a better understanding of what exactly I'm doing. So, right now I'm setting up ...
8
votes
1answer
42 views

TeX quotation marks short-circuit optional argument with \ifx

In a command with an optional argument, if I put a string beginning with TeX quotes (e.g., ``quote'') in the optional argument, something goes wrong. See the bottom entry in the example below. The ...
3
votes
1answer
35 views

Using pgfplotstabletypeset to conditionally bold small p-values

Following advice seen in other entries about using pgfplotstable on tex.stackexchange.com (such as pgfplotstable: Conditional post-processing of cell content on a per-column basis), I have encountered ...
2
votes
0answers
27 views

Insert or apply a decision structure to sequence or list

I would like to make the function calls \findLargest in the MWE below a little more dynamic and compact. As demonstrated in the example below, I can store glossaries values and include them in the ...
3
votes
1answer
73 views

Select largest value from a list of variables in LaTeX

I am trying to adapt this example How to iterate over a comma separated list? as my base. Except, rather than display all values, I actually want to iterate through all the values and only return / ...
3
votes
4answers
34 views

command to generate a \cite{} only on first use

In a book dealing with R, I use a command \pkg{} for every mention of an R package, that also generates index extries via another command \ixp{}. \newcommand{\pkg}[1]{\textsf{#1}\ixp{#1}} All ...
0
votes
0answers
22 views

ifthenelse in adress of letter

I write a letter with \documentclass[a4paper,12pt,addresshigh]{dinbrief} The letter itself starts with \begin{letter}{\Anschrift} and \newcommand{\Anschrift}{% \textbf{\Firma}\\ ...
3
votes
0answers
32 views

Problems in using the spreadtab and the ifthen packages

Using the spreadtab package for some computing, I have to write an expression (mixing of literal and numerical expressions) if some conditions are true. Using the ifthen package, all works well for a ...
1
vote
0answers
43 views

Ending a tikzpicture environment in conditional causes “Missing } inserted”

I want to create a number of tikzpictures. I have a number of items I want to draw. Each tikzpicture takes up a whole page and may contain up to 4 items. (It is not good enough to to have each item in ...
0
votes
0answers
14 views

How to change “ifthenelse” conditional to “ifnum” [duplicate]

I'm trying to put a conditional inside \cfoot from the fancyhdr package like this: if the document contains a one-page there will be no footer. if there are more pages the footer takes the format " ...
2
votes
1answer
22 views

\ifthenelse within \caption, \listoftables does not work

EXAMPLE 1 below works fine but EXAMPLE 2 produces "undefined control sequence". The only difference is the \vlabel command within brackets in the \caption command. What is the problem? EXAMPLE 1: ...
5
votes
2answers
55 views

How to determine if a macro argument contains the macro itself?

I would like to have a way to detect if a particular macro's argument contains that particular macro itself. Consider the following MNWE: \documentclass{article} \usepackage{etoolbox} ...
4
votes
1answer
60 views

How to control conditional statements within new commands and environments

I'm writing a pretty complicated class to typeset a book based on memoir. One of my commands draws a caption on the preceding verso page, draws content on the following recto and verso pages, and ...
2
votes
3answers
50 views

Multiple \if condition using etoolbox

First: I've found "Checking if two conditionals are met" but I don't know how to change it do suit my needs. Wanted: I have eight different predefined values and I want different definitions of a ...
2
votes
1answer
101 views

How can I know if I am inside an equation environment if it's nested with others?

I wanted to define some partial derivative commands that would be \partial y/\partial x if it was inside an inline equation and would use \frac{\partial y}{\partial x} if inside an equation ...
7
votes
3answers
187 views

Is there an “\if” command that determines if a command has been issued?

I need to redefine the \chapter command to change the \addcontentsline command depending on whether or not the \appendix command has been issued. Is there an "if" command that determines if a command ...
6
votes
1answer
163 views

How can I retrieve (and conditionally act on) the language of my document?

I have a collection of documents that share a common style file that has all the functions and templating shared by this particular collection. The majority of these are all in the same language, but ...
0
votes
1answer
26 views

Make macro which checks the type of math mode its in [duplicate]

I frequently find that I want to make a macro, say a derivative macro for example with the following syntax: \def\dd #1;#2;{ return... } However, I want it to check if it is inline math such as ...
8
votes
1answer
53 views

Using \ifdefined on \csname macros

I've run into this issue several times now, and have just worked around it in other ways. But it would be simpler just to know how to do it properly. I would like to use \ifdefined in the context of ...
4
votes
2answers
59 views

String comparisons not working with textgreek

Following the solution from this question as a guide - Are there any "if" commands like "\ifnum" in LaTeX? - I have setup a newcommand to perform a string comparison. ...
3
votes
1answer
89 views

Conditionally change node background color inside foreach

I generate 8 rectangle nodes using a \foreach loop but I would like one of them (the one at the position index) to have a gray background. How can I do that ? I would like to avoid repeating the ...
2
votes
1answer
45 views

IFNUM condition is not working for affiliation counter

I am using authblk.sty and using the \ifnum\value{}>1 concept using to switch the affiliation. But I can't able to get the if then else condition output. My requirement is Condition 1 If the ...
1
vote
1answer
50 views

Access specific glossary fields without triggering first usage

I would like to know if any of the fields that are manually configured during the creation of glossary entries can be accessed manually/deliberately in a macro or newcommand - possibly of the form: ...
2
votes
1answer
16 views

Handling a conditionally defined newif, nested in an ifx conditional?

Consider this MWE: \documentclass[11pt]{book} \def\entrytest{WORD} \def\entrycurrent{NOWORD} % \def\entrycurrent{WORD} \ifx\entrytest\entrycurrent \newif\ifsomething \somethingfalse \fi ...
8
votes
2answers
71 views

Splitting macros to individual tokens/characters, with catcode (to debug conditionals)?

Consider this MWE, modified from ifthenelse equal string comparison fails: \documentclass{article} \edef\test{german\relax} \edef\curentry{\string german\relax} \typeout{test: \meaning\test, ...
2
votes
1answer
58 views

Nested conditional glossary terms using Glossaries \ifglsused in \newglossaryentry

If I want to conditionally expand a glossary entry based on or related to another glossary term, I find the conditional \ifglsused{}{}{} statement is very helpful. To satisfy parent modifications ...
3
votes
1answer
31 views

Problem with expansion of \@ifnextchar inside tabular environment

I'd like to define a macro that expands to \hline and \cline inside the tabular environment depending on the next character: \documentclass{standalone} \makeatletter ...
0
votes
0answers
33 views

Conditionally prepend text to chapter title in TOC

I want to prepend some text to chapter titles on the TOC according to certain conditions. For example (this doesn't work): \documentclass[letterpaper,openany,oneside]{book} ...
1
vote
1answer
22 views

How to insert a bookmark only if the following command is completed

\documentclass{article} \usepackage{pdfpages} \usepackage{bookmark} \newcommand*\ifpdfexists[1]{% \IfFileExists{#1.pdf}{\includepdf[pages={-},fitpaper=true]{#1}\cleardoublepage}{\relax}} ...
0
votes
0answers
19 views

conditional text triggered by form

I need to build a form, with different questions, each question with boxes to be checked - this part is easy, and I have been using eforms package for such task. But this specific form needs to ...
6
votes
1answer
78 views

tabularx processes its body multiple times; how do I know which cycle I am in?

Assume that I enjoy setting my tables using an \itemized or list-like coding structure: \begin{mytabular}[.5\textwidth] \item head1 & head2% <-- header row \item abc & def \item ghi ...
3
votes
1answer
63 views

ifnum x is even DO THIS \else DO THIS \fi

I am looking for a conditional command with the next structure ifnum x is even DO THIS \else DO THIS \fi usually ifnum command have the options = < >, but I would like to have the option even ...
3
votes
1answer
74 views

How to switch the if else condition based on one command

I will try to code the if or else condition working based on the one command \sectiontype{} command Case 1: If the \sectiontype{} command is available in the tex file below mentioned code is ...
4
votes
3answers
88 views

ifnum: problem with multicolumn in tabular

The next code has an error \documentclass{article} \newcommand{\numtest}{1} \begin{document} \begin{tabular}{ll} text A & text B\\ text C & text D\\ \multicolumn{2}{c}{Long Text}\\ \ifnum ...
6
votes
1answer
94 views

ifpdf prematurely terminates iffalse

I have the following minimum code stored inside the file.dtx file: % \iffalse % \begin{macrocode} %<*driver> \documentclass{ltxdoc} \usepackage[utf8]{inputenc} \usepackage[english]{babel} ...
1
vote
0answers
54 views

Checking if a variable is not null

Please consider the following MWE: \documentclass{article} \usepackage{siunitx, etoolbox} \newcommand{\testa}{Some text} \newcommand{\testb}{40} ...
2
votes
1answer
73 views

How can I write a conditional coloring command that distinguishes variables within titles vs within the body text with titlesec/titletoc/tocloft?

Question Is it possible to write a conditional statement for commands that change them based on where they appear in the document, yet is fully compatible with the titlesec package and the tocloft ...
2
votes
0answers
13 views

Definition conditional on pgfversion [duplicate]

Due to a change in behaviour between versions of pgf, I want to introduce a conditional definition that depends on whether or not \pgfversion >= 3. How can I do this?
7
votes
2answers
206 views

How can I write a conditional coloring command that distinguishes variables within sectioning commands vs those within the body text?

Question Is it possible to write a conditional statement for commands that change them based on where they appear in the document? Example Situation When command appears in the body, it should be ...
4
votes
1answer
57 views

Conditional code based on token

This is a follow-up question to Xparse Adding backslash after each command. xparse allows for conditional tokens to be inserted into the parameter text for a macro using the t<token> directive ...
4
votes
2answers
363 views

Is it a convenient way to write longer program codes in LaTeX?

Before I only used ifthenelse and for loops, but not complicated data structures. I don't know what is the convenient way to write longer codes. As an example I would like to generate a random ...
2
votes
1answer
31 views

Conditional \addlegendentry

How can I add legend entries dependent on some variable? At least it does not work in the minimal example below. \documentclass{standalone} \usepackage{tikz,pgfplots} \begin{document} ...
9
votes
3answers
424 views

Understanding the math tikzlibrary

In my question The Spiral of Roots in TikZ, the answer by Mark Wibrow caught my attention but while trying to edit the code I found myself struggling with an ifelse statement. What I am trying to ...
4
votes
2answers
84 views

ifthenelse doesn't work in case of string comparison

I tried to use this code to place footer in all pages except the last page in which I just want an "end". \ifthenelse {\equal {\detokenize{\thepage}} ...
1
vote
1answer
37 views

Optional address on letter

I'm trying to add an optional letter address that I can add to the letter by defining as true or false. Is there any reason why the address isn't printing? \documentclass[letterpaper]{article} ...