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 \( \).
237 questions
2
votes
3
answers
152
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
189
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
42
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
152
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
70
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
42
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
147
views
LaTeX3 version of expandafter-ifx-csname?
I currently have this code from a previous question (link here)
\NewDocumentCommand \IfFontTF {mmmmmm}
{%
\begingroup
\fontencoding{#1}\fontfamily{#2}\fontseries{#3}\fontshape{#4}\try@load@...
2
votes
1
answer
45
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
99
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 ...
1
vote
1
answer
58
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
32
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
66
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
144
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
199
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
52
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
23
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
376
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
48
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
68
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
108
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
62
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 ...
0
votes
0
answers
30
views
Suppress 'note' field if empty from custom endnote in Image Credits page
I have an Image Credits page where I cite images using standard citations in a bib file. I use the 'note' field to report licensing information. Sometimes this field is empty and then the word 'note' ...
1
vote
0
answers
38
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
107
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
37
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
62
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
55
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
83
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 ...
0
votes
1
answer
100
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
57
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
102
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
136
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
50
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
55
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
98
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
164
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
70
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
140
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
40
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 ...
3
votes
1
answer
1k
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
57
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
62
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
44
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 ...
2
votes
1
answer
52
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
60
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
90
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
220
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
82
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
27
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 ...