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
2answers
190 views

understanding “ifthenelse” command with pgf random number

I can not understand why the following use of ifthenelse and pgf give me an error : \documentclass{article} \usepackage{pgf} \begin{document} \pgfmathrandominteger{\a}{2}{7} \pgfmathrandominteger{\b}...
2
votes
1answer
46 views

Missing } error from multiple “\immedite\write”s within a foreach loop; the current plot has no coordinates error with gnuplot

I suspect that these errors are coming from a section of code in which I loop through a master data file and restructure it so that I can give the newly made file as an argument to pgfplots. If I ...
2
votes
3answers
227 views

Conditional tests on string variables in tikzmath library

Is it possible to test for strings in the tikzmath library? (E.g. if <variable>=<string expression> then foo) I tried a naive test and it returned this error: Package PGF Math Error: ...
1
vote
1answer
71 views

exam class: define new environment which depends on \printanswers

I am having trouble defining a new environment which depends on the \printanswers option of the exam class. \documentclass{exam} \usepackage{framed} \printanswers %\noprintanswers \newenvironment{...
1
vote
2answers
62 views

Length sign conversion in math mode

I am setting up a document that outputs an equation, with some parts showing or not showing depending on commands i set in a different file. the commands look like this: \newcommand\coefficient{1.25}...
1
vote
1answer
71 views

Failure of \if condition inside \titlecontents

I need to add some word before contentslabel in toc by some condition using titletoc. \documentclass[]{report} \usepackage{titlesec, titletoc} \newif{\ifappendix} \titlecontents{section}% <...
0
votes
1answer
56 views

How to display chessboard with missing opposite diagonal corner pieces in latex?

So far I have a chessboard which is displayed fully, however, I want to modify it such that it has missing opposite diagonal corner pieces, I don't mind which corner. This is my code so far: \...
0
votes
2answers
362 views

How to resolve an incomplete \iffalse error?

I'm trying to create a multitude of 8x8 grids with a single random shaded box on each. This is for a classroom activity and I want a bunch of different grids and would rather not hard-code the random ...
2
votes
3answers
108 views

Hyperlinking conditions with math symbols error

I have this code borrowed from a similar stack thread \newcounter{susis} \newcommand{\myHyperlink}[2]{% \refstepcounter{susis}\label{susislink#1}% \ifcsname r@susistarget#1\endcsname \hyperlink{#1}{\...
1
vote
1answer
158 views

Different color for negative values in a comb plot

I am using pgfplots for plotting simple comb plots. There are some negative values in the data. Right now all the data is plotted in same color. I would like to plot the negative values in the data in ...
3
votes
1answer
171 views

LaTeX Utility/Template for Generic Reusable Code

I often find myself wanton of a LaTeX utility with the following semantics: In a file path/foo.tex: \OneTimeOnly{ % Code that is inserted only once, the first time the file is included. ... } ...
4
votes
1answer
184 views

xsim and “conditional” printing

I'd like to know if the following is possible with the xsim package: Could the space created by commands like \blank[width=4.8\linewidth,linespread=1.5]{} (as given in the manual) not be printed if ...
5
votes
1answer
61 views

Test what number is \thePagewiseLineNumber

I want to test (not to print) if the actual line is the x line of a page. With the help of the lineno package I able to know if the actual line is the x line of the document, testing what number is ...
2
votes
1answer
666 views

ACM acmart template anonymous mode conditional text

I'm writing a conference paper using the acmart template. As the conference is blind, I've set the anonymous=true option (How to remove author information in sigconf template (acmart.cls) for double ...
0
votes
1answer
27 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
152 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
485 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
120 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
106 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
68 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
445 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
49 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
88 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
120 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
114 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
86 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
153 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
99 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
175 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
78 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
72 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
65 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
307 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
48 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
159 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
261 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
109 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
300 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
78 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
80 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
332 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
173 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://...