{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
3answers
655 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
181 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
994 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
119 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
159 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
130 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
681 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
153 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 ...
5
votes
2answers
167 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
211 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
156 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
350 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
591 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
86 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
323 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
223 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} ...
3
votes
2answers
179 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
85 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
346 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
168 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% ...
13
votes
2answers
714 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
107 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
131 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 ...
4
votes
1answer
174 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
257 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
514 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
93 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
53 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
153 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
387 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 ...
19
votes
1answer
267 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 ...
10
votes
1answer
84 views

How can I detect if an environment is right after a sectioning command?

I'd like to build an environment that would detect if it is right after a sectioning command (\section, \subsection or \subsubsection) and smart enough to detect if a float-type environment (say ...
4
votes
2answers
315 views

How to define a if-condition? [duplicate]

I found several entries about the fact that the ifthen package is obsolete. So my question is: how to define a condition check then? I have searched and I find several example for ifthenelse ...
12
votes
1answer
234 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 ...
4
votes
1answer
225 views

Changing Template Header for Appendices

I am using a modified BYU Thesis Template for my thesis. I want to be able to change the page header for the the appendices to read "Appendix A Data & Display" instead of "Chapter A Data & ...
6
votes
1answer
159 views

Testing lines read from external file

I am trying to read some data from an external file and perform specific actions based on the contents of a given line. Below is my attempt to test a read line using \ifx - it does not work. I've ...
10
votes
1answer
161 views

How to make a conditional reference to a text label

I would like to make a conditional reference to an optional label in my latex document, see the Minimum Working Example below. Hence, IF the label exists somewhere in the document, THEN a reference ...
2
votes
2answers
734 views

Memoir oneside/twoside question

I have a memoir-class document: \documentclass[oneside,letterpaper]{memoir} which I set to oneside or twoside depending on if I want to create either an electronic copy (one side) or printable copy ...
13
votes
2answers
211 views

Load a package as optional argument

I'm creating my personal package. I'd like to use an option to turn on/off the line numbering provided by the package lineno. So, my sty file contains \RequirePackage{lineno} \linenumbers But if ...
10
votes
1answer
123 views

Expandable, very specific keyval processing

I am having a hard time trying to come up with an fully expandable keyval parsing macro which deals only with specific keys/values. I wouldn't even attempt this in full generality, that's way beyond ...
13
votes
1answer
153 views

testing for a documentclass option

I know that there are lots of similar question, but none of those have helped me so far - and I did google a lot. So my question is: I have a document class (emulateapj) which accepts a few options. ...
17
votes
1answer
146 views

Compile PDF without proofs

I am writing my degree thesis, and I need to make a synthesis of it: basically what I want to do is make a copy without the proofs...is there a way to exclude them automatically, without having to ...
4
votes
1answer
299 views

Boolean switch for conditional statement after its definition?

I'd like to use conditional statements in my preamble file and then define the value of the Boolean variable afterwards. The reason is that I import the preamble.tex first thing in my main file where ...
7
votes
2answers
193 views

Negating \ifeof

Trying to typeset lines from a file: \openin0=MyFile \loop \read0to\linein \linein \ifeof0 % Fails here \repeat Clearly, I want to test for not \ifeof, but I don't see a boolean ...
3
votes
2answers
126 views

Test for empty possibly itemized argument in tabu

For some reason, I can't test if #2 is empty in the following tabu use case. An Incomplete \ifx; all text was ignored after line 14 is thrown executing the following code. ...
10
votes
4answers
764 views

\if(username == foo) … \else .. \fi?

I think the pseudo code in the title says it all: How can TeX (or LaTeX) find out the $USER who is running pdflatex? I'm collaborating want the output to look very slightly different when I run latex ...
2
votes
1answer
437 views

If two columns LaTeX

I am writing a paper in LaTeX. I will need both the one-column and two-column versions of the paper. For this, the figure sizes/configurations need to be different in the two documents. I am looking ...