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

Test whether a string is in a list with variable

Based on this question, I'd like the following \newcommand{\word}{Paul} \newcommand{\butnot}{Joe} \IfStringInList{\word}{George,John,Paul,Ringo}{Beat it}{Roll it} \IfStringInList{\butnot}{George,John,...
1
vote
1answer
49 views

Conditional compilation depending on the compiler (LuaLaTeX/PdfLaTeX)

I am using plantuml package, which requires LuaLaTeX, but it takes a lot of time to build every time all figures. For that reason I prefer to make a dry run (to get only the pure LaTeX outcom), but ...
1
vote
1answer
49 views

Tables: Cell Color based on content / conditional cell coloring

I want a table to have red or green cell color, depending on the content: If the content is "a", make it green, if it is "b", make it red. BUT if the content is something else (e.g. in the column ...
0
votes
0answers
98 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[...
4
votes
2answers
133 views

Colouring column values based on a specific condition. How could I do this?

I am generating a big-table from a csv file using the latex code as given below. \documentclass{article} \usepackage{booktabs} \usepackage{csvsimple} \usepackage{caption} \usepackage{longtable} \...
4
votes
1answer
83 views

Seemingly unused \edef prior to an \ifx mysteriously affects the outcome of the \ifx. Why?

It is my understanding that in \ifx\x\y xx \else yy \fi, \ifx does NOT expand its arguments. If you want \ifx to compare the expanded values of \x and \y, then we need to do the expansion ourselves ...
2
votes
2answers
103 views

How to conditionally draw parts of a MetaPost drawing in ConTeXt?

The basis of my problem is I am making a 14x14 crossword puzzle, I have the data for each of the 196 cells from an outside document, but need only the cells with text inside to have borders. I tried ...
0
votes
2answers
35 views

combining ifthen with FPeval - problem

if i use \FPeval{\one}{\csname test1\endcsname} everything is fine. If i use \FPeval{\one}{\csname test1\endcsname+\csname test2\endcsname} in \ifthenelse, then i get en error. \...
2
votes
1answer
101 views

Conditionally add options to tcolorbox highlight math style

I have defined the following package: % Configuration \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{eqbox}[2018/01/01 Boxed Equations] \RequirePackage{xcolor} \RequirePackage{pgfopts} \...
2
votes
3answers
76 views

\ifthenelse do nothing

I want to define a table as command. Some lines schould only be printed, if there is a value for it. Because of that I am using the \ifthenelse command. Example: \begin{tabularx}{\linewidth}{|l|X|} ...
2
votes
1answer
26 views

Problem with stored values, macro options, and interaction with other package

Apologies for the rather general title, while trying to sort out a very specific problem: I'm trying to enhance the framework that Alan Munn provided here to represent naturally occurring discourse (...
1
vote
1answer
42 views

Reset stored values at pagebreaks and environment boundaries

Based on this question, I have created a simple macro that prints and stores its argument, and if it is issued again with the identical argument it prints nothing: % !TEX TS-program = xelatexmk \...
1
vote
1answer
21 views

Embedding if statements in environments

I am trying to write an environment so that I can toggle on and off the answers to questions on a hand out. I also want the answers to appear red and then the main text go back to black after the ...
2
votes
1answer
48 views

Extra blank page is at end of the pdf when use vertical text using tikz

I need some text in the left and right side of the pdf vertically so I use the following code but an extra blank page appears and end please help. \documentclass[twoside]{article} \usepackage{lipsum} ...
1
vote
0answers
43 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 ...
2
votes
1answer
53 views

How to make custom definition command without numbering?

I have the following \definition command/theorem (I don't really know much about LaTeX): \newtheoremstyle{definition} {0.8cm} {0.8cm} {} {0.4cm} {\bfseries} {.} {0.4cm} {} \...
2
votes
1answer
42 views

Exclamation mark around variable

What does the exclamation marks (!) around the \@subheader command do in the following? \renewcommand\maketitle{ ... \if!\@subheader!\else\noindent{\trfont{\@subheader}}\fi ... } Can someone please ...
3
votes
0answers
51 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 ...
2
votes
2answers
137 views

Detecting subscript in command argument

I have defined a command low that adds a subscript to an argument: \newcommand{\low}[1]{{#1}_{l_{\mathcal{A}}}} However, if the argument of low contains subscripts itsself (for example in the case ...
1
vote
1answer
40 views

XeLaTeX + \ifthenelse:

I use XelaTeX to produce my CV. Currently, I want to update it and have both Slovak and English CV within one document. I want to have all strings of one language grouped in the preamble, same for ...
5
votes
1answer
133 views

How to compare a string to a cs from a read properly?

The scenario: reading a date in a yyyy-mm-dd form from a file to a cs. This cs later gets compared to a 'current date' macro to write a few args in a specific way to an external file. The current day ...
1
vote
1answer
25 views

How to write if else condition for vertical spacing in newenvironment

I have defined an environment as follows. I would like to have a modification where, it does not add white vertical space if no arguments are provided. \documentclass[10]{article} \usepackage[a4paper,...
1
vote
2answers
259 views

Transpose a matrix and parenthesis

I would like to define a command transp having eventually one argument : the name of the matrix and finally two outputs. \transp{A} is the matrix A^T between parenthesis, \transp A is just the ...
3
votes
1answer
59 views

How to properly use new options into \pgfdeclareshape of makeshape package

I'm tryng to make new shapes with the help of makeshape package, and I'm having a lot of problems with new options. Here, an example: \makeatletter \def\pgf@izquierda{izquierda} \def\...
5
votes
2answers
77 views

filecontents: select rows of group to display

I have a file that contains 1,000 rows of product data. I want to select only a specific product type to print in my document. Minimal code in main.tex: \documentclass{article} \usepackage{...
1
vote
0answers
45 views

What is the TeX at symbol / @ for? [duplicate]

Edit Note: I am trying to research "switches" (like \chapter), which led to this question. It might be helpful to tag this "switches". I have seen a lot of documentation that appears to be using ...
0
votes
2answers
53 views

Code seems to have no effect when inside `iftoggle`

In this answer I have been suggested to patch hyperref’s automatic pdfauthor metadata handling mechanism as follows. The goal is to have PDF metadata work with authblk and multiple authors. \...
2
votes
1answer
59 views

Conditional output dependent on --shell-escape option value

I would like to print the git revision of the document with the latexgit package, which requires the --shell-escape option to work. As this feature is very optional for building the document, I would ...
0
votes
0answers
32 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} \...
4
votes
1answer
96 views

Is there latex3 work being done on a boolean case statement?

Various languages have constructs like select; when <expression 1> then <action 1>; when <expression 2> then <action 2>; ... when <expression n> ...
6
votes
1answer
129 views

How to save boolean values into the aux file? (using e.g. etoolbox's toogles)

I want to use etoolbox's toggles to achieve the following: In the preamble a toggle is created, during typesetting the document its value might change and at the end I want to write the value to the ...
4
votes
1answer
59 views

Auto append prefix to tcolorbox's title

I would like to have a tcolorbox environment that appends the prefix "Note:" to the given title. Thus, using the option title={My Title} to this environment would produce a title of Note: My ...
1
vote
2answers
109 views

Use of graphicspath in class

I am using my own class MyReportClass to write a report. I have taken inspiration from this answer to redefine the \includegraphics command inside the class in order to use the example-image-a in case ...
0
votes
0answers
34 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 ...
3
votes
0answers
144 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 ...
1
vote
3answers
103 views

@nameuse with value \relax in conditionals

This is a follow-up to this question: @nameuse as conditional where i asked about how to use \expandafter if i combine \@nameuse with \ifx. However, in my real-life example, i use \relax as a default ...
3
votes
2answers
144 views

@nameuse as conditional

Please consider the following, non-working, example: \documentclass{standalone} \makeatletter \parindent\z@ \@namedef{blafasel}{foo} \def\foo{foo} \def\bar{bar} \makeatother \begin{document}...
3
votes
2answers
51 views

Defining a command part by part

Let's say we have a command \foo with 1 argument. Can we produce a command \setfoo{aaa}{<some thing>} which redefines \foo to: if an argument of \foois equal to 'aaa', do ; otherwise do what \...
0
votes
0answers
25 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) ...
3
votes
1answer
79 views

Node label switching on condition

I try to create a dynamic graph where a node move along the axis line. When a condition on x is filled (X>1.8), I need the labels to be translated as i tried to do it in the following MWE \...
3
votes
1answer
80 views

Lost global definition after \ifthenelse using package xifthen

I created my MWE with the help of this Q&A. MWE: \documentclass{article} \usepackage{xifthen}% provides \isempty test \newcommand{\GlobalDef}[1][]{ % \ifthenelse{\isempty{#1}} % {} % ...
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
29 views

In LaTeX is there good way to optionally redact certain sections of a document? [duplicate]

I have a project which compiles a document written in LaTeX, compiled to PDF with xelatex. I would like to automatically produce 2 versions of the document: A "confidential" version which all ...
4
votes
2answers
244 views

csvsimple vs. conditional row coloring

I've a CSV file what I want process with csvsimple. My desire is to color some rows based on a conditional (one specified column has bigger value). Here is an MWE: \documentclass[12pt]{article} \...
4
votes
1answer
179 views

How to add conditions in LATEX macros?

I would like to create custom macros with conditions. For example, I would like to add an "if-condition" to a macro that I created to write derivatives of any order in relation to a single variable. ...
2
votes
1answer
49 views

Question: Something's wrong--perhaps a missing \item

My code is as following: \begin{denotation} \iffalse \item[符号1] 解释1 \item[符号2] 解释2 \fi \end{denotation} I have \item in my code. What's the real problem?
1
vote
1answer
27 views

How do I only call \maketitle if \title{} has been called

I'm merging 5-10 pandoc generated tex files using the docmute package. The individual files build, however when I \subimport or \input them into my main document I get an error: ! LaTeX Error: No \...
0
votes
1answer
54 views

Change theorem color using theorem notes in the amsthm package

When defining a new theorem style in the amsthm package, you can specify what's called (according to http://web.mat.bham.ac.uk/R.W.Kaye/latex/thm.pdf) a custom head specification. In there, you can ...
0
votes
2answers
77 views

How to have “preprocessor” flags in LaTeX [duplicate]

C programmers often use constructs like #ifdef foo printf("foo is defined "); #endif #ifndef foo printf("foo is not defined "); #endif to select certain code-paths during the compilation ...
4
votes
2answers
23 views

Conditional within align environment not resolving

I try to use a shortcut for setting matrices with different brackets. My solution works fine in displaymath and equation environments. However, as soon as I try to use it within align, there is an ...