A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

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
0
votes
0answers
82 views

conditional usepackage given documentclass [duplicate]

Possible Duplicate: Which document class is being used? How would I conditionally usepackage{enumitem} if the document class is memoir (but not beamer)? Could I use the etoolbox primitives, or ...
3
votes
2answers
2k views

ifthenelse conditional & macro

Why I get the error below if I use the \ifthenelse{\boolean{@parts}}% {% }{} conditional (defined into classicthesis.sty) you try to comment it, you don't have any error? \documentclass[11pt]{...
4
votes
1answer
419 views

Check if non-empty subsection exists under another section

I'd like to try to make a LaTeX class which enforces a number of (non-empty) sections to exist-- if the user doesn't define them manually, then some default section content will be created. \begin{...
7
votes
1answer
553 views

ifoddpage not working

I'm testing ifoddpage but it seems to say that every page is even: \documentclass{article} \usepackage{lipsum} \usepackage{ifoddpage} \newcommand\printpage{% Page is \thepage. It is \ifoddpage odd\...
10
votes
2answers
870 views

How do I check if a biblatex entry contains an author field?

I'm writing a paper on a very large number of pieces of artwork, and I've been trying to automate the creation of my section headings, but I've run into a roadblock when I try to check if a Biblatex ...
6
votes
2answers
690 views

Boolean based environments

I know that this question is basically identical to that of Hide custom environment content based on boolean Except I want to avoid using the environ package, which, otherwise, would be the best ...
4
votes
0answers
189 views

Where‎ ‎do‎ I start ‎learning‎ conditional tests ‎in ‎LaTeX‎?‎ [duplicate]

Possible Duplicate: LaTeX conditional expression I've already taken a look at ‎books‎ such as "‎Te‎X for the Impatient", but its examples aren't clear enough to me. What‎ book/tutorial ‎do‎ you ...
3
votes
0answers
287 views

Conditional coloring in LaTeX [duplicate]

Possible Duplicate: Parametrize shading in table through TikZ Is there any package that provide conditional coloring in LaTeX ? I would like to reproduce what Excel does with its conditional ...
3
votes
1answer
196 views

Defining macros based on environment

Right now, I have two macros, \intersects and \union, that simply point back to \cap and \cup respectively. Unfortunately, to have nice typesetting in display-like environments, I need to use \bigcap ...
9
votes
1answer
166 views

Package providing fully expandable conditionals

Is there a package providing a collection of fully expandable conditionals like this one: \newcommand\myif@num[1] {\ifnum#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} Background: Let'...
3
votes
3answers
3k views

ifpackageloaded question

why when i comment \usepackage{geometry} i get error? \documentclass{book} \usepackage{geometry} \makeatletter \@ifpackageloaded{geometry} { % i the package was ...
4
votes
2answers
151 views

A dangerous \if@ in the dtx preamble

Why does the following .dtx not compile, while the equivalent .tex file does? (You must name the file error.dtx, that's what \DocInput includes.) DTX: % \iffalse meta-comment %<*driver> \...
6
votes
2answers
388 views

How to extend a macro for e-mail addresses to support multiple arguments?

I prepared the following macros to format e-mail adresses in a e-mail header. \usepackage{xifthen}% Provides \ifthenelse and \isempty % E-Mail header strings with format. \newcommand{\fromString}{\...
3
votes
2answers
364 views

Reference Page of Float Object only if Page isn't actual page

Is it possible to tell LaTeX only use \pageref if the referenced object isn't on actual page? if \pageref{fig:hello_world} != self.page then \pageref{fig:hello_world} end
3
votes
2answers
592 views

\jobname in Gummi

The command \jobname usually print the file name without the path and extension, so inside a file called foo.tex will print just foo. With pdflatex foo.test or compiling from LaTeXila certainly I ...
19
votes
1answer
1k views

How does TeX handle \else and \fi in conditionals?

I have seen packages using \def\afterelse#1\else#2\fi{\fi#1} which TeX seems happy to accept. But on taking the first branch, isn't TeX expecting \else instead of \fi? That is, isn't the following ...
7
votes
2answers
2k views

Nesting of test commands (IfStrEq, IfSubStr etc.) of xstring

The following code does not work: \documentclass{article} \usepackage{xstring} \newcommand\checkempty[1]{ \IfStrEq{#1}{}{% Empty }{% NonEmpty } } \begin{document} \...
8
votes
1answer
2k views

How to create conditionals in a document class for latex?

I am trying to write a document class highschool.cls for the high school research papers in our school based on the book.cls in order to make the format of the papers standardized. I am trying to ...
2
votes
0answers
363 views

Latex Conditional Display of Image [closed]

I have an interesting situation, I am passing a variable into a LaTeX page via smarty & php. I am generating a PHP Quote form to be used by multiple companies, and what changes is just the logo ...
1
vote
0answers
81 views

Adding Text to Caption via Style File [closed]

I am trying to add text to a caption via a sty file. With the following code: \ifthenelse{\equal{#1}{caption}}{% {Sample Tex \\ Added Here} }{}% The style file will add "Sample TexAdded Here" to ...
3
votes
1answer
843 views

Adding vertical spacing between chapter and its first section in table of contents

I'm using the style files given by my university for my thesis but they are quite old (eethesis document class). In my PDF output, the vertical space before and after the major headings in the table ...
2
votes
1answer
317 views

Homework generation [duplicate]

Possible Duplicate: Conditional typesetting / build I have a database of LaTeX homework questions like this: question1 question2 question3 etc Is it possible to create a flag to select ...
3
votes
2answers
676 views

Beamer conditional pdf file generation

I would like to know if there is a method to generate beamer pdf presentation based on conditions. For example: -Main Beamer presentation: Slide 1 Slide 2 Slide 3 Slide 4 Slide 5 -For the first ...
1
vote
1answer
175 views

conditionally emit one table or another

I would like to specify a table and if it has any multiline cells then it should be output as a single pair of columns and otherwise as two pairs of columns. For example, if it looks like the First ...
2
votes
1answer
119 views

How to deal with conditions with many nested \and and \or?

This simple example will fail because of the priority rules are not taken into account : \documentclass{article} \usepackage{ifthen} \begin{document} \newcommand{\bibi}2 \newcommand{\toto}3 \...
10
votes
1answer
890 views

Counters for use in array/tabular cells

The following practical example \documentclass{article} \usepackage{array}% http://ctan.org/pkg/array \newcounter{tabcol}\newcounter{tabrow} \newcolumntype{C}{>{\stepcounter{tabcol}}c} \begin{...
4
votes
1answer
2k views

Define command that returns true/false (multiple conditions)

While using the datatool-package I encountered something strange. I have a loop, and each iteration it defines some variables that are later used by the command \DTLforeach from the datatool-package. ...
6
votes
1answer
383 views

blank lines break xparse or ifthen macro

Leaving blank line break simple macro but % terminating it fixes it. WTH is going on? I know one is suppose to use % BUT I can't have any blank lines in the macro without it complaining. A blank line ...
26
votes
7answers
13k views

Implementing switch cases

I'd like to have command built around a switch-case environment in LaTeX, much like the example below: \documentclass{article} \usepackage{xstring} \newcommand{\dothis}[1]{% \IfStrEqCase{#1}{{a}{so ...
6
votes
1answer
4k views

Boolean variables in LaTeX

I am trying to use "boolean" variables in LaTeX but am unable to have any success... I have a macro which takes 5 arguments, the last argument being optional. This macro is named educationItem and it ...
13
votes
1answer
188 views

Why does “\if\char98\char98 T \else F \fi” return F instead of T?

According to the TeXbook the two tokens following \if are expanded and compared? It seems then that \if\char98\char98 T \else F \fi should be the same as \if bb T \else F \fi which does return T. What ...
21
votes
5answers
7k views

Teach me how to use \loop…\repeat constructs, etc

The following code snippet is a part of the solution given here: \def\IncludeOutput#1{ \parskip=2mm \def\examplename{#1} \pdfximage{\Directory/\examplename.pdf}% \edef\lastpdfpage{\the\...
16
votes
2answers
7k views

Best practice for getting “If not foo” conditionals

So, here are two ways you might set things up such that \dostuff is done when foo is false. The "new conditional" method If you know when foo is going to be set, then after that do: \newif\ifnotfoo ...
6
votes
2answers
351 views

How to test if some command similar to \author is used in .tex file?

I want to modify \maketitle command in a new document class based in memoir. \maketitle command should include a new \director command similar to author. If this command is defined in text file, the ...
45
votes
5answers
22k views

new command with cases / conditionals / 'if… then's

Suppose I want to define a command, say, \tree with, say, two arguments. I would like \tree to do different things depending on what my first argument is. For example, if #1 = a, then return $\sqrt{#...
5
votes
2answers
683 views

Error using \string

Consider \documentclass{article} \usepackage{lmodern} \usepackage[T1]{fontenc} \begin{document} \texttt{\string\iftrue} %% \texttt =\long macro: %% #1->\ifmmode %% \nfss@text{\ttfamily#...
6
votes
1answer
456 views

Advanced conditionals

Is there some way to create more advanced conditional statements that can evaluate a logic expression and decide what to do based on the value of the expression? For example like in the following very ...
4
votes
2answers
811 views

Bold author if source is an article

i got some articles i cite in my thesis. The author should be bold in the bibliography but i dont know how. I tried to use \textbf in the bibtex file but then the format isn't correct anymore. Would ...
6
votes
3answers
286 views

How to “demux” several aspects from a `\foreach` variable with `\ifstrequal`?

How can I "demux" several features from a mode specification given in a \foreach? I would like to use a \foreach to draw several nodes in a TikZ picture. The loop will specify a mode for each node, ...
13
votes
1answer
4k views

How to use mod operation in latex with tikz

I need something similar to \ifnum \j mod 2 = 0 rest of a number, but do not know how to do this in line 22. \documentclass{article} \usepackage{tikz} \usepackage[active,tightpage]{preview} \...
6
votes
2answers
165 views

\let versus conditionals for customizing macro behavior

I have a large collection of macros that do different things but all eventually use the same macro internally (call this macro \tasks). Sort of like this, but with better macro names: \newcommand{\...
6
votes
1answer
237 views

How to check if key is already in aux file

Trying out some LaTeX commands, I wanted to build an Abbreviations list that would write acronyms to a file when defined and if already defined do nothing. It works fine so far, adding \abvr{OpenCL}{...
4
votes
1answer
122 views

How to create a command to insert a string, but possibly ignore white space before the command?

I would like to define a switch that shows additional comments in some text (containing formulas). As you can see below by setting showString to true, this works well. However, when I set it to false, ...
5
votes
1answer
961 views

Multilingual text with if statement

I'm working on a document in LaTeX and I would like to have multiple language versions. I could just copy everything and translate, but this would lead to multiple versions that I would have to update ...
30
votes
4answers
4k views

On testing two fully expanded character strings for equality

I know three macros that test two fully expanded character strings for equality: \ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>} (ifthen package) \IfStrEq{<op1>}{<...
4
votes
1answer
199 views

How to check if it is the first time or last time a macro has been used in ConTeXt?

I have some text in my document which appears repeatedly many times throughout the document, so I have defined a custom macro, e.g.: \define\mymacro{ \section{A} There is some text. \...
10
votes
1answer
2k views

Handling \ifnum's “! Missing number, treated as zero.”

Let's say I have a variable, which may - or may NOT - be a number; how can I handle the cases when it isn't a number, without crashing with "! Missing number, treated as zero." ? In practical terms, ...
15
votes
1answer
393 views

First occurrence of a command

I'm writing some macros that need to behave differently after first occurrence. I decided to use the etoolbox package's toggle. My MWE is as follows: \documentclass{article} \usepackage{etoolbox} \...
3
votes
1answer
317 views

Name arrangement macro

I'm trying to write a c.v. macro. I've got a first, middle and last name and I would like to arrange these as either "first middle last" or as "first last" if middle is unknown The code I have so far ...
15
votes
2answers
3k views

Best practice to implement a boolean macro argument?

Sometimes I'd like a macro to depend on a boolean argument but I don't know about the best way to implement this. So far, I end up introducing a global (say) \newif\ifextra that is used inside the ...