# Using breakable hyphen "= in \newcommand

I want to use a breakable hyphen "= in a command:

\documentclass[a4paper]{article}
\usepackage[ngerman]{babel}
\newcommand{\TT}{Test"=Text }
\begin{document}
This is a test whether the hyphen in \TT works or not.
In normal Test"=Text works.
\end{document}


In the text "= works fine, but as a command "= does not work. Any idea?

-
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. And a tip: You can use backticks  to mark your inline code as I did in my edit. – doncherry Jan 7 '12 at 21:33

The babel-shorthand "= isn't activated yet when the macro is defined, so you have to activate it:

\documentclass[a4paper]{article}
\usepackage[ngerman]{babel}
\shorthandon{"}
\newcommand{\TT}{Test"=Text }
\shorthandoff{"}
\begin{document}
This is a test whether the hyphen in \TT works or not.
In normal Test"=Text works.
\end{document}


"Activated" means that it makes LaTeX think "Wait, there's something going on here, better check the next characters really carefully", just like a backslash \ tells it that a macro follows. \shorthandon{"} tells LaTeX to watch out for any ". (This only works for " afaik, it's babel specific.) Normally, " isn't activated until \begin{document}.

-

With babel v3.9, released in March 2013, you may also use the new KeepShorthandsActive option which "[t]ells babel not to deactivate shorthands after loading a language file, so that they are also availabe in the preamble" (manual, p. 11).

\documentclass[a4paper]{article}
% The following requires babel v3.9 (released March 2013)
\usepackage[ngerman,KeepShorthandsActive]{babel}
\newcommand{\TT}{Test"=Text }
\begin{document}
This is a test whether the hyphen in \TT works or not.
In normal Test"=Text works.
\end{document}
`
-