1 # -*- coding: utf-8 -*-
2 # This file is part of lyx2lyx
3 # -*- coding: utf-8 -*-
4 # Copyright (C) 2016 The LyX team
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 """ Convert files to the file format generated by lyx 2.3"""
26 # Uncomment only what you need to import, please.
28 #from parser_tools import find_token, find_end_of, find_tokens, \
29 # find_token_exact, find_end_of_inset, find_end_of_layout, \
30 # find_token_backwards, is_in_inset, get_value, get_quoted_value, \
31 # del_token, check_token, get_option_value
33 from parser_tools import find_token, get_value
35 #from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, lyx2latex, \
36 # lyx2verbatim, length_in_bp, convert_info_insets
37 # insert_to_preamble, latex_length, revert_flex_inset, \
38 # revert_font_attrs, hex2ratio, str2bool
40 from lyx2lyx_tools import add_to_preamble
42 ####################################################################
43 # Private helper functions
47 ###############################################################################
49 ### Conversion and reversion routines
51 ###############################################################################
53 def convert_microtype(document):
54 " Add microtype settings. "
55 i = find_token(document.header, "\\font_tt_scale" , 0)
57 document.warning("Malformed LyX document: Can't find \\font_tt_scale.")
59 j = find_token(document.preamble, "\\usepackage{microtype}", 0)
61 document.header.insert(i + 1, "\\use_microtype 0")
63 document.header.insert(i + 1, "\\use_microtype 1")
64 del document.preamble[j]
67 def revert_microtype(document):
68 " Remove microtype settings. "
69 i = find_token(document.header, "\\use_microtype", 0)
72 value = get_value(document.header, "\\use_microtype" , i).split()[0]
73 del document.header[i]
75 add_to_preamble(document, ["\\usepackage{microtype}"])
83 supported_versions = ["2.3.0", "2.3"]
85 [509, [convert_microtype]]
89 [508, [revert_microtype]]
93 if __name__ == "__main__":