2
votes
1answer
52 views

How to get float numbers as parameter of \newcommand

I have defined a \newcommand function like into this code: \documentclass{scrartcl} \usepackage{pbox,calc} \newcounter{pointsExo} \setcounter{pointsExo}{4} \newcounter{pointsSousTotal} ...
6
votes
1answer
53 views

Conditional based on character following the macro

Basically, I would like to something like \xspace does, i.e. the meaning of the macro should depend on what is following it. So for example if I say \mymacro a it might expand to foo, and if any ...
4
votes
0answers
84 views

Conditionals—do something, if a given command is being used in the document

Is it possible to have a conditional that allow us to do something if a given command is being used in the document? For example for the \part command would be: ...
1
vote
1answer
72 views

Newcommand returning a boolean value

I'm using etoolbox. How can I create a new command that returns a boolean value? For example if I create the following command: \newcommand\ifkeyempty[1]{ \def\novalue{\pgfkeysnovalue}% ...
17
votes
2answers
348 views

Why does this simple \ifx test fail?

This should be easy, but I don't understand why the test below fails... I expected Hurrah! to be printed when the \currentchar count reaches 90 (i.e. the character code of Z). There must be some ...
9
votes
2answers
90 views

Conditionally use package and define command

I'm creating a class which should define a command if some package is available: \IfFileExists{eforms.sty}{ \usepackage[xetex]{eforms} \everyTextField{\textFont{GaramondNo8}\textSize{12}} ...
7
votes
2answers
188 views

math conditionals using (if - else - fi) command

I saw these command when i searching sth. I wonder if we can increase numbers if conditions. it's like if{0} = a, if{1}=b, if{2}=c, if{3}=d etc. \newcommand{mycommand}[1]{ \if{#1 != 0} Some text, ...
11
votes
2answers
162 views

New command with if/then statement conditioned on non-integer number?

In LaTeX, how do I declare a new command that gives different output depending no the result of a test with non-integer numbers? Specifically, I'd like to a command to compare a number with 0.01 (the ...
8
votes
1answer
78 views

Very simple condition in macros

I try to define a macro in LaTeX. This macro should give a different output when I use condition true and false. This does not work: \documentclass{article} \usepackage{lipsum} \newif\ifABC \ifABC ...
12
votes
2answers
169 views

How to test whether the starred-version of a command is defined?

This question is similar to How to conditionally define a new command in LaTeX? but I want to test if the starred version of a command is defined. The naive thing \makeatletter ...
4
votes
1answer
181 views

(x)ifthen in TikZ

I am searching for a way to conditionally handle some items in a TikZ \foreach specially using an \ifthenelse condition. However, the compiler responds ! Undefined control sequence. <argument> ...
7
votes
1answer
139 views

Macros with binary trees as arguments

I would like to have some macros which have binary trees as arguments. For the purpose of these macros, a binary tree is either root or it is {branch1}{branch2} for two binary trees branch1 and ...
5
votes
2answers
83 views

A command which produces index if optional argument is not empty

I would like to define a command which creates an index with a certain name, when i pass the name, and doesn't create any index if there is no name passed. My first idea was to write it like that: ...
21
votes
1answer
414 views

Use of \relax after \ifnum … \fi construction

I'm reading Malcolm Clark's A Plain TeX Primer. On page 111 there's an exercise to define a macro that prints the current time. I've reproduced Clark's answer below: \newcount\minleft ...
8
votes
1answer
84 views

Compare the height of arguments

I'm trying to define a \newcommand with three arguments. I'd like to: compare the height of these arguments choose the largest height to create frames (with that height) around the arguments. ...
11
votes
2answers
157 views

How to create a macro “environmentally-dependent”

Yesterday I was reading the etoolbox documentation where there are defined some new document commands such as: \Before<Begin/End>Environment{<envir>}{<code>} % ...
1
vote
0answers
26 views

Name separators, if condition for same command [duplicate]

I am new to LaTeX, just a Beginner, Basically a perl developer, I have created a .tex file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
6
votes
2answers
91 views

Separators for author group (IF conditon)

