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