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
2
votes
3answers
109 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 ...
1
vote
1answer
45 views

How to define \section to compile conditionally

I would like to create a structural delimiter that behaves identically to \section but compiles conditionally. In the MWE below I have labeled it \draftsection. The content of this section should ...
54
votes
3answers
51k views

Conditionally hidden slides in beamer

When creating a presentation, I sometimes create extra slides that contain additional information, a more thorough explanation, or an extra plot pertaining to certain parts of my talk. These extra ...
1
vote
1answer
28 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 ...
16
votes
3answers
1k views

Conditionally Remove Brackets

I'm trying to create a command with an optional argument using \newcommand{\Af}[1]{{\mathbf{A}_{(#1)}} where the argument is a number. However, I'd like that if no argument is given the bracket ...
5
votes
4answers
236 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 ...
0
votes
0answers
27 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 ...
2
votes
1answer
24 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
55 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
20 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 ...
115
votes
4answers
170k views

Large braces for specifying values of variables by condition

How do I produce a conditional expression with large brackets? For example: X = 0 if a=1, 1 otherwise, with a large left bracket and specifying each condition in a line?
2
votes
1answer
20 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 ...
2
votes
2answers
183 views

Conditionally redefine \big, \bigg, etc. to \left or \right (locally)

To speed up my typesetting work I'm exploring the possibility to redefine some commands "locally". In this particular case I'd like to redefine the \big, \Big, etc. commands to the \left and \right ...
0
votes
0answers
20 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 ...
4
votes
3answers
598 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
34 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
124 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
101 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
27 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
35 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
52 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
36 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
94 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{\...
258
votes
4answers
154k views

LaTeX conditional expression

I would like to be able to set a flag at the beginning of the main flag (say output) that tells if I want to produce a paper document or an electronic document. Then I should check this flag to ...
8
votes
4answers
714 views

Detect if a macro argument is only one symbol

I define a bunch of functions (or operators, if you like) using a little helper \parens, which adds parens on demand: \newcommand{\parens}[1]{ \ifthenelse{\equal{#1}{}}{}{(#1)} } \newcommand{\fv}[...
5
votes
1answer
3k views

Set styles for numbers in listings package

I am using the listings package for Smalltalk programming language but since it does not come out of the box, I am trying to do it by hand. Now I have a problem with numbers. No matter if I change: ...
1
vote
1answer
65 views

Different text on last page

I want to add one of two different texts, depending on whether it appears on the last page. I tried this: \documentclass{article} \usepackage[angle=0, opacity=1, scale=1,position={0,0}]{background} \...
0
votes
1answer
2k 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}{...
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
41 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
34 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
23 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. ...
1
vote
2answers
48 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 ...
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 ...
0
votes
0answers
106 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
44 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}{...
0
votes
1answer
53 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 $$ \...
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 ...
1
vote
1answer
37 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
65 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
47 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{\...
60
votes
6answers
24k views

If Then Else for odd page/even page

How to use if-then-else structure in LaTeX? I need an example of odd and even page. if odd then command 1 else command 2
2
votes
1answer
22 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 ...
11
votes
3answers
483 views

Write if statement to the toc

Here is a challenge: This construction works just fine as the if is contained to a single write statement \documentclass[a4paper]{book} \newcommand\test{\noindent test\par} \let\testA\iffalse \let\...
1
vote
1answer
27 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: \...
4
votes
1answer
37 views

How to know which column a text is in

I want to put a small circle with a letter at the margin in a two-column document. To decide in which margin this bullet goes, I use \if@firstcolumn. It works most of the time, but it sometimes goes ...
5
votes
1answer
44 views

Setting conditionals based on other conditionals

I'm trying to set a conditional \if... to true or false based on another condition. Something similar to this: \documentclass{article} \newif\iffirst \iftrue \let\iffirst\iftrue% ... similar to \...
3
votes
2answers
244 views

Using TikZ conditional statement?

I'd like some help to make a conditional statement in LaTeX and TikZ work. In this M(non-)WE, I'd like the first, third and fifth dots to be larger: \documentclass[tikz]{standalone} \usepackage{tikz} ...
50
votes
2answers
16k views

Can I test if a file exists?

Can I somehow test if a file exists? And can I use this to do only things when it exists? I like to do something like if(exist('members.csv')) { do something }

1
2 3 4 5
30