7

In May 2012 user9588 answered:

\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}

Is it possible to construct a macro \printhyphs which does following:

\documentclass[12pt,a4paper]{article}

<hyphenfile = my-path/sillyhyphens.txt>

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

Running (pdf|xe)latex will create a file: my-path/sillyhyphens.txt, containing:

If you can- not
re- con- sid- er this pro- pos- al, you are
in- com- pat- i- ble, my dear- est friend.

Whether or not the -signs are followed by a space is irrelevant.

  • I don't think this is possible; hyphenation happens at a very late stage of processing, when TeX is preparing boxes for typesetting. If you use \showhyphens{<text>} the hyphens are shown in the .log file and you can filter it. – egreg Jul 7 '13 at 16:05
  • I need this for the syllables in a (large) text and I use showhyphens at the moment. But it does not work (properly) with xelatex and filtering them is problematic. When they can appear in the .log file, so why not in another? – Jack Jul 7 '13 at 16:18
  • @Jack The package xltxtra redefines \showhyphens so that it works also with XeTeX. – egreg Jul 7 '13 at 21:29
  • @egreg Yes, I know. But one has to feed the words separated by commas rather than spaces and, worse: the hypenated words do not appear together on one line but as separate (hyphenated) words, spread all over the .log file. This makes processing a bit cumbersome. – Jack Jul 7 '13 at 22:18
  • @Jack We don't add "Solved" to the title; rather, if an answer is helpful and solves (totally or mostly) the problem, the better way is to accept it, by clicking the check mark near the start of the answer's text. – egreg Jul 8 '13 at 23:17
6

A solution based on package soul. \printhyphs is implemented as soul driver that collects the syllables and hyphenation points in macro \printhyphs@line, which written into the output file at the end of \printhyphs in \SOUL@postamble:

\documentclass{article}
\usepackage{soul}

\makeatletter
\newwrite\printhyphs@out
\immediate\openout\printhyphs@out=sillyhyphens.txt\relax

\DeclareRobustCommand*{\printhyphs}{%
  \SOUL@setup
  \def\SOUL@preamble{%
    \global\let\printhyphs@line\@empty
  }%
  \def\SOUL@everyspace##1{%
    \g@addto@macro\printhyphs@line{ }%
  }%
  \def\SOUL@everysyllable{%
    \expandafter\g@addto@macro\expandafter\printhyphs@line
    \expandafter{\the\SOUL@syllable}%
  }%
  \def\SOUL@everyhyphen{%
    \g@addto@macro\printhyphs@line{- }%
  }%
  \def\SOUL@everyexhyphen##1{%
    \g@addto@macro\printhyphs@line{##1}%
  }%
  \def\SOUL@postamble{%
    \immediate\write\printhyphs@out{\printhyphs@line}%
  }%
  \SOUL@
}

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

File sillyhyphens.txt is written with the following lines:

If you can- not
re- con- sider this pro- posal, you are
in- com- pat- i- ble, my dear- est friend.
  • Heiko, this is terrific and what I hoped for. Is the "y- ou" the only anomaly? Do you have a sugestion on how to get rid of the "y- ou" other than with sed or awk? – Jack Jul 7 '13 at 22:23
  • @Jack: Answer fixed and the settings for \lefthyphenmin and \righthyphenmin removed. – Heiko Oberdiek Jul 7 '13 at 22:35
  • I just found out that I had to fiddle a bit with \lefthyphenmin and \righthyphenmin. Thanks again! – Jack Jul 7 '13 at 22:49
  • @Jack: Just remove them, then the values of the current language are used. They were a left over from the example driver in the documentation of soul. – Heiko Oberdiek Jul 7 '13 at 22:50
4

from time to time, a "hyphenation exception log" (update) is published in tugboat. the most recent was in vol.33, no.1. the full list, in the form of a tugboat article file, tb0hyf.tex, is posted to ctan along with its .pdf output as part of the hyphenex package.

a "showhyphens" routine is used to produce this list; the code is in the article .tex file, and should be able to be adapted to the purpose you have in mind.

  • Thanks Barbara, for you confirmation that it IS possible. The point is that I tried to adapt the \printhyphens in my org post, but my knowledge of TeX is far to limited. I could not even understand all the error messages that were thrown on my screen. I'll go after Heiko's hint. – Jack Jul 7 '13 at 22:30

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.