2 Document Preamble
2.1 createDocument
2.2 describeDocument
2.3 endDocument
2.4 documentClass
2.5 setContents
2.6 setStructure
2.7 preambleComplete
2.8 endPreamble
2.9 beginDocument
3 Document Body
3.1 startCoverPage
3.2 endCoverPage
3.3 addToIndex
3.4 changeOutputFile
3.5 comment
3.6 copyFile
3.7 createTable
3.8 endList
3.9 endTable
3.10 footnote
3.11 includeFile
3.12 insertFigure
3.13 insertFile
3.14 InternalComment
3.15 listElement
3.16 paragraph
3.17 putLines
3.18 putVerbatim
3.19 setAutoWrap
3.20 setParagraphBias
3.21 startAppendicies
3.22 startList
3.23 tableRow
3.24 unnumberedParagraph
3.25 getLabel
Table 2.4-I Document Classes
Table 4-I Inline Formatting Commands
In reading this document, Familiarity with the STF Syntax Summary is assumed.
This document describes the Python library interface to the Simple Text Formatter (STF) automated documentation system.
Permission is granted to copy, distribute and/or modify this document under the terms of the
GNU Free Documentation License, Version 1.3 or any later version published by the Free
Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is available at: https://www.gnu.org/copyleft/fdl.html.
For more information, see the STF Syntax Summary
The preamble is the first section of an input file, before the text of the document itself, where document customization takes place.
Create an STF document, Arguments:
Name -- Document name, used for documentation purposes
Title -- Document title, appears at top. If omitted, a default is used.Example:
from stflib import StfDoc
self.doc = StfDoc("MyDoc")
self.doc.createDocument("Mydoc","This is a good doc")
Set document description, Argument: Description
Multiple lines are separated with <tab> characters.
Example: self.doc.describeDocument("Title\t\t\tAuthor: Freddie")
End the document, arguments: None
Closes the output file. Normally endDocument is optional, but it is required if the output file is to be processesd while the generating script is still active when STFXlate is invoked.
Set document class, Argument: documentClass
Recognized classes are:
Class |
Description |
HTML |
|---|---|---|
article |
This is the default and most common document class |
N |
extarticle |
Same as article but with extended font size support |
N |
report |
This is similar to an article, except the first paragraph level is named "Chapter" |
N |
extreport |
Same as report but with extended font size support |
N |
book |
This is similar to a report, except books use double sided output |
N |
manual |
This is a flag that indicates that the author will supply the LaTeX or HTML preamble |
Y |
HTML ignores all document classes, except for manual.
Example: self.doc.documentClass(article)
Define TOC, Arguments:
Contents=True -- True means to create a TOC, default True, optional.
Figures=True -- True means to include list of figures, default True, optional.
Index=True -- True means to include an index at end of document, default True, optional.
Tables=True -- True means to include list of tables, default True, optional.
Appendix=False -- True means to include support for appendicies, default False, optional.Example: self.doc.setContents(Figures=False, Index=False)
Adjust document defaults, Arguments:
Chapters=False -- True overrides defaults. Normally Chapter is controlled by document class. Setting Chapters to True indicates a manual document class that uses a first paragraph of 'Chapter'. Optional, default=False.
HTML_Local=True -- False specifies that, in expanding to HTML, referenced files are to be automatically prefaced with: "file://". Optional, default=True.
DebugFiles=False -- True specifies to include file names as comments. Optional, default=False.
FirstListAlphabetic=True -- False specifies lists expand as 1.a.A.a), True, the default, specifies lists expand as a.1.A.a). Optional.
TableXref=True -- False disables cross references in tables. This is useful when targeting to RTF format. Optional, default=True.
FrontMatter = True, the default supports a contents and an index. To use a cover page, set FrontMatter to false and enable the parts of the TOC desired (if any)explicitly. Optional, default=True.
Example: self.doc.setStructure(FirstListAlphabetic=False)
Specifies the end of the first half of the LaTeX preamble, Arguments: None
After preamble complete, LaTeX use package directives may be
inserted in the document command stream.
Preamble complete causes the first part of the document preamble
to be written.
This command is not used unless it is necessary to modify the
LaTeX packages in use or to add to the LaTeX configuration.
Example:
self.doc.preambleComplete()
self.doc.putVerbatim("\\usepackage{pdflscape}")
Specifies the end of the second half of the LaTeX preamble, Arguments: None.
After end preamble, LaTeX packages are configured.
EndPreamble causes the second part of the document preamble
to be written.
This command is not used unless it is necessary to modify the
LaTeX packages in use or to add to the LaTeX configuration.
Example:
self.doc.endPreamble()
self.doc.putVerbatim("\\pagenumbering{roman})"
Begin document -- ends preamble and starts the document, Arguments: None
Example: self.doc.beginDocument()
The document body contains the text to be formatted.
Begin cover page(s)
Cover pages are incompatible with describeDocument -- use one or the other.
If used, startCoverPage must be the first command after beginDocument. See 2.6.
Example: self.doc.startCoverPage()...
End cover page(s). Cover pages are incompatible with describeDocument -- use one or the other.
Example: self.doc.endCoverPage()
Add item to index, Argument: item
Example: self.doc.addToIndex("item-of-interest")
Arguments:
NewFile -- string containing path of the file to be opened.
Append -- Boolean, True specifies to append to NewFile rather than to replace it, default: False.If NewFile equals "", then switch back to the previous output file; otherwise change to outputting to NewFile.
Output files may be nested.
Output comment block, multiple lines are separated with <tab> or <nl>, Argument: text string. Comments are ignored in noWrap mode, i.e. in NoWrap mode comments are not inserted into the document.
Example: self.doc.comment("\tWhoa look at that\t")
Arguments: path -- path of filename
Copy file with minimal editing into document
Example: self.doc.copyFile("path")
All open lists are automatically closed:
Arguments:
Caption -- Title of the table. Required.
Header -- A one line column header. Columns are separated by tabs. Required.
ColumnSpec='' -- Optional string that specifies column formatting. If omitted, column sizes are taken from the header, notes:
* If ColumnSpec is omitted, it is inferred from the column lengths in the Header.
* Spec: |Col|col|...
* Col: l,r,c,p{}
* p{}: p{length}
* Sample ColumnSpec: |l|p{4.0in}|r| = 3 columns formatted as: justify left, size of 4 inches, justify right
Long=True -- Specifies whether the table can span pages or not. False means short. Short tables may be repositioned to minimize white space. Optional, default True.
Label='' -- Specifies an alphanumeric label with which to reference to the table. Specifying an asterisk ("*") causes a label to be generated and returned. Optional, default an empty string.Return: Label that can be used to refer to the table.
Examples:
self.doc.createTable("List of farbles", "Farble\tDescription ") --Creates a table with the column lengths taken from the description. Both columns will wrap to stay within bounds.
self.doc.createTable("List of farbles", "Farble\tDescription","|l|p{4in}|)" -- creates a table with two columns. The first column is left justified and will expand as necessary to hold the data, the second column wraps at four inches.
MyLabel = self.doc.createTable("List of farbles", "Farble\tDescription ", Long=False,Label="*") - Similar to the first example, but LaTeX may reposition the table in the document to reduce extra white space and "MyLabel" may be used to refer to the table in a reference later in the document; as in:
self.Doc.Putlines("See table \\ref{" + MyLabel + ",Page}).
Arguments: None
End a list (enumerated or bullet).
Example: self.doc.endList()
Arguments: None
End an active table.
Example: self.doc.endTable()
Output a footnote, arguments: String
Example:
self.doc.putLines("blah blah",Eol=False)
self.doc.footnote("notice that blah blah")
self.doc.putLines(" rest of line blah blah")
Insert STF file in document stream with normal interpreting. Include files may be nested.
Arguments:
File -- Path of file to be interpreted
POD=False -- True - file is in Perl POD format; False, file is in STF format.
Bias=0 -- Paragraph level bias.
Labels='' -- List of labels to be activated for the fileExample: self.doc.includeFile(MyFile.stf)
Insert a Figure, Arguments:
File -- path to figure.Typical extensions: jpg, jpeg, gif, png, bmp
Caption -- the figure title.
Label -- label - optional user specified label to refer to the table.Specifying "*" causes a label to be generated and returned.
Return: Label that can be used to refer to the table.
Esample:
self.doc.includeFile(MyFile.stf)
Insert file in document stream with no editing. File must be compatible with the final target (HTML, LaTeX, RTF, etc.)
Example:
.IFC HTML
self.doc.insertFile(MyFile.html)
.Endc
.ifc Latex | RTF
self.doc.insertFile(MyFile.tex)
.Endc
Output internal comment block, lines separated with <tab> or <nl>, Arguments: String
Example:
self.doc.InternalComment("Notice the blah format \t use this form for ...")
Add an item to a list, Argument: String
Example:
self.doc.listElement("Item")
Start a paragraph, Arguments:
Level -- Paragraph level, 1..9 for chaptered documents, 1..8 otherwise.
Header -- Paragraph header (goes in contents)
Label -- Optional label to refer to paragraph.Specifying "*" causes a label to be generated and returned.
Return: Label to refer to paragraph
Examples:
self.doc.paragraph(1,"title")
refer = self.doc.paragraph(1,"title","*")
self.doc.putLines("See paragraph \\ref{" + refer + ",page}.")
Output a set of lines separated by <tab> or <nl>, Arguments:
String -- a string containing one or more lines to be output.
Tabs=True -- A boolean specifying whether tabs are to be interpreted as a new line or not. Optional, default=True.
Eol -- A boolean specifying to end the line with a <NL>, default=True.A leading period is escaped.
A blank line starts a new block paragraph.
Inline commands are recognized, depending on the parse level.
Examples:
self.doc.putLines("Line1\tline2\t...")
self.doc.putLines("Line", Eol=False, Tabs=False)
Output literal line, Arguments:
String - string to be output.
Eol -- boolean specifying to terminate string with <NL>, default=True.Examples:
self.doc.putVerbatim("Line")
self.doc.putVerbatim("Line",Eol=False)
Enable/disable auto wrap, Argument Boolean
Example: self.doc.setAutoWrap(True)
Automatically bias the paragraph level. For example if Bias=1, specifying a level of one is interpreted as paragraph level 2. See the syntax summary for more information, arguments: integer
Example: self.doc.setParagraphBias(1)
Assuming appendicies are enabled, start appendicies, Arguments: None
self.doc.startAppendicies()
Begin an enumerated or a bullet list, Argument: Boolean
Bullet = True, begin a bullet list; Bullet = False, the default, begin an enumerated list.
Bullet lists have two nesting levels, enumerated lists have four.
Examples:
self.doc.startList() -- Start an alphabetic list.
self.doc.startList(Bullet=False) -- Start an alphabetic list.
self.doc.startList(True) -- Start a bullet list.
self.doc.startList(Bullet=True) -- Start a bullet list.
Insert a row in an active table, Argument: String
Columns separated by <tab> characters, example:
self.doc.tableRow("Column1\tColumn2) -- inserts a row in a two column table.
Start an unnumbered paragraph, Arguments:
Level -- Paragraph level, 1..9 for chaptered documents, 1..8 otherwise. Level sets the header font style to correspond to the numbered paragraph font style. Required.
Header -- Paragraph header (does not go in contents.) Required.
Label -- Optional label to refer to paragraph.Specifying "*" causes a label to be generated and returned.
Return label to refer to paragraph, example:
self.doc.unnumberedParagraph(2,"Notice that ...")
Return a label. The label may be used to refer to structures with in the document, arguments: None
Example:
MyLabel = self.doc.getLabel()
self.doc.paragraph(1, "Now is the time", Label=MyLabel)
...
self.doc.paragraph("See paragraph \ref{" + MyLabel + ",Page}.")
The following formatting options are available as inline commands. See the Syntax Summary for more information. They may be embedded in an output line or specified separately.
Command |
Action |
|---|---|
\bold{string} |
specifies to bold the string. This construct may span lines. |
\both{string} |
specifies to bold and italicize the string. This construct may span lines. |
\fixed{string} |
specifies to use a fixed spaced font. This construct may span lines. |
\href{url,text} |
specifies an external link, except only the 'text' is displayed in the document. |
\italics{string} |
specifies to italicize the string. This construct may span lines |
\norm{string} |
specifies to use the default (proportional) font. This construct may span lines. Note: Closing the current \fixed{} inline command will also revert to the normal font. |
\ref{label, [page]} |
specifies a reference to an internal label. If "page" is specified, then the reference is of the form 'label on page', otherwise it is of the form 'label', where 'label' represents the paragraph, table, or figure number. RTF, PDF and HTML format files support internal links. This construct cannot span lines. |
\und{string} |
specifies to underline the string. This construct may span lines. |
\url{url} |
specifies an external link. RTF, PDF and HTML format files support external links. This construct cannot span lines. |
The following examples will both output: Now is the time for all:
self.doc.putLines("Now is the \\bold{time} for all")
self.doc.putLines("Now is the",Eol=False)
self.doc.bold("time")
self.doc.putLines(" for all")