+vector<CitationStyle> const & TextClass::getCiteStyles(
+ CiteEngineType const & type) const
+{
+ static vector<CitationStyle> empty;
+ map<CiteEngineType, vector<CitationStyle> >::const_iterator it = cite_styles_.find(type);
+ if (it == cite_styles_.end())
+ return empty;
+ return it->second;
+}
+
+
+bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
+{
+ int const type = readCiteEngineType(lexrc);
+ bool authoryear = (type & ENGINE_TYPE_AUTHORYEAR);
+ bool numerical = (type & ENGINE_TYPE_NUMERICAL);
+ bool defce = (type & ENGINE_TYPE_DEFAULT);
+
+ if (rt == CITE_ENGINE) {
+ // The cite engines are not supposed to overwrite
+ // CiteStyle defined by the class or a module.
+ if (authoryear)
+ authoryear = getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
+ if (numerical)
+ numerical = getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
+ if (defce)
+ defce = getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
+ }
+
+ if (rt != CITE_ENGINE && !add) {
+ // Reset if we defined CiteStyle
+ // from the class or a module
+ if (authoryear)
+ cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
+ if (numerical)
+ cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
+ if (defce)
+ cite_styles_[ENGINE_TYPE_DEFAULT].clear();
+ }
+
+ string def;
+ bool getout = false;
+ while (!getout && lexrc.isOK()) {
+ lexrc.eatLine();
+ def = lexrc.getString();
+ def = subst(def, " ", "");
+ def = subst(def, "\t", "");
+ if (compare_ascii_no_case(def, "end") == 0) {
+ getout = true;
+ continue;
+ }
+ CitationStyle cs;
+ char ichar = def[0];
+ if (ichar == '#')
+ continue;
+ if (isUpperCase(ichar)) {
+ cs.forceUpperCase = true;
+ def[0] = lowercase(ichar);
+ }
+
+ /** For portability reasons (between different
+ * cite engines such as natbib and biblatex),
+ * we distinguish between:
+ * 1. The LyX name as output in the LyX file
+ * 2. Possible aliases that might fall back to
+ * the given LyX name in the current engine
+ * 3. The actual LaTeX command that is output
+ * (2) and (3) are optional.
+ * Also, the GUI string for the starred version can
+ * be changed
+ * The syntax is:
+ * LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd
+ */
+ enum ScanMode {
+ LyXName,
+ Alias,
+ LaTeXCmd,
+ StarDesc
+ };
+
+ ScanMode mode = LyXName;
+ ScanMode oldmode = LyXName;
+ string lyx_cmd;
+ string alias;
+ string latex_cmd;
+ string stardesc;
+ size_t const n = def.size();
+ for (size_t i = 0; i != n; ++i) {
+ ichar = def[i];
+ if (ichar == '|')
+ mode = Alias;
+ else if (ichar == '=')
+ mode = LaTeXCmd;
+ else if (ichar == '<') {
+ oldmode = mode;
+ mode = StarDesc;
+ } else if (ichar == '>')
+ mode = oldmode;
+ else if (mode == LaTeXCmd)
+ latex_cmd += ichar;
+ else if (mode == StarDesc)
+ stardesc += ichar;
+ else if (ichar == '$')
+ cs.hasQualifiedList = true;
+ else if (ichar == '*')
+ cs.hasStarredVersion = true;
+ else if (ichar == '[' && cs.textAfter)
+ cs.textBefore = true;
+ else if (ichar == '[')
+ cs.textAfter = true;
+ else if (ichar != ']') {
+ if (mode == Alias)
+ alias += ichar;
+ else
+ lyx_cmd += ichar;
+ }
+ }
+ cs.name = lyx_cmd;
+ cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd;
+ if (!alias.empty()) {
+ vector<string> const aliases = getVectorFromString(alias);
+ for (string const & s: aliases)
+ cite_command_aliases_[s] = lyx_cmd;
+ }
+ vector<string> const stardescs = getVectorFromString(stardesc, "!");
+ int size = int(stardesc.size());
+ if (size > 0)
+ cs.stardesc = stardescs[0];
+ if (size > 1)
+ cs.startooltip = stardescs[1];
+ if (add) {
+ if (authoryear)
+ class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
+ if (numerical)
+ class_cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
+ if (defce)
+ class_cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
+ } else {
+ if (authoryear)
+ cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
+ if (numerical)
+ cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
+ if (defce)
+ cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
+ }
+ }
+ // If we do AddToCiteEngine, do not apply yet,
+ // except if we have already a style to add something to
+ bool apply_ay = !add;
+ bool apply_num = !add;
+ bool apply_def = !add;
+ if (add) {
+ if (type & ENGINE_TYPE_AUTHORYEAR)
+ apply_ay = !getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
+ if (type & ENGINE_TYPE_NUMERICAL)
+ apply_num = !getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
+ if (type & ENGINE_TYPE_DEFAULT)
+ apply_def = !getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
+ }
+
+ // Add the styles from AddToCiteEngine to the class' styles
+ // (but only if they are not yet defined)
+ for (auto const & cis : class_cite_styles_) {
+ // Only consider the current CiteEngineType
+ if (!(type & cis.first))
+ continue;
+ for (auto const & ciss : cis.second) {
+ bool defined = false;
+ // Check if the style "name" is already def'ed
+ for (auto const & av : getCiteStyles(cis.first))
+ if (av.name == ciss.name)
+ defined = true;
+ if (!defined) {
+ if (cis.first == ENGINE_TYPE_AUTHORYEAR && apply_ay)
+ cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(ciss);
+ else if (cis.first == ENGINE_TYPE_NUMERICAL && apply_num)
+ cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(ciss);
+ else if (cis.first == ENGINE_TYPE_DEFAULT && apply_def)
+ cite_styles_[ENGINE_TYPE_DEFAULT].push_back(ciss);
+ }
+ }
+ }
+ if (type & ENGINE_TYPE_AUTHORYEAR && apply_ay)
+ class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
+ if (type & ENGINE_TYPE_NUMERICAL && apply_num)
+ class_cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
+ if (type & ENGINE_TYPE_DEFAULT && apply_def)
+ class_cite_styles_[ENGINE_TYPE_DEFAULT].clear();
+ return getout;
+}
+
+
+int TextClass::readCiteEngineType(Lexer & lexrc) const
+{
+ static_assert(ENGINE_TYPE_DEFAULT ==
+ (ENGINE_TYPE_AUTHORYEAR | ENGINE_TYPE_NUMERICAL),
+ "Incorrect default engine type");
+ if (!lexrc.next()) {
+ lexrc.printError("No cite engine type given for token: `$$Token'.");
+ return ENGINE_TYPE_DEFAULT;
+ }
+ string const type = rtrim(lexrc.getString());
+ if (compare_ascii_no_case(type, "authoryear") == 0)
+ return ENGINE_TYPE_AUTHORYEAR;
+ else if (compare_ascii_no_case(type, "numerical") == 0)
+ return ENGINE_TYPE_NUMERICAL;
+ else if (compare_ascii_no_case(type, "default") != 0) {
+ string const s = "Unknown cite engine type `" + type
+ + "' given for token: `$$Token',";
+ lexrc.printError(s);
+ }
+ return ENGINE_TYPE_DEFAULT;
+}
+
+
+bool TextClass::readCiteFormat(Lexer & lexrc, ReadType rt)