Skip to main content

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}.

Filter by
Sorted by
Tagged with
3 votes
2 answers
134 views

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} \...
underflow's user avatar
  • 1,129
0 votes
2 answers
59 views

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 ...
user1771398's user avatar
1 vote
0 answers
33 views

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{...
Denis Bitouzé's user avatar
2 votes
1 answer
66 views

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 ...
Aymane Fihadi's user avatar
8 votes
4 answers
333 views

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 ...
Richard's user avatar
  • 187
2 votes
1 answer
60 views

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 ...
Pedro's user avatar
  • 33
0 votes
2 answers
90 views

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. ...
jemhop's user avatar
  • 21
5 votes
1 answer
122 views

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{...
thecloisterbell's user avatar
0 votes
1 answer
104 views

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 ...
Bernd's user avatar
  • 1,905
3 votes
1 answer
134 views

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 ...
user2026844's user avatar
10 votes
2 answers
229 views

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 ...
plante's user avatar
  • 2,097
1 vote
0 answers
68 views

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 ...
bcsikos's user avatar
  • 879
2 votes
1 answer
108 views

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} \...
Deniz's user avatar
  • 53
2 votes
2 answers
191 views

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 ...
H. Pecoraro 's user avatar
1 vote
2 answers
110 views

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 ...
math_inquiry's user avatar
0 votes
2 answers
122 views

Consider the following sample code. %%% stop.cls \stop %%% test.tex \documentclass{stop} \begin{document} \end{document} LaTeXing test.tex generates the warning (\end occurred when \ifx on line 2 ...
gernot's user avatar
  • 52k
3 votes
2 answers
181 views

I basicually used this code to create a fading Bjornstrup style fancy heading. But I have one problem: this code doesn't display \chapter* properly. The annoying thing is I know what part of the code ...
Vebjorn's user avatar
  • 2,398
4 votes
2 answers
111 views

Imagine you have a tikz figure defined in myfig.tex : \begin{figure} %conditional statement (mychoice==1)... \draw[blue,thick] (0,0) -- (1,0); %conditional statement (mychoice==2)... \draw[red,thick] (...
Karlo's user avatar
  • 3,363
3 votes
0 answers
67 views

I want there to be specific indents (or something) that only applies to the second page. In particular, I have the if odd page for the last three blocks because if the boxes get enough text to push ...
Latex Learnin's user avatar
3 votes
2 answers
106 views

I’m writing a fully expandable macro that converts a TeX ⟨number⟩ to its Chinese representation (in the cardinal sense, not in the ordinal sense; the latter is much easier). The digits of the TeX ⟨...
Ruixi Zhang's user avatar
  • 9,933
0 votes
2 answers
110 views

I have a shared preamble file that provide uniform configuration for my documents. But it has no document class of its own. That way, I can determine the class for each document. But that means it ...
Steven Thomas Hatton's user avatar
1 vote
2 answers
74 views

I'd like to enclose subsection between \titlerule but I don't know how to avoid duplicating a line if a section is followed by a subsection. \documentclass{article} \usepackage{lipsum} \usepackage{...
edjmir's user avatar
  • 450
1 vote
0 answers
61 views

I am trying to create a Power-Round style problem set and want to include solutions to the problems as well, having an easily toggle-able option to include or exclude the solutions in the output (...
Sunny's user avatar
  • 133
-1 votes
1 answer
90 views

I started to use the correction program in Overleaf, and one error message I keep getting at this point related to my use of \iffalse ... \fi is the following: Suggested fix for error in classiclib....
Frode Alfson Bjørdal's user avatar
1 vote
0 answers
78 views

I'm trying to write a script in ConTeXt, and it's entirely possible that a character's lines might run over a page break. When that occurs, I'd like to be able to have ConTeXt handle the following ...
EnronEvolved's user avatar
5 votes
2 answers
209 views

Not important, but would be nice to understand: I have a strange interaction on beamer (only) with my lovely sign-macro for tabular. The sign-macro --- which I picked up a long time ago but don't ...
ivo Welch's user avatar
  • 4,264
0 votes
1 answer
74 views

I am not sure that the result of this code is the most appropriate for the nodes of points P and Q. What is the mistake made? \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \...
Paco Robledo's user avatar
11 votes
2 answers
457 views

I am updating some LaTeX code, dragging it kicking and screaming to somewhere around LaTeX3. Most of it is my code, I am unlearning various old bad habits so that I can learn new and improved bad ...
WaffleHouse2t2's user avatar
0 votes
0 answers
40 views

I am generating automatically subjets and corrections for exams. I usually use a "TexteouVide" function that displays the correction only if a boolean "correction" is true This ...
WNG's user avatar
  • 113
3 votes
1 answer
151 views

This is a contrived MWE that creates two key-value pairs for a new environment. One is a string which I evaluate if its empty using \tl_if_empty and generate the start of the "\begin{longtblr}&...
bennynihon's user avatar
2 votes
2 answers
138 views

I recently built a \version command to help version exams. The idea is that I'd pass in 5 arguments and set a flag at the start of the document that determines which argument gets read. However, this ...
Kellen Brosnahan's user avatar
3 votes
1 answer
114 views

The \else of \ifwindows binds wrong IMHO. Is this a bug - or a feature? \documentclass{article} \usepackage{iftex} \ifluatex \usepackage{ifplatform} \ifwindows lua-win \else lua-non-win ...
koppor's user avatar
  • 3,778
1 vote
1 answer
96 views

I've written my resume in LaTeX, however I think it would be useful to have the ability to compile a longer, multi-page version for certain jobs (such as ones requiring the federal format). Right now, ...
rainbowkitty227's user avatar
7 votes
3 answers
282 views

I wanted to make a command which accepted named boolean arguments like: \mycmd{foo=true, bar=false} So, I tried using keyval package and tried: \documentclass{article} \usepackage{keyval} \...
J...S's user avatar
  • 519
0 votes
1 answer
54 views

I am writing an exam in LaTeX, and I would like to include the solutions in the text. I'd like there to be one line at the top that I can comment out to remove all solutions from the exam. In the with-...
sgware's user avatar
  • 105
3 votes
2 answers
70 views

In the working draft of my book project, each of over 100 chapters gets a keyword/number for my own reference. I display the keywords (1) in the TOC, (2) at the start of the chapter, and (3) in the ...
marquinho's user avatar
  • 2,030
6 votes
2 answers
181 views

(This might really be a question about LaTeX macro names? Or about \ifx syntax?) I would like to check if the current font is Brill Italics, and if so, do something. I have tried something like this: \...
Natalie Weber's user avatar
5 votes
1 answer
132 views

Is there a way to test the definition of a command and do, for example, the following (with a correct conditional statement analogous to \ifthenelse): \documentclass{article} \def\Mycommand{\...
Jabot's user avatar
  • 343
2 votes
1 answer
111 views

I am trying to follow this post in defining a custom citation style where I show a different icon based on the type of the citation; as such, I am using the \ifstrequal command from the etoolbox ...
Bart Wolleswinkel's user avatar
3 votes
1 answer
128 views

I was reading the Asymptote doc about arithmetic and logical operators: https://asymptote.sourceforge.io/doc/Arithmetic-_0026-logical.html. How can I make a basic if elseif else statement in Asymptote?...
Jasper's user avatar
  • 10.9k
3 votes
1 answer
95 views

Consider the following MWE: \documentclass{article} \usepackage{fullpage} \newcounter{question} \renewcommand{\thequestion}{\Roman{question}} % see https://tex.stackexchange.com/a/729773/10898 \...
azetina's user avatar
  • 30.9k
6 votes
1 answer
266 views

tldr: I have a shared LaTeX input file containing a long equation (./theorem.tex). When included in a wide single-column document (notes.tex), the equation displays properly in one line. However, in a ...
Apollonius's user avatar
2 votes
1 answer
132 views

I would like to have my pdf outputs be automatically in darkmode if compiled at night according to my local time (I of course won't use it when I prepare this draft for publication). I see that I may ...
Gravifer's user avatar
  • 123
0 votes
2 answers
102 views

my first ever question. I've primarily been using LateX, and not delving into the innards of TeX, but maybe that time has come. Suppose I have a macro someMacro, which expects one argument. If the ...
DavidK's user avatar
  • 1
4 votes
2 answers
247 views

I am trying to use the package jsonparse1 (github page here, with documentation). I am reading some data from json files, and I have to fill my documents depending on the json entries, therefore I (...
Eddymage's user avatar
  • 235
4 votes
2 answers
270 views

My goal is to create a dynamic grading table like this: The table reads as follows.you would get grade 15 if you either had 50, 49 or 48 points, and grade 14 if you scored 47 points. For that I am ...
M. E.'s user avatar
  • 172
4 votes
3 answers
517 views

I have the following command in LaTeX: \DeclareMathOperator{\logistic}{lgc} I would like to modify it as follows: If the user simply writes \logistic, it should display just "lgc", as it ...
Kώστας Κούδας's user avatar
2 votes
3 answers
242 views

I would like to draw a Riemann sums plot where the bars are graphed based on the heights of each pair of consecutive intervals. The issue will be with the ifthenelse statement as I do not think the ...
Garth Fleming's user avatar
3 votes
2 answers
300 views

Look at: %here is the problem With the point in .\jobname1.tex it does not work, without it, it does. \TeX \jobname.tex\vskip\baselineskip Testing, if file \jobname1.tex ...
user avatar
3 votes
3 answers
216 views

After an embarrassing amount of attempted research and trial and error, I've landed on the following code that works as expected. If the current year is 2024, it says "They match!". If it's ...
Ben Grossmann's user avatar

1
2 3 4 5
39