Author: baum
Date: Sun Oct 30 14:21:06 2011
New Revision: 40091
URL: http://www.lyx.org/trac/changeset/40091
Log:
Fix bug #7844: \date{} in main text is recognized
Modified:
lyx-devel/trunk/src/tex2lyx/Preamble.cpp
lyx-devel/trunk/src/tex2lyx/Preamble.h
lyx-devel/trunk/src/tex2lyx/TODO.txt
lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
lyx-devel/trunk/src/tex2lyx/text.cpp
Modified: lyx-devel/trunk/src/tex2lyx/Preamble.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Preamble.cpp Sun Oct 30 13:47:45 2011
(r40090)
+++ lyx-devel/trunk/src/tex2lyx/Preamble.cpp Sun Oct 30 14:21:06 2011
(r40091)
@@ -294,6 +294,15 @@
}
+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::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::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 @@
ss << tc.sides();
h_papersides = ss.str();
}
- end_preamble(os, tc);
}
Modified: lyx-devel/trunk/src/tex2lyx/Preamble.h
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Preamble.h Sun Oct 30 13:47:45 2011
(r40090)
+++ lyx-devel/trunk/src/tex2lyx/Preamble.h Sun Oct 30 14:21:06 2011
(r40091)
@@ -42,10 +42,15 @@
///
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 @@
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);
};
Modified: lyx-devel/trunk/src/tex2lyx/TODO.txt
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/TODO.txt Sun Oct 30 13:47:45 2011
(r40090)
+++ lyx-devel/trunk/src/tex2lyx/TODO.txt Sun Oct 30 14:21:06 2011
(r40091)
@@ -49,8 +49,6 @@
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
Modified: lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp Sun Oct 30 13:47:45 2011
(r40090)
+++ lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp Sun Oct 30 14:21:06 2011
(r40091)
@@ -657,8 +657,7 @@
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 @@
ms << *it << '\n';
ms << "\\end_modules\n";
}
+ ostringstream ps;
+ preamble.writeLyXHeader(ps);
os << preamble.addModules(ps.str(), ms.str());
ss.seekg(0);
Modified: lyx-devel/trunk/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/text.cpp Sun Oct 30 13:47:45 2011
(r40090)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp Sun Oct 30 14:21:06 2011
(r40091)
@@ -2124,6 +2124,26 @@
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() == "*") &&