Assume we have two commands with the same name in different packages, like


\newcommand\house{This is a house.}


\newcommand\house{Esto es una casa.}

Can this macro be invoked differently from the calling document in a way that includes the package name?

If this is not possible, how can these two commands be grouped separately? The only way that comes to my mind is

\newcommand\houseinenglish{This is a house.}
\newcommand\houseinspanish{Esto es una casa.}
  • You can give an option when calling the package and use this option in the newcommand. I think xparse package will help you for the option but you can do it manual too
    – koleygr
    Aug 7, 2017 at 14:41
  • 3
    If you are writing those packages, you could have a look at the translations package and make a meta-macro.
    – TeXnician
    Aug 7, 2017 at 14:44

1 Answer 1


There are no namespaces in (La)TeX like in most programming languages. Following macro definitions will overwrite the previous ones (when defining macros with TeX's \def) or cause an error (when using LaTeX's \newcommand).

You can however copy the definition of one macro to another using \let\somenewmacro\someexistingmacro. The resulting macro is then independent from the other and does not use it later, like it would be the case when using \newcommand{\somenewcommand}{\someexistingmacro}.

In order to not cause error when the existing macro is defined again using \newcommand you can simply change its meaning to \relax so that \newcommand thinks it does not exists (as the does-already-exists check can not differ between a \relax and an undefined macro).

Basically try:

\let\house\relax % to 'undefine' it so that \newcommand\house works again 
\let\houseinspanish\house % or just use \house

Note that is is cumbersome if you have a lot of macros. Also if the macros uses further internal macros - also with the same names in both packages - you are in trouble.


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.