# Two conflicting packages in one document — doable?

I have two packages I want to use in the same document. Specifically musixtex and tengwarscript.

However they do conflict. Both packages use some of the same commands, obviously for very different things. Is there a way to load both packages in the same document, but only load one of them temporarily or intermittently?

-
The mind boggles! Are you writing out the music to the Lord of the Rings?? –  Loop Space May 18 '11 at 20:44
More seriously, is it just the odd command or is it a lot that are in conflict? –  Loop Space May 18 '11 at 20:45
You got it Andrew! It's nothing serious, just some fun with and for friends :) As I ran into the problem, well.. i wanted to see how to fix it should something like it arise in the future. The feedback I get is: ! I can't find file nur8' ! Emergency stop. mfput.log is completely empty. This happens if I try to compile a document, empty or not, so long as both packages are called in the preamble. –  Mr. V May 18 '11 at 20:54
I just did a bit of a basic look and could only find one command in common: \Tten. tengwarscript looks pretty good at namespacing all its internal macros (with teng@). Musixtex doesn't use that for anything specific other than to define it, so I would load musixtex first, then tengwarscript and use \ttie for the musixtex version of \Tten (since \Tten is just \let to \ttie). Of course, I may be missing something else that conflicts ... –  Loop Space May 18 '11 at 20:59
Could you add your code that doesn't work? It sounds like the problem is elsewhere as when I try a minimum document then I get no such errors (though I find that my suggestion in the previous comment doesn't work; you have to load tengwarscript first, save the definition of \Tten, and then restore it after loading \musixtex: \usepackage{tengwarscript}\let\origTten=\Tten\usepackage{musixtex}\let\Tten=\or‌​igTten). –  Loop Space May 18 '11 at 21:02

(Basically what was in my comment, but hopefully a bit clearer here.)

The only command that I can find which is defined in both tengwarscript and musixtex is \Tten. In tengwarscript it is defined with \newcommand which checks to see if it has already been defined (and throws an error if so). In \musixtex it is defined via a \let (which doesn't check), specifically \let\Tten=\ttie. Moreover, there is no other explicit use of \Tten in musixtex. So I would keep the tengwarscript definition of \Tten. For the musixtex version, you can use \ttie itself, or define another command to be equivalent to it, say \mTten. As tengwarscript explicitly checks to see if \Tten has been defined already but musixtex doesn't, the correct order to load them in is tengwarscript first and musixtex second. The following is a way to do this:

\documentclass{article}
\usepackage{tengwarscript}
\let\tengwarTten=\Tten
\usepackage{musixtex}
\let\mTten=\Tten
\let\Tten=\tengwarTten
\begin{document}
\end{document}


(Oh, and I'd like to see the final document ...)

As Marc van Leeuwen points out in the comments, as \Tten from musixtex does not need to be saved (since it already exists as \ttie), the shortest resolution of the conflict is:

\documentclass{article}
\usepackage{musixtex}
\let\Tten=\undefined % \relax will do here as well
\usepackage{tengwarscript}
\begin{document}
\end{document}


(Providing no one has defined \undefined, that is. If some idiot has done that then \relax will do instead. However, I doubt that anyone could redefine \undefined or \relax without breaking some serious stuff so I think both are pretty safe, with \relax the safest.)

-
@Mr. V: I recommend using the method that Gonzalo writes (and therefore also accepting his answer) since it is a little more robust and works independently of the order of the packages. You can always rename the saved symbol yet again using, say, \let\mTtex=\origTten if you so desire. –  Loop Space May 19 '11 at 8:59
Since you figured out the conflict details, and \Tten from musixtex is not used is not going to be used under that name at all (it is not used internally, and the user will use \Tten for the tengwarscript version), I think a simpler solution is to first \usepackage{musixtex}, followed by \let\Tten=\undefined to remove the offending definition, and then \usepackage{tengwarscript}. This assuming that \undefined is what its name suggests. –  Marc van Leeuwen Apr 27 '14 at 17:00
@MarcvanLeeuwen Providing no idiot has gone and defined \undefined then it is ... undefined. So \let\Tten=\undefined "undefines" \Tten. You can do the same with any undefined control sequence: \let\Tten=\someRandomRubbish works fine for me. So, yes, assuming that \Tten from musixtex is not used then your version is the shortest. –  Loop Space Apr 28 '14 at 6:24
@MarcvanLeeuwen The test for \newcommand explicitly tests to see if the proposed command name is either \relax or \end and refuses to define it if it matches. –  Loop Space Apr 28 '14 at 7:02

As Andrew has mentioned, the general procedure to prevent symbol names clashes when two packages define the same symbol name is to load the first package, rename the conflicting symbols, and then load the second package. The \savesymbol command from the savesym package can be used to this; \savesymbol{XXX} renames a symbol from \XXX to \origXXX:

\documentclass{article}
\usepackage{savesym}
\usepackage{musixtex}
\savesymbol{Tten}
\usepackage{tengwarscript}

\begin{document}
...
\end{document}

-
Nevermind, I just looked at the code and saw that it does. –  Loop Space May 19 '11 at 8:57