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

3
votes
1answer
37 views

Changing symbol size when used as subscript

This is a follow-up to this question. I'd like to define \fa to display \forall when typed as usual but be \mathsmaller{\forall} when \fa is used as a subscript. For example, I want to write ...
2
votes
1answer
43 views

Define symbols differently in text mode versus math mode

I'd like to define \a to be the $\forall$ symbol, but I'd like it be the regular $\forall$ in text-mode and \mathsmaller{\forall} in math mode. Is there any easy way to do this? I'm guessing it ...
2
votes
1answer
35 views

How can I make condition inside the geometry options?

I would like to make condition inside the geometry options \geometry { headsep = \baselineskip , textwidth = 42\baselineskip , textheight = 60\baselineskip , hmarginratio = 2:3 , ...
2
votes
1answer
46 views

Optional text printed in another colour

I would like to extend the version package to print some optionally added text in a different colour. Something like in the following example: \documentclass{article} \usepackage{version} ...
2
votes
1answer
57 views

When using \IfEq to compare strings, is it one of those times when I should use an expandable xparse command?

I recently asked How can I migrate commands and environments from LaTeX2e to LaTeX3? [XeTeX] While that question is good, the answer is likely quite complex and would take a some time to effectively ...
3
votes
3answers
117 views

Changing page to pages if more than one page

At the beginning of my document, I need to list the total number of pages in the document. I've got a system that works most of the time (see below), but if the document only has one page, then my ...
3
votes
1answer
68 views

Modify nodes near coords with \if

I would like to code something like this: if \thecitation is {This work} then nodes near coords={\thenumber{} [This work]} and plot color is Red else nodes near coords={\thenumber{} ...
2
votes
2answers
19 views

Manipulating arguments to a macro inside an argument

In LaTeX, I have a macro \p (okay, it's \paragraph, but perhaps the specific macro is not relevant?) with one argument. Sometimes I use it as \p{plain text} and sometimes as \p{\t{alternate ...
2
votes
1answer
22 views

pst-barcode Argument of \pst@@object has an extra }

I have the ISBN stored in two commands (depending of a class option) \theisbne \theisbnp The boolean options of the class are defined using xifthen \RequirePackage{xifthen} ...
0
votes
1answer
62 views

Compilation of main document, if subdocuments are compiled

I have a main latex document, and many other files included with \input{...}, e.g. by chapter. Often, I just work on a subfile and my idea is now, that I want to compile the main document if I start ...
1
vote
1answer
47 views

XParse doesn't recognize some of my variables

Based on the comments from my last question have I tried to create a new command using \NewDocumentCommand. However, it wont recognize some of the optional arguments - they just get printed as is. Any ...
0
votes
0answers
25 views

how to define a general conditional for a complete text

I wonder how to define a newcommand of the type with general conditionnal \def\a{} which givefor each call in the text %\begin{comment} %\end{comment} when a=0 and \begin{comment} ...
2
votes
0answers
54 views

“Draft” mode for document

Suppose you want to keep two versions of the same document: one where you highlight changes and one where you show the final result. How can I use a "debug" or "test" mode to turn on/off my \textbf ...
3
votes
1answer
29 views

Adding code (pagebreak) after value change in csvsimple

Background I want to create a document with the user data of our network at school, which should be handed out to the user. This should be done class by class. Approach The user data are given in a ...
0
votes
3answers
84 views

If condition without any package?

I create a table by rows like this: \row{1}{Sunday,Su,05.09.2015}{N}{08:00,17:00,12:00,13:00}{8.0,1}{Airplane Hangar} How can I prove, if the first parameter is 0 or 1, an if it's 1 then set a ...
3
votes
2answers
116 views

Ifthenelse conditionals in moderncv's cventry

Now that Frodo has left to fight Sauron, Bilbo is all alone at home and searching for new things to do. So it came to his mind that he could apply for a job. For his application, he uses the moderncv ...
7
votes
1answer
109 views

Has LaTeX3 syntax possibly changed since this question was last answered

I am adapting the LaTeX3 answer in this question: http://tex.stackexchange.com/a/61603 But I can't get the original MWE answer to compile using xelatex. I have renamed the variables, but the error ...
2
votes
0answers
40 views

Access xparse's \BooleanTrue via latex3 expl3

I'm implementing a command with xparse's boolean token processing \NewDocumentCommand{\op}{s o t' t. t^ g}{ % Here I need to check for % (#3 || #4 || #5) && !(#3 && #4 ...
1
vote
1answer
41 views

Conditional list of tables in LaTex [duplicate]

List of Tables can be obtained by using listoftables commands. I wonder how to skip listoftables output if the document doesn't contain any table. Thanks \documentclass[11pt]{article} ...
2
votes
2answers
80 views

Set comment toggle to false, error: Undefined control sequence

I want to toggle comments of and on. Off works, but when I set toggle to true, then I get an error: ./main.tex:36: Undefined control sequence. \endtcolorbox ->\unskip \tcb@after@box ...
1
vote
0answers
39 views

Set comment toggle to false, error: There's no line here to end [closed]

I want to show/hide comments when toggeling the code below: \newtoggle{comments} %\toggletrue{comments} \settoggle{comments}{true} %set true to show all comments, set false to hide all comments ...
1
vote
1answer
53 views

Display or hide stuff in a document

I am using comments in LaTeX, which are defined in my document as: \newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}{}}\linebreak} I would like to add something like ...
13
votes
2answers
171 views

