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
0 votes
0 answers
47 views

Code description for \tl_if_empty:VTF [duplicate]

Is the following code description correct ? %% Test for empty Token List \feuds_teorema_parent_tl. %% VTF are Type Specifers for the arguments to the function. %% V Indicates that first argument is ...
Veak's user avatar
  • 643
2 votes
2 answers
63 views

Conditionals in \foreach loops

I drew a ruler using the MWE below then I realized that It draws each medium (5 mm step) vertical line over the small ones (1 mm step) and each large (numbered) vertical bar over both medium and small ...
Brasil's user avatar
  • 1,276
2 votes
2 answers
117 views

Custom Environment with Parentheses around Optional Parameter

I am trying to create a custom "proof" environment that behaves as follows: \begin{proof}\end{proof} should produce \textit{Proof.}, while \begin{proof}{method}\end{proof} should produce \...
Baguette Boy's user avatar
1 vote
2 answers
71 views

Validate a date using datetime2 or other packages

Can an English date be validated using the datetime2 package? If not, are there any other packages/ways to do this? Valid arguments: 2023-06-14 , 2023-09-24 , ... Invalid arguments: 2023-06-XX , ...
projetmbc's user avatar
  • 13.4k
1 vote
1 answer
49 views

conditionals inside newcommand with multiple argument

