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
2answers
33 views

If else condition in document to control format of equation

How can I create a variable in the beginning of the latex document that will dictate how certain equation will be shown? Concretely, in the beginning I want to define a variable x which will take ...
2
votes
1answer
24 views

Use width of certain block of text as parameter

I wonder if it's possible to get the width of a certain block of text, passed as an argument in \newcommand and use it numerically inside a conditional. For example, defining a \newcommand which ...
1
vote
2answers
28 views

Setting a \newif to false ignored on first check in custom itemize environment

I'm working on a document template in which I have some nested itemize lists which I need to add some commands before and after each list element. To accomplish this, I've created a new environment ...
8
votes
1answer
217 views

What's a reliable way to detect math mode (including align*)?

I thought \ifmmode detected math mode, but clearly it does not: \documentclass{article} \usepackage{amsmath} \begin{document} \[ \ifmmode math \else not math \fi \] $\ifmmode math \else not math \...
4
votes
3answers
147 views

Conditional bracketing in macro

I am trying to make a macro for typesetting higher-categories, and would like to automatically enclose the optional argument in brackets if it is an expression containing + or -. In particular I would ...
0
votes
2answers
33 views

Cannot \newif inside a conditional

I want to create a conditional if it is not defined yet. The following is my unsuccessful attempt. %%% in file A \documentclass{article} \newif\ifdraft\drafttrue \def\OptionLoaded{} %%% in file B \...
0
votes
1answer
25 views

If-condition cannot be used in multline environment?

Incomplete \ifx error raises when compiling the following tex code. \documentclass{article} \usepackage{amsmath} \begin{document} \begin{multline} % <- Replacing `multline` with `equation` can fix ...
2
votes
1answer
33 views

Problem with a test in if statement

I'm having trouble with the implementation of a if statement. I want to know if today and five days from now happen in the same month. I get the correct values of the corresponding month to print but ...
2
votes
1answer
51 views

Error while trying to compute modulo 3 inside a foreach loop in TikZ

My goal is to draw an array of shapes in the following fashion: square, square, triangle, square, square, triangle ... I use a \foreach loop in which I use modular arithmetic to determine when to draw ...
0
votes
0answers
15 views

Formatting for solution in exam doc

I've been studying latex for a few months and it's been amazing how it solved my issues concerning typessetting math papers. I just want \thequestion to show once always with the first \thepartno and ...
2
votes
1answer
24 views

How do I test for even/odd page within TikZ \foreach loop

