3

Since I haven't given up on my problem from yesterday, I've been messing around with \edef, \def, \unexpanded, \expandafter and some other stuff. I also read about fragile commands and robust commands. As far as I can see, a robust command gives the same result anywhere in the document, contrary to fragile commands, which depend on context (therefore \chapter must be fragile).

Now I read, that \edef doesn't execute \defs. But how can I expand and force the execution of a \def.

example:

\def\any{content}
\def\changeAny#1{\def\any{#1}}
\def\textA{text}
\edef{\changeAny{otherContent} \textA}

This will break because edef will expand to

\edef\foo{\def\any{otherContent} text}

will expand to

\edef\foo{\def content{otherContent} text}

this causes \inaccessible-error after \def


Additional info:

I also experimented with flag replacement:

%existing fragile
\def\fragileCommand{original Content\\ of fragile}

\def\flag{\unexpanded{\flag}}
\let\fragileCommand\flag
\edef\texty{blabla \fragileCommand blabla}
\def\fragileCommand{original Content\\ of fragile}

\texty

That prevented from breaking, but didn't give (always) the desired result.

29
  • 3
    This feels like an 'X-Y' problem: what is the actual problem to solve?
    – Joseph Wright
    Commented May 25, 2016 at 14:21
  • 1
    @MaestroGlanz 'You can't' : \edef performs expansion not execution. In the same way, \expandafter\foo\def... doesn't do anything (as \def is not expandable).
    – Joseph Wright
    Commented May 25, 2016 at 14:28
  • 2
    @MaestroGlanz We still don't know what do you want to achieve. This is like asking if we can transform gravity to repel objects: no, we can't, but why on earth would you want that? Please, add that info to the question, and we will be able to help you. And “yesterday's problem” is not a nice reference: post a link in case it's relevant and add the details to the question itself.
    – Manuel
    Commented May 25, 2016 at 14:38
  • 2
    @MaestroGlanz I mean it is the same problem with your question style, that leaves it not answerable You post code without saying at a higher level the intention, so all anyone can do is say syntactically what is wrong with the code, not suggest alternatives. you can not say it is impossible to force an edef to make a def as it always does that \edef\foo{hello} is identical to \def\foo{hello} in behaviour. Commented May 25, 2016 at 15:18
  • 2
    This question, tex.stackexchange.com/questions/262027/…, is related to the use of \edef with arguments, but touches on interactions of \defs within \edefs. Commented May 25, 2016 at 15:38

0

Browse other questions tagged .