{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}.
7
votes
1answer
184 views
Testing for TeX boolean in Lua code
How can I test for a TeX boolean in Lua?
This kind of code doesn't work:
\newif\if@mypkg@someif
\begin{luacode}
-- some lua code
\if@mypkg@someif
-- some more lua code
\else
...
5
votes
2answers
177 views
Biblatex: ifx inside DeclareFieldFormat
I'm not having any luck using an \ifx command inside a \DeclareFieldFormat block with biblatex (v1.6). Is there something I'm missing? A minimal (non-)working example:
\documentclass{article}
...
23
votes
3answers
4k views
When to use @ in an \if statement
I am new to LaTeX and so this question might come across as rather basic.
It might also reflect my biases/assumptions from my C/C++ programming days.
I was seeing the code of the 'exam' class and ...
9
votes
1answer
187 views
\ifmmode doesn't seem to work correctly inside an array environment
I’m struggling with getting \ifmmode to work correctly when used inside an array environment which is inside a displaymath environment.
Here is a minimal example:
\documentclass{article}
...
10
votes
4answers
618 views
How to make a “condition” in a macro?
I would like to make a macro with two parameters which return a text. For instance, I want \M{1}{5} to return [1,5], and \M{2}{2} to return [2] (because the two arguments are the same). So I need to ...
16
votes
2answers
222 views
How can I detect if I'm inside or outside of a float environment?
I am trying to detect whether I am inside or outside a float. I know the way how caption works. It uses the internal \@captype. But in the example below you see that this test failed by using ...
5
votes
1answer
132 views
Testing for a blank line (“paragraph”) immediately after \begin{document}
(With this question, I hope to resolve an edge case relevant for my quoting package.)
Suppose I define a customized environment for displayed text. It resembles the standard LaTeX environment quote ...
11
votes
2answers
209 views
Can I conditionally scale an image with graphicx
In particular, when I include a graphic, I would like it to have width=\linewidth if it's width is greater than \linewidth, but I'd like it to have \scale=1 if it is smaller than the line width.
In ...
3
votes
3answers
237 views
Show “Page X of Y” only if there are multiple pages?
I'm trying to add a line in the header to be "Page X of Y", but only if there are multiple pages. My main problem is how to format the if statement. So far I have
\ifx \pageref{LastPage} 1
...
6
votes
2answers
804 views
Check if a string contains a given character
I want to implement an if-then-else depending on whether the argument contains a special character or not. Should I be looking here: http://www.tug.org/TUGboat/Articles/tb28-1/tb88glister.pdf, or does ...
4
votes
3answers
343 views
Create odd-numbered answers, or all answers
I'm starting with a clean slate creating a solutions manual. I would like the ability, by setting a switch, to produce only the solutions for the odd-numbered problems, or those for all problems, in ...
7
votes
3answers
193 views
Detecting which version of the LaTeX format is in use
ltxcmds provides \ltx@ifpackagelater, \ltx@ifclasslater, \ltx@iffilelater
and there is \@ifpackagelater - but is there any "if TeX later" or some other way to (automatically) get the used TeX version ...
5
votes
2answers
768 views
Figure numbering without the figure
It is quite common for academic journals to require article submissions to not include the figures, which are submitted separately. Then the journal staff position the figures in the text manually. ...
2
votes
1answer
164 views
Why is only one of these two options passed to pdflatex seen?
Consider the file define.tex.
\documentclass{article}
\RequirePackage{changes}
\makeatletter
\@namedef{Changes@AuthorColor}{red}
\colorlet{Changes@Color}{red}
\makeatother
\begin{document}
...
2
votes
3answers
250 views
How to simulate 2 dimensional loop using 1 dimensional loop?
animate package does not allow nested loops. Only a single loop is allowed. However, we often need to simulate 2 dimensional space in a single loop.
Please see the following C# code that I want to ...
3
votes
1answer
303 views
conditional highlighting with soul
The journal PLoS ONE, says in the FAQ
When submitting your revision, you will need to include the following new files:
[...] A ‘clean’ copy of your revised manuscript.
A revised manuscript with ...
1
vote
1answer
579 views
How to configure fancyhdr depending on the document class [duplicate]
Possible Duplicate:
How to configure theorems depending on the document class?
I would like to have if the book class is loaded but
if the article class is loaded. Can I do this with some ...
4
votes
2answers
272 views
How to configure theorems depending on the document class?
I would like to have \newtheorem{teo}{Teorema}[chapter] if the book class is loaded but \newtheorem{teo}{Teorema}[section] if the article class is loaded. Can I do this with some sort of ...
5
votes
1answer
237 views
How do I execute some commands conditionally?
What would be the correct way to execute commands conditionally in LaTeX?
Here is the problem I am having. I have a book_pdf.tex where I wish to define the style of the book as it would look in a ...
9
votes
1answer
1k views
Comparing an argument to a string when argument is a result of a command with etoolbox
I've got an example like that:
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\ab}{a}
\newcommand{\aORb}[1]{%
\ifstrequal{#1}{a}{"a" was given}{not a}, %
...
15
votes
1answer
390 views
What exactly does \@doendpe do?
Quoting from the LaTeX2e sources:
[\@endparenv, \@doendpe]
To suppress the paragraph indentation in text immediately following a
paragraph-making environment, \everypar is changed to remove ...
13
votes
2answers
2k views
What does \begingroup\expandafter…\endgroup do?
I often see code of the following form in package implementations (this example is from the LaTeX3 sources):
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname ...
2
votes
1answer
493 views
Multilingual beamer presentations from a single souce?
I have a beamer presentation of which I have two language versions (german and english), more languages are upcoming. I keep both versions in one source and select the one to typeset with the comment ...
2
votes
3answers
460 views
TeX Nested Loops With \iftoggle
This forum has helped me understand how to use nested loops in TeX, but now I am having trouble using \iftoggle (from the etoolbox package) with loops. My goal is to have a toggle that can keep track ...
4
votes
1answer
152 views
Defining a command that distinguishes between greek and roman letters?
I'm using pdftex and I want to define a command for the typesetting of quantum mechanical operators that produces upright letters with a \hat accent. The problem is that the obvious solution
...
2
votes
1answer
219 views
Testing for multi-line paragraphs
I'm running into a situation where I need to insert some code (specifically, \hfill) only if my paragraph runs more than one line. This isn't a simple alignment thing, as I'm working with ...
8
votes
2answers
241 views
French chapter numbers
This question led to a new feature in a package:
impnattypo
French typography recommends that chapters be numbered in uppercase roman numbers, except for chapter 1 which should be called ...
8
votes
1answer
487 views
How can I test if a document is being compiled by XeLaTeX?
Is there a way to programatically test whether the current document is being compiled by (pdf)LaTeX or XeLaTeX?
5
votes
1answer
495 views
Changbars to indicate location of conditional text
I am using etoolbox as per this question on LaTeX conditional expression, and would like to modify the conditional to print some sort of indicator (like a vertical change bar in the margin) to show ...
10
votes
4answers
3k views
Are there any “if” commands like “\ifnum” in LaTeX?
Are there any commands containing "if", similar to \ifnum, preferably in LaTeX (rathar than TeX)?
For example, is there anything like \ifstring? (I am not after \ifstring only, I want to know which ...
6
votes
1answer
718 views
How to tell if the current section is defined in Beamer?
I am customising the footer of my Beamer slides. The footer displays the title of the slides, followed by a ":", and then the current section title. This works fine if the current section is defined. ...
10
votes
2answers
672 views
Test if a paragraph has a page break in it?
I'm trying to use TikZ to make fancier frames. I'm using the clever \tikzmark thing that Andrew Stacey wrote to put nodes at the top left and bottom right of the body of an environment.
Then I use ...
9
votes
5answers
448 views
Test if token is a control sequence
Sometimes more complex (La)TeX macros test the next input token and branch dependent on its type. I'm aware how to test for catcodes and character codes, but sometimes I like to handle control ...
10
votes
2answers
486 views
Doing something only when the draft option is on?
I would like to do some stuff that is only enabled when the draft option is given in \documentclass[draft]{article}.
How would I go about doing this?
7
votes
3answers
394 views
\expandafter, \csname issue related to test for macro being defined
Just when I think I starting to understand \expandafter I run into this problem where I am trying to test if \ConditionG, \ConditionH, etc are defined in a loop. I tried all the combinations I could ...
5
votes
1answer
321 views
biblatex: What's the first character of a field?
I would like to know, what's the first character of the value of the editor field. If the character is a curly bracket "{" the value should be printed for example bold, if the first character is ...
1
vote
2answers
400 views
Book in two (or three) languages in LaTeX
I am writing a book in two languages: a Russian version and an English version. Is it possible to do this in the same file?
Something like \tltext{Hello world!}{Здравствуй, мир!}, and mark at the ...
12
votes
2answers
678 views
Define a Macro via Macro if Given Macro is not defined
I want to define a macro if it is not already defined. I can do this inline as the example below shows. But I would like to have a macro to do this functionality for me. My attempt to make this work ...
5
votes
1answer
260 views
Biblatex: Idiom for testing contents of list field
I am creating a Biblatex bibliography style for legal citations. In one particular case, I need to format the citation (of a court decision, i.e. jurisdiction) differently depending on the particular ...
9
votes
1answer
256 views
When is \if@nobreak set to \iftrue or \iffalse?
In my answer to a question on page breaking, I used a private switch that the user had to set by hand to prevent tables which start just after a section from breaking (at the first line).
It seems ...
4
votes
2answers
368 views
Deciding Boolean operation in LaTeX via Linux Terminal
How do I decide a Boolean operation in LaTeX via Linux terminal?
That is, I have:
%myfile.tex
\documentclass{article}
if parameter=true
is true
else
is false
\begin{document}
parameter
...
12
votes
2answers
632 views
Custom quotation style which depends on length of quotation
I am writing my PhD-thesis and I need to meet certain formatting requirements in regard to quotations. I know there is the quote environment. But in this conditions it doesn't match my universities ...
10
votes
1answer
372 views
How do I check whether the text will fit in one page?
I am trying to typeset a page that varies in length. Sometimes it's just shorter than A4, but sometimes it exceeds the length of A4.
My question is, how can I check whether the text will fit in one ...
8
votes
1answer
1k views
\ifnum and pgfmath: error
In the following example I want to use \ifnum to compare two numbers computed by pgfmath, for simplicity I use simply 1 and 2 in the example below. Compiling this code gives me the error:
ERROR: ...
10
votes
2answers
336 views
How can I check if the current code is inside a certain environment?
I would like to define a command which checks if it is executed inside a certain environment. Like this:
\documentclass{article}
\newenvironment{myenv}[0]{at start}{ at end}
...
8
votes
2answers
214 views
Passing text containing linebreaks as command or environment parameter?
I just tried to write some commands which used its argument to check whether they were empty (isempty{...} from package ifthen) or not. The problem was that the text to check contained a linebreak, ...
5
votes
2answers
348 views
If pagestyle equal to… — How should I ask it?
I'd like to use (or define) an If-statement for pagestyle.
I have no idea :(
Update:
I'm using in my document about 4 pagestyles. Just as a little example I wish to have at the border of my document ...
10
votes
1answer
360 views
Using ifthenelse for crop marks with tikz
How do I use to insert ifthenelse crop marks in Tikz. I want
ifthenelse{\printcrop=true}{\draw(0,0) -- ++(0,1);}{}
That is, if yes, make a drawing, else but do nothing.
And yet, where I can choose ...
10
votes
2answers
268 views
biblatex: Something like \ifentrytype
I’d like to change the bibmacro cite:short only for one entry type (@music). So is there a way to test for the entry type?
7
votes
2answers
2k views
Conditional cases expression
How can I create a command \if with 1 argument, namely #1,
\if{#1=1}{symbol1}...{#1=n}{symboln}
that returns symbol1, when #1 is 1, ..., and returns symboln, when #1 is n, and returns nothing, ...