As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [ifthenelse]

\ifthenelse{⟨test⟩}{⟨then clause⟩}{⟨else clause⟩} evaluates ⟨test⟩ as a boolean function, and then executes either ⟨then clause⟩ or ⟨else clause⟩. ⟨test⟩ is a boolean expression using the infix connectives, \and, \or, the unary \not and parentheses \( \).

Filter by
Sorted by
Tagged with
0 votes
0 answers
26 views

Error Missing Number, treated as zero after two If

I have trouble with \tikzset. When I create a function (here foo), the parameter \lfvert is not recognize on the second if statement. (The node didn't print it anymore) And that give me the following ...
2 votes
1 answer
98 views

A funny bug with input, newcommand, ifthenelse in a beamer

First I write a tex named thequest like: \begin{quest} Just a problem. \end{quest} Then in the main tex, I write \newtheorem{quest}{Question} \newcommand{\Fakeframe}[1]{\ifthenelse{\equal{#1}{}}{}{ ...
3 votes
1 answer
19 views

How can I access \institute content with \ifthenelse in beamer?

I try to check if \institute is empty in a beamer document. This fails. I found the solution for \author already here: Why does \insertauthor lead to an error inside \ifthenelse statement? You can ...
1 vote
1 answer
66 views

Code optimization: Boolean token equivalent to \ifdefempty, which can combine with \OR or \AND

I'm a new LaTeX user looking for some guidance. I wish to optimize the following code, since lines 3 and 5 are unnecessarily repeated, because I am using \ifdefempty{}{}{}, instead of some Boolean ...
0 votes
1 answer
356 views

Define new environment with conditions

I would like to define a new environment with conditions in my template file. My environment consists in a lign of header filled by a title (given at the environment in an argument) and then at the ...
2 votes
1 answer
169 views

How is \iffalse ... \fi handled?

Let's have a look at the example: Some text. \iffalse Nothing to print. \fi Further text. I would expect that this is handled like Some text. Further text. because the system simply removes the ...
0 votes
0 answers
31 views

Remove \thechapter in the Introduction

I'm using classicthesis with scrbook class, and my headings are defined as follows: \renewcommand{\sectionmark}[1]{\markright{\textsc{\MakeTextLowercase{\thesection}} \spacedlowsmallcaps{#1}}} \lehead{...
0 votes
0 answers
17 views

Is there a way to change multiple lines depending on a condition?

I'm working on my resume, and I have two versions -- one more tailored towards the Biology/premed side of my experience, and another focused more on my computational side. Right now, whenever I'm ...
0 votes
1 answer
39 views

Redefining a command with arguments inside another comand sometimes does not work

I try to generate a \law command that behaves differently depending on the settings. \setlaw changes the behaviour differently. It seems to work for the first two cases. However, when trying to put ...
0 votes
1 answer
50 views

Calculating marking points exam class

I want to calculate marking points for an exam by multiplying a percentage with the total number of points (e.g., 0.5 * \numpoints{}) to make a grading table. Problem is that before I run the ...
2 votes
1 answer
29 views

Why does \insertauthor lead to an error inside \ifthenelse statement?

Using \insertauthor in \ifthenelse statement throws an error (no error if it is used elsewhere in the document). \inserttitle or \insertdate works fine. Why do I get an error when I use \insertauthor ...
0 votes
1 answer
49 views

Switch case environment that provides different kinds of braces for an equation

I'm trying to create a shortcut for equations inside braces. Specifically, I'd like to create a command that works like this: input: \strongbraces{my particular expression} %basically the default ...
0 votes
1 answer
82 views

Typical mistake: xspace is always looking forwards, never backwards [closed]

How could we explain the difference between those two outputs, where the second one features } just after \xspace? MWE \documentclass{article} \usepackage{xspace} \usepackage[citestyle=authoryear]{...
4 votes
1 answer
216 views

Why 'yellow' isn't good for optional parameter of \fill, when it is the results of an \ifthenelse command?

Can anybody help me? Why are the 1st, 2nd and 5th code good but 3rd and 4th stop with warnings. First code is OK \documentclass{article} \usepackage{ifthen} \usepackage{tikz} \begin{document} \...
2 votes
1 answer
43 views

Alignment of if-else notation

I have three if-else condition notations one after the other. I want to align their brackets together but can't do so. \begin{equation*} \begin{rcases} \texttt{Chapter 1} \\ \texttt{Chapter 2}\...
0 votes
0 answers
17 views

Omit page reference if target is on the same or the facing page

I'm working on a two-side scrbook in which references are made to other sections, figures, etc. If the target is on the very same page, I want to omit a page reference in the text (i.e., if we're on ...
3 votes
3 answers
112 views

canonical macro definition for conditional with discrete choices from valid set

what is the canonical way to define a macro (presumably, now xparse is preferred) that acts differently based on one of a set of discrete choices. \mymacro[a]{does one thing, e.g., print this in red} \...
2 votes
2 answers
192 views

LaTeX3 case inside \equal

I have a LaTeX document where I have defined a switch case command using LaTeX3 syntax. I am using the case inside the \equal condition of an \ifthenelse command. However, I keep getting the wrong ...
2 votes
2 answers
53 views

How to compare an argument to a given string, within a 'newenvironment' definition?

Problem description I am trying to create an environment that produces boxed paragraphs with different styles. So I tried to implement some "if"-"elif"-"else" blocks, ...
1 vote
2 answers
66 views

Using boolean functions \ifthenelse changes citation numbers with complex bibliography setup

Finally my example with different options of bibliography works fine thanks to moewe. To the below example I needed to add boolean function: \usepackage{ifthen} \newboolean{print_or_not} \setboolean{...
0 votes
0 answers
46 views

\newcommand for \ifdefined

Is there a possibility to design a \newcommand for the if-structure? I want to shorten the \ifdefined\todo text \fi into something where I simply need to write \todo text without the \fi.
4 votes
3 answers
230 views

Division by zero and precision in math calculations

I have this table who is like almost to all my wishes: This is my code: \documentclass[border=5pt]{standalone} \usepackage{tikz,siunitx,calc} \begin{document} \sisetup{round-mode = places, round-...
1 vote
2 answers
70 views

Creating newcommand for a tens frame grid using tikz

I'm trying to create tens frames to model addition of numbers. I'd love it if \tensframe{#1}{#2} would show #1 green circles starting on the left and growing up, then #2 blue circles continuing from ...
3 votes
3 answers
192 views

Hiding an environment that contains minted code

Task: I want to create a 'notes' command and an environment which can be hidden by a boolean flag. Problem: These 'notes' can contain minted code blocks which mess up previous solutions found on the ...
0 votes
1 answer
57 views

Exit \ newcommand before exit [closed]

I need to prevent commands from reprocessing a parameter. Is there the way to exit command before end if condition is met just like return in JavaScript functions: function calculateSomething(param) { ...
1 vote
0 answers
19 views

I want Section 1 and chapter one the same page. otherwise the section on the new page

\usepackage{ifthen} \ifthenelse{\value{section}=1\OR \value{section}=0} {\renewcommand*{\thesection}{\arabic{section}} \let\bkdsection\section \renewcommand*\section{\bkdsection}} {\...
1 vote
1 answer
146 views

Omitting a dinkus / separator if it would be the first or last element on the page

I am working on a book of demotivational aphorisms. Since the aphorisms are brief I'm wrapping them in samepage and I allow more than one per page, if they fit. This kind of layout benefits from some ...
0 votes
1 answer
96 views

Get value of Biblatex's printfield{}

I would like to compare the value of a \printfield command in \ifthenelse It seems printfield does not return the value so ifthenelse can't check it. How can I access the value in a way that ...
1 vote
2 answers
52 views

How define a command with argument to specify which list to return?

I want to define a command that returns one or another list, as a list enclosed in braces, that, in my real document and not this MWE, I can use as an argument to something else (namely, the list over ...
0 votes
1 answer
67 views

Disable a package/classoption when the draft mode is on

I have a custom .cls file which passes the parameters of the \documentclass to a4paper. In this .cls file, I have (from the top), \NeedsTeXFormat{LaTeX2e}[1996/12/01] \ProvidesClass{Thesis} ...
0 votes
2 answers
104 views

How to check that something starts with * (or how to build your own exercise sheet from a moodle database)

I would like to check if something starts with an asterisk (*) My attempt: \def\testast#1{\ifx*#1\relax YES\else NO\fi} But the output of \testast{*Word} is WordYES while I would expect just YES The ...
1 vote
3 answers
71 views

Custom new command in math mode with two alternative outputs depending on input arguments

I have written some custom commands to use inside mathmode. The command basically corrects the style of the left side sub and superscript. It decides which script is the longest and right-justify the ...
4 votes
2 answers
146 views

How ifthen \equal could compare \relax to another \relax-like command?

I was implementing an ad hoc list data structure inside LaTeX, where \aaa expands value for aaa, \bbb exapnds value for bbb and to show that \bbb is next to \aaa on the list, \NEXTaaa expand to bbb, ...
1 vote
0 answers
166 views

Error "Extra \else" statement with "ceurart"

I am getting an error when I run pdflatex command on the following .tex document. \documentclass[ % twocolumn, % hf, ]{ceurart} \usepackage{minted} \setminted{breaklines=true} \def\UrlBreaks{\do\/\...
0 votes
1 answer
160 views

Assign a color to a variable name in a newcommand

I am writing a complex diagram using TikZ in which the colors used for certain nodes depend on the value of the input variable. I cannot use the color itself as an input variable as certain things ...
0 votes
1 answer
48 views

Use of an \if statement inside a tikz environment

In order to illustrate a large chapter number on the beginning of each chapter, I created a tikz environment and added it to the CLS file like this: \begin{tikzpicture} ........ \node[...
2 votes
1 answer
48 views

newif for table does not work

I create two different table contents and want to switch with a newif. \AAAfalse has no effect. What do I have to do? \documentclass[a4paper, landscape]{article} \usepackage{pgfplotstable} \...
0 votes
0 answers
21 views

Use scale if latex image is small enough, center in page otherwise [duplicate]

I automatically generate a bunch of diagrams, and I'd like them to be automatically formatted to fit the page according to the following style: If the diagram (in the form of a .png figure) is ...
2 votes
1 answer
78 views

Why does \ifthenelse not work?

Im currently dealing with a problem in my code. I keep getting the error use of \nextx does not match its definition From the \pgfmathsetmacro\nextAsInt... line. But i cant see the problem. It should ...
1 vote
0 answers
57 views

How can I switch quickly betwen two style files?

I would like to switch between two styles in a simpler way, I have two sty files (say a.sty and b.sty) and a different bibstyles for each file (say a.bst and b.bst). In order to switch between two ...
2 votes
1 answer
502 views

Extra \else and extra \fi error

I am writing a document that presents different information depending on a defined command. The code in a simple version is like this: \documentclass{article} %\usepackages ... \title{My title} \...
5 votes
2 answers
214 views

Check if number is in list

My goal is to have different headers and sortings depending on a list of numbers. I have multiple projects ordered by project number (desc). Now I want to highlight some projects, so that the ...
1 vote
0 answers
135 views

String equality check [closed]

I want to compare 2 strings and perform different tasks based on their results(using if-else loop) My code is here: \tab• \hyperlink{new}{New Features, Enhancements, and Changes}\linebreak \begin{...
0 votes
1 answer
314 views

IF statement in .cls file. How to control it from .tex file?

Minimum working code is attached herewith. If I change 1 to 0 in \newcommand{\numsections}{1}, I get heading without number, and to get numbered heading, I have to go to .cls file. I don't want the ...
4 votes
2 answers
126 views

How can I use integers as parameters for \ifcase

I am very confused about LaTeX's calculatation. I tried to defined an environment which could change its typography through an integer parameter I give freely. I chose \ifcase and tried as below: \...
4 votes
2 answers
169 views

Weird error: "\csname if@chapter@pp\endcsname" inside of \if ~ \fi

I can't understand why the following doesn't work: \documentclass{beamer} \newif\iftemp \tempfalse \iftemp \csname if@chapter@pp\endcsname \addcontentsline{toc}{part}{Appendices} \...
0 votes
1 answer
66 views

fix for texMemo class producing watermark when it shouldn't

I am starting to play with the texMemo document class (which can be found here). The class uses the ifthen package and the draft watermark package. I'm used the latter before but not the former. I ...
2 votes
1 answer
36 views

Conditionally formatting numbers using a \newcommand

I want to create a command the prints a number in red if its negative and green if it is positive. I have tried: \documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{ifthen} \...
9 votes
1 answer
262 views

If condition with non integer numbers in Tikz

I have the following code to build the derivates of a given function: \documentclass[tikz, border=.5cm]{standalone} \usepackage{tkz-fct} \usepackage{xfp} \usetikzlibrary{spy} \definecolor{vinho}{rgb}{...
1 vote
2 answers
394 views

Algorithm2e - write IfThenElse in one line

I have the following example \documentclass{report} \usepackage{algorithm2e} \begin{document} \begin{algorithm} \lIf{$\max_{\mathcal{AV}} > \theta_5$} { \...