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

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
59 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
119 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 ...
2
votes
1answer
96 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
87 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
130 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
110 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 ...
1
vote
1answer
125 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
113 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
63 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
69 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
73 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
137 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
86 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
80 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
59 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
54 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
473 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 ...
17
votes
5answers
844 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
160 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
86 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
367 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
108 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
153 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
69 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 ...
4
votes
1answer
85 views

Test if two things typeset identical results

I want to test if two somewhat arbitrary things typeset as exactly the same thing. For example I would like the test to tell me that abc is different from xyz, but is the same as \def\bar{abc}\bar. A ...
5
votes
1answer
197 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
359 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
174 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 ...
10
votes
3answers
839 views

Choosing styles conditionally in TikZ

I want to create a series of images that visualise a recursion tree as walked on by an algorithm. That means that different styles are applied to nodes depending on the step the algorithm is in, such ...
5
votes
2answers
147 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
901 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
118 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 ...
26
votes
3answers
2k views

Parametrize shading in table through TikZ

I wanted to do some shading in a table according to its values. For example, if you see the table below: a b c d a 90 10 0 0 b 0 80 10 10 c 0 0 95 5 d 0 10 5 85 I want to ...
13
votes
5answers
521 views

Test if the first character of a string is 'a'

Is there an easy way to make a macro returning a string (e.g. 'true') if the string input begins by some fixed character, say 'a' ? I can't figure how to combine the different packages to do this. ...
5
votes
1answer
116 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
144 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 ...
98
votes
4answers
37k views

LaTeX conditional expression

I would like to be able to set a flag at the beginning of the main flag (say output) that tells if I want to produce a paper document or an electronic document. Then I should check this flag to ...
7
votes
1answer
99 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
59 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
43 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 ...
4
votes
1answer
445 views

LaTeX3: Defining key to set boolean variable

I want to define a key, which, if set, sets a boolean variable to false. The documentation is not clear on that point. It states (source3.pdf, sect. 87, p. 134): Defines <key> to set ...
1
vote
0answers
14 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
87 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
66 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
44 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 ...
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} ...
7
votes
2answers
296 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, ...