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

7
votes
1answer
64 views

Function rotated about the x-axis

I try to reproduce some figure from that file: http://tug.org/TUGboat/tb33-1/tb103wolcott.pdf I exactly need Figure 7: f(x) = sin x rotated about the x-axis. The code for Figure 7 is in appendix B. ...
1
vote
2answers
118 views

csvsimple filtering problem

The following code works as I would expect. \documentclass{scrartcl} \usepackage{csvsimple,filecontents} \begin{document} \begin{filecontents*}{chunk.csv} AAAA,aaaaa BBBB,bbbbb CCCC,ccccc ...
15
votes
2answers
179 views

\ifnum command with multiple conditions (lower and upper bound)

First time posting here, very much a novice. I'm creating some background templates in beamer and I can't figure out why this \ifnum command isn't working properly. This is the code: ...
4
votes
1answer
40 views

Using character literals with \ifcase

Is there a way to implement a switch-like macro in LaTeX or do I have to nest ifs? Something that would look like: \ifcase#1 \case a{} \or\case b{} \or\case c{} \fi If not, could you ...
0
votes
0answers
21 views

A&A template returns error \renewcommand{\Newassociation}

I got the template to make scientific papers from the Astronomy&Astrophysics official website. Since I can not compile my own document, due to an error, I tried to compile the demo that is within ...
2
votes
0answers
31 views

conditional placement of ocg content

I am using ocg-p package to add layers of information in a pdf document, to be accessed by the reader interactively. To place the ocg layer in the desired location on the document I used rput command ...
3
votes
1answer
51 views

Conditional structure based on \rand value comparison

I have a simple code that inserts a complex layout for figures and I would like to randomly alternate the position options (for instance, alternating between top and bottom positioning: ...
14
votes
3answers
731 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
2answers
159 views

If-then-else inside TikZ graph?

I want to draw a graph like in the second picture of the following code: \documentclass{article} \usepackage{mathptmx} \usepackage{tikz} \usepackage{verbatim} ...
2
votes
1answer
39 views

Multiple choice questions type setting

See the fourth question: the choices are showing twice one is along horizontal and another is along vertical, but I need only one like the above three. The commands I have used is given below. ...
5
votes
2answers
128 views

Define a New Macro via a Macro Using xparse Syntax

I am trying to set up a macro that defines a macro that is to be executed only once. With what I learned from Define a Macro via Macro if Given Macro is not defined I can do that via the ...
3
votes
1answer
39 views

Variable scoping of edef definitions in a local group (inside an ifx conditional)?

Consider this MWE: \documentclass{article} \def\testswitch#1{ \def\isA{A} \def\firstOpt{#1} \edef\tmpstr{-init-} { % start local \edef\tmpstr{-loc defined-} } % end local ...
7
votes
1answer
86 views

How can I set up my custom class to load a different class depending on the class option(s) passed?

I have written class files in the past. One of them is even up on CTAN. But that was ages ago, and I am rusty today. I am trying to roll a new class file for my University. I am being a little ...
1
vote
0answers
26 views

Creating multiple output files, with content that depends on a variable

I'd like to write a template for a letter, which is meant to be sent to many people. Thus, the content should change slightly depending on who is the addressee. For instance, I imagine that the ...
8
votes
3answers
150 views

How to include a second file only if environment variable is set?

I have a LaTeX document which exists in two versions, a short version and the long version. The long version has an additional chapter inserted in the middle of the document. What I want to do, is if ...
6
votes
3answers
152 views

A reusable newlength (no stop/break if length already defined)

Often I have separate .tikz files, which may contain stuff like \newlength{\mytmplen}; and given I'm not very original with names, the same statement ends up in multiple such files. Which turns out to ...
1
vote
0answers
50 views

macro: repeat a command if new page else do nothing

QUESTION: How does one write a pair of macros that work in 1) beamer class and 2) article class, respectively, such that if it, \macroname{...}, is executed at a point in the code, that point ...
1
vote
1answer
59 views

