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

7
votes
2answers
231 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
122 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}} ...
3
votes
2answers
80 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
149 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
26 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
180 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. ...
4
votes
1answer
64 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 ...
3
votes
1answer
48 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 ...
5
votes
2answers
80 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 ...
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} ...
4
votes
1answer
52 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
102 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
128 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
28 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 ...
2
votes
1answer
25 views

defining a global flag to conditionally remove text

Apologies in advance. I deleted many features for my mwe, but I find LaTeX so hard to debug that the act of cutting out creates more errors and triggers more questions so I'm keeping it as it is at ...
2
votes
2answers
39 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 ...
0
votes
1answer
19 views

Print \newpage under certain conditions [duplicate]

I want to define a command which prints \newpage if the remaining free space on the current page is below a certain size, e.g. 200pt. I tried to adapt the snippet to my needs. The problem is that the ...
2
votes
1answer
134 views

Check if a string is just numbers or includes letters

Well, the title pretty much says it all, I'm looking for a way to tell if a string has any letters in it or if it's made up of just numbers. I used biblatex as a tag here because of my question's ...
10
votes
2answers
303 views

How to detect whether “I'm on arXiv.org”?

I write a class. I'm interested in having a different page headers (and eventually make some other small differences) based on whether the class is used on the site arXiv.org or not. Minimal example ...
2
votes
1answer
22 views

Codeblock execution conditional on filename

When making minutes of a meeting, I use two .tex files: an agenda- and a minutes file. The first one is included in the second one with the pdfpages package. Now, whilst the two files are identical ...
2
votes
1answer
35 views

Test if package with given options can be loaded

I need to introduce in my preamble a conditional structure to load a package if its complete version is installed, load its light version if it exists, or load some standard package otherwise. The ...
2
votes
2answers
88 views

Conditional test inside command parameter

I want to call \includegraphics with parameter width= #1\textwidth if the number i have provided thru \mycmd is >= 1 and scale= #1 otherwise. I already saw this: Can I conditionally scale an image ...
2
votes
4answers
74 views

Setting a counter value based on a conditional statement?

I've been trying to google and this seems like a silly thing that should be obvious, but everywhere I look is answering how to use counter values inside a conditional statement, which I can do fine. ...
3
votes
2answers
123 views

Check if two labels are undefined

I'm struggling to test if there are two labels undefined, in order to include some specific files only in that case. Until now, I only needed one condition: workshop, so I was checking like: ...
3
votes
1answer
588 views

Conditional formatting, rounding and postprocessing of a column in pgfplotstable

