Difference between revisions of "Documentation/SL/Using TeX hyphenation patterns in OpenOffice.org"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 25: Line 25:
 
The following conversion process must be followed step-by-step:
 
The following conversion process must be followed step-by-step:
  
1. Download up-to-date TeX hyphenation patterns
+
===1. Download up-to-date TeX hyphenation patterns===
 
[http://tug.org/tex-hyphen/ Tex hyphenation] repository contains up-to-date TeX hyphenation patterns. They are located here:
 
[http://tug.org/tex-hyphen/ Tex hyphenation] repository contains up-to-date TeX hyphenation patterns. They are located here:
 +
 
http://tug.org/svn/texhyphen/trunk/hyph-utf8/
 
http://tug.org/svn/texhyphen/trunk/hyph-utf8/
  
 
Example: for Slovenian language one would download file hyph-sl.pat.txt from the SVN repository.
 
Example: for Slovenian language one would download file hyph-sl.pat.txt from the SVN repository.
  
2. Convert TeX hyphenation patterns file into proper character set
+
===2. Convert TeX hyphenation patterns file into proper character set===
 
Hyphen for OpenOffice.org (prior to version 3.4) uses ISO-8859-X code-pages while TeX hyphenation patterns are in UTF-8. So conversion of downloaded patterns into right ISO-8859-X code-page is necessary.
 
Hyphen for OpenOffice.org (prior to version 3.4) uses ISO-8859-X code-pages while TeX hyphenation patterns are in UTF-8. So conversion of downloaded patterns into right ISO-8859-X code-page is necessary.
  
 
Example: Slovenian language uses ISO-8859-2 code-page, so one would open the UTF-8 file in a code-page savvy text editor and convert&save it into ISO-8859-2 code-page.
 
Example: Slovenian language uses ISO-8859-2 code-page, so one would open the UTF-8 file in a code-page savvy text editor and convert&save it into ISO-8859-2 code-page.
  
3. Run the substrings.pl conversion script
+
===3. Run the substrings.pl conversion script===
 
Hyphen library (based on libhnj from Raph Levien) uses a time optimized implementation of the [http://tug.org/docs/liang/ original Liang's algorithm of TeX], and substring.pl conversion is a requirement of this implementation. You can download the latest version of substrings.pl conversion script from [http://sourceforge.net/projects/hunspell/files/Hyphen the Hyphen repository]. At the time of writing this was:
 
Hyphen library (based on libhnj from Raph Levien) uses a time optimized implementation of the [http://tug.org/docs/liang/ original Liang's algorithm of TeX], and substring.pl conversion is a requirement of this implementation. You can download the latest version of substrings.pl conversion script from [http://sourceforge.net/projects/hunspell/files/Hyphen the Hyphen repository]. At the time of writing this was:
 +
 
http://sourceforge.net/projects/hunspell/files/Hyphen/2.5/hyphen-2.5.tar.gz/download hyphen-2.5.tar.gz
 
http://sourceforge.net/projects/hunspell/files/Hyphen/2.5/hyphen-2.5.tar.gz/download hyphen-2.5.tar.gz
  
Line 43: Line 45:
  
 
Example: for Slovenian the ISO-8859-2 code page is used and left and right hyphenmin values are 2. So one would use:
 
Example: for Slovenian the ISO-8859-2 code page is used and left and right hyphenmin values are 2. So one would use:
 
+
<pre>./substrings.pl hyph-sl.pat.txt hyph_sl_SI.dic ISO8859-2 2 2</pre>
./substrings.pl hyph-sl.pat.txt hyph_sl_SI.dic ISO8859-2 2 2
+
  
 
Warning: note how ISO8859-2 is used and not ISO-8859-2! Remember to omit the first hyphen in the ISO-2 codepage name!
 
Warning: note how ISO8859-2 is used and not ISO-8859-2! Remember to omit the first hyphen in the ISO-2 codepage name!
  
4. Add hyphenation rules for special characters
+
===4. Add hyphenation rules for special characters===
 
Special characters (apostrophe, hyphen, n-dash, m-dash ...) are word characters in OpenOffice.org, but not boundary characters in the hyphenation of OpenOffice.org which is an incompatibility with the TeX boundary hyphenation patterns. It results in potentially bad hyphenation for words with hyphens and other special characters. Please consider adding the following lines at the end of the converted hyphenation patterns file (.dat):  
 
Special characters (apostrophe, hyphen, n-dash, m-dash ...) are word characters in OpenOffice.org, but not boundary characters in the hyphenation of OpenOffice.org which is an incompatibility with the TeX boundary hyphenation patterns. It results in potentially bad hyphenation for words with hyphens and other special characters. Please consider adding the following lines at the end of the converted hyphenation patterns file (.dat):  
 
<pre>
 
<pre>
Line 63: Line 64:
 
Note: "<pre>...</pre>" represents all missing lines for other characters of your alphabet.
 
Note: "<pre>...</pre>" represents all missing lines for other characters of your alphabet.
  
5. Create the appropriate readme file
+
===5. Create/update the appropriate readme file===
 
The readme file contains the credits and licensing information.
 
The readme file contains the credits and licensing information.
  
Line 72: Line 73:
 
The hyphenation patterns that are included in the official OpenOffice.org builds require also the filled-in http://external.openoffice.org/ form data.
 
The hyphenation patterns that are included in the official OpenOffice.org builds require also the filled-in http://external.openoffice.org/ form data.
  
6. Create an OpenOffice.org dictionary extension
+
===6. Create/update an OpenOffice.org dictionary extension===
 
Package the converted hyphenation patterns in a OpenOffice.org extension and upload it to the OOo extension repository.
 
Package the converted hyphenation patterns in a OpenOffice.org extension and upload it to the OOo extension repository.
  

Revision as of 13:24, 23 July 2010

Summary: this document describes how to use TeX hyphenation patterns in OpenOffice.org.

Written by Martin Srebotnjak; some portions of text contributed by László Németh and Mojca Miklavec.

Introduction

OpenOffice.org uses Hyphen, part of the Hunspell project, as its hyphenation engine.

The hyphenation files are represented by two files:

  • the patterns file (a text file with all the patterns and extra hyphenation rules; hyph_xx_YY.dic) and
  • the readme file (a text file with all the credits and licensing information; README_hyph_xx_YY.txt).

The language descriptor xx_YY is ISO-code, you can look it up in the following table: http://wiki.services.openoffice.org/wiki/Languages

From OpenOffice.org 3.0 onwards the hyphenation patterns are packed as an OpenOffice.org extension, usually as a part of a dictionary language pack (with a spell-checking dictionary for the same language and, optionally, a thesaurus). A list of dictionary language packs is available here: http://extensions.services.openoffice.org/en/dictionaries

Using Tex patterns

Hyphen (and OpenOffice.org) can use TeX hyphenation patters for hyphenation, which is great, because TeX patterns are available for more than 50 different languages.

But because of differences between TeX hyphenation and Hyphen the TeX hyphenation patterns must be first converted. If conversion is not applied, several issues can surface:

  • not all TeX patterns will work in OpenOffice.org - which means that TeX patterns will perform substandardly in OpenOffice.org;
  • if code-page is not set correctly the TeX patterns can behave erratically in OpenOffice.org;

Conversion of TeX patterns

The following conversion process must be followed step-by-step:

1. Download up-to-date TeX hyphenation patterns

Tex hyphenation repository contains up-to-date TeX hyphenation patterns. They are located here:

http://tug.org/svn/texhyphen/trunk/hyph-utf8/

Example: for Slovenian language one would download file hyph-sl.pat.txt from the SVN repository.

2. Convert TeX hyphenation patterns file into proper character set

Hyphen for OpenOffice.org (prior to version 3.4) uses ISO-8859-X code-pages while TeX hyphenation patterns are in UTF-8. So conversion of downloaded patterns into right ISO-8859-X code-page is necessary.

Example: Slovenian language uses ISO-8859-2 code-page, so one would open the UTF-8 file in a code-page savvy text editor and convert&save it into ISO-8859-2 code-page.

3. Run the substrings.pl conversion script

Hyphen library (based on libhnj from Raph Levien) uses a time optimized implementation of the original Liang's algorithm of TeX, and substring.pl conversion is a requirement of this implementation. You can download the latest version of substrings.pl conversion script from the Hyphen repository. At the time of writing this was:

http://sourceforge.net/projects/hunspell/files/Hyphen/2.5/hyphen-2.5.tar.gz/download hyphen-2.5.tar.gz

The script takes the following parameters: the input file name, the output file name, the code-page setting and the LEFTHYPHENMIN and RIGHTHYPHEMIN values that define the minimum left and right length of hyphenated words.

Example: for Slovenian the ISO-8859-2 code page is used and left and right hyphenmin values are 2. So one would use:

./substrings.pl hyph-sl.pat.txt hyph_sl_SI.dic ISO8859-2 2 2

Warning: note how ISO8859-2 is used and not ISO-8859-2! Remember to omit the first hyphen in the ISO-2 codepage name!

4. Add hyphenation rules for special characters

Special characters (apostrophe, hyphen, n-dash, m-dash ...) are word characters in OpenOffice.org, but not boundary characters in the hyphenation of OpenOffice.org which is an incompatibility with the TeX boundary hyphenation patterns. It results in potentially bad hyphenation for words with hyphens and other special characters. Please consider adding the following lines at the end of the converted hyphenation patterns file (.dat):

8-8
8a8-8
8b8-8
8c8-8
...
-a8
-b8
-c8
...
Note: "
...
" represents all missing lines for other characters of your alphabet.

5. Create/update the appropriate readme file

The readme file contains the credits and licensing information.

Official TeX hyphenation patterns are released under the GNU Lesser General Public License (LGPL) which makes them appropriate for inclusion into OpenOffice.org.

If you use TeX hyphenation patterns from other source remember to note the license they are available under in the readme file.

The hyphenation patterns that are included in the official OpenOffice.org builds require also the filled-in http://external.openoffice.org/ form data.

6. Create/update an OpenOffice.org dictionary extension

Package the converted hyphenation patterns in a OpenOffice.org extension and upload it to the OOo extension repository.

Try extensively if it works properly in OpenOffice.org.

If the patterns perform well and the patterns are licensed under LGPL, the patterns could make it into the official releases of OpenOffice.org.

The future

With OpenOffice.org 3.4 support for UTF-8 patters will be introduced, which would make the Step 2 (from above) obsolete and change the conversion line from Step 3 into:

./substrings.pl hyph-sl.pat.txt hyph_sl_SI.dic UTF-8 2 2

But patterns in UTF-8 will not work with older OpenOffice.org versions (prior to 3.4). However, if you do decide to make an extension version with hyphenation patterns for OOo in UTF-8, do not forget to set the required version of OpenOffice.org in the extension description.xml to 3.4 or higher, like this (so that older version of OpenOffice.org can use the non-UTF-8 version of your extension):

    <dependencies>
        <OpenOffice.org-minimal-version value="3.4" d:name="OpenOffice.org 3.4" />
    </dependencies>

Conclusion

Since Hyphen/Hunspell is used also by other open-source software projects (as well as the OpenOffice.org hyphenation patterns files), following these instructions will provide correct patterns for programs like ...

See also

Automatic non-standard hyphenation in OpenOffice.org by László Németh

Personal tools