[texhax] listmacros?

Michael Doob mdoob at ccu.umanitoba.ca
Mon May 30 20:33:41 CEST 2011

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.

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.


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 \
     # 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++
     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
Winnipeg, MB, Canada R3T 2N2

More information about the texhax mailing list