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