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

5
votes
0answers
41 views

How to translate \ifthenelse from “ifthen” to “etoolbox”?

Trying to make conditional expressions that inspect the total page count of the document (see this question), i've found this solution using ifthen package: \documentclass{article} ...
7
votes
2answers
122 views

How to use the total page count in a conditional expression?

I would like to have different footer or page style depending on whether the document has one or more pages. I am not very experienced with TeX programming, so the answers about "Comparing an argument ...
4
votes
1answer
45 views

Аnalog of \ifodd condition for verification if page number is equal to some constant

I have a great example of using \ifodd condition if \makeatletter environment showed by @Symbol 1. \begin{document} \makeatletter \newbox\LT@oddhead \newbox\LT@evenhead ...
3
votes
0answers
51 views

Wonky behavior from \@ifnextchar,

When I compile the below MWE the first \@ifnextchar, always evaluates to false, which is clearly wrong in the last case. However, the second one (within \punctuationcheck) works just fine. Why would ...
7
votes
1answer
117 views

Omega appears from if result

I am attempting to edit an if statement that I was using in an environment I created. Previously, the code was \if #1\empty \else \textbf{#1.}\hspace{0.5em}% \fi I want to change it to something ...
1
vote
1answer
33 views

Is there a way to have different behavior for even pages and odd pages

I would like to modify the below template so that it prints out 1 problem per sheet. Example: Problem 1 on pages 1-3, problem 2 on 5-6 and nothing on page 4. Another Example: Problem 1 on Pages 1-2, ...
0
votes
0answers
38 views

Output two files

I'm tiring of maintaining two different CV and resume .tex files and want to combine them into a single file. I'm considering etoolbox as a way of combining my CV and resume into the same. Then I ...
8
votes
1answer
111 views

Defining a command that scans every arguments' macro “looking for” a token

Knowing that every command declaration with conditionally optional arguments, as \foo{...} expanding into \foo[default]{...} can be defined by \newcommand\foo[1][default]{...} or the safer version of: ...
4
votes
3answers
117 views

Tikz: draw a circle only in selected nodes

I created a table of nodes using tikz. And now I want to draw a circle inside every even node. I started from just trying to draw a circle in the second node. But my code is not working: ...
5
votes
1answer
54 views

Defining a command that conditionally defines/checks for counters

In order to complete one custom package command I needed an internal macro, I called it \@test@count{❬argument❭}, and should accomplish the following: Internally defines a new counter \❬argument❭ ...
4
votes
1answer
70 views

Write multiple pdfs with different options

Thanks a lot for the help in advance. This might be a stupid question, or a potential overkill for this kind of forum, but the situation is as follows: I'm writing my dissertation and - of course - ...
8
votes
5answers
376 views

A command which concatenates a string an arbitrary number of times

I'm trying to define a command \repeatstring{#1}{#2} which repeats the string #2 #1 times. Here is what I tried: (it is based on what I found in How to concatenate strings into a single command?) ...
0
votes
1answer
43 views

Showing/Hiding verbatim environment based on boolean condition

I would like to show and hide a verbatim or spverbatim environment based on a boolean condition (sth. like \showenv). I tried the solutions proposed at Hide custom environment content based on ...
5
votes
1answer
67 views

Conditional based on the version of pdflatex?

I would like to do this: \pdfsuppresswarningpagegroup=1 However, this feature is only supported by pdftex 1.40.15 and higher. How can I do this conditionally, so that my document won't be broken in ...
4
votes
1answer
48 views

Auto colour numbers in range

If I had some numbers in a tabular column, is there a way to automatically change the font colour of them if they are outside a range; eg red if under 10 and green if over 50? \documentclass{article} ...
1
vote
0answers
63 views

Conditional spacing based on length of chapter title

In LaTeX, (or possibly XeLaTeX), how can one achieve the following: A double spacing a 1- or 2-line chapter title, and single spacing under a 3- or more-line chapter title. A triple space ...
5
votes
2answers
76 views

How can I check if the filename of a LaTeX document contains a string?

I am preparing a LaTeX beamer presentation for students. I am looking for a simple way to create two versions of my presentation. One version for the Students, which just contains the text of the ...
3
votes
1answer
56 views

Conditional Zebra Tables

First, I'm using LyX with a rather long preamble because I want things fairly specific, but almost all the code in the preamble is cut-n-pasted from the 'Net with a couple modifications. I'm not a ...
2
votes
2answers
91 views

LaTeX3: If next in input stream is command X or environment X, do Y else Z

Because I write my own document class (okay, I try to ...), this question bothers me for weeks as there are many situation, in which I need something like this. Is there a way to test, if the next ...
0
votes
1answer
65 views

Menu Selection in LaTeX [closed]

I want to create a menu selection for different documents, what I mean for example is to run latex over the terminal, and the terminal prompt you if you want to create a diploma, a letter, a book, ...
1
vote
2answers
74 views

