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

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 ...
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 ...
2
votes
1answer
45 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
0answers
21 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. ...
0
votes
0answers
26 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} ...
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
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 ...
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 ...
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}} ...
38
votes
2answers
3k views

Understanding \@ifnextchar

I understand the definitions of the \makeatletter and \makeatother commands and also \def and \newcommand somewhat. But, explained in a simple way, what is happening in the following line? ...
111
votes
4answers
44k views

LaTeX conditional expression

I would like to be able to set a flag at the beginning of the main flag (say output) that tells if I want to produce a paper document or an electronic document. Then I should check this flag to ...
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
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 ...
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} ...
23
votes
2answers
399 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 ...
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 ...
2
votes
1answer
65 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?
29
votes
2answers
5k views

How to form “if … or … then” conditionals in TeX?

I feel really stupid for asking this, but how do you form more complex if conditionals in TeX? I'm looking for something like: \ifnum\x=1 OR \ifnum\x=14 {do this} \else {do that} \fi I ...
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
404 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} ...
7
votes
4answers
1k views

Logical String Length

How do I do a conditional 'if then else' statement, based on length of string being greater than (or less than, or equal) a specified value. For example, something Like \def\mystring{XYZ} ...
5
votes
2answers
95 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} ...
22
votes
4answers
594 views

Is there an \iftex4ht command, and if not, how should it be defined?

Background: I'm using TikZ to generate a load of pictures that I want to put on the web as SVGs. So I'm using the pgfsys-tex4ht.def driver and it's working very well. My gut feeling is that the SVG ...
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 ...
8
votes
1answer
161 views

How to translate \ifthenelse from “ifthen” to “etoolbox”?

Trying to make conditional expressions that inspect the total page count of the document (see this question), I've found this solution using ifthen package: \documentclass{article} ...
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} ...
15
votes
4answers
530 views

How to compare numbers with decimal point and logical OR operation?

I'm reading five values from external CSV file as [\sone, \stwo, \sthree, \sfour, \sfive]. Sample values could be [55.3, 89.0, 33.5, 40, 0.10]. Question : How to compare number with decimal points. ...
4
votes
1answer
153 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} ...
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 ...
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
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 ...
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 ...
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 ...
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
1answer
240 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 ...
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 ...
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} ...
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 ...