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
455 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 ...
0
votes
1answer
261 views

Undefined control sequence \iftoggle

As an extension to file ended while scanning use of \path, I tried using path with \iftoggle from etoolbox package. Below is the error I get File ended while scanning use of \etb@tgl@BuildC. Here ...
0
votes
1answer
240 views

''automatic'' header for one-section chapter

I am writing my master final work in LaTeXusing memoir class. For the header/footer I am using fancyhdr with the code \pagestyle{fancy} \renewcommand{\chaptermark}[1]{\markboth{#1}{}} \fancyhf{} \...
0
votes
1answer
50 views

How to change the way a counter is presented based on its value?

I need an environment where the way the counter of the environment is presented changes according with the value of the counter. If the counter is less then 10 it must be succeeded by the ordinal mark ...
0
votes
1answer
20 views

Make Eqns inside Conditional Bigger

The code below works, but when LaTex generates the equations, the equations are small and appear "scrunched". How can this code be modified s.t. the equations are at least as big as the term $F(x)$ in ...
0
votes
2answers
103 views

\IfStrEqCase issue using \csname

I want to use \csname inside \IfStrEqCase but I have an error. Here is my code: \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} \usepackage[brazil]{babel} \usepackage[T1]{...
0
votes
2answers
157 views

Circle individual item in list dependent on boolean

Is there a way to create an enumerated list which has an item that will be circled when toggling a boolean? I'd like to use it for creating multiple-choice tests and the solution key.
0
votes
1answer
68 views

Conditional branch with \ifinner and Spacing in higher derivative (2 independent questions) [duplicate]

I made some macros shown below, which outputs ordinary/partial derivative. I was checking whether they work as I expected, and found that \dif{y}{x} expands to \tfrac{\difd y}{\difd x} in align ...
0
votes
1answer
948 views

Switch between different output versions compiled from the same LaTeX source [duplicate]

For programming in C, it is quite common to switch between creating debug- and release-versions by passing a command line argument to the compiler. I would like to have something similar for pdflatex....
0
votes
1answer
56 views

Make macro which checks the type of math mode its in [duplicate]

I frequently find that I want to make a macro, say a derivative macro for example with the following syntax: \def\dd #1;#2;{ return... } However, I want it to check if it is inline math such as when ...
0
votes
1answer
388 views

Showing/Hiding verbatim environment based on boolean condition

I would like to show and hide a verbatim or spverbatim environment based on a boolean condition (sth. like \showenv). I tried the solutions proposed at Hide custom environment content based on boolean,...
0
votes
2answers
2k views

How to number a conditional equation

I am writing the following syntax to get a conditional equation. But the equation is not numbered. How can I number it? \[ f(x) = \begin{cases} x+7 & \text{if $5< x$}; \\ x^2-3 & \text{if ...
0
votes
1answer
35 views

Test if one of two macros not empty

I define two new macros and commands to change their content with the following commands in a .cls-file. \newcommand{\@mymacroa}{} \newcommand{\mymacroa}[1]{\renewcommand{\@mymacroa}{#1}} \newcommand{...
0
votes
1answer
49 views

Switch condition (IfStrEqCase) - no match & use inside pgfplot axis

I am trying to learn how to use switch conditions to apply in a document I am creating that contains plots. Here is an extract to create a MWE : \documentclass[border=2pt]{standalone} \usepackage[...
0
votes
1answer
42 views

Beamer footer shifted by adding an \if… \fi test

Ok --- I am getting crazy about this (I can workaround it, but I really would like to know what's happening). Consider this MWE copied almost straight from this answer: \documentclass{beamer} \...
0
votes
1answer
39 views

embedded command resulting in argument of \equal has extra } error

I am trying to make a macro (\ls) which will convert keywords into the mathmode version of their equivalent logic symbol. I've figured a way to make this work fine, except when it is in an argument of ...
0
votes
1answer
48 views

Use multi ifthenelse equal text

In the question Use xifthen: how set \cnttest not equal number, I learnt how to perform if-then-else tests where the condition compares two integers. Now, I would like to do the same, but with string ...
0
votes
1answer
31 views

How to format text based on a logical statement that reads in a value from a csv?

Background Hello, and thanks in advance for any insights you all can offer! Sorry for the very long post, but I noticed most new users are chastised for not sharing enough context. The TLDR version ...
0
votes
1answer
29 views

Equivalent of \iftotalfigures for xequations

To print my lists only when there are references I use the following syntax: % List of figures \iftotalfigures\listoffigures\fi % List of tables \iftotaltables\listoftables\fi Now I would like to ...
0
votes
2answers
63 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. \...
0
votes
1answer
37 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
1answer
28 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
1answer
29 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
1answer
97 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 ...
0
votes
1answer
51 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 }} \...
0
votes
1answer
312 views

Simple ifthenelse fails when included in a command

I have this test case for \ifthenelse which works as expected when I put it directly in my document \ifthenelse{\equal{x}{y}}{XXX}{YYY} If I put this in the definition of a new command, it still ...
0
votes
1answer
555 views

[no file]:72: Missing \endcsname inserted. [}]

friends! I'm having a problem in latex with the following error. I do not know how to navigate this error and where the actual problem is. What is the meaning of [no file]:72 in error? Any help would ...
0
votes
1answer
275 views

Include optional text versions within one file [closed]

I'm still new to LaTeX and I'm not sure if this can be done, so here goes: I've got two .tex files, there pretty similar and instead of updating them individually, which as got to be a pain. I want ...
0
votes
1answer
58 views

Using \let to change the argument of a a \newif command

I want to be able to switch mid-document between writing indices as subscripts vs within parens, e.g., x_t vs x(t). I've written some code to do this, see below. Everything is conditioned on the ...
0
votes
1answer
236 views

Compile \showtrue and \showfalse to different target files

I'm writing a problem set with a solution. Right now I have the following setup: \newtheorem*{sol}{Solution} \newif\ifshow \showfalse \ifshow \newenvironment{bluesol} {\begin{sol} \color{...
0
votes
1answer
251 views

Conditionally prepend text to chapter title in TOC

I want to prepend some text to chapter titles on the TOC according to certain conditions. For example (this doesn't work): \documentclass[letterpaper,openany,oneside]{book} \usepackage[spanish]{babel}...
0
votes
1answer
117 views

Command (using \ifthenelse) within 2nd optional (post) argument of footcite

I have defined a new command \mypageref to reference page numbers of text parts in my appendix. The begin of such a text part is labeled, e.g., by \label{text_begin}, and the end of the text part is ...
0
votes
1answer
783 views

conditional commands in .sty file, conditional on \documentclass [duplicate]

Possible Duplicate: Which document class is being used? I'd like to include conditional formatting in a .sty file, conditional on the document class of the document that invokes it. For example, ...
0
votes
1answer
49 views

Check whether a command from package is used and modify the style

I am trying to create a pagestyle, where \guideNameA is mandatory and if \guideNameB is used then I want modify the page style accordingly. Also I need to modify the document content by checking ...
0
votes
0answers
27 views

Show underlines in view mode, but omit when printing?

I would like to know if there is a way I could display URLs with underlines when being viewed in a PDF, but to omit them when printing. I saw the following code example from this answer: \usepackage{...
0
votes
0answers
20 views

Loop for each 3 rows with condition

Continues Old topic: algorithm Logic: Make Loop for each 3 rows in datatools I use this code with ifthenelse: If No = A/B/C, insert page A/B/C but result do not display in order of rows in file ...
0
votes
0answers
13 views

Include a standalone .tex file (which contains two languages) partially (one language or the other)

I am going to collect questions from faculty members written in two languages and combine them in a single main.tex exam file. I have created a sample main.tex file as follows: \documentclass{...
0
votes
0answers
31 views

Bug in tex iffalse and syntex

I had some code in the preamble that used \iffalse to hide it... I was noticing that every time I'd use synctex winedt would jump to the wrong position but I didn't understand why. I later removed the ...
0
votes
1answer
46 views

Check figure placement with \if statement

I would like to add a \noindent before a new paragraph but only if a floating figure is placed directly above it. How can I check this using an \if-statement? So looking at the example below I don'...
0
votes
1answer
39 views

If I need different answer choices based on question number, can that be automated

I asked a question relating to this but I did not have a working example. Here is the original post is-there-a-way-to-alternate-answer-choices-based-on-the-question-number-act-st . To summarize I ...
0
votes
0answers
24 views

Is it possible to format cells in a pgfplotstable based on values in another pgfplotstable?

Background This question is very similar to another question that I asked earlier concerning how to format text based on the values of a csv. The corresponding answer allowed me to read in a ...
0
votes
0answers
24 views

`\iffmode` fails for first token in matrix cells [duplicate]

\iffmode seems to fail for the first token in every matrix cell. Here is a minimal working example. \documentclass[margin=5mm]{standalone} \usepackage{mathtools} \newcommand{\foo}{% \ifmmode A% ...
0
votes
0answers
17 views

Optional Sections in a Document - passing parameters to latexmk or pdflatex [duplicate]

I want to define optional sections for the same document. My plan is to define something like the following command: \optional[audienceA,audienceB]{ % my latex content } so that i can pass a flag ...
0
votes
0answers
39 views

I want to detect an order placed at the beginning of each theorem

I want to detect an order placed at the beginning of each theorem. \documentclass{article} \usepackage{ifthen,ntheorem} \newtheorem{ex}{Exam} \begin{document} \begin{ex} \LaTeX{} There is the LaTeX ...
0
votes
0answers
195 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[...
0
votes
0answers
57 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} \...
0
votes
0answers
39 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 ...
0
votes
0answers
38 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) ...
0
votes
0answers
22 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
34 views

Write text only if Execute Metadata is not empty

I use the catchfilebetweentags package to get specific content from a common .tex file. MWE for the file where all content is stored (called master.tex): \documentclass[]{article} \usepackage{...