[Tex/LaTex] Beamer crashes with babel Turkish package

babelbeamergraphics

I just started to learn beamer and noticed that the problem in \usepackage[turkish]{babel} and \includegraphics inconcistency question applies for beamer and \shorthandoff{=} solution does not work. Has anyone have another solution? Thanks.

\documentclass{beamer}
\mode<presentation>
\usepackage[utf8]{inputenc}
\usepackage[turkish]{babel}
\usepackage{graphicx}

\begin{document}
\begin{frame}
    \begin{figure}
    \centering
    \shorthandoff{=}
    \includegraphics[scale=0.3]{resimler/stmornek2.png}
    \shorthandon{=}
    \end{figure}
\end{frame}
\end{document}

Best Answer

It works if you move the commands outside the frame:

\documentclass{beamer}
\mode<presentation>
\usepackage[turkish]{babel}
\usepackage{graphicx}

\begin{document}
\shorthandoff{=}
\begin{frame}
    \begin{figure}
    \centering
    \includegraphics[scale=0.3]{resimler/stmornek2.png}
    \end{figure}
\end{frame}
\shorthandon{=}
\end{document}

or if you add the fragile option to the frame:

\documentclass{beamer}
\mode<presentation>
\usepackage[turkish]{babel}
\usepackage{graphicx}

\begin{document}

\begin{frame}[fragile]
    \begin{figure}
    \shorthandoff{=}
    \centering
    \includegraphics[scale=0.3]{resimler/stmornek2.png}
    \shorthandon{=}
    \end{figure}
\end{frame}

\end{document}

As egreg mentions in his comment, you are using the utf8 option for inputenc, so you don't really need the = shorthands for the turkish module of babel, and you can simply deactivate them after \begin{document}:

\documentclass{beamer}
\mode<presentation>
\usepackage[utf8]{inputenc}
\usepackage[turkish]{babel}
\usepackage{graphicx}

\begin{document}
\shorthandoff{=}

\begin{frame}
    \begin{figure}
    \centering
    \includegraphics[scale=0.3]{resimler/stmornek2.png}
    \end{figure}
\end{frame}

\end{document}