3
votes
0answers
60 views

\if and \fi inside different \def macros

Recently I failed to solve specific task in LaTeX. I wanted to make document with several sections, each divided on several subsections. Each section I had placed to separate files, and used \input ...
13
votes
2answers
163 views

Why does this use of `\expandafter` not work?

I've written the following code: \newif\ifconsecutive \consecutivefalse \newcommand{\myfirst}[1]{#1\consecutivetrue\expandafter\consecutivefalse} \newcommand{\mysecond}[1]{\ifconsecutive ...
20
votes
1answer
122 views

Is implicit `\relax` in conditionals explained anywhere in the TeXbook?

I have been relying for years on TeX's behavior where, say \if1\fi expands to nothing and \if1\else\fi does the same. In the second case TeX inserts an 'implicit' \relax when it tries to expand \else. ...
1
vote
1answer
65 views

Check the value of a pgfkey

I need to be able to check if the value of a pgfkey is empty or not. A solution I have tried (using package etoolbox): \edef\temp{\pgfkeysvalueof{/path/key}}% ...
17
votes
2answers
366 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
91 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 ...
6
votes
2answers
400 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 ...
10
votes
1answer
114 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 ...
8
votes
3answers
194 views

Nested use of \ifcsname needs protection

I have a macro \command to ensure that the names of macros in my documentation are consistently formatted. Been work great, until I had an urge to procrastinate and had this brilliant idea that I can ...
10
votes
3answers
181 views

\expandafter and counters not playing nicely

My google-fu has finally failed me... I'm trying to write a package that will allow you say \addauthor{name, email} several times and have the title page properly formatted. Here is a minimal example ...
7
votes
1answer
115 views

Package providing fully expandable conditionals

Is there a package providing a collection of fully expandable conditionals like this one: \newcommand\myif@num[1] {\ifnum#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} Background: ...
6
votes
2answers
493 views

Nesting of test commands (IfStrEq, IfSubStr etc.) of xstring

The following code does not work: \documentclass{article} \usepackage{xstring} \newcommand\checkempty[1]{ \IfStrEq{#1}{}{% Empty }{% NonEmpty } } \begin{document} ...
6
votes
3answers
190 views

How to “demux” several aspects from a `\foreach` variable with `\ifstrequal`?

How can I "demux" several features from a mode specification given in a \foreach? I would like to use a \foreach to draw several nodes in a TikZ picture. The loop will specify a mode for each ...
24
votes
4answers
2k views

On testing two fully expanded character strings for equality

I know three macros that test two fully expanded character strings for equality: \ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>} (ifthen package) ...
7
votes
1answer
853 views

\newif conditional causing problem in \typeout or \edef

The following code produces result as expected, i.e., False True on the typeset document. \documentclass{minimal} \newif\iftest \newcommand{\test}[2]{ \iftest #1 \else #2 \fi } ...
7
votes
2answers
156 views

How to put a conditional construct in \edef

\ifthenelse works fine normally, but when used in \edef: \documentclass{article} \usepackage{ifthen} \newcommand\testing[1][]{% \edef\tmp{\ifthenelse{\equal{#1}{}}{Blank}{#1}}% } \begin{document} ...
18
votes
2answers
2k views

What does \begingroup\expandafter…\endgroup do?

I often see code of the following form in package implementations (this example is from the LaTeX3 sources): \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname ...