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
0
votes
0answers
20 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 ...
1
vote
3answers
38 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 ...
0
votes
0answers
39 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 ...
2
votes
1answer
17 views

etoolbox: ifdefvoid check for empty lines

I designed a system that reads a number of variables and, depending on the definition creates a text (either text "a" and the text contained in the variable (macro), or an alternate text "b" when the ...
4
votes
2answers
188 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
83 views

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

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 ...
9
votes
2answers
847 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
51 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 ...
0
votes
0answers
30 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 ...
4
votes
2answers
74 views

Conditionally execute a command if a specific package is loaded

I am loading the gitver package based on the expl3 solution accepted for my question here. However, I need to use some commands depending on whether the package has actually been loaded. For instance,...
6
votes
2answers
81 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
37 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
34 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
32 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 ...
0
votes
1answer
29 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 ...
4
votes
1answer
85 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{...
2
votes
1answer
99 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
0answers
14 views

Is it possible to format cells in a pgfplotstable based on values in another pgfplotstable?

Background This question is very similar to another question that I asked earlier concerning how to format text based on the values of a csv. The corresponding answer allowed me to read in a ...
0
votes
1answer
39 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
54 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
24 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
25 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
37 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
22 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
16 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
45 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
115 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
38 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
43 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
45 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
66 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#...
1
vote
1answer
34 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
57 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, ...
1
vote
1answer
27 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
162 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
76 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
92 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. \...
0
votes
2answers
35 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}...
5
votes
2answers
172 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 ...
2
votes
2answers
32 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
54 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
63 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
51 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
23 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 : \...
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
72 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
31 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
118 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 \...