summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty')
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty317
1 files changed, 230 insertions, 87 deletions
diff --git a/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty b/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
index 3f9c6571f74..562beef0f9e 100644
--- a/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
+++ b/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
@@ -6,7 +6,7 @@
%%
%% lua-ul.dtx (with options: `package')
%%
-%% Copyright (C) 2020-2021 by Marcel Krueger
+%% Copyright (C) 2020-2022 by Marcel Krueger
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
@@ -18,105 +18,248 @@
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage
+\ProvidesExplPackage
{lua-ul}
- [2021/05/12 v0.1.4 Underlining and related functionality for LuaTeX]
-
-\ifx\directlua\undefined
- \PackageError{lua-ul}{LuaLaTeX required}%
- {Lua-UL requires LuaLaTeX.
- Maybe you forgot to switch the engine in your editor?}
-\fi
-\directlua{require'lua-ul'}
-\RequirePackage{xparse}
-\newif\ifluaul@predefined
-\newif\ifluaul@soulnames
-\luaul@predefinedtrue
-\DeclareOption{minimal}{\luaul@predefinedfalse}
-\DeclareOption{soul}{\luaul@soulnamestrue}
+ {2022-05-31}{0.2.0}{Underlining and related functionality for LuaTeX}
+\msg_new:nnnn {lua-ul} {luatex-required} {LuaLaTeX~required} {
+ Lua-UL~requires~LuaLaTeX.~
+ Maybe~you~forgot~to~switch~the~engine~in~your~editor?
+}
+\msg_new:nnnn {lua-ul} {luacolor-required} {
+ Color~support~in~lua-ul~requires~luacolor.
+}{
+ This~error~can~be~fixed~by~adding~\token_to_str:N \usepackage{luacolor}~in~your~preamble.
+}
+\sys_if_engine_luatex:F {
+ \msg_error:nn {lua-ul} {luatex-required}
+}
+\lua_load_module:n {lua-ul}
+\bool_new:N \l__luaul_predefined_bool
+\bool_new:N \l__luaul_soulnames_bool
+\bool_set_true:N \l__luaul_predefined_bool
+\DeclareOption {minimal} { \bool_set_false:N \l__luaul_predefined_bool }
+\DeclareOption {soul} { \bool_set_true:N \l__luaul_soulnames_bool }
\ProcessOptions\relax
-\protected\def\luaul@maybedefineuse#1#2{%
- \unless\ifcsname#1\endcsname
- \expandafter\xdef\csname#1\endcsname{#2}%
- \fi
- \csname#1\endcsname
+\cs_new_protected:Npn \__luaul_maybe_define_use:Nx #1#2 {
+ \cs_if_free:NT #1 {
+ \cs_gset:Npx #1 {#2}
+ }
+ #1
}
- \newcommand\luaul@defaultcontext{%
- \number\dimexpr1ex
- @\unless\ifx\undefined\LuaCol@Attribute
- \the\LuaCol@Attribute
- \fi
- }
-\NewDocumentCommand\newunderlinetype
- { E{*}{{}} m O{\luaul@defaultcontext} m }{%
- \newcommand#2{}% "Reserve" the name
- \protected\def#2{%
- \expandafter\luaul@maybedefineuse
- \expanded{{\csstring#2@@#3}}%
- {\LuaULSetUnderline
- \LuaULNewUnderlineType#1{#4\hskip0pt}%
- }}%
+\cs_generate_variant:Nn \__luaul_maybe_define_use:Nx {c}
+\cs_new:Npn \__luaul_default_context: {
+ \dim_to_decimal_in_sp:n {1ex}
+ @
+ \cs_if_exist:NT \LuaCol@Attribute {
+ \int_use:N \LuaCol@Attribute
+ }
}
-\ifluaul@predefined
- \newcommand\luaul@highlight@color{yellow}
- \def\luaul@@setcolor\xcolor@#1#2{}
- \newcommand\luaul@setcolor[1]{%
- \ifx\XC@getcolor\undefined
- \def\luaul@currentcolor{#1}%
- \else
- \begingroup
- \XC@getcolor{#1}\luaul@tmpcolor
- \expanded{\endgroup
- \def\noexpand\luaul@currentcolor{%
- \expandafter\luaul@@setcolor\luaul@tmpcolor}}%
- \fi
- }
- \newcommand\luaul@applycolor{%
- \ifx\XC@getcolor\undefined
- \color{\luaul@currentcolor}%
- \else
- \expandafter\XC@undeclaredcolor\luaul@currentcolor
- \fi
- }
-\NewDocumentCommand\LuaULSetHighLightColor{om}{%
- \edef\luaul@highlight@color{\IfValueTF{#1}{[#1]{#2}}{#2}}%
+\NewDocumentCommand \newunderlinetype
+ { E{*}{{}} m O{\__luaul_default_context:} m } {
+ \cs_new_protected:Npn #2 {
+ \__luaul_maybe_define_use:cx {
+ __luaul_set_underline_ \cs_to_str:N #2 _ #3 :
+ } {
+ \LuaULSetUnderline
+ \LuaULNewUnderlineType #1 { #4 \hskip 0pt }
+ }
+ }
}
- \newunderlinetype\@underLine{%
- \leaders\vrule height -.65ex depth .75ex
+
+\bool_if:NT \l__luaul_predefined_bool {
+ \msg_new:nnnn {lua-ul} {height-inconsistent} {Specified~height~is~inconsistent~with~specified~top~and~bottom}{}
+ \msg_new:nnnn {lua-ul} {deprecated} {Used~deprecated~command~`\token_to_str:N #1'.~Please~replace~this~with~`\token_to_str:N #2`.}{}
+ \cs_new:Npn \__luaul_deprecated:NN #1#2 {
+ \cs_new_protected:Npn #1 {
+ \msg_warning:nnnn {lua-ul} {deprecated} {#1} {#2}
+ \cs_gset_eq:NN #1 #2
+ #1
+ }
+ }
+ \tl_new:N \l__luaul_current_color_tl
+ \cs_new:Npn \__luaul_set_color_strip:w \xcolor@ #1#2 {}
+ \cs_new_protected:Npn \luaul_set_color:n #1 {
+ \cs_if_free:NTF \XC@getcolor {
+ \tl_set:Nn \l__luaul_current_color_tl {#1}
+ } {
+ \group_begin:
+ \XC@getcolor {#1} \l_tmpa_tl
+ \use:e { \group_end:
+ \tl_set:Nn \exp_not:N \l__luaul_current_color_tl {
+ \exp_after:wN \__luaul_set_color_strip:w \l_tmpa_tl
+ }
+ }
+ }
+ }
+ \__luaul_deprecated:NN \luaul@setcolor \luaul_set_color:n
+ \cs_new_protected:Npn \luaul_apply_color: {
+ \IfPackageLoadedTF {luacolor} {
+ \cs_if_free:NTF \XC@getcolor {
+ \color {\l__luaul_current_color_tl}
+ }{
+ \exp_after:wN \XC@undeclaredcolor \l__luaul_current_color_tl
+ }
+ }{
+ \msg_error:nn {lua-ul} {luacolor-required}
+ }
+ }
+ \__luaul_deprecated:NN \luaul@applycolor \luaul_apply_color:
+ \cs_new:Npn \luaul_context_color: {
+ \l__luaul_current_color_tl
+ }
+ \cs_new:Npn \__luaul_default_colored_context: {
+ \dim_to_decimal_in_sp:n {1ex}
+ @
+ \luaul_context_color:
+ }
+ \tl_new:N \l__luaul_highlight_color_tl
+ \tl_set:Nn \l__luaul_highlight_color_tl {yellow}
+ \NewDocumentCommand \LuaULSetHighLightColor {om} {
+ \tl_set:Nx \l__luaul_highlight_color_tl {
+ \IfValueTF {#1} {
+ [#1]{#2}
+ }{
+ #2
+ }
+ }
}
- \NewDocumentCommand\underLine{+m}{{\@underLine#1}}
- \newunderlinetype\@strikeThrough{%
- \leaders\vrule height .55ex depth -.45ex
+ \dim_new:N \l__luaul_top_dim
+ \dim_new:N \l__luaul_bottom_dim
+ \dim_new:N \l__luaul_height_dim
+ \bool_new:N \l__luaul_top_set_bool
+ \bool_new:N \l__luaul_bottom_set_bool
+ \bool_new:N \l__luaul_height_set_bool
+ \bool_new:N \l__luaul_color_set_bool
+
+ \keys_define:nn {luaul / generic} {
+ top .code:n = {
+ \bool_set_true:N \l__luaul_top_set_bool
+ \dim_set:Nn \l__luaul_top_dim {#1}
+ },
+ bottom .code:n = {
+ \bool_set_true:N \l__luaul_bottom_set_bool
+ \dim_set:Nn \l__luaul_bottom_dim {(#1)*-1}
+ },
+ height .code:n = {
+ \bool_set_true:N \l__luaul_height_set_bool
+ \dim_set:Nn \l__luaul_height_dim {#1}
+ },
+ color .code:n = {
+ \bool_set_true:N \l__luaul_color_set_bool
+ \luaul_set_color:n {#1}
+ },
+ textcolor .code:n = {
+ \bool_set_false:N \l__luaul_color_set_bool
+ },
+ textcolor .value_forbidden:n = true,
}
- \newunderlinetype\colored@strikeThrough[\number\dimexpr1ex@%
- \luaul@currentcolor]{%
- \luaul@applycolor
+
+ \cs_new:Npn \__luaul_parse_generic_keys:n #1 {
+ \bool_set_false:N \l__luaul_top_set_bool
+ \bool_set_false:N \l__luaul_bottom_set_bool
+ \bool_set_false:N \l__luaul_height_set_bool
+
+ \keys_set:nn {luaul / generic} {#1}
+
+ \bool_if:NTF \l__luaul_bottom_set_bool {
+ \bool_if:NTF \l__luaul_top_set_bool {
+ \bool_if:NTF \l__luaul_height_set_bool {
+ \dim_compare:nNnF { \l__luaul_top_dim + \l__luaul_bottom_dim } = {\l__luaul_height_dim} {
+ \msg_error:nn {lua-ul} {height-inconsistent}
+ }
+ } {
+ \dim_set:Nn \l__luaul_height_dim { \l__luaul_top_dim + \l__luaul_bottom_dim }
+ }
+ } {
+ \dim_set:Nn \l__luaul_top_dim { \l__luaul_height_dim - \l__luaul_bottom_dim }
+ }
+ } {
+ \dim_set:Nn \l__luaul_bottom_dim { \l__luaul_height_dim - \l__luaul_top_dim }
+ }
+ }
+
+ \newunderlinetype \@@underLine [
+ \dim_to_decimal_in_sp:n { \l__luaul_top_dim }
+ @
+ \dim_to_decimal_in_sp:n { \l__luaul_bottom_dim }
+ @
+ \bool_if:NTF \l__luaul_color_set_bool {
+ colored @ \luaul_context_color:
+ } {
+ \cs_if_exist:NT \LuaCol@Attribute {
+ \int_use:N \LuaCol@Attribute
+ }
+ }
+ ] {
+ \bool_if:NT \l__luaul_color_set_bool {
+ \luaul_apply_color:
+ }
+ \leaders\vrule height \l__luaul_top_dim depth \l__luaul_bottom_dim
+ }
+ \newunderlinetype \@basicUnderLine {
+ \leaders \vrule height -.65ex depth .75ex
+ }
+
+ \NewDocumentCommand \@underLine {o} {
+ \IfValueTF {#1} {
+ \__luaul_parse_generic_keys:n {
+ top = -.65ex,
+ bottom = -.75ex,
+ }
+ \__luaul_parse_generic_keys:n {
+ #1
+ }
+ \@@underLine
+ } {
+ \@basicUnderLine
+ }
+ }
+ \NewDocumentCommand \underLine {o +m} {
+ \group_begin:
+ \@underLine [#1] #2
+ \group_end:
+ }
+
+ \newunderlinetype \@@strikeThrough {
+ \leaders \vrule height .55ex depth -.45ex
+ }
+ \newunderlinetype \@colored@strikeThrough [\__luaul_default_colored_context:] {
+ \luaul_apply_color:
\leaders\vrule height .55ex depth -.45ex
}
- \NewDocumentCommand\strikeThrough{o+m}{{%
- \IfValueTF{#1}{%
- \luaul@setcolor{#1}%
- \colored@strikeThrough
- }\@strikeThrough%
- #2%
- }}
+ \NewDocumentCommand \@strikeThrough {o} {
+ \IfValueTF {#1} {
+ \luaul_set_color:n {#1}
+ \@colored@strikeThrough
+ }
+ \@@strikeThrough
+ }
+ \NewDocumentCommand \strikeThrough {o +m} {
+ \group_begin:
+ \@strikeThrough #2
+ \group_end:
+ }
- \newunderlinetype\@highLight[\number\dimexpr1ex@%
- \luaul@currentcolor]{%
- \luaul@applycolor
+ \newunderlinetype \@@highLight [\__luaul_default_colored_context:] {
+ \luaul_apply_color:
\leaders\vrule height 1.75ex depth .75ex
}
- \NewDocumentCommand\highLight{O{\luaul@highlight@color}+m}{{%
- \luaul@setcolor{#1}%
- \@highLight#2%
- }}
- \ifluaul@soulnames
- \let\textul\underLine \let\ul\textul
- \let\textst\strikeThrough \let\st\textst
- \let\texthl\highLight \let\hl\texthl
- \fi
-\fi
+ \NewDocumentCommand \@highLight {O{\l__luaul_highlight_color_tl}} {
+ \luaul_set_color:n {#1}
+ \@@highLight
+ }
+ \NewDocumentCommand \highLight {O{\l__luaul_highlight_color_tl} +m} {
+ \group_begin:
+ \@highLight [#1] #2
+ \group_end:
+ }
+ \bool_if:NT \l__luaul_soulnames_bool {
+ \cs_new_eq:NN \textul \underLine \cs_new_eq:NN \ul \textul
+ \cs_new_eq:NN \textst \strikeThrough \cs_new_eq:NN \st \textst
+ \cs_new_eq:NN \texthl \highLight \cs_new_eq:NN \hl \texthl
+ }
+}
\ifx \reset@font \normalfont
\let \reset@font \relax
\DeclareRobustCommand \reset@font {%