Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [expansion]

{expansion} is about expanding tokens, including the manipulation of expansion order and the suppressing of expansion.

5
votes
1answer
56 views

xkeyval — read keys from file

I want to read xkeyval options from an external file, like: \setkeys{my@keys}{\input{conf}} I tried several combinations of \edef and \expandafter, but to no avail. Any ideas? Best regards, ...
4
votes
2answers
99 views

Different macro behavior when used in another macro

Please consider the following MWE : \documentclass{article} \newcommand{\mymargin}{\hspace*{3em}} \newcommand{\innerbox}[1]{\mymargin\fbox{#1}\mymargin} \newcommand{\outerbox}[1]{\fbox{#1}} \begin{...
3
votes
2answers
41 views

how to pass xkeyval cmdkey to macro

I want to pass a cmdkey from the xkeyval package to a macro. I can print the value of the cmdkey to a message, but when used with \in@ it seems to be unexpanded. Example below. I expect to see the ...
1
vote
1answer
29 views

Problem with expand, all restatable theorems points to the same theorem

I'm trying to manually do a small script that let me put proofs at the end, restate theorem... But I'm having some troubles with the restate, because all the theorems have the same name, so when I ...
2
votes
1answer
25 views

`\unexpand\expandafter` add spaces : how to append a text at the end of a file

I'd like to append code to a file containing latex code... So I tried the solution proposed here, but unfortunately it fails when there are backslash in the file: How can I open a file in "append&...
0
votes
1answer
64 views

practical use of `\noexpand` outside`\edef`(`\xdef`) and `\write`(`\messge`)?

After reading (and searching through) TeXbyTopic.pdf I have the impression that practical use of \noexpand falls into one of the following three cases, Inside \edef or \xdef, including the cases ...
1
vote
1answer
111 views

How to expand a \macro (or a copy) to save in a list at end of environment in xparse (expl3)?

I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3. I have defined a one command and two environments and I have had a problem with one of them. I use the ...
1
vote
1answer
37 views

Definition before \multicolumn or the like?

Is it possible to have definitions take effect at the beginning of the first cell of a tabular row (using array.sty, if relevant), and still leave room for \multicolumn, \hline, etc.? The problem is, ...
7
votes
1answer
48 views

Use of \noexpand in the implementation of \TextOrMath for eTeX

In latexrelease 2015/01/01, there are two implementations of \TextOrMath: one for regular TeX, the other one for eTeX-like engines (more precisely: those which support \protected). My question ...
3
votes
3answers
77 views

Check if a point is right or left of another one in TikZ

Trying to implement a handy way to check if a TikZ point is right or left of another one, I came up with the following MWE. \documentclass[border=1mm, tikz]{standalone} \makeatletter % prints 1 if #...
7
votes
2answers
149 views

Create test of text direction (luatex)

With luatex there is \textdir to change text direction and tex.textdir which give string representing text direction. I have created this macro to test text direction which supposedly gives TLT ...
0
votes
0answers
54 views

Expand one more time as needed? To compose with a macro that requires a maximally expanded argument?

Consider the case below as a minimal example. But the questions concerns understanding nonfragile composition of macros each which parse using something like xparse. (code below thanks to egreg) \...
1
vote
0answers
27 views

Arguments stops being evaluated inside tikz node [closed]

In the following example, the code \textwidth-1mm is "evaluated" in the first page, but on the second page (where I add a node around it), the text is not evaluated anymore and I can see a bit -1mm in ...
2
votes
2answers
31 views

Using macros in \pgfkeys command

Is there a general way to pass a <key list> contained inside a macro to the \pgfkeys command, in order to process it in the usual way? In simple examples, \expandafter helps but I do not really ...
0
votes
1answer
44 views

Expansion of macro in environment argument

I'd like to generate an environment that changes a bit according to an argument given for it. The reason is having different locales in the document. I have defined a command, EmitLanguageStr that ...
3
votes
2answers
140 views

How to implement \expandbefore, similarly to \expandafter?

I am trying to define a new command, but specifying the new control string "on the fly" using csname and endcsname. (This is for the purpose of implementing a dependency injection pattern.) **...
5
votes
3answers
95 views

Macro expansion inside \href

I want to make a shortcut for \href{tel:0123456789}{01\,23\,45\,67\,89} I can use \StrSubstitute from the xstring package as \StrSubstitute{01 23 45 67 89}{ }{\,} inside the second argument to ...
0
votes
0answers
22 views

New command and catcode [duplicate]

I have a command that may contain the ampersand charater: &. Sometimes, when I use this command, I want that ampersand interpreted as a space. This is why I wanted to use the TeX command \catcode. ...
1
vote
0answers
77 views

Creating a custom node shape with a variable number of anchors

For the sake of training my self on PGF, I want to create such node shape having multiply ports with a selecting switch as shown below This is my attempt to create this node for a particular number ...
3
votes
1answer
43 views

Assigning a value from xstring

I'm trying to write some basic validation of user input to a command \noinsuit which takes two parameters, an integer in [0, 13] and a letter indicating the suit. So I expect \noinsuit{1}{C} to be ...
7
votes
2answers
95 views

Problem with my understanding of expandafter and newcommand with arguments and sout

I've tried for days to get my head around the expansion of code. Sadly, I don't get it. I try to pass a command with arguments as an argument to sout. \documentclass{article} \usepackage{ulem,lipsum}...
3
votes
1answer
47 views

Macro expansion in TikZ node

I am having some problems with macro expansion in TikZ nodes. The MWE below is supposed to draw nodes at specified coordinates and display their coordinate rounded to the nearest number, but it shows ...
1
vote
1answer
41 views

Set length parameter based on KOMA \ifthispageodd

Background I'm using scrrept and titlesec (changing from titlesec to pure koma is on my todo list) any I've redefined \chapter to be a full page affair. The issue is when I'm using twosided. ...
6
votes
2answers
110 views

ConTeXt does not load png file given by lua code

This is my code: \defineexpandable[1]\background{ \directlua{ local cases = { "noise-blue.png", "noise-yellow.png", "noise-red.png", "noise-green.png" } tex....
3
votes
1answer
41 views

Remove math mode in macro defined text

I would like to remove the math mode in a text that is not defined directly, but in a macro. Here is my code: \documentclass{book} \begingroup \lccode`\~=`$ \lowercase{\endgroup \def~#1~{\...
1
vote
1answer
46 views

Check if the macro expands to undefined

MWE: \documentclass{article} \usepackage{clefval} \begin{document} \TheKey{test}{zez} \def\mymacro{\TheValue{test}} \makeatletter \ifdefined\V@test \mymacro \else empty \fi \ifdefined\mymacro \...
0
votes
1answer
37 views

Problem calling \creflabelformat from a command

I'm using the cleveref package with some customizations, using \creflabelformat. Because cleveref should be the last package to load, and because the customization commands should come after cleveref ...
1
vote
2answers
33 views

forcsvlist to use the expanded result of another forcsvlist

My problem is, that I have a list of authors, that I use at several places for several things. For example I would like to generate an Author's index. In the code below I would like to "rework" the ...
7
votes
3answers
532 views

Who ate my space? (How to stop \exp_args:Nf from consuming a space?)

I have a macro that uses \prg_replicate:nn to produce a number of spaces, then pass those spaces, after f-expanding \prg_replicate:nn, to another macro. The problem is that when I use \exp_args:Nf, it ...
9
votes
2answers
536 views

Is there a list of expandable TeX primitives? LaTeX? e-TeX? others?

According to Christian Hupfer's comment I understood that calculations are possible in a keyval list when the macro is expandable. The macro \numexpr being expandable, calculations are possible. ...
3
votes
1answer
177 views

Check if macro is fully expandable

Question Is there a way to check whether a macro is fully expandable (or rather "safe in an expansion-only context" [1])? Consider this code: \def\a{Just a string} \def\b{\a} \def\c{\def\unsafe} \...
1
vote
1answer
42 views

Prevent macro expansion within setbox

Following code is the quintessence of a problem i'm facing: \documentclass{minimal} \newbox\boxa \newbox\boxb \newbox\boxc \parindent=0pt \begin{document} \setbox\boxc\hbox{Hello World!} \def\...
2
votes
1answer
101 views

Using exam question counter as an argument

I am trying to use the exam class to create a study guide for my students that has all of the answers at the end of the document. I would like to have the answers automatically labeled by question ...
3
votes
4answers
217 views

Expanding macro twice

How would you expand a macro twice in LaTeX 2 (or 2epsilon). I am aware of the question What is the preferred way of expanding twice in expl3?, but I'm curious as to how you'd do it in LaTeX. I'd ...
15
votes
2answers
500 views

Passing arguments to a macro hidden in the text

Context: I'm trying to write a macro that behaves somewhat like C's printf family of functions. For instance, the following C code: #include <stdio.h> int main() { printf("Hello %s! Today'...
11
votes
3answers
336 views

Expanding macro defined by \csdef to define a style via \tikzset

I need to store tikz option in a \csdef{}: \csdef{My Node Option}{draw=red, thick, fill=yellow} How do I use this definition to define a style via \tikzset? I attempted to use .expand once as per ...
1
vote
2answers
51 views

Storing options for pgfkeys inside macro

I want to define some options as a list of key-value pairs inside a macro and use that macro inside a command that takes pgfkeys-style options. Here is a MWE: \documentclass{standalone} \usepackage{...
4
votes
2answers
126 views

Formatting phonenumbers with phonenumber-package and macros as argument (expand-problem)

I try to use the phonenumbers-package to format phonenumbers. As argument I want to use a macro (in the actual document the macro will be defined with pgfkeys!) What I tried so far: \documentclass{...
2
votes
1answer
29 views

\centering leads to cascade of errors

Context: I'm developing a title page (writing my own titlepage environment) and I'm writing my own \thanks command (to give me control over where I spew the footnotes). Not knowing how \footnote does ...
0
votes
1answer
41 views

Protect fragile variable in file path. Case of \ifthenelse in \includegraphics{}

In this script: \documentclass{article} \usepackage{ifthen} \usepackage{graphicx} \newcommand{\myfigure}[1]{% ...
9
votes
2answers
245 views

What is the difference between \unexpanded and \protected in ConTeXt?

EDIT: It turns out that \unexpanded in ConTeXt is different from \unexpanded in ε-TeX, so the earlier description doesn't apply. I'll update the question accordingly. From the ε-TeX manual: ...
2
votes
1answer
32 views

using commands in pgfkeys not working

The following latex code works as expected. It allows to draw a line parallel to the z axis: \documentclass[border=10pt]{standalone} \usepackage{tikz} \begin{document} \tikzset{ parallel to z axis/....
2
votes
1answer
43 views

How to protect a fragile command in a moving argument? The case of macro containing \ifthenelse in \caption

This script works as expected: \documentclass{article} \usepackage{ifthen} \usepackage{graphicx} \newcommand{\foo}[1]{ \newcommand{\capt}{ \ifthenelse{\equal{#1}{ORIG}} {original}...
2
votes
1answer
81 views

“Missing \endcsname inserted” error after \expandafter chain

Solved Thanks to @PhelypeOleinik for the solution! And thanks to everyone else who responded so quickly to provide assistance. For anyone who finds this post in the future, the error really had ...
0
votes
0answers
39 views

Weird \hfill behavior with custom length calculations?

I asked a question earlier about trying to write a macro/environment that would take in a number of \choice commands and then write them out in a way to minimize vertical space consumed, but still ...
1
vote
1answer
63 views

passing a parameter to nested macro inside caption

I'm having a really hard time understanding this error in a massive document. I took the time to work out a "minimal example", so I could post the error with precision. Please, when trying to answer, ...
6
votes
2answers
104 views

What are the values for parameters of an \edef at the time of definition?

Suppose we have the following short document \documentclass{article} \def\foo#1{\if#1XX\else not X\fi} \edef\bar#1{\if#1XX\else not X\fi} \begin{document} foo: X = \foo{X}, Y = \foo{Y} bar: X = \...
3
votes
1answer
62 views

How to expand pgfkeys value when the key path contains macros?

This question represents a second, more simplified, attempt at a problem I asked about some time ago but for which I received no answer. In short, I need to put the fully expanded result of a call to ...
0
votes
1answer
35 views

Avoid expansion of `\marginpar` argument

I'm trying to make a margin par that will show the value of some macro defined after the placement point of the marginpar (think of it as something like \footnotemark vs \footnotetext). However, the \...
4
votes
3answers
117 views

Trying to get \zap@space and \lowercase to work on string comparison

I am trying to do a non-case-sensitive check on two strings that may or may not have spaces in them. I have googled this and there is quite a lot of literature on either of these problems, but I can't ...