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

46 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
21 views

Prepending digits to section numbers in ToC

I have more than ten sections that I want to list in the ToC as the following: Which means I need to prepend 0s to sections of \ifnum\thesection<10. How do I do this in the ToC? MWE : \...
3
votes
0answers
49 views

Using conditionals inside mcexam

I want to write exams where the questions and answers are randomized, and mcexam lets me do almost everything I want. However, I would also like each question to be picked randomly from a group of ...
3
votes
0answers
129 views

Why do I get an “Incomplete \ifx” in this MWE?

I am trying to redefine the figure environment, which works fine in general. However, if the body of the figure environment to be replaced includes a tabular environment inside a conditional ...
3
votes
0answers
199 views

\ifbeamer@anotherslide and \ifbeamer@localanotherslide in beamerbasedecode.sty

At the beginning of the source file beamerbasedecode.sty of beamer class, two switches are defined: \newif\ifbeamer@anotherslide \newif\ifbeamer@localanotherslide By reading beamerbasedecode.sty and ...
3
votes
0answers
108 views

Problems in using the spreadtab and the ifthen packages

Using the spreadtab package for some computing, I have to write an expression (mixing of literal and numerical expressions) if some conditions are true. Using the ifthen package, all works well for a ...
2
votes
0answers
171 views

Change key and value with TikZ/pgfkeys

Another TikZ problem: Both vectors a plotted but the second produces an error: ! Dimension too large. <to be read again> \relax l.37 \myvector[text align=center](1,1) ...
2
votes
0answers
76 views

Document branching

I am moving myself from using LyX to just coding in LaTeX. I've been able to research and figure out a lot of things on my own, but there's one feature in LyX that I'd like to be able to code in LaTeX ...
2
votes
0answers
141 views

Filtering results of iterator from table in csv file

I am a Lua novice, and I would like to know if there is any way for an iterator to filter out or skip certain items in a table from a csv file. In particular, I would like for an iterator to be able ...
2
votes
0answers
29 views

commands / package for target-group-specific creation of documents

Is there a package that allows me to create target-group-specific documents. Basically I have two scenarios: There is an exercise document and each task is initially followed by a solution. In that ...
2
votes
0answers
106 views

Passing optional arguments to a listing environment based on conditionals

I am trying to make a presentation which can optionally compiled for handouts. This presentation also contains highlighted code snippets. For highlighting I use the code from this question. (Which ...
2
votes
0answers
95 views

Insert or apply a decision structure to sequence or list

I would like to make the function calls \findLargest in the MWE below a little more dynamic and compact. As demonstrated in the example below, I can store glossaries values and include them in the ...
2
votes
0answers
146 views

\if and \fi inside different \def macros

Recently I failed to solve specific task in LaTeX. I wanted to make document with several sections, each divided on several subsections. Each section I had placed to separate files, and used \input ...
1
vote
1answer
40 views

Different text on last page

I want to add one of two different texts, depending on whether it appears on the last page. I tried this: \documentclass{article} \usepackage[angle=0, opacity=1, scale=1,position={0,0}]{background} \...
1
vote
0answers
31 views

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error?

How to check if attempts at totally expanding the tokens of an arbitrary sequence of tokens would yield an error? How to check if attempts at totally expanding the tokens of an arbitrary sequence of ...
1
vote
0answers
41 views

again about appendix to make hidden slides

I tried to put some slides in the appendix, but it doesn't work on my compiler. If I add an appendix after the first compilation it works, probably because the navigation bar is not yet updated, but ...
1
vote
0answers
75 views

How to check if last displayed content was displaymath / minipage ends on displaymath?

Is there a way to check if a minipage ends with display math? Or more generally, if the line above was a displaymath? Background: I defined a command for a minipage-environment that fixes alot of ...
1
vote
0answers
36 views

Conditional execution based on existence of key/value pair in datatool

This question is a confirmation and a follow-up using the code from this question I'm preparing a template, which relies on some texts which will be provided in a CSV file (ex, disclaimer text, large ...
1
vote
0answers
37 views

How to change ifthen to allow changes within package or document?

I'm trying to change the font size of a table within a thesis. I'm using a template I found online quthesis. The style file has an \ifthen setup that I don't understand. It seems if the strict command ...
1
vote
0answers
115 views

Is there any way to do bit testing in tikz?

I want to do something in tikz that is a bitwise function of a number, e.g. \def\mask{165} %% = 0xa5 but it looks like TeX doesn't know hex \foreach \k in {0,...,7} { \node[mybox] (b\k) at ($(-\...
1
vote
0answers
44 views

Output plain ascii text to output file (expandable \IfStrEqCase with multiple matches)

This question is specfically about an expandable version of \IfStrEqCase (with multiple matches) as per Modified \IfStrEqCase with multiple matches per case. However, in case this is an x-y problem, ...
1
vote
0answers
51 views

\ltx@iffilelater (now) returns false results for babel's lan­guage def­i­ni­tion files

The present question follows \@ifpackagelater equivalent for babel's lan­guage def­i­ni­tion files? which was about conditional tests based on the version ⟨date⟩ of babel's lan­...
1
vote
0answers
41 views

Conditional compilation with multicols nested in a \newenvironment

I wish to include a question/solution bank at the end of the chapter. I want to be able to control its printing via a single comment/uncomment operation. The MWE is an article but my intention is to ...
1
vote
0answers
51 views

How to compare two macros containing Cyrillic?

Short question is: How to compare two macros containing Cyrillic? It is not difficult to compare two strings with \ifx for Latin strings \def\contentsnameinlanguage{Contents} \ifx\contentsname\...
1
vote
0answers
38 views

LaTeX Switch Case with Media9

sadly I am an absolute beginner to LaTeX programming. I would like to use a switch case to display embedded YouTube Videos using the package Media9. \ifcase\value{counterVideogroup1} \...
1
vote
0answers
107 views

Ignore \addvspace at top of mdframed environment

In the MWE below, I include a \addvspace{2.0ex} before my figure. This looks fine, except if the figure is at the top of the mdframe. Is there a way to for the \MyFigure macro to decect if I am at the ...
1
vote
0answers
441 views

Correct way to pass options to (class) loaded packages

I write a document with the book class and have a file (mainstyle.sty) with a number of packages that I use (pdfx, lipsum, placeins, etc\ldots). I recently started playing around with tufte-book and ...
1
vote
0answers
36 views

Combining \DTLgmeanforall with a conditional in a table created by datatool

I am organizing a list of students an there marks for exams in a .csv Document. These are printed in a tabular environment with the help of datatool. The Table lists the marks an the resulting mean. ...
1
vote
0answers
69 views

Conditional pagebreak depending on position on page

Is there a way to say, add a newline here, if there are less than x empty lines before the next assumed pagebreak? something like \newpageIfThisLineIsLinesAwayFromBottomLessThan{5} I know that this ...
1
vote
1answer
804 views

A method of distinguishing Iverson from other brackets?

Is there a common idiom or method for distinguishing Iverson brackets from "normal" brackets? In all examples I've seen, simple braces [...] are used for both; but in complex expressions, this can ...
1
vote
0answers
53 views

How to only print endnote section if there are any endnotes?

I am using the enotez package and would like to be able to call \printendnotes regardless of if there are actually any endnotes. In the case that there are no endnotes I would either like the \...
1
vote
0answers
110 views

“Draft” mode for document

Suppose you want to keep two versions of the same document: one where you highlight changes and one where you show the final result. How can I use a "debug" or "test" mode to turn on/off my \textbf ...
1
vote
0answers
303 views

Ending a tikzpicture environment in conditional causes “Missing } inserted”

