我正在从 TeX 应用程序文件编写一些小型转换脚本,如下所示MWE
:
\newwrite\html
\immediate\openout\html\jobname.html
\newcommand{\HalfTitle}[1]{\thispagestyle{empty}\bgroup%
\vbox to \vsize{\vfill%
\hbox to \hsize{\hss\Large#1\hss}%
\vfill}%
\immediate\write\html{<TPHT>#1</TPHT>}%
\egroup\clearemptydoublepage}%
\AtEndDocument{\closeout\html}
\HalfTitle{Half Title}
输出filename.html
创建为:
<TPHT>Half Title</TPHT>
通过使用相同的方法,我想获取标签内的某组文本<copyrt>...</copyrt>
,即
\begin{copyrt}
\textcopyright\ Copyright text goes here
lines
\end{copyrt}
输出应该是:
<copyrt>
<p>\textcopyright\ Copyright text goes here</p>
<p>lines</p>
</copyrt>
请指教....
答案1
您可以使用xparse
(自 2020-10-01 版本起内置于 LaTeX)和b
抓取环境主体的参数,然后可以使用\seq_set_split:Nnn
在每个环境中拆分环境主体\par
并将其写入文件.html
。请注意,使用此定义您不能在环境中使用逐字命令和环境copyrt
。
运行下面的示例将生成此.html
文件:
<TPHT>Half Title</TPHT>
<copyrt>
<p>\textcopyright \ Copyright text goes here</p>
<p>lines</p>
</copyrt>
\newwrite\html
\immediate\openout\html\jobname.html
\newcommand{\HalfTitle}[1]{\thispagestyle{empty}\bgroup%
\vbox to \vsize{\vfill%
\hbox to \hsize{\hss\Large#1\hss}%
\vfill}%
\immediate\write\html{<TPHT>#1</TPHT>}%
\egroup
% \clearemptydoublepage % <-- Don't know where this is from so I used
\cleardoublepage % instead
}%
\AtEndDocument{\closeout\html}
\RequirePackage{xparse}
\ExplSyntaxOn
\seq_new:N \l__madyyuvi_paragraphs_seq
\NewDocumentEnvironment{copyrt}{+b}
{
\iow_now:Nn \html { <copyrt> }
\seq_set_split:Nnn \l__madyyuvi_paragraphs_seq
{ \par } {#1} % <-- split #1 at \par
\seq_map_inline:Nn \l__madyyuvi_paragraphs_seq
{ \iow_now:Nn \html { <p>##1</p> } }
}
{ \iow_now:Nn \html { </copyrt> } }
\ExplSyntaxOff
\documentclass{memoir}
\begin{document}
\HalfTitle{Half Title}
\begin{copyrt}
\textcopyright\ Copyright text goes here
lines
\end{copyrt}
\end{document}