| 1 |
% !TeX root = selnolig.tex |
| 2 |
% !TEX TS-program = lualatex |
| 3 |
|
| 4 |
% This entire package is placed under the terms of the |
| 5 |
% LaTeX Project Public License, version 1.3 or later |
| 6 |
% (http://www.latex-project.org/lppl.txt). |
| 7 |
% It has the status "maintained". |
| 8 |
% |
| 9 |
% Author: Mico Loretan (loretan dot mico at gmail dot com) |
| 10 |
|
| 11 |
|
| 12 |
% Part 1: Preliminaries |
| 13 |
% --------------------- |
| 14 |
|
| 15 |
\def\selnoligpackagename{selnolig} |
| 16 |
\def\selnoligpackageversion{0.302} |
| 17 |
\def\selnoligpackagedate{2015/10/26} |
| 18 |
|
| 19 |
% Announce who we are. |
| 20 |
|
| 21 |
\typeout{=== Package \selnoligpackagename, |
| 22 |
Version \selnoligpackageversion, |
| 23 |
Date \selnoligpackagedate\space ===} |
| 24 |
\ProvidesPackage{selnolig}[\selnoligpackagedate] |
| 25 |
|
| 26 |
|
| 27 |
% Issue warning message if not running under LuaLaTeX. |
| 28 |
|
| 29 |
\RequirePackage{ifluatex} |
| 30 |
\ifluatex |
| 31 |
\RequirePackage{luatexbase} |
| 32 |
\else |
| 33 |
\typeout{ ======================================= } |
| 34 |
\typeout{ WARNING WARNING WARNING } |
| 35 |
\typeout{ --------------------------------------- } |
| 36 |
\typeout{ The ligature suppression macros of the } |
| 37 |
\typeout{ selnolig package *require* LuaLaTeX. } |
| 38 |
\typeout{ Because you're NOT running this package } |
| 39 |
\typeout{ under LuaLaTeX, ligature suppression } |
| 40 |
\typeout{ *can not* be performed. } |
| 41 |
\typeout{=========================================} |
| 42 |
\fi |
| 43 |
|
| 44 |
% If the 'fontspec' package isn't loaded by the time |
| 45 |
% the '\begin{document}' directive is encoutered, issue |
| 46 |
% an error message and exit. |
| 47 |
|
| 48 |
\AtBeginDocument{% |
| 49 |
\ifluatex |
| 50 |
\@ifpackageloaded{fontspec}{}{% |
| 51 |
\PackageError{selnolig}{% |
| 52 |
========================================== \MessageBreak |
| 53 |
Error Alert Error Alert \MessageBreak |
| 54 |
------------------------------------------ \MessageBreak |
| 55 |
The selnolig package *requires* the \MessageBreak |
| 56 |
'fontspec' package, but it hasn't been \MessageBreak |
| 57 |
loaded. Exiting now. \MessageBreak |
| 58 |
===========================================} |
| 59 |
} |
| 60 |
\fi |
| 61 |
} |
| 62 |
|
| 63 |
% Set up some fundamental Boolean variables, their |
| 64 |
% default values, and define the user options. |
| 65 |
|
| 66 |
% The main language options are 'english' and 'german'. |
| 67 |
% We provide the option 'otherlang' option just in case |
| 68 |
% a user wants to provide ligature suppression patterns |
| 69 |
% for languages other than English and German. |
| 70 |
|
| 71 |
\newif\if@english\@englishfalse |
| 72 |
\newif\if@german\@germanfalse |
| 73 |
\newif\if@otherlang\@otherlangfalse |
| 74 |
|
| 75 |
\DeclareOption{english}{\@englishtrue} |
| 76 |
% synonymous options: |
| 77 |
\DeclareOption{usenglish}{\@englishtrue} |
| 78 |
\DeclareOption{ukenglish}{\@englishtrue} |
| 79 |
\DeclareOption{USenglish}{\@englishtrue} |
| 80 |
\DeclareOption{UKenglish}{\@englishtrue} |
| 81 |
\DeclareOption{american}{\@englishtrue} |
| 82 |
\DeclareOption{british}{\@englishtrue} |
| 83 |
\DeclareOption{canadian}{\@englishtrue} |
| 84 |
\DeclareOption{australian}{\@englishtrue} |
| 85 |
\DeclareOption{newzealand}{\@englishtrue} |
| 86 |
|
| 87 |
\DeclareOption{ngerman}{\@germantrue} |
| 88 |
% synonymous options: |
| 89 |
\DeclareOption{german}{\@germantrue} |
| 90 |
\DeclareOption{austrian}{\@germantrue} |
| 91 |
\DeclareOption{naustrian}{\@germantrue} |
| 92 |
\DeclareOption{swiss}{\@germantrue} |
| 93 |
\DeclareOption{swissgerman}{\@germantrue} |
| 94 |
|
| 95 |
\DeclareOption{otherlang}{\@otherlangtrue} |
| 96 |
% synonymous option: |
| 97 |
\DeclareOption{otherlanguage}{\@otherlangtrue} |
| 98 |
|
| 99 |
|
| 100 |
% For English, the default is to load only a fairly basic |
| 101 |
% set of non-ligation rules pertaining to f-ligatures. |
| 102 |
% Among them are the "standard five" (ff, fi, fl, ffi, |
| 103 |
% and ffl) ligatures as well as the ft ligature. |
| 104 |
% |
| 105 |
% Two options to augment the "basic" setting: |
| 106 |
% - broadf More non-ligation rules for f-ligatures |
| 107 |
% - hdlig Additional ligature suppression rules for |
| 108 |
% 'historic' and/or 'discretionary' ligatures, |
| 109 |
% e.g., ct, sp, st, sk, th, as, is, us, fr, |
| 110 |
% ll, et, at, and ta |
| 111 |
|
| 112 |
\newif\if@broadfset\@broadfsetfalse |
| 113 |
\DeclareOption{broadf}{\@broadfsettrue} |
| 114 |
|
| 115 |
\newif\if@hdligset\@hdligsetfalse |
| 116 |
\DeclareOption{hdlig}{\@hdligsettrue} |
| 117 |
|
| 118 |
% The 'basic' option automatically sets the preceding |
| 119 |
% Booleans to 'false'. |
| 120 |
|
| 121 |
\DeclareOption{basic}{\@broadfsetfalse\@hdligsetfalse} |
| 122 |
|
| 123 |
|
| 124 |
% The package also provides hyphenation exception |
| 125 |
% patterns for English and German language words. |
| 126 |
% Loading these patterns is enabled by default. This |
| 127 |
% can be disabled by providing the option |
| 128 |
% 'noadditionalhyphenationpatterns'. |
| 129 |
|
| 130 |
\newif\if@addlhyph\@addlhyphtrue |
| 131 |
\DeclareOption{noadditionalhyphenationpatterns}{\@addlhyphfalse} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
% The option 'noftligs' serves to suppress ft and fft |
| 136 |
% ligatures *globally*. Default value: 'false'. |
| 137 |
|
| 138 |
\newif\if@noftligs\@noftligsfalse |
| 139 |
\DeclareOption{noftligs}{\@noftligstrue} |
| 140 |
|
| 141 |
|
| 142 |
% Finally, an option to set most language-related |
| 143 |
% Boolean variables (other than '@addlhyph') to |
| 144 |
% 'true' simultaneously. |
| 145 |
|
| 146 |
\DeclareOption{all}{% |
| 147 |
\@englishtrue \@broadfsettrue \@hdligsettrue |
| 148 |
\@germantrue \@otherlangtrue} |
| 149 |
|
| 150 |
% Finally, process all options |
| 151 |
\ProcessOptions\relax |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
% Part 2: Load the lua code and set up the user macros |
| 156 |
% ---------------------------------------------------- |
| 157 |
|
| 158 |
\ifluatex |
| 159 |
% Load the lua code contained in 'selnolig.lua'. |
| 160 |
\directlua{ require("selnolig.lua") } |
| 161 |
|
| 162 |
% Commands to switch selnolig's routines on and off |
| 163 |
\newcommand\selnoligon{% |
| 164 |
\directlua{ enableselnolig() }% |
| 165 |
} |
| 166 |
|
| 167 |
\newcommand\selnoligoff{% |
| 168 |
\directlua{ disableselnolig() }% |
| 169 |
} |
| 170 |
|
| 171 |
% By default, selnolig's macros are switched on |
| 172 |
\selnoligon |
| 173 |
|
| 174 |
|
| 175 |
% Recording operations of selnolig package to the log |
| 176 |
% file is enabled via the '\debugon' command. |
| 177 |
% Note: the default value of 'debug' (set in |
| 178 |
% 'selnolig.lua') is 'false'. To turn off logging |
| 179 |
% of selnolig's activity, use the command \debugoff. |
| 180 |
\newcommand\debugon{% |
| 181 |
\directlua{ debug=true } |
| 182 |
} |
| 183 |
\newcommand\debugoff{% |
| 184 |
\directlua{ debug=false } |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
% The first main user macro is called '\nolig': |
| 189 |
\newcommand\nolig[2]{ |
| 190 |
\directlua{ |
| 191 |
suppress_liga( "\luatexluaescapestring{#1}", |
| 192 |
"\luatexluaescapestring{#2}" ) |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
% A second user macro allows global overriding of |
| 197 |
% rules set by \nolig instructions: |
| 198 |
\newcommand\keeplig[1]{ |
| 199 |
\directlua{ |
| 200 |
always_keep_liga( "\luatexluaescapestring{#1}" ) |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
% A third user macro turns ligature suppression off |
| 205 |
% temporarily: |
| 206 |
\newcommand\uselig[1]{% |
| 207 |
\directlua{ enable_suppression(false) }% |
| 208 |
\mbox{#1}% |
| 209 |
\directlua{ enable_suppression(true) }% |
| 210 |
} |
| 211 |
|
| 212 |
% A fourth user macro: '\breaklig'. This is |
| 213 |
% hopefully easier to remember than having to |
| 214 |
% type "\-\hspace{0pt}". |
| 215 |
|
| 216 |
\newcommand{\breaklig}{\-{\hspace{0pt}}} |
| 217 |
|
| 218 |
|
| 219 |
\else |
| 220 |
% If *not* running under LuaLaTeX, provide dummy |
| 221 |
% definitions for package's four main user macros |
| 222 |
% as well as for the auxilliary macros \selnoligon, |
| 223 |
% \selnoligoff, \debugon, and \debugoff. |
| 224 |
\newcommand{\nolig}[2]{} |
| 225 |
\newcommand{\keeplig}[1]{} |
| 226 |
\newcommand{\uselig}[1]{\mbox{#1}} |
| 227 |
\newcommand{\breaklig}{\-{\hspace{0pt}}} |
| 228 |
\let\selnoligon\relax |
| 229 |
\let\selnoligoff\relax |
| 230 |
\let\debugon\relax |
| 231 |
\let\debugoff\relax |
| 232 |
|
| 233 |
\fi |
| 234 |
|
| 235 |
|
| 236 |
% Part 3: What to do if the 'english' option is set |
| 237 |
% ------------------------------------------------- |
| 238 |
|
| 239 |
\if@english |
| 240 |
\ifluatex % English ligature suppression rules |
| 241 |
\RequirePackage{selnolig-english-patterns} |
| 242 |
\fi |
| 243 |
\if@addlhyph |
| 244 |
\RequirePackage{selnolig-english-hyphex} |
| 245 |
\fi |
| 246 |
\fi |
| 247 |
|
| 248 |
|
| 249 |
% Part 4: What to do if the 'ngerman' option is set |
| 250 |
% ------------------------------------------------- |
| 251 |
|
| 252 |
\if@german |
| 253 |
\ifluatex % German ligature suppression rules |
| 254 |
\RequirePackage{selnolig-german-patterns} |
| 255 |
\fi |
| 256 |
\if@addlhyph |
| 257 |
\RequirePackage{selnolig-german-hyphex} |
| 258 |
\fi |
| 259 |
\fi |
| 260 |
|
| 261 |
|
| 262 |
% Part 5: What to do if the 'otherlang' option is set |
| 263 |
% --------------------------------------------------- |
| 264 |
|
| 265 |
\if@otherlang |
| 266 |
% currently nothing included |
| 267 |
\fi |