# is_in_inset, set_bool_value
# find_tokens, find_token_exact, check_token
-from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble, get_language_for_line)
+from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble, revert_language)
# revert_font_attrs, insert_to_preamble, latex_length
# get_ert, lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets
# revert_flex_inset, hex2ratio, str2bool
j = find_token(document.header, ft, 0)
if j != -1:
val = get_value(document.header, ft, j)
- vals = val.split()
- document.header[j] = ft + ' "' + fn + '" ' + vals[1]
+ words = val.split() # ! splits also values like '"DejaVu Sans"'
+ words[0] = '"' + fn + '"'
+ document.header[j] = ft + ' ' + ' '.join(words)
def revert_fonts(document, fm, fontmap):
" Revert native font definition to LaTeX "
continue
ft = mo.group(1) # 'roman', 'sans', 'typewriter', 'math'
val = get_value(document.header, ft, i)
- words = val.split()
- font = words[0].replace('"', '')
+ words = val.split(' ') # ! splits also values like '"DejaVu Sans"'
+ font = words[0].strip('"') # TeX font name has no whitespace
if not font in fm.font2pkgmap:
i += 1
continue
val = fontinfo.package
if not val in fontmap:
fontmap[val] = []
- document.header[i] = ft + ' "default" ' + words[1]
+ words[0] = '"default"'
+ document.header[i] = ft + ' ' + ' '.join(words)
if fontinfo.scaleopt != None:
xval = get_value(document.header, "\\font_" + fontinfo.scaletype + "_scale", 0)
mo = rscales.search(xval)
k = find_token(document.body, 'placement document', i, i + 2)
if k != -1:
del document.body[k]
- i = j
+ i += 1
continue
del document.body[k]
l = find_token(document.body, "\\begin_layout Plain Layout", i, j)
if l == -1:
document.warning("Can't find float layout!")
- i = j
+ i += 1
continue
alcmd = []
if alignment == "left":
alcmd = put_cmd_in_ert("\\raggedleft{}")
if len(alcmd) > 0:
document.body[l+1:l+1] = alcmd
- i = j
+ i += 1
def revert_tuftecite(document):
if vval != "":
needarray = True
vval += "V{\\linewidth}"
-
+
document.body[col_line] = document.body[col_line][:-1] + " special=\"" + vval + "\">"
# ERT newlines and linebreaks (since LyX < 2.4 automatically inserts parboxes
# with newlines, and we do not want that)
if engine in ["biblatex", "biblatex-natbib"]:
biblatex = True
- # Map lyx to latex encoding names
+ # Map lyx to latex encoding names
encodings = {
"utf8" : "utf8",
"utf8x" : "utf8x",
"lowersorbian" : ["%A, %d. %B %Y", "%d.%m.%y", "%d %B %Y", "%d %b %Y", "%d.%m.%Y"],
"macedonian" : ["%A, %d %B %Y", "%d.%m.%y", "%d %B %Y", "%d %b %Y", "%d.%m.%Y"],
"magyar" : ["%Y. %B %d., %A", "%Y. %m. %d.", "%Y. %B %d.", "%Y. %b %d.", "%Y.%m.%d."],
+ "malayalam" : ["%A, %d %B, %Y", "%d/%m/%y", "%d %B %Y", "%d %b %Y", "%d-%m-%Y"],
"marathi" : ["%A, %d %B, %Y", "%d/%m/%y", "%d %B %Y", "%d %b %Y", "%d-%m-%Y"],
"mongolian" : ["%A, %Y оны %m сарын %d", "%Y-%m-%d", "%Y оны %m сарын %d", "%d-%m-%Y", "%d-%m-%Y"],
"naustrian" : ["%A, %d. %B %Y", "%d.%m.%y", "%d. %B %Y", "%d. %b %Y", "%d.%m.%Y"],
fmt = re.sub('[^\'%]d', '%d', fmt)
fmt = fmt.replace("'", "")
result = dte.strftime(fmt)
+ if sys.version_info < (3,0):
+ # In Python 2, datetime module works with binary strings,
+ # our dateformat strings are utf8-encoded:
+ result = result.decode('utf-8')
document.body[i : j+1] = result
i = i + 1
"lowersorbian" : ["%H:%M:%S %Z", "%H:%M"],
"macedonian" : ["%H:%M:%S %Z", "%H:%M"],
"magyar" : ["%H:%M:%S %Z", "%H:%M"],
+ "malayalam" : ["%p %I:%M:%S %Z", "%p %I:%M"],
"marathi" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"mongolian" : ["%H:%M:%S %Z", "%H:%M"],
"naustrian" : ["%H:%M:%S %Z", "%H:%M"],
continue
arg = find_token(document.body, 'arg', i, j)
argv = get_quoted_value(document.body, "arg", arg)
- # remove trailing colons, menu accelerator (|...) and qt accelerator (&), while keeping literal " & "
+ # remove trailing colons, menu accelerator (|...) and qt accelerator (&), while keeping literal " & "
argv = argv.rstrip(':').split('|')[0].replace(" & ", "</amp;>").replace("&", "").replace("</amp;>", " & ")
document.body[i : j+1] = argv
i = i + 1
def convert_hebrew_parentheses(document):
" Don't reverse parentheses in Hebrew text"
+ current_language = document.language
for i, line in enumerate(document.body):
- if line.startswith('\\\\'):
- # not a text line, skip
- continue
- if get_language_for_line(document, i) == 'hebrew':
+ if line.startswith('\\lang '):
+ current_language = line[len('\\lang '):]
+ elif line.startswith('\\end_layout'):
+ current_language = document.language
+ elif current_language == 'hebrew' and not line.startswith('\\'):
document.body[i] = line.replace('(','\x00').replace(')','(').replace('\x00',')')
def revert_hebrew_parentheses(document):
" Store parentheses in Hebrew text reversed"
- # This only exists to keep the convert/revert nameing convention
+ # This only exists to keep the convert/revert naming convention
convert_hebrew_parentheses(document)
+def revert_malayalam(document):
+ " Set the document language to English but assure Malayalam output "
+
+ revert_language(document, "malayalam", "", "malayalam")
+
+
##
# Conversion hub
#
[564, []],
[565, [convert_AdobeFonts]], # Handle adobe fonts in GUI
[566, [convert_hebrew_parentheses]],
+ [567, []],
]
revert = [
+ [566, [revert_malayalam]],
[565, [revert_hebrew_parentheses]],
[564, [revert_AdobeFonts]],
[563, [revert_lformatinfo]],