Dov Feldstern wrote:
Georg Baum wrote:
Am Montag, 11. Juni 2007 23:38 schrieb Dov Feldstern:
Attached is a patch, using Georg's suggestion (refactoring). This is
the first time I'm doing a format change, so please make sure that
I'm doing everything which should be done in this case...
Looks perfect.
Georg
There's a slight problem, though... I'm getting this message now: "LyX:
Unknown language `default'"
I should be setting the language to the paragraph's language, not to
"default". How do I get the paragraph's language in lyx2lyx?
Thanks!
Dov
Attached is a new version of this patch, which uses the paragraph's
language as the default language. It may not be perfect, but I think
it's good enough, and it seems to work...
Opinions?
Thanks!
Dov
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revision 18750)
+++ src/Buffer.cpp (working copy)
@@ -142,7 +142,7 @@
namespace {
-int const LYX_FORMAT = 271;
+int const LYX_FORMAT = 272;
} // namespace anon
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py (revision 18750)
+++ lib/lyx2lyx/LyX.py (working copy)
@@ -77,7 +77,7 @@
("1_2", [220], generate_minor_versions("1.2" , 4)),
("1_3", [221], generate_minor_versions("1.3" , 7)),
("1_4", range(222,246), generate_minor_versions("1.4" , 4)),
- ("1_5", range(246,272), generate_minor_versions("1.5" , 0))]
+ ("1_5", range(246,273), generate_minor_versions("1.5" , 0))]
def formats_list():
Index: lib/lyx2lyx/lyx_1_5.py
===================================================================
--- lib/lyx2lyx/lyx_1_5.py (revision 18750)
+++ lib/lyx2lyx/lyx_1_5.py (working copy)
@@ -22,7 +22,7 @@
import re
import unicodedata
-from parser_tools import find_re, find_token, find_token_backwards,
find_token_exact, find_tokens, find_end_of, get_value
+from parser_tools import find_re, find_token, find_token_backwards,
find_token_exact, find_tokens, find_end_of, get_value, find_beginning_of,
find_nonempty_line
from LyX import get_encoding
@@ -37,6 +37,10 @@
" Find end of layout, where lines[i] is included."
return find_end_of(lines, i, "\\begin_layout", "\\end_layout")
+def find_beginning_of_layout(lines, i):
+ "Find beginning of layout, where lines[i] is included."
+ return find_beginning_of(lines, i, "\\begin_layout", "\\end_layout")
+
# End of helper functions
####################################################################
@@ -1099,22 +1103,59 @@
document.body[i] = unicodedata.normalize("NFKC", document.body[i])
-def normalize_font_whitespace(document):
+def normalize_font_whitespace_259(document):
""" Before format 259 the font changes were ignored if a
whitespace was the first or last character in the sequence, this function
transfers the whitespace outside."""
+
+ char_properties = {"\\series": "default",
+ "\\emph": "default",
+ "\\color": "none",
+ "\\shape": "default",
+ "\\bar": "default",
+ "\\family": "default"}
+ return normalize_font_whitespace(document, char_properties)
+def normalize_font_whitespace_272(document):
+ """ Before format 259 (sic) the font changes were ignored if a
+ whitespace was the first or last character in the sequence. This was
+ corrected for most font properties in format 259, but the language
+ was forgotten then. This function applies the same conversion done
+ there (namely, transfers the whitespace outside) for font language
+ changes, as well."""
+
+ char_properties = {"\\lang": "default"}
+ return normalize_font_whitespace(document, char_properties)
+
+def get_paragraph_language(document, i):
+ """ Return the language of the paragraph in which line i of the document
+ body is. If the first thing in the paragraph is a \\lang command, that
+ is the paragraph's langauge; otherwise, the paragraph's language is the
+ document's language."""
+
+ lines = document.body
+
+ first_nonempty_line = \
+ find_nonempty_line(lines, find_beginning_of_layout(lines, i) + 1)
+
+ words = lines[first_nonempty_line].split()
+
+ if len(words) > 1 and words[0] == "\\lang":
+ return words[1]
+ else:
+ return document.language
+
+def normalize_font_whitespace(document, char_properties):
+ """ Before format 259 the font changes were ignored if a
+ whitespace was the first or last character in the sequence, this function
+ transfers the whitespace outside. Only a change in one of the properties
+ in the provided char_properties is handled by this function."""
+
if document.backend != "latex":
return
lines = document.body
- char_properties = {"\\series": "default",
- "\\emph": "default",
- "\\color": "none",
- "\\shape": "default",
- "\\bar": "default",
- "\\family": "default"}
changes = {}
i = 0
@@ -1124,6 +1165,10 @@
if len(words) > 0 and words[0] == "\\begin_layout":
# a new paragraph resets all font changes
changes.clear()
+ # also reset the default language to be the paragraph's language
+ if "\\lang" in char_properties.keys():
+ char_properties["\\lang"] = \
+ get_paragraph_language(document, i + 1)
elif len(words) > 1 and words[0] in char_properties.keys():
# we have a font change
@@ -1675,7 +1720,7 @@
[256, []],
[257, [convert_caption]],
[258, [convert_lyxline]],
- [259, [convert_accent, normalize_font_whitespace]],
+ [259, [convert_accent, normalize_font_whitespace_259]],
[260, []],
[261, [convert_changes]],
[262, []],
@@ -1687,10 +1732,12 @@
[268, []],
[269, []],
[270, []],
- [271, [convert_ext_font_sizes]]
+ [271, [convert_ext_font_sizes]],
+ [272, [normalize_font_whitespace_272]]
]
revert = [
+ [271, []],
[270, [revert_ext_font_sizes]],
[269, [revert_beamer_alert, revert_beamer_structure]],
[268, [revert_preamble_listings_params, revert_listings_inset,
revert_include_listings]],
Index: development/FORMAT
===================================================================
--- development/FORMAT (revision 18750)
+++ development/FORMAT (working copy)
@@ -1,5 +1,12 @@
LyX file-format changes
-----------------------
+
+2007-06-13 Dov Feldstern <[EMAIL PROTECTED]>
+ * format incremented to 272: applying the conversion done in format 259
+ to the \lang property, which was forgotten back then... This is
+ slightly more complicated, because the default language has to be
+ determined on a per-paragraph basis.
+
2007-05-15 José Matos <[EMAIL PROTECTED]>
* format incremented to 271: extended textclasses accept the
normal font sizes: 10, 11 and 12pt.