Package doconce :: Module DocWriter :: Class _BaseWriter
[hide private]
[frames] | no frames]

Class _BaseWriter

source code

Known Subclasses:

Base class for document writing classes. Each subclass implements a specific format (html, latex, rst, etc.).

Instance Methods [hide private]
 
__init__(self, format, filename_extension) source code
 
write_to_file(self, filename)
Write formatted document to a file.
source code
 
__str__(self)
Return formatted document.
source code
 
header(self)
Header as required by format.
source code
 
footer(self)
Footer as required by format.
source code
 
not_impl(self, method) source code
 
title(self, title, authors_and_institutions=[], date='today')
Provide title and authors.
source code
 
today_date(self)
Return a string with today's date suitably formatted.
source code
 
section(self, title, label=None)
Write a section heading with the given title and an optional label (for navigation).
source code
 
subsection(self, title, label=None)
Write a subsection heading with the given title and an optional label (for navigation).
source code
 
subsubsection(self, title, label=None)
Write a subsubsection heading with the given title and an optional label (for navigation).
source code
 
paragraph(self, 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).
source code
 
paragraph_separator(self)
Add a (space) separator between running paragraphs.
source code
 
text(self, text, indent=0)
Write plain text.
source code
 
expandtext(self, text, tags, tags_replacements)
In a string text, replace all occurences of strings defined in tags by the corresponding strings defined in tags_replacements.
source code
 
list(self, items, listtype='itemize')
Write list or nested lists.
source code
 
unfold_list(self, items, item_handler, listtype, level=0)
Traverse a possibly nested list and call item_handler for each item.
source code
 
item_handler(self, item, listtype, level, keyword=None)
Write out the syntax for an item in a list.
source code
 
verbatim(self, code)
Write verbatim text in fixed-width form (typically for computer code).
source code
 
math(self, text)
Write block of mathematical text (equations).
source code
 
raw(self, text)
Write text directly 'as is' to output.
source code
 
figure_conversion(self, filename, extensions)
Convert filename to an image with type according to extension(s).
source code
 
figure(self, filename, caption, width=None, height=None, label=None)
Insert a figure into the document.
source code
 
table(self, 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.
source code
 
url(self, url_address, link_text=None)
Typeset an URL (with an optional link).
source code
 
link(self, link_text, link_target)
Typeset a hyperlink.
source code
Properties [hide private]
  document
Formatted document as a string
Method Details [hide private]

write_to_file(self, filename)

source code 

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).

header(self)

source code 

Header as required by format. Called in constructor.

footer(self)

source code 

Footer as required by format. Called in write_to_file.

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

source code 

Provide title and authors.

Parameters:
  • title - document title (string).
  • 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.
  • date - None implies no date, while 'today' generates the current date, otherwise a string is supplied.

text(self, text, indent=0)

source code 

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

expandtext(self, text, tags, tags_replacements)

source code 

In a string text, replace all occurences of strings defined in tags by the corresponding strings defined in tags_replacements. Both tags and tags_replacements are dictionaries with keys such as 'bold', 'emphasize', 'verbatim', 'math', and values consisting of regular expression patterns.

This method allows application code to use some generic ways of writing emphasized, boldface, and verbatim text, typically in the Doconce format with *emphasized text*, _boldface text_, and `verbatim fixed font width text`.

list(self, items, listtype='itemize')

source code 

Write list or nested lists.

Parameters:
  • items - list of items.
  • listtype - 'itemize', 'enumerate', or 'description'.

unfold_list(self, items, item_handler, listtype, level=0)

source code 

Traverse a possibly nested list and call item_handler for each item. To be used in subclasses for easy list handling.

Parameters:
  • items - list to be processed.
  • item_handler - callable, see that method for doc of arguments.
  • listtype - 'itemize', 'enumerate', or 'description'.
  • level - the level of a sublist (0 is main list, increased by 1 for each sublevel).

item_handler(self, item, listtype, level, keyword=None)

source code 

Write out the syntax for an item in a list.

Parameters:
  • 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.
  • listtype - 'itemize, 'enumerate', or 'description'.
  • level - list level number, 0 is the mainlist, increased by 1 for each sublist (the level number implies the amount of indentation).
  • keyword - the keyword of the item in a 'description' list.

figure_conversion(self, filename, extensions)

source code 

Convert filename to an image with type according to extension(s).

The first existing file with an extension encountered in the extensions list is returned. If no files with the right extensions are found, the convert utility from the ImageMagick suite is used to convert filename.ps or filename.eps to filename + extensions[0].

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

source code 

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.

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

source code 

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

Parameters:
  • table - list of list with rows/columns in table, including (optional) column-headline 1st row and row-headline 1st column.
  • 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).
  • column_headline_pos - position l/c/r for the headline row

Property Details [hide private]

document

Formatted document as a string

Get Method:
unreachable(self)