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