I am new to LaTeX, just a beginner, basically a Perl developer. I have created a LaTeX file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
5
votes
1answer
93 views

Any way to set a variable externally?

I just posted a question and can now generate a conditional section in a text: how to make a conditional document feature But to extend and generalize the question, first how could I create a ...
4
votes
2answers
123 views

how to make a conditional document feature

I saw in another question about how to create a condition, of which the best practice recommended was \iftoggle. I want to create a macro that will allow the creation of a teacher's note, a section ...
13
votes
5answers
422 views

Test if the first character of a string is 'a'

Is there an easy way to make a macro returning a string (e.g. 'true') if the string input begins by some fixed character, say 'a' ? I can't figure how to combine the different packages to do this. ...
6
votes
2answers
113 views

Branching construct based on the (babel) language selected

I'd like to keep one of my presentations in German and English and have defined a corresponding boolean variable withifthen and a command to typeset either the German or the English text. Is there ...
7
votes
3answers
134 views

Defining tabular rows with macros using `\ifnum` leads to `Incomplete \ifnum`

I am trying to define tabular rows using a macro which shall perform an conditional definition of the tabular row according to a given parameter. Please consider the following MWE: ...
14
votes
5answers
269 views

A macro that conditionally disregards the need for one of its arguments

Let's suppose I want to write nested equations that contain a fair few nested parenthetical/delimiter characters, like (), [], {}, ||, and perhaps others. Suppose too that I think these things look ...
9
votes
2answers
82 views

How to expand \ifthenelse so that it can be used in \parshape?

