{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}.
4
votes
1answer
33 views
conditional glossary style
I use glossaries to display a global symbol list but also local one for each equation. The first userkey is used to add the physical unit. But some smybols (like efficiencies or proportions) don't ...
8
votes
1answer
64 views
Test if a skip has an infinite stretch/shrink component
I want to implement an if-then-else depending on whether a skip contains a special character or not.
So far, I tried the idea: convert the skip to a token list, and check if the letter f is in the ...
0
votes
0answers
30 views
How to test if an command is empty {}? [duplicate]
I used \newcommand* foo {} to define a command so the user could set it later via \renewcommand* foo {content}. How do I create a conditional statement (if then else) that tests if foo is empty ("{}") ...
6
votes
1answer
62 views
Test if a chapter has sections
Is there an easy way to test if a chapter has sections? The question is related to short tables of contents displayed at the beginning of each chapter and that would be empty when the current chapter ...
3
votes
1answer
36 views
How to write a \newenvironment with a conditional structure and one optional parameter
I would like to define a new environment with an optional parameter. Currently, I have
\theoremstyle{plain}
\newtheorem{prop}{Proposition}
\newenvironment{propExt}[1][]{\ifx!#1! \begin{prop}
\else ...
10
votes
1answer
64 views
Scan argument for parentheses
I'd like to define a macro which expands to (#1) if #1 does not contain any parentheses, but expands to \big(#1\big) if it does.
I'd choose simplicity over generality: if a solution works in the most ...
11
votes
1answer
74 views
Is something the first item on a page?
How can i identify logically, whether something is the first item on a page, i.e. there is nothing above it (apart from header)?
Consider the following, is is basically a feature environment, which ...
10
votes
1answer
61 views
How can I detect if an environment is right after a sectioning command?
I'd like to build an environment that would detect if it is right after a sectioning command (\section, \subsection or \subsubsection) and smart enough to detect if a float-type environment (say ...
2
votes
1answer
77 views
How to define a if-condition?
I found several entries about the fact that the ifthen package is obsolete. So my question is: how to define a condition check then? I have searched and I find several example for ifthenelse ...
11
votes
1answer
54 views
Simple way to switch inline asymptote figures on and off
I use the inline asymptote environment \begin{asy} to draw a lot of the figures in my papers. To those not familiar with asymptote, the asymptote package creates *.asy files for each of the asy ...
4
votes
1answer
41 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 & ...
4
votes
1answer
43 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 ...
8
votes
1answer
47 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 ...
0
votes
0answers
27 views
“Extra \fi” error using acmtrans2e and fixmetodonotes
I get the following error
! Extra \fi.
\listofnotes ...TES@enabled \listofNOTES@note \fi
l.12 \listofnotes
when compiling the following document that uses the ACM actrans2e class:
...
2
votes
2answers
53 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 ...
12
votes
2answers
91 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 ...
9
votes
1answer
63 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
69 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.
...
16
votes
1answer
109 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
54 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
86 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
37 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
219 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
81 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 ...
1
vote
0answers
60 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 ...
5
votes
1answer
108 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
89 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
65 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
...
1
vote
1answer
51 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 ...
1
vote
0answers
41 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
29 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
39 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
73 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
32 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
83 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 ...
15
votes
2answers
155 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 ...
10
votes
2answers
144 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 ...
1
vote
0answers
46 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 ...
4
votes
1answer
112 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 ...
0
votes
0answers
75 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
77 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 ...
10
votes
3answers
157 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.
...
8
votes
0answers
146 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
46 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
144 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 ...
3
votes
1answer
103 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 ...
6
votes
1answer
246 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
}
13
votes
4answers
145 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
128 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 ...
5
votes
1answer
83 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}
...



