Hi, I have been looking into making lyx2lyx more robust and better integrated with lyx.
I have identified some issues in the code that I intend to fix later. On Friday, June 17, 2016 9:12:20 PM WEST Georg Baum wrote: > commit ff93b83953ea3276f9be8a4243a7e6f603f3fe38 > Author: Georg Baum <b...@lyx.org> > Date: Fri Jun 17 21:11:53 2016 +0200 > > implement lyx2lyx roundtrip for \use_microtype > > diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py > index 08ca2f0..f1596c0 100644 > --- a/lib/lyx2lyx/lyx_2_3.py > +++ b/lib/lyx2lyx/lyx_2_3.py > @@ -30,12 +30,14 @@ import sys, os > # find_token_backwards, is_in_inset, get_value, get_quoted_value, \ > # del_token, check_token, get_option_value > > +from parser_tools import find_token, get_value > + > #from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, > lyx2latex, \ # lyx2verbatim, length_in_bp, convert_info_insets > # insert_to_preamble, latex_length, revert_flex_inset, \ > # revert_font_attrs, hex2ratio, str2bool > > -from parser_tools import find_token > +from lyx2lyx_tools import add_to_preamble > > #################################################################### > # Private helper functions > @@ -48,12 +50,29 @@ from parser_tools import find_token > ### > ########################################################################### > #### > > +def convert_microtype(document): > + " Add microtype settings. " > + i = find_token(document.header, "\\font_tt_scale" , 0) > + if i == -1: > + document.warning("Malformed LyX document: Can't find > \\font_tt_scale.") + return; This seems to be too harsh, since we are issuing an warning we could take i = len(document.header) - 1 and proceed. > + j = find_token(document.preamble, "\\usepackage{microtype}", 0) > + if j == -1: > + document.header.insert(i + 1, "\\use_microtype 0") > + else: > + document.header.insert(i + 1, "\\use_microtype 1") > + del document.preamble[j] We should follow the lead of the lyx code and explicitly use false/true here, since the code in src/BufferParams.cpp reads: os << "\\use_microtype " << convert<string>(use_microtype) << '\n'; and in src/support/convert.cpp we have template<> string convert<string>(bool b) { return (b ? "true" : "false"); } > def revert_microtype(document): > " Remove microtype settings. " > i = find_token(document.header, "\\use_microtype", 0) > if i == -1: > return > + value = get_value(document.header, "\\use_microtype" , i).split()[0] > del document.header[i] > + if value == "1": > + add_to_preamble(document, ["\\usepackage{microtype}"]) For the same reason this code will not work since the value that comes from a lyx exported file will be "true", even if lyx itself accepts 1. It would be nice to have all the header parameters written in an uniform way, even the three-state flags. Adding this to the to do list. :-) Regards, -- José Abílio