summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/selnolig/selnolig.sty
blob: 7d56624a1570311906a6a31bf097ff1aff073352 (plain)
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
% !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.216}
\def\selnoligpackagedate{2013/05/25}

% Announce who we are. Issue warning message if we're
% not running under LuaLaTeX.

\typeout{=== Package \selnoligpackagename, 
             Version \selnoligpackageversion, 
             Date    \selnoligpackagedate ===}
\ProvidesPackage{selnolig}[\selnoligpackagedate]

\RequirePackage{ifluatex}

\ifluatex
  \RequirePackage{luatexbase,luacode,expl3}
\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 override this "basic" setting:
% - broadf  Many more non-ligation rules for f-ligatures,
%            incl. fb, fh, fj, and fk character pairs.
% - 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 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 'basic' option automatically sets the preceding Booleans 
% to 'false', even if historic and/or rare ligatures are enabled

\DeclareOption{basic}{\@broadfsetfalse\@hdligsetfalse}


% Last but not least, an option to set all 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
  
  % Record operations of selnolig package to the log 
  % file: Enabled via '\debugon' command
  \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}" )
     }
  }

\else
  % If *not* running under LuaLaTeX, provide dummy
  % definitions for package's user macros.
  \newcommand{\nolig}[2]{}
  \newcommand{\keeplig}[1]{}
  \let\selnoligon\relax
  \let\selnoligoff\relax
  \let\debugon\relax
  \let\debugoff\relax
\fi


% A third user macro: '\breaklig'. This is hopefully 
% easier to remember than having to type "\-\hspace{0pt}".
% (It's defined outside the \ifluatex conditional since
% it doesn't use any lua code.)

\newcommand\breaklig{\-{\hspace{0pt}}}



% Part 3: What to do if the 'english' option is set
% -------------------------------------------------

\if@english
   % load English-language ligature suppression rules
   \ifluatex
      \RequirePackage{selnolig-english-patterns}
   \fi

   % load additional hyphenation exception patterns
   \if@addlhyph
      \RequirePackage{selnolig-english-hyphex}
   \fi
\fi


% Part 4: What to do if the 'ngerman' option is set
% -------------------------------------------------

\if@german
   % load German-language ligature suppression rules
   \ifluatex
      \RequirePackage{selnolig-german-patterns}
   \fi

   % load additional hyphenation exception patterns
   \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