texlive[63469] Master/texmf-dist: lua-ul (1jun22)

commits+karl at tug.org commits+karl at tug.org
Wed Jun 1 22:08:41 CEST 2022


Revision: 63469
          http://tug.org/svn/texlive?view=revision&revision=63469
Author:   karl
Date:     2022-06-01 22:08:41 +0200 (Wed, 01 Jun 2022)
Log Message:
-----------
lua-ul (1jun22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/lua-ul/lua-ul.pdf
    trunk/Master/texmf-dist/source/lualatex/lua-ul/lua-ul.dtx
    trunk/Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty
    trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul-patches-preserve-attr.lua
    trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua
    trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
    trunk/Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua

Modified: trunk/Master/texmf-dist/doc/lualatex/lua-ul/lua-ul.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/lualatex/lua-ul/lua-ul.dtx
===================================================================
--- trunk/Master/texmf-dist/source/lualatex/lua-ul/lua-ul.dtx	2022-06-01 20:08:22 UTC (rev 63468)
+++ trunk/Master/texmf-dist/source/lualatex/lua-ul/lua-ul.dtx	2022-06-01 20:08:41 UTC (rev 63469)
@@ -1,6 +1,6 @@
 % \iffalse meta-comment
 %
-%% 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
@@ -42,8 +42,8 @@
 %</gobble>
 %<*driver>
 \documentclass{article}
-\usepackage{lua-ul}
-\usepackage{csquotes,doc,framed,metalogo,hyperref,luacolor,tikzducks,pict2e}
+\usepackage{luacolor,lua-ul}
+\usepackage{csquotes,doc,framed,metalogo,tikzducks,pict2e,hyperref}
 \RecordChanges
 \begin{document}
 \DocInput{lua-ul.dtx}
@@ -144,6 +144,17 @@
 %   Let's go back to traditional \highLight{highlighting}.
 % \end{framed}
 %
+% The \verb+\underLine+ allows an optional argument accepting keyval options to customize the underline.
+% Currently four keys are implemented:
+%
+% \begin{description}
+% \item[textcolor] Active by default. The underline is colored in the current text color.
+% \item[color] Allows setting the color of the underline according to the syntax the xcolor manual
+% documents for PSTricks.
+% \item[top/bottom/height] At most two of these three options should be set. Specifies the height of the upper/lower
+% edge of the underline or the linewidth.
+% \end{description}
+%
 % \section{Expert interface}
 % \DescribeMacro{\newunderlinetype}§
 % Sometimes, you might try to solve more interesting problems than boring underlining,
@@ -759,7 +770,7 @@
       end
       if last_value then
 %    \end{macrocode}
-% \changes{0.1.1}{2022-02-02}{Set attributes for negative glue node}
+% \changes{0.1.1}{2021-02-02}{Set attributes for negative glue node}
 % If the value changed and the old one wasn't \texttt{nil}, then we reached
 % the end of the previous underlined segment and therefore know it's length.
 % Therefore we can finally insert the underline.
@@ -923,43 +934,56 @@
 %</gobble>
 % \fi
 % \subsection{\TeX\ support package}
+% \changes{0.2.0}{2022-05-31}{Move to expl3}
 % Now only some \LaTeX\ glue code is still needed
 % \iffalse
 %<*package>
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage
+\ProvidesExplPackage
   {lua-ul}
-  [2021/05/12 v0.1.4 Underlining and related functionality for LuaTeX]
-
+  {2022-05-31}{0.2.0}{Underlining and related functionality for LuaTeX}
 % \fi
+% First define some messages.
+%    \begin{macrocode}
+\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.
+}
+%    \end{macrocode}
+%
 % Only \LuaLaTeX{} is supported.
 % For other engines we show an error.
 %    \begin{macrocode}
-\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}
+\sys_if_engine_luatex:F {
+  \msg_error:nn {lua-ul} {luatex-required}
+}
+\lua_load_module:n {lua-ul}
+%
 %    \end{macrocode}
 % We support some options. Especially \verb+minimal+ will disable the predefined commands \verb+\underLine+ and \verb+\strikeThrough+ and allow you to define similar commands with your custom settings instead, \verb+soul+ tries to replicate names of the \verb+soul+ package.
 %    \begin{macrocode}
-\newif\ifluaul at predefined
-\newif\ifluaul at soulnames
-\luaul at predefinedtrue
-\DeclareOption{minimal}{\luaul at predefinedfalse}
-\DeclareOption{soul}{\luaul at soulnamestrue}
+\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
 %    \end{macrocode}
