Debian Codegraph @

texmf-dist/tex/lualatex/lua-ul/lua-ul.sty

raw
1 %%
2 %% This is file `lua-ul.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% lua-ul.dtx (with options: `package')
8 %%
9 %% Copyright (C) 2020-2024 by Marcel Krueger
10 %%
11 %% This file may be distributed and/or modified under the
12 %% conditions of the LaTeX Project Public License, either
13 %% version 1.3c of this license or (at your option) any later
14 %% version. The latest version of this license is in:
15 %%
16 %% http://www.latex-project.org/lppl.txt
17 %%
18 %% and version 1.3 or later is part of all distributions of
19 %% LaTeX version 2005/12/01 or later.
20 \NeedsTeXFormat{LaTeX2e}
21 \ProvidesExplPackage
22 {lua-ul}
23 {2024-02-26}{0.2.1}{Underlining and related functionality for LuaTeX}
24 \msg_new:nnnn {lua-ul} {luatex-required} {LuaLaTeX~required} {
25 Lua-UL~requires~LuaLaTeX.~
26 Maybe~you~forgot~to~switch~the~engine~in~your~editor?
27 }
28 \msg_new:nnnn {lua-ul} {luacolor-required} {
29 Color~support~in~lua-ul~requires~luacolor.
30 }{
31 This~error~can~be~fixed~by~adding~\token_to_str:N \usepackage{luacolor}~in~your~preamble.
32 }
33 \sys_if_engine_luatex:F {
34 \msg_error:nn {lua-ul} {luatex-required}
35 }
36 \lua_load_module:n {lua-ul}
37 \bool_new:N \l__luaul_predefined_bool
38 \bool_new:N \l__luaul_soulnames_bool
39 \bool_set_true:N \l__luaul_predefined_bool
40 \DeclareOption {minimal} { \bool_set_false:N \l__luaul_predefined_bool }
41 \DeclareOption {soul} { \bool_set_true:N \l__luaul_soulnames_bool }
42 \ProcessOptions\relax
43 \cs_new_protected:Npn \__luaul_maybe_define_use:Nx #1#2 {
44 \cs_if_free:NT #1 {
45 \cs_gset:Npx #1 {#2}
46 }
47 #1
48 }
49 \cs_generate_variant:Nn \__luaul_maybe_define_use:Nx {c}
50 \cs_new:Npn \__luaul_default_context: {
51 \dim_to_decimal_in_sp:n {1ex}
52 @
53 \cs_if_exist:NT \LuaCol@Attribute {
54 \int_use:N \LuaCol@Attribute
55 }
56 }
57 \NewDocumentCommand \newunderlinetype
58 { E{*}{{}} m O{\__luaul_default_context:} m } {
59 \cs_new_protected:Npn #2 {
60 \__luaul_maybe_define_use:cx {
61 __luaul_set_underline_ \cs_to_str:N #2 _ #3 :
62 } {
63 \LuaULSetUnderline
64 \LuaULNewUnderlineType #1 { #4 \hskip 0pt }
65 }
66 }
67 }
68
69 \bool_if:NT \l__luaul_predefined_bool {
70 \msg_new:nnnn {lua-ul} {height-inconsistent} {Specified~height~is~inconsistent~with~specified~top~and~bottom}{}
71 \msg_new:nnnn {lua-ul} {deprecated} {Used~deprecated~command~`\token_to_str:N #1'.~Please~replace~this~with~`\token_to_str:N #2`.}{}
72 \cs_new:Npn \__luaul_deprecated:NN #1#2 {
73 \cs_new_protected:Npn #1 {
74 \msg_warning:nnnn {lua-ul} {deprecated} {#1} {#2}
75 \cs_gset_eq:NN #1 #2
76 #1
77 }
78 }
79 \tl_new:N \l__luaul_current_color_tl
80 \cs_new:Npn \__luaul_set_color_strip:w \xcolor@ #1#2 {}
81 \cs_new_protected:Npn \luaul_set_color:n #1 {
82 \cs_if_free:NTF \XC@getcolor {
83 \tl_set:Nn \l__luaul_current_color_tl {#1}
84 } {
85 \group_begin:
86 \XC@getcolor {#1} \l_tmpa_tl
87 \use:e { \group_end:
88 \tl_set:Nn \exp_not:N \l__luaul_current_color_tl {
89 \exp_after:wN \__luaul_set_color_strip:w \l_tmpa_tl
90 }
91 }
92 }
93 }
94 \__luaul_deprecated:NN \luaul@setcolor \luaul_set_color:n
95 \cs_new_protected:Npn \luaul_apply_color: {
96 \IfPackageLoadedTF {luacolor} {
97 \cs_if_free:NTF \XC@getcolor {
98 \color {\l__luaul_current_color_tl}
99 }{
100 \exp_after:wN \XC@undeclaredcolor \l__luaul_current_color_tl
101 }
102 }{
103 \msg_error:nn {lua-ul} {luacolor-required}
104 }
105 }
106 \__luaul_deprecated:NN \luaul@applycolor \luaul_apply_color:
107 \cs_new:Npn \luaul_context_color: {
108 \l__luaul_current_color_tl
109 }
110 \cs_new:Npn \__luaul_default_colored_context: {
111 \dim_to_decimal_in_sp:n {1ex}
112 @
113 \luaul_context_color:
114 }
115 \tl_new:N \l__luaul_highlight_color_tl
116 \tl_set:Nn \l__luaul_highlight_color_tl {yellow}
117 \NewDocumentCommand \LuaULSetHighLightColor {om} {
118 \tl_set:Nx \l__luaul_highlight_color_tl {
119 \IfValueTF {#1} {
120 [#1]{#2}
121 }{
122 #2
123 }
124 }
125 }
126
127 \dim_new:N \l__luaul_top_dim
128 \dim_new:N \l__luaul_bottom_dim
129 \dim_new:N \l__luaul_height_dim
130 \bool_new:N \l__luaul_top_set_bool
131 \bool_new:N \l__luaul_bottom_set_bool
132 \bool_new:N \l__luaul_height_set_bool
133 \bool_new:N \l__luaul_color_set_bool
134
135 \keys_define:nn {luaul / generic} {
136 top .code:n = {
137 \bool_set_true:N \l__luaul_top_set_bool
138 \dim_set:Nn \l__luaul_top_dim {#1}
139 },
140 bottom .code:n = {
141 \bool_set_true:N \l__luaul_bottom_set_bool
142 \dim_set:Nn \l__luaul_bottom_dim {(#1)*-1}
143 },
144 height .code:n = {
145 \bool_set_true:N \l__luaul_height_set_bool
146 \dim_set:Nn \l__luaul_height_dim {#1}
147 },
148 color .code:n = {
149 \bool_set_true:N \l__luaul_color_set_bool
150 \luaul_set_color:n {#1}
151 },
152 textcolor .code:n = {
153 \bool_set_false:N \l__luaul_color_set_bool
154 },
155 textcolor .value_forbidden:n = true,
156 }
157
158 \cs_new:Npn \__luaul_parse_generic_keys:n #1 {
159 \bool_set_false:N \l__luaul_top_set_bool
160 \bool_set_false:N \l__luaul_bottom_set_bool
161 \bool_set_false:N \l__luaul_height_set_bool
162
163 \keys_set:nn {luaul / generic} {#1}
164
165 \bool_if:NTF \l__luaul_bottom_set_bool {
166 \bool_if:NTF \l__luaul_top_set_bool {
167 \bool_if:NTF \l__luaul_height_set_bool {
168 \dim_compare:nNnF { \l__luaul_top_dim + \l__luaul_bottom_dim } = {\l__luaul_height_dim} {
169 \msg_error:nn {lua-ul} {height-inconsistent}
170 }
171 } {
172 \dim_set:Nn \l__luaul_height_dim { \l__luaul_top_dim + \l__luaul_bottom_dim }
173 }
174 } {
175 \dim_set:Nn \l__luaul_top_dim { \l__luaul_height_dim - \l__luaul_bottom_dim }
176 }
177 } {
178 \dim_set:Nn \l__luaul_bottom_dim { \l__luaul_height_dim - \l__luaul_top_dim }
179 }
180 }
181
182 \newunderlinetype \@@underLine [
183 \dim_to_decimal_in_sp:n { \l__luaul_top_dim }
184 @
185 \dim_to_decimal_in_sp:n { \l__luaul_bottom_dim }
186 @
187 \bool_if:NTF \l__luaul_color_set_bool {
188 colored @ \luaul_context_color:
189 } {
190 \cs_if_exist:NT \LuaCol@Attribute {
191 \int_use:N \LuaCol@Attribute
192 }
193 }
194 ] {
195 \bool_if:NT \l__luaul_color_set_bool {
196 \luaul_apply_color:
197 }
198 \leaders\vrule height \l__luaul_top_dim depth \l__luaul_bottom_dim
199 }
200 \newunderlinetype \@basicUnderLine {
201 \leaders \vrule height -.65ex depth .75ex
202 }
203
204 \NewDocumentCommand \@underLine {o} {
205 \IfValueTF {#1} {
206 \__luaul_parse_generic_keys:n {
207 top = -.65ex,
208 bottom = -.75ex,
209 }
210 \__luaul_parse_generic_keys:n {
211 #1
212 }
213 \@@underLine
214 } {
215 \@basicUnderLine
216 }
217 }
218 \NewDocumentCommand \underLine {o +m} {
219 \group_begin:
220 \@underLine [#1] #2
221 \group_end:
222 }
223
224 \newunderlinetype \@@strikeThrough {
225 \leaders \vrule height .55ex depth -.45ex
226 }
227 \newunderlinetype \@colored@strikeThrough [\__luaul_default_colored_context:] {
228 \luaul_apply_color:
229 \leaders\vrule height .55ex depth -.45ex
230 }
231 \NewDocumentCommand \@strikeThrough {o} {
232 \IfValueTF {#1} {
233 \luaul_set_color:n {#1}
234 \@colored@strikeThrough
235 }
236 \@@strikeThrough
237 }
238 \NewDocumentCommand \strikeThrough {o +m} {
239 \group_begin:
240 \@strikeThrough[#1] #2
241 \group_end:
242 }
243
244 \newunderlinetype \@@highLight [\__luaul_default_colored_context:] {
245 \luaul_apply_color:
246 \leaders\vrule height 1.75ex depth .75ex
247 }
248 \NewDocumentCommand \@highLight {O{\l__luaul_highlight_color_tl}} {
249 \luaul_set_color:n {#1}
250 \@@highLight
251 }
252 \NewDocumentCommand \highLight {O{\l__luaul_highlight_color_tl} +m} {
253 \group_begin:
254 \@highLight [#1] #2
255 \group_end:
256 }
257 \bool_if:NT \l__luaul_soulnames_bool {
258 \cs_new_eq:NN \textul \underLine \cs_new_eq:NN \ul \textul
259 \cs_new_eq:NN \textst \strikeThrough \cs_new_eq:NN \st \textst
260 \cs_new_eq:NN \texthl \highLight \cs_new_eq:NN \hl \texthl
261 }
262 }
263 \ifx \reset@font \normalfont
264 \let \reset@font \relax
265 \DeclareRobustCommand \reset@font {%
266 \normalfont
267 \LuaULResetUnderline*%
268 }
269 \else
270 \MakeRobust \reset@font
271 \begingroup
272 \expandafter \let
273 \expandafter \helper
274 \csname reset@font \endcsname
275 \expandafter \endgroup
276 \expandafter \gdef
277 \csname reset@font \expandafter \endcsname
278 \expandafter {%
279 \helper%
280 \LuaULResetUnderline*%
281 }
282 \fi
283 \output\expandafter\expandafter\expandafter{%
284 \expandafter\expandafter\expandafter\LuaULResetUnderline
285 \expandafter\expandafter\expandafter*%
286 \expandafter\@firstofone\the\output%
287 }
288 %%
289 %%
290 %% End of file `lua-ul.sty'.