Extension Points

Last modified by Vincent Massol on 2026/08/30 20:43

Reference

An extension can add to the LaTeX an export produces without owning the template that produces it. Every template exposes two UI extension points, one before its output and one after it, and what a UI extension contributes there is inserted into the exported document at that point. The shipped template stays in place and keeps whatever a later release changes in it, which is what separates an extension point from an override.

A contribution is an XWiki.UIExtensionClass object on a wiki page, or a UIExtension component, as at any other extension point.

The Points Every Template Has

NameExtension point idContent is inserted
Before any LaTeX Templateorg.xwiki.contrib.latex.*.beforebefore the template's output
After any LaTeX Templateorg.xwiki.contrib.latex.*.afterafter the template's output

The * stands for the name of the template being rendered, which is the simple class name of its Block: ParagraphBlock, TableCellBlock, ImageBlock. It is the name the renderer looks the template up by, so a contribution to org.xwiki.contrib.latex.ParagraphBlock.after lands after every paragraph of the export.

The shipped templates on GitHub are the complete list of the names in play, release by release.

Content contributed at these points is inserted as plain text. It is not rendered through the LaTeX renderer, so it is neither escaped nor formatted, and a Raw macro block in it produces nothing at all. Only the five document points below render their content as LaTeX.

The Document and Preamble Points

NameExtension point idContent is inserted
Before LaTeX XDOM Templateorg.xwiki.contrib.latex.XDOM.beforeat the top of the file, before \documentclass
Before LaTeX Preamble Templateorg.xwiki.contrib.latex.Preamble.beforeat the start of the preamble, before the first \usepackage
After LaTeX UsePackage Preamble Templateorg.xwiki.contrib.latex.Preamble.usepackage.afterafter the \usepackage lines the extension writes
After LaTeX Preamble Templateorg.xwiki.contrib.latex.Preamble.afterat the end of the preamble, before \begin{document}
After LaTeX XDOM Templateorg.xwiki.contrib.latex.XDOM.afterat the end of the body, before \end{document}

These five are written into the XDOM and Preamble templates themselves rather than coming from the mechanism above. That is what gives Preamble, a template belonging to no Block, points of its own, and what puts the content of org.xwiki.contrib.latex.XDOM.after inside the document rather than after \end{document}, where LaTeX would ignore it.

What the Content Is

A contribution is wiki syntax, and at the five document points it is rendered as LaTeX before being inserted. Ordinary text therefore arrives escaped: a per cent sign comes out as \%, a backslash as \textbackslash{}. LaTeX that has to reach the document untouched goes in a Raw macro whose syntax is latex/1.0, which needs the Raw Macro extension installed.

uix-raw-macro-example.png

The rest of the object is the usual one: Extension Point ID is the id from the tables above, and Extension Scope decides which wikis the contribution applies to.

The order Parameter

Several UI extensions can answer the same point. They are rendered in the order of their order parameter, lowest first, and one declaring no order at all is rendered last. Values that are whole numbers are compared as numbers, so 9 comes before 10; anything else is compared as text.

A Contribution in Full

Two contributions add a glossary to every export. The first, at org.xwiki.contrib.latex.Preamble.usepackage.after, loads the package and declares the entries:

{{raw syntax="latex/1.0"}}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{xdom}{name=XDOM, description={the tree a wiki page is parsed into}}
{{/raw}}

The second, at org.xwiki.contrib.latex.XDOM.after, prints the glossary where the document ends:

{{raw syntax="latex/1.0"}}
\printglossaries
{{/raw}}

The export then produces:

\usepackage{footnote}
\makesavenoteenv{tabular}
\makesavenoteenv{table}

\usepackage{glossaries}
\makeglossaries
\newglossaryentry{xdom}{name=XDOM, description={the tree a wiki page is parsed into}}

%% the rest of the preamble, then the exported page

\printglossaries
\end{document}

Related

Get Connected