Beamer Presentation compile error

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

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

• Seems to be a combination of beamer, bm and lmodern. For example \documentclass{beamer} \usepackage{bm} \usepackage{lmodern} \begin{document} s \end{document} will produce the error, swapping the order of bm and lmodern and the error goes away. – Torbjørn T. Jun 12 '16 at 9:51
• What's the reason for \usepackage{lmodern}? – egreg Jun 12 '16 at 10:15
• @egreg the reason is I would like to write accented letters – An old man in the sea. Jun 12 '16 at 13:48
• @Anoldmaninthesea. What has lmodern to do with accented letters? – egreg Jun 12 '16 at 13:51
• – An old man in the sea. Jun 12 '16 at 13:54

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}


Without a proper MWE, this is the best help I can offer: invoking professionalfonts produces no such error.

\documentclass{beamer}
\usefonttheme{professionalfonts}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{bm}
\usepackage{mathtools}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

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

• Sam, what's an MWE? – An old man in the sea. Jun 12 '16 at 14:45
• @Anoldmaninthesea., it's a "minimal working example"; check here: meta.tex.stackexchange.com/questions/228/… Basically, it's code that shows the problem as concisely as possible that begins with a documentclass and ends with \end{document}`. – Richard Jun 12 '16 at 15:03