Author: baum
Date: Sun Oct 30 14:44:00 2011
New Revision: 40092
URL: http://www.lyx.org/trac/changeset/40092

Log:
get rid of the modules_placeholder hack

Modified:
   lyx-devel/trunk/src/tex2lyx/Preamble.cpp
   lyx-devel/trunk/src/tex2lyx/Preamble.h
   lyx-devel/trunk/src/tex2lyx/test/test-structure.tex
   lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp

Modified: lyx-devel/trunk/src/tex2lyx/Preamble.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Preamble.cpp    Sun Oct 30 14:21:06 2011        
(r40091)
+++ lyx-devel/trunk/src/tex2lyx/Preamble.cpp    Sun Oct 30 14:44:00 2011        
(r40092)
@@ -40,8 +40,6 @@
 // special columntypes
 extern map<char, int> special_columns;
 
-const char * const modules_placeholder = "\001modules\001";
-
 Preamble preamble;
 
 namespace {
@@ -288,9 +286,9 @@
 }
 
 
-string Preamble::addModules(string const & lyxpreamble, string const & modules)
+void Preamble::addModule(string const & module)
 {
-       return subst(lyxpreamble, modules_placeholder, modules);
+       used_modules.push_back(module);
 }
 
 
@@ -801,9 +799,16 @@
                os << "\\begin_preamble\n" << h_preamble.str() << 
"\n\\end_preamble\n";
        if (!h_options.empty())
                os << "\\options " << h_options << "\n";
-       os << "\\use_default_options " << h_use_default_options << "\n"
-          << modules_placeholder
-          << "\\language " << h_language << "\n"
+       os << "\\use_default_options " << h_use_default_options << "\n";
+       if (!used_modules.empty()) {
+               os << "\\begin_modules\n";
+               vector<string>::const_iterator const end = used_modules.end();
+               vector<string>::const_iterator it = used_modules.begin();
+               for (; it != end; it++)
+                       os << *it << '\n';
+               os << "\\end_modules\n";
+       }
+       os << "\\language " << h_language << "\n"
           << "\\language_package " << h_language_package << "\n"
           << "\\inputencoding " << h_inputencoding << "\n"
           << "\\fontencoding " << h_fontencoding << "\n"

Modified: lyx-devel/trunk/src/tex2lyx/Preamble.h
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Preamble.h      Sun Oct 30 14:21:06 2011        
(r40091)
+++ lyx-devel/trunk/src/tex2lyx/Preamble.h      Sun Oct 30 14:44:00 2011        
(r40092)
@@ -40,8 +40,7 @@
        std::vector<std::string>
        getPackageOptions(std::string const & package) const;
        ///
-       std::string addModules(std::string const & lyxpreamble,
-                              std::string const & modules);
+       void addModule(std::string const & module);
        ///
        void suppressDate(bool suppress);
 
@@ -55,6 +54,8 @@
 private:
        ///
        std::map<std::string, std::vector<std::string> > used_packages;
+       ///
+       std::vector<std::string> used_modules;
 
        /// needed to handle encodings with babel
        bool one_language;

Modified: lyx-devel/trunk/src/tex2lyx/test/test-structure.tex
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/test/test-structure.tex Sun Oct 30 14:21:06 
2011        (r40091)
+++ lyx-devel/trunk/src/tex2lyx/test/test-structure.tex Sun Oct 30 14:44:00 
2011        (r40092)
@@ -25,10 +25,13 @@
  \addtolength{\leftmargin}{\labelsep}
  \renewcommand{\makelabel}[1]{##1\hfil}}}
 {\end{list}}
+\newcommand{\strong}[1]{\textbf{#1}}
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
 \newenvironment{foo}{==[}{]==}
 
+\usepackage{fixltx2e} % this should cause the fixltx2e module to be loaded
+
 \date{}
 
 \@ifundefined{showcaptionsetup}{}{%
@@ -78,6 +81,8 @@
 
 \section[Hello!]{A section with optional argument}
 
+This causes the \strong{logikalmkup} module to be loaded.
+
 \begin{quote}
 An environment
 \end{quote}

Modified: lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp     Sun Oct 30 14:21:06 2011        
(r40091)
+++ lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp     Sun Oct 30 14:44:00 2011        
(r40092)
@@ -671,18 +671,13 @@
        active_environments.pop_back();
 
        // We know the used modules only after parsing the full text
-       ostringstream ms;
        if (!used_modules.empty()) {
-               ms << "\\begin_modules\n";
                LayoutModuleList::const_iterator const end = used_modules.end();
                LayoutModuleList::const_iterator it = used_modules.begin();
                for (; it != end; it++)
-                       ms << *it << '\n';
-               ms << "\\end_modules\n";
+                       preamble.addModule(*it);
        }
-       ostringstream ps;
-       preamble.writeLyXHeader(ps);
-       os << preamble.addModules(ps.str(), ms.str());
+       preamble.writeLyXHeader(os);
 
        ss.seekg(0);
        os << ss.str();

Reply via email to