mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 05:12:40 +00:00
tex2lyx/text.cpp: tex2lyx supports now fileformat 252
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30059 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
be48e7f9e5
commit
f8d655d4e2
@ -90,14 +90,11 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char const * const known_latex_commands[] = { "ref", "cite", "label",
|
char const * const known_ref_commands[] = { "ref", "pageref", "vref",
|
||||||
"index", "printindex", "pageref", "url", "vref", "vpageref", "prettyref",
|
"vpageref", "prettyref", "eqref", 0 };
|
||||||
"eqref", 0 };
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* natbib commands.
|
* natbib commands.
|
||||||
* We can't put these into known_latex_commands because the argument order
|
|
||||||
* is reversed in lyx if there are 2 arguments.
|
|
||||||
* The starred forms are also known.
|
* The starred forms are also known.
|
||||||
*/
|
*/
|
||||||
char const * const known_natbib_commands[] = { "cite", "citet", "citep",
|
char const * const known_natbib_commands[] = { "cite", "citet", "citep",
|
||||||
@ -106,8 +103,6 @@ char const * const known_natbib_commands[] = { "cite", "citet", "citep",
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* jurabib commands.
|
* jurabib commands.
|
||||||
* We can't put these into known_latex_commands because the argument order
|
|
||||||
* is reversed in lyx if there are 2 arguments.
|
|
||||||
* No starred form other than "cite*" known.
|
* No starred form other than "cite*" known.
|
||||||
*/
|
*/
|
||||||
char const * const known_jurabib_commands[] = { "cite", "citet", "citep",
|
char const * const known_jurabib_commands[] = { "cite", "citet", "citep",
|
||||||
@ -359,12 +354,22 @@ void begin_inset(ostream & os, string const & name)
|
|||||||
os << "\n\\begin_inset " << name;
|
os << "\n\\begin_inset " << name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void begin_Cinset(ostream & os, string const & name)
|
||||||
|
{
|
||||||
|
os << "\n\\begin_inset CommandInset " << name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void end_inset(ostream & os)
|
void end_inset(ostream & os)
|
||||||
{
|
{
|
||||||
os << "\n\\end_inset\n\n";
|
os << "\n\\end_inset\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LatexCommand(ostream & os, string const & name)
|
||||||
|
{
|
||||||
|
os << "\nLatexCommand " << name << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void skip_braces(Parser & p)
|
void skip_braces(Parser & p)
|
||||||
{
|
{
|
||||||
@ -1462,9 +1467,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
else if (t.cs() == "bibitem") {
|
else if (t.cs() == "bibitem") {
|
||||||
context.set_item();
|
context.set_item();
|
||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
os << "\\bibitem ";
|
begin_Cinset(os, "bibitem");
|
||||||
|
LatexCommand(os, "bibitem");
|
||||||
os << p.getOpt();
|
os << p.getOpt();
|
||||||
os << '{' << p.verbatim_item() << '}' << "\n";
|
os << "key " << '"' << p.verbatim_item() << '"' << "\n";
|
||||||
|
end_inset(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs() == "def") {
|
else if (t.cs() == "def") {
|
||||||
@ -1781,7 +1788,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
else if (t.cs() == "tableofcontents") {
|
else if (t.cs() == "tableofcontents") {
|
||||||
p.skip_spaces();
|
p.skip_spaces();
|
||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
begin_inset(os, "LatexCommand \\tableofcontents\n");
|
begin_Cinset(os, "toc");
|
||||||
|
LatexCommand(os, "tableofcontents");
|
||||||
end_inset(os);
|
end_inset(os);
|
||||||
skip_braces(p); // swallow this
|
skip_braces(p); // swallow this
|
||||||
}
|
}
|
||||||
@ -1917,6 +1925,17 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
os << "\\lyxline";
|
os << "\\lyxline";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
// FIXME: Move the substitution into parser::getOpt()?
|
||||||
|
os << subst(p.getOpt(), "\n", " ");
|
||||||
|
os << "reference " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
|
||||||
|
end_inset(os);
|
||||||
|
}
|
||||||
|
|
||||||
else if (use_natbib &&
|
else if (use_natbib &&
|
||||||
is_known(t.cs(), known_natbib_commands) &&
|
is_known(t.cs(), known_natbib_commands) &&
|
||||||
((t.cs() != "citefullauthor" &&
|
((t.cs() != "citefullauthor" &&
|
||||||
@ -1924,19 +1943,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
t.cs() != "citeyearpar") ||
|
t.cs() != "citeyearpar") ||
|
||||||
p.next_token().asInput() != "*")) {
|
p.next_token().asInput() != "*")) {
|
||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
// tex lyx
|
string command = t.cs();
|
||||||
// \citet[before][after]{a} \citet[after][before]{a}
|
|
||||||
// \citet[before][]{a} \citet[][before]{a}
|
|
||||||
// \citet[after]{a} \citet[after]{a}
|
|
||||||
// \citet{a} \citet{a}
|
|
||||||
string command = '\\' + t.cs();
|
|
||||||
if (p.next_token().asInput() == "*") {
|
if (p.next_token().asInput() == "*") {
|
||||||
command += '*';
|
command += '*';
|
||||||
p.get_token();
|
p.get_token();
|
||||||
}
|
}
|
||||||
if (command == "\\citefullauthor")
|
if (command == "citefullauthor")
|
||||||
// alternative name for "\\citeauthor*"
|
// alternative name for "\\citeauthor*"
|
||||||
command = "\\citeauthor*";
|
command = "citeauthor*";
|
||||||
|
|
||||||
// text before the citation
|
// text before the citation
|
||||||
string before;
|
string before;
|
||||||
@ -1944,14 +1958,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
string after;
|
string after;
|
||||||
get_cite_arguments(p, true, before, after);
|
get_cite_arguments(p, true, before, after);
|
||||||
|
|
||||||
if (command == "\\cite") {
|
if (command == "cite") {
|
||||||
// \cite without optional argument means
|
// \cite without optional argument means
|
||||||
// \citet, \cite with at least one optional
|
// \citet, \cite with at least one optional
|
||||||
// argument means \citep.
|
// argument means \citep.
|
||||||
if (before.empty() && after.empty())
|
if (before.empty() && after.empty())
|
||||||
command = "\\citet";
|
command = "citet";
|
||||||
else
|
else
|
||||||
command = "\\citep";
|
command = "citep";
|
||||||
}
|
}
|
||||||
if (before.empty() && after == "[]")
|
if (before.empty() && after == "[]")
|
||||||
// avoid \citet[]{a}
|
// avoid \citet[]{a}
|
||||||
@ -1961,16 +1975,27 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
before.erase();
|
before.erase();
|
||||||
after.erase();
|
after.erase();
|
||||||
}
|
}
|
||||||
begin_inset(os, "LatexCommand ");
|
// remove the brackets around after and before
|
||||||
os << command << after << before
|
if (!after.empty()) {
|
||||||
<< '{' << p.verbatim_item() << "}\n";
|
after.erase(0, 1);
|
||||||
|
after.erase(after.length() - 1, 1);
|
||||||
|
}
|
||||||
|
if (!before.empty()) {
|
||||||
|
before.erase(0, 1);
|
||||||
|
before.erase(before.length() - 1, 1);
|
||||||
|
}
|
||||||
|
begin_Cinset(os, "citation");
|
||||||
|
LatexCommand(os, command);
|
||||||
|
os << "after " << '"' << after << '"' << "\n";
|
||||||
|
os << "before " << '"' << before << '"' << "\n";
|
||||||
|
os << "key " << '"' << p.verbatim_item() << '"' << "\n";
|
||||||
end_inset(os);
|
end_inset(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (use_jurabib &&
|
else if (use_jurabib &&
|
||||||
is_known(t.cs(), known_jurabib_commands)) {
|
is_known(t.cs(), known_jurabib_commands)) {
|
||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
string const command = '\\' + t.cs();
|
string const command = t.cs();
|
||||||
char argumentOrder = '\0';
|
char argumentOrder = '\0';
|
||||||
vector<string> const & options = used_packages["jurabib"];
|
vector<string> const & options = used_packages["jurabib"];
|
||||||
if (find(options.begin(), options.end(),
|
if (find(options.begin(), options.end(),
|
||||||
@ -1996,24 +2021,69 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
"package options if you used an\n"
|
"package options if you used an\n"
|
||||||
"earlier jurabib version." << endl;
|
"earlier jurabib version." << endl;
|
||||||
}
|
}
|
||||||
begin_inset(os, "LatexCommand ");
|
if (!after.empty()) {
|
||||||
os << command << after << before
|
after.erase(0, 1);
|
||||||
<< '{' << citation << "}\n";
|
after.erase(after.length() - 1, 1);
|
||||||
|
}
|
||||||
|
if (!before.empty()) {
|
||||||
|
before.erase(0, 1);
|
||||||
|
before.erase(before.length() - 1, 1);
|
||||||
|
}
|
||||||
|
begin_Cinset(os, "citation");
|
||||||
|
LatexCommand(os, command);
|
||||||
|
os << "after " << '"' << after << '"' << "\n";
|
||||||
|
os << "before " << '"' << before << '"' << "\n";
|
||||||
|
os << "key " << '"' << citation << '"' << "\n";
|
||||||
end_inset(os);
|
end_inset(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (is_known(t.cs(), known_latex_commands)) {
|
else if (t.cs() == "cite") {
|
||||||
// This needs to be after the check for natbib and
|
context.check_layout(os);
|
||||||
// jurabib commands, because "cite" has different
|
// lyx cannot handle newlines in a latex command
|
||||||
// arguments with natbib and jurabib.
|
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());
|
||||||
|
os << "after " << '"' << after << '"' << "\n";
|
||||||
|
os << "key " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
|
||||||
|
end_inset(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (t.cs() == "index") {
|
||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
begin_inset(os, "LatexCommand ");
|
begin_inset(os, "LatexCommand ");
|
||||||
os << '\\' << t.cs();
|
os << t.cs() << "\n";;
|
||||||
// lyx cannot handle newlines in a latex command
|
// lyx cannot handle newlines in a latex command
|
||||||
// FIXME: Move the substitution into parser::getOpt()?
|
os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
|
||||||
os << subst(p.getOpt(), "\n", " ");
|
end_inset(os);
|
||||||
os << subst(p.getOpt(), "\n", " ");
|
}
|
||||||
os << '{' << subst(p.verbatim_item(), "\n", " ") << "}\n";
|
|
||||||
|
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
|
||||||
|
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());
|
||||||
|
end_inset(os);
|
||||||
|
skip_braces(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 << "target " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
|
||||||
end_inset(os);
|
end_inset(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2342,13 +2412,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
|
|
||||||
else if (t.cs() == "bibliography") {
|
else if (t.cs() == "bibliography") {
|
||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
begin_inset(os, "LatexCommand ");
|
begin_Cinset(os, "bibtex");
|
||||||
os << "\\bibtex";
|
LatexCommand(os, "bibtex");
|
||||||
|
os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n";
|
||||||
// Do we have a bibliographystyle set?
|
// Do we have a bibliographystyle set?
|
||||||
if (!bibliographystyle.empty()) {
|
if (!bibliographystyle.empty())
|
||||||
os << '[' << bibliographystyle << ']';
|
os << "options " << '"' << bibliographystyle << '"' << "\n";
|
||||||
}
|
|
||||||
os << '{' << p.verbatim_item() << "}\n";
|
|
||||||
end_inset(os);
|
end_inset(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user