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,
100 /////////////////////
102 // Constructor for layout
103 LyXLayout::LyXLayout ()
105 margintype = MARGIN_STATIC;
106 latextype = LATEX_PARAGRAPH;
110 font = LyXFont(LyXFont::ALL_INHERIT);
111 labelfont = LyXFont(LyXFont::ALL_INHERIT);
112 resfont = LyXFont(LyXFont::ALL_SANE);
113 reslabelfont = LyXFont(LyXFont::ALL_SANE);
114 nextnoindent = false;
119 labelbottomsep = 0.0;
121 align = LYX_ALIGN_BLOCK;
122 alignpossible = LYX_ALIGN_BLOCK;
123 labeltype = LABEL_NO_LABEL;
124 endlabeltype = END_LABEL_NO_LABEL;
125 // Should or should not. That is the question.
126 // spacing.set(Spacing::OneHalf);
129 newline_allowed = true;
130 free_spacing = false;
134 // Reads a layout definition from file
135 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
137 // This table is sorted alphabetically [asierra 30March96]
138 keyword_item layoutTags[] = {
139 { "align", LT_ALIGN },
140 { "alignpossible", LT_ALIGNPOSSIBLE },
141 { "bottomsep", LT_BOTTOMSEP },
142 { "copystyle", LT_COPYSTYLE },
144 { "endlabeltype", LT_ENDLABELTYPE },
145 { "fill_bottom", LT_FILL_BOTTOM },
146 { "fill_top", LT_FILL_TOP },
148 { "freespacing", LT_FREE_SPACING },
149 { "intitle", LT_INTITLE },
150 { "itemsep", LT_ITEMSEP },
151 { "keepempty", LT_KEEPEMPTY },
152 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
153 { "labelfont", LT_LABELFONT },
154 { "labelindent", LT_LABELINDENT },
155 { "labelsep", LT_LABELSEP },
156 { "labelstring", LT_LABELSTRING },
157 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
158 { "labeltype", LT_LABELTYPE },
159 { "latexname", LT_LATEXNAME },
160 { "latexparam", LT_LATEXPARAM },
161 { "latextype", LT_LATEXTYPE },
162 { "leftmargin", LT_LEFTMARGIN },
163 { "margin", LT_MARGIN },
164 { "needprotect", LT_NEED_PROTECT },
165 { "newline", LT_NEWLINE },
166 { "nextnoindent", LT_NEXTNOINDENT },
167 { "obsoletedby", LT_OBSOLETEDBY },
168 { "parindent", LT_PARINDENT },
169 { "parsep", LT_PARSEP },
170 { "parskip", LT_PARSKIP },
171 { "preamble", LT_PREAMBLE },
172 { "rightmargin", LT_RIGHTMARGIN },
173 { "spacing", LT_SPACING },
174 { "textfont", LT_TEXTFONT },
175 { "topsep", LT_TOPSEP }
179 bool finished = false;
180 lexrc.pushTable(layoutTags, LT_INTITLE);
181 // parse style section
182 while (!finished && lexrc.IsOK() && !error) {
183 int le = lexrc.lex();
184 // See comment in lyxrc.C.
186 case LyXLex::LEX_FEOF:
189 case LyXLex::LEX_UNDEF: // parse error
190 lexrc.printError("Unknown layout tag `$$Token'");
195 switch(static_cast<LayoutTags>(le)) {
196 case LT_END: // end of structure
200 case LT_COPYSTYLE: // initialize with a known style
202 if (tclass.hasLayout(lexrc.GetString())) {
203 string tmpname = name_;
204 this->operator= (tclass.GetLayout(lexrc.GetString()));
207 lexrc.printError("Cannot copy known "
213 case LT_OBSOLETEDBY: // replace with a known style
215 if (tclass.hasLayout(lexrc.GetString())) {
216 string tmpname = name_;
217 this->operator= (tclass.GetLayout(lexrc.GetString()));
219 if (obsoleted_by().empty())
220 obsoleted_by_ = lexrc.GetString();
222 lexrc.printError("Cannot replace with"
229 case LT_MARGIN: // Margin style definition.
233 case LT_LATEXTYPE: // Latex style definition.
234 readLatexType(lexrc);
238 intitle = lexrc.next() && lexrc.GetInteger();
241 case LT_NEED_PROTECT:
242 needprotect = lexrc.next() && lexrc.GetInteger();
246 keepempty = lexrc.next() && lexrc.GetInteger();
259 labelfont.lyxRead(lexrc);
262 case LT_NEXTNOINDENT: // Indent next paragraph?
263 if (lexrc.next() && lexrc.GetInteger())
266 nextnoindent = false;
271 latexname_ = lexrc.GetString();
276 latexparam_ = lexrc.GetString();
280 preamble_ = lexrc.getLongString("EndPreamble");
284 readLabelType(lexrc);
287 case LT_ENDLABELTYPE:
288 readEndLabelType(lexrc);
291 case LT_LEFTMARGIN: // left margin type
293 leftmargin = lexrc.GetString();
296 case LT_RIGHTMARGIN: // right margin type
298 rightmargin = lexrc.GetString();
301 case LT_LABELINDENT: // label indenting flag
303 labelindent = lexrc.GetString();
306 case LT_PARINDENT: // paragraph indent. flag
308 parindent = lexrc.GetString();
311 case LT_PARSKIP: // paragraph skip size
313 parskip = lexrc.GetFloat();
316 case LT_ITEMSEP: // item separation size
318 itemsep = lexrc.GetFloat();
321 case LT_TOPSEP: // top separation size
323 topsep = lexrc.GetFloat();
326 case LT_BOTTOMSEP: // bottom separation size
328 bottomsep = lexrc.GetFloat();
331 case LT_LABEL_BOTTOMSEP: // label bottom separation size
333 labelbottomsep = lexrc.GetFloat();
336 case LT_LABELSEP: // label separator
338 labelsep = subst(lexrc.GetString(), 'x', ' ');
342 case LT_PARSEP: // par. separation size
344 parsep = lexrc.GetFloat();
347 case LT_FILL_TOP: // fill top flag
349 fill_top = lexrc.GetInteger();
352 case LT_FILL_BOTTOM: // fill bottom flag
354 fill_bottom = lexrc.GetInteger();
357 case LT_NEWLINE: // newlines allowed?
359 newline_allowed = lexrc.GetInteger();
362 case LT_ALIGN: // paragraph align
365 case LT_ALIGNPOSSIBLE: // paragraph allowed align
366 readAlignPossible(lexrc);
369 case LT_LABELSTRING: // label string definition
371 labelstring_ = lexrc.GetString();
374 case LT_LABELSTRING_APPENDIX: // label string appendix definition
376 labelstring_appendix_ = lexrc.GetString();
379 case LT_FREE_SPACING: // Allow for free spacing.
381 free_spacing = lexrc.GetInteger();
384 case LT_SPACING: // setspace.sty
403 void LyXLayout::readAlign(LyXLex & lexrc)
405 keyword_item alignTags[] = {
406 { "block", AT_BLOCK },
407 { "center", AT_CENTER },
408 { "layout", AT_LAYOUT },
410 { "right", AT_RIGHT }
413 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
414 int le = lexrc.lex();
416 case LyXLex::LEX_UNDEF:
417 lexrc.printError("Unknown alignment `$$Token'");
421 switch(static_cast<AlignTags>(le)) {
423 align = LYX_ALIGN_BLOCK;
426 align = LYX_ALIGN_LEFT;
429 align = LYX_ALIGN_RIGHT;
432 align = LYX_ALIGN_CENTER;
435 align = LYX_ALIGN_LAYOUT;
441 void LyXLayout::readAlignPossible(LyXLex & lexrc)
443 keyword_item alignTags[] = {
444 { "block", AT_BLOCK },
445 { "center", AT_CENTER },
446 { "layout", AT_LAYOUT },
448 { "right", AT_RIGHT }
451 lexrc.pushTable(alignTags, AT_LAYOUT);
452 alignpossible = LYX_ALIGN_NONE;
453 int lineno = lexrc.GetLineNo();
455 int le = lexrc.lex();
457 case LyXLex::LEX_UNDEF:
458 lexrc.printError("Unknown alignment `$$Token'");
462 switch (static_cast<AlignTags>(le)) {
464 alignpossible |= LYX_ALIGN_BLOCK;
467 alignpossible |= LYX_ALIGN_LEFT;
470 alignpossible |= LYX_ALIGN_RIGHT;
473 alignpossible |= LYX_ALIGN_CENTER;
476 alignpossible |= LYX_ALIGN_LAYOUT;
479 } while (lineno == lexrc.GetLineNo());
488 LA_CENTERED_TOP_ENVIRONMENT,
493 LA_COUNTER_SUBSECTION,
494 LA_COUNTER_SUBSUBSECTION,
495 LA_COUNTER_PARAGRAPH,
496 LA_COUNTER_SUBPARAGRAPH,
506 static keyword_item labelTypeTags[] = {
507 { "bibliography", LA_BIBLIO },
508 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
509 { "counter_chapter", LA_COUNTER_CHAPTER },
510 { "counter_enumi", LA_COUNTER_ENUMI },
511 { "counter_enumii", LA_COUNTER_ENUMII },
512 { "counter_enumiii", LA_COUNTER_ENUMIII },
513 { "counter_enumiv", LA_COUNTER_ENUMIV },
514 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
515 { "counter_section", LA_COUNTER_SECTION },
516 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
517 { "counter_subsection", LA_COUNTER_SUBSECTION },
518 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
519 { "manual", LA_MANUAL },
520 { "no_label", LA_NO_LABEL },
521 { "sensitive", LA_SENSITIVE },
522 { "static", LA_STATIC },
523 { "top_environment", LA_TOP_ENVIRONMENT }
528 void LyXLayout::readLabelType(LyXLex & lexrc)
530 keyword_item labelTypeTags[] = {
531 { "bibliography", LA_BIBLIO },
532 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
533 { "counter_chapter", LA_COUNTER_CHAPTER },
534 { "counter_enumi", LA_COUNTER_ENUMI },
535 { "counter_enumii", LA_COUNTER_ENUMII },
536 { "counter_enumiii", LA_COUNTER_ENUMIII },
537 { "counter_enumiv", LA_COUNTER_ENUMIV },
538 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
539 { "counter_section", LA_COUNTER_SECTION },
540 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
541 { "counter_subsection", LA_COUNTER_SUBSECTION },
542 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
543 { "manual", LA_MANUAL },
544 { "no_label", LA_NO_LABEL },
545 { "sensitive", LA_SENSITIVE },
546 { "static", LA_STATIC },
547 { "top_environment", LA_TOP_ENVIRONMENT }
550 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
551 int le = lexrc.lex();
553 case LyXLex::LEX_UNDEF:
554 lexrc.printError("Unknown labeltype tag `$$Token'");
558 switch (static_cast<LabelTypeTags>(le)) {
560 labeltype = LABEL_NO_LABEL;
563 labeltype = LABEL_MANUAL;
565 case LA_TOP_ENVIRONMENT:
566 labeltype = LABEL_TOP_ENVIRONMENT;
568 case LA_CENTERED_TOP_ENVIRONMENT:
569 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
572 labeltype = LABEL_STATIC;
575 labeltype = LABEL_SENSITIVE;
577 case LA_COUNTER_CHAPTER:
578 labeltype = LABEL_COUNTER_CHAPTER;
580 case LA_COUNTER_SECTION:
581 labeltype = LABEL_COUNTER_SECTION;
583 case LA_COUNTER_SUBSECTION:
584 labeltype = LABEL_COUNTER_SUBSECTION;
586 case LA_COUNTER_SUBSUBSECTION:
587 labeltype = LABEL_COUNTER_SUBSUBSECTION;
589 case LA_COUNTER_PARAGRAPH:
590 labeltype = LABEL_COUNTER_PARAGRAPH;
592 case LA_COUNTER_SUBPARAGRAPH:
593 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
595 case LA_COUNTER_ENUMI:
596 labeltype = LABEL_COUNTER_ENUMI;
598 case LA_COUNTER_ENUMII:
599 labeltype = LABEL_COUNTER_ENUMII;
601 case LA_COUNTER_ENUMIII:
602 labeltype = LABEL_COUNTER_ENUMIII;
604 case LA_COUNTER_ENUMIV:
605 labeltype = LABEL_COUNTER_ENUMIV;
608 labeltype = LABEL_BIBLIO;
613 static keyword_item endlabelTypeTags[] = {
614 { "box", END_LABEL_BOX },
615 { "filled_box", END_LABEL_FILLED_BOX },
616 { "no_label", END_LABEL_NO_LABEL }
619 void LyXLayout::readEndLabelType(LyXLex & lexrc)
621 pushpophelper pph(lexrc, endlabelTypeTags,
622 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
623 int le = lexrc.lex();
625 case LyXLex::LEX_UNDEF:
626 lexrc.printError("Unknown labeltype tag `$$Token'");
629 case END_LABEL_FILLED_BOX:
630 case END_LABEL_NO_LABEL:
631 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
634 lyxerr << "Unhandled value " << le
635 << " in LyXLayout::readEndLabelType." << endl;
641 static keyword_item marginTags[] = {
642 { "dynamic", MARGIN_DYNAMIC },
643 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
644 { "manual", MARGIN_MANUAL },
645 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
646 { "static", MARGIN_STATIC }
650 void LyXLayout::readMargin(LyXLex & lexrc)
652 keyword_item marginTags[] = {
653 { "dynamic", MARGIN_DYNAMIC },
654 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
655 { "manual", MARGIN_MANUAL },
656 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
657 { "static", MARGIN_STATIC }
660 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
662 int le = lexrc.lex();
664 case LyXLex::LEX_UNDEF:
665 lexrc.printError("Unknown margin type tag `$$Token'");
670 case MARGIN_FIRST_DYNAMIC:
671 case MARGIN_RIGHT_ADDRESS_BOX:
672 margintype = static_cast<LYX_MARGIN_TYPE>(le);
675 lyxerr << "Unhandled value " << le
676 << " in LyXLayout::readMargin." << endl;
683 static keyword_item latexTypeTags[] = {
684 { "command", LATEX_COMMAND },
685 { "environment", LATEX_ENVIRONMENT },
686 { "item_environment", LATEX_ITEM_ENVIRONMENT },
687 { "list_environment", LATEX_LIST_ENVIRONMENT },
688 { "paragraph", LATEX_PARAGRAPH }
693 void LyXLayout::readLatexType(LyXLex & lexrc)
695 keyword_item latexTypeTags[] = {
696 { "command", LATEX_COMMAND },
697 { "environment", LATEX_ENVIRONMENT },
698 { "item_environment", LATEX_ITEM_ENVIRONMENT },
699 { "list_environment", LATEX_LIST_ENVIRONMENT },
700 { "paragraph", LATEX_PARAGRAPH }
703 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
704 int le = lexrc.lex();
706 case LyXLex::LEX_UNDEF:
707 lexrc.printError("Unknown latextype tag `$$Token'");
709 case LATEX_PARAGRAPH:
711 case LATEX_ENVIRONMENT:
712 case LATEX_ITEM_ENVIRONMENT:
713 case LATEX_LIST_ENVIRONMENT:
714 latextype = static_cast<LYX_LATEX_TYPES>(le);
717 lyxerr << "Unhandled value " << le
718 << " in LyXLayout::readLatexType." << endl;
725 ST_SPACING_SINGLE = 1,
733 static keyword_item spacingTags[] = {
734 {"double", ST_SPACING_DOUBLE },
735 {"onehalf", ST_SPACING_ONEHALF },
736 {"other", ST_OTHER },
737 {"single", ST_SPACING_SINGLE }
742 void LyXLayout::readSpacing(LyXLex & lexrc)
744 keyword_item spacingTags[] = {
745 {"double", ST_SPACING_DOUBLE },
746 {"onehalf", ST_SPACING_ONEHALF },
747 {"other", ST_OTHER },
748 {"single", ST_SPACING_SINGLE }
751 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
752 int le = lexrc.lex();
754 case LyXLex::LEX_UNDEF:
755 lexrc.printError("Unknown spacing token `$$Token'");
759 switch(static_cast<SpacingTags>(le)) {
760 case ST_SPACING_SINGLE:
761 spacing.set(Spacing::Single);
763 case ST_SPACING_ONEHALF:
764 spacing.set(Spacing::Onehalf);
766 case ST_SPACING_DOUBLE:
767 spacing.set(Spacing::Double);
771 spacing.set(Spacing::Other, lexrc.GetFloat());
777 /* ******************************************************************* */
779 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
781 : name_(fn), latexname_(cln), description_(desc)
788 pagestyle_ = "default";
789 maxcounter_ = LABEL_COUNTER_CHAPTER;
790 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
791 opt_fontsize_ = "10|11|12";
792 opt_pagestyle_ = "empty|plain|headings|fancy";
798 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
800 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
801 if (!lay.Read(lexrc, *this)) {
803 lay.resfont = lay.font;
804 lay.resfont.realize(defaultfont());
805 lay.reslabelfont = lay.labelfont;
806 lay.reslabelfont.realize(defaultfont());
807 return false; // no errors
809 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
837 static keyword_item textClassTags[] = {
838 { "classoptions", TC_CLASSOPTIONS },
839 { "columns", TC_COLUMNS },
840 { "defaultfont", TC_DEFAULTFONT },
841 { "input", TC_INPUT },
842 { "leftmargin", TC_LEFTMARGIN },
843 { "maxcounter", TC_MAXCOUNTER },
844 { "nostyle", TC_NOSTYLE },
845 { "outputtype", TC_OUTPUTTYPE },
846 { "pagestyle", TC_PAGESTYLE },
847 { "preamble", TC_PREAMBLE },
848 { "providesamsmath", TC_PROVIDESAMSMATH },
849 { "providesmakeidx", TC_PROVIDESMAKEIDX },
850 { "providesurl", TC_PROVIDESURL },
851 { "rightmargin", TC_RIGHTMARGIN },
852 { "secnumdepth", TC_SECNUMDEPTH },
853 { "sides", TC_SIDES },
854 { "style", TC_STYLE },
855 { "tocdepth", TC_TOCDEPTH }
860 // Reads a textclass structure from file.
861 bool LyXTextClass::Read(string const & filename, bool merge)
863 keyword_item textClassTags[] = {
864 { "classoptions", TC_CLASSOPTIONS },
865 { "columns", TC_COLUMNS },
866 { "defaultfont", TC_DEFAULTFONT },
867 { "input", TC_INPUT },
868 { "leftmargin", TC_LEFTMARGIN },
869 { "maxcounter", TC_MAXCOUNTER },
870 { "nostyle", TC_NOSTYLE },
871 { "outputtype", TC_OUTPUTTYPE },
872 { "pagestyle", TC_PAGESTYLE },
873 { "preamble", TC_PREAMBLE },
874 { "providesamsmath", TC_PROVIDESAMSMATH },
875 { "providesmakeidx", TC_PROVIDESMAKEIDX },
876 { "providesurl", TC_PROVIDESURL },
877 { "rightmargin", TC_RIGHTMARGIN },
878 { "secnumdepth", TC_SECNUMDEPTH },
879 { "sides", TC_SIDES },
880 { "style", TC_STYLE },
881 { "tocdepth", TC_TOCDEPTH }
885 lyxerr[Debug::TCLASS] << "Reading textclass "
886 << MakeDisplayPath(filename)
889 lyxerr[Debug::TCLASS] << "Reading input file "
890 << MakeDisplayPath(filename)
893 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
896 lexrc.setFile(filename);
897 if (!lexrc.IsOK()) error = true;
900 while (lexrc.IsOK() && !error) {
901 int le = lexrc.lex();
903 case LyXLex::LEX_FEOF:
906 case LyXLex::LEX_UNDEF:
907 lexrc.printError("Unknown TextClass tag `$$Token'");
912 switch(static_cast<TextClassTags>(le)) {
913 case TC_OUTPUTTYPE: // output type definition
914 readOutputType(lexrc);
917 case TC_INPUT: // Include file
919 string tmp = LibFileSearch("layouts",
923 if (Read(tmp, true)) {
924 lexrc.printError("Error reading input"
933 string name = subst(lexrc.GetString(),
935 if (hasLayout(name)) {
936 LyXLayout & lay = GetLayout(name);
937 error = do_readStyle(lexrc, lay);
941 if (!(error = do_readStyle(lexrc, lay)))
942 layoutlist.push_back(lay);
946 lexrc.printError("No name given for style: `$$Token'.");
953 string style = subst(lexrc.GetString(),
955 if (!delete_layout(style))
956 lexrc.printError("Cannot delete style"
963 columns_ = lexrc.GetInteger();
968 switch(lexrc.GetInteger()) {
969 case 1: sides_ = OneSide; break;
970 case 2: sides_ = TwoSides; break;
972 lyxerr << "Impossible number of page"
973 " sides, setting to one."
983 pagestyle_ = strip(lexrc.GetString());
987 defaultfont_.lyxRead(lexrc);
988 if (!defaultfont_.resolved()) {
989 lexrc.printError("Warning: defaultfont should "
990 "be fully instantiated!");
991 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
996 readMaxCounter(lexrc);
1001 secnumdepth_ = lexrc.GetInteger();
1006 tocdepth_ = lexrc.GetInteger();
1009 // First step to support options
1010 case TC_CLASSOPTIONS:
1011 readClassOptions(lexrc);
1015 preamble_ = lexrc.getLongString("EndPreamble");
1018 case TC_PROVIDESAMSMATH:
1019 if (lexrc.next() && lexrc.GetInteger())
1020 provides_ |= amsmath;
1023 case TC_PROVIDESMAKEIDX:
1024 if (lexrc.next() && lexrc.GetInteger())
1025 provides_ |= makeidx;
1028 case TC_PROVIDESURL:
1029 if (lexrc.next() && lexrc.GetInteger())
1033 case TC_LEFTMARGIN: // left margin type
1035 leftmargin_ = lexrc.GetString();
1038 case TC_RIGHTMARGIN: // right margin type
1040 rightmargin_ = lexrc.GetString();
1045 if (!merge) { // we are at top level here.
1046 lyxerr[Debug::TCLASS] << "Finished reading textclass "
1047 << MakeDisplayPath(filename)
1050 lyxerr[Debug::TCLASS] << "Finished reading input file "
1051 << MakeDisplayPath(filename)
1059 static keyword_item outputTypeTags[] = {
1060 { "docbook", DOCBOOK },
1062 { "linuxdoc", LINUXDOC },
1063 { "literate", LITERATE }
1067 void LyXTextClass::readOutputType(LyXLex & lexrc)
1069 keyword_item outputTypeTags[] = {
1070 { "docbook", DOCBOOK },
1072 { "linuxdoc", LINUXDOC },
1073 { "literate", LITERATE }
1076 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1078 int le = lexrc.lex();
1080 case LyXLex::LEX_UNDEF:
1081 lexrc.printError("Unknown output type `$$Token'");
1087 outputType_ = static_cast<OutputType>(le);
1090 lyxerr << "Unhandled value " << le
1091 << " in LyXTextClass::readOutputType." << endl;
1098 enum MaxCounterTags {
1099 MC_COUNTER_CHAPTER = 1,
1101 MC_COUNTER_SUBSECTION,
1102 MC_COUNTER_SUBSUBSECTION,
1103 MC_COUNTER_PARAGRAPH,
1104 MC_COUNTER_SUBPARAGRAPH,
1113 static keyword_item maxCounterTags[] = {
1114 {"counter_chapter", MC_COUNTER_CHAPTER },
1115 {"counter_enumi", MC_COUNTER_ENUMI },
1116 {"counter_enumii", MC_COUNTER_ENUMII },
1117 {"counter_enumiii", MC_COUNTER_ENUMIII },
1118 {"counter_enumiv", MC_COUNTER_ENUMIV },
1119 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1120 {"counter_section", MC_COUNTER_SECTION },
1121 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1122 {"counter_subsection", MC_COUNTER_SUBSECTION },
1123 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1128 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1130 keyword_item maxCounterTags[] = {
1131 {"counter_chapter", MC_COUNTER_CHAPTER },
1132 {"counter_enumi", MC_COUNTER_ENUMI },
1133 {"counter_enumii", MC_COUNTER_ENUMII },
1134 {"counter_enumiii", MC_COUNTER_ENUMIII },
1135 {"counter_enumiv", MC_COUNTER_ENUMIV },
1136 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1137 {"counter_section", MC_COUNTER_SECTION },
1138 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1139 {"counter_subsection", MC_COUNTER_SUBSECTION },
1140 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1143 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1144 int le = lexrc.lex();
1146 case LyXLex::LEX_UNDEF:
1147 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1151 switch (static_cast<MaxCounterTags>(le)) {
1152 case MC_COUNTER_CHAPTER:
1153 maxcounter_ = LABEL_COUNTER_CHAPTER;
1155 case MC_COUNTER_SECTION:
1156 maxcounter_ = LABEL_COUNTER_SECTION;
1158 case MC_COUNTER_SUBSECTION:
1159 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1161 case MC_COUNTER_SUBSUBSECTION:
1162 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1164 case MC_COUNTER_PARAGRAPH:
1165 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1167 case MC_COUNTER_SUBPARAGRAPH:
1168 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1170 case MC_COUNTER_ENUMI:
1171 maxcounter_ = LABEL_COUNTER_ENUMI;
1173 case MC_COUNTER_ENUMII:
1174 maxcounter_ = LABEL_COUNTER_ENUMII;
1176 case MC_COUNTER_ENUMIII:
1177 maxcounter_ = LABEL_COUNTER_ENUMIII;
1179 case MC_COUNTER_ENUMIV:
1180 maxcounter_ = LABEL_COUNTER_ENUMIV;
1186 enum ClassOptionsTags {
1195 static keyword_item classOptionsTags[] = {
1197 {"fontsize", CO_FONTSIZE },
1198 {"other", CO_OTHER },
1199 {"pagestyle", CO_PAGESTYLE }
1204 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1206 keyword_item classOptionsTags[] = {
1208 {"fontsize", CO_FONTSIZE },
1209 {"other", CO_OTHER },
1210 {"pagestyle", CO_PAGESTYLE }
1213 lexrc.pushTable(classOptionsTags, CO_END);
1214 bool getout = false;
1215 while (!getout && lexrc.IsOK()) {
1216 int le = lexrc.lex();
1218 case LyXLex::LEX_UNDEF:
1219 lexrc.printError("Unknown ClassOption tag `$$Token'");
1223 switch (static_cast<ClassOptionsTags>(le)) {
1226 opt_fontsize_ = strip(lexrc.GetString());
1230 opt_pagestyle_ = strip(lexrc.GetString());
1234 options_ = lexrc.GetString();
1245 bool LyXTextClass::hasLayout(string const & name) const
1247 for (LayoutList::const_iterator cit = layoutlist.begin();
1248 cit != layoutlist.end(); ++cit) {
1249 if ((*cit).name() == name)
1256 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1258 for (LayoutList::const_iterator cit = layoutlist.begin();
1259 cit != layoutlist.end(); ++cit) {
1260 if ((*cit).name() == name)
1263 Assert(false); // we actually require the name to exist.
1264 return layoutlist.front();
1268 LyXLayout & LyXTextClass::GetLayout(string const & name)
1270 for (LayoutList::iterator it = layoutlist.begin();
1271 it != layoutlist.end(); ++it) {
1272 if ((*it).name() == name)
1275 Assert(false); // we actually require the name to exist.
1276 return layoutlist.front();
1280 bool LyXTextClass::delete_layout (string const & name)
1282 for(LayoutList::iterator it = layoutlist.begin();
1283 it != layoutlist.end(); ++it) {
1284 if ((*it).name() == name) {
1285 layoutlist.erase(it);
1293 // Load textclass info if not loaded yet
1294 void LyXTextClass::load()
1299 string real_file = LibFileSearch("layouts", name_, "layout");
1301 if (Read(real_file)) {
1302 lyxerr << "Error reading `"
1303 << MakeDisplayPath(real_file)
1304 << "'\n(Check `" << name_
1305 << "')\nCheck your installation and "
1306 "try Options/Reconfigure..." << endl;
1312 //////////////////////////////////////////
1314 // Gets textclass number from name
1315 pair<bool, LyXTextClassList::size_type>
1316 LyXTextClassList::NumberOfClass(string const & textclass) const
1318 for (ClassList::const_iterator cit = classlist.begin();
1319 cit != classlist.end(); ++cit) {
1320 if ((*cit).name() == textclass)
1321 return make_pair(true, cit - classlist.begin());
1323 return make_pair(false, size_type(0));
1327 // Gets layout structure from style number and textclass number
1329 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1330 LyXTextClass::size_type layout) const
1332 classlist[textclass].load();
1333 if (layout < classlist[textclass].numLayouts())
1334 return classlist[textclass][layout];
1335 return classlist[textclass][0];
1339 // Gets layout number from name and textclass number
1340 pair<bool, LyXTextClass::size_type>
1341 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1342 string const & name) const
1344 classlist[textclass].load();
1345 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1346 if (classlist[textclass][i].name() == name)
1347 return make_pair(true, i);
1349 if (name == "dummy")
1350 return make_pair(true, LYX_DUMMY_LAYOUT);
1351 return make_pair(false, LyXTextClass::LayoutList::size_type(0)); // not found
1355 // Gets a layout (style) name from layout number and textclass number
1357 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1358 LyXTextClass::size_type layout) const
1360 static string dummy("dummy");
1361 classlist[textclass].load();
1362 if (layout < classlist[textclass].numLayouts())
1363 return classlist[textclass][layout].name();
1368 // Gets a textclass name from number
1370 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1372 static string dummy("dummy");
1373 if (classlist.size() == 0) {
1376 Assert(number < classlist.size());
1377 return classlist[number].name();
1381 // Gets a textclass latexname from number
1383 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1385 static string dummy("dummy");
1386 classlist[number].load();
1387 if (classlist.size() == 0) {
1390 Assert(number < classlist.size());
1391 return classlist[number].latexname();
1395 // Gets a textclass description from number
1397 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1399 static string dummy("dummy");
1400 if (classlist.size() == 0) {
1403 Assert(number < classlist.size());
1404 return classlist[number].description();
1408 // Gets a textclass structure from number
1409 LyXTextClass const &
1410 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1412 classlist[textclass].load();
1413 if (textclass < classlist.size())
1414 return classlist[textclass];
1416 return classlist[0];
1420 void LyXTextClassList::Add(LyXTextClass const & t)
1422 classlist.push_back(t);
1426 // used when sorting the textclass list.
1427 class less_textclass_desc {
1429 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1430 return tc1.description() < tc2.description();
1435 // Reads LyX textclass definitions according to textclass config file
1436 bool LyXTextClassList::Read ()
1439 string real_file = LibFileSearch("", "textclass.lst");
1440 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1441 << real_file << "'" << endl;
1443 if (real_file.empty()) {
1444 lyxerr << "LyXTextClassList::Read: unable to find "
1445 "textclass file `" << MakeDisplayPath(real_file, 1000)
1446 << "'. Exiting." << endl;
1448 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1449 _("Check that the file \"textclass.lst\""),
1450 _("is installed correctly. Sorry, has to exit :-("));
1452 // This causes LyX to end... Not a desirable behaviour. Lgb
1453 // What do you propose? That the user gets a file dialog
1454 // and is allowed to hunt for the file? (Asger)
1455 // more that we have a layout for minimal.cls statically
1456 // compiled in... (Lgb)
1459 if (!lex.setFile(real_file)) {
1460 lyxerr << "LyXTextClassList::Read: "
1461 "lyxlex was not able to set file: "
1462 << real_file << endl;
1466 lyxerr << "LyXTextClassList::Read: unable to open "
1467 "textclass file `" << MakeDisplayPath(real_file, 1000)
1468 << "'\nCheck your installation. LyX can't continue."
1472 bool finished = false;
1473 string fname, clname, desc;
1474 // Parse config-file
1475 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1476 while (lex.IsOK() && !finished) {
1477 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1478 switch (lex.lex()) {
1479 case LyXLex::LEX_FEOF:
1483 fname = lex.GetString();
1484 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1486 clname = lex.GetString();
1487 lyxerr[Debug::TCLASS]
1488 << "Clname: " << clname << endl;
1490 desc = lex.GetString();
1491 lyxerr[Debug::TCLASS]
1492 << "Desc: " << desc << endl;
1493 // This code is run when we have
1494 // fname, clname and desc
1495 LyXTextClass tmpl(fname,
1499 debugging(Debug::TCLASS)) {
1507 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1509 if (classlist.size() == 0) {
1510 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1512 WriteAlert(_("LyX wasn't able to find any layout description!"),
1513 _("Check the contents of the file \"textclass.lst\""),
1514 _("Sorry, has to exit :-("));
1517 // Ok everything loaded ok, now sort the list.
1518 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1524 Returns false if this fails
1527 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1530 if (number < classlist.size()) {
1531 classlist[number].load();
1532 if (classlist[number].numLayouts() == 0) {
1542 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1545 case LyXTextClass::OneSide:
1548 case LyXTextClass::TwoSides: