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

0
votes
1answer
20 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
18 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
33 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 ...
5
votes
1answer
67 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} ...
1
vote
1answer
27 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
119 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?
2
votes
1answer
101 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 ...
5
votes
2answers
431 views

(x)ifthen in TikZ

I am searching for a way to conditionally handle some items in a TikZ \foreach specially using an \ifthenelse condition. However, the compiler responds ! Undefined control sequence. <argument> ...
2
votes
2answers
42 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 ...
1
vote
1answer
84 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 ...
3
votes
1answer
97 views

Is there a way to know how often latex has already run? [duplicate]

A few days ago, I have seen an example of a latex file, that did conditional \defs on subsequent runs but I can't find that one again. I still remember that it was by looking into the \jobname.aux do ...
5
votes
1answer
64 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 ...
40
votes
4answers
6k 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 ...
3
votes
1answer
49 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'. ...
25
votes
5answers
2k views

Testing for number

How do I test if a given parameter is a number, in order to apply a different style? And if not, just ignore... Like: \domorestuffifnumber{things} -> things \domorestuffifnumber{123} -> ...
4
votes
1answer
171 views

LaTeX block conditional including

I am researching possibility of building an automatic brief datasheet template in LaTeX, taking data straight out of a database. The database connection part is possible and can be done with such ...
3
votes
1answer
44 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 ...
4
votes
1answer
72 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 ...
4
votes
1answer
59 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 ...
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 ...
10
votes
4answers
147 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 # ...
3
votes
1answer
47 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
46 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: ...
8
votes
1answer
91 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]{} ...
2
votes
1answer
49 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 ...
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} ...
3
votes
1answer
64 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 ...
13
votes
2answers
155 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
2answers
67 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 ...
16
votes
2answers
776 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 ...
7
votes
5answers
286 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: ...
7
votes
2answers
150 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 ...
5
votes
0answers
63 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} ...
4
votes
1answer
52 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 ...
2
votes
2answers
106 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 ...
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, ...
12
votes
1answer
194 views

What's the difference in behavior between ifx and ifthenelse?

Why does the \ifx test give a different answer than \ifthenelse in the following simple example? testclass.cls (without the head and tail): \newcommand{\isempty}{\@empty} ...
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 ...
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 ...
4
votes
3answers
158 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: ...
8
votes
1answer
115 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
1answer
120 views

Conditionals—do something, if a given command is being used in the document

Is it possible to have a conditional that allow us to do something if a given command is being used in the document? For example for the \part command would be: ...
5
votes
1answer
77 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
74 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
392 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
51 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
91 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 ...
1
vote
0answers
67 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 ...
4
votes
1answer
52 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} ...