{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)

1
vote
0answers
70 views

Adding Text to Caption via Style File [closed]

I am trying to add text to a caption via a sty file. With the following code: \ifthenelse{\equal{#1}{caption}}{% {Sample Tex \\ Added Here} }{}% The style file will add "Sample TexAdded Here" ...
3
votes
1answer
331 views

Adding vertical spacing between chapter and its first section in table of contents

I'm using the style files given by my university for my thesis but they are quite old (eethesis document class). In my PDF output, the vertical space before and after the major headings in the table ...
2
votes
1answer
164 views

Homework generation [duplicate]

Possible Duplicate: Conditional typesetting / build I have a database of LaTeX homework questions like this: question1 question2 question3 etc Is it possible to create a flag to ...
3
votes
2answers
292 views

Beamer conditional pdf file generation

I would like to know if there is a method to generate beamer pdf presentation based on conditions. For example: -Main Beamer presentation: Slide 1 Slide 2 Slide 3 Slide 4 Slide 5 -For the first ...
1
vote
1answer
118 views

conditionally emit one table or another

I would like to specify a table and if it has any multiline cells then it should be output as a single pair of columns and otherwise as two pairs of columns. For example, if it looks like the First ...
1
vote
1answer
73 views

How to deal with conditions with many nested \and and \or?

This simple example will fail because of the priority rules are not taken into account : \documentclass{article} \usepackage{ifthen} \begin{document} \newcommand{\bibi}2 \newcommand{\toto}3 ...
4
votes
1answer
207 views

Counters for use in array/tabular cells

The following practical example \documentclass{article} \usepackage{array}% http://ctan.org/pkg/array \newcounter{tabcol}\newcounter{tabrow} \newcolumntype{C}{>{\stepcounter{tabcol}}c} ...
4
votes
1answer
447 views

Define command that returns true/false (multiple conditions)

While using the datatool-package I encountered something strange. I have a loop, and each iteration it defines some variables that are later used by the command \DTLforeach from the datatool-package. ...
5
votes
1answer
153 views

blank lines break xparse or ifthen macro

Leaving blank line break simple macro but % terminating it fixes it. WTH is going on? I know one is suppose to use % BUT I can't have any blank lines in the macro without it complaining. A blank line ...
10
votes
2answers
563 views

Implementing switch cases

I'd like to have command built around a switch-case environment in LaTeX, much like the example below: \documentclass{article} \usepackage{xstring} \newcommand{\dothis}[1]{% \IfStrEqCase{#1}{{a}{so ...
5
votes
1answer
968 views

Boolean variables in LaTeX

I am trying to use "boolean" variables in LaTeX but am unable to have any success... I have a macro which takes 5 arguments, the last argument being optional. This macro is named educationItem and it ...
13
votes
1answer
171 views

Why does “\if\char98\char98 T \else F \fi” return F instead of T?

According to the TeXbook the two tokens following \if are expanded and compared? It seems then that \if\char98\char98 T \else F \fi should be the same as \if bb T \else F \fi which does return T. What ...
10
votes
5answers
778 views

Teach me how to use \loop…\repeat constructs, etc

The following code snippet is a part of the solution given here: \def\IncludeOutput#1{ \parskip=2mm \def\examplename{#1} \pdfximage{\Directory/\examplename.pdf}% ...
9
votes
1answer
834 views

Best practice for getting “If not foo” conditionals

So, here are two ways you might set things up such that \dostuff is done when foo is false. The "new conditional" method If you know when foo is going to be set, then after that do: \newif\ifnotfoo ...
5
votes
2answers
132 views

How to test if some command similar to \author is used in .tex file?

I want to modify \maketitle command in a new document class based in memoir. \maketitle command should include a new \director command similar to author. If this command is defined in text file, the ...
13
votes
5answers
2k views

new command with cases / conditionals / 'if… then's

Suppose I want to define a command, say, \tree with, say, two arguments. I would like \tree to do different things depending on what my first argument is. For example, if #1 = a, then return ...
5
votes
2answers
473 views

Error using \string

Consider \documentclass{article} \usepackage{lmodern} \usepackage[T1]{fontenc} \begin{document} \texttt{\string\iftrue} %% \texttt =\long macro: %% #1->\ifmmode %% ...
6
votes
1answer
236 views

Advanced conditionals

Is there some way to create more advanced conditional statements that can evaluate a logic expression and decide what to do based on the value of the expression? For example like in the following very ...
4
votes
2answers
449 views

Bold author if source is an article

i got some articles i cite in my thesis. The author should be bold in the bibliography but i dont know how. I tried to use \textbf in the bibtex file but then the format isn't correct anymore. Would ...
6
votes
3answers
181 views

How to “demux” several aspects from a `\foreach` variable with `\ifstrequal`?

How can I "demux" several features from a mode specification given in a \foreach? I would like to use a \foreach to draw several nodes in a TikZ picture. The loop will specify a mode for each ...
8
votes
1answer
962 views

How to use mod operation in latex with tikz

I need something similar to \ifnum \j mod 2 = 0 rest of a number, but do not know how to do this in line 22. \documentclass{article} \usepackage{tikz} \usepackage[active,tightpage]{preview} ...
5
votes
2answers
137 views

\let versus conditionals for customizing macro behavior

I have a large collection of macros that do different things but all eventually use the same macro internally (call this macro \tasks). Sort of like this, but with better macro names: ...
6
votes
1answer
137 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
102 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
220 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 ...
22
votes
4answers
1k 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
97 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. ...
9
votes
1answer
805 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
176 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
155 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
600 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 ...
5
votes
2answers
2k 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
327 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
373 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
286 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
415 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 ...
28
votes
2answers
2k 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
299 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
300 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
103 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
393 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 ...
4
votes
1answer
313 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
288 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
559 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} ...
22
votes
5answers
348 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 ...
12
votes
2answers
622 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
234 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 ...
20
votes
5answers
2k 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 ...
15
votes
2answers
212 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
215 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 ...