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

1
vote
1answer
46 views

Formatted table based on arrayjob

I want to setup a rowcolor and the cell content of a tabular accordingly to the values stored into an array (arrayjob). The next MWE \documentclass[10pt]{article} \usepackage{arrayjob} %\usepackage{...
4
votes
2answers
95 views

How to force-expand a \def for \in@?

Take the following code as an example: \documentclass{standalone} \def\myvar{foobar} \begin{document} \makeatletter \in@{foo}{foobar}\ifin@ Yes\else No\fi, \in@{foo}{\myvar}\ifin@ Yes\else No\fi \...
2
votes
0answers
32 views

How to only print endnote section if there are any endnotes?

I am using the enotez package and would like to be able to call \printendnotes regardless of if there are actually any endnotes. In the case that there are no endnotes I would either like the \...
4
votes
2answers
72 views

Reset counter via macro with \ifcase in Plain

I am not able to reset a counter to zero using a macro in Plain TeX. This code uses \ifcase and the counter animalnum to output one of a list of animal names, incrementing the counter each time it is ...
4
votes
3answers
249 views

How to change the output of a command if it has been called already?

I want to create a command that changes its output the second time it gets called. For example, I want it to yield 1 the first time it's called, and 2 the second time: \newcommand\mycommand { do ...
5
votes
1answer
65 views

Comparing koma variable to string

I can't quite figure out how to compare a koma variable with a string by using \usekomavar{..}. I want to set another koma variable depending on the value of the first. So I want something like this ...
2
votes
1answer
48 views

Conditional complex column type

\documentclass{article} \usepackage{array} \usepackage{ragged2e} % \newcolumntype{M}[1]{>{\hspace{0pt}\raggedright\arraybackslash}m{#1}} % \newcolumntype{B}[1]{>{\hspace{0pt}\centering\...
3
votes
3answers
272 views

How can I test the value of two counters?

I'd like to test the value of counters (preferably as vanilla TeX as it gets). \documentclass{article} \newcounter{counterA} \newcounter{counterB} \setcounter{counterA}{2} \setcounter{counterB}{2} \...
2
votes
0answers
21 views

Automatically Detect When in an Mdframed frame title

I would like to be able to detect when I am within a frametitle={} of an mdframed environment. One way is to manually set a flag within the \frametitle={}, but wondering if there is some other way to ...
24
votes
2answers
4k views

What does \begingroup\expandafter…\endgroup do?

I often see code of the following form in package implementations (this example is from the LaTeX3 sources): \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname directlua\...
0
votes
2answers
49 views

Membership check on comma separated list [duplicate]

Does anyone know an easy way to check if an item is a member in a comma-separated list? Something like this would be excellent: \ifmember{elem1}{elem1,elem2,elem3}{true}{false} The above would ...
1
vote
1answer
265 views

LaTeX \if condition

I am using \if condition in a custom command in my LaTeX document. I would like to know where I can find some good explanation about \if command. I followed a Wikibooks \if page but it's just an ...
1
vote
2answers
54 views

Circle individual item in list dependent on boolean

Is there a way to create an enumerated list which has an item that will be circled when toggling a boolean? I'd like to use it for creating multiple-choice tests and the solution key.
0
votes
0answers
25 views

tex4ht \ifdefined\HCode equivalent for Latex2rtf

One of my favorite features of tex4ht is that I can customize formatting or content depending on what compiler is being used by enclosing code in an if statement that is capable of providing a flag ...
2
votes
1answer
43 views

Creating a PDF with Content Hidden Depending on a Response to a Form

Would it possible to create a say 3-page PDF document with LaTeX such that On page 1 the reader is presented with a yes/no question through something like a radio button; If the answer is yes, then ...
2
votes
2answers
88 views

How to switch macro expansion by giving optional arguments?

Popular ways to define a macro with optional arguments is using TeX's \def with the aid of \@ifnextchar[ and/or LaTeX's \newcommand. In both cases, macro's definition usually contains its optional ...
1
vote
1answer
46 views

\left( and \right) with maximum size

I would like to have two macros that mimic \left( and \right), but limits the size of the parenthesis to \Bigl( and \Bigr) (allows smaller sizes), respectively. In the below MWE, one needs to extend ...
11
votes
1answer
1k views

Conditional using non-integer numbers

I am trying to generate fractals using affine transformations. I need to generate a random number in the interval (0,1), and depending on the value of this random number choose a function to ...
2
votes
1answer
24 views

How can I exclude pages from this Boolean command?

I was using the code from Harish Kumar's excellent answer to this question to create a link t my table of contents. However, I wanted to alter it so that the link did not appear on the first two ...
40
votes
1answer
576 views

Test if paragraph has an overfull line

I'd like to test if the last paragraph has any overfull line. The naive approach of looking at the \badness once the paragraph is finished does not work, as it will only give the badness of the last ...
17
votes
6answers
607 views

Test whether passed parameter is a number (possibly floating point) or dimension

With TikZ using the calc library you can write things along the lines of \node (A) at ($(0,0)!0.75!(1,1)$) {}; or you can write something (rather different) \node (B) at ($(0,0)!2in!(1,1)$) {}; ...
2
votes
2answers
123 views

How to check for more elements a foreach loop?

I want to check if there are more elements in a foreach loop. How can this be done? This is an example for loop: \foreach \p/\q in {a/{1,2,3}, b/{4,5,6}} \foreach \r in \q { (\r) } EDIT#1 An ...
1
vote
1answer
29 views

tex4ht: include *.pdf image - need condition in configuration file

I use tex4ht to compile my document. In case if user includes .pdf image, I handle this situation in the following way (.cfg file): \Configure{graphics*} {pdf} {\Link[\csname Gin@base\endcsname ....
2
votes
0answers
59 views

“Draft” mode for document

Suppose you want to keep two versions of the same document: one where you highlight changes and one where you show the final result. How can I use a "debug" or "test" mode to turn on/off my \textbf ...
36
votes
4answers
11k 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 ...
11
votes
2answers
3k 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 ...
2
votes
1answer
140 views

Programming a step function

I have, say 7 values ordered increasily, a_0,a_1,...,a_6. I want to program a step-function on the intervals of extremity a_i, so a function f such that, f(x)=f_0 on [a_0,a_1[, f_1 on [a_1,a_2[..., ...
5
votes
3answers
216 views

Conditional within TikZ path?

I'm trying to make a macro for drawing square puzzle pieces in TikZ. There should be three possibilities for each edge, either jutting in, jutting out, or straight. Below is what I have so far. As ...
4
votes
1answer
174 views

Option argument for Beamer section slide

I am creating my own Beamer theme with a custom section slide. Ideally I would like the command \frame{\sectionpage} to have an additional, optional argument, that specifies the color of the ...
2
votes
1answer
39 views

How to know the number the last generated page?

I would like to replace \AtEndDocument{ \doSomething } by \AtEndDocument{ if (page == 1) { \doSomething } else { \doSomethingElse } } How can I know the index of the last page generated? ...
3
votes
1answer
56 views

Print text conditionally if argument is not empty

I would like to define a command with arguments managed using pgf-key that prints some text conditionally on the the fact that a value was indeed passed. Here is my current code \documentclass{...
0
votes
2answers
1k views

How to number a conditional equation

I am writing the following syntax to get a conditional equation. But the equation is not numbered. How can I number it? \[ f(x) = \begin{cases} x+7 & \text{if $5< x$}; \\ x^2-3 & \text{if ...
4
votes
3answers
328 views

Generating all coprime pairs (m,n)

Is there a way of generating a plot of every coprime pairs of integer (m,n)? Two numbers are coprime if their great common divisor equals one (gcd(m,n)=1) and in such case they satisfy the Bezout ...
4
votes
1answer
98 views

Are conditional footnotes possible?

We are looking to create production Latex tables using xtable in R. Each table will have different footnotes based on certain data in the table. For example, in the below table instead of ...
16
votes
4answers
7k views

Are there any “if” commands like “\ifnum” in LaTeX?

Are there any commands containing "if", similar to \ifnum, preferably in LaTeX (rathar than TeX)? For example, is there anything like \ifstring? (I am not after \ifstring only, I want to know which ...
25
votes
5answers
9k views

new command with cases / conditionals / 'if… then's

Suppose I want to define a command, say, \tree with, say, two arguments. I would like \tree to do different things depending on what my first argument is. For example, if #1 = a, then return $\sqrt{#...
11
votes
3answers
223 views

Biblatex: Selecting content depending on language

I am using biblatex and would like to quote English and German works. When writing a document in German, this works nicely with the help of \DeclareLanguageMapping and hyphenation to specify if a ...
2
votes
1answer
120 views

Show the \subtitle if not empty

How do I show the subtitle if it's defined? When have a subtitle the code is like this: \begin{center} \MakeTextUppercase{\textbf{\thetitle:}}\\ \MakeTextUppercase{\thesubtitle} \{center} And ...
4
votes
1answer
58 views

Basic comparison of macro to string in lualatex?

Still hammering away at a database problem. Mostly done, but stumped by: \documentclass{article} \begin{document} \newcommand{\testmacro}{U01} The macro testmacro equals ``U01'' \directlua{ if \...
8
votes
2answers
189 views

\if-statement to know whether a new chapter has been created

I am trying to create a conditional function to determine whether a new chapter has been created (for a different purpose than that of the MWE). So far I have been unsuccessful, despite having tryed ...
34
votes
4answers
34k views

Large braces for specifying values of variables by condition

How do I typeset something like, X = 0 if a=1, 1 otherwise, using those huge left braces and specifying each condition in a line?
1
vote
1answer
33 views

Detecting empty key values when key is provided

I believe I am looking for a LaTeX3 type syntax solution to more appropriately detect a missing argument. To me I would have expected key={} to be a valueless, blank, or empty argument key. After ...
50
votes
2answers
10k views

What does \ifx\\#1\\ stand for?

The following usage of \ifx can be found in several packages and also in answers on this site. What does this syntax exactly mean? Are there any alternatives and drawbacks? \newcommand{\mycommand}[2][...
0
votes
0answers
43 views

csvreader: conditional formating of negative numbers

I have a csv file that contains both strings and numbers, and am using csvsimple to print it in my pdf. For those numbers that are negative, I'd like to print them in red For the positives one, I'd ...
16
votes
2answers
2k views

If not DeclareOption

I have some documents using a same custom package. That "header" package loads by default the package fullpage. But I would like to write a new LaTeX document, using the same header, but without ...
7
votes
1answer
94 views

Check what kind of document class is used

I have defined a .sty-file which I use in a report, which holds a lot of good information and styles for how my documents should look like. This have been working great, until when I tried making a ...
2
votes
1answer
62 views

Change header if title is first on page

(Not a dupe of Is something the first item on a page? and another similar question, because these involve preventing rules at the top of a page by putting them in leaders; but leaders require boxes, ...
2
votes
1answer
42 views

lstlisting breaks ifbool block

I have the following piece of code: \documentclass{article} \usepackage{etoolbox} \usepackage{listings} \newbool{xyz} %\booltrue{xyz} \boolfalse{xyz} \begin{document} \ifbool{xyz}{ \section{...
6
votes
1answer
44 views

Is it possible to implement a package dependency which is version specific?

This question should really ask what is the best way to implement a version-specific package dependency. However, if I try to ask that, the system threatens to close my question. In this answer, ...
5
votes
3answers
240 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 ...