'FiraSansUltralight,ultralight'],
"sans", "sf", "FiraSans", "scaled", "lf", "true")
fm.expandFontMapping(['FiraMono'], "typewriter", "tt", "FiraMono", "scaled", "lf", "true")
+ elif font == 'libertinus':
+ fm.expandFontMapping(['libertinus,serif'], "roman", None, "libertinus", None, "osf")
+ fm.expandFontMapping(['libertinusmath'], "math", None, "libertinust1math", None, None)
return fm
def convert_fonts(document, fm, osfoption = "osf"):
i = 0
while True:
- i = find_token(document.body, '\\begin_inset Float', i+1)
+ i = find_token(document.body, '\\begin_inset Float', i + 1)
if i == -1:
break
j = find_end_of_inset(document.body, i)
- k = find_token(document.body, 'placement class', i, i + 2)
+ k = find_token(document.body, 'placement class', i, j)
if k == -1:
- k = find_token(document.body, 'placement document', i, i + 2)
+ k = find_token(document.body, 'placement document', i, j)
if k != -1:
del document.body[k]
continue
i = 0
while True:
- i = find_token(document.body, '\\begin_inset Float', i+1)
+ i = find_token(document.body, '\\begin_inset Float', i + 1)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Can't find end of inset at line " + str(i))
continue
- k = find_token(document.body, 'alignment', i, i+4)
+ k = find_token(document.body, 'alignment', i, j)
if k == -1:
i = j
continue
alcmd = put_cmd_in_ert("\\raggedleft{}")
if len(alcmd) > 0:
document.body[l+1:l+1] = alcmd
- i = j
+ # There might be subfloats, so we do not want to move past
+ # the end of the inset.
+ i += 1
def revert_tuftecite(document):
"""Revert \cite commands in tufte classes"""
r'End',
]
+
def convert_ruby_module(document):
"""Use ruby module instead of local module definition"""
if document.del_local_layout(ruby_inset_def):
document.add_module("ruby")
+
def revert_ruby_module(document):
"""Replace ruby module with local module definition"""
if document.del_module("ruby"):
or (lang == "japanese-cjk" and inputenc == "utf8-cjk")):
document.set_parameter("inputencoding", "utf8")
+
def revert_utf8_japanese(document):
"""Use Japanese utf8 variants with Japanese documents."""
inputenc = get_value(document.header, "\\inputencoding")
if pretext:
add_to_preamble(document, pretext)
-
+
+def revert_ams_spaces(document):
+ "Revert InsetSpace medspace and thickspace into their TeX-code counterparts"
+ Found = False
+ insets = ["\\medspace{}", "\\thickspace{}"]
+ for inset in insets:
+ i = 0
+ j = 0
+ i = find_token(document.body, "\\begin_inset space " + inset, i)
+ if i == -1:
+ continue
+ end = find_end_of_inset(document.body, i)
+ subst = put_cmd_in_ert(inset)
+ document.body[i : end + 1] = subst
+ Found = True
+
+ if Found == True:
+ # load amsmath in the preamble if not already loaded
+ i = find_token(document.header, "\\use_package amsmath 2", 0)
+ if i == -1:
+ add_to_preamble(document, ["\\@ifundefined{thickspace}{\\usepackage{amsmath}}{}"])
+ return
+
+
+def convert_parskip(document):
+ " Move old parskip settings to preamble "
+
+ i = find_token(document.header, "\\paragraph_separation skip", 0)
+ if i == -1:
+ return
+
+ j = find_token(document.header, "\\defskip", 0)
+ if j == -1:
+ document.warning("Malformed LyX document! Missing \\defskip.")
+ return
+
+ val = get_value(document.header, "\\defskip", j)
+
+ skipval = "\\medskipamount"
+ if val == "smallskip" or val == "medskip" or val == "bigskip":
+ skipval = "\\" + val + "amount"
+ else:
+ skipval = val
+
+ add_to_preamble(document, ["\\setlength{\\parskip}{" + skipval + "}", "\\setlength{\\parindent}{0pt}"])
+
+ document.header[i] = "\\paragraph_separation indent"
+ document.header[j] = "\\paragraph_indentation default"
+
+
+def revert_parskip(document):
+ " Revert new parskip settings to preamble "
+
+ i = find_token(document.header, "\\paragraph_separation skip", 0)
+ if i == -1:
+ return
+
+ j = find_token(document.header, "\\defskip", 0)
+ if j == -1:
+ document.warning("Malformed LyX document! Missing \\defskip.")
+ return
+
+ val = get_value(document.header, "\\defskip", j)
+
+ skipval = ""
+ if val == "smallskip" or val == "medskip" or val == "bigskip":
+ skipval = "[skip=\\" + val + "amount]"
+ elif val == "fullline":
+ skipval = "[skip=\\baselineskip]"
+ elif val != "halfline":
+ skipval = "[skip={" + val + "}]"
+
+ add_to_preamble(document, ["\\usepackage" + skipval + "{parskip}"])
+
+ document.header[i] = "\\paragraph_separation indent"
+ document.header[j] = "\\paragraph_indentation default"
+
+
+def revert_line_vspaces(document):
+ " Revert fulline and halfline vspaces to TeX "
+ insets = {
+ "fullline*" : "\\vspace*{\\baselineskip}",
+ "fullline" : "\\vspace{\\baselineskip}",
+ "halfline*" : "\\vspace*{0.5\\baselineskip}",
+ "halfline" : "\\vspace{0.5\\baselineskip}",
+ }
+ for inset in insets.keys():
+ i = 0
+ j = 0
+ i = find_token(document.body, "\\begin_inset VSpace " + inset, i)
+ if i == -1:
+ continue
+ end = find_end_of_inset(document.body, i)
+ subst = put_cmd_in_ert(insets[inset])
+ document.body[i : end + 1] = subst
+
+def convert_libertinus_rm_fonts(document):
+ """Handle Libertinus serif fonts definition to LaTeX"""
+
+ if not get_bool_value(document.header, "\\use_non_tex_fonts"):
+ fm = createFontMapping(['Libertinus'])
+ convert_fonts(document, fm)
+
+def revert_libertinus_rm_fonts(document):
+ """Revert Libertinus serif font definition to LaTeX"""
+
+ if not get_bool_value(document.header, "\\use_non_tex_fonts"):
+ fontmap = dict()
+ fm = createFontMapping(['libertinus'])
+ if revert_fonts(document, fm, fontmap):
+ add_preamble_fonts(document, fontmap)
+
+def revert_libertinus_sftt_fonts(document):
+ " Revert Libertinus sans and tt font definitions to LaTeX "
+
+ if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1:
+ preamble = ""
+ # first sf font
+ i = find_token(document.header, "\\font_sans \"LibertinusSans-LF\"", 0)
+ if i != -1:
+ j = find_token(document.header, "\\font_sans_osf true", 0)
+ if j != -1:
+ add_to_preamble(document, ["\\renewcommand{\\sfdefault}{LibertinusSans-OsF}"])
+ document.header[j] = "\\font_sans_osf false"
+ else:
+ add_to_preamble(document, ["\\renewcommand{\\sfdefault}{LibertinusSans-LF}"])
+ document.header[i] = document.header[i].replace("LibertinusSans-LF", "default")
+ sf_scale = 100.0
+ sfval = find_token(document.header, "\\font_sf_scale", 0)
+ if sfval == -1:
+ document.warning("Malformed LyX document: Missing \\font_sf_scale.")
+ else:
+ sfscale = document.header[sfval].split()
+ val = sfscale[1]
+ sfscale[1] = "100"
+ document.header[sfval] = " ".join(sfscale)
+ try:
+ # float() can throw
+ sf_scale = float(val)
+ except:
+ document.warning("Invalid font_sf_scale value: " + val)
+ if sf_scale != "100.0":
+ add_to_preamble(document, ["\\renewcommand*{\\LibertinusSans@scale}{" + str(sf_scale / 100.0) + "}"])
+ # now tt font
+ i = find_token(document.header, "\\font_typewriter \"LibertinusMono-TLF\"", 0)
+ if i != -1:
+ add_to_preamble(document, ["\\renewcommand{\\ttdefault}{LibertinusMono-TLF}"])
+ document.header[i] = document.header[i].replace("LibertinusMono-TLF", "default")
+ tt_scale = 100.0
+ ttval = find_token(document.header, "\\font_tt_scale", 0)
+ if ttval == -1:
+ document.warning("Malformed LyX document: Missing \\font_tt_scale.")
+ else:
+ ttscale = document.header[ttval].split()
+ val = ttscale[1]
+ ttscale[1] = "100"
+ document.header[ttval] = " ".join(ttscale)
+ try:
+ # float() can throw
+ tt_scale = float(val)
+ except:
+ document.warning("Invalid font_tt_scale value: " + val)
+ if tt_scale != "100.0":
+ add_to_preamble(document, ["\\renewcommand*{\\LibertinusMono@scale}{" + str(tt_scale / 100.0) + "}"])
+
+
+def revert_docbook_table_output(document):
+ i = find_token(document.header, '\\docbook_table_output')
+ if i != -1:
+ del document.header[i]
+
+
##
# Conversion hub
#
[591, [convert_postpone_fragile]],
[592, []],
[593, [convert_counter_maintenance]],
- [594, []]
+ [594, []],
+ [595, []],
+ [596, [convert_parskip]],
+ [597, [convert_libertinus_rm_fonts]],
+ [598, []]
]
-revert = [[593, [revert_counter_inset]],
+revert = [[597, [revert_docbook_table_output]],
+ [596, [revert_libertinus_rm_fonts,revert_libertinus_sftt_fonts]],
+ [595, [revert_parskip,revert_line_vspaces]],
+ [594, [revert_ams_spaces]],
+ [593, [revert_counter_inset]],
[592, [revert_counter_maintenance]],
[591, [revert_colrow_tracking]],
[590, [revert_postpone_fragile]],