12

This is a follow-up to tohecz's question, which I'm asking at the suggestion of Mico.

The original question asks how to discover the hyphenation points for particular words, and the answers explain how to do this in various ways and for various engines.

For example, user9588's answer introduces \showhyphens and Mico's comment explains how to use the command interactively.

So, here's a sample session:

$ tex
This is TeX, Version 3.14159265 (TeX Live 2014) (preloaded format=tex)
**\relax

*\showhyphens{un casgliad credadwy traddodiadau athroniaeth mathemateg canolfan hapusrwydd blwyddyn deuddeg llongyfarchiadau cyfeiriadau}

Underfull \hbox (badness 10000) detected at line 0
[] \tenrm un cas-gliad credadwy trad-do-di-adau athro-ni-aeth math-e-mateg cano
l-fan ha-pus-r-wydd blwyd-dyn deud-deg llongy-farchi-adau cyfeiri-adau

*\bye
(see the transcript file for additional information)
No pages of output.
Transcript written on texput.log.

Now, there is clearly a problem because these are not necessarily the correct hyphenation points. For example, dd is a single letter, yet TeX is splitting traddodiadau, blwyddyn and deuddeg in the middle of that letter.

The problem is not that the correct hyphenation patterns are unavailable:

Welsh hyphenation patterns

As can be seen, traddodiadau and deuddeg are split correctly in this output and, in general, the words are split at points which are not predicted by the sample session with \showhyphens.

The problem is that TeX needs to load the correct hyphenation patterns and to apply the correct set for the active language:

\documentclass[welsh,a6paper,twocolumn]{article}
\usepackage{babel}
\usepackage[hscale=.25]{geometry}
\begin{document}
    un casgliad credadwy traddodiadau athroniaeth mathemateg canolfan hapusrwydd blwyddyn deuddeg llongyfarchiadau cyfeiriadau
\end{document}

How can I display the possible hyphenation points for words in a language other than US English?

I've used a non-English example above, but the same question will also apply to other variants of English. For example, British hyphenation patterns differ from the American ones. (Compare the results of \showhyphens{favourite} and \showhyphens{favorite}, for example.)

  • Do you want a solution for plain? We are going to be a bit limited for Kunth's TeX as the format doesn't build in most of the hyphenation patterns. – Joseph Wright Dec 16 '14 at 19:14
  • 2
    \showhyphens can be used within a latex file, where you can easily set the desired language (presumably using babel). you'll just have to take the trouble to go through the extra step of creating a file and processing that. if you're going to be doing a lot of this over a long period of time, it might be worthwhile creating a language-specific format that could be used interactively, but it's been so long since i've done that, that i've forgotten how. – barbara beeton Dec 16 '14 at 19:34
10

You can use the testhyphens package.

\documentclass{article}
\usepackage[british,welsh]{babel}
\usepackage{testhyphens}

\begin{document}

\begin{checkhyphens}{}
un casgliad credadwy traddodiadau athroniaeth mathemateg canolfan
hapusrwydd blwyddyn deuddeg llongyfarchiadau cyfeiriadau
\end{checkhyphens}

\selectlanguage{british}

\begin{checkhyphens}{}
un casgliad credadwy traddodiadau athroniaeth mathemateg canolfan
hapusrwydd blwyddyn deuddeg llongyfarchiadau cyfeiriadau
\end{checkhyphens}

\end{document}

enter image description here

  • (+1) Thank you! I'd never heard of this. [Probably I should accept this but the number of answers so far makes me think I should wait just to see what people dream up!] – cfr Dec 16 '14 at 21:32
  • 2
    @cfr The advantage of this package is that it works also with XeLaTeX, while \showhyphens doesn't; you can load xltxtra, but the \showhyphens it defines has a different syntax (requires a comma separated list of words). – egreg Dec 16 '14 at 21:34
4

here's an adaptation of your file that will generate the hyphenations you seek:

\documentclass[welsh]{article}
\usepackage{babel}
\begin{document}
\showhyphens{un casgliad credadwy traddodiadau athroniaeth}

\showhyphens{mathemateg canolfan hapusrwydd blwyddyn}

\showhyphens{deuddeg llongyfarchiadau cyfeiriadau}

\end{document}

just process this with latex, and look in the log for the results:

Underfull \hbox (badness 10000) in paragraph at lines 7--7
[] \OT1/cmr/m/n/10 un casgl-iad cred-adwy tra-ddod-iadau athron-iaeth

\hbox(6.94444+1.94444)x16383.99998, glue set 1938.74178 []


Underfull \hbox (badness 10000) in paragraph at lines 9--9
[] \OT1/cmr/m/n/10 math-emateg canol-fan hapus-rwydd blwyddyn

\hbox(6.94444+1.94444)x16383.99998, glue set 2425.43556 []


Underfull \hbox (badness 10000) in paragraph at lines 11--11
[] \OT1/cmr/m/n/10 deu-ddeg llon-gy-farch-iadau cyf-eir-iadau

\hbox(6.94444+1.94444)x16383.99998, glue set 3240.64192 []
  • (+1) Thanks. Is there a way to not have to go through the log file to find these? The interactive method suggested to Mico was a response to somebody asking this in the 'standard' case, so I was hoping for a similar solution for other languages. – cfr Dec 16 '14 at 19:48
  • 1
    @cfr You can run LaTeX interactively too :-) See my updated answer: a bit tedious to have to type in the first couple of lines. – Joseph Wright Dec 16 '14 at 19:58
  • @JosephWright Thanks. I used that just because it seemed a really easy and straightforward method. Sorry if I wasn't clear. – cfr Dec 16 '14 at 20:54
4

Assuming you are using a plain-like format with the babel hyphenation patterns available (so say pdftex or xetex) you can switch to the correct hyphenation using the fact that \lang@<name> is the language number. Thus

\language\csname lang@welsh\endcsname
\showhyphens{un casgliad credadwy traddodiadau athroniaeth mathemateg canolfan hapusrwydd blwyddyn deuddeg llongyfarchiadau cyfeiriadau}
\bye

gives

[] \tenrm un casgl-iad cred-adwy tra-ddod-iadau athron-iaeth math-emateg canol-
fan hapus-rwydd blwyddyn deu-ddeg llon-gy-farch-iadau cyf-eir-iadau

If you want to use LaTeX then you want \l@<name> rather than \lang@<name>, plus you need at least the start of a document

\documentclass{article}
\begin{document}
\language\csname l@welsh\endcsname
\showhyphens{un casgliad credadwy traddodiadau athroniaeth mathemateg canolfan hapusrwydd blwyddyn deuddeg llongyfarchiadau cyfeiriadau}
  • (+1) Thanks. I'm actually using pdfLaTeX (mostly). But I don't care if I need to use something different to get the patterns. – cfr Dec 16 '14 at 19:50
  • 1
    Well your example was plain so I went with that: \lang@... is not defined for LaTeX, but you could use \l@... if you want to avoid the 'full fat' of loading babel just for an interactive test – Joseph Wright Dec 16 '14 at 19:55
  • 2
    for latex, you could create a dummy input file, ending before entering \showhyphens. i'd be inclined to add a note that will type out, something like \message{Enter words in braces, beginning with \string\showhyphens and finish with \string\end\string{document\string} when you are done. The results will be preserved in your log file.}. i'm sure this can be made spiffier, to show just the actual words with hyphens; i'll dig into my "exception list" tugboat article, but not right away. – barbara beeton Dec 16 '14 at 21:17

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.