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

4
votes
1answer
197 views

Changing Template Header for Appendices

I am using a modified BYU Thesis Template for my thesis. I want to be able to change the page header for the the appendices to read "Appendix A Data & Display" instead of "Chapter A Data & ...
5
votes
1answer
133 views

Testing lines read from external file

I am trying to read some data from an external file and perform specific actions based on the contents of a given line. Below is my attempt to test a read line using \ifx - it does not work. I've ...
10
votes
1answer
129 views

How to make a conditional reference to a text label

I would like to make a conditional reference to an optional label in my latex document, see the Minimum Working Example below. Hence, IF the label exists somewhere in the document, THEN a reference ...
2
votes
2answers
567 views

Memoir oneside/twoside question

I have a memoir-class document: \documentclass[oneside,letterpaper]{memoir} which I set to oneside or twoside depending on if I want to create either an electronic copy (one side) or printable copy ...
13
votes
2answers
193 views

Load a package as optional argument

I'm creating my personal package. I'd like to use an option to turn on/off the line numbering provided by the package lineno. So, my sty file contains \RequirePackage{lineno} \linenumbers But if ...
10
votes
1answer
116 views

Expandable, very specific keyval processing

I am having a hard time trying to come up with an fully expandable keyval parsing macro which deals only with specific keys/values. I wouldn't even attempt this in full generality, that's way beyond ...
13
votes
1answer
138 views

testing for a documentclass option

I know that there are lots of similar question, but none of those have helped me so far - and I did google a lot. So my question is: I have a document class (emulateapj) which accepts a few options. ...
17
votes
1answer
140 views

Compile PDF without proofs

I am writing my degree thesis, and I need to make a synthesis of it: basically what I want to do is make a copy without the proofs...is there a way to exclude them automatically, without having to ...
4
votes
1answer
244 views

Boolean switch for conditional statement after its definition?

I'd like to use conditional statements in my preamble file and then define the value of the Boolean variable afterwards. The reason is that I import the preamble.tex first thing in my main file where ...
7
votes
2answers
179 views

Negating \ifeof

Trying to typeset lines from a file: \openin0=MyFile \loop \read0to\linein \linein \ifeof0 % Fails here \repeat Clearly, I want to test for not \ifeof, but I don't see a boolean ...
3
votes
2answers
109 views

Test for empty possibly itemized argument in tabu

For some reason, I can't test if #2 is empty in the following tabu use case. An Incomplete \ifx; all text was ignored after line 14 is thrown executing the following code. ...
10
votes
4answers
676 views

\if(username == foo) … \else .. \fi?

I think the pseudo code in the title says it all: How can TeX (or LaTeX) find out the $USER who is running pdflatex? I'm collaborating want the output to look very slightly different when I run latex ...
1
vote
1answer
351 views

If two columns LaTeX

I am writing a paper in LaTeX. I will need both the one-column and two-column versions of the paper. For this, the figure sizes/configurations need to be different in the two documents. I am looking ...
3
votes
1answer
160 views

Enable and disable contents of \chapter command

I have large set of contents for the user. For a different user I would like to show different contents. For this I would like to produce different output by showing and not showing some of the ...
8
votes
1answer
941 views

Bibliographies when using subfiles

I am writing my Ph.D. thesis in XeLaTeX with Biblatex, and there are times when I need to compile individual chapters, and times when I need to compile the entire document, so I use subfiles, which ...
8
votes
3answers
168 views

xstring command in renewcommand

I'm trying renew \texttt command with condition on ending . or ,. But after making this: \usepackage{xstring} \let\OldTexttt\texttt \renewcommand{\texttt}[1]{% \OldTexttt{\hspace{0.4em}#1}% ...
5
votes
1answer
142 views

How to define a macro conditionally based on whether it is being used in text mode or math mode?

I'd like to be able to make a macro \foo whose definition would look something like \newcommand{\foo}{ \ifintextmode{abc} \ifinmathmode{x\cdot y\otimes z} } so that \foo $\foo$ produces ...
2
votes
1answer
82 views

