]> git.lyx.org Git - features.git/commitdiff
Fix wrong setting of bibinset options if \cite{*} was found.
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 2 Jan 2011 18:16:23 +0000 (18:16 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 2 Jan 2011 18:16:23 +0000 (18:16 +0000)
Improve heuristic for outputting \bibliographystyle: Now it is suppressed
if \bibliography follows immediately, since LyX adds it automatically in that
case.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37066 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/Parser.cpp
src/tex2lyx/Parser.h
src/tex2lyx/text.cpp

index 1242b67ff2895b345c8386023ebffbd7e4bf59a7..28e5b724c6ba149abdaf7edf541ab92b259a6a5f 100644 (file)
@@ -276,6 +276,19 @@ void Parser::putback()
 }
 
 
+void Parser::pushPosition()
+{
+       positions_.push_back(pos_);
+}
+
+
+void Parser::popPosition()
+{
+       pos_ = positions_.back();
+       positions_.pop_back();
+}
+
+
 bool Parser::good()
 {
        if (pos_ < tokens_.size())
index 51c063ebf76ffb7e895f157041a9f95163e64707..45d6c67ce8e9c1a4d99f03ba70c1ced94315c97f 100644 (file)
@@ -110,7 +110,9 @@ std::ostream & operator<<(std::ostream & os, Token const & t);
  */
 
 class Parser {
-
+       /// noncopyable
+       Parser(Parser const & p);
+       Parser & operator=(Parser const & p);
 public:
        ///
        Parser(idocstream & is);
@@ -128,6 +130,10 @@ public:
        int lineno() const { return lineno_; }
        ///
        void putback();
+       /// store current position
+       void pushPosition();
+       /// restore previous position
+       void popPosition();
        /// dump contents to screen
        void dump() const;
 
@@ -229,6 +235,8 @@ private:
        ///
        unsigned pos_;
        ///
+       std::vector<unsigned> positions_;
+       ///
        idocstringstream * iss_;
        ///
        idocstream & is_;
index 4543c488abaac5f973b9896f6c207e8303dff37e..341bfd3a7c9549625e9c99c89b1be41cceb710b4 100644 (file)
@@ -2272,7 +2272,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                os << "after " << '"' << after << '"' << "\n";
                                os << "key " << '"' << key << '"' << "\n";
                                end_inset(os);
-                       } else
+                       } else if (t.cs() == "nocite")
                                btprint = key;
                }
 
@@ -2722,9 +2722,30 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                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") {