Questions tagged [conditionals]

{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}.

Filter by
Sorted by
Tagged with
9
votes
1answer
286 views

Testing for TeX boolean in Lua code

How can I test for a TeX boolean in Lua? This kind of code doesn't work: \newif\if@mypkg@someif \begin{luacode} -- some lua code \if@mypkg@someif -- some more lua code \else -...
5
votes
2answers
309 views

Biblatex: ifx inside DeclareFieldFormat

I'm not having any luck using an \ifx command inside a \DeclareFieldFormat block with biblatex (v1.6). Is there something I'm missing? A minimal (non-)working example: \documentclass{article} \...
39
votes
3answers
12k views

When to use @ in an \if statement

I am new to LaTeX and so this question might come across as rather basic. It might also reflect my biases/assumptions from my C/C++ programming days. I was seeing the code of the 'exam' class and ...
31
votes
4answers
2k views

Alternate he / she in text

This question led to a new package: he-she I have seen a book that instead of using the masculine pronoun (he, his, etc.) alternates the gender ('he' then 'she' then next time 'he' again). Is ...
17
votes
4answers
4k views

How to make a “condition” in a macro?

I would like to make a macro with two parameters which return a text. For instance, I want \M{1}{5} to return [1,5], and \M{2}{2} to return [2] (because the two arguments are the same). So I need to ...
11
votes
2answers
656 views

Can I conditionally scale an image with graphicx

In particular, when I include a graphic, I would like it to have width=\linewidth if it's width is greater than \linewidth, but I'd like it to have \scale=1 if it is smaller than the line width. In ...
5
votes
1answer
218 views

Testing for a blank line (“paragraph”) immediately after \begin{document}

