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
1answer
26 views

Two different versions for exam, solution file needs to have a figure. Float(s) lost error with current code

I'm writing an exam for my class. The problems file needs to have an empty box after each question, while the solutions file should have the solution (preferably in a different colour). I got the code ...
0
votes
2answers
151 views

Problem with \ifthenelse inside some loops

Why this code produce some value not in the diagonal? Nine in total all below the diagonal. \documentclass{article} \usepackage{tikz} \usepackage{ifthen} \begin{document} \begin{tikzpicture} \...
12
votes
3answers
475 views

How to define new command for \{e_1,\cdots, e_n\}?

I want to make a new command that has three arguments: symbol (e, \omega,\cdots) superscript or subscript (^ or _) counter (n) If n=3 then returns \set{a}{^}{3} ====> output: {a^1,a^2,a^3} ...
0
votes
2answers
54 views

Conditional citation agreeing to parametized criteria

How can I include a citation only if it meets a certain criteria? Consider the following example, with improvised commands: \citationlevel{1} \citeif{1, something} \citeif{2, something} The first ...
3
votes
1answer
34 views

Boolean test for whether float has been moved?

Is it possible to create a boolean that knows whether or not a float remains inline, or has been moved? In my case, the float will be a raster image of known size. Sometimes it will fit inline where ...
3
votes
2answers
371 views

How to find the smallest number from a given set of numbers?

