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