doconce.DocWriter

DocWriter is a tool for writing documents in ASCII, HTML, LaTeX, Doconce, and other formats based on input from Python datastructures.

The base class _BaseWriter defines common functions and data structures, while subclasses HTML, Doconce, etc. implement (i.e., write to) various formats.

This module works, but is unifinished and needs documentation!

class doconce.DocWriter.DocWriter(*formats)

DocWriter can write documents in several formats at once.

dispatcher(*args, **kwargs)
documents()
figure(filename, caption, width=None, height=None, label=None)

Insert a figure into the document. filename should be without extension; a proper extension is added, and if the figure is not available in that image format, the convert utility from ImageMagick is called to convert the format.

Typeset a hyperlink.

list(items, listtype='itemize')

Write list or nested lists.

@param items: list of items. @param listtype: ‘itemize’, ‘enumerate’, or ‘description’.

math(text)

Write block of mathematical text (equations).

methods = ('title', 'section', 'subsection', 'subsubsection', 'paragraph', 'paragraph_separator', 'text', 'list', 'verbatim', 'math', 'raw', 'url', 'link', 'write_to_file', 'figure', 'table')
paragraph(title, ending='.', label=None)

Write a paragraph heading with the given title and an ending (period, question mark, colon) and an optional label (for navigation).

paragraph_separator()

Add a (space) separator between running paragraphs.

raw(text)

Write text directly ‘as is’ to output.

section(title, label=None)

Write a section heading with the given title and an optional label (for navigation).

subsection(title, label=None)

Write a subsection heading with the given title and an optional label (for navigation).

subsubsection(title, label=None)

Write a subsubsection heading with the given title and an optional label (for navigation).

table(table, column_headline_pos='c', column_pos='c')

Translates a two-dimensional list of data, containing strings or numbers, to a suitable “tabular” environment in the output.

@param table: list of list with rows/columns in table, including (optional) column-headline 1st row and row-headline 1st column. @param column_pos: specify the l/c/r position of data entries in columns, give either (e.g.) ‘llrrc’ or one char (if all are equal). @param column_headline_pos : position l/c/r for the headline row

text(text, indent=0)

Write plain text. Each line can be idented by a given number of spaces.

title(title, authors_and_institutions=[], date='today')

Provide title and authors.

@param title: document title (string). @param authors_and_institutions: list of authors and their associated institutions, where each list item is a tuple/list with author as first element followed by the name of all institutions this author is associated with. @param date: None implies no date, while ‘today’ generates the current date, otherwise a string is supplied.

url(url_address, link_text=None)

Typeset an URL (with an optional link).

verbatim(code)

Write verbatim text in fixed-width form (typically for computer code).

write_to_file(filename)

Write formatted document to a file. Just give the stem of the file name; the extension will be automatically added (depending on the document format).

class doconce.DocWriter.Doconce

Bases: doconce.DocWriter._BaseWriter

figure(filename, caption, width=None, height=None, label=None)

Insert a figure into the document. filename should be without extension; a proper extension is added, and if the figure is not available in that image format, the convert utility from ImageMagick is called to convert the format.

heading(underscores, title, label=None)
item_handler(item, listtype, level, keyword=None)

Write out the syntax for an item in a list.

@param item: text assoicated with the current list item. If item equals ‘_begin’ or ‘_end’, appropriate begin/end formatting of the list is written instead of an ordinary item. @param listtype: ‘itemize, ‘enumerate’, or ‘description’. @param level: list level number, 0 is the mainlist, increased by 1 for each sublist (the level number implies the amount of indentation). @param keyword: the keyword of the item in a ‘description’ list.

list(items, listtype='itemize')

Write list or nested lists.

@param items: list of items. @param listtype: ‘itemize’, ‘enumerate’, or ‘description’.

method(item, listtype, level, keyword=None)

Write out the syntax for an item in a list.

@param item: text assoicated with the current list item. If item equals ‘_begin’ or ‘_end’, appropriate begin/end formatting of the list is written instead of an ordinary item. @param listtype: ‘itemize, ‘enumerate’, or ‘description’. @param level: list level number, 0 is the mainlist, increased by 1 for each sublist (the level number implies the amount of indentation). @param keyword: the keyword of the item in a ‘description’ list.

paragraph(title, ending='.', label=None)

Write a paragraph heading with the given title and an ending (period, question mark, colon) and an optional label (for navigation).

paragraph_separator()
section(title, label=None)

Write a section heading with the given title and an optional label (for navigation).

subsection(title, label=None)

Write a subsection heading with the given title and an optional label (for navigation).

subsubsection(title, label=None)

Write a subsubsection heading with the given title and an optional label (for navigation).

table(table, column_headline_pos='c', column_pos='c')

Translates a two-dimensional list of data, containing strings or numbers, to a suitable “tabular” environment in the output.

@param table: list of list with rows/columns in table, including (optional) column-headline 1st row and row-headline 1st column. @param column_pos: specify the l/c/r position of data entries in columns, give either (e.g.) ‘llrrc’ or one char (if all are equal). @param column_headline_pos : position l/c/r for the headline row

text(text, indent=0)

Write plain text. Each line can be idented by a given number of spaces.

title(title, authors_and_institutions=[], date='today')

Provide title and authors.

@param title: document title (string). @param authors_and_institutions: list of authors and their associated institutions, where each list item is a tuple/list with author as first element followed by the name of all institutions this author is associated with. @param date: None implies no date, while ‘today’ generates the current date, otherwise a string is supplied.

