OK, got it to work with a lot of help from Dermot over at Sparx support.
As per 1229, the only help page which discusses these Document Script fragments is
Custom Query Fragments. They're not mentioned on
Creating a Template Fragment, which they should be (in row 7). Until such time as the help pages are fixed, here's the scoop.
1) As with Custom Script template fragments, you specify a script and a function to be called within the script. It doesn't have to be called main().
2) JScripts work. I haven't tested the others, but I certainly suspect that VBScripts don't work.
3) The script has to return a text string containing RTF (as opposed to Custom Scripts, which return XML).
4) The script may take parameters, and passing #OBJECTID# works.
5) Passing #PACKAGEID# doesn't work. It parses, but comes out 0.
6) The RTF data is included in the template fragment by placing an empty
custom> section in it. No fields in the section (another difference from Custom Script fragments).
That's it. Works like a charm.
/Uffe