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

8
votes
3answers
174 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
151 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
89 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
70 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
64 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
243 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
119 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
133 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 ...
18
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
463 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
209 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
534 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
250 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
297 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
248 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
896 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
249 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 ...
16
votes
1answer
3k 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
292 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
453 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
120 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
224 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
403 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
228 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
129 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
169 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
173 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
83 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
177 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
97 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
194 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
204 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
151 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
216 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
170 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
128 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
151 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
838 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
189 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. ...
1
vote
0answers
57 views

Only input file if it exists [duplicate]

Possible Duplicate: Expandable version of \InputIfFileExists or \IfFileExists I am writing a LaTeX file where I input other LaTeX files (if and only if its exits, otherwise it should not ...
14
votes
3answers
449 views

Making a “For Loop”

I am trying to make a "for loop" that will iterate the variable reaches 1. However, none of the "for loops" I have found in the Internet works. These files will be distributed to other people and ...
10
votes
3answers
232 views

Using \@ifnextchar to define a macro for “ante meridiem” time

I want to create a macro for times of days, as follows: \newcommand{\pmtime}{a.m.\xspace} The problem is that LaTeX thinks that the last period in a.m. denotes the end of a sentence, hence the ...
6
votes
1answer
255 views

Footer Suppression

I'm wondering if it's possible to suppress footers if the page has a footnote, but display the footer as normal otherwise. To be specific, I'm reproducing an old book which uses catchwords for pages ...
7
votes
1answer
118 views

Can I detect whether my macro is being used inside a subscript or superscript?

I defined this macro: \newcommand{\foldeq}[1]{\sim_{#1}} Later on, I noticed that when it's used inside a subscript, it looks a little bit hard to tell whether it's $\sim f$ or $\sim_f$. ($\sim f$ ...
7
votes
4answers
1k views

Logical String Length

How do I do a conditional 'if then else' statement, based on length of string being greater than (or less than, or equal) a specified value. For example, something Like \def\mystring{XYZ} ...