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