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

7
votes
1answer
97 views

How can I set up my custom class to load a different class depending on the class option(s) passed?

I have written class files in the past. One of them is even up on CTAN. But that was ages ago, and I am rusty today. I am trying to roll a new class file for my University. I am being a little ...
7
votes
2answers
94 views

Detect closing braces with a command

I want to make a command that detects if the next token written in the document is a closing brace. My best approach is to use the \@ifnextchar command. In fact, the following code: \makeatletter { ...
1
vote
1answer
46 views

Macros with \fi for showing and hiding proofs [duplicate]

I would like to be able to globally showing and hiding proofs on a document, and be able to use macros to open and close the proof environments. Here is my current MWE: \documentclass{article} ...
3
votes
0answers
29 views

Changing a macro's output depending on immediate context [duplicate]

I've set up a macro for differential parts as so: \newcommand{\dd}[1]{\,\mathrm{d}#1} which is useful for differentials at the end of integrals because of the space. (I realise the argument ...
6
votes
1answer
213 views

How to do a conditional line break

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 ...
2
votes
1answer
29 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 ...
10
votes
3answers
182 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 ...
6
votes
2answers
107 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 ...
6
votes
2answers
147 views

Detect whether I'm in a \footnote?

How do I detect whether I'm in a \footnote environment or not?
3
votes
2answers
67 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 ...
9
votes
1answer
203 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 ...
0
votes
0answers
27 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
123 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
98 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 ...
4
votes
1answer
172 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 ...
6
votes
2answers
101 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 ...
2
votes
1answer
216 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
61 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
69 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 ...
4
votes
1answer
294 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] ...
21
votes
1answer
128 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. ...
1
vote
1answer
95 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 ...
16
votes
2answers
174 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
67 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
62 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
63 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
141 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
22 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 ...
7
votes
1answer
100 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
173 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
118 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
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: ...
4
votes
1answer
101 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
147 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 ...
0
votes
1answer
222 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
68 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
176 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}% ...
1
vote
1answer
82 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
76 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 ...
6
votes
0answers
208 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 ...
8
votes
1answer
81 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} {% ...
14
votes
2answers
586 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} ...
1
vote
1answer
66 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 ...
4
votes
0answers
62 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 ...
12
votes
4answers
480 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 ...
3
votes
1answer
101 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
372 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 ...
8
votes
1answer
292 views

How to remove end-if in algorithms

I am writing an algorithm in latex, but there are lots of end-if and end-whiles in my algorithms which makes it un-professional and ugly. Is there a way to remove them from output of latex? ...
10
votes
2answers
182 views

Conditionally use package and define command

I'm creating a class which should define a command if some package is available: \IfFileExists{eforms.sty}{ \usepackage[xetex]{eforms} \everyTextField{\textFont{GaramondNo8}\textSize{12}} ...
1
vote
1answer
82 views

Can a latex IF loop take a perl variable?

I have a script written in perl which harvest data from an sql database, then produces a printed report in latex. I was looking to put an IF loop in the latex part of the script to print one set of ...