[texhax] Creating a source with macros embedded

Uwe Lueck uwe.lueck at web.de
Mon Sep 13 23:41:16 CEST 2010


"Mike B." <mb78aa at yahoo.com>, 30.07.2010 06:32:05:
> I use several files where I define abbreviations with \newcommand. I load these files at the preamble with
>     \input filea
>     \input fileb
> etc.
>
> Is it possible to transform a latex source file to have  all these macros embedded so I do not need to supply the abbreviations files?.
>
> For example, assume I define in filea
>     \newcommand{myabbr}{sometext}
>
> and my source code has
> blah blah \myabbr blah blah
>
> I would then obtain a new source code (with the macros replaced by their corresponding text)
> blah blah sometext blah blah
>
> so there is no need for to input the abbreviations files.

trying to reword: 
While abbreviating macros work as “substitutions” at 
compiling only, Mike wants them to work as substitions 
on the source files. 
 
One might answer that Mike just had been impressed too much 
by TeX’s macro mechanism and chose abbreviating macros 
erroneously when he should have used a different program 
(not TeX) to perform that substitutions, ...

* such as AWK or Perl. But indeed there are scripts right for Mike’s purpose 
(see http://ctan.org/pkg/PKGNAME for package PKGNAME): 
 
* de-macro | detex | ltx2x. 

* Instead, you can use functionality of certain editors: 
user-defined editor commands (e.g., with Vim), 
“autocompletion”; “expansion” 
(“auto-correction”, macros, variables, aliases; by shell ...) 
 
* If you are sufficiently mad, you may even choose TeX-based substitution: 
datatool | stringstrings  | ted | fifindo. 
The latter introduces a kind of script language 
(consisting of ordinary TeX macros) 
for performing multiple substitutions 
(still not very intuitive at present). 
 
* Back to ordinary use of macro files—for substitution! 
I am currently using an extension of my aforementioned 
fifinddo that “copies” one file into another, 
however: expanding especially chosen macros 
(I am generating HTML this way for my own purposes—“blog.sty”). 
This could be used here, but it would need \let\foo\relax  
for any standard LaTeX command that should not expand 
in this process (generating a source file). 
This may become useful if those source files don’t include 
the LaTeX document preamble, but rather are only (parts of) 
the body of the document environment. 

... previous made from 

    http://www.webdesign-bu.de/uwe_lueck/texhax.htm#mac-emb

Cheers, 

    Uwe.



More information about the texhax mailing list