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

1
vote
1answer
14 views

Definition-time expansiton of command line input

I'm trying to make the following code work correctly. I'm using command line call to python to check whether a number is in a list (no clue how to do this in pure LaTeX(?)). I then want to check ...
5
votes
2answers
61 views

Checking if argument is a floating point without breaking on control sequences in argument

Inspired by this answer to test whether an argument is a positive integer, I would like to extend this to floating point numbers. I want to have a macro \TestNumber that checks, whether its first ...
1
vote
1answer
23 views

Missing spaces in conditionals

I'm trying to print two different text if a string contains a ',' or not. The conditional is working, but the text is getting printing without spaces. This is the code for the command: \...
10
votes
1answer
109 views

\ifnum expanding too much - what is happening?

Consider the following example: \documentclass{article} \makeatletter \newcommand\fail[1]{% \ifnum1=#1% <- here a space is missing \expandafter \@firstoftwo \else \...
0
votes
0answers
25 views

How to insert conditional content in footer if box splits to next page? [on hold]

I am currently creating a songbook, and would like to add a small indicator in the footer of right (odd) pages, if the song continues on the next page. As I am fairly new to LaTeX and someone else ...
3
votes
2answers
65 views

Don't take white space into account when checking next character

Taken from this post, I have the following code to define a macro that takes an arbitrary number of arguments and concatenates them with an interleaving symbol (\simeq_{k}) in math mode: \...
1
vote
1answer
16 views

titlesec: display subsectiontitle in header only if there is a subsection

I want to have my header as the section name displayed on the left and the subsection name displayed on the right. This works well as long as every section has a subsection. However if there is no ...
2
votes
1answer
36 views

Custom boolean tag

I've created for my lessonbooks a boolean studentversion who can hide or reveal some teacher stuff under the advice of CarLatex. (see topic : https://tex.stackexchange.com/a/478695/169294) Is it ...
1
vote
1answer
27 views

Hide contents in environment but keep whitespace

I have a custom environment \newenvironment{mathsolution} that contains content that I want to hide based on the switch \showmathtrue and \showmathfalse. The code I have for this conditional is the ...
1
vote
1answer
37 views

Insert something when *not* before a page break

I've tried to find a solution but obviously the right search phrases escape me ... I need to insert something into the document which will be suppressed if it would be followed by a page break. For ...
1
vote
1answer
28 views

Configurate an error for a custom command and conditions

Is there a way to allow custom command to send a log entry who pointed to an error ? I want to create the command \difficulty who convert the four first integers in filled or emptied stars. Here is ...
2
votes
1answer
51 views

cals - switch to turn bold on/off

I have start looking at the package cals. In the documentation (this TUGboat article) the author has defined a handy macro to switch on and off colour in cells: \def\c{\ifx\cals@bgcolor\empty % ...
0
votes
0answers
8 views

Optional Sections in a Document - passing parameters to latexmk or pdflatex [duplicate]

I want to define optional sections for the same document. My plan is to define something like the following command: \optional[audienceA,audienceB]{ % my latex content } so that i can pass a flag ...
3
votes
3answers
59 views

how do I test for a unique string with multiple possibilities?

I'm writing a macro that takes a string and it returns an href based on that string. The string could have 150 different values. My question is how to write this in an efficient way. Using pdflatex. ...
9
votes
2answers
524 views

Question about exercise 11.5 in TeXbook

In answer to exercise 11.5 there is this comment: \def\\{\if\space\next\ % assume that \next is unexpandable What does this comment mean? If \next may be expandable, must we use the following ...
60
votes
3answers
8k views

Understanding \@ifnextchar

I understand the definitions of the \makeatletter and \makeatother commands and also \def and \newcommand somewhat. But, explained in a simple way, what is happening in the following line? \@...
0
votes
0answers
30 views

I want to detect an order placed at the beginning of each theorem

I want to detect an order placed at the beginning of each theorem. \documentclass{article} \usepackage{ifthen,ntheorem} \newtheorem{ex}{Exam} \begin{document} \begin{ex} \LaTeX{} There is the LaTeX ...
3
votes
2answers
79 views

keyval - function for keyB should act dependent on value of keyA - how to do this?

I'm new to LaTeX. I learn and I use article class. I struggle learning working with keyval package: I try to write macro \macro which only uses one mandatory argument where user can provide key value ...
1
vote
1answer
780 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 ...
1
vote
1answer
34 views

Different text on last page

I want to add one of two different texts, depending on whether it appears on the last page. I tried this: \documentclass{article} \usepackage[angle=0, opacity=1, scale=1,position={0,0}]{background} \...
1
vote
0answers
31 views

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error?

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error? How to check if attempts at totally expanding the tokens of an arbitrary sequence of ...
2
votes
1answer
48 views

Adding title to plots in groupplot from file

I am plotting a lower triangular matrix of plots with groupplot, and I would like to add a title to the plots on the diagonal. I generate these plots by reading data using \foreach, and therefore need ...
2
votes
2answers
209 views

How to check if comma list is empty?

How do I check if \myList is empty? Following (is my attempt) prints "NOT empty" when, in fact, the list is empty. \documentclass{standalone} \usepackage{expl3} \begin{document} \ExplSyntaxOn \...
1
vote
1answer
18 views

Problem with testing suffix of \jobname, \c_sys_jobname_str

I have latex files with file names T-BA-DEC-de-0001_Title1.tex and T-BA-DEC-de-0002_Text2.tex. I would like to switch code depending on these file names. Up to now I tried to solve the problem using \...
4
votes
1answer
58 views

Expansion of \ifnum creates a weird \relax token

There was I, procrastinating over some TeX code while I should have been writing my dissertation. The code was working more or less fine (better than the writing, at least), until a mysterious \relax ...
3
votes
2answers
53 views

if then, expandafter condition with 2 parameters - show and hide boxes

In topic: Display Box A or Box B if then condition i have used only one paratemeter Old Rule: condition with TextX \TextX | Show | Hide Value | \...
47
votes
4answers
15k views

How can I check in LaTeX (or plain TeX) whether a command exists, by name?

I'm looking for a LaTeX way to control macro expansion, contingent on some macro being defined or not. I'm looking for something like this (but then actually working): \newcommand[1]{\checkfor}{ \...
5
votes
2answers
97 views

Test whether a string is in a list with variable

Based on this question, I'd like the following \newcommand{\word}{Paul} \newcommand{\butnot}{Joe} \IfStringInList{\word}{George,John,Paul,Ringo}{Beat it}{Roll it} \IfStringInList{\butnot}{George,John,...
3
votes
1answer
58 views

Display Box A or Box B if then condition

I am using datatool and want to display \posterbox A, hide box B if \TextA = value, if \TextA = blank display \posterbox B and hide box A. Box A & Box B are different: Image, item, color, ...
1
vote
1answer
42 views

Conditional compilation depending on the compiler (LuaLaTeX/PdfLaTeX)

I am using plantuml package, which requires LuaLaTeX, but it takes a lot of time to build every time all figures. For that reason I prefer to make a dry run (to get only the pure LaTeX outcom), but ...
0
votes
0answers
26 views

Conditionals: “Incomplete \iffalse” [duplicate]

I'm using a boolean variable called flag to toggle extra text being shown or not in tables. I am following this post: Variables for hiding or showing text in Latex \documentclass[12pt, twocolumn]{...
2
votes
2answers
89 views

How to conditionally draw parts of a MetaPost drawing in ConTeXt?

The basis of my problem is I am making a 14x14 crossword puzzle, I have the data for each of the 196 cells from an outside document, but need only the cells with text inside to have borders. I tried ...
1
vote
1answer
37 views

Tables: Cell Color based on content / conditional cell coloring

I want a table to have red or green cell color, depending on the content: If the content is "a", make it green, if it is "b", make it red. BUT if the content is something else (e.g. in the column ...
0
votes
0answers
73 views

Conditional Latex table: Cell value color based on its value

I would like to create a conditional where values less than 7 are in red and values greater than or equal to 7 are in blue. I would like a result like the one below: Follows my MWE. \documentclass[...
4
votes
2answers
130 views

Colouring column values based on a specific condition. How could I do this?

I am generating a big-table from a csv file using the latex code as given below. \documentclass{article} \usepackage{booktabs} \usepackage{csvsimple} \usepackage{caption} \usepackage{longtable} \...
4
votes
1answer
80 views

Seemingly unused \edef prior to an \ifx mysteriously affects the outcome of the \ifx. Why?

It is my understanding that in \ifx\x\y xx \else yy \fi, \ifx does NOT expand its arguments. If you want \ifx to compare the expanded values of \x and \y, then we need to do the expansion ourselves ...
9
votes
2answers
814 views

\ifcase and macro expansion

There are some code. I strip out unrelated parts and get test one: \documentclass[a4paper,11pt]{extarticle} \begin{document} \newcommand{\mystrA}{% a% \or b% \or c% \else d% } \newcommand{\...
32
votes
6answers
3k views

Redundancy in bib file: conditionally suppress url if same as doi?

Mathscinet gives bibtex entries with both a doi and a url field included. Typically they look something like @article {some-article, […] DOI = {10.1016/j.apal.2008.12.003}, URL = {http://dx....
2
votes
1answer
88 views

Conditionally add options to tcolorbox highlight math style

I have defined the following package: % Configuration \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{eqbox}[2018/01/01 Boxed Equations] \RequirePackage{xcolor} \RequirePackage{pgfopts} \...
0
votes
2answers
29 views

combining ifthen with FPeval - problem

if i use \FPeval{\one}{\csname test1\endcsname} everything is fine. If i use \FPeval{\one}{\csname test1\endcsname+\csname test2\endcsname} in \ifthenelse, then i get en error. \...
6
votes
3answers
2k 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
3answers
61 views

\ifthenelse do nothing

I want to define a table as command. Some lines schould only be printed, if there is a value for it. Because of that I am using the \ifthenelse command. Example: \begin{tabularx}{\linewidth}{|l|X|} ...
2
votes
1answer
25 views

Problem with stored values, macro options, and interaction with other package

Apologies for the rather general title, while trying to sort out a very specific problem: I'm trying to enhance the framework that Alan Munn provided here to represent naturally occurring discourse (...
1
vote
1answer
41 views

Reset stored values at pagebreaks and environment boundaries

Based on this question, I have created a simple macro that prints and stores its argument, and if it is issued again with the identical argument it prints nothing: % !TEX TS-program = xelatexmk \...
1
vote
2answers
135 views

Dynamic Conditional Variables

I'm attempting to create documents of a priori unknown length that is determined by a set of conditions. I'm generating LaTeX variables, including conditional variables, using Python. Within a ...
1
vote
1answer
19 views

Embedding if statements in environments

I am trying to write an environment so that I can toggle on and off the answers to questions on a hand out. I also want the answers to appear red and then the main text go back to black after the ...
1
vote
0answers
40 views

again about appendix to make hidden slides

I tried to put some slides in the appendix, but it doesn't work on my compiler. If I add an appendix after the first compilation it works, probably because the navigation bar is not yet updated, but ...
2
votes
1answer
45 views

Extra blank page is at end of the pdf when use vertical text using tikz

I need some text in the left and right side of the pdf vertically so I use the following code but an extra blank page appears and end please help. \documentclass[twoside]{article} \usepackage{lipsum} ...
51
votes
2answers
44k views

Conditionally hidden slides in beamer

When creating a presentation, I sometimes create extra slides that contain additional information, a more thorough explanation, or an extra plot pertaining to certain parts of my talk. These extra ...
0
votes
2answers
49 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. \...