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

0
votes
2answers
644 views

How to number a conditional equation

I am writing the following syntax to get a conditional equation. But the equation is not numbered. How can I number it? \[ f(x) = \begin{cases} x+7 & \text{if $5< x$}; \\ x^2-3 & \text{if ...
6
votes
2answers
245 views

How to select conditional text?

I've three variable statements : Statement1 = You are Great Student. Statement2 = You are average Student. Statement3 = You Need improvement on list of topics mentioned below. In the report ...
6
votes
4answers
306 views

Is there a better way to check divisibility in LaTeX?

I want to draw a trimmed ruler, for example, from 2.3cm to 3.9cm where the distance between two consecutive marks is 1mm. I have difficulty to efficiently check whether or not the counter is a ...
9
votes
3answers
256 views

What is wrong with \ifnum#1=0.09\relax?

The following code does not compile with the following error message Missing = inserted for \ifnum \documentclass[pstricks,border=4pt]{standalone} \usepackage{multido} ...
2
votes
1answer
102 views

Conditional execution based on style existence (listings)

Is there a way in LaTeX (or e-TeX) to check if a style is defined using the listings package (inside a \lstnewenvironment definition)? I mean something like this: \lstdefinestyle{tmpdefaultstyle}{} ...
12
votes
1answer
715 views

If not DeclareOption

I have some documents using a same custom package. That "header" package loads by default the package fullpage. But I would like to write a new LaTeX document, using the same header, but without ...
2
votes
1answer
103 views

Conditional use of multicol

I'm using the multicol package to get two columns, but sometimes the contents is too wide in a particular column and I was wondering if there is a way to first make sure the contents will fit ...
11
votes
2answers
179 views

How to create a macro “environmentally-dependent”

Yesterday I was reading the etoolbox documentation where there are defined some new document commands such as: \Before<Begin/End>Environment{<envir>}{<code>} % ...
4
votes
1answer
93 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 ...
1
vote
0answers
27 views

Name separators, if condition for same command [duplicate]

I am new to LaTeX, just a Beginner, Basically a perl developer, I have created a .tex file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
6
votes
2answers
117 views

Separators for author group (IF conditon)

I am new to LaTeX, just a beginner, basically a Perl developer. I have created a LaTeX file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
3
votes
1answer
111 views

header-footer configuring

Need to start page numbering from the n-th page (in this case 6); used ifthen and fancyhdr packages. So, no dotted lines since page 6 and page 5 is already numbered. \usepackage{ifthen} ...
5
votes
2answers
267 views

Putting Multiline Conditional Equations

I am trying to write two equation like, a=b when a>1 a=c when a=0 One obvious choice is putting all in a tabular construct, as, \begin{tabular}{ll} $a=b$ & \text{when $a\ge 1$}\\ ...
5
votes
1answer
119 views

Any way to set a variable externally?

I just posted a question and can now generate a conditional section in a text: how to make a conditional document feature But to extend and generalize the question, first how could I create a ...
4
votes
2answers
157 views

how to make a conditional document feature

I saw in another question about how to create a condition, of which the best practice recommended was \iftoggle. I want to create a macro that will allow the creation of a teacher's note, a section ...
3
votes
1answer
85 views

`\ifhtlatex` needed for running tex4ht with different code [duplicate]

It is much easier to write my texts in an editor with LaTeX, but often clients ask for a word file. tex4ht does a good job, it produces html from a tex-file, which can be easily used. But there are ...
1
vote
1answer
250 views

Tabu/Longtabu: Conditional Column Definition

I want to create a longtabu table with a conditional number of columns: In development mode, 5 columns should be visiable. In the final version, only the first and the last column should be visible. ...
14
votes
5answers
572 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. ...
6
votes
2answers
141 views

Branching construct based on the (babel) language selected

I'd like to keep one of my presentations in German and English and have defined a corresponding boolean variable withifthen and a command to typeset either the German or the English text. Is there ...
4
votes
1answer
400 views

conditional content

I'm writing a document in LaTeX that I want to compile in two different versions, V1 and V2 (with two different formatting specifications). Sometimes I need to insert a bit of content into V1 that ...
5
votes
1answer
58 views

Change Sectional Skip Conditioned on Text Existing or not Before Sectional Division

I have a simple document layout with a main heading for the title, and the possibility of starting the first sectional unit (with a standard \section command) right after the title -- meaning, with no ...
7
votes
3answers
209 views

Defining tabular rows with macros using `\ifnum` leads to `Incomplete \ifnum`

I am trying to define tabular rows using a macro which shall perform an conditional definition of the tabular row according to a given parameter. Please consider the following MWE: ...
14
votes
5answers
277 views

A macro that conditionally disregards the need for one of its arguments

Let's suppose I want to write nested equations that contain a fair few nested parenthetical/delimiter characters, like (), [], {}, ||, and perhaps others. Suppose too that I think these things look ...
9
votes
2answers
95 views

How to expand \ifthenelse so that it can be used in \parshape?

How do I get the following MWE to work: \documentclass{article} \usepackage{xifthen} \usepackage{lipsum} \newboolean{bar} \setboolean{bar}{true} \def\foo{\parshape = 2 ...
5
votes
1answer
64 views

How to “count” some table cells and print the result?

Thanks to an answer from David Carlisle found on this site I managed to code this: \documentclass[a4paper,10pt]{article} \usepackage{colortbl} \usepackage{xcolor} ...
4
votes
3answers
765 views

Misplaced \omit and \multicolumn in \IfEqCase

I have the following code with a command that creates rows for a tabular: \documentclass[letterpaper,10pt]{article} \usepackage[utf8]{inputenc} \usepackage{xstring} \newcommand*{\condrow}[2]{ ...
21
votes
2answers
413 views

Show footnotes on odd pages only

I'm writing my thesis using the scrbook-class. Is it possible to display footnotes only on the odd (right) pages? This should mean that \footnote{something} should be collected on even pages and ...
4
votes
1answer
649 views

Use of the comment package

In a .tex document, I'm using the comment package to produce two different versions (let's say : versionA and versionB) of the document. Each version contains different parts (it could be paragraphs, ...
17
votes
3answers
835 views

Conditionally Remove Brackets

I'm trying to create a command with an optional argument using \newcommand{\Af}[1]{{\mathbf{A}_{(#1)}} where the argument is a number. However, I'd like that if no argument is given the bracket ...
3
votes
1answer
154 views

Are there more to applications of \iftrue and \iffalse?

While reading "TeX for the impatient" on the topics of iftrue and iffalse, I encountered this example, \def\isbigger{\let\bigger=\iftrue} \def\isnotbigger{\let\bigger=\iffalse} \def\test#1#2{\ifnum ...
10
votes
1answer
362 views

XeTeX UNICODE Table

I would like to try to write a minimal XeTeX source that generates a comprehensive UNICODE table, substituting in local fonts as required by the current plane. I made the attached code as an MWE for ...
4
votes
1answer
94 views

Testing for “emptiness” (theoretical consideration)

Consider the following theoretical problem: Sometimes, in LaTeX one wants to do the simple test if a macro is empty, e.g. \def\foo{% This is... \ifx\baz\@empty Sparta! \else a pony farm. \fi } ...
13
votes
1answer
373 views

Create Two PDF versions of Classroom slides from Single LaTeX file: Teacher and Student

Is there a way to create a single document that will process a LaTeX file in two different ways (different preambles) and produce two different outputs. Specifically, I want to produce a set of ...
34
votes
3answers
4k 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 ...
6
votes
1answer
89 views

Conditionals in lstlistings

I am trying to put in some lines of code using the lstlistings-package but the code differs on conditionals. How can I only change some lines depending on the conditional? Assume I have the If: ...
9
votes
1answer
427 views

Conditional format for correlation table

I'm using the script by Christian Feuersänger: \documentclass{standalone} \usepackage{colortbl} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotstableset{ /color cells/min/.initial=0, ...
2
votes
2answers
110 views

How to make an 'if' on roman numbered pages and another 'if' on arabic numbered pages

I want to make some conditions on roman pages and another condition on arabic numbered page. (I want to know how to remove the background from specific pages in both numbering categories). ...
1
vote
0answers
161 views

Knitr/LaTeX: conditional execution based on external parameters

I'm using knitr to create LaTeX documents with integrated R code. Now I'd like to readout some external parameters (saved in a TXT or CSV file) and create a document based on the conditions specified ...
8
votes
2answers
236 views

Problem of having \begin…\end inside \ifdefined…\fi clause

I am using beamer, and have a LaTeX code as below. \ifdefined\VAR \begin{itemize} \item blahblab \end{itemize} \fi this does not compile, throwing an error: ! Incomplete \ifx; all text was ...
2
votes
1answer
67 views

Conditional based on packageoption

I added a counter to the todonotes packages \todo so I could display the total number of todos I have left. However I also enjoy working with the package option disabled. Therefore I would like to ...
5
votes
1answer
91 views

\IfFileExists is acting inconsistently when testing another boolean in conjunction with \input

I've been refactoring some code and clearing out obsolete commands. I don't understand what's happening here: \begin{filecontents}{mkif} \newif\ifaeRoughDraft \def\testforRoughDraft ...
13
votes
4answers
294 views

How do you test whether a known key value has been set in pgfkeys

Using the .code handler to my keys and a private macro, I can easily test whether a key has been set when using pgfkeys. For example: \documentclass{article} \newcounter{mytestenvcounter} ...
2
votes
0answers
102 views

Equivalent of CSS adjacent selector in LaTeX [closed]

In CSS you can use the adjacent selector to create conditional formatting. For example, p + p to format a paragraph that follows a paragraph, or h1 + p to format a paragraph that follows a h1 element. ...
4
votes
1answer
286 views

Replace lstlisting with verbatim depending on a boolean

I use latex2rtf to convert latex documents to .rtf and thence to MS-word (see this thread). To do this, I set up a custom class and limit which packages are used as latex2rtf only accepts a limited ...
10
votes
2answers
155 views

How to test if-condition using \csname within an \ifcase branch

I am trying to test an if-condition, where the name of the condition depends on a macro argument. To do this, I use \csname ifcondition#1 \endcsname. This works fine in a simple macro like this: ...
3
votes
2answers
393 views

Setting a flag to make text visible in LaTeX

I am in the process of CV writing and some pieces of information are necessary to include in some applications, whilst in others they are unnecessary. For example, when applying for ...
5
votes
1answer
148 views

How to create two PDFoutput from the same source

I have a very long source file. I would like to prepare from this source two PDF files: PDF contains all of the source file PDF containing only a few, marked earlier parts of the source file. How ...
7
votes
2answers
180 views

newcommand conditionals

I am looking to create a command that adjusts my page layout, here is a sample: \newcommand{\margin}{ \pdfpageheight 297mm \pdfpagewidth 210mm \pagebreak \newgeometry{lmargin=31.5mm, rmargin=31.5mm, ...
8
votes
3answers
655 views

Detect aspect ratio in beamer

I'm doing my slides with beamer. At the moment I am not sure about the aspect ratio that will be used at the presentation. I know I can change the ratio with class options of beamer. The problem is ...
3
votes
0answers
36 views

Unexpect differences between calling \ifmmode from within a command and outside a command [duplicate]

In answering another question regarding testing for math mode, I proposed the following command \newcommand{\testa}{% \ifmmode ^{12}\text{CO(1-0)}% \else $^{12}$CO(1-0)% \fi } But ...