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

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
58 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
59 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
179 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
90 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
110 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
869 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 ...
11
votes
2answers
357 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
131 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
381 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
162 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
91 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 ...
12
votes
3answers
241 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
233 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
559 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
199 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 ...
13
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
266 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
308 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
112 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
185 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 ...
9
votes
1answer
293 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
805 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 ...
7
votes
1answer
172 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
117 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
141 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
148 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
76 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
140 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
85 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
165 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
175 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
148 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
117 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
168 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
148 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
93 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
138 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
438 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
163 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
56 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 ...
13
votes
3answers
400 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
170 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
233 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
107 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$ ...
6
votes
4answers
663 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} ...
10
votes
3answers
170 views

\expandafter and counters not playing nicely

My google-fu has finally failed me... I'm trying to write a package that will allow you say \addauthor{name, email} several times and have the title page properly formatted. Here is a minimal example ...
6
votes
1answer
492 views

What is wrong with the following latex code? [closed]

I have written this code to formulate the algorithm for merging two arrays, but I get an error. \begin{algorithm}[t] \caption{Serial Merge} \label{alg:insert} \begin{algorithmic}[1] \Require Two ...
15
votes
3answers
1k views

Includegraphics maximum width

With \includegraphics I can give the width of the resulting image (which would be scaled). How can I give a maximum width of the image? That is, if the original is smaller than X, I'd like to keep ...