{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
416 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 ...
7
votes
1answer
1k views

How to tell if the current section is defined in Beamer?

I am customising the footer of my Beamer slides. The footer displays the title of the slides, followed by a ":", and then the current section title. This works fine if the current section is defined. ...
6
votes
2answers
113 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. ...
6
votes
2answers
151 views

Is “conditionals” name of package?

In some package I have seen construct like this one: \if\blank{\myMacro}% %do something \else %do something else \fi I like it and I want to use it to test if call to a macro has empty result. ...
5
votes
1answer
147 views

How to create two PDFoutput from the same source

I have a very long source file. I would like to prepare from this source two PDF files: PDF contains all of the source file PDF containing only a few, marked earlier parts of the source file. How ...
5
votes
1answer
292 views

Suppressing remarks when not needed

I have written some remarks in some of my works that are somewhat informal and repetitive in nature (mainly for my own clarification). I was wondering if there is a way of suppressing them when I ...
4
votes
2answers
109 views

How to test if a given reference belongs to a list of labels?

This question is a prolongation of my previous question How to choose from a list for using result in \ref?. I got really good and interesting answers. Unfortunately I can not implement them for my ...
3
votes
1answer
63 views

How to use conditional (if statements) with data from acronyms?

I am using acronym for autocomplete my text like mailing functions. So I want the long text from acronym using all the time, and I am using \acro{}{} to define, so \acro{Maria}{f} - for me shows that ...
1
vote
2answers
246 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 ...
27
votes
4answers
6k views

How to conditionally define a new command in LaTeX?

I'm trying to compile a LaTeX code with an older version of some package. Thus, I'm having a few issues due to undefined commands. How can I add conditional code so that I can define some work-around ...
26
votes
3answers
7k views

When to use @ in an \if statement

I am new to LaTeX and so this question might come across as rather basic. It might also reflect my biases/assumptions from my C/C++ programming days. I was seeing the code of the 'exam' class and ...
19
votes
7answers
729 views

How to define a command to feed the contents of a list into an \ifcase construct?

It's common to use an \ifcase construct to redefine a command depending on the value of a counter. The following example illustrates this: \documentclass{article} \usepackage{xcolor} ...
23
votes
1answer
2k views

Check if next char is {

Using \@ifnextchar one can detect if e.g. the next Character is a [, e.g.: \@ifnextchar[% { %% code to execute if [ scanned. }{ %% code to execute if [ scanned. } However, I can’t seem to ...
19
votes
1answer
264 views

Is something the first item on a page?

How can i identify logically, whether something is the first item on a page, i.e. there is nothing above it (apart from header)? Consider the following, is is basically a feature environment, which ...
22
votes
5answers
358 views

Test if a given control sequence is a length register

I'm in need of a macro which receives a control sequence as argument and needs to branch if this macro is actually a length (of any kind, e.g. dimen, skip etc.) or "just" a normal macro (including one ...
21
votes
4answers
3k views

How can I check in LaTeX (or plain TeX) whether a command exists, by name?

I'm looking for a LaTeX way to control macro expansion, contingent on some macro being defined or not. I'm looking for something like this (but then actually working): \newcommand[1]{\checkfor}{ ...
17
votes
1answer
711 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!
15
votes
4answers
1k views

Running new command only if it exists

How do I get LaTeX to run a command only if it exists? I need something like: \documentclass[a4paper]{article} \usepackage[utf8]{inputenc} % \newcommand{\mytitle}{Title Test} \begin{document} \if ...
16
votes
5answers
470 views

Applying an operation only to capitals

I'd like to apply a function to capitals only so that: \emphcaps{YaWeH} Outputs like: \emph{Y}a\emph{W}e\emph{H} Preferably without using too many packages (I already use memoir). NOTES: I use ...
9
votes
1answer
423 views

Conditional format for correlation table

I'm using the script by Christian Feuersänger: \documentclass{standalone} \usepackage{colortbl} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotstableset{ /color cells/min/.initial=0, ...
25
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 ...
17
votes
6answers
1k views

Placing many conditionals in a series

I frequently need to do something like this: IF x < 1, DO a ELSE IF x < 2, DO b ELSE IF x < 3, DO c ELSE, DO d Using etoolbox, I end up nesting a lot of ifnumless, like this: ...
16
votes
3answers
343 views

newcommand does not work with \fi

I tried the command \newcommand{\fistudenti}{\fi} but it seems to work properly only in some cases. Here below there are two insances when it works and when it does not: WORKS: ...
15
votes
1answer
200 views

First occurrence of a command

I'm writing some macros that need to behave differently after first occurrence. I decided to use the etoolbox package's toggle. My MWE is as follows: \documentclass{article} \usepackage{etoolbox} ...
15
votes
2answers
227 views

Is there a way to determine if there is a float on a page?

I am busy developing some code to draw layouts. Part of the code overlays the layout as shown in the images below: The black arrows to the side of the images, denote the \topfraction and ...
15
votes
2answers
756 views

Custom quotation style which depends on length of quotation

I am writing my PhD-thesis and I need to meet certain formatting requirements in regard to quotations. I know there is the quote environment. But in this conditions it doesn't match my universities ...
11
votes
2answers
4k views

TikZ: conditional nodes inside \foreach

I want to use a \foreach construct to generate several pairs of nodes, except for one of them I want to do something different. This is what I tried: \begin{tikzpicture}[dot/.style={fill,circle,inner ...
11
votes
3answers
4k views

How to make LaTeX ignore the contents of an environment?

I would like to make a \todo command and environment whose behavior changes depending whether I define a command \showtodos. A basic \todo command is simple to write: ...
17
votes
2answers
369 views

Why does this simple \ifx test fail?

This should be easy, but I don't understand why the test below fails... I expected Hurrah! to be printed when the \currentchar count reaches 90 (i.e. the character code of Z). There must be some ...
15
votes
3answers
626 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. ...
14
votes
3answers
442 views

Making a “For Loop”

I am trying to make a "for loop" that will iterate the variable reaches 1. However, none of the "for loops" I have found in the Internet works. These files will be distributed to other people and ...
12
votes
1answer
225 views

Simple way to switch inline asymptote figures on and off

I use the inline asymptote environment \begin{asy} to draw a lot of the figures in my papers. To those not familiar with asymptote, the asymptote package creates *.asy files for each of the asy ...
12
votes
1answer
3k views

\ifnum and pgfmath: error

In the following example I want to use \ifnum to compare two numbers computed by pgfmath, for simplicity I use simply 1 and 2 in the example below. Compiling this code gives me the error: ERROR: ...
10
votes
1answer
428 views

Require a certain (or later) version of a package?

Is there a way to enforce that a certain version, or a later version, of a package is loaded when building the document? I've found that compiling a document on another platform, where the package ...
9
votes
2answers
130 views

Provide boolean from two arguments case insensitives

In most publications scientific names are abbreviated except the first time. Moreover, the names must be in italics and only the first letter of the generic name should be upper-case. The biocon ...
8
votes
1answer
313 views

Biblatex: Convert doi-url into doi field

I use biblatex and would like my bibliography to only include a DOI field, whenever there is DOI information available. This involves two things: Biblatex has to suppress the URL field whenever a ...
8
votes
1answer
1k views

How to use mod operation in latex with tikz

I need something similar to \ifnum \j mod 2 = 0 rest of a number, but do not know how to do this in line 22. \documentclass{article} \usepackage{tikz} \usepackage[active,tightpage]{preview} ...
6
votes
1answer
521 views

pgfplotstable: Conditional post-processing of cell content on a per-column basis

I am trying to add an asterisk to the content of certain cells depending on the cell's content (essentially, adding a marker for significant p-values) but I am having trouble trying to do so on a ...
5
votes
2answers
245 views

Checking if a macro expands to one of two given strings

I want to test if the expansion of a given macro, say \mystring, is equal to one of two given strings, say string1, string2. I guess it's possible to do this with etoolbox, with something like: ...
16
votes
4answers
689 views

Is this branching code I wrote a bit obfuscated?

I've been away for a while and I forget if this sort of question is appropriate, but here goes. Recently I wrote some code (in expl3 but I hope it's clear enough) and in hindsight I wonder on its ...
14
votes
5answers
277 views

A macro that conditionally disregards the need for one of its arguments

Let's suppose I want to write nested equations that contain a fair few nested parenthetical/delimiter characters, like (), [], {}, ||, and perhaps others. Suppose too that I think these things look ...
14
votes
3answers
480 views

How to make time-dependent code?

I would like to create a command \ifafter{year}{month}{day}{yes}{no} so that if the current date is after year/month/day, the command would produce yes, and otherwise produce no. I came up with a ...
12
votes
2answers
194 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 ...
12
votes
2answers
273 views

Can I detect whether LaTeX is in vertical mode?

I am writing a command that creates a margin paragraph. This requires that this command is only used in vertical mode, which is fine. If the command is used in a float, LaTeX gives a "not in outer par ...
10
votes
3answers
186 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 ...
10
votes
1answer
272 views

What documentation thoroughly explains how to use TeX conditionals?

I have a document which needs a large variety of plain TeX conditionals, e.g.: IF #1 >= 1 AND #2 >= 10 IF #1 != “tree” OR #2 == “mountain” IF 10 > #1 > 2 I have found limited ...
9
votes
1answer
1k views

Bibliographies when using subfiles

I am writing my Ph.D. thesis in XeLaTeX with Biblatex, and there are times when I need to compile individual chapters, and times when I need to compile the entire document, so I use subfiles, which ...
9
votes
1answer
292 views

Macros for hiding empty sections do not work properly

In an attempt to make it possible to outline much of my document by adding new parts to it, but without making parts that I have not written anything on show up in the compiled document, I have ...
8
votes
1answer
510 views

How do I configure fonts and package options for different engines?

I would like to be able to rely on the code in my document class to respond correctly to whether it is being rendered using pdfLaTeX or XeTeX engines. The editor I'm using (LyX) does this using ...
8
votes
1answer
538 views

Help wanted on \openout, \write and \closeout

Is there a way to test if a token is already associated with a writer? Something like this: \def\do@write#1{% \immediate\write\mywriter{something: #1}% } \def\@writesomething#1{% ...