[Tuglist] Script for substituting newcommand

Radhakrishnan CV tuglist@tug.org.in
Fri, 29 Mar 2002 19:28:12 +0530 (IST)


On Fri, 29 Mar 2002 at 17:37, Manoj K N wrote:

   Suppose a style file foo.sty contains a command
   \newcommand{\foo}[1]{Hello #1}
   
   A LaTeX file sample.tex contains the line \foo{bar}
   
   Is there any script (bash/perl) that reads sample.tex and foo.sty
   and substitutes it with Hello bar ?

That's what TeX does precisely, the only difference being the output 
is a dvi. But if you need an ASCII output, obviously it is 
non-trivial. One way might be to process the dvi with Eiten's tex4ht 
binary which is available in all the standard TeX distributions to 
extract the ASCII text from the dvi.

If you start writing a bash script or perl program, you might end up
in writing a whole lot of libraries that can understand all the
nuances of TeX/LaTeX's \def and \newcommand.  Probably LaTeX2HTML
which is a perl program can provide you some hooks on how to handle
the \newcommand, still LaTeX2HTML is incapable of handling all the
\newcommand definitions.

-- 
Radhakrishnan