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
4
votes
2answers
336 views

ampersand “&” causes if-else-fi to fail

I encountered a very strange problem today. I want to fill tables with automatic generated data. Hence, I designed a macro, which takes four arguments (one being optional). Arguments No. 1 and 4 ...
1
vote
1answer
53 views

How to set up a conditional loop that chooses which compiler to use within the same document?

I have a TeXlive 2019 installation with an unsolved problem that so far prevents me from compiling on this computer with LuaLaTeX, so I thought I could add to the preamble of the document that I'm ...
3
votes
2answers
247 views

How to check a boolean argument in a command with optional arguments?

I have a command with an optional argument, and I want to execute some code depending if argument is true or false (I am sure that this command will have always some argument convertible to a boolean, ...
25
votes
6answers
633 views

Test if a given control sequence is a length register

I'm in need of a macro which receives a control sequence as argument and needs to branch if this macro is actually a length (of any kind, e.g. dimen, skip etc.) or "just" a normal macro (including one ...
2
votes
1answer
37 views

Comparing the number of the current chapter with another one

I am typesetting a book (using the book class) which consists of a large number of small chapters and I wish to be able to freely change the order of the chapters. Since there are cross-references, I ...
0
votes
0answers
26 views

Loop for each 3 rows with condition

Continues Old topic: algorithm Logic: Make Loop for each 3 rows in datatools I use this code with ifthenelse: If No = A/B/C, insert page A/B/C but result do not display in order of rows in file ...
3
votes
3answers
90 views

LaTeX: How to define command depending on existence of another command (e.g. `\nameref`)?

I'd like to use \nameref with hyperref, but I want be able to render my document without hyperref, too. So I'd like to define a wrapper command around nameref (not defining a "dummy" \nameref myself),...
20
votes
7answers
1k views

Test whether passed parameter is a number (possibly floating point) or dimension

With TikZ using the calc library you can write things along the lines of \node (A) at ($(0,0)!0.75!(1,1)$) {}; or you can write something (rather different) \node (B) at ($(0,0)!2in!(1,1)$) {}; ...
0
votes
1answer
57 views

Switch condition (IfStrEqCase) - no match & use inside pgfplot axis

I am trying to learn how to use switch conditions to apply in a document I am creating that contains plots. Here is an extract to create a MWE : \documentclass[border=2pt]{standalone} \usepackage[...
4
votes
5answers
317 views

Having trouble with TikZ — For Loop and Conditionals

Essentially what I am trying to achieve is a grid of 12 circles with three rows and four columns. All I would like is for the two middle columns to be red while the other two columns are black. Here ...
6
votes
4answers
192 views

Conditionals across a new environment

I'm trying to create an environment where the text only appears if an optional argument is not changed (and disappears when it is). The gist of what I'm trying to do is: \newenvironment{entry}[3][0] ...
9
votes
1answer
155 views

Distinguish active characters from non-active pendants with expansion-methods only?

(Please take the following question rather for a moot point than for an everyday-problem.) Is there an expandable method for distinguishing an arbitrary explicit non-active character token from its ...
3
votes
1answer
150 views

A question about \ifcase syntax

The command \today has been defined as follows: \def\today{\ifcase\month\or January\or February\or March\or April\or May\or June\or July\or August\or September\or October\or November\or December\...
2
votes
1answer
159 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. ...
1
vote
3answers
55 views

Add text which can be turned on or off during compilation

I have written a book in LaTeX which I am reviewing at the moment. However, in the book, I want to insert more details for e.g. a printed version. Thus, I am searching for a possible option to include ...
1
vote
0answers
61 views

Print in draft mode, hide in final

Note: For context, please see my comment here. I would like to print the Git hash (from the VC package) while in draft mode and hide it when typesetting the final version of a document. I know this ...
2
votes
4answers
372 views

Verbatim Text Inside Environment which is inside a Boolean Condition

My code looks like this \documentclass{article} \usepackage{environ} \newcommand{\showsolution}{1} \NewEnviron{mysolution}{ \if\showsolution1 \fbox{\BODY} \fi} \begin{document} \begin{...
2
votes
1answer
56 views

Forcing bracketed arguments in LaTeX macros

I would like to define a macro in LaTeX, say \mymap, which on empty input just returns the function name, i.e., "mymap"; and on input "a" returns (the name of) the evaluation of the function in "a", ...
6
votes
2answers
152 views

How to use \cs_generate_variant:Nn to compare token lists?

I want to deal with this question by my method. The example below is some codes from interface3.pdf; But throws the error:  ! LaTeX3 Error: Variant form 'VV' deprecated for base form '\...
1
vote
1answer
74 views

How do I use `ifpackageloaded` inside a `cls` file?

I am writing a class that makes some changes in its commands according to the packages that are loaded in the main tex file. However, when is use \@ifpackageloaded for that purpose, it only performs ...
1
vote
1answer
47 views

New command with cases / conditionals / 'if… then's

I defined a command to insert figures easier and according to some college formatting. It is working just fine, but I am having a problem trying to add a conditional statement. The command is this: %\...
5
votes
2answers
6k views

How to define a if-condition? [duplicate]

I found several entries about the fact that the ifthen package is obsolete. So my question is: how to define a condition check then? I have searched and I find several example for ifthenelse (...
1
vote
3answers
55 views

Passing a macro to function expecting optional star

Initially this was meant as conditional typesetting using xparse rather than the other packages proposed here. Perhaps there are better approaches than the one I am pursuing, for that purpose, but in ...
4
votes
2answers
464 views

Check if number is in list of numbers

My end goal is to highlight certain nodes depending on their value, and there will be quite a few of them so I need there to be a conditional in a for loop. I've tried the following MWE, but it doesn'...
1
vote
0answers
94 views

Alternative indents for fullwidth in tufte-latex

I’m trying to add a larger indent to accomodate for the increased line width when using fullwidth in tufte-latex. It’s not working, the same new indent is applied to all paragraphs. Result with ...
13
votes
2answers
1k views

How to compare integers in TeX?

I do not understand how I can compare integers in TeX. \documentclass[]{article} \begin{document} \if 1<>0 1 is not equal 0. \else 1 equals 0. \fi \end{document} According to this code ...
1
vote
0answers
93 views

String check against a sage command, issue of expansion order? [closed]

I am trying to write a macro to do a conditional check against two strings. The problem I'm having is that I want to check the output of a \sage command and do a string comparison without expanding ...
0
votes
0answers
31 views

Bug in tex iffalse and syntex

I had some code in the preamble that used \iffalse to hide it... I was noticing that every time I'd use synctex winedt would jump to the wrong position but I didn't understand why. I later removed the ...
6
votes
2answers
107 views

How to conditionally load a package only if shell-escape (write18) is passed

The package gitver requires -shell-escape to fetch git metadata from the manuscript's git repository on the local filesystem. However, it is needless to pass the shell-escape flag when compiling the ...
0
votes
1answer
57 views

Beamer footer shifted by adding an \if… \fi test

Ok --- I am getting crazy about this (I can workaround it, but I really would like to know what's happening). Consider this MWE copied almost straight from this answer: \documentclass{beamer} \...
0
votes
1answer
74 views

Check figure placement with \if statement

I would like to add a \noindent before a new paragraph but only if a floating figure is placed directly above it. How can I check this using an \if-statement? So looking at the example below I don'...
0
votes
1answer
39 views

If I need different answer choices based on question number, can that be automated

I asked a question relating to this but I did not have a working example. Here is the original post is-there-a-way-to-alternate-answer-choices-based-on-the-question-number-act-st . To summarize I ...
2
votes
1answer
144 views

Compiling document with PerlTeX, then luaLaTeX - conditional \usepackage based on compilation tool

Slightly connected to my previous question (Output of PerlTex with current TeXlive on Windows), I have managed to generate .pdf files with PerlTeX (precisely, with option --latex=lualatex). Next step ...
0
votes
1answer
52 views

embedded command resulting in argument of \equal has extra } error

I am trying to make a macro (\ls) which will convert keywords into the mathmode version of their equivalent logic symbol. I've figured a way to make this work fine, except when it is in an argument of ...
0
votes
1answer
165 views

Etoolbox package : example

How to replace the C-like code ? \documentclass{book} % C-like code : #define FinalCompilationBooleanIsOn 1 % C-like code : if FinalCompilationBooleanIsOn { \usepackage{pst-all} \usepackage[...
5
votes
1answer
109 views

How to use dynamically generated filenames in \IfFileExists?

I have a file 0012 in the directory of the following tex file. I want to check the existence or non-existence of files inside the \forloop from 11 to 13. \documentclass{article} \usepackage{...
24
votes
1answer
1k views

Check if at begin of a line

For a list of bullet-separated items, I want the separator to be swallowed if it is the first or last element of the line. That is, I want something like \renewcommand{\and}{% \ifnolinebreak% &...
1
vote
2answers
355 views

titlesec define different styles for mainmatter (book class)

I'm aware that the book class implements the \@mainmatter variable which can be used in \if \fi conditionals. On a separate topic, I'm trying to achieve different chapter titles for front/backmatter ...
0
votes
1answer
121 views

Use multi ifthenelse equal text

In the question Use xifthen: how set \cnttest not equal number, I learnt how to perform if-then-else tests where the condition compares two integers. Now, I would like to do the same, but with string ...
1
vote
1answer
97 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
41 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 is ...
1
vote
1answer
92 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
52 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
26 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
46 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
18 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
62 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
36 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
267 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
73 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 2 3
4
5
31