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

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
113 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
110 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
260 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
117 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
154 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
84 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
247 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
552 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
140 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
342 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
198 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
94 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
63 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
712 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
408 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
608 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
831 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
145 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
340 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
93 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
364 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 ...
32
votes
3answers
3k 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
423 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
109 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
150 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
234 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
90 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
281 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
101 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
280 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
152 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
369 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
147 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
171 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
633 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 ...
8
votes
2answers
177 views

Macro with environmental dependent output

I'm trying to develop a macro that gives two different outputs depending on whether it is in math mode (i.e. $ $ or \begin{equation} ... \end{equation}) or anywhere else. The reason is that I use a ...
9
votes
3answers
932 views

Using counters and \ifthen in a macro: what's wrong?

I have (made, actually) a graphic of the forepaw-print of a bear that I want to use as a flourish mark at the end of chapters and a few other places. After finishing with the image, I created a mirror ...
5
votes
1answer
118 views

Is PDF capable of conditional display and, if so, how can I achieve it with pdfTeX/friends?

Most of the time, we (or more conservatively, I) think of PDF as a static format fit for printing. I've been surprised in the past at how versatile it is -- how dynamic and interactive it can be -- ...
5
votes
2answers
155 views

Variable persist outside environment

I am using the ifthen package for some conditional formatting. I am storing state in some booleans, but it seems that there is an issue with lexical scope. In particular, when a boolean is set within ...
3
votes
2answers
129 views

Conditional to \begin and \end some environment

The conditional structure of the macro of the MWE allow print two text strings as "true" and "false" alternatively. So you can print something like "false true false true false true" calling six times ...
0
votes
0answers
33 views

Include subsections depending on variables/ifthen [duplicate]

I am making a template for several books. I have a mainfile which includes the .tex files for my chapters. For each book, some chapters are always almost the same except for a few subsections. How ...
13
votes
1answer
613 views

Column break only if within first column of multicol

Background Creating books automatically using LaTeX-escaped user-generated content. Problem The book layouts make use of the multi-column package, with the book content separated into sections. If ...
1
vote
2answers
148 views

How can I toggle the document between print and view mode?

Is there a possibility to set a key into my header which defines the desired output of my document? I can imagine three modes: Print (black and white) Print (colored) PDF for display view With ...
5
votes
2answers
161 views

Conditional linebreak in align environment

I have a large document to typeset in two different page formats. Some of the equation lines are too long in the small format so I wanted to break some equation lines conditioned on whether the macro ...