document.warning("Malformed LyX document: Could not find end of tabular.")
i = j
continue
-
- k = find_token(document.body, "<features tabularvalignment=", i)
- if k == -1:
- i = j
- continue
-
- # which valignment is specified?
- tabularvalignment_re = re.compile(r'<features tabularvalignment="(top|bottom)">')
- m = tabularvalignment_re.match(document.body[k])
- if not m:
- i = j
- continue
-
- tabularvalignment = m.group(1)
-
- subst = ['\\end_layout', '\\end_inset']
- document.body[j+1:j+1] = subst # just inserts those lines
- subst = ['\\begin_inset Box Frameless',
- 'position "' + tabularvalignment[0] +'"',
- 'hor_pos "c"',
- 'has_inner_box 1',
- 'inner_pos "c"',
- 'use_parbox 0',
- 'width "0col%"',
- 'special "none"',
- 'height "1in"',
- 'height_special "totalheight"',
- 'status open',
- '',
- '\\begin_layout Plain Layout']
- document.body[i:i] = subst # this just inserts the array at i
- i += len(subst) + 2 # adjust i to save a few cycles
+ # don't set a box for longtables, only delete tabularvalignment
+ # the alignment is 2 lines below \\begin_inset Tabular
+ p = document.body[i+2].find("islongtable")
+ if p > -1:
+ q = document.body[i+2].find("tabularvalignment")
+ if q > -1:
+ document.body[i+2] = document.body[i+2][:q-1]
+ document.body[i+2] = document.body[i+2] + '>'
+ i = i + 1
+
+ # when no longtable
+ if p == -1:
+ tabularvalignment = 'c'
+ # which valignment is specified?
+ m = document.body[i+2].find('tabularvalignment="top"')
+ if m > -1:
+ tabularvalignment = 't'
+ m = document.body[i+2].find('tabularvalignment="bottom"')
+ if m > -1:
+ tabularvalignment = 'b'
+ # delete tabularvalignment
+ q = document.body[i+2].find("tabularvalignment")
+ if q > -1:
+ document.body[i+2] = document.body[i+2][:q-1]
+ document.body[i+2] = document.body[i+2] + '>'
+
+ # don't add a box when centered
+ if tabularvalignment == 'c':
+ i = j
+ continue
+ subst = ['\\end_layout', '\\end_inset']
+ document.body[j+1:j+1] = subst # just inserts those lines
+ subst = ['\\begin_inset Box Frameless',
+ 'position "' + tabularvalignment +'"',
+ 'hor_pos "c"',
+ 'has_inner_box 1',
+ 'inner_pos "c"',
+ 'use_parbox 0',
+ # we don't know the width, assume 50%
+ 'width "50col%"',
+ 'special "none"',
+ 'height "1in"',
+ 'height_special "totalheight"',
+ 'status open',
+ '',
+ '\\begin_layout Plain Layout']
+ document.body[i:i] = subst # this just inserts the array at i
+ i += len(subst) + 2 # adjust i to save a few cycles
def revert_phantom(document):
return
colorcode = get_value(document.header, '\\backgroundcolor', 0)
del document.header[i]
+ # don't clutter the preamble if backgroundcolor is not set
+ if colorcode == "#ffffff":
+ continue
# the color code is in the form #rrggbb where every character denotes a hex number
# convert the string to an int
red = string.atoi(colorcode[1:3],16)
i = i + 1
+def revert_strikeout(document):
+ " Reverts \\strikeout character style "
+ while True:
+ i = find_token(document.body, '\\strikeout', 0)
+ if i == -1:
+ return
+ del document.body[i]
+
+
+def revert_uulinewave(document):
+ " Reverts \\uuline, and \\uwave character styles "
+ while True:
+ i = find_token(document.body, '\\uuline', 0)
+ if i == -1:
+ break
+ del document.body[i]
+ while True:
+ i = find_token(document.body, '\\uwave', 0)
+ if i == -1:
+ return
+ del document.body[i]
+
+
+def revert_ulinelatex(document):
+ " Reverts \\uline character style "
+ i = find_token(document.body, '\\bar under', 0)
+ if i == -1:
+ return
+ insert_to_preamble(0, document,
+ '% Commands inserted by lyx2lyx for proper underlining\n'
+ + '\\PassOptionsToPackage{normalem}{ulem}\n'
+ + '\\usepackage{ulem}\n'
+ + '\\let\\cite@rig\\cite\n'
+ + '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n'
+ + ' \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n'
+ + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n')
+
+
+def revert_custom_processors(document):
+ " Remove bibtex_command and index_command params "
+ i = find_token(document.header, '\\bibtex_command', 0)
+ if i == -1:
+ document.warning("Malformed LyX document: Missing \\bibtex_command.")
+ return
+ del document.header[i]
+ i = find_token(document.header, '\\index_command', 0)
+ if i == -1:
+ document.warning("Malformed LyX document: Missing \\index_command.")
+ return
+ del document.header[i]
+
+
+def convert_nomencl_width(document):
+ " Add set_width param to nomencl_print "
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
+ if i == -1:
+ break
+ document.body.insert(i + 2, "set_width \"none\"")
+ i = i + 1
+
+
+def revert_nomencl_width(document):
+ " Remove set_width param from nomencl_print "
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
+ if i == -1:
+ break
+ j = find_end_of_inset(document.body, i)
+ l = find_token(document.body, "set_width", i, j)
+ if l == -1:
+ document.warning("Can't find set_width option for nomencl_print!")
+ i = j
+ continue
+ del document.body[l]
+ i = i + 1
+
+
+def revert_nomencl_cwidth(document):
+ " Remove width param from nomencl_print "
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
+ if i == -1:
+ break
+ j = find_end_of_inset(document.body, i)
+ l = find_token(document.body, "width", i, j)
+ if l == -1:
+ document.warning("Can't find width option for nomencl_print!")
+ i = j
+ continue
+ width = get_value(document.body, "width", i, j).strip('"')
+ del document.body[l]
+ add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
+ i = i + 1
+
+
+def revert_applemac(document):
+ " Revert applemac encoding to auto "
+ i = 0
+ if document.encoding == "applemac":
+ document.encoding = "auto"
+ i = find_token(document.header, "\\encoding", 0)
+ if i != -1:
+ document.header[i] = "\\encoding auto"
+
+
+def revert_longtable_align(document):
+ " Remove longtable alignment setting "
+ i = 0
+ j = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset Tabular", i)
+ if i == -1:
+ break
+ # the alignment is 2 lines below \\begin_inset Tabular
+ j = document.body[i+2].find("longtabularalignment")
+ if j == -1:
+ break
+ document.body[i+2] = document.body[i+2][:j-1]
+ document.body[i+2] = document.body[i+2] + '>'
+ i = i + 1
+
+
+def revert_branch_filename(document):
+ " Remove \\filename_suffix parameter from branches "
+ i = 0
+ while True:
+ i = find_token(document.header, "\\filename_suffix", i)
+ if i == -1:
+ return
+ del document.header[i]
+
+
##
# Conversion hub
#
[351, []],
[352, [convert_splitindex]],
[353, []],
- [354, []]
+ [354, []],
+ [355, []],
+ [356, []],
+ [357, []],
+ [358, []],
+ [359, [convert_nomencl_width]],
+ [360, []],
+ [361, []],
+ [362, []],
+ [363, []],
+ [364, []]
]
-revert = [[353, [revert_printindexall]],
+revert = [[363, [revert_branch_filename]],
+ [362, [revert_longtable_align]],
+ [361, [revert_applemac]],
+ [360, []],
+ [359, [revert_nomencl_cwidth]],
+ [358, [revert_nomencl_width]],
+ [357, [revert_custom_processors]],
+ [356, [revert_ulinelatex]],
+ [355, [revert_uulinewave]],
+ [354, [revert_strikeout]],
+ [353, [revert_printindexall]],
[352, [revert_subindex]],
[351, [revert_splitindex]],
[350, [revert_backgroundcolor]],