Typesetting very long words with hyphens inside
As you are using xetex you can set up character classes to insert some glue around the hyphens to help with line breaking and enable hyphenation.
\documentclass{article}
\usepackage{color}
\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\hclass
\newXeTeXintercharclass\lclass
\XeTeXcharclass`\-=\hclass
\count0=`\a
\loop
\XeTeXcharclass\count0=\lclass
\ifnum\count0<`z
\advance\count0 1
\repeat
\count0=`\A
\loop
\XeTeXcharclass\count0=\lclass
\ifnum\count0<`Z
\advance\count0 1
\repeat
\count0=1
\XeTeXinterchartoks\hclass\lclass{\hskip0pt plus .3pt minus .1pt\relax}
\XeTeXinterchartoks\lclass\hclass{\nobreak\hskip0pt plus .2pt\relax}
\righthyphenmin=2
\hyphenation{BL-AH UNI-F-ORM AL-PHA}
\begin{document}
\noindent X\dotfill X
a ``SIERRA-TANGO-CHARLIE-ECHO-YANKEE-OSCAR-MIKE-NOVEMBER-CHARLIE-VICTOR-WHISKEY-ALPHA-PAPA-BRAVO-UNIFORM-BLAH-BLAH-BLAH-BLAH-BLAH-BLAH''
zzzzzzzzz ``SIERRA-TANGO-CHARLIE-ECHO-YANKEE-OSCAR-MIKE-NOVEMBER-CHARLIE-VICTOR-WHISKEY-ALPHA-PAPA-BRAVO-UNIFORM-BLAH-BLAH-BLAH-BLAH-BLAH-BLAH''
zzzzzzzzz jjjj axaxax axaxaxa axaxax ``SIERRA-TANGO-CHARLIE-ECHO-YANKEE-OSCAR-MIKE-NOVEMBER-CHARLIE-VICTOR-WHISKEY-ALPHA-PAPA-BRAVO-UNIFORM-BLAH-BLAH-BLAH-BLAH-BLAH-BLAH''
\noindent X\dotfill X
\end{document}
I suggest you do three things:
Load the
babel
package in the following way:\usepackage[ngerman,english]{babel} \useshorthands{"} \addto\extrasenglish{\languageshorthands{ngerman}}
Change all instances of
-
in the long strings to"=
; this allows LaTeX to find hyphenation points (and break lines at those points...) for the words inside the long strings.Encase the paragraphs that contain the long strings in
sloppypar
environments.
As the following screenshot shows, the result is guaranteed to be perfect, but it'll be a whole lot better than without these modifications. Incidentally, if you're free to use LuaLaTeX instead of XeLaTeX, you'll get slightly better results, simply because microtype
cooperates more fully with LuaLaTeX than it does with XeLaTeX.
% !TeX program = xelatex
\documentclass{article}
\usepackage{fontspec,microtype}
\usepackage[ngerman,english]{babel}
\useshorthands{"}
\addto\extrasenglish{\languageshorthands{ngerman}}
\begin{document}
\hrule % just to illustrate width of textblock
\bigskip
\begin{sloppypar}
``SIERRA"=TANGO"=CHARLIE"=ECHO"=YANKEE"=OSCAR"=MIKE"=NOVEMBER"=CHARLIE"=VICTOR"=WHISKEY"=ALPHA"=PAPA"=BRAVO"=UNIFORM"=BLAH"=BLAH"=BLAH"=BLAH"=BLAH"=BLAH'', Tom said.
\end{sloppypar}
\bigskip
``SIERRA"=TANGO"=CHARLIE"=ECHO"=YANKEE"=OSCAR"=MIKE"=NOVEMBER"=CHARLIE"=VICTOR"=WHISKEY"=ALPHA"=PAPA"=BRAVO"=UNIFORM"=BLAH"=BLAH"=BLAH"=BLAH"=BLAH"=BLAH'', Tom said.
\bigskip
``SIERRA-TANGO-CHARLIE-ECHO-YANKEE-OSCAR-MIKE-NOVEMBER-CHARLIE-VICTOR-WHISKEY-ALPHA-PAPA-BRAVO-UNIFORM-BLAH-BLAH-BLAH-BLAH-BLAH-BLAH'', Tom said.
\end{document}