Skip to main content

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
0 answers
11 views

Accede to particular data inside variable

Suppose I have multiple products, each with a name, number, description, and photos (which could be one or multiple photos). I want to automatically list the names of the products on the cover page ...
2 votes
2 answers
86 views

default-valued optional (boolean) parameter for a new command in tikz

I want to define a command for TikZ which has a default-valued optional parameter which is a Boolean, initially set to false. I've looked around and have found: xparse appears to be obsolete: https://...
Jasper's user avatar
  • 912
0 votes
0 answers
44 views

How can I make a tcolorbox round its south corners if its bottom is close enough to the bottom of the page?

I'm making a document with triangular footers around the outer corner of the page, where the page number is. If a tcolorbox is too tall and too close to the bottom, it can be cut off by these footers. ...
Luca Ballanzeddu's user avatar
4 votes
1 answer
65 views

collcell and \IfBlankTF comparison not working

I'm having trouble with the \collcell package - a macro I made, which uses \IfBlankTF, works fine outside of a table, but somehow \collectcell is feeding something that's "non-blank" into my ...
James's user avatar
  • 145
5 votes
3 answers
477 views

Counter in Loop

I'm trying to set the color of every three items in a 5x3 pattern from a tikz picture: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \m in {1,2,3}{ \...
Matt Petersen's user avatar
3 votes
2 answers
103 views

Defining command for use with ifnum

I want to define a conditional command that I can easily use with \ifnum, hence such a command should expand to a number. However, I sometimes need to define temporary commands which breaks such usage,...
Tohiko's user avatar
  • 1,885
0 votes
0 answers
42 views

Listings hook to detect whether the current line contains a colon?