+%
 % Just one more tiny helper.
 %    \begin{macrocode}
-\protected\def\luaul at 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
 }
+\cs_generate_variant:Nn \__luaul_maybe_define_use:Nx {c}
 %    \end{macrocode}
 % The default for the context argument. Give that most stuff should
 % scale vertically with the font size, we expect most arguments
@@ -967,29 +991,43 @@
 % underlines will use the currently active text color, so especially
 % when luacolor is loaded we have to include the color attribute too.
 %    \begin{macrocode}
-  \newcommand\luaul at defaultcontext{%
-    \number\dimexpr1ex
-    @\unless\ifx\undefined\LuaCol at Attribute
-      \the\LuaCol at Attribute
-    \fi
+\cs_new:Npn \__luaul_default_context: {
+  \dim_to_decimal_in_sp:n {1ex}
+  @
+  \cs_if_exist:NT \LuaCol at Attribute {
+    \int_use:N \LuaCol at Attribute
   }
+}
 %    \end{macrocode}
 % The main macro.
 %    \begin{macrocode}
-\NewDocumentCommand\newunderlinetype
-    { E{*}{{}} m O{\luaul at defaultcontext} m }{%
-  \newcommand#2{}% "Reserve" the name
-  \protected\def#2{%
-    \expandafter\luaul at maybedefineuse
-      \expanded{{\csstring#2@@#3}}%
-      {\LuaULSetUnderline
-        \LuaULNewUnderlineType#1{#4\hskip0pt}%
-  }}%
+\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 }
+    }
+  }
 }
-\ifluaul at predefined
+
+\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
+    }
+  }
 %    \end{macrocode}
+%
 % \changes{0.0.2}{2020-03-15}{Allow \texttt{\protect\string\protect\highLight} color customization}
-% \changes{0.1.1}{2022-02-02}{Make color mechanism more generic}
+% \changes{0.1.1}{2021-02-02}{Make color mechanism more generic}
+% \changes{0.1.5}{2021-12-01}{Better error handling if luacolor is not loaded}
 % For \verb+\highLight+, the color should be customizable.
 % There are two cases: If \verb+xcolor+ is not loaded, we just accept
 % a simple color name. Otherwise, we accept color as documented in
@@ -996,75 +1034,201 @@
 % xcolor for PSTricks: Either a color name, a color expression or a
 % combination of colormodel and associated values.
 %    \begin{macrocode}
-  \newcommand\luaul at highlight@color{yellow}
-  \def\luaul@@setcolor\xcolor@#1#2{}
-  \newcommand\luaul at setcolor[1]{%
-    \ifx\XC at getcolor\undefined
-      \def\luaul at currentcolor{#1}%
-    \else
-      \begingroup
-        \XC at getcolor{#1}\luaul at tmpcolor
-      \expanded{\endgroup
-        \def\noexpand\luaul at currentcolor{%
-          \expandafter\luaul@@setcolor\luaul at tmpcolor}}%
-    \fi
+  \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 at getcolor {
+      \tl_set:Nn \l__luaul_current_color_tl {#1}
+    } {
+      \group_begin:
+        \XC at 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
+        }
+      }
+    }
   }
-  \newcommand\luaul at applycolor{%
-    \ifx\XC at getcolor\undefined
-      \color{\luaul at currentcolor}%
-    \else
-      \expandafter\XC at undeclaredcolor\luaul at currentcolor
-    \fi
+  \__luaul_deprecated:NN \luaul at setcolor \luaul_set_color:n
+  \cs_new_protected:Npn \luaul_apply_color: {
+    \IfPackageLoadedTF {luacolor} {
+      \cs_if_free:NTF \XC at getcolor {
+        \color {\l__luaul_current_color_tl}
+      }{
+        \exp_after:wN \XC at undeclaredcolor \l__luaul_current_color_tl
+      }
+    }{
+      \msg_error:nn {lua-ul} {luacolor-required}
+    }
   }
+  \__luaul_deprecated:NN \luaul at 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:
+  }
 %    \end{macrocode}
-% Now a user-level command to set the default color.
+% Now a user-level command to set the default color for highlights.
 %    \begin{macrocode}
-\NewDocumentCommand\LuaULSetHighLightColor{om}{%
-  \edef\luaul at highlight@color{\IfValueTF{#1}{[#1]{#2}}{#2}}%
-}
+  \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
+      }
+    }
+  }
 %    \end{macrocode}
 % \changes{0.1.1}{2021-02-02}{Use \texttt{xparse} for all user commands}
 % \changes{0.1.1}{2021-02-02}{Optionally color \texttt{\protect\string\protect\strikeThrough}}
 % \changes{0.1.2}{2021-02-15}{Allow \texttt{long} arguments (again)}
