My second iteration has added another TocDocument but this one has a procedure to populate an index entry and its pages.
That procedure might also be a place to add the values to a printable container should a user wish to print the index.
The procedure definition below follows the declaration of 2 variables which we will populate on each call.
{let public v1:#Visual, v2:#Visual}
{define-proc public {idx-entry entry:String, pages:String}:(Visual, Visual)
The procedure returns two visual objects which ensures that all entries and pages are formatted with the same look-n-feel.
A typical call might be
{set (v1, v2) = {idx-entry "parse", "369"}}
{heading level=4, {value v1}}
{heading level=5, {value v2}}
which is often preferrable to the simpler, error-prone and no-fun-to-maintain repetition of sequences such as
{heading
level=4,
{paragraph
paragraph-left-indent = 0.25in,
{bold parse}
}
}
{heading
level=5,
{paragraph
paragraph-left-indent = 0.50in,
{text
text-preserve-whitespace?=true,
text-breakable?=false,
369
}
}
}
for each entry.
With the simple abstraction which the procedure provides, we can change the layout in one place and we can consider adding a facility such that the user could customize the index and retain their changes as client-side persistent data. All of which points to a role for Curl in The-Future-of-the-Book, n'est-pas?
The complete procedure follows:
{define-proc public {idx-entry entry:String, pages:String}:(Visual, Visual) || TocTreeItem
{return
{paragraph
paragraph-left-indent = 0.25in,
{bold {value entry}}},
{paragraph
paragraph-left-indent = 0.50in,
{text
text-preserve-whitespace?=true,
text-breakable?=false,
{value pages}
}
}
}
}
You no doubt see many opportunities to improve this (the user is required to remember to add spaces between page numbers or otherwise format the string of page numbers; there are no options yet to control the font, emphasis etc)