From 9de8091bfb3391699d0b900932b91525a86d490e Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 3 Feb 2021 03:00:54 +0000 Subject: CTAN sync 202102030300 --- macros/luatex/latex/lua-ul/docstrip-luacode.sty | 4 +- macros/luatex/latex/lua-ul/lua-ul.dtx | 122 ++++++++++++++++++------ macros/luatex/latex/lua-ul/lua-ul.pdf | Bin 95868 -> 99609 bytes 3 files changed, 93 insertions(+), 33 deletions(-) (limited to 'macros/luatex/latex/lua-ul') diff --git a/macros/luatex/latex/lua-ul/docstrip-luacode.sty b/macros/luatex/latex/lua-ul/docstrip-luacode.sty index 944fcdc25e..29f055258f 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 by Marcel Krueger +%% Copyright (C) 2020-2021 by Marcel Krueger %% %% This file may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either @@ -13,7 +13,7 @@ \NeedsTeXFormat{LaTeX2e} \ProvidesPackage {docstrip-luacode} - [2020/03/07 v0.1.0 Directly execute Lua code from DocStrip files] + [2021/02/02 v0.1.1 Directly execute Lua code from DocStrip files] \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 14aa2fae0a..ad57f41b67 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 by Marcel Krueger +%% Copyright (C) 2020-2021 by Marcel Krueger %% %% This file may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either @@ -62,7 +62,7 @@ % \duck % \end{tikzpicture}§ % }} -% \newcommand\underDuck[1]{{\beginUnderDuck#1}} +% \NewDocumentCommand\underDuck{m}{{\beginUnderDuck#1}} % \newunderlinetype\beginUnderWavy[\number\dimexpr1ex]{\cleaders\hbox{§ % \setlength\unitlength{.3ex}§ % \begin{picture}(4,0)(0,1) @@ -72,11 +72,11 @@ % \qbezier(2,0)(3,-1)(4,0) % \end{picture}§ % }} -% \newcommand\underWavy[1]{{\beginUnderWavy#1}} +% \NewDocumentCommand\underWavy{m}{{\beginUnderWavy#1}} % \newunderlinetype\beginStrikeThough{\leaders\hbox{§ % \normalfont\bfseries/§ % }} -% \newcommand\StrikeThough[1]{{\beginStrikeThough#1}} +% \NewDocumentCommand\StrikeThough{m}{{\beginStrikeThough#1}} % % \newcommand\Luaul{Lua-UL} % \newcommand\luaul{Lua-UL} @@ -160,7 +160,7 @@ % you will have to define this manually.) % The optional argument provides a \enquote{context}: This \enquote{context} has to expand to a string % (something that can appear in a csname) which changes if the leaders box should be recalculated. -% The leader will be chached and reused whenever the context evaluates to the same string. +% The leader will be cached and reused whenever the context evaluates to the same string. % So if your leaders should depend on the fontsize, % the expansion of the context should contain the font size. If you leaders contain text in the current font, % your context should include \verb+\fontname+. The default context includes the current size of \texttt{1ex} @@ -168,7 +168,7 @@ % % The final argument contains the actual leader command. You should omit the final glue normally passed to \verb+\leaders+, % so e.g.\ write \verb+\leaders\hbox{ . }+ without appending \verb+\hfill+ or \verb+\hskip1pt+ etc. -% In most cases, the height and depth of your underlines is passed on to TeX to ensure that a deep underline does not interept other lines. +% In most cases, the height and depth of your underlines is passed on to TeX to ensure that a deep underline does not intercept other lines. % On the other hand, running dimensions work fine if you use a rule. % % For example, the special underline commands demonstrated above are implemented as @@ -180,7 +180,7 @@ % \duck % \end{tikzpicture}% % }} -% \newcommand\underDuck[1]{{\beginUnderDuck#1}} +% \NewDocumentCommand\underDuck{m}{{\beginUnderDuck#1}} % \newunderlinetype\beginUnderWavy[\number\dimexpr1ex]{\cleaders\hbox{% % \setlength\unitlength{.3ex}% % \begin{picture}(4,0)(0,1) @@ -190,11 +190,11 @@ % \qbezier(2,0)(3,-1)(4,0) % \end{picture}% % }} -% \newcommand\underWavy[1]{{\beginUnderWavy#1}} +% \NewDocumentCommand\underWavy{m}{{\beginUnderWavy#1}} % \newunderlinetype\beginStrikeThough{\leaders\hbox{% % \normalfont\bfseries/% % }} -% \newcommand\StrikeThough[1]{{\beginStrikeThough#1}} +% \NewDocumentCommand\StrikeThough{m}{{\beginStrikeThough#1}} % \end{verbatim} % % Here \verb+\underWavy+ uses a custom context because it doesn't change depending on the current font color. @@ -234,7 +234,7 @@ local callback_define % so we use the debug library to get the ``real'' \verb+callback.define+: % \begin{macrocode} for i=1,5 do - local name, func = debug.getupvalue(luatexbase.disable_callback, i) +local name, func = require'debug'.getupvalue(luatexbase.disable_callback, i) if name == 'callback_register' then callback_define = func break @@ -298,6 +298,7 @@ local has_attribute = node.direct.has_attribute local set_attribute = node.direct.set_attribute local dimensions = node.direct.dimensions local flush_node = node.direct.flush_node +local getattr = node.direct.getattributelist local getboth = node.direct.getboth local getfield = node.direct.getfield local getglue = node.direct.getglue @@ -318,6 +319,7 @@ local setlink = node.direct.setlink local hpack = node.direct.hpack local setfield = node.direct.setfield local slide = node.direct.slide +local setattr = node.direct.setattributelist local setglue = node.direct.setglue local setnext = node.direct.setnext local setshift = node.direct.setshift @@ -358,7 +360,7 @@ end local texnest = tex.nest % \end{macrocode} -% \changes{0.1.0}{2020-07-13}{Ensure that \texttt{\string\everyhbox} doesn't interfere with hlist scanning} +% \changes{0.1.0}{2020-07-13}{Ensure that \texttt{\protect\string\protect\everyhbox} doesn't interfere with hlist scanning} % To avoid influence from \texttt{\string\everyhbox} we reset \texttt{\string\everyhbox} to an empty token list directly before scanning. % As an added complication, we need to use a name which is guaranteed to be the primitive tokenlist and we % might have to restore it before reading the actual argument (There might be a reason why \texttt{\string\everyhbox} was sat after all. @@ -559,7 +561,7 @@ end % \end{macrocode} % \changes{0.0.3}{2020-03-17}{Make streight lines over hboxes} % \changes{0.0.4}{2020-03-31}{Consistently respect height and depth} -% Now the actual undelining +% Now the actual underlining % \begin{macrocode} local add_underline_hlist, add_underline_hbox, add_underline_vbox local function add_underline_vlist(head, attr, outervalue) @@ -658,11 +660,33 @@ function add_underline_hlist(head, attr, outervalue) stretch_order, shrink_order = fil_levels(head) end if last_value then +% \end{macrocode} +% \changes{0.1.1}{2022-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. +% +% Currently both the underline and the corresponding negative glue inherit +% the attributes from when the underline was defined. This makes sure that +% these nodes get consistent attributes (avoiding e.g. that only one of the +% nodes being picked up in a later pass and therefore interfering with the +% underlining) and that these are as much as possible under use control. +% +% We can't really predict what the most sensible value for attributes we +% don't control is, but by using this way any issues should be fixable with +% by adjusting the context argument. +% +% Currently this block gets duplicated a few lines down for the end of the +% list. This should get refactored into it's own function, but I have to be +% careful to handle all the special cases there. +% +% \begin{macrocode} local glue = new_glue_neg_dimensions(first, n, stretch_order, shrink_order) local w, st, sh = getglue(glue) local lead = nodecopy(underline_types[last_value]) setglue(lead, -w, -st, -sh, stretch_order, shrink_order) + setattr(glue, getattr(lead)) if underline_over_flag[last_value] then head = insert_before(head, n, glue) insert_after(head, glue, lead) @@ -690,6 +714,7 @@ function add_underline_hlist(head, attr, outervalue) local w, st, sh = getglue(glue) local lead = nodecopy(underline_types[last_value]) setglue(lead, -w, -st, -sh, stretch_order, shrink_order) + setattr(glue, getattr(lead)) if underline_over_flag[last_value] then insert_before(head, nil, glue) insert_after(head, glue, lead) @@ -791,7 +816,7 @@ luatexbase.add_to_callback('vpack_filter', \NeedsTeXFormat{LaTeX2e} \ProvidesPackage {lua-ul} - [2020/07/13 v0.1.0 Underlining and related functionality for LuaTeX] + [2021/02/02 v0.1.1 Underlining and related functionality for LuaTeX] % \fi % Only \LuaLaTeX{} is supported. @@ -851,6 +876,7 @@ luatexbase.add_to_callback('vpack_filter', \ifluaul@predefined % \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} % 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 @@ -861,15 +887,22 @@ luatexbase.add_to_callback('vpack_filter', \def\luaul@@setcolor\xcolor@#1#2{} \newcommand\luaul@setcolor[1]{% \ifx\XC@getcolor\undefined - \def\luaul@highlight@currentcolor{#1}% + \def\luaul@currentcolor{#1}% \else \begingroup \XC@getcolor{#1}\luaul@tmpcolor \expanded{\endgroup - \def\noexpand\luaul@highlight@currentcolor{% + \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 + } % \end{macrocode} % Now a user-level command to set the default color. % \begin{macrocode} @@ -877,27 +910,38 @@ luatexbase.add_to_callback('vpack_filter', \edef\luaul@highlight@color{\IfValueTF{#1}{[#1]{#2}}{#2}}% } % \end{macrocode} +% \changes{0.1.1}{2020-03-15}{Use \texttt{xparse} for all user commands} +% \changes{0.1.1}{2021-02-02}{Optionally color \texttt{\protect\string\protect\strikeThrough}} % 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\@underLine{% + \leaders\vrule height -.65ex depth .75ex + } + \NewDocumentCommand\underLine{m}{{\@underLine#1}} + + \newunderlinetype\@strikeThrough{% + \leaders\vrule height .55ex depth -.45ex + } + \newunderlinetype\colored@strikeThrough[\number\dimexpr1ex@% + \luaul@currentcolor]{% + \luaul@applycolor + \leaders\vrule height .55ex depth -.45ex + } + \NewDocumentCommand\strikeThrough{om}{{% + \IfValueTF{#1}{% + \luaul@setcolor{#1}% + \colored@strikeThrough + }\@strikeThrough% + #2% + }} \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@currentcolor]{% + \luaul@applycolor + \leaders\vrule height 1.75ex depth .75ex + } + \NewDocumentCommand\highLight{O{\luaul@highlight@color}m}{{% \luaul@setcolor{#1}% \@highLight#2% }} @@ -933,6 +977,22 @@ luatexbase.add_to_callback('vpack_filter', } \fi % \end{macrocode} +% \changes{0.1.1}{2021-02-02}{Patch \texttt{\protect\string\protect\output}} +% In the output routine, the page box is repacked before \verb+\reset@font+ is +% called, so we have to ensure to reset the attributes before that. This will +% use some awesome output routine hook as soon as that's in the kernel, until +% then manual patching it is. +% +% At the time I am writing this the remaining code of the package contains +% exactly ten times \verb+\expandafter+. Interestingly, that's also exactly +% the number of \verb+\expandafter+s we use here. +% \begin{macrocode} +\output\expandafter\expandafter\expandafter{% + \expandafter\expandafter\expandafter\LuaULResetUnderline + \expandafter\expandafter\expandafter*% + \expandafter\@firstofone\the\output% +} +% \end{macrocode} % \iffalse % % \fi diff --git a/macros/luatex/latex/lua-ul/lua-ul.pdf b/macros/luatex/latex/lua-ul/lua-ul.pdf index 326d8a612c..a868e5e6ef 100644 Binary files a/macros/luatex/latex/lua-ul/lua-ul.pdf and b/macros/luatex/latex/lua-ul/lua-ul.pdf differ -- cgit v1.2.3