{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
3answers
72 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 ...
2
votes
1answer
53 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
41 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
101 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
35 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
37 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
44 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
86 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
1answer
70 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
229 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
47 views

Conditional complex column type

\documentclass{article} \usepackage{array} \usepackage{ragged2e} % \newcolumntype{M}[1]{>{\hspace{0pt}\raggedright\arraybackslash}m{#1}} % ...
5
votes
1answer
62 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
250 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
20 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
46 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
22 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
172 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
42 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
79 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
45 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
21 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
52 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.
2
votes
2answers
120 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
27 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
136 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
210 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
88 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
50 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
49 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
38 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
299 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
104 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
93 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
51 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
185 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
32 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
40 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 ...
7
votes
1answer
91 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
60 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}{ ...
6
votes
1answer
43 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, ...
3
votes
1answer
37 views

Changing symbol size when used as subscript

This is a follow-up to this question. I'd like to define \fa to display \forall when typed as usual but be \mathsmaller{\forall} when \fa is used as a subscript. For example, I want to write ...
2
votes
1answer
48 views

Define symbols differently in text mode versus math mode

I'd like to define \a to be the $\forall$ symbol, but I'd like it be the regular $\forall$ in text-mode and \mathsmaller{\forall} in math mode. Is there any easy way to do this? I'm guessing it ...
2
votes
1answer
40 views

How can I make condition inside the geometry options?

I would like to make condition inside the geometry options \geometry { headsep = \baselineskip , textwidth = 42\baselineskip , textheight = 60\baselineskip , hmarginratio = 2:3 , ...
2
votes
1answer
58 views

Optional text printed in another colour

I would like to extend the version package to print some optionally added text in a different colour. Something like in the following example: \documentclass{article} \usepackage{version} ...
2
votes
1answer
89 views

When using \IfEq to compare strings, is it one of those times when I should use an expandable xparse command?

I recently asked How can I migrate commands and environments from LaTeX2e to LaTeX3? [XeTeX] While that question is good, the answer is likely quite complex and would take a some time to effectively ...
3
votes
3answers
133 views

Changing page to pages if more than one page

At the beginning of my document, I need to list the total number of pages in the document. I've got a system that works most of the time (see below), but if the document only has one page, then my ...
3
votes
1answer
94 views

Modify nodes near coords with \if

I would like to code something like this: if \thecitation is {This work} then nodes near coords={\thenumber{} [This work]} and plot color is Red else nodes near coords={\thenumber{} ...
2
votes
2answers
25 views

Manipulating arguments to a macro inside an argument

In LaTeX, I have a macro \p (okay, it's \paragraph, but perhaps the specific macro is not relevant?) with one argument. Sometimes I use it as \p{plain text} and sometimes as \p{\t{alternate ...