# How to invoke two equally defined commands from different packages

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

inenglish.sty

\newcommand\house{This is a house.}


inspanish.sty

\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 Aug 7, 2017 at 14:41
• If you are writing those packages, you could have a look at the translations package and make a meta-macro. Aug 7, 2017 at 14:44

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).



Basically try:

\usepackage{inenglish}
\let\houseinenglish\house
\let\house\relax % to 'undefine' it so that \newcommand\house works again
\usepackage{inspanish}
\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.

• It seems like a major flaw in the language to leave this up to the user. How do library developers ensure that the names they assign to their commands have not been used by some other group of developers in some other part of the world? Aug 16, 2021 at 10:25
• @user32882 Old comment, but developers can do e.g. latex3 - How do I register the prefix of my expl3 package? - TeX - LaTeX Stack Exchange. Not all developers do that unfortunately. Jul 23 at 15:15