]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
Fix typo.
[lyx.git] / src / tex2lyx / text.cpp
index 81605f3efca1a354c1bd8d1fcd93af54c3739ef1..eb88a9695810b32c9809eb5034eeffba54bafc91 100644 (file)
@@ -252,7 +252,7 @@ bool splitLatexLength(string const & len, string & value, string & unit)
 }
 
 
-/// A simple function to translate a latex length to something lyx can
+/// A simple function to translate a latex length to something LyX can
 /// understand. Not perfect, but rather best-effort.
 bool translate_len(string const & length, string & valstring, string & unit)
 {
@@ -354,10 +354,13 @@ void begin_inset(ostream & os, string const & name)
        os << "\n\\begin_inset " << name;
 }
 
-void begin_Cinset(ostream & os, string const & name)
+/*// use this void when format 288 is supported
+void begin_command_inset(ostream & os, string const & name,
+                                                string const & latexname)
 {
        os << "\n\\begin_inset CommandInset " << name;
-}
+       os << "\nLatexCommand " << latexname << "\n";
+}*/
 
 
 void end_inset(ostream & os)
@@ -365,11 +368,6 @@ void end_inset(ostream & os)
        os << "\n\\end_inset\n\n";
 }
 
-void LatexCommand(ostream & os, string const & name)
-{
-       os << "\nLatexCommand " << name << "\n";
-}
-
 
 void skip_braces(Parser & p)
 {
@@ -441,20 +439,6 @@ Layout const * findLayout(TextClass const & textclass, string const & name)
 void eat_whitespace(Parser &, ostream &, Context &, bool);
 
 
-Layout * captionlayout()
-{
-       static Layout * lay = 0;
-       if (!lay) {
-               lay = new Layout;
-               lay->setName(from_ascii("Caption"));
-               lay->setLatexName("caption");
-               lay->latextype = LATEX_COMMAND;
-               lay->optionalargs = 1;
-       }
-       return lay;
-}
-
-
 void output_command_layout(ostream & os, Parser & p, bool outer,
                           Context & parent_context,
                           Layout const * newlayout)
@@ -661,7 +645,7 @@ void parse_box(Parser & p, ostream & os, unsigned flags, bool outer,
                parse_text_in_inset(p, os, flags, outer, parent_context);
                end_inset(os);
 #ifdef PRESERVE_LAYOUT
-               // lyx puts a % after the end of the minipage
+               // LyX puts a % after the end of the minipage
                if (p.next_token().cat() == catNewline && p.next_token().cs().size() > 1) {
                        // new paragraph
                        //handle_comment(os, "%dummy", parent_context);
@@ -1450,7 +1434,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                        if (optarg) {
                                if (context.layout->labeltype != LABEL_MANUAL) {
-                                       // lyx does not support \item[\mybullet]
+                                       // LyX does not support \item[\mybullet]
                                        // in itemize environments
                                        handle_ert(os, "[", context);
                                        os << s;
@@ -1467,10 +1451,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "bibitem") {
                        context.set_item();
                        context.check_layout(os);
-                       begin_Cinset(os, "bibitem");
-                       LatexCommand(os, "bibitem");
-                       os << p.getOpt();
-                       os << "key " << '"' << p.verbatim_item() << '"' << "\n";
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
+                       os << "label \"" << p.getOptContent() << "\"\n";
+                       os << "key \"" << p.verbatim_item() << "\"\n";
                        end_inset(os);
                }
 
@@ -1588,13 +1572,33 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        p.skip_spaces();
                }
 
-               // Special handling for \caption
-               // FIXME: remove this when InsetCaption is supported.
-               else if (context.new_layout_allowed &&
-                        t.cs() == captionlayout()->latexname()) {
-                       output_command_layout(os, p, outer, context, 
-                                             captionlayout());
+               else if (t.cs() == "caption") {
+                       // FIXME: this should get some cleanup. All
+                       // the \begin_layout:s are output by the
+                       // Context class!
+                       p.skip_spaces();
+                       context.check_layout(os);
+                       p.skip_spaces();
+                       begin_inset(os, "Caption\n\n");
+                       os << "\\begin_layout " 
+                          << to_utf8(context.textclass.defaultLayout().name()) 
+                          << '\n';
+                       if (p.next_token().character() == '[') {
+                               p.get_token(); // eat '['
+                               begin_inset(os, "OptArg\n");
+                               os << "status collapsed\n";
+                               parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context);
+                               end_inset(os);
+                               eat_whitespace(p, os, context, false);
+                       }
+                       parse_text(p, os, FLAG_ITEM, outer, context);
+                       context.check_end_layout(os);
+                       // We don't need really a new paragraph, but
+                       // we must make sure that the next item gets a \begin_layout.
+                       context.new_paragraph(os);
+                       end_inset(os);
                        p.skip_spaces();
+                       os << "\\end_layout\n";
                }
 
                else if (t.cs() == "includegraphics") {
@@ -1788,8 +1792,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "tableofcontents") {
                        p.skip_spaces();
                        context.check_layout(os);
-                       begin_Cinset(os, "toc");
-                       LatexCommand(os, "tableofcontents");
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        end_inset(os);
                        skip_braces(p); // swallow this
                }
@@ -1927,9 +1931,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (is_known(t.cs(), known_ref_commands)) {
                        context.check_layout(os);
-                       begin_Cinset(os, "ref");
-                       LatexCommand(os, t.cs());
-                       // lyx cannot handle newlines in a latex command
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
+                       // LyX cannot handle newlines in a latex command
                        // FIXME: Move the substitution into parser::getOpt()?
                        os << subst(p.getOpt(), "\n", " ");
                        os << "reference " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
@@ -1984,8 +1988,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                before.erase(0, 1);
                                before.erase(before.length() - 1, 1);
                        }
-                       begin_Cinset(os, "citation");
-                       LatexCommand(os, command);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        os << "after " << '"' << after << '"' << "\n";
                        os << "before " << '"' << before << '"' << "\n";
                        os << "key " << '"' << p.verbatim_item() << '"' << "\n";
@@ -2029,8 +2033,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                before.erase(0, 1);
                                before.erase(before.length() - 1, 1);
                        }
-                       begin_Cinset(os, "citation");
-                       LatexCommand(os, command);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        os << "after " << '"' << after << '"' << "\n";
                        os << "before " << '"' << before << '"' << "\n";
                        os << "key " << '"' << citation << '"' << "\n";
@@ -2039,14 +2043,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "cite") {
                        context.check_layout(os);
-                       // lyx cannot handle newlines in a latex command
-                       string after = subst(p.getOpt(), "\n", " ");
-                       if (!after.empty()) {
-                               after.erase(0, 1);
-                               after.erase(after.length() - 1, 1);
-                       }
-                       begin_Cinset(os, "citation");
-                       LatexCommand(os, t.cs());
+                       // LyX cannot handle newlines in a latex command
+                       string after = subst(p.getOptContent(), "\n", " ");
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        os << "after " << '"' << after << '"' << "\n";
                        os << "key " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
@@ -2055,25 +2055,46 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "index") {
                        context.check_layout(os);
                        begin_inset(os, "LatexCommand ");
-                       os << t.cs() << "\n";;
-                       // lyx cannot handle newlines in a latex command
+                       os << t.cs() << "\n";
+                       // LyX cannot handle newlines in a latex command
                        os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
                }
+
+               else if (t.cs() == "nomenclature") {
+                       context.check_layout(os);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
+                       // LyX cannot handle newlines in a latex command
+                       string prefix = subst(p.getOptContent(), "\n", " ");
+                       if (!prefix.empty())
+                               os << "prefix " << '"' << prefix << '"' << "\n";
+                       os << "symbol " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
+                       os << "description " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
+                       end_inset(os);
+               }
                
                else if (t.cs() == "label") {
                        context.check_layout(os);
-                       begin_Cinset(os, t.cs());
-                       LatexCommand(os, t.cs());
-                       // lyx cannot handle newlines in a latex command
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
+                       // LyX cannot handle newlines in a latex command
                        os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
                }
 
                else if (t.cs() == "printindex") {
                        context.check_layout(os);
-                       begin_Cinset(os, "index_print");
-                       LatexCommand(os, t.cs());
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
+                       end_inset(os);
+                       skip_braces(p);
+               }
+
+               else if (t.cs() == "printnomenclature") {
+                       context.check_layout(os);
+                       begin_inset(os, "LatexCommand ");
+                       os << t.cs() << "\n";
                        end_inset(os);
                        skip_braces(p);
                }
@@ -2081,8 +2102,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "url") {
                        context.check_layout(os);
                        begin_inset(os, "LatexCommand ");
-                       os << t.cs() << "\n";;
-                       // lyx cannot handle newlines in a latex command
+                       os << t.cs() << "\n";
+                       // LyX cannot handle newlines in a latex command
                        os << "target " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
                        end_inset(os);
                }
@@ -2216,6 +2237,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        string const enc = subst(p.verbatim_item(), "\n", " ");
                        p.setEncoding(enc);
                }
+
                else if (t.cs() == "LyX" || t.cs() == "TeX"
                         || t.cs() == "LaTeX") {
                        context.check_layout(os);
@@ -2349,8 +2371,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                }
 
-               else if (t.cs() == "newline" ||
-                       t.cs() == "linebreak") {
+               else if (t.cs() == "newline") {
                        context.check_layout(os);
                        os << "\n\\" << t.cs() << "\n";
                        skip_braces(p); // eat {}
@@ -2412,8 +2433,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "bibliography") {
                        context.check_layout(os);
-                       begin_Cinset(os, "bibtex");
-                       LatexCommand(os, "bibtex");
+                       begin_inset(os, "LatexCommand ");
+                       os << "bibtex" << "\n";
                        os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n";
                        // Do we have a bibliographystyle set?
                        if (!bibliographystyle.empty())
@@ -2468,7 +2489,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                }
 
                else if (t.cs() == "newpage" ||
-                       t.cs() == "pagebreak" ||
                        t.cs() == "clearpage" ||
                        t.cs() == "cleardoublepage") {
                        context.check_layout(os);