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

hyphenation.xml 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- $Id$ -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
  18. <document>
  19. <header>
  20. <title>Apache™ FOP: Hyphenation</title>
  21. <version>$Revision$</version>
  22. </header>
  23. <body>
  24. <section id="support">
  25. <title>Hyphenation Support</title>
  26. <section id="intro">
  27. <title>Introduction</title>
  28. <p>Apache™ FOP uses Liang's hyphenation algorithm, well known from TeX. It needs
  29. language specific pattern and other data for operation.</p>
  30. <p>Because of <a href="#license-issues">licensing issues</a> (and for
  31. convenience), all hyphenation patterns for FOP are made available through
  32. the <a class="fork" href="http://offo.sourceforge.net/hyphenation/index.html">Objects For
  33. Formatting Objects</a> project.</p>
  34. <note>If you have made improvements to an existing Apache™ FOP hyphenation pattern,
  35. or if you have created one from scratch, please consider contributing these
  36. to OFFO so that they can benefit other FOP users as well.
  37. Please inquire on the <a href="../maillist.html#fop-user">FOP User
  38. mailing list</a>.</note>
  39. </section>
  40. <section id="license-issues">
  41. <title>License Issues</title>
  42. <p>Many of the hyphenation files distributed with TeX and its offspring are
  43. licenced under the <a class="fork" href="http://www.latex-project.org/lppl.html">LaTeX
  44. Project Public License (LPPL)</a>, which prevents them from being
  45. distributed with Apache software. The LPPL puts restrictions on file names
  46. in redistributed derived works which we feel can't guarantee. Some
  47. hyphenation pattern files have other or additional restrictions, for
  48. example against use for commercial purposes.</p>
  49. <p>Although Apache FOP cannot redistribute hyphenation pattern files that do
  50. not conform with its license scheme, that does not necessarily prevent users
  51. from using such hyphenation patterns with FOP. However, it does place on
  52. the user the responsibility for determining whether the user can rightly use
  53. such hyphenation patterns under the hyphenation pattern license.</p>
  54. <warning>The user is responsible to settle license issues for hyphenation
  55. pattern files that are obtained from non-Apache sources.</warning>
  56. </section>
  57. <section id="sources">
  58. <title>Sources of Custom Hyphenation Pattern Files</title>
  59. <p>The most important source of hyphenation pattern files is the
  60. <a class="fork" href="http://www.ctan.org/tex-archive/language/hyphenation/">CTAN TeX
  61. Archive</a>.</p>
  62. </section>
  63. <section id="install">
  64. <title>Installing Custom Hyphenation Patterns</title>
  65. <p>To install a custom hyphenation pattern for use with FOP:</p>
  66. <ol>
  67. <li>Convert the TeX hyphenation pattern file to the FOP format. The FOP
  68. format is an xml file conforming to the DTD found at
  69. <code>{fop-dir}/hyph/hyphenation.dtd</code>.</li>
  70. <li>Name this new file following this schema:
  71. <code>languageCode_countryCode.xml</code>. The country code is
  72. optional, and should be used only if needed. For example:
  73. <ul>
  74. <li><code>en_US.xml</code> would be the file name for American
  75. English hyphenation patterns.</li>
  76. <li><code>it.xml</code> would be the file name for Italian
  77. hyphenation patterns.</li>
  78. </ul>
  79. The language and country codes must match the XSL-FO input, which
  80. follows <a href="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt">ISO
  81. 639</a> (languages) and <a href="http://www.ics.uci.edu/pub/ietf/http/related/iso3166.txt">ISO
  82. 3166</a> (countries). NOTE: The ISO 639/ISO 3166 convention is that
  83. language names are written in lower case, while country codes are written
  84. in upper case. FOP does not check whether the language and country specified
  85. in the FO source are actually from the current standard, but it relies
  86. on it being two letter strings in a few places. So you can make up your
  87. own codes for custom hyphenation patterns, but they should be two
  88. letter strings too (patches for proper handling extensions are welcome)</li>
  89. <li>There are basically three ways to make the FOP-compatible hyphenation pattern
  90. file(s) accessible to FOP:
  91. <ul>
  92. <li>Download the precompiled JAR from <a class="fork" href="http://offo.sourceforge.net/hyphenation/index.html">OFFO
  93. </a> and place it either in the <code>{fop-dir}/lib</code> directory, or
  94. in a directory of your choice (and append the full path to the JAR to
  95. the environment variable <code>FOP_HYPHENATION_PATH</code>).</li>
  96. <li>Download the desired FOP-compatible hyphenation pattern file(s) from
  97. <a class="fork" href="http://offo.sourceforge.net/hyphenation/index.html">OFFO</a>,
  98. and/or take your self created hyphenation pattern file(s),
  99. <ul>
  100. <li>place them in the directory <code>{fop-dir}/hyph</code>, </li>
  101. <li>or place them in a directory of your choice and set the Ant variable
  102. <code>user.hyph.dir</code> to point to that directory (in
  103. <code>build-local.properties</code>),</li>
  104. </ul>
  105. and run Ant with build target
  106. <code>jar-hyphenation</code>. This will create a JAR containing the
  107. compiled patterns in <code>{fop-dir}/build</code> that will be added to the
  108. classpath on the next run.
  109. (When FOP is built from scratch, and there are pattern source file(s)
  110. present in the directory pointed to by the
  111. <code>user.hyph.dir</code> variable, this JAR will automatically
  112. be created from the supplied pattern(s)).</li>
  113. <li>Put the pattern source file(s) into a directory of your choice and
  114. configure FOP to look for custom patterns in this directory, by setting the
  115. <a href="configuration.html">&lt;hyphenation-base&gt;</a>
  116. configuration option.</li>
  117. </ul>
  118. </li>
  119. </ol>
  120. <warning>
  121. Either of these three options will ensure hyphenation is working when using
  122. FOP from the command-line. If FOP is being embedded, remember to add the location(s)
  123. of the hyphenation JAR(s) to the CLASSPATH (option 1 and 2) or to set the
  124. <a href="configuration.html#hyphenation-dir">&lt;hyphenation-dir&gt;</a>
  125. configuration option programmatically (option 3).
  126. </warning>
  127. </section>
  128. </section>
  129. <section id="patterns">
  130. <title>Hyphenation Patterns</title>
  131. <p>If you would like to build your own hyphenation pattern files, or modify
  132. existing ones, this section will help you understand how to do so. Even
  133. when creating a pattern file from scratch, it may be beneficial to start
  134. with an existing file and modify it. See <a class="fork" href="http://offo.sourceforge.net/hyphenation/index.html">
  135. OFFO's Hyphenation page</a> for examples.
  136. Here is a brief explanation of the contents of FOP's hyphenation patterns:</p>
  137. <warning>The remaining content of this section should be considered "draft"
  138. quality. It was drafted from theoretical literature, and has not been
  139. tested against actual FOP behavior. It may contain errors or omissions.
  140. Do not rely on these instructions without testing everything stated here.
  141. If you use these instructions, please provide feedback on the
  142. <a href="../maillist.html#fop-user">FOP User mailing list</a>, either
  143. confirming their accuracy, or raising specific problems that we can
  144. address.</warning>
  145. <ul>
  146. <li>The root of the pattern file is the &lt;hyphenation-info&gt; element.</li>
  147. <li>&lt;hyphen-char&gt;: its attribute "value" contains the character signalling
  148. a hyphen in the &lt;exceptions&gt; section. It has nothing to do with the
  149. hyphenation character used in FOP, use the XSLFO hyphenation-character
  150. property for defining the hyphenation character there. At some points
  151. a dash U+002D is hardwired in the code, so you'd better use this too
  152. (patches to rectify the situation are welcome). There is no default,
  153. if you declare exceptions with hyphenations, you must declare the
  154. hyphen-char too.</li>
  155. <li>&lt;hyphen-min&gt; contains two attributes:
  156. <ul>
  157. <li>before: the minimum number of characters in a word allowed to exist
  158. on a line immediately preceding a hyphenated word-break.</li>
  159. <li>after: the minimum number of characters in a word allowed to exist
  160. on a line immediately after a hyphenated word-break.</li>
  161. </ul>
  162. This element is unused and not even read. It should be considered a
  163. documentation for parameters used during pattern generation.
  164. </li>
  165. <li>&lt;classes&gt; contains whitespace-separated character sets. The members
  166. of each set should be treated as equivalent for purposes of hyphenation,
  167. usually upper and lower case of the same character. The first character
  168. of the set is the canonical character, the patterns and exceptions
  169. should only contain these canonical representation characters (except
  170. digits for weight, the period (.) as word delimiter in the patterns and
  171. the hyphen char in exceptions, of course).</li>
  172. <li>&lt;exceptions&gt; contains whitespace-separated words, each of which
  173. has either explicit hyphen characters to denote acceptable breakage
  174. points, or no hyphen characters, to indicate that this word should
  175. never be hyphenated, or contain explicit &lt;hyp&gt; elements for specifying
  176. changes of spelling due to hyphenation (like backen -&gt; bak-ken or
  177. Stoffarbe -&gt; Stoff-farbe in the old german spelling). Exceptions override
  178. the patterns described below. Explicit &lt;hyp&gt; declarations don't work
  179. yet (patches welcome). Exceptions are generally a bit brittle, test
  180. carefully.</li>
  181. <li>&lt;patterns&gt; includes whitespace-separated patterns, which are what
  182. drive most hyphenation decisions. The characters in these patterns are
  183. explained as follows:
  184. <ul>
  185. <li>non-numeric characters represent characters in a sub-word to be
  186. evaluated</li>
  187. <li>the period character (.) represents a word boundary, i.e. either
  188. the beginning or ending of a word</li>
  189. <li>numeric characters represent a scoring system for indicating the
  190. acceptability of a hyphen in this location. Odd numbers represent an
  191. acceptable location for a hyphen, with higher values overriding lower
  192. inhibiting values. Even numbers indicate an unacceptable location, with
  193. higher values overriding lower values indicating an acceptable position.
  194. A value of zero (inhibiting) is implied when there is no number present.
  195. Generally patterns are constructed so that valuse greater than 4 are rare.
  196. Due to a bug currently patterns with values of 8 and greater don't
  197. have an effect, so don't wonder.</li>
  198. </ul>
  199. Here are some examples from the English patterns file:
  200. <ul>
  201. <li>Knuth (<em>The TeXBook</em>, Appendix H) uses the example <strong>hach4</strong>, which indicates that it is extremely undesirable to place a hyphen after the substring "hach", for example in the word "toothach-es".</li>
  202. <li><strong>.leg5e</strong> indicates that "leg-e", when it occurs at the beginning of a word, is a very good place to place a hyphen, if one is needed. Words like "leg-end" and "leg-er-de-main" fit this pattern.</li>
  203. </ul>
  204. Note that the algorithm that uses this data searches for each of the word's substrings in the patterns, and chooses the <em>highest</em> value found for letter combination.
  205. </li>
  206. </ul>
  207. <p>If you want to convert a TeX hyphenation pattern file, you have to undo
  208. the TeX encoding for non-ASCII text. FOP uses Unicode, and the patterns
  209. must be proper Unicode too. You should be aware of the XML encoding issues,
  210. preferably use a good Unicode editor.</p>
  211. <p>Note that FOP does not do Unicode character normalization. If you use
  212. combining chars for accents and other character decorations, you must
  213. declare character classes for them, and use the same sequence of base character
  214. and combining marks in the XSLFO source, otherwise the pattern wouldn't match.
  215. Fortunately, Unicode provides precomposed characters for all important cases
  216. in common languages, until now nobody run seriously into this issue. Some dead
  217. languages and dialects, especially ancient ones, may pose a real problem
  218. though.</p>
  219. <p>If you want to generate your own patterns, an open-source utility called
  220. patgen can be used to assist in creating pattern files from dictionaries.
  221. It is available in many Unix/Linux distributions and every TeX distribution.
  222. Pattern creation for languages like english or german is an art. Read
  223. Frank Liang's original paper <a class="fork" href="http://www.tug.org/docs/liang/">"Word
  224. Hy-phen-a-tion by Com-pu-ter"</a> (yes, with hyphens) for details.
  225. The original patgen.web source, included in the TeX source distributions,
  226. contains valuable comments, unfortunately technical details often obscure the
  227. high level issues. Another important source of information is
  228. <a class="fork" href="http://mirrors.ctan.org/systems/knuth/dist/tex/texbook.tex">The
  229. TeX Book</a>, appendix H (either read the TeX source, or run it through
  230. TeX to typeset it). Secondary articles, for example the works by Petr Sojka,
  231. may also give some much needed insight into problems arising in automated
  232. hyphenation.</p>
  233. </section>
  234. </body>
  235. </document>