The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
8
votes
3answers
819 views

How to make a plain TeX conditional which checks if some specific numbers are present?

I need to make a simple conditional in a macro. If #1 is "1", "2", "3", "4", "5", or "6", then print Text: #1, otherwise, do nothing, even if it is empty. I tried this code: \ifnum#1=1 Text:~#1 \...
5
votes
1answer
122 views

Asymetric behaviour in user command with conditionals

I use frequently a user defined command to highlight modifications in latex documents. \providecommand{\ifeqthenelse}[4]{\edef\tempa{#1}\def\tempb{#2}\ifx\tempa\tempb {#3} \else {#4}\fi} \...
5
votes
1answer
579 views

How to write a TeX conditional to test start of a new page (ConTeXt)

Currently using: \edef\lastpagenumber{\pagenumber} after starting a new page, then in subsequent text: \ifnum\pagenumber>\lastpagenumber do something \else do something else \fi But ...
3
votes
2answers
1k views

Using string conditionals to determine document class

I am trying to set up a set of templates for most of the styles I have created or collected. Right now I am using a bunch of LaTeX files with the \input{} and setting variables with \def. What I am ...
6
votes
1answer
1k views

Switch Between Bibliography and Appendix in fancyhdr

What I am trying to accomplish is a fancyhdr that places Appendix or Bibliography in the header with one single definition. So if I am in the bibliography it should display Bibliography, but should ...
3
votes
1answer
705 views

How to compare two counters using TeX conditionals in ConTeXt?

I have two counters, \definenumber[words] and \definenumber[items]. I have tried to use TeX conditionals to compare them, e.g.: \ifnum\getnumber[words]=\getnumber[items] This will print some text ...
28
votes
3answers
6k views

How to check if the value of a parameter is a number?

I have a command with a parameter. I want to check if its value is a positive number and perform actions based on that. \newcommand{\mycommand}[1]{ \ifnum#1>0% %some actions \fi } ...
8
votes
2answers
596 views

Custom ToC — Put vspace only below chapters that have sections in them

I’m using the titletoc package in the book class. Currently, my chapter entries are configured like this (I left out the unimportant parameters for simplicity): \titlecontents{chapter}[0pc] {\...
5
votes
1answer
719 views

How can I place conditional statements in a LaTeX file dependant on how I'm processing it? [duplicate]

Possible Duplicate: Detect which TeX engine is used Conditional typesetting / build I'm currently writing a document in LaTeX (using the article documentclass for now, thinking about switching ...
1
vote
1answer
521 views

Unexpected conditional branch with \ifdim

I have a problem with the following code: \newtoks\sectoks \sectoks={\noindent} \newtoks\subsubjectstyle \subsubjectstyle={\emitsectglue 1\the\sectoks} \newtoks\postsectoks \postsectoks={\par\...
5
votes
1answer
493 views

How to control the PDF output based on the compiler being used?

I have a batch file that will compile the same input file with 3 compilers one after another as shown below. This mechanism is used to see the file size of the resulting PDF (before and after ...
21
votes
1answer
2k views

Require a certain (or later) version of a package?

Is there a way to enforce that a certain version, or a later version, of a package is loaded when building the document? I've found that compiling a document on another platform, where the package ...
18
votes
3answers
4k views

Conditionals in \newcommand

I find myself using the \newcommand macro a lot and apart from having the occasional difficulty with properly defining the optional parameter the macro works well. There is one serious limitation ...
31
votes
5answers
3k 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 xelatex ...
5
votes
1answer
588 views

Problem with a conditional in a tabular

I want to use conditionals to fill a tabular, but it fails. My MWE: \documentclass{article} \usepackage{environ} \newcounter{mycounter} \NewEnviron{montab}{% \setcounter{mycounter}{0} \...
10
votes
3answers
958 views

Different \section for odd and even pages

I would like to make the section titles look different on even and odd pages. I have the following MnWE with the trivial approach. The problem is that you don't know that your section header gets ...
5
votes
2answers
217 views

Two different text outputs depending on some parameter definition

I am using the astronomy and astrophysics class aa.cls. I use it with either of the two options: structabstract or referee. The first produces 2-column text, the second one-column text. I have some ...
13
votes
1answer
1k views

How to make \section start automatically in new page, except first in a chapter

I am working in report class. I would like to redefine \section so that it starts on a new page, except for the first section in every chapter. It seems I should just put code from this answer Start ...
4
votes
1answer
379 views

Comment Multi-line Text on Counter Condition

I have a document which I want to print in several (let's say 10) different versions. Some parts are just a draft, others are more or less finished, some are ready for publication and so on. I would ...
12
votes
1answer
329 views

How can I check if the current code is inside a tikzpicture?

I read the answer for this question (inside a environment) but I would like to know if there is something more specific. LaTeX keeps the current environment in the macro \@currenvir but how do the ...
11
votes
2answers
265 views

How can I check if a header has an ending full stop?

I am modifiyng some macros to enforce a section style that should end with a full stop. The full stop is added automatically, but sometimes people add the full stop and I get two. How can I modify the ...
31
votes
6answers
32k views

What is \iffalse for?

So this is something I've wondered about for a while. What use is a conditional that always evaluates to false? I guess it's a neat way to "hide code from LaTeX" but apart from that, is it ever useful?...
19
votes
3answers
453 views

Where can I find a documentation for low-level tex conditionals like \if?

I want to understand low-level stuff like \if better. I'm not looking for some random examples off Google showing me some statements but a specification of some sort - something mean and unforgiving. ...
4
votes
2answers
566 views

How to check if a macro expands to something greater than a constant?

Suppose I have a loop: \begin{tikzpicture} \foreach \frm \in {1,...,6}{ \only<\frm>{ % if \frm > 4: set \x to 1, 0 otherwise \node (foo) at (10+5*\x,7) {hello}; }} \end{...
15
votes
2answers
2k views

If document class is equal to something then do not use package

I am trying to create a file which includes common packages and macros I use. It is something like this. commonDefinitions.tex \interdisplaylinepenalty=2500 \usepackage{algorithmic} \usepackage{...
11
votes
1answer
567 views

biblatex: How to suppress back references for certain citations?

When using BibTeX's standard citation commands, such as \cite, typically back references are generated (if enabled) in the bibliography pointing back to the place of citation. That's a nice feature. ...
23
votes
2answers
11k views

TikZ: conditional nodes inside \foreach

I want to use a \foreach construct to generate several pairs of nodes, except for one of them I want to do something different. This is what I tried: \begin{tikzpicture}[dot/.style={fill,circle,inner ...
5
votes
1answer
482 views

Suppressing remarks when not needed

I have written some remarks in some of my works that are somewhat informal and repetitive in nature (mainly for my own clarification). I was wondering if there is a way of suppressing them when I don'...
6
votes
2answers
5k views

Less than or equal comparison within a whiledo

I am in the process of cleaning up the code for Sieve of Eratosthenes in tikz, but saw that when I initially did the code, I could not figure out how to do a <= comparison within the \whiledo, and ...
10
votes
1answer
6k views

Remove URL in IEEEtran bibliography

The question refers to the topic: Disabling URLs in bibliography Could you think of a solution, which allows to have the URL in bibliography entry or not depending on the entry type. I. e. remove the ...
9
votes
1answer
1k views

How do I configure fonts and package options for different engines?

I would like to be able to rely on the code in my document class to respond correctly to whether it is being rendered using pdfLaTeX or XeTeX engines. The editor I'm using (LyX) does this using ...
23
votes
1answer
1k views

Check if at begin of a line

For a list of bullet-separated items, I want the separator to be swallowed if it is the first or last element of the line. That is, I want something like \renewcommand{\and}{% \ifnolinebreak% &...
22
votes
5answers
8k views

Proper way to detect empty/blank text

I am attempting to ignore a command if it is passed with empty/blank text. My use case is not as complicated as one Expand away empty macros within ifthenelse where @egreg provides what seems like a ...
10
votes
2answers
1k views

How to test --jobname compilation option within latex file

Due to some commands in my preamble (\synctex=1,\makenomenclature,\settocdepth{subsection}) which are not fully compatible with --jobname procedure, I would like to add a test before these three line ...
16
votes
5answers
536 views

Applying an operation only to capitals

I'd like to apply a function to capitals only so that: \emphcaps{YaWeH} Outputs like: \emph{Y}a\emph{W}e\emph{H} Preferably without using too many packages (I already use memoir). NOTES: I use ...
3
votes
2answers
137 views

How to test if a macro has the shape of a coordinate from TikZ?

How can I know if a macro contains a coordinate, that is, in the sense of having the shape of a coordinate num,num. What I want to do is to know if a given macro, \pos, has the shape (in sense of ...
1
vote
3answers
1k views

Passing multiple arguments to an \ifthenelse routine

I have recently discovered LaTeX, trying to experiment wiht it to prepare a complicated industrial document (laboratory test instructions). A typical set of instructions contains a long sequence of ...
4
votes
2answers
259 views

String test, with an OR connector

In this post, a solution is given to the problem of defining a command which tests equality of two strings, sufficiently robust (in comparison to \ifthenelse) to admit complicated arguments (e.g. ...
5
votes
2answers
575 views

String test, with complicated arguments

I have a command \mycom{} which takes 1 argument. The command should perform a test on the argument and do something accordingly. For simple arguments, I can use \ifthenelse, but I need to consider ...
51
votes
2answers
46k views

Conditionally hidden slides in beamer

When creating a presentation, I sometimes create extra slides that contain additional information, a more thorough explanation, or an extra plot pertaining to certain parts of my talk. These extra ...
0
votes
1answer
762 views

conditional commands in .sty file, conditional on \documentclass [duplicate]

Possible Duplicate: Which document class is being used? I'd like to include conditional formatting in a .sty file, conditional on the document class of the document that invokes it. For example, ...
10
votes
2answers
420 views

How to make an infix \if variant?

How does one make custom \if variants in core TeX? I would like to write: \ifshape{it} ... \else ... \fi as in: \textit{Italic? \ifshape{it}Yes\else No\fi} Problem is, I get the error "Too many }'...
8
votes
1answer
205 views

Is testing f@shape considered best practice method for reliably detecting italic and slant modes?

Subject says it all. Is testing f@shape the cleanest, clearest, simplest, most reliable way to check for italic and slant modes? e.g.: \ifthenelse{\equal{\f@shape}{sl}}{italic}{not italic} \...
2
votes
1answer
308 views

Definining a new enviroment depending on a parameter

I want to create a new environment which depend if a parameter exists or not. The basic definition, which works fine, is: \newrgbcolor{bcolor}{1. 1. 1.}% \newenvironment{pbox} {\begin{lrbox}{\...
6
votes
2answers
631 views

How do I create an algorithmic Tikz code to obtain a list of numbers which is conditionaly defined by a recurence relation?

Suppose, our initials are $a_{1,0}=0$, $a_{1,1}=1$ and $a_{1,j}=0$ for $j<0$. For given an integer $n$, define $$a_{i,j}=\begin{cases} a_{i-1,\frac{j}{2}} & \text{ if $j$ is even},\\ a_{i-1,\...
39
votes
5answers
7k 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 shade ...
7
votes
2answers
1k views

problem with \ifthenelse + multicolumn

I encounter various problems when i want to control the display of a table with a ifthenelse test. For example, consider the following M(non)WE : \documentclass{article} \usepackage{multirow} \...
6
votes
2answers
4k views

Expand away empty macros within ifthenelse

I want to test whether a string, when it is finally printed, is empty. The following illustrates my problem, \documentclass{article} \usepackage{ifthen} \newcommand{\isempty}[1]% { \ifthenelse{\...
8
votes
1answer
1k views

Help wanted on \openout, \write and \closeout

Is there a way to test if a token is already associated with a writer? Something like this: \def\do@write#1{% \immediate\write\mywriter{something: #1}% } \def\@writesomething#1{% {\if@isopen\...
2
votes
1answer
495 views

keyvalue with kvoptions and switch structure

I am using kvoptions for a key-value syntax. However I need a switch syntax for the evaluation. Since boolexpr is problamatic (see here) I use now the other solution of this question. However the ...