]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_4.py
Whitespace cleanup
[lyx.git] / lib / lyx2lyx / lyx_2_4.py
index d32ff7903d10d59d2f530e90894bbfae10d25699..3fd876c826797d3c3f906e59117fba09c8104f59 100644 (file)
@@ -47,7 +47,7 @@ from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble, insert_to_preamble,
 # Private helper functions
 
 def add_preamble_fonts(document, fontmap):
-    " Add collected font-packages with their option to user-preamble"
+    """Add collected font-packages with their option to user-preamble"""
 
     for pkg in fontmap:
         if len(fontmap[pkg]) > 0:
@@ -85,7 +85,7 @@ class fontmapping:
         self.pkginmap = dict()  # defines, if a map for package exists
 
     def expandFontMapping(self, font_list, font_type, scale_type, pkg, scaleopt = None, osfopt = None, osfdef = "false"):
-        " Expand fontinfo mapping"
+        """Expand fontinfo mapping"""
         #
         # fontlist:    list of fontnames, each element
         #              may contain a ','-separated list of needed options
@@ -194,11 +194,13 @@ def createFontMapping(fontlist):
                                   '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"):
-    " Handle font definition (LaTeX preamble -> native) "
-
+    """Handle font definition (LaTeX preamble -> native)"""
     rpkg = re.compile(r'^\\usepackage(\[([^\]]*)\])?\{([^\}]+)\}')
     rscaleopt = re.compile(r'^scaled?=(.*)')
 
@@ -306,9 +308,8 @@ def convert_fonts(document, fm, osfoption = "osf"):
                     document.header.insert(fo, fotag + " \"" + ",".join(options) + "\"")
 
 
-
 def revert_fonts(document, fm, fontmap, OnlyWithXOpts = False, WithXOpts = False):
-    " Revert native font definition to LaTeX "
+    """Revert native font definition to LaTeX"""
     # fonlist := list of fonts created from the same package
     # Empty package means that the font-name is the same as the package-name
     # fontmap (key = package, val += found options) will be filled
