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

4
votes
1answer
97 views

Testing for “emptiness” (theoretical consideration)

Consider the following theoretical problem: Sometimes, in LaTeX one wants to do the simple test if a macro is empty, e.g. \def\foo{% This is... \ifx\baz\@empty Sparta! \else a pony farm. \fi } ...
13
votes
1answer
434 views

Create Two PDF versions of Classroom slides from Single LaTeX file: Teacher and Student

Is there a way to create a single document that will process a LaTeX file in two different ways (different preambles) and produce two different outputs. Specifically, I want to produce a set of ...
37
votes
3answers
6k views

Difference between \if and \ifx

I try to understand the subtleties of TeX programming, but it is not always easy. For example, in the following code : \def\first{abc} \def\second{abc} \ifx\first\second OK!\else false \fi I ...
6
votes
1answer
99 views

Conditionals in lstlistings

I am trying to put in some lines of code using the lstlistings-package but the code differs on conditionals. How can I only change some lines depending on the conditional? Assume I have the If: ...
9
votes
1answer
493 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, ...
2
votes
2answers
125 views

How to make an 'if' on roman numbered pages and another 'if' on arabic numbered pages

I want to make some conditions on roman pages and another condition on arabic numbered page. (I want to know how to remove the background from specific pages in both numbering categories). ...
2
votes
0answers
204 views

Knitr/LaTeX: conditional execution based on external parameters

I'm using knitr to create LaTeX documents with integrated R code. Now I'd like to readout some external parameters (saved in a TXT or CSV file) and create a document based on the conditions specified ...
8
votes
2answers
271 views

Problem of having \begin…\end inside \ifdefined…\fi clause

I am using beamer, and have a LaTeX code as below. \ifdefined\VAR \begin{itemize} \item blahblab \end{itemize} \fi this does not compile, throwing an error: ! Incomplete \ifx; all text was ...
2
votes
1answer
73 views

Conditional based on packageoption

I added a counter to the todonotes packages \todo so I could display the total number of todos I have left. However I also enjoy working with the package option disabled. Therefore I would like to ...
5
votes
1answer
101 views

\IfFileExists is acting inconsistently when testing another boolean in conjunction with \input

I've been refactoring some code and clearing out obsolete commands. I don't understand what's happening here: \begin{filecontents}{mkif} \newif\ifaeRoughDraft \def\testforRoughDraft ...
13
votes
4answers
354 views

How do you test whether a known key value has been set in pgfkeys

Using the .code handler to my keys and a private macro, I can easily test whether a key has been set when using pgfkeys. For example: \documentclass{article} \newcounter{mytestenvcounter} ...
2
votes
0answers
108 views

Equivalent of CSS adjacent selector in LaTeX [closed]

In CSS you can use the adjacent selector to create conditional formatting. For example, p + p to format a paragraph that follows a paragraph, or h1 + p to format a paragraph that follows a h1 element. ...
4
votes
1answer
346 views

Replace lstlisting with verbatim depending on a boolean

I use latex2rtf to convert latex documents to .rtf and thence to MS-word (see this thread). To do this, I set up a custom class and limit which packages are used as latex2rtf only accepts a limited ...
10
votes
2answers
180 views

How to test if-condition using \csname within an \ifcase branch

I am trying to test an if-condition, where the name of the condition depends on a macro argument. To do this, I use \csname ifcondition#1 \endcsname. This works fine in a simple macro like this: ...
3
votes
2answers
554 views

Setting a flag to make text visible in LaTeX

I am in the process of CV writing and some pieces of information are necessary to include in some applications, whilst in others they are unnecessary. For example, when applying for ...
5
votes
1answer
156 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 ...
7
votes
2answers
205 views

newcommand conditionals