(With this question, I hope to resolve an edge case relevant for my quoting package.) Suppose I define a customized environment for displayed text. It resembles the standard LaTeX environment quote (...
4
votes
3answers
506 views

Show “Page X of Y” only if there are multiple pages?

I'm trying to add a line in the header to be "Page X of Y", but only if there are multiple pages. My main problem is how to format the if statement. So far I have \ifx \pageref{LastPage} 1 \...
8
votes
3answers
413 views

Detecting which version of the LaTeX format is in use

ltxcmds provides \ltx@ifpackagelater, \ltx@ifclasslater, \ltx@iffilelater and there is \@ifpackagelater - but is there any "if TeX later" or some other way to (automatically) get the used TeX version (...
2
votes
1answer
269 views

Why is only one of these two options passed to pdflatex seen?

Consider the file define.tex. \documentclass{article} \RequirePackage{changes} \makeatletter \@namedef{Changes@AuthorColor}{red} \colorlet{Changes@Color}{red} \makeatother \begin{document} \ifdefined\...
2
votes
3answers
377 views

How to simulate 2 dimensional loop using 1 dimensional loop?

animate package does not allow nested loops. Only a single loop is allowed. However, we often need to simulate 2 dimensional space in a single loop. Please see the following C# code that I want to ...
12
votes
2answers
2k views

Test if a paragraph has a page break in it?

I'm trying to use TikZ to make fancier frames. I'm using the clever \tikzmark thing that Andrew Stacey wrote to put nodes at the top left and bottom right of the body of an environment. Then I use ...
1
vote
1answer
1k views

How to configure fancyhdr depending on the document class [duplicate]

Possible Duplicate: How to configure theorems depending on the document class? I would like to have if the book class is loaded but if the article class is loaded. Can I do this with some sort of ...
5
votes
1answer
654 views

How do I execute some commands conditionally?

What would be the correct way to execute commands conditionally in LaTeX? Here is the problem I am having. I have a book_pdf.tex where I wish to define the style of the book as it would look in a PDF....
5
votes
1answer
229 views

Defining a command that distinguishes between greek and roman letters?

I'm using pdftex and I want to define a command for the typesetting of quantum mechanical operators that produces upright letters with a \hat accent. The problem is that the obvious solution \...
42
votes
2answers
6k views

Opposite of \ensuremath: ensure that I'm *not* in math mode?

I'd like a macro that is the opposite of \ensuremath: something like \ensurenotmath, which makes sure that its argument is not typeset in math mode. Is there such a macro, or a way to implement it? ...
5
votes
3answers
3k views

TeX Nested Loops With \iftoggle

This forum has helped me understand how to use nested loops in TeX, but now I am having trouble using \iftoggle (from the etoolbox package) with loops. My goal is to have a toggle that can keep track ...
2
votes
1answer
441 views

Testing for multi-line paragraphs

I'm running into a situation where I need to insert some code (specifically, \hfill) only if my paragraph runs more than one line. This isn't a simple alignment thing, as I'm working with right-to-...
22
votes
1answer
4k views

How can I test if a document is being compiled by XeLaTeX?

Is there a way to programatically test whether the current document is being compiled by (pdf)LaTeX or XeLaTeX?
6
votes
1answer
302 views

What does \global\boolfalse{cbx@loccit} mean?

Pardon the newbie question. I see this in the first part of a \DeclareCiteCommand and I'm not sure what it means. Google has not returned any joy. Here's an example \newbibmacro*{cite}{% \...
29
votes
2answers
5k views

Doing something only when the draft option is on?

I would like to do some stuff that is only enabled when the draft option is given in \documentclass[draft]{article}. How would I go about doing this?
5
votes
1answer
407 views

biblatex: What's the first character of a field?

I would like to know, what's the first character of the value of the editor field. If the character is a curly bracket "{" the value should be printed for example bold, if the first character is ...
9
votes
1answer
478 views

Biblatex: Idiom for testing contents of list field

I am creating a Biblatex bibliography style for legal citations. In one particular case, I need to format the citation (of a court decision, i.e. jurisdiction) differently depending on the particular ...
1
vote
2answers
798 views

Book in two (or three) languages in LaTeX

I am writing a book in two languages: a Russian version and an English version. Is it possible to do this in the same file? Something like \tltext{Hello world!}{Здравствуй, мир!}, and mark at the ...
6
votes
2answers
913 views

Deciding Boolean operation in LaTeX via Linux Terminal

How do I decide a Boolean operation in LaTeX via Linux terminal? That is, I have: %myfile.tex \documentclass{article} if parameter=true is true else is false \begin{document} parameter \end{...
13
votes
1answer
600 views

How do I check whether the text will fit in one page?

I am trying to typeset a page that varies in length. Sometimes it's just shorter than A4, but sometimes it exceeds the length of A4. My question is, how can I check whether the text will fit in one ...
15
votes
1answer
6k views

\ifnum and pgfmath: error

In the following example I want to use \ifnum to compare two numbers computed by pgfmath, for simplicity I use simply 1 and 2 in the example below. Compiling this code gives me the error: ERROR: ...
9
votes
2answers
4k views

LaTeX: Use command argument in conditional?

I'm in the process of writing a command that outputs a certain text only if its argument is a nonzero number. I'd like to be able to write something like: \newcommand{mycommand}[1]{ \if{#1 != 0} Some ...
3
votes
1answer
250 views

Driver-dependent invocations of the graphix package?

The LaTeX General Guidelines show a conditional invocation of the graphicx package. I wanted to test this out. I did the following: Created a main.tex in which I LEFT OUT the big, complicated, ...
25
votes
2answers
13k views

Conditional cases expression

How can I create a command \if with 1 argument, namely #1, \if{#1=1}{symbol1}...{#1=n}{symboln} that returns symbol1, when #1 is 1, ..., and returns symboln, when #1 is n, and returns nothing, when ...
5
votes
1answer
447 views

Using \IfNoValueTF within a TikZ style specification.

In an answer to Flushing PGF commands and local variable Matthew had suggested using \IfNoValueTF within a TikZ \node specification to determine the text. This solution works great for me. However, ...
5
votes
2answers
769 views

If pagestyle equal to… — How should I ask it?

I'd like to use (or define) an If-statement for pagestyle. I have no idea :( Update: I'm using in my document about 4 pagestyles. Just as a little example I wish to have at the border of my document ...
8
votes
2answers
583 views

Passing text containing linebreaks as command or environment parameter?

I just tried to write some commands which used its argument to check whether they were empty (isempty{...} from package ifthen) or not. The problem was that the text to check contained a linebreak, ...
11
votes
1answer
620 views

Using ifthenelse for crop marks with tikz

How do I use to insert ifthenelse crop marks in Tikz. I want ifthenelse{\printcrop=true}{\draw(0,0) -- ++(0,1);}{} That is, if yes, make a drawing, else but do nothing. And yet, where I can choose ...
8
votes
1answer
876 views

How do I make make different versions of my document with command line compile flags?

I've found a number of answers online, and plainly none of them have seemed to be able to execute any conditional code. This answer looked particularly promising. One thing I noticed is that in the ...
1
vote
2answers
312 views

How to multiply compile according to selected tags?

I would like to do the following, by I am not sure how. Say I have a LaTeX file with series of annotations, each with zero or more "tags" (say, about their contents or the project they are related to)...
6
votes
2answers
658 views

In the verbatim environment, how can I display an 'if' statement I declared as '\ifcondition'?

I have declared a couple of if commands of the form \newif\iffinal \newif\ifsolutions Now I want to write about it in the same document! So I want to write something like \iffinal (...) \...
3
votes
1answer
531 views

Count number of paragraphs in command argument

Is there a way to count the number of paragraphs in a command argument? I would like to make a command doing something like this: \newcounter{\numberofparagraphs} \newcommand{\testcmd}[1]{ \...
7
votes
2answers
319 views

Nicer way to test that exactly one flag is set

I have a package that takes a long list of boolean flags (currently about 10) in its options, and I want to test if exactly one of these is set to true - something like an XOR for 10+ booleans. The ...
9
votes
2answers
2k views

Nest StrLen and ifthenelse commands

Here is a sample of code I am working on: \documentclass[10pt]{report} \usepackage{xstring} \usepackage{ifthen} \begin{document} \StrLen{123456}\\ %Prints 6 ...
4
votes
1answer
507 views

TikZ. Is there a way to alternate path to be drawn basing on some condition?

What I want is to connect nodes by stepped (horizontal-vertical-horizontal, hvh) path if they have different y-coordinate, and by straight line if they are on the same level. Costruction of the only ...
8
votes
2answers
3k views

\if@ statement explanation

I'm trying to tweak some .cls to fit my needs, and I'd really appreciate it if someone could explain me these statements: \if@radseminar% ... \else ... \fi If I understand correctly, it will match @...
15
votes
1answer
435 views

Conditioning behaviour of a macro on whether on top of a new page

Is there a way to find out, whether the currently typeset material will go to top of a page? I am trying to write a macro which, when invoked, typesets a horizontal divider to separate the subsequent ...
4
votes
0answers
160 views

Condition to determine if current line ends or starts the page [duplicate]

Possible Duplicate: Conditioning behaviour of a macro on whether on top of a new page I have two paragraphs with some separator (rule) between them. I want to make this separator appear only if ...
21
votes
2answers
3k views

Environments with conditionals in: why doesn't this work?

In response to this question I thought the obvious thing to do was the following: \documentclass{article} \newif\iffoo \newenvironment{foobar}{\iffoo}{\fi} \begin{document} \begin{foobar} Here is ...
25
votes
2answers
5k views

How can I test for the current font?

The situation is the following, I have one font a with one feature and another font b with another feature and I am writing a command that if the current font is a need to switch to font b but if the ...
6
votes
1answer
292 views

Asserting reference inequality

Is there a way for including assertions in a LaTeX document? I want to check that some condition is true, and only allow compilation of the document if it is (or at least complain otherwise). ...
6
votes
2answers
297 views

Telling LaTeX where to compile to from inside your document?

Here is a hypothetical scenario. I want to make a beamer presentation and a handout for that presentation. I start my file as follows: \newif\ifhandout \handouttrue \ifhandout \PassOptionsToClass{...
7
votes
1answer
361 views

Different content if command returns empty text (ConTeXt)

I have the following code in my ConTeXt environment: \startsetups[sectioninfo] \ss \rlap{\userpagenumber} \hfill § \getmarking[sectionnumber][current] \emspace \bf \getmarking[section][...
8
votes
1answer
1k views

Conditional compilation of beamer slides

I'm preparing a beamer slideshow, and I will have to print slides. I would rather use landscape mode slides, but it is possible that I need to use portrait mode ones. Sadly, I won't know until a few ...