From 7891283a2f2fb8a8a884bb212c36da8082764a9b Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 9 Jul 2022 03:01:16 +0000 Subject: CTAN sync 202207090301 --- macros/latex/contrib/prettytok/DEPENDS.txt | 3 +- macros/latex/contrib/prettytok/README | 6 +- macros/latex/contrib/prettytok/prettytok.lua | 98 +++ macros/latex/contrib/prettytok/prettytok.pdf | Bin 335928 -> 369580 bytes macros/latex/contrib/prettytok/prettytok.sty | 729 ++++----------------- macros/latex/contrib/prettytok/prettytok.tex | 171 +++-- .../contrib/prettytok/prettytok_template.html | 283 ++++++++ 7 files changed, 651 insertions(+), 639 deletions(-) create mode 100644 macros/latex/contrib/prettytok/prettytok.lua create mode 100644 macros/latex/contrib/prettytok/prettytok_template.html (limited to 'macros/latex/contrib/prettytok') diff --git a/macros/latex/contrib/prettytok/DEPENDS.txt b/macros/latex/contrib/prettytok/DEPENDS.txt index 5e0ae3b076..dd4fa25323 100644 --- a/macros/latex/contrib/prettytok/DEPENDS.txt +++ b/macros/latex/contrib/prettytok/DEPENDS.txt @@ -1,2 +1 @@ -expl3 -filecontentsdef +precattl diff --git a/macros/latex/contrib/prettytok/README b/macros/latex/contrib/prettytok/README index cefd81b493..531d9833dd 100644 --- a/macros/latex/contrib/prettytok/README +++ b/macros/latex/contrib/prettytok/README @@ -1,4 +1,8 @@ prettytok -- Pretty-print token list +Pretty-print token lists to HTML file for debugging purposes. +Open the file in any browser to view the result. + +Can be used to replace |\tl_analysis_show:n|. Released under the LaTeX Project Public License v1.3c or later See http://www.latex-project.org/lppl.txt @@ -20,4 +24,4 @@ This work has the LPPL maintenance status `maintained'. The Current Maintainer of this work is user202729. -This work consists of the files prettytok.sty. +This work consists of the files prettytok.sty, prettytok.lua, prettytok_template.html. diff --git a/macros/latex/contrib/prettytok/prettytok.lua b/macros/latex/contrib/prettytok/prettytok.lua new file mode 100644 index 0000000000..a0aba07243 --- /dev/null +++ b/macros/latex/contrib/prettytok/prettytok.lua @@ -0,0 +1,98 @@ +do +local function looks_like_token(t) + return type(t)=="userdata" or (type(t)=="table" and t.cmdname~=nil and t.tok~=nil) +end + +-- public API :: once the package is loaded, this holds the .tok value of the frozen relax token +prettyprint_frozenrelaxtok=nil + +local function prettyprint_one_arg(tokenlist) + + if looks_like_token(tokenlist) then + return prettyprint_one_arg({tokenlist}) + end + + local s="" + + local function printstring(t) + -- this is just for debugging/convenience purpose. If the item is a string instead of a token... + t=tostring(t) + for _, c in utf8.codes(t) do + if c==32 then + s=s.."token("..c..',"A"),' + else + s=s.."token("..c..',"C"),' + end + end + end + + if type(tokenlist)~="table" then + -- user give a string (or something similar). Print it as detokenized characters + printstring(tokenlist) + + else + + -- normal print of tokenlist + for i=1, #tokenlist do + local t=tokenlist[i] + if not looks_like_token(t) then + printstring(t) + elseif t.csname==nil then + s=s.."token("..t.mode..',"'..(({left_brace=1, right_brace=2, math_shift=3, tab_mark=4, mac_param=6, sup_mark=7, sub_mark=8, spacer="A", letter="B", other_char="C"})[t.cmdname])..'"),' + else + if t.active then + s=s.."token("..utf8.codepoint(t.csname)..',"D"),' + elseif t.tok==prettyprint_frozenrelaxtok then + s=s.."csfrozenrelax()," + else + s=s.."cs(" + for j=1, #t.csname do + s=s..t.csname:byte(j).."," + end + s=s..")," + end + end + end + + end + return s +end + +local function check_file_opened() + -- if it's \relax then get_macro() also returns nil + if token.get_macro("pretty_check_already_init:") == nil then + error("Output file not initialized!") + end +end + +local function get_file_number() + check_file_opened() + return token.get_mode(token.create("__prettyh_file")) +end + +function prettyprint(...) + local prettyfilenumber=get_file_number() + + local s="print_tl(" + local args={...} + for i=1, select("#", ...) do + s=s..prettyprint_one_arg(args[i]) + end + + texio.write(prettyfilenumber, s..")// - + +