+ continue;
+ }
+
+ if ((use_biblatex
+ && is_known(t.cs(), known_biblatex_commands)
+ && ((t.cs() == "cite"
+ || t.cs() == "citeauthor"
+ || t.cs() == "Citeauthor"
+ || t.cs() == "parencite"
+ || t.cs() == "citetitle")
+ || p.next_token().asInput() != "*"))
+ || (use_biblatex_natbib
+ && (is_known(t.cs(), known_biblatex_commands)
+ || is_known(t.cs(), known_natbib_commands))
+ && ((t.cs() == "cite" || t.cs() == "citet" || t.cs() == "Citet"
+ || t.cs() == "citep" || t.cs() == "Citep" || t.cs() == "citealt"
+ || t.cs() == "Citealt" || t.cs() == "citealp" || t.cs() == "Citealp"
+ || t.cs() == "citeauthor" || t.cs() == "Citeauthor"
+ || t.cs() == "parencite" || t.cs() == "citetitle")
+ || p.next_token().asInput() != "*"))){
+ context.check_layout(os);
+ string command = t.cs();
+ if (p.next_token().asInput() == "*") {
+ command += '*';
+ p.get_token();
+ }
+
+ bool const qualified = suffixIs(command, "s");
+ if (qualified)
+ command = rtrim(command, "s");
+
+ // text before the citation
+ string before;
+ // text after the citation
+ string after;
+ get_cite_arguments(p, true, before, after, qualified);
+
+ // These use natbib cmd names in LyX
+ // for inter-citeengine compativility
+ if (command == "citeyear")
+ command = "citebyear";
+ else if (command == "cite*")
+ command = "citeyear";
+ else if (command == "textcite")
+ command = "citet";
+ else if (command == "Textcite")
+ command = "Citet";
+ else if (command == "parencite")
+ command = "citep";
+ else if (command == "Parencite")
+ command = "Citep";
+ else if (command == "parencite*")
+ command = "citeyearpar";
+ else if (command == "smartcite")
+ command = "footcite";
+ else if (command == "Smartcite")
+ command = "Footcite";
+
+ string const emptyarg = qualified ? "()" : "[]";
+ if (before.empty() && after == emptyarg)
+ // avoid \cite[]{a}
+ after.erase();
+ else if (before == emptyarg && after == emptyarg) {
+ // avoid \cite[][]{a}
+ before.erase();
+ after.erase();
+ }
+ bool literal = false;
+ pair<bool, string> aft;
+ pair<bool, string> bef;
+ // remove the brackets around after and before
+ if (!after.empty()) {
+ after.erase(0, 1);
+ after.erase(after.length() - 1, 1);
+ aft = convert_latexed_command_inset_arg(after);
+ literal = !aft.first;
+ after = literal ? subst(after, "\n", " ") : aft.second;
+ }
+ if (!before.empty()) {
+ before.erase(0, 1);
+ before.erase(before.length() - 1, 1);
+ bef = convert_latexed_command_inset_arg(before);
+ literal |= !bef.first;
+ before = literal ? subst(before, "\n", " ") : bef.second;
+ }
+ string keys, pretextlist, posttextlist;
+ if (qualified) {
+ map<string, string> pres, posts, preslit, postslit;
+ vector<string> lkeys;
+ // text before the citation
+ string lbefore, lbeforelit;
+ // text after the citation
+ string lafter, lafterlit;
+ string lkey;
+ pair<bool, string> laft, lbef;
+ while (true) {
+ get_cite_arguments(p, true, lbefore, lafter);
+ // remove the brackets around after and before
+ if (!lafter.empty()) {
+ lafter.erase(0, 1);
+ lafter.erase(lafter.length() - 1, 1);
+ laft = convert_latexed_command_inset_arg(lafter);
+ literal |= !laft.first;
+ lafter = laft.second;
+ lafterlit = subst(lbefore, "\n", " ");
+ }
+ if (!lbefore.empty()) {
+ lbefore.erase(0, 1);
+ lbefore.erase(lbefore.length() - 1, 1);
+ lbef = convert_latexed_command_inset_arg(lbefore);
+ literal |= !lbef.first;
+ lbefore = lbef.second;
+ lbeforelit = subst(lbefore, "\n", " ");
+ }
+ if (lbefore.empty() && lafter == "[]") {
+ // avoid \cite[]{a}
+ lafter.erase();
+ lafterlit.erase();
+ }
+ else if (lbefore == "[]" && lafter == "[]") {
+ // avoid \cite[][]{a}
+ lbefore.erase();
+ lafter.erase();
+ lbeforelit.erase();
+ lafterlit.erase();
+ }
+ lkey = p.getArg('{', '}');
+ if (lkey.empty())
+ break;
+ if (!lbefore.empty()) {
+ pres.insert(make_pair(lkey, lbefore));
+ preslit.insert(make_pair(lkey, lbeforelit));
+ }
+ if (!lafter.empty()) {
+ posts.insert(make_pair(lkey, lafter));
+ postslit.insert(make_pair(lkey, lafterlit));
+ }
+ lkeys.push_back(lkey);
+ }
+ keys = convert_literate_command_inset_arg(getStringFromVector(lkeys));
+ if (literal) {
+ pres = preslit;
+ posts = postslit;
+ }
+ for (auto const & ptl : pres) {
+ if (!pretextlist.empty())
+ pretextlist += '\t';
+ pretextlist += ptl.first + " " + ptl.second;
+ }
+ for (auto const & potl : posts) {
+ if (!posttextlist.empty())
+ posttextlist += '\t';
+ posttextlist += potl.first + " " + potl.second;
+ }
+ } else
+ keys = convert_literate_command_inset_arg(p.verbatim_item());
+ if (literal) {
+ if (!after.empty())
+ after = subst(after, "\n", " ");
+ if (!before.empty())
+ before = subst(after, "\n", " ");
+ }
+ string lit = literal ? "\"true\"" : "\"false\"";
+ begin_command_inset(os, "citation", command);
+ os << "after " << '"' << after << '"' << "\n";
+ os << "before " << '"' << before << '"' << "\n";
+ os << "key \""
+ << keys
+ << "\"\n";
+ if (!pretextlist.empty())
+ os << "pretextlist " << '"' << pretextlist << '"' << "\n";
+ if (!posttextlist.empty())
+ os << "posttextlist " << '"' << posttextlist << '"' << "\n";
+ os << "literal " << lit << "\n";
+ end_inset(os);
+ // Need to set the cite engine if biblatex is loaded by
+ // the document class directly
+ if (preamble.citeEngine() == "basic")
+ use_biblatex_natbib ?
+ preamble.citeEngine("biblatex-natbib")
+ : preamble.citeEngine("biblatex");
+ continue;