Questions tagged [conditionals]

{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}.

Filter by
Sorted by
Tagged with
1
vote
1answer
41 views

Implementing nested if-then-else tests

I would like to implement the following processsing for each row of my data, which is read with datatool: if ( (\No = 5 and \B=11111) OR (\No = 5 and \B=22222) ): \inserpageA else if ( (\No = 5) ...
0
votes
1answer
17 views

How to format text based on a logical statement that reads in a value from a csv?

Background Hello, and thanks in advance for any insights you all can offer! Sorry for the very long post, but I noticed most new users are chastised for not sharing enough context. The TLDR version ...
1
vote
1answer
20 views

Latex Variables and if statement to show or hide code

I would like to define a document, in which I define variables at the beginning of the document and use them in the document to define, from which parts of the code, the pdf is created. This is the ...
1
vote
0answers
32 views

Conditional compilation within documentclass option?

This works fine and produces letter-size PDF. \documentclass{article} \usepackage[\ifdefined\afive a5paper \fi]{geometry} \begin{document} Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed ...
0
votes
0answers
24 views

`\iffmode` fails for first token in matrix cells [duplicate]

\iffmode seems to fail for the first token in every matrix cell. Here is a minimal working example. \documentclass[margin=5mm]{standalone} \usepackage{mathtools} \newcommand{\foo}{% \ifmmode A% ...
0
votes
1answer
17 views

Equivalent of \iftotalfigures for xequations

To print my lists only when there are references I use the following syntax: % List of figures \iftotalfigures\listoffigures\fi % List of tables \iftotaltables\listoftables\fi Now I would like to ...
2
votes
1answer
15 views

Counter value based on last environments

How to put the condition using TeX macros that rule should enabled only last test environment alone? Suppose the document contain only one \begin{test}...\end{test} rule should be enabled. If ...
3
votes
1answer
39 views

Programming table cell colour based on contents

I built this table based on an earlier Q&A: As you can see there's a problem with the header. How can I disable the highlighting for headers only? Here's the code: \documentclass{article} ...
0
votes
1answer
24 views

\thepage cannot refer the roman page number

I want to write 'A' in odd page number and 'B' in even page number. This code below only apply for arabic page number, but the roman page number can't. How to write 'A' in odd page number and 'B' in ...
5
votes
2answers
105 views

Nested FPifeq : Extra \fi error

I want to have a command Unit with 1 parameter that return : nothing if the parameter is 1 - if the parameter is -1 the parameter in any other case The goal is to show x and -x instead of 1*x* and -...
1
vote
1answer
34 views

Simpler way to effect OR with two \IfStrEq?

Consider the pseudo-code IF mystring = "this" OR mystring = "that" THEN \dosomething ENDIF Is there a simpler way than the following to implement that (inside the \CheckString command)? In ...
1
vote
0answers
35 views

Neural network diagram labeling issue

I have a neural network diagram drawn by using the package neuralnetwork. I have problem with labeling. The labels from input to hidden layers should be 1,2,3,4,5,6 but the code give me 1,2,3,1,2,3. ...
4
votes
2answers
40 views

Cleveref - Conditional label formats

I am trying to define a new reference style with cleveref: \crefname{prop}{property}{properties} \creflabelformat{prop}{#2#1.\@#3} This is meant to be used in a list of numbered properties in an ...
2
votes
3answers
57 views

How to check if the argument to a macro is a specific string?

I need to be able to pass [ ] (brackets with space in between) to a \def and check whether the \def's parameter contains [ ] (rather than something else). \begin{document} \def\bptoks{[ ]} \def\bpdef#...
32
votes
6answers
4k views

Testing for number

How do I test if a given parameter is a number, in order to apply a different style? And if not, just ignore... Like: \domorestuffifnumber{things} -> things \domorestuffifnumber{123} -> \...
1
vote
1answer
30 views

\ifthenelse statement inside includemedia options

I try to enable / disable some options for my 3D view with \ifthenelse. \documentclass[fontsize=12pt,paper=a4]{scrbook} \usepackage{media9} \usepackage{graphicx} \usepackage{ifthen} \begin{document} ...
3
votes
1answer
54 views

Mysterious horizontal space when using conditional macro

In order to deal with both burdensome expressions $K$-vector space and $K$-vector space $E$ at once, and this in both text and math mode alike, I defined a fine working shortcut taking two arguments, ...
4
votes
1answer
78 views

Unexpected behaviour of TeX condition in \draw macro

Let's consider code below \documentclass[tikz]{standalone} \usepackage{amsmath} \usetikzlibrary{arrows} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \foreach \i in {1,.....
1
vote
1answer
25 views

Ifoddpage statement inside switch case

Continuation of topics tcolorbox: specific width and height settings for odd and even pages and Distance Variable in front or back pages. I'd like to set lengths conditionally based on the expansion ...
6
votes
2answers
161 views

Is there a way to perform “if” check only once instead of every iteration in a loop?

The \zNonZero is equal to 0 if #1 is 0, but is equal to 1 if #1 is greater than 0. The problem is, the if check inside the loop is performed every iteration: I need it to be performed only once (for ...
1
vote
1answer
75 views

How to define a macro with a functional character?

I want to form a macro which will enable me to get the following result. Let's say I want L, M & N to be active in my document. And I also want character p to be functional in the code such that ...
2
votes
2answers
83 views

How to make an array of tokens?

I'm trying to code a function with the help of some characters in Devanagari script. I've replaced the characters with some other characters of a totally different script. This is the MWE to do it. \...
5
votes
2answers
169 views

Conditionally replacing sequences of characters

I am a noob in the area of plain TeX. All commands which are used in this question are written with the help of answers on this site and the 'LaTeX Wikibook'. I want to change keyboard mapping using ...
0
votes
2answers
32 views

conditional variable not set true inside a macro

In my class file I have this code: \newif\if@showsolution \def\solutions{\@showsolutiontrue} \if@showsolution \newenvironment{solution}{\textbf{L\"osung:}\\}{} \else \excludecomment{solution}...
2
votes
1answer
64 views

Macro to switch bold on and off in table cells

I have start looking at the package cals, so my examples are connected to that packages. However, my questions are general, applicable under other environments, too. In the documentation (this ...
2
votes
2answers
27 views

How do I make conditions based on list options?

Specifically, I need to write a command which changes its behavior if the option wide is turned on... So I need some kind of condition if wide is on then do this, else do that. Can somebody point ...
0
votes
1answer
49 views

Set path using if / else

Depending on the previous text I need to set e path to folder 1 or folder 2. With just one folder everything worked fine, but with the condition it doesn't. What am I missing? \newcommand{\nc}{text-...
5
votes
1answer
62 views

Why is \unexpanded not respected after an \if?

I was surprised to find that the argument of an \unexpanded is expanded if the \unexpanded is within the first two tokens after an \if. Using Knuth TeX's \noexpand instead works but I am curious where ...
1
vote
1answer
49 views

Conditionally set bibliography title

I am writing a class and would like to offer the option of changing the bibliography title as a class option. If no title was given I would like to just use the default one. Unfortunately I can't seem ...
3
votes
0answers
21 views

Prepending digits to section numbers in ToC

I have more than ten sections that I want to list in the ToC as the following: Which means I need to prepend 0s to sections of \ifnum\thesection<10. How do I do this in the ToC? MWE : \...
22
votes
2answers
25k views

If-then-else inside TikZ graph?

I want to draw a graph like in the second picture of the following code: \documentclass{article} \usepackage{mathptmx} \usepackage{tikz} \usepackage{verbatim} \usetikzlibrary{arrows,shapes,graphs,...
1
vote
1answer
41 views

Different text on last page

I want to add one of two different texts, depending on whether it appears on the last page. I tried this: \documentclass{article} \usepackage[angle=0, opacity=1, scale=1,position={0,0}]{background} \...
2
votes
2answers
65 views

Definition-time expansiton of command line input

I'm trying to make the following code work correctly. I'm using command line call to python to check whether a number is in a list (no clue how to do this in pure LaTeX(?)). I then want to check ...
5
votes
2answers
65 views

Checking if argument is a floating point without breaking on control sequences in argument

Inspired by this answer to test whether an argument is a positive integer, I would like to extend this to floating point numbers. I want to have a macro \TestNumber that checks, whether its first ...
1
vote
1answer
26 views

Missing spaces in conditionals

I'm trying to print two different text if a string contains a ',' or not. The conditional is working, but the text is getting printing without spaces. This is the code for the command: \...
10
votes
1answer
117 views

\ifnum expanding too much - what is happening?

Consider the following example: \documentclass{article} \makeatletter \newcommand\fail[1]{% \ifnum1=#1% <- here a space is missing \expandafter \@firstoftwo \else \...
3
votes
2answers
72 views

Don't take white space into account when checking next character

Taken from this post, I have the following code to define a macro that takes an arbitrary number of arguments and concatenates them with an interleaving symbol (\simeq_{k}) in math mode: \...
1
vote
1answer
19 views

titlesec: display subsectiontitle in header only if there is a subsection

I want to have my header as the section name displayed on the left and the subsection name displayed on the right. This works well as long as every section has a subsection. However if there is no ...
2
votes
1answer
39 views

Custom boolean tag

I've created for my lessonbooks a boolean studentversion who can hide or reveal some teacher stuff under the advice of CarLatex. (see topic : https://tex.stackexchange.com/a/478695/169294) Is it ...
1
vote
1answer
28 views

Hide contents in environment but keep whitespace

I have a custom environment \newenvironment{mathsolution} that contains content that I want to hide based on the switch \showmathtrue and \showmathfalse. The code I have for this conditional is the ...
1
vote
1answer
40 views

Insert something when *not* before a page break

I've tried to find a solution but obviously the right search phrases escape me ... I need to insert something into the document which will be suppressed if it would be followed by a page break. For ...
1
vote
1answer
28 views

Configurate an error for a custom command and conditions

Is there a way to allow custom command to send a log entry who pointed to an error ? I want to create the command \difficulty who convert the four first integers in filled or emptied stars. Here is ...
0
votes
0answers
11 views

Optional Sections in a Document - passing parameters to latexmk or pdflatex [duplicate]

I want to define optional sections for the same document. My plan is to define something like the following command: \optional[audienceA,audienceB]{ % my latex content } so that i can pass a flag ...
3
votes
3answers
60 views

how do I test for a unique string with multiple possibilities?

I'm writing a macro that takes a string and it returns an href based on that string. The string could have 150 different values. My question is how to write this in an efficient way. Using pdflatex. ...
9
votes
2answers
533 views

Question about exercise 11.5 in TeXbook

In answer to exercise 11.5 there is this comment: \def\\{\if\space\next\ % assume that \next is unexpandable What does this comment mean? If \next may be expandable, must we use the following ...
60
votes
3answers
9k 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? \@...
0
votes
0answers
35 views

I want to detect an order placed at the beginning of each theorem

I want to detect an order placed at the beginning of each theorem. \documentclass{article} \usepackage{ifthen,ntheorem} \newtheorem{ex}{Exam} \begin{document} \begin{ex} \LaTeX{} There is the LaTeX ...
3
votes
2answers
87 views

keyval - function for keyB should act dependent on value of keyA - how to do this?

I'm new to LaTeX. I learn and I use article class. I struggle learning working with keyval package: I try to write macro \macro which only uses one mandatory argument where user can provide key value ...
2
votes
1answer
834 views

A method of distinguishing Iverson from other brackets?

Is there a common idiom or method for distinguishing Iverson brackets from "normal" brackets? In all examples I've seen, simple braces [...] are used for both; but in complex expressions, this can ...
1
vote
0answers
31 views

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error?

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error? How to check if attempts at totally expanding the tokens of an arbitrary sequence of ...