The following code compiles without error. How can I change that?

Unlike most questions on this site, my problem is that my code compiles without error and I do not want it to. I want to be able the check whether \command is defined and to do something if it is ...
4
votes
1answer
73 views

\newif inside function definition in LuaTeX

In a function I have in a package I'm working on I'm trying to add the following line: \expandafter\newif\csname ifgre@scale@#1\endcsname% Now, this works fine under LuaLaTeX, but the package is ...
0
votes
0answers
44 views

Programming in Latex: Conditionals [duplicate]

I'm trying to learn how to programming in Latex. I want to make an if-else-statement. What I will do is something like this: \def\x{2} { \if x =2 Yes \else no \fi } But it doesn't work exactly how ...
1
vote
0answers
27 views

Passing optional arguments to a listing environment based on conditionals

I am trying to make a presentation which can optionally compiled for handouts. This presentation also contains highlighted code snippets. For highlighting I use the code from this question. (Which ...
1
vote
1answer
96 views

Creating a grid with different color vertices (graph)

I am new to using tikz and I have never used ifthenelse statements in latex before, but I am trying to create a grid where the vertices on every other diagonal are a different color and shape. This is ...
2
votes
1answer
90 views

Ifx and end of line [closed]

Can anyone shed some light on this? I have an interesting problem involving the "There's no line here to end" error. EDIT: Variables. I did not think to include this as I thought there was only one ...
7
votes
4answers
208 views

How to check if a macro expands to one of several strings?

I have the following problem: I am using the etoolbox package to check if a macro (say, \foo) expands to one of several possible strings (say, bar, baz, abc, or other). I need to execute different ...
4
votes
2answers
116 views

“Runaway argument?” just in the \input file

Update: Upon @egreg suggestion, the case shown below is the core of the problem and has nothing to do with include/input statements. I have a verbatim within toggle statements, which fails. A minimal ...
3
votes
1answer
55 views

Automate importing pages from PDF file and add text to some of these

I'm trying to use LaTeX for lecture notes, but am having trouble implementing it the way I want to. For each lecture I will have access to a PDF file with presentation slides, where one slide ...
3
votes
2answers
61 views

How to tell if last sectioning command was chapter/section/subsection/…?

I'm trying to define a command which creates a part/chapter/section/subsection/... depending on the last defined part/chapter/section/subsection/... It should look like this pseudo code: global ...
3
votes
2answers
230 views

If, elseif and else conditionals in the preamble

I have a scenario where I need to define a few commands and environments based on some condition in the preamble. I used to use \newtoggle, set the conditional using \toggletrue or \togglefalse and ...
6
votes
4answers
129 views

macros with multiple arguments in absence of some arguments

I would like to define a command with two arguments, say \mycommand{arg1}{arg2} in such a way that if the second argument is absent, then it takes the first argument in place of the second one, in ...
5
votes
1answer
52 views

How to end a user-defined environment having conditional start definitions?

For silly example, the following user-defined environment initiates either the itemize environment or the enumerate environment, depending on the optional argument. But if the argument variable cannot ...
0
votes
0answers
32 views

Selecting source code based on boolean

Is there a way to select source code based on a boolean and not just select text to display. \documentclass{exam} \usepackage{ifthen} \newif\ifanswers \answerstrue \begin{document} \begin{questions} ...
2
votes
1answer
34 views

if statement problem

I am having a problem with some code and I could use some help. I have been using this implementation for a long time now and no problems before. Here is how I store all my variables ...
4
votes
1answer
142 views

Option argument for Beamer section slide

I am creating my own Beamer theme with a custom section slide. Ideally I would like the command \frame{\sectionpage} to have an additional, optional argument, that specifies the color of the ...
6
votes
4answers
138 views

Conditional choice of version

I have a document with several sets of questions clustered in different versions. I would like to be able to choose which version to generate with a single parameter. The document is updated ...
1
vote
1answer
69 views

Split a macro call and its argument in conditional

How can one split a macro call and its argument in a conditional? Why doesn't \ifnum 1=1\textbf\else\textit\fi{Foo} work? Why it yields error “Too many }'s”?
6
votes
1answer
84 views

subfiles not detecting draft mode

specs: win7x64, miktex, texstudio folder structure: root/ - main.tex - text.tex I get expected wider left margin in main.tex: \documentclass[draft]{article} \usepackage{blindtext} % ...
4
votes
2answers
35 views

Testing for macro change

In a package I'm writing, I have a macro (call it \foo) which, by default takes one argument and is equivalent to \relax. Under certain circumstances, the user may wish to redefine \foo in their ...
0
votes
0answers
35 views

Conditional compilation with tags to allow flexible output

For various beamer slides I'd like to be able specify more granular on what slides to include and what slides to omit in my compilation. I'd like to specify multiple tags for each slide and I'd like ...
2
votes
5answers
223 views

Package to test whether a string is in a list

Is there a package that provides a command for testing whether a string is in a list? I saw several answers that define their own commands to perform this or similar tasks, but I prefer a ...
3
votes
2answers
49 views

ifthen and etoolbox cause faulty index

I am using the ifthen package to include/exclude passages in my document. However, I have noticed that when I have two formatted index entries for the same term, one inside \ifthenelse and one ...
3
votes
1answer
26 views

Why do extra characters not show up?

While reading code from various sources, I have often come across the construct \ifx\\<sth>\\ to check if <sth> is empty or not. For example, in the code from this answer I see: ...
5
votes
3answers
203 views

Generate multiple PDFs for different document versions in a single build

I am writing a document for a software which has two versions. Most of the content in the document is the same except few specific details. Right now, I am using the conditionals to build the document ...
4
votes
1answer
28 views

How to use `\@ifdefinable{xfoo}{…}` when `\foo` is already defined?

The following code fails to compile: \documentclass{article} \makeatletter \newcommand{\foo}{xyzzy} \@ifdefinable{xfoo}{\relax} \makeatother \begin{document} ... \end{document} More precisely, ...
2
votes
0answers
28 views

Robust handler of arguments with conditionals and complex elements

Context This question is a follow up of the answer of this question Spurious space on moderncv \cventry using \if Problem The problem is that complex content (for example, itemize on the content of ...
7
votes
4answers
180 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)} } ...