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.
9 # Full author contact details are available in file CREDITS
11 # This file houses conversion information for the preferences file.
13 # The converter functions 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.
18 # Incremented to format 2, r39670 by jrioux
19 # Support for multiple file extensions per format.
20 # No conversion necessary.
22 # Incremented to format 3, r39705 by tommaso
23 # Support for file formats that are natively (g)zipped.
24 # We must add the flag zipped=native to formats that
25 # were previously hardcoded in the C++ source: dia.
27 # Incremented to format 4, r40028 by vfr
28 # Remove support for default paper size.
30 # Incremented to format 5, r40030 by vfr
31 # Add a default length unit.
32 # No conversion necessary.
34 # Incremented to format 6, r40515 by younes
35 # Add use_qimage option.
36 # No conversion necessary.
38 # Incremented to format 7, r40789 by gb
39 # Add mime type to file format
41 # Incremented to format 8, 288c1e0f by rgh
42 # Add "nice" flag for converters
43 # No conversion necessary.
45 # Incremented to format 9, a18af620 by spitz
46 # Remove default_language rc.
48 # Incremented to format 10, 4985015 by tommaso
49 # Add close_buffer_with_last_view in preferences.
50 # No conversion necessary.
52 # Incremented to format 11, by gb
53 # Split pdf format into pdf and pdf6
55 # Incremented to format 12, by vfr
56 # Add option to use the system's theme icons
57 # No conversion necessary.
59 # Incremented to format 13, by bh
60 # Rename mac_like_word_movement to mac_like_cursor_movement
62 # Incremented to format 14, by spitz
63 # New RC default_otf_view_format
64 # No conversion necessary.
66 # Incremented to format 15, by prannoy
67 # Add fullscreen_statusbar
68 # No conversion necessary.
70 # Incremented to format 16, by lasgouttes
71 # Remove force_paint_single_char rc.
73 # Incremented to format 17, by lasgouttes
74 # Remove rtl_support rc.
76 # Incremented to format 18, by ef
77 # Add option to allow saving the document directory
78 # No conversion necessary.
80 # Incremented to format 19, by rgh
81 # remove print support
83 # Incremented to format 20, by tommaso
84 # Add options to forbid/ignore 'needauth' option
85 # No conversion necessary.
87 # Incremented to format 21, by spitz
88 # Add jbibtex_alternatives, allow "automatic" value
89 # of bibtex_command and jbibtex_command (actually the
91 # No conversion necessary.
93 # Incremented to format 22, by ef
94 # Add pygmentize_command for the python pygments syntax highlighter
95 # No conversion necessary.
97 # Incremented to format 23, by spitz
98 # Add default_platex_view_format, a default output format for
99 # Japanese documents via pLaTeX.
100 # No conversion necessary.
102 # Incremented to format 24, by spitz
103 # Rename collapsable to collapsible
105 # Incremented to format 25, by lasgouttes
106 # Remove use_qimage preference
108 # Incremented to format 26, by spitz
109 # Rename font_encoding preference
111 # Incremented to format 27, by spitz
112 # Add optional flavor value to needaux flag
114 # Incremented to format 28, by spitz
115 # Remove date_insert_format
117 # Incremented to format 29, by lasgouttes
118 # Remove use_pixmap_cache
120 # Incremented to format 30, by lasgouttes
121 # Add respect_os_kbd_language.
122 # No convergence necessary.
124 # Incremented to format 31, by spitz
125 # Add ct_additions_underlined.
126 # No convergence necessary.
128 # Incremented to format 32, by spitz
129 # Add ct_markup_copied.
130 # No convergence necessary.
132 # Incremented to format 33, by sanda
133 # Add \citation_search, \citation_search_pattern
134 # and \citation_search_view.
135 # No conversion necessary.
138 # NOTE: The format should also be updated in LYXRC.cpp and
143 ###########################################################
147 def get_format(line):
154 while i < len(line) and line[i] != '"':
155 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
160 entries.append(line[beg:end].replace('\\"', '"'))
163 elif not line[i].isspace():
165 while i < len(line) and not line[i].isspace():
168 entries.append(line[beg:end])
173 def simple_renaming(line, old, new):
174 i = line.lower().find(old.lower())
177 line = line[:i] + new + line[i+len(old):]
180 no_match = (False, [])
182 ######################################
183 ### Format 1 conversions (for LyX 2.0)
185 def remove_obsolete(line):
186 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
187 "\\plaintext_roff_command", "\\use_alt_language",
188 "\\use_escape_chars", "\\use_input_encoding",
189 "\\use_personal_dictionary", "\\use_pspell",
191 line = line.lower().lstrip()
193 if line.lower().startswith(tag):
198 def language_use_babel(line):
199 if not line.lower().startswith("\language_use_babel"):
201 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
202 m = re_lub.match(line)
207 newline = "\\language_package_selection " + newval
208 return (True, newline)
211 def language_package(line):
212 return simple_renaming(line, "\\language_package", "\\language_custom_package")
215 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
216 def latex_flavor(line):
217 if not line.lower().startswith("\\converter"):
226 "luatex": "lualatex",
230 if conv in conv2fl.keys():
231 flavor = conv2fl[conv]
234 if flavor == "latex":
237 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
240 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
241 def export_menu(line):
242 if not line.lower().startswith("\\format"):
250 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
252 # End format 1 conversions (for LyX 2.0)
253 ########################################
255 #################################
256 # Conversions from LyX 2.0 to 2.1
257 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
258 def zipped_native(line):
259 if not line.lower().startswith("\\format"):
261 m = zipre.match(line)
267 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
269 def remove_default_papersize(line):
270 if not line.lower().startswith("\\default_papersize"):
274 def add_mime_types(line):
275 if not line.lower().startswith("\\format"):
277 entries = get_format(line)
281 converted = converted + ' ""'
283 formats = {'tgif':'application/x-tgif', \
284 'fig':'application/x-xfig', \
285 'dia':'application/x-dia-diagram', \
286 'odg':'application/vnd.oasis.opendocument.graphics', \
287 'svg':'image/svg+xml', \
288 'bmp':'image/x-bmp', \
290 'jpg':'image/jpeg', \
291 'pbm':'image/x-portable-bitmap', \
292 'pgm':'image/x-portable-graymap', \
293 'png':'image/x-png', \
294 'ppm':'image/x-portable-pixmap', \
295 'tiff':'image/tiff', \
296 'xbm':'image/x-xbitmap', \
297 'xpm':'image/x-xpixmap', \
298 'docbook-xml':'application/docbook+xml', \
299 'dot':'text/vnd.graphviz', \
300 'ly':'text/x-lilypond', \
301 'latex':'text/x-tex', \
302 'text':'text/plain', \
303 'gnumeric':'application/x-gnumeric', \
304 'excel':'application/vnd.ms-excel', \
305 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
306 'xhtml':'application/xhtml+xml', \
307 'bib':'text/x-bibtex', \
308 'eps':'image/x-eps', \
309 'ps':'application/postscript', \
310 'pdf':'application/pdf', \
311 'dvi':'application/x-dvi', \
312 'html':'text/html', \
313 'odt':'application/vnd.oasis.opendocument.text', \
314 'sxw':'application/vnd.sun.xml.writer', \
315 'rtf':'application/rtf', \
316 'doc':'application/msword', \
318 'lyx':'application/x-lyx', \
319 'wmf':'image/x-wmf', \
321 if entries[1] in formats.keys():
322 converted = converted + ' "' + formats[entries[1]] + '"'
324 converted = converted + ' ""'
325 return (True, converted)
327 re_converter = re.compile(r'^\\converter\s+', re.IGNORECASE)
329 def split_pdf_format(line):
330 # strictly speaking, a new format would not require to bump the
331 # version number, but the old pdf format was hardcoded at several
332 # places in the C++ code, so an update seemed like a good idea.
333 if line.lower().startswith("\\format"):
334 entries = get_format(line)
335 if entries[1] == 'pdf':
340 converted = line.replace('application/pdf', '') + '''
341 \Format pdf6 pdf "PDF (graphics)" "" "''' + viewer + '" "" "vector" "application/pdf"'
342 return (True, converted)
343 elif line.lower().startswith("\\viewer_alternatives") or \
344 line.lower().startswith("\\editor_alternatives"):
345 entries = get_format(line)
346 if entries[1] == 'pdf':
347 converted = line + "\n" + entries[0] + ' pdf6 "' + entries[2] + '"'
348 return (True, converted)
349 elif re_converter.match(line):
350 entries = get_format(line)
351 # The only converter from pdf that is touched is pdf->eps:
352 # All other converters are likely meant for further processing on export.
353 # The only converter to pdf that stays untouched is dvi->pdf:
354 # All other converters are likely meant for graphics.
355 if len(entries) > 2 and \
356 ((entries[1] == 'pdf' and entries[2] == 'eps') or \
357 (entries[1] != 'ps' and entries[2] == 'pdf')):
358 if entries[1] == 'pdf':
359 converted = entries[0] + ' pdf6 ' + entries[2]
361 converted = entries[0] + ' ' + entries[1] + ' pdf6'
363 while i < len(entries):
364 converted = converted + ' "' + entries[i] + '"'
366 return (True, converted)
369 def remove_default_language(line):
370 if not line.lower().startswith("\\default_language"):
374 def mac_cursor_movement(line):
375 return simple_renaming(line, "\\mac_like_word_movement", "\\mac_like_cursor_movement")
377 # End conversions for LyX 2.0 to 2.1
378 ####################################
381 #################################
382 # Conversions from LyX 2.1 to 2.2
384 def remove_force_paint_single_char(line):
385 if not line.lower().startswith("\\force_paint_single_char"):
389 def remove_rtl(line):
390 if not line.lower().startswith("\\rtl "):
394 def remove_print_support(line):
395 tags = ("\\printer", "\\print_adapt_output", "\\print_command",
396 "\\print_evenpage_flag", "\\print_oddpage_flag", "\\print_pagerange_flag",
397 "\\print_copies_flag", "\\print_collcopies_flag", "\\print_reverse_flag",
398 "\\print_to_printer", "\\print_to_file", "\\print_file_extension")
399 line = line.lower().lstrip()
401 if line.lower().startswith(tag):
405 # End conversions for LyX 2.1 to 2.2
406 ####################################
409 #################################
410 # Conversions from LyX 2.2 to 2.3
412 def rename_collapsible(line):
413 return simple_renaming(line, "\\set_color \"collapsable", "\\set_color \"collapsible")
415 # End conversions for LyX 2.2 to 2.3
416 ####################################
419 #################################
420 # Conversions from LyX 2.3 to 2.4
422 def remove_use_qimage(line):
423 if not line.lower().startswith("\\use_qimage "):
427 def remove_font_encoding(line):
428 if not line.lower().startswith("\\font_encoding "):
432 def remove_date_insert_format(line):
433 if not line.lower().startswith("\\date_insert_format "):
437 def remove_use_pixmap_cache(line):
438 if not line.lower().startswith("\\use_pixmap_cache "):
442 # End conversions for LyX 2.3 to 2.4
443 ####################################
447 ############################################################
448 # Format-conversion map. Also add empty format changes here.
451 [ 1, [ # there were several conversions for format 1
459 [ 3, [ zipped_native ]],
460 [ 4, [ remove_default_papersize ]],
463 [ 7, [add_mime_types]],
465 [ 9, [ remove_default_language ]],
467 [ 11, [split_pdf_format]],
469 [ 13, [mac_cursor_movement]],
472 [ 16, [remove_force_paint_single_char]],
475 [ 19, [remove_print_support]],
480 [ 24, [rename_collapsible]],
481 [ 25, [remove_use_qimage]],
482 [ 26, [remove_font_encoding]],
484 [ 28, [remove_date_insert_format]],
485 [ 29, [remove_use_pixmap_cache]],