Questions tagged [conditionals]
{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}.
1,916 questions
3 votes
2 answers
128 views
arithmetic operations with \ifthenelse
Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example: \documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \...
0 votes
2 answers
53 views
Can we mix \newif's \ifname as in \ifgreen with \OR or \AND?
I created \ifCond1 and \ifCond2 with \newif. If I want to test one condition, I use \ifCond1 Condition 1 OK \else Condition 2 KO \fi. My question : is there a way to use \ifCond1 and \ifCond2 glued ...
1 vote
0 answers
29 views
Print biblatex' bibheading only if the underlying bibliography is non empty
In the following MCE, bibliographic references are grouped by year, with a bibheading for each year (an unnumbered section indicating the year in question). \documentclass{article} \usepackage{...
2 votes
1 answer
65 views
Conditional text in a document that uses xsim package
I would like to conditionally add text (for example, "- Answers") to my exercise sheet title based on the global solution/print option set in \xsimsetup. My goal is to have the title change ...
8 votes
4 answers
330 views
Vertical dashed lines in tikz. Figure from Proofs Without Words
I’m trying to recreate a figure from Roger B. Nelsen’s Proofs Without Words: Exercises in Visual Thinking—specifically “Sums of Squares V” (Integer Sums, p. 81). My code gets everything right except ...
2 votes
1 answer
56 views
Conditional formatting of annotated bibliography
I want to print a 'normal' and an annotated bibliography from the same .bib file. Both documents need to have the same custom style (not pictured in the MWE), so I used the method in: Print and format ...
0 votes
2 answers
86 views
etoolbox conditionals with kvoptions string options
I'm writing my first LaTeX class. After some research I've found that kvoptions seems to be the most recommended for key value class options, and etoolbox is recommended over ifthen for conditionals. ...
5 votes
1 answer
116 views
How do I create a new environment with a conditional?
I'd to be able to set a value at the start of my document that sets in which chapters examples will have solutions. My attempt at this is as follows. \newcommand{\solutionsupto}{2} \newenvironment{...
0 votes
1 answer
101 views
Custom ordering of list items [duplicate]
Background: I want to create a multiple choice exam in two versions, where the order of the choices differ. That is, both versions have the same questions and a list of answer options, but these ...
3 votes
1 answer
133 views
Switch ouput on / off with specific syntax
I would like to define two switches such that this code \begin{document} \A This is text A Some more text A \B some text B \A again some text A \end{document} produces the following output: This is ...
10 votes
2 answers
228 views
Interaction between \ifcat, \noexpand, and active characters
I have come across the following oddity. Consider this example: \catcode`!=\active \let~=\empty \ifcat\noexpand~\noexpand! yes\else no\fi \let~=\relax \ifcat\noexpand~\noexpand! yes\else no\fi Why ...
1 vote
0 answers
67 views
Exact positioning (placement) of text or boxes
This question is related to one of my previous questions: Specifying exact placement of answers in exam tests I would like to make exam tests that can be compiled without and with answers, and the ...
2 votes
1 answer
101 views
\ifbeamer@... inside an \if condition causes it to run
I have a custom .sty file that has an option, "slides", for including packages and commands specific to beamer documents. Here's how it's structured: \NeedsTeXFormat{LaTeX2e} \...
2 votes
2 answers
190 views
Difficulty writing an ifthenelse style command
Edit: The previous edit removed the extra line in my command definition, but it turns out that this was the actual problem and not that there were mismatches in argument types being passed between ...
1 vote
2 answers
110 views
sequence duplication problem while using \if
EDIT: As Skillmon pointed out in the comments: "If you input your file multiple times you're adding stuff to your sequences every time you input it (since you don't disable your \quan-macro on ...