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

4
votes
0answers
63 views

How to do a conditional line break - edited

I want to know how to do a conditional line break. Whenever the error message "There is no line to end here" comes, I want to disable the line break, otherwise to enable it, with a \\ command or ...
3
votes
2answers
45 views

Suppress month and day for journal articles and maintain for a newspaper articles

I haven't found a solution yet for this problem. I want to suppress month and day (if present) from all journal articles in bibliography but I at the same time I want to indicate year, month and day ...
2
votes
1answer
21 views

textpos toggling noshowtext option

Is there a way of toggling the textpos option [noshowtext]? I would like some textboxes to show the frame but not the text. And others to show both frame and text, but can't seem to find a way of ...
2
votes
1answer
455 views

how to use memoir \ifoddpage

Why does \ifoddpage seem to always return false in the following example? This is related to question 6143 on this same forum. I'm using XeLaTeX to produce a pdf file (i.e., xelatex test.tex) ...
9
votes
3answers
157 views

Global Conditional

I'm writing a set of notes for my students on trigonometry. At present, they have not met radians, which comes next year. I would like to use the same set of notes for them, but this year, give them ...
15
votes
4answers
2k views

Making switch/case with etoolbox's \ifdefequal

I've got a define such as \def\doctype{SomeString}. \doctype can take on one of five values. I want to do something like a switch statement in a programming language, i.e. (pseudocode): switch ...
8
votes
1answer
74 views

Problems understanding definition of \newif

Reading http://profs.sci.univr.it/~gregorio/introtex.pdf, I have come across the definition of \newif on page 75: \def\newif#1{\@ifdefinable{#1}{\@newif#1}} \def\@newif#1{\count@\escapechar ...
5
votes
2answers
106 views

Detect whether I'm in a \footnote?

How do I detect whether I'm in a \footnote environment or not?
16
votes
6answers
8k views

If Then Else for odd page/even page

How to use if-then-else structure in LaTeX? I need a example of odd and even page. if odd then command 1 else command 2
3
votes
2answers
43 views

Detect whether I'm on a left- or right-hand page? [duplicate]

How do I detect whether I'm on a left- or right-hand page? I would like to define a custom command with a conditional statement that executes a certain command if it's on a left-hand page and another ...
0
votes
0answers
25 views

Make left-hand pages' `\marginpar` text right-aligned [duplicate]

\marginpars only appear on the right margins of right-hand pages of my manuscript. For left-hand pages, they are are so far to the left that they aren't even on the page. The reason is because the ...
2
votes
1answer
60 views

How to get float numbers as parameter of \newcommand

I have defined a \newcommand function like into this code: \documentclass{scrartcl} \usepackage{pbox,calc} \newcounter{pointsExo} \setcounter{pointsExo}{4} \newcounter{pointsSousTotal} ...
5
votes
2answers
72 views

Is there a way to query the page size that I have set in the memoir class?

In my preamble, I have: \documentclass[a5paper,10pt,oneside,onecolumn,openany]{memoir} I would like to later define some layout options based on the value of the page size, which in this case is ...
5
votes
2answers
75 views

How to distinguish between Metafont and MetaPost?

Background I'm trying to make a nice SVG out of Knuth's Dangerous Bend symbol based on his own code, for which the obvious tool to use is MetaPost. However, I'd prefer to still be able to process the ...
3
votes
1answer
31 views

FancyVerb Error when using minted in a \ifthenelse

I'm new to LaTeX and wand to add some code with minted, which will only be rendered, when a \boolean variable is true. Here's my code: \documentclass{article} \usepackage {minted} \usepackage ...
4
votes
1answer
50 views

Command to disable environments [duplicate]

I have defined an environment called answer that displays the answer of a question of a test I'm supposed to prepare. The idea is to compile a version where the answers are displays and one were they ...
2
votes
1answer
65 views

TikZ-ifthen: decision making in a \foreach statement

Disclaimer I am not a programmer so I may not use the proper terminology to express myself. Please correct me if need be. Preamble I'm trying to draw a sinusoidal function and some arrows at ...
5
votes
1answer
57 views

