{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
4answers
7k views

Are there any “if” commands like “\ifnum” in LaTeX?

Are there any commands containing "if", similar to \ifnum, preferably in LaTeX (rathar than TeX)? For example, is there anything like \ifstring? (I am not after \ifstring only, I want to know which ...
23
votes
5answers
9k views

new command with cases / conditionals / 'if… then's

Suppose I want to define a command, say, \tree with, say, two arguments. I would like \tree to do different things depending on what my first argument is. For example, if #1 = a, then return ...
11
votes
3answers
219 views

Biblatex: Selecting content depending on language

I am using biblatex and would like to quote English and German works. When writing a document in German, this works nicely with the help of \DeclareLanguageMapping and hyphenation to specify if a ...
2
votes
1answer
100 views

Show the \subtitle if not empty

How do I show the subtitle if it's defined? When have a subtitle the code is like this: \begin{center} \MakeTextUppercase{\textbf{\thetitle:}}\\ \MakeTextUppercase{\thesubtitle} \{center} And ...
4
votes
1answer
51 views

Basic comparison of macro to string in lualatex?

Still hammering away at a database problem. Mostly done, but stumped by: \documentclass{article} \begin{document} \newcommand{\testmacro}{U01} The macro testmacro equals ``U01'' \directlua{ if ...
8
votes
2answers
184 views

\if-statement to know whether a new chapter has been created

I am trying to create a conditional function to determine whether a new chapter has been created (for a different purpose than that of the MWE). So far I have been unsuccessful, despite having tryed ...
32
votes
4answers
30k 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?
1
vote
1answer
32 views

Detecting empty key values when key is provided

I believe I am looking for a LaTeX3 type syntax solution to more appropriately detect a missing argument. To me I would have expected key={} to be a valueless, blank, or empty argument key. After ...
48
votes
2answers
10k views

What does \ifx\\#1\\ stand for?

The following usage of \ifx can be found in several packages and also in answers on this site. What does this syntax exactly mean? Are there any alternatives and drawbacks? ...
0
votes
0answers
40 views

csvreader: conditional formating of negative numbers

I have a csv file that contains both strings and numbers, and am using csvsimple to print it in my pdf. For those numbers that are negative, I'd like to print them in red For the positives one, I'd ...
15
votes
2answers
2k 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 ...
7
votes
1answer
91 views

Check what kind of document class is used

I have defined a .sty-file which I use in a report, which holds a lot of good information and styles for how my documents should look like. This have been working great, until when I tried making a ...
2
votes
1answer
59 views

Change header if title is first on page

(Not a dupe of Is something the first item on a page? and another similar question, because these involve preventing rules at the top of a page by putting them in leaders; but leaders require boxes, ...
2
votes
1answer
42 views

lstlisting breaks ifbool block

I have the following piece of code: \documentclass{article} \usepackage{etoolbox} \usepackage{listings} \newbool{xyz} %\booltrue{xyz} \boolfalse{xyz} \begin{document} \ifbool{xyz}{ ...
6
votes
1answer
43 views

Is it possible to implement a package dependency which is version specific?

This question should really ask what is the best way to implement a version-specific package dependency. However, if I try to ask that, the system threatens to close my question. In this answer, ...
5
votes
3answers
220 views

Generate multiple PDFs for different document versions in a single build

I am writing a document for a software which has two versions. Most of the content in the document is the same except few specific details. Right now, I am using the conditionals to build the document ...
5
votes
2answers
100 views

Does the LaTeX kernel define font-shape macros that expand to `it', `sc', etc.?

I need to perform a test on the current font shape. More specifically, I need to detect whether the current font shape is italic or slanted. Joseph Wright already provided a solution in his answer to ...
3
votes
1answer
37 views

Changing symbol size when used as subscript

This is a follow-up to this question. I'd like to define \fa to display \forall when typed as usual but be \mathsmaller{\forall} when \fa is used as a subscript. For example, I want to write ...
2
votes
1answer
48 views

Define symbols differently in text mode versus math mode

I'd like to define \a to be the $\forall$ symbol, but I'd like it be the regular $\forall$ in text-mode and \mathsmaller{\forall} in math mode. Is there any easy way to do this? I'm guessing it ...
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 ...
2
votes
1answer
40 views

How can I make condition inside the geometry options?

I would like to make condition inside the geometry options \geometry { headsep = \baselineskip , textwidth = 42\baselineskip , textheight = 60\baselineskip , hmarginratio = 2:3 , ...
13
votes
3answers
868 views

biblatex: is there a command analogous to \ifciteseen but within one page?

Biblatex is loaded as \usepackage[style=numeric-comp,hyperref=true]{biblatex} \ExecuteBibliographyOptions{citetracker=true,sorting=none,firstinits=true} I am looking for an if-command, which would ...
2
votes
1answer
58 views

Optional text printed in another colour

I would like to extend the version package to print some optionally added text in a different colour. Something like in the following example: \documentclass{article} \usepackage{version} ...
2
votes
1answer
89 views

When using \IfEq to compare strings, is it one of those times when I should use an expandable xparse command?

I recently asked How can I migrate commands and environments from LaTeX2e to LaTeX3? [XeTeX] While that question is good, the answer is likely quite complex and would take a some time to effectively ...
3
votes
3answers
133 views

Changing page to pages if more than one page

At the beginning of my document, I need to list the total number of pages in the document. I've got a system that works most of the time (see below), but if the document only has one page, then my ...
3
votes
1answer
94 views

Modify nodes near coords with \if

I would like to code something like this: if \thecitation is {This work} then nodes near coords={\thenumber{} [This work]} and plot color is Red else nodes near coords={\thenumber{} ...
0
votes
1answer
79 views

Compilation of main document, if subdocuments are compiled

I have a main latex document, and many other files included with \input{...}, e.g. by chapter. Often, I just work on a subfile and my idea is now, that I want to compile the main document if I start ...
2
votes
2answers
25 views

Manipulating arguments to a macro inside an argument

In LaTeX, I have a macro \p (okay, it's \paragraph, but perhaps the specific macro is not relevant?) with one argument. Sometimes I use it as \p{plain text} and sometimes as \p{\t{alternate ...
2
votes
1answer
27 views

pst-barcode Argument of \pst@@object has an extra }

I have the ISBN stored in two commands (depending of a class option) \theisbne \theisbnp The boolean options of the class are defined using xifthen \RequirePackage{xifthen} ...
1
vote
1answer
49 views

XParse doesn't recognize some of my variables

Based on the comments from my last question have I tried to create a new command using \NewDocumentCommand. However, it wont recognize some of the optional arguments - they just get printed as is. Any ...
0
votes
3answers
87 views

If condition without any package?

I create a table by rows like this: \row{1}{Sunday,Su,05.09.2015}{N}{08:00,17:00,12:00,13:00}{8.0,1}{Airplane Hangar} How can I prove, if the first parameter is 0 or 1, an if it's 1 then set a ...
0
votes
0answers
28 views

how to define a general conditional for a complete text

I wonder how to define a newcommand of the type with general conditionnal \def\a{} which givefor each call in the text %\begin{comment} %\end{comment} when a=0 and \begin{comment} ...
3
votes
1answer
35 views

Adding code (pagebreak) after value change in csvsimple

Background I want to create a document with the user data of our network at school, which should be handed out to the user. This should be done class by class. Approach The user data are given in a ...
7
votes
1answer
114 views

Has LaTeX3 syntax possibly changed since this question was last answered

I am adapting the LaTeX3 answer in this question: http://tex.stackexchange.com/a/61603 But I can't get the original MWE answer to compile using xelatex. I have renamed the variables, but the error ...
3
votes
2answers
157 views

Ifthenelse conditionals in moderncv's cventry

Now that Frodo has left to fight Sauron, Bilbo is all alone at home and searching for new things to do. So it came to his mind that he could apply for a job. For his application, he uses the moderncv ...
2
votes
0answers
50 views

Access xparse's \BooleanTrue via latex3 expl3

I'm implementing a command with xparse's boolean token processing \NewDocumentCommand{\op}{s o t' t. t^ g}{ % Here I need to check for % (#3 || #4 || #5) && !(#3 && #4 ...
1
vote
1answer
47 views

Conditional list of tables in LaTex [duplicate]

List of Tables can be obtained by using listoftables commands. I wonder how to skip listoftables output if the document doesn't contain any table. Thanks \documentclass[11pt]{article} ...
16
votes
2answers
2k views

Best practice for getting “If not foo” conditionals

So, here are two ways you might set things up such that \dostuff is done when foo is false. The "new conditional" method If you know when foo is going to be set, then after that do: \newif\ifnotfoo ...
156
votes
4answers
75k 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 ...
2
votes
2answers
141 views

Set comment toggle to false, error: Undefined control sequence

I want to toggle comments of and on. Off works, but when I set toggle to true, then I get an error: ./main.tex:36: Undefined control sequence. \endtcolorbox ->\unskip \tcb@after@box ...
1
vote
0answers
46 views

Set comment toggle to false, error: There's no line here to end [closed]

I want to show/hide comments when toggeling the code below: \newtoggle{comments} %\toggletrue{comments} \settoggle{comments}{true} %set true to show all comments, set false to hide all comments ...
1
vote
1answer
71 views

Display or hide stuff in a document

I am using comments in LaTeX, which are defined in my document as: \newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}{}}\linebreak} I would like to add something like ...
13
votes
2answers
176 views

The following code compiles without error. How can I change that?

Unlike most questions on this site, my problem is that my code compiles without error and I do not want it to. I want to be able the check whether \command is defined and to do something if it is ...
4
votes
1answer
83 views

\newif inside function definition in LuaTeX

In a function I have in a package I'm working on I'm trying to add the following line: \expandafter\newif\csname ifgre@scale@#1\endcsname% Now, this works fine under LuaLaTeX, but the package is ...
0
votes
0answers
46 views

Programming in Latex: Conditionals [duplicate]

I'm trying to learn how to programming in Latex. I want to make an if-else-statement. What I will do is something like this: \def\x{2} { \if x =2 Yes \else no \fi } But it doesn't work exactly how ...
1
vote
0answers
37 views

Passing optional arguments to a listing environment based on conditionals

I am trying to make a presentation which can optionally compiled for handouts. This presentation also contains highlighted code snippets. For highlighting I use the code from this question. (Which ...
1
vote
1answer
148 views

Creating a grid with different color vertices (graph)

I am new to using tikz and I have never used ifthenelse statements in latex before, but I am trying to create a grid where the vertices on every other diagonal are a different color and shape. This is ...
7
votes
4answers
216 views

How to check if a macro expands to one of several strings?

I have the following problem: I am using the etoolbox package to check if a macro (say, \foo) expands to one of several possible strings (say, bar, baz, abc, or other). I need to execute different ...
3
votes
1answer
67 views

Automate importing pages from PDF file and add text to some of these

I'm trying to use LaTeX for lecture notes, but am having trouble implementing it the way I want to. For each lecture I will have access to a PDF file with presentation slides, where one slide ...
4
votes
2answers
149 views

“Runaway argument?” just in the \input file

Update: Upon @egreg suggestion, the case shown below is the core of the problem and has nothing to do with include/input statements. I have a verbatim within toggle statements, which fails. A minimal ...