+% \changes{0.2.0}{2022-05-31}{Add keyval for \underLine}
 % The sizes for the predefined commands are stolen from the \enquote{soul}
 % default values.
 %    \begin{macrocode}
-  \newunderlinetype\@underLine{%
-    \leaders\vrule height -.65ex depth .75ex
+
+  \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,
   }
-  \NewDocumentCommand\underLine{+m}{{\@underLine#1}}
 
-  \newunderlinetype\@strikeThrough{%
-    \leaders\vrule height .55ex depth -.45ex
+  \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\colored at strikeThrough[\number\dimexpr1ex@%
-                                          \luaul at currentcolor]{%
-    \luaul at applycolor
+
+  \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 at Attribute {
+        \int_use:N \LuaCol at 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 at strikeThrough [\__luaul_default_colored_context:] {
+    \luaul_apply_color:
     \leaders\vrule height .55ex depth -.45ex
   }
-  \NewDocumentCommand\strikeThrough{o+m}{{%
-    \IfValueTF{#1}{%
-      \luaul at setcolor{#1}%
-      \colored at strikeThrough
-    }\@strikeThrough%
-    #2%
-  }}
+  \NewDocumentCommand \@strikeThrough {o} {
+    \IfValueTF {#1} {
+      \luaul_set_color:n {#1}
+      \@colored at strikeThrough
+    }
+    \@@strikeThrough
+  }
+  \NewDocumentCommand \strikeThrough {o +m} {
+    \group_begin:
+    \@strikeThrough #2
+    \group_end:
+  }
 
-  \newunderlinetype\@highLight[\number\dimexpr1ex@%
-                               \luaul at currentcolor]{%
-    \luaul at applycolor
+  \newunderlinetype \@@highLight [\__luaul_default_colored_context:] {
+    \luaul_apply_color:
     \leaders\vrule height 1.75ex depth .75ex
   }
-  \NewDocumentCommand\highLight{O{\luaul at highlight@color}+m}{{%
-    \luaul at setcolor{#1}%
-    \@highLight#2%
-  }}
-  \ifluaul at 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
+  }
+}
 %    \end{macrocode}
 % \changes{0.0.2}{2020-03-15}{Patch \texttt{\protect\string\protect\reset at font}}
 % Finally patch \verb+\reset at font+ to ensure that underlines do not propagate

Modified: trunk/Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty	2022-06-01 20:08:22 UTC (rev 63468)
+++ trunk/Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty	2022-06-01 20:08:41 UTC (rev 63469)
@@ -1,4 +1,4 @@
-%% 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
@@ -14,6 +14,8 @@
 \ProvidesPackage
   {docstrip-luacode}
   [2021/05/12 v0.1.4 Directly execute Lua code from DocStrip files]
+\RequirePackage{iftex}
+\RequireLuaTeX
 \expanded{%
   \def\noexpand\docstrip at luacode@argscanner#1\directlua{
   tex.sprint(\the\catcodetable at string, "\string\\end{docstrip-luacode}")

Modified: trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul-patches-preserve-attr.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul-patches-preserve-attr.lua	2022-06-01 20:08:22 UTC (rev 63468)
+++ trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul-patches-preserve-attr.lua	2022-06-01 20:08:41 UTC (rev 63469)
@@ -6,7 +6,7 @@
 --
 -- lua-ul.dtx  (with options: `preserve-attr')
 -- 
--- 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

Modified: trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua	2022-06-01 20:08:22 UTC (rev 63468)
+++ trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua	2022-06-01 20:08:41 UTC (rev 63469)
@@ -6,7 +6,7 @@
 --
 -- lua-ul.dtx  (with options: `luacode')
 -- 
--- 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

Modified: trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty	2022-06-01 20:08:22 UTC (rev 63468)
+++ trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty	2022-06-01 20:08:41 UTC (rev 63469)
@@ -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 at predefined
-\newif\ifluaul at soulnames
-\luaul at predefinedtrue
-\DeclareOption{minimal}{\luaul at predefinedfalse}
-\DeclareOption{soul}{\luaul at 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 at 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 at defaultcontext{%
-    \number\dimexpr1ex
-    @\unless\ifx\undefined\LuaCol at Attribute
-      \the\LuaCol at Attribute
-    \fi
+\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 at Attribute {
+    \int_use:N \LuaCol at Attribute
   }
-\NewDocumentCommand\newunderlinetype
-    { E{*}{{}} m O{\luaul at defaultcontext} m }{%
-  \newcommand#2{}% "Reserve" the name
-  \protected\def#2{%
-    \expandafter\luaul at maybedefineuse
-      \expanded{{\csstring#2@@#3}}%
-      {\LuaULSetUnderline
-        \LuaULNewUnderlineType#1{#4\hskip0pt}%
-  }}%
 }
-\ifluaul at predefined
-  \newcommand\luaul at highlight@color{yellow}
-  \def\luaul@@setcolor\xcolor@#1#2{}
-  \newcommand\luaul at setcolor[1]{%
-    \ifx\XC at getcolor\undefined
-      \def\luaul at currentcolor{#1}%
-    \else
-      \begingroup
-        \XC at getcolor{#1}\luaul at tmpcolor
-      \expanded{\endgroup
-        \def\noexpand\luaul at currentcolor{%
-          \expandafter\luaul@@setcolor\luaul at tmpcolor}}%
-    \fi
+\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 }
+    }
   }
-  \newcommand\luaul at applycolor{%
-    \ifx\XC at getcolor\undefined
-      \color{\luaul at currentcolor}%
-    \else
-      \expandafter\XC at undeclaredcolor\luaul at currentcolor
-    \fi
-  }
-\NewDocumentCommand\LuaULSetHighLightColor{om}{%
-  \edef\luaul at highlight@color{\IfValueTF{#1}{[#1]{#2}}{#2}}%
 }
-  \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
+    }
   }
-  \NewDocumentCommand\underLine{+m}{{\@underLine#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 at getcolor {
+      \tl_set:Nn \l__luaul_current_color_tl {#1}
+    } {
+      \group_begin:
+        \XC at 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 at setcolor \luaul_set_color:n
+  \cs_new_protected:Npn \luaul_apply_color: {
+    \IfPackageLoadedTF {luacolor} {
+      \cs_if_free:NTF \XC at getcolor {
+        \color {\l__luaul_current_color_tl}
+      }{
+        \exp_after:wN \XC at undeclaredcolor \l__luaul_current_color_tl
+      }
+    }{
+      \msg_error:nn {lua-ul} {luacolor-required}
+    }
+  }
+  \__luaul_deprecated:NN \luaul at 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
+      }
+    }
+  }
 
-  \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 at strikeThrough[\number\dimexpr1ex@%
-                                          \luaul at currentcolor]{%
-    \luaul at 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 at Attribute {
+        \int_use:N \LuaCol at 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 at strikeThrough [\__luaul_default_colored_context:] {
+    \luaul_apply_color:
     \leaders\vrule height .55ex depth -.45ex
   }
-  \NewDocumentCommand\strikeThrough{o+m}{{%
-    \IfValueTF{#1}{%
-      \luaul at setcolor{#1}%
-      \colored at strikeThrough
-    }\@strikeThrough%
-    #2%
-  }}
+  \NewDocumentCommand \@strikeThrough {o} {
+    \IfValueTF {#1} {
+      \luaul_set_color:n {#1}
+      \@colored at strikeThrough
+    }
+    \@@strikeThrough
+  }
+  \NewDocumentCommand \strikeThrough {o +m} {
+    \group_begin:
+    \@strikeThrough #2
+    \group_end:
+  }
 
-  \newunderlinetype\@highLight[\number\dimexpr1ex@%
-                               \luaul at currentcolor]{%
-    \luaul at applycolor
+  \newunderlinetype \@@highLight [\__luaul_default_colored_context:] {
+    \luaul_apply_color:
     \leaders\vrule height 1.75ex depth .75ex
   }
-  \NewDocumentCommand\highLight{O{\luaul at highlight@color}+m}{{%
-    \luaul at setcolor{#1}%
-    \@highLight#2%
-  }}
-  \ifluaul at 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 at font \normalfont
   \let \reset at font \relax
   \DeclareRobustCommand \reset at font {%

Modified: trunk/Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua	2022-06-01 20:08:22 UTC (rev 63468)
+++ trunk/Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua	2022-06-01 20:08:41 UTC (rev 63469)
@@ -6,7 +6,7 @@
 --
 -- lua-ul.dtx  (with options: `callback')
 -- 
--- 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



More information about the tex-live-commits mailing list.