{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
2answers
174 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
107 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
652 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
341 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
159 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
904 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
164 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
137 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
80 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
62 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
210 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
106 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
127 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
411 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
170 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
461 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
197 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
270 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
723 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
217 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
352 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
208 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
346 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
196 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
124 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
162 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
81 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
166 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
182 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 { ...
7
votes
1answer
187 views

How to detect that some macro expands to empty string or spaces only?

I need to check several macros and do some actions only if their expansion is not empty nor space only. In pseudo code I would look like this \if\macroToBeTested \doSomething ...
6
votes
2answers
150 views

Is “conditionals” name of package?

In some package I have seen construct like this one: \if\blank{\myMacro}% %do something \else %do something else \fi I like it and I want to use it to test if call to a macro has empty result. ...
8
votes
1answer
125 views

How to warn if a package hasn't been loaded

Is it possible to emit a warning if a package hasn't been loaded? If possible, I would prefer that the solution not require \usepackage{ifthen} as it couldn't emit the warning that it was missing the ...
8
votes
3answers
194 views

Nested use of \ifcsname needs protection

I have a macro \command to ensure that the names of macros in my documentation are consistently formatted. Been work great, until I had an urge to procrastinate and had this brilliant idea that I can ...
10
votes
1answer
156 views

Different styles for the same document

Suppose I am writing a paper, which I plan to submit to a journal/conference, but also put on a preprint server like the arXiv. Each publisher has its own style files required for typesetting the ...
5
votes
1answer
110 views

\IfSubStr does not work when used as parameter of another macro

It seem that if macro \IfSubStr from package xstring is used as parameter it is not expanded like other macros are. Here is minimal demonstration: \usepackage{xstring} \newcommand{\copyArg}[1]{#1} ...
10
votes
2answers
143 views

Writing a command to detect when in mdframed

I want to write a marginnote command that detects whether it is called within a mdframed environment, in particular I want to be able to distinguish the following normal text normal math text in ...
10
votes
3answers
619 views

Check for empty macro argument

There is a description on how to check whether the argument of a macro is empty in What does \ifx\\#1\\ stand for? Unfortunately, I can't get any of the examples there to work. Among others, I have ...
1
vote
1answer
176 views

Conditional inputfile , latex

I am using a conditionalinput file inside my main file %% Out2 doesn't exits %% Out exists I don't want to get caption and table number at position where I don't have file. ...