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

5
votes
1answer
47 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
57 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
98 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
67 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
108 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
107 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
87 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
81 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
72 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
100 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
58 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
68 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 ...
5
votes
0answers
96 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
76 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} {% ...
12
votes
2answers
285 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
48 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
71 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
359 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
81 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
125 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
66 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
179 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
352 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
129 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
138 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
894 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
107 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
155 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
106 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
121 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
92 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
40 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 ...
1
vote
0answers
13 views

Commenting out large blocks in the preamble when in draft mode [duplicate]

I would like something to enable me to comment out large blocks of my preamble when I've specified that my document is a draft. The comment environment provided by the verbatim package works well for ...
6
votes
1answer
84 views

How to detect if there is one or multiple pages in a glossaries entry's number list?

I'd like to be able to print e.g. "p. 1" if an acronym is only used on one page and e.g. "pp. 1, 2" if it is used on multiple pages. I have tried to define a new counter and use its value in the ...
4
votes
1answer
59 views

Check if the last letter of a name is an s or x or neither nor

In German we have a (often disregarded) rule for using apostrophes. In English it is like so: "This is Mike's chair." In German it depends on the names ending. It's like this: "Das ist Mikes ...
2
votes
2answers
42 views

Display first (sub) environment in an environment

I would like to make a bank of problems of similar type--however, I only want to display the first of each time. For example: \begin{bank} \begin{exercise} 2+2 \end{exercise} \begin{exercise} 4+3 ...
7
votes
2answers
238 views

math conditionals using (if - else - fi) command

I saw these command when i searching sth. I wonder if we can increase numbers if conditions. it's like if{0} = a, if{1}=b, if{2}=c, if{3}=d etc. \newcommand{mycommand}[1]{ \if{#1 != 0} Some text, ...
3
votes
1answer
103 views

One source text, two outputs [duplicate]

I have very long source text. I want to create two outputs: All text Only small pieces of this source text, selected by condition command MWE (precisely: not working) \documentclass{article} ...
6
votes
2answers
96 views

\RequirePackage within \if\else\fi

Why does the package iftex have to be loaded outside of a \if...\else\fi structure? (The same goes for packages ifpdf, ifluatex, ifxetex.) Consider: ...
11
votes
2answers
179 views

New command with if/then statement conditioned on non-integer number?

In LaTeX, how do I declare a new command that gives different output depending no the result of a test with non-integer numbers? Specifically, I'd like to a command to compare a number with 0.01 (the ...
1
vote
2answers
117 views

csvsimple filtering problem

The following code works as I would expect. \documentclass{scrartcl} \usepackage{csvsimple,filecontents} \begin{document} \begin{filecontents*}{chunk.csv} AAAA,aaaaa BBBB,bbbbb CCCC,ccccc ...
3
votes
0answers
53 views

Conditional Variation of \headheight

I'm trying to use \ifthenelse from the ifthen package to vary the size of \headheight within a document. I'd like this to be larger for the first page and then smaller for each subsequent page. I ...
8
votes
1answer
81 views

Very simple condition in macros

I try to define a macro in LaTeX. This macro should give a different output when I use condition true and false. This does not work: \documentclass{article} \usepackage{lipsum} \newif\ifABC \ifABC ...