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

3
votes
2answers
47 views

problems with ifthen and tabularx

I have a problem related with ifthen and tabularx packages. Here is a minimal example: \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage{tabularx,colortbl} \usepackage{xcolor} ...
3
votes
1answer
33 views

“Extra \fi” error when defining mutually exclusive package options with conditionals

I have been trying to create a package, which loads the babel package and sets the language with an option. I've been getting strange errors when trying to define mutually exclusive package options, ...
2
votes
0answers
21 views

How do I extend if logic from skipping particular slides to specific portions of a Beamer frame?

I have the following working structure for excluding particular lecture slides from the article form of a lecture: \documentclass[11pt,handout]{beamer} \newif\iflecture \lecturetrue % Next three ...
0
votes
0answers
61 views

Show DOI in BibLaTeX bibliography if article only published online

I'm trying to display DOI in BibLaTeX bibliography if the relevant article has not yet been published online (i.e. fields are blank for issue, volume, page number, etc.)? I found this Biblatex: Print ...
0
votes
0answers
17 views

Using if then logic with Beamer for integrated lecture notes [duplicate]

I am very comfortable with Beamer and Latex but have never used if then constructions. I typically build a lecture in complete slides, edit with pauses for a lecture version and finally distribute a ...
0
votes
1answer
29 views

Using \let to change the argument of a a \newif command

I want to be able to switch mid-document between writing indices as subscripts vs within parens, e.g., x_t vs x(t). I've written some code to do this, see below. Everything is conditioned on the ...
3
votes
3answers
56 views

How to conditionally color nodes in a grid with a style

I have 3 styles called S1, S2 and S3. I want to conditionally color the nodes. I tried the \ifnum with no luck. You can see the single line of code that has been commented out. That is what I ...
3
votes
1answer
40 views

Using a command (or a variable) in if/then condition

Imagine the following situation: A school offers two courses, course A and course B. One of the courses is math and the other is physics. Math is taught by Bill, and physics is taught by Susan. I want ...
2
votes
4answers
97 views

Programming a step function- part2

Based on a macro given by egreg in this question: Programming a step function I obtain a program which tests in which interval is a number \alpha, between the numbers bone, btwo, bthree, bfour. I use ...
2
votes
1answer
36 views

How can I implement xstring's \IfBeginWith equivalently in a non-user-level macro?

I have a string check macro \IfBeginsWith from xstring that is wrapped in a non-user level macro. I have learned here that the wrong approach would be to use user-level commands in a wrapper that no ...
3
votes
0answers
38 views

Set draft depending on operating system

I'm working on two different operating systems - MacOS and Windows. While the main part of my work is done on OSX, I sometimes switch to windows for several reasons. Problem is: Windows and OSX ...
2
votes
1answer
28 views

Conditionals and arrayjobx

I am struggling with the use of conditionals, I have a basic example given below that will output the table included. The code starts by defining \myletterA as the A character, and an array called ...
2
votes
1answer
90 views

Ifx and end of line [closed]

Can anyone shed some light on this? I have an interesting problem involving the "There's no line here to end" error. EDIT: Variables. I did not think to include this as I thought there was only one ...
1
vote
1answer
37 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} ...
4
votes
2answers
78 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 ...
3
votes
1answer
29 views

Conditional evaluation of Sweave chunk

I'm using some R code to import and manipulate a time series. The code takes some minutes to run and, as a result, it generates a relatively small time series. Now, to prevent typesetting to take an ...
2
votes
0answers
30 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
1answer
61 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
214 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
55 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
39 views

Conditional complex column type

\documentclass{article} \usepackage{array} \usepackage{ragged2e} % \newcolumntype{M}[1]{>{\hspace{0pt}\raggedright\arraybackslash}m{#1}} % ...
4
votes
1answer
65 views

Selecting a subset of questions among a long TeX file

I have a big list of questions and solutions and I want to select a subset of them to use in exams. I am using documentclass exam. See the following example \documentclass[12pt]{exam} ...
3
votes
3answers
206 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
18 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
3k 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 ...
0
votes
2answers
43 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
55 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
43 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
21 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
36 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
72 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
39 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
13 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
551 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
539 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)$) {}; ...
3
votes
2answers
107 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
20 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
54 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 ...
34
votes
4answers
10k 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
2k 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
124 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[..., ...
6
votes
3answers
183 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
142 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
37 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
36 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 ...
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
230 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
73 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
6k 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 ...