How to check if a fragile macro value is empty or will not create text with plain TeX conditionals?

A similar question has been already asked here, but has not been answered yet for fragile commands such as eg. \@author? What would be the right way to get detect if \author has been called with a ...
2
votes
0answers
46 views

Can include text which conditionally appears depending on PDF viewer? [duplicate]

Can you have a message in a document which only appears when particular PDF viewers are used? I am using pdflatex to create a PDF document. I am including pdf image which, unfortunately, does not ...
3
votes
1answer
66 views

\setbool not respected in footnote?

Can someone explain why \setbool (from etoolbox) is not respected when used in a command only used in a footnote? \documentclass[12pt]{article} \usepackage{etoolbox} \newcommand{\longshort}[1][]{% ...
3
votes
1answer
62 views

How do I create an expandable conditional with a loop inside?

I need to create an expandable conditional that uses a loop (that is, a ..._map_function:). It should either return true from inside the loop, or return false otherwise. In a 'normal' programming ...
4
votes
1answer
217 views

standalonetrue / standalonefalse?

You can use \standalonefalse to specify the parent document for which all sub-documents should be considered sub-documents, I think. Is it possible to re-enable standalone with something like ...
3
votes
1answer
110 views

Biblatex: No \postnotedelim for citations that aren't numerals

When I am citing pages in books, I use the citation format (Author 1982:45) But when I am citing something like paragraphs or online data with an ID number (i.e. things that aren't a plain ...
0
votes
2answers
128 views

How can i create multiple documents from one template - depending on special “variables”?

I am currently trying to set up a document template that allows for automated creation of different output files depending on a certain "input". The "input" could be a variable or a certain kind of ...
17
votes
2answers
1k views

Difference between \newbool and \newtoggle from etoolbox package

Paul Gaborit's answer to How to detect if option provided via \tikzset uses \newbool to define a new boolean \booltrue to set a boolean, and \ifbool to perform a conditional operation all from ...
12
votes
2answers
419 views

How to detect if option provided via \tikzset

I would like to be able to detect if a particular option has been provided via a \tikzset and issue a message based on that. The MWE yields: But once the conditional works (just a comment for ...
2
votes
1answer
176 views

if the remote file exists then include it, else include the local one

Here's the path where my tex file stands : /home/me/documents/foo.tex I also have one import file here : /home/me/texmf/tex/latex/personal/bar.tex However for security purpose I also include it ...
6
votes
1answer
477 views

pgfplotstable: Conditional post-processing of cell content on a per-column basis

I am trying to add an asterisk to the content of certain cells depending on the cell's content (essentially, adding a marker for significant p-values) but I am having trouble trying to do so on a ...
1
vote
0answers
209 views

Is there a 'try' command for LaTeX? [duplicate]

What I'm trying to do is input file1 if it exists and input file2 otherwise, without having to deal with an 'I can't find file' error. I would like to accomplish this using TeX, without using symbolic ...
3
votes
1answer
95 views

how to comment text depending on a number

I have a latex document with 24 questions labeled with numbers from 1 to 8. I want to give a number x between 1 and 8 to latex in the preamble so that all the questions become commented except the ...
13
votes
3answers
279 views

Gobbling an argument if it starts with #

My problem comes from pandoc and markdown, but it is not directly related with these tools, but instead with "customizing" the resulting pdf via some tex macro programming, so I think it is on topic. ...
9
votes
1answer
242 views

How to detect whether “I'm on arXiv.org”?

I write a class. I'm interested in having a different page headers (and eventually make some other small differences) based on whether the class is used on the site arXiv.org or not. Minimal example ...
2
votes
0answers
49 views

Is it possible to check if I am inside a float environment? [duplicate]

I have a class file that I am writing (it's my first one and I am new to LaTeX). I have a situation where I'd like to know if I am inside a float so that I can prevent attempting to create a nested ...
6
votes
1answer
767 views

Applying condition around \intertext and \shortintertext leaves excess vertical space

When I try to make either \intertext or \shortintertext conditional I get excess vertical spacing prior to the conditional text as per the MWE below. Note the excess vertical spacing prior to "Albert ...
4
votes
1answer
222 views

Disable underlining in display math and resume afterwards

In my documents I have conditional text, which is underlined (in non-display math mode) to make it more obvious to the reader as to exactly which portions of text is conditional text. In display math ...
14
votes
1answer
2k views

Can I test if a file exists? [duplicate]

Can I somehow test if a file exists? And can I use this to do only things when it exists? I like to do something like if(exist('members.csv')) { do something }
15
votes
4answers
284 views

Test if file is in \includeonly

Is it possible to check if a file is listed inside \includeonly{...} ? For example I would like to do something like this \includeonly{file1,file2} \if\isincluded file1 % \isincluded is a ...
4
votes
1answer
362 views

sum two numbers in \ifnum

I would like to implement a command in LaTeX which would sum two numbers before comparing them to a third number as follows: \ifnum #1+45>0 above \else left \fi where #1 is an angle in ...
6
votes
1answer
117 views

Conditional centering if single line

I would like to define a new environment that centers its contents if it can be typeset on a single line, but justifies the contents if it requires multiple lines. \documentclass{article} ...
3
votes
1answer
210 views

Test for old style numerals font feature (using fontspec)

Using XeLaTeX and fontspec, I want to test if the currently selected font has old style numerals (which I use in the main font, but not in the sans font). According to the fontspec documentation, it ...
10
votes
1answer
363 views

Define a \newif within a nested \ifdefined

The MWE below attemps to define a \newif within a \ifdefined. This works fine, except when the file is loaded the second time. As it is below generates the following error message: Incomplete ...
6
votes
1answer
1k views

Smaller font size in quote environment relative to context

I want to have all quotes in the quote-environment in a smaller font. This is possible with the etoolbox-package and the command: \AtBeginEnvironment{quote}{\small} But if I use a quote-environment ...
8
votes
1answer
200 views

Conditional page breaking

I have used LaTeX on and off for a number of years now for several large documents with evolving versions over long lifetimes. But every time it seems like, powerful and wonderful as LaTeX is, there ...
4
votes
1answer
125 views

How can I compare the width of a paragraph to 45% of the linewidth?

Here's my pseudo latex code to try and show what I'm trying to do in my memo latex class: \newcommand\headername{%should be the @memoto, or if too long, an abbreviated subject ...
1
vote
1answer
163 views

How do I hide “Chapter 0” in this custom style when using a numberless chapter?

Everything works perfect when I use \chapter{chaptername}, but I noticed that my table of contents and other similar non-numbered chapters have a "Chapter 0" in my header. \titleformat{\chapter} ...
6
votes
2answers
159 views

Test if chapter is a valid command

I want to test if the class supports chapters. However with the package titlesec the check for the command \chapter fails because it is always defined: \documentclass[]{scrartcl} ...
4
votes
1answer
82 views

test if a listings or glossaries style is valid

I want to test in my template if a call of \lstinputlisting[style=mystyle,... or \printglossary[style=mystyle,... is valid or will fail because of an unkown style. However I could no find out ...
1
vote
1answer
169 views

generalize \iftoggle in etoolbox

I am using nested loop conditional \iftoggle of etoolbox, is there any other generalized conditional? Usually it works as: \newtoggle{name} \settoggle{name}{true} \iftoggle{name}{do if name is ...
7
votes
1answer
90 views

Decide whether a label occurs in the current chapter

I want to decide if some label occurs in the same chapter as the current one. I use the zref package as suggested in Chapter ref with LaTeX to find out in which chapter a label occurs, and compare ...
5
votes
1answer
184 views

How to check image exists or not?

I'm working on Sweave and using includegraphics for include image in report dynamically. Pseudocode: <<> for ( i to 100) # run loop 1 to 100 { ...