[texhax] macro expansion and \input

Donald Arseneau asnd at triumf.ca
Tue Oct 2 07:34:04 CEST 2012


"Neal H. Walfield" <neal at walfield.org> writes:

> I have a number of generated files containing latex snippets.  So far,
> I've include them in my document using \input.  But, to make life a
> bit easier, I want to use a macro to generate the full filenames on
> the fly.  This is resulting in some macro expansion issues, which I
> don't understand.  The following is what I want to do:
> 
>   \documentclass{article}
>   
>   \begin{document}
>   
>   % My general-purpose macro.
>   \def\mutate#1{
>     \def\helper{#1}
>     \helper
>   }
>   
>   \input{\mutate{23}}

\def must be executed in normal processing to be effective. It is
not a macro (or other command) that works by expansion.  It is not
"expandable".

Why not make the \input part of your definition?

>   \def\myinput#1{
>     \edef\filename{#1}
>     \input{\filename}
>   }
> 
>   \myinput{\mutate{23}}

Again, \edef expansion does not process \def.

I mean

\def\mutateinput#1{%
  \def\helper{#1}%
  \input{\helper}%
}

Note I removed the blank spaces you were inserting.




Donald Arseneau                          asnd at triumf.ca


More information about the texhax mailing list