1 /** The .tex to .lyx converter
2 \author André Pönitz (2003)
22 using std::istringstream;
24 using std::ostringstream;
25 using std::stringstream;
30 void handle_comment(Parser & p)
34 Token const & t = p.get_token();
35 if (t.cat() == catNewline)
39 //cerr << "comment: " << s << "\n";
44 string const trim(string const & a, char const * p)
51 string::size_type r = a.find_last_not_of(p);
52 string::size_type l = a.find_first_not_of(p);
54 // Is this the minimal test? (lgb)
55 if (r == string::npos && l == string::npos)
58 return a.substr(l, r - l + 1);
62 void split(string const & s, vector<string> & result, char delim)
64 //cerr << "split 1: '" << s << "'\n";
67 while (getline(is, t, delim))
69 //cerr << "split 2\n";
73 string join(vector<string> const & input, char const * delim)
76 for (size_t i = 0; i < input.size(); ++i) {
85 char const ** is_known(string const & str, char const ** what)
87 for ( ; *what; ++what)
95 // current stack of nested environments
96 vector<string> active_environments;
99 string active_environment()
101 return active_environments.empty() ? string() : active_environments.back();
105 void clean_layouts(istream & is, ostream & os)
110 while (getline(is, line)) {
111 string tline = trim(line, " ");
112 if (line.substr(0, 8) == "\\layout ") {
113 //cerr << "layout: " << line << "\n";
116 } else if (eating && tline.empty()) {
117 //cerr << "eat empty line\n";
118 } else if (line.substr(0, 13) == "\\begin_deeper") {
122 //cerr << "ordinary line\n";
125 os << last << "\n\n";
133 int main(int argc, char * argv[])
136 cerr << "Usage: " << argv[0] << " <infile.tex>" << endl;
140 ifstream is(argv[1]);
145 parse_preamble(p, ss);
146 active_environments.push_back("document");
147 parse_text(p, ss, FLAG_END, true);
148 ss << "\n\\the_end\n";
151 clean_layouts(ss, cout);