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

2
votes
1answer
27 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
79 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
49 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
28 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
59 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
35 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
87 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
157 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
115 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
54 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
48 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
141 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
46 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
71 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
176 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
84 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
46 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
37 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
148 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
157 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
216 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
151 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
67 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
74 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
340 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
136 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 ...
6
votes
1answer
73 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 ...
2
votes
1answer
46 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
38 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
159 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
163 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
77 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
94 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
40 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
37 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
229 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
54 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
30 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
220 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
35 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, ...
3
votes
1answer
102 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
188 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)} } ...
6
votes
1answer
284 views

natbib + BibTeX: suppress url if doi is available

I am using natbib (+ BibTeX). Some entries in my bibliography file (.bib) have the field doi, some have url and some have both. I would like to edit the bibliography style file (.bst) so that, if doi ...
1
vote
1answer
42 views

Compile \showtrue and \showfalse to different target files

I'm writing a problem set with a solution. Right now I have the following setup: \newtheorem*{sol}{Solution} \newif\ifshow \showfalse \ifshow \newenvironment{bluesol} {\begin{sol} ...
3
votes
1answer
100 views

Conditional section title [ifthenelse] not working

I have the following code: \documentclass{article} \usepackage{ifthen} \usepackage{amsmath,amsfonts,amsthm,amssymb} \newcommand{\probName}{}% \newcounter{probCounter}% \setcounter{probCounter}{1} ...
3
votes
0answers
41 views

How can I efficiently create variants of a conditional?

Say I have the following: \prg_new_conditional:Nnn \sean_cond:n { T,F,TF } { \prg_return_false: } How can I efficiently create the following? (This list is arbitrary.) \sean_cond:nT \sean_cond:nF ...
0
votes
1answer
40 views

Why doesn't my \csname-based glossary macro work inside \section and \caption?

I'm a LaTeX newbie. I have a custom macro called \gloss that decorates its argument in a certain way - let's say that it adds a star symbol for the purpouse of the MWE. I have wrapped it around a ...
3
votes
1answer
61 views

Include preamble statements depending on compiler

I am trying different compilers like pdfLatex, luaLatex, latex to try differences in compiling things like pgfplots. But when i shange the compiler I also need to change the preamble. How can i do ...
2
votes
1answer
90 views

How can I conditionally reference a figure?

So here's my knitr .Rnw file: \documentclass{article} \usepackage{hyperref} \hypersetup{} \begin{document} \let\ref\autoref <<plot,fig.cap='try'>>= if(rnorm(1) > 0) x = rbinom(1, 100, ...
16
votes
1answer
240 views

Cleanest way to prepare bilingual document and output only one language [duplicate]

I am currently preparing the presentation for my internship evaluation. As a French student evaluated by researchers that may or may not speak French, I would like to maintain two versions of my ...