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
2 votes
2 answers
103 views

Beamer: Can't use itemize within if-statement

MWE: \documentclass{beamer} \begin{document} \begin{frame} \ifdim\textwidth=\textheight equal \else \begin{itemize} \item unequal ...
user avatar
  • 2,395
0 votes
2 answers
55 views

Is there a known way to build a macro that creates a dynamically sized array?

I'd like to be able to write a command that essentially takes two arguments, the number of rows and the number of columns, creates an array of the specified dimensions, and then allows for a variable ...
user avatar
0 votes
1 answer
47 views

Declare new command to denote the condition with additional settings

Can someone tell me how to set the parameters of a declared new command similar to how it is set in the TikZ package? More specifically, I would like to declare a function \condVert{} that sets a ...
user avatar
  • 97
3 votes
1 answer
84 views

expandafter and ifx

I try set color for only first letter, (aaa or bbb) in relation with test \ifx. I have more complicated task in original, but I want to understand how it work on this simple example. My MWE: \...
user avatar
  • 271
0 votes
0 answers
18 views

Hide environment depending on a flag [duplicate]

I have an environment which should only be shown, if a certain flag is set. Currently I do \ifenv \begin{env} Text \end{env} \fi but it would be nice to include the \ifenv and \fi into the ...
user avatar
1 vote
2 answers
50 views

Misplaced \omit for multicolumn in "if then else"-statement in tabular

