Questions tagged [ifthenelse]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
52 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
51 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
18 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
104 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
55 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 ...
  • 147
1 vote
2 answers
49 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 ...
  • 6,731
0 votes
1 answer
41 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
100 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
40 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
107 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, ...
0 votes
0 answers
104 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\/\...
  • 49
0 votes
1 answer
83 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,030
0 votes
1 answer
32 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
41 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,357
0 votes
0 answers
20 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
66 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
50 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
223 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
127 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
72 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
156 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
151 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
114 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
46 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} \...
0 votes
0 answers
62 views

XeLaTeX Awesome CV - conditionally add hyperlink to title text

I'm using font-awesome package for icons in my resume I want to add hyperlinks to few titles, examaple Link to Job Experience Certificate will be included in text if the URL is provided What I tried ...
1 vote
2 answers
180 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$} { \...
  • 377
0 votes
1 answer
56 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
213 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
391 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
35 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 ...
  • 1,975
2 votes
1 answer
116 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,845
0 votes
0 answers
29 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
49 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
45 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 ...
4 votes
1 answer
63 views

Generate an error message when the result of a command is empty

I have the following sample code: \documentclass{article} \usepackage{etoolbox} \newcommand{\defineSpecies}[2]{\csdef{spec@#1}{#2}} \newrobustcmd{\spec}[1]{\csuse{spec@#1}} \defineSpecies{h2o}{H$_2$...
  • 522
0 votes
1 answer
73 views

PGF/Tikz Ifthenelse complaining about missing num

This MWE \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture}[ overline/.style={black,fill}, underline/.style={black,fill=white}] \pgfmathsetmacro{\Px}{2} \...
  • 1,017
3 votes
1 answer
28 views

Executing only specific options

I'm pretty new to advanced LaTeX coding and therefore may not have a perfectly specific question. I hope you can help me anyway: I want to maintain different preambles at once. They can be seen as ...
  • 366
1 vote
1 answer
185 views

How to change the index in a foreach loop depending on the index value

I this example: \documentclass[border=2mm]{standalone} \usepackage {tikz} \usepackage {siunitx} \usetikzlibrary{3d} \usetikzlibrary{babel} \usetikzlibrary{calc} % \usepackage{...
  • 273
0 votes
1 answer
238 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 ...
  • 1
1 vote
2 answers
33 views

Allowed Algebra with \the\year

I have a homework problem that I reuse relatively frequently, and I'm trying to update the solution to match the dynamic. Suppose z(t) is a periodic function with period 3. Evaluate z(\the\year). \...
  • 119
2 votes
1 answer
73 views

Simple toggle animation won't work

I tried a simple toggleanimation. First i create a bool value If I set it to true, the if path is performed, set it to false results in the else path. So far so good. Within an animateinline i want to ...
  • 113
1 vote
1 answer
80 views

I am using \if condition in a custom command in my LaTeX document. can i know how to do the if statement in the uploaded image

\documentclass[a4paper,11pt]{article} \usepackage{siunitx} \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{textcomp} \usepackage{mathpazo} \usepackage{eulervm} \usepackage[utf8]{...
2 votes
1 answer
96 views

Pgfplots - conditional style

I would like to create a conditional style for my pgfplots graph that would use this or that elementary style, based on an input value. Here is an example of a conditional style depending on the value ...
  • 335
3 votes
1 answer
168 views

Conditional header appearance based on chapter name

I am converting a complex markdown document to pdf using pandoc. And need to add some formatting to it during the conversion. So I cannot have the styling and the data at the same place, means, I ...
0 votes
0 answers
47 views

Using a variable (?) to change color definition on STY file

I am trying to use a variable I define with \newcommand in a tex file (\profile) in an if-else loop to define a color (\main_color) in the style-file I am using. So when \profile is np \main_color ...
  • 101
0 votes
1 answer
52 views

Unexpected TikZ ifthenelse behavior [duplicate]

The TikZ user guide (version 3.18b, page 1042) says this: ifthenelse(x,y,z) This returns y if x evaluates to some non-zero value, otherwise z is returned. It would appear that both y and z are first ...
  • 7,967
1 vote
1 answer
47 views

How to define a macro containing if without closing fi, and another macro containing the closing fi

I am working on a LaTeX document and writing at several locations. For faster compiling, I have surrounded some sections with \iffalse, \fi constructs. When I proof-read the document at the end of the ...
0 votes
1 answer
86 views

Detect segment intersections with tikz

I have to detect when two segments intersect in a parametric figure that need's to computes coordinates into a tikz picture, and it won't works, seem's that "intersections=... total=\t" or &...