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

2
votes
1answer
90 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
87 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 ...
3
votes
1answer
72 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
87 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
92 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
60 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
52 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
143 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] ...
20
votes
1answer
122 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
73 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
138 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
49 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
59 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
58 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
102 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
21 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
72 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
112 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
108 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
88 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
65 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
84 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
77 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
62 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
108 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
62 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
69 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
103 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
79 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
336 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
49 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
56 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
469 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
76 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
365 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 ...
7
votes
1answer
89 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? ...
9
votes
2answers
129 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
67 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 ...
5
votes
1answer
182 views

Numerical conditional within tikz keys?

I would like to set up a presentation in which different parts of the same tikz picture appear, depending on the value of one, perhaps more, integer variables. I tried at first using a fixed picture, ...
18
votes
1answer
353 views

How to check if a variable contains a word in plain TeX?

I have a variable that contains a long list of keywords, e.g.: \keywords{computers, business, biology, fine art, literature, zoology} I need to make an if-then statement that checks for the ...
3
votes
0answers
142 views

Conditional formatting, rounding and postprocessing of a column in pgfplotstable

I want to round p-values in a table to two decimals (for example 0.05), have values less than 0.05 in bold font and have values less than 0.01 to come out as '<0.01' in bold font. Like this (the ...
5
votes
2answers
143 views

Is it possible to exit from the PostScript expression and abort the drawing?

I just want to draw a dot if the condition is satisfied and otherwise cancel the drawing of the single dot. The following code is the simplified version of my real scenario. Please don't suggest other ...
14
votes
3answers
897 views

Equivalent to “in” operator

I want to write a command that responds to an argument being in one set of reference strings or another. The argument takes a (musical) note name, and the command will print an accidental depending ...
10
votes
1answer
110 views

Pass conditional options to documentclass

I'd like to pass options to \documentclass basing on the compiler it runs, something in the lines \documentclass[if latex then use dvipdfm else nothing]{beamer} My motivation is that there're ...
2
votes
0answers
156 views

Constraint for a decoration: how to know result after decoration

My question is kind of extending of this answer. I want to decorate a path with text only when text fit the path, but also I want to know if decoration was success. I need to know this to be able to ...
5
votes
1answer
108 views

Using `ifthenelse` to combine two related functions into one

This question is based on Peter Grill's answer to "Table including rows of a master table".. The function PrintDTLTable was in Peter's original answer. I wanted a version that would run over all ...
4
votes
1answer
126 views

\ifnumcomp + \ref

I have a definition with 20 cases or so, and a proof about that definition has one case for each case of the definition. I'd like the proof cases to reorder themselves automatically when I reorder ...
7
votes
1answer
94 views

How to do pagenumbering in a fancy way

How do i get uneven increasing page numbers in the first half of my document, and in the second half in the second half? Example: 1,3,5,7,8,6,4,2 Here are my thoughts on how to solve it: My LaTeX ...
3
votes
0answers
56 views

how to add conditions inside itemize list?

List mentioned below is having three items. There are four variables : 1] varone 2] vartwo 3] varthree and 4] sub ; which are coming from external CSV file. Item 2 with "Value B" will be displayed if ...
1
vote
0answers
41 views

Indicating that the adjustwidth environment should be placed around text

I've been trying to work out a solution to this question about changing margins for body text without changing header/footer placement. Using the changepage package, I was able to work out the ...