Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
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
add comment

2 Answers

up vote 11 down vote accepted

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}.

share|improve this answer
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.