我有一个代码来处理 xml 文件并用其内容填充 tcolorboxes。我正在使用 luaxml,但似乎我总是得到一个字母缩进。需要最新的 luaxml。代码在这里,最后给出了输出的图片:
短信-sample.xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<!--File Created By SMS Backup & Restore v10.08.006 on 12/11/2020 18:37:07-->
<!--
To view this file in a more readable format, visit https://synctech.com.au/view-backup/
-->
<smses count="1" backup_set="10d45e83-2909-4a27-b853-b51113e62e92" backup_date="1605186427168" type="full">
<sms protocol="0" address="+162738495078" date="1602132754403" type="1" subject="null" body="Voluptatem aut ea sed. Voluptas dolorem nulla aut minima et rerum sequi veniam. Dolore itaque dolores quia. Dolore temporibus nihil quos. Voluptates excepturi sed et harum adipisci ad facere exercitationem." toa="null" sc_toa="null" service_center="+17283940567" read="1" status="-1" locked="0" date_sent="1602132750000" sub_id="1" readable_date="8 oct. 2020 10:22:34" contact_name="content processed by smslib.sty" />
</smses>
短信箱.tex
\documentclass{article}
\usepackage{lipsum}
\usepackage{luacode}
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\begin{luacode*}
smslib = require "smslib"
\end{luacode*}
\tcbset{tcboption/.is choice,
tcboption/.style={skin=enhanced,finish={%
\draw[blue, thin, -] (1.60em,1em) -- +(0,20.3em); } },
}
\newcommand{\bubble}[3][tcboption]{%
\begin{tcolorbox}[
#1,colback=blue!10!white,colframe=blue!70!black,
title={#2},fonttitle=\bfseries]
#3
\end{tcolorbox}
}
\newcommand\printsms[1]{%
\directlua{%
smslib.process_xml("#1")
}%
}
\begin{document}
\bubble[]{\raggedright without smslib.lua (using "senderbox" %
directly in sample.tex)}{\footnotesize address: +91919191919, %
read: 1, service center: +98988783333\\ date: \today
\tcblower
Voluptatem aut ea sed. Voluptas dolorem nulla aut minima et rerum sequi
veniam. Dolore itaque dolores quia. Dolore temporibus nihil quos.
Voluptates excepturi sed et harum adipisci ad facere exercitationem.}
\printsms{sms-sample.xml}
\end{document}
短信库
local domobject = require "luaxml-domobject"
local transform = require "luaxml-transform"
-- module
local M = {}
-- template for SMS print
local other_template = [[
\bubble{\raggedright @{contact_name} $\langle$@{address}$\rangle$}{
\raggedright\footnotesize subject:@{subject}, read: @{read}
@{readable_date}
\tcblower
@{body}}
]]
transform.add_action("sms[type='1']", other_template)
M.process_xml = function(filename)
local f, message = io.open(filename, "r")
if not f then
print("XML file error: ", message)
return nil, message
end
local content = f:read("*all")
f:close()
content = content:gsub("\r", "")
local dom = domobject.parse(content)
local converted = transform.process_dom(dom)
tex.print(converted)
end
return M
答案1
\tcblower
和之间的换行符@{body}
是造成虚假空白的原因:
local domobject = require "luaxml-domobject"
local transform = require "luaxml-transform"
-- module
local M = {}
-- template for SMS print
local other_template = [[
\bubble{\raggedright @{contact_name} $\langle$@{address}$\rangle$}{
\raggedright\footnotesize subject:@{subject}, read: @{read}
@{readable_date}
\tcblower @{body}}
]]
transform.add_action("sms[type='1']", other_template)
M.process_xml = function(filename)
local f, message = io.open(filename, "r")
if not f then
print("XML file error: ", message)
return nil, message
end
local content = f:read("*all")
f:close()
content = content:gsub("\r", "")
local dom = domobject.parse(content)
local converted = transform.process_dom(dom)
tex.print(converted)
end
return M