Take the 2-minute tour ×  Let's say I have a file foo.sty that
contains the following:   I would like to be able to run this
through some software and produce a data file saying what
commands and environments have been defined, and how many
optional and mandatory arguments they have -- something like
this:   I could code up something in perl that would work most
of the time, but I'm wondering if there's any way to do it so
that it's highly reliable. The impression I get is that
completely correct parsing of LaTeX is hard, and basically the
only thing that does it is LaTeX. Is there some way of getting
LaTeX to do this, maybe with an appropriately constructed .tex
file that pulls in foo.sty, introspects, and then does
write18's...?  I'm looking for a solution that's open-source and
that I can run on linux in an automated way (not a GUI).
share|improve this question You can redefine \newcommand and
\newenvironment to add a hook. Generally speaking, we have
various ways to define macros with optional arguments,