{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}.

learn more… | top users | synonyms (1)

5
votes
1answer
100 views

How to check if key is already in aux file

Trying out some LaTeX commands, I wanted to build an Abbreviations list that would write acronyms to a file when defined and if already defined do nothing. It works fine so far, adding ...
4
votes
1answer
94 views

How to create a command to insert a string, but possibly ignore white space before the command?

I would like to define a switch that shows additional comments in some text (containing formulas). As you can see below by setting showString to true, this works well. However, when I set it to false, ...
5
votes
1answer
179 views

Multilingual text with if statement

I'm working on a document in LaTeX and I would like to have multiple language versions. I could just copy everything and translate, but this would lead to multiple versions that I would have to update ...
18
votes
4answers
546 views

On testing two fully expanded character strings for equality

I know three macros that test two fully expanded character strings for equality: \ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>} (ifthen package) ...
4
votes
1answer
77 views

How to check if it is the first time or last time a macro has been used in ConTeXt?

I have some text in my document which appears repeatedly many times throughout the document, so I have defined a custom macro, e.g.: \define\mymacro{ \section{A} There is some text. ...
8
votes
1answer
459 views

Handling \ifnum's “! Missing number, treated as zero.”

Let's say I have a variable, which may - or may NOT - be a number; how can I handle the cases when it isn't a number, without crashing with "! Missing number, treated as zero." ? In practical terms, ...
15
votes
1answer
142 views

First occurrence of a command

I'm writing some macros that need to behave differently after first occurrence. I decided to use the etoolbox package's toggle. My MWE is as follows: \documentclass{article} \usepackage{etoolbox} ...
3
votes
1answer
121 views

Name arrangement macro

I'm trying to write a c.v. macro. I've got a first, middle and last name and I would like to arrange these as either "first middle last" or as "first last" if middle is unknown The code I have so far ...
12
votes
2answers
355 views

Best practice to implement a boolean macro argument?

Sometimes I'd like a macro to depend on a boolean argument but I don't know about the best way to implement this. So far, I end up introducing a global (say) \newif\ifextra that is used inside the ...
3
votes
2answers
845 views

Variables for hiding or showing text in Latex

I would like to have some variables for showing or hiding text in Latex. For example, I would like to have two versions of a document. A short version and a long version by changing a variable at the ...
4
votes
1answer
132 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: ...
4
votes
2answers
253 views

How to detect words starting with # in listings package?

I am writing some code with the listings package and I need to detect the words starting with the number sign (#) and apply certain style. For example, if I have this code: something #foo ...
2
votes
1answer
194 views

newcommand key value

This is a completely noob question for LaTeX package writers. Could somebody share a piece of code or a MWE for the following situation. I would like to define a newcommand which will depend on the ...
12
votes
2answers
336 views

How to tell when to use pdflatex, latex, and xelatex for any given tex file?

I'm writing an automatic compiling pipeline that should be able to compile any given tex file into a pdf. The diversity of the input tex files mainly shows up in what format of figures they use and ...
25
votes
2answers
924 views

Understanding \@ifnextchar

I understand the definitions of the \makeatletter and \makeatother commands and also \def and \newcommand somewhat. But, explained in a simple way, what is happening in the following line? ...
5
votes
2answers
219 views

\xspace in combination with ifmmode

Sometimes I want a special font for the word "true", use it in mathmode as well as outside, and have a correct space afterwords if I am not in mathmode. Using \newcommand{\tru}{\ifmmode ...
6
votes
1answer
179 views

Checking if is Appendix or Chapter

How can i check if the value in \thechapter or \value{chapter} is a letter or a number? That way i could identify if the counter is referring to a normal Chapter or an Appendix.
6
votes
1answer
95 views

Test if a given control sequence is an \outer macro

I'm in need of a macro which receives a control sequence as argument to test if this control sequence is actually an \outer macro. I can code it myself as below . \documentclass{minimal} ...
12
votes
2answers
257 views

Missing Item number in enumerate

You would think that I would know better than to mess with an egreg solution, but in my defense I used a DavidCarlisle solution from \setbox vs. \sbox and \savebox - What are the differences I need to ...
3
votes
1answer
161 views

Glossaries package: ignore \newacronym if acronym has been defined before

I have a document consisting of multiple tex files, one per chapter, I am using the glossaries package to create list of acronyms. Ideally I want to define acronyms as close to where they are used, ...
8
votes
2answers
194 views

How to make a switch for print vs. display versions of a document with respect to links/URLs

I want the print version of a document have links or URLs written out but the online version have the abbreviated tag/name. So the switch, set at the beginning, will choose between two alternatives, ...
1
vote
2answers
321 views

String equality in \ifx conditional using output from concatenating macros

Please consider the following MWE - where I try to test for string equality between an parameter, and a test string prepared by a macro: \documentclass{article} \def\testStr#1{IOIO#1} ...
21
votes
5answers
341 views

Test if a given control sequence is a length register

I'm in need of a macro which receives a control sequence as argument and needs to branch if this macro is actually a length (of any kind, e.g. dimen, skip etc.) or "just" a normal macro (including one ...
10
votes
2answers
480 views

Automatically remove page number if document has only one page (but not if two)

I write a lot of documents (agreements) based on memoir with the article option. Normal pagestyleis plain (page number centered in the footer). Sometimes a document is only one page long, and a page ...
11
votes
2answers
175 views

Can I detect whether LaTeX is in vertical mode?

I am writing a command that creates a margin paragraph. This requires that this command is only used in vertical mode, which is fine. If the command is used in a float, LaTeX gives a "not in outer par ...
17
votes
4answers
983 views

How I can automatically add a page if the total number of pages is odd?

I need automatically add a blank page (also without document header, numbering and footer) at the end of the document, if the total numbers of pages is odd. How I can do that? And preferably without ...
14
votes
2answers
167 views

Is there a way to determine if there is a float on a page?

I am busy developing some code to draw layouts. Part of the code overlays the layout as shown in the images below: The black arrows to the side of the images, denote the \topfraction and ...
3
votes
1answer
150 views

PGF loop variables in string comparisons

In a bigger context, I need to check whether an integer parameter is contained in a set of numbers. I decided to encode sets as strings; elements are separated by !. I don't know whether this is the ...
12
votes
1answer
157 views

Formatting floats differently based on placement

I'm interested in changing how floats are formatted depending on whether they are placed at the top, bottom, or middle of a page, or on a float page. One package I am aware of that does something like ...
9
votes
3answers
435 views

Choosing styles conditionally in TikZ

I want to create a series of images that visualise a recursion tree as walked on by an algorithm. That means that different styles are applied to nodes depending on the step the algorithm is in, such ...
3
votes
1answer
141 views

How to compare two dates using TeX primitives

This is a follow up to TeX capacity exceeded while parsing a date string I want to compare two dates, say today's date and a due date. I have the due date information stored (as number strings) in ...
6
votes
2answers
322 views

How to check if a value is not equal using TeX conditionals?

I have a value defined in a macro, e.g.: \mymacro{apple} I need to check if a value does not equal a string, e.g.: IF #1 NOT EQUAL TO "apple" THEN PRINT "It is not a apple, it is #1." FI I ...
2
votes
1answer
228 views

conditional inside a pgfplotsinvokeforeach loop

I'm using \pgfplotsinvokeforeach to do mathematical computations inside the \addplot options. Now I need a conditional to decide whether to plot a line or not depending on the current index of the ...
9
votes
1answer
213 views

Macros for hiding empty sections do not work properly

In an attempt to make it possible to outline much of my document by adding new parts to it, but without making parts that I have not written anything on show up in the compiled document, I have ...
6
votes
1answer
467 views

Applying \middle outside of a \left \right group

Background: I am using the solution from Creating a large "such that" symbol which checks that \currentgrouptype=16 in order to be able to determine if we are in the middle of a \left ... ...
1
vote
1answer
103 views

Using toggles from etoolbox to switch Sweave Schunks of code on and off

I would like to use the toggles from etoolbox to direct Sweave to evaluate or not evaluate chunks of code. Example: \newtoggle{FirstTime} \toggletrue{FirstTime} %\togglefalse{FirstTime} ...
12
votes
2answers
166 views

\if@minipage purpose in floats

In floating environments such as the captions of figures, LaTeX has a \global\@minipagefalse, why is this necessary and what does this switch do? \long\def\@makecaption#1#2{% ...
15
votes
7answers
392 views

How to define a command to feed the contents of a list into an \ifcase construct?

It's common to use an \ifcase construct to redefine a command depending on the value of a counter. The following example illustrates this: \documentclass{article} \usepackage{xcolor} ...
9
votes
1answer
223 views

What documentation thoroughly explains how to use TeX conditionals?

I have a document which needs a large variety of plain TeX conditionals, e.g.: IF #1 >= 1 AND #2 >= 10 IF #1 != “tree” OR #2 == “mountain” IF 10 > #1 > 2 I have found limited ...
24
votes
4answers
2k views

How to check if a macro value is empty or will not create text with plain TeX conditionals?

I have a macro which holds some text value, e.g. \macro{some text}. If it is empty, I would like for nothing to appear in the document, but it has some content of any kind which would produce text ...
8
votes
3answers
319 views

How to make a plain TeX conditional which checks if some specific numbers are present?

I need to make a simple conditional in a macro. If #1 is "1", "2", "3", "4", "5", or "6", then print Text: #1, otherwise, do nothing, even if it is empty. I tried this code: \ifnum#1=1 Text:~#1 ...
4
votes
1answer
89 views

Asymetric behaviour in user command with conditionals

I use frequently a user defined command to highlight modifications in latex documents. \providecommand{\ifeqthenelse}[4]{\edef\tempa{#1}\def\tempb{#2}\ifx\tempa\tempb {#3} \else {#4}\fi} ...
5
votes
1answer
246 views

How to write a TeX conditional to test start of a new page (ConTeXt)

Currently using: \edef\lastpagenumber{\pagenumber} after starting a new page, then in subsequent text: \ifnum\pagenumber>\lastpagenumber do something \else do something else \fi But ...
3
votes
2answers
321 views

Using string conditionals to determine document class

I am trying to set up a set of templates for most of the styles I have created or collected. Right now I am using a bunch of LaTeX files with the \input{} and setting variables with \def. What I am ...
6
votes
1answer
594 views

Switch Between Bibliography and Appendix in fancyhdr

What I am trying to accomplish is a fancyhdr that places Appendix or Bibliography in the header with one single definition. So if I am in the bibliography it should display Bibliography, but should ...
2
votes
1answer
176 views

How to compare two counters using TeX conditionals in ConTeXt?

I have two counters, \definenumber[words] and \definenumber[items]. I have tried to use TeX conditionals to compare them, e.g.: \ifnum\getnumber[words]=\getnumber[items] This will print some text ...
12
votes
3answers
450 views

How to check if the value of a parameter is a number?

I have a command with a parameter. I want to check if its value is a positive number and perform actions based on that. \newcommand{\mycommand}[1]{ \ifnum#1>0% %some actions \fi } ...
8
votes
2answers
239 views

Custom ToC — Put vspace only below chapters that have sections in them

I’m using the titletoc package in the book class. Currently, my chapter entries are configured like this (I left out the unimportant parameters for simplicity): \titlecontents{chapter}[0pc] ...
3
votes
1answer
339 views

How can I place conditional statements in a LaTeX file dependant on how I'm processing it? [duplicate]

Possible Duplicate: Detect which TeX engine is used Conditional typesetting / build I'm currently writing a document in LaTeX (using the article documentclass for now, thinking about ...
1
vote
1answer
160 views

Unexpected conditional branch with \ifdim

I have a problem with the following code: \newtoks\sectoks \sectoks={\noindent} \newtoks\subsubjectstyle \subsubjectstyle={\emitsectglue 1\the\sectoks} \newtoks\postsectoks ...

1 2 3 4 5 9