{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)

3
votes
1answer
104 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
130 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
189 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 ...
1
vote
2answers
149 views

csvsimple filtering problem

The following code works as I would expect. \documentclass{scrartcl} \usepackage{csvsimple,filecontents} \begin{document} \begin{filecontents*}{chunk.csv} AAAA,aaaaa BBBB,bbbbb CCCC,ccccc ...
3
votes
0answers
67 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
87 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
189 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 ...
2
votes
1answer
211 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. ...
5
votes
1answer
81 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 ...
6
votes
1answer
65 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} ...
4
votes
1answer
86 views

Test if two things typeset identical results

I want to test if two somewhat arbitrary things typeset as exactly the same thing. For example I would like the test to tell me that abc is different from xyz, but is the same as \def\bar{abc}\bar. A ...
2
votes
0answers
156 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
390 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> ...
8
votes
1answer
134 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 ...
6
votes
1answer
303 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
93 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
147 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 ...
6
votes
2answers
134 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 ...
3
votes
1answer
269 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
129 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
71 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} ...
4
votes
1answer
100 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
172 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
269 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
137 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
93 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: ...
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} ...
16
votes
4answers
339 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)$) {}; ...
3
votes
1answer
164 views

Numbering in Beamer handout

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

Dynamically set if environment should be printed [duplicate]

Is it possible to tell LaTeX whether or not some environments should be printed in the output PDF file? I want to create one version of my document with "extended" examples and another with fewer ...
23
votes
1answer
670 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 ...
2
votes
1answer
639 views

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

Can I use AND, OR in \ifthenelse? How, can you show me examples and documents? This would make my life easier.
7
votes
1answer
185 views

Is a page modulo 4?

If I want to test whether a page is odd/even (i.e. modulo 2) then I can use the following: \ifthenelse{\isodd{\thepage}}{}{} What can I do if I want to test whether a page is modulo 4? A minimal ...
13
votes
3answers
394 views

How to compare numbers with decimal point and logical OR operation?

I'm reading five values from external CSV file as [\sone, \stwo, \sthree, \sfour, \sfive]. Sample values could be [55.3, 89.0, 33.5, 40, 0.10]. Question : How to compare number with decimal points. ...
8
votes
1answer
105 views

Compare the height of arguments

I'm trying to define a \newcommand with three arguments. I'd like to: compare the height of these arguments choose the largest height to create frames (with that height) around the arguments. ...
0
votes
2answers
543 views

How to number a conditional equation

I am writing the following syntax to get a conditional equation. But the equation is not numbered. How can I number it? \[ f(x) = \begin{cases} x+7 & \text{if $5< x$}; \\ x^2-3 & \text{if ...
6
votes
2answers
219 views

How to select conditional text?

I've three variable statements : Statement1 = You are Great Student. Statement2 = You are average Student. Statement3 = You Need improvement on list of topics mentioned below. In the report ...
6
votes
4answers
270 views

Is there a better way to check divisibility in LaTeX?

I want to draw a trimmed ruler, for example, from 2.3cm to 3.9cm where the distance between two consecutive marks is 1mm. I have difficulty to efficiently check whether or not the counter is a ...
9
votes
3answers
250 views

What is wrong with \ifnum#1=0.09\relax?

The following code does not compile with the following error message Missing = inserted for \ifnum \documentclass[pstricks,border=4pt]{standalone} \usepackage{multido} ...
2
votes
1answer
96 views

Conditional execution based on style existence (listings)

Is there a way in LaTeX (or e-TeX) to check if a style is defined using the listings package (inside a \lstnewenvironment definition)? I mean something like this: \lstdefinestyle{tmpdefaultstyle}{} ...
11
votes
1answer
597 views

If not DeclareOption

I have some documents using a same custom package. That "header" package loads by default the package fullpage. But I would like to write a new LaTeX document, using the same header, but without ...
2
votes
1answer
93 views

Conditional use of multicol

I'm using the multicol package to get two columns, but sometimes the contents is too wide in a particular column and I was wondering if there is a way to first make sure the contents will fit ...
11
votes
2answers
177 views

How to create a macro “environmentally-dependent”

Yesterday I was reading the etoolbox documentation where there are defined some new document commands such as: \Before<Begin/End>Environment{<envir>}{<code>} % ...
4
votes
1answer
90 views

PSTricks, conditional frame size

Consider the following code: \documentclass{article} \usepackage{pst-eucl} \usepackage{siunitx} % LaTeX 3 syntax \ExplSyntaxOn \cs_new_eq:NN \calc \fp_eval:n \ExplSyntaxOff % constants ...
1
vote
0answers
27 views

Name separators, if condition for same command [duplicate]

I am new to LaTeX, just a Beginner, Basically a perl developer, I have created a .tex file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
6
votes
2answers
109 views

Separators for author group (IF conditon)

I am new to LaTeX, just a beginner, basically a Perl developer. I have created a LaTeX file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
3
votes
1answer
106 views

header-footer configuring

Need to start page numbering from the n-th page (in this case 6); used ifthen and fancyhdr packages. So, no dotted lines since page 6 and page 5 is already numbered. \usepackage{ifthen} ...
5
votes
2answers
244 views

Putting Multiline Conditional Equations

I am trying to write two equation like, a=b when a>1 a=c when a=0 One obvious choice is putting all in a tabular construct, as, \begin{tabular}{ll} $a=b$ & \text{when $a\ge 1$}\\ ...
5
votes
1answer
113 views

Any way to set a variable externally?

I just posted a question and can now generate a conditional section in a text: how to make a conditional document feature But to extend and generalize the question, first how could I create a ...
4
votes
2answers
152 views

how to make a conditional document feature

I saw in another question about how to create a condition, of which the best practice recommended was \iftoggle. I want to create a macro that will allow the creation of a teacher's note, a section ...