1 /** The .tex to .lyx converter
2 \author André Pönitz (2003)
24 using std::istringstream;
26 using std::ostringstream;
27 using std::stringstream;
33 void handle_comment(Parser & p)
37 Token const & t = p.get_token();
38 if (t.cat() == catNewline)
42 //cerr << "comment: " << s << "\n";
47 string const trim(string const & a, char const * p)
54 string::size_type r = a.find_last_not_of(p);
55 string::size_type l = a.find_first_not_of(p);
57 // Is this the minimal test? (lgb)
58 if (r == string::npos && l == string::npos)
61 return a.substr(l, r - l + 1);
65 void split(string const & s, vector<string> & result, char delim)
67 //cerr << "split 1: '" << s << "'\n";
70 while (getline(is, t, delim))
72 //cerr << "split 2\n";
76 string join(vector<string> const & input, char const * delim)
79 for (size_t i = 0; i < input.size(); ++i) {
88 char const ** is_known(string const & str, char const ** what)
90 for ( ; *what; ++what)
98 // current stack of nested environments
99 vector<string> active_environments;
102 string active_environment()
104 return active_environments.empty() ? string() : active_environments.back();
108 void clean_layouts(istream & is, ostream & os)
113 while (getline(is, line)) {
114 string tline = trim(line, " ");
115 if (line.substr(0, 8) == "\\layout ") {
116 //cerr << "layout: " << line << "\n";
119 } else if (eating && tline.empty()) {
120 //cerr << "eat empty line\n";
121 } else if (line.substr(0, 13) == "\\begin_deeper") {
125 //cerr << "ordinary line\n";
128 os << last << "\n\n";
136 int main(int argc, char * argv[])
139 cerr << "Usage: " << argv[0] << " <infile.tex>" << endl;
143 ifstream is(argv[1]);
148 parse_preamble(p, ss);
149 active_environments.push_back("document");
150 parse_text(p, ss, FLAG_END, true);
151 ss << "\n\\the_end\n";
154 clean_layouts(ss, cout);