summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/lua-ul
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-03-16 03:01:06 +0000
committerNorbert Preining <norbert@preining.info>2020-03-16 03:01:06 +0000
commitd50a41b6ab3d05fe5605a3a3b50ff68f61059296 (patch)
tree29468e087e9c19acf30b392dc705a54288d79137 /macros/luatex/latex/lua-ul
parent87cddce361c3b477029d13b27bdaa57190b2d74b (diff)
CTAN sync 202003160301
Diffstat (limited to 'macros/luatex/latex/lua-ul')
-rw-r--r--macros/luatex/latex/lua-ul/lua-ul.dtx164
-rw-r--r--macros/luatex/latex/lua-ul/lua-ul.pdfbin74195 -> 85488 bytes
2 files changed, 150 insertions, 14 deletions
diff --git a/macros/luatex/latex/lua-ul/lua-ul.dtx b/macros/luatex/latex/lua-ul/lua-ul.dtx
index be033be0b5..9573212ba2 100644
--- a/macros/luatex/latex/lua-ul/lua-ul.dtx
+++ b/macros/luatex/latex/lua-ul/lua-ul.dtx
@@ -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 @@ local function set_underline()
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 @@ function add_underline_h(head, attr)
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 @@ luatexbase.add_to_callback('pre_append_to_vlist_filter',
\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,7 +500,19 @@ luatexbase.add_to_callback('pre_append_to_vlist_filter',
\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@defaultcontext{%
+ \number\dimexpr1ex
+ @\unless\ifx\undefined\LuaCol@Attribute
+ \the\LuaCol@Attribute
+ \fi
+ }
% \end{macrocode}
% The main macro.
% \begin{macrocode}
@@ -452,21 +526,58 @@ luatexbase.add_to_callback('pre_append_to_vlist_filter',
}}%
}
\ifluaul@predefined
- \newcommand\luaul@defaultcontext{%
- \number\dimexpr1ex
- @\unless\ifx\undefined\LuaCol@Attribute
- \the\LuaCol@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@highlight@color{yellow}
+ \def\luaul@@setcolor\xcolor@#1#2{}
+ \newcommand\luaul@setcolor[1]{%
+ \ifx\XC@getcolor\undefined
+ \def\luaul@highlight@currentcolor{#1}
+ \else
+ \begingroup
+ \XC@getcolor{#1}\luaul@tmpcolor
+ \expanded{\endgroup
+ \def\noexpand\luaul@highlight@currentcolor{%
+ \expandafter\luaul@@setcolor\luaul@tmpcolor}}%
\fi
}
+% \end{macrocode}
+% Now a user-level command to set the default color.
+% \begin{macrocode}
+\NewDocumentCommand\LuaULSetHighLightColor{om}{%
+ \edef\luaul@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}}
\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@highlight@currentcolor]%
+ {%
+ \ifx\XC@getcolor\undefined
+ \color{\luaul@highlight@currentcolor}%
+ \else
+ \expandafter\XC@undeclaredcolor\luaul@highlight@currentcolor
+ \fi
+ \leaders\vrule height 1.75ex depth .75ex
+ }
+ \newcommand\highLight[2][\luaul@highlight@color]{{%
+ \luaul@setcolor{#1}%
+ \@highLight#2%
+ }}
\ifluaul@soulnames
\let\textul\underLine \let\ul\textul
\let\textst\strikeThrough \let\st\textst
@@ -474,6 +585,31 @@ luatexbase.add_to_callback('pre_append_to_vlist_filter',
\fi
\fi
% \end{macrocode}
+% \changes{0.0.2}{2020-03-15}{Patch \texttt{\protect\string\protect\reset@font}}
+% Finally patch \verb+\reset@font+ to ensure that underlines do not propagate
+% into unexpected places.
+% \begin{macrocode}
+\ifx \reset@font \normalfont
+ \let \reset@font \relax
+ \DeclareRobustCommand \reset@font {%
+ \normalfont
+ \LuaULResetUnderline*%
+ }
+\else
+ \MakeRobust \reset@font
+ \begingroup
+ \expandafter \let
+ \expandafter \helper
+ \csname reset@font \endcsname
+ \expandafter \endgroup
+ \expandafter \gdef
+ \csname reset@font \expandafter \endcsname
+ \expandafter {%
+ \helper%
+ \LuaULResetUnderline*%
+ }
+\fi
+% \end{macrocode}
% \iffalse
%</package>
% \fi
diff --git a/macros/luatex/latex/lua-ul/lua-ul.pdf b/macros/luatex/latex/lua-ul/lua-ul.pdf
index e8472c65bb..257d7fee40 100644
--- a/macros/luatex/latex/lua-ul/lua-ul.pdf
+++ b/macros/luatex/latex/lua-ul/lua-ul.pdf
Binary files differ