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.

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

share|improve this question
add comment

3 Answers

up vote 29 down vote accepted

Bing! Your wish has been granted.

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

share|improve this answer
    
Unbelievable! Still, I'm curious if someone has a solution that avoids the need to check the log file. –  tohecz May 10 '12 at 15:02
9  
@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!) –  tohecz 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
add comment

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

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

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

enter image description here

share|improve this answer
    
+1, and I can't understand how I overlooked this one. –  lockstep Apr 9 '13 at 19:08
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.