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

0
votes
0answers
18 views

Change theorem color using theorem notes in the amsthm package

When defining a new theorem style in the amsthm package, you can specify what's called (according to http://web.mat.bham.ac.uk/R.W.Kaye/latex/thm.pdf) a custom head specification. In there, you can ...
0
votes
2answers
30 views

How to have “preprocessor” flags in LaTeX [duplicate]

C programmers often use constructs like #ifdef foo printf("foo is defined "); #endif #ifndef foo printf("foo is not defined "); #endif to select certain code-paths during the compilation ...
3
votes
2answers
18 views

Conditional within align environment not resolving

I try to use a shortcut for setting matrices with different brackets. My solution works fine in displaymath and equation environments. However, as soon as I try to use it within align, there is an ...
1
vote
1answer
17 views

Printing the bibliography conditionally by hooking \cite to toggle a boolean

I want to print the Bibliography slide only if there were any citations in the presentation. To that end I have redefined the \cite command to include the toggling of a boolean. I tried multiple ...
17
votes
5answers
906 views

Generating multiple versions of a document using options

Before I start, I want to say that I have already read this post and this post I am writing a paper in two languages. I want to write other language version of every paragraphs and title just below ...
1
vote
2answers
77 views

Conditional environment

In a huge document, I would like to use 'env1' or 'env2' environment depending on the value of a global variable 'flagenv'. How could I define an environment 'foo' so that I can write something like : ...
1
vote
1answer
39 views

Conditionals used in a new environment of detection of how many lines of quotation and with the selection of a language in XeLaTeX

I would like that a new environment of quotation/quote detect how many lines a text has, then will increase or decrease the quotation length/margin. For example: \newenvironment{citacao}[1]% {\...
1
vote
1answer
43 views

biblatex - custom citation with conditional clause

I have a custom footnote citation command defined by modifying this answer in the following way: \DeclareCiteCommand{\citejournal} % to get the journal entry ...
2
votes
1answer
27 views

Indentation of footnotes depending on number of digits in footnote marks on the same page

I wanted to adjust the left indentation of footnotes depending on the number of digits of the footnote mark. Thus, footnotes with one digit are aligned a the length of single \parindent (which is set ...
2
votes
1answer
47 views

How do I get permission for exam materials?

MWE \documentclass{minimal} \usepackage{ulem} book = 1 phone = 0 photocopy = 1 internet = 0 tablet = 1 \begin{document} Book, \xout{phone}, photocopy, \xout{internet}, tablet, \ldots\ free or open. ...
0
votes
0answers
24 views

Adding conditional to environment

I want my assignment solutions to appear only when I set a variable to 1. Right now what I have is \documentclass{article} \newenvironment{solution}{\paragraph{\textbf{Solution:}}}{\par} \...
6
votes
1answer
49 views

How to compare number from \newenvironment argument

I am trying to create a new environment as follows \newenvironment{letters}[1]{% \vspace{-3mm} \ifnum #1=1% \else \begin{multicols}{#1} \fi \begin{enumerate}[label=\textbf{...
1
vote
1answer
38 views

How to test a \newif conditional in expl3

Suppose I want to test an \ifSomething conditional that is defined by a package which may or may not be loaded. I know how to do this in plain LaTeX, but I'd like to define an expl3 conditional to do ...
4
votes
1answer
199 views

How to use true/false inside definitions?

Suppose you want to define page style depending on a boolean value. I think both constructions below have equivalent output (or not?), but which is better/more indicated/professional/elegant? \if@...
4
votes
2answers
115 views

Tikz `\ifeven` triggering error

Why the following sample fails to compile in pdflatex when \ifeven is used? It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence....
2
votes
1answer
49 views

How to break a line inside a table cell and add text in the next column ONLY IN CERTAIN CASES?

I am quite new to LaTeX and I am making a wine menu. In some cases I need to add a price for a single glass and/or for a half-carafe... But ONLY in these cases, when such an option exists. I found ...
4
votes
2answers
140 views

Conditional Styling latex on items

I am trying to create an agenda (headlines) frame for my presentation slides. I am reducing redundancy, and define the itemized frame once, and reuse it. But each time, i want a different item in the ...
1
vote
1answer
17 views

How do I insert text in the main body conditional on whether or not a label is defined

I have a set of documents I work with, where I include various files to complete them. So the main document might appear: \section{Section A} \input{SectionText1} \input{SectionText2} \section{...
6
votes
1answer
101 views

Subtleties when using \def and \ifnum conditionals

I am having some difficultly comparing two numbers passed as arguments using \ifnum. Consider the command \def\comparenum[#1,#2] { \def\x{#1} \def\y{#2} \ifnum\x=\y TRUE \else FALSE \...
9
votes
1answer
151 views

Tabular with conditional rows based on content

I would like to define appropriate column types which suppress an entire row of a table if all of the columns (besides the title column, ie the first column) are empty. That is, with the tabular ...
2
votes
1answer
40 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
69 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
20 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
54 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
28 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
42 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
309 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
47 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
31 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
21 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
34 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] ...
5
votes
2answers
66 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
20 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
95 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
50 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
72 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
38 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
77 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
37 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
71 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
68 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
116 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
142 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
26 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
57 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
53 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
603 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 ...