1 # file prefs2prefs-prefs.py
2 # This file is part of LyX, the document processor.
3 # Licence details can be found in the file COPYING.
5 # author Richard Kimberly Heck
7 # Full author contact details are available in file CREDITS
9 # This file houses conversion information for the preferences file.
11 # There are two kinds of converter functions.
13 # Most of them take a line as argument and return a list:
15 # where the Bool says if we've modified anything and the NewLine is
16 # the new line, if so, which will be used to replace the old line.
17 # This can be used to erase lines (return (True, "")) or to modify
18 # existing preference lines.
20 # It is also possible for conversion routines to accept the whole
21 # list of lines and process that. This is useful (as in the change
22 # to format 35) when you need to add a preference if it's not already
26 ######################################################################
30 ######################################################################
32 # Incremented to format 2, r39670 by jrioux
33 # Support for multiple file extensions per format.
34 # No conversion necessary.
36 # Incremented to format 3, r39705 by tommaso
37 # Support for file formats that are natively (g)zipped.
38 # We must add the flag zipped=native to formats that
39 # were previously hardcoded in the C++ source: dia.
41 # Incremented to format 4, r40028 by vfr
42 # Remove support for default paper size.
44 # Incremented to format 5, r40030 by vfr
45 # Add a default length unit.
46 # No conversion necessary.
48 # Incremented to format 6, r40515 by younes
49 # Add use_qimage option.
50 # No conversion necessary.
52 # Incremented to format 7, r40789 by gb
53 # Add mime type to file format
55 # Incremented to format 8, 288c1e0f by rgh
56 # Add "nice" flag for converters
57 # No conversion necessary.
59 # Incremented to format 9, a18af620 by spitz
60 # Remove default_language rc.
62 # Incremented to format 10, 4985015 by tommaso
63 # Add close_buffer_with_last_view in preferences.
64 # No conversion necessary.
66 # Incremented to format 11, by gb
67 # Split pdf format into pdf and pdf6
69 # Incremented to format 12, by vfr
70 # Add option to use the system's theme icons
71 # No conversion necessary.
73 # Incremented to format 13, by bh
74 # Rename mac_like_word_movement to mac_like_cursor_movement
76 # Incremented to format 14, by spitz
77 # New RC default_otf_view_format
78 # No conversion necessary.
80 # Incremented to format 15, by prannoy
81 # Add fullscreen_statusbar
82 # No conversion necessary.
84 # Incremented to format 16, by lasgouttes
85 # Remove force_paint_single_char rc.
87 # Incremented to format 17, by lasgouttes
88 # Remove rtl_support rc.
90 # Incremented to format 18, by ef
91 # Add option to allow saving the document directory
92 # No conversion necessary.
94 # Incremented to format 19, by rgh
95 # remove print support
97 # Incremented to format 20, by tommaso
98 # Add options to forbid/ignore 'needauth' option
99 # No conversion necessary.
101 # Incremented to format 21, by spitz
102 # Add jbibtex_alternatives, allow "automatic" value
103 # of bibtex_command and jbibtex_command (actually the
105 # No conversion necessary.
107 # Incremented to format 22, by ef
108 # Add pygmentize_command for the python pygments syntax highlighter
109 # No conversion necessary.
111 # Incremented to format 23, by spitz
112 # Add default_platex_view_format, a default output format for
113 # Japanese documents via pLaTeX.
114 # No conversion necessary.
116 # Incremented to format 24, by spitz
117 # Rename collapsable to collapsible
119 # Incremented to format 25, by lasgouttes
120 # Remove use_qimage preference
122 # Incremented to format 26, by spitz
123 # Rename font_encoding preference
125 # Incremented to format 27, by spitz
126 # Add optional flavor value to needaux flag
128 # Incremented to format 28, by spitz
129 # Remove date_insert_format
131 # Incremented to format 29, by lasgouttes
132 # Remove use_pixmap_cache
134 # Incremented to format 30, by lasgouttes
135 # Add respect_os_kbd_language.
136 # No convergence necessary.
138 # Incremented to format 31, by spitz
139 # Add ct_additions_underlined.
140 # No convergence necessary.
142 # Incremented to format 32, by spitz
143 # Add ct_markup_copied.
144 # No convergence necessary.
146 # Incremented to format 33, by sanda
147 # Add \citation_search, \citation_search_pattern
148 # and \citation_search_view.
149 # No conversion necessary.
151 # Incremented to format 34, by yuriy
152 # Rename *.kmap files for Cyrillic languages
154 # Incremented to format 35, by spitz
155 # \set_color now takes three arguments
156 # \set_color lyxname x11hexname x11darkhexname
158 # Incremented to format 36, by rkh
159 # Set spellcheck_continuously to FALSE if it is not otherwise set
160 # (the new default is true, so this keeps behavior the same for
163 # Incremented to format 37, by chillenb
164 # Remove \fullscreen_width
165 # Remove \fullscreen_limit
169 # Incremented to format 38, by ec
170 # Add option to configure ui style
171 # No conversion necessary.
173 # NOTE: The format should also be updated in LYXRC.cpp and
174 # in configure.py (search for lyxrc_fileformat).
178 ###########################################################
182 def get_format(line):
189 while i < len(line) and line[i] != '"':
190 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
195 entries.append(line[beg:end].replace('\\"', '"'))
198 elif not line[i].isspace():
200 while i < len(line) and not line[i].isspace():
203 entries.append(line[beg:end])
208 def simple_renaming(line, old, new):
209 i = line.lower().find(old.lower())
212 line = line[:i] + new + line[i+len(old):]
215 no_match = (False, [])
217 ######################################
218 ### Format 1 conversions (for LyX 2.0)
220 def remove_obsolete(line):
221 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
222 "\\plaintext_roff_command", "\\use_alt_language",
223 "\\use_escape_chars", "\\use_input_encoding",
224 "\\use_personal_dictionary", "\\use_pspell",
226 line = line.lower().lstrip()
228 if line.lower().startswith(tag):
233 def language_use_babel(line):
234 if not line.lower().startswith(r"\language_use_babel"):
236 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
237 m = re_lub.match(line)
242 newline = "\\language_package_selection " + newval
243 return (True, newline)
246 def language_package(line):
247 return simple_renaming(line, "\\language_package", "\\language_custom_package")
250 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
251 def latex_flavor(line):
252 if not line.lower().startswith("\\converter"):
261 "luatex": "lualatex",
265 if conv in conv2fl.keys():
266 flavor = conv2fl[conv]
269 if flavor == "latex":
272 f"\\converter \"{conv}\" \"{fmat}\" \"{args}\" \"latex={flavor}\"")
275 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
276 def export_menu(line):
277 if not line.lower().startswith("\\format"):
285 f"\\Format {fmat} \"{opts},menu=export\"")
287 # End format 1 conversions (for LyX 2.0)
288 ########################################
290 #################################
291 # Conversions from LyX 2.0 to 2.1
292 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
293 def zipped_native(line):
294 if not line.lower().startswith("\\format"):
296 m = zipre.match(line)
302 f"\\Format {fmat} \"{opts},zipped=native\"")
304 def remove_default_papersize(line):
305 if not line.lower().startswith("\\default_papersize"):
309 def add_mime_types(line):
310 if not line.lower().startswith("\\format"):
312 entries = get_format(line)
316 converted = converted + ' ""'
318 formats = {'tgif':'application/x-tgif', \
319 'fig':'application/x-xfig', \
320 'dia':'application/x-dia-diagram', \
321 'odg':'application/vnd.oasis.opendocument.graphics', \
322 'svg':'image/svg+xml', \
323 'bmp':'image/x-bmp', \
325 'jpg':'image/jpeg', \
326 'pbm':'image/x-portable-bitmap', \
327 'pgm':'image/x-portable-graymap', \
328 'png':'image/x-png', \
329 'ppm':'image/x-portable-pixmap', \
330 'tiff':'image/tiff', \
331 'xbm':'image/x-xbitmap', \
332 'xpm':'image/x-xpixmap', \
333 'docbook-xml':'application/docbook+xml', \
334 'dot':'text/vnd.graphviz', \
335 'ly':'text/x-lilypond', \
336 'latex':'text/x-tex', \
337 'text':'text/plain', \
338 'gnumeric':'application/x-gnumeric', \
339 'excel':'application/vnd.ms-excel', \
340 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
341 'xhtml':'application/xhtml+xml', \
342 'bib':'text/x-bibtex', \
343 'eps':'image/x-eps', \
344 'ps':'application/postscript', \
345 'pdf':'application/pdf', \
346 'dvi':'application/x-dvi', \
347 'html':'text/html', \
348 'odt':'application/vnd.oasis.opendocument.text', \
349 'sxw':'application/vnd.sun.xml.writer', \
350 'rtf':'application/rtf', \
351 'doc':'application/msword', \
353 'lyx':'application/x-lyx', \
354 'wmf':'image/x-wmf', \
356 if entries[1] in formats.keys():
357 converted = converted + ' "' + formats[entries[1]] + '"'
359 converted = converted + ' ""'
360 return (True, converted)
362 re_converter = re.compile(r'^\\converter\s+', re.IGNORECASE)
364 def split_pdf_format(line):
365 # strictly speaking, a new format would not require to bump the
366 # version number, but the old pdf format was hardcoded at several
367 # places in the C++ code, so an update seemed like a good idea.
368 if line.lower().startswith("\\format"):
369 entries = get_format(line)
370 if entries[1] == 'pdf':
375 converted = line.replace('application/pdf', '') + r'''
376 \Format pdf6 pdf "PDF (graphics)" "" "''' + viewer + '" "" "vector" "application/pdf"'
377 return (True, converted)
378 elif line.lower().startswith("\\viewer_alternatives") or \
379 line.lower().startswith("\\editor_alternatives"):
380 entries = get_format(line)
381 if entries[1] == 'pdf':
382 converted = line + "\n" + entries[0] + ' pdf6 "' + entries[2] + '"'
383 return (True, converted)
384 elif re_converter.match(line):
385 entries = get_format(line)
386 # The only converter from pdf that is touched is pdf->eps:
387 # All other converters are likely meant for further processing on export.
388 # The only converter to pdf that stays untouched is dvi->pdf:
389 # All other converters are likely meant for graphics.
390 if len(entries) > 2 and \
391 ((entries[1] == 'pdf' and entries[2] == 'eps') or \
392 (entries[1] != 'ps' and entries[2] == 'pdf')):
393 if entries[1] == 'pdf':
394 converted = entries[0] + ' pdf6 ' + entries[2]
396 converted = entries[0] + ' ' + entries[1] + ' pdf6'
398 while i < len(entries):
399 converted = converted + ' "' + entries[i] + '"'
401 return (True, converted)
404 def remove_default_language(line):
405 if not line.lower().startswith("\\default_language"):
409 def mac_cursor_movement(line):
410 return simple_renaming(line, "\\mac_like_word_movement", "\\mac_like_cursor_movement")
412 # End conversions for LyX 2.0 to 2.1
413 ####################################
416 #################################
417 # Conversions from LyX 2.1 to 2.2
419 def remove_force_paint_single_char(line):
420 if not line.lower().startswith("\\force_paint_single_char"):
424 def remove_rtl(line):
425 if not line.lower().startswith("\\rtl "):
429 def remove_print_support(line):
430 tags = ("\\printer", "\\print_adapt_output", "\\print_command",
431 "\\print_evenpage_flag", "\\print_oddpage_flag", "\\print_pagerange_flag",
432 "\\print_copies_flag", "\\print_collcopies_flag", "\\print_reverse_flag",
433 "\\print_to_printer", "\\print_to_file", "\\print_file_extension")
434 line = line.lower().lstrip()
436 if line.lower().startswith(tag):
440 # End conversions for LyX 2.1 to 2.2
441 ####################################
444 #################################
445 # Conversions from LyX 2.2 to 2.3
447 def rename_collapsible(line):
448 return simple_renaming(line, "\\set_color \"collapsable", "\\set_color \"collapsible")
450 # End conversions for LyX 2.2 to 2.3
451 ####################################
454 #################################
455 # Conversions from LyX 2.3 to 2.4
457 def remove_use_qimage(line):
458 if not line.lower().startswith("\\use_qimage "):
462 def remove_font_encoding(line):
463 if not line.lower().startswith("\\font_encoding "):
467 def remove_date_insert_format(line):
468 if not line.lower().startswith("\\date_insert_format "):
472 def remove_use_pixmap_cache(line):
473 if not line.lower().startswith("\\use_pixmap_cache "):
477 def rename_cyrillic_kmap_files(line):
479 if not (line.startswith("\\kbmap_primary ")
480 or line.startswith("\\kbmap_secondary ")):
482 line = line.replace('"bg-bds-1251"', '"bulgarian"')
483 line = line.replace('"koi8-r"', '"russian"')
484 line = line.replace('"koi8-u"', '"ukrainian"')
487 def add_dark_color(line):
488 if not line.lower().startswith("\\set_color "):
490 colre = re.compile(r'^\\set_color\s+("[^"]+")\s+("[^"]+")\s*$', re.IGNORECASE)
491 m = colre.match(line)
494 line += " " + m.group(2)
497 def add_spellcheck_default(lines):
499 if l.startswith("\\spellcheck_continuously"):
501 lines.append("\\spellcheck_continuously false")
503 def remove_fullscreen_widthlimit(line):
505 if lower.startswith("\\fullscreen_width") or lower.startswith("\\fullscreen_limit"):
509 # End conversions for LyX 2.3 to 2.4
510 ####################################
514 ############################################################
515 # Format-conversion map. Also add empty format changes here.
518 [ 1, [ # there were several conversions for format 1
526 [ 3, [ zipped_native ]],
527 [ 4, [ remove_default_papersize ]],
530 [ 7, [add_mime_types]],
532 [ 9, [ remove_default_language ]],
534 [ 11, [split_pdf_format]],
536 [ 13, [mac_cursor_movement]],
539 [ 16, [remove_force_paint_single_char]],
542 [ 19, [remove_print_support]],
547 [ 24, [rename_collapsible]],
548 [ 25, [remove_use_qimage]],
549 [ 26, [remove_font_encoding]],
551 [ 28, [remove_date_insert_format]],
552 [ 29, [remove_use_pixmap_cache]],
557 [ 34, [rename_cyrillic_kmap_files]],
558 [ 35, [add_dark_color]],
559 [ 36, [add_spellcheck_default]],
560 [ 37, [remove_fullscreen_widthlimit]],