The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
1
vote
1answer
49 views

Conditional based on displaystyle

I'm trying to write a macro that returns different things depending on it if is used in a displayed equation or if it is used in an inline equation. Something like this, I assume: \newcommand{\foo}{% ...
4
votes
3answers
149 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 ...
1
vote
1answer
66 views

using includegraphics conditionally

I want to print a different logo sequentially for 4 years, and then resuse them. My script is not working... any idea? \documentclass{article} \usepackage{pgf,calculator,ifthen} \MODULO{\year}{4}{...
3
votes
3answers
89 views

Macro that calls ifthen's \equal doesn't work in section heading. Why?

In the following MWE, I have a macro \mytest that tests whether its argument is a or b, returning "yes"/"no", respectively. This macro uses (a) \ifthenelse and (b) \equal from the if then package. ...
2
votes
1answer
78 views

Loop newcommand with variable arguments

Following my previous question, I would like to know how to have variable inputs for a newcommand in order to do the following \documentclass{article} \newcommand*{\repsum}[VARIABLE NUMBER]{ \...
1
vote
3answers
316 views

How to properly use \DeclareOption within a macro

Using \ifthenelse statements I've defined a macro that prints it's value as long as it is different from the value of the previous time it was used. \RequirePackage{xifthen} \def\storedval{} % create ...
0
votes
1answer
95 views

Multiple nested \ifdefined statements

I use the "variables" in my header and would like to shorten the code by combining \ifdefined\@@author and \ifdefined\@group. Searching the repository for "ifdefined multiple arguments" etc. didn't ...
2
votes
2answers
206 views

Check number of arguments in a command

I know how to create if\else structures in LaTeX using \newif and \else. What I'm wondering is whether there's a way to check against the actual arguments given to a command. For example, if I have a ...
1
vote
0answers
76 views

How to check if last displayed content was displaymath / minipage ends on displaymath?

Is there a way to check if a minipage ends with display math? Or more generally, if the line above was a displaymath? Background: I defined a command for a minipage-environment that fixes alot of ...
9
votes
1answer
136 views

Distinguish active characters from non-active pendants with expansion-methods only?

(Please take the following question rather for a moot point than for an everyday-problem.) Is there an expandable method for distinguishing an arbitrary explicit non-active character token from its ...
3
votes
3answers
383 views

how can I compare strings using the if statement without package?

For example, \newenvironment{genPage}[2] {\clearpage\thispagestyle{#1}\normalsize\bfseries \if#2=c \centering \fi } {\newpage} \begin{document} \begin{genPage}{plain}{c} ...
1
vote
0answers
43 views

Conditional execution based on existence of key/value pair in datatool

This question is a confirmation and a follow-up using the code from this question I'm preparing a template, which relies on some texts which will be provided in a CSV file (ex, disclaimer text, large ...
1
vote
1answer
98 views

lstlisting teacher/student version

I would like to hide some parts of a lstlisting code and change it into a white rectangle (for example) for my students. Besides, under a boolean condition, I would like to come back to the version ...
1
vote
1answer
19 views

Adding a glossary entry whose name is a macro that uses \equal{}

I have defined some commands that use \equal{} to test if an argument is empty or not. I would like to use these commands as names in a glossary. However, the following minimum example does not work ...
1
vote
1answer
69 views

Overwrite dcases* to work inside align (to use mtpro2 braces)

This is a direct follow-up question from my previous one: Overwrite matrix to work inside align (to use mtpro2 parentheses and braces). Although this question is self-contained, I encourage ...
3
votes
3answers
898 views

Testing for a “if not defined” boolean

How can I test for a not defined boolean? I want to have \usepackage{xr-hyper} \usepackage{hyperref} \providebool{is_single_book} \booltrue{is_single_book} in my main.tex and in each of the ...
0
votes
1answer
139 views

Conditional Macro: if include &, then A; otherwise, B

I want to make a conditional macro. I currently use the line \def\[#1\]{\begin{align*}#1\end{align*}} since I often use align, and don't want to have to type \begin{align*} ... \end{align*} every ...
2
votes
3answers
154 views

Identifying if macro is an alias

I use a def as an alias like so: \def\alias{\foo} later on I would like to check if \alias is an alias for foo. (X is an alias of Y means the current definition of X is def\X{\Y}). See the MWE ...
1
vote
1answer
74 views

How to conditionally rotate a label in TikZ?

I want to create a macro that puts a label in a TikZ \draw environment; that rotates with the law: alfa<180, then rotate=alfa, else rotate=alfa-180. My code (where #7 is the angle, and #6 is the ...
1
vote
1answer
88 views

use jobname to “pass parameters”? [duplicate]

Yet another question about passing parameters when compiling. I thought I had a good (for me) solution, by compiling with different jobnames and do conditional compilation on the basis of the jobname, ...
4
votes
1answer
58 views

Prevent tikz node intersection

I'm making a macro to generate a tikzpicture depending on the arguments passed into the macro. I want to be able to draw a \node only if it won't intersect with a specified x coordinate. So say my ...
1
vote
1answer
143 views

Define Command/Macro with boolean flag

I'd love to have a command with a boolean flag. That flag is supposed to be used in a conditional statement. I'd love to have something like this: \command -> false \command[flag=...
0
votes
0answers
119 views

Usage of While-do constructs LaTeX

I'm curious, when reading about the ifthen-packages I've come across the syntax of while-do statements. What are they used for ? For example this piece of code from the documentation (this is copy-...
4
votes
1answer
76 views

Conditional to test whether in an itemize

I'm using LaTeX to write manuscripts for plays, I've been looking a bit into conditional expressions. The reason is that I want comments in the manus, and I currently have two different commands for ...
2
votes
5answers
196 views

How can I condition on the last token?

I would like to write a command \foo which, for the sake of simplicity, does just one thing, which is make sure its argument ends with a dot. Thus both foo{hello world} and foo{hello world.} expand to ...
2
votes
2answers
185 views

Conditional If-then-else/xIf-then-else Packages

I'm currently working on a presentation about the packages mentioned in the title. The problem I have is, I don't really understand why anyone would use conditional statements in a LaTeX document. ...
1
vote
1answer
46 views

\ifdefempty against linebreaks [duplicate]

I use LaTeX for text processing in conjunction with a template parser. I want to do things, when there would be text to print. So I have \newcommand{\zahltext}{% %% here may be dragons, this is ...
6
votes
4answers
200 views

nesting macro identifying string length 1 using xstring ifthen packages

I would like to write a latex macro \p which given input X returns X or (X) depending on whether X has character length 1 or not. Moreover, I want to be able to nest applications of \p. E.g. I want ...
7
votes
2answers
346 views

If/Else Statement Not Working When Trying To Reformat Subsections

I want my LaTeX code to number sections and subsections like (FYI: I'm using article not chapter or book): 0 Introduction (section) 1 A (section) 1.01 A1 (subsection) 1.02 A2 (subsection) ... 1.10 ...
17
votes
3answers
489 views

About what TeX does after it finds commented conditionals with ltxdoc

When I thought I understood the concept of the doc package, LaTeX proved me wrong. I was trying to make a file to use with ltxdoc when I realised I could not use conditionals in the preamble because ...
5
votes
1answer
185 views

Conditional \if@mainmatter don’t have any effect

I try to make a command who have different behavior depending if it is executed in mainmatter area or not. So I use the \if@mainmatter command as described in the topic Checking the mainmatter But, ...
3
votes
1answer
108 views

How can I prevent \ifnum to be ignored?

So I have the following code: \newcount\x\x\i \ifnum\x<3 \advance\x1 \fi \the\x \bye which I call from the command line with pdftex '\def\i{9}\input test.tex' This puts out 10 (or \i + 1), ...
1
vote
4answers
115 views

Custom \if command to check for multiple conditions

I'm creating a document class for bachelors' and masters' theses at my faculty. It's almost ready and tuned to this year's official requirements. However, things may change in future: for example, the ...
6
votes
2answers
317 views

Using \ifthenelse inside an option

I'm trying to create a \newcommand for images which takes width as an optional parameter. This is my current command which works (but doesn't use the parameter): \newcommand{\introimg}[3]{ \begin{...
5
votes
4answers
1k views

Hide/Show Solution for Problems

There are too many options for "Solution/Answer" environments which we can use and I am adopting this one for my "big" project that I am doing. At the moment, it looks like the easiest one for me to ...
0
votes
2answers
53 views

Generate path for \includegraphics with if-else macro

I would like to have a single option/macro (true/false or similar) that determines, from which folder to choose plots. There's only 2 folders for each plot. Mainly need this to switch between low ...
0
votes
1answer
30 views

exam class 2.6: use self defined environment which depends on \printanswers before first question

I am not longer able to use a self defined environment which depends on \printanswers before the first question since the exam class was updated to version 2.6. (I use this solution.) With the exam ...
0
votes
2answers
170 views

gdef with @ifnextchar

I am trying to create a command with two or three arguments, that creates a new command. In my classfile I have: \def\foobar#1#2{\gdef\foo{#1, #2, \@ifnextchar\bgroup{foo}{bar}}} If I call \foobar{...
2
votes
1answer
123 views

Use shortframetitle for list of frames only when defined

I'm creating a list of frames for my beamer presentation as in my previous question, which works like a charm. If a framesubtitle exists, it will be put into the list of frames in favor of the ...
3
votes
1answer
125 views

Printing a \pageref{} but only when not on that page in LaTeX

I would like to set up a macro to print a page reference with a reference, but only when the label is not on the same page. For example, I'm looking to define \myref{} so that this code: \...
2
votes
2answers
81 views

Problem with storing recursive calculus

I have the following issue with some recursive calculus. I just write the function \recsum that recursively computes the sum of an unspecified amount of integers. It works when I call the function ...
2
votes
1answer
18 views

Process first or last case differently with clist_map

I wrote this macro to transform a comma-separated list of objects into a custom-separated list of objects: \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\separators}{m}{% \clist_map_inline:...
2
votes
2answers
54 views

Hyphenation of camelCase inside an \ifthenelse while using custom hyphenation command

While writing software documentation, the need arose for a command that automatically hyphenates camelCase words at uppercase letters, e.g. camel-Case. Furthermore, these camelCase words are typeset ...
3
votes
1answer
44 views

Checking a command with \equal and then using that command for another command?

I am trying to check the definition of a command (either arabic, roman, Roman, Alph etc.) and from this information change the formatting of section titles, while making use of the command definition ...
0
votes
1answer
24 views

multipurpose index command with xparse: conditionals as arguents of \index not working

I want to define a multipurpose index command, \xindex{text}[index]/parent/ with one mandatory and two optional arguments. It should (i) print 'text' in the main text, (ii) send 'index' (or 'text') ...
0
votes
0answers
40 views

conditional if / else [duplicate]

I want in following examaple change the day of week according the inputted day. When I use dia in the document work, but when I use inside newcommand doesnt (look the example) \documentclass{article} ...
0
votes
1answer
705 views

condition if/else

In the following example I want write Tuesday if the variable dia is Monday. The following example write rest not matter the string of variable dia. \documentclass{article} \def\dia#1{\if{#1=monday}{...
4
votes
1answer
120 views

Icons on side of text, below section headings

I am currently trying to write a custom command that helps me display a bunch of icons on the side of a section text, right below the section heading. There is always the same amount of icons (in my ...
0
votes
1answer
59 views

How do I have to implement the following comparison [TikZ] [duplicate]

How do I have to implement the following comparison? \documentclass{scrartcl} \usepackage{etoolbox} \usepackage{tikz} \begin{document} \begin{tikzpicture} \pgfmathparse{sin(60)} \let\x=\...
1
vote
1answer
32 views

Character suppression at newline

I am attempting to typeset a list of names separated by specific characters, e.g. John Doe | Jane Doe | John Doe | Jane Doe | John Doe | Jane Doe | .... This list is to be input{} into various ...