Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I try to expand a macro containing a string with another string. It is in the document and thus I want to avoid using @.

I tried the following using etoolbox

\expandafter\def\fileAcronym\democodefile
\appto\fileAcronym{-acronym}

It does not work. The \demcocodefile is not expanded (thus the \expandafter).

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

What you're expanding is \fileAcronym and not \democodefile, since \expandafter expands whatever comes immediately after the next token. You could use

\expandafter\def\expandafter\fileAcronym\expandafter{\democodefile}
\appto\fileAcronym{-acronym}

but it may be more concise (since you're only using strings) to rather use

\edef\fileAcronym{\democodefile-acronym}
share|improve this answer
add comment

Assuming that \democodefile expands to the string you want to append something to, creating \fileAcronym that expands to the augmented string, the easiest way is to say

\let\fileAcronym\democodefile
\appto\fileAcronym{-acronym}

Without \appto:

\expandafter\def\expandafter\fileAcronym\expandafter{\democodefile-acronym}

With less characters

\edef\fileAcronym{\unexpanded\expandafter{\democodefile}-acronym}

(\unexpanded\expandafter can be replaced by \expandonce, if you already load etoolbox).


An “abstract” version:

\newcommand{\augmentstring}[3]{%
    \edef#1{\unexpanded\expandafter{#2}\unexpanded{#3}}%
}

With that code in the preamble you can say, in the document,

\augmentstring{\fileAcronym}{\democode}{-acronym}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.