This question is an extension of conditionals inside newcommand with empty argument I have a macro that looks like \newcommand{\pcs}[3]{{#1}_{#2}^{(#3)}} It is the third input where I would like to ...
Sayan's user avatar
  • 199
1 vote
2 answers
82 views

Create a new environment that can switch between center, flushleft, flushright from based on a parameter

I would like to create an environment that, provided with either center, left or right creates a center, flushleft, or flushright environment. My current code is the following: \newenvironment{...
Vincent's user avatar
  • 4,683
0 votes
1 answer
39 views

fancyhdr and extramarks packages: incorrect header when chapter ends page

I have an encountered a problem with the \fancyhdr and \extramarks packages. When a chapter ends on a page, it puts the wrong chapter number. However, if a new chapter starts on that page, it renders ...
ceramicquasar88's user avatar
2 votes
1 answer
86 views

How to include some commands depending on the version

Two versions of Latex or actually texlive need to edit one document. The older one does not know microtype etc. How can I conditionally include text and commands for one version or the other? \...
false's user avatar
  • 227
0 votes
0 answers
12 views

Define a heading style command, which ignores leading white space if it is used at the beginning of an environment

I want to define a kind of heading, that i can use in a shaded environment. I want this "heading" have a bit of leading vertical space, but would like to eliminate this space if the command ...
Shylock's user avatar
  • 15
1 vote
1 answer
29 views

Beamer: Show frame if it is defined

When constructing larger presentations with beamer, I often split them into several files on which I work individually. For the sake of an MWE, it might look something like this: \documentclass{...
Frunobulax's user avatar
  • 2,116
2 votes
1 answer
64 views

How to create a solution environment

I want to create a solution environment that works somehow like this: If at the beginning of the document, solutions are TRUE I want to show the text in the environment and be highlithed. If it is ...
Fischer's user avatar
  • 33
2 votes
0 answers
33 views

\iffalse not working inside of table

The following code is supposed to generate a table with a single row and two columns. It does however not compile. The error messages contains Incomplete \iffalse and A forbidden control sequence ...
M. Winter's user avatar
  • 521
1 vote
0 answers
20 views

Condition Based on Page Breaking

I am working on some software to automatically format documents to comply with strict court rules. Under these rules, it sometimes matters whether a given piece of text appears on the front cover or ...
bbernicker's user avatar
1 vote
3 answers
47 views

How to keep usual spacing between words inserted conditionnaly

Here is my MWE : \documentclass{article} \newcommand{\Titre}{Some text} \newcommand{\Date}{and then some} \begin{document} \ifdefined\Titre \Titre \else \fi \ifdefined\...
LMT-PhD's user avatar
  • 1,204
2 votes
2 answers
133 views

How to make bibliography to work in subfiles of a subfile?

I am writing a long report that needs the help of the subfiles package to break it into individual sections. It works like a charm until I further split one of the subfiles into two. Previously, the \...
Shixi's user avatar
  • 23
0 votes
0 answers
27 views

Properly use algorithm environment in latex/ overleaf

I am working with my old latex code, which at the time worked but now the output seems unexpected. I am using the following packages: \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{...
Azerbijanargh's user avatar
2 votes
3 answers
319 views

Incorrect result of if statement in LaTeX

\documentclass[a4paper,oneside,12pt]{book} \usepackage[left=3cm,right=2cm,top=2cm,bottom=2cm]{geometry} \begin{document} \edef\var{1} \if \var= 1 {var equal one} \else {var not ...
Ongky Denny Wijaya's user avatar
4 votes
3 answers
138 views

Have something appear in the footer only if section isn't over

I'm writing a gamebook. My text is divided into a lot of little paragraphs, with length varying from a couple of lines to a page and a half. Readers/players will start from paragraph 1 and then move ...
il mietitore's user avatar
3 votes
2 answers
89 views

How to fix titlesec overriding contentsname

I'm using the titlesec package to change the format of titles from this: To this: The way I did this can be illustrated using this MWE: \documentclass{report} % This is the code that changes the ...
Mailbox's user avatar
  • 239
0 votes
1 answer
31 views

Conditional statement to increase \footskip on certain pages

How can I write a conditional statement to increase the value of \footskip on all pages that include a footnote? I have tried reading the answers to similar questions (e.g. How to form "if ... or ...
Noah J's user avatar
  • 443
0 votes
0 answers
34 views

How can I make an \if conditional reusable?

This is related to a previous question of mine, how to use listings in conditionals. I'm using the answer kindly provided there to include different code snippets when their library of origin is ...
serval's user avatar
  • 97
2 votes
1 answer
54 views

How can I use listings in conditionals?

I have a library that contains code snippets formatted with the listings package. This library is used in two different documents, with slight variations depending on the document. I've been using ...
serval's user avatar
  • 97
1 vote
1 answer
43 views

Add a plural sign depending on the number of items

I'd like to add a plural sign (say a 's') when needed. My current use case is for pluralizing a noun based on the number of pages in a document but I could also count oranges and bananas down the road....
green diod's user avatar
0 votes
0 answers
20 views

Matching spacing with conditional versions

I am using an "if" to make two versions of a document (a problem set and an answer key). I would like both versions to have the same vertical spacing while using vfills, but I think that ...
user26305's user avatar
  • 152
1 vote
0 answers
41 views

Use of \noindent in a code={} of tcolorbox yields wacky vertical spacing

I adpated the code={} solution from Auto append prefix to tcolorbox's title to include a prefix to a title of a tcolorbox and was getting wacky spacing for a subsequent use of the mytitlebox ...
Peter Grill's user avatar
0 votes
1 answer
23 views

Automatic columnbreak in multicol env if section content is short

in my article template a part of the text is set in twocolumn mode. I'm using multicol package with the starred environment (to fill up one column after antoher). The twocolumn article part consists ...
lukeflo's user avatar
  • 1,091
1 vote
2 answers
81 views

Environment that detects if it contains a given command/string

I defined an environment that center and box a content. \newsavebox{\tempbox} %Allows to use fbox in newenvironment \newenvironment{result}[1][\textwidth] { \begin{center} %The box will be centered \...
Flowt's user avatar
  • 181
4 votes
1 answer
317 views

Why is there additional space?

I try using a specific section only if a variable is defined. Everything seems to work, however there is an additional space between the name of person B and the address, although the same code is ...
mrCarnivore's user avatar
  • 1,367
0 votes
0 answers
22 views

Multiple choice questions with hints about how many choices are expected (single vs multiple)

I use paper exams (with LaTeX) for midterms and finals, but I also use LMS quizzes for learning the material. As such, my students are used to Moodle, where if a multiple choice question is intended ...
Fuhrmanator's user avatar
1 vote
0 answers
45 views

Compare Token List result to a string

I have a command that (beyond my control) evaluate into a token list, and I want to compare it to a given string, I tried to follow this answer and create a variant on \tl_if_eq: \ExplSyntaxOn \...
Yuval Shmuel's user avatar
1 vote
1 answer
62 views

Conditional formula format with entered values and answer

With the luacode below I have tried to generate a conditional formula format with entered values including answer. However, it seems unnecessarily complicated and the formula formatting does not work. ...
PaulJGD's user avatar
  • 253
3 votes
1 answer
126 views

How to check for #1 being either `d` or `h` with latex3?

Is there a command in expl3 to check if #1 is either d or h or min and only then run a piece of code?
mrCarnivore's user avatar
  • 1,367
2 votes
1 answer
266 views

How is \iffalse ... \fi handled?

Let's have a look at the example: Some text. \iffalse Nothing to print. \fi Further text. I would expect that this is handled like Some text. Further text. because the system simply removes the ...
principal-ideal-domain's user avatar
0 votes
1 answer
38 views

Comparing pgfkey variable against a string

I want to check a mutable variable against many possible values, so that a macro will behave differently based on that value. Since there are many variables, they are stored using pgfkeys. Testing ...
eduardofischermath's user avatar
1 vote
1 answer
40 views

Define a `\DTMifdate` conditional using the `datetime2` package and `\today`

I got a question regarding the usage of the datetime2 package. I want to set some due date and to define a certain date such as \paperdate which is either \today when it's before the due date or the ...
pahohu's user avatar
  • 227
1 vote
1 answer
73 views

How to check if a command is empty?

I am trying to check if a variable is defined without using extra packages (since I want ot use it in an .lco file) and if it is defined then check if it is empty. The definition check works but the ...
mrCarnivore's user avatar
  • 1,367
2 votes
1 answer
78 views

Conditional row formatting LaTeX tables depending on selection in first column

Is there a way to highlight a specific row in table depending on the selection in first column. For example "HEA160" and this specific row turns red. \documentclass{scrartcl} \usepackage{...
PaulJGD's user avatar
  • 253
3 votes
1 answer
116 views

Help making conditionals in a macro

I have this bit of code that list the author in bold and each their affiliations in italics everytime \AddAuthor is called and send all authors to TOC. \newcommand{\AddAuthor}[2]{} %container \...
Andre's user avatar
  • 119
1 vote
0 answers
25 views

How to check whether on left or right column ? (In a two-column document)

In a two-columns document (or using the multicol package) : How do you check (for an "if-else" condition) if you are on the left or right column ? I've searched everywhere and only found ...
Nicolas Canovas's user avatar
0 votes
0 answers
25 views

How to make an environment that can do conditionnal formatting for MCQs

I would like to preface by saying I am almost completely new to LaTeX. Now, I am currently trying to make a document class for the Question Papers structure that is popular here. There are two kinds, ...
SP Craftsman's user avatar
0 votes
1 answer
34 views

Commenting out lineno and disabling commands related to it via ltxcmds fails to compile unless I manually delete the aux file

From a previous question, take this example \documentclass{book} \usepackage{lipsum} \usepackage[left, pagewise]{lineno} % LINE \usepackage{ltxcmds} \makeatletter \newcommand{\OnlyIfPackageLoaded}[...
Enlico's user avatar
  • 2,552
0 votes
0 answers
17 views

Trick with lineno on both sides can't be "compiled-out" via ltxcmds [duplicate]

Some time ago I took the solution from this answer to show lineno's line numbers on both sides of the page. However, I want numbers to be in place only sometimes (say when I need to send the document ...
Enlico's user avatar
  • 2,552
4 votes
2 answers
241 views

Incomplete \ifodd; all text was ignored after line

I'm having lots of trouble when using \ifodd. I want to make a pattern of alternating thick and thin lines, I have tried several ways but none of them works. With this structure \documentclass{...
Eduardo Jiménez's user avatar
1 vote
0 answers
67 views

Problem with multiple \str_case_e [closed]

I have a problem if I want to use multiple \str_case_e:nnTF. Could you please help me how to solve this? Is there something wrong with the \str_case_e:nnTF definition? Thank you. I use pdflatex on Mac ...
Milan Rusek's user avatar
2 votes
1 answer
79 views

ifcase eats up letters

I created a command that switches between GCD and LCM. However it has a side effect of erasing everything before the second visible character after the command. How can I fix this bug? \documentclass{...
hau2643's user avatar
  • 21
1 vote
1 answer
25 views

ifcase command that changes color does not work

I am creating a handout with a command that hides the answers for students and reveals the answers for instructors. I defined a new command invisible that takes a bool and text. If 0, the text should ...
om94266's user avatar
  • 11
5 votes
4 answers
377 views

How to use full-string conditionals in latex

I want some conditional paragraphs in my document. I've been following chapter 13.2 of "Tex by Topic", but I've run into limitations. \documentClass{report} \def\option{a} \begin{document}...
Stewart's user avatar
  • 679
0 votes
0 answers
50 views

Counting number of lines of code in align* environment

I am writing an exam paper, and I want to write the solutions immediately after the question. I then want to toggle the solutions on and off, which works via the \solution command. When solutions are ...
kwilliamson's user avatar
3 votes
1 answer
81 views

\nameref and xifthen's \isempty do not work properly

So, I made a macros \fullref and combined it with \ifthenelse to remove [] if no content were printed. But when, for example, theorem has no name, \nameref prints nothing but xifthen's \isempty do not ...
Vladyslav Rehan's user avatar
2 votes
2 answers
96 views

Why do these macros not evaluate to the same so that \ifx is true?

I have a document with paragraphs that were transcribed from an interview. Each of the paragraphs is from one author, alternating. Starting with "Author 1" I want to add the author name in ...
Fabian Schneider's user avatar

1
2 3 4 5
36