4

i have a problem with hyphenation and i could not find a solution.

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[german,ngerman]{babel}
\selectlanguage{ngerman}
\usepackage{cite}

\hyphenation{(Web"~)""Frame"-works}

The error message is:

Description Path Resource Location Type Improper \hyphenation will be flushed. \hyphenation{(Web"~ (followed by: )""Frame"-works}) line 84 Texlipse Build Error Description Path Resource Location Type Not a letter. \hyphenation{( (followed by: Web"~)""Frame"-works}) line 84 Texlipse Build Error I think the problem is the charackter ")"

Edit:

Thanks for all answers:

First i want to achieve the example here: http://de.wikibooks.org/wiki/LaTeX-W%C3%B6rterbuch:_Silbentrennung "~ : Mit dieser Anweisung setzt man einen Bindestrich, an dem nicht getrennt werden soll, beispielsweise bei Wortergänzungen in Klammern: (Haupt"~)""Straße The \hyphenation (Web-)Framework should prevent hyphenation (Web-). Example (Web-

)Framwork is wrong. I know the parenthesis aren't letters for TEX, but see the example it works. So I wonder what is wrong.

So here is the example:

\documentclass[
   11pt,                % Schriftgroesse 12pt
   a4paper,             % Layout fuer Din A4
   ngerman,             % deutsche Sprache, global
   oneside,            % einseitig
   headinclude,         % Kopfzeile wird Seiten-Layouts mit beruecksichtigt
   BCOR12mm,            % Korrektur fuer die Bindung
   DIV14,               % DIV-Wert fuer die Erstellung des Satzspiegels, siehe scrguide
   fleqn,               % fleqn: Glgen links (statt mittig)
   %draft,               % Keine Bilder in der Anzeige, overfull hboxes werden angezeigt
   appendixprefix,              %berschriften des Anhangs +"Anhang"
  %chapterprefix,               %berschriften der Kapitel +"KAPITEL"
   abstracton,
   pdftex                       %Ueberschrift Zusammenfassung einschalten
     ]{scrreprt}

\usepackage[german,ngerman]{babel}
\selectlanguage{german}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\hyphenation{(Web"~)""Frame"-works}  
\begin{document}
(Web-)Frameworks asdasd (Web-)Frameworks asd (Web-)Frameworks (Web-)Frameworks
(Web-)Frameworks asdsada (Web-)Frameworks asd (Web-)Frameworks (Web-)Frameworks
(Web-)Frameworks asdasdasd (Web-)Frameworks (Web-)Frameworks (Web-)Frameworks
(Web-)Frameworks asdasdas (Web-)Frameworks (Web-)Frameworks
\end{document}
  • 1
    Welcome to TeX.SE! I'm a german, please add a minimal working example I can copy on my computer and play with it. Then I can help you. – Mensch Feb 28 '15 at 13:32
  • By the way, you can drop option german and hence the next line. There is absolutely no use in it. – Johannes_B Feb 28 '15 at 13:33
  • 1
    The parenthesis aren't letters for TeX. ! Not a letter. l.8 \hyphenation{( Web"~)""Frame"-works} ? ! Not a letter. l.8 \hyphenation{(Web" ~)""Frame"-works} Hence the problem. But, as a fellow german, i don't know what you are trying to do. Do you want to prevent hyphenation there? – Johannes_B Feb 28 '15 at 13:35
  • You can only have words in \hyphenation not markup, what effect are you trying to specify? – David Carlisle Feb 28 '15 at 14:29
  • Please augment your code snippets to form a compilable example that generates the problem at hand. Please also state which TeX distribution you use. I suppose we can guess that you're using TeXclipse as the front-end... – Mico Feb 28 '15 at 14:29
5

In the argument to \hyphenation only letters and hyphens to mark the admissible break points are allowed; babel shortcuts are definitely not allowed.

The simplest strategy for coping with this problem is to define a macro:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\newcommand{\WFW}{(Web\mbox{-})\nolinebreak\hspace{0pt}Framework}
\babelhyphenation[ngerman]{frame-work frame-works}

\begin{document}

\WFW{} asdasd \WFW{} asd \WFW{} \WFW{}
\WFW{} asdsada \WFW{} asd \WFW{} \WFW{}
\WFW{} asdasdasd \WFW{} \WFW{} \WFW s
\WFW s asdasdas \WFW s \WFW s

\end{document}

enter image description here

If you don't want the command you can surely type the word as

(Web"~)""Framework

in your document and, thanks to the \babelhyphen declarations, hyphenation would only be Frame-work or Frame-works with a possible break after the parenthesis.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\babelhyphenation[ngerman]{frame-work frame-works}

\begin{document}

(Web"~)""Framework asdasd (Web"~)""Framework asd (Web"~)""Framework (Web"~)""Framework
(Web"~)""Framework asdsada (Web"~)""Framework asd (Web"~)""Framework (Web"~)""Framework
(Web"~)""Framework asdasdasd (Web"~)""Framework (Web"~)""Framework (Web"~)""Frameworks
(Web"~)""Frameworks asdasdas (Web"~)""Frameworks (Web"~)""Frameworks

\end{document}

enter image description here

You can define a new command like as follows

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\babelhyphenation[ngerman]{frame-work frame-works}

\shorthandon{"}
\newcommand{\WEB}{(Web"~)""}
\shorthandoff{"}

\begin{document}

(Web"~)""Framework asdasd (Web"~)""Framework asd (Web"~)""Framework (Web"~)""Framework
(Web"~)""Framework asdsada (Web"~)""Framework asd (Web"~)""Framework (Web"~)""Framework
(Web"~)""Framework asdasdasd (Web"~)""Framework (Web"~)""Framework (Web"~)""Frameworks
(Web"~)""Frameworks asdasdas (Web"~)""Frameworks (Web"~)""Frameworks

\WEB Framework asdasd \WEB Framework asd \WEB Framework \WEB Framework
\WEB Framework asdsada \WEB Framework asd \WEB Framework \WEB Framework
\WEB Framework asdasdasd \WEB Framework \WEB Framework \WEB Frameworks
\WEB Frameworks asdasdas \WEB Frameworks \WEB Frameworks

\end{document}

Alternatively,

\shorthandon{"}
\newcommand{\WEB}[1]{(Web"~)""#1}
\shorthandoff{"}

but the input should be \WEB{Framework}. Take your pick.

This is the output of the above example.

enter image description here

  • I know the possibility for new commands but this not what iam looking for. Why does the example work with (Haupt"~)""Straße – Andreas Feb 28 '15 at 20:51
  • @Michael Surely not. If I try \hyphenation{(Haupt"~)""Straße} I get an error message; but even if this weren't the case, the command would have no consequence in the hyphenation, because it's given when the language is not yet set to ngerman. – egreg Feb 28 '15 at 20:56
  • @Michael I added a different strategy. – egreg Feb 28 '15 at 21:01
  • you are right :( Of course the second strategy will work, but a global definition would be nice. So if i want to use (Web"~)""Frame"-works, i have to use commands? – Andreas Feb 28 '15 at 21:29
  • @Michael Yes, but you don't need the "- in the middle of Frameworks if you use the \babelhyphen command I suggest. – egreg Feb 28 '15 at 21:34
1

tl;dr

\newunicodechar{‑}{{\fontencoding{T1}\selectfont\symbol{'177}}\nolinebreak\hspace{0pt}}

Then just use ‑ (U+2011) instead of - (U+002D) before the closing parenthesis. This means you can now write (re‑)creation or (Web‑)Frameworks or even Entwicklungs‑, Test/QS‑, Staging‑ oder Produktivsystem (yes, I got dash-comma working).

If this does not work for you, @dessert reports that a combination of this and Dmitry’s answer works:

\newunicodechar{‑}{\babelhyphen{nobreak}}

Which one to use seems to depend on the version of babel you use, and how you use it.

Backstory

I was looking for this as well, but as a more generic solution, and so far, the answers I found all do not satisfy me. I do have the german Babel package included, but "~ just typeset a double-quote followed by a space for me (and, in fact, I think I prefer double quotes to render as quote characters).

I looked at Unicode, and ‑ U+2011 NON-BREAKING HYPHEN appears to be what I want. Apparently, Xe(La)TeX already supports this, but we use pdflatex (directly in one project, via maven-latex-plugin in another), so that was out.

This pointed me into the correct direction though: I already knew about \newunicodechar so I thought I could just make U+2011 available. My first attempt was…

% does not work
\newunicodechar{‑}{-}

… to just define it to the hyphen, but it does not work like that. So, after reading some answers here, I tried…

% throws an error message
\newunicodechar{‑}{\nobreakdash-\hspace{0pt}}

… but \nobreakdash is not known, apparently. Finally, I tried…

% works for me, except commas
\newunicodechar{‑}{-\nolinebreak\hspace{0pt}}

… and voilà, I can typeset “(Maschinen‑)Benutzernamen” without the ugly separation and the automatic hyphenation makes this into “(Maschinen-)Benut-⏎zernamen” which is just perfect. Even better, when copy/pasting from the PDF, you get an actual - U+002D HYPHEN-MINUS, which makes things like \texttt{<!‑‑} to get <!-- (for XML comments) work.

Update 2016-09-04: Commas

There was a problem though: ‑, would still shove the stray comma onto the next line. The explanation has to do with us still using the - ASCII hyphen-minus in our macro expansion, to which Teχ (un‑)helpfully adds a discretionary break. However, this can be worked around if the current font has a T1 encoding (and not just OT1 or LY1), by temporarily switching to the T1 encoding variant of the current font and outputting the named character 127 (0x7F), which is exactly the same as the standard \hyphenchar 45 (0x2D).

% works for me
\newunicodechar{‑}{{\fontencoding{T1}\selectfont\symbol{'177}}\nolinebreak\hspace{0pt}}

For the (custom TrueType) font I was using, this required some hacking due to a ttf2tfm bug; if you just want to make sure that your font’s T1 encoding has the correct glyph at the correct position, use this (and replace museo with your font name):

\documentclass{article}
\usepackage{fonttable}
\usepackage[T1]{fontenc}

\begin{document}
\thispagestyle{empty}
\pagestyle{empty}
\xfonttable{T1}{museo}{m}{n}
\end{document}

(Note: I merged my answers to several questions in this answer then copied it to these other questions, so don’t wonder if it shows up in three places.)

0
\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{xspace}

\shorthandon{"}
\newcommand\WFW{(Web"~)""Frameworks\xspace}
\hyphenation{Frame-works}% to prevent Fra-me-works
\begin{document}
\noindent
    \WFW asdsad \WFW asssda \WFW \WFW
    \WFW asdsada \WFW asd \WFW \WFW
    \WFW asdasdasd \WFW sss \WFW fff \WFW
    \WFW asdasdas \WFW \WFW
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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