I want to round p-values in a table to two decimals (for example 0.05), have values less than 0.05 in bold font and have values less than 0.01 to come out as '<0.01' in bold font. Like this (the ...
2
votes
0answers
11 views

Combining \DTLgmeanforall with a conditional in a table created by datatool

I am organizing a list of students an there marks for exams in a .csv Document. These are printed in a tabular environment with the help of datatool. The Table lists the marks an the resulting mean. ...
2
votes
0answers
46 views

How do I let a float know on which column it is placed?

Is there a safe and sound way to let the insides of a float environment know on which column the float is placed? Here is an examples that fails: \documentclass[twocolumn]{article} ...
4
votes
2answers
34 views

ifboolexpr with a list of toggles - true if any toggle is true

I'd like to write a single file with a collection of e.g. questions, but I want to produce various outputs with a different subsets of all questions each. So at the beginning of my file I want to ...
3
votes
2answers
22 views

Conditional formating of a verbatim type argument

I write problem sets whose answer keys contain matlab code. To accomplish this, I'm using matlab-prettifier, but I need to condition the output on whether I'm outputing the problem set questions or ...
7
votes
3answers
81 views

String comparison

\documentclass{article} \usepackage{xifthen, xstring} \newcommand{\IfOne}[3]{ \if\TokenIsIn#1 #2 \else #3 \fi } \newcommand{\IfTwo}[3]{ \ifthenelse{\equal{\TokenIsIn}{#1}}{#2}{#3} ...
2
votes
0answers
20 views

commands / package for target-group-specific creation of documents

Is there a package that allows me to create target-group-specific documents. Basically I have two scenarios: There is an exercise document and each task is initially followed by a solution. In that ...
7
votes
2answers
91 views

How do I define a \ifcommand only if it is not already defined?

To deal with a mess of compilation alternatives with multiple files, I use some \ifSomething switches. But I stumble when I need to check if a switch is defined, and define it if it is not. Minimal ...
4
votes
1answer
36 views

Conditional input of a file depending on a keyword that its contains

I have several files containing each an exercise and to make a document I include a set of this files. Some of them need a special treatment so I need a to make a conditional input command that test a ...
3
votes
1answer
41 views

Check what kind of document class is used with MWE

I try to autodefine the preamble using this and that approach but do get Undefined control sequence. \@ifundefined{\KOMAClassName } in case I write report for scrreprt. for both options. ...
3
votes
1answer
30 views

Testing for oneside or twosided document

After reading basics about catcode I started to use conditionals to autoset the preamble. Surprisingly when sandwiching the command I do get the error Undefined control sequence. \if@oneside, also ...
10
votes
2answers
350 views

tikz, conditional setting of shape parameters

In my illustration I use simplified sketches of stopwatches (timers), which appear in three different "modes": (1) start of interval (coloured green), (2) time in progress (yellow), and time is ...
3
votes
2answers
48 views

Spacing is off with convenience command

I want to define a command called \ksp{} that looks like this: \newcommand*{\ksp}{K_{sp}} However, this function gives an error if it's not invoked in math mode. See example here. ...
1
vote
2answers
47 views

\IfStrEqCase issue using \csname

I want to use \csname inside \IfStrEqCase but I have an error. Here is my code: \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} \usepackage[brazil]{babel} ...
5
votes
3answers
120 views

ifthen with different format numbers

I want to compare the number with different format, but do not get the desired result. \documentclass[a4paper]{article} \usepackage{ifthen} \usepackage{numprint} \npthousandsep{,} \npdecimalsign{.} ...
1
vote
1answer
27 views

Toggle is not checked

I used the answer from here for checking if an environment is placed on another page than the enclosing environment. I want to execute other commands as soon as I am on a new page, but only once on ...
3
votes
1answer
37 views

Can't insert linebreaks and ampersands in math mode using \newif

I write lecture notes and beamer slides using lots of macros containing math expressions. I'd like to be able to format conditional on whether or not I'm running beamer. So I've written ...
4
votes
1answer
39 views

Two column layout with bilingual two tables of contents for each language

Using texlive on Debian Jessie I am writing my application for a position and would like to include versions of the content in both German and English. I would like to have a page right after the ...
2
votes
1answer
73 views

Formatting matlab code within a macro

I know there have been a number of posts relating to this topic, in particular this one, but I find it impossible to believe that it's simply impossible to do the following incredibly basic thing ...
10
votes
1answer
292 views

querying whether a font feature has been activated via a fontspec command

A LaTeX package I'm currently writing makes use of -- and definitely requires -- some of the power of LuaLaTeX. I would like to make my package's user interface -- in particular, the options that need ...
2
votes
1answer
49 views

If algorithm in Latex

I want to create a simple algorithm in my latex document. I have a variable which comes to my latex template from the web-form it can have just two values "yes" or "no", so in case if this value "yes" ...
1
vote
0answers
30 views

Conditional pagebreak depending on position on page

Is there a way to say, add a newline here, if there are less than x empty lines before the next assumed pagebreak? something like \newpageIfThisLineIsLinesAwayFromBottomLessThan{5} I know that this ...
1
vote
0answers
46 views

A method of distinguishing Iverson from other brackets?

Is there a common idiom or method for distinguishing Iverson brackets from "normal" brackets? In all examples I've seen, simple braces [...] are used for both; but in complex expressions, this can ...
18
votes
4answers
1k views

How to determine whether a list of figures is empty, then not show it at all?

I want to check whether the document has any figures so as to decide whether or not to have a list of figures. Is this possible? Feasible without doing something like parsing the lof file? Note that ...
2
votes
1answer
46 views

Selecting source code based on boolean

Is there a way to select source code based on a boolean and not just select text to display. \documentclass{exam} \usepackage{ifthen} \newif\ifanswers \answerstrue \begin{document} \begin{questions} ...
5
votes
2answers
140 views

If command in LaTex

I am writing a project for a course and I want to make each Part to have a different color image on the side. But to do this I have to make a loop (that's what I think) to recognize the Part and and ...