# [texhax] listmacros?

W.J. Metzger wes at hef.ru.nl
Mon Jun 20 15:09:19 CEST 2011

```On Mon, 20 Jun 2011, Nitecki, Zbigniew H. wrote:

> cmdtrack was suggested to me also by Dragan Blagojevic.  It works beautifully on \newcommands defined in the body of the tex source file.
> However (not surprisingly) it does not do anything with \newcommands defined in .sty files called by the source.  This is really where it would
> be useful;  the few commands I define in the body of my paper make no difference as far as space is concerned, but my custom .sty files are really
> very big, and I use a relatively small portion of them in any given paper.

Did you put  \usepackage{cmdtrack}  BEFORE  the \usepackage  statements for
your custom style files (but preferably AFTER the \usepackage  statements
for any other packages?

Cheers, Wes

> I am a total novice (and one fearful of screwing up) when it comes to script and such.  If I want to use the script suggested below by Michael Doob,
> what do I do with it (ie, where do I put it, and what incantations do I need in the terminal?  I am most used to GUI interfaces, in particular I use TeXShop
> for processing my (la)tex files.
>
> Thanks for the advice, though.
>
> Zbigniew Nitecki
> Department of Mathematics
> Tufts University
> Medford, MA 02155
>
> telephones:
> Office    (617)627-3843
> Dept.    (617)627-3234
> Dept. fax    (617)627-3966
> http://www.tufts.edu/~znitecki/
>
>
>
>
> On Jun 20, 2011, at 7:42, Uwe Lueck wrote:
>
> "Michael Doob" <mdoob at ccu.umanitoba.ca<mailto:mdoob at ccu.umanitoba.ca>> wrote 30.05.2011 20:33:41:
> On Monday 30 May 2011 1:23 pm, Nitecki, Zbigniew H. wrote:
> I suspect the following does not exist, but wonder if it does or if some expert might suggest how to make it.
>
> Background: I have a pair of huge files containing many personally designed macros,
> which I used extensively in writing two books, and now use almost reflexively.
> When I write a relatively short paper in latex, I can of course append the two files to the paper
> when I send it out, but often I use a very small subset of the macros in these files.
>
> So I wonder if there is a command similar to the "listfiles" command
> (which lists the files used when compiling a document) but listing the macros used---either identified by package,
> or even better, providing a list of \newcommand's defining them.
> That way I could create a far smaller macro list custom designed for the paper at hand, and use it in place of the two
> large files when submitting a paper for publication or for the ArXiv.
>
> Maybe Michael Downes' cmdtrack is what you need?
>
>    http://ctan.org/pkg/cmdtrack
>
> -- found looking for something different.
>
> HTH -- Uwe.
>
> This problem comes up all the time. I wish authors were as conscientious as you are.
> I almost hesitate to add what follows: it is a hack that I wrote for office use only,
> so please don't get mad at me for being so sloppy. I think it will do the job for you.
>
> Cheers,
> Michael
>
> #!/bin/sh
> gawk '
> function isaletter(s){
> r = index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", s)
> return r
> }
> {
> inline = \$0
> inline = inline " %" # append blank as possible terminator
> while (1) # find control words in inline
> {
> ptr = index(inline, "\\")
> if (ptr == 0) break;
> if ( index(inline, "%") < ptr) break # found a comment marker
> inline = substr(inline,ptr); # throw away everything in front of \
> ptr=2;
> # now make ptr point to the last character in the control word
> if (isaletter(substr(inline, ptr,1)))
> {
> while(isaletter(substr(inline, ptr,1))) ptr++
> ptr--
> }
> print substr(inline,1,ptr);
> inline = substr(inline, ptr+1);
> }
> } ' \$* | sort | uniq -c | sort -n
>
>
>
> --
> ------------------------------------------------------------------
> Michael Doob Telephone: (204) 474-9796
> Department of Mathematics Fax: (204) 474-7606
> University of Manitoba email: Michael_Doob at umanitoba.ca<mailto:Michael_Doob at umanitoba.ca>
> Winnipeg, MB, Canada R3T 2N2
> ------------------------------------------------------------------
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
>
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org<mailto:postmaster at tug.org>
>
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
>
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org
>

--
Dr. W. J. Metzger            Experimental High Energy Physics Group
tel. +31-24-3653127          Faculty of Science