]> git.lyx.org Git - features.git/commitdiff
Fix bug #7844: \date{} in main text is recognized
authorGeorg Baum <georg.baum@post.rwth-aachen.de>
Sun, 30 Oct 2011 13:21:06 +0000 (13:21 +0000)
committerGeorg Baum <georg.baum@post.rwth-aachen.de>
Sun, 30 Oct 2011 13:21:06 +0000 (13:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40091 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/Preamble.cpp
src/tex2lyx/Preamble.h
src/tex2lyx/TODO.txt
src/tex2lyx/tex2lyx.cpp
src/tex2lyx/text.cpp

index e381af444d1ce9859bbca5f37e9766d8484298de..afc2b19cd29bad6f5a86c2eb1bb2223a3ca69606 100644 (file)
@@ -294,6 +294,15 @@ string Preamble::addModules(string const & lyxpreamble, string const & modules)
 }
 
 
+void Preamble::suppressDate(bool suppress)
+{
+       if (suppress)
+               h_suppress_date = "true";
+       else
+               h_suppress_date = "false";
+}
+
+
 void Preamble::add_package(string const & name, vector<string> & options)
 {
        // every package inherits the global options
@@ -750,7 +759,7 @@ void Preamble::handle_if(Parser & p, bool in_lyx_preamble)
 }
 
 
-void Preamble::end_preamble(ostream & os, TeX2LyXDocClass const & /*tc*/)
+void Preamble::writeLyXHeader(ostream & os)
 {
        // translate from babel to LyX names
        h_language = babel2lyx(h_language);
@@ -881,8 +890,8 @@ void Preamble::end_preamble(ostream & os, TeX2LyXDocClass const & /*tc*/)
 }
 
 
-void Preamble::parse(Parser & p, ostream & os,
-       string const & forceclass, TeX2LyXDocClass & tc)
+void Preamble::parse(Parser & p, string const & forceclass,
+                     TeX2LyXDocClass & tc)
 {
        // initialize fixed types
        special_columns['D'] = 3;
@@ -1358,7 +1367,6 @@ void Preamble::parse(Parser & p, ostream & os,
                ss << tc.sides();
                h_papersides = ss.str();
        }
-       end_preamble(os, tc);
 }
 
 
index 9aad4ecfc8cd2b77c2f5ad0c448e502e7cd7e1cb..9184a133ca58a2e605e3cd252d43550bd9f3ab94 100644 (file)
@@ -42,10 +42,15 @@ public:
        ///
        std::string addModules(std::string const & lyxpreamble,
                               std::string const & modules);
-
        ///
-       void parse(Parser & p, std::ostream & os,
-                  std::string const & forceclass, TeX2LyXDocClass & tc);
+       void suppressDate(bool suppress);
+
+
+       /// Parses the LaTeX preamble into internal data
+       void parse(Parser & p, std::string const & forceclass,
+                  TeX2LyXDocClass & tc);
+       /// Writes the LyX file header from internal data
+       void writeLyXHeader(std::ostream & os);
 
 private:
        ///
@@ -141,8 +146,6 @@ private:
                            std::string const & opts, bool in_lyx_preamble);
        ///
        void handle_if(Parser & p, bool in_lyx_preamble);
-       ///
-       void end_preamble(std::ostream & os, TeX2LyXDocClass const & tc);
 };
 
 
index a6191cb967bc518e83eadf7e7ee4bc2c64117349..8d62bbe81220d456b31f6a09614e07630c897877 100644 (file)
@@ -49,8 +49,6 @@ Format LaTeX feature                        LyX feature
 367    relative lengths for h and v space   InsetSpace, InsetVSpace
 368    glue lengths                         InsetSpace
 369    author id                            \author
-370    \date{}                              \suppress_date
-                                            (partly supported, see bug #7844)
 371    automatic mhchem loading             \use_mhchem
 375    \includeonly                         \{begin,end}_includeonly
 376    update .aux of unincluded children   \maintain_unincluded_children
index 36856c0f96397f687a8e7cb1c9dcd790fb1f99ce..5f2df53c513e9b804e2a1e55a042b8f154798647 100644 (file)
@@ -657,8 +657,7 @@ void tex2lyx(idocstream & is, ostream & os, string encoding)
        p.setEncoding(encoding);
        //p.dump();
 
-       ostringstream ps;
-       preamble.parse(p, ps, documentclass, textclass);
+       preamble.parse(p, documentclass, textclass);
 
        active_environments.push_back("document");
        Context context(true, textclass);
@@ -681,6 +680,8 @@ void tex2lyx(idocstream & is, ostream & os, string encoding)
                        ms << *it << '\n';
                ms << "\\end_modules\n";
        }
+       ostringstream ps;
+       preamble.writeLyXHeader(ps);
        os << preamble.addModules(ps.str(), ms.str());
 
        ss.seekg(0);
index bd8f3e9f67f0f485a20480cd672be4feaaf7cdd6..61a26202dc3528d95a945119b8db8abbf608f03a 100644 (file)
@@ -2124,6 +2124,26 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        eat_whitespace(p, os, context, true);
                }
 
+               // Must catch empty dates before findLayout is called below
+               else if (t.cs() == "date") {
+                       string const date = p.verbatim_item();
+                       if (date.empty())
+                               preamble.suppressDate(true);
+                       else {
+                               preamble.suppressDate(false);
+                               if (context.new_layout_allowed &&
+                                   (newlayout = findLayout(context.textclass,
+                                                           t.cs(), true))) {
+                                       // write the layout
+                                       output_command_layout(os, p, outer,
+                                                       context, newlayout);
+                                       p.skip_spaces();
+                               } else
+                                       handle_ert(os, "\\date{" + date + '}',
+                                                       context);
+                       }
+               }
+
                // Starred section headings
                // Must attempt to parse "Section*" before "Section".
                else if ((p.next_token().asInput() == "*") &&