From 7f370bc3613640dc925159b92014eae6ba2bf484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Fri, 16 Apr 2021 10:15:58 +0200 Subject: [PATCH] Some updates --- luametalatex-back-pdf.lua | 28 ++++++++--------- luametalatex-basecallbacks.lua | 5 ++-- luametalatex-baseregisters.lua | 3 ++ luametalatex-firstcode.lua | 55 +++++++++++++++++----------------- luametalatex-lateinit.lua | 10 ++++--- luametalatex-nodewriter.lua | 2 +- 6 files changed, 53 insertions(+), 50 deletions(-) diff --git a/luametalatex-back-pdf.lua b/luametalatex-back-pdf.lua index 6382634..ab4388e 100644 --- a/luametalatex-back-pdf.lua +++ b/luametalatex-back-pdf.lua @@ -63,18 +63,16 @@ local function get_outline() return outline end local properties = node.direct.properties -local immediateassignment = token.new(5, token.command_id'convert') -local global = token.new(0, token.command_id'prefix') -local deadcycles = token.new(8, token.command_id'set_page_property') -local zero_tok = token.create(0x30) -local relax = token.new(0, 0) -local reset_deadcycles = { - immediateassignment, - global, - deadcycles, - zero_tok, - relax, -} +local reset_deadcycles do + local tokens = { + token.primitive_tokens.global, + token.primitive_tokens.deadcycles,token.create(0x30), + token.primitive_tokens.relax, + } + function reset_deadcycles() + token.put_next(tokens) + end +end token.luacmd("shipout", function() local pfile = get_pfile() local total_voffset, total_hoffset = tex.voffset + pdfvariable.vorigin, tex.hoffset + pdfvariable.horigin @@ -95,8 +93,7 @@ token.luacmd("shipout", function() local content = pfile:stream(nil, '', out) pfile:indirect(page, string.format([[<>]], parent, content, -math.ceil(to_bp(list.depth)), math.ceil(to_bp(list.width)), math.ceil(to_bp(list.height)), resources(pdfvariable.pageresources .. pdf.pageresources), annots, pdfvariable.pageattr, pdf.pageattributes)) node.flush_list(list) - token.put_next(reset_deadcycles) - scan_token() + tex.runlocal(reset_deadcycles) end, 'force', 'protected') local infodir = "" @@ -226,7 +223,8 @@ function callbacks.stop_run() local size = pfile:close() texio.write_nl("term", "(see the transcript file for additional information)") -- TODO: Additional logging, epecially targeting the log file - texio.write_nl("term and log", string.format(" %d words of node memory still in use:", status.nodestate.use)) + texio.write_nl("term and log", " node memory still in use:") + -- texio.write_nl("term and log", string.format(" %d words of node memory still in use:", status.nodestate.use)) local by_type, by_sub = {}, {} for n, id, sub in node.traverse(node.usedlist()) do if id == whatsit_id then diff --git a/luametalatex-basecallbacks.lua b/luametalatex-basecallbacks.lua index 2ebf2e9..7b8cee9 100644 --- a/luametalatex-basecallbacks.lua +++ b/luametalatex-basecallbacks.lua @@ -103,9 +103,8 @@ local errorvalues = tex.geterrorvalues() function callbacks.intercept_tex_error(mode, errortype) errortype = errorvalues[errortype] if errortype == "eof" then - tex.runlocal(function()token.put_next(token.create'tracingall')end) - do_terminal_input() - tex.runlocal(token.skip_next) + -- print('EOF', token.peek_next()) + token.put_next(token.create'ABD') return 3 end texio.write'.' diff --git a/luametalatex-baseregisters.lua b/luametalatex-baseregisters.lua index e77811f..5855df1 100644 --- a/luametalatex-baseregisters.lua +++ b/luametalatex-baseregisters.lua @@ -121,6 +121,9 @@ tex_variable(count_code, scan_int, 'outputmode', 1) -- The "traditional" default tex_variable(dimen_code, scan_dimen, 'pageheight', 0) tex_variable(dimen_code, scan_dimen, 'pagewidth', 0) +tex_variable(dimen_code, scan_dimen, 'hoffset', 0) +tex_variable(dimen_code, scan_dimen, 'voffset', 0) + tex_variable(count_code, scan_int, 'bodydirection', 0) tex_variable(count_code, scan_int, 'pagedirection', 0) diff --git a/luametalatex-firstcode.lua b/luametalatex-firstcode.lua index af137d0..cd78218 100644 --- a/luametalatex-firstcode.lua +++ b/luametalatex-firstcode.lua @@ -190,36 +190,37 @@ token.luacmd("read", function(_, prefix) end local macro = scan_csname(true) local file = ifiles[id] - local line - if file then - line = file:reader() - if not line then - file:close() - ifiles[id] = nil - end - else - error[[FIXME: Ask the user for input]] - end - local endlocal - tex.runlocal(function() - endlocal = token.scan_next() - tex.sprint(endlocal) - tex.print(line and line ~= "" and line or " ") - tex.print(endlocal) - end) local tokens = {} local balance = 0 - while true do - local tok = token.scan_next() - if tok == endlocal then break end - if tok.command == 1 then - balance = balance + 1 - elseif tok.command == 2 then - balance = balance - 1 + repeat + local line + if file then + line = file:reader() + if not line then + file:close() + ifiles[id] = nil + end + else + line = io.stdin:read() end - tokens[#tokens+1] = tok - end - if balance ~= 0 then error[[FIXME: Read additional input lines]] end + local endlocal + tex.runlocal(function() + endlocal = token.scan_next() + tex.sprint(endlocal) + tex.print(line and line ~= "" and line or " ") + tex.print(endlocal) + end) + while true do + local tok = token.scan_next() + if tok == endlocal then break end + if tok.command == 1 then + balance = balance + 1 + elseif tok.command == 2 then + balance = balance - 1 + end + tokens[#tokens+1] = tok + end + until balance == 0 tex.runlocal(function() tokens[#tokens+1] = rbrace token.put_next(tokens) diff --git a/luametalatex-lateinit.lua b/luametalatex-lateinit.lua index 79afa89..2835524 100644 --- a/luametalatex-lateinit.lua +++ b/luametalatex-lateinit.lua @@ -68,7 +68,7 @@ end local undefined_cmd = token.command_id'undefined_cs' local lua_call_cmd = token.command_id'lua_call' local lua_value_cmd = token.command_id'lua_value' -local lua_expandable_call_cmd = token.command_id'lua_expandable_call' +local lua_protected_call_cmd = token.command_id'lua_protected_call' local if_test_cmd = token.command_id'if_test' function token.luacmd(name, func, ...) local idx @@ -78,10 +78,10 @@ function token.luacmd(name, func, ...) idx = tok.index elseif cmd == lua_call_cmd then idx = tok.index - elseif cmd == lua_expandable_call_cmd then + elseif cmd == lua_protected_call_cmd then idx = tok.index - elseif cmd == if_test_cmd and tok.index > 48 then - idx = tok.index - 48 + elseif cmd == if_test_cmd and tok.index > 49 then + idx = tok.index - 49 elseif ... == 'force' then idx = new_luafunction(name) set_lua(name, idx, select(2, ...)) @@ -106,6 +106,7 @@ if initex then local prepared = lua.prepared_code prepared[1] = string.format("fixupluafunctions(%i)", predefined_luafunctions) + --[[ for i=0,0 do -- maybeFIXME: In practise only one language is preloaded in LuaTeX anyway -- for i=0,tex.count[19] do -- Sometimes catches reserved language ids which are not used yet -- for i=0,lang.new():id()-1 do -- lang.new():id() is always 0 in luametatex?!? @@ -136,6 +137,7 @@ if initex then end prepared[#prepared+1] = str end + ]] for i=2,#prepared do if type(prepared[i]) ~= 'string' then prepared[i] = assert(prepared[i]()) diff --git a/luametalatex-nodewriter.lua b/luametalatex-nodewriter.lua index bd994b9..8964604 100644 --- a/luametalatex-nodewriter.lua +++ b/luametalatex-nodewriter.lua @@ -273,7 +273,7 @@ nodehandler.math = ignore_node nodehandler.kern = ignore_node -- The following are only for frontend use: nodehandler.boundary = ignore_node -nodehandler.local_par = ignore_node +nodehandler.par = ignore_node nodehandler.penalty = ignore_node nodehandler.mark = ignore_node