# Rename I18NPreamble to BabelPreamble and add LangPreamble
# Incremented to format 15, 28 May 2009 by lasgouttes
-# Add new tag OutputFormat; modules can be conditionned on feature
+# Add new tag OutputFormat; modules can be conditioned on feature
# "from->to".
# Incremented to format 16, 5 June 2009 by rgh
# HTMLTag, HTMLAttr, HTMLStyle, and HTMLPreamble
# For Floats:
# HTMLType, HTMLClass, HTMLStyle
-# These are still to be documented, once everything stabilizes.
+
+# Incremented to format 17, 12 August 2009 by rgh
+# Add IfStyle and IfCounter tags for layout.
+
+# Incremented to format 18, 27 October 2009 by rgh
+# Added some new tags for HTML output.
+
+# Incremented to format 19, 17 November 2009 by rgh
+# Added InPreamble tag.
+
+# Incremented to format 20, 17 December 2009 by rgh
+# Added ContentAsLabel tag.
+
+# Incremented to format 21, 12 January 2010 by rgh
+# Added HTMLTocLayout and HTMLTitle tags.
+
+# Incremented to format 22, 20 January 2010 by rgh
+# Added HTMLFormat tag to Counters.
+
+# Incremented to format 23, 13 February 2010 by spitz
+# Added Spellcheck tag.
+
+# Incremented to format 24, 5 March 2010 by rgh
+# Changed LaTeXBuiltin tag to NeedsFloatPkg and
+# added new tag ListCommand.
+
+# Incremented to format 25, 12 March 2010 by rgh
+# Added RefPrefix tag for layouts and floats.
+
+# Incremented to format 26, 29 March 2010 by rgh
+# Added CiteFormat.
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").
-currentFormat = 17
+# You might also want to consider running the
+# development/tools/updatelayouts.sh script to update all
+# layout files to the new format.
+
+currentFormat = 26
def usage(prog_name):
sys.exit(1)
-def trim_eol(line):
- " Remove end of line char(s)."
- if line[-2:-1] == '\r':
- return line[:-2]
- elif line[-1:] == '\r' or line[-1:] == '\n':
- return line[:-1]
- else:
- # file with no EOL in last line
- return line
-
-
def trim_bom(line):
" Remove byte order mark."
if line[0:3] == "\357\273\277":
return line
-def read(input):
+def read(source):
" Read input file and strip lineendings."
- lines = list()
- first_line = 1
- while 1:
- line = input.readline()
- if not line:
- break
- if (first_line):
- line = trim_bom(line)
- first_line = 0
- lines.append(trim_eol(line))
+ lines = source.read().splitlines()
+ lines[0] = trim_bom(lines[0])
return lines
def write(output, lines):
" Write output file with native lineendings."
- for line in lines:
- output.write(line + os.linesep)
+ output.write(os.linesep.join(lines) + os.linesep)
# Concatenates old and new in an intelligent way:
re_TocLevel = re.compile(r'^(\s*)(TocLevel)(\s+)(\S+)', re.IGNORECASE)
re_I18nPreamble = re.compile(r'^(\s*)I18nPreamble', re.IGNORECASE)
re_EndI18nPreamble = re.compile(r'^(\s*)EndI18nPreamble', re.IGNORECASE)
+ re_Float = re.compile(r'^\s*Float\s*$', re.IGNORECASE)
+ re_Type = re.compile(r'\s*Type\s+(\w+)', re.IGNORECASE)
+ re_Builtin = re.compile(r'^(\s*)LaTeXBuiltin\s+(\w*)', re.IGNORECASE)
+ re_True = re.compile(r'^\s*(?:true|1)\s*$', re.IGNORECASE)
# counters for sectioning styles (hardcoded in 1.3)
counters = {"part" : "\\Roman{part}",
while i < len(lines) and not re_EndBabelPreamble.match(lines[i]):
i += 1
continue
+
+ # Only new features
+ if format >= 24 and format <= 25:
+ i += 1
+ continue
+ if format == 23:
+ match = re_Float.match(lines[i])
+ i += 1
+ if not match:
+ continue
+ # we need to do two things:
+ # (i) Convert Builtin to NeedsFloatPkg
+ # (ii) Write ListCommand lines for the builtin floats table and figure
+ builtin = False
+ cmd = ""
+ while True and i < len(lines):
+ m1 = re_End.match(lines[i])
+ if m1:
+ if builtin and cmd:
+ line = " ListCommand " + cmd
+ lines.insert(i, line)
+ i += 1
+ break
+ m2 = re_Builtin.match(lines[i])
+ if m2:
+ builtin = True
+ ws1 = m2.group(1)
+ arg = m2.group(2)
+ newarg = ""
+ if re_True.match(arg):
+ newarg = "false"
+ else:
+ newarg = "true"
+ lines[i] = ws1 + "NeedsFloatPkg " + newarg
+ m3 = re_Type.match(lines[i])
+ if m3:
+ fltype = m3.group(1)
+ fltype = fltype.lower()
+ if fltype == "table":
+ cmd = "listoftables"
+ elif fltype == "figure":
+ cmd = "listoffigures"
+ # else unknown, which is why we're doing this
+ i += 1
+ continue
+
# This just involved new features, not any changes to old ones
- if format == 14 or format == 15 or format == 16:
+ if format >= 14 and format <= 22:
i += 1
continue
# Add the TocLevel setting for sectioning styles
if toclevel == "" and toclevels.has_key(style) and maxcounter <= toclevels[style]:
- lines.insert(i, '%sTocLevel %d' % (space1, toclevels[style]))
+ lines.insert(i, '%s\tTocLevel %d' % (space1, toclevels[style]))
i += 1
i += 1
# Open files
if len(argv) == 1:
- input = sys.stdin
+ source = sys.stdin
output = sys.stdout
elif len(argv) == 3:
- input = open(argv[1], 'rb')
+ source = open(argv[1], 'rb')
output = open(argv[2], 'wb')
else:
error(usage(argv[0]))
# Do the real work
- lines = read(input)
+ lines = read(source)
format = 1
while (format < currentFormat):
format = convert(lines)
# Close files
if len(argv) == 3:
- input.close()
+ source.close()
output.close()
return 0