@@ -390,7 +391,7 @@ def revert_fonts(document, fm, fontmap, OnlyWithXOpts = False, WithXOpts = False
 ###############################################################################
 
 def convert_inputencoding_namechange(document):
-    " Rename inputencoding settings. "
+    """Rename inputencoding settings."""
     i = find_token(document.header, "\\inputencoding", 0)
     if i == -1:
         return
@@ -398,7 +399,7 @@ def convert_inputencoding_namechange(document):
     document.header[i] = s.replace("default", "auto-legacy-plain")
 
 def revert_inputencoding_namechange(document):
-    " Rename inputencoding settings. "
+    """Rename inputencoding settings."""
     i = find_token(document.header, "\\inputencoding", 0)
     if i == -1:
         return
@@ -406,14 +407,14 @@ def revert_inputencoding_namechange(document):
     document.header[i] = s.replace("auto-legacy", "auto")
 
 def convert_notoFonts(document):
-    " Handle Noto fonts definition to LaTeX "
+    """Handle Noto fonts definition to LaTeX"""
 
     if not get_bool_value(document.header, "\\use_non_tex_fonts"):
         fm = createFontMapping(['Noto'])
         convert_fonts(document, fm)
 
 def revert_notoFonts(document):
-    " Revert native Noto font definition to LaTeX "
+    """Revert native Noto font definition to LaTeX"""
 
     if not get_bool_value(document.header, "\\use_non_tex_fonts"):
         fontmap = dict()
@@ -422,14 +423,14 @@ def revert_notoFonts(document):
             add_preamble_fonts(document, fontmap)
 
 def convert_latexFonts(document):
-    " Handle DejaVu and IBMPlex fonts definition to LaTeX "
+    """Handle DejaVu and IBMPlex fonts definition to LaTeX"""
 
     if not get_bool_value(document.header, "\\use_non_tex_fonts"):
         fm = createFontMapping(['DejaVu', 'IBM'])
         convert_fonts(document, fm)
 
 def revert_latexFonts(document):
-    " Revert native DejaVu font definition to LaTeX "
+    """Revert native DejaVu font definition to LaTeX"""
 
     if not get_bool_value(document.header, "\\use_non_tex_fonts"):
         fontmap = dict()
@@ -438,14 +439,14 @@ def revert_latexFonts(document):
             add_preamble_fonts(document, fontmap)
 
 def convert_AdobeFonts(document):
-    " Handle Adobe Source fonts definition to LaTeX "
+    """Handle Adobe Source fonts definition to LaTeX"""
 
     if not get_bool_value(document.header, "\\use_non_tex_fonts"):
         fm = createFontMapping(['Adobe'])
         convert_fonts(document, fm)
 
 def revert_AdobeFonts(document):
-    " Revert Adobe Source font definition to LaTeX "
+    """Revert Adobe Source font definition to LaTeX"""
 
     if not get_bool_value(document.header, "\\use_non_tex_fonts"):
         fontmap = dict()
@@ -454,7 +455,7 @@ def revert_AdobeFonts(document):
             add_preamble_fonts(document, fontmap)
 
 def removeFrontMatterStyles(document):
-    " Remove styles Begin/EndFrontmatter"
+    """Remove styles Begin/EndFrontmatter"""
 
     layouts = ['BeginFrontmatter', 'EndFrontmatter']
     tokenend = len('\\begin_layout ')
@@ -475,7 +476,7 @@ def removeFrontMatterStyles(document):
         document.body[i:j+1] = []
 
 def addFrontMatterStyles(document):
-    " Use styles Begin/EndFrontmatter for elsarticle"
+    """Use styles Begin/EndFrontmatter for elsarticle"""
 
     if document.textclass != "elsarticle":
         return
@@ -522,7 +523,7 @@ def addFrontMatterStyles(document):
 
 
 def convert_lst_literalparam(document):
-    " Add param literal to include inset "
+    """Add param literal to include inset"""
 
     i = 0
     while True:
@@ -539,7 +540,7 @@ def convert_lst_literalparam(document):
 
 
 def revert_lst_literalparam(document):
-    " Remove param literal from include inset "
+    """Remove param literal from include inset"""
 
     i = 0
     while True:
@@ -554,7 +555,7 @@ def revert_lst_literalparam(document):
 
 
 def revert_paratype(document):
-    " Revert ParaType font definitions to LaTeX "
+    """Revert ParaType font definitions to LaTeX"""
 
     if not get_bool_value(document.header, "\\use_non_tex_fonts"):
         preamble = ""
@@ -609,7 +610,7 @@ def revert_paratype(document):
 
 
 def revert_xcharter(document):
-    " Revert XCharter font definitions to LaTeX "
+    """Revert XCharter font definitions to LaTeX"""
 
     i = find_token(document.header, "\\font_roman \"xcharter\"", 0)
     if i == -1:
@@ -633,7 +634,7 @@ def revert_xcharter(document):
 
 
 def revert_lscape(document):
-    " Reverts the landscape environment (Landscape module) to TeX-code "
+    """Reverts the landscape environment (Landscape module) to TeX-code"""
 
     if not "landscape" in document.get_module_list():
         return
@@ -661,7 +662,7 @@ def revert_lscape(document):
 
 
 def convert_fontenc(document):
-    " Convert default fontenc setting "
+    """Convert default fontenc setting"""
 
     i = find_token(document.header, "\\fontencoding global", 0)
     if i == -1:
@@ -671,7 +672,7 @@ def convert_fontenc(document):
 
 
 def revert_fontenc(document):
-    " Revert default fontenc setting "
+    """Revert default fontenc setting"""
 
     i = find_token(document.header, "\\fontencoding auto", 0)
     if i == -1:
@@ -681,7 +682,7 @@ def revert_fontenc(document):
 
 
 def revert_nospellcheck(document):
-    " Remove nospellcheck font info param "
+    """Remove nospellcheck font info param"""
 
     i = 0
     while True:
@@ -692,19 +693,19 @@ def revert_nospellcheck(document):
 
 
 def revert_floatpclass(document):
-    " Remove float placement params 'document' and 'class' "
+    """Remove float placement params 'document' and 'class'"""
 
     del_token(document.header, "\\float_placement class")
 
     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
@@ -712,20 +713,20 @@ def revert_floatpclass(document):
 
 
 def revert_floatalignment(document):
-    " Remove float alignment params "
+    """Remove float alignment params"""
 
     galignment = get_value(document.header, "\\float_alignment", delete=True)
 
     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
@@ -746,10 +747,12 @@ def revert_floatalignment(document):
             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 "
+    """Revert \cite commands in tufte classes"""
 
     tufte = ["tufte-book", "tufte-handout"]
     if document.textclass not in tufte:
@@ -794,7 +797,7 @@ def revert_tuftecite(document):
 
 
 def revert_stretchcolumn(document):
-    " We remove the column varwidth flags or everything else will become a mess. "
+    """We remove the column varwidth flags or everything else will become a mess."""
     i = 0
     while True:
         i = find_token(document.body, "\\begin_inset Tabular", i+1)
@@ -811,7 +814,7 @@ def revert_stretchcolumn(document):
 
 
 def revert_vcolumns(document):
-    " Revert standard columns with line breaks etc. "
+    """Revert standard columns with line breaks etc."""
     i = 0
     needvarwidth = False
     needarray = False
@@ -904,7 +907,7 @@ def revert_vcolumns(document):
 
 
 def revert_bibencoding(document):
-    " Revert bibliography encoding "
+    """Revert bibliography encoding"""
 
     # Get cite engine
     engine = "basic"
@@ -1003,7 +1006,7 @@ def revert_bibencoding(document):
 
 
 def convert_vcsinfo(document):
-    " Separate vcs Info inset from buffer Info inset. "
+    """Separate vcs Info inset from buffer Info inset."""
 
     types = {
         "vcs-revision" : "revision",
@@ -1034,7 +1037,7 @@ def convert_vcsinfo(document):
 
 
 def revert_vcsinfo(document):
-    " Merge vcs Info inset to buffer Info inset. "
+    """Merge vcs Info inset to buffer Info inset."""
 
     args = ["revision", "tree-revision", "author", "time", "date" ]
     i = 0
@@ -1080,7 +1083,7 @@ def revert_vcsinfo_rev_abbrev(document):
             document.body[arg] = "arg \"revision\""
 
 def revert_dateinfo(document):
-    " Revert date info insets to static text. "
+    """Revert date info insets to static text."""
 
 # FIXME This currently only considers the main language and uses the system locale
 # Ideally, it should honor context languages and switch the locale accordingly.
@@ -1255,7 +1258,7 @@ def revert_dateinfo(document):
 
 
 def revert_timeinfo(document):
-    " Revert time info insets to static text. "
+    """Revert time info insets to static text."""
 
 # FIXME This currently only considers the main language and uses the system locale
 # Ideally, it should honor context languages and switch the locale accordingly.
@@ -1370,7 +1373,6 @@ def revert_timeinfo(document):
     }
 
     types = ["time", "fixtime", "modtime" ]
-    i = 0
     i = find_token(document.header, "\\language", 0)
     if i == -1:
         # this should not happen
@@ -1430,7 +1432,7 @@ def revert_timeinfo(document):
 
 
 def revert_namenoextinfo(document):
-    " Merge buffer Info inset type name-noext to name. "
+    """Merge buffer Info inset type name-noext to name."""
 
     i = 0
     while True:
@@ -1453,7 +1455,7 @@ def revert_namenoextinfo(document):
 
 
 def revert_l7ninfo(document):
-    " Revert l7n Info inset to text. "
+    """Revert l7n Info inset to text."""
 
     i = 0
     while True:
@@ -1476,7 +1478,7 @@ def revert_l7ninfo(document):
 
 
 def revert_listpargs(document):
-    " Reverts listpreamble arguments to TeX-code "
+    """Reverts listpreamble arguments to TeX-code"""
     i = 0
     while True:
         i = find_token(document.body, "\\begin_inset Argument listpreamble:", i+1)
@@ -1499,7 +1501,7 @@ def revert_listpargs(document):
 
 
 def revert_lformatinfo(document):
-    " Revert layout format Info inset to text. "
+    """Revert layout format Info inset to text."""
 
     i = 0
     while True:
@@ -1543,19 +1545,19 @@ def convert_hebrew_parentheses(document):
 
 
 def revert_hebrew_parentheses(document):
-    " Store parentheses in Hebrew text reversed"
+    """Store parentheses in Hebrew text reversed"""
     # 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 "
+    """Set the document language to English but assure Malayalam output"""
 
     revert_language(document, "malayalam", "", "malayalam")
 
 
 def revert_soul(document):
-    " Revert soul module flex insets to ERT "
+    """Revert soul module flex insets to ERT"""
 
     flexes = ["Spaceletters", "Strikethrough", "Underline", "Highlight", "Capitalize"]
 
@@ -1576,16 +1578,15 @@ def revert_soul(document):
 
 
 def revert_tablestyle(document):
-    " Remove tablestyle params "
+    """Remove tablestyle params"""
 
-    i = 0
     i = find_token(document.header, "\\tablestyle")
     if i != -1:
         del document.header[i]
 
 
 def revert_bibfileencodings(document):
-    " Revert individual Biblatex bibliography encodings "
+    """Revert individual Biblatex bibliography encodings"""
 
     # Get cite engine
     engine = "basic"
@@ -1693,7 +1694,7 @@ def revert_bibfileencodings(document):
 
 
 def revert_cmidruletrimming(document):
-    " Remove \\cmidrule trimming "
+    """Remove \\cmidrule trimming"""
 
     # FIXME: Revert to TeX code?
     i = 0
@@ -1749,19 +1750,21 @@ ruby_inset_def = [
     r'End',
 ]
 
+
 def convert_ruby_module(document):
-    " Use ruby module instead of local module definition "
+    """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 "
+    """Replace ruby module with local module definition"""
     if document.del_module("ruby"):
         document.append_local_layout(ruby_inset_def)
 
 
 def convert_utf8_japanese(document):
-    " Use generic utf8 with Japanese documents."
+    """Use generic utf8 with Japanese documents."""
     lang = get_value(document.header, "\\language")
     if not lang.startswith("japanese"):
         return
@@ -1770,8 +1773,9 @@ def convert_utf8_japanese(document):
         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."
+    """Use Japanese utf8 variants with Japanese documents."""
     inputenc = get_value(document.header, "\\inputencoding")
     if inputenc != "utf8":
         return
@@ -3471,6 +3475,15 @@ def revert_memoir_endnotes(document):
 def revert_totalheight(document):
     " Reverts graphics height parameter from totalheight to height "
 
+    relative_heights = {
+        "\\textwidth" : "text%",
+        "\\columnwidth" : "col%",
+        "\\paperwidth" : "page%",
+        "\\linewidth" : "line%",
+        "\\textheight" : "theight%",
+        "\\paperheight" : "pheight%",
+        "\\baselineskip " : "baselineskip%"
+    }
     i = 0
     while (True):
         i = find_token(document.body, "\\begin_inset Graphics", i)
@@ -3483,6 +3496,7 @@ def revert_totalheight(document):
             continue
 
         rx = re.compile(r'\s*special\s*(\S+)$')
+        rxx = re.compile(r'(\d*\.*\d+)(\S+)$')
         k = find_re(document.body, rx, i, j)
         special = ""
         oldheight = ""
@@ -3494,6 +3508,16 @@ def revert_totalheight(document):
             for spc in mspecial:
                 if spc[:7] == "height=":
                     oldheight = spc.split('=')[1]
+                    ms = rxx.search(oldheight)
+                    if ms:
+                        oldval = ms.group(1)
+                        oldunit = ms.group(2)
+                        if oldval[1] == ".":
+                            oldval = "0" + oldval
+                        if oldunit in list(relative_heights.keys()):
+                            oldval = str(float(oldval) * 100)
+                            oldunit = relative_heights[oldunit]
+                            oldheight = oldval + oldunit
                     mspecial.remove(spc)
                     break
             if len(mspecial) > 0:
@@ -3530,6 +3554,15 @@ def revert_totalheight(document):
 def convert_totalheight(document):
     " Converts graphics height parameter from totalheight to height "
 
+    relative_heights = {
+        "text%" : "\\textwidth",
+        "col%"  : "\\columnwidth",
+        "page%" : "\\paperwidth",
+        "line%" : "\\linewidth",
+        "theight%" : "\\textheight",
+        "pheight%" : "\\paperheight",
+        "baselineskip%" : "\\baselineskip"
+    }
     i = 0
     while (True):
         i = find_token(document.body, "\\begin_inset Graphics", i)
@@ -3560,19 +3593,23 @@ def convert_totalheight(document):
             else:
                 special = ""
 
-        rx = re.compile(r'(\s*height\s*)(\S+)$')
+        rx = re.compile(r'(\s*height\s*)(\d+)(\S+)$')
         kk = find_re(document.body, rx, i, j)
         if kk != -1:
             m = rx.match(document.body[kk])
             val = ""
             if m:
                 val = m.group(2)
+                unit = m.group(3)
+                if unit in list(relative_heights.keys()):
+                    val = str(float(val) / 100)
+                    unit = relative_heights[unit]
                 if k != -1:
                     if special != "":
-                        val = val + "," + special
+                        val = val + unit + "," + special
                     document.body[k] = "\tspecial " + "height=" + val
                 else:
-                    document.body.insert(kk + 1, "\tspecial height=" + val)
+                    document.body.insert(kk + 1, "\tspecial height=" + val + unit)
                 if newheight != "":
                     document.body[kk] = m.group(1) + newheight
                 else:
@@ -3740,7 +3777,7 @@ def revert_counter_inset(document):
             ert = put_cmd_in_ert("\\setcounter{%s}{\\value{%s}}" % (cnt, savecnt))
         else:
             document.warning("Unknown counter command `%s' in inset at line %d!" % (cnt, i))
-            
+
         if ert:
             document.body[i : j + 1] = ert
         i += 1
@@ -3752,7 +3789,178 @@ def revert_counter_inset(document):
     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
 #
@@ -3775,11 +3983,11 @@ convert = [
            [558, [removeFrontMatterStyles]],
            [559, []],
            [560, []],
-           [561, [convert_latexFonts]], # Handle dejavu, ibmplex fonts in GUI
+           [561, [convert_latexFonts]],  # Handle dejavu, ibmplex fonts in GUI
            [562, []],
            [563, []],
            [564, []],
-           [565, [convert_AdobeFonts]], # Handle adobe fonts in GUI
+           [565, [convert_AdobeFonts]],  # Handle adobe fonts in GUI
            [566, [convert_hebrew_parentheses]],
            [567, []],
            [568, []],
@@ -3808,10 +4016,18 @@ convert = [
            [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]],
@@ -3844,7 +4060,7 @@ revert =  [[593, [revert_counter_inset]],
            [563, [revert_lformatinfo]],
            [562, [revert_listpargs]],
            [561, [revert_l7ninfo]],
-           [560, [revert_latexFonts]], # Handle dejavu, ibmplex fonts in user preamble
+           [560, [revert_latexFonts]],  # Handle dejavu, ibmplex fonts in user preamble
            [559, [revert_timeinfo, revert_namenoextinfo]],
            [558, [revert_dateinfo]],
            [557, [addFrontMatterStyles]],
@@ -3856,7 +4072,7 @@ revert =  [[593, [revert_counter_inset]],
            [551, [revert_floatpclass, revert_floatalignment]],
            [550, [revert_nospellcheck]],
            [549, [revert_fontenc]],
-           [548, []],# dummy format change
+           [548, []],  # dummy format change
            [547, [revert_lscape]],
            [546, [revert_xcharter]],
            [545, [revert_paratype]],