[Python-checkins] CVS: python/dist/src/Doc/tools/sgmlconv latex2esis.py,1.20,1.21

Fred L. Drake python-dev@python.org
2000年11月22日 09:56:46 -0800


Update of /cvsroot/python/python/dist/src/Doc/tools/sgmlconv
In directory slayer.i.sourceforge.net:/tmp/cvs-serv12942/tools/sgmlconv
Modified Files:
	latex2esis.py 
Log Message:
Convert the LaTeX "tie" (~) to a simple space.
Add support for some combining characters.
Remove unnecessary imports and dependencies on PyXML and esistools.
Index: latex2esis.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tools/sgmlconv/latex2esis.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** latex2esis.py	1999年08月26日 17:54:16	1.20
--- latex2esis.py	2000年11月22日 17:56:43	1.21
***************
*** 17,21 ****
 __version__ = '$Revision$'
 
- import copy
 import errno
 import getopt
--- 17,20 ----
***************
*** 23,31 ****
 import re
 import string
- import StringIO
 import sys
 import UserList
 
- from esistools import encode
 from types import ListType, StringType, TupleType
 
--- 22,29 ----
 import re
 import string
 import sys
 import UserList
+ import xml.sax.saxutils
 
 from types import ListType, StringType, TupleType
 
***************
*** 51,54 ****
--- 49,56 ----
 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{([^}]*)}")
***************
*** 56,60 ****
 _begin_macro_rx = re.compile(r"[\\]([a-zA-Z]+[*]?) ?({|\s*\n?)")
 _comment_rx = re.compile("%+ ?(.*)\n[ \t]*")
! _text_rx = re.compile(r"[^]%\\{}]+")
 _optional_rx = re.compile(r"\s*[[]([^]]*)[]]")
 # _parameter_rx is this complicated to allow {...} inside a parameter;
--- 58,62 ----
 _begin_macro_rx = re.compile(r"[\\]([a-zA-Z]+[*]?) ?({|\s*\n?)")
 _comment_rx = re.compile("%+ ?(.*)\n[ \t]*")
! _text_rx = re.compile(r"[^]~%\\{}]+")
 _optional_rx = re.compile(r"\s*[[]([^]]*)[]]")
 # _parameter_rx is this complicated to allow {...} inside a parameter;
***************
*** 113,116 ****
--- 115,121 ----
 self.preamble = 1
 
+ def write_ordinal(self, ordinal):
+ self.write("-\\%%%d;\n" % ordinal)
+ 
 def err_write(self, msg):
 if DEBUG:
***************
*** 166,169 ****
--- 171,180 ----
 # 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:
***************
*** 291,294 ****
--- 302,310 ----
 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("")
***************
*** 303,306 ****
--- 319,330 ----
 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:
***************
*** 332,335 ****
--- 356,371 ----
 + 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):

AltStyle によって変換されたページ (->オリジナル) /