Customize the Index Template
Steps
index.tex is the root document of an export package, and it is written by a template like everything else the export produces, so the same lookup applies: a template of yours named latex/Index takes the place of the shipped one. Most customizations need less than that, because the default hands the title, the author and the date to three commands that a preamble of yours can redefine.
- Read the default you are starting from. It ships in the latex-filter jar under templates/latex/default/Index, and its opening is where the three commands are defined and where your preamble is pulled in.
\documentclass{$latex.properties.documentClass} \usepackage{standalone} \newcommand{\xwikidate}[1]{ \date{\DTMdate{#1}}} \newcommand{\xwikititle}[1]{ \title{#1}} \newcommand{\xwikiauthor}[1]{ \author{#1}} $latex.processor.render('Preamble')The three are called further down, after \begin{document}, when the export was asked for a cover page: \xwikititle sets the \title, \xwikiauthor the \author and \xwikidate the \date, and \maketitle draws the cover page from them.
- Change the title, the author or the date by redefining its command rather than the template. Each of the three takes one mandatory argument, so the redefinition declares it with [1]. It belongs in a latex/Preamble template, which renders the default preamble first and adds to it, as when customizing the preamble for any other reason. The Index template defines the three commands before it renders the preamble, which is what lets a \renewcommand there find them.
#set ($template = $latex.processor.getTemplate('default/Preamble')) $latex.processor.render($template) %% Push the date to the foot of the cover page \renewcommand{\xwikidate}[1]{\date{#1 \\ \vfill ~ \\ Text at bottom of page}}## - Replace the Index template itself for anything the three commands do not cover. Load the shipped template, edit the one piece you want different and render the result, the four-step way; your template goes on the skin at path latex/Index, and it asks for the shipped one as default/Index. This one widens the margins of the compiled document.
## Step 1: get the default template being overridden #set ($template = $latex.processor.getTemplate('default/Index')) ## Step 2: compute the new content #set ($newContent = $stringtool.replace($template.content.content, '\usepackage{standalone}', '\usepackage{standalone} \usepackage[margin=2cm]{geometry}')) ## Step 3: set the new content #set ($discard = $template.content.setContent($newContent)) ## Step 4: render the modified template $latex.processor.render($template)## - Export a page and open index.tex in the package. The added package sits where the replacement put it, ahead of the command definitions the default writes next.
\documentclass{article} \usepackage{standalone} \usepackage[margin=2cm]{geometry} \newcommand{\xwikidate}[1]{ \date{\DTMdate{#1}}} \newcommand{\xwikititle}[1]{ \title{#1}} \newcommand{\xwikiauthor}[1]{ \author{#1}}The redefined command is at the other end of the preamble, after every line the default preamble wrote and, more to the point, after the \newcommand it is overriding.
%% Use LaTeX quotes by default \MakeOuterQuote{"} %% Push the date to the foot of the cover page \renewcommand{\xwikidate}[1]{\date{#1 \\ \vfill ~ \\ Text at bottom of page}} % Used to format the date for the cover page \usepackage[useregional]{datetime2} \begin{document}
FAQ
Why is my redefinition ignored?
Because it never reached the preamble of the generated document. The only thing the Index template renders there is the Preamble template, so a latex/Preamble of your own, or a UI extension on org.xwiki.contrib.latex.Preamble.after, are the two places that land after the three definitions and before \begin{document}.
Can I leave the [1] out of the \renewcommand?
No. A redefinition declaring no argument leaves that argument behind as ordinary text, typeset where the command was called: a cover page built that way prints the raw date next to the title it was supposed to format.
Does customizing index.tex change the page files?
No. The Index template writes index.tex alone. The files under pages/ are written by the renderer's own templates, and they render the Preamble template too, which is why redefining a command reaches every file of the package while replacing the Index template reaches one.