{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}.

learn more… | top users | synonyms (1)

14
votes
3answers
895 views

Equivalent to “in” operator

I want to write a command that responds to an argument being in one set of reference strings or another. The argument takes a (musical) note name, and the command will print an accidental depending ...
10
votes
1answer
108 views

Pass conditional options to documentclass

I'd like to pass options to \documentclass basing on the compiler it runs, something in the lines \documentclass[if latex then use dvipdfm else nothing]{beamer} My motivation is that there're ...
2
votes
0answers
156 views

Constraint for a decoration: how to know result after decoration

My question is kind of extending of this answer. I want to decorate a path with text only when text fit the path, but also I want to know if decoration was success. I need to know this to be able to ...
26
votes
3answers
2k views

Parametrize shading in table through TikZ

I wanted to do some shading in a table according to its values. For example, if you see the table below: a b c d a 90 10 0 0 b 0 80 10 10 c 0 0 95 5 d 0 10 5 85 I want to ...
13
votes
5answers
494 views

Test if the first character of a string is 'a'

Is there an easy way to make a macro returning a string (e.g. 'true') if the string input begins by some fixed character, say 'a' ? I can't figure how to combine the different packages to do this. ...
5
votes
1answer
106 views

Using `ifthenelse` to combine two related functions into one

This question is based on Peter Grill's answer to "Table including rows of a master table".. The function PrintDTLTable was in Peter's original answer. I wanted a version that would run over all ...
4
votes
1answer
124 views

\ifnumcomp + \ref

I have a definition with 20 cases or so, and a proof about that definition has one case for each case of the definition. I'd like the proof cases to reorder themselves automatically when I reorder ...
94
votes
4answers
34k views

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 ...
7
votes
1answer
94 views

How to do pagenumbering in a fancy way

How do i get uneven increasing page numbers in the first half of my document, and in the second half in the second half? Example: 1,3,5,7,8,6,4,2 Here are my thoughts on how to solve it: My LaTeX ...
3
votes
0answers
56 views

how to add conditions inside itemize list?

List mentioned below is having three items. There are four variables : 1] varone 2] vartwo 3] varthree and 4] sub ; which are coming from external CSV file. Item 2 with "Value B" will be displayed if ...
1
vote
0answers
41 views

Indicating that the adjustwidth environment should be placed around text

I've been trying to work out a solution to this question about changing margins for body text without changing header/footer placement. Using the changepage package, I was able to work out the ...
4
votes
1answer
442 views

LaTeX3: Defining key to set boolean variable

I want to define a key, which, if set, sets a boolean variable to false. The documentation is not clear on that point. It states (source3.pdf, sect. 87, p. 134): Defines <key> to set ...
1
vote
0answers
13 views

Commenting out large blocks in the preamble when in draft mode [duplicate]

I would like something to enable me to comment out large blocks of my preamble when I've specified that my document is a draft. The comment environment provided by the verbatim package works well for ...
6
votes
1answer
84 views

How to detect if there is one or multiple pages in a glossaries entry's number list?

I'd like to be able to print e.g. "p. 1" if an acronym is only used on one page and e.g. "pp. 1, 2" if it is used on multiple pages. I have tried to define a new counter and use its value in the ...
4
votes
1answer
62 views

Check if the last letter of a name is an s or x or neither nor

In German we have a (often disregarded) rule for using apostrophes. In English it is like so: "This is Mike's chair." In German it depends on the names ending. It's like this: "Das ist Mikes ...
2
votes
2answers
43 views

Display first (sub) environment in an environment

I would like to make a bank of problems of similar type--however, I only want to display the first of each time. For example: \begin{bank} \begin{exercise} 2+2 \end{exercise} \begin{exercise} 4+3 ...
3
votes
1answer
103 views

One source text, two outputs [duplicate]

I have very long source text. I want to create two outputs: All text Only small pieces of this source text, selected by condition command MWE (precisely: not working) \documentclass{article} ...
7
votes
2answers
243 views

