From: Georg Baum Date: Sun, 30 Oct 2011 13:21:06 +0000 (+0000) Subject: Fix bug #7844: \date{} in main text is recognized X-Git-Tag: 2.1.0beta1~2425 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c93c44bf64475f67f26634a4d90e18d425a0c80b;p=features.git Fix bug #7844: \date{} in main text is recognized git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40091 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index e381af444d..afc2b19cd2 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -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 & 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); } diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index 9aad4ecfc8..9184a133ca 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -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); }; diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index a6191cb967..8d62bbe812 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -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 diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 36856c0f96..5f2df53c51 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -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); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index bd8f3e9f67..61a26202dc 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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() == "*") &&