Using " as shortcut with babel

I try to use " as a shortcut by using

\catcode\"=13
\newcommand*{"}[1]{^{(#1)}}


I have to use babel[german] but the package destroys with my shortcut.

Is ther any way to prevent this or do I have to use another character?

Edit I just had to place the commands inside the document and not the preamble. now everything works fine.

• If you do not use the babel part, disable it. It us explained in the babel manual (look for shorthands) – daleif Jan 3 '16 at 18:44
• \shorthandoff{"}? – Henri Menke Jan 3 '16 at 19:44
• that doesn't change anything – meneken17 Jan 3 '16 at 20:02

It's a timing problem: babel changes the meaning of " at begin document, so you should add your redefinition after that.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}

\shorthandoff{"}

\begingroup
\catcode"=\active
\AtBeginDocument{%
\newcommand{"}[1]{^{(#1)}}%
}
\endgroup

\begin{document}

$f"{2}$

\end{document}


My advice is not to do this and to keep the shorthands.