url(url_address, link_text=None)

Typeset an URL (with an optional link).

verbatim(code)

Write verbatim text in fixed-width form (typically for computer code).

class doconce.DocWriter.HTML

Bases: doconce.DocWriter._BaseWriter

INLINE_TAGS_SUBST = {'math2': '\\g<begin>\\g<puretext>\\g<end>', 'verbatim': '\\g<begin><tt>\\g<subst></tt>\\g<end>', 'emphasize': '\\g<begin><em>\\g<subst></em>\\g<end>', 'math': None, 'bold': '\\g<begin><b>\\g<subst></b>\\g<end>'}
figure(filename, caption, width=None, height=None, label=None)

Insert a figure into the document. filename should be without extension; a proper extension is added, and if the figure is not available in that image format, the convert utility from ImageMagick is called to convert the format.

footer()
header()
heading(level, title, label=None)
item_handler(item, listtype, level, keyword=None)

Write out the syntax for an item in a list.

@param item: text assoicated with the current list item. If item equals ‘_begin’ or ‘_end’, appropriate begin/end formatting of the list is written instead of an ordinary item. @param listtype: ‘itemize, ‘enumerate’, or ‘description’. @param level: list level number, 0 is the mainlist, increased by 1 for each sublist (the level number implies the amount of indentation). @param keyword: the keyword of the item in a ‘description’ list.

list(items, listtype='itemize')

Write list or nested lists.

@param items: list of items. @param listtype: ‘itemize’, ‘enumerate’, or ‘description’.

method(item, listtype, level, keyword=None)

Write out the syntax for an item in a list.

@param item: text assoicated with the current list item. If item equals ‘_begin’ or ‘_end’, appropriate begin/end formatting of the list is written instead of an ordinary item. @param listtype: ‘itemize, ‘enumerate’, or ‘description’. @param level: list level number, 0 is the mainlist, increased by 1 for each sublist (the level number implies the amount of indentation). @param keyword: the keyword of the item in a ‘description’ list.

paragraph(title, ending='.', label=None)

Write a paragraph heading with the given title and an ending (period, question mark, colon) and an optional label (for navigation).

paragraph_separator()
section(title, label=None)

Write a section heading with the given title and an optional label (for navigation).

subsection(title, label=None)

Write a subsection heading with the given title and an optional label (for navigation).

subsubsection(title, label=None)

Write a subsubsection heading with the given title and an optional label (for navigation).

table(table, column_headline_pos='c', column_pos='c')

Translates a two-dimensional list of data, containing strings or numbers, to a suitable “tabular” environment in the output.

@param table: list of list with rows/columns in table, including (optional) column-headline 1st row and row-headline 1st column. @param column_pos: specify the l/c/r position of data entries in columns, give either (e.g.) ‘llrrc’ or one char (if all are equal). @param column_headline_pos : position l/c/r for the headline row

table_border = '2'
table_cellpadding = '5'
table_cellspacing = '2'
text(text, indent=0)

Write plain text. Each line can be idented by a given number of spaces.

title(title, authors_and_institutions=[], date='today')

Provide title and authors.

@param title: document title (string). @param authors_and_institutions: list of authors and their associated institutions, where each list item is a tuple/list with author as first element followed by the name of all institutions this author is associated with. @param date: None implies no date, while ‘today’ generates the current date, otherwise a string is supplied.

url(url_address, link_text=None)

Typeset an URL (with an optional link).

verbatim(code)

Write verbatim text in fixed-width form (typically for computer code).

class doconce.DocWriter.LaTeX

Bases: doconce.DocWriter._BaseWriter

doconce.DocWriter.func_to_method(func, class_, method_name=None)
doconce.DocWriter.html_movie(plotfiles, interval_ms=300, width=800, height=600, casename='movie')

Takes a list plotfiles which should be for example of the form:

['frame00.png', 'frame01.png', ... ]

where each string should be the name of an image file and they should be in the proper order for viewing as an animation.

The result is html text strings that incorporate javascript to loop through the plots one after another. The html text also features buttons for controlling the movie. The parameter iterval_ms is the time interval between loading successive images and is in milliseconds.

The width and height parameters do not seem to have any effect for reasons not understood.

The following strings are returned: header, javascript code, form with movie and buttons, and footer. Concatenating these strings and dumping to an html file yields a kind of movie file to be viewed in a browser. The images variable in the javascript code is unique for each movie, because it is annotated by the casename string, so several such javascript sections can be used in the same html file.

This function is based on code written by R.J. LeVeque, based on a template from Alan McIntyre.

doconce.DocWriter.html_movie_embed(moviefile, width=400, height=400)

Return HTML for embedding a moviefile using the default handling of such files.

doconce.DocWriter.html_movie_embed_qt(moviefile, width=400, height=400)

Return HTML for embedding a moviefile (QuickTime code).

doconce.DocWriter.html_movie_embed_wmp(moviefile, width=400, height=400)

Return HTML text for embedding a movie file (Windows Media Player code).

doconce.DocWriter.makedocstr(parent_class, subclass_method)

Compose a string (to be used as doc string) from a method’s doc string in a parent class and an additional doc string in a subclass version of the method.

@param parent_class: class object for parent class. @param subclass_method: method object for subclass. @return: parent_class.method.__doc__ + subclass_method.__doc__

Previous topic

doconce.epytext

Next topic

doconce.expand_newcommands

This Page