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)
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 { "endlabeltype", LT_ENDLABELTYPE },
146 { "fill_bottom", LT_FILL_BOTTOM },
147 { "fill_top", LT_FILL_TOP },
149 { "freespacing", LT_FREE_SPACING },
150 { "intitle", LT_INTITLE },
151 { "itemsep", LT_ITEMSEP },
152 { "keepempty", LT_KEEPEMPTY },
153 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
154 { "labelfont", LT_LABELFONT },
155 { "labelindent", LT_LABELINDENT },
156 { "labelsep", LT_LABELSEP },
157 { "labelstring", LT_LABELSTRING },
158 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
159 { "labeltype", LT_LABELTYPE },
160 { "latexname", LT_LATEXNAME },
161 { "latexparam", LT_LATEXPARAM },
162 { "latextype", LT_LATEXTYPE },
163 { "leftmargin", LT_LEFTMARGIN },
164 { "margin", LT_MARGIN },
165 { "needprotect", LT_NEED_PROTECT },
166 { "newline", LT_NEWLINE },
167 { "nextnoindent", LT_NEXTNOINDENT },
168 { "obsoletedby", LT_OBSOLETEDBY },
169 { "parindent", LT_PARINDENT },
170 { "parsep", LT_PARSEP },
171 { "parskip", LT_PARSKIP },
172 { "preamble", LT_PREAMBLE },
173 { "rightmargin", LT_RIGHTMARGIN },
174 { "spacing", LT_SPACING },
175 { "textfont", LT_TEXTFONT },
176 { "topsep", LT_TOPSEP }
180 bool finished = false;
181 lexrc.pushTable(layoutTags, LT_INTITLE);
182 // parse style section
183 while (!finished && lexrc.IsOK() && !error) {
184 int le = lexrc.lex();
185 // See comment in lyxrc.C.
187 case LyXLex::LEX_FEOF:
190 case LyXLex::LEX_UNDEF: // parse error
191 lexrc.printError("Unknown layout tag `$$Token'");
196 switch(static_cast<LayoutTags>(le)) {
197 case LT_END: // end of structure
201 case LT_COPYSTYLE: // initialize with a known style
203 if (tclass.hasLayout(lexrc.GetString())) {
204 string tmpname = name_;
205 this->operator= (tclass.GetLayout(lexrc.GetString()));
208 lexrc.printError("Cannot copy known "
214 case LT_OBSOLETEDBY: // replace with a known style
216 if (tclass.hasLayout(lexrc.GetString())) {
217 string tmpname = name_;
218 this->operator= (tclass.GetLayout(lexrc.GetString()));
220 if (obsoleted_by().empty())
221 obsoleted_by_ = lexrc.GetString();
223 lexrc.printError("Cannot replace with"
230 case LT_MARGIN: // Margin style definition.
234 case LT_LATEXTYPE: // Latex style definition.
235 readLatexType(lexrc);
239 intitle = lexrc.next() && lexrc.GetInteger();
242 case LT_NEED_PROTECT:
243 needprotect = lexrc.next() && lexrc.GetInteger();
247 keepempty = lexrc.next() && lexrc.GetInteger();
260 labelfont.lyxRead(lexrc);
263 case LT_NEXTNOINDENT: // Indent next paragraph?
264 if (lexrc.next() && lexrc.GetInteger())
267 nextnoindent = false;
272 latexname_ = lexrc.GetString();
277 latexparam_ = lexrc.GetString();
281 preamble_ = lexrc.getLongString("EndPreamble");
285 readLabelType(lexrc);
288 case LT_ENDLABELTYPE:
289 readEndLabelType(lexrc);
292 case LT_LEFTMARGIN: // left margin type
294 leftmargin = lexrc.GetString();
297 case LT_RIGHTMARGIN: // right margin type
299 rightmargin = lexrc.GetString();
302 case LT_LABELINDENT: // label indenting flag
304 labelindent = lexrc.GetString();
307 case LT_PARINDENT: // paragraph indent. flag
309 parindent = lexrc.GetString();
312 case LT_PARSKIP: // paragraph skip size
314 parskip = lexrc.GetFloat();
317 case LT_ITEMSEP: // item separation size
319 itemsep = lexrc.GetFloat();
322 case LT_TOPSEP: // top separation size
324 topsep = lexrc.GetFloat();
327 case LT_BOTTOMSEP: // bottom separation size
329 bottomsep = lexrc.GetFloat();
332 case LT_LABEL_BOTTOMSEP: // label bottom separation size
334 labelbottomsep = lexrc.GetFloat();
337 case LT_LABELSEP: // label separator
339 labelsep = subst(lexrc.GetString(), 'x', ' ');
343 case LT_PARSEP: // par. separation size
345 parsep = lexrc.GetFloat();
348 case LT_FILL_TOP: // fill top flag
350 fill_top = lexrc.GetInteger();
353 case LT_FILL_BOTTOM: // fill bottom flag
355 fill_bottom = lexrc.GetInteger();
358 case LT_NEWLINE: // newlines allowed?
360 newline_allowed = lexrc.GetInteger();
363 case LT_ALIGN: // paragraph align
366 case LT_ALIGNPOSSIBLE: // paragraph allowed align
367 readAlignPossible(lexrc);
370 case LT_LABELSTRING: // label string definition
372 labelstring_ = lexrc.GetString();
375 case LT_LABELSTRING_APPENDIX: // label string appendix definition
377 labelstring_appendix_ = lexrc.GetString();
380 case LT_FREE_SPACING: // Allow for free spacing.
382 free_spacing = lexrc.GetInteger();
385 case LT_SPACING: // setspace.sty
404 void LyXLayout::readAlign(LyXLex & lexrc)
407 keyword_item alignTags[] = {
408 { "block", AT_BLOCK },
409 { "center", AT_CENTER },
410 { "layout", AT_LAYOUT },
412 { "right", AT_RIGHT }
415 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
416 int le = lexrc.lex();
418 case LyXLex::LEX_UNDEF:
419 lexrc.printError("Unknown alignment `$$Token'");
423 switch(static_cast<AlignTags>(le)) {
425 align = LYX_ALIGN_BLOCK;
428 align = LYX_ALIGN_LEFT;
431 align = LYX_ALIGN_RIGHT;
434 align = LYX_ALIGN_CENTER;
437 align = LYX_ALIGN_LAYOUT;
443 void LyXLayout::readAlignPossible(LyXLex & lexrc)
446 keyword_item alignTags[] = {
447 { "block", AT_BLOCK },
448 { "center", AT_CENTER },
449 { "layout", AT_LAYOUT },
451 { "right", AT_RIGHT }
454 lexrc.pushTable(alignTags, AT_LAYOUT);
455 alignpossible = LYX_ALIGN_NONE;
456 int lineno = lexrc.GetLineNo();
458 int le = lexrc.lex();
460 case LyXLex::LEX_UNDEF:
461 lexrc.printError("Unknown alignment `$$Token'");
465 switch (static_cast<AlignTags>(le)) {
467 alignpossible |= LYX_ALIGN_BLOCK;
470 alignpossible |= LYX_ALIGN_LEFT;
473 alignpossible |= LYX_ALIGN_RIGHT;
476 alignpossible |= LYX_ALIGN_CENTER;
479 alignpossible |= LYX_ALIGN_LAYOUT;
482 } while (lineno == lexrc.GetLineNo());
491 LA_CENTERED_TOP_ENVIRONMENT,
496 LA_COUNTER_SUBSECTION,
497 LA_COUNTER_SUBSUBSECTION,
498 LA_COUNTER_PARAGRAPH,
499 LA_COUNTER_SUBPARAGRAPH,
509 static keyword_item labelTypeTags[] = {
510 { "bibliography", LA_BIBLIO },
511 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
512 { "counter_chapter", LA_COUNTER_CHAPTER },
513 { "counter_enumi", LA_COUNTER_ENUMI },
514 { "counter_enumii", LA_COUNTER_ENUMII },
515 { "counter_enumiii", LA_COUNTER_ENUMIII },
516 { "counter_enumiv", LA_COUNTER_ENUMIV },
517 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
518 { "counter_section", LA_COUNTER_SECTION },
519 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
520 { "counter_subsection", LA_COUNTER_SUBSECTION },
521 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
522 { "manual", LA_MANUAL },
523 { "no_label", LA_NO_LABEL },
524 { "sensitive", LA_SENSITIVE },
525 { "static", LA_STATIC },
526 { "top_environment", LA_TOP_ENVIRONMENT }
531 void LyXLayout::readLabelType(LyXLex & lexrc)
534 keyword_item labelTypeTags[] = {
535 { "bibliography", LA_BIBLIO },
536 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
537 { "counter_chapter", LA_COUNTER_CHAPTER },
538 { "counter_enumi", LA_COUNTER_ENUMI },
539 { "counter_enumii", LA_COUNTER_ENUMII },
540 { "counter_enumiii", LA_COUNTER_ENUMIII },
541 { "counter_enumiv", LA_COUNTER_ENUMIV },
542 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
543 { "counter_section", LA_COUNTER_SECTION },
544 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
545 { "counter_subsection", LA_COUNTER_SUBSECTION },
546 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
547 { "manual", LA_MANUAL },
548 { "no_label", LA_NO_LABEL },
549 { "sensitive", LA_SENSITIVE },
550 { "static", LA_STATIC },
551 { "top_environment", LA_TOP_ENVIRONMENT }
554 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
555 int le = lexrc.lex();
557 case LyXLex::LEX_UNDEF:
558 lexrc.printError("Unknown labeltype tag `$$Token'");
562 switch (static_cast<LabelTypeTags>(le)) {
564 labeltype = LABEL_NO_LABEL;
567 labeltype = LABEL_MANUAL;
569 case LA_TOP_ENVIRONMENT:
570 labeltype = LABEL_TOP_ENVIRONMENT;
572 case LA_CENTERED_TOP_ENVIRONMENT:
573 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
576 labeltype = LABEL_STATIC;
579 labeltype = LABEL_SENSITIVE;
581 case LA_COUNTER_CHAPTER:
582 labeltype = LABEL_COUNTER_CHAPTER;
584 case LA_COUNTER_SECTION:
585 labeltype = LABEL_COUNTER_SECTION;
587 case LA_COUNTER_SUBSECTION:
588 labeltype = LABEL_COUNTER_SUBSECTION;
590 case LA_COUNTER_SUBSUBSECTION:
591 labeltype = LABEL_COUNTER_SUBSUBSECTION;
593 case LA_COUNTER_PARAGRAPH:
594 labeltype = LABEL_COUNTER_PARAGRAPH;
596 case LA_COUNTER_SUBPARAGRAPH:
597 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
599 case LA_COUNTER_ENUMI:
600 labeltype = LABEL_COUNTER_ENUMI;
602 case LA_COUNTER_ENUMII:
603 labeltype = LABEL_COUNTER_ENUMII;
605 case LA_COUNTER_ENUMIII:
606 labeltype = LABEL_COUNTER_ENUMIII;
608 case LA_COUNTER_ENUMIV:
609 labeltype = LABEL_COUNTER_ENUMIV;
612 labeltype = LABEL_BIBLIO;
617 static keyword_item endlabelTypeTags[] = {
618 { "box", END_LABEL_BOX },
619 { "filled_box", END_LABEL_FILLED_BOX },
620 { "no_label", END_LABEL_NO_LABEL }
623 void LyXLayout::readEndLabelType(LyXLex & lexrc)
625 pushpophelper pph(lexrc, endlabelTypeTags,
626 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
627 int le = lexrc.lex();
629 case LyXLex::LEX_UNDEF:
630 lexrc.printError("Unknown labeltype tag `$$Token'");
633 case END_LABEL_FILLED_BOX:
634 case END_LABEL_NO_LABEL:
635 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
638 lyxerr << "Unhandled value " << le
639 << " in LyXLayout::readEndLabelType." << endl;
645 static keyword_item marginTags[] = {
646 { "dynamic", MARGIN_DYNAMIC },
647 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
648 { "manual", MARGIN_MANUAL },
649 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
650 { "static", MARGIN_STATIC }
654 void LyXLayout::readMargin(LyXLex & lexrc)
657 keyword_item marginTags[] = {
658 { "dynamic", MARGIN_DYNAMIC },
659 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
660 { "manual", MARGIN_MANUAL },
661 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
662 { "static", MARGIN_STATIC }
665 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
667 int le = lexrc.lex();
669 case LyXLex::LEX_UNDEF:
670 lexrc.printError("Unknown margin type tag `$$Token'");
675 case MARGIN_FIRST_DYNAMIC:
676 case MARGIN_RIGHT_ADDRESS_BOX:
677 margintype = static_cast<LYX_MARGIN_TYPE>(le);
680 lyxerr << "Unhandled value " << le
681 << " in LyXLayout::readMargin." << endl;
688 static keyword_item latexTypeTags[] = {
689 { "command", LATEX_COMMAND },
690 { "environment", LATEX_ENVIRONMENT },
691 { "item_environment", LATEX_ITEM_ENVIRONMENT },
692 { "list_environment", LATEX_LIST_ENVIRONMENT },
693 { "paragraph", LATEX_PARAGRAPH }
698 void LyXLayout::readLatexType(LyXLex & lexrc)
701 keyword_item latexTypeTags[] = {
702 { "command", LATEX_COMMAND },
703 { "environment", LATEX_ENVIRONMENT },
704 { "item_environment", LATEX_ITEM_ENVIRONMENT },
705 { "list_environment", LATEX_LIST_ENVIRONMENT },
706 { "paragraph", LATEX_PARAGRAPH }
709 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
710 int le = lexrc.lex();
712 case LyXLex::LEX_UNDEF:
713 lexrc.printError("Unknown latextype tag `$$Token'");
715 case LATEX_PARAGRAPH:
717 case LATEX_ENVIRONMENT:
718 case LATEX_ITEM_ENVIRONMENT:
719 case LATEX_LIST_ENVIRONMENT:
720 latextype = static_cast<LYX_LATEX_TYPES>(le);
723 lyxerr << "Unhandled value " << le
724 << " in LyXLayout::readLatexType." << endl;
731 ST_SPACING_SINGLE = 1,
739 static keyword_item spacingTags[] = {
740 {"double", ST_SPACING_DOUBLE },
741 {"onehalf", ST_SPACING_ONEHALF },
742 {"other", ST_OTHER },
743 {"single", ST_SPACING_SINGLE }
748 void LyXLayout::readSpacing(LyXLex & lexrc)
751 keyword_item spacingTags[] = {
752 {"double", ST_SPACING_DOUBLE },
753 {"onehalf", ST_SPACING_ONEHALF },
754 {"other", ST_OTHER },
755 {"single", ST_SPACING_SINGLE }
758 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
759 int le = lexrc.lex();
761 case LyXLex::LEX_UNDEF:
762 lexrc.printError("Unknown spacing token `$$Token'");
766 switch(static_cast<SpacingTags>(le)) {
767 case ST_SPACING_SINGLE:
768 spacing.set(Spacing::Single);
770 case ST_SPACING_ONEHALF:
771 spacing.set(Spacing::Onehalf);
773 case ST_SPACING_DOUBLE:
774 spacing.set(Spacing::Double);
778 spacing.set(Spacing::Other, lexrc.GetFloat());
784 /* ******************************************************************* */
786 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
788 : name_(fn), latexname_(cln), description_(desc)
795 pagestyle_ = "default";
796 maxcounter_ = LABEL_COUNTER_CHAPTER;
797 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
798 opt_fontsize_ = "10|11|12";
799 opt_pagestyle_ = "empty|plain|headings|fancy";
805 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
807 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
808 if (!lay.Read(lexrc, *this)) {
810 lay.resfont = lay.font;
811 lay.resfont.realize(defaultfont());
812 lay.reslabelfont = lay.labelfont;
813 lay.reslabelfont.realize(defaultfont());
814 return false; // no errors
816 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
844 static keyword_item textClassTags[] = {
845 { "classoptions", TC_CLASSOPTIONS },
846 { "columns", TC_COLUMNS },
847 { "defaultfont", TC_DEFAULTFONT },
848 { "input", TC_INPUT },
849 { "leftmargin", TC_LEFTMARGIN },
850 { "maxcounter", TC_MAXCOUNTER },
851 { "nostyle", TC_NOSTYLE },
852 { "outputtype", TC_OUTPUTTYPE },
853 { "pagestyle", TC_PAGESTYLE },
854 { "preamble", TC_PREAMBLE },
855 { "providesamsmath", TC_PROVIDESAMSMATH },
856 { "providesmakeidx", TC_PROVIDESMAKEIDX },
857 { "providesurl", TC_PROVIDESURL },
858 { "rightmargin", TC_RIGHTMARGIN },
859 { "secnumdepth", TC_SECNUMDEPTH },
860 { "sides", TC_SIDES },
861 { "style", TC_STYLE },
862 { "tocdepth", TC_TOCDEPTH }
867 // Reads a textclass structure from file.
868 bool LyXTextClass::Read(string const & filename, bool merge)
871 keyword_item textClassTags[] = {
872 { "classoptions", TC_CLASSOPTIONS },
873 { "columns", TC_COLUMNS },
874 { "defaultfont", TC_DEFAULTFONT },
875 { "input", TC_INPUT },
876 { "leftmargin", TC_LEFTMARGIN },
877 { "maxcounter", TC_MAXCOUNTER },
878 { "nostyle", TC_NOSTYLE },
879 { "outputtype", TC_OUTPUTTYPE },
880 { "pagestyle", TC_PAGESTYLE },
881 { "preamble", TC_PREAMBLE },
882 { "providesamsmath", TC_PROVIDESAMSMATH },
883 { "providesmakeidx", TC_PROVIDESMAKEIDX },
884 { "providesurl", TC_PROVIDESURL },
885 { "rightmargin", TC_RIGHTMARGIN },
886 { "secnumdepth", TC_SECNUMDEPTH },
887 { "sides", TC_SIDES },
888 { "style", TC_STYLE },
889 { "tocdepth", TC_TOCDEPTH }
893 lyxerr[Debug::TCLASS] << "Reading textclass "
894 << MakeDisplayPath(filename)
897 lyxerr[Debug::TCLASS] << "Reading input file "
898 << MakeDisplayPath(filename)
901 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
904 lexrc.setFile(filename);
905 if (!lexrc.IsOK()) error = true;
908 while (lexrc.IsOK() && !error) {
909 int le = lexrc.lex();
911 case LyXLex::LEX_FEOF:
914 case LyXLex::LEX_UNDEF:
915 lexrc.printError("Unknown TextClass tag `$$Token'");
920 switch(static_cast<TextClassTags>(le)) {
921 case TC_OUTPUTTYPE: // output type definition
922 readOutputType(lexrc);
925 case TC_INPUT: // Include file
927 string tmp = LibFileSearch("layouts",
931 if (Read(tmp, true)) {
932 lexrc.printError("Error reading input"
941 string name = subst(lexrc.GetString(),
943 if (hasLayout(name)) {
944 LyXLayout & lay = GetLayout(name);
945 error = do_readStyle(lexrc, lay);
949 if (!(error = do_readStyle(lexrc, lay)))
950 layoutlist.push_back(lay);
954 lexrc.printError("No name given for style: `$$Token'.");
961 string style = subst(lexrc.GetString(),
963 if (!delete_layout(style))
964 lexrc.printError("Cannot delete style"
971 columns_ = lexrc.GetInteger();
976 switch(lexrc.GetInteger()) {
977 case 1: sides_ = OneSide; break;
978 case 2: sides_ = TwoSides; break;
980 lyxerr << "Impossible number of page"
981 " sides, setting to one."
991 pagestyle_ = strip(lexrc.GetString());
995 defaultfont_.lyxRead(lexrc);
996 if (!defaultfont_.resolved()) {
997 lexrc.printError("Warning: defaultfont should "
998 "be fully instantiated!");
999 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
1004 readMaxCounter(lexrc);
1007 case TC_SECNUMDEPTH:
1009 secnumdepth_ = lexrc.GetInteger();
1014 tocdepth_ = lexrc.GetInteger();
1017 // First step to support options
1018 case TC_CLASSOPTIONS:
1019 readClassOptions(lexrc);
1023 preamble_ = lexrc.getLongString("EndPreamble");
1026 case TC_PROVIDESAMSMATH:
1027 if (lexrc.next() && lexrc.GetInteger())
1028 provides_ |= amsmath;
1031 case TC_PROVIDESMAKEIDX:
1032 if (lexrc.next() && lexrc.GetInteger())
1033 provides_ |= makeidx;
1036 case TC_PROVIDESURL:
1037 if (lexrc.next() && lexrc.GetInteger())
1041 case TC_LEFTMARGIN: // left margin type
1043 leftmargin_ = lexrc.GetString();
1046 case TC_RIGHTMARGIN: // right margin type
1048 rightmargin_ = lexrc.GetString();
1053 if (!merge) { // we are at top level here.
1054 lyxerr[Debug::TCLASS] << "Finished reading textclass "
1055 << MakeDisplayPath(filename)
1058 lyxerr[Debug::TCLASS] << "Finished reading input file "
1059 << MakeDisplayPath(filename)
1067 static keyword_item outputTypeTags[] = {
1068 { "docbook", DOCBOOK },
1070 { "linuxdoc", LINUXDOC },
1071 { "literate", LITERATE }
1075 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)
1140 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 }
1153 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1154 int le = lexrc.lex();
1156 case LyXLex::LEX_UNDEF:
1157 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1161 switch (static_cast<MaxCounterTags>(le)) {
1162 case MC_COUNTER_CHAPTER:
1163 maxcounter_ = LABEL_COUNTER_CHAPTER;
1165 case MC_COUNTER_SECTION:
1166 maxcounter_ = LABEL_COUNTER_SECTION;
1168 case MC_COUNTER_SUBSECTION:
1169 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1171 case MC_COUNTER_SUBSUBSECTION:
1172 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1174 case MC_COUNTER_PARAGRAPH:
1175 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1177 case MC_COUNTER_SUBPARAGRAPH:
1178 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1180 case MC_COUNTER_ENUMI:
1181 maxcounter_ = LABEL_COUNTER_ENUMI;
1183 case MC_COUNTER_ENUMII:
1184 maxcounter_ = LABEL_COUNTER_ENUMII;
1186 case MC_COUNTER_ENUMIII:
1187 maxcounter_ = LABEL_COUNTER_ENUMIII;
1189 case MC_COUNTER_ENUMIV:
1190 maxcounter_ = LABEL_COUNTER_ENUMIV;
1196 enum ClassOptionsTags {
1205 static keyword_item classOptionsTags[] = {
1207 {"fontsize", CO_FONTSIZE },
1208 {"other", CO_OTHER },
1209 {"pagestyle", CO_PAGESTYLE }
1214 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1217 keyword_item classOptionsTags[] = {
1219 {"fontsize", CO_FONTSIZE },
1220 {"other", CO_OTHER },
1221 {"pagestyle", CO_PAGESTYLE }
1224 lexrc.pushTable(classOptionsTags, CO_END);
1225 bool getout = false;
1226 while (!getout && lexrc.IsOK()) {
1227 int le = lexrc.lex();
1229 case LyXLex::LEX_UNDEF:
1230 lexrc.printError("Unknown ClassOption tag `$$Token'");
1234 switch (static_cast<ClassOptionsTags>(le)) {
1237 opt_fontsize_ = strip(lexrc.GetString());
1241 opt_pagestyle_ = strip(lexrc.GetString());
1245 options_ = lexrc.GetString();
1256 bool LyXTextClass::hasLayout(string const & name) const
1258 for (LayoutList::const_iterator cit = layoutlist.begin();
1259 cit != layoutlist.end(); ++cit) {
1260 if ((*cit).name() == name)
1267 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1269 for (LayoutList::const_iterator cit = layoutlist.begin();
1270 cit != layoutlist.end(); ++cit) {
1271 if ((*cit).name() == name)
1274 Assert(false); // we actually require the name to exist.
1275 return layoutlist.front();
1279 LyXLayout & LyXTextClass::GetLayout(string const & name)
1281 for (LayoutList::iterator it = layoutlist.begin();
1282 it != layoutlist.end(); ++it) {
1283 if ((*it).name() == name)
1286 Assert(false); // we actually require the name to exist.
1287 return layoutlist.front();
1291 bool LyXTextClass::delete_layout (string const & name)
1293 for(LayoutList::iterator it = layoutlist.begin();
1294 it != layoutlist.end(); ++it) {
1295 if ((*it).name() == name) {
1296 layoutlist.erase(it);
1304 // Load textclass info if not loaded yet
1305 void LyXTextClass::load()
1310 string real_file = LibFileSearch("layouts", name_, "layout");
1312 if (Read(real_file)) {
1313 lyxerr << "Error reading `"
1314 << MakeDisplayPath(real_file)
1315 << "'\n(Check `" << name_
1316 << "')\nCheck your installation and "
1317 "try Options/Reconfigure..." << endl;
1323 //////////////////////////////////////////
1325 // Gets textclass number from name
1326 pair<bool, LyXTextClassList::size_type>
1327 LyXTextClassList::NumberOfClass(string const & textclass) const
1329 for (ClassList::const_iterator cit = classlist.begin();
1330 cit != classlist.end(); ++cit) {
1331 if ((*cit).name() == textclass)
1332 return make_pair(true, cit - classlist.begin());
1334 return make_pair(false, size_type(0));
1338 // Gets layout structure from style number and textclass number
1340 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1341 LyXTextClass::size_type layout) const
1343 classlist[textclass].load();
1344 if (layout < classlist[textclass].numLayouts())
1345 return classlist[textclass][layout];
1346 return classlist[textclass][0];
1350 // Gets layout number from name and textclass number
1351 pair<bool, LyXTextClass::size_type>
1352 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1353 string const & name) const
1355 classlist[textclass].load();
1356 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1357 if (classlist[textclass][i].name() == name)
1358 return make_pair(true, i);
1360 if (name == "dummy")
1361 return make_pair(true, LYX_DUMMY_LAYOUT);
1362 return make_pair(false, LyXTextClass::LayoutList::size_type(0)); // not found
1366 // Gets a layout (style) name from layout number and textclass number
1368 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1369 LyXTextClass::size_type layout) const
1371 static string dummy("dummy");
1372 classlist[textclass].load();
1373 if (layout < classlist[textclass].numLayouts())
1374 return classlist[textclass][layout].name();
1379 // Gets a textclass name from number
1381 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1383 static string dummy("dummy");
1384 if (classlist.size() == 0) {
1387 Assert(number < classlist.size());
1388 return classlist[number].name();
1392 // Gets a textclass latexname from number
1394 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1396 static string dummy("dummy");
1397 classlist[number].load();
1398 if (classlist.size() == 0) {
1401 Assert(number < classlist.size());
1402 return classlist[number].latexname();
1406 // Gets a textclass description from number
1408 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1410 static string dummy("dummy");
1411 if (classlist.size() == 0) {
1414 Assert(number < classlist.size());
1415 return classlist[number].description();
1419 // Gets a textclass structure from number
1420 LyXTextClass const &
1421 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1423 classlist[textclass].load();
1424 if (textclass < classlist.size())
1425 return classlist[textclass];
1427 return classlist[0];
1431 void LyXTextClassList::Add(LyXTextClass const & t)
1433 classlist.push_back(t);
1437 // used when sorting the textclass list.
1438 class less_textclass_desc {
1440 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1441 return tc1.description() < tc2.description();
1446 // Reads LyX textclass definitions according to textclass config file
1447 bool LyXTextClassList::Read ()
1450 string real_file = LibFileSearch("", "textclass.lst");
1451 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1452 << real_file << "'" << endl;
1454 if (real_file.empty()) {
1455 lyxerr << "LyXTextClassList::Read: unable to find "
1456 "textclass file `" << MakeDisplayPath(real_file, 1000)
1457 << "'. Exiting." << endl;
1459 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1460 _("Check that the file \"textclass.lst\""),
1461 _("is installed correctly. Sorry, has to exit :-("));
1463 // This causes LyX to end... Not a desirable behaviour. Lgb
1464 // What do you propose? That the user gets a file dialog
1465 // and is allowed to hunt for the file? (Asger)
1466 // more that we have a layout for minimal.cls statically
1467 // compiled in... (Lgb)
1470 if (!lex.setFile(real_file)) {
1471 lyxerr << "LyXTextClassList::Read: "
1472 "lyxlex was not able to set file: "
1473 << real_file << endl;
1477 lyxerr << "LyXTextClassList::Read: unable to open "
1478 "textclass file `" << MakeDisplayPath(real_file, 1000)
1479 << "'\nCheck your installation. LyX can't continue."
1483 bool finished = false;
1484 string fname, clname, desc;
1485 // Parse config-file
1486 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1487 while (lex.IsOK() && !finished) {
1488 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1489 switch (lex.lex()) {
1490 case LyXLex::LEX_FEOF:
1494 fname = lex.GetString();
1495 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1497 clname = lex.GetString();
1498 lyxerr[Debug::TCLASS]
1499 << "Clname: " << clname << endl;
1501 desc = lex.GetString();
1502 lyxerr[Debug::TCLASS]
1503 << "Desc: " << desc << endl;
1504 // This code is run when we have
1505 // fname, clname and desc
1506 LyXTextClass tmpl(fname,
1510 debugging(Debug::TCLASS)) {
1518 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1520 if (classlist.size() == 0) {
1521 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1523 WriteAlert(_("LyX wasn't able to find any layout description!"),
1524 _("Check the contents of the file \"textclass.lst\""),
1525 _("Sorry, has to exit :-("));
1528 // Ok everything loaded ok, now sort the list.
1529 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1535 Returns false if this fails
1538 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1541 if (number < classlist.size()) {
1542 classlist[number].load();
1543 if (classlist[number].numLayouts() == 0) {
1553 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1556 case LyXTextClass::OneSide:
1559 case LyXTextClass::TwoSides: