]> git.lyx.org Git - lyx.git/blob - src/lyxtextclass.C
Bug:1050
[lyx.git] / src / lyxtextclass.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2001 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #include "lyxtextclass.h"
15 #include "debug.h"
16 #include "lyxlex.h"
17 #include "counters.h"
18 #include "FloatList.h"
19
20 #include "support/lstrings.h"
21 #include "support/LAssert.h"
22 #include "support/lyxfunctional.h"
23 #include "support/filetools.h"
24
25 #include <algorithm>
26
27 using std::endl;
28 using std::find_if;
29 using std::remove_if;
30 using std::ostream;
31
32 namespace { // anon
33
34 struct compare_name {
35
36         compare_name(string const & name)
37                 : name_(name)
38         {}
39
40         bool operator()(boost::shared_ptr<LyXLayout> const & c)
41         {
42                 return c->name() == name_;
43         }
44
45         string name_;
46
47 };
48
49 } // anon
50
51
52 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
53                            string const & desc, bool texClassAvail )
54         : name_(fn), latexname_(cln), description_(desc),
55           floatlist_(new FloatList), ctrs_(new Counters), texClassAvail_(texClassAvail)
56 {
57         outputType_ = LATEX;
58         columns_ = 1;
59         sides_ = OneSide;
60         secnumdepth_ = 3;
61         tocdepth_ = 3;
62         pagestyle_ = "default";
63         maxcounter_ = LABEL_COUNTER_CHAPTER;
64         defaultfont_ = LyXFont(LyXFont::ALL_SANE);
65         opt_fontsize_ = "10|11|12";
66         opt_pagestyle_ = "empty|plain|headings|fancy";
67         provides_ = nothing;
68         titletype_ = TITLE_COMMAND_AFTER;
69         titlename_ = "maketitle";
70         loaded = false;
71 }
72
73
74 bool LyXTextClass::isTeXClassAvailable() const
75 {
76         return texClassAvail_;
77 }
78
79
80 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
81 {
82         lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
83         if (!lay.Read(lexrc, *this)) {
84                 // Resolve fonts
85                 lay.resfont = lay.font;
86                 lay.resfont.realize(defaultfont());
87                 lay.reslabelfont = lay.labelfont;
88                 lay.reslabelfont.realize(defaultfont());
89                 return false; // no errors
90         }
91         lyxerr << "Error parsing style `" << lay.name() << '\'' << endl;
92         return true;
93 }
94
95
96 enum TextClassTags {
97         TC_OUTPUTTYPE = 1,
98         TC_INPUT,
99         TC_STYLE,
100         TC_DEFAULTSTYLE,
101         TC_ENVIRONMENT,
102         TC_NOSTYLE,
103         TC_COLUMNS,
104         TC_SIDES,
105         TC_PAGESTYLE,
106         TC_DEFAULTFONT,
107         TC_MAXCOUNTER,
108         TC_SECNUMDEPTH,
109         TC_TOCDEPTH,
110         TC_CLASSOPTIONS,
111         TC_PREAMBLE,
112         TC_PROVIDESAMSMATH,
113         TC_PROVIDESNATBIB,
114         TC_PROVIDESMAKEIDX,
115         TC_PROVIDESURL,
116         TC_LEFTMARGIN,
117         TC_RIGHTMARGIN,
118         TC_FLOAT,
119         TC_COUNTER,
120         TC_NOFLOAT,
121         TC_TITLELATEXNAME,
122         TC_TITLELATEXTYPE
123 };
124
125 // Reads a textclass structure from file.
126 bool LyXTextClass::Read(string const & filename, bool merge)
127 {
128         keyword_item textClassTags[] = {
129                 { "classoptions",    TC_CLASSOPTIONS },
130                 { "columns",         TC_COLUMNS },
131                 { "counter",         TC_COUNTER },
132                 { "defaultfont",     TC_DEFAULTFONT },
133                 { "defaultstyle",    TC_DEFAULTSTYLE },
134                 { "environment",     TC_ENVIRONMENT },
135                 { "float",           TC_FLOAT },
136                 { "input",           TC_INPUT },
137                 { "leftmargin",      TC_LEFTMARGIN },
138                 { "maxcounter",      TC_MAXCOUNTER },
139                 { "nofloat",         TC_NOFLOAT },
140                 { "nostyle",         TC_NOSTYLE },
141                 { "outputtype",      TC_OUTPUTTYPE },
142                 { "pagestyle",       TC_PAGESTYLE },
143                 { "preamble",        TC_PREAMBLE },
144                 { "providesamsmath", TC_PROVIDESAMSMATH },
145                 { "providesmakeidx", TC_PROVIDESMAKEIDX },
146                 { "providesnatbib",  TC_PROVIDESNATBIB },
147                 { "providesurl",     TC_PROVIDESURL },
148                 { "rightmargin",     TC_RIGHTMARGIN },
149                 { "secnumdepth",     TC_SECNUMDEPTH },
150                 { "sides",           TC_SIDES },
151                 { "style",           TC_STYLE },
152                 { "titlelatexname",  TC_TITLELATEXNAME },
153                 { "titlelatextype",  TC_TITLELATEXTYPE },
154                 { "tocdepth",        TC_TOCDEPTH }
155         };
156
157         if (!merge)
158                 lyxerr[Debug::TCLASS] << "Reading textclass "
159                                       << MakeDisplayPath(filename)
160                                       << endl;
161         else
162                 lyxerr[Debug::TCLASS] << "Reading input file "
163                                      << MakeDisplayPath(filename)
164                                      << endl;
165
166         LyXLex lexrc(textClassTags,
167                 sizeof(textClassTags) / sizeof(textClassTags[0]));
168         bool error = false;
169
170         lexrc.setFile(filename);
171         if (!lexrc.isOK()) error = true;
172
173         // parsing
174         while (lexrc.isOK() && !error) {
175                 int le = lexrc.lex();
176
177                 switch (le) {
178                 case LyXLex::LEX_FEOF:
179                         continue;
180
181                 case LyXLex::LEX_UNDEF:
182                         lexrc.printError("Unknown TextClass tag `$$Token'");
183                         error = true;
184                         continue;
185
186                 default:
187                         break;
188                 }
189
190                 switch (static_cast<TextClassTags>(le)) {
191
192                 case TC_OUTPUTTYPE:   // output type definition
193                         readOutputType(lexrc);
194                         break;
195
196                 case TC_INPUT: // Include file
197                         if (lexrc.next()) {
198                                 string tmp = LibFileSearch("layouts",
199                                                             lexrc.getString(),
200                                                             "layout");
201
202                                 if (Read(tmp, true)) {
203                                         lexrc.printError("Error reading input"
204                                                          "file: "+tmp);
205                                         error = true;
206                                 }
207                         }
208                         break;
209
210                 case TC_DEFAULTSTYLE:
211                         if (lexrc.next()) {
212                                 string const name = subst(lexrc.getString(),
213                                                           '_', ' ');
214                                 defaultlayout_ = name;
215                         }
216                         break;
217
218                 case TC_ENVIRONMENT:
219                 case TC_STYLE:
220                         if (lexrc.next()) {
221                                 string const name = subst(lexrc.getString(),
222                                                     '_', ' ');
223                                 if (hasLayout(name)) {
224                                         LyXLayout * lay = operator[](name).get();
225                                         error = do_readStyle(lexrc, *lay);
226                                 } else {
227                                         LyXLayout lay;
228                                         lay.setName(name);
229                                         if (le == TC_ENVIRONMENT)
230                                                 lay.is_environment = true;
231                                         if (!(error = do_readStyle(lexrc, lay)))
232                                                 layoutlist_.push_back
233                                                         (boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
234                                         if (defaultlayout_.empty()) {
235                                                 // We do not have a default
236                                                 // layout yet, so we choose
237                                                 // the first layout we
238                                                 // encounter.
239                                                 defaultlayout_ = name;
240                                         }
241                                 }
242                         }
243                         else {
244                                 lexrc.printError("No name given for style: `$$Token'.");
245                                 error = true;
246                         }
247                         break;
248
249                 case TC_NOSTYLE:
250                         if (lexrc.next()) {
251                                 string const style = subst(lexrc.getString(),
252                                                      '_', ' ');
253                                 if (!delete_layout(style))
254                                         lyxerr << "Cannot delete style `"
255                                                << style << '\'' << endl;
256 //                                      lexrc.printError("Cannot delete style"
257 //                                                       " `$$Token'");
258                         }
259                         break;
260
261                 case TC_COLUMNS:
262                         if (lexrc.next())
263                                 columns_ = lexrc.getInteger();
264                         break;
265
266                 case TC_SIDES:
267                         if (lexrc.next()) {
268                                 switch (lexrc.getInteger()) {
269                                 case 1: sides_ = OneSide; break;
270                                 case 2: sides_ = TwoSides; break;
271                                 default:
272                                         lyxerr << "Impossible number of page"
273                                                 " sides, setting to one."
274                                                << endl;
275                                         sides_ = OneSide;
276                                         break;
277                                 }
278                         }
279                         break;
280
281                 case TC_PAGESTYLE:
282                         lexrc.next();
283                         pagestyle_ = rtrim(lexrc.getString());
284                         break;
285
286                 case TC_DEFAULTFONT:
287                         defaultfont_.lyxRead(lexrc);
288                         if (!defaultfont_.resolved()) {
289                                 lexrc.printError("Warning: defaultfont should "
290                                                  "be fully instantiated!");
291                                 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
292                         }
293                         break;
294
295                 case TC_MAXCOUNTER:
296                         readMaxCounter(lexrc);
297                         break;
298
299                 case TC_SECNUMDEPTH:
300                         lexrc.next();
301                         secnumdepth_ = lexrc.getInteger();
302                         break;
303
304                 case TC_TOCDEPTH:
305                         lexrc.next();
306                         tocdepth_ = lexrc.getInteger();
307                         break;
308
309                         // First step to support options
310                 case TC_CLASSOPTIONS:
311                         readClassOptions(lexrc);
312                         break;
313
314                 case TC_PREAMBLE:
315                         preamble_ = lexrc.getLongString("EndPreamble");
316                         break;
317
318                 case TC_PROVIDESAMSMATH:
319                         if (lexrc.next() && lexrc.getInteger())
320                                 provides_ |= amsmath;
321                         break;
322
323                 case TC_PROVIDESNATBIB:
324                         if (lexrc.next() && lexrc.getInteger())
325                                 provides_ |= natbib;
326                         break;
327
328                 case TC_PROVIDESMAKEIDX:
329                         if (lexrc.next() && lexrc.getInteger())
330                                 provides_ |= makeidx;
331                         break;
332
333                 case TC_PROVIDESURL:
334                         if (lexrc.next() && lexrc.getInteger())
335                                 provides_ |= url;
336                         break;
337
338                 case TC_LEFTMARGIN:     // left margin type
339                         if (lexrc.next())
340                                 leftmargin_ = lexrc.getString();
341                         break;
342
343                 case TC_RIGHTMARGIN:    // right margin type
344                         if (lexrc.next())
345                                 rightmargin_ = lexrc.getString();
346                         break;
347                 case TC_FLOAT:
348                         readFloat(lexrc);
349                         break;
350                 case TC_COUNTER:
351                         readCounter(lexrc);
352                         break;
353                 case TC_TITLELATEXTYPE:
354                         readTitleType(lexrc);
355                         break;
356                 case TC_TITLELATEXNAME:
357                         if (lexrc.next())
358                                 titlename_ = lexrc.getString();
359                         break;
360                 case TC_NOFLOAT:
361                         if (lexrc.next()) {
362                                 string const nofloat = lexrc.getString();
363                                 floatlist_->erase(nofloat);
364                         }
365                         break;
366                 }
367         }
368
369         if (!merge) { // we are at top level here.
370                 lyxerr[Debug::TCLASS] << "Finished reading textclass "
371                                       << MakeDisplayPath(filename)
372                                       << endl;
373                 if (defaultlayout_.empty()) {
374                         lyxerr << "Error: Textclass '" << name_
375                                << "' is missing a defaultstyle." << endl;
376                         error = true;
377                 }
378         } else
379                 lyxerr[Debug::TCLASS] << "Finished reading input file "
380                                       << MakeDisplayPath(filename)
381                                       << endl;
382
383         return error;
384 }
385
386
387 void LyXTextClass::readTitleType(LyXLex & lexrc)
388 {
389         keyword_item titleTypeTags[] = {
390                 { "commandafter", TITLE_COMMAND_AFTER },
391                 { "environment", TITLE_ENVIRONMENT }
392         };
393
394         pushpophelper pph(lexrc, titleTypeTags, TITLE_ENVIRONMENT);
395
396         int le = lexrc.lex();
397         switch (le) {
398         case LyXLex::LEX_UNDEF:
399                 lexrc.printError("Unknown output type `$$Token'");
400                 return;
401         case TITLE_COMMAND_AFTER:
402         case TITLE_ENVIRONMENT:
403                 titletype_ = static_cast<LYX_TITLE_LATEX_TYPES>(le);
404                 break;
405         default:
406                 lyxerr << "Unhandled value " << le
407                        << " in LyXTextClass::readTitleType." << endl;
408
409                 break;
410         }
411 }
412
413
414 void LyXTextClass::readOutputType(LyXLex & lexrc)
415 {
416         keyword_item outputTypeTags[] = {
417                 { "docbook", DOCBOOK },
418                 { "latex", LATEX },
419                 { "linuxdoc", LINUXDOC },
420                 { "literate", LITERATE }
421         };
422
423         pushpophelper pph(lexrc, outputTypeTags, LITERATE);
424
425         int le = lexrc.lex();
426         switch (le) {
427         case LyXLex::LEX_UNDEF:
428                 lexrc.printError("Unknown output type `$$Token'");
429                 return;
430         case LATEX:
431         case LINUXDOC:
432         case DOCBOOK:
433         case LITERATE:
434                 outputType_ = static_cast<OutputType>(le);
435                 break;
436         default:
437                 lyxerr << "Unhandled value " << le
438                        << " in LyXTextClass::readOutputType." << endl;
439
440                 break;
441         }
442 }
443
444
445 enum MaxCounterTags {
446         MC_COUNTER_CHAPTER = 1,
447         MC_COUNTER_SECTION,
448         MC_COUNTER_SUBSECTION,
449         MC_COUNTER_SUBSUBSECTION,
450         MC_COUNTER_PARAGRAPH,
451         MC_COUNTER_SUBPARAGRAPH,
452         MC_COUNTER_ENUMI,
453         MC_COUNTER_ENUMII,
454         MC_COUNTER_ENUMIII,
455         MC_COUNTER_ENUMIV
456 };
457
458
459 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
460 {
461         keyword_item maxCounterTags[] = {
462                 {"counter_chapter", MC_COUNTER_CHAPTER },
463                 {"counter_enumi", MC_COUNTER_ENUMI },
464                 {"counter_enumii", MC_COUNTER_ENUMII },
465                 {"counter_enumiii", MC_COUNTER_ENUMIII },
466                 {"counter_enumiv", MC_COUNTER_ENUMIV },
467                 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
468                 {"counter_section", MC_COUNTER_SECTION },
469                 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
470                 {"counter_subsection", MC_COUNTER_SUBSECTION },
471                 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
472         };
473
474         pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
475
476         int le = lexrc.lex();
477         switch (le) {
478         case LyXLex::LEX_UNDEF:
479                 lexrc.printError("Unknown MaxCounter tag `$$Token'");
480                 return;
481         default:
482                 break;
483         }
484
485         switch (static_cast<MaxCounterTags>(le)) {
486         case MC_COUNTER_CHAPTER:
487                 maxcounter_ = LABEL_COUNTER_CHAPTER;
488                 break;
489         case MC_COUNTER_SECTION:
490                 maxcounter_ = LABEL_COUNTER_SECTION;
491                 break;
492         case MC_COUNTER_SUBSECTION:
493                 maxcounter_ = LABEL_COUNTER_SUBSECTION;
494                 break;
495         case MC_COUNTER_SUBSUBSECTION:
496                 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
497                 break;
498         case MC_COUNTER_PARAGRAPH:
499                 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
500                 break;
501         case MC_COUNTER_SUBPARAGRAPH:
502                 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
503                 break;
504         case MC_COUNTER_ENUMI:
505                 maxcounter_ = LABEL_COUNTER_ENUMI;
506                 break;
507         case MC_COUNTER_ENUMII:
508                 maxcounter_ = LABEL_COUNTER_ENUMII;
509                 break;
510         case MC_COUNTER_ENUMIII:
511                 maxcounter_ = LABEL_COUNTER_ENUMIII;
512                 break;
513         case MC_COUNTER_ENUMIV:
514                 maxcounter_ = LABEL_COUNTER_ENUMIV;
515                 break;
516         }
517 }
518
519
520 enum ClassOptionsTags {
521         CO_FONTSIZE = 1,
522         CO_PAGESTYLE,
523         CO_OTHER,
524         CO_END
525 };
526
527
528 void LyXTextClass::readClassOptions(LyXLex & lexrc)
529 {
530         keyword_item classOptionsTags[] = {
531                 {"end", CO_END },
532                 {"fontsize", CO_FONTSIZE },
533                 {"other", CO_OTHER },
534                 {"pagestyle", CO_PAGESTYLE }
535         };
536
537         lexrc.pushTable(classOptionsTags, CO_END);
538         bool getout = false;
539         while (!getout && lexrc.isOK()) {
540                 int le = lexrc.lex();
541                 switch (le) {
542                 case LyXLex::LEX_UNDEF:
543                         lexrc.printError("Unknown ClassOption tag `$$Token'");
544                         continue;
545                 default: break;
546                 }
547                 switch (static_cast<ClassOptionsTags>(le)) {
548                 case CO_FONTSIZE:
549                         lexrc.next();
550                         opt_fontsize_ = rtrim(lexrc.getString());
551                         break;
552                 case CO_PAGESTYLE:
553                         lexrc.next();
554                         opt_pagestyle_ = rtrim(lexrc.getString());
555                         break;
556                 case CO_OTHER:
557                         lexrc.next();
558                         options_ = lexrc.getString();
559                         break;
560                 case CO_END:
561                         getout = true;
562                         break;
563                 }
564         }
565         lexrc.popTable();
566 }
567
568
569 enum FloatTags {
570         FT_TYPE = 1,
571         FT_NAME,
572         FT_PLACEMENT,
573         FT_EXT,
574         FT_WITHIN,
575         FT_STYLE,
576         FT_LISTNAME,
577         FT_BUILTIN,
578         FT_END
579 };
580
581 void LyXTextClass::readFloat(LyXLex & lexrc)
582 {
583         keyword_item floatTags[] = {
584                 { "end", FT_END },
585                 { "extension", FT_EXT },
586                 { "guiname", FT_NAME },
587                 { "latexbuiltin", FT_BUILTIN },
588                 { "listname", FT_LISTNAME },
589                 { "numberwithin", FT_WITHIN },
590                 { "placement", FT_PLACEMENT },
591                 { "style", FT_STYLE },
592                 { "type", FT_TYPE }
593         };
594
595         lexrc.pushTable(floatTags, FT_END);
596
597         string type;
598         string placement;
599         string ext;
600         string within;
601         string style;
602         string name;
603         string listname;
604         bool builtin = false;
605
606         bool getout = false;
607         while (!getout && lexrc.isOK()) {
608                 int le = lexrc.lex();
609                 switch (le) {
610                 case LyXLex::LEX_UNDEF:
611                         lexrc.printError("Unknown ClassOption tag `$$Token'");
612                         continue;
613                 default: break;
614                 }
615                 switch (static_cast<FloatTags>(le)) {
616                 case FT_TYPE:
617                         lexrc.next();
618                         type = lexrc.getString();
619                         // Here we could check if this type is already defined
620                         // and modify it with the rest of the vars instead.
621                         break;
622                 case FT_NAME:
623                         lexrc.next();
624                         name = lexrc.getString();
625                         break;
626                 case FT_PLACEMENT:
627                         lexrc.next();
628                         placement = lexrc.getString();
629                         break;
630                 case FT_EXT:
631                         lexrc.next();
632                         ext = lexrc.getString();
633                         break;
634                 case FT_WITHIN:
635                         lexrc.next();
636                         within = lexrc.getString();
637                         if (within == "none")
638                                 within.erase();
639                         break;
640                 case FT_STYLE:
641                         lexrc.next();
642                         style = lexrc.getString();
643                         break;
644                 case FT_LISTNAME:
645                         lexrc.next();
646                         listname = lexrc.getString();
647                         break;
648                 case FT_BUILTIN:
649                         lexrc.next();
650                         builtin = lexrc.getBool();
651                         break;
652                 case FT_END:
653                         getout = true;
654                         break;
655                 }
656         }
657
658         // Here if have a full float if getout == true
659         if (getout) {
660                 Floating newfloat(type, placement, ext, within,
661                                   style, name, listname, builtin);
662                 floatlist_->newFloat(newfloat);
663         }
664
665         lexrc.popTable();
666 }
667
668
669 enum CounterTags {
670         CT_NAME = 1,
671         CT_WITHIN,
672         CT_END
673 };
674
675 void LyXTextClass::readCounter(LyXLex & lexrc)
676 {
677         keyword_item counterTags[] = {
678                 { "end", CT_END },
679                 { "name", CT_NAME },
680                 { "within", CT_WITHIN }
681         };
682
683         lexrc.pushTable(counterTags, CT_END);
684
685         string name;
686         string within;
687
688         bool getout = false;
689         while (!getout && lexrc.isOK()) {
690                 int le = lexrc.lex();
691                 switch (le) {
692                 case LyXLex::LEX_UNDEF:
693                         lexrc.printError("Unknown ClassOption tag `$$Token'");
694                         continue;
695                 default: break;
696                 }
697                 switch (static_cast<CounterTags>(le)) {
698                 case CT_NAME:
699                         lexrc.next();
700                         name = lexrc.getString();
701                         break;
702                 case CT_WITHIN:
703                         lexrc.next();
704                         within = lexrc.getString();
705                         if (within == "none")
706                                 within.erase();
707                         break;
708                 case CT_END:
709                         getout = true;
710                         break;
711                 }
712         }
713
714         // Here if have a full float if getout == true
715         if (getout) {
716                 if (within.empty()) {
717                         ctrs_->newCounter(name);
718                 } else {
719                         ctrs_->newCounter(name, within);
720                 }
721         }
722
723         lexrc.popTable();
724 }
725
726
727 LyXFont const & LyXTextClass::defaultfont() const
728 {
729         return defaultfont_;
730 }
731
732
733 string const & LyXTextClass::leftmargin() const
734 {
735         return leftmargin_;
736 }
737
738
739 string const & LyXTextClass::rightmargin() const
740 {
741         return rightmargin_;
742 }
743
744
745 bool LyXTextClass::hasLayout(string const & n) const
746 {
747         string const name = (n.empty() ? defaultLayoutName() : n);
748
749         return find_if(layoutlist_.begin(), layoutlist_.end(),
750                        compare_name(name))
751                 != layoutlist_.end();
752 }
753
754
755
756 LyXLayout_ptr const & LyXTextClass::operator[](string const & name) const
757 {
758         lyx::Assert(!name.empty());
759
760         LayoutList::const_iterator cit =
761                 find_if(layoutlist_.begin(),
762                         layoutlist_.end(),
763                         compare_name(name));
764
765         if (cit == layoutlist_.end()) {
766                 lyxerr << "We failed to find the layout '" << name
767                        << "' in the layout list. You MUST investigate!"
768                        << endl;
769                 for (LayoutList::const_iterator it = layoutlist_.begin();
770                          it != layoutlist_.end(); ++it)
771                         lyxerr  << " " << it->get()->name() << endl;
772
773                 // we require the name to exist
774                 lyx::Assert(false);
775         }
776
777         return (*cit);
778 }
779
780
781
782 bool LyXTextClass::delete_layout(string const & name)
783 {
784         if (name == defaultLayoutName())
785                 return false;
786
787         LayoutList::iterator it =
788                 remove_if(layoutlist_.begin(), layoutlist_.end(),
789                           compare_name(name));
790
791         LayoutList::iterator end = layoutlist_.end();
792         bool const ret = (it != end);
793         layoutlist_.erase(it, end);
794         return ret;
795 }
796
797
798 // Load textclass info if not loaded yet
799 bool LyXTextClass::load() const
800 {
801         if (loaded)
802                 return true;
803
804         // Read style-file
805         string const real_file = LibFileSearch("layouts", name_, "layout");
806
807         if (const_cast<LyXTextClass*>(this)->Read(real_file)) {
808                 lyxerr << "Error reading `"
809                        << MakeDisplayPath(real_file)
810                        << "'\n(Check `" << name_
811                        << "')\nCheck your installation and "
812                         "try Options/Reconfigure..." << endl;
813                 loaded = false;
814         }
815         loaded = true;
816         return loaded;
817 }
818
819
820 FloatList & LyXTextClass::floats()
821 {
822         return *floatlist_.get();
823 }
824
825
826 FloatList const & LyXTextClass::floats() const
827 {
828         return *floatlist_.get();
829 }
830
831
832 Counters & LyXTextClass::counters() const
833 {
834         return *ctrs_.get();
835 }
836
837
838 string const & LyXTextClass::defaultLayoutName() const
839 {
840         // This really should come from the actual layout... (Lgb)
841         return defaultlayout_;
842 }
843
844
845 LyXLayout_ptr const & LyXTextClass::defaultLayout() const
846 {
847         return operator[](defaultLayoutName());
848 }
849
850
851 string const & LyXTextClass::name() const
852 {
853         return name_;
854 }
855
856
857 string const & LyXTextClass::latexname() const
858 {
859         const_cast<LyXTextClass*>(this)->load();
860         return latexname_;
861 }
862
863
864 string const & LyXTextClass::description() const
865 {
866         return description_;
867 }
868
869
870 string const & LyXTextClass::opt_fontsize() const
871 {
872         return opt_fontsize_;
873 }
874
875
876 string const & LyXTextClass::opt_pagestyle() const
877 {
878         return opt_pagestyle_;
879 }
880
881
882 string const & LyXTextClass::options() const
883 {
884         return options_;
885 }
886
887
888 string const & LyXTextClass::pagestyle() const
889 {
890         return pagestyle_;
891 }
892
893
894 string const & LyXTextClass::preamble() const
895 {
896         return preamble_;
897 }
898
899
900 LyXTextClass::PageSides LyXTextClass::sides() const
901 {
902         return sides_;
903 }
904
905
906 int LyXTextClass::secnumdepth() const
907 {
908         return secnumdepth_;
909 }
910
911
912 int LyXTextClass::tocdepth() const
913 {
914         return tocdepth_;
915 }
916
917
918 OutputType LyXTextClass::outputType() const
919 {
920         return outputType_;
921 }
922
923
924 bool LyXTextClass::provides(LyXTextClass::Provides p) const
925 {
926         return provides_ & p;
927 }
928
929
930 unsigned int LyXTextClass::columns() const
931 {
932         return columns_;
933 }
934
935
936 int LyXTextClass::maxcounter() const
937 {
938         return maxcounter_;
939 }
940
941
942 LYX_TITLE_LATEX_TYPES LyXTextClass::titletype() const
943 {
944         return titletype_;
945 }
946
947
948 string const & LyXTextClass::titlename() const
949 {
950         return titlename_;
951 }
952
953
954
955
956
957 int LyXTextClass::size() const
958 {
959         return layoutlist_.size();
960 }
961
962
963 ostream & operator<<(ostream & os, LyXTextClass::PageSides p)
964 {
965         switch (p) {
966         case LyXTextClass::OneSide:
967                 os << '1';
968                 break;
969         case LyXTextClass::TwoSides:
970                 os << '2';
971                 break;
972         }
973         return os;
974 }