You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/hyphenate/scribblings/hyphenate.html

3 lines
36 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>Hyphenate</title><link rel="stylesheet" type="text/css" href="scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="racket.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-racket.css" title="default"/><script type="text/javascript" src="scribble-common.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="scribble-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_0&quot;);">&#9658;</a></td><td></td><td><a href="" class="tocviewselflink" data-pltdoc="x">Hyphenate</a></td></tr></table></div><div class="tocviewsublistonly" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1&nbsp;</td><td><a href="#%28part._.Installation%29" class="tocviewlink" data-pltdoc="x">Installation</a></td></tr><tr><td align="right">2&nbsp;</td><td><a href="#%28part._.Interface%29" class="tocviewlink" data-pltdoc="x">Interface</a></td></tr><tr><td align="right">3&nbsp;</td><td><a href="#%28part._.License___source_code%29" class="tocviewlink" data-pltdoc="x">License &amp; source code</a></td></tr></table></div></div></div><div class="tocsub"><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber"></span><a href="#%28part._.Hyphenate%29" class="tocsubseclink" data-pltdoc="x">Hyphenate</a></td></tr><tr><td><span class="tocsublinknumber">1<tt>&nbsp;</tt></span><a href="#%28part._.Installation%29" class="tocsubseclink" data-pltdoc="x">Installation</a></td></tr><tr><td><span class="tocsublinknumber">2<tt>&nbsp;</tt></span><a href="#%28part._.Interface%29" class="tocsubseclink" data-pltdoc="x">Interface</a></td></tr><tr><td><a href="#%28def._%28%28lib._hyphenate%2Fmain..rkt%29._hyphenate%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span></a></td></tr><tr><td><a href="#%28def._%28%28lib._hyphenate%2Fmain..rkt%29._hyphenatef%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenatef</span></span></span></a></td></tr><tr><td><a href="#%28def._%28%28lib._hyphenate%2Fmain..rkt%29._unhyphenate%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="badlink"><span class="RktValLink">unhyphenate</span></span></span></a></td></tr><tr><td><span class="tocsublinknumber">3<tt>&nbsp;</tt></span><a href="#%28part._.License___source_code%29" class="tocsubseclink" data-pltdoc="x">License &amp; source code</a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="versionbox"><span class="versionNoNav">6.0.0.1</span></div><h2><a name="(part._.Hyphenate)"></a>Hyphenate</h2><div class="SAuthorListBox"><span class="SAuthorList"><p class="author">Matthew Butterick &lt;<a href="mailto:mb@mbtype.com">mb@mbtype.com</a>&gt;</p></span></div><p>A simple hyphenation engine that uses the Knuth&#8211;Liang hyphenation algorithm originally developed for TeX. This implementation is a port of Ned Batchelder&rsquo;s <a href="http://nedbatchelder.com/code/modules/hyphenate.html">Python version</a>. I have added little to their work. Accordingly, I take little credit.</p><p>I originally put together this module to handle hyphenation for my web-based book <a href="http://practicaltypography.com">Butterick&rsquo;s Practical Typography</a> (which I made with <font class="badlink"><span class="techoutside"><span class="techinside">Racket</span></span></font> &amp; <font class="badlink"><span class="techoutside"><span class="techinside">Scribble</span></span></font>). Though support for CSS-based hyphenation in web browsers is <a href="http://caniuse.com/#search=hyphen">still iffy</a>, soft hyphens work reliably well. But putting them into the text manually is a drag. And thus a module was born.</p><h3>1<tt>&nbsp;</tt><a name="(part._.Installation)"></a>Installation</h3><p><div class="SIntrapara">At the command line:
</div><div class="SIntrapara"><table cellspacing="0"><tr><td><p><span class="stt">raco pkg install hyphenate</span></p></td></tr></table></div></p><h3>2<tt>&nbsp;</tt><a name="(part._.Interface)"></a><a name="(mod-path._hyphenate)"></a>Interface</h3><p><table cellspacing="0" class="defmodule"><tr><td align="left" colspan="2"><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">require</span></span></span><span class="stt"> </span><a href="#%28mod-path._hyphenate%29" class="RktModLink" data-pltdoc="x"><span class="RktSym">hyphenate</span></a><span class="RktPn">)</span></td></tr></table></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><table cellspacing="0" class="prototype RForeground"><tr><td><span class="RktPn">(</span><a name="(def._((lib._hyphenate/main..rkt)._hyphenate))"></a><span title="Provided from: hyphenate"><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span></span></td><td><span class="hspace">&nbsp;</span></td><td><span class="RktVar">text</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span>[</td><td><span class="RktVar">joiner</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="RktPn">#:exceptions</span><span class="hspace">&nbsp;</span><span class="RktVar">exceptions</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="RktPn">#:min-length</span><span class="hspace">&nbsp;</span><span class="RktVar">length</span>]<span class="RktPn">)</span></td><td><span class="hspace">&nbsp;</span></td><td>&rarr;</td><td><span class="hspace">&nbsp;</span></td><td><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span></td></tr></table></blockquote></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">text</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">joiner</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">or/c</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">char?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">integer-&gt;char</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">173</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">exceptions</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">listof</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span>=<span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">length</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">or/c</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">integer?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">false?</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span>=<span class="hspace">&nbsp;</span><span class="RktVal">5</span></td></tr></table></blockquote></div><div class="SIntrapara">Hyphenate <span class="RktVar">text</span> by calculating hyphenation points and inserting <span class="RktVar">joiner</span> at those points. By default, <span class="RktVar">joiner</span> is the soft hyphen (Unicode 00AD = decimal 173). Words shorter than <span class="RktPn">#:min-length</span>&#160;<span class="RktVar">length</span> will not be hyphenated. To hyphenate words of any length, use <span class="RktPn">#:min-length</span>&#160;<span class="RktVal">#f</span>.</div></p><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>The REPL displays a soft hyphen as \u00AD. But in ordinary use, you&rsquo;ll only see a soft hyphen when it appears at the end of a line or page as part of a hyphenated word. Otherwise it&rsquo;s not displayed. In most of the examples here, I use a standard hyphen for clarity.</p></blockquote></blockquote></blockquote><p><table cellspacing="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ergo polymorphic"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"ergo poly\u00ADmor\u00ADphic"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ergo polymorphic"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"ergo poly-mor-phic"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ergo polymorphic"</span><span class="hspace">&nbsp;</span><span class="RktPn">#:min-length</span><span class="hspace">&nbsp;</span><span class="RktVal">13</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"ergo polymorphic"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ergo polymorphic"</span><span class="hspace">&nbsp;</span><span class="RktPn">#:min-length</span><span class="hspace">&nbsp;</span><span class="RktVal">#f</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"er\u00ADgo poly\u00ADmor\u00ADphic"</span></p></td></tr></table></blockquote></td></tr></table></p><p>Because the hyphenation is based on an algorithm rather than a dictionary, it makes good guesses with unusual words:</p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"scraunched strengths"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"scraunched strengths"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"Racketcon"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"Rack-et-con"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"supercalifragilisticexpialidocious"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"su-per-cal-ifrag-ilis-tic-ex-pi-ali-do-cious"</span></p></td></tr></table></blockquote></td></tr></table></p><p>Using the <span class="RktPn">#:exceptions</span> keyword, you can pass hyphenation exceptions as a list of words with hyphenation points marked with regular hyphens (<span class="RktVal">"-"</span>). If an exception word contains no hyphens, that word will never be hyphenated.</p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"polymorphic"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"poly-mor-phic"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"polymorphic"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="hspace">&nbsp;</span><span class="RktPn">#:exceptions</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">(</span><span class="RktVal">"polymo-rphic"</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"polymo-rphic"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"polymorphic"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="hspace">&nbsp;</span><span class="RktPn">#:exceptions</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">(</span><span class="RktVal">"polymorphic"</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"polymorphic"</span></p></td></tr></table></blockquote></td></tr></table></p><p>Knuth &amp; Liang were sufficiently confident about their algorithm that they originally released it with only 14 exceptions: <span style="font-style: italic">associate[s], declination, obligatory, philanthropic, present[s], project[s], reciprocity, recognizance, reformation, retribution</span>, and <span style="font-style: italic">table</span>. Admirable bravado, but it&rsquo;s not hard to discover others.</p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"wrong: columns signage lawyers"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"wrong: columns sig-nage lawyers"</span></p></td></tr><tr><td><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"right: columns signage lawyers"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">#:exceptions</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">(</span><span class="RktVal">"col-umns"</span><span class="hspace">&nbsp;</span><span class="RktVal">"sign-age"</span><span class="hspace">&nbsp;</span><span class="RktVal">"law-yers"</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">"right: col-umns sign-age law-yers"</span></p></td></tr></table></blockquote></td></tr></table></p><p>Overall, my impression is that the Knuth&#8211;Liang algorithm is more likely to miss legitimate hyphenation points (i.e., generate false negatives) than create erroneous hyphenation points (i.e., false positives). This is good policy. Perfect hyphenation &#8212; that is, hyphenation that represents an exact linguistic syllabification of each word &#8212;&#160;is hardly useful in typesetting contexts. Hyphenation simply seeks to mark possible line-break and page-break locations for whatever layout engine is drawing the text. The ultimate goal is to permit more even text flow. Like horseshoes and hand grenades, close is good enough. And a word wrongly hyphenated is more likely noticed by a reader than a word inefficiently hyphenated.</p><p>For this reason, certain words can&rsquo;t be hyphenated algorithmically, because the correct hyphenation depends on meaning, not merely on spelling. For instance:</p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Example:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"adder"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"adder"</span></p></td></tr></table></blockquote></td></tr></table></p><p>This is the right result. If you used <span style="font-style: italic">adder</span> to mean the machine, it would be hyphenated <span style="font-style: italic">add-er</span>; if you meant the snake, it would be <span style="font-style: italic">ad-der</span>. Better to avoid hyphenation than to hyphenate incorrectly.</p><p>Don&rsquo;t send raw HTML through <span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span>. It can&rsquo;t distinguish HTML tags and attributes from textual content, so it will hyphenate everything, which will goof up your file.</p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Example:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"&lt;body style=\"background: yellow\"&gt;Hello world&lt;/body&gt;"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"&lt;body style=\"back\u00ADground: yel\u00ADlow\"&gt;Hel\u00ADlo world&lt;/body&gt;"</span></p></td></tr></table></blockquote></td></tr></table></p><p>Instead, send your textual content through <span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span> <span style="font-style: italic">before</span> you put it into your HTML template. Or convert your HTML to an <font class="badlink"><span class="techoutside"><span class="techinside">X-expression</span></span></font> and process it selectively (e.g., with <span class="RktSym"><span class="badlink"><span class="RktValLink">match</span></span></span>).</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><table cellspacing="0" class="prototype RForeground"><tr><td><span class="RktPn">(</span><a name="(def._((lib._hyphenate/main..rkt)._hyphenatef))"></a><span title="Provided from: hyphenate"><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenatef</span></span></span></span></td><td><span class="hspace">&nbsp;</span></td><td><span class="RktVar">text</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="RktVar">pred</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span>[</td><td><span class="RktVar">joiner</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="RktPn">#:exceptions</span><span class="hspace">&nbsp;</span><span class="RktVar">exceptions</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td><td><span class="hspace">&nbsp;</span></td><td><span class="RktPn">#:min-length</span><span class="hspace">&nbsp;</span><span class="RktVar">length</span>]<span class="RktPn">)</span></td><td><span class="hspace">&nbsp;</span></td><td>&rarr;</td><td><span class="hspace">&nbsp;</span></td><td><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span></td></tr></table></blockquote></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">text</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">pred</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">procedure?</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">joiner</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">or/c</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">char?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">integer-&gt;char</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">|#x00AD|</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">exceptions</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">listof</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span>=<span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">length</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">or/c</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">integer?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">false?</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span>=<span class="hspace">&nbsp;</span><span class="RktVal">5</span></td></tr></table></blockquote></div><div class="SIntrapara">Like <span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span>, but only words matching <span class="RktVar">pred</span> are hyphenated. Convenient if you want to prevent hyphenation of certain sets of words, like proper names:</div></p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"Brennan Huff likes fancy sauce"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"Bren-nan Huff likes fan-cy sauce"</span></p></td></tr><tr><td><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">uncapitalized?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">&#955;</span></span></span><span class="RktPn">(</span><span class="RktSym">word</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">let</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">letter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">substring</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">word</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">equal?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">letter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string-downcase</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">letter</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenatef</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"Brennan Huff likes fancy sauce"</span><span class="hspace">&nbsp;</span><span class="RktSym">uncapitalized?</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">"Brennan Huff likes fan-cy sauce"</span></p></td></tr></table></blockquote></td></tr></table></p><p>It&rsquo;s possible to do fancier kinds of hyphenation restrictions that take account of context, like not hyphenating the last word of a paragraph. But <span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenatef</span></span></span> only operates on words. So you&rsquo;ll have to write some fancier code. Separate out the hyphenatable words, and then send them through good old <span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span>.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._hyphenate/main..rkt)._unhyphenate))"></a><span title="Provided from: hyphenate"><span class="RktSym"><span class="badlink"><span class="RktValLink">unhyphenate</span></span></span></span><span class="hspace">&nbsp;</span><span class="RktVar">text</span><span class="hspace">&nbsp;</span>[<span class="RktVar">joiner</span>]<span class="RktPn">)</span><span class="hspace">&nbsp;</span>&rarr;<span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span></p></blockquote></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">text</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktVar">joiner</span><span class="hspace">&nbsp;</span>:<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">or/c</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">char?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">integer-&gt;char</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">173</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Remove <span class="RktVar">joiner</span> from <span class="RktVar">text</span> using <span class="RktSym"><span class="badlink"><span class="RktValLink">string-replace</span></span></span>.</div></p><p>A side effect of using <span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span> is that soft hyphens (or whatever the <span class="RktVar">joiner</span> is) will be embedded in the output text. If you need to support copying of text, for instance in a GUI application, you&rsquo;ll probably want to strip out the hyphenation before the copied text is moved to the clipboard.</p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ribbon-cutting ceremony"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"rib\u00ADbon-cut\u00ADting cer\u00ADe\u00ADmo\u00ADny"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">unhyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ribbon-cutting ceremony"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"ribbon-cutting ceremony"</span></p></td></tr></table></blockquote></td></tr></table></p><p>Use this function cautiously &#8212; if <span class="RktVar">joiner</span> appeared in the original input to <span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span>, the output from <span class="RktSym"><span class="badlink"><span class="RktValLink">unhyphenate</span></span></span> won&rsquo;t be the same string.</p><p><table cellspacing="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ribbon-cutting ceremony"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"rib-bon-cut-ting cer-e-mo-ny"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">unhyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">hyphenate</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ribbon-cutting ceremony"</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#\-</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"ribboncutting ceremony"</span></p></td></tr></table></blockquote></td></tr></table></p><h3>3<tt>&nbsp;</tt><a name="(part._.License___source_code)"></a>License &amp; source code</h3><p>This module is licensed under the LGPL.</p><p>Source repository at <a href="http://github.com/mbutterick/hyphenate">http://github.com/mbutterick/hyphenate</a>.</p></div></div><div id="contextindicator">&nbsp;</div></body></html>