TL;DR see below at "core problem"
Problem
I'm trying to solve a conflict between the packages tipa (Fonts and macros for IPA phonetics characters) and babel with the ngerman option. The problem is the " character, which both packages make use of. I've gotten pretty far, here's what I've got:
Using just tipa
\documentclass{article}
\usepackage{tipa}
\usepackage[T1]{fontenc}
\begin{document}
\textipa{" ""}
\end{document}
produces the desired
ˈ ˌ
(primary and secondary stress)
Using just babel
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\begin{document}
"a "s "‘ "’ "< ">
\end{document}
produces the desired
ä ß „ “ « »
(result of babel shorthands specific to ngerman, i.e. english wouldn't produce this output)
Using babel and tipa
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tipa}
\usepackage[T1]{fontenc}
\begin{document}
\textipa{"x""x"a"s}
\end{document}
produces the not desired
ˈxxäß
Problem: the secondary stress is broken and a primary stress (") a) before a vowel results in a diaeresis or trema (= two dots, "umlaut") on the vowel and b) before an s results in a sharp s (ß).
My approach
Since in \textipa, " should be picked up by tipa, I used babel's \shorthandoff{"}:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tipa}
\usepackage[T1]{fontenc}
\begin{document}
\shorthandoff{"}
\textipa{"a""s}
\end{document}
produces the desired
ˈxˌxˈaˈs
Problem solved? Not quite. To limit the scope of \shorthandoff{"} and to save typing, I put it in a macro \myipa, which doesn't work:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tipa}
\usepackage[T1]{fontenc}
\newcommand{\myipa}[1]{\shorthandoff{"}\textipa{#1}}
\begin{document}
\myipa{"x""x"a"s}
\end{document}
produces the not desired
ˈxxäß
Putting the \shorthandoff{"} in \textipa's argument doesn't make a difference (\newcommand{\myipa}[1]{\textipa{\shorthandoff{"}#1}}).
Generally, putting \shorthandoff{"} in a macro works:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\newcommand{\shoff}{{\shorthandoff{"} "a}}
\begin{document}
"a \shoff{} "a
\end{document}
produces the desired
ä "a ä
TL;DR – the core problem
babel's \shorthandoff{"} doesn't seem to have an effect on input characters called outside of its direct range:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\newcommand{\shoff}[1]{{\shorthandoff{"} 2"a #1}}
\begin{document}
1"a \shoff{3"a} 4"a
\end{document}
produces
1ä 2"a 3ä 4ä
i.e. "a called in the same macro as \shorthandoff{"} produces "a (2), but "a called as an argument to a macro containing \shorthandoff{"} procudes ä (3).
How can I fix this macro to succeed in this last step of getting tipa and babel/ngerman to be friends?