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

2
votes
1answer
39 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
27 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 ...
9
votes
1answer
134 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 ...
10
votes
1answer
154 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
56 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
40 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 ...
6
votes
2answers
72 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 ...
1
vote
1answer
18 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
3answers
101 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]{ ...
3
votes
2answers
27 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. ...
2
votes
1answer
61 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 ...
5
votes
1answer
33 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 ...
5
votes
1answer
64 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 ...
2
votes
2answers
37 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 ...
5
votes
2answers
32 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 ...
3
votes
2answers
76 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
217 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} ...
1
vote
1answer
23 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 ...
4
votes
2answers
97 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
4answers
64 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 ...
7
votes
2answers
131 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 ...
5
votes
1answer
62 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 ...
4
votes
1answer
33 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
31 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
31 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} ...
2
votes
0answers
24 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 ...
8
votes
2answers
276 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}{ ...
3
votes
3answers
131 views

\pagestyle{plain} between chapters without page number after titlepage?

I've found numerous posts about removing the header/footer on the blank pages between chapters, and they work fine with one big exception... I need a \pagestyle{plain} (i.e. single centered pg#) at ...
1
vote
2answers
50 views

How to test whether report has been called with “draft” option

How can I test within a document, whether or not the initial \documentclass[a4paper,11pt,twoside,fleqn,draft]{report} includes the "draft" option? My naive attempt \newif\ifmydraft \mydraftfalse ...
0
votes
1answer
60 views

Switch between different output versions compiled from the same LaTeX source

For programming in C, it is quite common to switch between creating debug- and release-versions by passing a command line argument to the compiler. I would like to have something similar for ...
4
votes
2answers
365 views

LaTeX “Variables” - \@varname

I'm currently in the process of writing my first document class file (a personalized resume class), and I want to get a better understanding of what exactly I'm doing. So, right now I'm setting up ...
8
votes
1answer
47 views

TeX quotation marks short-circuit optional argument with \ifx

In a command with an optional argument, if I put a string beginning with TeX quotes (e.g., ``quote'') in the optional argument, something goes wrong. See the bottom entry in the example below. The ...
3
votes
1answer
58 views

Using pgfplotstabletypeset to conditionally bold small p-values

Following advice seen in other entries about using pgfplotstable on tex.stackexchange.com (such as pgfplotstable: Conditional post-processing of cell content on a per-column basis), I have encountered ...
3
votes
0answers
64 views

Insert or apply a decision structure to sequence or list

I would like to make the function calls \findLargest in the MWE below a little more dynamic and compact. As demonstrated in the example below, I can store glossaries values and include them in the ...
3
votes
1answer
98 views

Select largest value from a list of variables in LaTeX

I am trying to adapt this example How to iterate over a comma separated list? as my base. Except, rather than display all values, I actually want to iterate through all the values and only return / ...
3
votes
4answers
41 views

command to generate a \cite{} only on first use

In a book dealing with R, I use a command \pkg{} for every mention of an R package, that also generates index extries via another command \ixp{}. \newcommand{\pkg}[1]{\textsf{#1}\ixp{#1}} All ...
0
votes
0answers
25 views

ifthenelse in adress of letter

I write a letter with \documentclass[a4paper,12pt,addresshigh]{dinbrief} The letter itself starts with \begin{letter}{\Anschrift} and \newcommand{\Anschrift}{% \textbf{\Firma}\\ ...
3
votes
0answers
34 views

Problems in using the spreadtab and the ifthen packages

Using the spreadtab package for some computing, I have to write an expression (mixing of literal and numerical expressions) if some conditions are true. Using the ifthen package, all works well for a ...
1
vote
0answers
51 views

Ending a tikzpicture environment in conditional causes “Missing } inserted”

I want to create a number of tikzpictures. I have a number of items I want to draw. Each tikzpicture takes up a whole page and may contain up to 4 items. (It is not good enough to to have each item in ...
0
votes
0answers
15 views

How to change “ifthenelse” conditional to “ifnum” [duplicate]

I'm trying to put a conditional inside \cfoot from the fancyhdr package like this: if the document contains a one-page there will be no footer. if there are more pages the footer takes the format " ...
2
votes
1answer
27 views

\ifthenelse within \caption, \listoftables does not work

EXAMPLE 1 below works fine but EXAMPLE 2 produces "undefined control sequence". The only difference is the \vlabel command within brackets in the \caption command. What is the problem? EXAMPLE 1: ...
5
votes
2answers
61 views

How to determine if a macro argument contains the macro itself?

I would like to have a way to detect if a particular macro's argument contains that particular macro itself. Consider the following MNWE: \documentclass{article} \usepackage{etoolbox} ...
4
votes
1answer
80 views

How to control conditional statements within new commands and environments

I'm writing a pretty complicated class to typeset a book based on memoir. One of my commands draws a caption on the preceding verso page, draws content on the following recto and verso pages, and ...
2
votes
3answers
65 views

Multiple \if condition using etoolbox

First: I've found "Checking if two conditionals are met" but I don't know how to change it do suit my needs. Wanted: I have eight different predefined values and I want different definitions of a ...
2
votes
1answer
109 views

How can I know if I am inside an equation environment if it's nested with others?

I wanted to define some partial derivative commands that would be \partial y/\partial x if it was inside an inline equation and would use \frac{\partial y}{\partial x} if inside an equation ...
7
votes
3answers
195 views

Is there an “\if” command that determines if a command has been issued?

I need to redefine the \chapter command to change the \addcontentsline command depending on whether or not the \appendix command has been issued. Is there an "if" command that determines if a command ...
6
votes
1answer
174 views

How can I retrieve (and conditionally act on) the language of my document?

I have a collection of documents that share a common style file that has all the functions and templating shared by this particular collection. The majority of these are all in the same language, but ...
0
votes
1answer
31 views

Make macro which checks the type of math mode its in [duplicate]

I frequently find that I want to make a macro, say a derivative macro for example with the following syntax: \def\dd #1;#2;{ return... } However, I want it to check if it is inline math such as ...