TL;DR: I want to use the listings package for typesetting YAML snippets. For example: \begin{lstlisting}[language=yaml] key: value list: - value1 - value2 env: key1: value1 key2: value2 \end{...
ErikMD's user avatar
  • 101
3 votes
2 answers
131 views

Help with loops – why is there an Ω?

I am just getting some experience with looping constructs in TeX/LaTeX. I thought I understood how \@tfor works, and things were mostly coming out as I wanted. But I ran into some unexpected ...
Louis Deaett's user avatar
4 votes
2 answers
181 views

conditional enumerate labels

I am writing a math book. I have exercises that have questions AND subquestions (for example 1 then 1.a, 1.b, 2 then 2.a, 2.b, 2.c etc.). I also have exercises that have one questions, without ...
stargazer45's user avatar
3 votes
1 answer
256 views

How does \if:w work?

I cannot work out how \if:w works and LaTeX3's manual does not show any example on how to use it: I want to check whether the document is currently in oneside or twoside mode: \if@twoside Twoside ...
Dave's user avatar
  • 339
4 votes
1 answer
112 views

Why \IfPackageAtLeastTF{⟨package⟩}{⟨date⟩}{\PassOptionsToPackage{⟨option⟩}{⟨package⟩}}{} doesn't pass ⟨option⟩ to ⟨package⟩?

My current version of parskip is 2021-03-14 so: \IfPackageAtLeastTF{parskip}{2018-08-24}{\PassOptionsToPackage{indent}{parskip}}{} \usepackage{parskip} should pass the indent option to parskip. But ...
Denis Bitouzé's user avatar
1 vote
1 answer
26 views

Displaying article title in fancyhdr header with conditionals

I use the tip found here How to display article title in fancyhdr header to display article title in fancy header. But I'm not able to make it works within a condition sequence. As an example, this ...
AEgidius's user avatar
2 votes
2 answers
140 views

Checking if a certain fragment is located earlier in the document

Very often I want to refer to a certain claim I mentioned earlier in the document: "As I said earlier, blah." Since I often rearrange material, I need to ensure that "blah" indeed ...
Jabot's user avatar
  • 149
1 vote
2 answers
46 views

Can I change the effect of a command depending on the environment in which it's invoked?

I need a user-defined command to behave differently depending on whether it's invoked inside a \begin{quotation} environment or not. Is that possible? I don't know where to start!
digitig's user avatar
  • 125
1 vote
1 answer
32 views

Analyze number of spreadtab rows for conditionally changing text elements in the document

again I need your help. I'm writing my invoices for my small music busines with LATEX scrlttr2 and with a spreadtab-tables. It is working very well, but I want to have an automatic selection of some ...
Mr_Nofreeze's user avatar
3 votes
2 answers
104 views

\ifnum to draw a tikzpicture, less than or equals

I want to make a conditional statement that draws one tikz picture for specific values of \t and another for different \t values. Here is a M(non)WE: \documentclass{article} \usepackage{tikz,ifthen} \...
Jasper's user avatar
  • 912
2 votes
2 answers
57 views

Switching between translations of the Bible, looking up text

I have a document with scriptures listed, that I can call. (I'm not sure this is the best way to do it, but it's based on this stackoverflow answer.) \documentclass{book} \makeatletter \newcommand\...
dnh37's user avatar
  • 181
1 vote
0 answers
21 views

Conditional Output with user input

I am trying to write a form in Latex where I'm asking a question an if the answer is no I whant to ask another question. I'm a real beginner in Latex and I need a little help how to start it. It ...
Andrea K's user avatar
0 votes
0 answers
43 views

Check if a file has been modified since last compile in Overleaf

I have an if-statement that I call in my .tex document in Overleaf \IfFileExists{mypdf.pdf} {\includegraphics[width=1\textwidth}{mypdf.pdf}} {\includestandalone[width=1\...
David G.'s user avatar
  • 329
2 votes
1 answer
43 views

How make raggedleft really right aligned in if/else environment?

For some reason, the \raggedleft isn't really right-aligned. I tried minipage but that apparently doesn't work in the if/else environment. \documentclass[ % handout, english,usenames,...
jay.sf's user avatar
  • 509
3 votes
2 answers
55 views

Array or tabular in Beamer breaks \if

I want to have an array or tabular environment in an \if statement in Beamer. If I have an article, this compiles just fine: \documentclass{article} \def\x{1} \begin{document} \if\x1 \begin{tabular}{...
Sam Jaques's user avatar
3 votes
3 answers
359 views

How to define a command (or similar) that makes a conditional expression reusable?

I'm struggling with the correct use of conditional expressions with ifthenelse at the moment. I would like to define a command (or similar) that represents a certain conditional expression in order to ...
Simon's user avatar
  • 145
2 votes
3 answers
272 views

Defining a custom if command

In the following minimal example, I am able to define a custom \if* command based on ifcsname, however when I use it inside \loop construct I get Extra \fi errors \documentclass{article} \...
Tohiko's user avatar
  • 1,885
0 votes
2 answers
35 views

How to read from external file and compare to given string [duplicate]

I am trying to extract text from an external file (someexternalfile.txt) and compare it with a given string (sometext) but it is saying that the external text and the given string are not the same (...
fsr_j's user avatar
  • 75
0 votes
1 answer
57 views

Comparison of macros fails

I am new to LaTex and have been given a problem by my colleagues. They define a document type in a TeX file (e.g. 'svvr', 'srs', ...). This external definition corresponds to lines 4 and 5 in my ...
ruriger's user avatar
6 votes
3 answers
221 views

How can I improve the spacing after a top float?

Context I'm trying to create a macro (called here \myCommand) that separates two paragraphs and adds a different vertical space depending on the context. But I suppose this is a general problem which ...
B Legrand's user avatar
  • 433
2 votes
1 answer
36 views

Iterating over a list and conditionals in tabular environment not working. Incomplete \ifnum; all text was ignored after line 72

i work on a project with a lot of people and there are many who are not really familiar with LaTeX. Therefore, I have to define a command (\timeplan{}), which simplifies coloring tablecells (each ...
Viggo's user avatar
  • 65
0 votes
0 answers
37 views

Drawing items at selected grid locations

I would like to draw a grid and place queens are selected columns for each row. I am able to draw the grid, but the placement of queens is improper. \makeatletter\newcommand{\showQL}[3][,]{% \def\...
user317646's user avatar
1 vote
2 answers
35 views

Weird Question with def, and condition

MWE: \documentclass{article} \def\ENLANG{english} \def\FRLANG{french} \def\LANG{\ENLANG} \begin{document} \if\LANG\ENLANG \ENLANG \else \FRLANG \fi \ifx\LANG\ENLANG \ENLANG \else \FRLANG \fi \LANG\ \...
Twilight's user avatar
1 vote
1 answer
66 views

Detect if a parameter passed to command is a mathematical formula

I'm defining a command which displays braced paragraphs and an isomorphism between them, but I want the command to recognize if one of the paragraphs is something purely mathematical and therefore not ...
Lorenzo Carozzo's user avatar
7 votes
4 answers
312 views

Adding up numbers

In a local class file I maintain, we have a system that can automatically add up numbers (in our case, marks for an assignment) and then output the sum. I would like to develop it to add up limited ...
rbrignall's user avatar
  • 1,574
1 vote
2 answers
55 views

How to determine from the document body whether or not a page has a top float?

For a particular application, I need to know whether or not a page contains a top float. I have therefore taken the definition of the conditional \iftopfloat{<true>}{<false>} given in the ...
B Legrand's user avatar
  • 433
5 votes
6 answers
248 views

nested \ifx with extra \else error

I have this code with nested ifx (plain TeX): \def\test#1#2% { \edef\cmpa{#1} \edef\cmpb{x} \ifx\cmpa\cmpb it is x \edef\cmpa{#2} \edef\cmpb{1} \ifx\cmpa\cmpb and 1 \...
coonlight's user avatar
  • 137
2 votes
1 answer
54 views

\ifthenelse atomic proposition not behaving as expected when paired with fancy footer

I understand that the title of the thread is a bit cryptic, but I admit that I don't have much of a clue about the reason for which this (apparently simple) conditional (sometimes) fails in working as ...
il mietitore's user avatar
0 votes
0 answers
34 views

No page number for TOC entry followed by entry deeper and same page

Let's assume that my Introduction is Chapter 1 on page 1, with no sectioning. And Chapter 2, Section 2.1 and Subsection 2.1.1 appear on page 3. And Subsection 2.1.2 and Section 2.2 and Section 2.3 ...
Olivier's user avatar
  • 75
3 votes
1 answer
159 views

If-else-fi within foreach with recursion

Given a list of numbers of size n, n-1 combinations are formed. The numbers of each combination are multiplied and all the products are added. This is taken from question 711870. Recursion works on ...
antonio de la rosa's user avatar
1 vote
0 answers
32 views

How to make conditional command with non-numerical condition? [duplicate]

I would like to know if someone has a solution to the following problem: I have recently start to create shortcut to certain operator to display directly the parenthesis around their arguments. \...
Matsune's user avatar
  • 11
3 votes
4 answers
137 views

Compare first token after expanding macro once and discard the rest

How does one write an if clause that checks whether the first element of the immediate expansion is \mymacro, without fully expanding the input? \documentclass{minimal} \def\mymacro#1{Does something ...
Hyperplane's user avatar
1 vote
2 answers
73 views

How to do an if after an `exp:args` in expl3

Following this answer by @JasperHabicht, in my code, I would like to add an option to that macro so, depending on a flag I can execute either \drawMoveFromSgfCoords or \drawStoneFromSgfCoords. I still ...
psygo's user avatar
  • 438
5 votes
4 answers
487 views

Inline If-Else Statement Based on Macro Argument

How do I do an inline if-else statement? \draw[draw = #1, fill = \if black#1 white \else black \fi, line width = 0.1mm] (#2, #3) circle [radius = 0.25cm]; I've tried to do it based on this answer, ...
psygo's user avatar
  • 438
1 vote
1 answer
102 views

How to Color Certain cells in TikZ Pictures

I'm interested on coloring certain cells of a TikZ picture. It is the following: I did it by using the grid and creating the numbers. I present the code I create above: \begin{tikzpicture}[scale = 0....
MathHack's user avatar
3 votes
2 answers
218 views

Can I issue a warning when an uppercase symbol is used in my math command?

I have been using something like \renewcommand\vec[1] {\boldsymbol{\MakeLowercase{#1}}} \newcommand\mat[1] {\boldsymbol{\MakeUppercase{#1}}} for some time now to typeset vectors and matrices. ...
Mr Tsjolder from codidact's user avatar
3 votes
1 answer
61 views

ifmtarg testing a macro that is empty?

The following code works as expected: \NewDocumentCommand{\checker}{m}{\@ifmtarg{#1}{empty}{not empty}} \checker{} % Prints "empty" \checker{x} % Prints "not empty" However, how ...
Vincent's user avatar
  • 5,531
2 votes
3 answers
136 views

Conditional macros

Goal: I would like to have a macro that substitutes different commands depending in whether in displayed math mode or not. In particular, it should generate fixed-size angular brackets in text lines, \...
VKphysicist's user avatar
3 votes
4 answers
940 views

How can I write a LaTex command with 'if'-'then'-'else'?

I read LaTeX \if condition and How to write if and then in algorithm?, but so far it did not ring a bell for me. I am trying to create a command named dottedSkill like below. The logic behind it is: ...
Daniel Ferreira Castro's user avatar
0 votes
2 answers
59 views

Counter is incremented inside \if, even condition is not met

I have defined three counters which I'm going to increment within a condition. This should lead to the result that functional requirements are prefixed with FA (and a subsequent number) and non ...
MarvinMcFly's user avatar
2 votes
1 answer
105 views

Searching a list of words using Boolean operators

In the project I'm currently working on, the user can define, within an environment defined by the project, a list of tags, stored internally in a macro (for example, \tags). Each item in this list ...
user30654's user avatar
4 votes
2 answers
274 views

Using numbers from new commands in ifnum

I am trying to create a Latex document in which I define a list of items (e.g. fruits) at the beginning in order to change the resulting text / appearance of the document depending of the amount of ...
Lennart's user avatar
  • 43
5 votes
2 answers
253 views

Remove page number, if there is only one page in a section

In my current project, I want to create worksheets that I can print out and distribute. To do this, I want to reset the page number for each worksheet, but only display the page number if the ...
Jim Ye's user avatar
  • 85
1 vote
2 answers
36 views

Suppress text output but leave enumerate item labels in place

I am typesetting an exam question like \documentclass{article} \newenvironment{answer}{\par[}{]} \newenvironment{answersonly}{}{} \begin{document} \begin{answersonly} \begin{enumerate} \item Question ...
Markus Kuhn's user avatar

1
2 3 4 5
38