Additional Topics, Part 1¶
This tutorial covers some of the topics not covered in the Basic Tutorial. The focus here is on the flexibility offered by the configuration files, especially the XML Template and IPC File. A basic understanding of the topics covered in the Basic Tutorial is assumed.
For a tutorial covering topics more targeted towards formatting through the DOCX Stub and plugin usage, see Additional Topics, Part 2.
Topics Covered:
Project¶
The project for this tutorial is Games
. The
discussion will only focus on the relevant portions of the relevant files, so
readers are encouraged to download and extract the entire project before
delving into the tutorial.
The document created in the project will contain a couple of trivial lists of
board games just for illustration. The baseline version can be created using
Games.ipc
:
imprint Games.ipc
The output Games.docx
will look something like this:
Overriding Keywords¶
The includes system keyword is not only for IIF Files. It can also be used to modify portions of the IPC File in a traceable and repeatable manner.
Using the fact that included files can not override defined keywords, we can define an IPC File snippet that just overrides the keywords that we want, and includes everything else from the original file:
1 2 3 | caption_counter_depth = 0
includes = ['Games.ipc']
|
The example show here is used to modify the caption_counter_depth setting. The same technique can be used equally well to modify other System Keywords as well as User-Defined Keywords. Such modification is useful for testing and to create documents that are closely related to each other in terms of most of their configuration.
Games0.ipc
and its siblings
Games2.ipc
,
Games3.ipc
, and
GamesNone.ipc
are revisited
in the section on Setting the Caption Counter Depth.
Making Lists¶
Lists are created by setting the list
attribute of the
<par> tags. List items are just regular paragraphs with some
extra styling added on for bullets or numbering. A sample
XML Template with list items looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <imprint-template>
<par style="Title"><run>Sample of Board Games</run></par>
<toc>Contents</toc>
<par style="Heading 1">
<run>
Gridded Games
</run>
</par>
<par>
<run>
The following images show the boards used by different types of gridded
games. <figure-ref id="checkers"/> and <figure-ref id="chess"/> show
checkers and chess, respectively. These are some of the most common
games played on a static pre-made board. <figure-ref id="tic_tac_toe"/>
and <figure-ref id="battleship"/> show tic-tac-toe and battleship
boards. These are no less ubiquitous, but are generally played on
hand-drawn boards.
</run>
</par>
<par style="Heading 2">
<run>
Board Games
</run>
</par>
<par><run>This section lists games played on pre-made boards.</run></par>
<par list="numbered"><run>Checkers</run></par>
<figure id="checkers" handler="imprint.handlers.figure.ImageFile" />
<par list="continued"><run>Chess</run></par>
<figure id="chess" handler="imprint.handlers.figure.ImageFile" />
<par style="Heading 2">
<run>
Paper Games
</run>
</par>
<par>
<run>
This section lists games played on hand-drawn paper "boards".
While pre-made board versions of these games exist, they are
traditionally played on paper. For strictly board-type games, see
<segment-ref title="Board Games"/>.
</run>
</par>
<par list="num"><run style="Default Paragraph Font">Tic Tac Toe</run></par>
<table id="tic_tac_toe" handler="imprint.handlers.table.CSVFile" role="figure" />
<par list="cont" style="List Number"><run>Battleship</run></par>
<figure id="battleship" handler="imprint.handlers.figure.ImageFile" />
</imprint-template>
|
To start a new list, set the list
attribute to either numbered
or
bulleted
. Lines 26 and 43 in the example show how this is done.
The full word (which is case-insensitive by the way) can be spelled out, or
any prefix of it can be used, as in line 43.
To append elements to a list, set list
to continued
, as in lines
28 and 45. The list will be continued regardless of how many additional
paragraphs or other elements are placed between the list items. For example,
the figures on line 27, 29 and 46 and table on line 44 do not
break up the numbering scheme of the two lists we created:
Additional information is available in the List Styling tutorial.
Adding References¶
The text , and are dynamically generated reference names, which are automatically derived from the position of the figure or heading in the document outline.
The figure references are created by the <figure-ref> tags on lines 12, 14 and 15:
10 11 12 13 14 15 16 17 18 | <run>
The following images show the boards used by different types of gridded
games. <figure-ref id="checkers"/> and <figure-ref id="chess"/> show
checkers and chess, respectively. These are some of the most common
games played on a static pre-made board. <figure-ref id="tic_tac_toe"/>
and <figure-ref id="battleship"/> show tic-tac-toe and battleship
boards. These are no less ubiquitous, but are generally played on
hand-drawn boards.
</run>
|
Each <figure-ref> identifies the figure it refers to by its
id
attribute. This is how most References are identified.
The text reference on line 40 is greated by a
<segment-ref> tag, which points to paragraphs. Since
paragraphs do not normally have an id
attribute, they can be referenced by
title
instead:
39 40 41 | traditionally played on paper. For strictly board-type games, see
<segment-ref title="Board Games"/>.
</run>
|
The title
of a <segment-ref> is the
full text of the heading or other paragraph that is being pointed to, with all
the extra spaces and line-breaks removed:
20 21 22 23 24 | <par style="Heading 2">
<run>
Board Games
</run>
</par>
|
Among builtin tags, <figure> and <par> can be referenced by <figure-ref> and <segment-ref>, respectively. We have not seen <table-ref> tags in the tutorial so far, which reference <table>s. <table-ref> works just like <figure-ref>, but with “Table” in the reference name instead of “Figure”.
Using Roles¶
Roles allow tags to impersonate each other as reference targets. The most common usage is to turn tables or equations into figures that can be referenced as “Figure 1.3-1”, rather than being treated as a table or equation.
Our sample template creates such a <table> to describe Tic-Tac-Toe:
43 44 | <par list="num"><run style="Default Paragraph Font">Tic Tac Toe</run></par>
<table id="tic_tac_toe" handler="imprint.handlers.table.CSVFile" role="figure" />
|
The reference for this table can only be performed through a <figure-ref> tag, rather than the usual <table-ref>:
13 14 15 | checkers and chess, respectively. These are some of the most common
games played on a static pre-made board. <figure-ref id="tic_tac_toe"/>
and <figure-ref id="battleship"/> show tic-tac-toe and battleship
|
Any tag, whether it is normally referenceable or not, can impersonate a role.
For example, all it takes for a <latex> equation to become
a figure is the addition of an attribute: role="figure"
. That being said,
not all roles are suitable for every tag. For example, the
PathologicalCases
project has an
example of a <table> that plays the role of a heading with
role="par"
. This introduces the problem that <table>
should not contain text, and so normally can not be referenced by
<segment-ref>’s title attribute.