babel's active " making problems in math mode

MWE

\documentclass[norsk]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usetheme{Warsaw}
\begin{document}
\begin{frame}
forkaster hypotesen om at
$P(\text{"mynt"})=0,5$''.
\end{frame}
\end{document}


Giving the following error message:

ERROR: Argument of \language@active@arg" has an extra }.

--- TeX said ---
<inserted text>
\par
l.15 \end{frame}


From the .log file:

I've run across a } that doesn't seem to match anything. For example, \def\a#1{...} and \a} would produce this error. If you simply proceed now, the \par that I've just inserted will cause me to report a runaway argument that might be the root of the problem. But if your } was spurious, just type 2 and it will go away.

• What's the reason for typing \text{"mynt"}, which is wrong to begin with? May 12 '15 at 10:22

This is described in the babel documentation as a typical error, see section 1.5 on Shorthands. The problem is caused by the combination "}; the solution given is to add an empty pair of braces so you write "{}} instead.

\documentclass[norsk]{beamer}

\usepackage[utf8]{inputenc}
\usepackage{babel}
\usetheme{Warsaw}

\begin{document}

\begin{frame}
forkaster hypotesen om at
$P(\text{"mynt"{}})=0,5$''.
\end{frame}

\end{document}


You can improve the spacing of "m by writing "\!m instead.

However, it may well be simpler to use \qq from the textcmds package for these quotes:

\documentclass[norsk]{beamer}

\usepackage[utf8]{inputenc}
\usepackage[main=norsk]{babel}
\usepackage{textcmds}
\usetheme{Warsaw}

\begin{document}

\begin{frame}
\qq{forkaster hypotesen om at
$P(\text{\qq{mynt}})=0,5$}.
\end{frame}

\end{document}


See also the csquotes package.

• Is there some meaning to use closing before the word? May 12 '15 at 10:18
• I don't understand the question? May 12 '15 at 10:20
• @Sigur The poster shows knowledge of  ...' ', so I guess there is a specific reason to use " (I can't get the markdown right :-( ) May 12 '15 at 10:21
• @kjetilbhalvorsen, I asked why do you use ''mynt'' instead of mynt''? May 12 '15 at 10:23
• hmm.... because that is what emacs gives me? probably an error ... (I am using auctex) May 12 '15 at 10:34