# “ with tipa and babel's ngerman / \shorthandoff{”} in a macro

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?

-
Just out of curiosity: what's "TL;DR"? –  egreg Sep 30 '11 at 8:51
It stands for "too long, didn't read", the comma probably has turned into a semicolon because it's all-caps? I think it started out as a comment to posts perceived as too long, and has since become kind of a synonym for "summary" or "short version", for those people who don't want to read the whole thing and would otherwise add "TL;DR" as a comment. –  doncherry Sep 30 '11 at 12:43

You have to defer gathering the argument:

\newcommand{\myipa}{\begingroup\shorthandoff{"}\myipaI}
\newcommand{\myipaI}[1]{\tipaencoding #1\endgroup}


This will typeset correctly the bit \myipa{"x""x"a"s}. Of course such a command can't go in the argument of other commands. Should you need it into a section title, say

\shorthandoff{"}
\section{\textipa{"x""x"a"s}}
\shorthandon{"}


Here \myipa would not work if you need to typeset the table of contents. It's always the same problem: when some characters are gathered as arguments, their category code is fixed.

This however suggests a different approach:

\newcommand{\myipa}[1]{{\shorthandoff{"}\scantokens{\tipaencoding#1\endinput}}}


Or \DeclareRobustCommand, if you need it frequently in moving arguments; it's always possible to precede \myipa with \protect, for one or two cases.

-
\DeclareRobustCommand{\myipa}[1]{{\shorthandoff{"}\scantokens{\tipaencoding#1\e‌​ndinput}}} works in all cases, thanks a lot! –  doncherry Oct 1 '11 at 11:52