Document Type

The Document Complex Type provides programmatic control over document title, chapter titles, paragraph text, and command blocks. It is used when SOP code needs to create or mutate structured document content inside the same reactive graph.

Creation Syntax

@doc new Document "doc1"
@titleRes doc.setTitle "Demo Document"
@titleNow doc.getTitle

@doc new Document "doc1" creates or restores a document handle bound to id doc1. The method calls setTitle and getTitle interact with persistent document metadata.

Example

@doc new Document "doc1"
@par1 := "content_1"
@par21 := "content_2_1"

doc.setChapterTitle 1 "Title for chapter 1"
doc.setChapterTitle 2 "Title for chapter 2"
doc.setParagraphText 1 1 $par1 "and some other content"

@parText doc.getParagraphText 1 1
doc.setParagraphText 1 1 $parText $par21

This pattern is taken from tests/pipelines/documents/workWithDocsTest.mjs. The Document methods auto-create missing chapters/paragraphs where needed and then update values.

Step-by-Step Interaction

The interaction usually starts with document-level metadata methods such as setTitle and getTitle, or with info-level methods such as setInfoText and getInfoText. After document metadata is in place, scripts move to chapter-level methods where setChapterTitle, getChapterTitle, setChapterCommands, and getChapterCommands shape chapter structure and chapter command blocks. Finally, paragraph-level methods such as setParagraphText, getParagraphText, setParagraphCommands, and getParagraphCommands control local text and local executable instructions within each chapter branch.

Runtime Role Notes

The Document type bridges SOP execution with mutable document structures managed by the Documents plugin. It is designed for workflows where content and commands are generated or transformed in-place.