-/** The .tex to .lyx converter
- \author André Pönitz (2003)
+/**
+ * \file preamble.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
*/
// {[(
#include "tex2lyx.h"
+#include "layout.h"
+#include "lyxtextclass.h"
+#include "lyxlex.h"
+#include "support/filetools.h"
+
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
+#include <map>
-using std::cerr;
-using std::endl;
-using std::getline;
-using std::istream;
using std::istringstream;
using std::ostream;
using std::ostringstream;
using std::string;
using std::vector;
+using lyx::support::LibFileSearch;
+
+// special columntypes
+extern std::map<char, int> special_columns;
namespace {
-void end_preamble(ostream & os)
+void end_preamble(ostream & os, LyXTextClass const & /*textclass*/)
{
- os << "# tex2lyx 0.0.2 created this file\n"
- << "\\lyxformat 222\n"
+ os << "#LyX file created by tex2lyx 0.1.2 \n"
+ << "\\lyxformat 225\n"
<< "\\textclass " << h_textclass << "\n"
<< "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n";
if (h_options.size())
<< "\\papersides " << h_papersides << "\n"
<< "\\paperpagestyle " << h_paperpagestyle << "\n"
<< "\\tracking_changes " << h_tracking_changes << "\n"
- << "\\end_header\n\n\\layout Standard\n";
+ << "\\end_header\n";
}
-
} // anonymous namespace
-void parse_preamble(Parser & p, ostream & os)
+LyXTextClass const parse_preamble(Parser & p, ostream & os)
{
+ // initialize fixed types
+ special_columns['D'] = 3;
+
while (p.good()) {
Token const & t = p.get_token();
h_preamble << "\\def\\" << name << '{' << p.verbatim_item() << "}\n";
}
+ else if (t.cs() == "newcolumntype") {
+ string const name = p.getArg('{', '}');
+ trim(name);
+ int nargs = 0;
+ string opts = p.getOpt();
+ if (opts.size()) {
+ istringstream is(string(opts, 1));
+ //cerr << "opt: " << is.str() << "\n";
+ is >> nargs;
+ }
+ special_columns[name[0]] = nargs;
+ h_preamble << "\\newcolumntype{" << name << "}";
+ if (nargs)
+ h_preamble << "[" << nargs << "]";
+ h_preamble << "{" << p.verbatim_item() << "}\n";
+ }
+
else if (t.cs() == "setcounter") {
string const name = p.getArg('{', '}');
string const content = p.getArg('{', '}');
else if (name == "parindent")
h_paragraph_separation = "skip";
else
- h_preamble << "\\setlength{" + name + "}{" + content + "}\n";
+ h_preamble << "\\setlength{" << name << "}{" << content << "}\n";
}
else if (t.cs() == "par")
else if (t.cs() == "begin") {
string const name = p.getArg('{', '}');
- if (name == "document") {
- end_preamble(os);
- return;
- }
+ if (name == "document")
+ break;
h_preamble << "\\begin{" << name << "}";
}
else if (t.cs().size())
h_preamble << '\\' << t.cs() << ' ';
}
-}
+ LyXTextClass textclass;
+ textclass.Read(LibFileSearch("layouts", h_textclass, "layout"));
+ end_preamble(os, textclass);
+ return textclass;
+}
// }])