Ifthenelse variable equality

Last week I made simple coordinate transformation in order to define \tdplotsetcoord in Cartesian coord. system. My work and support of exp. user can be viewed in this topic. The code looks as ...
0
votes
1answer
60 views

ifthenelse equal string comparison fails

I am trying to fix some problems with the accessibility.sty package from www.babs.gmxhome.de There is one string comparison which always results to false, i.e. the language code definition will not ...
4
votes
2answers
35 views

vspace mysteriously being inserted after nested custom environment

I have created my own environment that creates a table using tabu and then puts some vertical space after it, unless my environment is being nested, in which case I want it to skip the vertical space. ...
0
votes
0answers
52 views

How do I add multiple macro definition inside an \ifbool compound statement?

What follows is my example doofus.sty: \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{doofus}% [2014/01/01 v0.01a LaTeX doofus package]%\filedate\space\fileversion\space \typeout{Package doofus, \csname ...
7
votes
2answers
259 views

Is there any analog to #pragma once in (La)TeX?

In C, I can write #pragma once as a preprocessor directive at the top of a header file, which tells any compiler that supports it to include the file a maximum of one time per compilation cycle, ...
4
votes
1answer
457 views

Simple if statement latex

Having difficulties understanding basic latex operations I want to use: if not (number between x and y): next iteration in loop Can anyone help me with a simple if statement for this? \newread\reader ...
3
votes
0answers
78 views

\if and \fi inside different \def macros

Recently I failed to solve specific task in LaTeX. I wanted to make document with several sections, each divided on several subsections. Each section I had placed to separate files, and used \input ...
3
votes
1answer
45 views

Print text when bibliography is empty

With biblatex, I'm looking for a way to check if the bibliography is empty, and if so, print some custom text. Something along the lines of this pseudocode: \ifempty\thebibliography [[ no ...
3
votes
1answer
58 views

conditional loop printing text and icon

I'm new in the Latex world. I'm writing a little guide and I've choose Latex, in particular Texmaker for writing it. I'm trying to do a loop for printing some instruction as File -> Save as -> Ok. ...
6
votes
2answers
52 views

Background image used for a whole section/chapter at once

I've seen a few examples with \BgThisPage being used to specify a background image for 1 single page (or another command to set one for ALL pages at once). Those two extremes are the only options I ...
6
votes
1answer
74 views

testing parameter values with \ifx

Let's say that I would like to redefine \@seccntformat so that whenever the section counter is printed, it is prefixed by Section, but other counters should no be changed. Here is my failed attempt: ...
2
votes
1answer
37 views

LYX - Conditional Sections

I've created an automatic report for my company that gets some input datasets and automatically returns a data analysis report with texts, figures, tables, and some data analysis results. Depending on ...
2
votes
2answers
139 views

Strange errors while writing a package

This short document: \documentclass[a4paper]{report} \usepackage{gnu} \begin{document} \end{document} with the following package: %!TEX encoding = UTF-8 Unicode \def\fileversion{2.7} ...
4
votes
1answer
68 views

text inside tikz node which can skip to an other

I would like to put text in a mini page with fixed length inside a tikz node using \sbox , if the text skip a specified length (10cm) it will be saved in an other \sbox and used inside a tikz node ...
0
votes
0answers
24 views

How to define a show/hidden switch? [duplicate]

I'm preparing some notes, basically some theorems and their proofs. I'd like to define a show/hidden switch, so that when it was turned on (to show) , all content are generated into the pdf; if it's ...
12
votes
1answer
162 views

What's the difference in behavior between ifx and ifthenelse?

Why does the \ifx test give a different answer than \ifthenelse in the following simple example? testclass.cls (without the head and tail): \newcommand{\isempty}{\@empty} ...
3
votes
1answer
70 views

Is there a way to know how often latex has already run? [duplicate]

A few days ago, I have seen an example of a latex file, that did conditional \defs on subsequent runs but I can't find that one again. I still remember that it was by looking into the \jobname.aux do ...
7
votes
3answers
116 views

Conditional compilation of code based on package version [duplicate]

I am working on a document with a colleague and we have different versions of PGF/Tikz installed -- I have version 3 and he has version 2.10. This is causing a problem for compilation on our two ...
4
votes
1answer
76 views

How can I loop back to a slide after showing conditional slides in Beamer?

I am working on a presentation that has conditional slides, using the formatting suggested here: Conditionally hidden slides in beamer I would like to be able to continue with my presentation after ...
9
votes
1answer
122 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. ...
15
votes
2answers
354 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: ...
0
votes
0answers
59 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
1answer
57 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
53 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: ...
2
votes
1answer
92 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. ...
6
votes
2answers
257 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} ...
6
votes
2answers
152 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
51 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 ...
4
votes
1answer
56 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 ...
1
vote
0answers
30 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 ...