I want to create a number of tikzpictures. I have a number of items I want to draw. Each tikzpicture takes up a whole page and may contain up to 4 items. (It is not good enough to to have each item in ...
1
vote
0answers
55 views

Creating multiple output files, with content that depends on a variable

I'd like to write a template for a letter, which is meant to be sent to many people. Thus, the content should change slightly depending on who is the addressee. For instance, I imagine that the ...
0
votes
0answers
34 views

I want to detect an order placed at the beginning of each theorem

I want to detect an order placed at the beginning of each theorem. \documentclass{article} \usepackage{ifthen,ntheorem} \newtheorem{ex}{Exam} \begin{document} \begin{ex} \LaTeX{} There is the LaTeX ...
0
votes
0answers
83 views

Conditional Latex table: Cell value color based on its value

I would like to create a conditional where values less than 7 are in red and values greater than or equal to 7 are in blue. I would like a result like the one below: Follows my MWE. \documentclass[...
0
votes
0answers
31 views

Access to Testable Environment variables

I've figured out how to access environment variables, I can test on a value. I can't test on the value of an environment variable. I thought it best to include my test case: \documentclass{article} \...
0
votes
0answers
28 views

Is it possible to make an “if” section in TeX which is conditional on an environment version being set?

I'd like to produce two slightly different versions of a document. One will include confidential information, the other will be slightly redacted. Is it possible to use an environment variable and ...
0
votes
0answers
24 views

Conditionally print VC macros

How might I go about conditionally printing a macro? I know this exists for graphics (\includegraphics) and there's ifdraft for the rest. For example, using fancyhdr I have the following (simplified) ...
0
votes
0answers
19 views

Translating a book: supporting both languages in a single project

I am currently translating a project from english to spanish. The project is organized by using subfiles. I want to move all .tex files to a 'en' folder, while creating a 'es' folder where I would ...
0
votes
0answers
28 views

Write text only if Execute Metadata is not empty

I use the catchfilebetweentags package to get specific content from a common .tex file. MWE for the file where all content is stored (called master.tex): \documentclass[]{article} \usepackage{...
0
votes
0answers
101 views

Usage of While-do constructs LaTeX

I'm curious, when reading about the ifthen-packages I've come across the syntax of while-do statements. What are they used for ? For example this piece of code from the documentation (this is copy-...
0
votes
0answers
110 views

Conditional to execute alternative code when error detected

I would like to be able to build a conditional to execute one set of code if the conditional would compile, versus another if the code would generate an error. Take the following code block which ...
0
votes
0answers
64 views

\if@onecolumn doesn't work

I am using IEEEtran template. I wanted to adjust pictures or tables flexibly according to the column setting, so I wrote this: \resizebox{\if@onecolumn 0.75\columnwidth \else \columnwidth \fi}{!}{...
0
votes
0answers
159 views

If condition on text width

I need to create an ``if clause" based on the length of the subtitle. My code is: \documentclass{beamer} \subtitle{Testing the Subtitles} \newlength{\sbtw}\settowidth{\sbtw}{\insertsubtitle} \ifnum ...
0
votes
0answers
68 views

How to conditionally format in LaTeX?

I am interested in formatting the following code such that if a conditional is met (Add = 0 and Del = 0), then my document prints out "There are no additions or deletions". Otherwise, the document ...
0
votes
0answers
165 views

An environment for conditional compilation using a switch

I want to bar certain parts of my document from compiling based on a toggle switch. The reason is that my books contain a lot of PGF diagrams and graphs and the whole book takes a lot of time to ...