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 # NOTE: The format should also be updated in LYXRC.cpp and
166 # in configure.py (search for lyxrc_fileformat).
170 ###########################################################
174 def get_format(line):
181 while i < len(line) and line[i] != '"':
182 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
187 entries.append(line[beg:end].replace('\\"', '"'))
190 elif not line[i].isspace():
192 while i < len(line) and not line[i].isspace():
195 entries.append(line[beg:end])
200 def simple_renaming(line, old, new):
201 i = line.lower().find(old.lower())
204 line = line[:i] + new + line[i+len(old):]
207 no_match = (False, [])
209 ######################################
210 ### Format 1 conversions (for LyX 2.0)
212 def remove_obsolete(line):
213 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
214 "\\plaintext_roff_command", "\\use_alt_language",
215 "\\use_escape_chars", "\\use_input_encoding",
216 "\\use_personal_dictionary", "\\use_pspell",
218 line = line.lower().lstrip()
220 if line.lower().startswith(tag):
225 def language_use_babel(line):
226 if not line.lower().startswith("\language_use_babel"):
228 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
229 m = re_lub.match(line)
234 newline = "\\language_package_selection " + newval
235 return (True, newline)
238 def language_package(line):
239 return simple_renaming(line, "\\language_package", "\\language_custom_package")
242 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
243 def latex_flavor(line):
244 if not line.lower().startswith("\\converter"):
253 "luatex": "lualatex",
257 if conv in conv2fl.keys():
258 flavor = conv2fl[conv]
261 if flavor == "latex":
264 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
267 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
268 def export_menu(line):
269 if not line.lower().startswith("\\format"):
277 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
279 # End format 1 conversions (for LyX 2.0)
280 ########################################
282 #################################
283 # Conversions from LyX 2.0 to 2.1
284 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
285 def zipped_native(line):
286 if not line.lower().startswith("\\format"):
288 m = zipre.match(line)
294 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
296 def remove_default_papersize(line):
297 if not line.lower().startswith("\\default_papersize"):
301 def add_mime_types(line):
302 if not line.lower().startswith("\\format"):
304 entries = get_format(line)
308 converted = converted + ' ""'
310 formats = {'tgif':'application/x-tgif', \
311 'fig':'application/x-xfig', \
312 'dia':'application/x-dia-diagram', \
313 'odg':'application/vnd.oasis.opendocument.graphics', \
314 'svg':'image/svg+xml', \
315 'bmp':'image/x-bmp', \
317 'jpg':'image/jpeg', \
318 'pbm':'image/x-portable-bitmap', \
319 'pgm':'image/x-portable-graymap', \
320 'png':'image/x-png', \
321 'ppm':'image/x-portable-pixmap', \
322 'tiff':'image/tiff', \
323 'xbm':'image/x-xbitmap', \
324 'xpm':'image/x-xpixmap', \
325 'docbook-xml':'application/docbook+xml', \
326 'dot':'text/vnd.graphviz', \
327 'ly':'text/x-lilypond', \
328 'latex':'text/x-tex', \
329 'text':'text/plain', \
330 'gnumeric':'application/x-gnumeric', \
331 'excel':'application/vnd.ms-excel', \
332 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
333 'xhtml':'application/xhtml+xml', \
334 'bib':'text/x-bibtex', \
335 'eps':'image/x-eps', \
336 'ps':'application/postscript', \
337 'pdf':'application/pdf', \
338 'dvi':'application/x-dvi', \
339 'html':'text/html', \
340 'odt':'application/vnd.oasis.opendocument.text', \
341 'sxw':'application/vnd.sun.xml.writer', \
342 'rtf':'application/rtf', \
343 'doc':'application/msword', \
345 'lyx':'application/x-lyx', \
346 'wmf':'image/x-wmf', \
348 if entries[1] in formats.keys():
349 converted = converted + ' "' + formats[entries[1]] + '"'
351 converted = converted + ' ""'
352 return (True, converted)
354 re_converter = re.compile(r'^\\converter\s+', re.IGNORECASE)
356 def split_pdf_format(line):
357 # strictly speaking, a new format would not require to bump the
358 # version number, but the old pdf format was hardcoded at several
359 # places in the C++ code, so an update seemed like a good idea.
360 if line.lower().startswith("\\format"):
361 entries = get_format(line)
362 if entries[1] == 'pdf':
367 converted = line.replace('application/pdf', '') + '''
368 \Format pdf6 pdf "PDF (graphics)" "" "''' + viewer + '" "" "vector" "application/pdf"'
369 return (True, converted)
370 elif line.lower().startswith("\\viewer_alternatives") or \
371 line.lower().startswith("\\editor_alternatives"):
372 entries = get_format(line)
373 if entries[1] == 'pdf':
374 converted = line + "\n" + entries[0] + ' pdf6 "' + entries[2] + '"'
375 return (True, converted)
376 elif re_converter.match(line):
377 entries = get_format(line)
378 # The only converter from pdf that is touched is pdf->eps:
379 # All other converters are likely meant for further processing on export.
380 # The only converter to pdf that stays untouched is dvi->pdf:
381 # All other converters are likely meant for graphics.
382 if len(entries) > 2 and \
383 ((entries[1] == 'pdf' and entries[2] == 'eps') or \
384 (entries[1] != 'ps' and entries[2] == 'pdf')):
385 if entries[1] == 'pdf':
386 converted = entries[0] + ' pdf6 ' + entries[2]
388 converted = entries[0] + ' ' + entries[1] + ' pdf6'
390 while i < len(entries):
391 converted = converted + ' "' + entries[i] + '"'
393 return (True, converted)
396 def remove_default_language(line):
397 if not line.lower().startswith("\\default_language"):
401 def mac_cursor_movement(line):
402 return simple_renaming(line, "\\mac_like_word_movement", "\\mac_like_cursor_movement")
404 # End conversions for LyX 2.0 to 2.1
405 ####################################
408 #################################
409 # Conversions from LyX 2.1 to 2.2
411 def remove_force_paint_single_char(line):
412 if not line.lower().startswith("\\force_paint_single_char"):
416 def remove_rtl(line):
417 if not line.lower().startswith("\\rtl "):
421 def remove_print_support(line):
422 tags = ("\\printer", "\\print_adapt_output", "\\print_command",
423 "\\print_evenpage_flag", "\\print_oddpage_flag", "\\print_pagerange_flag",
424 "\\print_copies_flag", "\\print_collcopies_flag", "\\print_reverse_flag",
425 "\\print_to_printer", "\\print_to_file", "\\print_file_extension")
426 line = line.lower().lstrip()
428 if line.lower().startswith(tag):
432 # End conversions for LyX 2.1 to 2.2
433 ####################################
436 #################################
437 # Conversions from LyX 2.2 to 2.3
439 def rename_collapsible(line):
440 return simple_renaming(line, "\\set_color \"collapsable", "\\set_color \"collapsible")
442 # End conversions for LyX 2.2 to 2.3
443 ####################################
446 #################################
447 # Conversions from LyX 2.3 to 2.4
449 def remove_use_qimage(line):
450 if not line.lower().startswith("\\use_qimage "):
454 def remove_font_encoding(line):
455 if not line.lower().startswith("\\font_encoding "):
459 def remove_date_insert_format(line):
460 if not line.lower().startswith("\\date_insert_format "):
464 def remove_use_pixmap_cache(line):
465 if not line.lower().startswith("\\use_pixmap_cache "):
469 def rename_cyrillic_kmap_files(line):
471 if not (line.startswith("\\kbmap_primary ")
472 or line.startswith("\\kbmap_secondary ")):
474 line = line.replace('"bg-bds-1251"', '"bulgarian"')
475 line = line.replace('"koi8-r"', '"russian"')
476 line = line.replace('"koi8-u"', '"ukrainian"')
479 def add_dark_color(line):
480 if not line.lower().startswith("\\set_color "):
482 colre = re.compile(r'^\\set_color\s+("[^"]+")\s+("[^"]+")\s*$', re.IGNORECASE)
483 m = colre.match(line)
486 line += " " + m.group(2)
489 def add_spellcheck_default(lines):
491 if l.startswith("\\spellcheck_continuously"):
493 lines.append("\\spellcheck_continuously false")
495 # End conversions for LyX 2.3 to 2.4
496 ####################################
500 ############################################################
501 # Format-conversion map. Also add empty format changes here.
504 [ 1, [ # there were several conversions for format 1
512 [ 3, [ zipped_native ]],
513 [ 4, [ remove_default_papersize ]],
516 [ 7, [add_mime_types]],
518 [ 9, [ remove_default_language ]],
520 [ 11, [split_pdf_format]],
522 [ 13, [mac_cursor_movement]],
525 [ 16, [remove_force_paint_single_char]],
528 [ 19, [remove_print_support]],
533 [ 24, [rename_collapsible]],
534 [ 25, [remove_use_qimage]],
535 [ 26, [remove_font_encoding]],
537 [ 28, [remove_date_insert_format]],
538 [ 29, [remove_use_pixmap_cache]],
543 [ 34, [rename_cyrillic_kmap_files]],
544 [ 35, [add_dark_color]],
545 [ 36, [add_spellcheck_default]]