}
+void Parser::pushPosition()
+{
+ positions_.push_back(pos_);
+}
+
+
+void Parser::popPosition()
+{
+ pos_ = positions_.back();
+ positions_.pop_back();
+}
+
+
bool Parser::good()
{
if (pos_ < tokens_.size())
*/
class Parser {
-
+ /// noncopyable
+ Parser(Parser const & p);
+ Parser & operator=(Parser const & p);
public:
///
Parser(idocstream & is);
int lineno() const { return lineno_; }
///
void putback();
+ /// store current position
+ void pushPosition();
+ /// restore previous position
+ void popPosition();
/// dump contents to screen
void dump() const;
///
unsigned pos_;
///
+ std::vector<unsigned> positions_;
+ ///
idocstringstream * iss_;
///
idocstream & is_;
os << "after " << '"' << after << '"' << "\n";
os << "key " << '"' << key << '"' << "\n";
end_inset(os);
- } else
+ } else if (t.cs() == "nocite")
btprint = key;
}
else if (t.cs() == "bibliographystyle") {
// store new bibliographystyle
bibliographystyle = p.verbatim_item();
- // output new bibliographystyle.
- // This is only necessary if used in some other macro than \bibliography.
- handle_ert(os, "\\bibliographystyle{" + bibliographystyle + "}", context);
+ // If any other command than \bibliography and
+ // \nocite{*} follows, we need to output the style
+ // (because it might be used by that command).
+ // Otherwise, it will automatically be output by LyX.
+ p.pushPosition();
+ bool output = true;
+ for (Token t2 = p.get_token(); p.good(); t2 = p.get_token()) {
+ if (t2.cat() == catBegin)
+ break;
+ if (t2.cat() != catEscape)
+ continue;
+ if (t2.cs() == "nocite") {
+ if (p.getArg('{', '}') == "*")
+ continue;
+ } else if (t2.cs() == "bibliography")
+ output = false;
+ break;
+ }
+ p.popPosition();
+ if (output) {
+ handle_ert(os,
+ "\\bibliographystyle{" + bibliographystyle + '}',
+ context);
+ }
}
else if (t.cs() == "bibliography") {