]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / tex2lyx / text.C
index 1002b99b4b7014b97bbbc36cbd32b9d56525db9c..71546bc17620ffa2445d56cc017310b9bc2fec20 100644 (file)
 #include "context.h"
 #include "FloatList.h"
 #include "lengthcommon.h"
-#include "support/FileInfo.h"
 #include "support/lstrings.h"
-#include "support/tostr.h"
+#include "support/convert.h"
 #include "support/filetools.h"
 
+#include <boost/filesystem/operations.hpp>
 #include <boost/tuple/tuple.hpp>
 
 #include <iostream>
@@ -29,7 +29,6 @@
 #include <sstream>
 #include <vector>
 
-using lyx::support::FileInfo;
 using lyx::support::MakeAbsPath;
 using lyx::support::rtrim;
 using lyx::support::suffixIs;
@@ -46,6 +45,8 @@ using std::istringstream;
 using std::string;
 using std::vector;
 
+namespace fs = boost::filesystem;
+
 
 /// thin wrapper around parse_text using a string
 string parse_text(Parser & p, unsigned flags, const bool outer,
@@ -196,7 +197,7 @@ map<string, string> split_map(string const & s)
  * The latter can be a real unit like "pt", or a latex length variable
  * like "\textwidth". The unit may contain additional stuff like glue
  * lengths, but we don't care, because such lengths are ERT anyway.
- * \return true if \param value and \param unit are valid.
+ * \returns true if \p value and \p unit are valid.
  */
 bool splitLatexLength(string const & len, string & value, string & unit)
 {
@@ -282,10 +283,10 @@ string translate_len(string const & length)
 
 
 /*!
- * Translates a LaTeX length into \param value, \param unit and
- * \param special parts suitable for a box inset.
+ * Translates a LaTeX length into \p value, \p unit and
+ * \p special parts suitable for a box inset.
  * The difference from translate_len() is that a box inset knows about
- * some special "units" that are stored in \param special.
+ * some special "units" that are stored in \p special.
  */
 void translate_box_len(string const & length, string & value, string & unit, string & special)
 {
@@ -316,7 +317,7 @@ string find_file(string const & name, string const & path,
                // We don't use ChangeExtension() because it does the wrong
                // thing if name contains a dot.
                string const trial = name + '.' + (*what);
-               if (FileInfo(MakeAbsPath(trial, path)).exist())
+               if (fs::exists(MakeAbsPath(trial, path)))
                        return trial;
        }
        return string();
@@ -361,9 +362,10 @@ void handle_ert(ostream & os, string const & s, Context & context, bool check_la
        for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
                if (*it == '\\')
                        os << "\n\\backslash\n";
-               else if (*it == '\n')
-                       os << "\n\\newline\n";
-               else
+               else if (*it == '\n') {
+                       newcontext.new_paragraph(os);
+                       newcontext.check_layout(os);
+               } else
                        os << *it;
        }
        newcontext.check_end_layout(os);
@@ -385,7 +387,8 @@ void handle_comment(ostream & os, string const & s, Context & context)
                        os << *it;
        }
        // make sure that our comment is the last thing on the line
-       os << "\n\\newline";
+       newcontext.new_paragraph(os);
+       newcontext.check_layout(os);
        newcontext.check_end_layout(os);
        end_inset(os);
 }
@@ -444,7 +447,7 @@ void output_command_layout(ostream & os, Parser & p, bool outer,
                        eat_whitespace(p, os, context, false);
                }
        }
-       parse_text_snippet(p, os, FLAG_ITEM, outer, context);
+       parse_text(p, os, FLAG_ITEM, outer, context);
        context.check_end_layout(os);
        if (parent_context.deeper_paragraph) {
                // We must suppress the "end deeper" because we
@@ -664,7 +667,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                if (p.next_token().asInput() == "[") {
                        os << "placement " << p.getArg('[', ']') << '\n';
                }
-               os << "wide " << tostr(is_starred)
+               os << "wide " << convert<string>(is_starred)
                   << "\nsideways false"
                   << "\nstatus open\n\n";
                parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
@@ -686,11 +689,11 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                        parent_context.new_paragraph(os);
                }
                if (name == "flushleft" || name == "raggedright")
-                       parent_context.add_extra_stuff("\\align left ");
+                       parent_context.add_extra_stuff("\\align left\n");
                else if (name == "flushright" || name == "raggedleft")
-                       parent_context.add_extra_stuff("\\align right ");
+                       parent_context.add_extra_stuff("\\align right\n");
                else
-                       parent_context.add_extra_stuff("\\align center ");
+                       parent_context.add_extra_stuff("\\align center\n");
                parse_text(p, os, FLAG_END, outer, parent_context);
                // Just in case the environment is empty ..
                parent_context.extra_stuff.erase();
@@ -994,37 +997,48 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                ; // ignore it in {}`` or -{}-
                        else if (s == "[" || s == "]" || s == "*")
                                os << s;
-                       else if (is_known(next.cs(), known_sizes))
+                       else if (is_known(next.cs(), known_sizes)) {
                                // s will change the size, so we must reset
                                // it here
-                               os << s << "\n\\size " << context.font.size
-                                  << "\n";
-                       else if (is_known(next.cs(), known_font_families))
+                               os << s;
+                               if (!context.atParagraphStart())
+                                       os << "\n\\size "
+                                          << context.font.size << "\n";
+                       } else if (is_known(next.cs(), known_font_families)) {
                                // s will change the font family, so we must
                                // reset it here
-                               os << s << "\n\\family "
-                                  << context.font.family << "\n";
-                       else if (is_known(next.cs(), known_font_series))
+                               os << s;
+                               if (!context.atParagraphStart())
+                                       os << "\n\\family "
+                                          << context.font.family << "\n";
+                       } else if (is_known(next.cs(), known_font_series)) {
                                // s will change the font series, so we must
                                // reset it here
-                               os << s << "\n\\series "
-                                  << context.font.series << "\n";
-                       else if (is_known(next.cs(), known_font_shapes))
+                               os << s;
+                               if (!context.atParagraphStart())
+                                       os << "\n\\series "
+                                          << context.font.series << "\n";
+                       } else if (is_known(next.cs(), known_font_shapes)) {
                                // s will change the font shape, so we must
                                // reset it here
-                               os << s << "\n\\shape "
-                                  << context.font.shape << "\n";
-                       else if (is_known(next.cs(), known_old_font_families) ||
-                                is_known(next.cs(), known_old_font_series) ||
-                                is_known(next.cs(), known_old_font_shapes))
+                               os << s;
+                               if (!context.atParagraphStart())
+                                       os << "\n\\shape "
+                                          << context.font.shape << "\n";
+                       } else if (is_known(next.cs(), known_old_font_families) ||
+                                  is_known(next.cs(), known_old_font_series) ||
+                                  is_known(next.cs(), known_old_font_shapes)) {
                                // s will change the font family, series
                                // and shape, so we must reset it here
-                               os << s
-                                  <<  "\n\\family " << context.font.family
-                                  << "\n\\series " << context.font.series
-                                  << "\n\\shape "  << context.font.shape
-                                  << "\n";
-                       else {
+                               os << s;
+                               if (!context.atParagraphStart())
+                                       os <<  "\n\\family "
+                                          << context.font.family
+                                          << "\n\\series "
+                                          << context.font.series
+                                          << "\n\\shape "
+                                          << context.font.shape << "\n";
+                       } else {
                                handle_ert(os, "{", context, false);
                                // s will end the current layout and begin a
                                // new one if necessary
@@ -1129,12 +1143,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "noindent") {
                        p.skip_spaces();
-                       context.add_extra_stuff("\\noindent ");
+                       context.add_extra_stuff("\\noindent\n");
                }
 
                else if (t.cs() == "appendix") {
                        p.skip_spaces();
-                       context.add_extra_stuff("\\start_of_appendix ");
+                       context.add_extra_stuff("\\start_of_appendix\n");
                }
 
                // Must attempt to parse "Section*" before "Section".
@@ -1156,13 +1170,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                }
 
                else if (t.cs() == "includegraphics") {
+                       bool const clip = p.next_token().asInput() == "*";
+                       if (clip)
+                               p.get_token();
                        map<string, string> opts = split_map(p.getArg('[', ']'));
+                       if (clip)
+                               opts["clip"] = string();
                        string name = subst(p.verbatim_item(), "\\lyxdot ", ".");
 
                        string const path = getMasterFilePath();
                        // We want to preserve relative / absolute filenames,
                        // therefore path is only used for testing
-                       if (!FileInfo(MakeAbsPath(name, path)).exist()) {
+                       if (!fs::exists(MakeAbsPath(name, path))) {
                                // The file extension is probably missing.
                                // Now try to find it out.
                                string const dvips_name =
@@ -1191,7 +1210,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                } else if (!pdftex_name.empty())
                                        name = pdftex_name;
 
-                               if (!FileInfo(MakeAbsPath(name, path)).exist())
+                               if (!fs::exists(MakeAbsPath(name, path)))
                                        cerr << "Warning: Could not find graphics file '"
                                             << name << "'." << endl;
                        }
@@ -1291,7 +1310,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        end_inset(os);
                }
 
-               else if (t.cs() == "footnote") {
+               else if (t.cs() == "footnote" ||
+                        (t.cs() == "thanks" && context.layout->intitle)) {
                        p.skip_spaces();
                        context.check_layout(os);
                        begin_inset(os, "Foot\n");
@@ -1330,6 +1350,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                }
 
                else if (t.cs() == "makeindex" || t.cs() == "maketitle") {
+                       // FIXME: Somehow prevent title layouts if
+                       // "maketitle" was not found
                        p.skip_spaces();
                        skip_braces(p); // swallow this
                }
@@ -1454,8 +1476,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (use_natbib &&
                         is_known(t.cs(), known_natbib_commands) &&
                         ((t.cs() != "citefullauthor" &&
-                          t.cs() != "citeyear" &&
-                          t.cs() != "citeyearpar") ||
+                          t.cs() != "citeyear" &&
+                          t.cs() != "citeyearpar") ||
                          p.next_token().asInput() != "*")) {
                        context.check_layout(os);
                        // tex                       lyx
@@ -1524,12 +1546,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        string const citation = p.verbatim_item();
                        if (!before.empty() && argumentOrder == '\0') {
                                cerr << "Warning: Assuming argument order "
-                                    << "of jurabib version 0.6 for\n'"
+                                       "of jurabib version 0.6 for\n'"
                                     << command << before << after << '{'
                                     << citation << "}'.\n"
-                                    << "Add 'jurabiborder' to the jurabib "
-                                    << "package options if you used an\n"
-                                    << "earlier jurabib version." << endl;
+                                       "Add 'jurabiborder' to the jurabib "
+                                       "package options if you used an\n"
+                                       "earlier jurabib version." << endl;
                        }
                        begin_inset(os, "LatexCommand ");
                        os << command << after << before