const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists",
0};
+/// packages that work only in xetex
+const char * const known_xetex_packages[] = {"arabxetex", "fixlatvian",
+"fontbook", "fontwrap", "mathspec", "philokalia", "polyglossia", "unisugar",
+"xeCJK", "xecolor", "xecyr", "xeindex", "xepersian", "xunicode", 0};
+
// codes used to remove packages that are loaded automatically by LyX.
// Syntax: package_beg_sep<name>package_mid_sep<package loading code>package_end_sep
const char package_beg_sep = '\001';
}
+void Preamble::registerAuthor(std::string const & name)
+{
+ Author author(from_utf8(name), empty_docstring());
+ author.setUsed(true);
+ authors_.record(author);
+ h_tracking_changes = "true";
+ h_output_changes = "true";
+}
+
+
+Author const & Preamble::getAuthor(std::string const & name) const
+{
+ Author author(from_utf8(name), empty_docstring());
+ for (AuthorList::Authors::const_iterator it = authors_.begin();
+ it != authors_.end(); it++)
+ if (*it == author)
+ return *it;
+ static Author const dummy;
+ return dummy;
+}
+
+
void Preamble::add_package(string const & name, vector<string> & options)
{
// every package inherits the global options
}
+void Preamble::handle_geometry(vector<string> & options)
+{
+ h_use_geometry = "true";
+ vector<string>::iterator it;
+ // paper orientation
+ if ((it = find(options.begin(), options.end(), "landscape")) != options.end()) {
+ h_paperorientation = "landscape";
+ options.erase(it);
+ }
+ // paper size
+ // keyval version: "paper=letter"
+ string paper = process_keyval_opt(options, "paper");
+ if (!paper.empty())
+ h_papersize = paper + "paper";
+ // alternative version: "letterpaper"
+ handle_opt(options, known_paper_sizes, h_papersize);
+ delete_opt(options, known_paper_sizes);
+ // page margins
+ char const * const * margin = known_paper_margins;
+ for (; *margin; ++margin) {
+ string value = process_keyval_opt(options, *margin);
+ if (!value.empty()) {
+ int k = margin - known_paper_margins;
+ string name = known_coded_paper_margins[k];
+ h_margins += '\\' + name + ' ' + value + '\n';
+ }
+ }
+}
+
+
void Preamble::handle_package(Parser &p, string const & name,
string const & opts, bool in_lyx_preamble)
{
add_package(name, options);
string scale;
+ if (is_known(name, known_xetex_packages))
+ xetex = true;
+
// roman fonts
if (is_known(name, known_roman_fonts)) {
h_font_roman = name;
else if (name == "url")
; // ignore this
- else if (name == "color" || name == "subscript" || name == "ulem") {
+ else if (name == "booktabs" || name == "color" ||
+ name == "longtable" || name == "subscript" ||
+ name == "ulem") {
if (!in_lyx_preamble)
h_preamble << package_beg_sep << name
<< package_mid_sep << "\\usepackage{"
; // ignore this
else if (name == "geometry")
- ; // Ignore this, the geometry settings are made by the \geometry
- // command. This command is handled below.
+ handle_geometry(options);
else if (name == "rotfloat")
; // ignore this
<< "\\html_math_output " << h_html_math_output << "\n"
<< "\\html_css_as_file " << h_html_css_as_file << "\n"
<< "\\html_be_strict " << h_html_be_strict << "\n"
+ << authors_
<< "\\end_header\n\n"
<< "\\begin_body\n";
// clear preamble for subdocuments
else if (t.cs() == "color") {
string const space =
- (p.hasOpt() ? p.getArg('[', ']') : string());
+ (p.hasOpt() ? p.getOpt() : string());
string argument = p.getArg('{', '}');
// check the case that a standard color is used
if (space.empty() && is_known(argument, known_basic_colors)) {
else {
h_preamble << t.asInput();
if (!space.empty())
- h_preamble << '[' << space << ']';
+ h_preamble << space;
h_preamble << '{' << argument << '}';
// the color might already be set because \definecolor
// is parsed before this
opts.erase(it);
}
// paper sizes
- // some size options are know to any document classes, other sizes
+ // some size options are known to any document classes, other sizes
// are handled by the \geometry command of the geometry package
handle_opt(opts, known_class_paper_sizes, h_papersize);
delete_opt(opts, known_class_paper_sizes);
}
else if (t.cs() == "geometry") {
- h_use_geometry = "true";
vector<string> opts = split_options(p.getArg('{', '}'));
- vector<string>::iterator it;
- // paper orientation
- if ((it = find(opts.begin(), opts.end(), "landscape")) != opts.end()) {
- h_paperorientation = "landscape";
- opts.erase(it);
- }
- // paper size
- handle_opt(opts, known_paper_sizes, h_papersize);
- delete_opt(opts, known_paper_sizes);
- // page margins
- char const * const * margin = known_paper_margins;
- int k = -1;
- for (; *margin; ++margin) {
- k += 1;
- // search for the "=" in e.g. "lmargin=2cm" to get the value
- for(size_t i = 0; i != opts.size(); i++) {
- if (opts.at(i).find(*margin) != string::npos) {
- string::size_type pos = opts.at(i).find("=");
- string value = opts.at(i).substr(pos + 1);
- string name = known_coded_paper_margins[k];
- h_margins += "\\" + name + " " + value + "\n";
- }
- }
- }
+ handle_geometry(opts);
}
else if (t.cs() == "definecolor") {