Questions tagged [conditionals]

{conditionals} is about macros like \if and \ifx that may execute other macros depending on whether certain conditions are true or not. Popular packages are {etoolbox} and {ifthen}.

is about macros like \if and \ifx that may execute other macros depending on whether certain conditions are true or not. Popular packages are and .

1835 questions
282
votes
4 answers

LaTeX conditional expression

I would like to be able to set a flag at the beginning of the main flag (say output) that tells if I want to produce a paper document or an electronic document. Then I should check this flag to define or not empty pages, hypperref, oneside or…
Cedric H.
  • 4,162
56
votes
3 answers

Variables for hiding or showing text in Latex

I would like to have some variables for showing or hiding text in Latex. For example, I would like to have two versions of a document. A short version and a long version by changing a variable at the top of the latex document. For example: I want to…
glarkou
  • 711
46
votes
9 answers

Implementing switch cases

I'd like to have command built around a switch-case environment in LaTeX, much like the example below: \documentclass{article} \usepackage{xstring} \newcommand{\dothis}[1]{% \IfStrEqCase{#1}{{a}{so you typed a} {b}{now this is b} {c}{you…
Count Zero
  • 17,424
42
votes
1 answer

LaTeX \if condition

I am using \if condition in a custom command in my LaTeX document. I would like to know where I can find some good explanation about \if command. I followed a Wikibooks \if page but it's just an example; there are not any explanation.
JuliusII
  • 547
34
votes
6 answers

Testing for number

How do I test if a given parameter is a number, in order to apply a different style? And if not, just ignore... Like: \domorestuffifnumber{things} -> things \domorestuffifnumber{123} -> \emph{123} Thanks.
26
votes
2 answers

Conditional cases expression

How can I create a command \if with 1 argument, namely #1, \if{#1=1}{symbol1}...{#1=n}{symboln} that returns symbol1, when #1 is 1, ..., and returns symboln, when #1 is n, and returns nothing, when #1 isn't 1,...,n? For example, I'd like to use…
Leo
  • 3,499
23
votes
5 answers

Are there any "if" commands like "\ifnum" in LaTeX?

Are there any commands containing "if", similar to \ifnum, preferably in LaTeX (rathar than TeX)? For example, is there anything like \ifstring? (I am not after \ifstring only, I want to know which options are available, if any).
Regis Santos
  • 14,463
21
votes
4 answers

How to test if a string is empty

I tried several thing to test if a parameter is empty or equal to a specific carater. How should one proceed ? By the way, what is the best way to have conditionnal code on a parameter who can have three values : empty, v, h…
Tarass
  • 16,912
21
votes
1 answer

Boolean operators: can I use AND, OR in `\ifthenelse`? How?

Can I use AND, OR in \ifthenelse from the ifthen package? If so, can you show me examples and links to documentation? This would make my life easier.
redblob
  • 211
  • 1
  • 2
  • 3
16
votes
3 answers

Do all \if's need to be defined before a nested if?

I have this MWE, which does not compile (Extra \else, Extra \fi) unless I load the showlabels package before the outer \if. (\ifSL@AMS is defined in showlabels.sty.) Is that a general requirement that I have so far never violated, or am I coming up…
bers
  • 5,404
14
votes
1 answer

ifnum x is even DO THIS \else DO THIS \fi

I am looking for a conditional command with the next structure ifnum x is even DO THIS \else DO THIS \fi usually ifnum command have the options = < >, but I would like to have the option even and odd.
Gitano
  • 1,389
13
votes
1 answer

Define a \newif within a nested \ifdefined

The MWE below attemps to define a \newif within a \ifdefined. This works fine, except when the file is loaded the second time. As it is below generates the following error message: Incomplete \ifdefined; all text was ignored after line 1. However…
Peter Grill
  • 223,288
13
votes
1 answer

Why does "\if\char98\char98 T \else F \fi" return F instead of T?

According to the TeXbook the two tokens following \if are expanded and compared? It seems then that \if\char98\char98 T \else F \fi should be the same as \if bb T \else F \fi which does return T. What is wrong with my interpretation?
13
votes
3 answers

Write if statement to the toc

Here is a challenge: This construction works just fine as the if is contained to a single write statement \documentclass[a4paper]{book} \newcommand\test{\noindent…
daleif
  • 54,450
13
votes
5 answers

How to print "Spring" if in month is in Jan-June? Otherwise "Fall"?

I teach classes and in my notes I have "Fall 2015" during fall semester and "Spring 2016" during Spring semester. I can use \the\year for the year. But is there something like \the\season for Fall and Spring? And if so, how can I customize which…
Xu Wang
  • 1,239
1
2 3
11 12