Tagged Questions

{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
1answer
23 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
111 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
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 ...
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 ...
3
votes
1answer
48 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'. ...
4
votes
1answer
58 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
56 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
40 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
46 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: ...
4
votes
1answer
70 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
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 # ...
2
votes
1answer
100 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
47 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
90 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
154 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
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 ...
3
votes
2answers
64 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
285 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
58 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
148 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
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 ...
5
votes
1answer
63 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
121 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
114 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
152 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
76 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
87 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
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} ...
1
vote
0answers
66 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
91 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
61 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
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 ...
0
votes
1answer
69 views

Menu Selection in LaTeX [closed]

I want to create a menu selection for different documents, what I mean for example is to run latex over the terminal, and the terminal prompt you if you want to create a diploma, a letter, a book, ...
1
vote
2answers
104 views

Ifthenelse variable equality

Last week I made simple coordinate transformation in order to define \tdplotsetcoord in Cartesian coord. system. My work and support of exp. user can be viewed in this topic. The code looks as ...
0
votes
1answer
120 views

ifthenelse equal string comparison fails

I am trying to fix some problems with the accessibility.sty package from www.babs.gmxhome.de There is one string comparison which always results to false, i.e. the language code definition will not ...
4
votes
2answers
39 views

vspace mysteriously being inserted after nested custom environment

I have created my own environment that creates a table using tabu and then puts some vertical space after it, unless my environment is being nested, in which case I want it to skip the vertical space. ...
0
votes
0answers
60 views

How do I add multiple macro definition inside an \ifbool compound statement?

What follows is my example doofus.sty: \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{doofus}% [2014/01/01 v0.01a LaTeX doofus package]%\filedate\space\fileversion\space \typeout{Package doofus, \csname ...
7
votes
2answers
265 views

Is there any analog to #pragma once in (La)TeX?

In C, I can write #pragma once as a preprocessor directive at the top of a header file, which tells any compiler that supports it to include the file a maximum of one time per compilation cycle, ...
4
votes
1answer
959 views

Simple if statement latex

Having difficulties understanding basic latex operations I want to use: if not (number between x and y): next iteration in loop Can anyone help me with a simple if statement for this? \newread\reader ...
3
votes
0answers
87 views

\if and \fi inside different \def macros

Recently I failed to solve specific task in LaTeX. I wanted to make document with several sections, each divided on several subsections. Each section I had placed to separate files, and used \input ...
3
votes
1answer
48 views

Print text when bibliography is empty

With biblatex, I'm looking for a way to check if the bibliography is empty, and if so, print some custom text. Something along the lines of this pseudocode: \ifempty\thebibliography [[ no ...