1

I have already seen Can one TeX file output to multiple PDF files?, and I'm aware this is likely to require "external" scripting - but I just wanted to see if anyone has a straightforward approach.

With the MWE posted below, I'm trying to create an "article card" - for each of the given citations sourced from a bibliography, generate a page with the given citation, and all of the author names - one author name per line. This works fine as far as Latex to PDF is concerned; and the output is something like this (click for full res):

test.png

Now this is what I want to do - I want each of these pages as a .odt Open Document, with the same name as the citation; that is, instead of the single PDF with 4 pages -- I'd want 4 ODT documents, named according to the respective citation key, that is: aksin.odt, cotton.odt, herrmann.odt, murray.odt, for each page respectively.

I have seen How to convert .tex into .odt? - Ask Ubuntu, and the suggestions there - but I'm not really sure, if it would be possible e.g. to call latex test.tex + biber test once, and then do one (or multiple) calls to, say mk4ht oolatex test.tex which would generate the per-page .odt files.

Any ideas/pointers about the most straightforward way to achieve this?

The test.tex code:

\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}
5

I can't find any tool which can split a ODT file to standalone pages, so
I think easiest way is to make a script which will create a TeX file for each card and call oolatex on these files. We can create one big .bbl file which include all records from a bib file and use this file for each file.

The Lua script 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

as you can see, dummy TeX file is used to create a bbl file, which is then copied for each citekey. Also a TeX file for each citekey is created, using templete file, "template.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}

I removed some unneeded packages from your sample.

It should be compiled with

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

The result needs some refinements, though:

enter image description here

2
  • That is fantastic, @michal.h21 - I would never have thought of using Lua for the purpose, many thanks for that!
    – sdaau
    Apr 16 '15 at 13:10
  • @sdaau it is just that I am most familiar with Lua and it is included in every TeX distribution, any language would work (even TeX itself, but it would be much more difficult)
    – michal.h21
    Apr 16 '15 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.