[OS X TeX] tex'ing newcommands

Donal Day dbd at virginia.edu
Wed May 26 16:13:42 EDT 2004

On May 26, 2004, at 2:47 PM, Jonathan Kew wrote:

> On 26 May 2004, at 6:38 pm, William F. Adams wrote:
>
>> On Wednesday, May 26, 2004, at 01:29  PM, Donal Day wrote:
>>
>>> Does there exist a tool that will read this file of definitions,
>>> strip out the definitions, put each on a line and render them into a
>>>  latex document? I would then compile it and keep the output as a
>>> handy reference. If so, I could usefully share this file and the
>>> list of commands with my collaborators so we can all benefit.
>>
>> One can replace \def with your own command (say \mef) and then have a
>> switch at the beginning of the file which determines how \mef is
>> defined, whether it makes a command or typesets its argument.
>>
>
> No need to replace anything in the file. Create a file
> "printdefs.ltx", something like this:
>
> % - - - - - printdefs.ltx - - - - -
> \def\mydefsfile{mydefinitions.tex}
>
> \documentclass{article}
>
> \begin{document}
>
> \noindent Definitions in {\tt\mydefsfile}:
>
> % redefine \def and \newcommand; note that we don't handle parameters!
> \let\Def=\def
> \def\def#1#2{{\let\def=\Def \noindent {\tt\string #1} : #2\par}}
> \let\newcommand=\def
>
> % lots of standard LaTeX macros will break now,
> % so we go for more primitive methods...
> \csname @@input\endcsname \mydefsfile
>
> % need to restore this before \end{document}
> \let\def=\Def
>
> \end{document}
> % - - - - - end of file - - - - -
>
> Change the filename defined at the beginning, of course. Run this
> through LaTeX, and you should get a listing.
>
> One warning: this won't work for definitions of commands with
> parameters; that would take quite a bit more effort, I'd think.
>
> JK

This worked. Thanks Jonathan.

Donal

-----------------------------------------------------
Post: <mailto:MacOSX-TeX at email.esm.psu.edu>