Tagged Questions

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

10
votes
2answers
209 views

How to create command that creates new if command?

I want to load parameters (for conditional compilation) from files. I wrote command param that creates new if command and read parameter from file, containing following line: \paramnametrue % or ...
6
votes
2answers
154 views

expl3 switch for booleans: Is there a \bool_case:Nnn?

There's \int_case:Nnn, \tl_case:Nnn, \str_case:Nnn, but I can't find something like \bool_case:Nnn. I know I can write: \bool_if:NT \l__<mymodule>_<nameA>_bool { ... } \bool_if:NT ...
16
votes
3answers
343 views

newcommand does not work with \fi

I tried the command \newcommand{\fistudenti}{\fi} but it seems to work properly only in some cases. Here below there are two insances when it works and when it does not: WORKS: ...
1
vote
1answer
556 views

Setting \pagestyle{fancy} seems into create an error

Calling fancy page style is somehow apparently causing the following condition to test true. \documentclass{article} \usepackage{fancyhdr} \pagestyle{fancy} \ifcsname chapter\endcsname% ...
3
votes
2answers
86 views

Replace and add a/to a specific sequence of tokens

Is there a way to find a specific sequence of tokens and add after it a command? Or is there a way to find a specific sequence of tokens and replace it with another one? And do it only if the sequence ...
8
votes
1answer
313 views

Biblatex: Convert doi-url into doi field

I use biblatex and would like my bibliography to only include a DOI field, whenever there is DOI information available. This involves two things: Biblatex has to suppress the URL field whenever a ...
11
votes
1answer
219 views

Is color undefined

I want to check whether a color has been previously defined, consider the below code which doesn't execute. \documentclass{article} \usepackage{xcolor} ...
3
votes
2answers
171 views

Checking in LaTeX for a specific character?

I have a LaTeX problem that I cannot solve by myself. I have a repeating arrangement of characters which I want to format automatically in LaTeX. 1H-NMR (400 MHz; DMSO-d6): \textdelta 12.41 (s, ...
1
vote
2answers
84 views

Print macro content with condition

I would like something like the following: \documentclass{article} \newcommand{\acell}{} \newcommand{\bcell} \newccomand{\zcell}[1]{#1} \ifx\acell{A} \ifx\bcell{A} \zcell{yes} \else \zcell{no} ...
14
votes
3answers
331 views

Rotate image according to pagenumber

For writing my master thesis I have an image in landscape that needs to be oriented correctly when it is eventually printed in a book. If the page with the image is on the left side (even page ...
12
votes
2answers
168 views

What would be a suitable replacement for ifcsname in a non-etex situation?

From the pgfkeys.code.tex file: % This is useful: \def\pgfkeys@ifcsname#1\endcsname#2\else#3\fi{\expandafter\ifx\csname#1\endcsnam e\relax#3\else#2\fi}% \ifx\eTeXrevision\undefined% \else% ...
13
votes
2answers
667 views

Is a TeX macro defined?

I am looking for a way in TeX to check if a macro was defined. Currently I use a rather tangled way. I exploit a sort of side effect when comparing two macros via \ifx; this command returns: true, ...
4
votes
2answers
106 views

Test for a character, no matter if active or not (futurelet token)

I'd like to test for a character, irrespective its current catcode (i.e. active or not). This is very similar to How do I test for a character, irrespective of catcode?, however I cannot use ...
9
votes
2answers
130 views

Provide boolean from two arguments case insensitives

In most publications scientific names are abbreviated except the first time. Moreover, the names must be in italics and only the first letter of the generic name should be upper-case. The biocon ...
4
votes
1answer
170 views

LaTeX block conditional including

I am researching possibility of building an automatic brief datasheet template in LaTeX, taking data straight out of a database. The database connection part is possible and can be done with such ...
5
votes
1answer
253 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 ...
7
votes
2answers
498 views

Expand command read from file

I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
9
votes
1answer
93 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
52 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
151 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
372 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
86 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 ...
19
votes
1answer
262 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
84 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 ...
4
votes
2answers
306 views

How to define a if-condition? [duplicate]

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 ...
12
votes
1answer
225 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
218 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
149 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
149 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
677 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
205 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
122 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
148 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
146 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
280 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
188 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
120 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
736 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 ...
2
votes
1answer
415 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
169 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 ...
9
votes
1answer
1k 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
172 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
148 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
87 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
68 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
237 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
116 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
129 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 ...