How do I get the following MWE to work: \documentclass{article} \usepackage{xifthen} \usepackage{lipsum} \newboolean{bar} \setboolean{bar}{true} \def\foo{\parshape = 2 ...
4
votes
3answers
406 views

Misplaced \omit and \multicolumn in \IfEqCase

I have the following code with a command that creates rows for a tabular: \documentclass[letterpaper,10pt]{article} \usepackage[utf8]{inputenc} \usepackage{xstring} \newcommand*{\condrow}[2]{ ...
17
votes
3answers
790 views

Conditionally Remove Brackets

I'm trying to create a command with an optional argument using \newcommand{\Af}[1]{{\mathbf{A}_{(#1)}} where the argument is a number. However, I'd like that if no argument is given the bracket ...
4
votes
1answer
77 views

Testing for “emptiness” (theoretical consideration)

Consider the following theoretical problem: Sometimes, in LaTeX one wants to do the simple test if a macro is empty, e.g. \def\foo{% This is... \ifx\baz\@empty Sparta! \else a pony farm. \fi } ...
2
votes
1answer
56 views

Conditional based on packageoption

I added a counter to the todonotes packages \todo so I could display the total number of todos I have left. However I also enjoy working with the package option disabled. Therefore I would like to ...
7
votes
2answers
125 views

newcommand conditionals

I am looking to create a command that adjusts my page layout, here is a sample: \newcommand{\margin}{ \pdfpageheight 297mm \pdfpagewidth 210mm \pagebreak \newgeometry{lmargin=31.5mm, rmargin=31.5mm, ...
3
votes
0answers
30 views

Unexpect differences between calling \ifmmode from within a command and outside a command [duplicate]

In answering another question regarding testing for math mode, I proposed the following command \newcommand{\testa}{% \ifmmode ^{12}\text{CO(1-0)}% \else $^{12}$CO(1-0)% \fi } But ...
8
votes
2answers
152 views

Macro with environmental dependent output

I'm trying to develop a macro that gives two different outputs depending on whether it is in math mode (i.e. $ $ or \begin{equation} ... \end{equation}) or anywhere else. The reason is that I use a ...
9
votes
3answers
524 views

Using counters and \ifthen in a macro: what's wrong?

I have (made, actually) a graphic of the forepaw-print of a bear that I want to use as a flourish mark at the end of chapters and a few other places. After finishing with the image, I created a mirror ...
10
votes
2answers
191 views

How to create command that creates new if command?

I want to load parameters (for conditional compilation) from files. I wrote command param that creates new if command and read parameter from file, containing following line: \paramnametrue % or ...
15
votes
3answers
306 views

newcommand does not work with \fi

I tried the command \newcommand{\fistudenti}{\fi} but it seems to work properly only in some cases. Here below there are two insances when it works and when it does not: WORKS: ...
3
votes
2answers
68 views

Replace and add a/to a specific sequence of tokens

Is there a way to find a specific sequence of tokens and add after it a command? Or is there a way to find a specific sequence of tokens and replace it with another one? And do it only if the sequence ...
1
vote
2answers
70 views

Print macro content with condition

I would like something like the following: \documentclass{article} \newcommand{\acell}{} \newcommand{\bcell} \newccomand{\zcell}[1]{#1} \ifx\acell{A} \ifx\bcell{A} \zcell{yes} \else \zcell{no} ...
11
votes
2answers
378 views

Is a TeX macro defined?

I am looking for a way in TeX to check if a macro was defined. Currently I use a rather tangled way. I exploit a sort of side effect when comparing two macros via \ifx; this command returns: true, ...
6
votes
2answers
303 views

Expand command read from file

I have a file, that contains a list of latex commands each command per line. Now I want to read this file line per line and execute/expand the macros automatically. I tried the following but this only ...
0
votes
0answers
44 views

How to test if an command is empty {}? [duplicate]

I used \newcommand* foo {} to define a command so the user could set it later via \renewcommand* foo {content}. How do I create a conditional statement (if then else) that tests if foo is empty ("{}") ...
12
votes
1answer
166 views

Simple way to switch inline asymptote figures on and off

I use the inline asymptote environment \begin{asy} to draw a lot of the figures in my papers. To those not familiar with asymptote, the asymptote package creates *.asy files for each of the asy ...
9
votes
1answer
107 views

Expandable, very specific keyval processing

I am having a hard time trying to come up with an fully expandable keyval parsing macro which deals only with specific keys/values. I wouldn't even attempt this in full generality, that's way beyond ...
7
votes
2answers
142 views

Negating \ifeof

Trying to typeset lines from a file: \openin0=MyFile \loop \read0to\linein \linein \ifeof0 % Fails here \repeat Clearly, I want to test for not \ifeof, but I don't see a boolean ...
8
votes
3answers
147 views

xstring command in renewcommand

I'm trying renew \texttt command with condition on ending . or ,. But after making this: \usepackage{xstring} \let\OldTexttt\texttt \renewcommand{\texttt}[1]{% \OldTexttt{\hspace{0.4em}#1}% ...
16
votes
2answers
847 views

Difference between \newbool and \newtoggle from etoolbox package

Paul Gaborit's answer to How to detect if option provided via \tikzset uses \newbool to define a new boolean \booltrue to set a boolean, and \ifbool to perform a conditional operation all from ...
12
votes
3answers
239 views

Gobbling an argument if it starts with #

My problem comes from pandoc and markdown, but it is not directly related with these tools, but instead with "customizing" the resulting pdf via some tex macro programming, so I think it is on topic. ...
6
votes
1answer
542 views

Applying condition around \intertext and \shortintertext leaves excess vertical space

When I try to make either \intertext or \shortintertext conditional I get excess vertical spacing prior to the conditional text as per the MWE below. Note the excess vertical spacing prior to "Albert ...
7
votes
1answer
174 views

How to detect that some macro expands to empty string or spaces only?

I need to check several macros and do some actions only if their expansion is not empty nor space only. In pseudo code I would look like this \if\macroToBeTested \doSomething ...
6
votes
2answers
148 views

Is “conditionals” name of package?

In some package I have seen construct like this one: \if\blank{\myMacro}% %do something \else %do something else \fi I like it and I want to use it to test if call to a macro has empty result. ...
5
votes
1answer
93 views

\IfSubStr does not work when used as parameter of another macro

It seem that if macro \IfSubStr from package xstring is used as parameter it is not expanded like other macros are. Here is minimal demonstration: \usepackage{xstring} \newcommand{\copyArg}[1]{#1} ...