% !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.250} \def\selnoligpackagedate{2013/06/30} % 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} % 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 \if@noftligs{% % suppress ft and fft ligatures globally \AtBeginDocument{ \nolig{ft}{f|t} } \fi % 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}" ) } } % A third user macro turns ligature suppression % off temporarily: \newcommand\uselig[1]{% \directlua{ enable_suppression(false) }% \mbox{#1}% \directlua{ enable_suppression(true) }% } \else % If *not* running under LuaLaTeX, provide dummy % definitions for package's user macros. \newcommand{\nolig}[2]{} \newcommand{\keeplig}[1]{} \newcommand{\uselig}[1]{\mbox{#1}} \let\selnoligon\relax \let\selnoligoff\relax \let\debugon\relax \let\debugoff\relax \fi % A fourth 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