mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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.
This commit is contained in:
parent
1a87c5313d
commit
4534a20f1a
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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]
|
||||
)
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user