summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/lua-ul
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-06-02 03:03:07 +0000
committerNorbert Preining <norbert@preining.info>2022-06-02 03:03:07 +0000
commitd04e1ae659e8517e73bdabbd147386187d88fcb4 (patch)
treeeffdc25fc252bc1eaa513934be50107c297c2140 /macros/luatex/latex/lua-ul
parent395236b957a38aebc12c385c6de965af2b61f034 (diff)
CTAN sync 202206020303
Diffstat (limited to 'macros/luatex/latex/lua-ul')
-rw-r--r--macros/luatex/latex/lua-ul/docstrip-luacode.sty4
-rw-r--r--macros/luatex/latex/lua-ul/lua-ul.dtx344
-rw-r--r--macros/luatex/latex/lua-ul/lua-ul.pdfbin103958 -> 109525 bytes
3 files changed, 257 insertions, 91 deletions
diff --git a/macros/luatex/latex/lua-ul/docstrip-luacode.sty b/macros/luatex/latex/lua-ul/docstrip-luacode.sty
index f3a2136a6a..bcd35b8c4e 100644
--- a/macros/luatex/latex/lua-ul/docstrip-luacode.sty
+++ b/macros/luatex/latex/lua-ul/docstrip-luacode.sty
@@ -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@luacode@argscanner#1\directlua{
tex.sprint(\the\catcodetable@string, "\string\\end{docstrip-luacode}")
diff --git a/macros/luatex/latex/lua-ul/lua-ul.dtx b/macros/luatex/latex/lua-ul/lua-ul.dtx
index edaf0f3ca4..addff775bc 100644
--- a/macros/luatex/latex/lua-ul/lua-ul.dtx
+++ b/macros/luatex/latex/lua-ul/lua-ul.dtx
@@ -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 @@ function add_underline_hlist(head, attr, outervalue)
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 @@ require'lua-ul-patches-preserve-attr'
%</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@predefined
-\newif\ifluaul@soulnames
-\luaul@predefinedtrue
-\DeclareOption{minimal}{\luaul@predefinedfalse}
-\DeclareOption{soul}{\luaul@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@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,104 +991,244 @@ require'lua-ul-patches-preserve-attr'
% 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
+\cs_new:Npn \__luaul_default_context: {
+ \dim_to_decimal_in_sp:n {1ex}
+ @
+ \cs_if_exist:NT \LuaCol@Attribute {
+ \int_use:N \LuaCol@Attribute
}
+}
% \end{macrocode}
% The main macro.
% \begin{macrocode}
-\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}%
- }}%
+\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@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
% 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@currentcolor{#1}%
- \else
- \begingroup
- \XC@getcolor{#1}\luaul@tmpcolor
- \expanded{\endgroup
- \def\noexpand\luaul@currentcolor{%
- \expandafter\luaul@@setcolor\luaul@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@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}
+ }
}
- \newcommand\luaul@applycolor{%
- \ifx\XC@getcolor\undefined
- \color{\luaul@currentcolor}%
- \else
- \expandafter\XC@undeclaredcolor\luaul@currentcolor
- \fi
+ \__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:
}
% \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@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 \@@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
+ }
}
- \newunderlinetype\colored@strikeThrough[\number\dimexpr1ex@%
- \luaul@currentcolor]{%
- \luaul@applycolor
+ \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
+ }
+}
% \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
diff --git a/macros/luatex/latex/lua-ul/lua-ul.pdf b/macros/luatex/latex/lua-ul/lua-ul.pdf
index b59518bd9e..b8f1bbc8f0 100644
--- a/macros/luatex/latex/lua-ul/lua-ul.pdf
+++ b/macros/luatex/latex/lua-ul/lua-ul.pdf
Binary files differ