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

11
votes
1answer
544 views

Using ifthenelse for crop marks with tikz

How do I use to insert ifthenelse crop marks in Tikz. I want ifthenelse{\printcrop=true}{\draw(0,0) -- ++(0,1);}{} That is, if yes, make a drawing, else but do nothing. And yet, where I can choose ...
11
votes
2answers
787 views

biblatex: Something like \ifentrytype

I’d like to change the bibmacro cite:short only for one entry type (@music). So is there a way to test for the entry type?
17
votes
2answers
7k views

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, ...
5
votes
1answer
373 views

Using \IfNoValueTF within a TikZ style specification.

In an answer to Flushing PGF commands and local variable Matthew had suggested using \IfNoValueTF within a TikZ \node specification to determine the text. This solution works great for me. However, ...
11
votes
1answer
1k views

Conditional using non-integer numbers

I am trying to generate fractals using affine transformations. I need to generate a random number in the interval (0,1), and depending on the value of this random number choose a function to ...
8
votes
1answer
576 views

How do I make make different versions of my document with command line compile flags?

I've found a number of answers online, and plainly none of them have seemed to be able to execute any conditional code. This answer looked particularly promising. One thing I noticed is that in the ...
3
votes
1answer
461 views

Count number of paragraphs in command argument

Is there a way to count the number of paragraphs in a command argument? I would like to make a command doing something like this: \newcounter{\numberofparagraphs} \newcommand{\testcmd}[1]{ \...
13
votes
2answers
531 views

How does one detect whether one is in the preamble or not?

In LaTeX, I'd like to know whether a documentclass has been loaded and whether code is inside a \begin{document}. In other words, is there a \ifpreamble similar to \ifvmode and friends? Partially ...
35
votes
1answer
6k views

Test if a package (or package option) is loaded

[french]{babel} (aka frenchb) is incompatible with some other packages, such as tikz, since it tries to insert \thinspace before semi-colons. In order to make these two play nice, you have to call \...
5
votes
1answer
508 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 <...
16
votes
3answers
3k views

Hide custom environment content based on boolean

I have a custom environment which adds some text around its content, but I also want it to be able to show or hide its contents depending on a boolean. I have tried doing the following: \newif\...
10
votes
1answer
3k views

Using ifthenelse in pgfmath

Following questions on constructing functions on the forum, I tried to build some myself. I can't seem to get the ifthenelse function in TikZ/PGF to work. Here is an example: \documentclass[]{minimal}...
6
votes
2answers
1k views

Nest StrLen and ifthenelse commands

Here is a sample of code I am working on: \documentclass[10pt]{report} \usepackage{xstring} \usepackage{ifthen} \begin{document} \StrLen{123456}\\ %Prints 6 ...
18
votes
2answers
1k views

Conditional “if a package is available”

I'd like to do something like the following (in pseudo-TeX) \ifpackageavailable{packagefoo} \usefoo \else \usefooreplacement \fi For example, I know that a template file I wrote is used by people ...
10
votes
5answers
3k views

How to test if a number is negative

Is there an easy way to test if a number is negative? I don't need a general solution, but it does need to be able to handle a floating point value. I was using this solution from tex.ac.uk until I ...
34
votes
2answers
4k views

Opposite of \ensuremath: ensure that I'm *not* in math mode?

I'd like a macro that is the opposite of \ensuremath: something like \ensurenotmath, which makes sure that its argument is not typeset in math mode. Is there such a macro, or a way to implement it? ...
4
votes
1answer
422 views

TikZ. Is there a way to alternate path to be drawn basing on some condition?

What I want is to connect nodes by stepped (horizontal-vertical-horizontal, hvh) path if they have different y-coordinate, and by straight line if they are on the same level. Costruction of the only ...
4
votes
0answers
155 views

Condition to determine if current line ends or starts the page [duplicate]

Possible Duplicate: Conditioning behaviour of a macro on whether on top of a new page I have two paragraphs with some separator (rule) between them. I want to make this separator appear only ...
16
votes
2answers
2k views

Environments with conditionals in: why doesn't this work?

In response to this question I thought the obvious thing to do was the following: \documentclass{article} \newif\iffoo \newenvironment{foobar}{\iffoo}{\fi} \begin{document} \begin{foobar} Here is ...
6
votes
2answers
463 views

In the verbatim environment, how can I display an 'if' statement I declared as '\ifcondition'?

I have declared a couple of if commands of the form \newif\iffinal \newif\ifsolutions Now I want to write about it in the same document! So I want to write something like \iffinal (...) \...
21
votes
2answers
3k views

How can I test for the current font?

The situation is the following, I have one font a with one feature and another font b with another feature and I am writing a command that if the current font is a need to switch to font b but if the ...
6
votes
2answers
277 views

Telling LaTeX where to compile to from inside your document?

Here is a hypothetical scenario. I want to make a beamer presentation and a handout for that presentation. I start my file as follows: \newif\ifhandout \handouttrue \ifhandout \PassOptionsToClass{...
73
votes
3answers
25k views

Why is the ifthen package obsolete?

In the LaTeX companion, the authors recommend to use the package ifthen for complex conditional. But in his answer to LaTeX conditional expression Will Robertson doesn't mention it, and in the ...
27
votes
4answers
2k views

Test success of write18

For the new version of my package and class standalone I like to call external programs: further (pdf)latex runs to optionally compile included standalone files, and to convert the resulting PDF to ...
6
votes
1answer
201 views

What does \global\boolfalse{cbx@loccit} mean?

Pardon the newbie question. I see this in the first part of a \DeclareCiteCommand and I'm not sure what it means. Google has not returned any joy. Here's an example \newbibmacro*{cite}{% \...
18
votes
2answers
965 views

Check if an entry is cited multiple times

I am trying to find out whether it is currently possible to have a test in Biblatex that tests at the very first time an entry is cited whether the same entry will be cited more than once in the ...
6
votes
1answer
235 views

Asserting reference inequality

Is there a way for including assertions in a LaTeX document? I want to check that some condition is true, and only allow compilation of the document if it is (or at least complain otherwise). ...
7
votes
1answer
858 views

Conditional compilation of beamer slides

I'm preparing a beamer slideshow, and I will have to print slides. I would rather use landscape mode slides, but it is possible that I need to use portrait mode ones. Sadly, I won't know until a few ...
3
votes
1answer
222 views

Driver-dependent invocations of the graphix package?

The LaTeX General Guidelines show a conditional invocation of the graphicx package. I wanted to test this out. I did the following: Created a main.tex in which I LEFT OUT the big, complicated, ...
25
votes
1answer
1k views

What is an \if?

I'm reading TeX by Topic, but in little chunks (rather than from first page to last) and just read the stuff on conditionals. I want to be sure that I understand what's going on when TeX starts ...
6
votes
3answers
2k views

Conditionally displaying/hiding parts of document using macros

I'm currently using the following approach to conditionally display/hide parts of my document: % PREAMBLE \def\MyVersion{1} % BODY \ifnum\MyVersion=1 This is version one. % possibly other ...
7
votes
1answer
326 views

Different content if command returns empty text (ConTeXt)

I have the following code in my ConTeXt environment: \startsetups[sectioninfo] \ss \rlap{\userpagenumber} \hfill § \getmarking[sectionnumber][current] \emspace \bf \getmarking[section][...
27
votes
4answers
1k views

Alternate he / she in text

This question led to a new package: he-she I have seen a book that instead of using the masculine pronoun (he, his, etc.) alternates the gender ('he' then 'she' then next time 'he' again). Is ...
6
votes
3answers
315 views

Zero parameters in command definition

Let us say I want to define a command for typesetting (a+b)^2: \newcommand{\sumsquare}[2]{\ensuremath{(#1+#2)^2}} How can I modify it so that \sumsquare{a}{0} will produce a^2?
1
vote
2answers
270 views

How to multiply compile according to selected tags?

I would like to do the following, by I am not sure how. Say I have a LaTeX file with series of annotations, each with zero or more "tags" (say, about their contents or the project they are related to)...
7
votes
2answers
2k views

LaTeX: Use command argument in conditional?

I'm in the process of writing a command that outputs a certain text only if its argument is a nonzero number. I'd like to be able to write something like: \newcommand{mycommand}[1]{ \if{#1 != 0} Some ...
12
votes
3answers
790 views

Is there a way to detect from inside a package that MiKTeX is used?

Is there a way to detect that the MiKTeX TeX LaTeX executable is used? Something like \ifmiktex or even \IfFileExists{<some file only present in MiKTeX>}{}{}? The reason is that in one of my ...
6
votes
4answers
923 views

Declaring document-wide font size outside of the document class command

I have a document, where I want two versions: one versions 10pt size and another version, 2 page to a side 12pt. So I currently have: \documentclass[10pt,a4paper,oneside,openany,article]{memoir} \...
5
votes
2answers
860 views

Compare a character to a character code?

How can one compare a character (e.g. "U") with a character code in a certain font (e.g. "\char85"). I'd expect the following to work: \documentclass{article} \usepackage{ifthen} \begin{document} \...
2
votes
1answer
286 views

Are there any packages that I should not be using with ifthen package

I am new to TeX and I started adding package files to prepare my document without worrying about conflicts. I am asking this subjective question because I am not sure if I can post entire document ...
34
votes
4answers
34k views

Large braces for specifying values of variables by condition

How do I typeset something like, X = 0 if a=1, 1 otherwise, using those huge left braces and specifying each condition in a line?
8
votes
2answers
2k views

\if@ statement explanation

I'm trying to tweak some .cls to fit my needs, and I'd really appreciate it if someone could explain me these statements: \if@radseminar% ... \else ... \fi If I understand correctly, it will match @...
16
votes
3answers
797 views

Redefine command when inside a specific other command possible?

How, in general, can I (re)define commands based on in which other command they are nested? A more specific example: I have a custom latex command (say, \code{}) that makes text appear bold. However,...
2
votes
2answers
146 views

Conditionals within captions

I have defined a conditional using the ifthen package as: \newcommand{\Switch}[1] { \ifthenelse{\equal{#1}{1}}{Test1}{Test2} } Running this command works without problem. However, if I try to place ...
4
votes
2answers
438 views

How do I set a variable inside of \rlap

Two questions please about this code example: 1) Why does \rlap prevent me from setting a variable? 2) How do I set a variable from within an \rlap that is visible outside of \rlap? I'm using MikTex ...
17
votes
2answers
2k views

How to programmatically make tabular rows using `\whiledo` ?

The following code snippet does not work: \documentclass{minimal} \usepackage{longtable} \usepackage{ifthen} \newcounter{xyz} \setcounter{xyz}{0} \begin{document} \begin{longtable}{|*2{c|}} \hline \...
2
votes
1answer
581 views

how to use memoir \ifoddpage

Why does \ifoddpage seem to always return false in the following example? This is related to question 6143 on this same forum. I'm using XeLaTeX to produce a pdf file (i.e., xelatex test.tex) \...
29
votes
5answers
3k 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} -> \...