3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
10 * \author André Pönitz
12 * Full author contact details are available in file CREDITS.
17 #include "TextClass.h"
19 #include "LayoutFile.h"
20 #include "CiteEnginesList.h"
24 #include "FloatList.h"
28 #include "ModuleList.h"
30 #include "frontends/alert.h"
32 #include "support/lassert.h"
33 #include "support/debug.h"
34 #include "support/ExceptionMessage.h"
35 #include "support/FileName.h"
36 #include "support/filetools.h"
37 #include "support/gettext.h"
38 #include "support/lstrings.h"
39 #include "support/os.h"
40 #include "support/TempFile.h"
51 using namespace lyx::support;
55 // Keep the changes documented in the Customization manual.
57 // If you change this format, then you MUST also make sure that
58 // your changes do not invalidate the hardcoded layout file in
59 // LayoutFile.cpp. Additions will never do so, but syntax changes
60 // could. See LayoutFileList::addEmptyClass() and, especially, the
61 // definition of the layoutpost string.
62 // You should also run the development/tools/updatelayouts.py script,
63 // to update the format of all of our layout files.
65 int const LAYOUT_FORMAT = 78; // spitz: FontsizeFormat
68 // Layout format for the current lyx file format. Controls which format is
69 // targeted by Local Layout > Convert. In master, equal to LAYOUT_FORMAT.
70 int const LYXFILE_LAYOUT_FORMAT = LAYOUT_FORMAT;
75 class LayoutNamesEqual : public unary_function<Layout, bool> {
77 LayoutNamesEqual(docstring const & name)
80 bool operator()(Layout const & c) const
82 return c.name() == name_;
89 bool layout2layout(FileName const & filename, FileName const & tempfile,
90 int const format = LAYOUT_FORMAT)
92 FileName const script = libFileSearch("scripts", "layout2layout.py");
94 LYXERR0("Could not find layout conversion "
95 "script layout2layout.py.");
99 ostringstream command;
100 command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
102 << ' ' << quoteName(filename.toFilesystemEncoding())
103 << ' ' << quoteName(tempfile.toFilesystemEncoding());
104 string const command_str = command.str();
106 LYXERR(Debug::TCLASS, "Running `" << command_str << '\'');
108 cmd_ret const ret = runCommand(command_str);
109 if (ret.first != 0) {
110 if (format == LAYOUT_FORMAT)
111 LYXERR0("Conversion of layout with layout2layout.py has failed.");
118 string translateReadType(TextClass::ReadType rt)
121 case TextClass::BASECLASS:
123 case TextClass::MERGE:
125 case TextClass::MODULE:
126 return "module file";
127 case TextClass::CITE_ENGINE:
128 return "cite engine";
129 case TextClass::VALIDATION:
139 // This string should not be translated here,
140 // because it is a layout identifier.
141 docstring const TextClass::plain_layout_ = from_ascii(N_("Plain Layout"));
144 /////////////////////////////////////////////////////////////////////////
148 /////////////////////////////////////////////////////////////////////////
150 TextClass::TextClass()
151 : loaded_(false), tex_class_avail_(false),
152 opt_enginetype_("authoryear|numerical"), opt_fontsize_("10|11|12"),
153 opt_pagesize_("default|a4paper|a5paper|b5paper|letterpaper|legalpaper|executivepaper"),
154 opt_pagestyle_("empty|plain|headings|fancy"), fontsize_format_("$$spt"), pagesize_("default"),
155 pagestyle_("default"), tablestyle_("default"), columns_(1), sides_(OneSide), secnumdepth_(3),
156 tocdepth_(3), outputType_(LATEX), outputFormat_("latex"),
157 has_output_format_(false), defaultfont_(sane_font),
158 titletype_(TITLE_COMMAND_AFTER), titlename_("maketitle"),
159 min_toclevel_(0), max_toclevel_(0), maxcitenames_(2),
160 cite_full_author_list_(true), bibintoc_(false)
165 bool TextClass::readStyle(Lexer & lexrc, Layout & lay) const
167 LYXERR(Debug::TCLASS, "Reading style " << to_utf8(lay.name()));
168 if (!lay.read(lexrc, *this)) {
169 LYXERR0("Error parsing style `" << to_utf8(lay.name()) << '\'');
173 lay.resfont = lay.font;
174 lay.resfont.realize(defaultfont_);
175 lay.reslabelfont = lay.labelfont;
176 lay.reslabelfont.realize(defaultfont_);
177 return true; // no errors
217 TC_ADDTOHTMLPREAMBLE,
239 LexerKeyword textClassTags[] = {
240 { "addtociteengine", TC_ADDTOCITEENGINE },
241 { "addtohtmlpreamble", TC_ADDTOHTMLPREAMBLE },
242 { "addtohtmlstyles", TC_ADDTOHTMLSTYLES },
243 { "addtopreamble", TC_ADDTOPREAMBLE },
244 { "bibintoc", TC_BIBINTOC },
245 { "citeengine", TC_CITEENGINE },
246 { "citeenginetype", TC_CITEENGINETYPE },
247 { "citeformat", TC_CITEFORMAT },
248 { "citeframework", TC_CITEFRAMEWORK },
249 { "classoptions", TC_CLASSOPTIONS },
250 { "columns", TC_COLUMNS },
251 { "counter", TC_COUNTER },
252 { "defaultbiblio", TC_DEFAULTBIBLIO },
253 { "defaultfont", TC_DEFAULTFONT },
254 { "defaultmodule", TC_DEFAULTMODULE },
255 { "defaultstyle", TC_DEFAULTSTYLE },
256 { "excludesmodule", TC_EXCLUDESMODULE },
257 { "float", TC_FLOAT },
258 { "format", TC_FORMAT },
259 { "fullauthorlist", TC_FULLAUTHORLIST },
260 { "htmlpreamble", TC_HTMLPREAMBLE },
261 { "htmlstyles", TC_HTMLSTYLES },
262 { "htmltocsection", TC_HTMLTOCSECTION },
263 { "ifcounter", TC_IFCOUNTER },
264 { "input", TC_INPUT },
265 { "insetlayout", TC_INSETLAYOUT },
266 { "leftmargin", TC_LEFTMARGIN },
267 { "maxcitenames", TC_MAXCITENAMES },
268 { "modifystyle", TC_MODIFYSTYLE },
269 { "nocounter", TC_NOCOUNTER },
270 { "nofloat", TC_NOFLOAT },
271 { "noinsetlayout", TC_NOINSETLAYOUT },
272 { "nostyle", TC_NOSTYLE },
273 { "outlinername", TC_OUTLINERNAME },
274 { "outputformat", TC_OUTPUTFORMAT },
275 { "outputtype", TC_OUTPUTTYPE },
276 { "packageoptions", TC_PKGOPTS },
277 { "pagesize", TC_PAGESIZE },
278 { "pagestyle", TC_PAGESTYLE },
279 { "preamble", TC_PREAMBLE },
280 { "provides", TC_PROVIDES },
281 { "providesmodule", TC_PROVIDESMODULE },
282 { "providestyle", TC_PROVIDESTYLE },
283 { "requires", TC_REQUIRES },
284 { "rightmargin", TC_RIGHTMARGIN },
285 { "secnumdepth", TC_SECNUMDEPTH },
286 { "sides", TC_SIDES },
287 { "style", TC_STYLE },
288 { "tablestyle", TC_TABLESTYLE },
289 { "titlelatexname", TC_TITLELATEXNAME },
290 { "titlelatextype", TC_TITLELATEXTYPE },
291 { "tocdepth", TC_TOCDEPTH }
297 bool TextClass::convertLayoutFormat(support::FileName const & filename, ReadType rt)
299 LYXERR(Debug::TCLASS, "Converting layout file to " << LAYOUT_FORMAT);
300 TempFile tmp("convertXXXXXX.layout");
301 FileName const tempfile = tmp.name();
302 bool success = layout2layout(filename, tempfile);
304 success = readWithoutConv(tempfile, rt) == OK;
309 std::string TextClass::convert(std::string const & str)
311 TempFile tmp1("localXXXXXX.layout");
312 FileName const fn = tmp1.name();
313 ofstream os(fn.toFilesystemEncoding().c_str());
316 TempFile tmp2("convert_localXXXXXX.layout");
317 FileName const tempfile = tmp2.name();
318 bool success = layout2layout(fn, tempfile, LYXFILE_LAYOUT_FORMAT);
321 ifstream is(tempfile.toFilesystemEncoding().c_str());
333 TextClass::ReturnValues TextClass::readWithoutConv(FileName const & filename, ReadType rt)
335 if (!filename.isReadableFile()) {
336 lyxerr << "Cannot read layout file `" << filename << "'."
341 LYXERR(Debug::TCLASS, "Reading " + translateReadType(rt) + ": " +
342 to_utf8(makeDisplayPath(filename.absFileName())));
344 // Define the plain layout used in table cells, ert, etc. Note that
345 // we do this before loading any layout file, so that classes can
346 // override features of this layout if they should choose to do so.
347 if (rt == BASECLASS && !hasLayout(plain_layout_))
348 layoutlist_.push_back(createBasicLayout(plain_layout_));
350 Lexer lexrc(textClassTags);
351 lexrc.setFile(filename);
352 ReturnValues retval = read(lexrc, rt);
354 LYXERR(Debug::TCLASS, "Finished reading " + translateReadType(rt) + ": " +
355 to_utf8(makeDisplayPath(filename.absFileName())));
361 bool TextClass::read(FileName const & filename, ReadType rt)
363 ReturnValues const retval = readWithoutConv(filename, rt);
364 if (retval != FORMAT_MISMATCH)
367 bool const worx = convertLayoutFormat(filename, rt);
369 LYXERR0 ("Unable to convert " << filename <<
370 " to format " << LAYOUT_FORMAT);
375 TextClass::ReturnValues TextClass::validate(std::string const & str)
378 return tc.read(str, VALIDATION);
382 TextClass::ReturnValues TextClass::read(std::string const & str, ReadType rt)
384 Lexer lexrc(textClassTags);
385 istringstream is(str);
387 ReturnValues retval = read(lexrc, rt);
389 if (retval != FORMAT_MISMATCH)
392 // write the layout string to a temporary file
393 TempFile tmp("TextClass_read");
394 FileName const tempfile = tmp.name();
395 ofstream os(tempfile.toFilesystemEncoding().c_str());
397 LYXERR0("Unable to create temporary file");
403 // now try to convert it to LAYOUT_FORMAT
404 if (!convertLayoutFormat(tempfile, rt)) {
405 LYXERR0("Unable to convert internal layout information to format "
414 // Reads a textclass structure from file.
415 TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
420 // The first usable line should be
421 // Format LAYOUT_FORMAT
422 if (lexrc.lex() != TC_FORMAT || !lexrc.next()
423 || lexrc.getInteger() != LAYOUT_FORMAT)
424 return FORMAT_MISMATCH;
428 while (lexrc.isOK() && !error) {
429 int le = lexrc.lex();
432 case Lexer::LEX_FEOF:
435 case Lexer::LEX_UNDEF:
436 lexrc.printError("Unknown TextClass tag `$$Token'");
444 // used below to track whether we are in an IfStyle or IfCounter tag.
445 bool modifystyle = false;
446 bool providestyle = false;
447 bool ifcounter = false;
449 switch (static_cast<TextClassTags>(le)) {
453 lexrc.printError("Duplicate Format directive");
456 case TC_OUTPUTFORMAT:
458 outputFormat_ = lexrc.getString();
459 has_output_format_ = true;
464 readOutputType(lexrc);
465 switch(outputType_) {
467 outputFormat_ = "latex";
470 outputFormat_ = "docbook";
473 outputFormat_ = "literate";
478 case TC_INPUT: // Include file
481 string const inc = lexrc.getString();
482 if (!path().empty() && (prefixIs(inc, "./") ||
483 prefixIs(inc, "../")))
484 tmp = fileSearch(path(), inc, "layout");
486 tmp = libFileSearch("layouts", inc,
490 lexrc.printError("Could not find input file: " + inc);
492 } else if (!read(tmp, MERGE)) {
493 lexrc.printError("Error reading input file: " + tmp.absFileName());
499 case TC_DEFAULTSTYLE:
501 docstring const name = from_utf8(subst(lexrc.getString(),
503 defaultlayout_ = name;
510 case TC_PROVIDESTYLE:
511 // if modifystyle is true, then we got here by falling through
512 // so we are not in an ProvideStyle block
518 lexrc.printError("No name given for style: `$$Token'.");
522 docstring const name = from_utf8(subst(lexrc.getString(),
525 string s = "Could not read name for style: `$$Token' "
526 + lexrc.getString() + " is probably not valid UTF-8!";
529 // Since we couldn't read the name, we just scan the rest
530 // of the style and discard it.
531 error = !readStyle(lexrc, lay);
535 bool const have_layout = hasLayout(name);
537 // If the layout already exists, then we want to add it to
538 // the existing layout, as long as we are not in an ProvideStyle
540 if (have_layout && !providestyle) {
541 Layout & lay = operator[](name);
542 error = !readStyle(lexrc, lay);
544 // If the layout does not exist, then we want to create a new
545 // one, but not if we are in a ModifyStyle block.
546 else if (!have_layout && !modifystyle) {
548 layout.setName(name);
549 error = !readStyle(lexrc, layout);
551 layoutlist_.push_back(layout);
553 if (defaultlayout_.empty()) {
554 // We do not have a default layout yet, so we choose
555 // the first layout we encounter.
556 defaultlayout_ = name;
559 // There are two ways to get here:
560 // (i) The layout exists but we are in an ProvideStyle block
561 // (ii) The layout doesn't exist, but we are in an ModifyStyle
563 // Either way, we just scan the rest and discard it
566 // signal to coverity that we do not care about the result
567 (void)readStyle(lexrc, lay);
574 docstring const style = from_utf8(subst(lexrc.getString(),
576 if (!deleteLayout(style))
577 lyxerr << "Cannot delete style `"
578 << to_utf8(style) << '\'' << endl;
582 case TC_NOINSETLAYOUT:
584 docstring const style = from_utf8(subst(lexrc.getString(),
586 if (!deleteInsetLayout(style))
587 LYXERR0("Style `" << style << "' cannot be removed\n"
588 "because it was not found!");
594 columns_ = lexrc.getInteger();
599 switch (lexrc.getInteger()) {
600 case 1: sides_ = OneSide; break;
601 case 2: sides_ = TwoSides; break;
603 lyxerr << "Impossible number of page"
604 " sides, setting to one."
614 pagesize_ = rtrim(lexrc.getString());
619 pagestyle_ = rtrim(lexrc.getString());
623 defaultfont_ = lyxRead(lexrc);
624 if (!defaultfont_.resolved()) {
625 lexrc.printError("Warning: defaultfont should "
626 "be fully instantiated!");
627 defaultfont_.realize(sane_font);
633 secnumdepth_ = lexrc.getInteger();
638 tocdepth_ = lexrc.getInteger();
641 // First step to support options
642 case TC_CLASSOPTIONS:
643 readClassOptions(lexrc);
647 preamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
650 case TC_HTMLPREAMBLE:
651 htmlpreamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
655 htmlstyles_ = lexrc.getLongString(from_ascii("EndStyles"));
658 case TC_HTMLTOCSECTION:
659 html_toc_section_ = from_utf8(trim(lexrc.getString()));
662 case TC_ADDTOPREAMBLE:
663 preamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
666 case TC_ADDTOHTMLPREAMBLE:
667 htmlpreamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
670 case TC_ADDTOHTMLSTYLES:
671 htmlstyles_ += lexrc.getLongString(from_ascii("EndStyles"));
676 string const feature = lexrc.getString();
678 if (lexrc.getInteger())
679 provides_.insert(feature);
681 provides_.erase(feature);
687 vector<string> const req
688 = getVectorFromString(lexrc.getString());
689 requires_.insert(req.begin(), req.end());
695 string const pkg = lexrc.getString();
697 string const options = lexrc.getString();
698 package_options_[pkg] = options;
702 case TC_DEFAULTMODULE: {
704 string const module = lexrc.getString();
705 if (find(default_modules_.begin(), default_modules_.end(), module) == default_modules_.end())
706 default_modules_.push_back(module);
710 case TC_PROVIDESMODULE: {
712 string const module = lexrc.getString();
713 if (find(provided_modules_.begin(), provided_modules_.end(), module) == provided_modules_.end())
714 provided_modules_.push_back(module);
718 case TC_EXCLUDESMODULE: {
720 string const module = lexrc.getString();
721 // modules already have their own way to exclude other modules
723 LYXERR0("ExcludesModule tag cannot be used in a module!");
726 if (find(excluded_modules_.begin(), excluded_modules_.end(), module) == excluded_modules_.end())
727 excluded_modules_.push_back(module);
731 case TC_LEFTMARGIN: // left margin type
733 leftmargin_ = lexrc.getDocString();
736 case TC_RIGHTMARGIN: // right margin type
738 rightmargin_ = lexrc.getDocString();
741 case TC_INSETLAYOUT: {
743 lexrc.printError("No name given for InsetLayout: `$$Token'.");
747 docstring const name = subst(lexrc.getDocString(), '_', ' ');
749 string s = "Could not read name for InsetLayout: `$$Token' "
750 + lexrc.getString() + " is probably not valid UTF-8!";
753 // Since we couldn't read the name, we just scan the rest
754 // of the style and discard it.
755 il.read(lexrc, *this);
756 // Let's try to continue rather than abort.
758 } else if (hasInsetLayout(name)) {
759 InsetLayout & il = insetlayoutlist_[name];
760 error = !il.read(lexrc, *this);
764 error = !il.read(lexrc, *this);
766 insetlayoutlist_[name] = il;
772 error = !readFloat(lexrc);
776 error = !readCiteEngine(lexrc, rt);
779 case TC_ADDTOCITEENGINE:
780 error = !readCiteEngine(lexrc, rt, true);
783 case TC_CITEENGINETYPE:
785 opt_enginetype_ = rtrim(lexrc.getString());
789 error = !readCiteFormat(lexrc, rt);
792 case TC_CITEFRAMEWORK:
794 citeframework_ = rtrim(lexrc.getString());
797 case TC_MAXCITENAMES:
799 maxcitenames_ = size_t(lexrc.getInteger());
802 case TC_DEFAULTBIBLIO:
804 vector<string> const dbs =
805 getVectorFromString(rtrim(lexrc.getString()), "|");
806 vector<string>::const_iterator it = dbs.begin();
807 vector<string>::const_iterator end = dbs.end();
808 for (; it != end; ++it) {
809 if (!contains(*it, ':')) {
810 vector<string> const enginetypes =
811 getVectorFromString(opt_enginetype_, "|");
812 for (string const &s: enginetypes)
813 cite_default_biblio_style_[s] = *it;
816 string const db = split(*it, eng, ':');
817 cite_default_biblio_style_[eng] = db;
825 bibintoc_ = lexrc.getBool();
828 case TC_FULLAUTHORLIST:
830 cite_full_author_list_ &= lexrc.getBool();
835 docstring const cnt = lexrc.getDocString();
836 if (!counters_.remove(cnt))
837 LYXERR0("Unable to remove counter: " + to_utf8(cnt));
846 docstring const name = lexrc.getDocString();
848 string s = "Could not read name for counter: `$$Token' "
849 + lexrc.getString() + " is probably not valid UTF-8!";
850 lexrc.printError(s.c_str());
852 // Since we couldn't read the name, we just scan the rest
856 error = !counters_.read(lexrc, name, !ifcounter);
859 lexrc.printError("No name given for style: `$$Token'.");
864 case TC_TITLELATEXTYPE:
865 readTitleType(lexrc);
868 case TC_TITLELATEXNAME:
870 titlename_ = lexrc.getString();
875 string const nofloat = lexrc.getString();
876 floatlist_.erase(nofloat);
880 case TC_OUTLINERNAME:
881 error = !readOutlinerName(lexrc);
886 tablestyle_ = rtrim(lexrc.getString());
891 // at present, we abort if we encounter an error,
892 // so there is no point continuing.
899 if (defaultlayout_.empty()) {
900 LYXERR0("Error: Textclass '" << name_
901 << "' is missing a defaultstyle.");
905 // Try to erase "stdinsets" from the provides_ set.
907 // Provides stdinsets 1
908 // declaration simply tells us that the standard insets have been
909 // defined. (It's found in stdinsets.inc but could also be used in
910 // user-defined files.) There isn't really any such package. So we
911 // might as well go ahead and erase it.
912 // If we do not succeed, then it was not there, which means that
913 // the textclass did not provide the definitions of the standard
914 // insets. So we need to try to load them.
915 int erased = provides_.erase("stdinsets");
917 FileName tmp = libFileSearch("layouts", "stdinsets.inc");
920 frontend::Alert::warning(_("Missing File"),
921 _("Could not find stdinsets.inc! This may lead to data loss!"));
923 } else if (!read(tmp, MERGE)) {
924 frontend::Alert::warning(_("Corrupt File"),
925 _("Could not read stdinsets.inc! This may lead to data loss!"));
930 min_toclevel_ = Layout::NOT_IN_TOC;
931 max_toclevel_ = Layout::NOT_IN_TOC;
932 const_iterator lit = begin();
933 const_iterator len = end();
934 for (; lit != len; ++lit) {
935 int const toclevel = lit->toclevel;
936 if (toclevel != Layout::NOT_IN_TOC) {
937 if (min_toclevel_ == Layout::NOT_IN_TOC)
938 min_toclevel_ = toclevel;
940 min_toclevel_ = min(min_toclevel_, toclevel);
941 max_toclevel_ = max(max_toclevel_, toclevel);
944 LYXERR(Debug::TCLASS, "Minimum TocLevel is " << min_toclevel_
945 << ", maximum is " << max_toclevel_);
947 return (error ? ERROR : OK);
951 void TextClass::readTitleType(Lexer & lexrc)
953 LexerKeyword titleTypeTags[] = {
954 { "commandafter", TITLE_COMMAND_AFTER },
955 { "environment", TITLE_ENVIRONMENT }
958 PushPopHelper pph(lexrc, titleTypeTags);
960 int le = lexrc.lex();
962 case Lexer::LEX_UNDEF:
963 lexrc.printError("Unknown output type `$$Token'");
965 case TITLE_COMMAND_AFTER:
966 case TITLE_ENVIRONMENT:
967 titletype_ = static_cast<TitleLatexType>(le);
970 LYXERR0("Unhandled value " << le << " in TextClass::readTitleType.");
976 void TextClass::readOutputType(Lexer & lexrc)
978 LexerKeyword outputTypeTags[] = {
979 { "docbook", DOCBOOK },
981 { "literate", LITERATE }
984 PushPopHelper pph(lexrc, outputTypeTags);
986 int le = lexrc.lex();
988 case Lexer::LEX_UNDEF:
989 lexrc.printError("Unknown output type `$$Token'");
994 outputType_ = static_cast<OutputType>(le);
997 LYXERR0("Unhandled value " << le);
1003 void TextClass::readClassOptions(Lexer & lexrc)
1015 LexerKeyword classOptionsTags[] = {
1017 {"fontsize", CO_FONTSIZE },
1018 {"fontsizeformat", CO_FONTSIZE_FORMAT },
1019 {"header", CO_HEADER },
1020 {"other", CO_OTHER },
1021 {"pagesize", CO_PAGESIZE },
1022 {"pagestyle", CO_PAGESTYLE }
1025 lexrc.pushTable(classOptionsTags);
1026 bool getout = false;
1027 while (!getout && lexrc.isOK()) {
1028 int le = lexrc.lex();
1030 case Lexer::LEX_UNDEF:
1031 lexrc.printError("Unknown ClassOption tag `$$Token'");
1039 opt_fontsize_ = rtrim(lexrc.getString());
1041 case CO_FONTSIZE_FORMAT:
1043 fontsize_format_ = rtrim(lexrc.getString());
1047 opt_pagesize_ = rtrim(lexrc.getString());
1051 opt_pagestyle_ = rtrim(lexrc.getString());
1055 if (options_.empty())
1056 options_ = lexrc.getString();
1058 options_ += ',' + lexrc.getString();
1062 class_header_ = subst(lexrc.getString(), """, "\"");
1073 vector<CitationStyle> const & TextClass::getCiteStyles(
1074 CiteEngineType const & type) const
1076 static vector<CitationStyle> empty;
1077 map<CiteEngineType, vector<CitationStyle> >::const_iterator it = cite_styles_.find(type);
1078 if (it == cite_styles_.end())
1084 bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
1086 int const type = readCiteEngineType(lexrc);
1087 bool authoryear = (type & ENGINE_TYPE_AUTHORYEAR);
1088 bool numerical = (type & ENGINE_TYPE_NUMERICAL);
1089 bool defce = (type & ENGINE_TYPE_DEFAULT);
1091 if (rt == CITE_ENGINE) {
1092 // The cite engines are not supposed to overwrite
1093 // CiteStyle defined by the class or a module.
1095 authoryear = getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
1097 numerical = getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
1099 defce = getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
1102 if (rt != CITE_ENGINE && !add) {
1103 // Reset if we defined CiteStyle
1104 // from the class or a module
1106 cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
1108 cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
1110 cite_styles_[ENGINE_TYPE_DEFAULT].clear();
1114 bool getout = false;
1115 while (!getout && lexrc.isOK()) {
1117 def = lexrc.getString();
1118 def = subst(def, " ", "");
1119 def = subst(def, "\t", "");
1120 if (compare_ascii_no_case(def, "end") == 0) {
1125 char ichar = def[0];
1128 if (isUpperCase(ichar)) {
1129 cs.forceUpperCase = true;
1130 def[0] = lowercase(ichar);
1133 /** For portability reasons (between different
1134 * cite engines such as natbib and biblatex),
1135 * we distinguish between:
1136 * 1. The LyX name as output in the LyX file
1137 * 2. Possible aliases that might fall back to
1138 * the given LyX name in the current engine
1139 * 3. The actual LaTeX command that is output
1140 * (2) and (3) are optional.
1141 * Also, the GUI string for the starred version can
1144 * LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd
1153 ScanMode mode = LyXName;
1154 ScanMode oldmode = LyXName;
1159 size_t const n = def.size();
1160 for (size_t i = 0; i != n; ++i) {
1164 else if (ichar == '=')
1166 else if (ichar == '<') {
1169 } else if (ichar == '>')
1171 else if (mode == LaTeXCmd)
1173 else if (mode == StarDesc)
1175 else if (ichar == '$')
1176 cs.hasQualifiedList = true;
1177 else if (ichar == '*')
1178 cs.hasStarredVersion = true;
1179 else if (ichar == '[' && cs.textAfter)
1180 cs.textBefore = true;
1181 else if (ichar == '[')
1182 cs.textAfter = true;
1183 else if (ichar != ']') {
1191 cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd;
1192 if (!alias.empty()) {
1193 vector<string> const aliases = getVectorFromString(alias);
1194 for (string const &s: aliases)
1195 cite_command_aliases_[s] = lyx_cmd;
1197 vector<string> const stardescs = getVectorFromString(stardesc, "!");
1198 int size = int(stardesc.size());
1200 cs.stardesc = stardescs[0];
1202 cs.startooltip = stardescs[1];
1205 class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
1207 class_cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
1209 class_cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
1212 cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
1214 cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
1216 cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
1219 // If we do AddToCiteEngine, do not apply yet,
1220 // except if we have already a style to add something to
1221 bool apply_ay = !add;
1222 bool apply_num = !add;
1223 bool apply_def = !add;
1225 if (type & ENGINE_TYPE_AUTHORYEAR)
1226 apply_ay = !getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
1227 if (type & ENGINE_TYPE_NUMERICAL)
1228 apply_num = !getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
1229 if (type & ENGINE_TYPE_DEFAULT)
1230 apply_def = !getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
1233 // Add the styles from AddToCiteEngine to the class' styles
1234 // (but only if they are not yet defined)
1235 for (auto const & cis : class_cite_styles_) {
1236 // Only consider the current CiteEngineType
1237 if (!(type & cis.first))
1239 for (auto const & ciss : cis.second) {
1240 bool defined = false;
1241 // Check if the style "name" is already def'ed
1242 for (auto const & av : getCiteStyles(cis.first))
1243 if (av.name == ciss.name)
1246 if (cis.first == ENGINE_TYPE_AUTHORYEAR && apply_ay)
1247 cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(ciss);
1248 else if (cis.first == ENGINE_TYPE_NUMERICAL && apply_num)
1249 cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(ciss);
1250 else if (cis.first == ENGINE_TYPE_DEFAULT && apply_def)
1251 cite_styles_[ENGINE_TYPE_DEFAULT].push_back(ciss);
1255 if (type & ENGINE_TYPE_AUTHORYEAR && apply_ay)
1256 class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
1257 if (type & ENGINE_TYPE_NUMERICAL && apply_num)
1258 class_cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
1259 if (type & ENGINE_TYPE_DEFAULT && apply_def)
1260 class_cite_styles_[ENGINE_TYPE_DEFAULT].clear();
1265 int TextClass::readCiteEngineType(Lexer & lexrc) const
1267 static_assert(ENGINE_TYPE_DEFAULT ==
1268 (ENGINE_TYPE_AUTHORYEAR | ENGINE_TYPE_NUMERICAL),
1269 "Incorrect default engine type");
1270 if (!lexrc.next()) {
1271 lexrc.printError("No cite engine type given for token: `$$Token'.");
1272 return ENGINE_TYPE_DEFAULT;
1274 string const type = rtrim(lexrc.getString());
1275 if (compare_ascii_no_case(type, "authoryear") == 0)
1276 return ENGINE_TYPE_AUTHORYEAR;
1277 else if (compare_ascii_no_case(type, "numerical") == 0)
1278 return ENGINE_TYPE_NUMERICAL;
1279 else if (compare_ascii_no_case(type, "default") != 0) {
1280 string const s = "Unknown cite engine type `" + type
1281 + "' given for token: `$$Token',";
1282 lexrc.printError(s);
1284 return ENGINE_TYPE_DEFAULT;
1288 bool TextClass::readCiteFormat(Lexer & lexrc, ReadType rt)
1290 int const type = readCiteEngineType(lexrc);
1293 // Cite engine definitions do not overwrite existing
1294 // definitions from the class or a module
1295 bool const overwrite = rt != CITE_ENGINE;
1296 while (lexrc.isOK()) {
1298 etype = lexrc.getString();
1299 if (compare_ascii_no_case(etype, "end") == 0)
1304 definition = lexrc.getString();
1305 char initchar = etype[0];
1306 if (initchar == '#')
1308 if (initchar == '!' || initchar == '_' || prefixIs(etype, "B_")) {
1309 bool defined = false;
1310 bool aydefined = false;
1311 bool numdefined = false;
1312 // Check if the macro is already def'ed
1313 for (auto const & cm : cite_macros_) {
1314 if (!(type & cm.first))
1316 if (cm.second.find(etype) != cm.second.end()) {
1317 if (type == cm.first)
1318 // defined as default or specific type
1320 if (cm.first == ENGINE_TYPE_AUTHORYEAR)
1321 // defined for author-year
1323 else if (cm.first == ENGINE_TYPE_NUMERICAL)
1324 // defined for numerical
1328 if (!defined || overwrite) {
1329 if (type & ENGINE_TYPE_AUTHORYEAR && (type != ENGINE_TYPE_DEFAULT || !aydefined))
1330 cite_macros_[ENGINE_TYPE_AUTHORYEAR][etype] = definition;
1331 if (type & ENGINE_TYPE_NUMERICAL && (type != ENGINE_TYPE_DEFAULT || !numdefined))
1332 cite_macros_[ENGINE_TYPE_NUMERICAL][etype] = definition;
1333 if (type == ENGINE_TYPE_DEFAULT)
1334 cite_macros_[ENGINE_TYPE_DEFAULT][etype] = definition;
1337 bool defined = false;
1338 bool aydefined = false;
1339 bool numdefined = false;
1340 // Check if the format is already def'ed
1341 for (auto const & cm : cite_formats_) {
1342 if (!(type & cm.first))
1344 if (cm.second.find(etype) != cm.second.end()) {
1345 if (type == cm.first)
1346 // defined as default or specific type
1348 if (cm.first == ENGINE_TYPE_AUTHORYEAR)
1349 // defined for author-year
1351 else if (cm.first == ENGINE_TYPE_NUMERICAL)
1352 // defined for numerical
1356 if (!defined || overwrite){
1357 if (type & ENGINE_TYPE_AUTHORYEAR && (type != ENGINE_TYPE_DEFAULT || !aydefined))
1358 cite_formats_[ENGINE_TYPE_AUTHORYEAR][etype] = definition;
1359 if (type & ENGINE_TYPE_NUMERICAL && (type != ENGINE_TYPE_DEFAULT || !numdefined))
1360 cite_formats_[ENGINE_TYPE_NUMERICAL][etype] = definition;
1361 if (type == ENGINE_TYPE_DEFAULT)
1362 cite_formats_[ENGINE_TYPE_DEFAULT][etype] = definition;
1370 bool TextClass::readFloat(Lexer & lexrc)
1387 FT_ALLOWED_PLACEMENT,
1393 LexerKeyword floatTags[] = {
1394 { "allowedplacement", FT_ALLOWED_PLACEMENT },
1395 { "allowssideways", FT_ALLOWS_SIDEWAYS },
1396 { "allowswide", FT_ALLOWS_WIDE },
1398 { "extension", FT_EXT },
1399 { "guiname", FT_NAME },
1400 { "htmlattr", FT_HTMLATTR },
1401 { "htmlstyle", FT_HTMLSTYLE },
1402 { "htmltag", FT_HTMLTAG },
1403 { "ispredefined", FT_PREDEFINED },
1404 { "listcommand", FT_LISTCOMMAND },
1405 { "listname", FT_LISTNAME },
1406 { "numberwithin", FT_WITHIN },
1407 { "placement", FT_PLACEMENT },
1408 { "refprefix", FT_REFPREFIX },
1409 { "style", FT_STYLE },
1410 { "type", FT_TYPE },
1411 { "usesfloatpkg", FT_USESFLOAT }
1414 lexrc.pushTable(floatTags);
1418 docstring htmlstyle;
1424 string allowed_placement = "!htbpH";
1429 bool usesfloat = true;
1430 bool ispredefined = false;
1431 bool allowswide = true;
1432 bool allowssideways = true;
1434 bool getout = false;
1435 while (!getout && lexrc.isOK()) {
1436 int le = lexrc.lex();
1438 case Lexer::LEX_UNDEF:
1439 lexrc.printError("Unknown float tag `$$Token'");
1447 type = lexrc.getString();
1448 if (floatlist_.typeExist(type)) {
1449 Floating const & fl = floatlist_.getType(type);
1450 placement = fl.placement();
1452 within = fl.within();
1455 listname = fl.listName();
1456 usesfloat = fl.usesFloatPkg();
1457 ispredefined = fl.isPredefined();
1458 listcommand = fl.listCommand();
1459 refprefix = fl.refPrefix();
1464 name = lexrc.getString();
1468 placement = lexrc.getString();
1470 case FT_ALLOWED_PLACEMENT:
1472 allowed_placement = lexrc.getString();
1476 ext = lexrc.getString();
1480 within = lexrc.getString();
1481 if (within == "none")
1486 style = lexrc.getString();
1488 case FT_LISTCOMMAND:
1490 listcommand = lexrc.getString();
1494 refprefix = lexrc.getString();
1498 listname = lexrc.getString();
1502 usesfloat = lexrc.getBool();
1506 ispredefined = lexrc.getBool();
1508 case FT_ALLOWS_SIDEWAYS:
1510 allowssideways = lexrc.getBool();
1512 case FT_ALLOWS_WIDE:
1514 allowswide = lexrc.getBool();
1518 htmlattr = lexrc.getString();
1522 htmlstyle = lexrc.getLongString(from_ascii("EndHTMLStyle"));
1526 htmltag = lexrc.getString();
1536 // Here we have a full float if getout == true
1538 if (!usesfloat && listcommand.empty()) {
1539 // if this float uses the same auxfile as an existing one,
1540 // there is no need for it to provide a list command.
1541 FloatList::const_iterator it = floatlist_.begin();
1542 FloatList::const_iterator en = floatlist_.end();
1543 bool found_ext = false;
1544 for (; it != en; ++it) {
1545 if (it->second.ext() == ext) {
1551 LYXERR0("The layout does not provide a list command " <<
1552 "for the float `" << type << "'. LyX will " <<
1553 "not be able to produce a float list.");
1555 Floating fl(type, placement, ext, within, style, name,
1556 listname, listcommand, refprefix, allowed_placement,
1557 htmltag, htmlattr, htmlstyle, usesfloat, ispredefined,
1558 allowswide, allowssideways);
1559 floatlist_.newFloat(fl);
1560 // each float has its own counter
1561 counters_.newCounter(from_ascii(type), from_ascii(within),
1562 docstring(), docstring());
1563 // also define sub-float counters
1564 docstring const subtype = "sub-" + from_ascii(type);
1565 counters_.newCounter(subtype, from_ascii(type),
1566 "\\alph{" + subtype + "}", docstring());
1572 bool TextClass::readOutlinerName(Lexer & lexrc)
1577 type = lexrc.getString();
1579 lexrc.printError("No type given for OutlinerName: `$$Token'.");
1583 name = lexrc.getDocString();
1585 lexrc.printError("No name given for OutlinerName: `$$Token'.");
1588 outliner_names_[type] = name;
1593 string const & TextClass::prerequisites(string const & sep) const
1595 if (contains(prerequisites_, ',')) {
1596 vector<string> const pres = getVectorFromString(prerequisites_);
1597 prerequisites_ = getStringFromVector(pres, sep);
1599 return prerequisites_;
1603 bool TextClass::hasLayout(docstring const & n) const
1605 docstring const name = n.empty() ? defaultLayoutName() : n;
1607 return find_if(layoutlist_.begin(), layoutlist_.end(),
1608 LayoutNamesEqual(name))
1609 != layoutlist_.end();
1613 bool TextClass::hasInsetLayout(docstring const & n) const
1617 InsetLayouts::const_iterator it = insetlayoutlist_.find(n);
1618 return it != insetlayoutlist_.end();
1622 Layout const & TextClass::operator[](docstring const & name) const
1624 LATTEST(!name.empty());
1627 find_if(begin(), end(), LayoutNamesEqual(name));
1630 LYXERR0("We failed to find the layout '" << name
1631 << "' in the layout list. You MUST investigate!");
1632 for (const_iterator cit = begin(); cit != end(); ++cit)
1633 lyxerr << " " << to_utf8(cit->name()) << endl;
1635 // We require the name to exist
1636 static const Layout dummy;
1637 LASSERT(false, return dummy);
1644 Layout & TextClass::operator[](docstring const & name)
1646 LATTEST(!name.empty());
1647 // Safe to continue, given what we do below.
1649 iterator it = find_if(begin(), end(), LayoutNamesEqual(name));
1652 LYXERR0("We failed to find the layout '" << to_utf8(name)
1653 << "' in the layout list. You MUST investigate!");
1654 for (const_iterator cit = begin(); cit != end(); ++cit)
1655 LYXERR0(" " << to_utf8(cit->name()));
1657 // we require the name to exist
1659 // we are here only in release mode
1660 layoutlist_.push_back(createBasicLayout(name, true));
1661 it = find_if(begin(), end(), LayoutNamesEqual(name));
1668 bool TextClass::deleteLayout(docstring const & name)
1670 if (name == defaultLayoutName() || name == plainLayoutName())
1673 LayoutList::iterator it =
1674 remove_if(layoutlist_.begin(), layoutlist_.end(),
1675 LayoutNamesEqual(name));
1677 LayoutList::iterator end = layoutlist_.end();
1678 bool const ret = (it != end);
1679 layoutlist_.erase(it, end);
1684 bool TextClass::deleteInsetLayout(docstring const & name)
1686 return insetlayoutlist_.erase(name);
1690 // Load textclass info if not loaded yet
1691 bool TextClass::load(string const & path) const
1696 // Read style-file, provided path is searched before the system ones
1697 // If path is a file, it is loaded directly.
1698 FileName layout_file(path);
1699 if (!path.empty() && !layout_file.isReadableFile())
1700 layout_file = FileName(addName(path, name_ + ".layout"));
1701 if (layout_file.empty() || !layout_file.exists())
1702 layout_file = libFileSearch("layouts", name_, "layout");
1703 loaded_ = const_cast<TextClass*>(this)->read(layout_file);
1706 lyxerr << "Error reading `"
1707 << to_utf8(makeDisplayPath(layout_file.absFileName()))
1708 << "'\n(Check `" << name_
1709 << "')\nCheck your installation and "
1710 "try Options/Reconfigure..."
1718 bool DocumentClass::addLayoutIfNeeded(docstring const & n) const
1723 layoutlist_.push_back(createBasicLayout(n, true));
1728 string DocumentClass::forcedLayouts() const
1732 const_iterator const e = end();
1733 for (const_iterator i = begin(); i != e; ++i) {
1734 if (i->forcelocal > 0) {
1736 os << "Format " << LAYOUT_FORMAT << '\n';
1746 InsetLayout const & DocumentClass::insetLayout(docstring const & name) const
1748 // FIXME The fix for the InsetLayout part of 4812 would be here:
1749 // Add the InsetLayout to the document class if it is not found.
1751 InsetLayouts::const_iterator cen = insetlayoutlist_.end();
1752 while (!n.empty()) {
1753 InsetLayouts::const_iterator cit = insetlayoutlist_.lower_bound(n);
1754 if (cit != cen && cit->first == n) {
1755 if (cit->second.obsoleted_by().empty())
1757 n = cit->second.obsoleted_by();
1758 return insetLayout(n);
1760 // If we have a generic prefix (e.g., "Note:"),
1761 // try if this one alone is found.
1762 size_t i = n.find(':');
1763 if (i == string::npos)
1767 // Layout "name" not found.
1768 return plainInsetLayout();
1772 InsetLayout const & DocumentClass::plainInsetLayout() {
1773 static const InsetLayout plain_insetlayout_;
1774 return plain_insetlayout_;
1778 docstring const & TextClass::defaultLayoutName() const
1780 return defaultlayout_;
1784 Layout const & TextClass::defaultLayout() const
1786 return operator[](defaultLayoutName());
1790 bool TextClass::isDefaultLayout(Layout const & layout) const
1792 return layout.name() == defaultLayoutName();
1796 bool TextClass::isPlainLayout(Layout const & layout) const
1798 return layout.name() == plainLayoutName();
1802 Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
1804 static Layout * defaultLayout = NULL;
1806 if (defaultLayout) {
1807 defaultLayout->setUnknown(unknown);
1808 defaultLayout->setName(name);
1809 return *defaultLayout;
1812 static char const * s = "Margin Static\n"
1813 "LatexType Paragraph\n"
1816 "AlignPossible Left, Right, Center\n"
1817 "LabelType No_Label\n"
1819 istringstream ss(s);
1820 Lexer lex(textClassTags);
1822 defaultLayout = new Layout;
1823 defaultLayout->setUnknown(unknown);
1824 defaultLayout->setName(name);
1825 if (!readStyle(lex, *defaultLayout)) {
1826 // The only way this happens is because the hardcoded layout above
1830 return *defaultLayout;
1834 DocumentClassPtr getDocumentClass(
1835 LayoutFile const & baseClass, LayoutModuleList const & modlist,
1836 string const & cengine, bool const clone)
1838 DocumentClassPtr doc_class =
1839 DocumentClassPtr(new DocumentClass(baseClass));
1840 LayoutModuleList::const_iterator it = modlist.begin();
1841 LayoutModuleList::const_iterator en = modlist.end();
1842 for (; it != en; ++it) {
1843 string const modName = *it;
1844 LyXModule * lm = theModuleList[modName];
1846 docstring const msg =
1847 bformat(_("The module %1$s has been requested by\n"
1848 "this document but has not been found in the list of\n"
1849 "available modules. If you recently installed it, you\n"
1850 "probably need to reconfigure LyX.\n"), from_utf8(modName));
1852 frontend::Alert::warning(_("Module not available"), msg);
1855 if (!lm->isAvailable() && !clone) {
1856 docstring const prereqs = from_utf8(getStringFromVector(lm->prerequisites(), "\n\t"));
1857 docstring const msg =
1858 bformat(_("The module %1$s requires a package that is not\n"
1859 "available in your LaTeX installation, or a converter that\n"
1860 "you have not installed. LaTeX output may not be possible.\n"
1861 "Missing prerequisites:\n"
1863 "See section 3.1.2.3 (Modules) of the User's Guide for more information."),
1864 from_utf8(modName), prereqs);
1865 frontend::Alert::warning(_("Package not available"), msg, true);
1867 FileName layout_file = libFileSearch("layouts", lm->getFilename());
1868 if (!doc_class->read(layout_file, TextClass::MODULE)) {
1869 docstring const msg =
1870 bformat(_("Error reading module %1$s\n"), from_utf8(modName));
1871 frontend::Alert::warning(_("Read Error"), msg);
1875 if (cengine.empty())
1878 LyXCiteEngine * ce = theCiteEnginesList[cengine];
1880 docstring const msg =
1881 bformat(_("The cite engine %1$s has been requested by\n"
1882 "this document but has not been found in the list of\n"
1883 "available engines. If you recently installed it, you\n"
1884 "probably need to reconfigure LyX.\n"), from_utf8(cengine));
1886 frontend::Alert::warning(_("Cite Engine not available"), msg);
1887 } else if (!ce->isAvailable() && !clone) {
1888 docstring const prereqs = from_utf8(getStringFromVector(ce->prerequisites(), "\n\t"));
1889 docstring const msg =
1890 bformat(_("The cite engine %1$s requires a package that is not\n"
1891 "available in your LaTeX installation, or a converter that\n"
1892 "you have not installed. LaTeX output may not be possible.\n"
1893 "Missing prerequisites:\n"
1895 "See section 3.1.2.3 (Modules) of the User's Guide for more information."),
1896 from_utf8(cengine), prereqs);
1897 frontend::Alert::warning(_("Package not available"), msg, true);
1899 FileName layout_file = libFileSearch("citeengines", ce->getFilename());
1900 if (!doc_class->read(layout_file, TextClass::CITE_ENGINE)) {
1901 docstring const msg =
1902 bformat(_("Error reading cite engine %1$s\n"), from_utf8(cengine));
1903 frontend::Alert::warning(_("Read Error"), msg);
1911 /////////////////////////////////////////////////////////////////////////
1915 /////////////////////////////////////////////////////////////////////////
1917 DocumentClass::DocumentClass(LayoutFile const & tc)
1922 bool DocumentClass::hasLaTeXLayout(std::string const & lay) const
1924 LayoutList::const_iterator it = layoutlist_.begin();
1925 LayoutList::const_iterator end = layoutlist_.end();
1926 for (; it != end; ++it)
1927 if (it->latexname() == lay)
1933 bool DocumentClass::provides(string const & p) const
1935 return provides_.find(p) != provides_.end();
1939 bool DocumentClass::hasTocLevels() const
1941 return min_toclevel_ != Layout::NOT_IN_TOC;
1945 Layout const & DocumentClass::getTOCLayout() const
1947 // we're going to look for the layout with the minimum toclevel
1948 TextClass::LayoutList::const_iterator lit = begin();
1949 TextClass::LayoutList::const_iterator const len = end();
1950 int minlevel = 1000;
1951 Layout const * lay = NULL;
1952 for (; lit != len; ++lit) {
1953 int const level = lit->toclevel;
1954 // we don't want Part or unnumbered sections
1955 if (level == Layout::NOT_IN_TOC || level < 0
1956 || level >= minlevel || lit->counter.empty())
1963 // hmm. that is very odd, so we'll do our best.
1964 return operator[](defaultLayoutName());
1968 Layout const & DocumentClass::htmlTOCLayout() const
1970 if (html_toc_section_.empty())
1971 html_toc_section_ = getTOCLayout().name();
1972 return operator[](html_toc_section_);
1976 string const DocumentClass::getCiteFormat(CiteEngineType const & type,
1977 string const & entry, bool const punct, string const & fallback) const
1979 string default_format = "{%fullnames:author%[[%fullnames:author%, ]][[{%fullnames:editor%[[%fullnames:editor%, ed., ]]}]]}"
1980 "\"%title%\"{%journal%[[, {!<i>!}%journal%{!</i>!}]][[{%publisher%[[, %publisher%]]"
1981 "[[{%institution%[[, %institution%]]}]]}]]}{%year%[[ (%year%)]]}{%pages%[[, %pages%]]}";
1983 default_format += ".";
1985 map<CiteEngineType, map<string, string> >::const_iterator itype = cite_formats_.find(type);
1986 if (itype == cite_formats_.end())
1987 return default_format;
1988 map<string, string>::const_iterator it = itype->second.find(entry);
1989 if (it == itype->second.end() && !fallback.empty())
1990 it = itype->second.find(fallback);
1991 if (it == itype->second.end())
1992 return default_format;
1994 return it->second + ".";
1999 string const & DocumentClass::getCiteMacro(CiteEngineType const & type,
2000 string const & macro) const
2002 static string empty;
2003 map<CiteEngineType, map<string, string> >::const_iterator itype = cite_macros_.find(type);
2004 if (itype == cite_macros_.end())
2006 map<string, string>::const_iterator it = itype->second.find(macro);
2007 if (it == itype->second.end())
2013 vector<string> const DocumentClass::citeCommands(
2014 CiteEngineType const & type) const
2016 vector<CitationStyle> const styles = citeStyles(type);
2017 vector<CitationStyle>::const_iterator it = styles.begin();
2018 vector<CitationStyle>::const_iterator end = styles.end();
2019 vector<string> cmds;
2020 for (; it != end; ++it) {
2021 CitationStyle const cite = *it;
2022 cmds.push_back(cite.name);
2028 vector<CitationStyle> const & DocumentClass::citeStyles(
2029 CiteEngineType const & type) const
2031 static vector<CitationStyle> empty;
2032 map<CiteEngineType, vector<CitationStyle> >::const_iterator it = cite_styles_.find(type);
2033 if (it == cite_styles_.end())
2039 /////////////////////////////////////////////////////////////////////////
2043 /////////////////////////////////////////////////////////////////////////
2045 ostream & operator<<(ostream & os, PageSides p)