1

When a new macro is created (typically with \newcommand, \renewcommand or \newenvironment), it requires the user to come up with a name and a definition. The name should only consist of letters (or use arguments) and be unique.

However, sometimes when I add a new package to the document, it turns out the name of my macro coincides the name defined by the new package. For instance, this recently happened when I added ulem package, which resulted in unexpected behavior due to my previously defined \uline command.

On top of that, when collaborating with other users who may leave their own macro definitions anywhere in the code, it would be nice to be able to instantly check whether there is no two different macros with the same name.

Currently, the only way to check for the uniqueness of my macro name is to perform a full-text search for "\myNewMacroName" or "\myNewEnvironmentName" on all doc files for 3000+ packages and all *.tex files in the current project. This is of course doable, but is quite time-consuming and annoying.

Is there a faster and more robust way of assuring the unique and correct name for the new macro? Probably an add-on or built-in checker that would operate like a code-completion aid, but specifically for a customized LaTeX environment.

  • 2
    Such an add-on would have to be TeX-based, otherwise you could easily fool it with, say, \expandafter\def\csname somemacro\endcsname{...}, or more complicate constructs, like key-val parsers, which automatically build the macro names from the arguments. And if such add on has to be TeX-based, the easiest way is to move your macro definitions to the very end of the preamble and always use \newcommand (or something equivalent) to check whether the name is already taken – Phelype Oleinik Dec 14 '19 at 13:33
  • 4
    for internal package code it is good practice to use a "unique" prefix so longtable internals are etc, \LT@... but for top level commands it just depends... – David Carlisle Dec 14 '19 at 13:34
  • 1
    For internal names you can add @ characters, which are not normally allowed in macro names (see \makeatletter and \makeatother). You can also use groups and local definitions. – John Kormylo Dec 14 '19 at 17:18

Your Answer

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

Browse other questions tagged or ask your own question.