How to check whether two labels fall on the same page?

I'd like to have something like 5--10 in the header of an article (my document is a journal issue) if it spans the pages 5-10, and 5 (as opposed to 5--5) if it is short and fits on one page. I use ...
4
votes
1answer
44 views

How to swap subcaptions of zoomboxes?

I greatly appreciate the zoomboxes given in this question: How to create magnified subfigures and corresponding boxes for portions of a large image. As the comments thread is already long enough I ...
3
votes
1answer
69 views

Conditions for fancy chapter title

I use a book class and here is a part of my fancy title page for the mainmatter chapters. \newlength\chapterwidth \settowidth\chapterwidth{\huge\chaptertitlename} \titleformat{\chapter}[display] ...
30
votes
3answers
2k views

Difference between \if and \ifx

I try to understand the subtleties of TeX programming, but it is not always easy. For example, in the following code : \def\first{abc} \def\second{abc} \ifx\first\second OK!\else false \fi I ...
1
vote
1answer
52 views

Conditional formatting in moderncv

We busily discussed a method of implementing conditional statements in the moderncv class (Conditional content in moderncv) last month. Sean Allred came up with a great solution to solve this (see ...
20
votes
1answer
117 views

Is implicit `\relax` in conditionals explained anywhere in the TeXbook?

I have been relying for years on TeX's behavior where, say \if1\fi expands to nothing and \if1\else\fi does the same. In the second case TeX inserts an 'implicit' \relax when it tries to expand \else. ...
16
votes
2answers
119 views

Does etoolbox's \ifboolexpr use lazy evaluation?

In other words, is bool{testB} evaluated at all in this example code? \newbool{testA} \newbool{testB} \booltrue{testA} \booltrue{testB} \ifboolexpr{ bool{testA} or bool{testB} }{OK}{Something's ...
5
votes
1answer
31 views

how to use conditional to define different \begin and \end environment at compile time

I just need little help on the syntax for this. I am using tex4ht, and I get an error when I use empheq for the align environment. I want to build this TeX file both in pdflatex and htlatex. I ...
6
votes
1answer
53 views

Conditional based on character following the macro

Basically, I would like to something like \xspace does, i.e. the meaning of the macro should depend on what is following it. So for example if I say \mymacro a it might expand to foo, and if any ...
1
vote
0answers
56 views

Special conditionals (TeX)

Is there a way to compare strings rather than single tokens? Is there a way to check if a parameter in a command is a string or a single character? If there is either, how do I?
5
votes
1answer
67 views

Only show header if section number > 0

The current section name + chapter.section number is shown in the header. This is normal behaviour (what I want). Example: How can I remove the header text, if there is no section on the page. The ...
0
votes
0answers
20 views

Conditional on counter definition (TeX) [duplicate]

Is there a way to make a conditional where the test is the definition of a counter with a specific name, i.e. "if there exists a counter named foo, then do [bar], otherwise do [baz]"? If so, how do I ...
2
votes
1answer
57 views

Conditionally Hiding Parts of Bibtex Fields Depending on Language Field Value

I would like to create a document with a bibliography using XeLaTeX with Biber. In the bibliography, there are Chinese books and articles, as well as English or German ones. Some of the authors have ...
7
votes
1answer
58 views

\apptocmd into a conditional—why it does not work?

Why the following MWE does not work while if I comment the conditional it works? \documentclass{beamer} \makeatletter \@ifclassloaded{beamer}{ \usepackage{bookmark} \usepackage{etoolbox} ...
5
votes
1answer
64 views

Nested ifnum conditional groupplots with pgfplots?

I want to use groupplots, and set a variable to conditionally plot the plots. Here is the minimal non-working example: \documentclass{article} \usepackage{pgfplots} \usetikzlibrary{calc} ...
6
votes
2answers
99 views

How do I declare and pass conditions to commands?

I'm new to LaTeX so I'm not quite sure how to proceed with this. I'm trying to have different versions of the same document, depending on which variables are set. What I want is to change the whole ...
4
votes
0answers
85 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: ...
1
vote
1answer
79 views

Newcommand returning a boolean value

I'm using etoolbox. How can I create a new command that returns a boolean value? For example if I create the following command: \newcommand\ifkeyempty[1]{ \def\novalue{\pgfkeysnovalue}% ...
0
votes
1answer
46 views

\@ifundefined actually defines macros? [duplicate]

Is it just me or is it a bit illogical that \documentclass[a4paper]{article} \begin{document} \makeatletter \@ifundefined{chapter}{}{} \makeatother \ifdefined\chapter chapter\else no chapter\fi ...
5
votes
2answers
56 views

Does the LaTeX kernel define font-shape macros that expand to `it', `sc', etc.?

I need to perform a test on the current font shape. More specifically, I need to detect whether the current font shape is italic or slanted. Joseph Wright already provided a solution in his answer to ...
1
vote
1answer
45 views

Check the value of a pgfkey

I need to be able to check if the value of a pgfkey is empty or not. A solution I have tried (using package etoolbox): \edef\temp{\pgfkeysvalueof{/path/key}}% ...
4
votes
2answers
66 views

Why is it not possible to embed \if construction in docstrip

I would like to create a DTX files which could be compiled in two different ways depending of a user's choice. One way to get only the user documentation, and another to get user documentation and ...
11
votes
2answers
244 views

String comparison in \ifthenelse

I want find a certain line of text in a data file cities.txt: A;London B;Berlin C;Paris with the xstring and [xifthen][2] packages: \documentclass[12pt, a4paper]{article} \usepackage{xstring} ...
4
votes
0answers
68 views

Display beamer headline in frames conditional on section and subsection environments

I'm trying to create a beamer presentation (in LyX) where frames conditionally display a headline containing section and subsection navigation depending on (a) whether a frame is in a section ...
4
votes
1answer
75 views

PSTricks, conditional frame size

Consider the following code: \documentclass{article} \usepackage{pst-eucl} \usepackage{siunitx} % LaTeX 3 syntax \ExplSyntaxOn \cs_new_eq:NN \calc \fp_eval:n \ExplSyntaxOff % constants ...
8
votes
1answer
69 views

Why won't \ifx match on list element of a foreach list if that element is a macro?

I have the following: \documentclass{minimal} \usepackage{tikz} \begin{document} \begin{tikzpicture} \def\nend{6} \def\rb{1.5mm} \draw (0,0) -- (\nend,0); \foreach \x in {0,...,\nend} {% ...
4
votes
0answers
54 views

Checking environment in order to end it

I used to typeset verse with memoir package using some heavy \vspace trickery. The verse environment was too hard to control in terms of vertical space due to the immense amount of obscure glue. For ...
1
vote
1answer
42 views

Remove empty row inserted by etoolbox

I generate table with some conditional expression using toolbox package. \documentclass{article} \usepackage{etoolbox} \begin{document} \providetoggle{ch} \begin{tabular}{ |l|c|} \hline ...
12
votes
4answers
460 views

Condition within condition

Consider the following logical satatements: If \conditionA != 100 and \conditionB != 100 do ``Something~A'' If \conditionA != 100 and \conditionB = 100 do ``Something~B'' If \conditionA = 100 and ...
16
votes
5answers
722 views

Combining \ifxetex and \ifluatex with the logical OR operation

I want to write in the preamble of a LaTeX document code that should be take into account by different compilers when the document is typeset. There are fragments that should be used: only by ...
3
votes
1answer
151 views

Enable and disable contents of \chapter command

I have large set of contents for the user. For a different user I would like to show different contents. For this I would like to produce different output by showing and not showing some of the ...
3
votes
1answer
52 views

Check if a number is in a comma separated list (print or display selected sections from a specific list)

I'm trying to check if a section number belongs to a specified list: \ifnum\value{section}=\mylist % check if section number in mylist --- WRONG \dosomething \fi The conditional is ...
17
votes
2answers
349 views

Why does this simple \ifx test fail?

This should be easy, but I don't understand why the test below fails... I expected Hurrah! to be printed when the \currentchar count reaches 90 (i.e. the character code of Z). There must be some ...