使用正则表达式并创建包含计数文本前后的单独文件为此,我从原始文件中导出了 PI 说明LaTeX
并将其存储在单独的 LaTeX 文件中Global_PItexts.tex
。
现在,我想从Global_PItexts.tex
文件中读取 PI 指令并将 PI 指令插入原始 LaTeX 文件中。
我的原始 LaTeX 文件是:
\documentclass{article}
\usepackage{luacode}
\begin{document}
\begin{luacode*}
local domobject = require "luaxml-domobject"
local transform = require "luaxml-transform"
sample = [[
<?xml version="1.0" encoding="utf-8"?>
<art>
<title>Scattering of flexural waves an electric current</title>
<para>Smart testing structures are $a+b$ components Reduce acoustic noise used in engineering applications that are capable of sensing or reacting to their environment \textit{change} xxxxxxxxx Sample XXX1 their mechanical properties. in a predictable and desired manner. In addition to carrying mechanical loads, Abc alleviate vibration, reduce acoustic noise, change their mechanical properties as required or monitor their own condition.</para>
</art>]]
-- open LuaLaTeXpi file
local apifile = io.open("Global_PItexts.tex", "rb")
local dom = domobject.parse(sample)
--Get Before and After Text
local function check_pi(el)
local before = el:get_sibling_node(-1)
local after = el:get_sibling_node(1)
local before_text, after_text = "", ""
-- get surrounding 50 characters
if before then
before_text = before:get_text()
before_text = before_text:sub(-50)
end
if after then
after_text = after:get_text()
after_text = after_text:sub(1,50)
end
local text = before_text .. "<!" .. el._attr[ "_text" ] .. "!>" .. after_text .. "\n"
apifile:read(text)
--- How to print apifile text here in terminal/command?
print ("TEXT IS",apifile)
end
\end{luacode*}
\end{document}
我的Global_PItexts.tex
是:
or reacting to their environment \textit{change} <!--LuaLaTeX xxxxxxxxx Sample XXX1--> their mechanical properties. in a predictable and
manner. In addition to carrying mechanical loads, <!--LuaLaTeX \hspace*{12pt}Abc--> alleviate vibration, reduce acoustic noise, chang
mechanical properties as required or monitor their <!--\linebreak --> own condition.
预期输出 LaTeX 文件为:
\documentclass{article}
\usepackage{luacode}
\begin{document}
\begin{luacode*}
local domobject = require "luaxml-domobject"
local transform = require "luaxml-transform"
sample = [[
<?xml version="1.0" encoding="utf-8"?>
<art>
<title>Scattering of flexural waves an electric current</title>
<para>Smart testing structures are $a+b$ components Reduce acoustic noise used in engineering applications that are capable of sensing or reacting to their environment \textit{change} <?LuaLaTeX xxxxxxxxx Sample XXX1?> their mechanical properties. in a predictable and desired manner. In addition to carrying mechanical loads, <?LuaLaTeX \hspace*{12pt}Abc?> alleviate vibration, reduce acoustic noise, change their mechanical properties as required or monitor their <?LuaLaTeX \break?> own condition.</para>
</art>]]
\end{luacode*}
\end{document}
读取Global_PItexts.tex
文件并将PI指令插入原始LaTeX
文件中。如何实现?