math conditionals using (if - else - fi) command

I saw these command when i searching sth. I wonder if we can increase numbers if conditions. it's like if{0} = a, if{1}=b, if{2}=c, if{3}=d etc. \newcommand{mycommand}[1]{ \if{#1 != 0} Some text, ...
6
votes
2answers
99 views

\RequirePackage within \if\else\fi

Why does the package iftex have to be loaded outside of a \if...\else\fi structure? (The same goes for packages ifpdf, ifluatex, ifxetex.) Consider: ...
11
votes
2answers
179 views

New command with if/then statement conditioned on non-integer number?

In LaTeX, how do I declare a new command that gives different output depending no the result of a test with non-integer numbers? Specifically, I'd like to a command to compare a number with 0.01 (the ...
3
votes
0answers
55 views

Conditional Variation of \headheight

I'm trying to use \ifthenelse from the ifthen package to vary the size of \headheight within a document. I'd like this to be larger for the first page and then smaller for each subsequent page. I ...
8
votes
1answer
82 views

Very simple condition in macros

I try to define a macro in LaTeX. This macro should give a different output when I use condition true and false. This does not work: \documentclass{article} \usepackage{lipsum} \newif\ifABC \ifABC ...
12
votes
2answers
178 views

How to test whether the starred-version of a command is defined?

This question is similar to How to conditionally define a new command in LaTeX? but I want to test if the starred version of a command is defined. The naive thing \makeatletter ...
5
votes
1answer
72 views

Conditional expression to convert figure to table. Is it possible?

I have a though one for you: I'm writing in MultiMarkdown and all my figures, tables, charts are usually pictures. This allows me to write something like this: The MultiMarkdown input ![This is the ...
2
votes
1answer
162 views

Nested ifthenelse in tikz fails after arbitrary changes

Attempting to draw a random polymer mesh, which I intended to visualize by drawing a series of random walks between (x,0) and (x,1) where x is arbitrary. My first attempt is attached, and it compiles. ...
8
votes
1answer
127 views

Fontsize determination

We usually point out explicitly or not normalfont size in \documentclass[11pt]{article} etc. 11pt may be absent here explicitly. Which variable contains this 11 or 10, 12pt?. I need get it in a ...
17
votes
3answers
805 views

Conditionally Remove Brackets

I'm trying to create a command with an optional argument using \newcommand{\Af}[1]{{\mathbf{A}_{(#1)}} where the argument is a number. However, I'd like that if no argument is given the bracket ...
6
votes
1answer
59 views

Conditionally add multicols to enumerate environment

I would like an environment to be called by \begin{myenv} that conditionally adds multicols if called by \begin{myenv}{<number of columns>}. This is what I tried: \documentclass{article} ...
2
votes
0answers
126 views

Why can't I get a conditional command to work in a macro invoked within a tikzpicture?

I wanted to create a macro that can be invoked in the middle of a tikz path and behave differently, conditional on one of the arguments. Here is an example document: \documentclass[a4paper]{amsart} ...
5
votes
1answer
298 views

(x)ifthen in TikZ

I am searching for a way to conditionally handle some items in a TikZ \foreach specially using an \ifthenelse condition. However, the compiler responds ! Undefined control sequence. <argument> ...
6
votes
2answers
131 views

How to optimize a conditional text translation?

I am working on a short story written in french, and containing a number of short dialogs in english. A friend suggested it might be a courtesy to potential readers to tranlslate the english content ...
6
votes
1answer
243 views

Plot complex self defined function with TikZ

I'm trying to plot a function with TikZ that behaves different for several cases. Therefore I use an \ifthenelse in the \def statement. Using such a definition a plot with TikZ does not work. However, ...
2
votes
1answer
88 views

Conditional assignment in a loop

Objective: I want to compile the temporary.tex file containing PSTricks code twice. One with -jobname=Rotated and the other one with -jobname=Unrotated. The resulting Rotated.ps will be passed to ...
7
votes
1answer
143 views

Macros with binary trees as arguments

