1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
23 #include "support/filetools.h"
24 #include "lyx_gui_misc.h"
27 #include "support/LAssert.h"
30 // Global variable: textclass table.
31 LyXTextClassList textclasslist;
34 // Reads the style files
37 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
39 if (!textclasslist.Read()) {
40 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
41 "during parsing.\n Exiting." << endl;
45 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
49 // The order of the LayoutTags enum is no more important. [asierra300396]
60 //LT_ENVIRONMENT_DEFAULT,
76 LT_LABELSTRING_APPENDIX,
98 // This table is sorted alphabetically [asierra 30March96]
99 static keyword_item layoutTags[] = {
100 { "align", LT_ALIGN },
101 { "alignpossible", LT_ALIGNPOSSIBLE },
102 { "bottomsep", LT_BOTTOMSEP },
103 { "copystyle", LT_COPYSTYLE },
105 { "fill_bottom", LT_FILL_BOTTOM },
106 { "fill_top", LT_FILL_TOP },
108 { "freespacing", LT_FREE_SPACING },
109 { "intitle", LT_INTITLE },
110 { "itemsep", LT_ITEMSEP },
111 { "keepempty", LT_KEEPEMPTY },
112 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
113 { "labelfont", LT_LABELFONT },
114 { "labelindent", LT_LABELINDENT },
115 { "labelsep", LT_LABELSEP },
116 { "labelstring", LT_LABELSTRING },
117 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
118 { "labeltype", LT_LABELTYPE },
119 { "latexname", LT_LATEXNAME },
120 { "latexparam", LT_LATEXPARAM },
121 { "latextype", LT_LATEXTYPE },
122 { "leftmargin", LT_LEFTMARGIN },
123 { "margin", LT_MARGIN },
124 { "needprotect", LT_NEED_PROTECT },
125 { "newline", LT_NEWLINE },
126 { "nextnoindent", LT_NEXTNOINDENT },
127 { "obsoletedby", LT_OBSOLETEDBY },
128 { "parindent", LT_PARINDENT },
129 { "parsep", LT_PARSEP },
130 { "parskip", LT_PARSKIP },
131 { "preamble", LT_PREAMBLE },
132 { "rightmargin", LT_RIGHTMARGIN },
133 { "spacing", LT_SPACING },
134 { "textfont", LT_TEXTFONT },
135 { "topsep", LT_TOPSEP }
140 /////////////////////
142 // Constructor for layout
143 LyXLayout::LyXLayout ()
145 margintype = MARGIN_STATIC;
146 latextype = LATEX_PARAGRAPH;
150 font = LyXFont(LyXFont::ALL_INHERIT);
151 labelfont = LyXFont(LyXFont::ALL_INHERIT);
152 resfont = LyXFont(LyXFont::ALL_SANE);
153 reslabelfont = LyXFont(LyXFont::ALL_SANE);
154 nextnoindent = false;
159 labelbottomsep = 0.0;
161 align = LYX_ALIGN_BLOCK;
162 alignpossible = LYX_ALIGN_BLOCK;
163 labeltype = LABEL_NO_LABEL;
164 // Should or should not. That is the question.
165 // spacing.set(Spacing::OneHalf);
168 newline_allowed = true;
169 free_spacing = false;
173 // Reads a layout definition from file
174 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
177 // This table is sorted alphabetically [asierra 30March96]
178 keyword_item layoutTags[] = {
179 { "align", LT_ALIGN },
180 { "alignpossible", LT_ALIGNPOSSIBLE },
181 { "bottomsep", LT_BOTTOMSEP },
182 { "copystyle", LT_COPYSTYLE },
184 { "fill_bottom", LT_FILL_BOTTOM },
185 { "fill_top", LT_FILL_TOP },
187 { "freespacing", LT_FREE_SPACING },
188 { "intitle", LT_INTITLE },
189 { "itemsep", LT_ITEMSEP },
190 { "keepempty", LT_KEEPEMPTY },
191 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
192 { "labelfont", LT_LABELFONT },
193 { "labelindent", LT_LABELINDENT },
194 { "labelsep", LT_LABELSEP },
195 { "labelstring", LT_LABELSTRING },
196 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
197 { "labeltype", LT_LABELTYPE },
198 { "latexname", LT_LATEXNAME },
199 { "latexparam", LT_LATEXPARAM },
200 { "latextype", LT_LATEXTYPE },
201 { "leftmargin", LT_LEFTMARGIN },
202 { "margin", LT_MARGIN },
203 { "needprotect", LT_NEED_PROTECT },
204 { "newline", LT_NEWLINE },
205 { "nextnoindent", LT_NEXTNOINDENT },
206 { "obsoletedby", LT_OBSOLETEDBY },
207 { "parindent", LT_PARINDENT },
208 { "parsep", LT_PARSEP },
209 { "parskip", LT_PARSKIP },
210 { "preamble", LT_PREAMBLE },
211 { "rightmargin", LT_RIGHTMARGIN },
212 { "spacing", LT_SPACING },
213 { "textfont", LT_TEXTFONT },
214 { "topsep", LT_TOPSEP }
218 bool finished = false;
219 lexrc.pushTable(layoutTags, LT_INTITLE);
220 // parse style section
221 while (!finished && lexrc.IsOK() && !error) {
222 int le = lexrc.lex();
223 // See comment in lyxrc.C.
225 case LyXLex::LEX_FEOF:
228 case LyXLex::LEX_UNDEF: // parse error
229 lexrc.printError("Unknown layout tag `$$Token'");
234 switch(static_cast<LayoutTags>(le)) {
235 case LT_END: // end of structure
239 case LT_COPYSTYLE: // initialize with a known style
241 if (tclass.hasLayout(lexrc.GetString())) {
242 string tmpname = name_;
243 this->operator= (tclass.GetLayout(lexrc.GetString()));
246 lexrc.printError("Cannot copy known "
252 case LT_OBSOLETEDBY: // replace with a known style
254 if (tclass.hasLayout(lexrc.GetString())) {
255 string tmpname = name_;
256 this->operator= (tclass.GetLayout(lexrc.GetString()));
258 if (obsoleted_by().empty())
259 obsoleted_by_ = lexrc.GetString();
261 lexrc.printError("Cannot replace with"
268 case LT_MARGIN: // Margin style definition.
272 case LT_LATEXTYPE: // Latex style definition.
273 readLatexType(lexrc);
277 intitle = lexrc.next() && lexrc.GetInteger();
280 case LT_NEED_PROTECT:
281 needprotect = lexrc.next() && lexrc.GetInteger();
285 keepempty = lexrc.next() && lexrc.GetInteger();
298 labelfont.lyxRead(lexrc);
301 case LT_NEXTNOINDENT: // Indent next paragraph?
302 if (lexrc.next() && lexrc.GetInteger())
305 nextnoindent = false;
310 latexname_ = lexrc.GetString();
315 latexparam_ = lexrc.GetString();
319 preamble_ = lexrc.getLongString("EndPreamble");
323 readLabelType(lexrc);
326 case LT_LEFTMARGIN: // left margin type
328 leftmargin = lexrc.GetString();
331 case LT_RIGHTMARGIN: // right margin type
333 rightmargin = lexrc.GetString();
336 case LT_LABELINDENT: // label indenting flag
338 labelindent = lexrc.GetString();
341 case LT_PARINDENT: // paragraph indent. flag
343 parindent = lexrc.GetString();
346 case LT_PARSKIP: // paragraph skip size
348 parskip = lexrc.GetFloat();
351 case LT_ITEMSEP: // item separation size
353 itemsep = lexrc.GetFloat();
356 case LT_TOPSEP: // top separation size
358 topsep = lexrc.GetFloat();
361 case LT_BOTTOMSEP: // bottom separation size
363 bottomsep = lexrc.GetFloat();
366 case LT_LABEL_BOTTOMSEP: // label bottom separation size
368 labelbottomsep = lexrc.GetFloat();
371 case LT_LABELSEP: // label separator
373 labelsep = subst(lexrc.GetString(), 'x', ' ');
377 case LT_PARSEP: // par. separation size
379 parsep = lexrc.GetFloat();
382 case LT_FILL_TOP: // fill top flag
384 fill_top = lexrc.GetInteger();
387 case LT_FILL_BOTTOM: // fill bottom flag
389 fill_bottom = lexrc.GetInteger();
392 case LT_NEWLINE: // newlines allowed?
394 newline_allowed = lexrc.GetInteger();
397 case LT_ALIGN: // paragraph align
400 case LT_ALIGNPOSSIBLE: // paragraph allowed align
401 readAlignPossible(lexrc);
404 case LT_LABELSTRING: // label string definition
406 labelstring_ = lexrc.GetString();
409 case LT_LABELSTRING_APPENDIX: // label string appendix definition
411 labelstring_appendix_ = lexrc.GetString();
414 case LT_FREE_SPACING: // Allow for free spacing.
416 free_spacing = lexrc.GetInteger();
419 case LT_SPACING: // setspace.sty
439 static keyword_item alignTags[] = {
440 { "block", AT_BLOCK },
441 { "center", AT_CENTER },
442 { "layout", AT_LAYOUT },
444 { "right", AT_RIGHT }
448 void LyXLayout::readAlign(LyXLex & lexrc)
451 keyword_item alignTags[] = {
452 { "block", AT_BLOCK },
453 { "center", AT_CENTER },
454 { "layout", AT_LAYOUT },
456 { "right", AT_RIGHT }
459 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
460 int le = lexrc.lex();
462 case LyXLex::LEX_UNDEF:
463 lexrc.printError("Unknown alignment `$$Token'");
467 switch(static_cast<AlignTags>(le)) {
469 align = LYX_ALIGN_BLOCK;
472 align = LYX_ALIGN_LEFT;
475 align = LYX_ALIGN_RIGHT;
478 align = LYX_ALIGN_CENTER;
481 align = LYX_ALIGN_LAYOUT;
487 void LyXLayout::readAlignPossible(LyXLex & lexrc)
490 keyword_item alignTags[] = {
491 { "block", AT_BLOCK },
492 { "center", AT_CENTER },
493 { "layout", AT_LAYOUT },
495 { "right", AT_RIGHT }
498 lexrc.pushTable(alignTags, AT_LAYOUT);
499 alignpossible = LYX_ALIGN_NONE;
500 int lineno = lexrc.GetLineNo();
502 int le = lexrc.lex();
504 case LyXLex::LEX_UNDEF:
505 lexrc.printError("Unknown alignment `$$Token'");
509 switch (static_cast<AlignTags>(le)) {
511 alignpossible |= LYX_ALIGN_BLOCK;
514 alignpossible |= LYX_ALIGN_LEFT;
517 alignpossible |= LYX_ALIGN_RIGHT;
520 alignpossible |= LYX_ALIGN_CENTER;
523 alignpossible |= LYX_ALIGN_LAYOUT;
526 } while (lineno == lexrc.GetLineNo());
535 LA_CENTERED_TOP_ENVIRONMENT,
540 LA_COUNTER_SUBSECTION,
541 LA_COUNTER_SUBSUBSECTION,
542 LA_COUNTER_PARAGRAPH,
543 LA_COUNTER_SUBPARAGRAPH,
553 static keyword_item labelTypeTags[] = {
554 { "bibliography", LA_BIBLIO },
555 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
556 { "counter_chapter", LA_COUNTER_CHAPTER },
557 { "counter_enumi", LA_COUNTER_ENUMI },
558 { "counter_enumii", LA_COUNTER_ENUMII },
559 { "counter_enumiii", LA_COUNTER_ENUMIII },
560 { "counter_enumiv", LA_COUNTER_ENUMIV },
561 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
562 { "counter_section", LA_COUNTER_SECTION },
563 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
564 { "counter_subsection", LA_COUNTER_SUBSECTION },
565 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
566 { "manual", LA_MANUAL },
567 { "no_label", LA_NO_LABEL },
568 { "sensitive", LA_SENSITIVE },
569 { "static", LA_STATIC },
570 { "top_environment", LA_TOP_ENVIRONMENT }
575 void LyXLayout::readLabelType(LyXLex & lexrc)
578 keyword_item labelTypeTags[] = {
579 { "bibliography", LA_BIBLIO },
580 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
581 { "counter_chapter", LA_COUNTER_CHAPTER },
582 { "counter_enumi", LA_COUNTER_ENUMI },
583 { "counter_enumii", LA_COUNTER_ENUMII },
584 { "counter_enumiii", LA_COUNTER_ENUMIII },
585 { "counter_enumiv", LA_COUNTER_ENUMIV },
586 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
587 { "counter_section", LA_COUNTER_SECTION },
588 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
589 { "counter_subsection", LA_COUNTER_SUBSECTION },
590 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
591 { "manual", LA_MANUAL },
592 { "no_label", LA_NO_LABEL },
593 { "sensitive", LA_SENSITIVE },
594 { "static", LA_STATIC },
595 { "top_environment", LA_TOP_ENVIRONMENT }
598 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
599 int le = lexrc.lex();
601 case LyXLex::LEX_UNDEF:
602 lexrc.printError("Unknown labeltype tag `$$Token'");
606 switch (static_cast<LabelTypeTags>(le)) {
608 labeltype = LABEL_NO_LABEL;
611 labeltype = LABEL_MANUAL;
613 case LA_TOP_ENVIRONMENT:
614 labeltype = LABEL_TOP_ENVIRONMENT;
616 case LA_CENTERED_TOP_ENVIRONMENT:
617 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
620 labeltype = LABEL_STATIC;
623 labeltype = LABEL_SENSITIVE;
625 case LA_COUNTER_CHAPTER:
626 labeltype = LABEL_COUNTER_CHAPTER;
628 case LA_COUNTER_SECTION:
629 labeltype = LABEL_COUNTER_SECTION;
631 case LA_COUNTER_SUBSECTION:
632 labeltype = LABEL_COUNTER_SUBSECTION;
634 case LA_COUNTER_SUBSUBSECTION:
635 labeltype = LABEL_COUNTER_SUBSUBSECTION;
637 case LA_COUNTER_PARAGRAPH:
638 labeltype = LABEL_COUNTER_PARAGRAPH;
640 case LA_COUNTER_SUBPARAGRAPH:
641 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
643 case LA_COUNTER_ENUMI:
644 labeltype = LABEL_COUNTER_ENUMI;
646 case LA_COUNTER_ENUMII:
647 labeltype = LABEL_COUNTER_ENUMII;
649 case LA_COUNTER_ENUMIII:
650 labeltype = LABEL_COUNTER_ENUMIII;
652 case LA_COUNTER_ENUMIV:
653 labeltype = LABEL_COUNTER_ENUMIV;
656 labeltype = LABEL_BIBLIO;
663 static keyword_item marginTags[] = {
664 { "dynamic", MARGIN_DYNAMIC },
665 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
666 { "manual", MARGIN_MANUAL },
667 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
668 { "static", MARGIN_STATIC }
672 void LyXLayout::readMargin(LyXLex & lexrc)
675 keyword_item marginTags[] = {
676 { "dynamic", MARGIN_DYNAMIC },
677 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
678 { "manual", MARGIN_MANUAL },
679 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
680 { "static", MARGIN_STATIC }
683 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
685 int le = lexrc.lex();
687 case LyXLex::LEX_UNDEF:
688 lexrc.printError("Unknown margin type tag `$$Token'");
693 case MARGIN_FIRST_DYNAMIC:
694 case MARGIN_RIGHT_ADDRESS_BOX:
695 margintype = static_cast<LYX_MARGIN_TYPE>(le);
698 lyxerr << "Unhandled value " << le
699 << " in LyXLayout::readMargin." << endl;
706 static keyword_item latexTypeTags[] = {
707 { "command", LATEX_COMMAND },
708 { "environment", LATEX_ENVIRONMENT },
709 { "item_environment", LATEX_ITEM_ENVIRONMENT },
710 { "list_environment", LATEX_LIST_ENVIRONMENT },
711 { "paragraph", LATEX_PARAGRAPH }
716 void LyXLayout::readLatexType(LyXLex & lexrc)
719 keyword_item latexTypeTags[] = {
720 { "command", LATEX_COMMAND },
721 { "environment", LATEX_ENVIRONMENT },
722 { "item_environment", LATEX_ITEM_ENVIRONMENT },
723 { "list_environment", LATEX_LIST_ENVIRONMENT },
724 { "paragraph", LATEX_PARAGRAPH }
727 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
728 int le = lexrc.lex();
730 case LyXLex::LEX_UNDEF:
731 lexrc.printError("Unknown latextype tag `$$Token'");
733 case LATEX_PARAGRAPH:
735 case LATEX_ENVIRONMENT:
736 case LATEX_ITEM_ENVIRONMENT:
737 case LATEX_LIST_ENVIRONMENT:
738 latextype = static_cast<LYX_LATEX_TYPES>(le);
741 lyxerr << "Unhandled value " << le
742 << " in LyXLayout::readLatexType." << endl;
749 ST_SPACING_SINGLE = 1,
757 static keyword_item spacingTags[] = {
758 {"double", ST_SPACING_DOUBLE },
759 {"onehalf", ST_SPACING_ONEHALF },
760 {"other", ST_OTHER },
761 {"single", ST_SPACING_SINGLE }
766 void LyXLayout::readSpacing(LyXLex & lexrc)
769 keyword_item spacingTags[] = {
770 {"double", ST_SPACING_DOUBLE },
771 {"onehalf", ST_SPACING_ONEHALF },
772 {"other", ST_OTHER },
773 {"single", ST_SPACING_SINGLE }
776 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
777 int le = lexrc.lex();
779 case LyXLex::LEX_UNDEF:
780 lexrc.printError("Unknown spacing token `$$Token'");
784 switch(static_cast<SpacingTags>(le)) {
785 case ST_SPACING_SINGLE:
786 spacing.set(Spacing::Single);
788 case ST_SPACING_ONEHALF:
789 spacing.set(Spacing::Onehalf);
791 case ST_SPACING_DOUBLE:
792 spacing.set(Spacing::Double);
796 spacing.set(Spacing::Other, lexrc.GetFloat());
802 /* ******************************************************************* */
804 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
806 : name_(fn), latexname_(cln), description_(desc)
813 pagestyle_ = "default";
814 maxcounter_ = LABEL_COUNTER_CHAPTER;
815 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
816 opt_fontsize_ = "10|11|12";
817 opt_pagestyle_ = "empty|plain|headings|fancy";
823 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
825 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
826 if (!lay.Read(lexrc, *this)) {
828 lay.resfont = lay.font;
829 lay.resfont.realize(defaultfont());
830 lay.reslabelfont = lay.labelfont;
831 lay.reslabelfont.realize(defaultfont());
832 return false; // no errors
834 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
862 static keyword_item textClassTags[] = {
863 { "classoptions", TC_CLASSOPTIONS },
864 { "columns", TC_COLUMNS },
865 { "defaultfont", TC_DEFAULTFONT },
866 { "input", TC_INPUT },
867 { "leftmargin", TC_LEFTMARGIN },
868 { "maxcounter", TC_MAXCOUNTER },
869 { "nostyle", TC_NOSTYLE },
870 { "outputtype", TC_OUTPUTTYPE },
871 { "pagestyle", TC_PAGESTYLE },
872 { "preamble", TC_PREAMBLE },
873 { "providesamsmath", TC_PROVIDESAMSMATH },
874 { "providesmakeidx", TC_PROVIDESMAKEIDX },
875 { "providesurl", TC_PROVIDESURL },
876 { "rightmargin", TC_RIGHTMARGIN },
877 { "secnumdepth", TC_SECNUMDEPTH },
878 { "sides", TC_SIDES },
879 { "style", TC_STYLE },
880 { "tocdepth", TC_TOCDEPTH }
885 // Reads a textclass structure from file.
886 bool LyXTextClass::Read(string const & filename, bool merge)
889 keyword_item textClassTags[] = {
890 { "classoptions", TC_CLASSOPTIONS },
891 { "columns", TC_COLUMNS },
892 { "defaultfont", TC_DEFAULTFONT },
893 { "input", TC_INPUT },
894 { "leftmargin", TC_LEFTMARGIN },
895 { "maxcounter", TC_MAXCOUNTER },
896 { "nostyle", TC_NOSTYLE },
897 { "outputtype", TC_OUTPUTTYPE },
898 { "pagestyle", TC_PAGESTYLE },
899 { "preamble", TC_PREAMBLE },
900 { "providesamsmath", TC_PROVIDESAMSMATH },
901 { "providesmakeidx", TC_PROVIDESMAKEIDX },
902 { "providesurl", TC_PROVIDESURL },
903 { "rightmargin", TC_RIGHTMARGIN },
904 { "secnumdepth", TC_SECNUMDEPTH },
905 { "sides", TC_SIDES },
906 { "style", TC_STYLE },
907 { "tocdepth", TC_TOCDEPTH }
911 lyxerr[Debug::TCLASS] << "Reading textclass "
912 << MakeDisplayPath(filename)
915 lyxerr[Debug::TCLASS] << "Reading input file "
916 << MakeDisplayPath(filename)
919 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
922 lexrc.setFile(filename);
923 if (!lexrc.IsOK()) error = true;
926 while (lexrc.IsOK() && !error) {
927 int le = lexrc.lex();
929 case LyXLex::LEX_FEOF:
932 case LyXLex::LEX_UNDEF:
933 lexrc.printError("Unknown TextClass tag `$$Token'");
938 switch(static_cast<TextClassTags>(le)) {
939 case TC_OUTPUTTYPE: // output type definition
940 readOutputType(lexrc);
943 case TC_INPUT: // Include file
945 string tmp = LibFileSearch("layouts",
949 if (Read(tmp, true)) {
950 lexrc.printError("Error reading input"
959 string name = subst(lexrc.GetString(),
961 if (hasLayout(name)) {
962 LyXLayout & lay = GetLayout(name);
963 error = do_readStyle(lexrc, lay);
967 if (!(error = do_readStyle(lexrc, lay)))
968 layoutlist.push_back(lay);
972 lexrc.printError("No name given for style: `$$Token'.");
979 string style = subst(lexrc.GetString(),
981 if (!delete_layout(style))
982 lexrc.printError("Cannot delete style"
989 columns_ = lexrc.GetInteger();
994 switch(lexrc.GetInteger()) {
995 case 1: sides_ = OneSide; break;
996 case 2: sides_ = TwoSides; break;
998 lyxerr << "Impossible number of page"
999 " sides, setting to one."
1009 pagestyle_ = strip(lexrc.GetString());
1012 case TC_DEFAULTFONT:
1013 defaultfont_.lyxRead(lexrc);
1014 if (!defaultfont_.resolved()) {
1015 lexrc.printError("Warning: defaultfont should "
1016 "be fully instantiated!");
1017 defaultfont_.realize(LyXFont::ALL_SANE);
1022 readMaxCounter(lexrc);
1025 case TC_SECNUMDEPTH:
1027 secnumdepth_ = lexrc.GetInteger();
1032 tocdepth_ = lexrc.GetInteger();
1035 // First step to support options
1036 case TC_CLASSOPTIONS:
1037 readClassOptions(lexrc);
1041 preamble_ = lexrc.getLongString("EndPreamble");
1044 case TC_PROVIDESAMSMATH:
1045 if (lexrc.next() && lexrc.GetInteger())
1046 provides_ |= amsmath;
1049 case TC_PROVIDESMAKEIDX:
1050 if (lexrc.next() && lexrc.GetInteger())
1051 provides_ |= makeidx;
1054 case TC_PROVIDESURL:
1055 if (lexrc.next() && lexrc.GetInteger())
1059 case TC_LEFTMARGIN: // left margin type
1061 leftmargin_ = lexrc.GetString();
1064 case TC_RIGHTMARGIN: // right margin type
1066 rightmargin_ = lexrc.GetString();
1071 if (!merge) { // we are at top level here.
1072 lyxerr[Debug::TCLASS] << "Finished reading textclass "
1073 << MakeDisplayPath(filename)
1076 lyxerr[Debug::TCLASS] << "Finished reading input file "
1077 << MakeDisplayPath(filename)
1085 static keyword_item outputTypeTags[] = {
1086 { "docbook", DOCBOOK },
1088 { "linuxdoc", LINUXDOC },
1089 { "literate", LITERATE }
1093 void LyXTextClass::readOutputType(LyXLex & lexrc)
1096 keyword_item outputTypeTags[] = {
1097 { "docbook", DOCBOOK },
1099 { "linuxdoc", LINUXDOC },
1100 { "literate", LITERATE }
1103 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1105 int le = lexrc.lex();
1107 case LyXLex::LEX_UNDEF:
1108 lexrc.printError("Unknown output type `$$Token'");
1114 outputType_ = static_cast<OutputType>(le);
1117 lyxerr << "Unhandled value " << le
1118 << " in LyXTextClass::readOutputType." << endl;
1125 enum MaxCounterTags {
1126 MC_COUNTER_CHAPTER = 1,
1128 MC_COUNTER_SUBSECTION,
1129 MC_COUNTER_SUBSUBSECTION,
1130 MC_COUNTER_PARAGRAPH,
1131 MC_COUNTER_SUBPARAGRAPH,
1140 static keyword_item maxCounterTags[] = {
1141 {"counter_chapter", MC_COUNTER_CHAPTER },
1142 {"counter_enumi", MC_COUNTER_ENUMI },
1143 {"counter_enumii", MC_COUNTER_ENUMII },
1144 {"counter_enumiii", MC_COUNTER_ENUMIII },
1145 {"counter_enumiv", MC_COUNTER_ENUMIV },
1146 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1147 {"counter_section", MC_COUNTER_SECTION },
1148 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1149 {"counter_subsection", MC_COUNTER_SUBSECTION },
1150 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1155 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1158 keyword_item maxCounterTags[] = {
1159 {"counter_chapter", MC_COUNTER_CHAPTER },
1160 {"counter_enumi", MC_COUNTER_ENUMI },
1161 {"counter_enumii", MC_COUNTER_ENUMII },
1162 {"counter_enumiii", MC_COUNTER_ENUMIII },
1163 {"counter_enumiv", MC_COUNTER_ENUMIV },
1164 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1165 {"counter_section", MC_COUNTER_SECTION },
1166 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1167 {"counter_subsection", MC_COUNTER_SUBSECTION },
1168 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1171 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1172 int le = lexrc.lex();
1174 case LyXLex::LEX_UNDEF:
1175 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1179 switch (static_cast<MaxCounterTags>(le)) {
1180 case MC_COUNTER_CHAPTER:
1181 maxcounter_ = LABEL_COUNTER_CHAPTER;
1183 case MC_COUNTER_SECTION:
1184 maxcounter_ = LABEL_COUNTER_SECTION;
1186 case MC_COUNTER_SUBSECTION:
1187 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1189 case MC_COUNTER_SUBSUBSECTION:
1190 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1192 case MC_COUNTER_PARAGRAPH:
1193 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1195 case MC_COUNTER_SUBPARAGRAPH:
1196 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1198 case MC_COUNTER_ENUMI:
1199 maxcounter_ = LABEL_COUNTER_ENUMI;
1201 case MC_COUNTER_ENUMII:
1202 maxcounter_ = LABEL_COUNTER_ENUMII;
1204 case MC_COUNTER_ENUMIII:
1205 maxcounter_ = LABEL_COUNTER_ENUMIII;
1207 case MC_COUNTER_ENUMIV:
1208 maxcounter_ = LABEL_COUNTER_ENUMIV;
1214 enum ClassOptionsTags {
1223 static keyword_item classOptionsTags[] = {
1225 {"fontsize", CO_FONTSIZE },
1226 {"other", CO_OTHER },
1227 {"pagestyle", CO_PAGESTYLE }
1232 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1235 keyword_item classOptionsTags[] = {
1237 {"fontsize", CO_FONTSIZE },
1238 {"other", CO_OTHER },
1239 {"pagestyle", CO_PAGESTYLE }
1242 lexrc.pushTable(classOptionsTags, CO_END);
1243 bool getout = false;
1244 while (!getout && lexrc.IsOK()) {
1245 int le = lexrc.lex();
1247 case LyXLex::LEX_UNDEF:
1248 lexrc.printError("Unknown ClassOption tag `$$Token'");
1252 switch (static_cast<ClassOptionsTags>(le)) {
1255 opt_fontsize_ = strip(lexrc.GetString());
1259 opt_pagestyle_ = strip(lexrc.GetString());
1263 options_ = lexrc.GetString();
1274 bool LyXTextClass::hasLayout(string const & name) const
1276 for (LayoutList::const_iterator cit = layoutlist.begin();
1277 cit != layoutlist.end(); ++cit) {
1278 if ((*cit).name() == name)
1285 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1287 for (LayoutList::const_iterator cit = layoutlist.begin();
1288 cit != layoutlist.end(); ++cit) {
1289 if ((*cit).name() == name)
1292 Assert(false); // we actually require the name to exist.
1293 return layoutlist.front();
1297 LyXLayout & LyXTextClass::GetLayout(string const & name)
1299 for (LayoutList::iterator it = layoutlist.begin();
1300 it != layoutlist.end(); ++it) {
1301 if ((*it).name() == name)
1304 Assert(false); // we actually require the name to exist.
1305 return layoutlist.front();
1309 bool LyXTextClass::delete_layout (string const & name)
1311 for(LayoutList::iterator it = layoutlist.begin();
1312 it != layoutlist.end(); ++it) {
1313 if ((*it).name() == name) {
1314 layoutlist.erase(it);
1322 // Load textclass info if not loaded yet
1323 void LyXTextClass::load()
1328 string real_file = LibFileSearch("layouts", name_, "layout");
1330 if (Read(real_file)) {
1331 lyxerr << "Error reading `"
1332 << MakeDisplayPath(real_file)
1333 << "'\n(Check `" << name_
1334 << "')\nCheck your installation and "
1335 "try Options/Reconfigure..." << endl;
1341 //////////////////////////////////////////
1343 // Gets textclass number from name
1344 pair<bool, LyXTextClassList::size_type>
1345 LyXTextClassList::NumberOfClass(string const & textclass) const
1347 for (ClassList::const_iterator cit = classlist.begin();
1348 cit != classlist.end(); ++cit) {
1349 if ((*cit).name() == textclass)
1350 return make_pair(true, cit - classlist.begin());
1352 return make_pair(false, size_type(0));
1356 // Gets layout structure from style number and textclass number
1358 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1359 LyXTextClass::size_type layout) const
1361 classlist[textclass].load();
1362 if (layout < classlist[textclass].numLayouts())
1363 return classlist[textclass][layout];
1364 return classlist[textclass][0];
1368 // Gets layout number from name and textclass number
1369 pair<bool, LyXTextClass::size_type>
1370 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1371 string const & name) const
1373 classlist[textclass].load();
1374 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1375 if (classlist[textclass][i].name() == name)
1376 return make_pair(true, i);
1378 if (name == "dummy")
1379 return make_pair(true, LYX_DUMMY_LAYOUT);
1380 return make_pair(false, LyXTextClass::LayoutList::size_type(0)); // not found
1384 // Gets a layout (style) name from layout number and textclass number
1386 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1387 LyXTextClass::size_type layout) const
1389 static string dummy("dummy");
1390 classlist[textclass].load();
1391 if (layout < classlist[textclass].numLayouts())
1392 return classlist[textclass][layout].name();
1397 // Gets a textclass name from number
1399 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1401 static string dummy("dummy");
1402 if (classlist.size() == 0) {
1405 Assert(number < classlist.size());
1406 return classlist[number].name();
1410 // Gets a textclass latexname from number
1412 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1414 static string dummy("dummy");
1415 classlist[number].load();
1416 if (classlist.size() == 0) {
1419 Assert(number < classlist.size());
1420 return classlist[number].latexname();
1424 // Gets a textclass description from number
1426 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1428 static string dummy("dummy");
1429 if (classlist.size() == 0) {
1432 Assert(number < classlist.size());
1433 return classlist[number].description();
1437 // Gets a textclass structure from number
1438 LyXTextClass const &
1439 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1441 classlist[textclass].load();
1442 if (textclass < classlist.size())
1443 return classlist[textclass];
1445 return classlist[0];
1449 void LyXTextClassList::Add(LyXTextClass const & t)
1451 classlist.push_back(t);
1455 // used when sorting the textclass list.
1456 class less_textclass_desc {
1458 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1459 return tc1.description() < tc2.description();
1464 // Reads LyX textclass definitions according to textclass config file
1465 bool LyXTextClassList::Read ()
1468 string real_file = LibFileSearch("", "textclass.lst");
1469 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1470 << real_file << "'" << endl;
1472 if (real_file.empty()) {
1473 lyxerr << "LyXTextClassList::Read: unable to find "
1474 "textclass file `" << MakeDisplayPath(real_file, 1000)
1475 << "'. Exiting." << endl;
1477 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1478 _("Check that the file \"textclass.lst\""),
1479 _("is installed correctly. Sorry, has to exit :-("));
1481 // This causes LyX to end... Not a desirable behaviour. Lgb
1482 // What do you propose? That the user gets a file dialog
1483 // and is allowed to hunt for the file? (Asger)
1484 // more that we have a layout for minimal.cls statically
1485 // compiled in... (Lgb)
1488 if (!lex.setFile(real_file)) {
1489 lyxerr << "LyXTextClassList::Read: "
1490 "lyxlex was not able to set file: "
1491 << real_file << endl;
1495 lyxerr << "LyXTextClassList::Read: unable to open "
1496 "textclass file `" << MakeDisplayPath(real_file, 1000)
1497 << "'\nCheck your installation. LyX can't continue."
1501 bool finished = false;
1502 string fname, clname, desc;
1503 // Parse config-file
1504 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1505 while (lex.IsOK() && !finished) {
1506 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1507 switch (lex.lex()) {
1508 case LyXLex::LEX_FEOF:
1512 fname = lex.GetString();
1513 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1515 clname = lex.GetString();
1516 lyxerr[Debug::TCLASS]
1517 << "Clname: " << clname << endl;
1519 desc = lex.GetString();
1520 lyxerr[Debug::TCLASS]
1521 << "Desc: " << desc << endl;
1522 // This code is run when we have
1523 // fname, clname and desc
1524 LyXTextClass tmpl(fname,
1528 debugging(Debug::TCLASS)) {
1536 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1538 if (classlist.size() == 0) {
1539 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1541 WriteAlert(_("LyX wasn't able to find any layout description!"),
1542 _("Check the contents of the file \"textclass.lst\""),
1543 _("Sorry, has to exit :-("));
1546 // Ok everything loaded ok, now sort the list.
1547 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1553 Returns false if this fails
1556 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1559 if (number < classlist.size()) {
1560 classlist[number].load();
1561 if (classlist[number].numLayouts() == 0) {