HTMLtag module for LaTeX users
William Park
April 1999
HTMLtag module allows LaTeX user to generate HTML
document using more familiar LaTeX structures, such as title, table of
contents, numbered sections, numbered equations, tabular and array
tables, math expressions as transparent GIF images, references,
footnotes, etc. It automatically handles the formating detail of HTML
tags (hence the name), and, thus, enables the user to write the
content of document as easily as he can with LaTeX.
Essentially, user would write a Python script, importing
HTMLtag and other modules as needed, and run it through python.
The HTML document is generated and sent to "stdout" which would
normally be redirected unless the script is CGI. For example,
python test.source > test.html
The module does not convert already existing LaTeX file to
HTML, like latex2html [1]. Moreover,
latex2html produces many HTML files which are difficult to
download or upload over the Internet; in comparison, HTMLtag is
designed to produce one file. Similiar package for generating HTML
document already exist, namely HTMLgen and HTMLCreate
[2], but they are difficult to use for writing
something that vaguely resembles LaTeX document, something that every
LaTeX user knows how to write.
To get an overview of this article, see Table of
Contents at the bottom.
- Summary
- Implements HTML tag and options, with or without closing tag
- Methods
- __init__(self, string [, string [, string] ])
- setoptions(self, string)
- string = head(self)
- string = tail(self)
- string = __call__(self [, string])
- Attributes
- tag = string
- options = dictionary
- prefix = string
- suffix = string
This is core class which handles all the details of HTML
tag and its options. Basically, HTML tag is made up of head part
which contains all the options
and tail part
The text that goes in between can include another HTML tag; that is,
HTML tag can be nested but cannot overlap. Tag object would be used
where HTML tag is repeatedly used and modified. OpenTag class defines
only head part of HTML tag, and the tail part can be omitted or does
not exist.
- Summary
- Implements nested HTML tags
- Methods
- __init__(self [, Tag() [, ...] ])
- string = head(self)
- string = tail(self)
- string = __call__(self [, string])
- Attributes
- argv = tuple
This class is convenient when nested HTML tags have many
options that are error prone to type manually. For example, the title
of this article was print with
p = Tag('p')
big = Tag('big')
pbigbig = NestedTag(p, big, big)
print pbigbig(self.title)
which is equivalent to
print '' + self.title + '
'
- Summary
- Prints document title at the beginning and end of document
- Methods
- __init__(self, string, string [, string [, string] ])
- begin_document(self [, string])
- maketitle(self)
- makeclosing(self)
- end_document(self)
- Attributes
- title = string
- author = string
- date = string
- email = string
For an example, the title, author, and date at the top was
generated with
title = HTMLtag.Title(
title = 'HTMLtag module for LaTeX users',
author = 'William Park',
date = 'April 1999',
email = 'parkw@better.net')
title.begin_document()
title.maketitle()
and the closing at the bottom was generated with
title.makeclosing()
title.end_document()
- Summary
- Generates HTML table for text and math contents
- Methods
- __init__(self [, string])
- string = __call__(self, string | list)
- list = text_to_list(self, string)
- Attributes
- rowsep = string
- colsep = string
- format = string
- table = Tag()
- tr = Tag()
- td = Tag()
They differ in the default vertical alignment of columns
and presence of borders. For example,
p = HTMLtag.Tabular('rcl')
p(['left', 'center', 'right'], ['a', 'b', 'c'], ['1', '2', '3']])
will generates table suitable for text contents,
left |
center |
right |
a |
b |
c |
1 |
2 |
3 |
and
p = HTMLtag.Array('rcl')
p(['left', 'center', 'right'], ['a', 'b', 'c'], ['1', '2', '3']])
will generates table suitable for math contents,
left |
center |
right |
a |
b |
c |
1 |
2 |
3 |
- Summary
- Generates and print numbered footnotes
- Usage
- Tag() = footnote(string)
- Global Variables
- footnote_counter = number
- footnote_data = list
For an example of footnotes, see List of Footnotes at the
bottom, which was generated with
HTMLtag.makefootnotes()
- Summary
- Generates numbered section, subsection, and subsubsection,
and prints table of contents
- Usage
- Tag() = section(string [, string])
- Tag() = subsection(string [, string])
- Tag() = subsubsection(string [, string])
- Global Variables
- section_counter0 = number
- section_counter1 = number
- section_counter2 = number
- section_data = list
For an example, see Table of Contents at the bottom, which
was generated with
HTMLtag.tableofcontents()
- Summary
- Escape unsafe HTML characters within math expression or
unconditionally
- Usage
- string = escapemath(string)
- string = escapeall(string)
escapemath() escapes the following 6 math
expressions
< << <= > >> >=
which are delimited by whitespaces. And, escapeall() escapes
3 unsafe characters
< & >
unconditionally wherever they occur.
- Summary
- Converts LaTeX expression to transparent GIF image
- Usage
- Tag() = latex2gif(string [, number])
- Global Variables
- gif_counter = number
- latex_template = string
- run_latex = 0 or 1
For example, the image for Fourier transform of x(t)
and for inverse Fourier transform of X(f)
were generated with
img1 = HTMLtag.latex2gif(r'$$X(f) = \int_0^\infty x(t) e^{-j2\pi ft} dt$$')
img2 = HTMLtag.latex2gif(r'$$x(t) = \int_0^\infty X(f) e^{j2\pi ft} df$$')
- Summary
- Generates numbered equations
- Usage
- Tag() = equation(string)
- Global Variables
- equation_counter = number
For example,
a = HTMLtag.equation(img1())
b = HTMLtag.equation(img2())
will display the Fourier transform pair with equation numbers
 | (1) |
 | (2) |
so that they can be referenced as Eqns 1 and 2.
- [1]
- latex2html is perl script
for converting arbitrary LaTeX file to HTML. In fact, the online
Python documentations are generated by this program. This and other
programs useful in converting from TeX/LaTeX to HTML can be found at
http://www.tug.org/interest.html
- [2]
- HTMLgen and HTMLCreate packages
can be found in HTML section of http://www.python.org/topics
This file was generated using HTMLtag package.
William Park parkw@better.net
April 1999