Since my update to the latest LaTex Distribution I am running into an Misplaced \omit. }-Error. Here is my minimal working example: \documentclass[parskip=half+,11pt]{scrartcl} \usepackage[utf8]{...
user avatar
  • 197
2 votes
5 answers
188 views

\ifblank does not work correctly with \pgfkeys

The macro \test below is used to test if its argument is blank, and it gives unexpected result. What's wrong with my code? Example: \documentclass{article} \usepackage{tikz,etoolbox} \begin{document} \...
user avatar
  • 2,353
0 votes
0 answers
49 views

Evaluate LaTeX parts conditionally depending on Lua state

In LuaLaTeX, I want to evaluate parts of the document conditionally, depending on Lua state. A way to evaluate parts conditionally in LaTeX is a \if \else \fi construct. A simple approach to connect ...
user avatar
  • 2,928
2 votes
1 answer
117 views

Detect delimiter

Is it possible to check whether a token is a delimiter, i.e (, ), |, \vert, \langle, \rangle, etc without directly checking each of them in a condition? The structure of delimiter is well described ...
user avatar
  • 2,253
0 votes
0 answers
48 views

Conditional inclusion of environment gives random errors

I've spent a few hours trying to debug the following. I did manage to fix it, but mostly by chance. Can someone enlighten me on what actually happened? Initial setup I'm using \usetikzlibrary{external}...
user avatar
  • 1,383
0 votes
3 answers
112 views

How \string and \newcommand work?

I try to write a command that each notation can link to the first appearance. Consider a notations A and a vector B. Define a command that fun{'}=B' and fun{x}=B^{x} for x=/='. If I want to write B^(A)...
user avatar
2 votes
1 answer
45 views

Check the presence of file which starts with specific string in LaTeX

I have a directory that contains multiple files. I can easily determine the presence or absence of a file with the following command. \IfFileExists{sample.png}{....}{} But how can I check the ...
user avatar
  • 777
1 vote
1 answer
87 views

How to combine the \circled command on one-digit numbers and the \newcircled commands on two-digit numbers?

First a MWE and its output are as follows. \documentclass{article} \usepackage{tikz} %%%define circled command%%%%%%%%%%%%%% \newcommand*\circled[1]{% \tikz[baseline=(char.base)]\node[shape=circle,...
user avatar
  • 3,031
7 votes
3 answers
331 views

How to avoid warning on \ifsomething \end{document} \fi

This is truly an unimportant curiosity/itch question. I have chapters in a book that can compile either within the whole book or by themselves. At the end, the files have statements like: \...
user avatar
  • 3,401
6 votes
1 answer
123 views

Detect if is currently in a list

Is there anyway to detect if the code is currently inside a list, no matter itemize, enumerate or description? Note: I'm using enumitem for configuring lists. Motivation: The reason I'm asking this is ...
user avatar
  • 6,200
4 votes
1 answer
79 views

Execute \clearpage before a section only if a certain amount of lines are already filled

I use: \AddToHook{cmd/section/before}{\clearpage} to start a new page before a new section. Is there a possibility to only execute this, if more than X percentage of the page is already filled? So ...
user avatar
0 votes
2 answers
55 views

Export two copies of document with a \newif variable toggled on and off

Consider the following document (test.tex): \documentclass{article} \usepackage{blindtext} \newif \ifoption \optiontrue % (*) \begin{document} \ifoption % ...
user avatar
  • 273
0 votes
1 answer
44 views

Height of \parbox can not be assigned with condition?

I want to assign the height of my \parbox with condition, as I did below, but fail. Why and how to deal with it? Code: \documentclass[a4paper]{article} \usepackage{etoolbox} \usepackage{geometry} \...
user avatar
  • 2,353
2 votes
2 answers
77 views

Show plots conditionally / progressively

I would like to show my plot through multiple stages. For example, I'd like to show first the blue plot, then blue and red, and finally all three, without copying the file multiple times and ...
user avatar
  • 1,383
0 votes
1 answer
32 views

Make paragraph-formatting apply to all environments but not to short paragraphs

I am aware that this is a hyper specific question but I have been playing around with making all paragraphs perfect rectangles just like in this StackExchange question. And as in these older threads I ...
user avatar
  • 23
3 votes
1 answer
111 views

How to make the value of a lengh macro change with another

\documentclass[a4paper]{article} \usepackage{xcolor,pgf,etoolbox} \usepackage{geometry} \geometry{showframe} \geometry{left=1cm,right=1cm,top=1cm,bottom=1cm} \parindent0pt \begin{document} \newdimen\...
user avatar
  • 2,353
0 votes
0 answers
25 views

How can I typeset lstlisting verbatim content conditionally?

I need to write a macro (or an environment if that helps) that allows its parameter/content to be printed conditionally. Below is an MWE. You can play with the \foofalse comment sign to enable/disable ...
user avatar
4 votes
2 answers
71 views

Recursively using \@ifnextchar in itemize environment

I'm having some troubles using the \@ifnextchar macro recursively. My goal is to be able to call \subitem{item1}{item2}...{itemN} inside either an enumerate or itemize environment. This is what I have ...
user avatar
  • 143
1 vote
3 answers
101 views

Define a macro whose name depends on a condition

I tried the following three ways to give value(here is aaa) to a macro whose name depends on a condition. Only the third one works. However, the value aaa has to be written twice. If the value is very ...
user avatar
  • 2,353
1 vote
1 answer
30 views

LaTeX xsim: printing only even/odd number answer

I am writing exercises sheets for my student and I want to print only solutions to odd (or even) numbered exercises using LaTeX xsim. I have searched on Google and looked in the xsim manual, but ...
user avatar
0 votes
0 answers
14 views

Square brackets throw an error while parentheses don't [duplicate]

Why does the following work \documentclass[answers]{exam} \begin{document} \begin{center} \Large\textbf{ \shortstack{ Assignment 1 \...
user avatar
  • 8,789
0 votes
1 answer
73 views

Tikzpicture with conditioned tikzset

I want to have a tikz picture which changes its behaviour depending on the variable \PA. I have two files. One file contains only the tikz picture (Tikz.tex) and a main file which loads the picture ...
user avatar
  • 55
0 votes
2 answers
39 views

Combine different commands into one using a conditional

I define the following commands \def\R{\mathbb{R}} \def\Rd{\R^d} \def\Rn{\R^n} Is it possible to combine these three commands into one using a conditional? As an example, I would like \Rx to output \...
user avatar
9 votes
3 answers
472 views

Problems testing for a leap year using expl3

For a recent project I tried to become acquainted with LaTeX3 but unfortunately, I have some difficulties and cannot find the issue, which is why I'm asking for a helpful hint. In the project, I want ...
user avatar
  • 2,688
1 vote
1 answer
61 views

How to extract multiple information from the \jobname

I use one .tex file to create multiple CV depending on the \jobname. For that I use the ifthen package and for each type of CV I create a Boolean value that I use to conditionally include some text. ...
user avatar
  • 13
2 votes
1 answer
151 views

How to detect EOF for two source files in loop condition?

For a critical edition in two languages, my Main.tex file has a loop that: reads a line from first source file reads a line from second source file outputs the lines with the \chunks command uses \...
user avatar
0 votes
2 answers
96 views

How to define table cell color depending on cell text value imported from the CSV file

I am trying to color table cell depending on the text value imported from the CSV file. The CSV file has three possible text values that are "High", "Intermediate" and "Low&...
user avatar
  • 38
0 votes
1 answer
32 views

\iftoggledefined: Detect if newtoggle was defined

I am looking for \iftoggledefined{<toggle name>}{<true>}{<false>}. I checked the etoolbox documentation and did not see such a thing. Based on Difference between \newbool and \...
user avatar
2 votes
3 answers
84 views

How to define a macro that holds the value that \f@series assumes for bold?

To start with, I am only interested in solutions that work with pdfLaTeX, as opposed to, say, those that only work with LuaLaTex. The 'narrow' problem First, a preliminary note: some packages redefine ...
user avatar
1 vote
1 answer
47 views

Using \ifx in a macro

I am trying to make a macro that checks if the two arguments have the same string using \ifx. But I observed seemingly inconsistent behavior. Here is my code: \documentclass{minimal} \begin{document} ...
user avatar
  • 413
3 votes
2 answers
95 views

Detect end of \input-file (not \read-file) in Knuthian TeX?

In Knuthian-TeX I'd like to have a macro which switches to verbatim-category-code-régime and then calls another macro which processes characters from the current input-file one by one until reaching ...
user avatar
3 votes
3 answers
137 views

How to use variables in a conditional function with expl3?

I want to learn expl3 programming. To make myself familiar with the syntax, I wanted to create some dummy programms, such as computing prime numbers. However, I am stuck defining a function which ...
user avatar
  • 1,661
0 votes
0 answers
19 views

Use scale if latex image is small enough, center in page otherwise [duplicate]

I automatically generate a bunch of diagrams, and I'd like them to be automatically formatted to fit the page according to the following style: If the diagram (in the form of a .png figure) is ...
user avatar
  • 195
4 votes
2 answers
164 views

"Lazy" cases with expl3?

Problem: i would like to have a command, which takes one mandatory and one optional argument. If the optional argument exist, select the corresponding case, otherwise return all case opportunities. ...
user avatar
1 vote
1 answer
69 views

Create latex boolean from pythontex

I essentially want to do something like this. \documentclass{scrartcl} \usepackage{fontspec} \usepackage[gobble=auto]{pythontex} \usepackage{ifthen} \begin{document} \newboolean{tex_bool} \begin{...
user avatar
  • 15
2 votes
3 answers
68 views

Implementing Switch Case with date or other numbers

I try to use a "Switch Case" macro in my LaTex File. But I want to put in the "Switch Case" macro the month not a number. Unfortunately a get nada as output instead of 31.01.22. ...
user avatar
  • 119
1 vote
0 answers
41 views

How to make code conditional on LaTeX kernel version [duplicate]

I want to make use of some kernel features introduced in the latest release (2021-11-15) in a package. In order to maintain some backwards compatibility, I want to issue a warning and use a workaround ...
user avatar
  • 12.7k
0 votes
0 answers
17 views

Redefine command depending on options [duplicate]

I would like to change a parameter depending on the option in Beamer class. If [handout] is set, I want to show graphics smaller. To do this, I was creating a boolean \ifhandoutand was trying to ...
user avatar
  • 1
2 votes
1 answer
147 views

Extra \else and extra \fi error

I am writing a document that presents different information depending on a defined command. The code in a simple version is like this: \documentclass{article} %\usepackages ... \title{My title} \...
user avatar
3 votes
1 answer
29 views

includegraphics: option for downscaling only

in the scripts for my students, I have a lot of screenshots which I include into the paper via e. g. \includegraphics[width=0.7\linewidth]{"MyScreenshot"} do scale them down which works fine....
user avatar
0 votes
1 answer
65 views

Need conditional that evaluates to nothing

Resolution: The problem was with the outdated version of moderncv I was using. I put some additional details at the end of the question, but I will delete this question. Thanks to those who wrote to ...
user avatar
2 votes
1 answer
25 views

putting two distinct images on event and odd paged headers

I want to put images in the headers of all pages but the first page of a document. Besides for the first page, on each and every odd page, I want one image; while on each and even page I want another ...
user avatar
1 vote
2 answers
93 views

variable in expl3 case function does not seem to expand/substitue (code compiles but strange output)

the provided code copy-paste ready and compiles. Problem: the \l_secondIndex_tl variable does not seem to expand to its stored value in the \tl_case:NnF -line and therefore the code does not find the ...
user avatar
2 votes
1 answer
44 views

Suggestions for conditionally loading image A or image B

I have a latex color definition file (that I switch out with \input) to produced a "themed" PDF for green, tan, and blue (works well with some Python code). The final step is to ...
user avatar
  • 161
1 vote
0 answers
59 views

String equality check [closed]

I want to compare 2 strings and perform different tasks based on their results(using if-else loop) My code is here: \tab• \hyperlink{new}{New Features, Enhancements, and Changes}\linebreak \begin{...
user avatar
  • 23

1
2 3 4 5
34