将书目驱动的 Latex 文档拆分为每页的开放文档 ODT 文件?

将书目驱动的 Latex 文档拆分为每页的开放文档 ODT 文件?

我已经看到了一个 TeX 文件可以输出为多个 PDF 文件吗?,我知道这可能需要“外部”脚本 - 但我只是想看看是否有人有直接的方法。

使用下面发布的 MWE,我尝试创建一个“文章卡” - 对于来自参考书目的每个给定引文,生成一个包含给定引文和所有作者姓名的页面 - 每行一个作者姓名。就 Latex 到 PDF 而言,这工作得很好;输出如下所示(单击可查看完整分辨率):

测试.png

现在我想做的是——我希望这些页面中的每一页都是一个 .odt 打开文档,并且与引用同名;也就是说,不是单个包含 4 页的 PDF——我想要 4 个 ODT 文档,根据相应的引用键命名,即:每页分别为aksin.odtcotton.odtherrmann.odt、 。murray.odt

我见过如何将 .tex 转换为 .odt? - 询问 Ubuntu,以及那里的建议 - 但我不太确定,是否有可能例如调用latex test.tex+biber test一次,然后进行一次(或多次)调用,比如说mk4ht oolatex test.tex哪个会生成每页的 .odt 文件。

关于实现这一目标的最直接方法有什么想法/指示吗?

代码test.tex

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage[top=3cm,bottom=3cm,left=2cm,right=2cm,showframe]{geometry}
\usepackage{pgffor}
\usepackage[firstinits=true]{biblatex}
\bibliography{biblatex-examples}

