[Tex/LaTex] Conflict between mathtools and MnSymbol

incompatibilitymathtools

When I run latex on the following file, it terminates successfully, and produces the expected result:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage[fleqn,tbtags]{mathtools}
%% \usepackage{MnSymbol}
\begin{document}
$$ x \xhookrightarrow{\gamma} y $$
\end{document}

But if I uncomment the commented-out line, I get this error:

! Undefined control sequence.
<argument> \lhook
                  \joinrel \relbar
l.6 $$ x \xhookrightarrow{\gamma}
                                  y $$
? 

Is there any way to get around this? (Of course, the example above does not require MnSymbol, but I do need it, along with mathtools, for what I'm working on.)

FWIW, here are the versions I have of the packages mentioned in the example:

Package: amsmath 2000/07/18 v2.13 AMS math features
Package: mathtools 2011/02/12 v1.10 mathematical typesetting tools
Package: MnSymbol 2007/01/21 v1.4 support for the MnSymbol font

Thanks!

PS: ironically enough, the only reason I have for using MnSymbol is to use its arrow definitions, as in

$$
\begin{matrix}
X & & \xrightarrow{h} & & Y \\
  & {\scriptstyle f} \lhooksearrow & & \rhookswarrow {\scriptstyle g} & \\
  & & Z & & \\
\end{matrix}
$$

to produce commutative diagrams like:

results from latex code above

…whose layout I find just barely acceptable (the arrows are too short, and don't necessarily lie right on, and/or parallel to, the lines connecting their source and target symbols; the spacing between these symbols is not always the best; etc.). IOW, if there is a better way to produce diagrams like these, possibly without needing MnSymbol, please let me know. Thanks!

Best Answer

As far as I can tell, MnSymbol undefines \lhook because it provides ready made "hooked arrows", while \lhook is used for building them from "normal arrows" in the default math fonts.

Just write, after loading MnSymbol,

\let\originallhook\lhook
\usepackage{MnSymbol}
\let\lhook\originallhook

but what's obtained with \xhookrightarrow won't be perfect. A bit better is

\let\originallhook\lhook
\usepackage{MnSymbol}
\newcommand{\lhook}{\mathrel{\raise.018ex\hbox{$\originallhook$}}}

On the other hand, you should look at the specialized package Xy-pic or at the more general TikZ for building diagrams.

Related Question