"""
__version__ = '$Revision$'
-import copy
import errno
import getopt
import os
import re
import string
-import StringIO
import sys
import UserList
+import xml.sax.saxutils
-from esistools import encode
from types import ListType, StringType, TupleType
try:
self.stack = stack[:]
LaTeXFormatError.__init__(self, msg)
+def encode(s):
+ s = xml.sax.saxutils.escape(s)
+ return s.replace("\n", "\\n\n-")
+
\f
_begin_env_rx = re.compile(r"[\\]begin{([^}]*)}")
_end_env_rx = re.compile(r"[\\]end{([^}]*)}")
_begin_macro_rx = re.compile(r"[\\]([a-zA-Z]+[*]?) ?({|\s*\n?)")
_comment_rx = re.compile("%+ ?(.*)\n[ \t]*")
-_text_rx = re.compile(r"[^]%\\{}]+")
+_text_rx = re.compile(r"[^]~%\\{}]+")
_optional_rx = re.compile(r"\s*[[]([^]]*)[]]")
# _parameter_rx is this complicated to allow {...} inside a parameter;
# this is useful to match tabular layout specifications like {c|p{24pt}}
self.line = string.join(map(string.rstrip, ifp.readlines()), "\n")
self.preamble = 1
+ def write_ordinal(self, ordinal):
+ self.write("-\\%%%d;\n" % ordinal)
+
def err_write(self, msg):
if DEBUG:
sys.stderr.write(str(msg) + "\n")
if m:
# start of macro
macroname = m.group(1)
+ if macroname == "c":
+ # Ugh! This is a combining character...
+ endpos = m.end()
+ self.combining_char("c", line[endpos])
+ line = line[endpos + 1:]
+ continue
entry = self.get_entry(macroname)
if entry.verbatim:
# magic case!
del stack[-1]
line = line[1:]
continue
+ if line[0] == "~":
+ # don't worry about the "tie" aspect of this command
+ line = line[1:]
+ self.write("- \n")
+ continue
if line[0] == "{":
stack.append("")
line = line[1:]
self.write("(BREAK\n)BREAK\n")
line = line[2:]
continue
+ if line[:2] == r"\_":
+ line = "_" + line[2:]
+ continue
+ if line[:2] in (r"\'", r'\"'):
+ # combining characters...
+ self.combining_char(line[1], line[2])
+ line = line[3:]
+ continue
m = _text_rx.match(line)
if m:
text = encode(m.group())
+ string.join(stack, ", "))
# otherwise we just ran out of input here...
+ # This is a really limited table of combinations, but it will have
+ # to do for now.
+ _combinations = {
+ ("c", "c"): 0x00E7,
+ ("'", "e"): 0x00E9,
+ ('"', "o"): 0x00F6,
+ }
+
+ def combining_char(self, prefix, char):
+ ordinal = self._combinations[(prefix, char)]
+ self.write("-\\%%%d;\n" % ordinal)
+
def start_macro(self, name):
conversion = self.get_entry(name)
parameters = conversion.parameters