From: Georg Baum Date: Fri, 17 Dec 2010 21:02:39 +0000 (+0000) Subject: Increase tex2lyx output format to 288. X-Git-Tag: 2.0.0~1338 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7610b9add51911c77de5667d43a535a6c6ebde9c;p=features.git Increase tex2lyx output format to 288. 278: Nothing to do, tex2lyx writes already an \end_deeper for each \begin_deeper 279-280: Nothing to do, tex2lyx does not produce character styles yet 281-282: Nothing to do (empty lyx2lyx conversion) 283: Nothing to do, tex2lyx does not produce character styles yet 284-286: Nothing to do (empty lyx2lyx conversion) 287: Nothing to do, tex2lyx does not produce wrapped figures yet 288: Use new syntax for command inset This time, the (not format related) bug fix is to parse the starred jurabib and natbib citation commands correctly. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36927 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/test/test-structure.tex b/src/tex2lyx/test/test-structure.tex index 69a49351f7..9cae8ca327 100644 --- a/src/tex2lyx/test/test-structure.tex +++ b/src/tex2lyx/test/test-structure.tex @@ -146,5 +146,18 @@ and bibliography: blub +Test for missing \textbackslash end\_deeper (file format 278). +This must stay at the very end of the document! +\begin{itemize} +\item par1 + +par2 +\begin{enumerate} +\item par1 + +par2 +\end{enumerate} + +\end{itemize} \end{document} diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index f87f767239..af99b51023 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -114,7 +114,7 @@ extern CommandMap known_math_environments; /// extern bool noweb_mode; /// LyX format that is created by tex2lyx -int const LYX_FORMAT = 277; +int const LYX_FORMAT = 288; /// path of the master .tex file extern std::string getMasterFilePath(); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 9784a3ab07..3899601e98 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -95,7 +95,8 @@ char const * const known_ref_commands[] = { "ref", "pageref", "vref", /*! * natbib commands. - * The starred forms are also known. + * The starred forms are also known except for "citefullauthor", + * "citeyear" and "citeyearpar". */ char const * const known_natbib_commands[] = { "cite", "citet", "citep", "citealt", "citealp", "citeauthor", "citeyear", "citeyearpar", @@ -111,7 +112,7 @@ char const * const known_jurabib_commands[] = { "cite", "citet", "citep", // "fullcite", // "footcite", "footcitet", "footcitep", "footcitealt", "footcitealp", // "footciteauthor", "footciteyear", "footciteyearpar", -"citefield", "citetitle", "cite*", 0 }; +"citefield", "citetitle", 0 }; /// LaTeX names for quotes char const * const known_quotes[] = { "dq", "guillemotleft", "flqq", "og", @@ -355,13 +356,13 @@ void begin_inset(ostream & os, string const & name) os << "\n\\begin_inset " << name; } -/*// use this void when format 288 is supported + void begin_command_inset(ostream & os, string const & name, - string const & latexname) + string const & latexname) { - os << "\n\\begin_inset CommandInset " << name; - os << "\nLatexCommand " << latexname << "\n"; -}*/ + begin_inset(os, "CommandInset "); + os << name << "\nLatexCommand " << latexname << '\n'; +} void end_inset(ostream & os) @@ -1502,8 +1503,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "bibitem") { context.set_item(); context.check_layout(os); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "bibitem", "bibitem"); os << "label \"" << p.getOptContent() << "\"\n"; os << "key \"" << p.verbatim_item() << "\"\n"; end_inset(os); @@ -1857,8 +1857,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "tableofcontents") { p.skip_spaces(); context.check_layout(os); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "toc", "tableofcontents"); end_inset(os); skip_braces(p); // swallow this } @@ -1996,8 +1995,7 @@ 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_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "ref", t.cs()); // LyX cannot handle newlines in a latex command // FIXME: Move the substitution into parser::getOpt()? os << subst(p.getOpt(), "\n", " "); @@ -2057,8 +2055,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, // LyX cannot handle newlines in the parameter before = subst(before, "\n", " "); } - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "citation", command); os << "after " << '"' << after << '"' << "\n"; os << "before " << '"' << before << '"' << "\n"; os << "key " << '"' << p.verbatim_item() << '"' << "\n"; @@ -2066,9 +2063,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } else if (use_jurabib && - is_known(t.cs(), known_jurabib_commands)) { + is_known(t.cs(), known_jurabib_commands) && + (t.cs() == "cite" || p.next_token().asInput() != "*")) { context.check_layout(os); - string const command = t.cs(); + string command = t.cs(); + if (p.next_token().asInput() == "*") { + command += '*'; + p.get_token(); + } char argumentOrder = '\0'; vector const & options = used_packages["jurabib"]; if (find(options.begin(), options.end(), @@ -2102,8 +2104,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, before.erase(0, 1); before.erase(before.length() - 1, 1); } - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "citation", command); os << "after " << '"' << after << '"' << "\n"; os << "before " << '"' << before << '"' << "\n"; os << "key " << '"' << citation << '"' << "\n"; @@ -2114,8 +2115,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context.check_layout(os); // LyX cannot handle newlines in a latex command string after = subst(p.getOptContent(), "\n", " "); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "citation", "cite"); os << "after " << '"' << after << '"' << "\n"; os << "key " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; end_inset(os); @@ -2123,8 +2123,7 @@ 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"; + begin_command_inset(os, "index", "index"); // LyX cannot handle newlines in a latex command os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; end_inset(os); @@ -2132,8 +2131,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "nomenclature") { context.check_layout(os); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "nomenclature", "nomenclature"); // LyX cannot handle newlines in a latex command string prefix = subst(p.getOptContent(), "\n", " "); if (!prefix.empty()) @@ -2145,8 +2143,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "label") { context.check_layout(os); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "label", "label"); // LyX cannot handle newlines in a latex command os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; end_inset(os); @@ -2154,24 +2151,21 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "printindex") { context.check_layout(os); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "index_print", "printindex"); end_inset(os); skip_braces(p); } else if (t.cs() == "printnomenclature") { context.check_layout(os); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "nomencl_print", "printnomenclature"); end_inset(os); skip_braces(p); } else if (t.cs() == "url") { context.check_layout(os); - begin_inset(os, "LatexCommand "); - os << t.cs() << "\n"; + begin_command_inset(os, "url", "url"); // LyX cannot handle newlines in a latex command os << "target " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; end_inset(os); @@ -2551,7 +2545,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "bibliography") { context.check_layout(os); - begin_inset(os, "LatexCommand "); + begin_command_inset(os, "bibliography", "bibliography"); os << "bibtex" << "\n"; os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n"; // Do we have a bibliographystyle set?