texlive[54332] Master/texmf-dist: lua-ul (15mar20)

commits+karl at tug.org commits+karl at tug.org
Sun Mar 15 22:32:40 CET 2020


Revision: 54332
          http://tug.org/svn/texlive?view=revision&revision=54332
Author:   karl
Date:     2020-03-15 22:32:40 +0100 (Sun, 15 Mar 2020)
Log Message:
-----------
lua-ul (15mar20)

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/lua-ul.lua
    trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty

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	2020-03-15 21:32:29 UTC (rev 54331)
+++ trunk/Master/texmf-dist/source/lualatex/lua-ul/lua-ul.dtx	2020-03-15 21:32:40 UTC (rev 54332)
@@ -43,6 +43,7 @@
 \documentclass{article}
 \usepackage{lua-ul}
 \usepackage{csquotes,doc,framed,metalogo,hyperref,luacolor,tikzducks,pict2e}
+\RecordChanges
 \begin{document}
 \DocInput{lua-ul.dtx}
 \PrintIndex
@@ -116,6 +117,32 @@
 %   \end{document}
 % \end{verbatim}
 %
+% The \verb+\highLight+ command highlights the argument in yellow by default. This color can be changed
+% either by providing a color as optional argument or by changing the default through \verb+\LuaULSetHighLightColor+:
+%
+% \begin{verbatim}
+%   \documentclass{article}
+%   \usepackage{xcolor,luacolor,lua-ul}
+%   \LuaULSetHighLightColor{green}
+%   \begin{document}
+%   Lots of stuff is \highLight{important enough to be highlighted},
+%   but only few things are dangerous enough to deserve
+%   \highLight[red]{red highlighting.}
+%
+%   \LuaULSetHighLightColor{yellow}
+%   Let's go back to traditional \highLight{highlighting}.
+%   \end{document}
+% \end{verbatim}
+%
+% \begin{framed}
+%   \LuaULSetHighLightColor{green}
+%   Lots of stuff is \highLight{important enough to be highlighted}, but only few things
+%   are dangerous enough to deserve \highLight[red]{red highlighting.}
+%
+%   \LuaULSetHighLightColor{yellow}
+%   Let's go back to traditional \highLight{highlighting}.
+% \end{framed}
+%
 % \section{Expert interface}
 % \DescribeMacro{\newunderlinetype}§
 % Sometimes, you might try to solve more interesting problems than boring underlining,
@@ -178,6 +205,7 @@
 % 
 % \StopEventually{}
 % \section{The implementation}
+% \changes{0.0.1}{2020-03-12}{Initial release}
 % \subsection{Helper modules}
 % First we need a separate Lua module \verb+pre_append_to_vlist_filter+ which
 % provides a variant of the \verb+append_to_vlist_filter+ callback which can be
@@ -313,15 +341,48 @@
   end
   tex.attribute[j] = token.scan_int()
 end
+%    \end{macrocode}
+% \changes{0.0.2}{2020-03-15}{Add command to disable active underlining}
+%    \begin{macrocode}
+local function reset_underline()
+  local reset_all = token.scan_keyword'*'
+  local j
+  for i=1,#underlineattrs do
+    local attr = underlineattrs[i]
+    if tex.attribute[attr] ~= -0x7FFFFFFF then
+      if reset_all then
+        tex.attribute[attr] = -0x7FFFFFFF
+      else
+        j = attr
+      end
+    end
+  end
+  if not j then
+    if not reset_all then
+      tex.error("No underline active", {"You tried to disable \z
+            underlining but underlining was not active",
+            "in the first place. Maybe you wanted to ensure that \z
+            no underling can be active anymore?", "Then you should \z
+            append a *."})
+    end
+    return
+  end
+  tex.attribute[j] = -0x7FFFFFFF
+end
 local functions = lua.get_functions_table()
+local set_lua = token.set_lua
 local new_underline_type_func =
     luatexbase.new_luafunction"luaul.new_underline_type"
 local set_underline_func =
     luatexbase.new_luafunction"luaul.set_underline_func"
-token.set_lua("LuaULNewUnderlineType", new_underline_type_func)
-token.set_lua("LuaULSetUnderline", set_underline_func, "protected")
+local reset_underline_func =
+    luatexbase.new_luafunction"luaul.reset_underline_func"
+set_lua("LuaULNewUnderlineType", new_underline_type_func)
+set_lua("LuaULSetUnderline", set_underline_func, "protected")
+set_lua("LuaULResetUnderline", reset_underline_func, "protected")
 functions[new_underline_type_func] = new_underline_type
 functions[set_underline_func] = set_underline
+functions[reset_underline_func] = reset_underline
 
 local add_underline_h
 local function add_underline_v(head, attr)
@@ -379,9 +440,10 @@
     local width = node.rangedimensions(head, first)
     local kern = node.new(kern_t)
     kern.kern = -width
-    kern.next = node.copy(underline_types[last_value])
-    kern.next.width = width
-    node.tail(head.head).next = kern
+    local lead = node.copy(underline_types[last_value])
+    lead.width = width
+    head.head = node.insert_before(head.head, first, lead)
+    node.insert_after(head, lead, kern)
   end
 end
 local function filter(b, loc, prev, mirror)
@@ -407,7 +469,7 @@
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage
   {lua-ul}
-  [2020/03/12 v0.0.1 Underlining and related functionality for LuaTeX]
+  [2020/03/15 v0.0.2 Underlining and related functionality for LuaTeX]
 
 % \fi
 % Only \LuaLaTeX{} is supported.
@@ -438,8 +500,20 @@
   \fi
   \csname#1\endcsname
 }
-
 %    \end{macrocode}
+% The default for the context argument. Give that most stuff should
+% scale vertically with the font size, we expect most arguments
+% to be given in \texttt{ex}. Additionally especially traditional
+% 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
+  }
+%    \end{macrocode}
 % The main macro.
 %    \begin{macrocode}
 \NewDocumentCommand\newunderlinetype{mO{\luaul at defaultcontext}m}{%
@@ -452,12 +526,37 @@
   }}%
 }
 \ifluaul at predefined
-  \newcommand\luaul at defaultcontext{%
-    \number\dimexpr1ex
-    @\unless\ifx\undefined\LuaCol at Attribute
-      \the\LuaCol at Attribute
+%    \end{macrocode}
+% \changes{0.0.2}{2020-03-15}{Allow \texttt{\protect\string\protect\highLight} color customization}
+% 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
+% 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 highlight@currentcolor{#1}
+    \else
+      \begingroup
+        \XC at getcolor{#1}\luaul at tmpcolor
+      \expanded{\endgroup
+        \def\noexpand\luaul at highlight@currentcolor{%
+          \expandafter\luaul@@setcolor\luaul at tmpcolor}}%
     \fi
   }
+%    \end{macrocode}
+% Now a user-level command to set the default color.
+%    \begin{macrocode}
+\NewDocumentCommand\LuaULSetHighLightColor{om}{%
+  \edef\luaul at highlight@color{\IfValueTF{#1}{[#1]{#2}}{#2}}%
+}
+%    \end{macrocode}
+% The sizes for the predefined commands are stolen from the \enquote{soul}
+% default values.
+%    \begin{macrocode}
   \newunderlinetype\@underLine%
     {\leaders\vrule height -.65ex depth .75ex}
   \newcommand\underLine[1]{{\@underLine#1}}
@@ -464,9 +563,21 @@
   \newunderlinetype\@strikeThrough%
     {\leaders\vrule height .55ex depth -.45ex}
   \newcommand\strikeThrough[1]{{\@strikeThrough#1}}
-  \newunderlinetype\@highLight[\number\dimexpr1ex]%
-    {\color{yellow}\leaders\vrule height 1.75ex depth .75ex}
-  \newcommand\highLight[1]{{\@highLight#1}}
+
+  \newunderlinetype\@highLight[\number\dimexpr1ex@%
+                               \luaul at highlight@currentcolor]%
+    {%
+      \ifx\XC at getcolor\undefined
+        \color{\luaul at highlight@currentcolor}%
+      \else
+        \expandafter\XC at undeclaredcolor\luaul at highlight@currentcolor
+      \fi
+      \leaders\vrule height 1.75ex depth .75ex
+    }
+  \newcommand\highLight[2][\luaul at highlight@color]{{%
+    \luaul at setcolor{#1}%
+    \@highLight#2%
+  }}
   \ifluaul at soulnames
     \let\textul\underLine \let\ul\textul
     \let\textst\strikeThrough \let\st\textst
@@ -474,6 +585,31 @@
   \fi
 \fi
 %    \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
+% into unexpected places.
+%    \begin{macrocode}
+\ifx \reset at font \normalfont
+  \let \reset at font \relax
+  \DeclareRobustCommand \reset at font {%
+    \normalfont
+    \LuaULResetUnderline*%
+  }
+\else
+  \MakeRobust \reset at font
+  \begingroup
+    \expandafter \let
+        \expandafter \helper
+        \csname reset at font \endcsname
+  \expandafter \endgroup
+  \expandafter \gdef
+    \csname reset at font \expandafter \endcsname
+  \expandafter {%
+    \helper%
+    \LuaULResetUnderline*%
+  }
+\fi
+%    \end{macrocode}
 % \iffalse
 %</package>
 % \fi

Modified: trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua	2020-03-15 21:32:29 UTC (rev 54331)
+++ trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua	2020-03-15 21:32:40 UTC (rev 54332)
@@ -71,15 +71,45 @@
   end
   tex.attribute[j] = token.scan_int()
 end
+local function reset_underline()
+  local reset_all = token.scan_keyword'*'
+  local j
+  for i=1,#underlineattrs do
+    local attr = underlineattrs[i]
+    if tex.attribute[attr] ~= -0x7FFFFFFF then
+      if reset_all then
+        tex.attribute[attr] = -0x7FFFFFFF
+      else
+        j = attr
+      end
+    end
+  end
+  if not j then
+    if not reset_all then
+      tex.error("No underline active", {"You tried to disable \z
+            underlining but underlining was not active",
+            "in the first place. Maybe you wanted to ensure that \z
+            no underling can be active anymore?", "Then you should \z
+            append a *."})
+    end
+    return
+  end
+  tex.attribute[j] = -0x7FFFFFFF
+end
 local functions = lua.get_functions_table()
+local set_lua = token.set_lua
 local new_underline_type_func =
     luatexbase.new_luafunction"luaul.new_underline_type"
 local set_underline_func =
     luatexbase.new_luafunction"luaul.set_underline_func"
-token.set_lua("LuaULNewUnderlineType", new_underline_type_func)
-token.set_lua("LuaULSetUnderline", set_underline_func, "protected")
+local reset_underline_func =
+    luatexbase.new_luafunction"luaul.reset_underline_func"
+set_lua("LuaULNewUnderlineType", new_underline_type_func)
+set_lua("LuaULSetUnderline", set_underline_func, "protected")
+set_lua("LuaULResetUnderline", reset_underline_func, "protected")
 functions[new_underline_type_func] = new_underline_type
 functions[set_underline_func] = set_underline
+functions[reset_underline_func] = reset_underline
 
 local add_underline_h
 local function add_underline_v(head, attr)
@@ -137,9 +167,10 @@
     local width = node.rangedimensions(head, first)
     local kern = node.new(kern_t)
     kern.kern = -width
-    kern.next = node.copy(underline_types[last_value])
-    kern.next.width = width
-    node.tail(head.head).next = kern
+    local lead = node.copy(underline_types[last_value])
+    lead.width = width
+    head.head = node.insert_before(head.head, first, lead)
+    node.insert_after(head, lead, kern)
   end
 end
 local function filter(b, loc, prev, mirror)

Modified: trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty	2020-03-15 21:32:29 UTC (rev 54331)
+++ trunk/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty	2020-03-15 21:32:40 UTC (rev 54332)
@@ -20,7 +20,7 @@
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage
   {lua-ul}
-  [2020/03/12 v0.0.1 Underlining and related functionality for LuaTeX]
+  [2020/03/15 v0.0.2 Underlining and related functionality for LuaTeX]
 
 \ifx\directlua\undefined
   \PackageError{lua-ul}{LuaLaTeX required}%
@@ -41,7 +41,12 @@
   \fi
   \csname#1\endcsname
 }
-
+  \newcommand\luaul at defaultcontext{%
+    \number\dimexpr1ex
+    @\unless\ifx\undefined\LuaCol at Attribute
+      \the\LuaCol at Attribute
+    \fi
+  }
 \NewDocumentCommand\newunderlinetype{mO{\luaul at defaultcontext}m}{%
   \newcommand#1{}% "Reserve" the name
   \protected\def#1{%
@@ -52,12 +57,22 @@
   }}%
 }
 \ifluaul at predefined
-  \newcommand\luaul at defaultcontext{%
-    \number\dimexpr1ex
-    @\unless\ifx\undefined\LuaCol at Attribute
-      \the\LuaCol at Attribute
+  \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 highlight@currentcolor{#1}
+    \else
+      \begingroup
+        \XC at getcolor{#1}\luaul at tmpcolor
+      \expanded{\endgroup
+        \def\noexpand\luaul at highlight@currentcolor{%
+          \expandafter\luaul@@setcolor\luaul at tmpcolor}}%
     \fi
   }
+\NewDocumentCommand\LuaULSetHighLightColor{om}{%
+  \edef\luaul at highlight@color{\IfValueTF{#1}{[#1]{#2}}{#2}}%
+}
   \newunderlinetype\@underLine%
     {\leaders\vrule height -.65ex depth .75ex}
   \newcommand\underLine[1]{{\@underLine#1}}
@@ -64,9 +79,21 @@
   \newunderlinetype\@strikeThrough%
     {\leaders\vrule height .55ex depth -.45ex}
   \newcommand\strikeThrough[1]{{\@strikeThrough#1}}
-  \newunderlinetype\@highLight[\number\dimexpr1ex]%
-    {\color{yellow}\leaders\vrule height 1.75ex depth .75ex}
-  \newcommand\highLight[1]{{\@highLight#1}}
+
+  \newunderlinetype\@highLight[\number\dimexpr1ex@%
+                               \luaul at highlight@currentcolor]%
+    {%
+      \ifx\XC at getcolor\undefined
+        \color{\luaul at highlight@currentcolor}%
+      \else
+        \expandafter\XC at undeclaredcolor\luaul at highlight@currentcolor
+      \fi
+      \leaders\vrule height 1.75ex depth .75ex
+    }
+  \newcommand\highLight[2][\luaul at highlight@color]{{%
+    \luaul at setcolor{#1}%
+    \@highLight#2%
+  }}
   \ifluaul at soulnames
     \let\textul\underLine \let\ul\textul
     \let\textst\strikeThrough \let\st\textst
@@ -73,6 +100,26 @@
     \let\texthl\highLight \let\hl\texthl
   \fi
 \fi
+\ifx \reset at font \normalfont
+  \let \reset at font \relax
+  \DeclareRobustCommand \reset at font {%
+    \normalfont
+    \LuaULResetUnderline*%
+  }
+\else
+  \MakeRobust \reset at font
+  \begingroup
+    \expandafter \let
+        \expandafter \helper
+        \csname reset at font \endcsname
+  \expandafter \endgroup
+  \expandafter \gdef
+    \csname reset at font \expandafter \endcsname
+  \expandafter {%
+    \helper%
+    \LuaULResetUnderline*%
+  }
+\fi
 %% 
 %%
 %% End of file `lua-ul.sty'.



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