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