This is a follow-up to this question on contributing to CTAN, but it applies to the situation when writing ones own package for private use. In brief, the question is:

Is there a way to avoid name-clashes with defining macros?

In a bit more detail, I know that \newcommand checks this, but I find that I need the flexibility of \def. Also, I tend to define a lot of internal commands that then get used in various ways in the ones that the user actually uses and I suspect that many others do the same. It's a lot harder to go through every package and check that every command is "clean", especially since many will be defined via the \csname construction. On the other hand, because most of the commands are internal, I'd be quite happy to simply add a unique prefix to each of them to avoid such a conflict. For example, at the moment all my internal commands are prefixed \my@ and external ones \my (with the exception of one package that was written specifically for one paper which gets \hopf@ and \hopf respectively).

So, expanding on my question above:

  1. Is there a convention on CTAN to avoid conflicting names?
  2. Is there an automatic way to avoid conflicts when loading a package?

(I should confess that I strongly doubt that there is a positive answer to the second question since so many packages rely on being able to redefine macros defined by other packages; still, the programmers seem to be able to cope with this so I do wonder if TeXperts can as well.)

  • 3
    well, you already gave the answer in your question :D Yeah, I also use something like \my@.. but of course it's not 100% reliable. Aug 3, 2010 at 9:53
  • @Juan: I'd better make sure I never use one of your packages as well as one of mine! Aug 3, 2010 at 11:21

1 Answer 1


It's impossible to check everything, as you say. One way people work when they need the power of \def is to use \newcommand first:


Alternatively, you can use \@ifundefined to do the testing.

For internal macros, the usual method is to pick a prefix that you hope no-one else is using. This tends to work best if you simply use the package name you've picked, which of course you can check on CTAN:


For user macros, some people use a similar approach, especially if the macros are only used rarely: something like \MyPkgMacroNameOne. Of course, this can be rather awkward as the names get quite long.

With my LaTeX3 'hat' on, I'd point out that we are trying to come up with a scheme for LaTeX3 that will be more flexible and reliable. I can't say we have a definitive answer at the moment, and so suggestions are welcome!

  • 1
    Regarding LaTeX3: I find myself using the '@' symbol as a sort of namespace separator and as a way of designating commands as "internal" versus "exported". Maybe LaTeX3 could automatically prefix commands defined within a package with some unique prefix if they already contain an "ampersat"? Aug 3, 2010 at 12:34
  • 4
    PS Can one buy LaTeX3 hats yet? Aug 3, 2010 at 12:35
  • :-) I don't know if you're familiar with the LaTeX3 approach, but there are no '@' symbols, I'm afraid. A typical name would by \cs_set_eq:NN (which is more-or-less \let renamed). The idea is to be more rigid with namespaces, but Tex doesn't let us do this 'automagically' as it doesn't have namespacing at the engine level. There have been suggestions on at least recording which names are taken by which packages.
    – Joseph Wright
    Aug 3, 2010 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.