{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
20 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
18 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
50 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
16 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
55 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
39 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 ...
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
4answers
94 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
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
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 ...
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
77 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
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
212 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 ...
2
votes
1answer
35 views

Conditional complex column type

\documentclass{article} \usepackage{array} \usepackage{ragged2e} % \newcolumntype{M}[1]{>{\hspace{0pt}\raggedright\arraybackslash}m{#1}} % ...
5
votes
1answer
53 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 ...
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 ...
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 ...
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 ...
1
vote
1answer
54 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 ...
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
71 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 ...
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 ...
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.
3
votes
2answers
106 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
1answer
123 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
182 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
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
1answer
28 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 ...
3
votes
1answer
35 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 ...
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? ...
4
votes
3answers
229 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 ...
2
votes
1answer
67 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
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 ...
4
votes
1answer
36 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
175 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 ...
1
vote
1answer
27 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 ...
0
votes
0answers
29 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 ...
2
votes
2answers
287 views

Strange errors while writing a package

This short document: \documentclass[a4paper]{report} \usepackage{gnu} \begin{document} \end{document} with the following package: %!TEX encoding = UTF-8 Unicode \def\fileversion{2.7} ...
9
votes
1answer
136 views

Package providing fully expandable conditionals

Is there a package providing a collection of fully expandable conditionals like this one: \newcommand\myif@num[1] {\ifnum#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} Background: ...
17
votes
3answers
3k views

Implementing switch cases

I'd like to have command built around a switch-case environment in LaTeX, much like the example below: \documentclass{article} \usepackage{xstring} \newcommand{\dothis}[1]{% \IfStrEqCase{#1}{{a}{so ...
5
votes
1answer
341 views

Suppressing remarks when not needed

I have written some remarks in some of my works that are somewhat informal and repetitive in nature (mainly for my own clarification). I was wondering if there is a way of suppressing them when I ...
17
votes
2answers
6k views

Conditional cases expression

How can I create a command \if with 1 argument, namely #1, \if{#1=1}{symbol1}...{#1=n}{symboln} that returns symbol1, when #1 is 1, ..., and returns symboln, when #1 is n, and returns nothing, ...
32
votes
5answers
12k views

If Then Else for odd page/even page

How to use if-then-else structure in LaTeX? I need a example of odd and even page. if odd then command 1 else command 2
17
votes
4answers
2k views

Making switch/case with etoolbox's \ifdefequal

I've got a define such as \def\doctype{SomeString}. \doctype can take on one of five values. I want to do something like a switch statement in a programming language, i.e. (pseudocode): switch ...