]> git.lyx.org Git - lyx.git/blob - src/lyxrc.C
fix crash when collapsing ert with cursor inside
[lyx.git] / src / lyxrc.C
1 /**
2  * \file lyxrc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  * \author John Levon
10  * \author André Pönitz
11  * \author Allan Rae
12  * \author Dekel Tsur
13  *
14  * Full author contact details are available in file CREDITS.
15  */
16
17 #include <config.h>
18
19 #include <fstream>
20 #include <iostream>
21
22 #include "lyxrc.h"
23
24 #include "debug.h"
25 #include "converter.h"
26 #include "format.h"
27 #include "gettext.h"
28 #include "lastfiles.h"
29 #include "LColor.h"
30 #include "lyxlex.h"
31 #include "lyxfont.h"
32 #include "mover.h"
33
34 #include "graphics/GraphicsTypes.h"
35
36 #include "support/convert.h"
37 #include "support/environment.h"
38 #include "support/filetools.h"
39 #include "support/lstrings.h"
40 #include "support/userinfo.h"
41
42 using lyx::support::ascii_lowercase;
43 using lyx::support::bformat;
44 using lyx::support::ExpandPath;
45 using lyx::support::getEnv;
46 using lyx::support::LibFileSearch;
47 using lyx::support::token;
48
49 using std::cout;
50 using std::endl;
51
52 using std::ios;
53 using std::ofstream;
54 using std::ostream;
55 using std::string;
56
57
58 namespace {
59
60 // when adding something to this array keep it sorted!
61 keyword_item lyxrcTags[] = {
62         { "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND },
63         { "\\alternate_language", LyXRC::RC_ALT_LANG },
64         { "\\ascii_linelen", LyXRC::RC_ASCII_LINELEN },
65         { "\\ascii_roff_command", LyXRC::RC_ASCIIROFF_COMMAND },
66         { "\\auto_number", LyXRC::RC_AUTO_NUMBER },
67         { "\\auto_region_delete", LyXRC::RC_AUTOREGIONDELETE },
68         { "\\auto_reset_options", LyXRC::RC_AUTORESET_OPTIONS },
69         { "\\autosave", LyXRC::RC_AUTOSAVE },
70         { "\\backupdir_path", LyXRC::RC_BACKUPDIR_PATH },
71         { "\\bibtex_command", LyXRC::RC_BIBTEX_COMMAND },
72         { "\\bind_file", LyXRC::RC_BINDFILE },
73         { "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES },
74         { "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND },
75         { "\\converter", LyXRC::RC_CONVERTER },
76         { "\\copier", LyXRC::RC_COPIER },
77         { "\\cursor_follows_scrollbar", LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR },
78         { "\\custom_export_command", LyXRC::RC_CUSTOM_EXPORT_COMMAND },
79         { "\\custom_export_format", LyXRC::RC_CUSTOM_EXPORT_FORMAT },
80         { "\\cygwin_path_fix_needed", LyXRC::RC_CYGWIN_PATH_FIX },
81         { "\\date_insert_format", LyXRC::RC_DATE_INSERT_FORMAT },
82         { "\\default_language", LyXRC::RC_DEFAULT_LANGUAGE },
83         { "\\default_papersize", LyXRC::RC_DEFAULT_PAPERSIZE },
84         { "\\dialogs_iconify_with_main", LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN },
85         { "\\display_graphics", LyXRC::RC_DISPLAY_GRAPHICS },
86         { "\\document_path", LyXRC::RC_DOCUMENTPATH },
87         { "\\escape_chars", LyXRC::RC_ESC_CHARS },
88         { "\\font_encoding", LyXRC::RC_FONT_ENCODING },
89         { "\\format", LyXRC::RC_FORMAT },
90         { "\\index_command", LyXRC::RC_INDEX_COMMAND },
91         { "\\input", LyXRC::RC_INPUT },
92         { "\\kbmap", LyXRC::RC_KBMAP },
93         { "\\kbmap_primary", LyXRC::RC_KBMAP_PRIMARY },
94         { "\\kbmap_secondary", LyXRC::RC_KBMAP_SECONDARY },
95         { "\\label_init_length", LyXRC::RC_LABEL_INIT_LENGTH },
96         { "\\language_auto_begin", LyXRC::RC_LANGUAGE_AUTO_BEGIN },
97         { "\\language_auto_end", LyXRC::RC_LANGUAGE_AUTO_END },
98         { "\\language_command_begin", LyXRC::RC_LANGUAGE_COMMAND_BEGIN },
99         { "\\language_command_end", LyXRC::RC_LANGUAGE_COMMAND_END },
100         { "\\language_command_local", LyXRC::RC_LANGUAGE_COMMAND_LOCAL },
101         { "\\language_global_options", LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS },
102         { "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE },
103         { "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL },
104         { "\\lastfiles", LyXRC::RC_LASTFILES },
105         { "\\make_backup", LyXRC::RC_MAKE_BACKUP },
106         { "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE },
107         { "\\num_lastfiles", LyXRC::RC_NUMLASTFILES },
108         { "\\path_prefix", LyXRC::RC_PATH_PREFIX },
109         { "\\personal_dictionary", LyXRC::RC_PERS_DICT },
110         { "\\popup_bold_font", LyXRC::RC_POPUP_BOLD_FONT },
111         { "\\popup_font_encoding", LyXRC::RC_POPUP_FONT_ENCODING },
112         { "\\popup_normal_font", LyXRC::RC_POPUP_NORMAL_FONT },
113         { "\\preview", LyXRC::RC_PREVIEW },
114         { "\\preview_hashed_labels", LyXRC::RC_PREVIEW_HASHED_LABELS },
115         { "\\preview_scale_factor", LyXRC::RC_PREVIEW_SCALE_FACTOR },
116         { "\\print_adapt_output", LyXRC::RC_PRINT_ADAPTOUTPUT },
117         { "\\print_collcopies_flag", LyXRC::RC_PRINTCOLLCOPIESFLAG },
118         { "\\print_command", LyXRC::RC_PRINT_COMMAND },
119         { "\\print_copies_flag", LyXRC::RC_PRINTCOPIESFLAG },
120         { "\\print_evenpage_flag", LyXRC::RC_PRINTEVENPAGEFLAG },
121         { "\\print_extra_options", LyXRC::RC_PRINTEXSTRAOPTIONS },
122         { "\\print_file_extension", LyXRC::RC_PRINTFILEEXTENSION },
123         { "\\print_landscape_flag", LyXRC::RC_PRINTLANDSCAPEFLAG },
124         { "\\print_oddpage_flag", LyXRC::RC_PRINTODDPAGEFLAG },
125         { "\\print_pagerange_flag", LyXRC::RC_PRINTPAGERANGEFLAG },
126         { "\\print_paper_dimension_flag", LyXRC::RC_PRINTPAPERDIMENSIONFLAG },
127         { "\\print_paper_flag", LyXRC::RC_PRINTPAPERFLAG },
128         { "\\print_reverse_flag", LyXRC::RC_PRINTREVERSEFLAG },
129         { "\\print_spool_command", LyXRC::RC_PRINTSPOOL_COMMAND },
130         { "\\print_spool_printerprefix", LyXRC::RC_PRINTSPOOL_PRINTERPREFIX },
131         { "\\print_to_file", LyXRC::RC_PRINTTOFILE },
132         { "\\print_to_printer", LyXRC::RC_PRINTTOPRINTER },
133         { "\\printer", LyXRC::RC_PRINTER },
134         { "\\rtl", LyXRC::RC_RTL_SUPPORT },
135         { "\\screen_dpi", LyXRC::RC_SCREEN_DPI },
136         { "\\screen_font_encoding", LyXRC::RC_SCREEN_FONT_ENCODING },
137         // compatibility with versions older than 1.2.0 only Angus 10 Jan 2002
138         { "\\screen_font_encoding_menu", LyXRC::RC_POPUP_FONT_ENCODING },
139         // compatibility with versions older than 1.2.0 only Angus 10 Jan 2002
140         { "\\screen_font_menu", LyXRC::RC_POPUP_BOLD_FONT },
141         // compatibility with versions older than 1.2.0 only Angus 10 Jan 2002
142         { "\\screen_font_popup", LyXRC::RC_POPUP_NORMAL_FONT },
143         { "\\screen_font_roman", LyXRC::RC_SCREEN_FONT_ROMAN },
144         { "\\screen_font_roman_foundry", LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY },
145         { "\\screen_font_sans", LyXRC::RC_SCREEN_FONT_SANS },
146         { "\\screen_font_sans_foundry", LyXRC::RC_SCREEN_FONT_SANS_FOUNDRY },
147         { "\\screen_font_scalable", LyXRC::RC_SCREEN_FONT_SCALABLE },
148         { "\\screen_font_sizes", LyXRC::RC_SCREEN_FONT_SIZES },
149         { "\\screen_font_typewriter", LyXRC::RC_SCREEN_FONT_TYPEWRITER },
150         { "\\screen_font_typewriter_foundry", LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY },
151         { "\\screen_zoom", LyXRC::RC_SCREEN_ZOOM },
152         { "\\serverpipe", LyXRC::RC_SERVERPIPE },
153         { "\\set_color", LyXRC::RC_SET_COLOR },
154         { "\\show_banner", LyXRC::RC_SHOW_BANNER },
155         { "\\spell_command", LyXRC::RC_SPELL_COMMAND },
156         { "\\tempdir_path", LyXRC::RC_TEMPDIRPATH },
157         { "\\template_path", LyXRC::RC_TEMPLATEPATH },
158         { "\\tex_allows_spaces", LyXRC::RC_TEX_ALLOWS_SPACES },
159         { "\\ui_file", LyXRC::RC_UIFILE },
160         { "\\use_alt_language", LyXRC::RC_USE_ALT_LANG },
161         { "\\use_escape_chars", LyXRC::RC_USE_ESC_CHARS },
162         { "\\use_input_encoding", LyXRC::RC_USE_INP_ENC },
163         { "\\use_personal_dictionary", LyXRC::RC_USE_PERS_DICT },
164         // compatibility with versions older than 1.4.0 only
165         { "\\use_pspell", LyXRC::RC_USE_SPELL_LIB },
166         { "\\use_spell_lib", LyXRC::RC_USE_SPELL_LIB },
167         // compatibility with versions older than 1.4.0 only
168         { "\\use_tempdir", LyXRC::RC_USETEMPDIR },
169         { "\\user_email", LyXRC::RC_USER_EMAIL },
170         { "\\user_name", LyXRC::RC_USER_NAME },
171         { "\\view_dvi_paper_option", LyXRC::RC_VIEWDVI_PAPEROPTION },
172         // compatibility with versions older than 1.4.0 only
173         { "\\viewer" ,LyXRC::RC_VIEWER},
174         { "\\wheel_jump", LyXRC::RC_WHEEL_JUMP }
175 };
176
177 const int lyxrcCount = sizeof(lyxrcTags) / sizeof(keyword_item);
178
179 } // namespace anon
180
181
182 LyXRC::LyXRC()
183 {
184         setDefaults();
185 }
186
187
188 void LyXRC::setDefaults() {
189         bind_file = "cua";
190         ui_file = "default";
191         // Get printer from the environment. If fail, use default "",
192         // assuming that everything is set up correctly.
193         printer = getEnv("PRINTER");
194         print_adapt_output = false;
195         print_command = "dvips";
196         print_evenpage_flag = "-B";
197         print_oddpage_flag = "-A";
198         print_pagerange_flag = "-pp";
199         print_copies_flag = "-c";
200         print_collcopies_flag = "-C";
201         print_reverse_flag = "-r";
202         print_landscape_flag = "-t landscape";
203         print_to_printer = "-P";
204         print_to_file = "-o ";
205         print_file_extension = ".ps";
206         print_paper_flag = "-t";
207         print_paper_dimension_flag = "-T";
208         document_path.erase();
209         tempdir_path = "/tmp";
210         view_dvi_paper_option.erase();
211         default_papersize = PAPER_USLETTER;
212         custom_export_format = "ps";
213         chktex_command = "chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38";
214         bibtex_command = "bibtex";
215         fontenc = "default";
216         index_command = "makeindex -c -q";
217         dpi = 75;
218         // Because a screen typically is wider than a piece of paper:
219         zoom = 150;
220         wheel_jump = 5;
221         // Default LaTeX font size:
222         font_sizes[LyXFont::SIZE_TINY] = "5.0";
223         font_sizes[LyXFont::SIZE_SCRIPT] = "7.0";
224         font_sizes[LyXFont::SIZE_FOOTNOTE] = "8.0";
225         font_sizes[LyXFont::SIZE_SMALL] = "9.0";
226         font_sizes[LyXFont::SIZE_NORMAL] = "10.0";
227         font_sizes[LyXFont::SIZE_LARGE] = "12.0";
228         font_sizes[LyXFont::SIZE_LARGER] = "14.4";
229         font_sizes[LyXFont::SIZE_LARGEST] = "17.26";
230         font_sizes[LyXFont::SIZE_HUGE] = "20.74";
231         font_sizes[LyXFont::SIZE_HUGER] = "24.88";
232         use_scalable_fonts = true;
233         roman_font_name = "";
234         sans_font_name = "";
235         typewriter_font_name = "";
236         popup_bold_font = "-*-helvetica-bold-r";
237         popup_normal_font = "-*-helvetica-medium-r";
238         font_norm = "iso8859-1";
239         font_norm_type = ISO_8859_1;
240         popup_font_encoding.erase();
241         autosave = 300;
242         auto_region_delete = true;
243         auto_reset_options = false;
244         ascii_linelen = 65;
245         num_lastfiles = maxlastfiles;
246         check_lastfiles = true;
247         make_backup = true;
248         backupdir_path.erase();
249         display_graphics = lyx::graphics::ColorDisplay;
250         // Spellchecker settings:
251         use_spell_lib = true;
252         isp_command = "ispell";
253         isp_accept_compound = false;
254         isp_use_input_encoding = false;
255         isp_use_alt_lang = false;
256         isp_use_pers_dict = false;
257         isp_use_esc_chars = false;
258         use_kbmap = false;
259         rtl_support = false;
260         auto_number = true;
261         mark_foreign_language = true;
262         language_auto_begin = true;
263         language_auto_end = true;
264         language_global_options = true;
265         language_use_babel = true;
266         language_package = "\\usepackage{babel}";
267         language_command_begin = "\\selectlanguage{$$lang}";
268         language_command_local = "\\foreignlanguage{$$lang}{";
269         default_language = "english";
270         show_banner = true;
271         cygwin_path_fix = false;
272         tex_allows_spaces = false;
273         date_insert_format = "%A, %e %B %Y";
274         cursor_follows_scrollbar = false;
275         dialogs_iconify_with_main = false;
276         label_init_length = 3;
277         preview = PREVIEW_OFF;
278         preview_hashed_labels  = false;
279         preview_scale_factor = "0.9";
280
281         user_name = lyx::support::user_name();
282
283         user_email = lyx::support::user_email();
284 }
285
286
287 namespace {
288
289 void oldFontFormat(string & family, string & foundry)
290 {
291         if (family.empty() || family[0] != '-')
292                 return;
293         foundry = token(family, '-', 1);
294         family = token(family, '-', 2);
295         if (foundry == "*")
296                 foundry.erase();
297 }
298
299 } // namespace anon
300
301
302 int LyXRC::read(string const & filename)
303 {
304         LyXLex lexrc(lyxrcTags, lyxrcCount);
305         if (lyxerr.debugging(Debug::PARSER))
306                 lexrc.printTable(lyxerr);
307
308         lexrc.setFile(filename);
309         if (!lexrc.isOK()) return -2;
310
311         lyxerr[Debug::LYXRC] << "Reading '" << filename << "'..." << endl;
312
313         return read(lexrc);
314 }
315
316
317 int LyXRC::read(std::istream & is)
318 {
319         LyXLex lexrc(lyxrcTags, lyxrcCount);
320         if (lyxerr.debugging(Debug::PARSER))
321                 lexrc.printTable(lyxerr);
322
323         lexrc.setStream(is);
324         if (!lexrc.isOK()) return -2;
325
326         lyxerr[Debug::LYXRC] << "Reading istream..." << endl;
327
328         return read(lexrc);
329 }
330
331
332 int LyXRC::read(LyXLex & lexrc)
333 {
334         if (!lexrc.isOK()) return -2;
335
336         while (lexrc.isOK()) {
337                 // By using two switches we take advantage of the compiler
338                 // telling us if we have missed a LyXRCTags element in
339                 // the second switch.
340                 // Note that this also shows a problem with LyXLex since it
341                 // helps us avoid taking advantage of the strictness of the
342                 // compiler.
343
344                 int le = lexrc.lex();
345                 switch (le) {
346                 case LyXLex::LEX_UNDEF:
347                         lexrc.printError("Unknown tag `$$Token'");
348                         continue;
349                 case LyXLex::LEX_FEOF:
350                         continue;
351                 default: break;
352                 }
353                 switch (static_cast<LyXRCTags>(le)) {
354                 case RC_INPUT: // Include file
355                         if (lexrc.next()) {
356                                 string const tmp =
357                                         LibFileSearch(string(),
358                                                       lexrc.getString());
359                                 if (read(tmp)) {
360                                         lexrc.printError("Error reading "
361                                                          "included file: "+tmp);
362                                 }
363                         }
364                         break;
365                 case RC_BINDFILE:                     // RVDK_PATCH_5
366                         if (lexrc.next()) {
367                                 bind_file = lexrc.getString();
368                         }
369                         break;
370
371                 case RC_UIFILE:
372                         if (lexrc.next()) {
373                                 ui_file = lexrc.getString();
374                         }
375                         break;
376
377                 case RC_AUTORESET_OPTIONS:
378                         if (lexrc.next()) {
379                                 auto_reset_options = lexrc.getBool();
380                         }
381                         break;
382
383                 case RC_DISPLAY_GRAPHICS:
384                         if (lexrc.next()) {
385                                 display_graphics = lyx::graphics::displayTranslator().find(lexrc.getString());
386                         }
387                         break;
388
389                 case RC_CYGWIN_PATH_FIX:
390                         if (lexrc.next()) {
391                                 cygwin_path_fix = lexrc.getBool();
392                         }
393                         break;
394
395                 case RC_TEX_ALLOWS_SPACES:
396                         if (lexrc.next()) {
397                                 tex_allows_spaces = lexrc.getBool();
398                         }
399                         break;
400
401                 case RC_KBMAP:
402                         if (lexrc.next()) {
403                                 use_kbmap = lexrc.getBool();
404                         }
405                         break;
406
407                 case RC_KBMAP_PRIMARY:
408                         if (lexrc.next()) {
409                                 string const kmap(lexrc.getString());
410                                 if (kmap.empty()) {
411                                         // nothing
412                                 } else if (!LibFileSearch("kbd", kmap,
413                                                           "kmap").empty()) {
414                                         primary_kbmap = kmap;
415                                 } else {
416                                         lexrc.printError("LyX: Keymap `$$Token' not found");
417                                 }
418                         }
419                         break;
420
421                 case RC_KBMAP_SECONDARY:
422                         if (lexrc.next()) {
423                                 string const kmap(lexrc.getString());
424                                 if (kmap.empty()) {
425                                         // nothing
426                                 } else if (!LibFileSearch("kbd", kmap,
427                                                           "kmap").empty()) {
428                                         secondary_kbmap = kmap;
429                                 } else {
430                                         lexrc.printError("LyX: Keymap `$$Token' not found");
431                                 }
432                         }
433                         break;
434
435                 case RC_FONT_ENCODING:
436                         if (lexrc.next()) {
437                                 fontenc = lexrc.getString();
438                         }
439                         break;
440
441                 case RC_PRINTER:
442                         if (lexrc.next()) {
443                                 printer = lexrc.getString();
444                         }
445                         break;
446
447                 case RC_PRINT_COMMAND:
448                         if (lexrc.next()) {
449                                 print_command = lexrc.getString();
450                         }
451                         break;
452
453                 case RC_PRINTEVENPAGEFLAG:
454                         if (lexrc.next()) {
455                                 print_evenpage_flag = lexrc.getString();
456                         }
457                         break;
458
459                 case RC_PRINTODDPAGEFLAG:
460                         if (lexrc.next()) {
461                                 print_oddpage_flag = lexrc.getString();
462                         }
463                         break;
464
465                 case RC_PRINTPAGERANGEFLAG:
466                         if (lexrc.next()) {
467                                 print_pagerange_flag = lexrc.getString();
468                         }
469                         break;
470
471                 case RC_PRINTCOPIESFLAG:
472                         if (lexrc.next()) {
473                                 print_copies_flag = lexrc.getString();
474                         }
475                         break;
476
477                 case RC_PRINTCOLLCOPIESFLAG:
478                         if (lexrc.next()) {
479                                 print_collcopies_flag = lexrc.getString();
480                         }
481                         break;
482
483                 case RC_PRINTREVERSEFLAG:
484                         if (lexrc.next()) {
485                                 print_reverse_flag = lexrc.getString();
486                         }
487                         break;
488
489                 case RC_PRINTLANDSCAPEFLAG:
490                         if (lexrc.next()) {
491                                 print_landscape_flag = lexrc.getString();
492                         }
493                         break;
494
495                 case RC_PRINTTOPRINTER:
496                         if (lexrc.next()) {
497                                 print_to_printer = lexrc.getString();
498                         }
499                         break;
500
501                 case RC_PRINT_ADAPTOUTPUT:
502                         if (lexrc.next()) {
503                                 print_adapt_output = lexrc.getBool();
504                         }
505                         break;
506
507                 case RC_PRINTTOFILE:
508                         if (lexrc.next()) {
509                                 print_to_file = lexrc.getString();
510                         }
511                         break;
512
513                 case RC_PRINTFILEEXTENSION:
514                         if (lexrc.next()) {
515                                 print_file_extension = lexrc.getString();
516                         }
517                         break;
518
519                 case RC_PRINTEXSTRAOPTIONS:
520                         if (lexrc.next()) {
521                                 print_extra_options = lexrc.getString();
522                         }
523                         break;
524
525                 case RC_PRINTSPOOL_COMMAND:
526                         if (lexrc.next()) {
527                                 print_spool_command = lexrc.getString();
528                         }
529                         break;
530
531                 case RC_PRINTSPOOL_PRINTERPREFIX:
532                         if (lexrc.next()) {
533                                 print_spool_printerprefix = lexrc.getString();
534                         }
535                         break;
536
537                 case RC_PRINTPAPERDIMENSIONFLAG:
538                         if (lexrc.next()) {
539                                 print_paper_dimension_flag = lexrc.getString();
540                         }
541                         break;
542
543                 case RC_PRINTPAPERFLAG:
544                         if (lexrc.next()) {
545                                 print_paper_flag = lexrc.getString();
546                         }
547                         break;
548
549                 case RC_CUSTOM_EXPORT_COMMAND:
550                         if (lexrc.next()) {
551                                 custom_export_command = lexrc.getString();
552                         }
553                         break;
554
555                 case RC_CUSTOM_EXPORT_FORMAT:
556                         if (lexrc.next()) {
557                                 custom_export_format = lexrc.getString();
558                         }
559                         break;
560
561                 case RC_DEFAULT_PAPERSIZE:
562                         if (lexrc.next()) {
563                                 string const size =
564                                         ascii_lowercase(lexrc.getString());
565                                 if (size == "usletter")
566                                         default_papersize =
567                                                 PAPER_USLETTER;
568                                 else if (size == "legal")
569                                         default_papersize =
570                                                 PAPER_LEGALPAPER;
571                                 else if (size == "executive")
572                                         default_papersize =
573                                                 PAPER_EXECUTIVEPAPER;
574                                 else if (size == "a3")
575                                         default_papersize =
576                                                 PAPER_A3PAPER;
577                                 else if (size == "a4")
578                                         default_papersize =
579                                                 PAPER_A4PAPER;
580                                 else if (size == "a5")
581                                         default_papersize =
582                                                 PAPER_A5PAPER;
583                                 else if (size == "b5")
584                                         default_papersize =
585                                                 PAPER_B5PAPER;
586                         }
587                         break;
588
589                 case RC_VIEWDVI_PAPEROPTION:
590                         if (lexrc.next()) {
591                                 view_dvi_paper_option = lexrc.getString();
592                         } else {
593                                 view_dvi_paper_option.erase();
594                         }
595                         break;
596
597                 case RC_CHKTEX_COMMAND:
598                         if (lexrc.next()) {
599                                 chktex_command = lexrc.getString();
600                         }
601                         break;
602
603                 case RC_BIBTEX_COMMAND:
604                         if (lexrc.next()) {
605                                 bibtex_command = lexrc.getString();
606                         }
607                         break;
608
609                 case RC_INDEX_COMMAND:
610                         if (lexrc.next()) {
611                                 index_command = lexrc.getString();
612                         }
613                         break;
614
615                 case RC_SCREEN_DPI:
616                         if (lexrc.next()) {
617                                 dpi = lexrc.getInteger();
618                         }
619                         break;
620
621                 case RC_SCREEN_ZOOM:
622                         if (lexrc.next()) {
623                                 zoom = lexrc.getInteger();
624                         }
625                         break;
626
627                 case RC_WHEEL_JUMP:
628                         if (lexrc.next()) {
629                                 wheel_jump = lexrc.getInteger();
630                         }
631                         break;
632
633                 case RC_SCREEN_FONT_SIZES:
634                         if (lexrc.next()) {
635                                 font_sizes[LyXFont::SIZE_TINY] =
636                                         lexrc.getString();
637                         }
638                         if (lexrc.next()) {
639                                 font_sizes[LyXFont::SIZE_SCRIPT] =
640                                         lexrc.getString();
641                         }
642                         if (lexrc.next()) {
643                                 font_sizes[LyXFont::SIZE_FOOTNOTE] =
644                                         lexrc.getString();
645                         }
646                         if (lexrc.next()) {
647                                 font_sizes[LyXFont::SIZE_SMALL] =
648                                         lexrc.getString();
649                         }
650                         if (lexrc.next()) {
651                                 font_sizes[LyXFont::SIZE_NORMAL] =
652                                         lexrc.getString();
653                         }
654                         if (lexrc.next()) {
655                                 font_sizes[LyXFont::SIZE_LARGE] =
656                                         lexrc.getString();
657                         }
658                         if (lexrc.next()) {
659                                 font_sizes[LyXFont::SIZE_LARGER] =
660                                         lexrc.getString();
661                         }
662                         if (lexrc.next()) {
663                                 font_sizes[LyXFont::SIZE_LARGEST] =
664                                         lexrc.getString();
665                         }
666                         if (lexrc.next()) {
667                                 font_sizes[LyXFont::SIZE_HUGE] =
668                                         lexrc.getString();
669                         }
670                         if (lexrc.next()) {
671                                 font_sizes[LyXFont::SIZE_HUGER] =
672                                         lexrc.getString();
673                         }
674                         break;
675
676                 case RC_SCREEN_FONT_SCALABLE:
677                         if (lexrc.next()) {
678                                 use_scalable_fonts = lexrc.getBool();
679                         }
680                         break;
681
682                 case RC_AUTOSAVE:
683                         if (lexrc.next()) {
684                                 autosave = lexrc.getInteger();
685                         }
686                         break;
687
688                 case RC_DOCUMENTPATH:
689                         if (lexrc.next()) {
690                                 document_path = ExpandPath(lexrc.getString());
691                         }
692                         break;
693
694                 case RC_TEMPLATEPATH:
695                         if (lexrc.next()) {
696                                 template_path = ExpandPath(lexrc.getString());
697                         }
698                         break;
699
700                 case RC_TEMPDIRPATH:
701                         if (lexrc.next()) {
702                                 tempdir_path = ExpandPath(lexrc.getString());
703                         }
704                         break;
705
706                 case RC_USETEMPDIR:
707                         if (lexrc.next()) {
708                                 lyxerr << "Ignoring obsolete use_tempdir flag." << endl;
709                         }
710                         break;
711
712                 case RC_LASTFILES:
713                         if (lexrc.next()) {
714                                 lastfiles = ExpandPath(lexrc.getString());
715                         }
716                         break;
717
718                 case RC_NUMLASTFILES:
719                         if (lexrc.next()) {
720                                 num_lastfiles = lexrc.getInteger();
721                         }
722                         break;
723
724                 case RC_CHECKLASTFILES:
725                         if (lexrc.next()) {
726                                 check_lastfiles = lexrc.getBool();
727                         }
728                         break;
729
730                 case RC_SCREEN_FONT_ROMAN:
731                         if (lexrc.next()) {
732                                 roman_font_name = lexrc.getString();
733                                 oldFontFormat(roman_font_name,
734                                               roman_font_foundry);
735                         }
736                         break;
737
738                 case RC_SCREEN_FONT_SANS:
739                         if (lexrc.next()) {
740                                 sans_font_name = lexrc.getString();
741                                 oldFontFormat(sans_font_name, sans_font_foundry);
742                         }
743                         break;
744
745                 case RC_SCREEN_FONT_TYPEWRITER:
746                         if (lexrc.next()) {
747                                 typewriter_font_name = lexrc.getString();
748                                 oldFontFormat(typewriter_font_name,
749                                               typewriter_font_foundry);
750                         }
751                         break;
752
753                 case RC_SCREEN_FONT_ROMAN_FOUNDRY:
754                         if (lexrc.next()) {
755                                 roman_font_foundry = lexrc.getString();
756                         }
757                         break;
758
759                 case RC_SCREEN_FONT_SANS_FOUNDRY:
760                         if (lexrc.next()) {
761                                 sans_font_foundry = lexrc.getString();
762                         }
763                         break;
764
765                 case RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
766                         if (lexrc.next()) {
767                                 typewriter_font_foundry = lexrc.getString();
768                         }
769                         break;
770
771                 case RC_SCREEN_FONT_ENCODING:
772                         if (lexrc.next()) {
773                                 font_norm = lexrc.getString();
774                                 set_font_norm_type();
775                         }
776                         break;
777
778                 case RC_POPUP_BOLD_FONT:
779                         if (lexrc.next()) {
780                                 popup_bold_font = lexrc.getString();
781                         }
782                         break;
783
784                 case RC_POPUP_NORMAL_FONT:
785                         if (lexrc.next()) {
786                                 popup_normal_font = lexrc.getString();
787                         }
788                         break;
789
790                 case RC_POPUP_FONT_ENCODING:
791                         if (lexrc.next()) {
792                                 popup_font_encoding = lexrc.getString();
793                         }
794                         break;
795
796                 case RC_SET_COLOR:
797                 {
798                         string lyx_name, x11_name;
799
800                         if (lexrc.next()) {
801                                 lyx_name = lexrc.getString();
802                         } else {
803                                 lexrc.printError("Missing color tag.");
804                                 break;
805                         }
806
807                         if (lexrc.next()) {
808                                 x11_name = lexrc.getString();
809                         } else {
810                                 lexrc.printError("Missing color name for color: `$$Token'");
811                                 break;
812                         }
813
814                         LColor::color const col =
815                                 lcolor.getFromLyXName(lyx_name);
816                         if (col == LColor::none ||
817                             col == LColor::inherit ||
818                             col == LColor::ignore)
819                                 break;
820
821                         if (!lcolor.setColor(col, x11_name)) {
822                                 lyxerr << "Bad lyxrc set_color for "
823                                         << lyx_name << endl;
824
825                         }
826                         break;
827                 }
828                 case RC_AUTOREGIONDELETE:
829                         // Auto region delete defaults to true
830                         if (lexrc.next()) {
831                                 auto_region_delete = lexrc.getBool();
832                         }
833                         break;
834
835                 case RC_SERVERPIPE:
836                         if (lexrc.next()) {
837                                 lyxpipes = ExpandPath(lexrc.getString());
838                         }
839                         break;
840
841                 case RC_CURSOR_FOLLOWS_SCROLLBAR:
842                         if (lexrc.next()) {
843                                 cursor_follows_scrollbar = lexrc.getBool();
844                         }
845                         break;
846
847                 case RC_DIALOGS_ICONIFY_WITH_MAIN:
848                         if (lexrc.next()) {
849                                 dialogs_iconify_with_main = lexrc.getBool();
850                         }
851                         break;
852
853                 case RC_ASCIIROFF_COMMAND:
854                         if (lexrc.next()) {
855                                 ascii_roff_command = lexrc.getString();
856                         }
857                         break;
858                 case RC_ASCII_LINELEN:
859                         if (lexrc.next()) {
860                                 ascii_linelen = lexrc.getInteger();
861                         }
862                         break;
863                         // Spellchecker settings:
864                 case RC_USE_SPELL_LIB:
865                         if (lexrc.next()) {
866                                 use_spell_lib = lexrc.getBool();
867                         }
868                         break;
869                 case RC_SPELL_COMMAND:
870                         if (lexrc.next()) {
871                                 isp_command = lexrc.getString();
872                         }
873                         break;
874                 case RC_ACCEPT_COMPOUND:
875                         if (lexrc.next()) {
876                                 isp_accept_compound = lexrc.getBool();
877                         }
878                         break;
879                 case RC_USE_INP_ENC:
880                         if (lexrc.next()) {
881                                 isp_use_input_encoding = lexrc.getBool();
882                         }
883                         break;
884                 case RC_USE_ALT_LANG:
885                         if (lexrc.next()) {
886                                 isp_use_alt_lang = lexrc.getBool();
887                         }
888                         break;
889                 case RC_USE_PERS_DICT:
890                         if (lexrc.next()) {
891                                 isp_use_pers_dict = lexrc.getBool();
892                         }
893                         break;
894                 case RC_USE_ESC_CHARS:
895                         if (lexrc.next()) {
896                                 isp_use_esc_chars = lexrc.getBool();
897                         }
898                         break;
899                 case RC_ALT_LANG:
900                         if (lexrc.next()) {
901                                 isp_alt_lang = lexrc.getString();
902                         }
903                         break;
904                 case RC_PERS_DICT:
905                         if (lexrc.next()) {
906                                 isp_pers_dict = lexrc.getString();
907                         }
908                         break;
909                 case RC_ESC_CHARS:
910                         if (lexrc.next()) {
911                                 isp_esc_chars = lexrc.getString();
912                         }
913                         break;
914                 case RC_MAKE_BACKUP:
915                         if (lexrc.next()) {
916                                 make_backup = lexrc.getBool();
917                         }
918                         break;
919                 case RC_BACKUPDIR_PATH:
920                         if (lexrc.next()) {
921                                 backupdir_path = ExpandPath(lexrc.getString());
922                         }
923                         break;
924                 case RC_DATE_INSERT_FORMAT:
925                         if (lexrc.next()) {
926                                 date_insert_format = lexrc.getString();
927                         }
928                         break;
929                 case RC_LANGUAGE_PACKAGE:
930                         if (lexrc.next()) {
931                                 language_package = lexrc.getString();
932                         }
933                         break;
934                 case RC_LANGUAGE_AUTO_BEGIN:
935                         if (lexrc.next()) {
936                                 language_auto_begin = lexrc.getBool();
937                         }
938                         break;
939                 case RC_LANGUAGE_AUTO_END:
940                         if (lexrc.next()) {
941                                 language_auto_end = lexrc.getBool();
942                         }
943                         break;
944                 case RC_LANGUAGE_GLOBAL_OPTIONS:
945                         if (lexrc.next()) {
946                                 language_global_options = lexrc.getBool();
947                         }
948                         break;
949                 case RC_LANGUAGE_USE_BABEL:
950                         if (lexrc.next()) {
951                                 language_use_babel = lexrc.getBool();
952                         }
953                         break;
954                 case RC_LANGUAGE_COMMAND_BEGIN:
955                         if (lexrc.next()) {
956                                 language_command_begin = lexrc.getString();
957                         }
958                         break;
959                 case RC_LANGUAGE_COMMAND_END:
960                         if (lexrc.next()) {
961                                 language_command_end = lexrc.getString();
962                         }
963                         break;
964                 case RC_LANGUAGE_COMMAND_LOCAL:
965                         if (lexrc.next()) {
966                                 language_command_local = lexrc.getString();
967                         }
968                         break;
969                 case RC_RTL_SUPPORT:
970                         if (lexrc.next()) {
971                                 rtl_support = lexrc.getBool();
972                         }
973                         break;
974                 case RC_AUTO_NUMBER:
975                         if (lexrc.next()) {
976                                 auto_number = lexrc.getBool();
977                         }
978                         break;
979                 case RC_MARK_FOREIGN_LANGUAGE:
980                         if (lexrc.next()) {
981                                 mark_foreign_language = lexrc.getBool();
982                         }
983                         break;
984
985                 case RC_COPIER: {
986                         string fmt, command;
987                         if (lexrc.next()) {
988                                 fmt = lexrc.getString();
989                         }
990                         if (lexrc.next()) {
991                                 command = lexrc.getString();
992                         }
993                         movers.set(fmt, command);
994                         break;
995                 }
996
997                 case RC_CONVERTER: {
998                         string from, to, command, flags;
999                         if (lexrc.next()) {
1000                                 from = lexrc.getString();
1001                         }
1002                         if (lexrc.next()) {
1003                                 to = lexrc.getString();
1004                         }
1005                         if (lexrc.next()) {
1006                                 command = lexrc.getString();
1007                         }
1008                         if (lexrc.next()) {
1009                                 flags = lexrc.getString();
1010                         }
1011                         if (command.empty()
1012                             || token(command, ' ', 0) == "none") {
1013                                 converters.erase(from, to);
1014                         } else {
1015                                 converters.add(from, to, command, flags);
1016                         }
1017                         break;
1018                 }
1019                 // compatibility with versions older than 1.4.0 only
1020                 case RC_VIEWER: {
1021                         string format, command;
1022                         if (lexrc.next()) {
1023                                 format = lexrc.getString();
1024                         }
1025                         if (lexrc.next()) {
1026                                 command = lexrc.getString();
1027                                 if (token(command, ' ', 0) == "none")
1028                                         command.erase();
1029                         }
1030                         formats.setViewer(format, command);
1031                         break;
1032                 }
1033                 case RC_FORMAT: {
1034                         string format, extension, prettyname, shortcut;
1035                         if (lexrc.next()) {
1036                                 format = lexrc.getString();
1037                         }
1038                         if (lexrc.next()) {
1039                                 extension = lexrc.getString();
1040                         }
1041                         if (lexrc.next()) {
1042                                 prettyname = lexrc.getString();
1043                         }
1044                         if (lexrc.next()) {
1045                                 shortcut = lexrc.getString();
1046                         }
1047                         string viewer, editor;
1048                         // Hack to ensure compatibility with versions older
1049                         // than 1.4.0
1050                         int le = lexrc.lex();
1051                         if (le != LyXLex::LEX_FEOF && le != LyXLex::LEX_UNDEF) {
1052                                 viewer = lexrc.getString();
1053                                 if (le == LyXLex::LEX_DATA) {
1054                                         if (token(viewer, ' ', 0) == "none")
1055                                                 viewer.erase();
1056                                         if (lexrc.next()) {
1057                                                 editor = lexrc.getString();
1058                                                 if (token(editor, ' ', 0) == "none")
1059                                                         editor.erase();
1060                                         }
1061                                 } else {
1062                                         // We have got a known token.
1063                                         // Therefore this is an old style
1064                                         // format definition without
1065                                         // viewer and editor.
1066                                         lexrc.pushToken(viewer);
1067                                         viewer.erase();
1068                                 }
1069                         }
1070                         if (prettyname.empty()) {
1071                                 if (converters.formatIsUsed(format)) {
1072                                         lyxerr << "Can't delete format "
1073                                                << format << endl;
1074                                 } else {
1075                                         formats.erase(format);
1076                                 }
1077                         } else {
1078                                 formats.add(format, extension, prettyname,
1079                                             shortcut, viewer, editor);
1080                         }
1081                         break;
1082                 }
1083                 case RC_DEFAULT_LANGUAGE:
1084                         if (lexrc.next()) {
1085                                 default_language = lexrc.getString();
1086                         }
1087                         break;
1088
1089                 case RC_LABEL_INIT_LENGTH:
1090                         if (lexrc.next()) {
1091                                 label_init_length = lexrc.getInteger();
1092                         }
1093                         break;
1094
1095                 case RC_SHOW_BANNER:
1096                         if (lexrc.next()) {
1097                                 show_banner = lexrc.getBool();
1098                         }
1099                         break;
1100
1101                 case RC_PREVIEW:
1102                         if (lexrc.next()) {
1103                                 string const tmp = lexrc.getString();
1104                                 if (tmp == "true" || tmp == "on")
1105                                         preview = PREVIEW_ON;
1106                                 else if (tmp == "no_math")
1107                                         preview = PREVIEW_NO_MATH;
1108                                 else {
1109                                         preview = PREVIEW_OFF;
1110                                         if (tmp != "false" && tmp != "off")
1111                                                 lyxerr << "Unrecognized "
1112                                                         "preview status \""
1113                                                        << tmp << '\n' << endl;
1114                                 }
1115                         }
1116                         break;
1117
1118                 case RC_PREVIEW_HASHED_LABELS:
1119                         if (lexrc.next()) {
1120                                 preview_hashed_labels = lexrc.getBool();
1121                         }
1122                         break;
1123
1124                 case RC_PREVIEW_SCALE_FACTOR:
1125                         if (lexrc.next()) {
1126                                 preview_scale_factor = lexrc.getString();
1127                         }
1128                         break;
1129
1130                 case RC_USER_NAME:
1131                         if (lexrc.next())
1132                                 user_name = lexrc.getString();
1133                         break;
1134
1135                 case RC_USER_EMAIL:
1136                         if (lexrc.next())
1137                                 user_email = lexrc.getString();
1138                         break;
1139
1140                 case RC_PATH_PREFIX:
1141                         if (lexrc.next())
1142                                 path_prefix = lexrc.getString();
1143                         break;
1144
1145                 case RC_LAST: break; // this is just a dummy
1146                 }
1147         }
1148
1149         /// Update converters data-structures
1150         converters.update(formats);
1151         converters.buildGraph();
1152
1153         return 0;
1154 }
1155
1156
1157 void LyXRC::write(string const & filename, bool ignore_system_lyxrc) const
1158 {
1159         ofstream ofs(filename.c_str());
1160         if (ofs)
1161                 write(ofs, ignore_system_lyxrc);
1162 }
1163
1164
1165 void LyXRC::print() const
1166 {
1167         if (lyxerr.debugging())
1168                 write(lyxerr, false);
1169         else
1170                 write(cout, false);
1171 }
1172
1173
1174 class SameMover {
1175 public:
1176         typedef std::pair<std::string, SpecialisedMover> Data;
1177
1178         SameMover(Data const & comparison)
1179                 : comparison_(comparison) {}
1180
1181         bool operator()(Data const & data) const
1182         {
1183                 return data.first == comparison_.first &&
1184                         data.second.command() == comparison_.second.command();
1185         }
1186
1187 private:
1188         Data comparison_;
1189 };
1190
1191
1192 void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
1193 {
1194         os << "### This file is part of\n"
1195            << "### ========================================================\n"
1196            << "###          LyX, The Document Processor\n"
1197            << "###\n"
1198            << "###          Copyright 1995 Matthias Ettrich\n"
1199            << "###          Copyright 1995-2001 The LyX Team.\n"
1200            << "###\n"
1201            << "### ========================================================\n"
1202            << "\n"
1203            << "# This file is written by LyX, if you want to make your own\n"
1204            << "# modifications you should do them from inside LyX and save\n"
1205            << "\n";
1206
1207         // Why the switch you might ask. It is a trick to ensure that all
1208         // the elements in the LyXRCTags enum is handled. As you can see
1209         // there are no breaks at all. So it is just a huge fall-through.
1210         // The nice thing is that we will get a warning from the compiler
1211         // if we forget an element.
1212         LyXRCTags tag = RC_LAST;
1213         switch (tag) {
1214         case RC_LAST:
1215         case RC_INPUT:
1216                 // input/include files are not done here
1217         case RC_BINDFILE:
1218                 if (ignore_system_lyxrc ||
1219                     bind_file != system_lyxrc.bind_file) {
1220                         os << "\\bind_file " << bind_file << "\n";
1221                 }
1222                 //
1223                 // Misc Section
1224                 //
1225                 os << "\n#\n"
1226                    << "# MISC SECTION ######################################\n"
1227                    << "#\n\n";
1228
1229                 // bind files are not done here.
1230
1231         case RC_PATH_PREFIX:
1232                 if (ignore_system_lyxrc ||
1233                     path_prefix != system_lyxrc.path_prefix) {
1234                         os << "\\path_prefix \"" << path_prefix << "\"\n";
1235                 }
1236
1237         case RC_UIFILE:
1238                 if (ignore_system_lyxrc ||
1239                     ui_file != system_lyxrc.ui_file) {
1240                         os << "\\ui_file \"" << ui_file << "\"\n";
1241                 }
1242         case RC_AUTOREGIONDELETE:
1243                 if (ignore_system_lyxrc ||
1244                     auto_region_delete != system_lyxrc.auto_region_delete) {
1245                         os << "# Set to false to inhibit automatic replacement of\n"
1246                            << "# the current selection.\n"
1247                            << "\\auto_region_delete " << convert<string>(auto_region_delete)
1248                            << '\n';
1249                 }
1250         case RC_AUTORESET_OPTIONS:
1251                 if (ignore_system_lyxrc ||
1252                     auto_reset_options != system_lyxrc.auto_reset_options) {
1253                         os << "# Set to false to inhibit automatic reset of\n"
1254                            << "# the class options to defaults on class change.\n"
1255                            << "\\auto_reset_options "
1256                            << convert<string>(auto_reset_options)
1257                            << '\n';
1258                 }
1259         case RC_AUTOSAVE:
1260                 if (ignore_system_lyxrc ||
1261                     autosave != system_lyxrc.autosave) {
1262                         os << "# The time interval between auto-saves in seconds.\n"
1263                            << "\\autosave " << autosave << '\n';
1264                 }
1265         case RC_DISPLAY_GRAPHICS:
1266                 if (ignore_system_lyxrc ||
1267                     display_graphics != system_lyxrc.display_graphics) {
1268                         os << "# Display graphics within LyX\n"
1269                            << "# monochrome|grayscale|color|none\n"
1270                            << "\\display_graphics "
1271                            << lyx::graphics::displayTranslator().find(display_graphics)
1272                            << '\n';
1273                 }
1274
1275         case RC_VIEWDVI_PAPEROPTION:
1276                 if (ignore_system_lyxrc ||
1277                     view_dvi_paper_option
1278                     != system_lyxrc.view_dvi_paper_option) {
1279                         os << "# Options used to specify paper size to the\n"
1280                            << "# view_dvi_command (e.g. -paper)\n"
1281                            << "\\view_dvi_paper_option \""
1282                            << view_dvi_paper_option << "\"\n";
1283                 }
1284         case RC_DEFAULT_PAPERSIZE:
1285                 if (ignore_system_lyxrc ||
1286                     default_papersize != system_lyxrc.default_papersize) {
1287                         os << "# The default papersize to use.\n"
1288                            << "\\default_papersize \"";
1289                         switch (default_papersize) {
1290                         case PAPER_USLETTER:
1291                                 os << "usletter"; break;
1292                         case PAPER_LEGALPAPER:
1293                                 os << "legal"; break;
1294                         case PAPER_EXECUTIVEPAPER:
1295                                 os << "executive"; break;
1296                         case PAPER_A3PAPER:
1297                                 os << "a3"; break;
1298                         case PAPER_A4PAPER:
1299                                 os << "a4"; break;
1300                         case PAPER_A5PAPER:
1301                                 os << "a5"; break;
1302                         case PAPER_B5PAPER:
1303                                 os << "b5"; break;
1304                         case PAPER_DEFAULT: break;
1305                         }
1306                         os << "\"\n";
1307                 }
1308         case RC_CHKTEX_COMMAND:
1309                 if (ignore_system_lyxrc ||
1310                     chktex_command != system_lyxrc.chktex_command) {
1311                         os << "\\chktex_command \"" << chktex_command << "\"\n";
1312                 }
1313         case RC_BIBTEX_COMMAND:
1314                 if (ignore_system_lyxrc ||
1315                     bibtex_command != system_lyxrc.bibtex_command) {
1316                         os << "\\bibtex_command \"" << bibtex_command << "\"\n";
1317                 }
1318         case RC_INDEX_COMMAND:
1319                 if (ignore_system_lyxrc ||
1320                     index_command != system_lyxrc.index_command) {
1321                         os << "\\index_command \"" << index_command << "\"\n";
1322                 }
1323         case RC_CYGWIN_PATH_FIX:
1324                 if (ignore_system_lyxrc ||
1325                     cygwin_path_fix != system_lyxrc.cygwin_path_fix) {
1326                         os << "\\cygwin_path_fix_needed "
1327                            << convert<string>(cygwin_path_fix) << '\n';
1328                 }
1329         case RC_TEX_ALLOWS_SPACES:
1330                 if (tex_allows_spaces != system_lyxrc.tex_allows_spaces) {
1331                         os << "\\tex_allows_spaces "
1332                            << convert<string>(tex_allows_spaces) << '\n';
1333                 }
1334         case RC_KBMAP:
1335                 if (ignore_system_lyxrc ||
1336                     use_kbmap != system_lyxrc.use_kbmap) {
1337                         os << "\\kbmap " << convert<string>(use_kbmap) << '\n';
1338                 }
1339         case RC_KBMAP_PRIMARY:
1340                 if (ignore_system_lyxrc ||
1341                     primary_kbmap != system_lyxrc.primary_kbmap) {
1342                         os << "\\kbmap_primary \"" << primary_kbmap << "\"\n";
1343                 }
1344         case RC_KBMAP_SECONDARY:
1345                 if (ignore_system_lyxrc ||
1346                     secondary_kbmap != system_lyxrc.secondary_kbmap) {
1347                         os << "\\kbmap_secondary \"" << secondary_kbmap
1348                            << "\"\n";
1349                 }
1350         case RC_SERVERPIPE:
1351                 if (ignore_system_lyxrc ||
1352                     lyxpipes != system_lyxrc.lyxpipes) {
1353                         os << "\\serverpipe \"" << lyxpipes << "\"\n";
1354                 }
1355         case RC_DATE_INSERT_FORMAT:
1356                 if (ignore_system_lyxrc ||
1357                     date_insert_format != system_lyxrc.date_insert_format) {
1358                         os << "\\date_insert_format \"" << date_insert_format
1359                            << "\"\n";
1360                 }
1361         case RC_LABEL_INIT_LENGTH:
1362                 if (ignore_system_lyxrc ||
1363                     label_init_length != system_lyxrc.label_init_length) {
1364                         os << "\\label_init_length " << label_init_length
1365                            << '\n';
1366                 }
1367
1368         case RC_USER_NAME:
1369                 os << "\\user_name \"" << user_name << "\"\n";
1370
1371         case RC_USER_EMAIL:
1372                 os << "\\user_email \"" << user_email << "\"\n";
1373
1374         case RC_SHOW_BANNER:
1375                 if (ignore_system_lyxrc ||
1376                     show_banner != system_lyxrc.show_banner) {
1377                         os << "\\show_banner " << convert<string>(show_banner) << '\n';
1378                 }
1379
1380         case RC_PREVIEW:
1381                 if (ignore_system_lyxrc ||
1382                     preview != system_lyxrc.preview) {
1383                         string status;
1384                         switch (preview) {
1385                         case PREVIEW_ON:
1386                                 status = "on";
1387                                 break;
1388                         case PREVIEW_NO_MATH:
1389                                 status = "no_math";
1390                                 break;
1391                         case PREVIEW_OFF:
1392                                 status = "off";
1393                                 break;
1394                         }
1395                         os << "\\preview " << status << '\n';
1396                 }
1397
1398         case RC_PREVIEW_HASHED_LABELS:
1399                 if (ignore_system_lyxrc ||
1400                     preview_hashed_labels !=
1401                     system_lyxrc.preview_hashed_labels) {
1402                         os << "\\preview_hashed_labels "
1403                            << convert<string>(preview_hashed_labels) << '\n';
1404                 }
1405
1406         case RC_PREVIEW_SCALE_FACTOR:
1407                 if (ignore_system_lyxrc ||
1408                     preview_scale_factor != system_lyxrc.preview_scale_factor) {
1409                         os << "\\preview_scale_factor "
1410                            << preview_scale_factor << '\n';
1411                 }
1412
1413                 os << "\n#\n"
1414                    << "# SCREEN & FONTS SECTION ############################\n"
1415                    << "#\n\n";
1416
1417         case RC_POPUP_NORMAL_FONT:
1418                 if (ignore_system_lyxrc ||
1419                     popup_normal_font != system_lyxrc.popup_normal_font) {
1420                         os << "\\popup_normal_font \"" << popup_normal_font
1421                            << "\"\n";
1422                 }
1423         case RC_POPUP_BOLD_FONT:
1424                 if (ignore_system_lyxrc ||
1425                     popup_bold_font != system_lyxrc.popup_bold_font) {
1426                         os << "\\popup_bold_font \"" << popup_bold_font
1427                            << "\"\n";
1428                 }
1429         case RC_POPUP_FONT_ENCODING:
1430                 if (ignore_system_lyxrc ||
1431                     popup_font_encoding != system_lyxrc.popup_font_encoding) {
1432                         os << "\\popup_font_encoding \"" << popup_font_encoding
1433                            << "\"\n";
1434                 }
1435         case RC_SCREEN_DPI:
1436                 if (ignore_system_lyxrc ||
1437                     dpi != system_lyxrc.dpi) {
1438                         os << "\\screen_dpi " << dpi << '\n';
1439                 }
1440         case RC_SCREEN_ZOOM:
1441                 if (ignore_system_lyxrc ||
1442                     zoom != system_lyxrc.zoom) {
1443                         os << "\\screen_zoom " << zoom << '\n';
1444                 }
1445         case RC_WHEEL_JUMP:
1446                 if (ignore_system_lyxrc ||
1447                     wheel_jump != system_lyxrc.wheel_jump) {
1448                         os << "\\wheel_jump " << wheel_jump << '\n';
1449                 }
1450         case RC_CURSOR_FOLLOWS_SCROLLBAR:
1451                 if (ignore_system_lyxrc ||
1452                     cursor_follows_scrollbar
1453                     != system_lyxrc.cursor_follows_scrollbar) {
1454                         os << "\\cursor_follows_scrollbar "
1455                            << convert<string>(cursor_follows_scrollbar) << '\n';
1456                 }
1457         case RC_DIALOGS_ICONIFY_WITH_MAIN:
1458                 if (ignore_system_lyxrc ||
1459                     dialogs_iconify_with_main
1460                    != system_lyxrc.dialogs_iconify_with_main) {
1461                         os << "\\dialogs_iconify_with_main "
1462                           <<  convert<string>(dialogs_iconify_with_main) << '\n';
1463                 }
1464         case RC_SCREEN_FONT_ROMAN:
1465                 if (ignore_system_lyxrc ||
1466                     roman_font_name != system_lyxrc.roman_font_name) {
1467                         os << "\\screen_font_roman \"" << roman_font_name
1468                            << "\"\n";
1469                 }
1470         case RC_SCREEN_FONT_ROMAN_FOUNDRY:
1471                 if (ignore_system_lyxrc ||
1472                     roman_font_foundry != system_lyxrc.roman_font_foundry) {
1473                         os << "\\screen_font_roman_foundry \"" << roman_font_foundry
1474                            << "\"\n";
1475                 }
1476         case RC_SCREEN_FONT_SANS:
1477                 if (ignore_system_lyxrc ||
1478                     sans_font_name != system_lyxrc.sans_font_name) {
1479                         os << "\\screen_font_sans \"" << sans_font_name
1480                            << "\"\n";
1481                 }
1482         case RC_SCREEN_FONT_SANS_FOUNDRY:
1483                 if (ignore_system_lyxrc ||
1484                     sans_font_foundry != system_lyxrc.sans_font_foundry) {
1485                         os << "\\screen_font_sans_foundry \"" << sans_font_foundry
1486                            << "\"\n";
1487                 }
1488         case RC_SCREEN_FONT_TYPEWRITER:
1489                 if (ignore_system_lyxrc ||
1490                     typewriter_font_name != system_lyxrc.typewriter_font_name) {
1491                         os << "\\screen_font_typewriter \""
1492                            << typewriter_font_name << "\"\n";
1493                 }
1494         case RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
1495                 if (ignore_system_lyxrc ||
1496                     typewriter_font_foundry != system_lyxrc.typewriter_font_foundry) {
1497                         os << "\\screen_font_typewriter_foundry \""
1498                            << typewriter_font_foundry << "\"\n";
1499                 }
1500
1501         case RC_SCREEN_FONT_SCALABLE:
1502                 if (ignore_system_lyxrc ||
1503                     use_scalable_fonts != system_lyxrc.use_scalable_fonts) {
1504                         os << "\\screen_font_scalable "
1505                            << convert<string>(use_scalable_fonts)
1506                            << '\n';
1507                 }
1508         case RC_SCREEN_FONT_ENCODING:
1509                 if (ignore_system_lyxrc ||
1510                     font_norm != system_lyxrc.font_norm) {
1511                         os << "\\screen_font_encoding \"" << font_norm
1512                            << "\"\n";
1513                 }
1514         case RC_SCREEN_FONT_SIZES:
1515                 if (ignore_system_lyxrc ||
1516                     font_sizes[LyXFont::SIZE_TINY]
1517                     != system_lyxrc.font_sizes[LyXFont::SIZE_TINY] ||
1518                     font_sizes[LyXFont::SIZE_SCRIPT]
1519                     != system_lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] ||
1520                     font_sizes[LyXFont::SIZE_FOOTNOTE]
1521                     != system_lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] ||
1522                     font_sizes[LyXFont::SIZE_SMALL]
1523                     != system_lyxrc.font_sizes[LyXFont::SIZE_SMALL] ||
1524                     font_sizes[LyXFont::SIZE_NORMAL]
1525                     != system_lyxrc.font_sizes[LyXFont::SIZE_NORMAL] ||
1526                     font_sizes[LyXFont::SIZE_LARGE]
1527                     != system_lyxrc.font_sizes[LyXFont::SIZE_LARGE] ||
1528                     font_sizes[LyXFont::SIZE_LARGER]
1529                     != system_lyxrc.font_sizes[LyXFont::SIZE_LARGER] ||
1530                     font_sizes[LyXFont::SIZE_LARGEST]
1531                     != system_lyxrc.font_sizes[LyXFont::SIZE_LARGEST] ||
1532                     font_sizes[LyXFont::SIZE_HUGE]
1533                     != system_lyxrc.font_sizes[LyXFont::SIZE_HUGE] ||
1534                     font_sizes[LyXFont::SIZE_HUGER]
1535                     != system_lyxrc.font_sizes[LyXFont::SIZE_HUGER]) {
1536                         os.setf(ios::fixed);
1537                         os.precision(2);
1538                         os << "\\screen_font_sizes"
1539                            << ' ' << font_sizes[LyXFont::SIZE_TINY]
1540                            << ' ' << font_sizes[LyXFont::SIZE_SCRIPT]
1541                            << ' ' << font_sizes[LyXFont::SIZE_FOOTNOTE]
1542                            << ' ' << font_sizes[LyXFont::SIZE_SMALL]
1543                            << ' ' << font_sizes[LyXFont::SIZE_NORMAL]
1544                            << ' ' << font_sizes[LyXFont::SIZE_LARGE]
1545                            << ' ' << font_sizes[LyXFont::SIZE_LARGER]
1546                            << ' ' << font_sizes[LyXFont::SIZE_LARGEST]
1547                            << ' ' << font_sizes[LyXFont::SIZE_HUGE]
1548                            << ' ' << font_sizes[LyXFont::SIZE_HUGER]
1549                            << '\n';
1550                 }
1551
1552                 os << "\n#\n"
1553                    << "# COLOR SECTION ###################################\n"
1554                    << "#\n\n";
1555
1556         case RC_SET_COLOR:
1557                 for (int i = 0; i < LColor::ignore; ++i) {
1558                         LColor::color lc = static_cast<LColor::color>(i);
1559
1560                         string const col(lcolor.getX11Name(lc));
1561                         if (ignore_system_lyxrc ||
1562                             col != system_lcolor.getX11Name(lc)) {
1563                                 os << "\\set_color \""
1564                                    << lcolor.getLyXName(lc) << "\" \""
1565                                    << col << "\"\n";
1566                         }
1567                 }
1568
1569                 os << "\n#\n"
1570                    << "# PRINTER SECTION ###################################\n"
1571                    << "#\n\n";
1572
1573         case RC_PRINTER:
1574                 if (ignore_system_lyxrc ||
1575                     printer != system_lyxrc.printer) {
1576                         os << "\\printer \"" << printer << "\"\n";
1577                 }
1578         case RC_PRINT_ADAPTOUTPUT:
1579                 if (ignore_system_lyxrc ||
1580                     print_adapt_output != system_lyxrc.print_adapt_output) {
1581                         os << "\\print_adapt_output "
1582                            << convert<string>(print_adapt_output)
1583                            << '\n';
1584                 }
1585         case RC_PRINT_COMMAND:
1586                 if (ignore_system_lyxrc ||
1587                     print_command != system_lyxrc.print_command) {
1588                         os << "\\print_command \"" << print_command << "\"\n";
1589                 }
1590         case RC_PRINTEXSTRAOPTIONS:
1591                 if (ignore_system_lyxrc ||
1592                     print_extra_options != system_lyxrc.print_extra_options) {
1593                         os << "\\print_extra_options \"" << print_extra_options
1594                            << "\"\n";
1595                 }
1596         case RC_PRINTSPOOL_COMMAND:
1597                 if (ignore_system_lyxrc ||
1598                     print_spool_command != system_lyxrc.print_spool_command) {
1599                         os << "\\print_spool_command \"" << print_spool_command
1600                            << "\"\n";
1601                 }
1602         case RC_PRINTSPOOL_PRINTERPREFIX:
1603                 if (ignore_system_lyxrc ||
1604                     print_spool_printerprefix
1605                     != system_lyxrc.print_spool_printerprefix) {
1606                         os << "\\print_spool_printerprefix \""
1607                            << print_spool_printerprefix << "\"\n";
1608                 }
1609         case RC_PRINTEVENPAGEFLAG:
1610                 if (ignore_system_lyxrc ||
1611                     print_evenpage_flag != system_lyxrc.print_evenpage_flag) {
1612                         os << "\\print_evenpage_flag \"" << print_evenpage_flag
1613                            << "\"\n";
1614                 }
1615         case RC_PRINTODDPAGEFLAG:
1616                 if (ignore_system_lyxrc ||
1617                     print_oddpage_flag != system_lyxrc.print_oddpage_flag) {
1618                         os << "\\print_oddpage_flag \"" << print_oddpage_flag
1619                            << "\"\n";
1620                 }
1621         case RC_PRINTREVERSEFLAG:
1622                 if (ignore_system_lyxrc ||
1623                     print_reverse_flag != system_lyxrc.print_reverse_flag) {
1624                         os << "\\print_reverse_flag \"" << print_reverse_flag
1625                            << "\"\n";
1626                 }
1627         case RC_PRINTLANDSCAPEFLAG:
1628                 if (ignore_system_lyxrc ||
1629                     print_landscape_flag != system_lyxrc.print_landscape_flag) {
1630                         os << "\\print_landscape_flag \"" << print_landscape_flag
1631                            << "\"\n";
1632                 }
1633         case RC_PRINTPAGERANGEFLAG:
1634                 if (ignore_system_lyxrc ||
1635                     print_pagerange_flag != system_lyxrc.print_pagerange_flag) {
1636                         os << "\\print_pagerange_flag \"" << print_pagerange_flag
1637                            << "\"\n";
1638                 }
1639         case RC_PRINTCOPIESFLAG:
1640                 if (ignore_system_lyxrc ||
1641                     print_copies_flag != system_lyxrc.print_copies_flag) {
1642                         os << "\\print_copies_flag \"" << print_copies_flag
1643                            << "\"\n";
1644                 }
1645         case RC_PRINTCOLLCOPIESFLAG:
1646                 if (ignore_system_lyxrc ||
1647                     print_collcopies_flag
1648                     != system_lyxrc.print_collcopies_flag) {
1649                         os << "\\print_collcopies_flag \""
1650                            << print_collcopies_flag
1651                            << "\"\n";
1652                 }
1653         case RC_PRINTPAPERFLAG:
1654                 if (ignore_system_lyxrc ||
1655                     print_paper_flag != system_lyxrc.print_paper_flag) {
1656                         os << "\\print_paper_flag \"" << print_paper_flag
1657                            << "\"\n";
1658                 }
1659         case RC_PRINTPAPERDIMENSIONFLAG:
1660                 if (ignore_system_lyxrc ||
1661                     print_paper_dimension_flag
1662                     != system_lyxrc.print_paper_dimension_flag) {
1663                         os << "\\print_paper_dimension_flag \""
1664                            << print_paper_dimension_flag << "\"\n";
1665                 }
1666         case RC_PRINTTOPRINTER:
1667                 if (ignore_system_lyxrc ||
1668                     print_to_printer != system_lyxrc.print_to_printer) {
1669                         os << "\\print_to_printer \"" << print_to_printer
1670                            << "\"\n";
1671                 }
1672         case RC_PRINTTOFILE:
1673                 if (ignore_system_lyxrc ||
1674                     print_to_file != system_lyxrc.print_to_file) {
1675                         os << "\\print_to_file \"" << print_to_file << "\"\n";
1676                 }
1677         case RC_PRINTFILEEXTENSION:
1678                 if (ignore_system_lyxrc ||
1679                     print_file_extension != system_lyxrc.print_file_extension) {
1680                         os << "\\print_file_extension \""
1681                            << print_file_extension
1682                            << "\"\n";
1683                 }
1684
1685                 os << "\n#\n"
1686                    << "# EXPORT SECTION ####################################\n"
1687                    << "#\n\n";
1688
1689         case RC_CUSTOM_EXPORT_COMMAND:
1690                 if (ignore_system_lyxrc ||
1691                     custom_export_command
1692                     != system_lyxrc.custom_export_command) {
1693                         os << "\\custom_export_command \""
1694                            << custom_export_command
1695                            << "\"\n";
1696                 }
1697         case RC_CUSTOM_EXPORT_FORMAT:
1698                 if (ignore_system_lyxrc ||
1699                     custom_export_format
1700                     != system_lyxrc.custom_export_format) {
1701                         os << "\\custom_export_format \"" << custom_export_format
1702                            << "\"\n";
1703                 }
1704
1705                 os << "\n#\n"
1706                    << "# TEX SECTION #######################################\n"
1707                    << "#\n\n";
1708
1709         case RC_FONT_ENCODING:
1710                 if (ignore_system_lyxrc ||
1711                     fontenc != system_lyxrc.fontenc) {
1712                         os << "\\font_encoding \"" << fontenc << "\"\n";
1713                 }
1714
1715                 os << "\n#\n"
1716                    << "# FILE SECTION ######################################\n"
1717                    << "#\n\n";
1718
1719         case RC_DOCUMENTPATH:
1720                 if (ignore_system_lyxrc ||
1721                     document_path != system_lyxrc.document_path) {
1722                         os << "\\document_path \"" << document_path << "\"\n";
1723                 }
1724         case RC_LASTFILES:
1725                 if (ignore_system_lyxrc ||
1726                     lastfiles != system_lyxrc.lastfiles) {
1727                         os << "\\lastfiles \"" << lastfiles << "\"\n";
1728                 }
1729         case RC_NUMLASTFILES:
1730                 if (ignore_system_lyxrc ||
1731                     num_lastfiles != system_lyxrc.num_lastfiles) {
1732                         os << "\\num_lastfiles " << num_lastfiles << '\n';
1733                 }
1734         case RC_CHECKLASTFILES:
1735                 if (ignore_system_lyxrc ||
1736                     check_lastfiles != system_lyxrc.check_lastfiles) {
1737                         os << "\\check_lastfiles " << convert<string>(check_lastfiles)
1738                            << '\n';
1739                 }
1740         case RC_TEMPLATEPATH:
1741                 if (ignore_system_lyxrc ||
1742                     template_path != system_lyxrc.template_path) {
1743                         os << "\\template_path \"" << template_path << "\"\n";
1744                 }
1745         case RC_TEMPDIRPATH:
1746                 if (ignore_system_lyxrc ||
1747                     tempdir_path != system_lyxrc.tempdir_path) {
1748                         os << "\\tempdir_path \"" << tempdir_path << "\"\n";
1749                 }
1750         case RC_USETEMPDIR:
1751                 // Ignore it
1752         case RC_ASCII_LINELEN:
1753                 if (ignore_system_lyxrc ||
1754                     ascii_linelen != system_lyxrc.ascii_linelen) {
1755                         os << "\\ascii_linelen " << ascii_linelen << '\n';
1756                 }
1757         case RC_MAKE_BACKUP:
1758                 if (ignore_system_lyxrc ||
1759                     make_backup != system_lyxrc.make_backup) {
1760                         os << "\\make_backup " << convert<string>(make_backup) << '\n';
1761                 }
1762         case RC_BACKUPDIR_PATH:
1763                 if (ignore_system_lyxrc ||
1764                     backupdir_path != system_lyxrc.backupdir_path) {
1765                         os << "\\backupdir_path \"" << backupdir_path << "\"\n";
1766                 }
1767
1768                 os << "\n#\n"
1769                    << "# ASCII EXPORT SECTION ##############################\n"
1770                    << "#\n\n";
1771
1772         case RC_ASCIIROFF_COMMAND:
1773                 if (ignore_system_lyxrc ||
1774                     ascii_roff_command != system_lyxrc.ascii_roff_command) {
1775                         os << "\\ascii_roff_command \"" << ascii_roff_command
1776                            << "\"\n";
1777                 }
1778
1779                 os << "\n#\n"
1780                    << "# SPELLCHECKER SECTION ##############################\n"
1781                    << "#\n\n";
1782         case RC_USE_SPELL_LIB:
1783                 if (ignore_system_lyxrc ||
1784                     use_spell_lib != system_lyxrc.use_spell_lib) {
1785                         os << "\\use_spell_lib " << convert<string>(use_spell_lib) << '\n';
1786                 }
1787         case RC_SPELL_COMMAND:
1788                 if (ignore_system_lyxrc ||
1789                     isp_command != system_lyxrc.isp_command) {
1790                         os << "\\spell_command \"" << isp_command << "\"\n";
1791                 }
1792         case RC_ACCEPT_COMPOUND:
1793                 if (ignore_system_lyxrc ||
1794                     isp_accept_compound != system_lyxrc.isp_accept_compound) {
1795                         os << "\\accept_compound " << convert<string>(isp_accept_compound)
1796                            << '\n';
1797                 }
1798         case RC_USE_ALT_LANG:
1799                 if (ignore_system_lyxrc ||
1800                     isp_use_alt_lang != system_lyxrc.isp_use_alt_lang) {
1801                         os << "\\use_alt_language " << convert<string>(isp_use_alt_lang)
1802                            << '\n';
1803                 }
1804         case RC_ALT_LANG:
1805                 if (ignore_system_lyxrc ||
1806                     isp_alt_lang != system_lyxrc.isp_alt_lang) {
1807                         os << "\\alternate_language \"" << isp_alt_lang
1808                            << "\"\n";
1809                 }
1810         case RC_USE_ESC_CHARS:
1811                 if (ignore_system_lyxrc ||
1812                     isp_use_esc_chars != system_lyxrc.isp_use_esc_chars) {
1813                         os << "\\use_escape_chars " << convert<string>(isp_use_esc_chars)
1814                            << '\n';
1815                 }
1816         case RC_ESC_CHARS:
1817                 if (ignore_system_lyxrc ||
1818                     isp_esc_chars != system_lyxrc.isp_esc_chars) {
1819                         os << "\\escape_chars \"" << isp_esc_chars << "\"\n";
1820                 }
1821         case RC_USE_PERS_DICT:
1822                 if (ignore_system_lyxrc ||
1823                     isp_use_pers_dict != system_lyxrc.isp_use_pers_dict) {
1824                         os << "\\use_personal_dictionary "
1825                            << convert<string>(isp_use_pers_dict)
1826                            << '\n';
1827                 }
1828         case RC_PERS_DICT:
1829                 if (isp_pers_dict != system_lyxrc.isp_pers_dict) {
1830                         os << "\\personal_dictionary \"" << isp_pers_dict
1831                            << "\"\n";
1832                 }
1833         case RC_USE_INP_ENC:
1834                 if (ignore_system_lyxrc ||
1835                     isp_use_input_encoding
1836                     != system_lyxrc.isp_use_input_encoding) {
1837                         os << "\\use_input_encoding "
1838                            << convert<string>(isp_use_input_encoding)
1839                            << '\n';
1840                 }
1841
1842                 os << "\n#\n"
1843                    << "# LANGUAGE SUPPORT SECTION ##########################\n"
1844                    << "#\n\n";
1845
1846         case RC_RTL_SUPPORT:
1847                 if (ignore_system_lyxrc ||
1848                     rtl_support != system_lyxrc.rtl_support) {
1849                         os << "\\rtl " << convert<string>(rtl_support) << '\n';
1850                 }
1851         case RC_LANGUAGE_PACKAGE:
1852                 if (ignore_system_lyxrc ||
1853                     language_package != system_lyxrc.language_package) {
1854                         os << "\\language_package \"" << language_package
1855                            << "\"\n";
1856                 }
1857         case RC_LANGUAGE_GLOBAL_OPTIONS:
1858                 if (ignore_system_lyxrc ||
1859                     language_global_options
1860                     != system_lyxrc.language_global_options) {
1861                         os << "\\language_global_options \""
1862                            << convert<string>(language_global_options)
1863                            << "\"\n";
1864                 }
1865         case RC_LANGUAGE_USE_BABEL:
1866                 if (ignore_system_lyxrc ||
1867                     language_use_babel != system_lyxrc.language_use_babel) {
1868                         os << "\\language_use_babel \""
1869                            << convert<string>(language_use_babel)
1870                            << "\"\n";
1871                 }
1872         case RC_LANGUAGE_COMMAND_BEGIN:
1873                 if (ignore_system_lyxrc ||
1874                     language_command_begin
1875                     != system_lyxrc.language_command_begin) {
1876                         os << "\\language_command_begin \""
1877                            << language_command_begin
1878                            << "\"\n";
1879                 }
1880         case RC_LANGUAGE_COMMAND_END:
1881                 if (ignore_system_lyxrc ||
1882                     language_command_end
1883                     != system_lyxrc.language_command_end) {
1884                         os << "\\language_command_end \"" << language_command_end
1885                            << "\"\n";
1886                 }
1887         case RC_LANGUAGE_COMMAND_LOCAL:
1888                 if (ignore_system_lyxrc ||
1889                     language_command_local
1890                     != system_lyxrc.language_command_local) {
1891                         os << "\\language_command_local \""
1892                            << language_command_local
1893                            << "\"\n";
1894                 }
1895         case RC_LANGUAGE_AUTO_BEGIN:
1896                 if (ignore_system_lyxrc ||
1897                     language_auto_begin != system_lyxrc.language_auto_begin) {
1898                         os << "\\language_auto_begin "
1899                            << convert<string>(language_auto_begin) << '\n';
1900                 }
1901         case RC_LANGUAGE_AUTO_END:
1902                 if (ignore_system_lyxrc ||
1903                     language_auto_end != system_lyxrc.language_auto_end) {
1904                         os << "\\language_auto_end "
1905                            << convert<string>(language_auto_end) << '\n';
1906                 }
1907         case RC_MARK_FOREIGN_LANGUAGE:
1908                 if (ignore_system_lyxrc ||
1909                     mark_foreign_language
1910                     != system_lyxrc.mark_foreign_language) {
1911                         os << "\\mark_foreign_language " <<
1912                                 convert<string>(mark_foreign_language) << '\n';
1913                 }
1914
1915                 os << "\n#\n"
1916                    << "# 2nd MISC SUPPORT SECTION ##########################\n"
1917                    << "#\n\n";
1918
1919         case RC_AUTO_NUMBER:
1920                 if (ignore_system_lyxrc ||
1921                     auto_number != system_lyxrc.auto_number) {
1922                         os << "\\auto_number " << convert<string>(auto_number) << '\n';
1923                 }
1924         case RC_DEFAULT_LANGUAGE:
1925                 if (ignore_system_lyxrc ||
1926                     default_language != system_lyxrc.default_language) {
1927                         os << "\\default_language " << default_language << '\n';
1928                 }
1929
1930                 os << "\n#\n"
1931                    << "# FORMATS SECTION ##########################\n"
1932                    << "#\n\n";
1933
1934         case RC_FORMAT:
1935                 // New/modifed formats
1936                 for (Formats::const_iterator cit = formats.begin();
1937                      cit != formats.end(); ++cit) {
1938                         Format const * format =
1939                                 system_formats.getFormat(cit->name());
1940                         if (!format ||
1941                             format->extension() != cit->extension() ||
1942                             format->prettyname() != cit->prettyname() ||
1943                             format->shortcut() != cit->shortcut() ||
1944                             format->viewer() != cit->viewer() ||
1945                             format->editor() != cit->editor())
1946                                 os << "\\format \"" << cit->name() << "\" \""
1947                                    << cit->extension() << "\" \""
1948                                    << cit->prettyname() << "\" \""
1949                                    << cit->shortcut() << "\" \""
1950                                    << cit->viewer() << "\" \""
1951                                    << cit->editor() << "\"\n";
1952                 }
1953
1954                 // Look for deleted formats
1955                 for (Formats::const_iterator cit = system_formats.begin();
1956                      cit != system_formats.end(); ++cit)
1957                         if (!formats.getFormat(cit->name()))
1958                                 os << "\\format \"" << cit->name()
1959                                    << "\" \"\" \"\" \"\" \"\" \"\"\n";
1960         case RC_VIEWER:
1961                 // Ignore it
1962
1963                 os << "\n#\n"
1964                    << "# CONVERTERS SECTION ##########################\n"
1965                    << "#\n\n";
1966
1967         case RC_CONVERTER:
1968                 // Look for new converters
1969                 for (Converters::const_iterator cit = converters.begin();
1970                      cit != converters.end(); ++cit) {
1971                         Converter const * converter =
1972                                 system_converters.getConverter(cit->from,
1973                                                                cit->to);
1974                         if (!converter ||
1975                             converter->command != cit->command ||
1976                             converter->flags != cit->flags)
1977                                 os << "\\converter \"" << cit->from << "\" \""
1978                                    << cit->to << "\" \""
1979                                    << cit->command << "\" \""
1980                                    << cit->flags << "\"\n";
1981                 }
1982
1983                 // New/modifed converters
1984                 for (Converters::const_iterator cit = system_converters.begin();
1985                      cit != system_converters.end(); ++cit)
1986                         if (!converters.getConverter(cit->from, cit->to))
1987                                 os << "\\converter \"" << cit->from
1988                                    << "\" \"" << cit->to << "\" \"\" \"\"\n";
1989
1990         case RC_COPIER:
1991                 os << "\n#\n"
1992                    << "# COPIERS SECTION ##########################\n"
1993                    << "#\n\n";
1994
1995                 // Look for new movers
1996                 Movers::iterator const sysbegin = system_movers.begin();
1997                 Movers::iterator const sysend = system_movers.end();
1998
1999                 for (Movers::iterator it = movers.begin(), end = movers.end();
2000                      it != end; ++it) {
2001                         Movers::iterator const sysit =
2002                                 std::find_if(sysbegin, sysend, SameMover(*it));
2003                         if (sysit == sysend) {
2004                                 std::string const & fmt = it->first;
2005                                 std::string const & command =
2006                                         it->second.command();
2007
2008                                 os << "\\copier " << fmt
2009                                    << " \"" << command << "\"\n";
2010                         }
2011                 }
2012
2013                 // We don't actually delete SpecialisedMover(s) from the
2014                 // map, just clear their 'command', so there's no need
2015                 // to test for anything else.
2016         }
2017
2018         os.flush();
2019 }
2020
2021 void LyXRC::set_font_norm_type()
2022 {
2023         if (font_norm == "iso10646-1")
2024                 font_norm_type = ISO_10646_1;
2025         else if (font_norm == "iso8859-1")
2026                 font_norm_type = ISO_8859_1;
2027         else if (font_norm == "iso8859-3")
2028                 font_norm_type = ISO_8859_3;
2029         else if (font_norm == "iso8859-4")
2030                 font_norm_type = ISO_8859_4;
2031         else if (font_norm == "iso8859-6.8x")
2032                 font_norm_type = ISO_8859_6_8;
2033         else if (font_norm == "iso8859-9")
2034                 font_norm_type = ISO_8859_9;
2035         else if (font_norm == "iso8859-15")
2036                 font_norm_type = ISO_8859_15;
2037         else
2038                 font_norm_type = OTHER_ENCODING;
2039 }
2040
2041
2042 string const LyXRC::getDescription(LyXRCTags tag)
2043 {
2044         string str;
2045
2046         switch (tag) {
2047         case RC_ACCEPT_COMPOUND:
2048                 str = _("Consider run-together words, such as \"diskdrive\" for \"disk drive\", as legal words?");
2049                 break;
2050
2051         case RC_ALT_LANG:
2052         case RC_USE_ALT_LANG:
2053                 str = _("Specify an alternate language. The default is to use the language of the document.");
2054                 break;
2055
2056         case RC_ASCIIROFF_COMMAND:
2057                 str = _("Use to define an external program to render tables in the ASCII output. E.g. \"groff -t -Tlatin1 $$FName\" where $$FName is the input file. If \"none\" is specified, an internal routine is used.");
2058                 break;
2059
2060         case RC_ASCII_LINELEN:
2061                 str = _("This is the maximum line length of an exported ASCII file (LaTeX, SGML or plain text).");
2062                 break;
2063
2064         case RC_AUTOREGIONDELETE:
2065                 str = _("De-select if you don't want the current selection to be replaced automatically by what you type.");
2066                 break;
2067
2068         case RC_AUTORESET_OPTIONS:
2069                 str = _("De-select if you don't want the class options to be reset to defaults after class change.");
2070                 break;
2071
2072         case RC_AUTOSAVE:
2073                 str = _("The time interval between auto-saves (in seconds). 0 means no auto-save.");
2074                 break;
2075
2076         case RC_AUTO_NUMBER:
2077                 break;
2078
2079         case RC_BACKUPDIR_PATH:
2080                 str = _("The path for storing backup files. If it is an empty string, LyX will store the backup file in the same directory as the original file.");
2081                 break;
2082
2083         case RC_BIBTEX_COMMAND:
2084                 str = _("Define the options of bibtex (cf. man bibtex) or select an alternative compiler (e.g. mlbibtex or bibulus).");
2085                 break;
2086
2087         case RC_BINDFILE:
2088                 str = _("Keybindings file. Can either specify an absolute path, or LyX will look in its global and local bind/ directories.");
2089                 break;
2090
2091         case RC_CHECKLASTFILES:
2092                 str = _("Select to check whether the lastfiles still exist.");
2093                 break;
2094
2095         case RC_CHKTEX_COMMAND:
2096                 str = _("Define how to run chktex. E.g. \"chktex -n11 -n1 -n3 -n6 -n9 -22 -n25 -n30 -n38\" Refer to the ChkTeX documentation.");
2097                 break;
2098
2099         case RC_CONVERTER:
2100                 break;
2101
2102         case RC_COPIER:
2103                 break;
2104
2105         case RC_CURSOR_FOLLOWS_SCROLLBAR:
2106                 str = _("LyX normally doesn't update the cursor position if you move the scrollbar. Set to true if you'd prefer to always have the cursor on screen.");
2107                 break;
2108
2109         case RC_CUSTOM_EXPORT_COMMAND:
2110                 break;
2111
2112         case RC_CUSTOM_EXPORT_FORMAT:
2113                 break;
2114
2115         case RC_CYGWIN_PATH_FIX:
2116                 break;
2117
2118         case RC_DATE_INSERT_FORMAT:
2119                 //xgettext:no-c-format
2120                 str = _("This accepts the normal strftime formats; see man strftime for full details. E.g.\"%A, %e. %B %Y\".");
2121                 break;
2122
2123         case RC_DEFAULT_LANGUAGE:
2124                 str = _("New documents will be assigned this language.");
2125                 break;
2126
2127         case RC_DEFAULT_PAPERSIZE:
2128                 str = _("Specify the default paper size.");
2129                 break;
2130
2131         case RC_DIALOGS_ICONIFY_WITH_MAIN:
2132                 str = _("Iconify the dialogs when the main window is iconified. (Affects only dialogs shown after the change has been made.)");
2133                 break;
2134
2135         case RC_DISPLAY_GRAPHICS:
2136                 str = _("Select how LyX will display any graphics.");
2137                 break;
2138
2139         case RC_DOCUMENTPATH:
2140                 str = _("The default path for your documents. An empty value selects the directory LyX was started from.");
2141                 break;
2142
2143         case RC_ESC_CHARS:
2144         case RC_USE_ESC_CHARS:
2145                 str = _("Specify additional chars that can be part of a word.");
2146                 break;
2147
2148         case RC_FONT_ENCODING:
2149                 str = _("The font encoding used for the LaTeX2e fontenc package. T1 is highly recommended for non-English languages.");
2150                 break;
2151
2152         case RC_FORMAT:
2153                 break;
2154
2155         case RC_INDEX_COMMAND:
2156                 str = _("Define the options of makeindex (cf. man makeindex) or select an alternative compiler. E.g., using xindy/make-rules, the command string would be \"makeindex.sh -m $$lang\".");
2157                 break;
2158
2159         case RC_INPUT:
2160                 break;
2161
2162         case RC_KBMAP:
2163         case RC_KBMAP_PRIMARY:
2164         case RC_KBMAP_SECONDARY:
2165                 str = _("Use this to set the correct mapping file for your keyboard. You'll need this if you for instance want to type German documents on an American keyboard.");
2166                 break;
2167
2168         case RC_LABEL_INIT_LENGTH:
2169                 str = _("Maximum number of words in the initialization string for a new label");
2170                 break;
2171
2172         case RC_LANGUAGE_AUTO_BEGIN:
2173                 str = _("Select if a language switching command is needed at the beginning of the document.");
2174                 break;
2175
2176         case RC_LANGUAGE_AUTO_END:
2177                 str = _("Select if a language switching command is needed at the end of the document.");
2178                 break;
2179
2180         case RC_LANGUAGE_COMMAND_BEGIN:
2181                 str = _("The LaTeX command for changing from the language of the document to another language. E.g. \\selectlanguage{$$lang} where $$lang is substituted by the name of the second language.");
2182                 break;
2183
2184         case RC_LANGUAGE_COMMAND_END:
2185                 str = _("The LaTeX command for changing back to the language of the document.");
2186                 break;
2187
2188         case RC_LANGUAGE_COMMAND_LOCAL:
2189                 str = _("The LaTeX command for local changing of the language.");
2190                 break;
2191
2192         case RC_LANGUAGE_GLOBAL_OPTIONS:
2193                 str = _("De-select if you don't want the language(s) used as an argument to \\documentclass.");
2194                 break;
2195
2196         case RC_LANGUAGE_PACKAGE:
2197                 str = _("The LaTeX command for loading the language package. E.g. \"\\usepackage{babel}\", \"\\usepackage{omega}\".");
2198                 break;
2199
2200         case RC_LANGUAGE_USE_BABEL:
2201                 str = _("De-select if you don't want babel to be used when the language of the document is the default language.");
2202                 break;
2203
2204         case RC_LASTFILES:
2205                 str = _("The file where the last-files information should be stored.");
2206                 break;
2207
2208         case RC_MAKE_BACKUP:
2209                 str = _("De-select if you don't want LyX to create backup files.");
2210                 break;
2211
2212         case RC_MARK_FOREIGN_LANGUAGE:
2213                 str = _("Select to control the highlighting of words with a language foreign to that of the document.");
2214                 break;
2215
2216         case RC_NUMLASTFILES:
2217                 str = bformat(_("Maximal number of lastfiles. Up to %1$d can appear in the file menu."), maxlastfiles);
2218                 break;
2219
2220         case RC_PATH_PREFIX:
2221                 str = _("Specify those directories which should be "
2222                          "prepended to the PATH environment variable. "
2223                          "Use the OS native format.");
2224                 break;
2225
2226         case RC_PERS_DICT:
2227         case RC_USE_PERS_DICT:
2228                 str = _("Specify an alternate personal dictionary file. E.g. \".ispell_english\".");
2229                 break;
2230
2231         case RC_POPUP_BOLD_FONT:
2232                 str = _("The bold font in the dialogs.");
2233                 break;
2234
2235         case RC_POPUP_FONT_ENCODING:
2236                 str = _("The encoding for the menu/popups fonts.");
2237                 break;
2238
2239         case RC_POPUP_NORMAL_FONT:
2240                 str = _("The normal font in the dialogs.");
2241                 break;
2242
2243         case RC_PREVIEW:
2244                 str = _("Shows a typeset preview of things such as math");
2245                 break;
2246
2247         case RC_PREVIEW_HASHED_LABELS:
2248                 str = _("Previewed equations will have \"(#)\" labels rather than numbered ones");
2249                 break;
2250
2251         case RC_PREVIEW_SCALE_FACTOR:
2252                 str = _("Scale the preview size to suit.");
2253                 break;
2254
2255         case RC_PRINTCOLLCOPIESFLAG:
2256                 str = _("The option for specifying whether the copies should be collated.");
2257                 break;
2258
2259         case RC_PRINTCOPIESFLAG:
2260                 str = _("The option for specifying the number of copies to print.");
2261                 break;
2262
2263         case RC_PRINTER:
2264                 str = _("The default printer to print on. If none is specified, LyX will use the environment variable PRINTER.");
2265                 break;
2266
2267         case RC_PRINTEVENPAGEFLAG:
2268                 str = _("The option to print only even pages.");
2269                 break;
2270
2271         case RC_PRINTEXSTRAOPTIONS:
2272                 str = _("Extra options to pass to printing program after everything else, but before the filename of the DVI file to be printed.");
2273                 break;
2274
2275         case RC_PRINTFILEEXTENSION:
2276                 str = _("Extension of printer program output file. Usually \".ps\".");
2277                 break;
2278
2279         case RC_PRINTLANDSCAPEFLAG:
2280                 str = _("The option to print out in landscape.");
2281                 break;
2282
2283         case RC_PRINTODDPAGEFLAG:
2284                 str = _("The option to print only odd pages.");
2285                 break;
2286
2287         case RC_PRINTPAGERANGEFLAG:
2288                 str = _("The option for specifying a comma-separated list of pages to print.");
2289                 break;
2290
2291         case RC_PRINTPAPERDIMENSIONFLAG:
2292                 str = _("Option to specify the dimensions of the print paper.");
2293                 break;
2294
2295         case RC_PRINTPAPERFLAG:
2296                 str = _("The option to specify paper type.");
2297                 break;
2298
2299         case RC_PRINTREVERSEFLAG:
2300                 str = _("The option to reverse the order of the pages printed.");
2301                 break;
2302
2303         case RC_PRINTSPOOL_COMMAND:
2304                 str = _("When set, this printer option automatically prints to a file and then calls a separate print spooling program on that file with the given name and arguments.");
2305                 break;
2306
2307         case RC_PRINTSPOOL_PRINTERPREFIX:
2308                 str = _("If you specify a printer name in the print dialog, the following argument is prepended along with the printer name after the spool command.");
2309                 break;
2310
2311         case RC_PRINTTOFILE:
2312                 str = _("Option to pass to the print program to print to a file.");
2313                 break;
2314
2315         case RC_PRINTTOPRINTER:
2316                 str = _("Option to pass to the print program to print on a specific printer.");
2317                 break;
2318
2319         case RC_PRINT_ADAPTOUTPUT:
2320                 str = _("Select for LyX to pass the name of the destination printer to your print command.");
2321                 break;
2322
2323         case RC_PRINT_COMMAND:
2324                 str = _("Your favorite print program, e.g. \"dvips\", \"dvilj4\".");
2325                 break;
2326
2327         case RC_RTL_SUPPORT:
2328                 str = _("Select to enable support of right-to-left languages (e.g. Hebrew, Arabic).");
2329                 break;
2330
2331         case RC_SCREEN_DPI:
2332                 str = _("DPI (dots per inch) of your monitor is auto-detected by LyX. If that goes wrong, override the setting here.");
2333                 break;
2334
2335         case RC_SCREEN_FONT_ENCODING:
2336                 str = _("The encoding for the screen fonts.");
2337                 break;
2338
2339         case RC_SCREEN_FONT_ROMAN:
2340         case RC_SCREEN_FONT_SANS:
2341         case RC_SCREEN_FONT_TYPEWRITER:
2342                 str = _("The screen fonts used to display the text while editing.");
2343                 break;
2344
2345         case RC_SCREEN_FONT_ROMAN_FOUNDRY:
2346         case RC_SCREEN_FONT_SANS_FOUNDRY:
2347         case RC_SCREEN_FONT_TYPEWRITER_FOUNDRY:
2348                 break;
2349
2350         case RC_SCREEN_FONT_SCALABLE:
2351                 str = _("Allow bitmap fonts to be resized. If you are using a bitmap font, selecting this option may make some fonts look blocky in LyX. Deselecting this option makes LyX use the nearest bitmap font size available, instead of scaling.");
2352                 break;
2353
2354         case RC_SCREEN_FONT_SIZES:
2355                 str = _("The font sizes used for calculating the scaling of the screen fonts.");
2356                 break;
2357
2358         case RC_SCREEN_ZOOM:
2359                 //xgettext:no-c-format
2360                 str = _("The zoom percentage for screen fonts. A setting of 100% will make the fonts roughly the same size as on paper.");
2361                 break;
2362
2363         case RC_SERVERPIPE:
2364                 str = _("This starts the lyxserver. The pipes get an additional extension \".in\" and \".out\". Only for advanced users.");
2365                 break;
2366
2367         case RC_SET_COLOR:
2368                 break;
2369
2370         case RC_SHOW_BANNER:
2371                 str = _("De-select if you don't want the startup banner.");
2372                 break;
2373
2374         case RC_SPELL_COMMAND:
2375                 str = _("What command runs the spell checker?");
2376                 break;
2377
2378         case RC_TEMPDIRPATH:
2379                 str = _("LyX will place its temporary directories in this path. They will be deleted when you quit LyX.");
2380                 break;
2381
2382         case RC_TEMPLATEPATH:
2383                 str = _("The path that LyX will set when offering to choose a template. An empty value selects the directory LyX was started from.");
2384                 break;
2385
2386         case RC_TEX_ALLOWS_SPACES:
2387                 break;
2388
2389         case RC_UIFILE:
2390                 str = _("The UI (user interface) file. Can either specify an absolute path, or LyX will look in its global and local ui/ directories.");
2391                 break;
2392
2393         case RC_USER_EMAIL:
2394                 break;
2395
2396         case RC_USER_NAME:
2397                 break;
2398
2399         case RC_USETEMPDIR:
2400                 break;
2401
2402         case RC_USE_INP_ENC:
2403                 str = _("Specify whether to pass the -T input encoding option to ispell. Enable this if you can't spellcheck words with international letters in them. This may not work with all dictionaries.");
2404                 break;
2405
2406         case RC_USE_SPELL_LIB:
2407                 break;
2408
2409         case RC_VIEWDVI_PAPEROPTION:
2410                 str = _("Specify the paper command to DVI viewer (leave empty or use \"-paper\")");
2411                 break;
2412
2413         case RC_VIEWER:
2414                 break;
2415
2416         case RC_WHEEL_JUMP:
2417                 str = _("The number of lines that are scrolled by mice with wheels or five button mice.");
2418                 break;
2419
2420         case RC_LAST:
2421                 break;
2422         }
2423
2424         return str;
2425 }
2426
2427 // The global instance
2428 LyXRC lyxrc;
2429
2430 // The global copy of the system lyxrc entries (everything except preferences)
2431 LyXRC system_lyxrc;