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