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 \( \).
247 questions
5
votes
5
answers
234
views
\ifthenelse and modulo
I have a list of numbers from 1 to 12. I want to print the numbers 3,6,9 and 12 in purple, the others in blue.
With my code:
\documentclass{standalone}
\usepackage{tikz,ifthen}
\begin{document}
\...
2
votes
2
answers
109
views
floating point arithmetic and boolean operations with \ifthenelse
This is a follow up to my previous post about arithmetic operations and tikz
I would like to performance floating point arithmetic & boolean operations in conjunction with \ifthenelse. Here is a ...
3
votes
2
answers
134
views
arithmetic operations with \ifthenelse
Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:
\documentclass{amsart}
\usepackage{tikz, ifthen}
\begin{document}
\begin{tikzpicture}
\...
0
votes
2
answers
59
views
Can we mix \newif's \ifname as in \ifgreen with \OR or \AND?
I created \ifCond1 and \ifCond2 with \newif.
If I want to test one condition, I use \ifCond1 Condition 1 OK \else Condition 2 KO \fi.
My question : is there a way to use \ifCond1 and \ifCond2 glued ...
3
votes
2
answers
117
views
\pgfmathifthenelse gives error
I write exam questions in Latex. I defined parameters and use \pgfmathsetmacro to do the calculation and print the result. This makes it easy to just change the values to generate a different question....
5
votes
2
answers
336
views
Line to be filled by students
I am preparing materials for my students, and I would like to leave some blanks for them to fill in. For this, I want to define a new command — let’s call it \answerline — to be used like this:
Dog ...
2
votes
2
answers
191
views
Difficulty writing an ifthenelse style command
Edit: The previous edit removed the extra line in my command definition, but it turns out that this was the actual problem and not that there were mismatches in argument types being passed between ...
2
votes
1
answer
73
views
tcolorbox with and without lower part
My problem is whether or not to show the lower part of a tcolorbox based on a conditional statement that takes a given argument.
I'm wondering: Why doesn't the conditional statement work?
I've checked ...
0
votes
1
answer
74
views
Position of nodes with the "ifthen" package
I am not sure that the result of this code is the most appropriate for the nodes of points P and Q. What is the mistake made?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\...
2
votes
2
answers
88
views
generate random lines in a table
I'd like to generate a table with some random content. Ideally, I would have lines like a & b & c where I produce a; and sometimes b is a random number and c is blank; and sometimes b is blank ...
3
votes
1
answer
95
views
Change label based input value
Consider the following MWE:
\documentclass{article}
\usepackage{fullpage}
\newcounter{question}
\renewcommand{\thequestion}{\Roman{question}}
% see https://tex.stackexchange.com/a/729773/10898
\...
2
votes
3
answers
242
views
Condition IF in Tikz
I would like to draw a Riemann sums plot where the bars are graphed based on the heights of each pair of consecutive intervals. The issue will be with the ifthenelse statement as I do not think the ...
3
votes
3
answers
263
views
Conditionally making environment content disappear
I am working on project from which I want to produce both an answer key and a solutions manual to a long list of questions (I am also producing the problem sheet from this project as well). The ...
0
votes
1
answer
85
views
Compare imported data from CSV with ifthenelse
I'm trying to make a comparison in Latex with data imported from a CSV file.
Unfortunately, the comparison doesn't work (or gives wrong result) when variable is assigned a value from CSV file even ...
3
votes
3
answers
216
views
Weirdness with `\ifnum`: `\ifnum\curyear=2024` gives an error, but `\ifnum2024=\curyear` works as expected
After an embarrassing amount of attempted research and trial and error, I've landed on the following code that works as expected. If the current year is 2024, it says "They match!". If it's ...
0
votes
0
answers
102
views
Extracting data from CSV - known cells
I have an Excel file which is created when the user inputs for a quote creation.
E.g. in cell "D3" you find the company name, in cell "D11" the expiry date of the quote.
Table ...
1
vote
1
answer
78
views
Putting if-else in environment
I made a tcolorbox based environment that I want to toggle on and off depending upon whether I want to show the solutions or not.
The following code works fine when \boxtoggle is set to 1, but not ...
1
vote
2
answers
242
views
LaTeX3 version of expandafter-ifx-csname?
Note [cfr]: the code below does NOT work. Please follow the link for amended code which does. I do not know how to edit this question without changing its meaning and its author has not updated it in ...
2
votes
1
answer
73
views
Tikz numbering time series diagram nodes using foreach
I'm trying to build a repeating graph that starts at t-1 and progresses to t+1 but I can't figure out how to print the time series correctly.
I have three identical diagrams cascaded where the left ...
2
votes
2
answers
250
views
If-then-else statement with page number as the condition
I want to check the page count of the entire document to implement different commands using an if-then-else statement. I've looked all over SE, but I haven't found a solution that works for me; if I ...
2
votes
1
answer
190
views
Adding multiple positions at same company to resume class document
I'm using the resume.cls made by Trey Hunner (see here for Github link if interested). The below is a minimally-reproducible example.
The resume.cls only allows me to add in a single job title and ...
1
vote
0
answers
55
views
Using \ifthenelse and \isempty in newcommand used in glossaries's name
I want to use \ifthenelse while defining symbols with \newcommand. This works all fine, until I try to use those symbols (here \densCanv) in my glossary as a name:
\documentclass[a4paper,10pt]{article}...
0
votes
1
answer
105
views
Problem with ifthenelse
\documentclass{article}
\usepackage{ifthen}
\usepackage{currfile}
\newcommand{\textforpicture}{
\ifthenelse{John}{This is text 1 and the name of this file is \currfilebase}{nothing}
\ifthenelse{Jack}{...
2
votes
2
answers
191
views
Checking if a certain fragment is located earlier in the document
Very often I want to refer to a certain claim I mentioned earlier in the document: "As I said earlier, blah." Since I often rearrange material, I need to ensure that "blah" indeed ...
3
votes
2
answers
505
views
\ifnum to draw a tikzpicture, less than or equals
I want to make a conditional statement that draws one tikz picture for specific values of \t and another for different \t values.
Here is a M(non)WE:
\documentclass{article}
\usepackage{tikz,ifthen}
\...
1
vote
1
answer
120
views
Extra \fi error when listing inside a custom environment
I am trying to write a solutions environment sol which I can use to write solutions within assignments. There are two reasons for the environment,
Solutions may be different colour.
Solutions can be ...
1
vote
0
answers
55
views
Conditional Output with user input
I am trying to write a form in Latex where I'm asking a question an if the answer is no I whant to ask another question. I'm a real beginner in Latex and I need a little help how to start it.
It ...
3
votes
3
answers
487
views
How to define a command (or similar) that makes a conditional expression reusable?
I'm struggling with the correct use of conditional expressions with ifthenelse at the moment. I would like to define a command (or similar) that represents a certain conditional expression in order to ...
1
vote
1
answer
69
views
Trouble formating presorted table with csvsimple
\documentclass{article}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{csvsimple}
\csvstyle{mystyle}{
tabular=|c|c|c|,
table head=\hline Gruppe & Buchstabe & Zahl \\ \hline,
...
1
vote
0
answers
15
views
Information about surrounding text [duplicate]
I'm trying to define a command which raises an issue about spaces.
Basically, I want to have a single command for these two :
\documentclass{article}
\newcommand{\Cinf}{$C^\infty$ }
\newcommand{\...
1
vote
1
answer
117
views
`foreach` does not work together with `ifthenelse` and `mod`
In the minimal example below, the commented out line does not work.
Other lines work correctly.
I can't understand what the reason is.
Here is a similar question, but my variable \im takes integer ...
0
votes
0
answers
182
views
Precedence of \and and \or
I am using the ifthen package. I see some comments on the web that there is a more recent alternative, so maybe the answer to this is, I should switch. But in any event . . .
So if I have an ...
2
votes
1
answer
90
views
\ifthenelse atomic proposition not behaving as expected when paired with fancy footer
I understand that the title of the thread is a bit cryptic, but I admit that I don't have much of a clue about the reason for which this (apparently simple) conditional (sometimes) fails in working as ...
1
vote
0
answers
59
views
rotate table or not, depending on its width
I build a Tex file in C# and then compile to PDF.
How would I rotate a table sideways if it is to wide for portrait?
So the actual, displayed width is only known AFTER the table is generated in C#..
I'...
1
vote
1
answer
125
views
How to Color Certain cells in TikZ Pictures
I'm interested on coloring certain cells of a TikZ picture. It is the following:
I did it by using the grid and creating the numbers. I present the code I create above:
\begin{tikzpicture}[scale = 0....
1
vote
0
answers
47
views
Printing toc/lof/lot/others
How can I print toc only if isn't empty?
\documentclass{article}
\begin{document}
%if there is a section, toc will be printed, else it wont be
\tableofcontents
%\section%in this case it wont be ...
1
vote
1
answer
99
views
Missing number, treated as zero error when using for loops and conditionals in tikz
I would be nice to be able to have a code that, by modifying certian parameters like height and width and cells to be colored red or green, generates a table for me. The code I have is already a ...
0
votes
1
answer
69
views
A sheet of Input-Orders
I have a sheet of input orders like:
\input{something}
\input{another thing}
\input{some other thing}
...
I want to make a command like \myinput{} so that if I use \myinput{24} then that will input ...
0
votes
1
answer
132
views
beamer and \ifstrempty
EDIT. Consider the following code. I wish to avoid empty beamercolorbox, if the required item to insert therein is empty.
Consider the case of a section without a subsection, then the subsection ...
1
vote
1
answer
142
views
LaTeX: \equal not recognized within \section command
I have the following code, where I want to steer the language of some titles and some texts using a "\newcommand". The following minimal example uses the new command "kLanguage", ...
0
votes
2
answers
104
views
ifthenelse with mismatched braces [duplicate]
I am writing some lecture notes, and I would like to have automatically generated two versions. One version includes everything (examples, additional explanations, etc.), and another one with only the ...
1
vote
1
answer
154
views
Incomplete ifElse
Overleaf gives me an error saying that there's an incomplete if-else. I don't have any if-else in the document. I'm not sure why there's an error.
If I comment out the second \item the compiler is ...
0
votes
2
answers
254
views
Two texts with the same width on two different lines, but with different font sizes
I want to create a new command for a template cover, and I think a specific type of formatting would look great, but I'm having trouble implementing it. Essentially, what I want to do is have a title ...
0
votes
0
answers
89
views
iftoggle or ifthenelse within a bibtex file, author field not expanded
I am trying to put a conditional statement within a bib file, namely in the author field. I tried with both the ifthenelse and the iftoggle commands, but to no avail. The condition is respected, but ...
1
vote
2
answers
92
views
Error with a command whose purpose is to allow a value to adapt over the course of a document
I am trying to write a command that will do the following, in order:
Measure the width of an input word.
Compare this value to an existing value.
If the input word's width is greater, then take on ...
2
votes
0
answers
172
views
\iffalse not working inside of table
The following code is supposed to generate a table with a single row and two columns. It does however not compile. The error messages contains Incomplete \iffalse and A forbidden control sequence ...
5
votes
3
answers
186
views
Have something appear in the footer only if section isn't over
I'm writing a gamebook. My text is divided into a lot of little paragraphs, with length varying from a couple of lines to a page and a half. Readers/players will start from paragraph 1 and then move ...
1
vote
1
answer
107
views
Add a plural sign depending on the number of items
I'd like to add a plural sign (say a 's') when needed. My current use case is for pluralizing a noun based on the number of pages in a document but I could also count oranges and bananas down the road....
2
votes
1
answer
175
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
73
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 ...