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
4 votes
2 answers
144 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
247 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
  • 327
4 votes
1 answer
102 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
24 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
138 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
44 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
31 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
91 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
  • 397
2 votes
2 answers
56 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
19 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
30 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
  • 477
3 votes
2 answers
53 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
351 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
263 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,833
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
33 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
35 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
61 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
305 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
246 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
33 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
156 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
135 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
71 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
482 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
100 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
205 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
53 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,327
2 votes
3 answers
133 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
836 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
56 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
103 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
250 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
251 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
0 votes
1 answer
55 views

A sheet of Input-Orders

I have a sheet of input orders like: \input{something} \input{another thing} \input{some other thing} ... I want to make a command like \myinput{} so that if I use \myinput{24} then that will input ...
Ngiap's user avatar
  • 89
3 votes
1 answer
115 views

Can't check if a string(token list) type macro in a sequence in LaTeX3?

This is my first time on TeX Stack Exchange, so please forgive me if I unintentionally offend anyone. Compile Environment(using pdflatex to compile): WSL: x86_64 Linux 5.15.133.1-microsoft-standard-...
zpding's user avatar
  • 134
0 votes
1 answer
120 views

How to compare aspect ratios?

I have a box whose side lengths are recorded as lengths as in \newlength{\imageWidth} \setlength{\imageWidth}{300mm} \newlength{\imageHeight} \setlength{\imageHeight}{200mm} I am trying to create a ...
Julian's user avatar
  • 751
4 votes
2 answers
82 views

Expand conditional in the outer specification for a tabularray table

I am trying to create a custom tblr environment for a schedule which I reuse often. I want to include an optional label for cross-referencing. I'm using the xparse \NewDocumentEnvironment command ...
jw5801's user avatar
  • 157
0 votes
1 answer
63 views

Nested if .. else

What's wrong with the syntax of the \if...\else \if...\else...\fi below? My intention is that if either OptA is true, then \which is defined to be Chose A, or if instead OptB is true, then \which is ...
murray's user avatar
  • 8,692
0 votes
1 answer
85 views

LaTeX: \equal not recognized within \section command

I have the following code, where I want to steer the language of some titles and some texts using a "\newcommand". The following minimal example uses the new command "kLanguage", ...
iGeeks's user avatar
  • 19
0 votes
2 answers
132 views

LaTeX conditional processing via command line arguments [duplicate]

I use Beamer presentations in workshops where I set questions, have students work on the answers, and then display some sample answers. I give the students a version of the presentation without the ...
glyn's user avatar
  • 113
0 votes
1 answer
64 views

Conditional expressions look always false

Experimenting with conditional expressions, namely with this trivial if... \def\testvar{testvalue} \if\testvar{testvalue}{istrue}\else{isfalse}\fi I get always isfalse. I think I did everything as I ...
peterh's user avatar
  • 341

1
2 3 4 5
38