I am looking to create a command that adjusts my page layout, here is a sample: \newcommand{\margin}{ \pdfpageheight 297mm \pdfpagewidth 210mm \pagebreak \newgeometry{lmargin=31.5mm, rmargin=31.5mm, ...
8
votes
3answers
828 views

Detect aspect ratio in beamer

I'm doing my slides with beamer. At the moment I am not sure about the aspect ratio that will be used at the presentation. I know I can change the ratio with class options of beamer. The problem is ...
3
votes
0answers
36 views

Unexpect differences between calling \ifmmode from within a command and outside a command [duplicate]

In answering another question regarding testing for math mode, I proposed the following command \newcommand{\testa}{% \ifmmode ^{12}\text{CO(1-0)}% \else $^{12}$CO(1-0)% \fi } But ...
8
votes
2answers
202 views

Macro with environmental dependent output

I'm trying to develop a macro that gives two different outputs depending on whether it is in math mode (i.e. $ $ or \begin{equation} ... \end{equation}) or anywhere else. The reason is that I use a ...
9
votes
3answers
1k views

Using counters and \ifthen in a macro: what's wrong?

I have (made, actually) a graphic of the forepaw-print of a bear that I want to use as a flourish mark at the end of chapters and a few other places. After finishing with the image, I created a mirror ...
5
votes
1answer
125 views

Is PDF capable of conditional display and, if so, how can I achieve it with pdfTeX/friends?

Most of the time, we (or more conservatively, I) think of PDF as a static format fit for printing. I've been surprised in the past at how versatile it is -- how dynamic and interactive it can be -- ...
5
votes
2answers
201 views

Variable persist outside environment

I am using the ifthen package for some conditional formatting. I am storing state in some booleans, but it seems that there is an issue with lexical scope. In particular, when a boolean is set within ...
3
votes
2answers
152 views

Conditional to \begin and \end some environment

The conditional structure of the macro of the MWE allow print two text strings as "true" and "false" alternatively. So you can print something like "false true false true false true" calling six times ...
0
votes
0answers
33 views

Include subsections depending on variables/ifthen [duplicate]

I am making a template for several books. I have a mainfile which includes the .tex files for my chapters. For each book, some chapters are always almost the same except for a few subsections. How ...
13
votes
1answer
886 views

Column break only if within first column of multicol

Background Creating books automatically using LaTeX-escaped user-generated content. Problem The book layouts make use of the multi-column package, with the book content separated into sections. If ...
1
vote
2answers
174 views

How can I toggle the document between print and view mode?

Is there a possibility to set a key into my header which defines the desired output of my document? I can imagine three modes: Print (black and white) Print (colored) PDF for display view With ...
6
votes
2answers
186 views

Conditional linebreak in align environment

I have a large document to typeset in two different page formats. Some of the equation lines are too long in the small format so I wanted to break some equation lines conditioned on whether the macro ...
10
votes
2answers
221 views

How to create command that creates new if command?

I want to load parameters (for conditional compilation) from files. I wrote command param that creates new if command and read parameter from file, containing following line: \paramnametrue % or ...
6
votes
2answers
174 views

expl3 switch for booleans: Is there a \bool_case:Nnn?

There's \int_case:Nnn, \tl_case:Nnn, \str_case:Nnn, but I can't find something like \bool_case:Nnn. I know I can write: \bool_if:NT \l__<mymodule>_<nameA>_bool { ... } \bool_if:NT ...
16
votes
3answers
389 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: ...
1
vote
1answer
758 views

Setting \pagestyle{fancy} seems into create an error

Calling fancy page style is somehow apparently causing the following condition to test true. \documentclass{article} \usepackage{fancyhdr} \pagestyle{fancy} \ifcsname chapter\endcsname% ...
3
votes
2answers
98 views

Replace and add a/to a specific sequence of tokens

Is there a way to find a specific sequence of tokens and add after it a command? Or is there a way to find a specific sequence of tokens and replace it with another one? And do it only if the sequence ...
8
votes
1answer
371 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 ...
11
votes
1answer
269 views

Is color undefined

I want to check whether a color has been previously defined, consider the below code which doesn't execute. \documentclass{article} \usepackage{xcolor} ...
4
votes
2answers
236 views

Checking in LaTeX for a specific character?

I have a LaTeX problem that I cannot solve by myself. I have a repeating arrangement of characters which I want to format automatically in LaTeX. 1H-NMR (400 MHz; DMSO-d6): \textdelta 12.41 (s, ...
1
vote
2answers
88 views

Print macro content with condition

I would like something like the following: \documentclass{article} \newcommand{\acell}{} \newcommand{\bcell} \newccomand{\zcell}[1]{#1} \ifx\acell{A} \ifx\bcell{A} \zcell{yes} \else \zcell{no} ...
14
votes
3answers
398 views

Rotate image according to pagenumber

For writing my master thesis I have an image in landscape that needs to be oriented correctly when it is eventually printed in a book. If the page with the image is on the left side (even page ...
12
votes
2answers
188 views

What would be a suitable replacement for ifcsname in a non-etex situation?

From the pgfkeys.code.tex file: % This is useful: \def\pgfkeys@ifcsname#1\endcsname#2\else#3\fi{\expandafter\ifx\csname#1\endcsnam e\relax#3\else#2\fi}% \ifx\eTeXrevision\undefined% \else% ...
14
votes
2answers
926 views

Is a TeX macro defined?

I am looking for a way in TeX to check if a macro was defined. Currently I use a rather tangled way. I exploit a sort of side effect when comparing two macros via \ifx; this command returns: true, ...
4
votes
2answers
112 views

Test for a character, no matter if active or not (futurelet token)

I'd like to test for a character, irrespective its current catcode (i.e. active or not). This is very similar to How do I test for a character, irrespective of catcode?, however I cannot use ...
9
votes
2answers
139 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 ...
5
votes
1answer
185 views

LaTeX block conditional including

I am researching possibility of building an automatic brief datasheet template in LaTeX, taking data straight out of a database. The database connection part is possible and can be done with such ...
5
votes
1answer
289 views

conditional glossary style

I use glossaries to display a global symbol list but also local one for each equation. The first userkey is used to add the physical unit. But some smybols (like efficiencies or proportions) don't ...
7
votes
2answers
620 views

Expand command read from file

I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
9
votes
1answer
96 views

Test if a skip has an infinite stretch/shrink component

I want to implement an if-then-else depending on whether a skip contains a special character or not. So far, I tried the idea: convert the skip to a token list, and check if the letter f is in the ...
0
votes
0answers
56 views

How to test if an command is empty {}? [duplicate]

I used \newcommand* foo {} to define a command so the user could set it later via \renewcommand* foo {content}. How do I create a conditional statement (if then else) that tests if foo is empty ("{}") ...
6
votes
1answer
159 views

Test if a chapter has sections

Is there an easy way to test if a chapter has sections? The question is related to short tables of contents displayed at the beginning of each chapter and that would be empty when the current chapter ...
3
votes
1answer
504 views

How to write a \newenvironment with a conditional structure and one optional parameter

I would like to define a new environment with an optional parameter. Currently, I have \theoremstyle{plain} \newtheorem{prop}{Proposition} \newenvironment{propExt}[1][]{\ifx!#1! \begin{prop} \else ...
10
votes
1answer
86 views

Scan argument for parentheses

I'd like to define a macro which expands to (#1) if #1 does not contain any parentheses, but expands to \big(#1\big) if it does. I'd choose simplicity over generality: if a solution works in the most ...