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

5
votes
2answers
59 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
85 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
21 views

How to insert conditional content in footer if box splits to next page?

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 ...
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 ...
3
votes
2answers
62 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
35 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
522 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
29 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
33 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
206 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 | \...
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, ...
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,...
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]{...
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 ...
2
votes
2answers
88 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
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. \...
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} \...
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
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 ...
2
votes
1answer
44 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} ...
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
47 views

How to make custom definition command without numbering?

I have the following \definition command/theorem (I don't really know much about LaTeX): \newtheoremstyle{definition} {0.8cm} {0.8cm} {} {0.4cm} {\bfseries} {.} {0.4cm} {} \...
2
votes
1answer
40 views

Exclamation mark around variable

What does the exclamation marks (!) around the \@subheader command do in the following? \renewcommand\maketitle{ ... \if!\@subheader!\else\noindent{\trfont{\@subheader}}\fi ... } Can someone please ...
3
votes
0answers
44 views

Using conditionals inside mcexam

I want to write exams where the questions and answers are randomized, and mcexam lets me do almost everything I want. However, I would also like each question to be picked randomly from a group of ...
2
votes
2answers
129 views

Detecting subscript in command argument

I have defined a command low that adds a subscript to an argument: \newcommand{\low}[1]{{#1}_{l_{\mathcal{A}}}} However, if the argument of low contains subscripts itsself (for example in the case ...
1
vote
1answer
32 views

XeLaTeX + \ifthenelse:

I use XelaTeX to produce my CV. Currently, I want to update it and have both Slovak and English CV within one document. I want to have all strings of one language grouped in the preamble, same for ...
5
votes
1answer
129 views

How to compare a string to a cs from a read properly?

The scenario: reading a date in a yyyy-mm-dd form from a file to a cs. This cs later gets compared to a 'current date' macro to write a few args in a specific way to an external file. The current day ...
1
vote
1answer
25 views

How to write if else condition for vertical spacing in newenvironment

I have defined an environment as follows. I would like to have a modification where, it does not add white vertical space if no arguments are provided. \documentclass[10]{article} \usepackage[a4paper,...
1
vote
2answers
241 views

Transpose a matrix and parenthesis

I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs. \transp{A} is the matrix A^T between parenthesis, \transp A is just the ...
3
votes
1answer
52 views

How to properly use new options into \pgfdeclareshape of makeshape package

I'm tryng to make new shapes with the help of makeshape package, and I'm having a lot of problems with new options. Here, an example: \makeatletter \def\pgf@izquierda{izquierda} \def\...
5
votes
2answers
71 views

filecontents: select rows of group to display

I have a file that contains 1,000 rows of product data. I want to select only a specific product type to print in my document. Minimal code in main.tex: \documentclass{article} \usepackage{...
1
vote
0answers
42 views

What is the TeX at symbol / @ for? [duplicate]

Edit Note: I am trying to research "switches" (like \chapter), which led to this question. It might be helpful to tag this "switches". I have seen a lot of documentation that appears to be using ...