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
2 votes
1 answer
27 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 ...
  • 21
0 votes
1 answer
45 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
80 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
215 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
40 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 ...
0 votes
0 answers
20 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 ...
3 votes
3 answers
108 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} \...
  • 3,539
2 votes
2 answers
184 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 ...
  • 143
2 votes
2 answers
46 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, ...
0 votes
1 answer
42 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 ...
  • 1
1 vote
2 answers
62 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{...
  • 53
0 votes
0 answers
41 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
218 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
68 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 ...
0 votes
1 answer
55 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) { ...
  • 29
1 vote
1 answer
60 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 ...
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
132 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 ...
  • 137
0 votes
1 answer
82 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 ...
  • 167
1 vote
2 answers
50 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 ...
  • 7,350
0 votes
1 answer
58 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} ...
  • 123
0 votes
2 answers
103 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
54 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 ...
  • 650
4 votes
2 answers
140 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
145 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\/\...
  • 73
0 votes
1 answer
133 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 ...
  • 1,080
0 votes
1 answer
37 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
47 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} \...
  • 6,711
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 ...
  • 197
2 votes
1 answer
76 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
53 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 ...
  • 133
2 votes
1 answer
396 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
188 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
112 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{...
  • 23
0 votes
1 answer
264 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
163 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} \...
4 votes
2 answers
119 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: \...
0 votes
1 answer
60 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 ...
  • 103
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} \...
1 vote
2 answers
319 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$} { \...
  • 397
0 votes
1 answer
78 views

Condition for if the page is one sided

I want to do something like below \documentclass[a4paper, 12pt, oneside]{article} \begin{documnet} \if@twoside The page is doublesided. All good. \else \textbf{{\Huge The page is not double sided! ...
  • 123
9 votes
1 answer
247 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}{...
4 votes
3 answers
499 views

Creating new environment with ifthenelse

I want to make it so all proofs in my document are conditional using the ifthen package. So far I have \usepackage{ifthen} \newboolean{proofs} \setboolean{proofs}{true} ... \ifthenelse{\boolean{...
0 votes
1 answer
37 views

Nesting macros : probme with ifnum

I'm designing 2 macros, and nesting them fails and I can't see where I've made a mistake. The 1st macro takes a floating point number (eg 3.2) and check it agains 3 thresholds. The second macro ...
  • 2,055
2 votes
1 answer
139 views

Graph of Thomae function by an amateur

I am trying to plot the Thomae function, which is defined in the following way: Now, I went through this answer, but unfortunately, could not grasp much. My idea is simple. Run two nested loops for ...
2 votes
1 answer
40 views

New command using if/then statement based on cleveref values?

I have a special command defined called \Exerref which works on labels, much like \Cref. Would it be possible to create a new command, let's call it \Sref, that invokes either \Exerref or \Cref based ...
  • 2,885
0 votes
0 answers
32 views

How to adapt titlespacing to odd or even pages

\documentclass[a4paper,12pt,twoside]{report} \usepackage{titlesec} \titleformat{\chapter}[display]{}{\chaptername}{-2pt}{\hskip5cm \centering \Huge \bfseries \mbox} \titlespacing{\chapter}{0pt}{-...
1 vote
1 answer
58 views

\whiledo not working when using it to generate table

I'm trying to use \whiledo (contained in the ifthen package) to automate the creation of a table. The idea—more or less—is that by setting a value \colnum to a number x, I can make a table with x+1 ...
0 votes
1 answer
47 views

Return type for \newcommand probably doesn't fit \DTLfetch?

I want to fetch from the csv file with a boolean condition (either give me the fruit or give me the count). The first command (CMDone) works and says "count" and the fetch also works and ...