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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin doctoc_api n 1.0]
[copyright {2003-2004 Andreas Kupries <andreas_kupries@users.sourceforge.net>}]
[moddesc {Documentation tools}]
[titledesc {Specification of the Interface to ToC Formatting Engines}]
[description]
[para]
This document specifies version 1 of the interface an toc formatting
engine has to comply with to be usable by the package
[package doctools::toc].
The specification of the [term doctoc] format all toc formatting
engines have to process can be found in the companion document
[term doctoc_fmt].
[section API]
[subsection {EXPORTED COMMANDS}]
Each toc formatting engine has to provide a number of commands through
which objects created by the package [package doctools::toc] will upon
the functionality of the engine. These commands are described here.
[list_begin definitions]
[lst_item [emph {Management commands}]]
[list_begin definitions]
[call [cmd toc_numpasses]]
This command is called by a doctoc object immediately after it has
loaded the engine. No other command of the engine will be called
before it. It has to return the number of passes this engine requires
to fully process the input document. This value has to be an integer
number greater or equal to one.
[call [cmd toc_initialize]]
This command is called at the beginning of every conversion run, as
the first command of that run. Note that a run is not a pass, but may
consist of multiple passes. See [cmd toc_numpasses]. The command has
to initialize the general state of the toc formatting engine, beyond
the initialization done during the load.
[call [cmd toc_setup] [arg n]]
This command is called at the beginning of each pass over the input in
a run. Its argument is the number of the pass which has begun. Passes
are counted from [const 1] upward. The command has to set up the
internal state of the toc formatting engine for this particular pass.
[call [cmd toc_postprocess] [arg text]]
This command is called immediately after the last pass in a run. Its
argument is the result of the conversion generated by that pass. It is
provided to allow the engine to perform any global last-ditch
modifications of the generated document. The text returned by this
command will be the final result of the conversion.
[nl]
An engine for a format which requires no postprocessing can simply
return the argument without change.
[call [cmd toc_shutdown]]
This command is called at the end of every conversion run. It is the
last command called in a run. It has to clean up of all the
run-specific state in the toc formatting engine. After the call the
engine has to be in a state which allows the initiation of another run
without fear that information from the last run is leaked into this
new run.
[call [cmd toc_listvariables]]
This command is called by a doctoc object after it has loaded the
engine (after [cmd toc_numpasses]). It has to return a list containing
the names of the engine parameters provided by the engine. This list
can be empty.
[call [cmd toc_varset] [arg varname] [arg text]]
This command is called whenever the doctoc object wishes to set an
engine parameter to a particular value. The parameter to change is
specified by [arg varname], the value to set in [arg text].
[nl]
The command has to throw an error if an unknown [arg varname] is
used. Only the names returned by [cmd toc_listvariables] are
considered known.
[nl]
The values of all engine parameters have to persist between passes and
runs.
[list_end]
[nl]
[lst_item [emph {Formatting commands}]]
The commands listed in this section are responsible for the conversion
of the input into the wanted output.
Their names are the names of the associated markup command, with
prefix [const fmt_] added to them.
Not all markup commands have associated formatting commands. The two
exceptions are [cmd vset] and [cmd include]. These markup commands are
processed by the doctoc object itself.
[nl]
A detailed documentation of the markup commands can be found in the
companion document [term doctoc_fmt]. It is the formal specification
of the [term doctoc] format.
[nl]
[emph Note]: The formatting commands can expect that they are only
called in an order allowed by the format specification.
[list_begin definitions]
[call [cmd fmt_plain_text] [arg text]]
This command has no associated markup command. It is called for any
plain text encountered by the processor in the input. It has to
perform any special processing required for plain text. The text
returned as its result is added to the output. If no special
processing is required it has to simply return its argument without
change.
[call [cmd fmt_comment] [arg text]]
This command has to format the [arg text] as a comment and return the
formatted string. It has to return the empty string if the output
format has no way of formatting comments.
[call [cmd fmt_toc_begin] [arg text] [arg title]]
This command has to format the label [arg text] and the associated
[arg title] string as the start of the generated table of contents and
return the formatted string.
[call [cmd fmt_toc_end]]
This command has to generate the end of the generated table of contents and return
the formatted string.
[call [cmd fmt_division_start] [arg text] [opt [arg symfile]]]
This command has to open the beginning of a new section in the
generated table of contents and return the formatted string.
This opening may refer to another file, if supported by the format,
and specified through [arg symfile]. An possible application of this
would be to refer to a smaller table of contents just for the section.
The [arg text] argument is the title of the new section.
[call [cmd fmt_division_end]]
This command has to close a section in the generated table of contents
and return the formatted string.
[call [cmd fmt_item] [arg file] [arg text] [arg desc]]
This command has to format an individual toc element and return the
formatted string.
The document referenced by the element is specified through its
symbolic name [arg file], whereas the label to use for the link is
provided by [arg text].
Use the command [cmd dt_fmap] to convert the symbolic name to the
actual link.
It is described in section [sectref {IMPORTED ENVIRONMENT}].
The last argument, [arg desc], provides a short descriptive text for
the referenced document.
[list_end]
[list_end]
[para]
[subsection {IMPORTED ENVIRONMENT}]
The implementation of an toc formatting engine can make the
following assumptions about the environment it is executed in:
[list_begin enum]
[enum]
That it has full access to its own safe interpreter. In other words,
the engine cannot damage the other parts of the processor, nor can it
damage the filesystem.
[enum]
That the following commands are provided by the doctoc object
controlling the engine:
[list_begin definitions]
[lst_item {Doctools commands}]
[list_begin definitions]
[call [cmd dt_format]]
This command returns the name of the format currently executing.
[call [cmd dt_fmap] [arg symfname]]
This command returns the actual name to use in the output in place of
the symbolic filename [arg symfname]. It will return the unchanged
input if no mapping was found for [arg symfname].
[call [cmd dt_source] [arg file]]
This command allows the toc formatting engine to load additional tcl
code.
Only files which are either in the same directory as the file
containing the engine, or below it, can be loaded. Trying to load a
file outside of this directory causes an error.
[list_end]
[nl]
[lst_item {Expander commands}]
All of the commands below are methods of the expander object (without
the prefix [const ex_]) handling the current input. This gives the
engine limited access to the state of the expander.
Their arguments and results are described in the documentation for the
package [package expander].
[list_begin definitions]
[call [cmd ex_cappend]]
[call [cmd ex_cget]]
[call [cmd ex_cis]]
[call [cmd ex_cname]]
[call [cmd ex_cpop]]
[call [cmd ex_cpush]]
[call [cmd ex_cset]]
[call [cmd ex_lb]]
[call [cmd ex_rb]]
[list_end]
[nl]
[lst_item {Other commands}]
The file [file _toc_common.tcl] contains default implementations of
[cmd fmt_plaint_text] and all the [const toc_] commands listed in
section [sectref {EXPORTED COMMANDS}].
It resides in the subdirectory [file mpformats] containing all the
predefined formats. This means that all external formats (i.e. not
provided by the package [package doctools::toc]) cannot use it
immediately, but have to have a copy at their location.
[list_end]
[list_end]
[see_also doctoc_fmt doctoc]
[keywords markup {generic markup} toc {table of contents} TMML HTML nroff LaTeX]
[manpage_end]
|