% based on {name:delim}, biblatex.def
% use newline as delimiter (not \par, as it indents)
\newbibmacro*{name:delimline}[1]{%
  \ifnumgreater{\value{listcount}}{\value{liststart}}
    {\ifboolexpr{
       test {\ifnumless{\value{listcount}}{\value{liststop}}}
       or
       test \ifmorenames
     }
       {\newline}%{\multinamedelim}
       {\newline}}%{\lbx@finalnamedelim{#1}}}
    {}}

% based on {name:first-last}, biblatex.def
% simply uses the above line as delimiter
\newbibmacro*{name:first-lastline}[4]{%
  \usebibmacro{name:delimline}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \ifblank{#2}{}{\mkbibnamefirst{#2}\isdot\bibnamedelimd}%
  \ifblank{#3}{}{%
    \mkbibnameprefix{#3}\isdot
    \ifpunctmark{'}
      {}
      {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
  \mkbibnamelast{#1}\isdot
  \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}}

% based on [labelname], biblatex.def
\DeclareNameFormat{labelnameallline}{%
%   \ifcase\value{uniquename}%
%     \usebibmacro{name:last}{#1}{#3}{#5}{#7}%
%   \or
%     \ifuseprefix
%       {\usebibmacro{name:first-lastline}{#1}{#4}{#5}{#8}}% w/ firstinits
%       {\usebibmacro{name:first-lastline}{#1}{#4}{#6}{#8}}% w/ firstinits
%   \or
    \usebibmacro{name:first-lastline}{#1}{#3}{#5}{#7}% % without firstinits!
%   \fi
%  %\usebibmacro{name:andothers}% output all explicitly
}

% \setkeys{blx@opt@pre}{firstinits=false}%
% \csname KV@blx@opt@pre@firstinits\endcsname -> \settoggle {blx@firstinits}{#1}

\DeclareCiteCommand{\citeallnamesline}
  {\usebibmacro{prenote}}
  %{\printnames[first-last]{labelnameallline}}
  {%
    \makeatletter%
    % NO spaces here in iftoggle, or before endcsname!
    \typeout{IT IS: \expandafter\meaning\csname KV@blx@opt@pre@firstinits\endcsname}%
    \iftoggle{blx@firstinits}{\typeout{true}}{\typeout{false}}%
    %\setkeys{blx@opt@pre}{firstinits=false}% no influence here, if it is false already; but doesn't matter, because NameFormat labelnameallline now explicitly uses full names
    \makeatother%
    % print all names w/ \thelisttotal, regardless of other settings
    \printnames[labelnameallline][-\thelisttotal]{author}%
  }
  {}%\multicitedelim}
  {\usebibmacro{postnote}}


\def\pageTemplate#1{%
  \section*{\centering Article Card}
  \bigskip
  \noindent The paper is:
  \bigskip

  \fullcite{#1}
  \bigskip

  \noindent The authors are:
  \bigskip

  \noindent%
  %\citeauthor{#1}
  \citeallnamesline{#1}

  \clearpage
}

\begin{document}

\foreach\x in {aksin,cotton,herrmann,murray}{
  \pageTemplate{\x}
}

\end{document}

答案1

我找不到任何可以将ODT文件拆分为独立页面的工具,所以
我认为最简单的方法是编写一个脚本,该脚本将为每张卡创建一个 TeX 文件并调用oolatex这些文件。我们可以创建一个包含文件中的所有记录的大.bbl文件bib,并将此文件用于每个文件。

Lua脚本makecards.lua

local bibfile = arg[1]
local citekeys = arg[2]
local tplfilename = "template.tex"
print("bibfile:  "..bibfile)
print("citekeys: "..citekeys)

local main = [[
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{biblatex}
\bibliography{$bibfile}
\begin{document}
\nocite{*}
\end{document}
]]
main = main:gsub("$bibfile",bibfile)

local latex = io.popen("latex -jobname="..bibfile,"w")
latex:write(main)
latex:close()

os.execute("biber "..bibfile)
local bblfile = io.open(bibfile..".bbl","r")
local bbl = bblfile:read("*all")
bblfile:close()

local tplfile = io.open(tplfilename,"r")
local tpl = tplfile:read("*all")
tplfile:close()
tpl = tpl:gsub("$bibfile",bibfile)

for key in citekeys:gmatch("([^%,]+)") do
  print(key)
  local tpl = tpl:gsub("$bibkey",key)
  local f = io.open(key..".tex","w")
  f:write(tpl)
  f:close()
  local b = io.open(key..".bbl","w")
  b:write(bbl)
  b:close()
  os.execute("mk4ht oolatex " .. key)
end

如您所见,使用虚拟 TeX 文件创建一个bbl文件,然后将其复制到每个 citekey。此外,还使用模板文件“template.tex”为每个 citekeycitekey创建一个 TeX 文件:

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[firstinits=true]{biblatex}
\bibliography{$bibfile}
\usepackage{titlesec}
\titleformat*{\section}{\bfseries\large\centering}

% based on {name:delim}, biblatex.def
% use newline as delimiter (not \par, as it indents)
\newbibmacro*{name:delimline}[1]{%
  \ifnumgreater{\value{listcount}}{\value{liststart}}
    {\ifboolexpr{
       test {\ifnumless{\value{listcount}}{\value{liststop}}}
       or
       test \ifmorenames
     }
       {\newline}%{\multinamedelim}
       {\newline}}%{\lbx@finalnamedelim{#1}}}
    {}}

% based on {name:first-last}, biblatex.def
% simply uses the above line as delimiter
\newbibmacro*{name:first-lastline}[4]{%
  \usebibmacro{name:delimline}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \ifblank{#2}{}{\mkbibnamefirst{#2}\isdot\bibnamedelimd}%
  \ifblank{#3}{}{%
    \mkbibnameprefix{#3}\isdot
    \ifpunctmark{'}
      {}
      {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
  \mkbibnamelast{#1}\isdot
  \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}}

% based on [labelname], biblatex.def
\DeclareNameFormat{labelnameallline}{%
%   \ifcase\value{uniquename}%
%     \usebibmacro{name:last}{#1}{#3}{#5}{#7}%
%   \or
%     \ifuseprefix
%       {\usebibmacro{name:first-lastline}{#1}{#4}{#5}{#8}}% w/ firstinits
%       {\usebibmacro{name:first-lastline}{#1}{#4}{#6}{#8}}% w/ firstinits
%   \or
    \usebibmacro{name:first-lastline}{#1}{#3}{#5}{#7}% % without firstinits!
%   \fi
%  %\usebibmacro{name:andothers}% output all explicitly
}

% \setkeys{blx@opt@pre}{firstinits=false}%
% \csname KV@blx@opt@pre@firstinits\endcsname -> \settoggle {blx@firstinits}{#1}

\DeclareCiteCommand{\citeallnamesline}
  {\usebibmacro{prenote}}
  %{\printnames[first-last]{labelnameallline}}
  {%
    \makeatletter%
    % NO spaces here in iftoggle, or before endcsname!
    \typeout{IT IS: \expandafter\meaning\csname KV@blx@opt@pre@firstinits\endcsname}%
    \iftoggle{blx@firstinits}{\typeout{true}}{\typeout{false}}%
    %\setkeys{blx@opt@pre}{firstinits=false}% no influence here, if it is false already; but doesn't matter, because NameFormat labelnameallline now explicitly uses full names
    \makeatother%
    % print all names w/ \thelisttotal, regardless of other settings
    \printnames[labelnameallline][-\thelisttotal]{author}%
  }
  {}%\multicitedelim}
  {\usebibmacro{postnote}}


\def\pageTemplate#1{%
  \section*{Article Card}
  \bigskip
  \noindent The paper is:
  \bigskip

  \fullcite{#1}
  \bigskip

  \noindent The authors are:
  \bigskip

  \noindent%
  %\citeauthor{#1}
  \citeallnamesline{#1}

  \clearpage
}

\begin{document}

  \pageTemplate{$bibkey}

\end{document}

我从你的样本中删除了一些不需要的包。

它应该用

texlua makecards.lua bibfilename "citekeys,separated,with,comma"

但结果需要一些改进:

在此处输入图片描述

相关内容