X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftex2lyx%2Ftext.cpp;h=ce330a2b9ffe97a21a1c0da1ac0093632469fdd6;hb=3628ceec480c3d8fa9673f80f781eb1153fb9e1f;hp=f2fe12def5dbe36ad70bfca283d103a82ed923e0;hpb=7178f98b0fe8cb1e2fbe7e3e9771ae0afa4734f8;p=lyx.git diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index f2fe12def5..ce330a2b9f 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -124,6 +124,9 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer, return os.str(); } +string fboxrule = ""; +string fboxsep = ""; +string shadow_size = ""; char const * const known_ref_commands[] = { "ref", "pageref", "vref", "vpageref", "prettyref", "nameref", "eqref", 0 }; @@ -133,11 +136,11 @@ char const * const known_coded_ref_commands[] = { "ref", "pageref", "vref", char const * const known_refstyle_commands[] = { "algref", "chapref", "corref", "eqref", "enuref", "figref", "fnref", "lemref", "parref", "partref", "propref", - "secref", "subref", "tabref", "thmref", 0 }; + "secref", "subsecref", "tabref", "thmref", 0 }; char const * const known_refstyle_prefixes[] = { "alg", "chap", "cor", "eq", "enu", "fig", "fn", "lem", "par", "part", "prop", - "sec", "sub", "tab", "thm", 0 }; + "sec", "subsec", "tab", "thm", 0 }; /** @@ -249,12 +252,20 @@ char const * const known_coded_font_shapes[] = { "italic", "slanted", /// Known special characters which need skip_spaces_braces() afterwards char const * const known_special_chars[] = {"ldots", "lyxarrow", "textcompwordmark", -"slash", "textasciitilde", "textasciicircum", "textbackslash", 0}; +"slash", "textasciitilde", "textasciicircum", "textbackslash", +"LyX", "TeX", "LaTeXe", +"LaTeX", 0}; + +/// special characters from known_special_chars which may have a \\protect before +char const * const known_special_protect_chars[] = {"LyX", "TeX", +"LaTeXe", "LaTeX", 0}; /// the same as known_special_chars with .lyx names -char const * const known_coded_special_chars[] = {"\\SpecialChar \\ldots{}\n", -"\\SpecialChar \\menuseparator\n", "\\SpecialChar \\textcompwordmark{}\n", -"\\SpecialChar \\slash{}\n", "~", "^", "\n\\backslash\n", 0}; +char const * const known_coded_special_chars[] = {"\\SpecialChar ldots\n", +"\\SpecialChar menuseparator\n", "\\SpecialChar ligaturebreak\n", +"\\SpecialChar breakableslash\n", "~", "^", "\n\\backslash\n", +"\\SpecialChar LyX\n", "\\SpecialChar TeX\n", "\\SpecialChar LaTeX2e\n", +"\\SpecialChar LaTeX\n", 0}; /*! * Graphics file extensions known by the dvips driver of the graphics package. @@ -295,12 +306,6 @@ char const * const known_coded_spaces[] = { "space{}", "space{}", "hfill{}", "dotfill{}", "hrulefill{}", "leftarrowfill{}", "rightarrowfill{}", "upbracefill{}", "downbracefill{}", 0}; -/// These are translated by LyX to commands like "\\LyX{}", so we have to put -/// them in ERT. "LaTeXe" must come before "LaTeX"! -char const * const known_phrases[] = {"LyX", "TeX", "LaTeXe", "LaTeX", 0}; -char const * const known_coded_phrases[] = {"LyX", "TeX", "LaTeX2e", "LaTeX", 0}; -int const known_phrase_lengths[] = {3, 5, 7, 0}; - /// known TIPA combining diacritical marks char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut", "textsubtilde", "textseagull", "textsubbridge", "textinvsubbridge", @@ -308,7 +313,7 @@ char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut", "textovercross", "textsubarch", "textsuperimposetilde", "textraising", "textlowering", "textadvancing", "textretracting", "textdoublegrave", "texthighrise", "textlowrise", "textrisefall", "textsyllabic", -"textsubring", 0}; +"textsubring", "textsubbar", 0}; /// TIPA tones that need special handling char const * const known_tones[] = {"15", "51", "45", "12", "454", 0}; @@ -516,8 +521,8 @@ docstring convert_unicodesymbols(docstring s) bool termination; docstring rem; set req; - docstring parsed = encodings.fromLaTeXCommand(s, - Encodings::TEXT_CMD, termination, rem, &req); + docstring parsed = normalize_c(encodings.fromLaTeXCommand(s, + Encodings::TEXT_CMD, termination, rem, &req)); set::const_iterator it = req.begin(); set::const_iterator en = req.end(); for (; it != en; ++it) @@ -575,6 +580,16 @@ void output_ert_inset(ostream & os, string const & s, Context & context) } +void output_comment(Parser & p, ostream & os, string const & s, + Context & context) +{ + if (p.next_token().cat() == catNewline) + output_ert_inset(os, '%' + s, context); + else + output_ert_inset(os, '%' + s + '\n', context); +} + + Layout const * findLayout(TextClass const & textclass, string const & name, bool command) { Layout const * layout = findLayoutWithoutModule(textclass, name, command); @@ -830,11 +845,12 @@ bool parse_command(string const & command, Parser & p, ostream & os, void parse_box(Parser & p, ostream & os, unsigned outer_flags, unsigned inner_flags, bool outer, Context & parent_context, string const & outer_type, string const & special, - string const & inner_type) + string inner_type, string const & frame_color, + string const & background_color) { string position; string inner_pos; - string hor_pos = "c"; + string hor_pos = "l"; // We need to set the height to the LaTeX default of 1\\totalheight // for the case when no height argument is given string height_value = "1"; @@ -845,6 +861,63 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, string width_unit; string latex_width; string width_special = "none"; + string thickness = "0.4pt"; + if (!fboxrule.empty()) + thickness = fboxrule; + else + thickness = "0.4pt"; + string separation; + if (!fboxsep.empty()) + separation = fboxsep; + else + separation = "3pt"; + string shadowsize; + if (!shadow_size.empty()) + shadowsize = shadow_size; + else + shadowsize = "4pt"; + string framecolor = "black"; + string backgroundcolor = "none"; + if (!frame_color.empty()) + framecolor = frame_color; + if (!background_color.empty()) + backgroundcolor = background_color; + // if there is a color box around the \begin statements have not yet been parsed + // so do this now + if (!frame_color.empty() || !background_color.empty()) { + eat_whitespace(p, os, parent_context, false); + p.get_token().asInput(); // the '{' + // parse minipage + if (p.next_token().asInput() == "\\begin") { + p.get_token().asInput(); + p.getArg('{', '}'); + inner_type = "minipage"; + inner_flags = FLAG_END; + active_environments.push_back("minipage"); + } + // parse parbox + else if (p.next_token().asInput() == "\\parbox") { + p.get_token().asInput(); + inner_type = "parbox"; + inner_flags = FLAG_ITEM; + } + // parse makebox + else if (p.next_token().asInput() == "\\makebox") { + p.get_token().asInput(); + inner_type = "makebox"; + inner_flags = FLAG_ITEM; + } + // in case there is just \colorbox{color}{text} + else { + latex_width = ""; + inner_type = "makebox"; + inner_flags = FLAG_BRACE_LAST; + position = "t"; + inner_pos = "t"; + } + } + if (!p.hasOpt() && (inner_type == "makebox" || outer_type == "mbox")) + hor_pos = "c"; if (!inner_type.empty() && p.hasOpt()) { if (inner_type != "makebox") position = p.getArg('[', ']'); @@ -885,6 +958,9 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, inner_pos = position; } } + } else { + if (inner_type == "makebox") + hor_pos = "c"; } } if (inner_type.empty()) { @@ -902,6 +978,9 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, << " for " << outer_type << endl; hor_pos = "c"; } + } else { + if (outer_type == "framebox") + hor_pos = "c"; } } } else if (inner_type != "makebox") @@ -932,9 +1011,8 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, if (!outer_type.empty() && !inner_type.empty() && (inner_flags & FLAG_END)) active_environments.push_back(inner_type); - // LyX can't handle length variables - bool use_ert = contains(width_unit, '\\') || contains(height_unit, '\\'); - if (!use_ert && !outer_type.empty() && !inner_type.empty()) { + bool use_ert = false; + if (!outer_type.empty() && !inner_type.empty()) { // Look whether there is some content after the end of the // inner box, but before the end of the outer box. // If yes, we need to output ERT. @@ -953,18 +1031,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, } p.popPosition(); } - // 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") { - width_value = "1"; - width_unit = "in"; - width_special = "width"; - } else if (latex_width.empty() && outer_type == "framebox") { - width_value.clear(); - width_unit.clear(); - width_special = "none"; - } + if (use_ert) { ostringstream ss; if (!outer_type.empty()) { @@ -1034,7 +1101,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, begin_inset(os, "Box "); if (outer_type == "framed") os << "Framed\n"; - else if (outer_type == "framebox" || outer_type == "fbox") + else if (outer_type == "framebox" || outer_type == "fbox" || !frame_color.empty()) os << "Boxed\n"; else if (outer_type == "shadowbox") os << "Shadowbox\n"; @@ -1053,6 +1120,8 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, os << "hor_pos \"" << hor_pos << "\"\n"; if (outer_type == "mbox") os << "has_inner_box 1\n"; + else if (!frame_color.empty() && inner_type == "makebox") + os << "has_inner_box 0\n"; else os << "has_inner_box " << !inner_type.empty() << "\n"; os << "inner_pos \"" << inner_pos << "\"\n"; @@ -1060,15 +1129,32 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, << '\n'; if (outer_type == "mbox") os << "use_makebox 1\n"; + else if (!frame_color.empty()) + os << "use_makebox 0\n"; else os << "use_makebox " << (inner_type == "makebox") << '\n'; - if (outer_type == "fbox" || outer_type == "mbox") + if (outer_type == "mbox" || (outer_type == "fbox" && inner_type.empty())) os << "width \"\"\n"; + // for values like "1.5\width" LyX uses "1.5in" as width ad sets "width" as sepecial + else if (contains(width_unit, '\\')) + os << "width \"" << width_value << "in" << "\"\n"; else os << "width \"" << width_value << width_unit << "\"\n"; - os << "special \"" << width_special << "\"\n"; - os << "height \"" << height_value << height_unit << "\"\n"; + if (contains(width_unit, '\\')) { + width_unit.erase (0,1); // remove the leading '\' + os << "special \"" << width_unit << "\"\n"; + } else + os << "special \"" << width_special << "\"\n"; + if (contains(height_unit, '\\')) + os << "height \"" << height_value << "in" << "\"\n"; + else + os << "height \"" << height_value << height_unit << "\"\n"; os << "height_special \"" << height_special << "\"\n"; + os << "thickness \"" << thickness << "\"\n"; + os << "separation \"" << separation << "\"\n"; + os << "shadowsize \"" << shadowsize << "\"\n"; + os << "framecolor \"" << framecolor << "\"\n"; + os << "backgroundcolor \"" << backgroundcolor << "\"\n"; os << "status open\n\n"; // Unfortunately we can't use parse_text_in_inset: @@ -1113,13 +1199,13 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, // LyX puts a % after the end of the minipage if (p.next_token().cat() == catNewline && p.next_token().cs().size() > 1) { // new paragraph - //output_ert_inset(os, "%dummy", parent_context); + //output_comment(p, os, "dummy", parent_context); p.get_token(); p.skip_spaces(); parent_context.new_paragraph(os); } else if (p.next_token().cat() == catSpace || p.next_token().cat() == catNewline) { - //output_ert_inset(os, "%dummy", parent_context); + //output_comment(p, os, "dummy", parent_context); p.get_token(); p.skip_spaces(); // We add a protected space if something real follows @@ -1130,6 +1216,26 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, } #endif } + if (inner_type == "minipage" && (!frame_color.empty() || !background_color.empty())) + active_environments.pop_back(); + if (inner_flags != FLAG_BRACE_LAST && (!frame_color.empty() || !background_color.empty())) { + // in this case we have to eat the the closing brace of the color box + p.get_token().asInput(); // the '}' + } + if (p.next_token().asInput() == "}") { + // in this case we assume that the closing brace is from the box settings + // therefore reset these values for the next box + fboxrule = ""; + fboxsep = ""; + shadow_size = ""; + } + + // all boxes except of Frameless and Shaded require calc + if (!(outer_type.empty() || outer_type == "mbox") && + !((outer_type == "shaded" && inner_type.empty()) || + (outer_type == "minipage" && inner_type == "shaded") || + (outer_type == "parbox" && inner_type == "shaded"))) + preamble.registerAutomaticallyLoadedPackage("calc"); } @@ -1165,8 +1271,7 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer, p.skip_spaces(true); } } - if (outer_type == "shaded" || outer_type == "fbox" - || outer_type == "mbox") { + if (outer_type == "shaded" || outer_type == "mbox") { // These boxes never have an inner box ; } else if (p.next_token().asInput() == "\\parbox") { @@ -1192,14 +1297,14 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer, eat_whitespace(p, os, parent_context, false); } parse_box(p, os, flags, FLAG_END, outer, parent_context, - outer_type, special, inner); + outer_type, special, inner, "", ""); } else { if (inner_flags == FLAG_ITEM) { p.get_token(); eat_whitespace(p, os, parent_context, false); } parse_box(p, os, flags, inner_flags, outer, parent_context, - outer_type, special, inner); + outer_type, special, inner, "", ""); } } @@ -1336,12 +1441,12 @@ void parse_environment(Parser & p, ostream & os, bool outer, if (!opt.empty()) os << "placement " << opt << '\n'; if (contains(opt, "H")) - preamble.registerAutomaticallyLoadedPackage("float"); + preamble.registerAutomaticallyLoadedPackage("float"); else { Floating const & fl = parent_context.textclass.floats() - .getType(unstarred_name); - if (!fl.floattype().empty() && fl.usesFloatPkg()) - preamble.registerAutomaticallyLoadedPackage("float"); + .getType(unstarred_name); + if (!fl.floattype().empty() && fl.usesFloatPkg()) + preamble.registerAutomaticallyLoadedPackage("float"); } os << "wide " << convert(is_starred) @@ -1434,7 +1539,7 @@ void parse_environment(Parser & p, ostream & os, bool outer, parent_context, name, "shaded"); else parse_box(p, os, 0, FLAG_END, outer, parent_context, - "", "", name); + "", "", name, "", ""); p.skip_spaces(); } @@ -1450,15 +1555,17 @@ void parse_environment(Parser & p, ostream & os, bool outer, preamble.registerAutomaticallyLoadedPackage("verbatim"); } - else if (name == "verbatim") { + else if (unstarred_name == "verbatim") { // FIXME: this should go in the generic code that // handles environments defined in layout file that // have "PassThru 1". However, the code over there is // already too complicated for my taste. + string const ascii_name = + (name == "verbatim*") ? "Verbatim*" : "Verbatim"; parent_context.new_paragraph(os); Context context(true, parent_context.textclass, - &parent_context.textclass[from_ascii("Verbatim")]); - string s = p.verbatimEnvironment("verbatim"); + &parent_context.textclass[from_ascii(ascii_name)]); + string s = p.verbatimEnvironment(name); output_ert(os, s, context); p.skip_spaces(); } @@ -1586,6 +1693,7 @@ void parse_environment(Parser & p, ostream & os, bool outer, eat_whitespace(p, os, parent_context, false); parse_outer_box(p, os, FLAG_END, outer, parent_context, name, ""); p.skip_spaces(); + preamble.registerAutomaticallyLoadedPackage("framed"); } else if (name == "lstlisting") { @@ -1784,7 +1892,7 @@ void parse_comment(Parser & p, ostream & os, Token const & t, Context & context) LASSERT(t.cat() == catComment, return); if (!t.cs().empty()) { context.check_layout(os); - output_ert_inset(os, '%' + t.cs(), context); + output_comment(p, os, t.cs(), context); if (p.next_token().cat() == catNewline) { // A newline after a comment line starts a new // paragraph @@ -1967,7 +2075,6 @@ void copy_file(FileName const & src, string dstname) dst = FileName(dstname); else dst = makeAbsPath(dstname, absParent); - string const absMaster = getMasterFilePath(false); FileName const srcpath = src.onlyPath(); FileName const dstpath = dst.onlyPath(); if (equivalent(srcpath, dstpath)) @@ -2360,36 +2467,28 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cat() == catLetter) { context.check_layout(os); - // Workaround for bug 4752. - // FIXME: This whole code block needs to be removed - // when the bug is fixed and tex2lyx produces - // the updated file format. - // The replacement algorithm in LyX is so stupid that - // it even translates a phrase if it is part of a word. - bool handled = false; - for (int const * l = known_phrase_lengths; *l; ++l) { - string phrase = t.cs(); - for (int i = 1; i < *l && p.next_token().isAlnumASCII(); ++i) - phrase += p.get_token().cs(); - if (is_known(phrase, known_coded_phrases)) { - output_ert_inset(os, phrase, context); - handled = true; - break; - } else { - for (size_t i = 1; i < phrase.length(); ++i) - p.putback(); - } - } - if (!handled) - os << t.cs(); + os << t.cs(); } else if (t.cat() == catOther || t.cat() == catAlign || t.cat() == catParameter) { - // This translates "&" to "\\&" which may be wrong... context.check_layout(os); - os << t.cs(); + if (t.asInput() == "-" && p.next_token().asInput() == "-" && + context.merging_hyphens_allowed && + context.font.family != "ttfamily" && + !context.layout->pass_thru) { + if (p.next_next_token().asInput() == "-") { + // --- is emdash + os << to_utf8(docstring(1, 0x2014)); + p.get_token(); + } else + // -- is endash + os << to_utf8(docstring(1, 0x2013)); + p.get_token(); + } else + // This translates "&" to "\\&" which may be wrong... + os << t.cs(); } else if (p.isParagraph()) { @@ -2739,8 +2838,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context.check_layout(os); // FIXME: This is a hack to prevent paragraph // deletion if it is empty. Handle this better! - output_ert_inset(os, - "%dummy comment inserted by tex2lyx to " + output_comment(p, os, + "dummy comment inserted by tex2lyx to " "ensure that this paragraph is not empty", context); // Both measures above may generate an additional @@ -2814,7 +2913,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, // the syntax is \subfloat[list entry][sub caption]{content} // if it is a table of figure depends on the surrounding float // FIXME: second optional argument is not parsed - bool has_caption = false; p.skip_spaces(); // do nothing if there is no outer float if (!float_type.empty()) { @@ -2826,6 +2924,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, << "\nstatus collapsed\n\n"; // test for caption string caption; + bool has_caption = false; if (p.next_token().cat() != catEscape && p.next_token().character() == '[') { p.get_token(); // eat '[' @@ -3145,7 +3244,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "textcolor") { // scheme is \textcolor{color name}{text} string const color = p.verbatim_item(); - // we only support the predefined colors of the color package + // we support the predefined colors of the color and the xcolor package if (color == "black" || color == "blue" || color == "cyan" || color == "green" || color == "magenta" || color == "red" || color == "white" || color == "yellow") { @@ -3155,6 +3254,16 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context.check_layout(os); os << "\n\\color inherit\n"; preamble.registerAutomaticallyLoadedPackage("color"); + } else if (color == "brown" || color == "darkgray" || color == "gray" + || color == "lightgray" || color == "lime" || color == "olive" + || color == "orange" || color == "pink" || color == "purple" + || color == "teal" || color == "violet") { + context.check_layout(os); + os << "\n\\color " << color << "\n"; + parse_text_snippet(p, os, FLAG_ITEM, outer, context); + context.check_layout(os); + os << "\n\\color inherit\n"; + preamble.registerAutomaticallyLoadedPackage("xcolor"); } else // for custom defined colors output_ert_inset(os, t.asInput() + "{" + color + "}", context); @@ -3240,7 +3349,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "textipa") { context.check_layout(os); begin_inset(os, "IPA\n"); + bool merging_hyphens_allowed = context.merging_hyphens_allowed; + context.merging_hyphens_allowed = false; parse_text_in_inset(p, os, FLAG_ITEM, outer, context); + context.merging_hyphens_allowed = merging_hyphens_allowed; end_inset(os); preamble.registerAutomaticallyLoadedPackage("tipa"); preamble.registerAutomaticallyLoadedPackage("tipx"); @@ -3371,20 +3483,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, end_inset(os); } - else if (is_known(t.cs(), known_phrases) || - (t.cs() == "protect" && - p.next_token().cat() == catEscape && - 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. - where = is_known( - t.cs() == "protect" ? p.get_token().cs() : t.cs(), - known_phrases); - context.check_layout(os); - os << known_coded_phrases[where - known_phrases]; - skip_spaces_braces(p); - } - // handle refstyle first to catch \eqref which can also occur // without refstyle. Only recognize these commands if // refstyle.sty was found in the preamble (otherwise \eqref @@ -3652,7 +3750,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context.check_layout(os); begin_inset(os, "script "); os << t.cs().substr(4) << '\n'; - parse_text_in_inset(p, os, FLAG_ITEM, false, context); + newinsetlayout = findInsetLayout(context.textclass, t.cs(), true); + parse_text_in_inset(p, os, FLAG_ITEM, false, context, newinsetlayout); end_inset(os); if (t.cs() == "textsubscript") preamble.registerAutomaticallyLoadedPackage("subscript"); @@ -3795,17 +3894,32 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, p.setEncoding(enc, Encoding::inputenc); } - else if ((where = is_known(t.cs(), known_special_chars))) { + else if (is_known(t.cs(), known_special_chars) || + (t.cs() == "protect" && + p.next_token().cat() == catEscape && + is_known(p.next_token().cs(), known_special_protect_chars))) { + // LyX sometimes puts a \protect in front, so we have to ignore it + where = is_known( + t.cs() == "protect" ? p.get_token().cs() : t.cs(), + known_special_chars); context.check_layout(os); os << known_coded_special_chars[where - known_special_chars]; skip_spaces_braces(p); } else if ((t.cs() == "nobreakdash" && p.next_token().asInput() == "-") || + (t.cs() == "protect" && p.next_token().asInput() == "\\nobreakdash" && + p.next_next_token().asInput() == "-") || (t.cs() == "@" && p.next_token().asInput() == ".")) { + // LyX sometimes puts a \protect in front, so we have to ignore it + if (t.cs() == "protect") + p.get_token(); context.check_layout(os); - os << "\\SpecialChar \\" << t.cs() - << p.get_token().asInput() << '\n'; + if (t.cs() == "nobreakdash") + os << "\\SpecialChar nobreakdash\n"; + else + os << "\\SpecialChar endofsentence\n"; + p.get_token(); } else if (t.cs() == "textquotedbl") { @@ -3819,7 +3933,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, || t.cs() == "%" || t.cs() == "-") { context.check_layout(os); if (t.cs() == "-") - os << "\\SpecialChar \\-\n"; + os << "\\SpecialChar softhyphen\n"; else os << t.cs(); } @@ -4126,7 +4240,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context, "parbox", "shaded"); } else parse_box(p, os, 0, FLAG_ITEM, outer, context, - "", "", t.cs()); + "", "", t.cs(), "", ""); } else if (t.cs() == "fbox" || t.cs() == "mbox" || @@ -4134,6 +4248,52 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, t.cs() == "shadowbox" || t.cs() == "doublebox") parse_outer_box(p, os, FLAG_ITEM, outer, context, t.cs(), ""); + else if (t.cs() == "fcolorbox" || t.cs() == "colorbox") { + string backgroundcolor; + preamble.registerAutomaticallyLoadedPackage("xcolor"); + if (t.cs() == "fcolorbox") { + string const framecolor = p.getArg('{', '}'); + backgroundcolor = p.getArg('{', '}'); + parse_box(p, os, 0, 0, outer, context, "", "", "", framecolor, backgroundcolor); + } else { + backgroundcolor = p.getArg('{', '}'); + parse_box(p, os, 0, 0, outer, context, "", "", "", "", backgroundcolor); + } + } + + // FIXME: due to the compiler limit of "if" nestings + // the code for the alignment was put here + // put them in their own if if this is fixed + else if (t.cs() == "fboxrule" || t.cs() == "fboxsep" + || t.cs() == "shadowsize" + || t.cs() == "raggedleft" || t.cs() == "centering" + || t.cs() == "raggedright") { + if (t.cs() == "fboxrule") + fboxrule = ""; + if (t.cs() == "fboxsep") + fboxsep = ""; + if (t.cs() == "shadowsize") + shadow_size = ""; + if (t.cs() != "raggedleft" && t.cs() != "centering" + && t.cs() != "raggedright") { + p.skip_spaces(true); + while (p.good() && p.next_token().cat() != catSpace + && p.next_token().cat() != catNewline + && p.next_token().cat() != catEscape) { + if (t.cs() == "fboxrule") + fboxrule = fboxrule + p.get_token().asInput(); + if (t.cs() == "fboxsep") + fboxsep = fboxsep + p.get_token().asInput(); + if (t.cs() == "shadowsize") + shadow_size = shadow_size + p.get_token().asInput(); + } + } else { + output_ert_inset(os, t.asInput(), context); + } + } + + //\framebox() is part of the picture environment and different from \framebox{} + //\framebox{} will be parsed by parse_outer_box else if (t.cs() == "framebox") { if (p.next_token().character() == '(') { //the syntax is: \framebox(x,y)[position]{content} @@ -4168,7 +4328,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } else //the syntax is: \makebox[width][position]{content} parse_box(p, os, 0, FLAG_ITEM, outer, context, - "", "", t.cs()); + "", "", t.cs(), "", ""); } else if (t.cs() == "smallskip" || @@ -4597,7 +4757,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, // fromLaTeXCommand() does not yet // recognize tipa short cuts p.get_token(); - name = "\\b"; + name = "\\textsubbar"; } else if (name == "\\textdoublevertline") { // FIXME: This is not correct, // \textvertline is higher than \textbardbl @@ -4664,8 +4824,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, bool termination; docstring rem; set req; - docstring s = encodings.fromLaTeXCommand(from_utf8(name), - Encodings::TEXT_CMD, termination, rem, &req); + docstring s = normalize_c(encodings.fromLaTeXCommand(from_utf8(name), + Encodings::TEXT_CMD, termination, rem, &req)); if (!s.empty()) { context.check_layout(os); os << to_utf8(s);