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

8
votes
1answer
81 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
177 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
160 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
71 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
58 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
81 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
120 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
290 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
125 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
236 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
87 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 ...
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 ...
3
votes
1answer
195 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
117 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} ...
4
votes
1answer
80 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
162 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
187 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: ...
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
313 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
134 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 ...
22
votes
1answer
547 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
423 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
165 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
310 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
91 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
402 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
184 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
233 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
232 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
92 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
414 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
79 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
169 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
78 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
26 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
96 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
95 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
234 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
100 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
133 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 ...
3
votes
1answer
81 views

`\ifhtlatex` needed for running tex4ht with different code [duplicate]

It is much easier to write my texts in an editor with LaTeX, but often clients ask for a word file. tex4ht does a good job, it produces html from a tex-file, which can be easily used. But there are ...
1
vote
1answer
197 views

Tabu/Longtabu: Conditional Column Definition

I want to create a longtabu table with a conditional number of columns: In development mode, 5 columns should be visiable. In the final version, only the first and the last column should be visible. ...
13
votes
5answers
484 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. ...
6
votes
2answers
122 views

Branching construct based on the (babel) language selected

I'd like to keep one of my presentations in German and English and have defined a corresponding boolean variable withifthen and a command to typeset either the German or the English text. Is there ...
4
votes
1answer
167 views

conditional content

I'm writing a document in LaTeX that I want to compile in two different versions, V1 and V2 (with two different formatting specifications). Sometimes I need to insert a bit of content into V1 that ...