char const * const known_font_families[] = { "rmfamily", "sffamily",
"ttfamily", 0};
-/// the same as known_old_font_families and known_font_families with .lyx names
+/// LaTeX names for font family changing commands
+char const * const known_text_font_families[] = { "textrm", "textsf",
+"texttt", 0};
+
+/// The same as known_old_font_families, known_font_families and
+/// known_text_font_families with .lyx names
char const * const known_coded_font_families[] = { "roman", "sans",
"typewriter", 0};
/// LaTeX names for font series
char const * const known_font_series[] = { "bfseries", "mdseries", 0};
-/// the same as known_old_font_series and known_font_series with .lyx names
+/// LaTeX names for font series changing commands
+char const * const known_text_font_series[] = { "textbf", "textmd", 0};
+
+/// The same as known_old_font_series, known_font_series and
+/// known_text_font_series with .lyx names
char const * const known_coded_font_series[] = { "bold", "medium", 0};
/// LaTeX 2.09 names for font shapes
char const * const known_font_shapes[] = { "itshape", "slshape", "scshape",
"upshape", 0};
-/// the same as known_old_font_shapes and known_font_shapes with .lyx names
+/// LaTeX names for font shape changing commands
+char const * const known_text_font_shapes[] = { "textit", "textsl", "textsc",
+"textup", 0};
+
+/// The same as known_old_font_shapes, known_font_shapes and
+/// known_text_font_shapes with .lyx names
char const * const known_coded_font_shapes[] = { "italic", "slanted",
"smallcaps", "up", 0};
+/// Known special characters which need skip_spaces_braces() afterwards
+char const * const known_special_chars[] = {"ldots", "lyxarrow",
+"textcompwordmark", "slash", 0};
+
+/// the same as known_special_chars with .lyx names
+char const * const known_coded_special_chars[] = {"ldots{}", "menuseparator",
+"textcompwordmark{}", "slash{}", 0};
+
/*!
* Graphics file extensions known by the dvips driver of the graphics package.
* These extensions are used to complete the filename of an included
for (size_t i = 0; i < no_arguments; ++i) {
switch (template_arguments[i]) {
case required:
+ case req_group:
// This argument contains regular LaTeX
handle_ert(os, ert + '{', context);
eat_whitespace(p, os, context, false);
- parse_text(p, os, FLAG_ITEM, outer, context);
+ if (template_arguments[i] == required)
+ parse_text(p, os, FLAG_ITEM, outer, context);
+ else
+ parse_text_snippet(p, os, FLAG_ITEM, outer, context);
ert = "}";
break;
case item:
else
ert += p.verbatim_item();
break;
+ case displaymath:
case verbatim:
// This argument may contain special characters
ert += '{' + p.verbatim_item() + '}';
break;
case optional:
+ case opt_group:
// true because we must not eat whitespace
// if an optional arg follows we must not strip the
// brackets from this one
latex_width = p.verbatim_item();
// if e.g. only \ovalbox{content} was used, set the width to 1\columnwidth
// as this is LyX's standard for such cases (except for makebox)
+ // \framebox is more special and handled below
if (latex_width.empty() && inner_type != "makebox"
&& outer_type != "framebox")
latex_width = "1\\columnwidth";
}
p.popPosition();
}
- // if only \makebox{content} was used we can its width to 1\width
+ // if only \makebox{content} was used we can set its width to 1\width
// because this identic and also identic to \mbox
// this doesn't work for \framebox{content}, thus we have to use ERT for this
if (latex_width.empty() && inner_type == "makebox") {
// the inner env
if (!inner_type.empty() && (inner_flags & FLAG_END))
active_environments.pop_back();
+
+ // Ensure that the end of the outer box is parsed correctly:
+ // The opening brace has been eaten by parse_outer_box()
+ if (!outer_type.empty() && (outer_flags & FLAG_ITEM)) {
+ outer_flags &= ~FLAG_ITEM;
+ outer_flags |= FLAG_BRACE_LAST;
+ }
parse_text(p, os, outer_flags, outer, parent_context);
if (outer_flags & FLAG_END)
handle_ert(os, "\\end{" + outer_type + '}',
parse_math(p, os, FLAG_END, MATH_MODE);
os << "\\end{" << name << "}";
end_inset(os);
+ if (is_display_math_env(name)) {
+ // Prevent the conversion of a line break to a space
+ // (bug 7668). This does not change the output, but
+ // looks ugly in LyX.
+ eat_whitespace(p, os, parent_context, false);
+ }
}
- else if (name == "tabular" || name == "longtable") {
+ else if (unstarred_name == "tabular" || name == "longtable") {
eat_whitespace(p, os, parent_context, false);
+ string width = "0pt";
+ if (name == "tabular*") {
+ width = lyx::translate_len(p.getArg('{', '}'));
+ eat_whitespace(p, os, parent_context, false);
+ }
parent_context.check_layout(os);
begin_inset(os, "Tabular ");
- handle_tabular(p, os, name == "longtable", parent_context);
+ handle_tabular(p, os, name, width, parent_context);
end_inset(os);
p.skip_spaces();
}
else if (parent_context.textclass.floats().typeExist(unstarred_name)) {
+ eat_whitespace(p, os, parent_context, false);
+ string const opt = p.hasOpt() ? p.getArg('[', ']') : string();
eat_whitespace(p, os, parent_context, false);
parent_context.check_layout(os);
begin_inset(os, "Float " + unstarred_name + "\n");
float_type = unstarred_name;
else
float_type = "";
- if (p.hasOpt())
- os << "placement " << p.getArg('[', ']') << '\n';
+ if (!opt.empty())
+ os << "placement " << opt << '\n';
os << "wide " << convert<string>(is_starred)
<< "\nsideways false"
<< "\nstatus open\n\n";
{
Layout const * newlayout = 0;
InsetLayout const * newinsetlayout = 0;
+ char const * const * where = 0;
// Store the latest bibliographystyle and nocite{*} option
// (needed for bibtex inset)
string btprint;
context.check_layout(os);
begin_inset(os, "Formula ");
Token const & n = p.get_token();
- if (n.cat() == catMath && outer) {
+ bool const display(n.cat() == catMath && outer);
+ if (display) {
// TeX's $$...$$ syntax for displayed math
os << "\\[";
parse_math(p, os, FLAG_SIMPLE, MATH_MODE);
os << '$';
}
end_inset(os);
+ if (display) {
+ // Prevent the conversion of a line break to a
+ // space (bug 7668). This does not change the
+ // output, but looks ugly in LyX.
+ eat_whitespace(p, os, context, false);
+ }
}
else if (t.cat() == catSuper || t.cat() == catSub)
parse_math(p, os, FLAG_EQUATION, MATH_MODE);
os << "\\]";
end_inset(os);
+ // Prevent the conversion of a line break to a space
+ // (bug 7668). This does not change the output, but
+ // looks ugly in LyX.
+ eat_whitespace(p, os, context, false);
}
else if (t.cs() == "begin")
}
else if (t.cs() == "item") {
- p.skip_spaces();
string s;
- bool optarg = false;
- if (p.next_token().cat() != catEscape &&
- p.next_token().character() == '[') {
- p.get_token(); // eat '['
- s = parse_text_snippet(p, FLAG_BRACK_LAST,
- outer, context);
- optarg = true;
- }
+ bool const optarg = p.hasOpt();
+ if (optarg) {
+ // FIXME: This swallows comments, but we cannot use
+ // eat_whitespace() since we must not output
+ // anything before the item.
+ s = p.getArg('[', ']');
+ } else
+ p.skip_spaces(false);
context.set_item();
context.check_layout(os);
if (context.has_item) {
if (context.layout->labeltype != LABEL_MANUAL) {
// LyX does not support \item[\mybullet]
// in itemize environments
- handle_ert(os, "[", context);
- os << s;
- handle_ert(os, "]", context);
+ Parser p2(s + ']');
+ os << parse_text_snippet(p2,
+ FLAG_BRACK_LAST, outer, context);
} else if (!s.empty()) {
+ // LyX adds braces around the argument,
+ // so we need to remove them here.
+ if (s.size() > 2 && s[0] == '{' &&
+ s[s.size()-1] == '}')
+ s = s.substr(1, s.size()-2);
+ // If the argument contains a space we
+ // must put it into ERT: Otherwise LyX
+ // would misinterpret the space as
+ // item delimiter (bug 7663)
+ if (contains(s, ' ')) {
+ handle_ert(os, s, context);
+ } else {
+ Parser p2(s + ']');
+ os << parse_text_snippet(p2,
+ FLAG_BRACK_LAST,
+ outer, context);
+ }
// The space is needed to separate the
// item from the rest of the sentence.
- os << s << ' ';
+ os << ' ';
eat_whitespace(p, os, context, false);
}
}
handle_ert(os, "\\listof{" + name + "}", context);
}
- else if (t.cs() == "textrm")
+ else if ((where = is_known(t.cs(), known_text_font_families)))
parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\family",
- context.font.family, "roman");
+ context, "\\family", context.font.family,
+ known_coded_font_families[where - known_text_font_families]);
- else if (t.cs() == "textsf")
+ else if ((where = is_known(t.cs(), known_text_font_series)))
parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\family",
- context.font.family, "sans");
+ context, "\\series", context.font.series,
+ known_coded_font_series[where - known_text_font_series]);
- else if (t.cs() == "texttt")
+ else if ((where = is_known(t.cs(), known_text_font_shapes)))
parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\family",
- context.font.family, "typewriter");
-
- else if (t.cs() == "textmd")
- parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\series",
- context.font.series, "medium");
-
- else if (t.cs() == "textbf")
- parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\series",
- context.font.series, "bold");
-
- else if (t.cs() == "textup")
- parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\shape",
- context.font.shape, "up");
-
- else if (t.cs() == "textit")
- parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\shape",
- context.font.shape, "italic");
-
- else if (t.cs() == "textsl")
- parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\shape",
- context.font.shape, "slanted");
-
- else if (t.cs() == "textsc")
- parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\shape",
- context.font.shape, "smallcaps");
+ context, "\\shape", context.font.shape,
+ known_coded_font_shapes[where - known_text_font_shapes]);
else if (t.cs() == "textnormal" || t.cs() == "normalfont") {
context.check_layout(os);
is_known(p.next_token().cs(), known_phrases))) {
// LyX sometimes puts a \protect in front, so we have to ignore it
// FIXME: This needs to be changed when bug 4752 is fixed.
- char const * const * where = is_known(
+ where = is_known(
t.cs() == "protect" ? p.get_token().cs() : t.cs(),
known_phrases);
context.check_layout(os);
skip_spaces_braces(p);
}
- else if (is_known(t.cs(), known_ref_commands)) {
+ else if ((where = is_known(t.cs(), known_ref_commands))) {
string const opt = p.getOpt();
if (opt.empty()) {
context.check_layout(os);
- char const * const * where = is_known(t.cs(),
- known_ref_commands);
begin_command_inset(os, "ref",
known_coded_ref_commands[where - known_ref_commands]);
os << "reference \""
preamble.registerAutomaticallyLoadedPackage("subscript");
}
- else if (is_known(t.cs(), known_quotes)) {
- char const * const * where = is_known(t.cs(), known_quotes);
+ else if ((where = is_known(t.cs(), known_quotes))) {
context.check_layout(os);
begin_inset(os, "Quotes ");
os << known_coded_quotes[where - known_quotes];
skip_braces(p);
}
- else if (is_known(t.cs(), known_sizes) &&
+ else if ((where = is_known(t.cs(), known_sizes)) &&
context.new_layout_allowed) {
- char const * const * where = is_known(t.cs(), known_sizes);
context.check_layout(os);
TeXFont const oldFont = context.font;
context.font.size = known_coded_sizes[where - known_sizes];
eat_whitespace(p, os, context, false);
}
- else if (is_known(t.cs(), known_font_families) &&
+ else if ((where = is_known(t.cs(), known_font_families)) &&
context.new_layout_allowed) {
- char const * const * where =
- is_known(t.cs(), known_font_families);
context.check_layout(os);
TeXFont const oldFont = context.font;
context.font.family =
eat_whitespace(p, os, context, false);
}
- else if (is_known(t.cs(), known_font_series) &&
+ else if ((where = is_known(t.cs(), known_font_series)) &&
context.new_layout_allowed) {
- char const * const * where =
- is_known(t.cs(), known_font_series);
context.check_layout(os);
TeXFont const oldFont = context.font;
context.font.series =
eat_whitespace(p, os, context, false);
}
- else if (is_known(t.cs(), known_font_shapes) &&
+ else if ((where = is_known(t.cs(), known_font_shapes)) &&
context.new_layout_allowed) {
- char const * const * where =
- is_known(t.cs(), known_font_shapes);
context.check_layout(os);
TeXFont const oldFont = context.font;
context.font.shape =
output_font_change(os, oldFont, context.font);
eat_whitespace(p, os, context, false);
}
- else if (is_known(t.cs(), known_old_font_families) &&
+ else if ((where = is_known(t.cs(), known_old_font_families)) &&
context.new_layout_allowed) {
- char const * const * where =
- is_known(t.cs(), known_old_font_families);
context.check_layout(os);
TeXFont const oldFont = context.font;
context.font.init();
eat_whitespace(p, os, context, false);
}
- else if (is_known(t.cs(), known_old_font_series) &&
+ else if ((where = is_known(t.cs(), known_old_font_series)) &&
context.new_layout_allowed) {
- char const * const * where =
- is_known(t.cs(), known_old_font_series);
context.check_layout(os);
TeXFont const oldFont = context.font;
context.font.init();
eat_whitespace(p, os, context, false);
}
- else if (is_known(t.cs(), known_old_font_shapes) &&
+ else if ((where = is_known(t.cs(), known_old_font_shapes)) &&
context.new_layout_allowed) {
- char const * const * where =
- is_known(t.cs(), known_old_font_shapes);
context.check_layout(os);
TeXFont const oldFont = context.font;
context.font.init();
p.setEncoding(enc);
}
- else if (t.cs() == "ldots") {
- context.check_layout(os);
- os << "\\SpecialChar \\ldots{}\n";
- skip_spaces_braces(p);
- }
-
- else if (t.cs() == "lyxarrow") {
- context.check_layout(os);
- os << "\\SpecialChar \\menuseparator\n";
- skip_spaces_braces(p);
- }
-
- else if (t.cs() == "textcompwordmark") {
- context.check_layout(os);
- os << "\\SpecialChar \\textcompwordmark{}\n";
- skip_spaces_braces(p);
- }
-
- else if (t.cs() == "slash") {
+ else if ((where = is_known(t.cs(), known_special_chars))) {
context.check_layout(os);
- os << "\\SpecialChar \\slash{}\n";
+ os << "\\SpecialChar \\"
+ << known_coded_special_chars[where - known_special_chars]
+ << '\n';
skip_spaces_braces(p);
}
}
//\makebox() is part of the picture environment and different from \makebox{}
- //\makebox{} will be parsed by parse_box when bug 2956 is fixed
+ //\makebox{} will be parsed by parse_box
else if (t.cs() == "makebox") {
string arg = t.asInput();
if (p.next_token().character() == '(') {
//the syntax is: \makebox(x,y)[position]{content}
arg += p.getFullParentheseArg();
arg += p.getFullOpt();
- handle_ert(os, arg + p.get_token().asInput(), context);
+ eat_whitespace(p, os, context, false);
+ handle_ert(os, arg + '{', context);
+ eat_whitespace(p, os, context, false);
+ parse_text(p, os, FLAG_ITEM, outer, context);
+ handle_ert(os, "}", context);
} else
//the syntax is: \makebox[width][position]{content}
parse_box(p, os, 0, FLAG_ITEM, outer, context,
skip_spaces_braces(p);
}
- else if (is_known(t.cs(), known_spaces)) {
- char const * const * where = is_known(t.cs(), known_spaces);
+ else if ((where = is_known(t.cs(), known_spaces))) {
context.check_layout(os);
begin_inset(os, "space ");
os << '\\' << known_coded_spaces[where - known_spaces]