From 691a5a7c0967fb486a973b1ee0719a4d910f80f8 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Wed, 22 Nov 2000 17:56:43 +0000 Subject: Convert the LaTeX "tie" (~) to a simple space. Add support for some combining characters. Remove unnecessary imports and dependencies on PyXML and esistools. --- Doc/tools/sgmlconv/latex2esis.py | 44 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Doc/tools/sgmlconv/latex2esis.py b/Doc/tools/sgmlconv/latex2esis.py index 325b0b1..379878a 100755 --- a/Doc/tools/sgmlconv/latex2esis.py +++ b/Doc/tools/sgmlconv/latex2esis.py @@ -16,17 +16,15 @@ to load an alternate table from an external file. """ __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: @@ -50,12 +48,16 @@ class LaTeXStackError(LaTeXFormatError): self.stack = stack[:] LaTeXFormatError.__init__(self, msg) +def encode(s): + s = xml.sax.saxutils.escape(s) + return s.replace("\n", "\\n\n-") + _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}} @@ -112,6 +114,9 @@ class Conversion: 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") @@ -165,6 +170,12 @@ class Conversion: 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! @@ -290,6 +301,11 @@ class Conversion: 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:] @@ -302,6 +318,14 @@ class Conversion: 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()) @@ -332,6 +356,18 @@ class Conversion: + 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 -- cgit v0.12