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
0
votes
1answer
28 views

\if\subject\subjectold returns false even though subject and subjectold should be the same

I am currently working with conditionals and I am currently stuck because even though the conditional argument should not be used (e.g. \subject should be "B", \subjectold and \bio too), the test ...
1
vote
1answer
66 views

\ifnum of variable

I want to check if a variable is less than 0 in a tikzpicture environment. I've read it can be done with \ifnum. My code, simplified, is \begin{center} \begin{animateinline}[loop, poster = first, ...
1
vote
1answer
55 views

Koma variable as boolean

I would like to have a komavar that is of type bool and then depending on whether the option is set or not I would want to import a package. Basically I'm looking for something like \documentclass{...
2
votes
1answer
51 views

Conditionally resuming a list

I have defined an environment viz. Examples in the following way: \newtheoremstyle{myexcstyle}{3ex}{3ex}{}{}{\scshape}{:}{.5em}{} \theoremstyle{myexcstyle} \newtheorem*{exmps}{Examples} \...
0
votes
0answers
49 views

Why does \if in a tikzpicture evaluate to true for \if 33 \empty? [duplicate]

I have the following code: \documentclass[11pt]{article} \usepackage{tikz} \begin{document} \newcount\x \x=-1 \begin{tikzpicture} \foreach \percentA in {33} { \if \percentA \empty \else \...
0
votes
0answers
20 views

Printing Instructor's (all items) vs. Student's Solutions Manual (odd items only) (Take 2):

This is a rephrasing of a previous question I posed. I do thank the individuals that have helped to resolve it. I apologize for the lack of clarity in my previous post. So, here it is again... I ...
2
votes
1answer
71 views

Mutually-exclusive TikZ .is choice keys

My TikZ drawing package has a command that will draw a "simple beam", which is basically a rectangle between two arbitrary points. The code below is the relevant part from the package: % arara: ...
2
votes
1answer
30 views

How can enter list of names that change in every page

I have list of names : Jhon Doe name 2 ... and I want to put them in top left corner. How to put these names in order on each page automatically. background package or eso-pic tikz with fancyhdr ...
8
votes
4answers
175 views

How to safely check by means of expansion-methods whether a list of tokens contains a token which is defined in terms of \outer?

I take the following question for a moot thing. Nonetheless it makes me sick that I don't see a good and robust solution myself. ;-) Assume something like this: \def\unfold{\umbrella My bald head ...
1
vote
4answers
125 views

Why doesn't this \ifx test if the macro is empty?

Consider the following MWE: \documentclass{standalone} \newcommand{\myname}{ss} \newcommand{\mycmd}{\ifx\myname\undefined{Please enter your name}\else{Professor \myname}\fi} \begin{document} \...
15
votes
3answers
11k views

How to test if a string is empty

I tried several thing to test if a parameter is empty or equal to a specific carater. How should one proceed ? By the way, what is the best way to have conditionnal code on a parameter who can have ...
1
vote
1answer
35 views

@currenvir check returns false

Good day, I'm trying to check for the solution environment and close it if it's open. I have tried this answer and checking directly for the @insolution toggle that is set by solution environment ...
2
votes
1answer
49 views

Invoking functions indirectly (using a string) in BibTeX

Is it possible to do indirect function calls in BibTeX styles, i.e. to get the function name from a field in the .bib? EXECUTE would be able to do that but these statements don't work within functions(...
3
votes
2answers
69 views

etoolbox: ifdefvoid check for empty lines

I designed a system that reads a number of variables and, depending on the definition creates a text (either text "a" and the text contained in the variable (macro), or an alternate text "b" when the ...
4
votes
3answers
126 views

If else statement in a tabularx

In the MWE below, I'm trying to build a table with 6 columns if statement is true. \documentclass{article} \usepackage{tabularx} \newif\iftest \testtrue \begin{document} \begin{table}[t!] \...
4
votes
2answers
87 views

Alter arguments in custom command

I would like to modify my func command in such a way that the domain/codomain arguments can be altered, e.g. so that arg=R^n yields $\mathbb{R}^n$. \documentclass[a4paper]{article} \usepackage{...
0
votes
1answer
100 views

Why does \ifdim work here but \if doesn't?

I'm very new to LaTeX, and need to compare a length I've defined with a default value (and set another length accordingly). Consequently, I'm exploring the murky (to me anyway) world of LaTeX ...
0
votes
1answer
56 views

Check whether a command from package is used and modify the style

I am trying to create a pagestyle, where \guideNameA is mandatory and if \guideNameB is used then I want modify the page style accordingly. Also I need to modify the document content by checking ...
2
votes
3answers
124 views

Conditional yshift in \newtcolorbox

I'm currently writting a book in xelatex, and in the progress of creating a couple of highlight boxes, I've encountered a problem. Some boxes have titles and some doesn't have, because of that, the ...
0
votes
2answers
71 views

How to create sections and input file provided a different file exists?

My Issue: I have to compile a LaTeX file which contains a series of possible outcomes for a series of possible case studies. As not all the outcomes I list in the first \clistmapline have a case ...
1
vote
1answer
33 views

LaTeX code for formatting sequential equation references differently from non-sequential references?

Consider a simple macro, \Eqs{ref1}{ref2}, accepting references ref1 and ref2 as arguments. In the current environment, the commands \ref{ref1} and \ref{ref2} expand to simple unformatted integers, e....
10
votes
2answers
200 views

Splitting macros to individual tokens/characters, with catcode (to debug conditionals)?

Consider this MWE, modified from ifthenelse equal string comparison fails: \documentclass{article} \edef\test{german\relax} \edef\curentry{\string german\relax} \typeout{test: \meaning\test, ...
1
vote
1answer
62 views

Deactivate Hyperref conditionally if no Hypertarget exists

Is there a reasonably easy/effective way to deactivate a hyperlink conditionally using the hyperref package, ie the hyper-target doesn't exist in the LaTeX output ie, display no hyperlink for this ...
1
vote
1answer
49 views

pgfplots adjust style given string/class value from a table `scatter/@pre marker code/.code `

Similar to this question, I would like to set the style (color/shape) of scatter points, depending on the value of a certain column read from a table. \documentclass[tikz,border=3mm]{standalone} \...
5
votes
1answer
169 views

Text formating depending on conditions

I have some conditions which are stored in boolean variables, such as \bool_new:N \l_word_numbered_bool \bool_new:N \l_word_lowercase_bool \bool_new:N \l_word_centering_bool I need to format words (...
4
votes
3answers
225 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 ...
2
votes
3answers
72 views

command definition: check if input is empty or greater than zero

For some reason this workaround works: \IfStrEq{#1}{\empty}{\def\tmp{0}}{\ifnum#1>0\def\tmp{1}\else\def\tmp{0}\fi} \ifnum\tmp=1 TRUE \else FALSE \fi but this combination doesn't \ifnum\...
2
votes
2answers
59 views

switch string/commands based on “random” values to produce random cards

Update Or is there a way to generate random number between 1 and 52 using lcg package, then associate it to one of the 52 cards from the pst-poker package. Which might be easier to achieve? OP ...
0
votes
0answers
32 views

Show underlines in view mode, but omit when printing?

I would like to know if there is a way I could display URLs with underlines when being viewed in a PDF, but to omit them when printing. I saw the following code example from this answer: \usepackage{...
6
votes
2answers
122 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 ...
2
votes
1answer
34 views

Environment which behaves differently depending on the column it's in

I'm trying to create an environment within a twocolumn document which behaves differently depending on which column it's in. Specifically, I'm making a tcolorbox, which is supposed to stretch to the ...
2
votes
1answer
65 views

Why is comparison between number and numeric argument not working in \ifnum and \ifdim conditionals?

I was modifying \@ssect command to edit \section* appearance. First I passed a further argument to \@ssect \def\@ssect#1#2#3#4#5#6{%... then I edited the dependencies in \@startsection by modifying \...
2
votes
2answers
106 views

How to get Tikz to ignore drawing on some conditions?

I am trying to develop part of my code, under the condition that if some variable inputs of the functions are equal to zero, tikz do not draw some parts of the drawings. Here is a MWE (although the ...
20
votes
2answers
377 views

Expandable test for an empty token list—methods, performance, and robustness

With ε-TeX, the go-to method for testing if a <token-list> is empty is the following test: \if\relax\detokenize{<token-list>}\relax % empty \else % not empty \fi The method ...
1
vote
2answers
67 views

pgfplotstable: correct way to generate new columns using custom commands in a table that can be plotted with tikz

Sorry if the title is too big, but I didn't know how to express it as something specific, I try to generate new columns in a table using custom commands, for instance: \documentclass{scrbook} \...
4
votes
1answer
2k 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 ...
2
votes
2answers
60 views

Macro changing a string depending on letter case

I would like to define a new mathmode command such that: the input is a string s; the output is the same string where the font of each caracter has been changed depending on whether the character is ...
6
votes
1answer
93 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 ...
2
votes
1answer
227 views

How to Display Conditional Probability in LyX?

I am looking for a way to show $P(\theta|X)$ but with the proper spacing?
4
votes
2answers
225 views

How can I use \if \then \else with \@ifclassloaded{}

I wrote a package that uses the \@ifclassloaded{} command to handle the document class, like, \RequirePackage{pgffor} \makeatletter% \@ifclassloaded{book} {% <code block> } \makeatother% \...
0
votes
1answer
42 views

Test if one of two macros not empty

I define two new macros and commands to change their content with the following commands in a .cls-file. \newcommand{\@mymacroa}{} \newcommand{\mymacroa}[1]{\renewcommand{\@mymacroa}{#1}} \newcommand{...
3
votes
1answer
36 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 : \...
1
vote
0answers
90 views

Tufte book and references

I'm using an automated way to generate a research diary / logbook. (Credit: Using LaTeX to keep a diary) However I'm having trouble getting references to work properly. I get weird results with ...
6
votes
1answer
3k views

How can I loop back to a slide after showing conditional slides in Beamer?

I am working on a presentation that has conditional slides, using the formatting suggested here: Conditionally hidden slides in beamer I would like to be able to continue with my presentation after ...
4
votes
2answers
335 views

ampersand “&” causes if-else-fi to fail

I encountered a very strange problem today. I want to fill tables with automatic generated data. Hence, I designed a macro, which takes four arguments (one being optional). Arguments No. 1 and 4 ...
1
vote
1answer
53 views

How to set up a conditional loop that chooses which compiler to use within the same document?

I have a TeXlive 2019 installation with an unsolved problem that so far prevents me from compiling on this computer with LuaLaTeX, so I thought I could add to the preamble of the document that I'm ...
3
votes
2answers
244 views

How to check a boolean argument in a command with optional arguments?

I have a command with an optional argument, and I want to execute some code depending if argument is true or false (I am sure that this command will have always some argument convertible to a boolean, ...
25
votes
6answers
632 views

Test if a given control sequence is a length register

I'm in need of a macro which receives a control sequence as argument and needs to branch if this macro is actually a length (of any kind, e.g. dimen, skip etc.) or "just" a normal macro (including one ...
2
votes
1answer
37 views

Comparing the number of the current chapter with another one

I am typesetting a book (using the book class) which consists of a large number of small chapters and I wish to be able to freely change the order of the chapters. Since there are cross-references, I ...
0
votes
0answers
26 views

Loop for each 3 rows with condition

Continues Old topic: algorithm Logic: Make Loop for each 3 rows in datatools I use this code with ifthenelse: If No = A/B/C, insert page A/B/C but result do not display in order of rows in file ...

1 2
3
4 5
31