{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
27 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
81 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
69 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
121 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: ...
2
votes
1answer
21 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
0answers
10 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
29 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} ...
5
votes
5answers
149 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
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
21 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 ...
2
votes
0answers
19 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
88 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
35 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 ...
7
votes
3answers
77 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} ...
3
votes
1answer
36 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
28 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 ...
3
votes
2answers
46 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
45 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
117 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
25 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 ...
2
votes
2answers
32 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 ...
3
votes
1answer
36 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
36 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
72 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 ...
2
votes
1answer
47 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
29 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
41 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 ...
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 ...
0
votes
0answers
26 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 ...
11
votes
4answers
852 views

How to print “Spring” if in month is in Jan-June? Otherwise “Fall”?

I teach classes and in my notes I have "Fall 2015" during fall semester and "Spring 2016" during Spring semester. I can use \the\year for the year. But is there something like \the\season for ...
5
votes
2answers
117 views

Choose documentclass according to condition

I would like to choose the documentclass according to a value. For instance, something like this \newcommand{\mode}{0} if (mode is 0) then \documentclass{...} else if (mode is 1) then ...
3
votes
2answers
75 views

problems with ifthen and tabularx

I have a problem related with ifthen and tabularx packages. Here is a minimal example: \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage{tabularx,colortbl} \usepackage{xcolor} ...
3
votes
1answer
39 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
24 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
17 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
32 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
69 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
50 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
40 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
33 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
42 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
83 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
67 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
225 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
46 views

Conditional complex column type

\documentclass{article} \usepackage{array} \usepackage{ragged2e} % \newcolumntype{M}[1]{>{\hspace{0pt}\raggedright\arraybackslash}m{#1}} % ...
5
votes
1answer
60 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
239 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} ...