Referencing \pgfmathsetmacro variable inside an \ifthenelse statement

How do I correctly reference a value calculated using a \pgfmathsetmacro definition when defining the check condition of an \ifthenelse statement? Example Problem; Randomly scattering nodes within a ...
3
votes
1answer
31 views

Conditionals inside document

Sorry I was not able to reproduce this problem outside Friggeri's CV template... I am using Friggeri's CV template with the same friggeri-cv.cls (I have only changed all the Helvetica fonts to ...
2
votes
1answer
25 views

Conditionally change font color of number passed from pythontex

I would like to color numbers red if they are less than zero. In my final report, these number will be generated from a python script. To use the pythontex package, I first run xelatex doc.tex, then ...
8
votes
2answers
118 views

tikz, conditional setting of shape parameters

In my illustration I use simplified sketches of stopwatches (timers), which appear in three different "modes": (1) start of interval (coloured green), (2) time in progress (yellow), and time is ...
6
votes
1answer
72 views

Using conditionals in tabular preamble with array

I'm trying to use a conditional in the column setup for my tabular. That is, the definition of one column (actually several columns) is dependent on a boolean value (as set up from the etoolbox ...
2
votes
1answer
71 views

How to test if a string is empty

I tried several thing to test if a parameter is empty or equal to a specific carater. How should one proceed ? By the way, what is the best way to have conditionnal code on a parameter who can have ...
5
votes
5answers
152 views

new command with cases?

This has been answered here for text outputs with the use of \IfEqCase from the xstring package. But if I want to use the output as a value to set a parameter in a function, it fails. Here is my MWE: ...
8
votes
2answers
50 views

“Extra \else” and inserted “\inaccessible” when using textbf with pgffor

I'm getting errors whenever I try to make \textbf interact with pgffor and xparse. Here's an MWE that gives ERROR: Extra \else and ERROR: Missing control sequence inserted at the end of the \coljoin ...
12
votes
2answers
157 views

Why does this use of `\expandafter` not work?

I've written the following code: \newif\ifconsecutive \consecutivefalse \newcommand{\myfirst}[1]{#1\consecutivetrue\expandafter\consecutivefalse} \newcommand{\mysecond}[1]{\ifconsecutive ...
18
votes
2answers
2k views

Use “default” figure if file is missing?

I was recently in charge of organizing all of the references and labels in a very large scientific proposal document. My workflow typically involved compiling the document, seeing a "There were ...
2
votes
1answer
36 views

Customizable inclusion of frames-slides from a huge Beamer presentation [duplicate]

I have one master-huge beamer presentation having lots of frames. Depending on the audience I wish to customize, say, for lay audience I will just include basic slides, for experts I wish to include ...
3
votes
1answer
56 views

How to use conditional (if statements) with data from acronyms?

I am using acronym for autocomplete my text like mailing functions. So I want the long text from acronym using all the time, and I am using \acro{}{} to define, so \acro{Maria}{f} - for me shows that ...
5
votes
1answer
43 views

How to detect if \thepage is undefined?

The sig-alternate class by default disables page numbers, which breaks mparhack (amongst other things). How can I include tex code only if \thepage is properly defined? I tried \ifcsname and ...
5
votes
1answer
69 views

How to use If with on variables

I want to create my own documentclass and use some variables for creating titlepages etc with it. So what's the best way/package for doing this? the class file: \ProvidesClass{myOwnClass}[v0.1] ...
6
votes
1answer
115 views

How to do a conditional line break

I want to know how to do a conditional line break. Whenever the error message "There is no line to end here" comes, I want to disable the line break, otherwise to enable it, with a \\ command or ...
0
votes
2answers
53 views

newcommand with variable number of arguments

I have seen several related questions, but none seems to address specifically this. I would like to define a command that accepts a variable number of arguments. Something like ...
7
votes
1answer
64 views

Detect closing braces with a command

I want to make a command that detects if the next token written in the document is a closing brace. My best approach is to use the \@ifnextchar command. In fact, the following code: \makeatletter { ...
4
votes
2answers
67 views

Suppress month and day for journal articles and maintain for a newspaper articles

I haven't found a solution yet for this problem. I want to suppress month and day (if present) from all journal articles in bibliography but I at the same time I want to indicate year, month and day ...
1
vote
1answer
34 views

Macros with \fi for showing and hiding proofs [duplicate]

I would like to be able to globally showing and hiding proofs on a document, and be able to use macros to open and close the proof environments. Here is my current MWE: \documentclass{article} ...
3
votes
0answers
27 views

Changing a macro's output depending on immediate context

I've set up a macro for differential parts as so: \newcommand{\dd}[1]{\,\mathrm{d}#1} which is useful for differentials at the end of integrals because of the space. (I realise the argument ...
2
votes
1answer
24 views

textpos toggling noshowtext option

Is there a way of toggling the textpos option [noshowtext]? I would like some textboxes to show the frame but not the text. And others to show both frame and text, but can't seem to find a way of ...
2
votes
1answer
469 views

how to use memoir \ifoddpage

Why does \ifoddpage seem to always return false in the following example? This is related to question 6143 on this same forum. I'm using XeLaTeX to produce a pdf file (i.e., xelatex test.tex) ...
9
votes
3answers
175 views

Global Conditional

I'm writing a set of notes for my students on trigonometry. At present, they have not met radians, which comes next year. I would like to use the same set of notes for them, but this year, give them ...
16
votes
4answers
2k views

Making switch/case with etoolbox's \ifdefequal

I've got a define such as \def\doctype{SomeString}. \doctype can take on one of five values. I want to do something like a switch statement in a programming language, i.e. (pseudocode): switch ...
8
votes
1answer
120 views

Problems understanding definition of \newif

Reading http://profs.sci.univr.it/~gregorio/introtex.pdf, I have come across the definition of \newif on page 75: \def\newif#1{\@ifdefinable{#1}{\@newif#1}} \def\@newif#1{\count@\escapechar ...
5
votes
2answers
124 views

Detect whether I'm in a \footnote?

How do I detect whether I'm in a \footnote environment or not?
16
votes
6answers
8k views

If Then Else for odd page/even page

How to use if-then-else structure in LaTeX? I need a example of odd and even page. if odd then command 1 else command 2
3
votes
2answers
53 views

Detect whether I'm on a left- or right-hand page? [duplicate]

How do I detect whether I'm on a left- or right-hand page? I would like to define a custom command with a conditional statement that executes a certain command if it's on a left-hand page and another ...
0
votes
0answers
25 views

Make left-hand pages' `\marginpar` text right-aligned [duplicate]

\marginpars only appear on the right margins of right-hand pages of my manuscript. For left-hand pages, they are are so far to the left that they aren't even on the page. The reason is because the ...
2
votes
1answer
84 views

How to get float numbers as parameter of \newcommand

I have defined a \newcommand function like into this code: \documentclass{scrartcl} \usepackage{pbox,calc} \newcounter{pointsExo} \setcounter{pointsExo}{4} \newcounter{pointsSousTotal} ...
5
votes
2answers
85 views

Is there a way to query the page size that I have set in the memoir class?

In my preamble, I have: \documentclass[a5paper,10pt,oneside,onecolumn,openany]{memoir} I would like to later define some layout options based on the value of the page size, which in this case is ...
6
votes
2answers
85 views

How to distinguish between Metafont and MetaPost?

Background I'm trying to make a nice SVG out of Knuth's Dangerous Bend symbol based on his own code, for which the obvious tool to use is MetaPost. However, I'd prefer to still be able to process the ...
3
votes
1answer
68 views

FancyVerb Error when using minted in a \ifthenelse

I'm new to LaTeX and wand to add some code with minted, which will only be rendered, when a \boolean variable is true. Here's my code: \documentclass{article} \usepackage {minted} \usepackage ...