| 1 |
% \iffalse meta-comment -- by the way, this file contains UTF-8 |
| 2 |
% |
| 3 |
% Written in 2009, 2010 by Manuel Pégourié-Gonnard and Élie Roux. |
| 4 |
% <[email protected]> |
| 5 |
% <[email protected]> |
| 6 |
% |
| 7 |
% This work is under the CC0 license. As an exception, the files |
| 8 |
% luainputenc.sty, lutf8.def and lutf8x.def have more restrictions. |
| 9 |
% See these file for more details. |
| 10 |
% |
| 11 |
% People who helped on this package: |
| 12 |
% Javier Bezos |
| 13 |
% Will Robertson |
| 14 |
% Hans Hagen |
| 15 |
% Heiko Oberdiek |
| 16 |
% Javier Mugica |
| 17 |
% |
| 18 |
% This work consists of the main source file luainputenc.dtx |
| 19 |
% and the derived files |
| 20 |
% luainputenc.sty, luainputenc.lua, lutf8.def, lutf8x.def, |
| 21 |
% and luainputenc.pdf |
| 22 |
% |
| 23 |
% Unpacking: |
| 24 |
% tex luainputenc.dtx |
| 25 |
% Documentation: |
| 26 |
% pdflatex luainputenc.dtx |
| 27 |
% |
| 28 |
%<*ignore> |
| 29 |
\begingroup |
| 30 |
\def\x{LaTeX2e}% |
| 31 |
\expandafter\endgroup |
| 32 |
\ifcase 0\ifx\install y1\fi\expandafter |
| 33 |
\ifx\csname processbatchFile\endcsname\relax\else1\fi |
| 34 |
\ifx\fmtname\x\else 1\fi\relax |
| 35 |
\else\csname fi\endcsname |
| 36 |
%</ignore> |
| 37 |
%<*install> |
| 38 |
\input docstrip.tex |
| 39 |
|
| 40 |
\keepsilent |
| 41 |
\askforoverwritefalse |
| 42 |
|
| 43 |
\let\MetaPrefix\relax |
| 44 |
|
| 45 |
\preamble |
| 46 |
This is a generated file. |
| 47 |
|
| 48 |
Written in 2009, 2010 by Manuel Pegourie-Gonnard and Elie Roux. |
| 49 |
|
| 50 |
This work is under the CC0 license. As an exception, the files |
| 51 |
luainputenc.sty, lutf8.def and lutf8x.def have more restrictions. |
| 52 |
See these file for more details. |
| 53 |
|
| 54 |
People who helped on this package: |
| 55 |
Javier Bezos |
| 56 |
Will Robertson |
| 57 |
Hans Hagen |
| 58 |
Heiko Oberdiek |
| 59 |
Javier Mugica |
| 60 |
|
| 61 |
This work consists of the main source file luainputenc.dtx |
| 62 |
and the derived files |
| 63 |
luainputenc.sty, luainputenc.lua, lutf8.def, lutf8x.def, |
| 64 |
and luainputenc.pdf |
| 65 |
|
| 66 |
\endpreamble |
| 67 |
|
| 68 |
\let\MetaPrefix\DoubleperCent |
| 69 |
|
| 70 |
\generate{% |
| 71 |
\usedir{tex/lualatex/luainputenc}% |
| 72 |
\file{luainputenc.sty}{\from{luainputenc.dtx}{package}}% |
| 73 |
\file{lutf8.def}{\from{luainputenc.dtx}{def}}% |
| 74 |
\file{lutf8x.def}{\from{luainputenc.dtx}{defx}}% |
| 75 |
} |
| 76 |
|
| 77 |
\generate{% |
| 78 |
\usedir{doc/luatex/luainputenc}% |
| 79 |
\file{test.tex}{\from{luainputenc.dtx}{test}}% |
| 80 |
} |
| 81 |
|
| 82 |
\def\MetaPrefix{-- } |
| 83 |
|
| 84 |
\def\luapostamble{% |
| 85 |
\MetaPrefix^^J% |
| 86 |
\MetaPrefix\space End of File `\outFileName'.% |
| 87 |
} |
| 88 |
|
| 89 |
\def\currentpostamble{\luapostamble}% |
| 90 |
|
| 91 |
\generate{% |
| 92 |
\usedir{tex/lualatex/luainputenc}% |
| 93 |
\file{luainputenc.lua}{\from{luainputenc.dtx}{lua}}% |
| 94 |
} |
| 95 |
|
| 96 |
\nopreamble |
| 97 |
\nopostamble |
| 98 |
|
| 99 |
\generate{% |
| 100 |
\file{inputenc.sty.diff}{\from{luainputenc.dtx}{patch}}% |
| 101 |
} |
| 102 |
|
| 103 |
\obeyspaces |
| 104 |
\Msg{************************************************************************} |
| 105 |
\Msg{*} |
| 106 |
\Msg{* To finish the installation you have to move the following} |
| 107 |
\Msg{* files into a directory searched by TeX:} |
| 108 |
\Msg{*} |
| 109 |
\Msg{* luainputenc.sty luainputenc.lua lutf8.def lutf8x.def} |
| 110 |
\Msg{*} |
| 111 |
\Msg{* Happy TeXing!} |
| 112 |
\Msg{*} |
| 113 |
\Msg{************************************************************************} |
| 114 |
|
| 115 |
\endbatchfile |
| 116 |
%</install> |
| 117 |
%<*ignore> |
| 118 |
\fi |
| 119 |
%</ignore> |
| 120 |
% \iffalse |
| 121 |
%<package> |
| 122 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 123 |
%<package>\ProvidesPackage{luainputenc} |
| 124 |
%<package> [2010/11/19 v0.973 inputenc package for LuaTeX] |
| 125 |
%<package> |
| 126 |
% \fi |
| 127 |
%<*driver> |
| 128 |
\documentclass{ltxdoc} |
| 129 |
\usepackage[utf8]{inputenc} |
| 130 |
\usepackage[T1]{fontenc} |
| 131 |
\usepackage{textcomp} |
| 132 |
\usepackage{lmodern} |
| 133 |
\usepackage{metalogo} |
| 134 |
\usepackage[lmargin=5cm, textwidth=14cm]{geometry} |
| 135 |
\usepackage[bookmarks=true, colorlinks=true]{hyperref} |
| 136 |
\usepackage{bookmark} |
| 137 |
\usepackage[english]{babel} |
| 138 |
\providecommand\eTeX{e\TeX} |
| 139 |
\newcommand\pf{\textsf} |
| 140 |
\newcommand\file{\texorpdfstring{\nolinkurl}{}} |
| 141 |
\newcommand\code{\texttt} |
| 142 |
\newcommand*\email[1]{\href{mailto:#1}{#1}} |
| 143 |
\begin{document} |
| 144 |
\DocInput{luainputenc.dtx}% |
| 145 |
\end{document} |
| 146 |
%</driver> |
| 147 |
% \fi |
| 148 |
% |
| 149 |
% \CheckSum{0} |
| 150 |
% |
| 151 |
% \CharacterTable |
| 152 |
% {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 |
| 153 |
% 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 |
| 154 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 155 |
% Exclamation \! Double quote \" Hash (number) \# |
| 156 |
% Dollar \$ Percent \% Ampersand \& |
| 157 |
% Acute accent \' Left paren \( Right paren \) |
| 158 |
% Asterisk \* Plus \+ Comma \, |
| 159 |
% Minus \- Point \. Solidus \/ |
| 160 |
% Colon \: Semicolon \; Less than \< |
| 161 |
% Equals \= Greater than \> Question mark \? |
| 162 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 163 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 164 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 165 |
% Right brace \} Tilde \~} |
| 166 |
% |
| 167 |
% \title{The \textsf{luainputenc} package} |
| 168 |
% \date{2010/11/19 v0.973} |
| 169 |
% \author{% |
| 170 |
% Manuel P\'egouri\'e-Gonnard \email{[email protected]} \\ |
| 171 |
% \'Elie Roux \email{[email protected]}} |
| 172 |
% |
| 173 |
% \maketitle |
| 174 |
% |
| 175 |
% \begin{abstract} |
| 176 |
% Input encoding management for Lua\TeX, needed only for compatibility with |
| 177 |
% old documents. For new documents, using UTF-8 encoding and Unicode fonts is |
| 178 |
% \emph{strongly} recommended. You've been warned! |
| 179 |
% \end{abstract} |
| 180 |
% |
| 181 |
% \tableofcontents |
| 182 |
% |
| 183 |
% \section{Overview: When (not) to use this package} |
| 184 |
% |
| 185 |
% This package is strictly meant for compatibility. It is usefull in the two |
| 186 |
% (overlapping) following cases: |
| 187 |
% \begin{enumerate} |
| 188 |
% \item Your source is not encoded in UTF-8 and you don't want to reencode it |
| 189 |
% for some reason. |
| 190 |
% \item Your document is using legacy 8-bit fonts (with \pf{fontenc}), as |
| 191 |
% opposed to modern Unicode fonts (most probably with \pf{fontspec} or |
| 192 |
% \pf{luaotfload} and \pf{fontenc} with option \code{EU2}). |
| 193 |
% \end{enumerate} |
| 194 |
% Surprisingly enough, in the second case \pf{luainputenc} is needed, due to |
| 195 |
% the way \LaTeX\ implements font encodings. |
| 196 |
% |
| 197 |
% From the user point of view, adapting an old document for \LuaTeX\ is really |
| 198 |
% easy: replacing \pf{inputenc} by \pf{luainputenc} in the preamble is |
| 199 |
% enough. |
| 200 |
% |
| 201 |
% Note that \pf{luainputenc} automatically loads \pf{inputenc} if called |
| 202 |
% with an old engine, so you will still be able to compile your documents with |
| 203 |
% pdf\TeX\ without changing them. |
| 204 |
% |
| 205 |
% \pf{luainputenc} has several modes of operation. By default, it basically |
| 206 |
% turns \LuaTeX\ into an 8-bit engine, which means you loose half of the |
| 207 |
% benefits from using \LuaTeX. If you are using only Unicode fonts, you can |
| 208 |
% activate a nicer mode of operation using the \code{unactivate} package |
| 209 |
% option. That way, \LuaTeX\ remains a true Unicode engine. |
| 210 |
% |
| 211 |
% Unicode fonts with \LuaTeX\ are handled using a new encoding: \code{EU2}. It |
| 212 |
% is used internally by the \pf{fontspec} package when loading Unicode fonts. |
| 213 |
% This encoding is special as it needs non-ASCII characters to be non-active |
| 214 |
% (unlike other font encodings), so you cannot mix old encodings and EU2. If |
| 215 |
% you're using only Unicode fonts, this isn't a problem: use the |
| 216 |
% \code{unactivate} package option mentioned in the previous paragraph. |
| 217 |
% |
| 218 |
% But if you |
| 219 |
% want to use both 8-bit fonts and Unicode fonts in your document, you need to |
| 220 |
% use another package option, \code{lutf8x}. This option |
| 221 |
% overrides \LaTeX's mechanism for font encoding switching, so that it |
| 222 |
% (un)activates non-ASCII characters on-the-fly. With this options, you'll be |
| 223 |
% able change the font encoding from/to \code{EU2}, for example: |
| 224 |
% |
| 225 |
% \begin{verbatim} |
| 226 |
% abc |
| 227 |
% { |
| 228 |
% \fontencoding{EU2}\usefont |
| 229 |
% \font\foo="MyOtfFont.otf"\foo |
| 230 |
% abc |
| 231 |
% } |
| 232 |
% abc |
| 233 |
% \end{verbatim} |
| 234 |
% |
| 235 |
% \section{Documentation} |
| 236 |
% |
| 237 |
% \subsection{Introduction} |
| 238 |
% |
| 239 |
% One the the most interesting new features of Lua\TeX\ is the fact that it is |
| 240 |
% (like Omega/Aleph) not limited to 256 characters, and can now understand |
| 241 |
% Unicode. The problem is that it does not read input the way older engines |
| 242 |
% (like pdf\TeX) do, and thus \textsf{inputenc} is totally broken with Lua\TeX |
| 243 |
% . This package aims at replacing \textsf{inputenc} for Lua\TeX , by adapting |
| 244 |
% the way Lua\TeX\ handles input, and the way \textsf{inputenc} handles UTF-8. |
| 245 |
% This package has two very distinct modes: 8-bit and UTF-8. |
| 246 |
% |
| 247 |
% \subsection{Overview of 8-bit mode} |
| 248 |
% |
| 249 |
% This package \textbf{does not} map 8-bit encodings to utf8. It allows |
| 250 |
% Lua\TeX\ to read 8-bit characters, by converting each byte into a unicode |
| 251 |
% character with the same character number. The resulting unicode characters |
| 252 |
% are not true UTF-8, they are what we will call ``fake UTF-8". For example |
| 253 |
% the byte 225 will be converted into the unicode character with number 225 |
| 254 |
% (two bytes long). It will be true UTF-8 only if the encoding is latin1. |
| 255 |
% |
| 256 |
% Here is how it works: the 8-bit encodings are converted into fake UTF-8, so |
| 257 |
% that the corresponding tokens are chars with the good numbers. Then (like |
| 258 |
% \textsf{inputenc}) it reads the char numbers, and converts it into LICR |
| 259 |
% (\LaTeX\ Internal Character Representation), with the font encoding. |
| 260 |
% |
| 261 |
% In Lua\TeX\ version 0.43, a new callback called |process_output_buffer|, |
| 262 |
% this callbacks allows to make Lua\TeX\ write 8-bit instead of UTF-8, so the |
| 263 |
% behaviour is the same as pdfTeX as this level. For versions prior to 0.43 |
| 264 |
% though, we need to do more tricky things, described in the next paragraph. |
| 265 |
% This machinery is disabled for Lua\TeX\ version 0.43 and superior, so you |
| 266 |
% can keep the default behaviour, which will be compatible with pdfTeX in |
| 267 |
% most cases, but you can consider the machinery obsolete. |
| 268 |
% |
| 269 |
% For these old versions, \textsf{luainputenc} only changes the input |
| 270 |
% behaviour, it does not change the ouput behaviour (when files are written |
| 271 |
% for example). The consequence is that files will still be written by |
| 272 |
% Lua\TeX\ in UTF-8 (fake UTF-8 in this case), even if the asked input |
| 273 |
% encoding is a 8-bit encoding. In most cases it's not a problem, as most |
| 274 |
% files will be written in LICR, meaning ASCII, which is both 8-bit and UTF-8. |
| 275 |
% The problem comes when characters with a number $>$ 128 are written in a |
| 276 |
% 8-bit encoding. This may happen if you use |\protect| in a section for |
| 277 |
% example. In these cases, Lua\TeX\ will write fake UTF-8, and try to read |
| 278 |
% 8-bit encoding, so it will get confused. |
| 279 |
% |
| 280 |
% The proposed solution is to unactivate the input conversion when we read |
| 281 |
% certain files or extentions. This package should work with no change for |
| 282 |
% most documents, but if you cook your own aux files with an unknown |
| 283 |
% extention, you may have to force the package to read some files in UTF-8 |
| 284 |
% instead of 8-bit. See comments in the \texttt{.sty} file to know the useful |
| 285 |
% commands. |
| 286 |
% |
| 287 |
% \subsection{Overview of UTF-8 mode} |
| 288 |
% |
| 289 |
% The behaviour of \textsf{inputenc} in utf8 mode is to read the input byte by |
| 290 |
% byte, and decide if the character we are in is 1, 2, 3 or 4 bytes long, and |
| 291 |
% then read other bytes accordingly. This behaviour fails with Lua\TeX\ |
| 292 |
% because it reads input character by character (characters do not have a |
| 293 |
% fixed number of bytes in unicode). The result is thus an error. |
| 294 |
% |
| 295 |
% All characters recognized by \TeX\ are active characters, that correspond to |
| 296 |
% a LICR macro. Then \textsf{inputenc} reads the \texttt{*.dfu} files that |
| 297 |
% contain the correspondance between these LICR macros and a character number |
| 298 |
% in the fonts for different font encodings (T1, OT1, etc.). |
| 299 |
% |
| 300 |
% \subsubsection{legacy mode} |
| 301 |
% |
| 302 |
% \textsf{luainputenc} can get this behaviour (we will call it \emph{legacy |
| 303 |
% mode}, but another difference implied by the fact that Lua\TeX\ can read |
| 304 |
% more than 256 characters is that fonts can also have more than 256 |
| 305 |
% characters. Lua\TeX\ can thus read unicode fonts. If we want to use unicode |
| 306 |
% fonts (OTF for example), we can't use the \emph{legacy mode} anymore, as it |
| 307 |
% would mean that we would have to rewrite a specially long |
| 308 |
% \texttt{unicode.dfu} file, and it would be totally inefficient, as for |
| 309 |
% instance \texttt{\'e} (unicode character number 233) would be mapped to |
| 310 |
% \texttt{\string\'e}, and then mapped back to \texttt{\string\char\ 233}. |
| 311 |
% |
| 312 |
% \subsubsection{unicode font mode} |
| 313 |
% |
| 314 |
% To fix this, the most simple solution is to desactivate all activated |
| 315 |
% characters, thus typing \texttt{\'e} will directly call |
| 316 |
% \texttt{\string\char\ 233} in the unicode fonts, and produce a \texttt{\'e}. |
| 317 |
% We will call this behaviour the \emph{unicode font mode}. To enable this |
| 318 |
% mode, you can use the option \texttt{unactivate} in \textsf{luainputenc}, |
| 319 |
% and you must use the font encoding \texttt{EU2} provided by the \textsf{euenc} |
| 320 |
% package. See documentation of \textsf{euenc} package for more details about |
| 321 |
% \texttt{EU2}. To use this mode with \texttt{EU2}, you must be able to open OTF |
| 322 |
% fonts. A simple way to do so it by using the package \textsf{luaotfload}. |
| 323 |
% |
| 324 |
% \subsubsection{mixed mode} |
| 325 |
% |
| 326 |
% But the \emph{unicode font mode} has a strong limitation (that will |
| 327 |
% certainly dissapear with time): it cannot use non-unicode fonts. If you want |
| 328 |
% to mix unicode fonts and old fonts, you'll have to use the \emph{mixed |
| 329 |
% mode}. In this mode you can type some parts of your document in \emph{legacy |
| 330 |
% mode} and some in \emph{unicode font mode}. The reason why we chose not to |
| 331 |
% integrate this choice in the \emph{legacy mode} is that we wanted to have a |
| 332 |
% mode that preserved most of the backward compatibility, to safely compile |
| 333 |
% old documents; the \emph{mixed mode} introduces new things that may break |
| 334 |
% old documents. To get the \emph{mixed mode}, you must pass the option |
| 335 |
% \texttt{lutf8x} to \textsf{luainputenc}. This mode is the most experimental. |
| 336 |
% |
| 337 |
% \section{Accessing the encoding in lua} |
| 338 |
% |
| 339 |
% In order to access the encoding and the package option in lua, two variables |
| 340 |
% are set: |luainputenc.package_option| contains the option passed to the |
| 341 |
% package, and |luainputenc.encoding| that contains the encoding (defaults to |
| 342 |
% utf8, and is utf8 even with the options |unactivate|, |utf8x|, etc.). |
| 343 |
% |
| 344 |
% \section{Files} |
| 345 |
% |
| 346 |
% This package contains a \texttt{.sty} file for both \LaTeX\ and Plain, a |
| 347 |
% patch for inputenc to use \textsf{luainputenc} so that you can process old |
| 348 |
% documents without changing anything, and the lua functions. |
| 349 |
% |
| 350 |
% \subsection{\texttt{inputenc.sty} patch} |
| 351 |
% |
| 352 |
% A good thing would be to patch \textsf{inputenc} to load |
| 353 |
% \textsf{luainputenc} instead, so that you don't have to change your |
| 354 |
% documents to load \textsf{luainputenc} especially. The \LaTeX\ team is |
| 355 |
% extremely conservative and does not want this patch applied (maybe we will |
| 356 |
% find a solution later). Here is a patch for inputenc.sty: |
| 357 |
% |
| 358 |
% \iffalse |
| 359 |
%<*patch> |
| 360 |
% \fi |
| 361 |
% |
| 362 |
% \begin{macrocode} |
| 363 |
|
| 364 |
\ifnum\@tempcnta<`#2\relax |
| 365 |
\advance\@tempcnta\@ne |
| 366 |
\repeat} |
| 367 |
+ |
| 368 |
+\begingroup\expandafter\expandafter\expandafter\endgroup |
| 369 |
+\expandafter\ifx\csname XeTeXversion\endcsname\relax\else |
| 370 |
+ \RequirePackage{xetex-inputenc} |
| 371 |
+ \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{xetex-inputenc}} |
| 372 |
+ \ProcessOptions* |
| 373 |
+ \expandafter\endinput |
| 374 |
+\fi |
| 375 |
+\begingroup\expandafter\expandafter\expandafter\endgroup |
| 376 |
+\expandafter\ifx\csname directlua\endcsname\relax\else |
| 377 |
+ \RequirePackage{luainputenc} |
| 378 |
+ \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{luainputenc}} |
| 379 |
+ \ProcessOptions* |
| 380 |
+ \expandafter\endinput |
| 381 |
+\fi |
| 382 |
+ |
| 383 |
\ProcessOptions |
| 384 |
\endinput |
| 385 |
%% |
| 386 |
|
| 387 |
% \end{macrocode} |
| 388 |
% |
| 389 |
% \iffalse |
| 390 |
%</patch> |
| 391 |
% \fi |
| 392 |
% |
| 393 |
% \subsection{\texttt{luainputenc.sty}} |
| 394 |
% |
| 395 |
% This file has some code from \texttt{inputenc.sty}, but also provides new |
| 396 |
% options, and new macros to convert from 8-bit to fake UTF-8. |
| 397 |
% |
| 398 |
% \iffalse |
| 399 |
%<*package> |
| 400 |
% \fi |
| 401 |
% |
| 402 |
% \begin{macrocode} |
| 403 |
% |
| 404 |
%% This file was adapted from inputenc.sty, which copyright is: |
| 405 |
%% Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 |
| 406 |
%% 2005 2006 The LaTeX3 Project. |
| 407 |
%% |
| 408 |
%% inputenc.sty is under the lppl version 1.3c or later, and can be |
| 409 |
%% found in the base LaTeX system. |
| 410 |
%% |
| 411 |
%% The lppl can be found at http://www.latex-project.org/lppl.txt |
| 412 |
%% |
| 413 |
%% The changes to inputenc.sty are Copyright 2009 Elie Roux, and are |
| 414 |
%% under the CC0 license. |
| 415 |
%% |
| 416 |
%% The changes are LuaTeX support. |
| 417 |
%% |
| 418 |
%% This file is distributed under the CC0 license, with clause 6 of the |
| 419 |
%% lppl as additional restrictions. |
| 420 |
|
| 421 |
% \end{macrocode} |
| 422 |
% |
| 423 |
% First we check if we are called with Lua\TeX , (pdf)\TeX or Xe\TeX . If |
| 424 |
% we are called with pdf\TeX , we default to \textsf{inputenc}, and to |
| 425 |
% \textsf{xetex-inputenc} if we are called with Xe\TeX . We also remap the |
| 426 |
% new options to \texttt{utf8} in these cases. |
| 427 |
% |
| 428 |
% \begin{macrocode} |
| 429 |
|
| 430 |
\RequirePackage{ifluatex} |
| 431 |
\RequirePackage{ifxetex} |
| 432 |
|
| 433 |
\ifxetex |
| 434 |
\DeclareOption{unactivate}{\PassOptionsToPackage{utf8}{xetex-inputenc}} |
| 435 |
\DeclareOption{lutf8}{\PassOptionsToPackage{utf8}{xetex-inputenc}} |
| 436 |
\DeclareOption{lutf8x}{\PassOptionsToPackage{utf8}{xetex-inputenc}} |
| 437 |
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{xetex-inputenc}} |
| 438 |
\ProcessOptions* |
| 439 |
\RequirePackage{xetex-inputenc} |
| 440 |
\expandafter\endinput |
| 441 |
\fi |
| 442 |
|
| 443 |
\ifluatex\else |
| 444 |
\DeclareOption{unactivate}{\PassOptionsToPackage{utf8}{inputenc}} |
| 445 |
\DeclareOption{lutf8}{\PassOptionsToPackage{utf8}{inputenc}} |
| 446 |
\DeclareOption{lutf8x}{\PassOptionsToPackage{utf8}{inputenc}} |
| 447 |
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{inputenc}} |
| 448 |
\ProcessOptions* |
| 449 |
\RequirePackage{inputenc} |
| 450 |
\expandafter\endinput |
| 451 |
\fi |
| 452 |
|
| 453 |
% \end{macrocode} |
| 454 |
% |
| 455 |
% Here we know we are called with Lua\TeX . We first require |
| 456 |
% \textsf{luatextra} and ensure a few primitives, then we load the |
| 457 |
% \texttt{lua} file. |
| 458 |
% |
| 459 |
% \begin{macrocode} |
| 460 |
|
| 461 |
\RequirePackage{luatexbase} |
| 462 |
\luatexbase@ensure@primitive{luaescapestring} |
| 463 |
|
| 464 |
\RequireLuaModule{luainputenc} |
| 465 |
|
| 466 |
% \end{macrocode} |
| 467 |
% |
| 468 |
% Here is some code from \textsf{inputenc}. |
| 469 |
% |
| 470 |
% \begin{macrocode} |
| 471 |
|
| 472 |
\def\DeclareInputMath#1{% |
| 473 |
\@inpenc@test |
| 474 |
\bgroup |
| 475 |
\uccode`\~#1% |
| 476 |
\uppercase{% |
| 477 |
\egroup |
| 478 |
\def~% |
| 479 |
}% |
| 480 |
} |
| 481 |
\def\DeclareInputText#1#2{% |
| 482 |
\def\reserved@a##1 ${}% |
| 483 |
\def\reserved@b{#2}% |
| 484 |
\ifcat_\expandafter\reserved@a\meaning\reserved@b$ $_% |
| 485 |
\DeclareInputMath{#1}{#2}% |
| 486 |
\else |
| 487 |
\DeclareInputMath{#1}{\IeC{#2}}% |
| 488 |
\fi |
| 489 |
} |
| 490 |
\def\IeC{% |
| 491 |
\ifx\protect\@typeset@protect |
| 492 |
\expandafter\@firstofone |
| 493 |
\else |
| 494 |
\noexpand\IeC |
| 495 |
\fi |
| 496 |
} |
| 497 |
% \end{macrocode} |
| 498 |
% |
| 499 |
% We changed a little the behaviour of this macro: we removed |
| 500 |
% |\@inpenc@loop\^^?\^^ff|, because it made no sense in UTF-8 mode. We will |
| 501 |
% call this line for 8-bit encodings. |
| 502 |
% |
| 503 |
% Note that the code has been changed for |\endlinechar|, because in new |
| 504 |
% versions (from v0.43) of Lua\TeX{} the value cannot exceed 127. |
| 505 |
% Thus, with the old version of \textsf{luainputenc}, when trying |
| 506 |
% to add 10000, it fails silently, and when 10000 is substracted, the |
| 507 |
% new value is -1, resulting in no end of lines at all in the document. |
| 508 |
% |
| 509 |
% \begin{macrocode} |
| 510 |
|
| 511 |
\def\inputencoding#1{% |
| 512 |
\the\inpenc@prehook |
| 513 |
\gdef\@inpenc@test{\global\let\@inpenc@test\relax}% |
| 514 |
\edef\@inpenc@undefined{\noexpand\@inpenc@undefined@{#1}}% |
| 515 |
\edef\inputencodingname{#1}% |
| 516 |
\@inpenc@loop\^^A\^^H% |
| 517 |
\@inpenc@loop\^^K\^^K% |
| 518 |
\@inpenc@loop\^^N\^^_% |
| 519 |
\xdef\saved@endlinechar{\the\endlinechar }% |
| 520 |
\endlinechar=-1 |
| 521 |
\xdef\saved@space@catcode{\the\catcode`\ }% |
| 522 |
\catcode`\ 9\relax |
| 523 |
\input{#1.def}% |
| 524 |
\endlinechar=\saved@endlinechar{}% |
| 525 |
\catcode`\ \saved@space@catcode\relax |
| 526 |
\ifx\@inpenc@test\relax\else |
| 527 |
\PackageWarning{inputenc}% |
| 528 |
{No characters defined\MessageBreak |
| 529 |
by input encoding change to `#1'\MessageBreak}% |
| 530 |
\fi |
| 531 |
\the\inpenc@posthook |
| 532 |
\luatexbase@directlua{luainputenc.set_option("\luatexluaescapestring{#1}")} |
| 533 |
} |
| 534 |
\newtoks\inpenc@prehook |
| 535 |
\newtoks\inpenc@posthook |
| 536 |
\def\@inpenc@undefined@#1{\PackageError{inputenc}% |
| 537 |
{Keyboard character used is undefined\MessageBreak |
| 538 |
in inputencoding `#1'}% |
| 539 |
{You need to provide a definition with |
| 540 |
\noexpand\DeclareInputText\MessageBreak or |
| 541 |
\noexpand\DeclareInputMath before using this key.}}% |
| 542 |
\def\@inpenc@loop#1#2{% |
| 543 |
\@tempcnta`#1\relax |
| 544 |
\loop |
| 545 |
\catcode\@tempcnta\active |
| 546 |
\bgroup |
| 547 |
\uccode`\~\@tempcnta |
| 548 |
\uppercase{% |
| 549 |
\egroup |
| 550 |
\let~\inpenc@undefined |
| 551 |
}% |
| 552 |
\ifnum\@tempcnta<`#2\relax |
| 553 |
\advance\@tempcnta\@ne |
| 554 |
\repeat} |
| 555 |
|
| 556 |
% \end{macrocode} |
| 557 |
% |
| 558 |
% Here we declare our options. Note that we remap \texttt{utf8} to |
| 559 |
% \texttt{lutf8}, because we use out \texttt{lutf8.def} instead of |
| 560 |
% \textsf{inputenc}'s \texttt{utf8.def}. |
| 561 |
% |
| 562 |
% \begin{macrocode} |
| 563 |
|
| 564 |
\DeclareOption{utf8}{% |
| 565 |
\inputencoding{lutf8}% |
| 566 |
} |
| 567 |
|
| 568 |
\DeclareOption{lutf8}{% |
| 569 |
\inputencoding{lutf8}% |
| 570 |
} |
| 571 |
|
| 572 |
\DeclareOption{utf8x}{% |
| 573 |
\inputencoding{lutf8}% |
| 574 |
} |
| 575 |
|
| 576 |
\DeclareOption{lutf8x}{% |
| 577 |
\inputencoding{lutf8x}% |
| 578 |
} |
| 579 |
|
| 580 |
% \end{macrocode} |
| 581 |
% |
| 582 |
% For the \texttt{unactivate} option, for \emph{unicode font mode}, we just |
| 583 |
% don't do anything. |
| 584 |
% |
| 585 |
% \begin{macrocode} |
| 586 |
|
| 587 |
\DeclareOption{unactivate}{% |
| 588 |
\edef\inputencodingname{unactivate}% |
| 589 |
\luatexbase@directlua{luainputenc.set_option([[unactivate]])} |
| 590 |
} |
| 591 |
|
| 592 |
% \end{macrocode} |
| 593 |
% |
| 594 |
% All other options are 8-bit encodings, so we activate the translation |
| 595 |
% into fake UTF-8, and we execute the loop we removes from |
| 596 |
% |\inputencoding|. |
| 597 |
% |
| 598 |
% \begin{macrocode} |
| 599 |
|
| 600 |
\DeclareOption*{% |
| 601 |
\lIE@activate % |
| 602 |
\@inpenc@loop\^^?\^^ff% |
| 603 |
\inputencoding{\CurrentOption}% |
| 604 |
} |
| 605 |
|
| 606 |
% \end{macrocode} |
| 607 |
% |
| 608 |
% The rest of the file is only the machinery for LuaTeX versions without |
| 609 |
% the callback |process_output_buffer|, so it will be deprecated after |
| 610 |
% TeXLive 2009, you are not advised to use it. |
| 611 |
% |
| 612 |
% \begin{macrocode} |
| 613 |
|
| 614 |
\ifnum\luatexversion>42 |
| 615 |
|
| 616 |
\newcommand*{\lIE@activate}[0]{% |
| 617 |
\luatexbase@directlua{luainputenc.register_callbacks()}% |
| 618 |
} |
| 619 |
|
| 620 |
\else |
| 621 |
|
| 622 |
% \end{macrocode} |
| 623 |
% |
| 624 |
% |\lIE@setstarted| and |\lIE@setstopped| are called when the fake UTF-8 |
| 625 |
% translation must be activated or desactivated. You can call them several |
| 626 |
% successive times. They are called very often, even if the package is not |
| 627 |
% activated (for example if it's loaded with the utf8 option), but they act |
| 628 |
% only if the package is activated. |
| 629 |
% |
| 630 |
% \begin{macrocode} |
| 631 |
|
| 632 |
\newcommand*\lIE@setstarted[0]{% |
| 633 |
\ifnum\lIE@activated=1 % |
| 634 |
\luatexbase@directlua{luainputenc.setstarted()}% |
| 635 |
\fi % |
| 636 |
} |
| 637 |
|
| 638 |
\newcommand*\lIE@setstopped[0]{% |
| 639 |
\ifnum\lIE@activated=1 % |
| 640 |
\luatexbase@directlua{luainputenc.setstopped()}% |
| 641 |
\fi % |
| 642 |
} |
| 643 |
|
| 644 |
% \end{macrocode} |
| 645 |
% |
| 646 |
% The following 5 macros are made to declare a file that will have to be |
| 647 |
% read in fake UTF-8 and not in 8-bit. These files are the ones that will |
| 648 |
% be generated by \TeX . In \textbf{no way} this means you can include true |
| 649 |
% UTF-8 files, it means that you can include files that have been written |
| 650 |
% by Lua\TeX\ with \textsf{luainputenc}, which means files in fake UTF-8. |
| 651 |
% The macros are very simple, when you call them with a file name (the same |
| 652 |
% as the one you will use with \string\input ), it will read it with or |
| 653 |
% without the fake UTF-8 translation. This package includes a whole bunch |
| 654 |
% of extentions that will be read in fake UTF-8, so the occasions to use |
| 655 |
% these macros will be rare, but if you use them, please report it to the |
| 656 |
% package maintainer. |
| 657 |
% |
| 658 |
% \begin{macro}{\lIE@SetUtfFile} |
| 659 |
% |
| 660 |
% If you call this macro with a file name, each time you will input this |
| 661 |
% file, it will be read in fake UTF-8. You can call it with a file that you |
| 662 |
% generate with Lua\TeX\ and that you want to include. |
| 663 |
% |
| 664 |
% \begin{macrocode} |
| 665 |
|
| 666 |
\newcommand*\lIE@SetUtfFile[1]{% |
| 667 |
\luatexbase@directlua{luainputenc.set_unicode_file("\luatexluaescapestring{#1}")}% |
| 668 |
} |
| 669 |
|
| 670 |
% \end{macrocode} |
| 671 |
% |
| 672 |
% \end{macro} |
| 673 |
% |
| 674 |
% \begin{macro}{\lIE@SetNonUtfFile} |
| 675 |
% |
| 676 |
% Same as the previous macro, except that the file will be read as 8-bit. |
| 677 |
% This macro is useful if there is an exception in an extention (see |
| 678 |
% further comments). |
| 679 |
% |
| 680 |
% \begin{macrocode} |
| 681 |
|
| 682 |
\newcommand*\lIE@SetNonUtfFile[1]{% |
| 683 |
\luatexbase@directlua{luainputenc.set_non_unicode_file("\luatexluaescapestring{#1}")}% |
| 684 |
} |
| 685 |
|
| 686 |
% \end{macrocode} |
| 687 |
% |
| 688 |
% \end{macro} |
| 689 |
% |
| 690 |
% \begin{macro}{\lIE@UnsetFile} |
| 691 |
% |
| 692 |
% This macro gives a file the default behaviour of its extention. |
| 693 |
% |
| 694 |
% \begin{macrocode} |
| 695 |
|
| 696 |
\newcommand*\lIE@UnsetFile[1]{% |
| 697 |
\luatexbase@directlua{luainputenc.unset_file("\luatexluaescapestring{#1}")}% |
| 698 |
} |
| 699 |
|
| 700 |
% \end{macrocode} |
| 701 |
% |
| 702 |
% \end{macro} |
| 703 |
% |
| 704 |
% \begin{macro}{\lIE@SetUtfExt} |
| 705 |
% |
| 706 |
% You can tell \textsf{luainputenc} to treat all files with a particular |
| 707 |
% extention in a certain way. The way the file extention is checked is to |
| 708 |
% compare the four last characters of the filename. So if your extention |
| 709 |
% has only three letters, you must include the preceding dot. This macro |
| 710 |
% tells \textsf{luainputenc} to read all files from an extention in fake |
| 711 |
% UTF-8. |
| 712 |
% |
| 713 |
% \begin{macrocode} |
| 714 |
|
| 715 |
\newcommand*\lIE@SetUtfExt[1]{% |
| 716 |
\luatexbase@directlua{luainputenc.set_unicode_extention("\luatexluaescapestring{#1}")}% |
| 717 |
} |
| 718 |
|
| 719 |
% \end{macrocode} |
| 720 |
% |
| 721 |
% \end{macro} |
| 722 |
% |
| 723 |
% \begin{macro}{\lIE@SetUtfExt} |
| 724 |
% |
| 725 |
% Same as before, but the files will be read in 8-bit. |
| 726 |
% |
| 727 |
% \begin{macrocode} |
| 728 |
|
| 729 |
\newcommand*\lIE@SetNonUtfExt[1]{ |
| 730 |
\luatexbase@directlua{luainputenc.set_non_unicode_extention("\luatexluaescapestring{#1}")} |
| 731 |
} |
| 732 |
|
| 733 |
% \end{macrocode} |
| 734 |
% |
| 735 |
% \end{macro} |
| 736 |
% |
| 737 |
% \begin{macro}{\lIE@InputUtfFile} |
| 738 |
% |
| 739 |
% This macro inputs a file in fake UTF-8. It has the ``feature" to unset |
| 740 |
% the behaviour on the file you will call, so to be safe, you must call |
| 741 |
% them with files for which the behaviour has not been set. |
| 742 |
% |
| 743 |
% \begin{macrocode} |
| 744 |
|
| 745 |
|
| 746 |
\newcommand*\lIE@InputUtfFile[1]{% |
| 747 |
\lIE@SetUtfFile{#1}% |
| 748 |
\input #1% |
| 749 |
\lIE@UnsetFile{#1}% |
| 750 |
} |
| 751 |
|
| 752 |
% \end{macrocode} |
| 753 |
% |
| 754 |
% \end{macro} |
| 755 |
% |
| 756 |
% \begin{macro}{\lIE@InputNonUtfFile} |
| 757 |
% |
| 758 |
% Same as before, but to read a file as 8-bit. |
| 759 |
% |
| 760 |
% \begin{macrocode} |
| 761 |
|
| 762 |
\newcommand*\lIE@InputNonUtfFile[1]{% |
| 763 |
\lIE@SetNonUtfFile{#1}% |
| 764 |
\input #1% |
| 765 |
\lIE@UnsetFile{#1}% |
| 766 |
} |
| 767 |
|
| 768 |
% \end{macrocode} |
| 769 |
% |
| 770 |
% \end{macro} |
| 771 |
% |
| 772 |
% Two definitions to put the previous two macros in the user space. |
| 773 |
% |
| 774 |
% \begin{macrocode} |
| 775 |
|
| 776 |
\newcommand*\InputUtfFile[1]{% |
| 777 |
\lIE@InputUtfFile{#1}% |
| 778 |
} |
| 779 |
|
| 780 |
\newcommand*\InputNonUtfFile[1]{% |
| 781 |
\lIE@InputNonUtfFile{#1}% |
| 782 |
} |
| 783 |
|
| 784 |
\newcount\lIE@activated |
| 785 |
|
| 786 |
\newcommand*{\lIE@activate}[0]{% |
| 787 |
\lIE@activated=1 % |
| 788 |
\lIE@setstarted % |
| 789 |
} |
| 790 |
|
| 791 |
\newcommand*{\lIE@FromInputenc}[1]{% |
| 792 |
\ifnum\lIE@activated=0 % |
| 793 |
\lIE@activate % |
| 794 |
\fi% |
| 795 |
} |
| 796 |
|
| 797 |
\fi |
| 798 |
|
| 799 |
\ProcessOptions* |
| 800 |
|
| 801 |
% \end{macrocode} |
| 802 |
% |
| 803 |
% \iffalse |
| 804 |
%</package> |
| 805 |
% \fi |
| 806 |
% |
| 807 |
% \iffalse |
| 808 |
%<*def> |
| 809 |
% \fi |
| 810 |
% |
| 811 |
% \subsection{\texttt{lutf8.def}} |
| 812 |
% |
| 813 |
% \begin{macrocode} |
| 814 |
%% This file was adapted from utf8.def, which copyright is: |
| 815 |
%% Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 |
| 816 |
%% 2004 2005 2006 The LaTeX3 Project. |
| 817 |
%% |
| 818 |
%% utf8.def is under the lppl version 1.3c or later, and can be found |
| 819 |
%% in the base LaTeX system. |
| 820 |
%% |
| 821 |
%% The lppl can be found at http://www.latex-project.org/lppl.txt |
| 822 |
%% |
| 823 |
%% The changes to utf8.def are Copyright 2009 Elie Roux, and are under |
| 824 |
%% the CC0 license. |
| 825 |
%% |
| 826 |
%% The changes are LuaTeX support. |
| 827 |
%% |
| 828 |
%% This file is distributed under the CC0 license, with clause 6 of the |
| 829 |
%% lppl as additional restrictions. |
| 830 |
|
| 831 |
% \end{macrocode} |
| 832 |
% |
| 833 |
% Most of the file is taken from \texttt{utf8.def}, the main changes are |
| 834 |
% commented. A lot of code was removed, especially the codes that analysed |
| 835 |
% the unicode characters byte by byte. |
| 836 |
% |
| 837 |
% \begin{macrocode} |
| 838 |
|
| 839 |
|
| 840 |
\ProvidesFile{lutf8.def} |
| 841 |
[2010/05/10 v0.97 UTF-8 support for luainputenc] |
| 842 |
|
| 843 |
\makeatletter |
| 844 |
\catcode`\ \saved@space@catcode |
| 845 |
|
| 846 |
\@inpenc@test |
| 847 |
|
| 848 |
\ifx\@begindocumenthook\@undefined |
| 849 |
\makeatother |
| 850 |
\endinput \fi |
| 851 |
|
| 852 |
% \end{macrocode} |
| 853 |
% |
| 854 |
% This function is changed a lot. Its aim is to map the character (first |
| 855 |
% argument) to a macro (second argument). In \texttt{utf8.def} it was |
| 856 |
% complicated as unicode was analyzed byte by byte. With Lua\TeX\ it is |
| 857 |
% extremely simple, we just have to activate the character, and call a |
| 858 |
% traditional |\DeclareInputTeXt|. |
| 859 |
% |
| 860 |
% \begin{macrocode} |
| 861 |
|
| 862 |
\gdef\DeclareUnicodeCharacter#1#2{% |
| 863 |
\@tempcnta"#1% |
| 864 |
\catcode\@tempcnta\active % |
| 865 |
\DeclareInputText{\the\@tempcnta}{#2}% |
| 866 |
} |
| 867 |
|
| 868 |
\@onlypreamble\DeclareUnicodeCharacter |
| 869 |
|
| 870 |
\def\cdp@elt#1#2#3#4{% |
| 871 |
\wlog{Now handling font encoding #1 ...}% |
| 872 |
\lowercase{% |
| 873 |
\InputIfFileExists{#1enc.dfu}}% |
| 874 |
{\wlog{... processing UTF-8 mapping file for font encoding |
| 875 |
#1}% |
| 876 |
\catcode`\ 9\relax}% |
| 877 |
{\wlog{... no UTF-8 mapping file for font encoding #1}}% |
| 878 |
} |
| 879 |
\cdp@list |
| 880 |
|
| 881 |
\def\DeclareFontEncoding@#1#2#3{% |
| 882 |
\expandafter % |
| 883 |
\ifx\csname T@#1\endcsname\relax % |
| 884 |
\def\cdp@elt{\noexpand\cdp@elt}% |
| 885 |
\xdef\cdp@list{\cdp@list\cdp@elt{#1}% |
| 886 |
{\default@family}{\default@series}% |
| 887 |
{\default@shape}}% |
| 888 |
\expandafter\let\csname#1-cmd\endcsname\@changed@cmd % |
| 889 |
\begingroup % |
| 890 |
\wlog{Now handling font encoding #1 ...}% |
| 891 |
\lowercase{% |
| 892 |
\InputIfFileExists{#1enc.dfu}}% |
| 893 |
{\wlog{... processing UTF-8 mapping file for font encoding #1}}% |
| 894 |
{\wlog{... no UTF-8 mapping file for font encoding #1}}% |
| 895 |
\endgroup |
| 896 |
\else |
| 897 |
\@font@info{Redeclaring font encoding #1}% |
| 898 |
\fi |
| 899 |
\global\@namedef{T@#1}{#2}% |
| 900 |
\global\@namedef{M@#1}{\default@M#3}% |
| 901 |
\xdef\LastDeclaredEncoding{#1}% |
| 902 |
} |
| 903 |
|
| 904 |
\DeclareUnicodeCharacter{00A9}{\textcopyright} |
| 905 |
\DeclareUnicodeCharacter{00AA}{\textordfeminine} |
| 906 |
\DeclareUnicodeCharacter{00AE}{\textregistered} |
| 907 |
\DeclareUnicodeCharacter{00BA}{\textordmasculine} |
| 908 |
\DeclareUnicodeCharacter{02C6}{\textasciicircum} |
| 909 |
\DeclareUnicodeCharacter{02DC}{\textasciitilde} |
| 910 |
\DeclareUnicodeCharacter{200C}{\textcompwordmark} |
| 911 |
\DeclareUnicodeCharacter{2026}{\textellipsis} |
| 912 |
\DeclareUnicodeCharacter{2122}{\texttrademark} |
| 913 |
\DeclareUnicodeCharacter{2423}{\textvisiblespace} |
| 914 |
|
| 915 |
% \end{macrocode} |
| 916 |
% |
| 917 |
% \iffalse |
| 918 |
%</def> |
| 919 |
% \fi |
| 920 |
% |
| 921 |
% \iffalse |
| 922 |
%<*defx> |
| 923 |
% \fi |
| 924 |
% |
| 925 |
% \subsection{\texttt{lutf8x.def}} |
| 926 |
% |
| 927 |
% \begin{macrocode} |
| 928 |
%% This file was adapted from utf8.def, which copyright is: |
| 929 |
%% Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 |
| 930 |
%% 2004 2005 2006 The LaTeX3 Project. |
| 931 |
%% |
| 932 |
%% utf8.def is under the lppl version 1.3c or later, and can be found |
| 933 |
%% in the base LaTeX system. |
| 934 |
%% |
| 935 |
%% The lppl can be found at http://www.latex-project.org/lppl.txt |
| 936 |
%% |
| 937 |
%% The changes to utf8.def are Copyright 2009 Elie Roux, and are under |
| 938 |
%% the CC0 license. |
| 939 |
%% |
| 940 |
%% The changes are LuaTeX support. |
| 941 |
%% |
| 942 |
%% This file is distributed under the CC0 license, with clause 6 of the |
| 943 |
%% lppl as additional restrictions. |
| 944 |
|
| 945 |
% \end{macrocode} |
| 946 |
% |
| 947 |
% This file is mostly the code from \texttt{lutf.def}, but it adds |
| 948 |
% mechanisms to pass from \emph{legacy mode} to \emph{unicode font mode}. |
| 949 |
% The trick is to put in a lua table all characters that are activated by |
| 950 |
% the \emph{legacy mode}, and to unactivate them when we switch to |
| 951 |
% \emph{unicode font mode}. This is made (almost) entirely in lua. The |
| 952 |
% difficult part is the changes in |\DeclareFontEncoding|. |
| 953 |
% |
| 954 |
% \begin{macrocode} |
| 955 |
|
| 956 |
\ProvidesFile{lutf8x.def} |
| 957 |
[2010/05/10 v0.97 UTF-8 support for luainputenc] |
| 958 |
|
| 959 |
\makeatletter |
| 960 |
\catcode`\ \saved@space@catcode |
| 961 |
|
| 962 |
\@inpenc@test |
| 963 |
|
| 964 |
\ifx\@begindocumenthook\@undefined |
| 965 |
\makeatother |
| 966 |
\endinput \fi |
| 967 |
|
| 968 |
% \end{macrocode} |
| 969 |
% |
| 970 |
% We change it a little to add the activated character in the lua table. |
| 971 |
% |
| 972 |
% \begin{macrocode} |
| 973 |
|
| 974 |
\gdef\DeclareUnicodeCharacter#1#2{% |
| 975 |
\@tempcnta"#1% |
| 976 |
\luatexbase@directlua{luainputenc.declare_character('\the\@tempcnta')}% |
| 977 |
\catcode\@tempcnta\active % |
| 978 |
\DeclareInputText{\the\@tempcnta}{#2}% |
| 979 |
} |
| 980 |
|
| 981 |
\@onlypreamble\DeclareUnicodeCharacter |
| 982 |
|
| 983 |
\def\cdp@elt#1#2#3#4{% |
| 984 |
\wlog{Now handling font encoding #1 ...}% |
| 985 |
\lowercase{% |
| 986 |
\InputIfFileExists{#1enc.dfu}}% |
| 987 |
{\wlog{... processing UTF-8 mapping file for font encoding |
| 988 |
#1}% |
| 989 |
\catcode`\ 9\relax}% |
| 990 |
{\wlog{... no UTF-8 mapping file for font encoding #1}}% |
| 991 |
} |
| 992 |
\cdp@list |
| 993 |
|
| 994 |
% \end{macrocode} |
| 995 |
% |
| 996 |
% The macros to change from/to \emph{legacy mode} to/from \emph{unicode |
| 997 |
% font mode}. |
| 998 |
% |
| 999 |
% \begin{macrocode} |
| 1000 |
|
| 1001 |
\def\lIE@ActivateUnicodeCatcodes{% |
| 1002 |
\luatexbase@directlua{luainputenc.activate_characters()}% |
| 1003 |
} |
| 1004 |
|
| 1005 |
\def\lIE@DesactivateUnicodeCatcodes{% |
| 1006 |
\luatexbase@directlua{luainputenc.desactivate_characters()}% |
| 1007 |
} |
| 1008 |
|
| 1009 |
\def\lIE@CharactersActivated{% |
| 1010 |
\luatexbase@directlua{luainputenc.force_characters_activated()} |
| 1011 |
} |
| 1012 |
|
| 1013 |
\edef\lIE@EU{EU2} |
| 1014 |
|
| 1015 |
% \end{macrocode} |
| 1016 |
% |
| 1017 |
% We add some code to automatically activate or unactivate characters |
| 1018 |
% according to the encoding changes. Note that we override |\@@enc@update|, |
| 1019 |
% which may pose some problems if a package of yours does it too. |
| 1020 |
% Fortunately this package is the only one that does it in \TeX Live. |
| 1021 |
% |
| 1022 |
% \begin{macrocode} |
| 1023 |
|
| 1024 |
\def\DeclareFontEncoding@#1#2#3{% |
| 1025 |
\edef\lIE@test{#1}% |
| 1026 |
\ifx\lIE@test\lIE@EU % |
| 1027 |
\ifx\LastDeclaredEncoding\lIE@EU\else % |
| 1028 |
\lIE@CharactersActivated % |
| 1029 |
\lIE@DesactivateUnicodeCatcodes % |
| 1030 |
\fi |
| 1031 |
\gdef\@@enc@update{% |
| 1032 |
\edef\lIE@test{#1}% |
| 1033 |
\ifx\f@encoding\lIE@EU % |
| 1034 |
\lIE@DesactivateUnicodeCatcodes % |
| 1035 |
\else % |
| 1036 |
\lIE@ActivateUnicodeCatcodes % |
| 1037 |
\fi |
| 1038 |
\expandafter\let\csname\cf@encoding-cmd\endcsname\@changed@cmd |
| 1039 |
\expandafter\let\csname\f@encoding-cmd\endcsname\@current@cmd |
| 1040 |
\default@T |
| 1041 |
\csname T@\f@encoding\endcsname |
| 1042 |
\csname D@\f@encoding\endcsname |
| 1043 |
\let\enc@update\relax |
| 1044 |
\let\cf@encoding\f@encoding |
| 1045 |
} |
| 1046 |
\else % |
| 1047 |
\expandafter % |
| 1048 |
\ifx\csname T@#1\endcsname\relax % |
| 1049 |
\def\cdp@elt{\noexpand\cdp@elt}% |
| 1050 |
\xdef\cdp@list{\cdp@list\cdp@elt{#1}% |
| 1051 |
{\default@family}{\default@series}% |
| 1052 |
{\default@shape}}% |
| 1053 |
\expandafter\let\csname#1-cmd\endcsname\@changed@cmd % |
| 1054 |
\begingroup % |
| 1055 |
\wlog{Now handling font encoding #1 ...}% |
| 1056 |
\lowercase{% |
| 1057 |
\InputIfFileExists{#1enc.dfu}}% |
| 1058 |
{\wlog{... processing UTF-8 mapping file for font encoding #1}}% |
| 1059 |
{\wlog{... no UTF-8 mapping file for font encoding #1}}% |
| 1060 |
\endgroup |
| 1061 |
\else |
| 1062 |
\@font@info{Redeclaring font encoding #1}% |
| 1063 |
\fi |
| 1064 |
\fi % |
| 1065 |
\global\@namedef{T@#1}{#2}% |
| 1066 |
\global\@namedef{M@#1}{\default@M#3}% |
| 1067 |
\xdef\LastDeclaredEncoding{#1}% |
| 1068 |
} |
| 1069 |
|
| 1070 |
\DeclareUnicodeCharacter{00A9}{\textcopyright} |
| 1071 |
\DeclareUnicodeCharacter{00AA}{\textordfeminine} |
| 1072 |
\DeclareUnicodeCharacter{00AE}{\textregistered} |
| 1073 |
\DeclareUnicodeCharacter{00BA}{\textordmasculine} |
| 1074 |
\DeclareUnicodeCharacter{02C6}{\textasciicircum} |
| 1075 |
\DeclareUnicodeCharacter{02DC}{\textasciitilde} |
| 1076 |
\DeclareUnicodeCharacter{200C}{\textcompwordmark} |
| 1077 |
\DeclareUnicodeCharacter{2026}{\textellipsis} |
| 1078 |
\DeclareUnicodeCharacter{2122}{\texttrademark} |
| 1079 |
\DeclareUnicodeCharacter{2423}{\textvisiblespace} |
| 1080 |
|
| 1081 |
% \end{macrocode} |
| 1082 |
% |
| 1083 |
% \iffalse |
| 1084 |
%</defx> |
| 1085 |
% \fi |
| 1086 |
% |
| 1087 |
% |
| 1088 |
% \subsection{\texttt{luainputenc.lua}} |
| 1089 |
% |
| 1090 |
% First the \texttt{inputenc} module is registered as a Lua\TeX\ module, |
| 1091 |
% with some informations. |
| 1092 |
% |
| 1093 |
% \iffalse |
| 1094 |
%<*lua> |
| 1095 |
% \fi |
| 1096 |
% |
| 1097 |
% \begin{macrocode} |
| 1098 |
|
| 1099 |
module('luainputenc', package.seeall) |
| 1100 |
|
| 1101 |
luainputenc.module = { |
| 1102 |
name = "luainputenc", |
| 1103 |
version = 0.97, |
| 1104 |
date = "2010/05/10", |
| 1105 |
description = "Lua simple inputenc package.", |
| 1106 |
author = "Elie Roux", |
| 1107 |
copyright = "Elie Roux", |
| 1108 |
license = "CC0", |
| 1109 |
} |
| 1110 |
|
| 1111 |
luatexbase.provides_module(luainputenc.module) |
| 1112 |
|
| 1113 |
local format = string.format |
| 1114 |
|
| 1115 |
luainputenc.log = luainputenc.log or function(...) |
| 1116 |
luatexbase.module_log('luainputenc', format(...)) |
| 1117 |
end |
| 1118 |
|
| 1119 |
% \end{macrocode} |
| 1120 |
% |
| 1121 |
% We keep the option and the true encoding in two variables. |
| 1122 |
% |
| 1123 |
% \begin{macrocode} |
| 1124 |
|
| 1125 |
luainputenc.encoding = "utf8" |
| 1126 |
luainputenc.package_option = nil |
| 1127 |
|
| 1128 |
function luainputenc.set_option(option) |
| 1129 |
luainputenc.package_option = option |
| 1130 |
if option == "lutf8" or option == "lutf8x" or option == "utf8x" or option == "unactivate" then |
| 1131 |
luainputenc.encoding = "utf8" |
| 1132 |
else |
| 1133 |
luainputenc.encoding = option |
| 1134 |
end |
| 1135 |
end |
| 1136 |
|
| 1137 |
% \end{macrocode} |
| 1138 |
% |
| 1139 |
% Some local declarations. |
| 1140 |
% |
| 1141 |
% \begin{macrocode} |
| 1142 |
|
| 1143 |
local char, utfchar, byte, format, gsub, utfbyte, utfgsub = |
| 1144 |
string.char, unicode.utf8.char, string.byte, string.format, string.gsub, unicode.utf8.byte, unicode.utf8.gsub |
| 1145 |
|
| 1146 |
% \end{macrocode} |
| 1147 |
% |
| 1148 |
% The function to transform a 8-bit character in the corresponding fake |
| 1149 |
% UTF-8 character. |
| 1150 |
% |
| 1151 |
% \begin{macrocode} |
| 1152 |
|
| 1153 |
function luainputenc.byte_to_utf(ch) |
| 1154 |
return utfchar(byte(ch)) |
| 1155 |
end |
| 1156 |
|
| 1157 |
% \end{macrocode} |
| 1158 |
% |
| 1159 |
% The function that will be registered in the |
| 1160 |
% \texttt{process\_input\_buffer} callback when needed. |
| 1161 |
% |
| 1162 |
% \begin{macrocode} |
| 1163 |
|
| 1164 |
function luainputenc.fake_utf_read(buf) |
| 1165 |
return gsub(buf,"(.)", luainputenc.byte_to_utf) |
| 1166 |
end |
| 1167 |
|
| 1168 |
% \end{macrocode} |
| 1169 |
% |
| 1170 |
% The function to transform a fake utf8 character in the corresponding |
| 1171 |
% 8-bit character. |
| 1172 |
% |
| 1173 |
% \begin{macrocode} |
| 1174 |
|
| 1175 |
function luainputenc.utf_to_byte(ch) |
| 1176 |
return char(utfbyte(ch)) |
| 1177 |
end |
| 1178 |
|
| 1179 |
% \end{macrocode} |
| 1180 |
% |
| 1181 |
% The function that will be registered in the |
| 1182 |
% \texttt{process\_output\_buffer} callback if it exists. |
| 1183 |
% |
| 1184 |
% \begin{macrocode} |
| 1185 |
|
| 1186 |
function luainputenc.fake_utf_write(buf) |
| 1187 |
return utfgsub(buf,"(.)", luainputenc.utf_to_byte) |
| 1188 |
end |
| 1189 |
|
| 1190 |
% \end{macrocode} |
| 1191 |
% |
| 1192 |
% Here we register the two callbacks, and the behaviour is the same as in pdfTeX. |
| 1193 |
% The next part of the file is only the machinery for LuaTeX versions without |
| 1194 |
% the callback |process_output_buffer|, so it will be deprecated after |
| 1195 |
% TeXLive 2009, you are not advised to use it. |
| 1196 |
% |
| 1197 |
% \begin{macrocode} |
| 1198 |
|
| 1199 |
if tex.luatexversion > 42 then |
| 1200 |
|
| 1201 |
function luainputenc.register_callbacks() |
| 1202 |
luatexbase.add_to_callback('process_output_buffer', luainputenc.fake_utf_write, 'luainputenc.fake_utf_write') |
| 1203 |
luatexbase.add_to_callback('process_input_buffer', luainputenc.fake_utf_read, 'luainputenc.fake_utf_read') |
| 1204 |
end |
| 1205 |
|
| 1206 |
else |
| 1207 |
|
| 1208 |
% \end{macrocode} |
| 1209 |
% |
| 1210 |
% \texttt{start()} and \texttt{stop()} are the functions that register or |
| 1211 |
% unregister the function in the callback. When the function is registered, |
| 1212 |
% Lua\TeX\ reads the input in fake UTF-8. |
| 1213 |
% |
| 1214 |
% \begin{macrocode} |
| 1215 |
|
| 1216 |
local started, stopped = 1, 0 |
| 1217 |
|
| 1218 |
luainputenc.state = stopped |
| 1219 |
|
| 1220 |
function luainputenc.setstate(state) |
| 1221 |
if state == luainputenc.state then |
| 1222 |
return |
| 1223 |
elseif state == started then |
| 1224 |
luainputenc.start() |
| 1225 |
else |
| 1226 |
luainputenc.stop() |
| 1227 |
end |
| 1228 |
end |
| 1229 |
|
| 1230 |
function luainputenc.setstarted() |
| 1231 |
luainputenc.setstate(started) |
| 1232 |
end |
| 1233 |
|
| 1234 |
function luainputenc.setstopped() |
| 1235 |
luainputenc.setstate(stopped) |
| 1236 |
end |
| 1237 |
|
| 1238 |
function luainputenc.start() |
| 1239 |
luatexbase.add_to_callback('process_input_buffer', luainputenc.fake_utf_read, |
| 1240 |
'luainputenc.fake_utf_read') |
| 1241 |
luainputenc.state = started |
| 1242 |
if luainputenc.callback_registered == 0 then |
| 1243 |
luainputenc.register_callback() |
| 1244 |
end |
| 1245 |
end |
| 1246 |
|
| 1247 |
function luainputenc.stop() |
| 1248 |
luatexbase.remove_from_callback('process_input_buffer', 'luainputenc.fake_utf_read') |
| 1249 |
luainputenc.state = stopped |
| 1250 |
return |
| 1251 |
end |
| 1252 |
|
| 1253 |
% \end{macrocode} |
| 1254 |
% |
| 1255 |
% Here is a list of all file extentions for which we consider that the |
| 1256 |
% files have been written by Lua\TeX , and thus must be read in fake UTF-8. |
| 1257 |
% I may have forgotten things in the list. If you find a new extention, |
| 1258 |
% please report the maintainer. |
| 1259 |
% |
| 1260 |
% \begin{macrocode} |
| 1261 |
|
| 1262 |
luainputenc.unicode_extentions = { |
| 1263 |
['.aux'] = 1, -- basic files |
| 1264 |
['.toc'] = 1, |
| 1265 |
['.gls'] = 1, |
| 1266 |
['.ind'] = 1, |
| 1267 |
['.idx'] = 1, |
| 1268 |
['.vrb'] = 1, -- beamer and powerdot |
| 1269 |
['.nav'] = 1, -- other beamer extentions |
| 1270 |
['.sol'] = 1, |
| 1271 |
['.qsl'] = 1, |
| 1272 |
['.snm'] = 1, |
| 1273 |
['.pgn'] = 1, -- pagereference |
| 1274 |
['.cpg'] = 1, -- AlProTeX |
| 1275 |
['.pst'] = 1, -- pst-tree |
| 1276 |
['.tmp'] = 1, -- sauerj/collect |
| 1277 |
['.sym'] = 1, -- listofsymbols |
| 1278 |
['.sub'] = 1, -- listofsymbols |
| 1279 |
['.lof'] = 1, -- preprint |
| 1280 |
['.lot'] = 1, -- preprint |
| 1281 |
['mtc1'] = 1, -- minitoc |
| 1282 |
['.ovr'] = 1, -- thumbss |
| 1283 |
['.fff'] = 1, -- endplate |
| 1284 |
['.sbb'] = 1, -- splitbib |
| 1285 |
['.bbl'] = 1, -- latex |
| 1286 |
['.ain'] = 1, -- authorindex |
| 1287 |
['.abb'] = 1, -- juraabbrev |
| 1288 |
['.ent'] = 1, -- endnotes |
| 1289 |
['.end'] = 1, -- fn2end |
| 1290 |
['.thm'] = 1, -- ntheorem |
| 1291 |
['.xtr'] = 1, -- extract |
| 1292 |
['.han'] = 1, -- linguho |
| 1293 |
['.bnd'] = 1, -- bibref |
| 1294 |
['.bbl'] = 1, -- bibref |
| 1295 |
['.col'] = 1, -- mwrite |
| 1296 |
['.ttt'] = 1, -- endfloat |
| 1297 |
['.fax'] = 1, -- lettre |
| 1298 |
['.tns'] = 1, -- lettre |
| 1299 |
['.odt'] = 1, -- lettre |
| 1300 |
['.etq'] = 1, -- lettre |
| 1301 |
['.emd'] = 1, -- poemscol |
| 1302 |
['.emx'] = 1, -- poemscol |
| 1303 |
['.ctn'] = 1, -- poemscol |
| 1304 |
['.hst'] = 1, -- vhistory |
| 1305 |
['.acr'] = 1, -- crosswrd |
| 1306 |
['.dwn'] = 1, -- crosswrd |
| 1307 |
['.ttc'] = 1, -- talk |
| 1308 |
-- ['.txt'] = 1, -- coverpage, but not sure it's safe to include it... |
| 1309 |
['.eve'] = 1, -- calend0 |
| 1310 |
['.scn'] = 1, -- cwebmac |
| 1311 |
} |
| 1312 |
|
| 1313 |
% \end{macrocode} |
| 1314 |
% |
| 1315 |
% The code to define a specific behaviour for certain files. |
| 1316 |
% |
| 1317 |
% \begin{macrocode} |
| 1318 |
|
| 1319 |
luainputenc.unicode_files = {} |
| 1320 |
|
| 1321 |
luainputenc.non_unicode_files = {} |
| 1322 |
|
| 1323 |
function luainputenc.set_unicode_file(filename) |
| 1324 |
if luainputenc.non_unicode_files[filename] == 1 then |
| 1325 |
luainputenc.non_unicode_files[filename] = nil |
| 1326 |
end |
| 1327 |
luainputenc.unicode_files[filename] = 1 |
| 1328 |
end |
| 1329 |
|
| 1330 |
function luainputenc.set_non_unicode_file(filename) |
| 1331 |
if luainputenc.unicode_files[filename] == 1 then |
| 1332 |
luainputenc.unicode_files[filename] = nil |
| 1333 |
end |
| 1334 |
luainputenc.non_unicode_files[filename] = 1 |
| 1335 |
end |
| 1336 |
|
| 1337 |
function luainputenc.set_unicode_extention(ext) |
| 1338 |
luainputenc.unicode_extention[ext] = 1 |
| 1339 |
end |
| 1340 |
|
| 1341 |
function luainputenc.set_non_unicode_extention(ext) |
| 1342 |
if luainputenc.unicode_extentions[ext] == 1 then |
| 1343 |
luainputenc.unicode_extentions[ext] = nil |
| 1344 |
end |
| 1345 |
end |
| 1346 |
|
| 1347 |
function luainputenc.unset_file(filename) |
| 1348 |
if luainputenc.unicode_files[filename] == 1 then |
| 1349 |
luainputenc.unicode_files[filename] = nil |
| 1350 |
elseif luainputenc.non_unicode_files[filename] == 1 then |
| 1351 |
luainputenc.non_unicode_files[filename] = nil |
| 1352 |
end |
| 1353 |
end |
| 1354 |
|
| 1355 |
local unicode, non_unicode = stopped, started |
| 1356 |
|
| 1357 |
function luainputenc.find_state(filename) |
| 1358 |
if luainputenc.unicode_files[filename] == 1 then |
| 1359 |
return unicode |
| 1360 |
elseif luainputenc.non_unicode_files[filename] == 1 then |
| 1361 |
return non_unicode |
| 1362 |
else |
| 1363 |
local ext = filename:sub(-4) |
| 1364 |
if luainputenc.unicode_extentions[ext] == 1 then |
| 1365 |
return unicode |
| 1366 |
else |
| 1367 |
return non_unicode |
| 1368 |
end |
| 1369 |
end |
| 1370 |
end |
| 1371 |
|
| 1372 |
% \end{macrocode} |
| 1373 |
% |
| 1374 |
% We register the functions to stop or start the fake UTF-8 translation in |
| 1375 |
% the appropriate callbacks if necessary. |
| 1376 |
% |
| 1377 |
% \begin{macrocode} |
| 1378 |
|
| 1379 |
function luainputenc.pre_read_file(env) |
| 1380 |
if not env.path then |
| 1381 |
return |
| 1382 |
end |
| 1383 |
local currentstate = luainputenc.state |
| 1384 |
luainputenc.setstate(luainputenc.find_state(env.filename)) |
| 1385 |
env.previousstate = currentstate |
| 1386 |
end |
| 1387 |
|
| 1388 |
function luainputenc.close(env) |
| 1389 |
luainputenc.setstate(env.previousstate) |
| 1390 |
end |
| 1391 |
|
| 1392 |
luainputenc.callback_registered = 0 |
| 1393 |
|
| 1394 |
function luainputenc.register_callback() |
| 1395 |
if luainputenc.callback_registered == 0 then |
| 1396 |
luatexbase.add_to_callback('pre_read_file', luainputenc.pre_read_file, |
| 1397 |
'luainputenc.pre_read_file') |
| 1398 |
luatexbase.add_to_callback('file_close', luainputenc.close, 'luainputenc.close') |
| 1399 |
luainputenc.callback_registered = 1 |
| 1400 |
end |
| 1401 |
end |
| 1402 |
|
| 1403 |
end |
| 1404 |
|
| 1405 |
% \end{macrocode} |
| 1406 |
% |
| 1407 |
% Finally we provide some functions to activate or disactivate the catcodes |
| 1408 |
% of the non-ASCII characters. |
| 1409 |
% |
| 1410 |
% \begin{macrocode} |
| 1411 |
|
| 1412 |
|
| 1413 |
luainputenc.activated_characters = {} |
| 1414 |
luainputenc.characters_are_activated = false |
| 1415 |
|
| 1416 |
function luainputenc.declare_character(c) |
| 1417 |
luainputenc.activated_characters[tonumber(c)] = true |
| 1418 |
end |
| 1419 |
|
| 1420 |
function luainputenc.force_characters_activated () |
| 1421 |
luainputenc.characters_are_activated = true |
| 1422 |
end |
| 1423 |
|
| 1424 |
function luainputenc.activate_characters() |
| 1425 |
if not luainputenc.characters_are_activated then |
| 1426 |
for n, _ in pairs(luainputenc.activated_characters) do |
| 1427 |
tex.sprint(string.format('\\catcode %d\\active',n)) |
| 1428 |
end |
| 1429 |
luainputenc.characters_are_activated = true |
| 1430 |
end |
| 1431 |
end |
| 1432 |
|
| 1433 |
function luainputenc.desactivate_characters() |
| 1434 |
if luainputenc.characters_are_activated then |
| 1435 |
for n, _ in pairs(luainputenc.activated_characters) do |
| 1436 |
tex.sprint(string.format('\\catcode %d=11',n)) |
| 1437 |
end |
| 1438 |
luainputenc.characters_are_activated = false |
| 1439 |
end |
| 1440 |
end |
| 1441 |
|
| 1442 |
% \end{macrocode} |
| 1443 |
% |
| 1444 |
% \iffalse |
| 1445 |
%</lua> |
| 1446 |
% \fi |
| 1447 |
% |
| 1448 |
% \section{Test file} |
| 1449 |
% |
| 1450 |
% Very minimal, just check that the package correctly loads with an option |
| 1451 |
% and doesn't crash on a one-line plain ASCII document body\dots |
| 1452 |
% |
| 1453 |
% \begin{macrocode} |
| 1454 |
%<*test> |
| 1455 |
\documentclass{article} |
| 1456 |
\usepackage[utf8]{luainputenc} |
| 1457 |
\begin{document} |
| 1458 |
bla |
| 1459 |
\end{document} |
| 1460 |
%</test> |
| 1461 |
% \end{macrocode} |
| 1462 |
% |
| 1463 |
% \Finale |
| 1464 |
\endinput |