{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
0answers
238 views

Conditional formatting, rounding and postprocessing of a column in pgfplotstable

I want to round p-values in a table to two decimals (for example 0.05), have values less than 0.05 in bold font and have values less than 0.01 to come out as '<0.01' in bold font. Like this (the ...
5
votes
2answers
156 views

Is it possible to exit from the PostScript expression and abort the drawing?

I just want to draw a dot if the condition is satisfied and otherwise cancel the drawing of the single dot. The following code is the simplified version of my real scenario. Please don't suggest other ...
14
votes
3answers
913 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
132 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
158 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 ...
5
votes
1answer
140 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
180 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 ...
7
votes
1answer
108 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
68 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
44 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 ...
1
vote
0answers
14 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
90 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
67 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
48 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 ...
7
votes
2answers
405 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, ...
3
votes
1answer
105 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
142 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
196 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
186 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
74 views

Conditional Variation of \headheight [duplicate]

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
88 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
199 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
247 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
85 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
68 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
89 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
171 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
2answers
448 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
141 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
346 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
98 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
154 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
141 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
349 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
133 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
77 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
110 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
193 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
306 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
140 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
97 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
44 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
353 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
185 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
729 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
809 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
209 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 ...
14
votes
3answers
453 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
111 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. ...