[Tex/LaTex] Beamer Presentation compile error

amsmathbeamerbmerrorsmathtools

I'm trying to do a presentation doing a Beamer template.

I've loaded the following packages:

\usepackage{graphicx}
\usepackage{booktabs} 
\usepackage{bm}
\usepackage{mathtools}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

Everything else is according to the template with minor changes like instead \date{\today} I put \date{June 20, 2016}, or instead of \frametitle{Overview} I put \frametitle{Sumário}.

I'm trying to compile this with texmaker, but I get the following error:

! LaTeX Error: Command `\mathbf' already defined.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... 

I've yet to use that command in the presentation, and the line texmaker indicates as the beginning of problematic section is right at the start, i.e. \begin{document}

I know that if I comment out the bm package the problem goes away, but I've used this combination of packages in documents before without any problem.

Why is this happening?

Any help would be appreciated.

Best Answer

Change the package loading order. Note that graphicx is already loaded by beamer.

On the other hand, loading lmodern is not needed, unless you're on MiKTeX and don't have a working installation of the CM-Super fonts.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{mathtools}
\usepackage{bm}
\usepackage{booktabs}

\begin{document}

\begin{frame}
\frametitle{Test}

Some text and math:
\[
\sum_{k=1}^n k^2=n\left(n+\frac{1}{2}\right)(n+1)
\]

\end{frame}

\end{document}

enter image description here

Related Question