Author: baum
Date: Sun Jan  2 19:16:23 2011
New Revision: 37066
URL: http://www.lyx.org/trac/changeset/37066

Log:
Fix wrong setting of bibinset options if \cite{*} was found.
Improve heuristic for outputting \bibliographystyle: Now it is suppressed
if \bibliography follows immediately, since LyX adds it automatically in that
case.

Modified:
   lyx-devel/trunk/src/tex2lyx/Parser.cpp
   lyx-devel/trunk/src/tex2lyx/Parser.h
   lyx-devel/trunk/src/tex2lyx/text.cpp

Modified: lyx-devel/trunk/src/tex2lyx/Parser.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Parser.cpp      Sun Jan  2 17:54:58 2011        
(r37065)
+++ lyx-devel/trunk/src/tex2lyx/Parser.cpp      Sun Jan  2 19:16:23 2011        
(r37066)
@@ -276,6 +276,19 @@
 }
 
 
+void Parser::pushPosition()
+{
+       positions_.push_back(pos_);
+}
+
+
+void Parser::popPosition()
+{
+       pos_ = positions_.back();
+       positions_.pop_back();
+}
+
+
 bool Parser::good()
 {
        if (pos_ < tokens_.size())

Modified: lyx-devel/trunk/src/tex2lyx/Parser.h
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Parser.h        Sun Jan  2 17:54:58 2011        
(r37065)
+++ lyx-devel/trunk/src/tex2lyx/Parser.h        Sun Jan  2 19:16:23 2011        
(r37066)
@@ -110,7 +110,9 @@
  */
 
 class Parser {
-
+       /// noncopyable
+       Parser(Parser const & p);
+       Parser & operator=(Parser const & p);
 public:
        ///
        Parser(idocstream & is);
@@ -128,6 +130,10 @@
        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 @@
        ///
        unsigned pos_;
        ///
+       std::vector<unsigned> positions_;
+       ///
        idocstringstream * iss_;
        ///
        idocstream & is_;

Modified: lyx-devel/trunk/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/text.cpp        Sun Jan  2 17:54:58 2011        
(r37065)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp        Sun Jan  2 19:16:23 2011        
(r37066)
@@ -2272,7 +2272,7 @@
                                os << "after " << '"' << after << '"' << "\n";
                                os << "key " << '"' << key << '"' << "\n";
                                end_inset(os);
-                       } else
+                       } else if (t.cs() == "nocite")
                                btprint = key;
                }
 
@@ -2722,9 +2722,30 @@
                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") {

Reply via email to