Excluding toc macro in Latex PDF

Hi,

I’ve found out that I can exclude parts of a wiki page from being exported into pdf for the normal process. From https://www.xwiki.org/xwiki/bin/view/FAQ/How%20to%20exclude%20some%20content%20from%20PDF%20export

Is there a similar method to remove the toc macro in latex? The velocitty code for the normal pdf export doesn’t work for latex.

Best regards,
Leon

Hi, yes it’s possible through an override of the LaTeX template for the toc macro.

See https://extensions.xwiki.org/xwiki/bin/view/Extension/LaTeX/Syntax%201.0/#HTemplateOverrides

FYI the default toc macro template is doing this: latex/latex-syntax/src/main/resources/templates/latex/default/macros/toc at d0065b8de360f914a0c5f352fa3eb7f37aa2e325 · xwiki-contrib/latex · GitHub

All you need to do is provide an override that does nothing.

Now if you want to selectively ignore the toc macro depending on some conditions, it’s a bit more complex and one idea is to also override the toc macro template but instead of doing nothing, add an IF in it based on some condition. For example you could decide that the following syntax would ignore the toc when used:

(% latex-toc=false %)(((
{{toc.../}}
)))

Actually there’s a simpler way for the selective ignore of the toc macro :slight_smile:

You can do the same than what is at https://www.xwiki.org/xwiki/bin/view/FAQ/How%20to%20exclude%20some%20content%20from%20PDF%20export

That will work too. Just don’t filter on $request.format != 'pdf'.

I’ve tried this method but it doesn’t seem to work with the latex export.

I’ve now documented it at https://extensions.xwiki.org/xwiki/bin/view/Extension/LaTeX/Syntax%201.0/#HConditionalExport

And it’s also linked from https://www.xwiki.org/xwiki/bin/view/FAQ/How%20to%20exclude%20some%20content%20from%20PDF%20export

1 Like

Is it possible to override this for all pages? At the moment I have to hide all tocs during PDF export. (Even pages created by other users). Most people don’t even have permission to use a script macro. It would be useful to have a pdf export template with script support (before the pdf file is completely generated with the template, there is a script attached to the template that would allow me to go through all pages with Groovy and remove toc)