summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-03-14 22:10:45 +0000
committerKarl Berry <karl@freefriends.org>2020-03-14 22:10:45 +0000
commitca238fa81c51ff5ba715598b5082b5637f917456 (patch)
tree23986f4555dd33bee98e789cc3475f46a68b5104 /Master/texmf-dist/tex/lualatex
parentae2a5f357df974b9a9140e188de98de09c83cf36 (diff)
lua-ul (13mar20)
git-svn-id: svn://tug.org/texlive/trunk@54304 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty33
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua156
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty78
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua68
4 files changed, 335 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty b/Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty
new file mode 100644
index 00000000000..944fcdc25e6
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty
@@ -0,0 +1,33 @@
+%% Copyright (C) 2020 by Marcel Krueger
+%%
+%% This file may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3c of this license or (at your option) any later
+%% version. The latest version of this license is in:
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of
+%% LaTeX version 2005/12/01 or later.
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage
+ {docstrip-luacode}
+ [2020/03/07 v0.1.0 Directly execute Lua code from DocStrip files]
+\expanded{%
+ \def\noexpand\docstrip@luacode@argscanner#1\directlua{
+ tex.sprint(\the\catcodetable@string, "\string\\end{docstrip-luacode}")
+ local scanner = token.create'docstrip@luacode@argscanner'
+ local file = lpeg.Ct((lpeg.P'\csstring\%' * (1-lpeg.P'\string\r')^0 + lpeg.C((1-lpeg.P'\string\r')^0) * '\string\r')^0)/function(s)return table.concat(s,'\string\n')end
+ local func = luatexbase.new_luafunction'docstrip-luacode'
+ token.set_lua('docstrip-luacode', func, 'protected')
+ lua.get_functions_table()[func] = function()
+ local name = token.scan_string()
+ tex.catcodetable = \the\catcodetable@string
+ tex.setcatcode(32, 12)
+ token.put_next(scanner)
+ token.scan_token()
+ package.preload[name], msg = loadstring(file:match(token.scan_string()))
+ end
+}{\relax{#1}\noexpand\end{docstrip-luacode}}}
+\endinput
diff --git a/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua b/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua
new file mode 100644
index 00000000000..1fe53eefe1c
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.lua
@@ -0,0 +1,156 @@
+--
+-- This is file `lua-ul.lua',
+-- generated with the docstrip utility.
+--
+-- The original source files were:
+--
+-- lua-ul.dtx (with options: `luacode')
+--
+-- Copyright (C) 2020 by Marcel Krueger
+--
+-- This file may be distributed and/or modified under the
+-- conditions of the LaTeX Project Public License, either
+-- version 1.3c of this license or (at your option) any later
+-- version. The latest version of this license is in:
+--
+-- http://www.latex-project.org/lppl.txt
+--
+-- and version 1.3 or later is part of all distributions of
+-- LaTeX version 2005/12/01 or later.
+local hlist_t = node.id'hlist'
+local vlist_t = node.id'vlist'
+local kern_t = node.id'kern'
+local glue_t = node.id'glue'
+
+local char_given = token.command_id'char_given'
+
+local underlineattrs = {}
+local underline_types = {}
+local saved_values = {}
+local function new_underline_type()
+ for i=1,#underlineattrs do
+ local attr = underlineattrs[i]
+ saved_values[i] = tex.attribute[attr]
+ tex.attribute[attr] = -0x7FFFFFFF
+ end
+ local b = token.scan_list()
+ for i=1,#underlineattrs do
+ tex.attribute[underlineattrs[i]] = saved_values[i]
+ end
+ local lead = b.head
+ if not lead.leader then
+ tex.error("Leader required", {"An underline type has to \z
+ be defined by leader. You should use one of the", "commands \z
+ \\leaders, \\cleaders, or \\xleader, or \\gleaders here."})
+ else
+ if lead.next then
+ tex.error("Too many nodes", {"An underline type can only be \z
+ defined by a single leaders specification,", "not by \z
+ multiple nodes. Maybe you supplied an additional glue?",
+ "Anyway, the additional nodes will be ignored"})
+ end
+ table.insert(underline_types, lead)
+ b.head = lead.next
+ node.flush_node(b)
+ end
+ token.put_next(token.new(#underline_types, char_given))
+end
+local function set_underline()
+ local j
+ for i=1,#underlineattrs do
+ local attr = underlineattrs[i]
+ if tex.attribute[attr] == -0x7FFFFFFF then
+ j = attr
+ break
+ end
+ end
+ if not j then
+ j = luatexbase.new_attribute(
+ "luaul" .. tostring(#underlineattrs+1))
+ underlineattrs[#underlineattrs+1] = j
+ end
+ tex.attribute[j] = token.scan_int()
+end
+local functions = lua.get_functions_table()
+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")
+functions[new_underline_type_func] = new_underline_type
+functions[set_underline_func] = set_underline
+
+local add_underline_h
+local function add_underline_v(head, attr)
+ for n in node.traverse(head) do
+ if head.id == hlist_t then
+ add_underline_h(n, attr)
+ elseif head.id == vlist_t then
+ add_underline_v(n.head, attr)
+ end
+ end
+end
+function add_underline_h(head, attr)
+ local used = false
+ node.slide(head.head)
+ local last_value
+ local first
+ for n in node.traverse(head.head) do
+ local new_value = node.has_attribute(n, attr)
+ if n.id == hlist_t then
+ new_value = nil
+ add_underline_h(n, attr)
+ elseif n.id == vlist_t then
+ new_value = nil
+ add_underline_v(n.head, attr)
+ elseif n.id == kern_t and n.subtype == 0 then
+ if n.next and not node.has_attribute(n.next, attr) then
+ new_value = nil
+ else
+ new_value = last_value
+ end
+ elseif n.id == glue_t and (
+ n.subtype == 8 or
+ n.subtype == 9 or
+ n.subtype == 15 or
+ false) then
+ new_value = nil
+ end
+ if last_value ~= new_value then
+ if last_value then
+ local width = node.rangedimensions(head, first, n)
+ local kern = node.new(kern_t)
+ kern.kern = -width
+ 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
+ if new_value then
+ first = n
+ end
+ last_value = new_value
+ end
+ end
+ if last_value then
+ 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
+ end
+end
+local function filter(b, loc, prev, mirror)
+ for i = 1, #underlineattrs do
+ add_underline_v(b, underlineattrs[i])
+ end
+ return true
+end
+require'pre_append_to_vlist_filter'
+luatexbase.add_to_callback('pre_append_to_vlist_filter',
+ filter, 'add underlines to list')
+--
+--
+-- End of file `lua-ul.lua'.
diff --git a/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty b/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
new file mode 100644
index 00000000000..08069171817
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
@@ -0,0 +1,78 @@
+%%
+%% This is file `lua-ul.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% lua-ul.dtx (with options: `package')
+%%
+%% Copyright (C) 2020 by Marcel Krueger
+%%
+%% This file may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3c of this license or (at your option) any later
+%% version. The latest version of this license is in:
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3 or later is part of all distributions of
+%% LaTeX version 2005/12/01 or later.
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage
+ {lua-ul}
+ [2020/03/12 v0.0.1 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@predefined
+\newif\ifluaul@soulnames
+\luaul@predefinedtrue
+\DeclareOption{minimal}{\luaul@predefinedfalse}
+\DeclareOption{soul}{\luaul@soulnamestrue}
+\ProcessOptions\relax
+\protected\def\luaul@maybedefineuse#1#2{%
+ \unless\ifcsname#1\endcsname
+ \expandafter\xdef\csname#1\endcsname{#2}%
+ \fi
+ \csname#1\endcsname
+}
+
+\NewDocumentCommand\newunderlinetype{mO{\luaul@defaultcontext}m}{%
+ \newcommand#1{}% "Reserve" the name
+ \protected\def#1{%
+ \expandafter\luaul@maybedefineuse
+ \expanded{{\csstring#1@@#2}}%
+ {\LuaULSetUnderline
+ \LuaULNewUnderlineType\hbox{#3\hskip0pt}%
+ }}%
+}
+\ifluaul@predefined
+ \newcommand\luaul@defaultcontext{%
+ \number\dimexpr1ex
+ @\unless\ifx\undefined\LuaCol@Attribute
+ \the\LuaCol@Attribute
+ \fi
+ }
+ \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}}
+ \ifluaul@soulnames
+ \let\textul\underLine \let\ul\textul
+ \let\textst\strikeThrough \let\st\textst
+ \let\texthl\highLight \let\hl\texthl
+ \fi
+\fi
+%%
+%%
+%% End of file `lua-ul.sty'.
diff --git a/Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua b/Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua
new file mode 100644
index 00000000000..1417b588625
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/lua-ul/pre_append_to_vlist_filter.lua
@@ -0,0 +1,68 @@
+--
+-- This is file `pre_append_to_vlist_filter.lua',
+-- generated with the docstrip utility.
+--
+-- The original source files were:
+--
+-- lua-ul.dtx (with options: `callback')
+--
+-- Copyright (C) 2020 by Marcel Krueger
+--
+-- This file may be distributed and/or modified under the
+-- conditions of the LaTeX Project Public License, either
+-- version 1.3c of this license or (at your option) any later
+-- version. The latest version of this license is in:
+--
+-- http://www.latex-project.org/lppl.txt
+--
+-- and version 1.3 or later is part of all distributions of
+-- LaTeX version 2005/12/01 or later.
+if luatexbase.callbacktypes.pre_append_to_vlist_filter then
+ return
+end
+
+local call_callback = luatexbase.call_callback
+local flush_node = node.flush_node
+local prepend_prevdepth = node.prepend_prevdepth
+local callback_define
+
+for i=1,5 do
+ local name, func = debug.getupvalue(luatexbase.disable_callback, i)
+ if name == 'callback_register' then
+ callback_define = func
+ break
+ end
+end
+if not callback_define then
+ error[[Unable to find callback.define]]
+end
+
+local function filtered_append_to_vlist_filter(box,
+ locationcode,
+ prevdepth,
+ mirrored)
+ local current = call_callback("pre_append_to_vlist_filter",
+ box, locationcode, prevdepth,
+ mirrored)
+ if not current then
+ flush_node(box)
+ return
+ elseif current == true then
+ current = box
+ end
+ return call_callback("append_to_vlist_filter",
+ box, locationcode, prevdepth, mirrored)
+end
+
+callback_define('append_to_vlist_filter',
+ filtered_append_to_vlist_filter)
+luatexbase.callbacktypes.append_to_vlist_filter = nil
+luatexbase.create_callback('append_to_vlist_filter', 'exclusive',
+ function(n, _, prevdepth)
+ return prepend_prevdepth(n, prevdepth)
+ end)
+luatexbase.create_callback('pre_append_to_vlist_filter',
+ 'list', false)
+--
+--
+-- End of file `pre_append_to_vlist_filter.lua'.