I'm creating a document using the TikZ foreach loop. Here's a snippet \documentclass{article} \usepackage{tikz} \begin{document} \foreach \myi in {1,2,...,17} { hello(\myi) \clearpage \...
0
votes
0answers
45 views

Shorthand or simplified boolean expressions?

I have a lot of self-defined booleans and conditional statements, and have conditions like \ifthenelse{\NOT \boolean{foo} \AND \NOT \boolean{bar} \AND \NOT \boolean{baz}}{...}{...} I want a way to ...
0
votes
2answers
33 views

\if statement inside an environment

Ideally, I want to write \newif\ifhint \hintfalse \newenvironment{myhint}{\ifhint}{\fi} But,but, then the \fi is not read! I just want to put this whole bunch in comment, any other solution is ...
1
vote
1answer
15 views

Conditional add to Counter based on conditional ifboolexpr

I want to add to a counter based on an ifboolexpr using etoolbox but cant get it to work as I had hoped. I want to put various conditions throughout my document and then at the end have a count of how ...
1
vote
1answer
28 views

Print ISBN only if DOI is not defined (including in crossref entry!)

A previous question here asks whether it is possible for Biblatex to print an entry's ISBN only if it doesn't already contain a DOI. The accepted answer by Andrew Swann is to use Biblatex's source ...
2
votes
1answer
45 views

Am I using etoolbox correctly for string comparison?

I have a little environment to enumerate question statements. Sometimes, I want the label to not be a number but some string instead. In that case, I do not want the counter to be incremented. % ...
1
vote
1answer
30 views

How can I display the page number of a cross-referenced object, but only if the object is on different page?

I am creating a command called \fullref{<label>} that takes a label and outputs the number of the labeled object and name and optionally the page number where to find the object if it's on a ...
2
votes
3answers
140 views

How to query if a file has changed (a \IfFileHasChanged conditional)?

We know \IfFileExists{<file>}{<yes>}{<no>}. How can I create a command \IfFileHasChanged{<file>}{<yes>}{<no>} for a file which has changed (and does exist!). I mean ...
0
votes
0answers
32 views

How to convert the last number of the ref command output to string

There is an answer explaining how to convert numbers to text here. But if I use a \ref output in the command \convertdigits, it throws the error Missing number, treated as zero. even if the ref output ...
5
votes
4answers
260 views

On a conditional command: more powerful than \ifnum

According to the TEX in a Nutshell, Petr Olšák, page 16/29, we get: \ifnum ⟨number 1⟩ ⟨relation⟩ ⟨number 2⟩ . The ⟨relation⟩ could be < or = or >. It returns true if the comparison of the two ...
2
votes
1answer
27 views

If else in \newtheoremstyle

I'd like to make a custom theorem style such that would have the condition in it. To be more specific, when there is an optional argument in my theorem environment, the title should be taken from that,...
1
vote
1answer
57 views

Is there a valid source to read about the description and examples of an arbitrary TEX command such as \ifnum?

When I encounter a new TEX command to learn for the first time such as \ifnum, I do not know where to start to read about the description and examples. I know ctan.org is full of TEX packages but is ...
1
vote
2answers
21 views

conditional code in custom command in `\href`-environment

The below is my MWE. I have defined a function, because I want to post many links in my document. These point to a website that shows German laws; either the overview page for that law, or, if ...
0
votes
0answers
22 views

Creating a macro for supertabulars \tablefirsthead [Beginner]

I am trying to create a macro that reads in the number of given elements and creates the table header for the supertabulars command \tablefirsthead. There is a loop for getting the size of the given ...
2
votes
1answer
25 views

How can I conditionally output the short author in my beamer footline?

I have a footline where I want to output the authors name, but it is perfectly legitimate to not pass the authors name and hence the \insertshortauthor macro can be empty. The problem is we use | in ...
4
votes
3answers
620 views

Why does \ifx consider \MakeUppercase{1} and \MakeLowercase{1} different?

In this minimal example, an uppercase number is different of the same lowercase number. Why? \documentclass{memoir} \begin{document} \def\testone{\MakeUppercase{1}} \def\testtwo{\MakeLowercase{1}} \...
1
vote
2answers
40 views

Defining a new command using a conditional

I want to define a new command (to be used only in mathmode), the execution of which depends on the input given to it. Particularly, I want to define \F as \newcommand{\F}[1]{F#1} if the first ...
3
votes
3answers
139 views

Is it possible to conditionally input a file in LaTeX?

I'm new to LaTeX, and here's what I'm trying to accomplish: I have Markdown and LaTeX files in my working directory, say markdown_1.md and latex_1.tex. In my main LaTeX file, main.tex, I have defined ...
0
votes
1answer
19 views

Defining a case dependent default path

I am using latex together with the cloud service Nextcloud. As a result, I compile the same .tex file from different machines, such that all my figures have different global file paths. To solve this ...
4
votes
1answer
105 views

Draw path only if condition is met

I am using TikZ and would like to draw a path from one node to another if a condition is met. Here is my code: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{tikz} \begin{document} \...
1
vote
1answer
31 views

How can I automatically have a frametitle on my agenda page in beamer?

Rephrased I am still struggling with beamer. What I want to achieve is, that the agenda page automatically has the table of contents and writes Agenda at the exact same location as the section would ...
1
vote
2answers
36 views

Indirect control of behavior: how do I lengthen some pages and not others?

I'd like to be able to control the behavior of latex indirectly. Let me try to explain what I mean. I've got a large document, generated by a program. We can assume that each page (or page group) ...
1
vote
1answer
53 views

xcolor (TikZ): How to create a function 'ifcolorexists'

I have defined eight colors (stepcolor0,...,stepcolor7). Now I could have a list with more than 8 color-bearers. So I could need something like a function "\ifcolorexists{stepcolor22}{...
0
votes
2answers
39 views

Cumulative for loop with conditionals

I'm trying to do a for loop so that each iteration takes into account the result of the previous iteration. Specifically, I start with a definition (let's say \newcommand\start{(0)}) and then I enter ...
0
votes
1answer
42 views

Conditional statement destroyed frame

I tryed to get a different headline on the title page with if else fi, but it destroyed the frame styles. Why? Need help in beamertheme.sty \setbeamertemplate{headline} {% \ifnum \insertpagenumber=1 ...
1
vote
1answer
36 views

How to make and break a loop in tikz picture?

I wanted to make a picture of a numeric semigroup S(p,q) - draw all points that belong to it smaller than p*q. I don't know how to break the loop. My code does not work: \documentclass{amsart} \...
1
vote
1answer
26 views

How to create sidenote helper macro which handles notes inside captions

I am trying to write a simple macro that will add a sidenote which will inline the note if it is added to a caption. To do this I am testing if I am in inner mode, but the test doesn't seem to work. ...
0
votes
2answers
41 views

Error caused by \ifthenelse within \newenvironment

I am trying to write a new environment for proving mathematical theorems. What I have is \newenvironment{proof}[1][] {\textbf{proof}\ifthenelse{\equal{#1}{}}{.}{of #1.}} {\begin{...
3
votes
1answer
101 views

How can I print a warning, only if my document exceeds a certain length?

I'd like a warning to show up in my document as soon as it exceeds a defined length. I found how to print the the total word count of my document (assuming the main file to be main.tex): \newcommand{\...
2
votes
0answers
29 views

Usage of TikZ matrix nodes in an environment not possible

I am trying to make an exercise sheet that should contain the solutions in the LaTeX code as well. Using package options I can select whether the solutions should be typeset or not. I got a problem ...
1
vote
2answers
51 views

LaTeX `or` statements

I need to test if one of multiple is defined. I know this command: \ifIsDefined{\MYVAR}{ % Do sometyhing } But, I need to test for two conditions like if A or B is defined, then do this How ...
0
votes
0answers
115 views

How to make one CheckBox (from hyperref) status dependent on other CheckBoxes'?

I want to have four CheckBoxes A, B, C and D: B,C and D change their status on mouse click, in the usual way. And A is checked automatically only when all B, C and D are checked, A doesn't response ...
1
vote
1answer
51 views

How can I rewrite these conditionals effectively?

I'm working on modernizing and adapting an old LuaLaTeX template made for exams and other university documents. The thing is, the document is full of conditionals like these: \newcommand{\showMarks}{...
3
votes
1answer
43 views

Test failing with long definitions

I was trying to define a command to behave differently when the text is italic, and I came across a difference between \newcommand and \newcommand* (or rather, I think, a behavior of \long definitions ...
0
votes
1answer
56 views

How does \if \else work at \DeclareDocumentCommand?

I made a command with DeclareDocumentCommand from the packet xparse, and I have had troubles. My problem is that the \ifmmode (if mathmode) and the else don't work correctly, because when I type $$ \...
1
vote
1answer
41 views

doing something only when document option “final” is declared

Similar to Doing something only when the draft option is on? I wonder whether I can typeset a code only if the final option is declared within the documentclass line. \documentclass[final]{article} ...
2
votes
2answers
68 views

Using \setlength inside \mathchoice

I've written some somewhat complex tikz macros which use a length to set their scale. I've realised I want them to have a different scale when used inside display math versus inline math mode, and I ...
2
votes
1answer
56 views

latex/tikz macro conditional set options for \draw

this is some kind of a expansion of latex/tikz macro conditional up to now, I have something like this: \newif\ifCond \tikzset{ cond/.is if=Cond,Cond/.default=false, } \newcommand{\...
2
votes
1answer
27 views

Notation for arguments by means of ifthen package

I have this idea to create a piece of code that would allow me for a handy introduction of arguments in my notes for students, by which I mean this kind of fractional notation: I need a command that ...
1
vote
1answer
28 views

Is this patch involving toc still needed in current LaTeX?

A bug involving the toc and \add@percent@to@temptokena discussed in Write if statement to the toc can be fixed with the following code provided in https://tex.stackexchange.com/a/513685/13492: \...

1
2 3 4 5
31