# Display hyphenation options for a specific word

When TeX produces Overfull box, is puts something like this in the log:

Overfull \hbox (15.47195pt too wide) in paragraph at lines 7--9
[]\OT1/cmr/m/n/10 I re-ally re-ally want to get dis-played the op-tions for
hy-phen-ation xxxxxxxxxxxxxx |


I would like a macro \showhyphens that would for an entry like \showhyphens{hyphenation} display its hyphenation options, i.e. hy-phen-ation. This should be displayed either in the document (preferred) or in the log.

(Background: I need this for sumbitting a paper that contains many multi-part words and similar stuff like $(2,3)$-representation etc. I know that there are ways to modify - with \discretionary to make the word breakable, but it makes the code extremly unreadable and I'm not allowed to make this a macro definition.)

-

## 4 Answers

Bing! Your wish has been granted.

Seriously: \showhyphens already exists under that exact same name.

-
Unbelievable! Still, I'm curious if someone has a solution that avoids the need to check the log file. –  yo' May 10 '12 at 15:02
@tohecz -- I tend to use the \showhyphens tool interactively (using the steps listed in the TeXBook): First, type tex (not latex) in an open command window, and you'll get a ** prompt; at the ** prompt type \relax, and you'll get a * (single-asterisk) prompt. At the * prompt, type \showhyphens{hyphenation} (or whatever words you're interested in) and watch TeX's output. Whey you're done, type \bye to exit TeX. :-) On your second observation: I'm not aware of a variant of the \showhyphens command that does not write its output to the log file. –  Mico May 10 '12 at 15:28
@Mico sounds great! That is the solution I wanted. (I did not think it's TeX command not LaTeX and even though I'm aware of the interactive mode, this usage of it is hilarious!) –  yo' May 10 '12 at 15:45
Note that \showhyphens won't work with XeLaTeX if the current font is an OpenType one. The package xltxtra redefines the command, but the words must be separated by commas, rather than spaces. –  egreg May 10 '12 at 16:08
@Mico How do you tell tex the language? –  cfr Dec 16 '14 at 3:13

Ok, here is the answer for printing the hyphens:

\documentclass[12pt,a4paper]{article}
\def\rehbox{{\unskip\unpenalty\setbox0\lastbox\ifhbox0 \rehbox
\hbox{\unhbox0} \else \leavevmode \fi}}
\newcommand\printhyphens[1]{%
\setbox0\vbox{{%
\pretolerance-1\hsize=0pt\hfuzz=\maxdimen
\noindent\hspace*{0pt}#1\par\rehbox}\par}%
\unvbox 0
}

\begin{document}
\printhyphens{If you cannot reconsider this proposal, you are
incompatible, my dearest friend.}
\end{document}


As the first version is limited by its usage of the save stack, here is a version that isn't. However, as stated in the comments, it is O(n^3), so it will become inefficient for large arguments rather fast, and the whole point of not using the save stack is to be able to use large arguments. So it would really make more sense to first split the input into words or lines and process them one by one, using a call of the first version of \printhyphens.

\documentclass[12pt,a4paper]{article}
\def\rehbox{\unskip\unpenalty\setbox2\lastbox\ifhbox2
\setbox0\hbox{\hbox{\unhbox2} \unhbox0}\expandafter\rehbox\fi}
\newcommand\printhyphens[1]{%
\setbox0\vbox{{\setbox0\hbox{}%
\pretolerance-1\hsize=0pt\hfuzz=\maxdimen
\noindent\hspace*{0pt}#1\par\rehbox\unhbox0}\par}%
\unvbox 0
}

\begin{document}
\printhyphens{If you cannot reconsider this proposal, you are
incompatible, my dearest friend.}
\end{document}

-
This is a great little program! However, if there are more than about 140 words in the argument of the \printhyphen statement, the program crashes with a "TeX capacity exceeded, sorry [grouping levels = 255]" message. Is there a way to make the \rehbox statement non-recursive? –  Mico May 10 '12 at 20:14
Not without a complete rewrite with a huge loss of performance (instead of storing the boxes on the save stack, about O(n), you would have to append them to a global box, O(n^3)). It would likely make more sense to feed it one word at a time. Which reminds me: you might need \hspace*{0pt} after \noindent to have the first word hyphenated as well. –  user9588 May 11 '12 at 12:27
Thanks, David. I suspected there was a very good reason you'd implemented the program the way you did! –  Mico May 11 '12 at 13:19
The documentation (version 2.19) of the soul package contains yet another method in section 7.3: mirror.unl.edu/ctan/macros/latex/contrib/soul/soul.pdf –  Lover of Structure Feb 19 '13 at 11:07

With LuaTeX you have two options: \usepackage{lua-visual-debug} gives a lot of information whereas \usepackage{showhyphens} marks only all possible hyphenation points.

-
+1, and I can't understand how I overlooked this one. –  lockstep Apr 9 '13 at 19:08

Because I know that OP (yo) understand Czech then I can refer the book "TeXbook naruby" (full text available on the internet here), page 225 below and page 226. The macro \showhyphenpar is presented here. The paragraph after \showhyphenpar is printed with all words shown as hy-phen-ated.

\def\showhyphenpar{\bgroup
\def\par{\setparams\endgraf\composelines}
\setbox0=\vbox\bgroup \noindent\hskip0pt\relax}
\def\setparams{\rightskip=0pt plus1fil
\linepenalty=1000 \pretolerance=-1 \hyphenpenalty=-10000}
\def\composelines{\setbox2=\hbox{}%
\loop \setbox0=\lastbox \unskip \unpenalty
\ifhbox0 % je už \vbox vyprázdněn?
\global\setbox2=\hbox{\unhbox0\unskip\unhbox2}
\repeat
\egroup % vyprázdněný \vbox ukončím
\exhyphenpenalty=10000 % \box2 vyšoupnu do vnějšího seznamu
\emergencystretch=4em \leavevmode\unhbox2 \endgraf\egroup}


The principles of this macro is described in the TeXbook naruby.

-
Díky. –  yo' Mar 9 at 21:42