{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
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 ...
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.
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
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 ...
5
votes
1answer
95 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} \begin{...
3
votes
1answer
61 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
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{...
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? ...
4
votes
3answers
330 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
121 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
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 ...
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 ...
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 ...
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 ...
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, ...
3
votes
1answer
39 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
51 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
45 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
60 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} \usepackage{...
2
votes
1answer
105 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
136 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
114 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{} \cite{\...
2
votes
2answers
27 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 1}{...
2
votes
1answer
29 views

pst-barcode Argument of \pst@@object has an extra }

I have the ISBN stored in two commands (depending of a class option) \theisbne \theisbnp The boolean options of the class are defined using xifthen \RequirePackage{xifthen} \newboolean{@sbmcpm@...
0
votes
1answer
88 views

Compilation of main document, if subdocuments are compiled

I have a main latex document, and many other files included with \input{...}, e.g. by chapter. Often, I just work on a subfile and my idea is now, that I want to compile the main document if I start ...
1
vote
1answer
49 views

XParse doesn't recognize some of my variables

Based on the comments from my last question have I tried to create a new command using \NewDocumentCommand. However, it wont recognize some of the optional arguments - they just get printed as is. Any ...
0
votes
0answers
29 views

how to define a general conditional for a complete text

I wonder how to define a newcommand of the type with general conditionnal \def\a{} which givefor each call in the text %\begin{comment} %\end{comment} when a=0 and \begin{comment} \end{...
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 ...
3
votes
1answer
36 views

Adding code (pagebreak) after value change in csvsimple

Background I want to create a document with the user data of our network at school, which should be handed out to the user. This should be done class by class. Approach The user data are given in a ...
0
votes
3answers
90 views

If condition without any package?

I create a table by rows like this: \row{1}{Sunday,Su,05.09.2015}{N}{08:00,17:00,12:00,13:00}{8.0,1}{Airplane Hangar} How can I prove, if the first parameter is 0 or 1, an if it's 1 then set a ...
3
votes
2answers
181 views

Ifthenelse conditionals in moderncv's cventry

Now that Frodo has left to fight Sauron, Bilbo is all alone at home and searching for new things to do. So it came to his mind that he could apply for a job. For his application, he uses the moderncv ...
7
votes
1answer
115 views

Has LaTeX3 syntax possibly changed since this question was last answered

I am adapting the LaTeX3 answer in this question: http://tex.stackexchange.com/a/61603 But I can't get the original MWE answer to compile using xelatex. I have renamed the variables, but the error ...
2
votes
0answers
60 views

Access xparse's \BooleanTrue via latex3 expl3

I'm implementing a command with xparse's boolean token processing \NewDocumentCommand{\op}{s o t' t. t^ g}{ % Here I need to check for % (#3 || #4 || #5) && !(#3 && #4 &...
1
vote
1answer
51 views

Conditional list of tables in LaTex [duplicate]

List of Tables can be obtained by using listoftables commands. I wonder how to skip listoftables output if the document doesn't contain any table. Thanks \documentclass[11pt]{article} \begin{...
2
votes
2answers
175 views

Set comment toggle to false, error: Undefined control sequence

I want to toggle comments of and on. Off works, but when I set toggle to true, then I get an error: ./main.tex:36: Undefined control sequence. \endtcolorbox ->\unskip \tcb@after@box ...
1
vote
0answers
46 views

Set comment toggle to false, error: There's no line here to end [closed]

I want to show/hide comments when toggeling the code below: \newtoggle{comments} %\toggletrue{comments} \settoggle{comments}{true} %set true to show all comments, set false to hide all comments \...
1
vote
1answer
73 views

Display or hide stuff in a document

I am using comments in LaTeX, which are defined in my document as: \newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}{}}\linebreak} I would like to add something like ...
13
votes
2answers
181 views

The following code compiles without error. How can I change that?

Unlike most questions on this site, my problem is that my code compiles without error and I do not want it to. I want to be able the check whether \command is defined and to do something if it is ...
4
votes
1answer
91 views

\newif inside function definition in LuaTeX

In a function I have in a package I'm working on I'm trying to add the following line: \expandafter\newif\csname ifgre@scale@#1\endcsname% Now, this works fine under LuaLaTeX, but the package is ...
0
votes
0answers
46 views

Programming in Latex: Conditionals [duplicate]

I'm trying to learn how to programming in Latex. I want to make an if-else-statement. What I will do is something like this: \def\x{2} { \if x =2 Yes \else no \fi } But it doesn't work exactly how ...
1
vote
0answers
39 views

Passing optional arguments to a listing environment based on conditionals

I am trying to make a presentation which can optionally compiled for handouts. This presentation also contains highlighted code snippets. For highlighting I use the code from this question. (Which ...
1
vote
1answer
166 views

Creating a grid with different color vertices (graph)

I am new to using tikz and I have never used ifthenelse statements in latex before, but I am trying to create a grid where the vertices on every other diagonal are a different color and shape. This is ...
2
votes
1answer
158 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 ...
7
votes
4answers
222 views

How to check if a macro expands to one of several strings?

I have the following problem: I am using the etoolbox package to check if a macro (say, \foo) expands to one of several possible strings (say, bar, baz, abc, or other). I need to execute different ...