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

3
votes
1answer
48 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
32 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
34 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
11 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
57 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
0answers
22 views

If statements in glossaries definitions recognizing state of \gls{entry}

Using a conditional if statement how can I compare \gls{x} with \glsentryshort{y} Note that x does not equal y, however, x may be a prefix of y which has been defined as a function of each other. ...
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
27 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
18 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
18 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
76 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
53 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
65 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
81 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
88 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
48 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
67 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
193 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
48 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
357 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
21 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
409 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
68 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} ...
5
votes
2answers
96 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} ...
12
votes
0answers
133 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
56 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
94 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
155 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
53 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 ...
6
votes
1answer
187 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
49 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
161 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
218 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
132 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
35 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
31 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
45 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
36 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 ...
3
votes
3answers
150 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
123 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 ...
2
votes
2answers
50 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
81 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
102 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
90 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 ...
3
votes
1answer
73 views

Nested \ifdefined statements

I am trying to populate a list of variables (in the attached example starting with \@addressone) with the values obtained from a set of commands. The first variable will get the first of whatever ...
1
vote
0answers
13 views

overfull \hbox ..with figures (like to do If scale>width, use max width) [duplicate]

Well, I'm having a problem with figure. I'm using figures like this: \begin{figure}[!ht] \centering \includegraphics[scale=1]{\importacaodedados importacaodearquivos.png} \caption{Importação de ...
3
votes
1answer
60 views

Opening and closing brackets in combination with the ifthen package

Related to this question, however, I was not able to solve my problem. Let me give some background. I want to switch between the article style and a specific journal style. The journal style has ...
4
votes
2answers
66 views

Randomly select one of two possible texts

Let's say I have two possible questions. I want only one to be on the generated PDF and I want this one to be randomly selected among the two potential candidates. I thought this would be sufficient: ...