summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/spelling/spelling.sty
blob: d73661ee1ea38d7ed7275eb737316997fcd1d5dc (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
%%% spelling.sty
%%% Copyright 2012, 2013 Stephan Hennig
%%
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3 of this license
%% or (at your option) any later version.  The latest version of this
%% license is in http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% See file README for more information.
%%
\ProvidesPackage{spelling}
  [2013/02/12 v0.3 Aid spell-checking (SH)]
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
% Test for the LuaTeX engine.
\RequirePackage{ifluatex}
\ifluatex
\else
\PackageError{spelling}{LuaTeX engine required}{You could try with the
  `lualatex' command.}
\fi
\RequirePackage{ifthen}
\RequirePackage{luatexbase}
% Load main Lua file.
\directlua name {spelling}{
  % The main Lua file is not a module, so we must pass a full path to
  % `dofile`.
  local f = kpse.find_file('spelling.lua', 'lua')
  dofile(f)
}
% Words are extracted after pages have been built.  In lack of a proper
% Lua call-back, we're hooking into shipout from the LaTeX side.
\RequirePackage{atbegshi}
\AtBeginShipout{%
  \directlua name {spelling-atbeginshipout}{cb_AtBeginShipout_pkg_spelling(\the\AtBeginShipoutBox)}%
}
% Provide command for reading-in a list of bad spellings.
\newcommand*{\spellingreadbad}[1]{%
  \directlua{
    pkg_spelling_stage[1].parse_bad_plain_list_file('\luaescapestring{#1}')
  }%
}
% Provide command for reading-in a list of good spellings.
\newcommand*{\spellingreadgood}[1]{%
  \directlua{
    pkg_spelling_stage[1].parse_good_plain_list_file('\luaescapestring{#1}')
  }%
}
% Provide command for reading bad spellings from a LanguageTool XML
% file.
\newcommand*{\spellingreadLT}[1]{%
  \directlua{
    pkg_spelling_stage[1].parse_XML_LanguageTool_file('\luaescapestring{#1}')
  }%
}
% Provide command for enabling/disabling visual feedback.
\newcommand*{\spellinghighlight}[1]{%
  \ifthenelse{\equal{#1}{on}}{%
    \directlua{
      pkg_spelling_stage[2].enable_word_highlighting()
    }%
  }{%
    \directlua{
      pkg_spelling_stage[2].disable_word_highlighting()
    }%
  }%
}
% Provide command for setting visual feedback colour.
\newcommand*{\spellinghighlightcolor}[1]{%
  \directlua{
    pkg_spelling_stage[2].set_highlight_color('\luaescapestring{#1}')
  }%
}
% Provide command for enabling/disabling text ouput.
\newcommand*{\spellingoutput}[1]{%
  \ifthenelse{\equal{#1}{on}}{%
    \directlua{
      pkg_spelling_stage[4].enable_text_output()
    }%
  }{%
    \directlua{
      pkg_spelling_stage[4].disable_text_output()
    }%
  }%
}
% Provide command for setting text output file name.
\newcommand*{\spellingoutputname}[1]{%
  \directlua{
    pkg_spelling_stage[4].set_output_file_name('\luaescapestring{#1}')
  }%
}
% Provide command for setting text output file line length.
\newcommand*{\spellingoutputlinelength}[1]{%
  \directlua{
    pkg_spelling_stage[4].set_output_line_length('\luaescapestring{#1}')
  }%
}
% Provide command for setting text output EOL character.
\newcommand*{\spellingoutputeol}[1]{%
  \directlua{
    pkg_spelling_stage[4].set_output_eol('\luaescapestring{#1}')
  }%
}
% Provide command for enabling/disabling text extraction.
\newcommand*{\spellingextract}[1]{%
  \ifthenelse{\equal{#1}{on}}{%
    \directlua{
      pkg_spelling_stage[2].enable_text_tagging()
    }%
  }{%
    \directlua{
      pkg_spelling_stage[2].disable_text_tagging()
    }%
  }%
}
% Provide command to declare code point mappings.
\newcommand*{\spellingmapping}[2]{%
  \directlua{
    local r = pkg_spelling_stage[2].set_mapping(\luaescapestring{#1}, '\luaescapestring{#2}')
    if r == false then
      texio.write_nl('package spelling: invalid mapping: \luaescapestring{#1} => \luaescapestring{#2}')
    end
  }%
}
% Provide command to clear all existing code point mappings.
\newcommand*{\spellingclearallmappings}{%
  \directlua{
    pkg_spelling_stage[2].clear_all_mappings()
  }%
}
% Provide command to specify table paragraph behaviour.
\newcommand*{\spellingtablepar}[1]{%
  \directlua{
    pkg_spelling_stage[3].set_table_paragraphs(\luaescapestring{#1})
  }%
}
%
% Read bad and good spellings from default sources.
\directlua{
  pkg_spelling_stage[1].parse_default_bad_and_good()
}%
%
% Enable visual feedback.
\spellinghighlight{on}
% Enable text ouput at the end of the LuaTeX run.
\spellingoutput{on}
% Enable text extraction.
\spellingextract{on}