This is the reverse question of How to find out where a macro is defined? (and Where do I find out how a command/environment is defined? and How to find a package name by a command name?) and is inspired by the fact that the resolution of Error with cleveref + enumerate + tikz-qtree turned out to be a name clash between two packages.

I can see the use of a script that would take a package (for some variant of TeX) and produce a list of all the stuff it defines, with the idea that comparing two of these would help in the hunt for namespace collisions.

First Question: Does such a script exist?

If the answer to that is "No", then it shouldn't be too hard to write such a script; the key is to figure out where things are defined.

Second Question: What are the main ways in which assignments are made?

(Note that this could easily be specific to flavour of TeX used.) The word "main" is there because the purpose of such a script is not to be a necessary and sufficient test but a quick test to eliminate obvious possibilities. In particular, a package author who does something like \let\mydef\def \mydef\something{else} is probably knowledgeable enough that they are aware of the potential for namespace collisions and know how to avoid them. But \expandafter\def\csname s()mewe1rd c()mm@nd\endcsname should probably be allowed for.

  • 2
    Is trace package useful? BTW, tokens, dimensions, boxes, etc. are registers.
    – Leo Liu
    Mar 22, 2011 at 10:25

2 Answers 2


I don't think such a script exists. The closest thing I know of is (la)texdef which got recently published by me. It shows you the definition of (a) macro/s on the command line. The package(s) and class can be provided as option. If you suspect one macro name to be used by two packages it allows you to check if it is getting defined by both. I'm planning to add some option to detect the source file of the definition using my package filehook as demonstrated by Leo Liu in his answer to How to find out where a macro is defined?.

It could also be extended or forked to produce the output you want. I wouldn't go down the route of parsing TeX code, but instead creating a TeX file by the script (as (la)texdef does) and redefine \def and friends to print the macro name. Something like:

  \message{DEF: #1^^J}%
% Same for \edef, \gdef, \xdef and \let

The output can be then formatted by the script, sorted and presented to the user. Adding an option which automatically compares the macros defined by two packages would also not be to complicated.

Another idea would be to use \tracingassigns and parse the output. It might be simpler and more precise.

Update 2011/04/03

I modified now the mentioned latexdef script to include options for listing the command sequences (macros) of the given packages. The (shortened) definition can be displayed alongside:

  --list, -l           : List user level command sequences of the given packages.
  --list-defs, -L      : List user level command sequences and their shorten definitions of the given packages.
  --list-all, -ll      : List all command sequences of the given packages.
  --list-defs-all, -LL : List all command sequences and their shorten definitions of the given packages.

So latexdef -p <package> -l will list all user level macros (which do not include @ or a space). I uploaded this as v1.3 to CTAN where it should be available shortly.

  • Just seeing Leo Liu's comment on the question which reminds me that register names are not defined using \def and friends but using \chardef and friends. This need also be added to the above list, i.e. redefined to output the names. Mar 22, 2011 at 10:38
  • I didn't realise that your script worked by running it through TeX and then looking at the output. That's an interesting approach. I had more in mind some sort of perl script that would just go through looking for key patterns. But as you say, it is probably easier this way. Mar 22, 2011 at 13:07
  • @Andrew: Using TeX is the only reliable way to parse TeX. I made a test with \tracingassigns and might add it as a feature. Mar 22, 2011 at 13:44

First question : I think No

Second Question : You give some examples but some macros can be defined by a package like xkeyval and the macro \define@cmdkey. There are other packages that work the same way as xkeyval. The method used is \csname ...\endcsnamebut the names of the macros are built with sometimes prefix and suffix; this is not easy to trace

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .