# \edef in LaTeX 3?

Is there a version of `\DeclareDocumentCommand` (in LaTeX 3) which performs like `\edef`? I.e. where the argument is evaluated at the time of definition as opposed to the time the macro is called?

For example

``````\ExplSyntaxOn
\fp_zero_new:N {\fpX}
\fp_set:Nn {\fpX} {6}
\DeclareDocumentCommand { \dX } {} {\fp_to_decimal:N{\fpX}}

\fp_set:Nn{\fpX} {12}

\dX
\ExplSyntaxOff
``````

prints 12

``````\ExplSyntaxOn
\fp_zero_new:N {\fpX}
\fp_set:Nn {\fpX} {6}
\edef\dX{\fp_to_decimal:N{\fpX}}

\fp_set:Nn{\fpX} {12}

\dX
\ExplSyntaxOff
``````

prints 6

and I would like \dX to expand to 6

-
Can you show a use case? –  egreg Jul 6 '14 at 23:42

The family of commands in `xparse` for creating new document commands are not really intended for this sort of thing. This can be seen in your example where `\DeclareDocumentCommand` is intermixed with `expl3` code.

The short answer is that the `expl3` version of `\edef` is either `\cs_set:Npx` or `\tl_set:Nx` depending if you're creating a macro that takes arguments or simply a token list.

``````\edef\dX{\fp_to_decimal:N{\fpX}}
``````

you should just use

``````\tl_set:Nx \dX { \fp_to_decimal:N { \fpX } }
``````
-
Thanks, this is exactly what I wanted. Am I correct that the x in :Nx is what tells it to expand the argument? (as when I replaced it with :Nn it didn't work) –  Nate Ackerman Jul 7 '14 at 3:07
Exactly: `x` means ‘expand the argument fully (i.e., with `\edef`) before passing it to `\tl_set:Nn`’. See `expl3.pdf` or `source3.pdf` for a full explanation of the various argument types. –  Will Robertson Jul 7 '14 at 4:22
@WillRobertson, where do you get `source3.pdf`? –  daleif Jul 7 '14 at 8:29
@daleif — It should be available with `texdoc source3` if you have a complete TeX Live or MiKTeX installation. Otherwise <mirror.ctan.org/tex-archive/macros/latex/contrib/l3kernel>; –  Will Robertson Jul 7 '14 at 8:34
@WillRobertson I just tried and it doesn't work for me (may be because of that “freeze” they apply to TeX Live at some point). –  Manuel Jul 7 '14 at 8:35