* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author André Pönitz
+ * \author André Pönitz
* \author Jean-Marc Lasgouttes
- * \author Uwe Stöhr
+ * \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
#include "Layout.h"
#include "Length.h"
-#include "support/lstrings.h"
#include "support/convert.h"
+#include "support/FileName.h"
#include "support/filetools.h"
+#include "support/lstrings.h"
-#include <boost/tuple/tuple.hpp>
+#include <boost/assert.hpp>
+#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
-using std::cerr;
-using std::endl;
-using std::find;
-using std::map;
-using std::ostream;
-using std::ostringstream;
-using std::istringstream;
-using std::string;
-using std::vector;
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-using support::addExtension;
-using support::changeExtension;
-using support::FileName;
-using support::makeAbsPath;
-using support::makeRelPath;
-using support::rtrim;
-using support::suffixIs;
-using support::contains;
-using support::subst;
-
void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
Context const & context)
}
-char const * const known_latex_commands[] = { "ref", "cite", "label",
- "index", "pageref", "url", "vref", "vpageref", "prettyref",
+char const * const known_latex_commands[] = { "ref", "cite", "nocite", "label",
+ "index", "printindex", "pageref", "url", "vref", "vpageref", "prettyref",
"eqref", 0 };
/*!
"citefield", "citetitle", "cite*", 0 };
/// LaTeX names for quotes
-char const * const known_quotes[] = { "glqq", "grqq", "quotedblbase",
-"textquotedblleft", "quotesinglbase", "guilsinglleft", "guilsinglright", 0};
+char const * const known_quotes[] = { "dq", "guillemotleft", "flqq", "og",
+"guillemotright", "frqq", "fg", "glq", "glqq", "textquoteleft", "grq", "grqq",
+"quotedblbase", "textquotedblleft", "quotesinglbase", "textquoteright", "flq",
+"guilsinglleft", "frq", "guilsinglright", 0};
/// the same as known_quotes with .lyx names
-char const * const known_coded_quotes[] = { "gld", "grd", "gld",
-"grd", "gls", "fls", "frs", 0};
+char const * const known_coded_quotes[] = { "prd", "ard", "ard", "ard",
+"ald", "ald", "ald", "gls", "gld", "els", "els", "grd",
+"gld", "grd", "gls", "ers", "fls",
+"fls", "frs", "frs", 0};
/// LaTeX names for font sizes
char const * const known_sizes[] = { "tiny", "scriptsize", "footnotesize",
if (contains(len, '\\'))
unit = trim(string(len, i));
else
- unit = support::ascii_lowercase(trim(string(len, i)));
+ unit = ascii_lowercase(trim(string(len, i)));
return true;
}
}
-class isLayout : public std::unary_function<LayoutPtr, bool> {
-public:
- isLayout(string const name) : name_(name) {}
- bool operator()(LayoutPtr const & ptr) const {
- return ptr->latexname() == name_;
- }
-private:
- string const name_;
-};
-
-
-LayoutPtr findLayout(TextClass const & textclass,
- string const & name)
+LayoutPtr findLayout(TextClass const & textclass, string const & name)
{
- TextClass::const_iterator beg = textclass.begin();
- TextClass::const_iterator end = textclass.end();
-
- TextClass::const_iterator
- it = std::find_if(beg, end, isLayout(name));
-
- return (it == end) ? LayoutPtr() : *it;
+ DocumentClass::const_iterator lit = textclass.begin();
+ DocumentClass::const_iterator len = textclass.end();
+ for (; lit != len; ++lit)
+ if (lit->latexname() == name)
+ return &*lit;
+ return LayoutPtr();
}
parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
end_inset(os);
p.skip_spaces();
- // FIXME the comment note inset has a trailing "{}" pair
- //p.skip_braces(p);
}
else if (name == "lyxgreyedout") {
}
// The single '=' is meant here.
- else if ((newlayout = findLayout(parent_context.textclass, name)).get() &&
+ else if ((newlayout = findLayout(parent_context.textclass, name)) &&
newlayout->isEnvironment()) {
eat_whitespace(p, os, parent_context, false);
Context context(true, parent_context.textclass, newlayout,
/// get the arguments of a natbib or jurabib citation command
-std::pair<string, string> getCiteArguments(Parser & p, bool natbibOrder)
+void get_cite_arguments(Parser & p, bool natbibOrder,
+ string & before, string & after)
{
// We need to distinguish "" and "[]", so we can't use p.getOpt().
// text before the citation
- string before;
+ before.clear();
// text after the citation
- string after = p.getFullOpt();
+ after = p.getFullOpt();
if (!after.empty()) {
before = p.getFullOpt();
if (natbibOrder && !before.empty())
- std::swap(before, after);
+ swap(before, after);
}
- return std::make_pair(before, after);
}
-/// Convert filenames with TeX macros and/or quotes to something LyX can understand
+/// Convert filenames with TeX macros and/or quotes to something LyX
+/// can understand
string const normalize_filename(string const & name)
{
Parser p(trim(name, "\""));
/// convention (relative to .lyx file) if it is relative
void fix_relative_filename(string & name)
{
- if (lyx::support::absolutePath(name))
+ FileName fname(name);
+ if (fname.isAbsolute())
return;
+
// FIXME UNICODE encoding of name may be wrong (makeAbsPath expects
// utf8)
name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name, getMasterFilePath()).absFilename()),
// always must be in an own paragraph.
context.new_paragraph(os);
Context newcontext(true, context.textclass,
- context.textclass[from_ascii("Scrap")]);
+ &context.textclass[from_ascii("Scrap")]);
newcontext.check_layout(os);
os << name;
while (p.good()) {
// extended to other quotes, but is not so easy (a
// left english quote is the same as a right german
// quote...)
- else if (t.asInput() == "`"
- && p.next_token().asInput() == "`") {
+ else if (t.asInput() == "`" && p.next_token().asInput() == "`") {
context.check_layout(os);
begin_inset(os, "Quotes ");
os << "eld";
p.get_token();
skip_braces(p);
}
- else if (t.asInput() == "'"
- && p.next_token().asInput() == "'") {
+ else if (t.asInput() == "'" && p.next_token().asInput() == "'") {
context.check_layout(os);
begin_inset(os, "Quotes ");
os << "erd";
skip_braces(p);
}
+ else if (t.asInput() == ">" && p.next_token().asInput() == ">") {
+ context.check_layout(os);
+ begin_inset(os, "Quotes ");
+ os << "ald";
+ end_inset(os);
+ p.get_token();
+ skip_braces(p);
+ }
+
+ else if (t.asInput() == "<" && p.next_token().asInput() == "<") {
+ context.check_layout(os);
+ begin_inset(os, "Quotes ");
+ os << "ard";
+ end_inset(os);
+ p.get_token();
+ skip_braces(p);
+ }
+
else if (t.asInput() == "<"
&& p.next_token().asInput() == "<" && noweb_mode) {
p.get_token();
else if ((p.next_token().asInput() == "*") &&
context.new_layout_allowed &&
// The single '=' is meant here.
- (newlayout = findLayout(context.textclass,
- t.cs() + '*')).get() &&
- newlayout->isCommand()) {
+ (newlayout = findLayout(context.textclass, t.cs() + '*')) &&
+ newlayout->isCommand()) {
p.get_token();
output_command_layout(os, p, outer, context, newlayout);
p.skip_spaces();
// The single '=' is meant here.
else if (context.new_layout_allowed &&
- (newlayout = findLayout(context.textclass, t.cs())).get() &&
+ (newlayout = findLayout(context.textclass, t.cs())) &&
newlayout->isCommand()) {
output_command_layout(os, p, outer, context, newlayout);
p.skip_spaces();
numberOfbbOptions++;
if (numberOfbbOptions == 4)
os << "\tBoundingBox "
- << opts["bbllx"] << opts["bblly"]
- << opts["bburx"] << opts["bbury"] << '\n';
+ << opts["bbllx"] << " " << opts["bblly"] << " "
+ << opts["bburx"] << " " << opts["bbury"] << '\n';
else if (numberOfbbOptions > 0)
cerr << "Warning: Ignoring incomplete includegraphics boundingbox arguments.\n";
numberOfbbOptions = 0;
numberOfbbOptions++;
if (numberOfbbOptions == 2)
os << "\tBoundingBox 0bp 0bp "
- << opts["natwidth"] << opts["natheight"] << '\n';
+ << opts["natwidth"] << " " << opts["natheight"] << '\n';
else if (numberOfbbOptions > 0)
cerr << "Warning: Ignoring incomplete includegraphics boundingbox arguments.\n";
ostringstream special;
else if (t.cs() == "tableofcontents") {
p.skip_spaces();
context.check_layout(os);
- begin_inset(os, "CommandInset toc\n");
- os << "LatexCommand tableofcontents\n";
+ begin_inset(os, "LatexCommand \\tableofcontents\n");
end_inset(os);
skip_braces(p); // swallow this
}
else if (t.cs() == "listof") {
p.skip_spaces(true);
- string const name = p.verbatim_item();
- string const name2 = subst(p.verbatim_item(), "\n", " ");
+ string const name = p.get_token().asString();
if (context.textclass.floats().typeExist(name)) {
context.check_layout(os);
begin_inset(os, "FloatList ");
os << name << "\n";
end_inset(os);
- // the second argument is not needed
+ p.get_token(); // swallow second arg
} else
- handle_ert(os, "\\listof{" + name + "}{" + name2 + "}", context);
+ handle_ert(os, "\\listof{" + name + "}", context);
}
else if (t.cs() == "textrm")
string before;
// text after the citation
string after;
+ get_cite_arguments(p, true, before, after);
- boost::tie(before, after) = getCiteArguments(p, true);
if (command == "\\cite") {
// \cite without optional argument means
// \citet, \cite with at least one optional
string const command = '\\' + t.cs();
char argumentOrder = '\0';
vector<string> const & options = used_packages["jurabib"];
- if (std::find(options.begin(), options.end(),
+ if (find(options.begin(), options.end(),
"natbiborder") != options.end())
argumentOrder = 'n';
- else if (std::find(options.begin(), options.end(),
+ else if (find(options.begin(), options.end(),
"jurabiborder") != options.end())
argumentOrder = 'j';
string before;
// text after the citation
string after;
+ get_cite_arguments(p, argumentOrder != 'j', before, after);
- boost::tie(before, after) =
- getCiteArguments(p, argumentOrder != 'j');
string const citation = p.verbatim_item();
if (!before.empty() && argumentOrder == '\0') {
cerr << "Warning: Assuming argument order "
skip_braces(p);
}
- else if (t.cs() == "lyxline") {
- context.check_layout(os);
- // the argument can be omitted, is handled by LyX
- subst(p.verbatim_item(), "\n", " ");
- os << "\\lyxline\n ";
-
- }
-
else if (t.cs() == "textcompwordmark") {
context.check_layout(os);
os << "\\SpecialChar \\textcompwordmark{}\n";
else if (t.cs() == "bibliography") {
context.check_layout(os);
- begin_inset(os, "CommandInset bibtex");
- os << "\nLatexCommand bibtex";
+ begin_inset(os, "LatexCommand ");
+ os << "\\bibtex";
// Do we have a bibliographystyle set?
- if (!bibliographystyle.empty())
- os << "\noptions " << '"' << bibliographystyle << '"';
- os << "\nbibfiles " << '"' << p.verbatim_item() << '"';
- end_inset(os);
- }
-
- else if (t.cs() == "printindex") {
- context.check_layout(os);
- begin_inset(os, "CommandInset index_print\n");
- os << "LatexCommand printindex";
- end_inset(os);
- skip_braces(p);
- }
-
- else if (t.cs() == "printnomenclature") {
- context.check_layout(os);
- begin_inset(os, "CommandInset nomencl_print\n");
- os << "LatexCommand printnomenclature";
+ if (!bibliographystyle.empty()) {
+ os << '[' << bibliographystyle << ']';
+ }
+ os << '{' << p.verbatim_item() << "}\n";
end_inset(os);
- skip_braces(p);
}
else if (t.cs() == "parbox")
else if (t.cs() == "newcommand" ||
t.cs() == "providecommand" ||
- t.cs() == "renewcommand") {
+ t.cs() == "renewcommand" ||
+ t.cs() == "newlyxcommand") {
// these could be handled by parse_command(), but
// we need to call add_known_command() here.
string name = t.asInput();
}
string const command = p.verbatim_item();
string const opt1 = p.getOpt();
- string const opt2 = p.getFullOpt();
- add_known_command(command, opt1, !opt2.empty());
- string const ert = name + '{' + command + '}' +
- opt1 + opt2 +
- '{' + p.verbatim_item() + '}';
+ string optionals;
+ unsigned optionalsNum = 0;
+ while (true) {
+ string const opt = p.getFullOpt();
+ if (opt.empty())
+ break;
+ optionalsNum++;
+ optionals += opt;
+ }
+ add_known_command(command, opt1, optionalsNum);
+ string const ert = name + '{' + command + '}' + opt1
+ + optionals + '{' + p.verbatim_item() + '}';
context.check_layout(os);
begin_inset(os, "FormulaMacro");