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
1
vote
1answer
129 views

Define Command/Macro with boolean flag

I'd love to have a command with a boolean flag. That flag is supposed to be used in a conditional statement. I'd love to have something like this: \command -> false \command[flag=...
0
votes
0answers
109 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-...
4
votes
1answer
65 views

Conditional to test whether in an itemize

I'm using LaTeX to write manuscripts for plays, I've been looking a bit into conditional expressions. The reason is that I want comments in the manus, and I currently have two different commands for ...
2
votes
5answers
187 views

How can I condition on the last token?

I would like to write a command \foo which, for the sake of simplicity, does just one thing, which is make sure its argument ends with a dot. Thus both foo{hello world} and foo{hello world.} expand to ...
2
votes
2answers
161 views

Conditional If-then-else/xIf-then-else Packages

I'm currently working on a presentation about the packages mentioned in the title. The problem I have is, I don't really understand why anyone would use conditional statements in a LaTeX document. ...
1
vote
1answer
46 views

\ifdefempty against linebreaks [duplicate]

I use LaTeX for text processing in conjunction with a template parser. I want to do things, when there would be text to print. So I have \newcommand{\zahltext}{% %% here may be dragons, this is ...
6
votes
4answers
196 views

nesting macro identifying string length 1 using xstring ifthen packages

I would like to write a latex macro \p which given input X returns X or (X) depending on whether X has character length 1 or not. Moreover, I want to be able to nest applications of \p. E.g. I want ...
7
votes
2answers
325 views

If/Else Statement Not Working When Trying To Reformat Subsections

I want my LaTeX code to number sections and subsections like (FYI: I'm using article not chapter or book): 0 Introduction (section) 1 A (section) 1.01 A1 (subsection) 1.02 A2 (subsection) ... 1.10 ...
17
votes
3answers
487 views

About what TeX does after it finds commented conditionals with ltxdoc

When I thought I understood the concept of the doc package, LaTeX proved me wrong. I was trying to make a file to use with ltxdoc when I realised I could not use conditionals in the preamble because ...
5
votes
1answer
169 views

Conditional \if@mainmatter don’t have any effect

I try to make a command who have different behavior depending if it is executed in mainmatter area or not. So I use the \if@mainmatter command as described in the topic Checking the mainmatter But, ...
3
votes
1answer
105 views

How can I prevent \ifnum to be ignored?

So I have the following code: \newcount\x\x\i \ifnum\x<3 \advance\x1 \fi \the\x \bye which I call from the command line with pdftex '\def\i{9}\input test.tex' This puts out 10 (or \i + 1), ...
1
vote
4answers
102 views

Custom \if command to check for multiple conditions

I'm creating a document class for bachelors' and masters' theses at my faculty. It's almost ready and tuned to this year's official requirements. However, things may change in future: for example, the ...
6
votes
2answers
302 views

Using \ifthenelse inside an option

I'm trying to create a \newcommand for images which takes width as an optional parameter. This is my current command which works (but doesn't use the parameter): \newcommand{\introimg}[3]{ \begin{...
4
votes
4answers
894 views

Hide/Show Solution for Problems

There are too many options for "Solution/Answer" environments which we can use and I am adopting this one for my "big" project that I am doing. At the moment, it looks like the easiest one for me to ...
0
votes
2answers
51 views

Generate path for \includegraphics with if-else macro

I would like to have a single option/macro (true/false or similar) that determines, from which folder to choose plots. There's only 2 folders for each plot. Mainly need this to switch between low ...
0
votes
1answer
28 views

exam class 2.6: use self defined environment which depends on \printanswers before first question

I am not longer able to use a self defined environment which depends on \printanswers before the first question since the exam class was updated to version 2.6. (I use this solution.) With the exam ...
0
votes
2answers
162 views

gdef with @ifnextchar

I am trying to create a command with two or three arguments, that creates a new command. In my classfile I have: \def\foobar#1#2{\gdef\foo{#1, #2, \@ifnextchar\bgroup{foo}{bar}}} If I call \foobar{...
2
votes
1answer
111 views

Use shortframetitle for list of frames only when defined

I'm creating a list of frames for my beamer presentation as in my previous question, which works like a charm. If a framesubtitle exists, it will be put into the list of frames in favor of the ...
3
votes
1answer
119 views

Printing a \pageref{} but only when not on that page in LaTeX

I would like to set up a macro to print a page reference with a reference, but only when the label is not on the same page. For example, I'm looking to define \myref{} so that this code: \...
2
votes
2answers
79 views

Problem with storing recursive calculus

I have the following issue with some recursive calculus. I just write the function \recsum that recursively computes the sum of an unspecified amount of integers. It works when I call the function ...
2
votes
1answer
15 views

Process first or last case differently with clist_map

I wrote this macro to transform a comma-separated list of objects into a custom-separated list of objects: \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\separators}{m}{% \clist_map_inline:...
2
votes
2answers
54 views

Hyphenation of camelCase inside an \ifthenelse while using custom hyphenation command

While writing software documentation, the need arose for a command that automatically hyphenates camelCase words at uppercase letters, e.g. camel-Case. Furthermore, these camelCase words are typeset ...
3
votes
1answer
44 views

Checking a command with \equal and then using that command for another command?

I am trying to check the definition of a command (either arabic, roman, Roman, Alph etc.) and from this information change the formatting of section titles, while making use of the command definition ...
0
votes
1answer
20 views

multipurpose index command with xparse: conditionals as arguents of \index not working

I want to define a multipurpose index command, \xindex{text}[index]/parent/ with one mandatory and two optional arguments. It should (i) print 'text' in the main text, (ii) send 'index' (or 'text') ...
0
votes
0answers
40 views

conditional if / else [duplicate]

I want in following examaple change the day of week according the inputted day. When I use dia in the document work, but when I use inside newcommand doesnt (look the example) \documentclass{article} ...
0
votes
1answer
640 views

condition if/else

In the following example I want write Tuesday if the variable dia is Monday. The following example write rest not matter the string of variable dia. \documentclass{article} \def\dia#1{\if{#1=monday}{...
4
votes
1answer
110 views

Icons on side of text, below section headings

I am currently trying to write a custom command that helps me display a bunch of icons on the side of a section text, right below the section heading. There is always the same amount of icons (in my ...
0
votes
1answer
58 views

How do I have to implement the following comparison [TikZ] [duplicate]

How do I have to implement the following comparison? \documentclass{scrartcl} \usepackage{etoolbox} \usepackage{tikz} \begin{document} \begin{tikzpicture} \pgfmathparse{sin(60)} \let\x=\...
1
vote
1answer
32 views

Character suppression at newline

I am attempting to typeset a list of names separated by specific characters, e.g. John Doe | Jane Doe | John Doe | Jane Doe | John Doe | Jane Doe | .... This list is to be input{} into various ...
4
votes
2answers
70 views

Alter arguments in custom command

I would like to modify my func command in such a way that the domain/codomain arguments can be altered, e.g. so that arg=R^n yields $\mathbb{R}^n$. \documentclass[a4paper]{article} \usepackage{...
2
votes
1answer
53 views

Adding title to plots in groupplot from file

I am plotting a lower triangular matrix of plots with groupplot, and I would like to add a title to the plots on the diagonal. I generate these plots by reading data using \foreach, and therefore need ...
1
vote
1answer
115 views

Conditional plotting by position in pgfplots groupplot

Edit: I was able to get the layout in the last image following the accepted answer. Just needs some visual tweaking now. I have some issues with compilation with LuaLatex, which I will troubleshoot ...
4
votes
1answer
98 views

How to define a style of undefined key choice? [duplicate]

I would like to implement something like default in a switch statement, but for .is choice pgf key. I know that there is an error key handler /errors/unknown choice value but I don't know how to use ...
4
votes
1answer
201 views

Why does this test with ifthenelse not compile?

Why does the following test using \ifthenelse not compile: \documentclass[border=30pt, tikz]{standalone} \usepackage{tikz,tikz-3dplot} \usepackage{ifthen} \usepackage{animate, calc}%%%%%%%%%%%% \...
1
vote
1answer
57 views

List of Figures + Beamer? (followup)

I'm interested in making a list of figures in Beamer so that I don't have to cite each image in its caption and I can save slide space. The following example (per users Marco Daniel and Carsten) is ...
3
votes
2answers
141 views

Using conditionals in tikzset

EDIT Through carelessness, I misrepresented the error that I was getting. I have corrected the example code and my comments. I'd like to be able to setup 1 TikZ node .style altered by conditionals. ...
0
votes
0answers
117 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 ...
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 ...
3
votes
2answers
49 views

Why does this suppress command work when conditionals don't?

I have been exploring different methods of suppressing environment content under some conditionals. The problem with environments is that a lot of the tricks don't work because of how the environment ...
0
votes
1answer
39 views

If value changes for no apparent reason

I am trying to create a horizontal enumeration environment with 3 items per row. As seen in the example the \ifferstitem conditional seems to turn to TRUE from FALSE for no apparent reason (at least ...
1
vote
1answer
111 views

Checking if certain package option is declared inside .sty

I'm writting a package in which the user may choose between three types of documents through declared options when issuing the \usepackage command: undergraduatethesis, technicalreport and ...
4
votes
1answer
142 views

A question on pgfmath, variables, conditionals and scope

First, I would like to apologize for the vague title of my question, somehow I didn't manage to come up with something more precise. Based on an answer to this question, I wanted to create a function ...
1
vote
1answer
73 views

If-statement, using maketitle and titlepage

I've created a new environment using the NewEnviron-package, looking like \NewEnviron{AbstractTitle}{ \twocolumn[ % \maketitle \begin{onecolabstract}\noindent \BODY \end{...
1
vote
3answers
163 views

\newcommand with one or two argument

I am trying to define a shorthand command for making some references faster to write. As of now the best I can do is \newcommand{\apologien}[2]{#1\textit{A} #2} \newcommand{\apo}[1]{\apologien{1}{#1}}...
6
votes
1answer
61 views

Output Content ONLY from a Single Macro

I want a mode where the output consists of ONLY a single macro. In the MWE below, that is the output of \ImportantMacro. All other text outside of this macro is to be ignored. An obvious start to ...
4
votes
2answers
260 views

Using \ifthenelse for setting color of Tikz node

I would like to make use of some shorthand for drawing boxes in Tikz. A minimal working example: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{tikz} \usepackage{xstring} \...
5
votes
1answer
417 views

What is the difference between the two following structures?

First: \def\cs#1#2{00\fi\def\csa{#1}\def\csb{#2} \ifx\csa\csb} \if\cs{...}{...} Second: \def\cs#1#2{\fi\def\csa{#1}\def\csb{#2} \ifx\csa\csb} \if\cs{...}{...} I mean what role does 00 play in this ...
0
votes
1answer
49 views

What is the correct method for conditional printing of variables?

I hope I've used the right terms for my question. I'm working on a template and it has variables which need to be setup by the user. Not all users have the same amount of variables. Users are ...
1
vote
1answer
318 views

if condition in tikz

In the following command definition: \newcommand{\DrawTriangle}[5]{% \begin{tikzpicture}[scale=0.5] \coordinate (A) at (-1.5,-1); \coordinate (C) at (1.5,-1); \coordinate (B) at (1.5,1); \...
1
vote
1answer
61 views

Change section heading conditional on if text follows

I am writing a book with computer projects, My subheadings are numbered and in the format 'Task 1', 'Task 2' etc. The current code in the def file is: \titleformat{\subsection} [hang]% shape {\...