I would like to have some macros which have binary trees as arguments. For the purpose of these macros, a binary tree is either root or it is {branch1}{branch2} for two binary trees branch1 and ...
21
votes
5answers
2k views

How I can automatically add a page if the total number of pages is odd?

I need automatically add a blank page (also without document header, numbering and footer) at the end of the document, if the total numbers of pages is odd. How I can do that? And preferably without ...
5
votes
1answer
57 views

Change Sectional Skip Conditioned on Text Existing or not Before Sectional Division

I have a simple document layout with a main heading for the title, and the possibility of starting the first sectional unit (with a standard \section command) right after the title -- meaning, with no ...
3
votes
1answer
197 views

TikZ calendar and conditional tests

I would like to specially mark national holidays in my calendar. Some of the rules are "First Monday in June" and "Last Monday in October". I have been looking at the example on p. 280 of the PGF ...
7
votes
2answers
119 views

Generating random conversions

I am working on a system to randomly generate some exercises on unit conversion. The students get a exercise like 27.89 mm = ...... hm I achieved this whit the use of a random value generator ...
7
votes
1answer
68 views

How to use \ref command in the test block of \ifnum?

Is there a way to use \ref{} inside the test part of \ifnum. The following example runs into an error. \documentclass{article} \begin{document} \begin{table} \caption{ex} \label{tab:ex} ...
22
votes
1answer
558 views

Use of \relax after \ifnum … \fi construction

I'm reading Malcolm Clark's A Plain TeX Primer. On page 111 there's an exercise to define a macro that prints the current time. I've reproduced Clark's answer below: \newcount\minleft ...
4
votes
1answer
81 views

Loop Multi-Contingency using etoolbox

I want to use the etoolbox package to manage some loop contingencies over a counting index. In particular, I'd like to do something different on the first and last times through the loop. Now I can ...
10
votes
3answers
164 views

How to align the conditions in a hierarchical structure?

I know how to align the conditions on the left side of the conditions with either aligned, cases, or array if there is only one level. However, I can't figure out how to do so in a hierarchical ...
3
votes
2answers
195 views

How to write multiple conditions in separate lines in braced equations?

How do I typeset something like, X = 0 if a=1 & b=1 & c= 5 & d=9 ; 0 otherwise, using those huge left braces and specifying each condition in a line (4 conditions in 4 separate lines)?
8
votes
1answer
129 views

Adding some text on a page break

How can one test if certain chunks of text (say, numbered questions in a questionnaire) is split between two pages and add automatically related text ("Continued question NN") on the top of the second ...
5
votes
2answers
90 views

A command which produces index if optional argument is not empty

I would like to define a command which creates an index with a certain name, when i pass the name, and doesn't create any index if there is no name passed. My first idea was to write it like that: ...
15
votes
5answers
2k views

Proper way to detect empty/blank text

I am attempting to ignore a command if it is passed with empty/blank text. My use case is not as complicated as one Expand away empty macros within ifthenelse where @egreg provides what seems like a ...
16
votes
4answers
316 views

Test whether passed parameter is a number (possibly floating point) or dimension

With TikZ using the calc library you can write things along the lines of \node (A) at ($(0,0)!0.75!(1,1)$) {}; or you can write something (rather different) \node (B) at ($(0,0)!2in!(1,1)$) {}; ...
2
votes
1answer
42 views

ifthen: Replacing a single character in a fixed environment with a longer string

We use a custom command to highlight system properties: \newcommand{\propDesc}[2]{ \fcolorbox{white}{propbg}{ \begin{minipage}[c]{\textwidth} \vspace{1ex} \textcolor{title}{#1} \\ #2 \vspace{1ex} ...
3
votes
1answer
138 views

Numbering in Beamer handout

Consider the following MWE. \documentclass[handout]{beamer} \newcounter{slidenumber} \defbeamertemplate*{footline}{infolines theme frame plus slide}{ \setcounter{slidenumber}{\insertpagenumber}% ...
20
votes
4answers
2k views

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} -> ...