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