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

Filter by
Sorted by
Tagged with
2
votes
3answers
47 views

How to check if the argument to a macro is a specific string?

I need to be able to pass [ ] (brackets with space in between) to a \def and check whether the \def's parameter contains [ ] (rather than something else). \begin{document} \def\bptoks{[ ]} \def\bpdef#...
1
vote
1answer
28 views

\ifthenelse statement inside includemedia options

I try to enable / disable some options for my 3D view with \ifthenelse. \documentclass[fontsize=12pt,paper=a4]{scrbook} \usepackage{media9} \usepackage{graphicx} \usepackage{ifthen} \begin{document} ...
3
votes
1answer
53 views

Mysterious horizontal space when using conditional macro

In order to deal with both burdensome expressions $K$-vector space and $K$-vector space $E$ at once, and this in both text and math mode alike, I defined a fine working shortcut taking two arguments, ...
1
vote
1answer
25 views

Ifoddpage statement inside switch case

Continuation of topics tcolorbox: specific width and height settings for odd and even pages and Distance Variable in front or back pages. I'd like to set lengths conditionally based on the expansion ...
6
votes
2answers
158 views

Is there a way to perform “if” check only once instead of every iteration in a loop?

The \zNonZero is equal to 0 if #1 is 0, but is equal to 1 if #1 is greater than 0. The problem is, the if check inside the loop is performed every iteration: I need it to be performed only once (for ...
1
vote
1answer
71 views

How to define a macro with a functional character?

I want to form a macro which will enable me to get the following result. Let's say I want L, M & N to be active in my document. And I also want character p to be functional in the code such that ...
2
votes
2answers
80 views

How to make an array of tokens?

I'm trying to code a function with the help of some characters in Devanagari script. I've replaced the characters with some other characters of a totally different script. This is the MWE to do it. \...
0
votes
2answers
29 views

conditional variable not set true inside a macro

In my class file I have this code: \newif\if@showsolution \def\solutions{\@showsolutiontrue} \if@showsolution \newenvironment{solution}{\textbf{L\"osung:}\\}{} \else \excludecomment{solution}...
5
votes
2answers
167 views

Conditionally replacing sequences of characters

I am a noob in the area of plain TeX. All commands which are used in this question are written with the help of answers on this site and the 'LaTeX Wikibook'. I want to change keyboard mapping using ...
2
votes
2answers
27 views

How do I make conditions based on list options?

Specifically, I need to write a command which changes its behavior if the option wide is turned on... So I need some kind of condition if wide is on then do this, else do that. Can somebody point ...
0
votes
1answer
48 views

Set path using if / else

Depending on the previous text I need to set e path to folder 1 or folder 2. With just one folder everything worked fine, but with the condition it doesn't. What am I missing? \newcommand{\nc}{text-...
5
votes
1answer
58 views

Why is \unexpanded not respected after an \if?

I was surprised to find that the argument of an \unexpanded is expanded if the \unexpanded is within the first two tokens after an \if. Using Knuth TeX's \noexpand instead works but I am curious where ...
1
vote
1answer
48 views

Conditionally set bibliography title

I am writing a class and would like to offer the option of changing the bibliography title as a class option. If no title was given I would like to just use the default one. Unfortunately I can't seem ...
3
votes
0answers
21 views

Prepending digits to section numbers in ToC

I have more than ten sections that I want to list in the ToC as the following: Which means I need to prepend 0s to sections of \ifnum\thesection<10. How do I do this in the ToC? MWE : \...
2
votes
2answers
52 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
63 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
26 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
116 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 \...
1
vote
1answer
17 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
37 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 ...
3
votes
2answers
68 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
39 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
64 views

Macro to switch bold on and off in table cells

I have start looking at the package cals, so my examples are connected to that packages. However, my questions are general, applicable under other environments, too. In the documentation (this ...
0
votes
0answers
9 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
529 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 ...
0
votes
0answers
34 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
86 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
40 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
2answers
221 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 \...
5
votes
1answer
60 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
56 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 | \...
3
votes
1answer
60 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, ...
5
votes
2answers
98 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,...
1
vote
1answer
46 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
27 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]{...
1
vote
1answer
41 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
83 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
132 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
83 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 ...
2
votes
2answers
99 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 ...
0
votes
2answers
33 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. \...
2
votes
1answer
97 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} \...
2
votes
3answers
66 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
26 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 \...