Stack Exchange Network

Stack Exchange network consists of 175 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
2answers
37 views

Code seems to have no effect when inside `iftoggle`

In this answer I have been suggested to patch hyperref’s automatic pdfauthor metadata handling mechanism as follows. The goal is to have PDF metadata work with authblk and multiple authors. \...
2
votes
1answer
28 views

Conditional output dependent on --shell-escape option value

I would like to print the git revision of the document with the latexgit package, which requires the --shell-escape option to work. As this feature is very optional for building the document, I would ...
0
votes
0answers
22 views

Access to Testable Environment variables

I've figured out how to access environment variables, I can test on a value. I can't test on the value of an environment variable. I thought it best to include my test case: \documentclass{article} \...
3
votes
1answer
82 views

Is there latex3 work being done on a boolean case statement?

Various languages have constructs like select; when <expression 1> then <action 1>; when <expression 2> then <action 2>; ... when <expression n> ...
6
votes
1answer
118 views

How to save boolean values into the aux file? (using e.g. etoolbox's toogles)

I want to use etoolbox's toggles to achieve the following: In the preamble a toggle is created, during typesetting the document its value might change and at the end I want to write the value to the ...
4
votes
1answer
46 views

Auto append prefix to tcolorbox's title

I would like to have a tcolorbox environment that appends the prefix "Note:" to the given title. Thus, using the option title={My Title} to this environment would produce a title of Note: My ...
1
vote
2answers
40 views

Use of graphicspath in class

I am using my own class MyReportClass to write a report. I have taken inspiration from this answer to redefine the \includegraphics command inside the class in order to use the example-image-a in case ...
0
votes
0answers
22 views

Is it possible to make an “if” section in TeX which is conditional on an environment version being set?

I'd like to produce two slightly different versions of a document. One will include confidential information, the other will be slightly redacted. Is it possible to use an environment variable and ...
3
votes
0answers
85 views

Why do I get an “Incomplete \ifx” in this MWE?

I am trying to redefine the figure environment, which works fine in general. However, if the body of the figure environment to be replaced includes a tabular environment inside a conditional ...
1
vote
3answers
79 views

@nameuse with value \relax in conditionals

This is a follow-up to this question: @nameuse as conditional where i asked about how to use \expandafter if i combine \@nameuse with \ifx. However, in my real-life example, i use \relax as a default ...
4
votes
2answers
133 views

@nameuse as conditional

Please consider the following, non-working, example: \documentclass{standalone} \makeatletter \parindent\z@ \@namedef{blafasel}{foo} \def\foo{foo} \def\bar{bar} \makeatother \begin{document}...
4
votes
2answers
42 views

Defining a command part by part

Let's say we have a command \foo with 1 argument. Can we produce a command \setfoo{aaa}{<some thing>} which redefines \foo to: if an argument of \foois equal to 'aaa', do ; otherwise do what \...
0
votes
0answers
14 views

Conditionally print VC macros

How might I go about conditionally printing a macro? I know this exists for graphics (\includegraphics) and there's ifdraft for the rest. For example, using fancyhdr I have the following (simplified) ...
3
votes
1answer
57 views

Node label switching on condition

I try to create a dynamic graph where a node move along the axis line. When a condition on x is filled (X>1.8), I need the labels to be translated as i tried to do it in the following MWE \...
3
votes
1answer
57 views

Lost global definition after \ifthenelse using package xifthen

I created my MWE with the help of this Q&A. MWE: \documentclass{article} \usepackage{xifthen}% provides \isempty test \newcommand{\GlobalDef}[1][]{ % \ifthenelse{\isempty{#1}} % {} % ...
0
votes
0answers
15 views

Translating a book: supporting both languages in a single project

I am currently translating a project from english to spanish. The project is organized by using subfiles. I want to move all .tex files to a 'en' folder, while creating a 'es' folder where I would ...
0
votes
0answers
25 views

In LaTeX is there good way to optionally redact certain sections of a document? [duplicate]

I have a project which compiles a document written in LaTeX, compiled to PDF with xelatex. I would like to automatically produce 2 versions of the document: A "confidential" version which all ...
4
votes
2answers
152 views

csvsimple vs. conditional row coloring

I've a CSV file what I want process with csvsimple. My desire is to color some rows based on a conditional (one specified column has bigger value). Here is an MWE: \documentclass[12pt]{article} \...
4
votes
1answer
131 views

How to add conditions in LATEX macros?

I would like to create custom macros with conditions. For example, I would like to add an "if-condition" to a macro that I created to write derivatives of any order in relation to a single variable. ...
2
votes
1answer
25 views

Question: Something's wrong--perhaps a missing \item

My code is as following: \begin{denotation} \iffalse \item[符号1] 解释1 \item[符号2] 解释2 \fi \end{denotation} I have \item in my code. What's the real problem?
1
vote
1answer
20 views

How do I only call \maketitle if \title{} has been called

I'm merging 5-10 pandoc generated tex files using the docmute package. The individual files build, however when I \subimport or \input them into my main document I get an error: ! LaTeX Error: No \...
0
votes
1answer
47 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
35 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
19 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
19 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 ...
19
votes
5answers
964 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
87 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
47 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
49 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
56 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
55 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. ...
6
votes
1answer
59 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{...
2
votes
1answer
43 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
244 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
127 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
57 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
146 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
21 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
114 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
172 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
83 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{\...
2
votes
3answers
57 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
29 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
43 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
368 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
54 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
41 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
23 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{...