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

4
votes
1answer
30 views

How can I make a command execute exactly once in an AMS environment?

I'm wanting to create a command similar to AMS's proof environment that automatically calls a command (like AMS's \qedhere) when it gets to the end, but allows you to call the command earlier if you ...
18
votes
2answers
1k views

Conditional “if a package is available”

I'd like to do something like the following (in pseudo-TeX) \ifpackageavailable{packagefoo} \usefoo \else \usefooreplacement \fi For example, I know that a template file I wrote is used by people ...
4
votes
2answers
201 views

Why can't I use braces in an \if… \fi group?

I am starting to use \newif in a LaTeX class definition to finally stop carrying around all my definitions and imports from article to article. Since I am trying to define options, I am ending ...
3
votes
1answer
35 views

How can I make a command execute exactly once in an argument?

I'm wanting to create a command similar to AMS's proof environment that automatically calls a command (like AMS's \qedhere) when it gets to the end, but allows you to call the command earlier if you ...
5
votes
0answers
18 views

How can I conditionally designate an active quote in csquotes.cfg?

How can I conditionally designate an active quote in csquotes.cfg so that no error is produced if the same character is made into an active quote in the .cfg and the document's preamble? I have the ...
2
votes
1answer
19 views

Pass iteration variable from foreach to custom command

I am trying to figure out why the following code does not work: \documentclass{article} \usepackage{etoolbox} \usepackage{pgffor} \newcommand\setProblemShow[2]{% \csdef{isProblemShow#1}{#2}} \...
3
votes
1answer
26 views

Looking to distinguish between a scale factor and a dimension

I'd like to be able to define a macro, say, \def\testit{<something>} and then test to see what <something> is. If <something> is a dimension (e.g, 4in) then I can do \resizebox{4in}...
10
votes
2answers
137 views

Creating an error message

Is there a way to create my own error message that is given if the main font size isn't set to 11pt and then the compilation of the document begin stopped? Update I'm trying to write a package, ...
3
votes
1answer
58 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
27 views

ConTeXt : defining specific behavior with mode

I'm trying to define my own start/stop block, for a conditional compilation with some formatting. I tried to use modes and add a margin rule if the block is to be shown. However, it compiles ...
2
votes
1answer
161 views

Nested conditional glossary terms using Glossaries \ifglsused in \newglossaryentry

If I want to conditionally expand a glossary entry based on or related to another glossary term, I find the conditional \ifglsused{}{}{} statement is very helpful. To satisfy parent modifications ...
3
votes
1answer
83 views

Comment Package: Problem when using German Special Character “ß” (Similar to “ss”) [duplicate]

I am preparing a bilingual document and using the comment package to distinguish between the two languages. When I use the special character ß in a comment environment then I get an error message (...
6
votes
1answer
100 views

tabularx processes its body multiple times; how do I know which cycle I am in?

Assume that I enjoy setting my tables using an \itemized or list-like coding structure: \begin{mytabular}[.5\textwidth] \item head1 & head2% <-- header row \item abc & def \item ghi &...
2
votes
2answers
46 views

how to use verbatim or verb after checking for flag using \ifbool{}{}?

I had no idea that verb or verbatim are not allowed inside \ifbool check. This makes it very limited. I needed to generate code based on a flag. The code to generate happened to have small part of it ...
2
votes
1answer
15 views

Tasks: two column under certain condition

With the help of the task package you can produce easily enumerated lists with two or more columns: if you write \begin{tasks}... everything is printed in one column if you write \begin{tasks}(2)... ...
1
vote
1answer
33 views

If Not Switching When In Environment

I have the following environment to create an invoice. It works perfectly except that the rows do not switch between light and dark gray (they stay light) so I assume that \iflight is staying true. If ...
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
2answers
49 views

LaTeX3 RenewDocumentCommand for cite with an optional argument for punctuation

When working with citations there are many distinct ways the citation must be incorporated within the text. Even when you work exclusively with number formats (this example excludes Author year style ...
1
vote
1answer
43 views

pgfkeys and ifs

I'm still looking for a viable solution to have "conditional pictures", or pictures, where I can enable and disable certain parts of the pictures with styles (very much like beamer overlays). My aim ...
3
votes
1answer
37 views

How to place a enumerate environment within an if statement?

Why does the following minimal working example produces an error unless the enumerate environment is removed? Is there a simple workaround? \documentclass[10pt,presentation]{beamer} \newif\...
2
votes
2answers
52 views

Conditional preamble and pstricks problem \psTilt and \PstLightThreeDText

Look at the following MWE. \PassOptionsToPackage{export}{adjustbox} \documentclass{article} \usepackage{fancyvrb} \usepackage{graphicx} \usepackage{adjustbox} \newcounter{psextern} \makeatletter \...
4
votes
2answers
93 views

A simple macro for optimization problems (ifnum error)

I am trying to create a simple macro for optimization problems that must (as per the publisher) compile with LaTeX2e. I want the macro to look like the example below in terms of usage (the actual ...
5
votes
2answers
65 views

Using \if in a tabularx

I am trying to use \if within a tabularx environment. This works: \documentclass{scrlttr2} \usepackage{tabularx} \begin{document} \newcounter{x} \setcounter{x}{0} \begin{tabularx}{\...
1
vote
1answer
17 views

Suppress Sections with Key in Preamble

How do I suppress a section unless a line of code activates it or suppress it with a line of code that I can comment out? This line of code has to be placed at the top of the document. For context, I ...
16
votes
2answers
991 views

Automatically remove page number if document has only one page (but not if two)

I write a lot of documents (agreements) based on memoir with the article option. Normal pagestyleis plain (page number centered in the footer). Sometimes a document is only one page long, and a page ...
7
votes
2answers
266 views

How to use the total page count in a conditional expression?

I would like to have different footer or page style depending on whether the document has one or more pages. I am not very experienced with TeX programming, so the answers about "Comparing an argument ...
3
votes
1answer
42 views

Counting the number of strings stored in array

I stored a list of strings (command strings) in an array following the answer here: http://tex.stackexchange.com/a/215571/61517 . Now I wanted to access them randomly, and therefore I added a random ...
6
votes
2answers
48 views

Problem with nested 'ifnum' when checking evenness of parameters

I would like to know how to check properly for evenness or oddness within some macro. I have played a little with fp and pgfmath package, but it seems I am not keen enough in TeX to do it properly. ...
4
votes
2answers
91 views

If-if-else-expression using a variable

I am trying to create a document class containing the layout for a bachelors thesis and want to keep it as general as possible. In my title page (which is defined in the document class, not the main ...
2
votes
1answer
31 views

CsvSimple with tabular: set specific number of rows

For a tabular environment with csvsimple I would like to set the number of rows specifically. This example is an attempt to show only the first two rows: \documentclass{article} \usepackage{...
9
votes
3answers
405 views

Do all \if's need to be defined before a nested if?

I have this MWE, which does not compile (Extra \else, Extra \fi) unless I load the showlabels package before the outer \if. (\ifSL@AMS is defined in showlabels.sty.) Is that a general requirement that ...
3
votes
1answer
36 views

Conditionals work, Listings work, but when put together, no [duplicate]

In an earlier question I learned the following code to define conditionally compiled text (for a teacher guide) \newtoggle{teach} \toggletrue{teach} \NewEnviron{teachr} {\iftoggle{teach}{\BODY}{}} \...
1
vote
2answers
50 views

Global variable to macros

I have a eskdi.sty style file where I define two command: \newcommand{\gostorganizatia}[2]{% \ifnum #1 = 1% 1 - text; 2 - logo \gdef\gostorganizatiaopt{text}%% \def\gostorganizatiatext#2{\...
8
votes
1answer
59 views

Generating two pdf versions (based on conditional statement) from same tex file with arara

I teach university courses and my goal is to be able to output two pdf's from the same tex file: A problem set A problem set with solutions I already do this manually by calling \newif and then ...
3
votes
1answer
20 views

how to use \footrue inside environment definition

Based on this clear explanation by @David, I tried to define a command to test if a particular environment was used or not. But I really don't know why the result is always false. MWE \...
4
votes
2answers
37 views

Why doesn't this simple conditional code work in the tufte-book class?

This is follow up question to If Then Else for odd page/even page. Why doesn't this simple conditional code work in the tufte-book class? It shows me Even on every page! while it works fine in the ...
66
votes
6answers
3k views

Which document class is being used?

Is there a way to programmatically determine which document class is in effect? I'd like to be able to write conditional macros that behave differently depending on which document class is currently ...
2
votes
0answers
18 views

How to branch based on the documentclass? [duplicate]

I have a macros.tex file where I keep my macros and I use them with different document classes. I want to skip including some of my macros based on the document class (e.g. if it is beamer). How ...
8
votes
2answers
273 views

Does \InputIfFileExists not work anymore?

For several years I've used the following in most LaTeX documents to input a macros file that lives in different folders on my Mac and my Linux machine: \InputIfFileExists{/Mac/path/macros.tex}% {\...
6
votes
3answers
135 views

Conditional formatting in \newcommand

I'm using the following from a dictionary template: \newcommand{\entry}[4]{\framebox(7,7){}\hspace{.75em}\markboth{#1}{#1}\textbf{#1}\ {(#2)}\ \textit{#3}\ $\bullet$\ {#4}} \entry{Purfling}{pur-...
3
votes
2answers
82 views

How does \if actually get used?

I apologize if this is too newbie or a duplicate, but I've banged my head against it long enough, and searched without success. :( I am trying to use an \if to test for an empty string without ...
4
votes
1answer
159 views

How do I get list of all predefined \if commands in LaTeX?

I was trying some programming in LaTeX and found that \ifx was predefined, since I get an error from this: \documentclass[10pt]{book}% \newif\ifx \xtrue \begin{document} \end{document} Then I found ...
0
votes
2answers
33 views

If condition controlled with a loop variable

I want to print some images according to a variable being changed in a loop: if variable group is 1, then the image should not be printed. But if the value of group is 2, then the image should be ...
6
votes
6answers
190 views

How to write macro with variable amount of text variables

I am trying to make a signature block macro that accepts a variable number of text variables so that I can add or subtract the text without using empty fields "{}" as arguments. \sigblock{0}{2}{...
4
votes
1answer
76 views

avoid logarithm of zero in pgfmathparse conditional assignment

How can i avoid the error message ! Package PGF Math Error: I cannot calculate the logarithm of '0' (in ' 0>1 ? ln(0) : 0'). in the following code? If possible, i want to evaluate the statement ...
5
votes
2answers
93 views

\@ifpackagelater equivalent for babel's lan­guage def­i­ni­tion files?

It is possible to make conditional constructs based on the version ⟨date⟩ of a ⟨package⟩, thanks to \@ifpackagelater{⟨package⟩}{⟨date⟩}{⟨yes⟩}{⟨no⟩}. So far, so good. But this doesn't work for babel-*...
4
votes
1answer
57 views

Choose color based on value for Kpi reporting

I trying to make a report containing colored spheres that should be wrapped in a command and updated dynamically. I have defined af colored sphere that receives a color, a value and a text. The color ...
3
votes
1answer
108 views

Robust handler of arguments with conditionals and complex elements

Context This question is a follow up of the answer of this question Spurious space on moderncv \cventry using \if Problem The problem is that complex content (for example, itemize on the content of ...
3
votes
3answers
137 views

Creating a macro that conditionally turns on an \iffalse and \fi

I'd like to construct a conditional \iffalse and \fi. Specifically, I'd like to define a counter and a macro such that if the counter set to one,the macro would either set an \iffalse, if the argument ...
1
vote
1answer
29 views

Include optional text versions within one file [closed]

I'm still new to LaTeX and I'm not sure if this can be done, so here goes: I've got two .tex files, there pretty similar and instead of updating them individually, which as got to be a pain. I want ...