Here is another casualty of TeX's flat namespace and another reason to start using LaTeX3...
I noticed today that the algorithm2e and keystroke packages clash. More specifically, they both define a command called \Return:
- in
algorithm2e,\Returnis a command for typesetting the pseudocode Return keyword; - in
keystroke,\Returnis a command that typesets Return.
Both packages define their \Return command using \newcommand; therefore, if both packages are loaded, LaTeX returns an error when it encounters the second \newcommand\Return.
I solved the problem by giving keystroke's \Return a new, unique name that doesn't clash with anything I'm using so far, like so:
\documentclass{article}
\usepackage{keystroke}
\let\ksReturn\Return
\let\Return\relax
\usepackage{algorithm2e}
\begin{document}
\Return \quad \ksReturn
\end{document}
That worked, but I have a question:
As a user (not a package writer/maintainer), what is best practice for fixing a clash between two homonymous, yet different, commands defined in two different packages, without altering either of the .sty files? Can my approach have any detrimental side-effect (aside from my new name possibly generating a different clash)?
Side note: keystroke is quite an old package. At the time of writing this post, the current version dates back to November 2000, whereas the current version of algorithm2e was released more recently, in January 2013.
Edit: a less problematic and more powerful package for typesetting menu sequences,
paths, and keyboard shortcuts is the excellent menukeys package.
\Returnoccurs only once inkeystroke.sty: in its own definition. Therefore, no problem here; but otherwise, my approach would be problematic, you're right. One would hope that the package writer would use@in her internal-command names to reduce the risk of conflict, but not everyone follows that practice. – jub0bs Oct 04 '13 at 07:08algorithmwould be defined just there and not at the outer level. But even this wouldn't solve all problems, because it's not so strange thinking to use the\Returnkey symbol insidealgorithm. Probably thekeystrokepackage should have defined its commands in the form\key{Return}. Oh, no!\keyis used somewhere else… – egreg Oct 04 '13 at 08:01keystrokepackage does have a\keystroke(not\key) macro for typesetting keyboard keys. – jub0bs Oct 19 '13 at 17:26