1 # -*- coding: utf-8 -*-
3 # file prefs2prefs-prefs.py
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
7 # author Richard Kimberly Heck
9 # Full author contact details are available in file CREDITS
11 # This file houses conversion information for the preferences file.
13 # There are two kinds of converter functions.
15 # Most of them take a line as argument and return a list:
17 # where the Bool says if we've modified anything and the NewLine is
18 # the new line, if so, which will be used to replace the old line.
19 # This can be used to erase lines (return (True, "")) or to modify
20 # existing preference lines.
22 # It is also possible for conversion routines to accept the whole
23 # list of lines and process that. This is useful (as in the change
24 # to format 35) when you need to add a preference if it's not already
28 ######################################################################
32 ######################################################################
34 # Incremented to format 2, r39670 by jrioux
35 # Support for multiple file extensions per format.
36 # No conversion necessary.
38 # Incremented to format 3, r39705 by tommaso
39 # Support for file formats that are natively (g)zipped.
40 # We must add the flag zipped=native to formats that
41 # were previously hardcoded in the C++ source: dia.
43 # Incremented to format 4, r40028 by vfr
44 # Remove support for default paper size.
46 # Incremented to format 5, r40030 by vfr
47 # Add a default length unit.
48 # No conversion necessary.
50 # Incremented to format 6, r40515 by younes
51 # Add use_qimage option.
52 # No conversion necessary.
54 # Incremented to format 7, r40789 by gb
55 # Add mime type to file format
57 # Incremented to format 8, 288c1e0f by rgh
58 # Add "nice" flag for converters
59 # No conversion necessary.
61 # Incremented to format 9, a18af620 by spitz
62 # Remove default_language rc.
64 # Incremented to format 10, 4985015 by tommaso
65 # Add close_buffer_with_last_view in preferences.
66 # No conversion necessary.
68 # Incremented to format 11, by gb
69 # Split pdf format into pdf and pdf6
71 # Incremented to format 12, by vfr
72 # Add option to use the system's theme icons
73 # No conversion necessary.
75 # Incremented to format 13, by bh
76 # Rename mac_like_word_movement to mac_like_cursor_movement
78 # Incremented to format 14, by spitz
79 # New RC default_otf_view_format
80 # No conversion necessary.
82 # Incremented to format 15, by prannoy
83 # Add fullscreen_statusbar
84 # No conversion necessary.
86 # Incremented to format 16, by lasgouttes
87 # Remove force_paint_single_char rc.
89 # Incremented to format 17, by lasgouttes
90 # Remove rtl_support rc.
92 # Incremented to format 18, by ef
93 # Add option to allow saving the document directory
94 # No conversion necessary.
96 # Incremented to format 19, by rgh
97 # remove print support
99 # Incremented to format 20, by tommaso
100 # Add options to forbid/ignore 'needauth' option
101 # No conversion necessary.
103 # Incremented to format 21, by spitz
104 # Add jbibtex_alternatives, allow "automatic" value
105 # of bibtex_command and jbibtex_command (actually the
107 # No conversion necessary.
109 # Incremented to format 22, by ef
110 # Add pygmentize_command for the python pygments syntax highlighter
111 # No conversion necessary.
113 # Incremented to format 23, by spitz
114 # Add default_platex_view_format, a default output format for
115 # Japanese documents via pLaTeX.
116 # No conversion necessary.
118 # Incremented to format 24, by spitz
119 # Rename collapsable to collapsible
121 # Incremented to format 25, by lasgouttes
122 # Remove use_qimage preference
124 # Incremented to format 26, by spitz
125 # Rename font_encoding preference
127 # Incremented to format 27, by spitz
128 # Add optional flavor value to needaux flag
130 # Incremented to format 28, by spitz
131 # Remove date_insert_format
133 # Incremented to format 29, by lasgouttes
134 # Remove use_pixmap_cache
136 # Incremented to format 30, by lasgouttes
137 # Add respect_os_kbd_language.
138 # No convergence necessary.
140 # Incremented to format 31, by spitz
141 # Add ct_additions_underlined.
142 # No convergence necessary.
144 # Incremented to format 32, by spitz
145 # Add ct_markup_copied.
146 # No convergence necessary.
148 # Incremented to format 33, by sanda
149 # Add \citation_search, \citation_search_pattern
150 # and \citation_search_view.
151 # No conversion necessary.
153 # Incremented to format 34, by yuriy
154 # Rename *.kmap files for Cyrillic languages
156 # Incremented to format 35, by spitz
157 # \set_color now takes three arguments
158 # \set_color lyxname x11hexname x11darkhexname
160 # Incremented to format 36, by rkh
161 # Set spellcheck_continuously to FALSE if it is not otherwise set
162 # (the new default is true, so this keeps behavior the same for
165 # Incremented to format 37, by chillenb
166 # Remove \fullscreen_width
167 # Remove \fullscreen_limit
171 # Incremented to format 38, by ec
172 # Add option to configure ui style
173 # No conversion necessary.
175 # NOTE: The format should also be updated in LYXRC.cpp and
176 # in configure.py (search for lyxrc_fileformat).
180 ###########################################################
184 def get_format(line):
191 while i < len(line) and line[i] != '"':
192 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
197 entries.append(line[beg:end].replace('\\"', '"'))
200 elif not line[i].isspace():
202 while i < len(line) and not line[i].isspace():
205 entries.append(line[beg:end])
210 def simple_renaming(line, old, new):
211 i = line.lower().find(old.lower())
214 line = line[:i] + new + line[i+len(old):]
217 no_match = (False, [])
219 ######################################
220 ### Format 1 conversions (for LyX 2.0)
222 def remove_obsolete(line):
223 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
224 "\\plaintext_roff_command", "\\use_alt_language",
225 "\\use_escape_chars", "\\use_input_encoding",
226 "\\use_personal_dictionary", "\\use_pspell",
228 line = line.lower().lstrip()
230 if line.lower().startswith(tag):
235 def language_use_babel(line):
236 if not line.lower().startswith(r"\language_use_babel"):
238 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
239 m = re_lub.match(line)
244 newline = "\\language_package_selection " + newval
245 return (True, newline)
248 def language_package(line):
249 return simple_renaming(line, "\\language_package", "\\language_custom_package")
252 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
253 def latex_flavor(line):
254 if not line.lower().startswith("\\converter"):
263 "luatex": "lualatex",
267 if conv in conv2fl.keys():
268 flavor = conv2fl[conv]
271 if flavor == "latex":
274 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
277 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
278 def export_menu(line):
279 if not line.lower().startswith("\\format"):
287 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
289 # End format 1 conversions (for LyX 2.0)
290 ########################################
292 #################################
293 # Conversions from LyX 2.0 to 2.1
294 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
295 def zipped_native(line):
296 if not line.lower().startswith("\\format"):
298 m = zipre.match(line)
304 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
306 def remove_default_papersize(line):
307 if not line.lower().startswith("\\default_papersize"):
311 def add_mime_types(line):
312 if not line.lower().startswith("\\format"):
314 entries = get_format(line)
318 converted = converted + ' ""'
320 formats = {'tgif':'application/x-tgif', \
321 'fig':'application/x-xfig', \
322 'dia':'application/x-dia-diagram', \
323 'odg':'application/vnd.oasis.opendocument.graphics', \
324 'svg':'image/svg+xml', \
325 'bmp':'image/x-bmp', \
327 'jpg':'image/jpeg', \
328 'pbm':'image/x-portable-bitmap', \
329 'pgm':'image/x-portable-graymap', \
330 'png':'image/x-png', \
331 'ppm':'image/x-portable-pixmap', \
332 'tiff':'image/tiff', \
333 'xbm':'image/x-xbitmap', \
334 'xpm':'image/x-xpixmap', \
335 'docbook-xml':'application/docbook+xml', \
336 'dot':'text/vnd.graphviz', \
337 'ly':'text/x-lilypond', \
338 'latex':'text/x-tex', \
339 'text':'text/plain', \
340 'gnumeric':'application/x-gnumeric', \
341 'excel':'application/vnd.ms-excel', \
342 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
343 'xhtml':'application/xhtml+xml', \
344 'bib':'text/x-bibtex', \
345 'eps':'image/x-eps', \
346 'ps':'application/postscript', \
347 'pdf':'application/pdf', \
348 'dvi':'application/x-dvi', \
349 'html':'text/html', \
350 'odt':'application/vnd.oasis.opendocument.text', \
351 'sxw':'application/vnd.sun.xml.writer', \
352 'rtf':'application/rtf', \
353 'doc':'application/msword', \
355 'lyx':'application/x-lyx', \
356 'wmf':'image/x-wmf', \
358 if entries[1] in formats.keys():
359 converted = converted + ' "' + formats[entries[1]] + '"'
361 converted = converted + ' ""'
362 return (True, converted)
364 re_converter = re.compile(r'^\\converter\s+', re.IGNORECASE)
366 def split_pdf_format(line):
367 # strictly speaking, a new format would not require to bump the
368 # version number, but the old pdf format was hardcoded at several
369 # places in the C++ code, so an update seemed like a good idea.
370 if line.lower().startswith("\\format"):
371 entries = get_format(line)
372 if entries[1] == 'pdf':
377 converted = line.replace('application/pdf', '') + r'''
378 \Format pdf6 pdf "PDF (graphics)" "" "''' + viewer + '" "" "vector" "application/pdf"'
379 return (True, converted)
380 elif line.lower().startswith("\\viewer_alternatives") or \
381 line.lower().startswith("\\editor_alternatives"):
382 entries = get_format(line)
383 if entries[1] == 'pdf':
384 converted = line + "\n" + entries[0] + ' pdf6 "' + entries[2] + '"'
385 return (True, converted)
386 elif re_converter.match(line):
387 entries = get_format(line)
388 # The only converter from pdf that is touched is pdf->eps:
389 # All other converters are likely meant for further processing on export.
390 # The only converter to pdf that stays untouched is dvi->pdf:
391 # All other converters are likely meant for graphics.
392 if len(entries) > 2 and \
393 ((entries[1] == 'pdf' and entries[2] == 'eps') or \
394 (entries[1] != 'ps' and entries[2] == 'pdf')):
395 if entries[1] == 'pdf':
396 converted = entries[0] + ' pdf6 ' + entries[2]
398 converted = entries[0] + ' ' + entries[1] + ' pdf6'
400 while i < len(entries):
401 converted = converted + ' "' + entries[i] + '"'
403 return (True, converted)
406 def remove_default_language(line):
407 if not line.lower().startswith("\\default_language"):
411 def mac_cursor_movement(line):
412 return simple_renaming(line, "\\mac_like_word_movement", "\\mac_like_cursor_movement")
414 # End conversions for LyX 2.0 to 2.1
415 ####################################
418 #################################
419 # Conversions from LyX 2.1 to 2.2
421 def remove_force_paint_single_char(line):
422 if not line.lower().startswith("\\force_paint_single_char"):
426 def remove_rtl(line):
427 if not line.lower().startswith("\\rtl "):
431 def remove_print_support(line):
432 tags = ("\\printer", "\\print_adapt_output", "\\print_command",
433 "\\print_evenpage_flag", "\\print_oddpage_flag", "\\print_pagerange_flag",
434 "\\print_copies_flag", "\\print_collcopies_flag", "\\print_reverse_flag",
435 "\\print_to_printer", "\\print_to_file", "\\print_file_extension")
436 line = line.lower().lstrip()
438 if line.lower().startswith(tag):
442 # End conversions for LyX 2.1 to 2.2
443 ####################################
446 #################################
447 # Conversions from LyX 2.2 to 2.3
449 def rename_collapsible(line):
450 return simple_renaming(line, "\\set_color \"collapsable", "\\set_color \"collapsible")
452 # End conversions for LyX 2.2 to 2.3
453 ####################################
456 #################################
457 # Conversions from LyX 2.3 to 2.4
459 def remove_use_qimage(line):
460 if not line.lower().startswith("\\use_qimage "):
464 def remove_font_encoding(line):
465 if not line.lower().startswith("\\font_encoding "):
469 def remove_date_insert_format(line):
470 if not line.lower().startswith("\\date_insert_format "):
474 def remove_use_pixmap_cache(line):
475 if not line.lower().startswith("\\use_pixmap_cache "):
479 def rename_cyrillic_kmap_files(line):
481 if not (line.startswith("\\kbmap_primary ")
482 or line.startswith("\\kbmap_secondary ")):
484 line = line.replace('"bg-bds-1251"', '"bulgarian"')
485 line = line.replace('"koi8-r"', '"russian"')
486 line = line.replace('"koi8-u"', '"ukrainian"')
489 def add_dark_color(line):
490 if not line.lower().startswith("\\set_color "):
492 colre = re.compile(r'^\\set_color\s+("[^"]+")\s+("[^"]+")\s*$', re.IGNORECASE)
493 m = colre.match(line)
496 line += " " + m.group(2)
499 def add_spellcheck_default(lines):
501 if l.startswith("\\spellcheck_continuously"):
503 lines.append("\\spellcheck_continuously false")
505 def remove_fullscreen_widthlimit(line):
507 if lower.startswith("\\fullscreen_width") or lower.startswith("\\fullscreen_limit"):
511 # End conversions for LyX 2.3 to 2.4
512 ####################################
516 ############################################################
517 # Format-conversion map. Also add empty format changes here.
520 [ 1, [ # there were several conversions for format 1
528 [ 3, [ zipped_native ]],
529 [ 4, [ remove_default_papersize ]],
532 [ 7, [add_mime_types]],
534 [ 9, [ remove_default_language ]],
536 [ 11, [split_pdf_format]],
538 [ 13, [mac_cursor_movement]],
541 [ 16, [remove_force_paint_single_char]],
544 [ 19, [remove_print_support]],
549 [ 24, [rename_collapsible]],
550 [ 25, [remove_use_qimage]],
551 [ 26, [remove_font_encoding]],
553 [ 28, [remove_date_insert_format]],
554 [ 29, [remove_use_pixmap_cache]],
559 [ 34, [rename_cyrillic_kmap_files]],
560 [ 35, [add_dark_color]],
561 [ 36, [add_spellcheck_default]],
562 [ 37, [remove_fullscreen_widthlimit]],