Wiki source code of Export Part of a Page

Last modified by Vincent Massol on 2026/08/30 19:36

Show last authors
1 An export displays the page through the same pipeline a view does, so the page's scripts run again while it is being exported, and they can tell the two apart: the export job carries over the action of the request that started it, and that action is ##latexexport##. Testing it in a Velocity script keeps a part of the page out of the LaTeX package while leaving it on the page, which is how a [[LaTeX export>>doc:documentation.extensions.dev.latex.WebHome]] drops the navigation aids a reader of the PDF does not need. This How-to removes a table of contents from the export.
2
3 1. Export the page as it stands and open its file under ##pages/## in the package. Everything the page displays is in there, the table of contents included, where it becomes an ##etoc## block repeating what the PDF's own table of contents already gives.(((
4 {{code language="tex"}}
5 \begin{document}
6
7 \etocsettocstyle{}{}
8 \tableofcontents
9
10 \heading{1}{Introduction}
11 \label{HIntroduction}
12
13 Some text.
14 {{/code}}
15 )))
16 1. Wrap the part to leave out in a Velocity macro and guard it with the action. The page needs the Script right for the macro to run at all.(((
17 {{code language="none"}}
18 {{velocity}}
19 #if ($xcontext.action != 'latexexport')
20 {{toc/}}
21 #end
22 {{/velocity}}
23
24 = Introduction =
25
26 Some text.
27 {{/code}}
28
29 The guard is a plain Velocity ##if##, so anything the page can compute is available to it: a whole section, one table row, an image swapped for another. What it must not hold is content you want in **both** outputs, since the export never takes the ##else## branch either.
30 )))
31 1. Export again. The guarded block is gone from the package and nothing is left where it stood, while viewing the page still shows the table of contents, because ##$xcontext.action## is ##view## there.(((
32 {{code language="tex"}}
33 \begin{document}
34
35 \heading{1}{Introduction}
36 \label{HIntroduction}
37
38 Some text.
39 {{/code}}
40 )))

Get Connected