Is there any package or macro that implements getting the smallest number from a given row of numbers? using ifthen package. I was not able to get it. Here is my MWE. \documentclass[a4paper]{...
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 ($(-\...
2
votes
2answers
74 views

Conditional output into section works, but not into chapter

I built a custom language-switch macro for my document. It seems to be working fine in some cases, but not in others. How to make this work in any case, e.g. just output the content of the first or ...
1
vote
1answer
179 views

If-else in Latex

I want to have different headers/footers, depending on what "part" I have, which is defined in the "mPart" variable... I'm using the following code to distinguish between the parts: \newcommand{\...
5
votes
1answer
101 views

Defining conditionals (newif) in a loop using the loop variable

I want to define a set of conditionals using newif in a loop. The loop variable should become part of the conditional's name. However, I'm running into trouble when trying to set the conditional and ...
1
vote
1answer
66 views

Pgfplotstable - Using conditional statement in assign column name

I'm currently loading a table via '\pgfplotstabletypeset` and I found out that I can manipulate the header like this: \documentclass{article} \usepackage{pgfplotstable} \usepackage{filecontents} \...
5
votes
2answers
437 views

How to add different labels below nodes?

I have the following code and I want to make the count like 1,2,3 then 12 (the total number of neurons). \documentclass{standalone} \usepackage{tikz} \begin{document} \pagestyle{empty}...
1
vote
1answer
48 views

Conditional Citation

I am working on writing a chapter for which I want to control whether citations will appear or not in the end. Something like a global variable: CITATIONS_APPEAR = TRUE if TRUE: citations will ...
0
votes
2answers
85 views

Chess notation: Switch between color and notation style

Consider the following two examples: Example A \documentclass{article} \usepackage{xskak} \begin{document} \usetextfig \textsymfigsymbol{R}a1 versus \usesymfig \textsymfigsymbol{R}a1 \end{...
3
votes
2answers
117 views

Conditional cross references (\in and \at) in ConTeXt?

I am currently in the process of writing a comprehensive theoretical manual for my students. To make it easier to compile texts of varying difficulties for different groups of students, I also make ...
3
votes
1answer
110 views

Excluding whole frames with ifthen does not work (any more…)

I have a large slide deck (a multi-day training course) from which I want to generate different training courses (different lengths and combinations of subjects) by including/excluding certain slides. ...
0
votes
1answer
84 views

Chess notation: figure or symbol

This is somewhat a follow-up question to xskak: Switching between notation styles. I would like to create a command for a pawn move that either gives the name of the file in which the pawn is placed ...
1
vote
2answers
142 views

Dynamic Conditional Variables

I'm attempting to create documents of a priori unknown length that is determined by a set of conditions. I'm generating LaTeX variables, including conditional variables, using Python. Within a ...
0
votes
2answers
98 views

Conditional overlay specification in beamer: \begin{frame}\ifDraft<1000>\fi?

I have some slides with a lot of overlays. While still working on my slides (so to speak in "draft mode"), I would like to collapse them into a single frame; only when compiling the final version I'd ...
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}{!}{...
1
vote
2answers
170 views

Expanding a macro as the argument to \input results in undefined control sequence error

I'm creating a package which defines a command that looks something like this: \newcommand{\mycommand}[2]{ \input{|"\mypackage@buildcommand{#1}{#2}"} } mypackage@buildcommand uses the ifthen ...
1
vote
0answers
74 views

TIKZ MODULO inside of FOR LOOP [duplicate]

I am doing something simple with tikz, but code keeps not compiling. I would like to have something like this: \foreach \x in {0,...,4} \foreach \y in {0,...,4} \ifthenelse{mod(\x, 2)=0 \...
3
votes
1answer
71 views

Testing membership in a list

My question is similar to the one asked in ASdeL's question, except I am testing a loop variable against a predefined set. It seems that none of the solutions there are working for me because \imgidx ...
1
vote
1answer
63 views

Bugs in conditional structure in a newcommand definition with optional arguments

I am trying to create a new command for add a caption and/or the label to an equation. The not optional parameter is for the text of the equation and first optional parameter is for the label, the ...
3
votes
3answers
290 views

Bib conditionally render fields

How can I get biblatex/biber to only render the URL field if the type of the bib latex citation is misc, i.e. not article?
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
1answer
65 views

User defined macro in condition

I'm a LaTeX newbie and want to use current vertical position in a condition. I wrote this macro \ypos: \usepackage{zref-savepos} \newcommand*{\ypos}[1]{% \zsavepos{#1}% \zposy{#1}% } How can I ...
0
votes
1answer
47 views

Custom enumitem list reset conditional variable

I've defined a new list like this: \usepackage{enumitem} \usepackage{mdframed} \newcommand{\questionlabel}{Question } \newcommand{\restorequestionlabel}{\renewcommand{\questionlabel}{Question }} \...
1
vote
1answer
154 views

DeclareOption conditional does not seem to work

I can't seem to figure out why this isn't working. I'd like to set up an option for this package to allow for a preprint version (with no page range marked) and a final version with the page range ...
0
votes
1answer
246 views

How does one use pdf@strcmp in the pdftexcmds package? [duplicate]

I am trying to compare two strings with pdf@strcmp but I get the error: ! Undefined control sequence. <argument> \pdf @strcmp{abc}{abc} l.6 \section{\pdf@strcmp{abc}{abc}} ...
1
vote
3answers
107 views

Rewrite part of BibTeX file on reading?

I use Mendeley to manage my bibliography, pdf's, and to generate BibTeX files. It has one serious bug for me: an italicized word in a title (e.g, a scientific name of an organism) is written to the ....
3
votes
3answers
293 views

Conditional math symbols

In my private notes, I use non-standard mathematical symbols: I like using 0 to denote the empty set. Quite reasonably, my advisor does not like this if I do this in my paper. So I'd like to use 0 ...
4
votes
1answer
75 views

Unexpected behaviour of TeX condition in \draw macro

Let's consider code below \documentclass[tikz]{standalone} \usepackage{amsmath} \usetikzlibrary{arrows} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \foreach \i in {1,.....
4
votes
1answer
79 views

Using a conditional on a custom defined variable

Last month, I asked this question, about how to personalize a flowchart based on data available in a text file. The idea was to be able to adjust the width of arrows depending on numbers in the text ...
3
votes
1answer
320 views

What type of variable stores Boolean values?

Does LaTeX3 (specifically, expl3) support variables of type Boolean? If not, variables of what type (a token? a token list? a string?) should I use to store Boolean values (i.e. \c_true_bool and \...
5
votes
2answers
171 views

checking for empty argument in meta-command

In a current work, i'm using tons of CURIEs (shortened URIs), as common in my community. So i defined a meta-command called \defcurie that i can use to define a prefix like \defcurie{dbr}{http://...
2
votes
1answer
99 views

Why does \if with \fancypagestyle only work inside header and footer declarations?

I am writing a package where the first page has a custom header and footer made by fancyhdr while the remaining the pages have a different page style. However, I am curious as to the reason why this ...
0
votes
1answer
330 views

Latex custom header with fancyhdr

I would like to customize my headers in the following way in a book: On non-text pages (like for example part titles, or chapter title pages): no header, no footer On text pages On even pages: page ...
1
vote
1answer
80 views

How to surround multiple-element arguments with parantheses?

A command without brackets specifying the argument takes just the first element after it as an argument, so that a^bc will only have the superscripted b. I would like to exploit this with typeset ...
3
votes
1answer
95 views

Add parentheses if argument has subscript

I'm looking for the way to create new command \newcommand{\transpose}[1]{#1^T}. But what is important here I want the command to check if the argument has super- or subscript and add parentheses if ...
4
votes
4answers
332 views

Is it possible to have a tcblisting environment within an \ifthenelse?

I would like to choose which code to print according to a boolean flag. If I use my \ifthenelse with plain text it works perfectly, but if I put a tcblisting environment instead of the plain text, it ...
8
votes
1answer
303 views

How to determine if a PDF page exists before including it?

I want to test if a PDF contains the specified page before inserting it with \includegraphicx[page=?]{filename.pdf}. (Normally specifying a non-existent page generates a fatal error.) How can I do ...
4
votes
1answer
58 views

How do I test for page orientation in LaTeX?

I'm looking for a way to test whether the current orientation of my document is portrait or landscape within LaTeX. This would be similar to the following test for font size: \ifthenelse{\equal{\f@...
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­...
3
votes
2answers
198 views

Split the \@authors list at \and

With xparse it's pretty easy to split a list at each occurrence of a token. In my MWE I set up a new command \mylist in which I passes two names separated by \and. The xparse script splits the list at ...
2
votes
1answer
79 views

Use of variable within the call of a function

I need to call various commands based on some combination of conditions. Due to a huge number of possible cases, it would be very convenient to use variables inside the name of the called command. Is ...
2
votes
1answer
413 views

Test if \author{} macro is empty

I have to check if the \author{} macro is empty because the output should change if this condition is set. There are two ways the author can be empty: \author{} No \author{} command in the document. ...
0
votes
0answers
156 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 ...
1
vote
2answers
98 views

\let-number checker

Is there a safe way to check if some macro input is a number that was \let to a number? I.e. suppose we said \let\foo=1, is it possible to define a macro \isnumber that determines if \foo was a number?...
1
vote
2answers
323 views

comparing \x and \value{section} with if

I want to evaluate whether my variable \x (that comes from a foreach loop) is the same as my current section number. I tried \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage[T1]{...