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

0
votes
0answers
14 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 ...
7
votes
4answers
152 views

Detect if a macro argument is only one symbol

I define a bunch of functions (or operators, if you like) using a little helper \parens, which adds parens on demand: \newcommand{\parens}[1]{ \ifthenelse{\equal{#1}{}}{}{(#1)} } ...
4
votes
1answer
15 views

How to use `\@ifdefinable{xfoo}{…}` when `\foo` is already defined?

The following code fails to compile: \documentclass{article} \makeatletter \newcommand{\foo}{xyzzy} \@ifdefinable{xfoo}{\relax} \makeatother \begin{document} ... \end{document} More precisely, ...
4
votes
1answer
264 views

How can I loop back to a slide after showing conditional slides in Beamer?

I am working on a presentation that has conditional slides, using the formatting suggested here: Conditionally hidden slides in beamer I would like to be able to continue with my presentation after ...
2
votes
0answers
15 views

Robust handler of arguments with conditionals and complex elements

Context This question is a follow up of the answer of this question Spurious space on moderncv \cventry using \if Problem The problem is that complex content (for example, itemize on the content of ...
3
votes
2answers
64 views

Spurious space on moderncv \cventry using \if

I am trying to display some information in a \cventry conditionally using a defined \ifdetails switch. However, for some reason that is beyond my knowledge, an spurious space (or new line) is created. ...
8
votes
1answer
126 views

Testing for “emptiness”

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 } I am interested in how the ...
65
votes
3answers
21k 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 ...
17
votes
1answer
4k views

Comparing an argument to a string when argument is a result of a command with etoolbox

I've got an example like that: \documentclass{article} \usepackage{etoolbox} \newcommand{\ab}{a} \newcommand{\aORb}[1]{% \ifstrequal{#1}{a}{"a" was given}{not a}, % ...
8
votes
1answer
363 views

Display beamer headline in frames conditional on section and subsection environments

Objective I'm trying to create a beamer presentation (in LyX) where frames conditionally display a headline containing section and subsection navigation depending on (a) whether a frame is in a ...
4
votes
1answer
30 views

natbib + BibTeX: suppress url if doi is available

I am using natbib (+ BibTeX). Some entries in my bibliography file (.bib) have the field doi, some have url and some have both. I would like to edit the bibliography style file (.bst) so that, if doi ...
1
vote
1answer
32 views

Compile \showtrue and \showfalse to different target files

I'm writing a problem set with a solution. Right now I have the following setup: \newtheorem*{sol}{Solution} \newif\ifshow \showfalse \ifshow \newenvironment{bluesol} {\begin{sol} ...
6
votes
2answers
85 views

Conditional code on page size

I've never done any coding in Latex than involves anything too complex (anything more than just writing and customizing a few stuff here and there), so I'm having troubles finding what I need to do ...
3
votes
1answer
30 views

Conditional section title [ifthenelse] not working

I have the following code: \documentclass{article} \usepackage{ifthen} \usepackage{amsmath,amsfonts,amsthm,amssymb} \newcommand{\probName}{}% \newcounter{probCounter}% \setcounter{probCounter}{1} ...
3
votes
0answers
36 views

How can I efficiently create variants of a conditional?

Say I have the following: \prg_new_conditional:Nnn \sean_cond:n { T,F,TF } { \prg_return_false: } How can I efficiently create the following? (This list is arbitrary.) \sean_cond:nT \sean_cond:nF ...
0
votes
1answer
27 views

Why doesn't my \csname-based glossary macro work inside \section and \caption?

I'm a LaTeX newbie. I have a custom macro called \gloss that decorates its argument in a certain way - let's say that it adds a star symbol for the purpouse of the MWE. I have wrapped it around a ...
3
votes
1answer
29 views

Include preamble statements depending on compiler

I am trying different compilers like pdfLatex, luaLatex, latex to try differences in compiling things like pgfplots. But when i shange the compiler I also need to change the preamble. How can i do ...
16
votes
1answer
186 views

Cleanest way to prepare bilingual document and output only one language [duplicate]

I am currently preparing the presentation for my internship evaluation. As a French student evaluated by researchers that may or may not speak French, I would like to maintain two versions of my ...
2
votes
1answer
54 views

How can I conditionally reference a figure?

So here's my knitr .Rnw file: \documentclass{article} \usepackage{hyperref} \hypersetup{} \begin{document} \let\ref\autoref <<plot,fig.cap='try'>>= if(rnorm(1) > 0) x = rbinom(1, 100, ...
1
vote
1answer
30 views

Conditional page break to start a new section

I am trying to have a conditional page break for a section if there is not enough space in the bottom. To be clear, when an new section starts I want to check if there is enough space (25% of the text ...
20
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" ...
9
votes
1answer
140 views

Somewhat versatile usage of \@gobble and \@firstofone found in several macros

I was doing search about my question (see here for more detail) and found a thread commath and \ifinner. In the thread, there is a macro named \spx , the definition and usage of which are extracted ...
0
votes
1answer
37 views

Conditional branch with \ifinner and Spacing in higher derivative (2 independent questions) [duplicate]

I made some macros shown below, which outputs ordinary/partial derivative. I was checking whether they work as I expected, and found that \dif{y}{x} expands to \tfrac{\difd y}{\difd x} in align ...
3
votes
3answers
108 views

How to easily write conditional pages? [closed]

Is there any easy way to make latex write only some of the pages? My current idea is to make a function using the ifthen-package in the following way: \newcommand{\WhatDoYouWantToWrite}[1]{ ...
10
votes
1answer
160 views

\newcommand and its intricacies

I recently came across the following command: \newcommand{\minitab}[2][c]{\begin{tabular}{#1}#2\end{tabular}} Well, this is close to the syntax laid out on p.845 of TLC, but I still don't ...
3
votes
2answers
68 views

Evaluate strings of key-value option in custom package by using a switch-case environment

I'm trying to write a custom package MyUnicodefonts where I'd like to store all my font settings for various math fonts and roman fonts (later also mono and sans). In my document I intend to choose ...
0
votes
0answers
41 views

How to change margins based on paper size?

My document uses US letter: \ProcessOptions\LoadClass[letterpaper,twoside]{report}, with the following margins setup: \geometry{tmargin=25mm, bmargin=25mm}. Now, if I change the paper size option ...
1
vote
1answer
24 views

How to switch between “ON” & “OFF” modes for printing line numbers in a modular document, using lineno package?

Background: I am using the modular document approach for writing my thesis. Since, the work is still in progress, I am also printing line numbers wherever needed, using the \linenumbers & ...
2
votes
1answer
64 views

How to detect LuaLaTex inside my .tex file and exclude bits and pieces conditionally

Let me state my "problem" first. When using PdfLateX my .tex file compiles rather swiftly and all is fine. I use TeXStudio and make use of the PDF preview feature. Since my LaTeX fu isn't the ...
16
votes
2answers
1k views

How to determine whether a list of figures is empty, then not show it at all?

I want to check whether the document has any figures so as to decide whether or not to have a list of figures. Is this possible? Feasible without doing something like parsing the lof file? Note that ...
5
votes
1answer
35 views

How to make option langid={english} conditional?

How can i make all references to have langid={english} option unless there are cyrillic letters inside a reference, then it should be langid={russian}? Optional question: How can i make all references ...
4
votes
2answers
99 views

Is is possible to conditionally switch languages within one document? [duplicate]

I'm quite new to biblatex. I'm typesetting a collection that has papers both in English and Russian, and I'm making a single bibliography at the end of the book. For the bibliography to look pretty, ...
5
votes
1answer
68 views

Text formating depending on conditions

I have some conditions which are stored in boolean variables, such as \bool_new:N \l_word_numbered_bool \bool_new:N \l_word_lowercase_bool \bool_new:N \l_word_centering_bool I need to format words ...
5
votes
2answers
35 views

Mysterious error message when using iftex package

I am using iftex package to detect which TeX engine I am using. In the following example (MWE) I am using pdfTeX engine: \documentclass[norsk]{beamer} \usepackage{iftex} %\RequireLuaTeX \ifXeTeX ...
2
votes
2answers
38 views

How to know if there is any section in a chapter

I want to use a conditional expression that modifies the chapter title depending if the chapter has some sections or not. Example: \ifnum \value{chaptersections}>0 \setchaptername1 \else ...
3
votes
2answers
82 views

Environment which sends text conditionally to an appendix?

I am writing a paper and would like an environment that has the following property. If some flag is set to "true" in the preamble, all text wrapped in that environment is sent to the appendix. If the ...
4
votes
2answers
90 views

Howto: if argument is numerical … else

I'm trying to create a differentiation command. At the moment I have the following: \newcommand{\diff}[1][]{% \def\ArgI{{#1}}% \diffRelay% } \newcommand{\diffRelay}[2][]{% ...
10
votes
2answers
252 views

conditional against font color

I want to change the text according to its current font color. I can test argument against font family \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} ...
4
votes
2answers
254 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
1answer
25 views

Use default message if file is missing

There is very simple and fool-proof solution for default actions if included file is missing. It is using \IfFileExists{IncludedFile}% {% routine if file exists }% {% routine if file does not exist ...
5
votes
4answers
68 views

How to conditionally uncomment only one portion of code?

I'm trying to design a tex file that could store multiple colour schemes (which I would define once and for all), which I could "activate" one at a time to assign quickly a colour scheme to my ...
5
votes
1answer
68 views

Compilation error with \ifnum in ConTeXt

Why the following code gives me the following error? Code: \begingroup \catcode`\"=12 \gdef\newmcodes@{\mathcode`\'39\mathcode`\*42\mathcode`\."613A% \ifnum\mathcode`\-=45 \else ...
43
votes
4answers
8k views

How to check if a macro value is empty or will not create text with plain TeX conditionals?

I have a macro which holds some text value, e.g. \macro{some text}. If it is empty, I would like for nothing to appear in the document, but it has some content of any kind which would produce text ...
7
votes
2answers
136 views

Comparing strings extracted from Jobname

I have some code that parses \jobname, but it's not working as expected. I've included a minimal example below where the file name is HelloWorld.tex. When I print the \jobname, it comes out as ...
4
votes
1answer
35 views

How to set a newenvironment to skip words by flag?

I want to create a environment to include some words, but hide it when a flag is set up. However, I cannot put \begin{comment} \end{comment} into \newenvironment for some reason. How should I do this? ...
3
votes
1answer
35 views

newcommand based on what environment is active

I want to have command to insert different heading style based on what environment is currently active. I found that the environment should be accessible via macro \@currenvir, but for me, the "else" ...
4
votes
1answer
41 views

Why does beamer's \insertauthor report as nonempty?

I'm working on a beamer theme in which each of the title page elements is optional; for example, I don't want defining an empty date to produce a large empty space on the title slide. I figured I ...
3
votes
1answer
35 views

Adding extra conditional to a sidenote command

Below is an adapted part of the code from the sidenotes package, which I intend to include in my class file. I'm trying to extend it with an optional argument [flip], with usage \sidenote[flip]{Text} ...
8
votes
2answers
284 views

If statements and variables

I need some help understanding if statements. How do I make the following pseudocode in LaTeX. \newcommand{\@leader}{} \newcommand{\leader}[1]{\renewcommand\@leader{#1}} \newcommand{\donow}{ ...
2
votes
0answers
27 views

\ifbeamer@anotherslide and \ifbeamer@localanotherslide in beamerbasedecode.sty

At the beginning of the source file beamerbasedecode.sty of beamer class, two switches are defined: \newif\ifbeamer@anotherslide \newif\ifbeamer@localanotherslide By reading beamerbasedecode.sty ...