Wiki source code of Customize the Index Template
Last modified by Vincent Massol on 2026/08/30 19:37
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | ##index.tex## is the root document of an [[export package>>doc:documentation.extensions.dev.latex.export-package.WebHome]], and it is written by a template like everything else the export produces, so [[the same lookup>>doc:documentation.extensions.dev.latex.template-mechanism.WebHome]] 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. | ||
| 2 | |||
| 3 | 1. 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.((( | ||
| 4 | {{code language="tex"}} | ||
| 5 | \documentclass{$latex.properties.documentClass} | ||
| 6 | \usepackage{standalone} | ||
| 7 | |||
| 8 | \newcommand{\xwikidate}[1]{ | ||
| 9 | \date{\DTMdate{#1}}} | ||
| 10 | \newcommand{\xwikititle}[1]{ | ||
| 11 | \title{#1}} | ||
| 12 | \newcommand{\xwikiauthor}[1]{ | ||
| 13 | \author{#1}} | ||
| 14 | |||
| 15 | $latex.processor.render('Preamble') | ||
| 16 | {{/code}} | ||
| 17 | |||
| 18 | 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. | ||
| 19 | ))) | ||
| 20 | 1. 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>>doc:documentation.extensions.dev.latex.override-template.customize-preamble.WebHome]]. The ##Index## template defines the three commands before it renders the preamble, which is what lets a ##\renewcommand## there find them.((( | ||
| 21 | {{code language="tex"}} | ||
| 22 | #set ($template = $latex.processor.getTemplate('default/Preamble')) | ||
| 23 | $latex.processor.render($template) | ||
| 24 | %% Push the date to the foot of the cover page | ||
| 25 | \renewcommand{\xwikidate}[1]{\date{#1 \\ \vfill ~ \\ Text at bottom of page}}## | ||
| 26 | {{/code}} | ||
| 27 | ))) | ||
| 28 | 1. 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>>doc:documentation.extensions.dev.latex.override-template.WebHome]]; 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.((( | ||
| 29 | {{code language="tex"}} | ||
| 30 | ## Step 1: get the default template being overridden | ||
| 31 | #set ($template = $latex.processor.getTemplate('default/Index')) | ||
| 32 | ## Step 2: compute the new content | ||
| 33 | #set ($newContent = $stringtool.replace($template.content.content, '\usepackage{standalone}', '\usepackage{standalone} | ||
| 34 | \usepackage[margin=2cm]{geometry}')) | ||
| 35 | ## Step 3: set the new content | ||
| 36 | #set ($discard = $template.content.setContent($newContent)) | ||
| 37 | ## Step 4: render the modified template | ||
| 38 | $latex.processor.render($template)## | ||
| 39 | {{/code}} | ||
| 40 | ))) | ||
| 41 | 1. 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.((( | ||
| 42 | {{code language="tex"}} | ||
| 43 | \documentclass{article} | ||
| 44 | \usepackage{standalone} | ||
| 45 | \usepackage[margin=2cm]{geometry} | ||
| 46 | |||
| 47 | \newcommand{\xwikidate}[1]{ | ||
| 48 | \date{\DTMdate{#1}}} | ||
| 49 | \newcommand{\xwikititle}[1]{ | ||
| 50 | \title{#1}} | ||
| 51 | \newcommand{\xwikiauthor}[1]{ | ||
| 52 | \author{#1}} | ||
| 53 | {{/code}} | ||
| 54 | |||
| 55 | 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. | ||
| 56 | |||
| 57 | {{code language="tex"}} | ||
| 58 | %% Use LaTeX quotes by default | ||
| 59 | \MakeOuterQuote{"} | ||
| 60 | %% Push the date to the foot of the cover page | ||
| 61 | \renewcommand{\xwikidate}[1]{\date{#1 \\ \vfill ~ \\ Text at bottom of page}} | ||
| 62 | |||
| 63 | % Used to format the date for the cover page | ||
| 64 | \usepackage[useregional]{datetime2} | ||
| 65 | |||
| 66 | \begin{document} | ||
| 67 | {{/code}} | ||
| 68 | ))) |