def revert_use_package(document, pkg, commands, oldauto): # oldauto defines how the version we are reverting to behaves: # if it is true, the old version uses the package automatically. # if it is false, the old version never uses the package. regexp = re.compile(r'(\\use_package\s+%s)' % pkg) i = find_re(document.header, regexp, 0) value = "1" # default is auto if i != -1: value = get_value(document.header, "\\use_package" , i).split()[1] del document.header[i] if value == "2": # on add_to_preamble(document, ["\\usepackage{" + pkg + "}"]) elif value == "1" and not oldauto: # auto i = 0 while True: i = find_token(document.body, '\\begin_inset Formula', i) if i == -1: return j = find_end_of_inset(document.body, i) if j == -1: document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i)) i += 1 continue code = "\n".join(document.body[i:j]) for c in commands: if code.find("\\%s" % c) != -1: add_to_preamble(document, ["\\usepackage{" + pkg + "}"]) return i = j
def revert_use_package(document, pkg, commands, oldauto): # oldauto defines how the version we are reverting to behaves: # if it is true, the old version uses the package automatically. # if it is false, the old version never uses the package. regexp = re.compile(r'(\\use_package\s+%s)' % pkg) i = find_re(document.header, regexp, 0) value = "1" # default is auto if i != -1: value = get_value(document.header, "\\use_package", i).split()[1] del document.header[i] if value == "2": # on add_to_preamble(document, ["\\usepackage{" + pkg + "}"]) elif value == "1" and not oldauto: # auto i = 0 while True: i = find_token(document.body, '\\begin_inset Formula', i) if i == -1: return j = find_end_of_inset(document.body, i) if j == -1: document.warning( "Malformed LyX document: Can't find end of Formula inset at line " + str(i)) i += 1 continue code = "\n".join(document.body[i:j]) for c in commands: if code.find("\\%s" % c) != -1: add_to_preamble(document, ["\\usepackage{" + pkg + "}"]) return i = j
def revert_microtype(document): " Remove microtype settings. " i = find_token(document.header, "\\use_microtype", 0) if i == -1: return use_microtype = get_bool_value(document.header, "\\use_microtype", i) del document.header[i] if use_microtype: add_to_preamble(document, ["\\usepackage{microtype}"])
def revert_syriac(document): "Set the document language to English but assure Syriac output" if document.language == "syriac": document.language = "english" i = find_token(document.header, "\\language syriac", 0) if i != -1: document.header[i] = "\\language english" j = find_token(document.header, "\\language_package default", 0) if j != -1: document.header[j] = "\\language_package default" add_to_preamble(document, ["\\AtBeginDocument{\setotherlanguage{syriac}}"]) document.body[2:2] = [ "\\begin_layout Standard", "\\begin_inset ERT", "status open", "", "\\begin_layout Plain Layout", "", "", "\\backslash", "resetdefaultlanguage{syriac}", "\\end_layout", "", "\\end_inset", "", "", "\\end_layout", "" ]
def revert_xcharter(document): " Revert XCharter font definitions to LaTeX " i = find_token(document.header, "\\font_roman \"xcharter\"", 0) if i == -1: return # replace unsupported font setting document.header[i] = document.header[i].replace("xcharter", "default") # no need for preamble code with system fonts if get_bool_value(document.header, "\\use_non_tex_fonts"): return # transfer old style figures setting to package options j = find_token(document.header, "\\font_osf true") if j != -1: options = "[osf]" document.header[j] = "\\font_osf false" else: options = "" if i != -1: add_to_preamble(document, ["\\usepackage%s{XCharter}" % options])
def revert_paratype(document): " Revert ParaType font definitions to LaTeX " if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1: preamble = "" i1 = find_token(document.header, "\\font_roman \"PTSerif-TLF\"", 0) i2 = find_token(document.header, "\\font_sans \"default\"", 0) i3 = find_token(document.header, "\\font_typewriter \"default\"", 0) j = find_token(document.header, "\\font_sans \"PTSans-TLF\"", 0) sfval = get_value(document.header, "\\font_sf_scale", 0) # cutoff " 100" sfval = sfval[:-4] sfoption = "" if sfval != "100": sfoption = "scaled=" + format(float(sfval) / 100, '.2f') k = find_token(document.header, "\\font_typewriter \"PTMono-TLF\"", 0) ttval = get_value(document.header, "\\font_tt_scale", 0) # cutoff " 100" ttval = ttval[:-4] ttoption = "" if ttval != "100": ttoption = "scaled=" + format(float(ttval) / 100, '.2f') if i1 != -1 and i2 != -1 and i3 != -1: add_to_preamble(document, ["\\usepackage{paratype}"]) else: if i1 != -1: add_to_preamble(document, ["\\usepackage{PTSerif}"]) document.header[i1] = document.header[i1].replace( "PTSerif-TLF", "default") if j != -1: if sfoption != "": add_to_preamble(document, ["\\usepackage[" + sfoption + "]{PTSans}"]) else: add_to_preamble(document, ["\\usepackage{PTSans}"]) document.header[j] = document.header[j].replace( "PTSans-TLF", "default") if k != -1: if ttoption != "": add_to_preamble(document, ["\\usepackage[" + ttoption + "]{PTMono}"]) else: add_to_preamble(document, ["\\usepackage{PTMono}"]) document.header[k] = document.header[k].replace( "PTMono-TLF", "default")