Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [conditionals]

{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}.

2
votes
1answer
37 views

How to globally change the value of an if (so it can be changed in a tabular)

I'd like to toggle between two values each time a macro is called. I can make it work, unless it's in a tabular. I'd like to make it work in a tabular. I assume this has something to do with scope. ...
1
vote
1answer
54 views

Tikz: incomplete \iffalse error with pgfmathparse

I'm trying to create a pie chart like this one (link), but when I use the code I get an error with this code: \pgfmathparse{(-\midangle<180?"west":"east") } \edef\textanchor{\...
0
votes
0answers
18 views

pdf@strcmp doesn't work with class StringOption

I'm writing a package and trying to use conditionals on a string option defined as follows. \RequirePackage{kvoptions} \DeclareStringOption{lang}[english] \ProcessKeyvalOptions* I have ...
2
votes
3answers
48 views

Conditional Execution of a Command based on used Documentclass

I use KOMA-Script-classes almost exclusively and because i don't like, that it always prints several elements of the table of contents in bold letters, i have included \addtokomafont{chapterentry}{\...
0
votes
1answer
24 views

Prompted \read input when there should be none

I can't understand how \read# to \sth or \ifeof are supposed to work. If an stream not in [0,15] is used, or the stream is closed, or doesn't exist, it will prompt you to manually input the num if you'...
0
votes
1answer
25 views

\ifx can't match \read cs

