{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
1answer
49 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
180 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
40 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
339 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
15 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
383 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
65 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
36 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
90 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} ...
11
votes
0answers
120 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
48 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
91 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
80 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
43 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
179 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
46 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
144 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
214 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
130 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
34 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
28 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
41 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
34 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
140 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
104 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
46 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
72 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
93 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
85 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
60 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
11 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
57 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
58 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: ...
4
votes
1answer
77 views

Trouble setting header content conditionally with titlesec and extramarks

I'm writing a commentary on a Classical text and trying to imitate many of the layout choices of the Cambridge Greek and Latin Classics series. In particular, I've been working on having the header ...
10
votes
4answers
151 views

# in conditionals in alignment tabs?

I am looking for ideas how to make TeX understand that when # appears both in the if-else and in the else-fi part of a conditional in an alignment tab, in the end there will never be more than one # ...
2
votes
1answer
107 views

How to conditionally draw nodes of a tree in TikZ

I want to draw several trees with tikZ (Version 2.10) which are very similar in the sense that there is a first tree and the others are obtained by ommiting some of the nodes of the first one. I ...
2
votes
1answer
61 views

How to test whether pic text is empty in TiKZ?

If I wish to add a pin to a node in TiKZ, I can do so like this: \documentclass[tikz,border=5pt]{standalone} \begin{document} \begin{tikzpicture} \node [draw, thick, circle, minimum ...
8
votes
1answer
109 views

Incomplete \iftrue is valid input?

Is LuaTeX beta-0.79.1 correct in thinking the following is valid input: \iftrue \bye
1
vote
1answer
27 views

Is there a way to display a specific command and hide the rest

I would like to use the same Latex source file for both my document and the accompanying slides. When creating a document it's easy to hide the slide sections by doing this: \newcommand{\slide}[1]{} ...
1
vote
0answers
19 views

Conditional for documentclass [duplicate]

I was wondering whether it is possible to execute a command depending on the used documentclass. \documentclass{dinbrief} %\documentclass[a4paper]{letter} \usepackage{ifthen} \begin{document} ...
13
votes
2answers
176 views

ifx, macros and grouping

I do not understand how \ifx interacts with macro definitions. Here is a minimal example: \def\a#1{\b} \def\b#1#2{[#1:#2]} \a ABC The output is [B:C], as expected. If I change the definition of \a ...
3
votes
1answer
68 views

Smaller vertical space between repeated environments

I have a new environment that is defined with addvspace at the beginning and end. This works fine if it is surrounded by text. Now, I want this space to be smaller (smallskipamount) between these ...
3
votes
2answers
74 views

Conditionals used in defining of new environment

I want to produce two versions of one document with different content. The idea is to comment out certain sections if a logical variable is false. This logical variable will be inputted eventually ...
7
votes
5answers
291 views

Read number from file

I have a file called _runs.ini. Depending on its content, the document is compiled differently. I tried to read the content and executed a \ifthenelse-command without success. Here's my MWE: ...
8
votes
1answer
139 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} ...
7
votes
2answers
160 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 ...
4
votes
1answer
66 views

Аnalog of \ifodd condition for verification if page number is equal to some constant

I have a great example of using \ifodd condition if \makeatletter environment showed by @Symbol 1. \begin{document} \makeatletter \newbox\LT@oddhead \newbox\LT@evenhead ...
5
votes
1answer
69 views

Wonky behavior from \@ifnextchar,

When I compile the below MWE the first \@ifnextchar, always evaluates to false, which is clearly wrong in the last case. However, the second one (within \punctuationcheck) works just fine. Why would ...
7
votes
1answer
124 views

Omega appears from if result

I am attempting to edit an if statement that I was using in an environment I created. Previously, the code was \if #1\empty \else \textbf{#1.}\hspace{0.5em}% \fi I want to change it to something ...