osf = True
preamble = "\\usepackage"
if osf:
- preamble += "[osf]"
document.header[j] = "\\font_osf false"
- preamble += "{libertine}"
+ else:
+ preamble += "[lining]"
+ preamble += "{libertine-type1}"
add_to_preamble(document, [preamble])
document.header[i] = "\\font_roman default"
preamble += "]{mathdesign}"
add_to_preamble(document, [preamble])
document.header[i] = "\\font_roman default"
-
+
+
+def revert_texgyre(document):
+ " Revert native TeXGyre font definition to LaTeX "
+
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ texgyre_fonts = ["tgadventor", "tgbonum", "tgchorus", "tgcursor", \
+ "tgheros", "tgpagella", "tgschola", "tgtermes"]
+ i = find_token(document.header, "\\font_roman", 0)
+ if i != -1:
+ val = get_value(document.header, "\\font_roman", i)
+ if val in texgyre_fonts:
+ preamble = "\\usepackage{%s}" % val
+ add_to_preamble(document, [preamble])
+ document.header[i] = "\\font_roman default"
+ i = find_token(document.header, "\\font_sans", 0)
+ if i != -1:
+ val = get_value(document.header, "\\font_sans", i)
+ if val in texgyre_fonts:
+ preamble = "\\usepackage{%s}" % val
+ add_to_preamble(document, [preamble])
+ document.header[i] = "\\font_sans default"
+ i = find_token(document.header, "\\font_typewriter", 0)
+ if i != -1:
+ val = get_value(document.header, "\\font_typewriter", i)
+ if val in texgyre_fonts:
+ preamble = "\\usepackage{%s}" % val
+ add_to_preamble(document, [preamble])
+ document.header[i] = "\\font_typewriter default"
+
+
+def revert_ipadeco(document):
+ " Revert IPA decorations to ERT "
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset IPADeco", i)
+ if i == -1:
+ return
+ end = find_end_of_inset(document.body, i)
+ if end == -1:
+ document.warning("Can't find end of inset at line " + str(i))
+ i += 1
+ continue
+ line = document.body[i]
+ rx = re.compile(r'\\begin_inset IPADeco (.*)$')
+ m = rx.match(line)
+ decotype = m.group(1)
+ if decotype != "toptiebar" and decotype != "bottomtiebar":
+ document.warning("Invalid IPADeco type: " + decotype)
+ i = end
+ continue
+ blay = find_token(document.body, "\\begin_layout Plain Layout", i, end)
+ if blay == -1:
+ document.warning("Can't find layout for inset at line " + str(i))
+ i = end
+ continue
+ bend = find_end_of_layout(document.body, blay)
+ if bend == -1:
+ document.warning("Malformed LyX document: Could not find end of IPADeco inset's layout.")
+ i = end
+ continue
+ substi = ["\\begin_inset ERT", "status collapsed", "",
+ "\\begin_layout Plain Layout", "", "", "\\backslash",
+ decotype + "{", "\\end_layout", "", "\\end_inset"]
+ substj = ["\\size default", "", "\\begin_inset ERT", "status collapsed", "",
+ "\\begin_layout Plain Layout", "", "}", "\\end_layout", "", "\\end_inset"]
+ # do the later one first so as not to mess up the numbering
+ document.body[bend:end + 1] = substj
+ document.body[i:blay + 1] = substi
+ i = end + len(substi) + len(substj) - (end - bend) - (blay - i) - 2
+ add_to_preamble(document, "\\usepackage{tipa}")
+
+
+def revert_ipachar(document):
+ ' Revert \\IPAChar to ERT '
+ i = 0
+ found = False
+ while i < len(document.body):
+ m = re.match(r'(.*)\\IPAChar \\(\w+\{\w+\})(.*)', document.body[i])
+ if m:
+ found = True
+ before = m.group(1)
+ ipachar = m.group(2)
+ after = m.group(3)
+ subst = [before,
+ '\\begin_inset ERT',
+ 'status collapsed', '',
+ '\\begin_layout Standard',
+ '', '', '\\backslash',
+ ipachar,
+ '\\end_layout', '',
+ '\\end_inset', '',
+ after]
+ document.body[i: i+1] = subst
+ i = i + len(subst)
+ else:
+ i = i + 1
+ if found:
+ add_to_preamble(document, "\\usepackage{tone}")
+
+
+def revert_minionpro(document):
+ " Revert native MinionPro font definition to LaTeX "
+
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ i = find_token(document.header, "\\font_roman minionpro", 0)
+ if i != -1:
+ osf = False
+ j = find_token(document.header, "\\font_osf true", 0)
+ if j != -1:
+ osf = True
+ preamble = "\\usepackage"
+ if osf:
+ document.header[j] = "\\font_osf false"
+ else:
+ preamble += "[lf]"
+ preamble += "{MinionPro}"
+ add_to_preamble(document, [preamble])
+ document.header[i] = "\\font_roman default"
+
+
+def revert_mathfonts(document):
+ " Revert native math font definitions to LaTeX "
+
+ i = find_token(document.header, "\\font_math", 0)
+ if i == -1:
+ return
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ val = get_value(document.header, "\\font_math", i)
+ if val == "eulervm":
+ add_to_preamble(document, "\\usepackage{eulervm}")
+ elif val == "default":
+ mathfont_dict = {
+ "lmodern": "\\renewcommand{\\rmdefault}{lmr}",
+ "minionpro": "\\usepackage[onlytext,lf]{MinionPro}",
+ "minionpro-osf": "\\usepackage[onlytext]{MinionPro}",
+ "palatino": "\\renewcommand{\\rmdefault}{ppl}",
+ "palatino-osf": "\\renewcommand{\\rmdefault}{pplj}",
+ "times": "\\renewcommand{\\rmdefault}{ptm}",
+ "utopia": "\\renewcommand{\\rmdefault}{futs}",
+ "utopia-osf": "\\renewcommand{\\rmdefault}{futj}",
+ }
+ j = find_token(document.header, "\\font_roman", 0)
+ if j != -1:
+ rm = get_value(document.header, "\\font_roman", j)
+ k = find_token(document.header, "\\font_osf true", 0)
+ if k != -1:
+ rm += "-osf"
+ if rm in mathfont_dict.keys():
+ add_to_preamble(document, mathfont_dict[rm])
+ document.header[j] = "\\font_roman default"
+ if k != -1:
+ document.header[k] = "\\font_osf false"
+ del document.header[i]
+
+
+def revert_mdnomath(document):
+ " Revert mathdesign and fourier without math "
+
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ mathdesign_dict = {
+ "md-charter": "mdbch",
+ "md-utopia": "mdput",
+ "md-garamond": "mdugm"
+ }
+ i = find_token(document.header, "\\font_roman", 0)
+ if i == -1:
+ return
+ val = get_value(document.header, "\\font_roman", i)
+ if val in mathdesign_dict.keys():
+ j = find_token(document.header, "\\font_math", 0)
+ if j == -1:
+ document.header[i] = "\\font_roman %s" % mathdesign_dict[val]
+ mval = get_value(document.header, "\\font_math", j)
+ if mval == "default":
+ document.header[i] = "\\font_roman default"
+ add_to_preamble(document, "\\renewcommand{\\rmdefault}{%s}" % mathdesign_dict[val])
+ else:
+ document.header[i] = "\\font_roman %s" % mathdesign_dict[val]
+
+
+def convert_mdnomath(document):
+ " Change mathdesign font name "
+
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ mathdesign_dict = {
+ "mdbch": "md-charter",
+ "mdput": "md-utopia",
+ "mdugm": "md-garamond"
+ }
+ i = find_token(document.header, "\\font_roman", 0)
+ if i == -1:
+ return
+ val = get_value(document.header, "\\font_roman", i)
+ if val in mathdesign_dict.keys():
+ document.header[i] = "\\font_roman %s" % mathdesign_dict[val]
+
+
+def revert_newtxmath(document):
+ " Revert native newtxmath definitions to LaTeX "
+
+ i = find_token(document.header, "\\font_math", 0)
+ if i == -1:
+ return
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ val = get_value(document.header, "\\font_math", i)
+ mathfont_dict = {
+ "libertine-ntxm": "\\usepackage[libertine]{newtxmath}",
+ "minion-ntxm": "\\usepackage[minion]{newtxmath}",
+ "newtxmath": "\\usepackage{newtxmath}",
+ }
+ if val in mathfont_dict.keys():
+ add_to_preamble(document, mathfont_dict[val])
+ document.header[i] = "\\font_math auto"
+
+
+def revert_biolinum(document):
+ " Revert native biolinum font definition to LaTeX "
+
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ i = find_token(document.header, "\\font_sans biolinum", 0)
+ if i != -1:
+ osf = False
+ j = find_token(document.header, "\\font_osf true", 0)
+ if j != -1:
+ osf = True
+ preamble = "\\usepackage"
+ if not osf:
+ preamble += "[lf]"
+ preamble += "{biolinum-type1}"
+ add_to_preamble(document, [preamble])
+ document.header[i] = "\\font_sans default"
+
##
# Conversion hub
[433, [convert_armenian]],
[434, []],
[435, []],
- [436, []]
+ [436, []],
+ [437, []],
+ [438, []],
+ [439, []],
+ [440, []],
+ [441, [convert_mdnomath]],
+ [442, []],
+ [443, []],
+ [444, []]
]
revert = [
- [434, [revert_mathdesign]],
+ [443, [revert_biolinum]],
+ [442, []],
+ [441, [revert_newtxmath]],
+ [440, [revert_mdnomath]],
+ [439, [revert_mathfonts]],
+ [438, [revert_minionpro]],
+ [437, [revert_ipadeco, revert_ipachar]],
+ [436, [revert_texgyre]],
+ [435, [revert_mathdesign]],
[434, [revert_txtt]],
[433, [revert_libertine]],
[432, [revert_armenian]],