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

  • Some old TUGboat articles did it in a paragraph, I guess with Plain. Are those macros available somewhere? – jarnosz Jul 14 '17 at 19:27

Bing! Your wish has been granted.

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

| improve this answer | |
  • 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
  • 14
    @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
  • 1
    @Mico How do you tell tex the language? – cfr Dec 16 '14 at 3:13

Ok, here is the answer for printing the hyphens:

\def\rehbox{{\unskip\unpenalty\setbox0\lastbox\ifhbox0 \rehbox
    \hbox{\unhbox0} \else \leavevmode \fi}}
  \unvbox 0

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

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.

  \setbox0\hbox{\hbox{\unhbox2} \unhbox0}\expandafter\rehbox\fi}
  \unvbox 0

\printhyphens{If you cannot reconsider this proposal, you are
  incompatible, my dearest friend.}
| improve this answer | |
  • 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
  • 1
    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.

See http://texdoc.net/texmf-dist/doc/lualatex/showhyphens/showhyphens-doc.pdf

enter image description here

| improve this answer | |

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.

   \setbox0=\vbox\bgroup \noindent\hskip0pt\relax}
\def\setparams{\rightskip=0pt plus1fil
   \linepenalty=1000 \pretolerance=-1 \hyphenpenalty=-10000}
   \loop \setbox0=\lastbox \unskip \unpenalty
   \ifhbox0 % je už \vbox vyprázdněn?
   \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.

| improve this answer | |
  • Díky. – yo' Mar 9 '15 at 21:42

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.