import sys, os
from parser_tools import find_token, find_end_of, find_tokens, get_value
+from unicode_symbols import read_unicodesymbols
####################################################################
# Private helper functions
"theight%":"\\backslash\ntextheight", "pheight%":"\\backslash\npageheight"}
# Convert LyX units to LaTeX units
- for unit in units.keys():
+ for unit in list(units.keys()):
if len.find(unit) != -1:
len = '%f' % (len2value(len) / 100)
len = len.strip('0') + units[unit]
return l
-def read_unicodesymbols():
+# FIXME: Remove this function if the version imported from unicode_symbols works.
+# This function was the predecessor from that function, that in the meanwhile got
+# new fixes.
+def read_unicodesymbols2():
" Read the unicodesymbols list of unicode characters and corresponding commands."
+
+ # Provide support for both python 2 and 3
+ PY2 = sys.version_info[0] == 2
+ if not PY2:
+ unichr = chr
+ # End of code to support for both python 2 and 3
+
pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
spec_chars = []
continue
inert = ert_end >= curline
content += lyxline2latex(document, lines[curline], inert)
-
+
return content
document.body[i] = document.body[i].replace('\\begin_inset CharStyle', '\\begin_inset Flex')
def revert_flex(document):
- "Revert Flex to Charstyle"
+ "Revert Flex to CharStyle"
i = 0
while True:
i = find_token(document.body, "\\begin_inset Flex", i)
def remove_inzip_options(document):
"Remove inzipName and embed options from the Graphics inset"
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset Graphics", i)
if i == -1:
return
LatexCommand cmd
"""
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset LatexCommand", i)
if i == -1:
return
will not be able to recognize. Not sure what to do about that.
"""
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset CommandInset", i)
if i == -1:
return
def convert_latexcommand_index(document):
- "Convert from LatexCommand form to collapsable form."
+ "Convert from LatexCommand form to collapsible form."
i = 0
r1 = re.compile('name "(.*)"')
while True:
def revert_latexcommand_index(document):
- "Revert from collapsable form to LatexCommand form."
+ "Revert from collapsible form to LatexCommand form."
i = 0
while True:
i = find_token(document.body, "\\begin_inset Index", i)
def revert_inset_info(document):
'Replace info inset with its content'
i = 0
- while 1:
+ while True:
i = find_token(document.body, '\\begin_inset Info', i)
if i == -1:
return
def convert_framed_notes(document):
"Convert framed notes to boxes. "
i = 0
- while 1:
+ while True:
i = find_tokens(document.body, ["\\begin_inset Note Framed", "\\begin_inset Note Shaded"], i)
if i == -1:
return
return
newmodlist = []
for mod in modlist:
- if modulemap.has_key(mod):
+ if mod in modulemap:
newmodlist.append(modulemap[mod])
else:
document.warning("Can't find module %s in the module map!" % mod)
def revert_framed_notes(document):
"Revert framed boxes to notes. "
i = 0
- while 1:
+ while True:
i = find_tokens(document.body, ["\\begin_inset Box Framed", "\\begin_inset Box Shaded"], i)
if i == -1:
def revert_nocite(document):
"Revert LatexCommand nocite to ERT"
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset CommandInset citation", i)
if i == -1:
return
def revert_rotfloat(document):
" Revert sideways custom floats. "
i = 0
- while 1:
+ while True:
# whitespace intended (exclude \\begin_inset FloatList)
i = find_token(document.body, "\\begin_inset Float ", i)
if i == -1:
def revert_widesideways(document):
" Revert wide sideways floats. "
i = 0
- while 1:
+ while True:
# whitespace intended (exclude \\begin_inset FloatList)
i = find_token(document.body, '\\begin_inset Float ', i)
if i == -1:
def revert_inset_embedding(document, type):
' Remove embed tag from certain type of insets'
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset %s" % type, i)
if i == -1:
return
def convert_subfig(document):
" Convert subfigures to subfloats. "
i = 0
- while 1:
+ while True:
addedLines = 0
i = find_token(document.body, '\\begin_inset Graphics', i)
if i == -1:
def revert_subfig(document):
" Revert subfloats. "
i = 0
- while 1:
+ while True:
# whitespace intended (exclude \\begin_inset FloatList)
i = find_tokens(document.body, ['\\begin_inset Float ', '\\begin_inset Wrap'], i)
if i == -1:
def revert_pdfpages(document):
' Revert pdfpages external inset to ERT '
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset External", i)
if i == -1:
return
def revert_graphics_group(document):
' Revert group information from graphics insets '
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_inset Graphics", i)
if i == -1:
return
"Paragraph*": "Paragraph",
"Subparagraph*": "Subparagraph"}
i = 0
- while 1:
+ while True:
i = find_token(document.body, "\\begin_layout", i)
if i == -1:
return