{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
32 views

Set PGFplots coordinate label using ifnum

I can't overcome this little nasty issue. Using \ifnum I set labels position around the coordinates in my pgfplot. This works fine but : I am only able to test if variable \coordindex is greater or ...
6
votes
1answer
170 views

Is it possible to test whether small caps are available with the current font?

Is it possible to test, in the document body, whether small caps are available with the current font (both for pdf(la)tex and xe(la)tex)? What I'd like to do is something like: \usepackage{xifthen} ...
3
votes
1answer
42 views

Checking the mainmatter

I need to check where the text (from package .sty), if it is in the mainmatter section, then include some headers \pagestyle{LL}, if the other then \pagestyle{plain} or some other. Construction ...
8
votes
2answers
105 views

Incomplete \iffalse using \phantom

Can anyone help me debug the code below? As written, it produces an Incomplete \iffalse error on the \xdef line on the final iteration. The problem is somehow related to the \phantom macro, as ...
9
votes
3answers
210 views

Why in the discussion of the definition of \newif are the following things true

This is a couple of questions that stem from the answer to Problems understanding definition of \newif by @egreg. In that @egreg says Let's look at \expandafter\expandafter\expandafter ...
3
votes
2answers
124 views

How to pass vertical line

I have the following problem. The general idea is to test whether #1 is empty and if it isn't then write vertical line "|" and #1: \documentclass{article} \usepackage{makeidx,hyperref} \makeindex ...
0
votes
1answer
25 views

Command (using \ifthenelse) within 2nd optional (post) argument of footcite

I have defined a new command \mypageref to reference page numbers of text parts in my appendix. The begin of such a text part is labeled, e.g., by \label{text_begin}, and the end of the text part is ...
2
votes
1answer
22 views

If used insdide \cs_new(_protected), \IfNoValue(TF) doesn't detect -NoValue- at document-level

I guess my problem is related to Commands from xparse inside functions created by \cs_new:Npn? but I still don't understand what's going on: in the following WE (not minimal, sorry for this), why ...
2
votes
2answers
38 views

Make an item in itemize disappear if a condition is not met

Here is the MWE: \documentclass{article} \newcommand{\VarOne}{1500} \begin{document} I want this list to have item Two if VarOne is more than 1000. If it is not, this will be a two item list. By the ...
1
vote
1answer
30 views

Biblatex: Selecting content depending on language

I am using biblatex and would like to quote English and German works. When writing a document in German, this works nicely with the help of \DeclareLanguageMapping and hyphenation to specify if a ...
3
votes
3answers
124 views

Safe test for an empty expanded macro argument?

How can I test in a safe way (i.e. without reserving tokens as explained here) if an expanded macro argument is empty?
1
vote
1answer
93 views

Incomplete \iffalse error in AMS alignment

MWE: \documentclass[a4paper]{report} \usepackage{amsmath,xparse} \makeatletter \newif\ifinvd@lims\invd@limsfalse \newif\iflr\lrfalse \ExplSyntaxOn \newcommand{\delim}[3][lr]{ \begingroup ...
2
votes
2answers
43 views

Environment which sends text conditionally to an appendix?

I am writing a paper and would like an environment that has the following property. If some flag is set to "true" in the preamble, all text wrapped in that environment is sent to the appendix. If the ...
3
votes
1answer
59 views

program IF-THEN-ELSE alignment

I am using the 'program' package to describe a function. When I use the IF-THEN-ELSE statement I expect the lines to be aligned relative to the 'if'. But the lines are aligned relative to the 'then'. ...
5
votes
1answer
73 views

Conditional statement in beamer style file

Here is an example of a part of a beamer style file I use for a presentation: { \nointerlineskip% \begin{beamercolorbox}[wd=\paperwidth,ht=0.6cm,leftskip=.3cm,rightskip=.3cm]{frametitle} ...
4
votes
1answer
70 views

incomplete ifnum

I am using a loop to define keys with the xkeyval package, as well as to actually read out the keys inside some self-defined command. Everything works perfectly - but for some reason, as soon as I ...
3
votes
1answer
49 views

Nested \ifdefined statements

I am trying to populate a list of variables (in the attached example starting with \@addressone) with the values obtained from a set of commands. The first variable will get the first of whatever ...
1
vote
0answers
11 views

overfull \hbox ..with figures (like to do If scale>width, use max width) [duplicate]

Well, I'm having a problem with figure. I'm using figures like this: \begin{figure}[!ht] \centering \includegraphics[scale=1]{\importacaodedados importacaodearquivos.png} \caption{Importação de ...
3
votes
1answer
50 views

Opening and closing brackets in combination with the ifthen package

Related to this question, however, I was not able to solve my problem. Let me give some background. I want to switch between the article style and a specific journal style. The journal style has ...
4
votes
2answers
54 views

Randomly select one of two possible texts

Let's say I have two possible questions. I want only one to be on the generated PDF and I want this one to be randomly selected among the two potential candidates. I thought this would be sufficient: ...
4
votes
1answer
75 views

Trouble setting header content conditionally with titlesec and extramarks

I'm writing a commentary on a Classical text and trying to imitate many of the layout choices of the Cambridge Greek and Latin Classics series. In particular, I've been working on having the header ...
10
votes
4answers
148 views

# in conditionals in alignment tabs?

I am looking for ideas how to make TeX understand that when # appears both in the if-else and in the else-fi part of a conditional in an alignment tab, in the end there will never be more than one # ...
2
votes
1answer
103 views

How to conditionally draw nodes of a tree in TikZ

I want to draw several trees with tikZ (Version 2.10) which are very similar in the sense that there is a first tree and the others are obtained by ommiting some of the nodes of the first one. I ...
2
votes
1answer
53 views

How to test whether pic text is empty in TiKZ?

If I wish to add a pin to a node in TiKZ, I can do so like this: \documentclass[tikz,border=5pt]{standalone} \begin{document} \begin{tikzpicture} \node [draw, thick, circle, minimum ...
8
votes
1answer
94 views

Incomplete \iftrue is valid input?

Is LuaTeX beta-0.79.1 correct in thinking the following is valid input: \iftrue \bye
1
vote
1answer
27 views

Is there a way to display a specific command and hide the rest

I would like to use the same Latex source file for both my document and the accompanying slides. When creating a document it's easy to hide the slide sections by doing this: \newcommand{\slide}[1]{} ...
1
vote
0answers
18 views

Conditional for documentclass [duplicate]

I was wondering whether it is possible to execute a command depending on the used documentclass. \documentclass{dinbrief} %\documentclass[a4paper]{letter} \usepackage{ifthen} \begin{document} ...
13
votes
2answers
156 views

ifx, macros and grouping

I do not understand how \ifx interacts with macro definitions. Here is a minimal example: \def\a#1{\b} \def\b#1#2{[#1:#2]} \a ABC The output is [B:C], as expected. If I change the definition of \a ...
3
votes
1answer
66 views

Smaller vertical space between repeated environments

I have a new environment that is defined with addvspace at the beginning and end. This works fine if it is surrounded by text. Now, I want this space to be smaller (smallskipamount) between these ...
3
votes
2answers
68 views

Conditionals used in defining of new environment

I want to produce two versions of one document with different content. The idea is to comment out certain sections if a logical variable is false. This logical variable will be inputted eventually ...
7
votes
5answers
287 views

Read number from file

I have a file called _runs.ini. Depending on its content, the document is compiled differently. I tried to read the content and executed a \ifthenelse-command without success. Here's my MWE: ...
5
votes
0answers
83 views

How to translate \ifthenelse from “ifthen” to “etoolbox”?

Trying to make conditional expressions that inspect the total page count of the document (see this question), i've found this solution using ifthen package: \documentclass{article} ...
7
votes
2answers
153 views

How to use the total page count in a conditional expression?

I would like to have different footer or page style depending on whether the document has one or more pages. I am not very experienced with TeX programming, so the answers about "Comparing an argument ...
4
votes
1answer
59 views

Аnalog of \ifodd condition for verification if page number is equal to some constant

I have a great example of using \ifodd condition if \makeatletter environment showed by @Symbol 1. \begin{document} \makeatletter \newbox\LT@oddhead \newbox\LT@evenhead ...
5
votes
1answer
65 views

Wonky behavior from \@ifnextchar,

When I compile the below MWE the first \@ifnextchar, always evaluates to false, which is clearly wrong in the last case. However, the second one (within \punctuationcheck) works just fine. Why would ...
7
votes
1answer
122 views

Omega appears from if result

I am attempting to edit an if statement that I was using in an environment I created. Previously, the code was \if #1\empty \else \textbf{#1.}\hspace{0.5em}% \fi I want to change it to something ...
1
vote
1answer
35 views

Is there a way to have different behavior for even pages and odd pages

I would like to modify the below template so that it prints out 1 problem per sheet. Example: Problem 1 on pages 1-3, problem 2 on 5-6 and nothing on page 4. Another Example: Problem 1 on Pages 1-2, ...
0
votes
0answers
42 views

Output two files

I'm tiring of maintaining two different CV and resume .tex files and want to combine them into a single file. I'm considering etoolbox as a way of combining my CV and resume into the same. Then I ...
8
votes
1answer
120 views

Defining a command that scans every arguments' macro “looking for” a token

Knowing that every command declaration with conditionally optional arguments, as \foo{...} expanding into \foo[default]{...} can be defined by \newcommand\foo[1][default]{...} or the safer version of: ...
4
votes
3answers
178 views

Tikz: draw a circle only in selected nodes

I created a table of nodes using tikz. And now I want to draw a circle inside every even node. I started from just trying to draw a circle in the second node. But my code is not working: ...
5
votes
1answer
83 views

Defining a command that conditionally defines/checks for counters

In order to complete one custom package command I needed an internal macro, I called it \@test@count{❬argument❭}, and should accomplish the following: Internally defines a new counter \❬argument❭ ...
4
votes
1answer
75 views

Write multiple pdfs with different options

Thanks a lot for the help in advance. This might be a stupid question, or a potential overkill for this kind of forum, but the situation is as follows: I'm writing my dissertation and - of course - ...
8
votes
5answers
400 views

A command which concatenates a string an arbitrary number of times

I'm trying to define a command \repeatstring{#1}{#2} which repeats the string #2 #1 times. Here is what I tried: (it is based on what I found in How to concatenate strings into a single command?) ...
0
votes
1answer
58 views

Showing/Hiding verbatim environment based on boolean condition

I would like to show and hide a verbatim or spverbatim environment based on a boolean condition (sth. like \showenv). I tried the solutions proposed at Hide custom environment content based on ...
5
votes
1answer
100 views

Conditional based on the version of pdflatex?

I would like to do this: \pdfsuppresswarningpagegroup=1 However, this feature is only supported by pdftex 1.40.15 and higher. How can I do this conditionally, so that my document won't be broken in ...
4
votes
1answer
54 views

Auto colour numbers in range

If I had some numbers in a tabular column, is there a way to automatically change the font colour of them if they are outside a range; eg red if under 10 and green if over 50? \documentclass{article} ...
1
vote
0answers
69 views

Conditional spacing based on length of chapter title

In LaTeX, (or possibly XeLaTeX), how can one achieve the following: A double spacing a 1- or 2-line chapter title, and single spacing under a 3- or more-line chapter title. A triple space ...
5
votes
2answers
102 views

How can I check if the filename of a LaTeX document contains a string?

I am preparing a LaTeX beamer presentation for students. I am looking for a simple way to create two versions of my presentation. One version for the Students, which just contains the text of the ...
3
votes
1answer
64 views

Conditional Zebra Tables

First, I'm using LyX with a rather long preamble because I want things fairly specific, but almost all the code in the preamble is cut-n-pasted from the 'Net with a couple modifications. I'm not a ...
2
votes
2answers
115 views

LaTeX3: If next in input stream is command X or environment X, do Y else Z

Because I write my own document class (okay, I try to ...), this question bothers me for weeks as there are many situation, in which I need something like this. Is there a way to test, if the next ...