From 4534a20f1a247c85236da8b3271534765e4b4025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Matos?= Date: Mon, 17 Jun 2024 11:31:10 +0100 Subject: [PATCH] Fix functions that used functions but did not defined it The functions were selected from the parser files where document is always defined. The only case was this code was used was on document.warning. Since our documents are well formed this code was never active and thus the reason why we did not saw this before. One possible solution to assure that these type of errors do not occur is to make the convention that all the functions in lyx2lyx_tools have as the first argument document. --- lib/lyx2lyx/lyx2lyx_tools.py | 9 +++++---- lib/lyx2lyx/lyx_2_0.py | 4 ++-- lib/lyx2lyx/lyx_2_2.py | 2 +- lib/lyx2lyx/lyx_2_4.py | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/lyx2lyx/lyx2lyx_tools.py b/lib/lyx2lyx/lyx2lyx_tools.py index 2e77a1947c..706c808fc6 100644 --- a/lib/lyx2lyx/lyx2lyx_tools.py +++ b/lib/lyx2lyx/lyx2lyx_tools.py @@ -107,7 +107,7 @@ from unicode_symbols import unicode_reps def add_to_preamble(document, text): "Add text to the preamble if it is not already there." - if type(text) is not list: + if not isinstance(text, list): # split on \n just in case # it'll give us the one element list we want # if there's no \n, too @@ -138,7 +138,7 @@ def add_to_preamble(document, text): def insert_to_preamble(document, text, index=0): """Insert text to the preamble at a given line""" - if type(text) is not list: + if not isinstance(text, list): # split on \n just in case # it'll give us the one element list we want # if there's no \n, too @@ -425,7 +425,7 @@ def latex_length(slen): return (percent, slen) -def length_in_bp(length): +def length_in_bp(document, length): "Convert a length in LyX format to its value in bp units" em_width = 10.0 / 72.27 # assume 10pt font size @@ -465,8 +465,9 @@ def length_in_bp(length): return "%g" % (float(value) * scales[unit]) -def revert_flex_inset(lines, name, LaTeXname): +def revert_flex_inset(document, name, LaTeXname): "Convert flex insets to TeX code" + lines = document.body i = 0 while True: i = find_token(lines, "\\begin_inset Flex " + name, i) diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 56b26fa5a4..5dfc348176 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1685,8 +1685,8 @@ def revert_IEEEtran(document): if document.textclass != "IEEEtran": return - revert_flex_inset(document.body, "IEEE membership", "\\IEEEmembership") - revert_flex_inset(document.body, "Lowercase", "\\MakeLowercase") + revert_flex_inset(document, "IEEE membership", "\\IEEEmembership") + revert_flex_inset(document, "Lowercase", "\\MakeLowercase") layouts = ( "Special Paper Notice", diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py index 3b429e516c..30aafb7789 100644 --- a/lib/lyx2lyx/lyx_2_2.py +++ b/lib/lyx2lyx/lyx_2_2.py @@ -1881,7 +1881,7 @@ def convert_revert_external_bbox(document, forward): tokens[t] += "bp" else: for t in range(1, 5): - tokens[t] = length_in_bp(tokens[t]) + tokens[t] = length_in_bp(document, tokens[t]) document.body[k] = ( "\tboundingBox " + tokens[1] + " " + tokens[2] + " " + tokens[3] + " " + tokens[4] ) diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index 7704072ded..e846c01c37 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -2232,11 +2232,11 @@ def revert_soul(document): if i != -1: add_to_preamble(document, ["\\usepackage{color}"]) - revert_flex_inset(document.body, "Spaceletters", "\\so") - revert_flex_inset(document.body, "Strikethrough", "\\st") - revert_flex_inset(document.body, "Underline", "\\ul") - revert_flex_inset(document.body, "Highlight", "\\hl") - revert_flex_inset(document.body, "Capitalize", "\\caps") + revert_flex_inset(document, "Spaceletters", "\\so") + revert_flex_inset(document, "Strikethrough", "\\st") + revert_flex_inset(document, "Underline", "\\ul") + revert_flex_inset(document, "Highlight", "\\hl") + revert_flex_inset(document, "Capitalize", "\\caps") def revert_tablestyle(document): @@ -4287,7 +4287,7 @@ def revert_enotez(document): if find_token(document.body, "\\begin_inset Flex Endnote", 0) != -1: use = True - revert_flex_inset(document.body, "Endnote", "\\endnote") + revert_flex_inset(document, "Endnote", "\\endnote") i = 0 while True: @@ -4324,7 +4324,7 @@ def revert_memoir_endnotes(document): ): encommand = "\\endnote" - revert_flex_inset(document.body, "Endnote", encommand) + revert_flex_inset(document, "Endnote", encommand) i = 0 while True: @@ -6634,10 +6634,10 @@ def revert_cov_options(document): def revert_expreambles(document): """Revert covington example preamble flex insets to ERT""" - revert_flex_inset(document.body, "Example Preamble", "\\expreamble") - revert_flex_inset(document.body, "Subexample Preamble", "\\subexpreamble") - revert_flex_inset(document.body, "Example Postamble", "\\expostamble") - revert_flex_inset(document.body, "Subexample Postamble", "\\subexpostamble") + revert_flex_inset(document, "Example Preamble", "\\expreamble") + revert_flex_inset(document, "Subexample Preamble", "\\subexpreamble") + revert_flex_inset(document, "Example Postamble", "\\expostamble") + revert_flex_inset(document, "Subexample Postamble", "\\subexpostamble") def revert_hequotes(document):