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

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
458 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 (...) \...
20
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
961 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
234 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
854 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
221 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
324 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
268 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
788 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
922 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
853 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 ...
33
votes
4answers
33k 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
790 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
145 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
578 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} -> \...
16
votes
3answers
805 views

Check if LuaTeX is running

I want to check if my tex document is compiled with LuaTeX (or any other Lua TeX compiler). The simple approach from the TeXbook is to check the \directlua macro against \@empty, like \ifx\directlua\...
5
votes
2answers
468 views

a/an substitution in LaTeX

I was wondering if there is a conditional command that I can use in LaTeX (e.g., \ifthenelse) that would allow me to, in one case, use the word 'a' and in another use the word 'an' based on the ...
15
votes
1answer
388 views

Conditioning behaviour of a macro on whether on top of a new page

Is there a way to find out, whether the currently typeset material will go to top of a page? I am trying to write a macro which, when invoked, typesets a horizontal divider to separate the subsequent ...
17
votes
1answer
932 views

Conditional pagebreak?

Is there a way I can have LaTeX insert a pagebreak, if the last line of the page is a certain string? e.g. \noindent \textsl{Solution}: thanks very much!
33
votes
5answers
13k views

If Then Else for odd page/even page

How to use if-then-else structure in LaTeX? I need a example of odd and even page. if odd then command 1 else command 2
9
votes
3answers
2k views

How to use the exact same file for handout and presentation modes in beamer

I want to use the exact same file for my beamer presentation and handout. I do not like the need to comment out lines in order to create the handout or presentation (my current solution), nor do I ...
160
votes
4answers
77k 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 ...
26
votes
4answers
2k views

Redundancy in bib file: conditionally suppress url if same as doi?

Mathscinet gives bibtex entries with both a doi and a url field included. Typically they look something like @article {some-article, […] DOI = {10.1016/j.apal.2008.12.003}, URL = {http://dx....
7
votes
2answers
271 views

Nicer way to test that exactly one flag is set

I have a package that takes a long list of boolean flags (currently about 10) in its options, and I want to test if exactly one of these is set to true - something like an XOR for 10+ booleans. The ...
4
votes
1answer
534 views

Booleans fail in tabular environment

I've got a workaround for this problem, but maybe someone knows a cleaner way to fix it. I'm using the standard packages in TexLive 2009. Here's the code that doesn't work: \documentclass{article} \...
6
votes
3answers
673 views

etoolbox conditional causes unwanted empty row in tabular

This code leaves an empty row at the bottom: \documentclass{article} \usepackage{etoolbox} \def\somedef{foo} \begin{document} \begin{tabular}{|l|} \hline First row, not important \\ \hline \...
22
votes
4answers
772 views

Is there an \iftex4ht command, and if not, how should it be defined?

Background: I'm using TikZ to generate a load of pictures that I want to put on the web as SVGs. So I'm using the pgfsys-tex4ht.def driver and it's working very well. My gut feeling is that the SVG ...
17
votes
4answers
3k views

Making switch/case with etoolbox's \ifdefequal

I've got a define such as \def\doctype{SomeString}. \doctype can take on one of five values. I want to do something like a switch statement in a programming language, i.e. (pseudocode): switch (\...
36
votes
6answers
7k views

Is it possible to keep my translation together with original text?

I have an English article in LaTeX, which I'm going to translate to Russian. I want to keep my translation in sync with the original text. It means that I want every paragraph to stay as close to its ...
11
votes
2answers
270 views

What is “dimen” in the documentation for the ifthen package?

In the documentation for the ifthen package, there is a test called \lengthtest which compares two <dimen> parameters with the operators <, > or =. (For other test commands, <dimen> ...
21
votes
4answers
2k views

Detect beginning of a sentence in a macro for capitalization

Is it possible to make macros give different results at the beginning of a new sentence? Suppose that I want the macro "\secname" to write "Section" at the beginning of a new sentence, and "section" ...
12
votes
2answers
10k views

Tikz/Pgf if statements

I'm having trouble writing if statements, I can find next to no documentation on them and what I want to do seems quite simple. I'm using the orbitals pgf/tikz example from here, and I'd like to ...
4
votes
3answers
2k views

How to use \newcommand for \href?

I want to format Wikipedia entries in my document in a standard way: \href{http://en.wikipedia.org/wiki/Foo}{Foo} So I thought about using \newcommand*: \documentclass{article} \usepackage{ifthen} ...