1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
21 #include "support/filetools.h"
22 #include "lyx_gui_misc.h"
25 #include "support/LAssert.h"
32 // Global variable: textclass table.
33 LyXTextClassList textclasslist;
36 // Reads the style files
39 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
41 if (!textclasslist.Read()) {
42 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
43 "during parsing.\n Exiting." << endl;
47 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
51 // The order of the LayoutTags enum is no more important. [asierra300396]
62 //LT_ENVIRONMENT_DEFAULT,
78 LT_LABELSTRING_APPENDIX,
101 /////////////////////
103 // Constructor for layout
104 LyXLayout::LyXLayout ()
106 margintype = MARGIN_STATIC;
107 latextype = LATEX_PARAGRAPH;
111 font = LyXFont(LyXFont::ALL_INHERIT);
112 labelfont = LyXFont(LyXFont::ALL_INHERIT);
113 resfont = LyXFont(LyXFont::ALL_SANE);
114 reslabelfont = LyXFont(LyXFont::ALL_SANE);
115 nextnoindent = false;
120 labelbottomsep = 0.0;
122 align = LYX_ALIGN_BLOCK;
123 alignpossible = LYX_ALIGN_BLOCK;
124 labeltype = LABEL_NO_LABEL;
125 endlabeltype = END_LABEL_NO_LABEL;
126 // Should or should not. That is the question.
127 // spacing.set(Spacing::OneHalf);
130 newline_allowed = true;
131 free_spacing = false;
135 // Reads a layout definition from file
136 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
138 // This table is sorted alphabetically [asierra 30March96]
139 keyword_item layoutTags[] = {
140 { "align", LT_ALIGN },
141 { "alignpossible", LT_ALIGNPOSSIBLE },
142 { "bottomsep", LT_BOTTOMSEP },
143 { "copystyle", LT_COPYSTYLE },
145 { "endlabelstring", LT_ENDLABELSTRING },
146 { "endlabeltype", LT_ENDLABELTYPE },
147 { "fill_bottom", LT_FILL_BOTTOM },
148 { "fill_top", LT_FILL_TOP },
150 { "freespacing", LT_FREE_SPACING },
151 { "intitle", LT_INTITLE },
152 { "itemsep", LT_ITEMSEP },
153 { "keepempty", LT_KEEPEMPTY },
154 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
155 { "labelfont", LT_LABELFONT },
156 { "labelindent", LT_LABELINDENT },
157 { "labelsep", LT_LABELSEP },
158 { "labelstring", LT_LABELSTRING },
159 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
160 { "labeltype", LT_LABELTYPE },
161 { "latexname", LT_LATEXNAME },
162 { "latexparam", LT_LATEXPARAM },
163 { "latextype", LT_LATEXTYPE },
164 { "leftmargin", LT_LEFTMARGIN },
165 { "margin", LT_MARGIN },
166 { "needprotect", LT_NEED_PROTECT },
167 { "newline", LT_NEWLINE },
168 { "nextnoindent", LT_NEXTNOINDENT },
169 { "obsoletedby", LT_OBSOLETEDBY },
170 { "parindent", LT_PARINDENT },
171 { "parsep", LT_PARSEP },
172 { "parskip", LT_PARSKIP },
173 { "preamble", LT_PREAMBLE },
174 { "rightmargin", LT_RIGHTMARGIN },
175 { "spacing", LT_SPACING },
176 { "textfont", LT_TEXTFONT },
177 { "topsep", LT_TOPSEP }
181 bool finished = false;
182 lexrc.pushTable(layoutTags, LT_INTITLE);
183 // parse style section
184 while (!finished && lexrc.IsOK() && !error) {
185 int le = lexrc.lex();
186 // See comment in lyxrc.C.
188 case LyXLex::LEX_FEOF:
191 case LyXLex::LEX_UNDEF: // parse error
192 lexrc.printError("Unknown layout tag `$$Token'");
197 switch(static_cast<LayoutTags>(le)) {
198 case LT_END: // end of structure
202 case LT_COPYSTYLE: // initialize with a known style
204 if (tclass.hasLayout(lexrc.GetString())) {
205 string tmpname = name_;
206 this->operator= (tclass.GetLayout(lexrc.GetString()));
209 lexrc.printError("Cannot copy known "
215 case LT_OBSOLETEDBY: // replace with a known style
217 if (tclass.hasLayout(lexrc.GetString())) {
218 string tmpname = name_;
219 this->operator= (tclass.GetLayout(lexrc.GetString()));
221 if (obsoleted_by().empty())
222 obsoleted_by_ = lexrc.GetString();
224 lexrc.printError("Cannot replace with"
231 case LT_MARGIN: // Margin style definition.
235 case LT_LATEXTYPE: // Latex style definition.
236 readLatexType(lexrc);
240 intitle = lexrc.next() && lexrc.GetInteger();
243 case LT_NEED_PROTECT:
244 needprotect = lexrc.next() && lexrc.GetInteger();
248 keepempty = lexrc.next() && lexrc.GetInteger();
261 labelfont.lyxRead(lexrc);
264 case LT_NEXTNOINDENT: // Indent next paragraph?
265 if (lexrc.next() && lexrc.GetInteger())
268 nextnoindent = false;
273 latexname_ = lexrc.GetString();
278 latexparam_ = lexrc.GetString();
282 preamble_ = lexrc.getLongString("EndPreamble");
286 readLabelType(lexrc);
289 case LT_ENDLABELTYPE:
290 readEndLabelType(lexrc);
293 case LT_LEFTMARGIN: // left margin type
295 leftmargin = lexrc.GetString();
298 case LT_RIGHTMARGIN: // right margin type
300 rightmargin = lexrc.GetString();
303 case LT_LABELINDENT: // label indenting flag
305 labelindent = lexrc.GetString();
308 case LT_PARINDENT: // paragraph indent. flag
310 parindent = lexrc.GetString();
313 case LT_PARSKIP: // paragraph skip size
315 parskip = lexrc.GetFloat();
318 case LT_ITEMSEP: // item separation size
320 itemsep = lexrc.GetFloat();
323 case LT_TOPSEP: // top separation size
325 topsep = lexrc.GetFloat();
328 case LT_BOTTOMSEP: // bottom separation size
330 bottomsep = lexrc.GetFloat();
333 case LT_LABEL_BOTTOMSEP: // label bottom separation size
335 labelbottomsep = lexrc.GetFloat();
338 case LT_LABELSEP: // label separator
340 labelsep = subst(lexrc.GetString(), 'x', ' ');
344 case LT_PARSEP: // par. separation size
346 parsep = lexrc.GetFloat();
349 case LT_FILL_TOP: // fill top flag
351 fill_top = lexrc.GetInteger();
354 case LT_FILL_BOTTOM: // fill bottom flag
356 fill_bottom = lexrc.GetInteger();
359 case LT_NEWLINE: // newlines allowed?
361 newline_allowed = lexrc.GetInteger();
364 case LT_ALIGN: // paragraph align
367 case LT_ALIGNPOSSIBLE: // paragraph allowed align
368 readAlignPossible(lexrc);
371 case LT_LABELSTRING: // label string definition
373 labelstring_ = lexrc.GetString();
376 case LT_ENDLABELSTRING: // endlabel string definition
378 endlabelstring_ = lexrc.GetString();
381 case LT_LABELSTRING_APPENDIX: // label string appendix definition
383 labelstring_appendix_ = lexrc.GetString();
386 case LT_FREE_SPACING: // Allow for free spacing.
388 free_spacing = lexrc.GetInteger();
391 case LT_SPACING: // setspace.sty
410 void LyXLayout::readAlign(LyXLex & lexrc)
412 keyword_item alignTags[] = {
413 { "block", AT_BLOCK },
414 { "center", AT_CENTER },
415 { "layout", AT_LAYOUT },
417 { "right", AT_RIGHT }
420 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
421 int le = lexrc.lex();
423 case LyXLex::LEX_UNDEF:
424 lexrc.printError("Unknown alignment `$$Token'");
428 switch(static_cast<AlignTags>(le)) {
430 align = LYX_ALIGN_BLOCK;
433 align = LYX_ALIGN_LEFT;
436 align = LYX_ALIGN_RIGHT;
439 align = LYX_ALIGN_CENTER;
442 align = LYX_ALIGN_LAYOUT;
448 void LyXLayout::readAlignPossible(LyXLex & lexrc)
450 keyword_item alignTags[] = {
451 { "block", AT_BLOCK },
452 { "center", AT_CENTER },
453 { "layout", AT_LAYOUT },
455 { "right", AT_RIGHT }
458 lexrc.pushTable(alignTags, AT_LAYOUT);
459 alignpossible = LYX_ALIGN_NONE;
460 int lineno = lexrc.GetLineNo();
462 int le = lexrc.lex();
464 case LyXLex::LEX_UNDEF:
465 lexrc.printError("Unknown alignment `$$Token'");
469 switch (static_cast<AlignTags>(le)) {
471 alignpossible |= LYX_ALIGN_BLOCK;
474 alignpossible |= LYX_ALIGN_LEFT;
477 alignpossible |= LYX_ALIGN_RIGHT;
480 alignpossible |= LYX_ALIGN_CENTER;
483 alignpossible |= LYX_ALIGN_LAYOUT;
486 } while (lineno == lexrc.GetLineNo());
495 LA_CENTERED_TOP_ENVIRONMENT,
500 LA_COUNTER_SUBSECTION,
501 LA_COUNTER_SUBSUBSECTION,
502 LA_COUNTER_PARAGRAPH,
503 LA_COUNTER_SUBPARAGRAPH,
513 static keyword_item labelTypeTags[] = {
514 { "bibliography", LA_BIBLIO },
515 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
516 { "counter_chapter", LA_COUNTER_CHAPTER },
517 { "counter_enumi", LA_COUNTER_ENUMI },
518 { "counter_enumii", LA_COUNTER_ENUMII },
519 { "counter_enumiii", LA_COUNTER_ENUMIII },
520 { "counter_enumiv", LA_COUNTER_ENUMIV },
521 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
522 { "counter_section", LA_COUNTER_SECTION },
523 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
524 { "counter_subsection", LA_COUNTER_SUBSECTION },
525 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
526 { "manual", LA_MANUAL },
527 { "no_label", LA_NO_LABEL },
528 { "sensitive", LA_SENSITIVE },
529 { "static", LA_STATIC },
530 { "top_environment", LA_TOP_ENVIRONMENT }
535 void LyXLayout::readLabelType(LyXLex & lexrc)
537 keyword_item labelTypeTags[] = {
538 { "bibliography", LA_BIBLIO },
539 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
540 { "counter_chapter", LA_COUNTER_CHAPTER },
541 { "counter_enumi", LA_COUNTER_ENUMI },
542 { "counter_enumii", LA_COUNTER_ENUMII },
543 { "counter_enumiii", LA_COUNTER_ENUMIII },
544 { "counter_enumiv", LA_COUNTER_ENUMIV },
545 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
546 { "counter_section", LA_COUNTER_SECTION },
547 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
548 { "counter_subsection", LA_COUNTER_SUBSECTION },
549 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
550 { "manual", LA_MANUAL },
551 { "no_label", LA_NO_LABEL },
552 { "sensitive", LA_SENSITIVE },
553 { "static", LA_STATIC },
554 { "top_environment", LA_TOP_ENVIRONMENT }
557 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
558 int le = lexrc.lex();
560 case LyXLex::LEX_UNDEF:
561 lexrc.printError("Unknown labeltype tag `$$Token'");
565 switch (static_cast<LabelTypeTags>(le)) {
567 labeltype = LABEL_NO_LABEL;
570 labeltype = LABEL_MANUAL;
572 case LA_TOP_ENVIRONMENT:
573 labeltype = LABEL_TOP_ENVIRONMENT;
575 case LA_CENTERED_TOP_ENVIRONMENT:
576 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
579 labeltype = LABEL_STATIC;
582 labeltype = LABEL_SENSITIVE;
584 case LA_COUNTER_CHAPTER:
585 labeltype = LABEL_COUNTER_CHAPTER;
587 case LA_COUNTER_SECTION:
588 labeltype = LABEL_COUNTER_SECTION;
590 case LA_COUNTER_SUBSECTION:
591 labeltype = LABEL_COUNTER_SUBSECTION;
593 case LA_COUNTER_SUBSUBSECTION:
594 labeltype = LABEL_COUNTER_SUBSUBSECTION;
596 case LA_COUNTER_PARAGRAPH:
597 labeltype = LABEL_COUNTER_PARAGRAPH;
599 case LA_COUNTER_SUBPARAGRAPH:
600 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
602 case LA_COUNTER_ENUMI:
603 labeltype = LABEL_COUNTER_ENUMI;
605 case LA_COUNTER_ENUMII:
606 labeltype = LABEL_COUNTER_ENUMII;
608 case LA_COUNTER_ENUMIII:
609 labeltype = LABEL_COUNTER_ENUMIII;
611 case LA_COUNTER_ENUMIV:
612 labeltype = LABEL_COUNTER_ENUMIV;
615 labeltype = LABEL_BIBLIO;
620 static keyword_item endlabelTypeTags[] = {
621 { "box", END_LABEL_BOX },
622 { "filled_box", END_LABEL_FILLED_BOX },
623 { "no_label", END_LABEL_NO_LABEL },
624 { "static", END_LABEL_STATIC }
627 void LyXLayout::readEndLabelType(LyXLex & lexrc)
629 pushpophelper pph(lexrc, endlabelTypeTags,
630 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
631 int le = lexrc.lex();
633 case LyXLex::LEX_UNDEF:
634 lexrc.printError("Unknown labeltype tag `$$Token'");
636 case END_LABEL_STATIC:
638 case END_LABEL_FILLED_BOX:
639 case END_LABEL_NO_LABEL:
640 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
643 lyxerr << "Unhandled value " << le
644 << " in LyXLayout::readEndLabelType." << endl;
650 static keyword_item marginTags[] = {
651 { "dynamic", MARGIN_DYNAMIC },
652 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
653 { "manual", MARGIN_MANUAL },
654 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
655 { "static", MARGIN_STATIC }
659 void LyXLayout::readMargin(LyXLex & lexrc)
661 keyword_item marginTags[] = {
662 { "dynamic", MARGIN_DYNAMIC },
663 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
664 { "manual", MARGIN_MANUAL },
665 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
666 { "static", MARGIN_STATIC }
669 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
671 int le = lexrc.lex();
673 case LyXLex::LEX_UNDEF:
674 lexrc.printError("Unknown margin type tag `$$Token'");
679 case MARGIN_FIRST_DYNAMIC:
680 case MARGIN_RIGHT_ADDRESS_BOX:
681 margintype = static_cast<LYX_MARGIN_TYPE>(le);
684 lyxerr << "Unhandled value " << le
685 << " in LyXLayout::readMargin." << endl;
692 static keyword_item latexTypeTags[] = {
693 { "command", LATEX_COMMAND },
694 { "environment", LATEX_ENVIRONMENT },
695 { "item_environment", LATEX_ITEM_ENVIRONMENT },
696 { "list_environment", LATEX_LIST_ENVIRONMENT },
697 { "paragraph", LATEX_PARAGRAPH }
702 void LyXLayout::readLatexType(LyXLex & lexrc)
704 keyword_item latexTypeTags[] = {
705 { "command", LATEX_COMMAND },
706 { "environment", LATEX_ENVIRONMENT },
707 { "item_environment", LATEX_ITEM_ENVIRONMENT },
708 { "list_environment", LATEX_LIST_ENVIRONMENT },
709 { "paragraph", LATEX_PARAGRAPH }
712 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
713 int le = lexrc.lex();
715 case LyXLex::LEX_UNDEF:
716 lexrc.printError("Unknown latextype tag `$$Token'");
718 case LATEX_PARAGRAPH:
720 case LATEX_ENVIRONMENT:
721 case LATEX_ITEM_ENVIRONMENT:
722 case LATEX_LIST_ENVIRONMENT:
723 latextype = static_cast<LYX_LATEX_TYPES>(le);
726 lyxerr << "Unhandled value " << le
727 << " in LyXLayout::readLatexType." << endl;
734 ST_SPACING_SINGLE = 1,
742 static keyword_item spacingTags[] = {
743 {"double", ST_SPACING_DOUBLE },
744 {"onehalf", ST_SPACING_ONEHALF },
745 {"other", ST_OTHER },
746 {"single", ST_SPACING_SINGLE }
751 void LyXLayout::readSpacing(LyXLex & lexrc)
753 keyword_item spacingTags[] = {
754 {"double", ST_SPACING_DOUBLE },
755 {"onehalf", ST_SPACING_ONEHALF },
756 {"other", ST_OTHER },
757 {"single", ST_SPACING_SINGLE }
760 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
761 int le = lexrc.lex();
763 case LyXLex::LEX_UNDEF:
764 lexrc.printError("Unknown spacing token `$$Token'");
768 switch(static_cast<SpacingTags>(le)) {
769 case ST_SPACING_SINGLE:
770 spacing.set(Spacing::Single);
772 case ST_SPACING_ONEHALF:
773 spacing.set(Spacing::Onehalf);
775 case ST_SPACING_DOUBLE:
776 spacing.set(Spacing::Double);
780 spacing.set(Spacing::Other, lexrc.GetFloat());
786 /* ******************************************************************* */
788 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
790 : name_(fn), latexname_(cln), description_(desc)
797 pagestyle_ = "default";
798 maxcounter_ = LABEL_COUNTER_CHAPTER;
799 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
800 opt_fontsize_ = "10|11|12";
801 opt_pagestyle_ = "empty|plain|headings|fancy";
807 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
809 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
810 if (!lay.Read(lexrc, *this)) {
812 lay.resfont = lay.font;
813 lay.resfont.realize(defaultfont());
814 lay.reslabelfont = lay.labelfont;
815 lay.reslabelfont.realize(defaultfont());
816 return false; // no errors
818 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
846 static keyword_item textClassTags[] = {
847 { "classoptions", TC_CLASSOPTIONS },
848 { "columns", TC_COLUMNS },
849 { "defaultfont", TC_DEFAULTFONT },
850 { "input", TC_INPUT },
851 { "leftmargin", TC_LEFTMARGIN },
852 { "maxcounter", TC_MAXCOUNTER },
853 { "nostyle", TC_NOSTYLE },
854 { "outputtype", TC_OUTPUTTYPE },
855 { "pagestyle", TC_PAGESTYLE },
856 { "preamble", TC_PREAMBLE },
857 { "providesamsmath", TC_PROVIDESAMSMATH },
858 { "providesmakeidx", TC_PROVIDESMAKEIDX },
859 { "providesurl", TC_PROVIDESURL },
860 { "rightmargin", TC_RIGHTMARGIN },
861 { "secnumdepth", TC_SECNUMDEPTH },
862 { "sides", TC_SIDES },
863 { "style", TC_STYLE },
864 { "tocdepth", TC_TOCDEPTH }
869 // Reads a textclass structure from file.
870 bool LyXTextClass::Read(string const & filename, bool merge)
872 keyword_item textClassTags[] = {
873 { "classoptions", TC_CLASSOPTIONS },
874 { "columns", TC_COLUMNS },
875 { "defaultfont", TC_DEFAULTFONT },
876 { "input", TC_INPUT },
877 { "leftmargin", TC_LEFTMARGIN },
878 { "maxcounter", TC_MAXCOUNTER },
879 { "nostyle", TC_NOSTYLE },
880 { "outputtype", TC_OUTPUTTYPE },
881 { "pagestyle", TC_PAGESTYLE },
882 { "preamble", TC_PREAMBLE },
883 { "providesamsmath", TC_PROVIDESAMSMATH },
884 { "providesmakeidx", TC_PROVIDESMAKEIDX },
885 { "providesurl", TC_PROVIDESURL },
886 { "rightmargin", TC_RIGHTMARGIN },
887 { "secnumdepth", TC_SECNUMDEPTH },
888 { "sides", TC_SIDES },
889 { "style", TC_STYLE },
890 { "tocdepth", TC_TOCDEPTH }
894 lyxerr[Debug::TCLASS] << "Reading textclass "
895 << MakeDisplayPath(filename)
898 lyxerr[Debug::TCLASS] << "Reading input file "
899 << MakeDisplayPath(filename)
902 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
905 lexrc.setFile(filename);
906 if (!lexrc.IsOK()) error = true;
909 while (lexrc.IsOK() && !error) {
910 int le = lexrc.lex();
912 case LyXLex::LEX_FEOF:
915 case LyXLex::LEX_UNDEF:
916 lexrc.printError("Unknown TextClass tag `$$Token'");
921 switch(static_cast<TextClassTags>(le)) {
922 case TC_OUTPUTTYPE: // output type definition
923 readOutputType(lexrc);
926 case TC_INPUT: // Include file
928 string tmp = LibFileSearch("layouts",
932 if (Read(tmp, true)) {
933 lexrc.printError("Error reading input"
942 string name = subst(lexrc.GetString(),
944 if (hasLayout(name)) {
945 LyXLayout & lay = GetLayout(name);
946 error = do_readStyle(lexrc, lay);
950 if (!(error = do_readStyle(lexrc, lay)))
951 layoutlist.push_back(lay);
955 lexrc.printError("No name given for style: `$$Token'.");
962 string style = subst(lexrc.GetString(),
964 if (!delete_layout(style))
965 lexrc.printError("Cannot delete style"
972 columns_ = lexrc.GetInteger();
977 switch(lexrc.GetInteger()) {
978 case 1: sides_ = OneSide; break;
979 case 2: sides_ = TwoSides; break;
981 lyxerr << "Impossible number of page"
982 " sides, setting to one."
992 pagestyle_ = strip(lexrc.GetString());
996 defaultfont_.lyxRead(lexrc);
997 if (!defaultfont_.resolved()) {
998 lexrc.printError("Warning: defaultfont should "
999 "be fully instantiated!");
1000 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
1005 readMaxCounter(lexrc);
1008 case TC_SECNUMDEPTH:
1010 secnumdepth_ = lexrc.GetInteger();
1015 tocdepth_ = lexrc.GetInteger();
1018 // First step to support options
1019 case TC_CLASSOPTIONS:
1020 readClassOptions(lexrc);
1024 preamble_ = lexrc.getLongString("EndPreamble");
1027 case TC_PROVIDESAMSMATH:
1028 if (lexrc.next() && lexrc.GetInteger())
1029 provides_ |= amsmath;
1032 case TC_PROVIDESMAKEIDX:
1033 if (lexrc.next() && lexrc.GetInteger())
1034 provides_ |= makeidx;
1037 case TC_PROVIDESURL:
1038 if (lexrc.next() && lexrc.GetInteger())
1042 case TC_LEFTMARGIN: // left margin type
1044 leftmargin_ = lexrc.GetString();
1047 case TC_RIGHTMARGIN: // right margin type
1049 rightmargin_ = lexrc.GetString();
1054 if (!merge) { // we are at top level here.
1055 lyxerr[Debug::TCLASS] << "Finished reading textclass "
1056 << MakeDisplayPath(filename)
1059 lyxerr[Debug::TCLASS] << "Finished reading input file "
1060 << MakeDisplayPath(filename)
1068 static keyword_item outputTypeTags[] = {
1069 { "docbook", DOCBOOK },
1071 { "linuxdoc", LINUXDOC },
1072 { "literate", LITERATE }
1076 void LyXTextClass::readOutputType(LyXLex & lexrc)
1078 keyword_item outputTypeTags[] = {
1079 { "docbook", DOCBOOK },
1081 { "linuxdoc", LINUXDOC },
1082 { "literate", LITERATE }
1085 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1087 int le = lexrc.lex();
1089 case LyXLex::LEX_UNDEF:
1090 lexrc.printError("Unknown output type `$$Token'");
1096 outputType_ = static_cast<OutputType>(le);
1099 lyxerr << "Unhandled value " << le
1100 << " in LyXTextClass::readOutputType." << endl;
1107 enum MaxCounterTags {
1108 MC_COUNTER_CHAPTER = 1,
1110 MC_COUNTER_SUBSECTION,
1111 MC_COUNTER_SUBSUBSECTION,
1112 MC_COUNTER_PARAGRAPH,
1113 MC_COUNTER_SUBPARAGRAPH,
1122 static keyword_item maxCounterTags[] = {
1123 {"counter_chapter", MC_COUNTER_CHAPTER },
1124 {"counter_enumi", MC_COUNTER_ENUMI },
1125 {"counter_enumii", MC_COUNTER_ENUMII },
1126 {"counter_enumiii", MC_COUNTER_ENUMIII },
1127 {"counter_enumiv", MC_COUNTER_ENUMIV },
1128 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1129 {"counter_section", MC_COUNTER_SECTION },
1130 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1131 {"counter_subsection", MC_COUNTER_SUBSECTION },
1132 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1137 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1139 keyword_item maxCounterTags[] = {
1140 {"counter_chapter", MC_COUNTER_CHAPTER },
1141 {"counter_enumi", MC_COUNTER_ENUMI },
1142 {"counter_enumii", MC_COUNTER_ENUMII },
1143 {"counter_enumiii", MC_COUNTER_ENUMIII },
1144 {"counter_enumiv", MC_COUNTER_ENUMIV },
1145 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1146 {"counter_section", MC_COUNTER_SECTION },
1147 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1148 {"counter_subsection", MC_COUNTER_SUBSECTION },
1149 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1152 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1153 int le = lexrc.lex();
1155 case LyXLex::LEX_UNDEF:
1156 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1160 switch (static_cast<MaxCounterTags>(le)) {
1161 case MC_COUNTER_CHAPTER:
1162 maxcounter_ = LABEL_COUNTER_CHAPTER;
1164 case MC_COUNTER_SECTION:
1165 maxcounter_ = LABEL_COUNTER_SECTION;
1167 case MC_COUNTER_SUBSECTION:
1168 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1170 case MC_COUNTER_SUBSUBSECTION:
1171 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1173 case MC_COUNTER_PARAGRAPH:
1174 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1176 case MC_COUNTER_SUBPARAGRAPH:
1177 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1179 case MC_COUNTER_ENUMI:
1180 maxcounter_ = LABEL_COUNTER_ENUMI;
1182 case MC_COUNTER_ENUMII:
1183 maxcounter_ = LABEL_COUNTER_ENUMII;
1185 case MC_COUNTER_ENUMIII:
1186 maxcounter_ = LABEL_COUNTER_ENUMIII;
1188 case MC_COUNTER_ENUMIV:
1189 maxcounter_ = LABEL_COUNTER_ENUMIV;
1195 enum ClassOptionsTags {
1204 static keyword_item classOptionsTags[] = {
1206 {"fontsize", CO_FONTSIZE },
1207 {"other", CO_OTHER },
1208 {"pagestyle", CO_PAGESTYLE }
1213 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1215 keyword_item classOptionsTags[] = {
1217 {"fontsize", CO_FONTSIZE },
1218 {"other", CO_OTHER },
1219 {"pagestyle", CO_PAGESTYLE }
1222 lexrc.pushTable(classOptionsTags, CO_END);
1223 bool getout = false;
1224 while (!getout && lexrc.IsOK()) {
1225 int le = lexrc.lex();
1227 case LyXLex::LEX_UNDEF:
1228 lexrc.printError("Unknown ClassOption tag `$$Token'");
1232 switch (static_cast<ClassOptionsTags>(le)) {
1235 opt_fontsize_ = strip(lexrc.GetString());
1239 opt_pagestyle_ = strip(lexrc.GetString());
1243 options_ = lexrc.GetString();
1254 bool LyXTextClass::hasLayout(string const & name) const
1256 for (LayoutList::const_iterator cit = layoutlist.begin();
1257 cit != layoutlist.end(); ++cit) {
1258 if ((*cit).name() == name)
1265 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1267 for (LayoutList::const_iterator cit = layoutlist.begin();
1268 cit != layoutlist.end(); ++cit) {
1269 if ((*cit).name() == name)
1272 Assert(false); // we actually require the name to exist.
1273 return layoutlist.front();
1277 LyXLayout & LyXTextClass::GetLayout(string const & name)
1279 for (LayoutList::iterator it = layoutlist.begin();
1280 it != layoutlist.end(); ++it) {
1281 if ((*it).name() == name)
1284 Assert(false); // we actually require the name to exist.
1285 return layoutlist.front();
1289 bool LyXTextClass::delete_layout (string const & name)
1291 for(LayoutList::iterator it = layoutlist.begin();
1292 it != layoutlist.end(); ++it) {
1293 if ((*it).name() == name) {
1294 layoutlist.erase(it);
1302 // Load textclass info if not loaded yet
1303 void LyXTextClass::load()
1308 string real_file = LibFileSearch("layouts", name_, "layout");
1310 if (Read(real_file)) {
1311 lyxerr << "Error reading `"
1312 << MakeDisplayPath(real_file)
1313 << "'\n(Check `" << name_
1314 << "')\nCheck your installation and "
1315 "try Options/Reconfigure..." << endl;
1321 //////////////////////////////////////////
1323 // Gets textclass number from name
1324 pair<bool, LyXTextClassList::size_type>
1325 LyXTextClassList::NumberOfClass(string const & textclass) const
1327 for (ClassList::const_iterator cit = classlist.begin();
1328 cit != classlist.end(); ++cit) {
1329 if ((*cit).name() == textclass)
1330 return make_pair(true,
1331 size_type(cit - classlist.begin()));
1333 return make_pair(false, size_type(0));
1337 // Gets layout structure from style number and textclass number
1339 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1340 LyXTextClass::size_type layout) const
1342 classlist[textclass].load();
1343 if (layout < classlist[textclass].numLayouts())
1344 return classlist[textclass][layout];
1345 return classlist[textclass][0];
1349 // Gets layout number from name and textclass number
1350 pair<bool, LyXTextClass::size_type>
1351 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1352 string const & name) const
1354 classlist[textclass].load();
1355 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1356 if (classlist[textclass][i].name() == name)
1357 return make_pair(true, i);
1359 if (name == "dummy")
1360 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1361 return make_pair(false, LyXTextClass::size_type(0)); // not found
1365 // Gets a layout (style) name from layout number and textclass number
1367 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1368 LyXTextClass::size_type layout) const
1370 static string dummy("dummy");
1371 classlist[textclass].load();
1372 if (layout < classlist[textclass].numLayouts())
1373 return classlist[textclass][layout].name();
1378 // Gets a textclass name from number
1380 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1382 static string dummy("dummy");
1383 if (classlist.size() == 0) {
1386 Assert(number < classlist.size());
1387 return classlist[number].name();
1391 // Gets a textclass latexname from number
1393 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1395 static string dummy("dummy");
1396 classlist[number].load();
1397 if (classlist.size() == 0) {
1400 Assert(number < classlist.size());
1401 return classlist[number].latexname();
1405 // Gets a textclass description from number
1407 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1409 static string dummy("dummy");
1410 if (classlist.size() == 0) {
1413 Assert(number < classlist.size());
1414 return classlist[number].description();
1418 // Gets a textclass structure from number
1419 LyXTextClass const &
1420 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1422 classlist[textclass].load();
1423 if (textclass < classlist.size())
1424 return classlist[textclass];
1426 return classlist[0];
1430 void LyXTextClassList::Add(LyXTextClass const & t)
1432 classlist.push_back(t);
1436 // used when sorting the textclass list.
1437 class less_textclass_desc {
1439 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1440 return tc1.description() < tc2.description();
1445 // Reads LyX textclass definitions according to textclass config file
1446 bool LyXTextClassList::Read ()
1449 string real_file = LibFileSearch("", "textclass.lst");
1450 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1451 << real_file << "'" << endl;
1453 if (real_file.empty()) {
1454 lyxerr << "LyXTextClassList::Read: unable to find "
1455 "textclass file `" << MakeDisplayPath(real_file, 1000)
1456 << "'. Exiting." << endl;
1458 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1459 _("Check that the file \"textclass.lst\""),
1460 _("is installed correctly. Sorry, has to exit :-("));
1462 // This causes LyX to end... Not a desirable behaviour. Lgb
1463 // What do you propose? That the user gets a file dialog
1464 // and is allowed to hunt for the file? (Asger)
1465 // more that we have a layout for minimal.cls statically
1466 // compiled in... (Lgb)
1469 if (!lex.setFile(real_file)) {
1470 lyxerr << "LyXTextClassList::Read: "
1471 "lyxlex was not able to set file: "
1472 << real_file << endl;
1476 lyxerr << "LyXTextClassList::Read: unable to open "
1477 "textclass file `" << MakeDisplayPath(real_file, 1000)
1478 << "'\nCheck your installation. LyX can't continue."
1482 bool finished = false;
1483 string fname, clname, desc;
1484 // Parse config-file
1485 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1486 while (lex.IsOK() && !finished) {
1487 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1488 switch (lex.lex()) {
1489 case LyXLex::LEX_FEOF:
1493 fname = lex.GetString();
1494 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1496 clname = lex.GetString();
1497 lyxerr[Debug::TCLASS]
1498 << "Clname: " << clname << endl;
1500 desc = lex.GetString();
1501 lyxerr[Debug::TCLASS]
1502 << "Desc: " << desc << endl;
1503 // This code is run when we have
1504 // fname, clname and desc
1505 LyXTextClass tmpl(fname,
1509 debugging(Debug::TCLASS)) {
1517 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1519 if (classlist.size() == 0) {
1520 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1522 WriteAlert(_("LyX wasn't able to find any layout description!"),
1523 _("Check the contents of the file \"textclass.lst\""),
1524 _("Sorry, has to exit :-("));
1527 // Ok everything loaded ok, now sort the list.
1528 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1534 Returns false if this fails
1537 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1540 if (number < classlist.size()) {
1541 classlist[number].load();
1542 if (classlist[number].numLayouts() == 0) {
1552 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1555 case LyXTextClass::OneSide:
1558 case LyXTextClass::TwoSides: