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

6
votes
1answer
174 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
31 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
108 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
72 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
128 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
53 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
57 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
21 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 ...
9
votes
2answers
91 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
65 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
37 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
42 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
24 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
79 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
92 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
96 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
96 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
99 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
55 views

Checking if a variable is not null [duplicate]

Please consider the following MWE: \documentclass{article} \usepackage{siunitx, etoolbox} \newcommand{\testa}{Some text} \newcommand{\testb}{40} ...
2
votes
1answer
78 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
213 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
61 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
370 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
38 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
452 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
92 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
48 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} ...
6
votes
2answers
133 views

Enhanced fill-in-the-blank document

I am about to improve my lecture slides from last semester. Specifically, I would like to add a fill-in-the-blank option. I found this code suggestion (from here): \documentclass{article} ...
17
votes
0answers
222 views

Test if paragraph has an overfull line

I'd like to test if the last paragraph has any overfull line. The naive approach of looking at the \badness once the paragraph is finished does not work, as it will only give the badness of the last ...
3
votes
1answer
75 views

Conditional table construction with datatool

The following minimal example creates a 3-row table width a horizontal rule separating rows 2 and 3: \documentclass{article} \usepackage{filecontents,datatool,booktabs} \usepackage[table]{xcolor} ...
4
votes
2answers
103 views

Return original argument if csname is not defined

For some #1,#2 I define the \csname base:#1:#2\endcsname. Then I define the following \def\data#1#2{\ifcsname base:#1:#2\endcsname \csname base:#1:#2\endcsname\fi} and afterwards ...
4
votes
1answer
534 views

Why a `Missing = inserted for \ifnum` error for empty l3seq sequences?

I'm trying to use expl3 sequences in order to stored 0, 1 or more affiliations to 1 or more authors stored in a datatool database. The following MWE works nicely: \documentclass{article} ...
3
votes
1answer
77 views

Set PGFplots coordinate label using ifnum

I can't overcome this little nasty issue. Using \ifnum I set labels position around the coordinates in my pgfplot. This works fine but : I am only able to test if variable \coordindex is greater or ...
7
votes
1answer
211 views

Is it possible to test whether small caps are available with the current font?

Is it possible to test, in the document body, whether small caps are available with the current font (both for pdf(la)tex and xe(la)tex)? What I'd like to do is something like: \usepackage{xifthen} ...
3
votes
1answer
66 views

Checking the mainmatter

I need to check where the text (from package .sty), if it is in the mainmatter section, then include some headers \pagestyle{LL}, if the other then \pagestyle{plain} or some other. Construction ...
8
votes
2answers
196 views

Incomplete \iffalse using \phantom

Can anyone help me debug the code below? As written, it produces an Incomplete \iffalse error on the \xdef line on the final iteration. The problem is somehow related to the \phantom macro, as ...
9
votes
3answers
230 views

Why in the discussion of the definition of \newif are the following things true

This is a couple of questions that stem from the answer to Problems understanding definition of \newif by @egreg. In that @egreg says Let's look at \expandafter\expandafter\expandafter ...
3
votes
2answers
136 views

How to pass vertical line

I have the following problem. The general idea is to test whether #1 is empty and if it isn't then write vertical line "|" and #1: \documentclass{article} \usepackage{makeidx,hyperref} \makeindex ...
0
votes
1answer
43 views

Command (using \ifthenelse) within 2nd optional (post) argument of footcite

I have defined a new command \mypageref to reference page numbers of text parts in my appendix. The begin of such a text part is labeled, e.g., by \label{text_begin}, and the end of the text part is ...
2
votes
1answer
40 views

If used insdide \cs_new(_protected), \IfNoValue(TF) doesn't detect -NoValue- at document-level

I guess my problem is related to Commands from xparse inside functions created by \cs_new:Npn? but I still don't understand what's going on: in the following WE (not minimal, sorry for this), why ...
2
votes
2answers
71 views

Make an item in itemize disappear if a condition is not met

Here is the MWE: \documentclass{article} \newcommand{\VarOne}{1500} \begin{document} I want this list to have item Two if VarOne is more than 1000. If it is not, this will be a two item list. By the ...
1
vote
1answer
42 views

Biblatex: Selecting content depending on language

I am using biblatex and would like to quote English and German works. When writing a document in German, this works nicely with the help of \DeclareLanguageMapping and hyphenation to specify if a ...
4
votes
3answers
187 views

Safe test for an empty expanded macro argument?

How can I test in a safe way (i.e. without reserving tokens as explained here) if an expanded macro argument is empty?
1
vote
1answer
193 views

Incomplete \iffalse error in AMS alignment

MWE: \documentclass[a4paper]{report} \usepackage{amsmath,xparse} \makeatletter \newif\ifinvd@lims\invd@limsfalse \newif\iflr\lrfalse \ExplSyntaxOn \newcommand{\delim}[3][lr]{ \begingroup ...
3
votes
2answers
78 views

Environment which sends text conditionally to an appendix?

I am writing a paper and would like an environment that has the following property. If some flag is set to "true" in the preamble, all text wrapped in that environment is sent to the appendix. If the ...
3
votes
1answer
112 views

program IF-THEN-ELSE alignment

I am using the 'program' package to describe a function. When I use the IF-THEN-ELSE statement I expect the lines to be aligned relative to the 'if'. But the lines are aligned relative to the 'then'. ...
5
votes
1answer
137 views

Conditional statement in beamer style file

Here is an example of a part of a beamer style file I use for a presentation: { \nointerlineskip% \begin{beamercolorbox}[wd=\paperwidth,ht=0.6cm,leftskip=.3cm,rightskip=.3cm]{frametitle} ...
4
votes
1answer
133 views

incomplete ifnum

I am using a loop to define keys with the xkeyval package, as well as to actually read out the keys inside some self-defined command. Everything works perfectly - but for some reason, as soon as I ...