# del_token, check_token, get_option_value
from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, lyx2latex, \
- lyx2verbatim, length_in_bp
+ lyx2verbatim, length_in_bp, convert_info_insets
# insert_to_preamble, latex_length, revert_flex_inset, \
# revert_font_attrs, hex2ratio, str2bool
###
###############################################################################
+def convert_longtable_label_internal(document, forward):
+ """
+ Convert reference to "LongTableNoNumber" into "Unnumbered" if forward is True
+ else revert it.
+ """
+ old_reference = "\\begin_inset Caption LongTableNoNumber"
+ new_reference = "\\begin_inset Caption Unnumbered"
+
+ # if the purpose is to revert swap the strings roles
+ if not forward:
+ old_reference, new_reference = new_reference, old_reference
+
+ i = 0
+ while True:
+ i = find_token(document.body, old_reference, i)
+
+ if i == -1:
+ return
+
+ document.body[i] = new_reference
+
+
+def convert_longtable_label(document):
+ convert_longtable_label_internal(document, True)
+
+
+def revert_longtable_label(document):
+ convert_longtable_label_internal(document, False)
+
+
def convert_separator(document):
"""
Convert layout separators to separator insets and add (LaTeX) paragraph
}
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_deeper", i)
if i == -1:
break
i = i + 1
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\align", i)
if i == -1:
break
regexp = re.compile(r'^\\begin_layout (?:(-*)|(\s*))(Separator|EndOfSlide)(?:(-*)|(\s*))$', re.IGNORECASE)
i = 0
- while 1:
+ while True:
i = find_re(document.body, regexp, i)
if i == -1:
return
"", "\\end_inset", ""]
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset Separator", i)
if i == -1:
return
i = i + 1
+def convert_parbreak(document):
+ """
+ Convert parbreak separators not specifically used to separate
+ environments to latexpar separators.
+ """
+ parbreakinset = "\\begin_inset Separator parbreak"
+ i = 0
+ while True:
+ i = find_token(document.body, parbreakinset, i)
+ if i == -1:
+ return
+ lay = get_containing_layout(document.body, i)
+ if lay == False:
+ document.warning("Malformed LyX document: Can't convert separator inset at line " + str(i))
+ i += 1
+ continue
+ if lay[0] == "Standard":
+ # Convert only if not alone in the paragraph
+ k1 = find_nonempty_line(document.body, lay[1] + 1, i + 1)
+ k2 = find_nonempty_line(document.body, i + 1, lay[2])
+ if (k1 < i) or (k2 > i + 1) or not check_token(document.body[i], parbreakinset):
+ document.body[i] = document.body[i].replace("parbreak", "latexpar")
+ else:
+ document.body[i] = document.body[i].replace("parbreak", "latexpar")
+ i += 1
+
+
+def revert_parbreak(document):
+ """
+ Revert latexpar separators to parbreak separators.
+ """
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset Separator latexpar", i)
+ if i == -1:
+ return
+ document.body[i] = document.body[i].replace("latexpar", "parbreak")
+ i += 1
+
+
def revert_smash(document):
" Set amsmath to on if smash commands are used "
while i < len(document.body):
words = document.body[i].split()
if len(words) > 1 and words[0] == "\\begin_inset" and \
- words[1] in ["CommandInset", "ERT", "External", "Formula", "Graphics", "IPA", "listings"]:
+ words[1] in ["CommandInset", "ERT", "External", "Formula", "FormulaMacro", "Graphics", "IPA", "listings"]:
# must not replace anything in insets that store LaTeX contents in .lyx files
# (math and command insets withut overridden read() and write() methods
# filtering out IPA makes Text::readParToken() more simple
else:
i = j
continue
+ if len(words) > 0 and words[0] in ["\\leftindent", "\\paragraph_spacing", "\\align", "\\labelwidthstring"]:
+ # skip paragraph parameters (bug 10243)
+ i += 1
+ continue
while True:
j = document.body[i].find("--")
if j == -1:
else:
i = j
continue
- for key, value in specialchars.iteritems():
+ for key, value in specialchars.items():
if forward:
document.body[i] = document.body[i].replace("\\SpecialChar " + key, "\\SpecialChar " + value)
document.body[i] = document.body[i].replace("\\SpecialCharNoPassThru " + key, "\\SpecialCharNoPassThru " + value)
if i == -1:
document.warning("Malformed LyX document: No \\textclass!!")
return
- if document.dir == "":
- origin = "stdin"
+ if document.dir == u'':
+ origin = u'stdin'
else:
- relpath = ''
- if document.systemlyxdir and document.systemlyxdir != '':
+ relpath = u''
+ if document.systemlyxdir and document.systemlyxdir != u'':
try:
if os.path.isabs(document.dir):
absdir = os.path.normpath(document.dir)
else:
abssys = os.path.normpath(os.path.abspath(document.systemlyxdir))
relpath = os.path.relpath(absdir, abssys)
- if relpath.find('..') == 0:
- relpath = ''
+ if relpath.find(u'..') == 0:
+ relpath = u''
except:
- relpath = ''
- if relpath == '':
- origin = document.dir.replace('\\', '/') + '/'
+ relpath = u''
+ if relpath == u'':
+ origin = document.dir.replace(u'\\', u'/') + u'/'
else:
- origin = os.path.join("/systemlyxdir", relpath).replace('\\', '/') + '/'
- if os.name != 'nt':
- origin = unicode(origin, sys.getfilesystemencoding())
+ origin = os.path.join(u"/systemlyxdir", relpath).replace(u'\\', u'/') + u'/'
document.header[i:i] = ["\\origin " + origin]
# register that xcolor must be loaded in the preamble
if xcolor == False:
xcolor = True
- add_to_preamble(document, ["\\@ifundefined{rangeHsb}{\usepackage{xcolor}}{}"])
+ add_to_preamble(document, ["\\@ifundefined{rangeHsb}{\\usepackage{xcolor}}{}"])
# find the next \\color and/or the next \\end_layout
j = find_token(document.body, "\\color", i + 1)
k = find_token(document.body, "\\end_layout", i + 1)
pass
else:
# we also neeed to load xcolor in the preamble but only once
- add_to_preamble(document, ["\\@ifundefined{rangeHsb}{\usepackage{xcolor}}{}"])
+ add_to_preamble(document, ["\\@ifundefined{rangeHsb}{\\usepackage{xcolor}}{}"])
document.body[einset + 1 : einset + 1] = put_cmd_in_ert("}")
if framecolor != defaultframecolor:
document.body[binset:binset] = put_cmd_in_ert("\\fcolorbox{" + framecolor + "}{" + backcolor + "}{")
del document.header[i]
-def delete_TOG_project_URL(document):
- i = 0
- j = 0
- while True:
- # delete the TOG project URL
- i = find_token(document.body, "\\begin_layout TOG project URL", i)
- if i != -1:
- j = find_end_of_layout(document.body, i + 1)
- else:
- return
- if j != -1:
- del(document.body[i : j + 1])
- else:
- document.warning("Malformed LyX document: Can't find end of layout TOG project URL")
- return
- i += 1
-
-
-def delete_TOG_video_URL(document):
- i = 0
- j = 0
- while True:
- # delete the TOG video URL
- i = find_token(document.body, "\\begin_layout TOG video URL", i)
- if i != -1:
- j = find_end_of_layout(document.body, i)
- else:
- return
- if j != -1:
- del(document.body[i : j + 1])
- else:
- document.warning("Malformed LyX document: Can't find end of layout TOG video URL")
- return
- i += 1
+def convert_info_tabular_feature(document):
+ def f(arg):
+ return arg.replace("inset-modify tabular", "tabular-feature")
+ convert_info_insets(document, "shortcut(s)?|icon", f)
-def delete_TOG_data_URL(document):
- i = 0
- j = 0
- while True:
- # delete the TOG video URL
- i = find_token(document.body, "\\begin_layout TOG data URL", i)
- if i != -1:
- j = find_end_of_layout(document.body, i)
- else:
- return
- if j != -1:
- del(document.body[i : j + 1])
- else:
- document.warning("Malformed LyX document: Can't find end of layout TOG data URL")
- return
- i += 1
-
-
-def delete_TOG_code_URL(document):
- i = 0
- j = 0
- while True:
- # delete the TOG video URL
- i = find_token(document.body, "\\begin_layout TOG code URL", i)
- if i != -1:
- j = find_end_of_layout(document.body, i)
- else:
- return
- if j != -1:
- del(document.body[i : j + 1])
- else:
- document.warning("Malformed LyX document: Can't find end of layout TOG code URL")
- return
- i += 1
-
-
-def convert_ACM_siggraph(document):
- " Convert to version 0.92 of acmsiggraph. "
- if document.textclass != "acmsiggraph":
- return
- # at first delete the now nonexistent styles since their info is now
- # not needed and even unwanted
- delete_TOG_project_URL(document)
- delete_TOG_video_URL(document)
- delete_TOG_data_URL(document)
- delete_TOG_code_URL(document)
- # now add a note that the user knows that he still has work to do
- note = ["\\begin_layout Standard", "\\begin_inset Note Note", "status open", "",
- "\\begin_layout Plain Layout", "", "\\series bold",
- "\\color red", "Important note:", "\series default",
- " This file was converted by \\SpecialChar LyX to the format of acmsigplan 0.92.",
- " This conversion is incomplete because you must add new information about",
- " your article.",
- " To see what is required, open the \\SpecialChar LyX template file ",
- "\\family sans",
- "ACM-siggraph.lyx",
- "\\family default",
- ".",
- "\\end_layout",
- "",
- "\\end_inset",
- "",
- "",
- "\\end_layout",
- ""]
- document.body[1:1] = note
+def revert_info_tabular_feature(document):
+ def f(arg):
+ return arg.replace("tabular-feature", "inset-modify tabular")
+ convert_info_insets(document, "shortcut(s)?|icon", f)
##
[502, []],
[503, []],
[504, [convert_save_props]],
- [505, [convert_ACM_siggraph]]
+ [505, []],
+ [506, [convert_info_tabular_feature]],
+ [507, [convert_longtable_label]],
+ [508, [convert_parbreak]]
]
revert = [
- [504, [revert_save_props]],
+ [507, [revert_parbreak]],
+ [506, [revert_longtable_label]],
+ [505, [revert_info_tabular_feature]],
+ [504, []],
[503, [revert_save_props]],
[502, [revert_verbatim_star]],
[501, [revert_solution]],