| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% This is a module for hyphenation patterns loading for LuaTeX. It is under |
| 4 |
% the CC0 license (http://creativecommons.org/publicdomain/zero/1.0/). |
| 5 |
% |
| 6 |
%<*ignore> |
| 7 |
\begingroup |
| 8 |
\def\x{LaTeX2e}% |
| 9 |
\expandafter\endgroup |
| 10 |
\ifcase 0\ifx\install y1\fi\expandafter |
| 11 |
\ifx\csname processbatchFile\endcsname\relax\else1\fi |
| 12 |
\ifx\fmtname\x\else 1\fi\relax |
| 13 |
\else\csname fi\endcsname |
| 14 |
%</ignore> |
| 15 |
%<*install> |
| 16 |
\input docstrip.tex |
| 17 |
|
| 18 |
\keepsilent |
| 19 |
\askforoverwritefalse |
| 20 |
|
| 21 |
\def\MetaPrefix{-- } |
| 22 |
|
| 23 |
\def\luapostamble{% |
| 24 |
\MetaPrefix^^J% |
| 25 |
\MetaPrefix\space End of File `\outFileName'.% |
| 26 |
} |
| 27 |
|
| 28 |
\def\currentpostamble{\luapostamble}% |
| 29 |
|
| 30 |
\preamble |
| 31 |
|
| 32 |
This is a generated file (source: luatex-hyphen.dtx). |
| 33 |
|
| 34 |
Copyright (C) 2012-2013 by The LuaLaTeX development team. |
| 35 |
|
| 36 |
This work is under the CC0 license. |
| 37 |
|
| 38 |
\endpreamble |
| 39 |
|
| 40 |
\generate{% |
| 41 |
\file{luatex-hyphen.lua}{\from{luatex-hyphen.dtx}{lua}}% |
| 42 |
} |
| 43 |
|
| 44 |
\endbatchfile |
| 45 |
%</install> |
| 46 |
%<*ignore> |
| 47 |
\fi |
| 48 |
%</ignore> |
| 49 |
%<*driver> |
| 50 |
\NeedsTeXFormat{LaTeX2e} |
| 51 |
\ProvidesFile{luatex-hyphen.drv} |
| 52 |
[2013/05/16 v1.6 Hyphenation pattern loading for LuaTeX] |
| 53 |
\documentclass{ltxdoc} |
| 54 |
\usepackage[ |
| 55 |
pdftitle={The luatex-hyphen package}, |
| 56 |
pdfsubject={Hyphenation pattern loading for LuaTeX}, |
| 57 |
pdfauthor={Manuel Pégourié-Gonnard, Khaled Hosny & Elie Roux}, |
| 58 |
pdfkeywords={luatex, lualatex, unicode, hyphenation} |
| 59 |
]{hyperref} |
| 60 |
\usepackage{fontspec} |
| 61 |
\setmainfont[ |
| 62 |
Ligatures = TeX, |
| 63 |
BoldFont = {Linux Libertine O Bold}, |
| 64 |
ItalicFont = {Linux Libertine O Italic}, |
| 65 |
SlantedFont = {Linux Libertine O Italic}, |
| 66 |
]{Linux Libertine O} |
| 67 |
\setmonofont[Ligatures=TeX,Scale=MatchLowercase]{Liberation Mono} |
| 68 |
\setsansfont[Ligatures=TeX,Scale=MatchLowercase]{Iwona Medium} |
| 69 |
\EnableCrossrefs |
| 70 |
\CodelineIndex |
| 71 |
\begin{document} |
| 72 |
\DocInput{luatex-hyphen.dtx}% |
| 73 |
\end{document} |
| 74 |
%</driver> |
| 75 |
% \fi |
| 76 |
% |
| 77 |
% \CheckSum{0} |
| 78 |
% |
| 79 |
% \CharacterTable |
| 80 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 81 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 82 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 83 |
% Exclamation \! Double quote \" Hash (number) \# |
| 84 |
% Dollar \$ Percent \% Ampersand \& |
| 85 |
% Acute accent \' Left paren \( Right paren \) |
| 86 |
% Asterisk \* Plus \+ Comma \, |
| 87 |
% Minus \- Point \. Solidus \/ |
| 88 |
% Colon \: Semicolon \; Less than \< |
| 89 |
% Equals \= Greater than \> Question mark \? |
| 90 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 91 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 92 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 93 |
% Right brace \} Tilde \~} |
| 94 |
% |
| 95 |
% \GetFileInfo{luatex-hyphen.drv} |
| 96 |
% |
| 97 |
% \title{The \texttt{hyphen.cfg} file for Lua\TeX } |
| 98 |
% \date{2013/05/16 v1.6} |
| 99 |
% \author{Khaled Hosny, Élie Roux, and Manuel Pégourié-Gonnard\\ |
| 100 |
% \texttt{[email protected]} \\ |
| 101 |
% \texttt{[email protected]} \\ |
| 102 |
% \texttt{[email protected]}} |
| 103 |
% |
| 104 |
% \maketitle |
| 105 |
% |
| 106 |
% \begin{abstract} |
| 107 |
% This package is mainly a Lua module, to be used by \textsf{Babel} and |
| 108 |
% \textsf{polyglossia} to adapt their hyphenation patterns loading mechanism to |
| 109 |
% Lua\TeX's dynamic pattern loading capabilities. It makes use of a |
| 110 |
% \texttt{language.dat.lua} file (whose format is described below) that should |
| 111 |
% be present in the distribution, in addition to the regular |
| 112 |
% \texttt{language.dat} file. |
| 113 |
% |
| 114 |
% \textsf{Babel} needed to be updated -- this used to be the goal of this |
| 115 |
% package -- before version \textsf{3.9} (\TeX Live 2013) and |
| 116 |
% \textsf{polyglossia} handles Lua\TeX\ since version \textsf{1.3} (\TeX Live |
| 117 |
% 2013). |
| 118 |
% |
| 119 |
% There is a version of \texttt{etex.src} modified for the same reasons using |
| 120 |
% similar code, which also makes use of the \texttt{luatex-hyphen.lua} and |
| 121 |
% \texttt{language.dat.lua} files described here. |
| 122 |
% \end{abstract} |
| 123 |
% |
| 124 |
% \section{Documentation} |
| 125 |
% |
| 126 |
% Hyphenation patterns should be loaded at runtime with Lua\TeX: if they appear |
| 127 |
% in the format, they will be rehashed when the format is loaded anyway, which |
| 128 |
% makes the format quite long to load (many seconds even on modern machines) |
| 129 |
% and provides for bad user experience. Hence, it is desirable to load as few |
| 130 |
% patterns as possible in the format, and load on-demand the needed patterns |
| 131 |
% at runtime. |
| 132 |
% |
| 133 |
% This package provides a modified version of hyphen.cfg adapted to Lua\TeX, |
| 134 |
% as well as a supporting Lua module. Since a lot of things, especially the |
| 135 |
% catcodes, are not as predictable at runtime than at format creation time, we |
| 136 |
% don't \verb+\input+ the usual pattern files, but rather load the patterns |
| 137 |
% using the Lua interface, using a special plain text version of the pattern |
| 138 |
% files if available. |
| 139 |
% |
| 140 |
% The existence and file name of such a version cannot be guessed, so we need |
| 141 |
% a specific database: the file \texttt{language.dat.lua}. This file should be |
| 142 |
% loadable by Lua and return a table whose keys are the canonical language |
| 143 |
% names as found in \texttt{language.dat}, and the values are Lua tables |
| 144 |
% consisting of: |
| 145 |
% \begin{enumerate} |
| 146 |
% \item A fixed part with one mandatory field: |
| 147 |
% \begin{quote} |
| 148 |
% \verb+synonyms = { <string> alternative name, ...}+ |
| 149 |
% \end{quote} |
| 150 |
% This field's value must be the same as in \texttt{language.dat}. |
| 151 |
% \item A variable part consisting of either: |
| 152 |
% \begin{itemize} |
| 153 |
% \item For most languages: |
| 154 |
% \begin{quote} |
| 155 |
% \verb+patterns = <string> filenames for patterns+\\ |
| 156 |
% \verb+hyphenation = <string> filenames for exceptions+\\ |
| 157 |
% \end{quote} |
| 158 |
% Each string contains a coma-separated list of file names (whitespace |
| 159 |
% before or after the coma is not accepted). |
| 160 |
% The files given by \verb+patterns+ (resp. \verb+hypenation+) must be |
| 161 |
% plain text files encoded in UTF-8, with only patterns (resp. |
| 162 |
% exceptions) and not even comments: their content will be used |
| 163 |
% directly without being parsed by \TeX. If one of these keys is |
| 164 |
% missing or is the empty string, it is ignored and no patterns (resp. |
| 165 |
% exceptions) are loaded for this language. |
| 166 |
% \item Special cases are supported by a field \verb+special+. Currently, |
| 167 |
% the following kind of values are recognized: |
| 168 |
% \begin{description} |
| 169 |
% \item[\texttt{'disabled:<reason>'}] allows to disable specific |
| 170 |
% languages: when the user tries to load this language, an error |
| 171 |
% will be issued, with the \verb+<reason>+. |
| 172 |
% \item[\texttt{'language0'}] only \texttt{english} should use this |
| 173 |
% type of special, to indicate it is normally dumped in the format |
| 174 |
% as \verb+\language0+ (see below). |
| 175 |
% \end{description} |
| 176 |
% Special languages may have \texttt{*hyphenmin} information when it |
| 177 |
% makes sense (mostly \verb+\language0+). |
| 178 |
% \end{itemize} |
| 179 |
% \item Optional fields may be added. For example: |
| 180 |
% \begin{quote} |
| 181 |
% \verb+loader = <string> name of the TeX loader+\\ |
| 182 |
% \verb+lefthyphenmin = <number> value for \lefthyphenmin+\\ |
| 183 |
% \verb+righthyphenmin = <number> value for \righthyphenmin+ |
| 184 |
% \end{quote} |
| 185 |
% Those fields are present in \texttt{language.dat.lua} as generated by |
| 186 |
% \texttt{tlmgr}, for example, but they \emph{are not} used by the present |
| 187 |
% code in any way. |
| 188 |
% \end{enumerate} |
| 189 |
% Languages that are mentioned in \texttt{language.dat} but not in |
| 190 |
% \texttt{language.dat.lua} will be loaded in the format. So, if the |
| 191 |
% \texttt{language.dat.lua} file is missing or incomplete, languages will just |
| 192 |
% go back to the ``old'' behaviour, resulting in longer startup time, which |
| 193 |
% seems less bad than complete breakage. |
| 194 |
% |
| 195 |
% For backward compatibility, Knuth's original patterns for US English are |
| 196 |
% always loaded in the format, as \verb+\language0+.\footnote{It is assumed |
| 197 |
% to be the first entry in \texttt{language.dat}.} |
| 198 |
% |
| 199 |
% \StopEventually{ |
| 200 |
% } |
| 201 |
% |
| 202 |
% \section{Implementation} |
| 203 |
% |
| 204 |
% \begin{macrocode} |
| 205 |
%<*lua> |
| 206 |
% \end{macrocode} |
| 207 |
% |
| 208 |
% Start a Lua module, two functions for error and information reporting. |
| 209 |
% |
| 210 |
% \begin{macrocode} |
| 211 |
luatexhyphen = luatexhyphen or {} |
| 212 |
local luatexhyphen = luatexhyphen |
| 213 |
local function wlog(msg, ...) |
| 214 |
texio.write_nl('log', 'luatex-hyphen: '..msg:format(...)) |
| 215 |
end |
| 216 |
local function err(msg, ...) |
| 217 |
error('luatex-hyphen: '..msg:format(...), 2) |
| 218 |
end |
| 219 |
% \end{macrocode} |
| 220 |
% |
| 221 |
% Load the \texttt{language.dat.lua} file with the Lua version of the |
| 222 |
% language database. |
| 223 |
% |
| 224 |
% \begin{macrocode} |
| 225 |
local dbname = "language.dat.lua" |
| 226 |
local language_dat |
| 227 |
local dbfile = kpse.find_file(dbname, 'lua') |
| 228 |
if not dbfile then |
| 229 |
err("file not found: "..dbname) |
| 230 |
else |
| 231 |
wlog('using data file: %s', dbfile) |
| 232 |
language_dat = dofile(dbfile) |
| 233 |
end |
| 234 |
% \end{macrocode} |
| 235 |
% |
| 236 |
% Look up a language in the database, and return the associated |
| 237 |
% information, as well as the canonical name of the language. |
| 238 |
% |
| 239 |
% \begin{macrocode} |
| 240 |
local function lookupname(name) |
| 241 |
if language_dat[name] then |
| 242 |
return language_dat[name], name |
| 243 |
else |
| 244 |
for canon, data in pairs(language_dat) do |
| 245 |
for _,syn in ipairs(data.synonyms) do |
| 246 |
if syn == name then |
| 247 |
return data, canon |
| 248 |
end |
| 249 |
end |
| 250 |
end |
| 251 |
end |
| 252 |
end |
| 253 |
luatexhyphen.lookupname = lookupname |
| 254 |
% \end{macrocode} |
| 255 |
% |
| 256 |
% Set hyphenation patterns and exceptions for a language given by its name |
| 257 |
% (in the database) and number (value of \verb+\language+). Doesn't return |
| 258 |
% anything, but will call \verb+error()+ if things go wrong. |
| 259 |
% |
| 260 |
% \begin{macrocode} |
| 261 |
local function loadlanguage(lname, id) |
| 262 |
if id == 0 then |
| 263 |
return |
| 264 |
end |
| 265 |
local msg = "loading%s patterns and exceptions for: %s (\\language%d)" |
| 266 |
% \end{macrocode} |
| 267 |
% |
| 268 |
% Lookup the language in the database. |
| 269 |
% |
| 270 |
% \begin{macrocode} |
| 271 |
local ldata, cname = lookupname(lname) |
| 272 |
if not ldata then |
| 273 |
err("no entry in %s for this language: %s", dbname, lname) |
| 274 |
end |
| 275 |
% \end{macrocode} |
| 276 |
% |
| 277 |
% Handle special languages. |
| 278 |
% |
| 279 |
% \begin{macrocode} |
| 280 |
if ldata.special then |
| 281 |
if ldata.special:find('^disabled:') then |
| 282 |
err("language disabled by %s: %s (%s)", dbname, cname, |
| 283 |
ldata.special:gsub('^disabled:', '')) |
| 284 |
elseif ldata.special == 'language0' then |
| 285 |
err("\\language0 should be dumped in the format") |
| 286 |
else |
| 287 |
err("bad entry in %s for language %s") |
| 288 |
end |
| 289 |
end |
| 290 |
% \end{macrocode} |
| 291 |
% |
| 292 |
% The generic case: load hyphenation patterns and exceptions from files |
| 293 |
% given by the language code. |
| 294 |
% |
| 295 |
% \begin{macrocode} |
| 296 |
wlog(msg, '', cname, id) |
| 297 |
for _, item in ipairs{'patterns', 'hyphenation'} do |
| 298 |
local filelist = ldata[item] |
| 299 |
if filelist ~= nil and filelist ~= '' then |
| 300 |
for _, file in ipairs(filelist:explode(',')) do |
| 301 |
local file = kpse.find_file(file) or err("file not found: %s", file) |
| 302 |
local fh = io.open(file, 'r') |
| 303 |
local data = fh:read('*a') or err("file not readable: %s", f) |
| 304 |
fh:close() |
| 305 |
lang[item](lang.new(id), data) |
| 306 |
end |
| 307 |
else |
| 308 |
if item == 'hyphenation' then item = item..' exceptions' end |
| 309 |
wlog("info: no %s for this language", item) |
| 310 |
end |
| 311 |
end |
| 312 |
end |
| 313 |
luatexhyphen.loadlanguage = loadlanguage |
| 314 |
% \end{macrocode} |
| 315 |
% |
| 316 |
% Add \textsf{Babel}'s ``dialects'' as synonyms. |
| 317 |
% |
| 318 |
% \begin{macrocode} |
| 319 |
local function adddialect(dialect, language) |
| 320 |
if dialect ~= '0' then |
| 321 |
dialect = dialect:gsub('l@', '') |
| 322 |
language = language:gsub('l@', '') |
| 323 |
data = lookupname(language) |
| 324 |
if data then |
| 325 |
data.synonyms[#data.synonyms+1] = dialect |
| 326 |
end |
| 327 |
end |
| 328 |
end |
| 329 |
luatexhyphen.adddialect = adddialect |
| 330 |
% \end{macrocode} |
| 331 |
% |
| 332 |
% \begin{macrocode} |
| 333 |
%</lua> |
| 334 |
% \end{macrocode} |
| 335 |
% |
| 336 |
% \Finale |
| 337 |
\endinput |