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 "CiteEnginesList.h"
22 #include "FloatList.h"
24 #include "LayoutFile.h"
26 #include "ModuleList.h"
28 #include "frontends/alert.h"
30 #include "support/lassert.h"
31 #include "support/debug.h"
32 #include "support/FileName.h"
33 #include "support/filetools.h"
34 #include "support/gettext.h"
35 #include "support/lstrings.h"
36 #include "support/os.h"
37 #include "support/TempFile.h"
48 using namespace lyx::support;
52 // Keep the changes documented in the Customization manual.
54 // If you change this format, then you MUST also make sure that
55 // your changes do not invalidate the hardcoded layout file in
56 // LayoutFile.cpp. Additions will never do so, but syntax changes
57 // could. See LayoutFileList::addEmptyClass() and, especially, the
58 // definition of the layoutpost string.
59 // You should also run the development/tools/updatelayouts.py script,
60 // to update the format of all of our layout files.
62 int const LAYOUT_FORMAT = 104; // rkh: RefFormat for counters
65 // Layout format for the current lyx file format. Controls which format is
66 // targeted by Local Layout > Convert. In master, equal to LAYOUT_FORMAT.
67 int const LYXFILE_LAYOUT_FORMAT = LAYOUT_FORMAT;
72 bool layout2layout(FileName const & filename, FileName const & tempfile,
73 int const format = LAYOUT_FORMAT)
75 FileName const script = libFileSearch("scripts", "layout2layout.py");
77 LYXERR0("Could not find layout conversion "
78 "script layout2layout.py.");
82 ostringstream command;
83 command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
85 << ' ' << quoteName(filename.toFilesystemEncoding())
86 << ' ' << quoteName(tempfile.toFilesystemEncoding());
87 string const command_str = command.str();
89 LYXERR(Debug::TCLASS, "Running `" << command_str << '\'');
91 cmd_ret const ret = runCommand(command_str);
93 if (format == LAYOUT_FORMAT)
94 LYXERR0("Conversion of layout with layout2layout.py has failed.");
101 string translateReadType(TextClass::ReadType rt)
104 case TextClass::BASECLASS:
106 case TextClass::MERGE:
108 case TextClass::MODULE:
109 return "module file";
110 case TextClass::CITE_ENGINE:
111 return "cite engine";
112 case TextClass::VALIDATION:
122 // This string should not be translated here,
123 // because it is a layout identifier.
124 docstring const TextClass::plain_layout_ = from_ascii(N_("Plain Layout"));
127 /////////////////////////////////////////////////////////////////////////
131 /////////////////////////////////////////////////////////////////////////
133 TextClass::TextClass()
134 : loaded_(false), tex_class_avail_(false),
135 opt_enginetype_("authoryear|numerical"), opt_fontsize_("10|11|12"),
136 opt_pagesize_("default|a4|a5|b5|letter|legal|executive"),
137 opt_pagestyle_("empty|plain|headings|fancy"), fontsize_format_("$$spt"), pagesize_("default"),
138 pagesize_format_("$$spaper"), pagestyle_("default"), tablestyle_("default"),
139 docbookroot_("article"), docbookforceabstract_(false),
140 columns_(1), sides_(OneSide), secnumdepth_(3), tocdepth_(3), outputType_(LATEX),
141 outputFormat_("latex"), has_output_format_(false), defaultfont_(sane_font),
142 titletype_(TITLE_COMMAND_AFTER), titlename_("maketitle"),
143 min_toclevel_(0), max_toclevel_(0), maxcitenames_(2),
144 cite_full_author_list_(true), bibintoc_(false) {
148 bool TextClass::readStyle(Lexer & lexrc, Layout & lay, ReadType rt) const
150 LYXERR(Debug::TCLASS, "Reading style " << to_utf8(lay.name()));
151 if (!lay.read(lexrc, *this, rt == VALIDATION)) {
152 LYXERR0("Error parsing style `" << to_utf8(lay.name()) << '\'');
156 lay.resfont = lay.font;
157 lay.resfont.realize(defaultfont_);
158 lay.reslabelfont = lay.labelfont;
159 lay.reslabelfont.realize(defaultfont_);
160 return true; // no errors
174 TC_MODIFYINSETLAYOUT,
175 TC_PROVIDEINSETLAYOUT,
203 TC_ADDTOHTMLPREAMBLE,
221 TC_DOCBOOKFORCEABSTRACT
227 LexerKeyword textClassTags[] = {
228 { "addtociteengine", TC_ADDTOCITEENGINE },
229 { "addtohtmlpreamble", TC_ADDTOHTMLPREAMBLE },
230 { "addtohtmlstyles", TC_ADDTOHTMLSTYLES },
231 { "addtopreamble", TC_ADDTOPREAMBLE },
232 { "bibintoc", TC_BIBINTOC },
233 { "citeengine", TC_CITEENGINE },
234 { "citeenginetype", TC_CITEENGINETYPE },
235 { "citeformat", TC_CITEFORMAT },
236 { "citeframework", TC_CITEFRAMEWORK },
237 { "classoptions", TC_CLASSOPTIONS },
238 { "columns", TC_COLUMNS },
239 { "counter", TC_COUNTER },
240 { "defaultbiblio", TC_DEFAULTBIBLIO },
241 { "defaultfont", TC_DEFAULTFONT },
242 { "defaultmodule", TC_DEFAULTMODULE },
243 { "defaultstyle", TC_DEFAULTSTYLE },
244 { "docbookforceabstract", TC_DOCBOOKFORCEABSTRACT },
245 { "docbookroot", TC_DOCBOOKROOT },
246 { "excludesmodule", TC_EXCLUDESMODULE },
247 { "float", TC_FLOAT },
248 { "format", TC_FORMAT },
249 { "fullauthorlist", TC_FULLAUTHORLIST },
250 { "htmlpreamble", TC_HTMLPREAMBLE },
251 { "htmlstyles", TC_HTMLSTYLES },
252 { "htmltocsection", TC_HTMLTOCSECTION },
253 { "ifcounter", TC_IFCOUNTER },
254 { "input", TC_INPUT },
255 { "inputglobal", TC_INPUT_GLOBAL },
256 { "insetlayout", TC_INSETLAYOUT },
257 { "leftmargin", TC_LEFTMARGIN },
258 { "maxcitenames", TC_MAXCITENAMES },
259 { "modifyinsetlayout", TC_MODIFYINSETLAYOUT },
260 { "modifystyle", TC_MODIFYSTYLE },
261 { "nocounter", TC_NOCOUNTER },
262 { "nofloat", TC_NOFLOAT },
263 { "noinsetlayout", TC_NOINSETLAYOUT },
264 { "nostyle", TC_NOSTYLE },
265 { "outlinername", TC_OUTLINERNAME },
266 { "outputformat", TC_OUTPUTFORMAT },
267 { "outputtype", TC_OUTPUTTYPE },
268 { "packageoptions", TC_PKGOPTS },
269 { "pagesize", TC_PAGESIZE },
270 { "pagestyle", TC_PAGESTYLE },
271 { "preamble", TC_PREAMBLE },
272 { "provideinsetlayout", TC_PROVIDEINSETLAYOUT },
273 { "provides", TC_PROVIDES },
274 { "providesmodule", TC_PROVIDESMODULE },
275 { "providestyle", TC_PROVIDESTYLE },
276 { "requires", TC_REQUIRES },
277 { "rightmargin", TC_RIGHTMARGIN },
278 { "secnumdepth", TC_SECNUMDEPTH },
279 { "sides", TC_SIDES },
280 { "style", TC_STYLE },
281 { "tablestyle", TC_TABLESTYLE },
282 { "titlelatexname", TC_TITLELATEXNAME },
283 { "titlelatextype", TC_TITLELATEXTYPE },
284 { "tocdepth", TC_TOCDEPTH }
290 bool TextClass::convertLayoutFormat(support::FileName const & filename, ReadType rt)
292 LYXERR(Debug::TCLASS, "Converting layout file to " << LAYOUT_FORMAT);
293 TempFile tmp("convertXXXXXX.layout");
294 FileName const tempfile = tmp.name();
295 bool success = layout2layout(filename, tempfile);
297 success = readWithoutConv(tempfile, rt) == OK;
302 std::string TextClass::convert(std::string const & str)
304 TempFile tmp1("localXXXXXX.layout");
305 FileName const fn = tmp1.name();
306 ofstream os(fn.toFilesystemEncoding().c_str());
309 TempFile tmp2("convert_localXXXXXX.layout");
310 FileName const tempfile = tmp2.name();
311 bool success = layout2layout(fn, tempfile, LYXFILE_LAYOUT_FORMAT);
314 ifstream is(tempfile.toFilesystemEncoding().c_str());
326 TextClass::ReturnValues TextClass::readWithoutConv(FileName const & filename, ReadType rt)
328 if (!filename.isReadableFile()) {
329 lyxerr << "Cannot read layout file `" << filename << "'."
334 LYXERR(Debug::TCLASS, "Reading " + translateReadType(rt) + ": " +
335 to_utf8(makeDisplayPath(filename.absFileName())));
337 // Define the plain layout used in table cells, ert, etc. Note that
338 // we do this before loading any layout file, so that classes can
339 // override features of this layout if they should choose to do so.
340 if (rt == BASECLASS && !hasLayout(plain_layout_))
341 layoutlist_.push_back(createBasicLayout(plain_layout_));
343 Lexer lexrc(textClassTags);
344 lexrc.setFile(filename);
345 ReturnValues retval = read(lexrc, rt);
347 LYXERR(Debug::TCLASS, "Finished reading " + translateReadType(rt) + ": " +
348 to_utf8(makeDisplayPath(filename.absFileName())));
354 bool TextClass::read(FileName const & filename, ReadType rt)
356 ReturnValues const retval = readWithoutConv(filename, rt);
357 if (retval != FORMAT_MISMATCH)
360 bool const worx = convertLayoutFormat(filename, rt);
362 LYXERR0 ("Unable to convert " << filename <<
363 " to format " << LAYOUT_FORMAT);
368 TextClass::ReturnValues TextClass::validate(std::string const & str)
371 return tc.read(str, VALIDATION);
375 TextClass::ReturnValues TextClass::read(std::string const & str, ReadType rt)
377 Lexer lexrc(textClassTags);
378 istringstream is(str);
380 ReturnValues retval = read(lexrc, rt);
382 if (retval != FORMAT_MISMATCH)
385 // write the layout string to a temporary file
386 TempFile tmp("TextClass_read");
387 FileName const tempfile = tmp.name();
388 ofstream os(tempfile.toFilesystemEncoding().c_str());
390 LYXERR0("Unable to create temporary file");
396 // now try to convert it to LAYOUT_FORMAT
397 if (!convertLayoutFormat(tempfile, rt)) {
398 LYXERR0("Unable to convert internal layout information to format "
407 // Reads a textclass structure from file.
408 TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
413 // The first usable line should be
414 // Format LAYOUT_FORMAT
415 if (lexrc.lex() != TC_FORMAT || !lexrc.next()
416 || lexrc.getInteger() != LAYOUT_FORMAT)
417 return FORMAT_MISMATCH;
421 while (lexrc.isOK() && !error) {
422 int le = lexrc.lex();
425 case Lexer::LEX_FEOF:
428 case Lexer::LEX_UNDEF:
429 lexrc.printError("Unknown TextClass tag `$$Token'");
437 // used below to track whether we are in an IfStyle or IfCounter tag.
439 bool provide = false;
440 bool ifcounter = false;
441 bool only_global = false;
443 switch (static_cast<TextClassTags>(le)) {
447 lexrc.printError("Duplicate Format directive");
450 case TC_OUTPUTFORMAT:
452 outputFormat_ = lexrc.getString();
453 has_output_format_ = true;
458 readOutputType(lexrc);
459 switch(outputType_) {
461 outputFormat_ = "latex";
464 outputFormat_ = "literate";
469 case TC_INPUT_GLOBAL:
472 case TC_INPUT: // Include file
475 string const inc = lexrc.getString();
476 if (!path().empty() && (prefixIs(inc, "./") ||
477 prefixIs(inc, "../")))
478 tmp = fileSearch(path(), inc, "layout");
480 // InputGlobal only searches in the system and
481 // build directories. This allows to reuse and
482 // modify files in the user directory.
483 tmp = libFileSearch("layouts", inc,
484 "layout", must_exist, only_global);
488 lexrc.printError("Could not find input file: " + inc);
490 } else if (!read(tmp, MERGE)) {
491 lexrc.printError("Error reading input file: " + tmp.absFileName());
497 case TC_DEFAULTSTYLE:
499 docstring const name = from_utf8(subst(lexrc.getString(),
501 defaultlayout_ = name;
508 case TC_PROVIDESTYLE:
509 // if modifystyle is true, then we got here by falling through
510 // so we are not in an ProvideStyle block
516 lexrc.printError("No name given for style: `$$Token'.");
520 docstring const name = from_utf8(subst(lexrc.getString(),
523 string s = "Could not read name for style: `$$Token' "
524 + lexrc.getString() + " is probably not valid UTF-8!";
527 // Since we couldn't read the name, we just scan the rest
528 // of the style and discard it.
529 error = !readStyle(lexrc, lay, rt);
533 bool const have_layout = hasLayout(name);
535 // If the layout already exists, then we want to add it to
536 // the existing layout, as long as we are not in an ProvideStyle
538 if (have_layout && !provide) {
539 Layout & lay = operator[](name);
540 error = !readStyle(lexrc, lay, rt);
542 // If the layout does not exist, then we want to create a new
543 // one, but not if we are in a ModifyStyle block.
544 else if (!have_layout && !modify) {
546 layout.setName(name);
547 error = !readStyle(lexrc, layout, rt);
549 layoutlist_.push_back(layout);
551 if (defaultlayout_.empty()) {
552 // We do not have a default layout yet, so we choose
553 // the first layout we encounter.
554 defaultlayout_ = name;
557 // There are two ways to get here:
558 // (i) The layout exists but we are in an ProvideStyle block
559 // (ii) The layout doesn't exist, but we are in an ModifyStyle
561 // Either way, we just scan the rest and discard it
564 // signal to coverity that we do not care about the result
565 (void)readStyle(lexrc, lay, rt);
572 docstring const style = from_utf8(subst(lexrc.getString(),
574 if (!deleteLayout(style))
575 lyxerr << "Cannot delete style `"
576 << to_utf8(style) << '\'' << endl;
580 case TC_NOINSETLAYOUT:
582 docstring const style = from_utf8(subst(lexrc.getString(),
584 if (!deleteInsetLayout(style))
585 LYXERR0("Style `" << style << "' cannot be removed\n"
586 "because it was not found!");
592 columns_ = lexrc.getInteger();
597 switch (lexrc.getInteger()) {
598 case 1: sides_ = OneSide; break;
599 case 2: sides_ = TwoSides; break;
601 lyxerr << "Impossible number of page"
602 " sides, setting to one."
612 pagesize_ = rtrim(lexrc.getString());
617 pagestyle_ = rtrim(lexrc.getString());
621 defaultfont_ = lyxRead(lexrc);
622 if (!defaultfont_.resolved()) {
623 lexrc.printError("Warning: defaultfont should "
624 "be fully instantiated!");
625 defaultfont_.realize(sane_font);
631 secnumdepth_ = lexrc.getInteger();
636 tocdepth_ = lexrc.getInteger();
639 // First step to support options
640 case TC_CLASSOPTIONS:
641 readClassOptions(lexrc);
645 preamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
648 case TC_HTMLPREAMBLE:
649 htmlpreamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
653 htmlstyles_ = lexrc.getLongString(from_ascii("EndStyles"));
656 case TC_HTMLTOCSECTION:
657 html_toc_section_ = from_utf8(trim(lexrc.getString()));
660 case TC_ADDTOPREAMBLE:
661 preamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
664 case TC_ADDTOHTMLPREAMBLE:
665 htmlpreamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
668 case TC_ADDTOHTMLSTYLES:
669 htmlstyles_ += lexrc.getLongString(from_ascii("EndStyles"));
674 string const feature = lexrc.getString();
676 if (lexrc.getInteger())
677 provides_.insert(feature);
679 provides_.erase(feature);
685 vector<string> const req
686 = getVectorFromString(lexrc.getString());
687 required_.insert(req.begin(), req.end());
693 string const pkg = lexrc.getString();
695 string const options = lexrc.getString();
696 package_options_[pkg] = options;
700 case TC_DEFAULTMODULE: {
702 string const module = lexrc.getString();
703 if (find(default_modules_.begin(), default_modules_.end(), module) == default_modules_.end())
704 default_modules_.push_back(module);
708 case TC_PROVIDESMODULE: {
710 string const module = lexrc.getString();
711 if (find(provided_modules_.begin(), provided_modules_.end(), module) == provided_modules_.end())
712 provided_modules_.push_back(module);
716 case TC_EXCLUDESMODULE: {
718 string const module = lexrc.getString();
719 // modules already have their own way to exclude other modules
721 LYXERR0("ExcludesModule tag cannot be used in a module!");
724 if (find(excluded_modules_.begin(), excluded_modules_.end(), module) == excluded_modules_.end())
725 excluded_modules_.push_back(module);
729 case TC_LEFTMARGIN: // left margin type
731 leftmargin_ = lexrc.getDocString();
734 case TC_RIGHTMARGIN: // right margin type
736 rightmargin_ = lexrc.getDocString();
739 case TC_MODIFYINSETLAYOUT:
742 case TC_PROVIDEINSETLAYOUT:
743 // if modifyinsetlayout is true, then we got here by falling through
744 // so we are not in an ProvideInsetLayout block
748 case TC_INSETLAYOUT: {
750 lexrc.printError("No name given for InsetLayout: `$$Token'.");
754 docstring const name = subst(lexrc.getDocString(), '_', ' ');
755 bool const validating = (rt == VALIDATION);
756 bool const have_layout = name.empty() ? false : hasInsetLayout(name);
758 string s = "Could not read name for InsetLayout: `$$Token' "
759 + lexrc.getString() + " is probably not valid UTF-8!";
762 // Since we couldn't read the name, we just scan the rest
763 // of the style and discard it.
764 il.read(lexrc, *this);
765 // Let's try to continue rather than abort, unless we're validating
766 // in which case we want to report the error
769 } else if (have_layout && !provide) {
770 InsetLayout & il = insetlayoutlist_[name];
771 error = !il.read(lexrc, *this, validating);
772 } else if (!modify && !have_layout) {
775 error = !il.read(lexrc, *this, validating);
777 insetlayoutlist_[name] = il;
780 // We just scan the rest of the style and discard it.
781 il.read(lexrc, *this);
787 error = !readFloat(lexrc);
791 error = !readCiteEngine(lexrc, rt);
794 case TC_ADDTOCITEENGINE:
795 error = !readCiteEngine(lexrc, rt, true);
798 case TC_CITEENGINETYPE:
800 opt_enginetype_ = rtrim(lexrc.getString());
804 error = !readCiteFormat(lexrc, rt);
807 case TC_CITEFRAMEWORK:
809 citeframework_ = rtrim(lexrc.getString());
812 case TC_MAXCITENAMES:
814 maxcitenames_ = size_t(lexrc.getInteger());
817 case TC_DEFAULTBIBLIO:
819 vector<string> const dbs =
820 getVectorFromString(rtrim(lexrc.getString()), "|");
821 for (auto const & dbase : dbs) {
822 if (!contains(dbase, ':')) {
823 vector<string> const enginetypes =
824 getVectorFromString(opt_enginetype_, "|");
825 for (string const & s: enginetypes)
826 cite_default_biblio_style_[s] = dbase;
829 string const db = split(dbase, eng, ':');
830 cite_default_biblio_style_[eng] = db;
838 bibintoc_ = lexrc.getBool();
841 case TC_FULLAUTHORLIST:
843 cite_full_author_list_ &= lexrc.getBool();
848 docstring const cnt = lexrc.getDocString();
849 if (!counters_.remove(cnt))
850 LYXERR0("Unable to remove counter: " + to_utf8(cnt));
859 docstring const name = lexrc.getDocString();
861 string s = "Could not read name for counter: `$$Token' "
862 + lexrc.getString() + " is probably not valid UTF-8!";
863 lexrc.printError(s.c_str());
865 // Since we couldn't read the name, we just scan the rest
869 error = !counters_.read(lexrc, name, !ifcounter);
872 lexrc.printError("No name given for style: `$$Token'.");
877 case TC_TITLELATEXTYPE:
878 readTitleType(lexrc);
881 case TC_TITLELATEXNAME:
883 titlename_ = lexrc.getString();
888 string const nofloat = lexrc.getString();
889 floatlist_.erase(nofloat);
893 case TC_OUTLINERNAME:
894 error = !readOutlinerName(lexrc);
899 tablestyle_ = rtrim(lexrc.getString());
904 docbookroot_ = lexrc.getString();
907 case TC_DOCBOOKFORCEABSTRACT:
909 docbookforceabstract_ = lexrc.getBool();
914 // at present, we abort if we encounter an error,
915 // so there is no point continuing.
922 if (defaultlayout_.empty()) {
923 LYXERR0("Error: Textclass '" << name_
924 << "' is missing a defaultstyle.");
928 // Try to erase "stdinsets" from the provides_ set.
930 // Provides stdinsets 1
931 // declaration simply tells us that the standard insets have been
932 // defined. (It's found in stdinsets.inc but could also be used in
933 // user-defined files.) There isn't really any such package. So we
934 // might as well go ahead and erase it.
935 // If we do not succeed, then it was not there, which means that
936 // the textclass did not provide the definitions of the standard
937 // insets. So we need to try to load them.
938 size_type const erased = provides_.erase("stdinsets");
940 FileName tmp = libFileSearch("layouts", "stdinsets.inc");
943 frontend::Alert::warning(_("Missing File"),
944 _("Could not find stdinsets.inc! This may lead to data loss!"));
946 } else if (!read(tmp, MERGE)) {
947 frontend::Alert::warning(_("Corrupt File"),
948 _("Could not read stdinsets.inc! This may lead to data loss!"));
953 min_toclevel_ = Layout::NOT_IN_TOC;
954 max_toclevel_ = Layout::NOT_IN_TOC;
955 for (auto const & lay : *this) {
956 int const toclevel = lay.toclevel;
957 if (toclevel != Layout::NOT_IN_TOC) {
958 if (min_toclevel_ == Layout::NOT_IN_TOC)
959 min_toclevel_ = toclevel;
961 min_toclevel_ = min(min_toclevel_, toclevel);
962 max_toclevel_ = max(max_toclevel_, toclevel);
965 LYXERR(Debug::TCLASS, "Minimum TocLevel is " << min_toclevel_
966 << ", maximum is " << max_toclevel_);
968 return (error ? ERROR : OK);
972 void TextClass::readTitleType(Lexer & lexrc)
974 LexerKeyword titleTypeTags[] = {
975 { "commandafter", TITLE_COMMAND_AFTER },
976 { "environment", TITLE_ENVIRONMENT }
979 PushPopHelper pph(lexrc, titleTypeTags);
981 int le = lexrc.lex();
983 case Lexer::LEX_UNDEF:
984 lexrc.printError("Unknown output type `$$Token'");
986 case TITLE_COMMAND_AFTER:
987 case TITLE_ENVIRONMENT:
988 titletype_ = static_cast<TitleLatexType>(le);
991 LYXERR0("Unhandled value " << le << " in TextClass::readTitleType.");
997 void TextClass::readOutputType(Lexer & lexrc)
999 LexerKeyword outputTypeTags[] = {
1001 { "literate", LITERATE }
1004 PushPopHelper pph(lexrc, outputTypeTags);
1006 int le = lexrc.lex();
1008 case Lexer::LEX_UNDEF:
1009 lexrc.printError("Unknown output type `$$Token'");
1013 outputType_ = static_cast<OutputType>(le);
1016 LYXERR0("Unhandled value " << le);
1022 void TextClass::readClassOptions(Lexer & lexrc)
1034 LexerKeyword classOptionsTags[] = {
1036 {"fontsize", CO_FONTSIZE },
1037 {"fontsizeformat", CO_FONTSIZE_FORMAT },
1038 {"other", CO_OTHER },
1039 {"pagesize", CO_PAGESIZE },
1040 {"pagesizeformat", CO_PAGESIZE_FORMAT },
1041 {"pagestyle", CO_PAGESTYLE }
1044 lexrc.pushTable(classOptionsTags);
1045 bool getout = false;
1046 while (!getout && lexrc.isOK()) {
1047 int le = lexrc.lex();
1049 case Lexer::LEX_UNDEF:
1050 lexrc.printError("Unknown ClassOption tag `$$Token'");
1058 opt_fontsize_ = rtrim(lexrc.getString());
1060 case CO_FONTSIZE_FORMAT:
1062 fontsize_format_ = rtrim(lexrc.getString());
1066 opt_pagesize_ = rtrim(lexrc.getString());
1068 case CO_PAGESIZE_FORMAT:
1070 pagesize_format_ = rtrim(lexrc.getString());
1074 opt_pagestyle_ = rtrim(lexrc.getString());
1078 if (options_.empty())
1079 options_ = lexrc.getString();
1081 options_ += ',' + lexrc.getString();
1092 vector<CitationStyle> const & TextClass::getCiteStyles(
1093 CiteEngineType const & type) const
1095 static vector<CitationStyle> empty;
1096 map<CiteEngineType, vector<CitationStyle> >::const_iterator it = cite_styles_.find(type);
1097 if (it == cite_styles_.end())
1103 bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
1105 int const type = readCiteEngineType(lexrc);
1106 bool authoryear = (type & ENGINE_TYPE_AUTHORYEAR);
1107 bool numerical = (type & ENGINE_TYPE_NUMERICAL);
1108 bool defce = (type & ENGINE_TYPE_DEFAULT);
1110 if (rt == CITE_ENGINE) {
1111 // The cite engines are not supposed to overwrite
1112 // CiteStyle defined by the class or a module.
1114 authoryear = getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
1116 numerical = getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
1118 defce = getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
1121 if (rt != CITE_ENGINE && !add) {
1122 // Reset if we defined CiteStyle
1123 // from the class or a module
1125 cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
1127 cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
1129 cite_styles_[ENGINE_TYPE_DEFAULT].clear();
1133 bool getout = false;
1134 while (!getout && lexrc.isOK()) {
1136 def = lexrc.getString();
1137 def = subst(def, " ", "");
1138 def = subst(def, "\t", "");
1139 if (compare_ascii_no_case(def, "end") == 0) {
1144 char ichar = def[0];
1147 if (isUpperCase(ichar)) {
1148 cs.forceUpperCase = true;
1149 def[0] = lowercase(ichar);
1152 /** For portability reasons (between different
1153 * cite engines such as natbib and biblatex),
1154 * we distinguish between:
1155 * 1. The LyX name as output in the LyX file
1156 * 2. Possible aliases that might fall back to
1157 * the given LyX name in the current engine
1158 * 3. The actual LaTeX command that is output
1159 * (2) and (3) are optional.
1160 * Also, the GUI string for the starred version can
1163 * LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd
1172 ScanMode mode = LyXName;
1173 ScanMode oldmode = LyXName;
1178 size_t const n = def.size();
1179 for (size_t i = 0; i != n; ++i) {
1183 else if (ichar == '=')
1185 else if (ichar == '<') {
1188 } else if (ichar == '>')
1190 else if (mode == LaTeXCmd)
1192 else if (mode == StarDesc)
1194 else if (ichar == '$')
1195 cs.hasQualifiedList = true;
1196 else if (ichar == '*')
1197 cs.hasStarredVersion = true;
1198 else if (ichar == '[' && cs.textAfter)
1199 cs.textBefore = true;
1200 else if (ichar == '[')
1201 cs.textAfter = true;
1202 else if (ichar != ']') {
1210 cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd;
1211 if (!alias.empty()) {
1212 vector<string> const aliases = getVectorFromString(alias);
1213 for (string const & s: aliases)
1214 cite_command_aliases_[s] = lyx_cmd;
1216 vector<string> const stardescs = getVectorFromString(stardesc, "!");
1217 int size = int(stardesc.size());
1219 cs.stardesc = stardescs[0];
1221 cs.startooltip = stardescs[1];
1224 class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
1226 class_cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
1228 class_cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
1231 cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
1233 cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
1235 cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
1238 // If we do AddToCiteEngine, do not apply yet,
1239 // except if we have already a style to add something to
1240 bool apply_ay = !add;
1241 bool apply_num = !add;
1242 bool apply_def = !add;
1244 if (type & ENGINE_TYPE_AUTHORYEAR)
1245 apply_ay = !getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
1246 if (type & ENGINE_TYPE_NUMERICAL)
1247 apply_num = !getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
1248 if (type & ENGINE_TYPE_DEFAULT)
1249 apply_def = !getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
1252 // Add the styles from AddToCiteEngine to the class' styles
1253 // (but only if they are not yet defined)
1254 for (auto const & cis : class_cite_styles_) {
1255 // Only consider the current CiteEngineType
1256 if (!(type & cis.first))
1258 for (auto const & ciss : cis.second) {
1259 bool defined = false;
1260 // Check if the style "name" is already def'ed
1261 for (auto const & av : getCiteStyles(cis.first))
1262 if (av.name == ciss.name)
1265 if (cis.first == ENGINE_TYPE_AUTHORYEAR && apply_ay)
1266 cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(ciss);
1267 else if (cis.first == ENGINE_TYPE_NUMERICAL && apply_num)
1268 cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(ciss);
1269 else if (cis.first == ENGINE_TYPE_DEFAULT && apply_def)
1270 cite_styles_[ENGINE_TYPE_DEFAULT].push_back(ciss);
1274 if (type & ENGINE_TYPE_AUTHORYEAR && apply_ay)
1275 class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
1276 if (type & ENGINE_TYPE_NUMERICAL && apply_num)
1277 class_cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
1278 if (type & ENGINE_TYPE_DEFAULT && apply_def)
1279 class_cite_styles_[ENGINE_TYPE_DEFAULT].clear();
1284 int TextClass::readCiteEngineType(Lexer & lexrc) const
1286 static_assert(ENGINE_TYPE_DEFAULT ==
1287 (ENGINE_TYPE_AUTHORYEAR | ENGINE_TYPE_NUMERICAL),
1288 "Incorrect default engine type");
1289 if (!lexrc.next()) {
1290 lexrc.printError("No cite engine type given for token: `$$Token'.");
1291 return ENGINE_TYPE_DEFAULT;
1293 string const type = rtrim(lexrc.getString());
1294 if (compare_ascii_no_case(type, "authoryear") == 0)
1295 return ENGINE_TYPE_AUTHORYEAR;
1296 else if (compare_ascii_no_case(type, "numerical") == 0)
1297 return ENGINE_TYPE_NUMERICAL;
1298 else if (compare_ascii_no_case(type, "default") != 0) {
1299 string const s = "Unknown cite engine type `" + type
1300 + "' given for token: `$$Token',";
1301 lexrc.printError(s);
1303 return ENGINE_TYPE_DEFAULT;
1307 bool TextClass::readCiteFormat(Lexer & lexrc, ReadType rt)
1309 int const type = readCiteEngineType(lexrc);
1312 // Cite engine definitions do not overwrite existing
1313 // definitions from the class or a module
1314 bool const overwrite = rt != CITE_ENGINE;
1315 while (lexrc.isOK()) {
1317 etype = lexrc.getString();
1318 if (compare_ascii_no_case(etype, "end") == 0)
1323 definition = lexrc.getString();
1324 char initchar = etype[0];
1325 if (initchar == '#')
1327 if (initchar == '!' || initchar == '_' || prefixIs(etype, "B_")) {
1328 bool defined = false;
1329 bool aydefined = false;
1330 bool numdefined = false;
1331 // Check if the macro is already def'ed
1332 for (auto const & cm : cite_macros_) {
1333 if (!(type & cm.first))
1335 if (cm.second.find(etype) != cm.second.end()) {
1336 if (type == cm.first)
1337 // defined as default or specific type
1339 if (cm.first == ENGINE_TYPE_AUTHORYEAR)
1340 // defined for author-year
1342 else if (cm.first == ENGINE_TYPE_NUMERICAL)
1343 // defined for numerical
1347 if (!defined || overwrite) {
1348 if (type & ENGINE_TYPE_AUTHORYEAR && (type != ENGINE_TYPE_DEFAULT || !aydefined))
1349 cite_macros_[ENGINE_TYPE_AUTHORYEAR][etype] = definition;
1350 if (type & ENGINE_TYPE_NUMERICAL && (type != ENGINE_TYPE_DEFAULT || !numdefined))
1351 cite_macros_[ENGINE_TYPE_NUMERICAL][etype] = definition;
1352 if (type == ENGINE_TYPE_DEFAULT)
1353 cite_macros_[ENGINE_TYPE_DEFAULT][etype] = definition;
1356 bool defined = false;
1357 bool aydefined = false;
1358 bool numdefined = false;
1359 // Check if the format is already def'ed
1360 for (auto const & cm : cite_formats_) {
1361 if (!(type & cm.first))
1363 if (cm.second.find(etype) != cm.second.end()) {
1364 if (type == cm.first)
1365 // defined as default or specific type
1367 if (cm.first == ENGINE_TYPE_AUTHORYEAR)
1368 // defined for author-year
1370 else if (cm.first == ENGINE_TYPE_NUMERICAL)
1371 // defined for numerical
1375 if (!defined || overwrite){
1376 if (type & ENGINE_TYPE_AUTHORYEAR && (type != ENGINE_TYPE_DEFAULT || !aydefined))
1377 cite_formats_[ENGINE_TYPE_AUTHORYEAR][etype] = definition;
1378 if (type & ENGINE_TYPE_NUMERICAL && (type != ENGINE_TYPE_DEFAULT || !numdefined))
1379 cite_formats_[ENGINE_TYPE_NUMERICAL][etype] = definition;
1380 if (type == ENGINE_TYPE_DEFAULT)
1381 cite_formats_[ENGINE_TYPE_DEFAULT][etype] = definition;
1389 bool TextClass::readFloat(Lexer & lexrc)
1405 FT_DOCBOOKFLOATTYPE,
1411 FT_ALLOWED_PLACEMENT,
1419 LexerKeyword floatTags[] = {
1420 { "allowedplacement", FT_ALLOWED_PLACEMENT },
1421 { "allowssideways", FT_ALLOWS_SIDEWAYS },
1422 { "allowswide", FT_ALLOWS_WIDE },
1423 { "docbookattr", FT_DOCBOOKATTR },
1424 { "docbookcaption", FT_DOCBOOKCAPTION },
1425 { "docbookfloattype", FT_DOCBOOKFLOATTYPE },
1426 { "docbooktag", FT_DOCBOOKTAG },
1427 { "docbooktagtype", FT_DOCBOOKTAGTYPE },
1429 { "extension", FT_EXT },
1430 { "guiname", FT_NAME },
1431 { "htmlattr", FT_HTMLATTR },
1432 { "htmlstyle", FT_HTMLSTYLE },
1433 { "htmltag", FT_HTMLTAG },
1434 { "ispredefined", FT_PREDEFINED },
1435 { "listcommand", FT_LISTCOMMAND },
1436 { "listname", FT_LISTNAME },
1437 { "numberwithin", FT_WITHIN },
1438 { "placement", FT_PLACEMENT },
1439 { "prettyformat", FT_PRETTYFORMAT },
1440 { "refprefix", FT_REFPREFIX },
1441 { "requires", FT_REQUIRES },
1442 { "style", FT_STYLE },
1443 { "type", FT_TYPE },
1444 { "usesfloatpkg", FT_USESFLOAT }
1447 lexrc.pushTable(floatTags);
1451 docstring htmlstyle;
1454 string docbookcaption;
1456 string docbooktagtype;
1457 string docbookfloattype;
1462 string allowed_placement = "!htbpH";
1468 docstring prettyformat;
1469 bool usesfloat = true;
1470 bool ispredefined = false;
1471 bool allowswide = true;
1472 bool allowssideways = true;
1474 bool getout = false;
1475 while (!getout && lexrc.isOK()) {
1476 int le = lexrc.lex();
1478 case Lexer::LEX_UNDEF:
1479 lexrc.printError("Unknown float tag `$$Token'");
1487 type = lexrc.getString();
1488 if (floatlist_.typeExist(type)) {
1489 Floating const & fl = floatlist_.getType(type);
1490 placement = fl.placement();
1492 within = fl.within();
1495 listname = fl.listName();
1496 usesfloat = fl.usesFloatPkg();
1497 ispredefined = fl.isPredefined();
1498 listcommand = fl.listCommand();
1499 refprefix = fl.refPrefix();
1504 name = lexrc.getString();
1508 placement = lexrc.getString();
1510 case FT_ALLOWED_PLACEMENT:
1512 allowed_placement = lexrc.getString();
1516 ext = lexrc.getString();
1520 within = lexrc.getString();
1521 if (within == "none")
1526 style = lexrc.getString();
1528 case FT_LISTCOMMAND:
1530 listcommand = lexrc.getString();
1534 refprefix = lexrc.getString();
1538 listname = lexrc.getString();
1542 usesfloat = lexrc.getBool();
1546 required = lexrc.getString();
1550 ispredefined = lexrc.getBool();
1552 case FT_ALLOWS_SIDEWAYS:
1554 allowssideways = lexrc.getBool();
1556 case FT_ALLOWS_WIDE:
1558 allowswide = lexrc.getBool();
1562 htmlattr = lexrc.getString();
1566 htmlstyle = lexrc.getLongString(from_ascii("EndHTMLStyle"));
1570 htmltag = lexrc.getString();
1572 case FT_PRETTYFORMAT:
1574 prettyformat = lexrc.getDocString();
1576 case FT_DOCBOOKATTR:
1578 docbookattr = lexrc.getString();
1580 case FT_DOCBOOKCAPTION:
1582 docbookcaption = lexrc.getString();
1586 docbooktag = lexrc.getString();
1588 case FT_DOCBOOKTAGTYPE:
1590 docbooktagtype = lexrc.getString();
1592 case FT_DOCBOOKFLOATTYPE:
1594 docbookfloattype = lexrc.getString();
1600 LYXERR0("Unhandled value " << le << " in TextClass::readFloat.");
1607 // Here we have a full float if getout == true
1609 if (!usesfloat && listcommand.empty()) {
1610 // if this float uses the same auxfile as an existing one,
1611 // there is no need for it to provide a list command.
1612 bool found_ext = false;
1613 for (auto const & f : floatlist_) {
1614 if (f.second.ext() == ext) {
1620 LYXERR0("The layout does not provide a list command " <<
1621 "for the float `" << type << "'. LyX will " <<
1622 "not be able to produce a float list.");
1624 Floating fl(type, placement, ext, within, style, name,
1625 listname, listcommand, refprefix, allowed_placement,
1626 htmltag, htmlattr, htmlstyle, docbooktag, docbookattr,
1627 docbooktagtype, docbookfloattype, docbookcaption,
1628 required, usesfloat, ispredefined,
1629 allowswide, allowssideways);
1630 floatlist_.newFloat(fl);
1631 // each float has its own counter
1632 counters_.newCounter(from_ascii(type), from_ascii(within),
1633 docstring(), docstring(),
1634 prettyformat.empty() ? bformat(_("%1$s ##"), _(name)) : prettyformat,
1635 bformat(_("%1$s (Float)"), _(name)));
1636 // also define sub-float counters
1637 docstring const subtype = "sub-" + from_ascii(type);
1638 counters_.newCounter(subtype, from_ascii(type),
1639 "\\alph{" + subtype + "}", docstring(),
1640 prettyformat.empty() ? bformat(_("Sub-%1$s ##"), _(name)) : prettyformat,
1641 bformat(_("Sub-%1$s (Float)"), _(name)));
1647 bool TextClass::readOutlinerName(Lexer & lexrc)
1652 type = lexrc.getString();
1654 lexrc.printError("No type given for OutlinerName: `$$Token'.");
1658 name = lexrc.getDocString();
1660 lexrc.printError("No name given for OutlinerName: `$$Token'.");
1663 outliner_names_[type] = name;
1668 string const & TextClass::prerequisites(string const & sep) const
1670 if (contains(prerequisites_, ',')) {
1671 vector<string> const pres = getVectorFromString(prerequisites_);
1672 prerequisites_ = getStringFromVector(pres, sep);
1674 return prerequisites_;
1678 bool TextClass::hasLayout(docstring const & n) const
1680 docstring const name = n.empty() ? defaultLayoutName() : n;
1681 return getLayout(name) != nullptr;
1685 bool TextClass::hasInsetLayout(docstring const & n) const
1689 InsetLayouts::const_iterator it = insetlayoutlist_.find(n);
1690 return it != insetlayoutlist_.end();
1694 Layout const & TextClass::operator[](docstring const & name) const
1696 LATTEST(!name.empty());
1698 Layout const * c = getLayout(name);
1700 LYXERR0("We failed to find the layout '" << name
1701 << "' in the layout list. You MUST investigate!");
1702 for (auto const & lay : *this)
1703 lyxerr << " " << to_utf8(lay.name()) << endl;
1705 // We require the name to exist
1706 static const Layout dummy;
1707 LASSERT(false, return dummy);
1714 Layout & TextClass::operator[](docstring const & name)
1716 LATTEST(!name.empty());
1717 // Safe to continue, given what we do below.
1719 Layout * c = getLayout(name);
1721 LYXERR0("We failed to find the layout '" << to_utf8(name)
1722 << "' in the layout list. You MUST investigate!");
1723 for (auto const & lay : *this)
1724 LYXERR0(" " << to_utf8(lay.name()));
1726 // we require the name to exist
1728 // we are here only in release mode
1729 layoutlist_.push_back(createBasicLayout(name, true));
1730 c = getLayout(name);
1737 bool TextClass::deleteLayout(docstring const & name)
1739 if (name == defaultLayoutName() || name == plainLayoutName())
1742 LayoutList::iterator it =
1743 remove_if(layoutlist_.begin(), layoutlist_.end(),
1744 [name](const Layout &c) { return c.name() == name; });
1746 LayoutList::iterator const end = layoutlist_.end();
1747 bool const ret = (it != end);
1748 layoutlist_.erase(it, end);
1753 bool TextClass::deleteInsetLayout(docstring const & name)
1755 return insetlayoutlist_.erase(name);
1759 // Load textclass info if not loaded yet
1760 bool TextClass::load(string const & path) const
1765 // Read style-file, provided path is searched before the system ones
1766 // If path is a file, it is loaded directly.
1767 FileName layout_file(path);
1768 if (!path.empty() && !layout_file.isReadableFile())
1769 layout_file = FileName(addName(path, name_ + ".layout"));
1770 if (layout_file.empty() || !layout_file.exists())
1771 layout_file = libFileSearch("layouts", name_, "layout");
1772 loaded_ = const_cast<TextClass*>(this)->read(layout_file);
1775 lyxerr << "Error reading `"
1776 << to_utf8(makeDisplayPath(layout_file.absFileName()))
1777 << "'\n(Check `" << name_
1778 << "')\nCheck your installation and "
1779 "try Tools/Reconfigure..."
1787 Layout const * TextClass::getLayout(docstring const & name) const
1789 LayoutList::const_iterator cit =
1790 find_if(begin(), end(),
1791 [name](const Layout &c) { return c.name() == name; });
1792 if (cit == layoutlist_.end())
1799 Layout * TextClass::getLayout(docstring const & name)
1801 LayoutList::iterator it =
1802 find_if(layoutlist_.begin(), layoutlist_.end(),
1803 [name](const Layout &c) { return c.name() == name; });
1804 if (it == layoutlist_.end())
1811 bool DocumentClass::addLayoutIfNeeded(docstring const & n) const
1816 layoutlist_.push_back(createBasicLayout(n, true));
1821 string DocumentClass::forcedLayouts() const
1825 for (auto const & lay : *this) {
1826 if (lay.forcelocal > 0) {
1828 os << "Format " << LAYOUT_FORMAT << '\n';
1838 InsetLayout const & DocumentClass::insetLayout(docstring const & name) const
1840 // FIXME The fix for the InsetLayout part of 4812 would be here:
1841 // Add the InsetLayout to the document class if it is not found.
1843 InsetLayouts::const_iterator cen = insetlayoutlist_.end();
1844 while (!n.empty()) {
1845 InsetLayouts::const_iterator cit = insetlayoutlist_.lower_bound(n);
1846 if (cit != cen && cit->first == n) {
1847 if (cit->second.obsoleted_by().empty())
1849 n = cit->second.obsoleted_by();
1850 return insetLayout(n);
1852 // If we have a generic prefix (e.g., "Note:"),
1853 // try if this one alone is found.
1854 size_t i = n.find(':');
1855 if (i == string::npos)
1859 // Layout "name" not found.
1860 return plainInsetLayout();
1864 InsetLayout const & DocumentClass::plainInsetLayout() {
1865 static const InsetLayout plain_insetlayout_;
1866 return plain_insetlayout_;
1870 docstring const & TextClass::defaultLayoutName() const
1872 return defaultlayout_;
1876 Layout const & TextClass::defaultLayout() const
1878 return operator[](defaultLayoutName());
1882 bool TextClass::isDefaultLayout(Layout const & layout) const
1884 return layout.name() == defaultLayoutName();
1888 bool TextClass::isPlainLayout(Layout const & layout) const
1890 return layout.name() == plainLayoutName();
1894 Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
1896 static Layout * defaultLayout = nullptr;
1898 if (defaultLayout) {
1899 defaultLayout->setUnknown(unknown);
1900 defaultLayout->setName(name);
1901 return *defaultLayout;
1904 static char const * s = "Margin Static\n"
1905 "LatexType Paragraph\n"
1908 "AlignPossible Left, Right, Center\n"
1909 "LabelType No_Label\n"
1911 istringstream ss(s);
1912 Lexer lex(textClassTags);
1914 defaultLayout = new Layout;
1915 defaultLayout->setUnknown(unknown);
1916 defaultLayout->setName(name);
1917 if (!readStyle(lex, *defaultLayout, BASECLASS)) {
1918 // The only way this happens is because the hardcoded layout above
1922 return *defaultLayout;
1926 DocumentClassPtr getDocumentClass(LayoutFile const & baseClass, LayoutModuleList const & modlist,
1927 string const & cengine, bool clone, bool internal)
1929 bool const show_warnings = !clone && !internal;
1930 DocumentClassPtr doc_class =
1931 DocumentClassPtr(new DocumentClass(baseClass));
1932 for (auto const & mod : modlist) {
1933 LyXModule * lm = theModuleList[mod];
1935 if (show_warnings) {
1936 docstring const msg =
1937 bformat(_("The module %1$s has been requested by\n"
1938 "this document but has not been found in the list of\n"
1939 "available modules. If you recently installed it, you\n"
1940 "probably need to reconfigure LyX.\n"), from_utf8(mod));
1941 frontend::Alert::warning(_("Module not available"), msg);
1945 if (!lm->isAvailable() && show_warnings) {
1946 docstring const prereqs = from_utf8(getStringFromVector(lm->prerequisites(), "\n\t"));
1947 docstring const msg =
1948 bformat(_("The module %1$s requires a package that is not\n"
1949 "available in your LaTeX installation, or a converter that\n"
1950 "you have not installed. LaTeX output may not be possible.\n"
1951 "Missing prerequisites:\n"
1953 "See section 3.1.2.3 (Modules) of the User's Guide for more information."),
1954 from_utf8(mod), prereqs);
1955 frontend::Alert::warning(_("Package not available"), msg, true);
1957 FileName layout_file = libFileSearch("layouts", lm->getFilename());
1958 if (!doc_class->read(layout_file, TextClass::MODULE)) {
1959 docstring const msg =
1960 bformat(_("Error reading module %1$s\n"), from_utf8(mod));
1961 frontend::Alert::warning(_("Read Error"), msg);
1965 if (cengine.empty())
1968 LyXCiteEngine * ce = theCiteEnginesList[cengine];
1970 if (show_warnings) {
1971 docstring const msg =
1972 bformat(_("The cite engine %1$s has been requested by\n"
1973 "this document but has not been found in the list of\n"
1974 "available engines. If you recently installed it, you\n"
1975 "probably need to reconfigure LyX.\n"), from_utf8(cengine));
1976 frontend::Alert::warning(_("Cite Engine not available"), msg);
1978 } else if (!ce->isAvailable() && show_warnings) {
1979 docstring const prereqs = from_utf8(getStringFromVector(ce->prerequisites(), "\n\t"));
1980 docstring const msg =
1981 bformat(_("The cite engine %1$s requires a package that is not\n"
1982 "available in your LaTeX installation, or a converter that\n"
1983 "you have not installed. LaTeX output may not be possible.\n"
1984 "Missing prerequisites:\n"
1986 "See section 3.1.2.3 (Modules) of the User's Guide for more information."),
1987 from_utf8(cengine), prereqs);
1988 frontend::Alert::warning(_("Package not available"), msg, true);
1990 FileName layout_file = libFileSearch("citeengines", ce->getFilename());
1991 if (!doc_class->read(layout_file, TextClass::CITE_ENGINE)) {
1992 docstring const msg =
1993 bformat(_("Error reading cite engine %1$s\n"), from_utf8(cengine));
1994 frontend::Alert::warning(_("Read Error"), msg);
2002 /////////////////////////////////////////////////////////////////////////
2006 /////////////////////////////////////////////////////////////////////////
2008 DocumentClass::DocumentClass(LayoutFile const & tc)
2013 bool DocumentClass::hasLaTeXLayout(std::string const & lay) const
2015 for (auto const & l : layoutlist_)
2016 if (l.latexname() == lay)
2022 bool DocumentClass::provides(string const & p) const
2024 return provides_.find(p) != provides_.end();
2028 bool DocumentClass::hasTocLevels() const
2030 return min_toclevel_ != Layout::NOT_IN_TOC;
2034 Layout const & DocumentClass::getTOCLayout() const
2036 // we're going to look for the layout with the minimum toclevel
2037 int minlevel = 1000;
2038 Layout const * lay = nullptr;
2039 for (auto const & l : *this) {
2040 int const level = l.toclevel;
2041 // we don't want Part or unnumbered sections
2042 if (level == Layout::NOT_IN_TOC || level < 0
2043 || level >= minlevel || l.counter.empty())
2050 // hmm. that is very odd, so we'll do our best.
2051 return operator[](defaultLayoutName());
2055 Layout const & DocumentClass::htmlTOCLayout() const
2057 if (html_toc_section_.empty())
2058 html_toc_section_ = getTOCLayout().name();
2059 return operator[](html_toc_section_);
2063 string const DocumentClass::getCiteFormat(CiteEngineType const & type,
2064 string const & entry, bool const punct, string const & fallback) const
2066 string default_format = "{%fullnames:author%[[%fullnames:author%, ]][[{%fullnames:editor%[[%fullnames:editor%, ed., ]]}]]}"
2067 "\"%title%\"{%journal%[[, {!<i>!}%journal%{!</i>!}]][[{%publisher%[[, %publisher%]]"
2068 "[[{%institution%[[, %institution%]]}]]}]]}{%year%[[ (%year%)]]}{%pages%[[, %pages%]]}";
2070 default_format += ".";
2072 map<CiteEngineType, map<string, string> >::const_iterator itype = cite_formats_.find(type);
2073 if (itype == cite_formats_.end())
2074 return default_format;
2075 map<string, string>::const_iterator it = itype->second.find(entry);
2076 if (it == itype->second.end() && !fallback.empty())
2077 it = itype->second.find(fallback);
2078 if (it == itype->second.end())
2079 return default_format;
2081 return it->second + ".";
2086 string const & DocumentClass::getCiteMacro(CiteEngineType const & type,
2087 string const & macro) const
2089 static string empty;
2090 map<CiteEngineType, map<string, string> >::const_iterator itype = cite_macros_.find(type);
2091 if (itype == cite_macros_.end())
2093 map<string, string>::const_iterator it = itype->second.find(macro);
2094 if (it == itype->second.end())
2100 vector<string> const DocumentClass::citeCommands(
2101 CiteEngineType const & type) const
2103 vector<CitationStyle> const styles = citeStyles(type);
2104 vector<string> cmds;
2105 cmds.reserve(styles.size());
2106 for (auto const & cs : styles)
2107 cmds.push_back(cs.name);
2113 vector<CitationStyle> const & DocumentClass::citeStyles(
2114 CiteEngineType const & type) const
2116 static vector<CitationStyle> empty;
2117 map<CiteEngineType, vector<CitationStyle> >::const_iterator it = cite_styles_.find(type);
2118 if (it == cite_styles_.end())
2124 /////////////////////////////////////////////////////////////////////////
2128 /////////////////////////////////////////////////////////////////////////
2130 ostream & operator<<(ostream & os, PageSides p)