One .dat file contains periods (beginning and ending dates on separate rows) which are to be read once then compared with the date, and if it matches it goes \immediate\write\fileB{\Date{} #2, #3} in ...
1
vote
1answer
39 views

Conditionals that use \ref

Consider the following minimal example: \documentclass[a4paper,12pt]{article} \begin{document} \section{First Section}\label{sect_1} Question: Is this Section \ref{sect_1}? IFX Answer: \ifx\ref{...
5
votes
2answers
267 views

Problem with nested if statements

I'm trying to use some nested if statements to decide if a file exists and what kind of loadings are possible: \IfFileExists{./emoji.sty}{ \ifxetex \usepackage[bw,font=seguiemj.ttf]{emoji} \...
1
vote
2answers
44 views

How does the if-condition work?

How can I use an if conditonal in LaTeX? If the conditon is true I want to execute a code and if not then continue. Sorry for my example code and English. I dont know how to do it. \documentclass[...
0
votes
1answer
24 views

Error with ifthenelse

The code \newcommand{\variableBackgroundColor}{% \ifthenelse{1=1}%\(\boolean{Colle} \OR \boolean{DM}\)} %then {black!10!white} %else {white} } \tcolorboxenvironment{private_exo}{boxrule=...
0
votes
0answers
19 views

Write text only if Execute Metadata is not empty

I use the catchfilebetweentags package to get specific content from a common .tex file. MWE for the file where all content is stored (called master.tex): \documentclass[]{article} \usepackage{...
4
votes
1answer
31 views

check if a bib environment is defined

I am using the \defbibenvironment command for code like this \defbibenvironment{numbered+bold}{...} which is later used in \printbibliography[env=numbered+bold, heading=none, resetnumbers=true] ...
4
votes
2answers
52 views

How test value of a command with `\ifthenelse` and `\equal`?

Revised question (Trying to follow suggestion in comment by David Carlisle.) I want to assign a string as the value of a command and then take alternative actions (by means of ifthenelse) according ...
0
votes
0answers
11 views

Extra White Space after iftenelse in Title [duplicate]

To begin, here is a MWE: \documentclass[12pt]{article} \usepackage{float} \usepackage{tikz} \usepackage{subfig} \usepackage{ifthen} \begin{document} \newcommand{\titlename}[1] { \ifthenelse{\...
1
vote
1answer
17 views

Conditional based on displaystyle

I'm trying to write a macro that returns different things depending on it if is used in a displayed equation or if it is used in an inline equation. Something like this, I assume: \newcommand{\foo}{% ...
4
votes
3answers
87 views

Trying to get \zap@space and \lowercase to work on string comparison

I am trying to do a non-case-sensitive check on two strings that may or may not have spaces in them. I have googled this and there is quite a lot of literature on either of these problems, but I can't ...
1
vote
1answer
44 views

using includegraphics conditionally

I want to print a different logo sequentially for 4 years, and then resuse them. My script is not working... any idea? \documentclass{article} \usepackage{pgf,calculator,ifthen} \MODULO{\year}{4}{...
3
votes
3answers
68 views

Macro that calls ifthen's \equal doesn't work in section heading. Why?

In the following MWE, I have a macro \mytest that tests whether its argument is a or b, returning "yes"/"no", respectively. This macro uses (a) \ifthenelse and (b) \equal from the if then package. ...
2
votes
1answer
31 views

Loop newcommand with variable arguments

Following my previous question, I would like to know how to have variable inputs for a newcommand in order to do the following \documentclass{article} \newcommand*{\repsum}[VARIABLE NUMBER]{ \...
1
vote
3answers
57 views

How to properly use \DeclareOption within a macro

Using \ifthenelse statements I've defined a macro that prints it's value as long as it is different from the value of the previous time it was used. \RequirePackage{xifthen} \def\storedval{} % create ...
0
votes
1answer
29 views

Multiple nested \ifdefined statements

I use the "variables" in my header and would like to shorten the code by combining \ifdefined\@@author and \ifdefined\@group. Searching the repository for "ifdefined multiple arguments" etc. didn't ...
2
votes
2answers
54 views

Check number of arguments in a command

I know how to create if\else structures in LaTeX using \newif and \else. What I'm wondering is whether there's a way to check against the actual arguments given to a command. For example, if I have a ...
1
vote
0answers
65 views

How to check if last displayed content was displaymath / minipage ends on displaymath?

Is there a way to check if a minipage ends with display math? Or more generally, if the line above was a displaymath? Background: I defined a command for a minipage-environment that fixes alot of ...
8
votes
1answer
114 views

Distinguish active characters from non-active pendants with expansion-methods only?

(Please take the following question rather for a moot point than for an everyday-problem.) Is there an expandable method for distinguishing an arbitrary explicit non-active character token from its ...
3
votes
3answers
131 views

how can I compare strings using the if statement without package?

For example, \newenvironment{genPage}[2] {\clearpage\thispagestyle{#1}\normalsize\bfseries \if#2=c \centering \fi } {\newpage} \begin{document} \begin{genPage}{plain}{c} ...
1
vote
0answers
21 views

Conditional execution based on existence of key/value pair in datatool

This question is a confirmation and a follow-up using the code from this question I'm preparing a template, which relies on some texts which will be provided in a CSV file (ex, disclaimer text, large ...
1
vote
1answer
54 views

lstlisting teacher/student version

I would like to hide some parts of a lstlisting code and change it into a white rectangle (for example) for my students. Besides, under a boolean condition, I would like to come back to the version ...
1
vote
1answer
15 views

Adding a glossary entry whose name is a macro that uses \equal{}

I have defined some commands that use \equal{} to test if an argument is empty or not. I would like to use these commands as names in a glossary. However, the following minimum example does not work ...
1
vote
1answer
49 views

Overwrite dcases* to work inside align (to use mtpro2 braces)

This is a direct follow-up question from my previous one: Overwrite matrix to work inside align (to use mtpro2 parentheses and braces). Although this question is self-contained, I encourage ...
3
votes
3answers
568 views

Testing for a “if not defined” boolean

How can I test for a not defined boolean? I want to have \usepackage{xr-hyper} \usepackage{hyperref} \providebool{is_single_book} \booltrue{is_single_book} in my main.tex and in each of the ...
0
votes
1answer
56 views

Conditional Macro: if include &, then A; otherwise, B

I want to make a conditional macro. I currently use the line \def\[#1\]{\begin{align*}#1\end{align*}} since I often use align, and don't want to have to type \begin{align*} ... \end{align*} every ...
2
votes
3answers
146 views

Identifying if macro is an alias

I use a def as an alias like so: \def\alias{\foo} later on I would like to check if \alias is an alias for foo. (X is an alias of Y means the current definition of X is def\X{\Y}). See the MWE ...
1
vote
1answer
69 views

How to conditionally rotate a label in TikZ?

I want to create a macro that puts a label in a TikZ \draw environment; that rotates with the law: alfa<180, then rotate=alfa, else rotate=alfa-180. My code (where #7 is the angle, and #6 is the ...
1
vote
1answer
53 views

use jobname to “pass parameters”? [duplicate]

Yet another question about passing parameters when compiling. I thought I had a good (for me) solution, by compiling with different jobnames and do conditional compilation on the basis of the jobname, ...
3
votes
1answer
46 views

Prevent tikz node intersection

I'm making a macro to generate a tikzpicture depending on the arguments passed into the macro. I want to be able to draw a \node only if it won't intersect with a specified x coordinate. So say my ...
0
votes
0answers
84 views

Which LaTeX editors support conditionals or branches?

LyX has branches, which designate portions of a document to compile only when all branches covering those portions are active. I understand from @scottkosty that the LaTeX equivalent is conditionals. ...
1
vote
1answer
42 views

Define Command/Macro with boolean flag

I'd love to have a command with a boolean flag. That flag is supposed to be used in a conditional statement. I'd love to have something like this: \command -> false \command[flag=...
0
votes
0answers
32 views

Usage of While-do constructs LaTeX

I'm curious, when reading about the ifthen-packages I've come across the syntax of while-do statements. What are they used for ? For example this piece of code from the documentation (this is copy-...
4
votes
1answer
36 views

Conditional to test whether in an itemize

I'm using LaTeX to write manuscripts for plays, I've been looking a bit into conditional expressions. The reason is that I want comments in the manus, and I currently have two different commands for ...
2
votes
5answers
131 views

How can I condition on the last token?

I would like to write a command \foo which, for the sake of simplicity, does just one thing, which is make sure its argument ends with a dot. Thus both foo{hello world} and foo{hello world.} expand to ...
2
votes
2answers
48 views

Conditional If-then-else/xIf-then-else Packages

I'm currently working on a presentation about the packages mentioned in the title. The problem I have is, I don't really understand why anyone would use conditional statements in a LaTeX document. ...
1
vote
1answer
37 views

\ifdefempty against linebreaks [duplicate]

I use LaTeX for text processing in conjunction with a template parser. I want to do things, when there would be text to print. So I have \newcommand{\zahltext}{% %% here may be dragons, this is ...
6
votes
4answers
160 views

nesting macro identifying string length 1 using xstring ifthen packages

I would like to write a latex macro \p which given input X returns X or (X) depending on whether X has character length 1 or not. Moreover, I want to be able to nest applications of \p. E.g. I want ...
7
votes
2answers
260 views

If/Else Statement Not Working When Trying To Reformat Subsections

I want my LaTeX code to number sections and subsections like (FYI: I'm using article not chapter or book): 0 Introduction (section) 1 A (section) 1.01 A1 (subsection) 1.02 A2 (subsection) ... 1.10 ...
17
votes
3answers
475 views

About what TeX does after it finds commented conditionals with ltxdoc

When I thought I understood the concept of the doc package, LaTeX proved me wrong. I was trying to make a file to use with ltxdoc when I realised I could not use conditionals in the preamble because ...
5
votes
1answer
103 views

Conditional \if@mainmatter don’t have any effect

I try to make a command who have different behavior depending if it is executed in mainmatter area or not. So I use the \if@mainmatter command as described in the topic Checking the mainmatter But, ...
3
votes
1answer
91 views

How can I prevent \ifnum to be ignored?

So I have the following code: \newcount\x\x\i \ifnum\x<3 \advance\x1 \fi \the\x \bye which I call from the command line with pdftex '\def\i{9}\input test.tex' This puts out 10 (or \i + 1), ...
1
vote
4answers
48 views

Custom \if command to check for multiple conditions

I'm creating a document class for bachelors' and masters' theses at my faculty. It's almost ready and tuned to this year's official requirements. However, things may change in future: for example, the ...
6
votes
2answers
207 views

Using \ifthenelse inside an option

I'm trying to create a \newcommand for images which takes width as an optional parameter. This is my current command which works (but doesn't use the parameter): \newcommand{\introimg}[3]{ \begin{...
4
votes
4answers
246 views

Hide/Show Solution for Problems

There are too many options for "Solution/Answer" environments which we can use and I am adopting this one for my "big" project that I am doing. At the moment, it looks like the easiest one for me to ...