}
-void handle_backslash(ostream & os, string const & s)
+void output_ert(ostream & os, string const & s, Context & context)
{
- for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- if (*it == '\\')
- os << "\n\\backslash\n";
- else
- os << *it;
- }
-}
-
-
-void handle_ert(ostream & os, string const & s, Context & context)
-{
- // We must have a valid layout before outputting the ERT inset.
context.check_layout(os);
- Context newcontext(true, context.textclass);
- InsetLayout const & layout = context.textclass.insetLayout(from_ascii("ERT"));
- if (layout.forcePlainLayout())
- newcontext.layout = &context.textclass.plainLayout();
- begin_inset(os, "ERT");
- os << "\nstatus collapsed\n";
- newcontext.check_layout(os);
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
if (*it == '\\')
os << "\n\\backslash\n";
else if (*it == '\n') {
- newcontext.new_paragraph(os);
- newcontext.check_layout(os);
+ context.new_paragraph(os);
+ context.check_layout(os);
} else
os << *it;
}
- newcontext.check_end_layout(os);
- end_inset(os);
+ context.check_end_layout(os);
}
-void handle_comment(ostream & os, string const & s, Context & context)
+void output_ert_inset(ostream & os, string const & s, Context & context)
{
- // TODO: Handle this better
+ // We must have a valid layout before outputting the ERT inset.
+ context.check_layout(os);
Context newcontext(true, context.textclass);
InsetLayout const & layout = context.textclass.insetLayout(from_ascii("ERT"));
if (layout.forcePlainLayout())
newcontext.layout = &context.textclass.plainLayout();
begin_inset(os, "ERT");
os << "\nstatus collapsed\n";
- newcontext.check_layout(os);
- handle_backslash(os, s);
- // make sure that our comment is the last thing on the line
- newcontext.new_paragraph(os);
- newcontext.check_layout(os);
- newcontext.check_end_layout(os);
+ output_ert(os, s, newcontext);
end_inset(os);
}
case required:
case req_group:
// This argument contains regular LaTeX
- handle_ert(os, ert + '{', context);
+ output_ert_inset(os, ert + '{', context);
eat_whitespace(p, os, context, false);
if (template_arguments[i] == required)
parse_text(p, os, FLAG_ITEM, outer, context);
break;
}
}
- handle_ert(os, ert, context);
+ output_ert_inset(os, ert, context);
}
}
if (inner_type == "shaded")
ss << "\\begin{shaded}";
- handle_ert(os, ss.str(), parent_context);
+ output_ert_inset(os, ss.str(), parent_context);
if (!inner_type.empty()) {
parse_text(p, os, inner_flags, outer, parent_context);
if (inner_flags & FLAG_END)
- handle_ert(os, "\\end{" + inner_type + '}',
+ output_ert_inset(os, "\\end{" + inner_type + '}',
parent_context);
else
- handle_ert(os, "}", parent_context);
+ output_ert_inset(os, "}", parent_context);
}
if (!outer_type.empty()) {
// If we already read the inner box we have to pop
}
parse_text(p, os, outer_flags, outer, parent_context);
if (outer_flags & FLAG_END)
- handle_ert(os, "\\end{" + outer_type + '}',
+ output_ert_inset(os, "\\end{" + outer_type + '}',
parent_context);
else if (inner_type.empty() && outer_type == "framebox")
// in this case it is already closed later
;
else
- handle_ert(os, "}", parent_context);
+ output_ert_inset(os, "}", parent_context);
}
} else {
// LyX does not like empty positions, so we have
// LyX puts a % after the end of the minipage
if (p.next_token().cat() == catNewline && p.next_token().cs().size() > 1) {
// new paragraph
- //handle_comment(os, "%dummy", parent_context);
+ //output_ert_inset(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) {
- //handle_comment(os, "%dummy", parent_context);
+ //output_ert_inset(os, "%dummy", parent_context);
p.get_token();
p.skip_spaces();
// We add a protected space if something real follows
context.layout = &parent_context.textclass.plainLayout();
string s;
if (in_line) {
- s = p.plainCommand('!', '!', "lstinline");
- context.new_paragraph(os);
- context.check_layout(os);
+ // set catcodes to verbatim early, just in case.
+ p.setCatcodes(VERBATIM_CATCODES);
+ string delim = p.get_token().asInput();
+ s = p.verbatimStuff(delim);
+// context.new_paragraph(os);
} else
- s = p.plainEnvironment("lstlisting");
- for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- if (*it == '\\')
- os << "\n\\backslash\n";
- else if (*it == '\n') {
- // avoid adding an empty paragraph at the end
- if (it + 1 != et) {
- context.new_paragraph(os);
- context.check_layout(os);
- }
- } else
- os << *it;
- }
- context.check_end_layout(os);
+ s = p.verbatimEnvironment("lstlisting");
+ output_ert(os, s, context);
end_inset(os);
}
bool const new_layout_allowed = parent_context.new_layout_allowed;
if (specialfont)
parent_context.new_layout_allowed = false;
- handle_ert(os, "\\begin{" + name + "}", parent_context);
+ output_ert_inset(os, "\\begin{" + name + "}", parent_context);
parse_text_snippet(p, os, flags, outer, parent_context);
- handle_ert(os, "\\end{" + name + "}", parent_context);
+ output_ert_inset(os, "\\end{" + name + "}", parent_context);
if (specialfont)
parent_context.new_layout_allowed = new_layout_allowed;
}
else if (name == "verbatim") {
// FIXME: this should go in the generic code that
// handles environments defined in layout file that
- // have "PassThru 1". However, the code there is
+ // have "PassThru 1". However, the code over there is
// already too complicated for my taste.
parent_context.new_paragraph(os);
Context context(true, parent_context.textclass,
- &parent_context.textclass[from_ascii("Verbatim")]);
- context.check_layout(os);
- string s = p.verbatimStuff("\\end{verbatim}");
- // ignore one newline at beginning or end of string
- if (prefixIs(s, "\n"))
- s.erase(0,1);
- if (suffixIs(s, "\n"))
- s.erase(s.length(),1);
-
- string::const_iterator it2 = s.begin();
- for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- context.check_layout(os);
- if (*it == '\\') {
- os << "\n\\backslash\n";
- context.need_end_layout = true;
- } else if (*it == '\n') {
- context.new_paragraph(os);
- } else {
- os << *it;
- context.need_end_layout = true;
- }
- }
- context.new_paragraph(os);
+ &parent_context.textclass[from_ascii("Verbatim")]);
+ string s = p.verbatimEnvironment("verbatim");
+ output_ert(os, s, context);
p.skip_spaces();
}
bool knownMapping = mapping == preamble.fontCJK();
if (buggy_encoding || !knownMapping || !where) {
parent_context.check_layout(os);
- handle_ert(os, "\\begin{" + name + "}{" + encoding + "}{" + mapping + "}",
+ output_ert_inset(os, "\\begin{" + name + "}{" + encoding + "}{" + mapping + "}",
parent_context);
// we must parse the content as verbatim because e.g. JIS can contain
// normally invalid characters
string const s = p.plainEnvironment("CJK");
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
if (*it == '\\')
- handle_ert(os, "\\", parent_context);
+ output_ert_inset(os, "\\", parent_context);
else if (*it == '$')
- handle_ert(os, "$", parent_context);
+ output_ert_inset(os, "$", parent_context);
else
os << *it;
}
- handle_ert(os, "\\end{" + name + "}",
+ output_ert_inset(os, "\\end{" + name + "}",
parent_context);
} else {
string const lang =
parse_arguments("\\begin{" + name + "}", arguments, p, os,
outer, parent_context);
if (contents == verbatim)
- handle_ert(os, p.ertEnvironment(name),
+ output_ert_inset(os, p.ertEnvironment(name),
parent_context);
else
parse_text_snippet(p, os, FLAG_END, outer,
parent_context);
- handle_ert(os, "\\end{" + name + "}", parent_context);
+ output_ert_inset(os, "\\end{" + name + "}", parent_context);
if (specialfont)
parent_context.new_layout_allowed = new_layout_allowed;
}
LASSERT(t.cat() == catComment, return);
if (!t.cs().empty()) {
context.check_layout(os);
- handle_comment(os, '%' + t.cs(), context);
+ output_ert_inset(os, '%' + t.cs(), context);
if (p.next_token().cat() == catNewline) {
// A newline after a comment line starts a new
// paragraph
// done (we might get called recursively)
context.new_paragraph(os);
} else
- handle_ert(os, "\n", context);
+ output_ert_inset(os, "\n", context);
eat_whitespace(p, os, context, true);
}
} else {
os << "\n\\def" << ert;
end_inset(os);
} else
- handle_ert(os, command + ert, context);
+ output_ert_inset(os, command + ert, context);
}
else
cerr << "Warning: Inserting missing ']' in '"
<< s << "'." << endl;
- handle_ert(os, s, context);
+ output_ert_inset(os, s, context);
}
else if (t.cat() == catLetter) {
for (int i = 1; i < *l && p.next_token().isAlnumASCII(); ++i)
phrase += p.get_token().cs();
if (is_known(phrase, known_coded_phrases)) {
- handle_ert(os, phrase, context);
+ output_ert_inset(os, phrase, context);
handled = true;
break;
} else {
if (context.new_layout_allowed)
context.new_paragraph(os);
else
- handle_ert(os, "\\par ", context);
+ output_ert_inset(os, "\\par ", context);
eat_whitespace(p, os, context, true);
}
p.next_token().character() == '-'))
; // ignore it in {}`` or -{}-
else
- handle_ert(os, "{}", context);
+ output_ert_inset(os, "{}", context);
} else if (next.cat() == catEscape &&
is_known(next.cs(), known_quotes) &&
end.cat() == catEnd) {
p.get_token();
} else {
p.putback();
- handle_ert(os, "{", context);
+ output_ert_inset(os, "{", context);
parse_text_snippet(p, os,
FLAG_BRACE_LAST,
outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
}
} else if (! context.new_layout_allowed) {
- handle_ert(os, "{", context);
+ output_ert_inset(os, "{", context);
parse_text_snippet(p, os, FLAG_BRACE_LAST,
outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
} else if (is_known(next.cs(), known_sizes)) {
// next will change the size, so we must
// reset it here
<< "\n\\shape "
<< context.font.shape << "\n";
} else {
- handle_ert(os, "{", context);
+ output_ert_inset(os, "{", context);
parse_text_snippet(p, os, FLAG_BRACE_LAST,
outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
}
}
}
return;
}
cerr << "stray '}' in text\n";
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
}
else if (t.cat() == catComment)
// FIXME: Do this in check_layout()!
context.has_item = false;
if (optarg)
- handle_ert(os, "\\item", context);
+ output_ert_inset(os, "\\item", context);
else
- handle_ert(os, "\\item ", context);
+ output_ert_inset(os, "\\item ", context);
}
if (optarg) {
if (context.layout->labeltype != LABEL_MANUAL) {
// would misinterpret the space as
// item delimiter (bug 7663)
if (contains(s, ' ')) {
- handle_ert(os, s, context);
+ output_ert_inset(os, s, context);
} else {
Parser p2(s + ']');
os << parse_text_snippet(p2,
string key = convert_command_inset_arg(p.verbatim_item());
if (contains(label, '\\') || contains(key, '\\')) {
// LyX can't handle LaTeX commands in labels or keys
- handle_ert(os, t.asInput() + '[' + label +
+ output_ert_inset(os, t.asInput() + '[' + label +
"]{" + p.verbatim_item() + '}',
context);
} else {
context.check_layout(os);
// FIXME: This is a hack to prevent paragraph
// deletion if it is empty. Handle this better!
- handle_comment(os,
+ output_ert_inset(os,
"%dummy comment inserted by tex2lyx to "
"ensure that this paragraph is not empty",
context);
for (; it != en; ++it)
preamble.registerAutomaticallyLoadedPackage(*it);
} else
- handle_ert(os,
+ output_ert_inset(os,
"\\date{" + p.verbatim_item() + '}',
context);
}
// output it as ERT
if (p.hasOpt()) {
string opt_arg = convert_command_inset_arg(p.getArg('[', ']'));
- handle_ert(os, t.asInput() + '[' + opt_arg +
+ output_ert_inset(os, t.asInput() + '[' + opt_arg +
"]{" + p.verbatim_item() + '}', context);
} else
- handle_ert(os, t.asInput() + "{" + p.verbatim_item() + '}', context);
+ output_ert_inset(os, t.asInput() + "{" + p.verbatim_item() + '}', context);
}
}
if (s == "\xb1" || s == "\xb3" || s == "\xb2" || s == "\xb5")
os << s;
else
- handle_ert(os, "\\ensuremath{" + s + "}",
+ output_ert_inset(os, "\\ensuremath{" + s + "}",
context);
}
// swallow this
skip_spaces_braces(p);
} else
- handle_ert(os, t.asInput(), context);
+ output_ert_inset(os, t.asInput(), context);
}
else if (t.cs() == "tableofcontents" || t.cs() == "lstlistoflistings") {
end_inset(os);
p.get_token(); // swallow second arg
} else
- handle_ert(os, "\\listof{" + name + "}", context);
+ output_ert_inset(os, "\\listof{" + name + "}", context);
}
else if ((where = is_known(t.cs(), known_text_font_families)))
preamble.registerAutomaticallyLoadedPackage("color");
} else
// for custom defined colors
- handle_ert(os, t.asInput() + "{" + color + "}", context);
+ output_ert_inset(os, t.asInput() + "{" + color + "}", context);
}
else if (t.cs() == "underbar" || t.cs() == "uline") {
preamble.registerAutomaticallyLoadedPackage("varioref");
} else {
// LyX does not yet support optional arguments of ref commands
- handle_ert(os, t.asInput() + '[' + opt + "]{" +
+ output_ert_inset(os, t.asInput() + '[' + opt + "]{" +
p.verbatim_item() + "}", context);
}
}
context, "\\lang",
context.font.language, lang);
} else
- handle_ert(os, t.asInput() + langopts, context);
+ output_ert_inset(os, t.asInput() + langopts, context);
} else {
lang = preamble.polyglossia2lyx(t.cs().substr(4, string::npos));
parse_text_attributes(p, os, FLAG_ITEM, outer,
os << '"';
skip_braces(p);
} else {
- handle_ert(os, "\\char`", context);
+ output_ert_inset(os, "\\char`", context);
}
} else {
- handle_ert(os, "\\char", context);
+ output_ert_inset(os, "\\char", context);
}
}
p.setCatcodes(VERBATIM_CATCODES);
string delim = p.get_token().asInput();
string const arg = p.verbatimStuff(delim);
- handle_ert(os, "\\verb" + delim + arg + delim, context);
+ output_ert_inset(os, "\\verb" + delim + arg + delim, context);
}
// Problem: \= creates a tabstop inside the tabbing environment
// and else an accent. In the latter case we really would want
// \={o} instead of \= o.
else if (t.cs() == "=" && (flags & FLAG_TABBING))
- handle_ert(os, t.asInput(), context);
+ output_ert_inset(os, t.asInput(), context);
// accents (see Table 6 in Comprehensive LaTeX Symbol List)
else if (t.cs().size() == 1
preamble.registerAutomaticallyLoadedPackage(*it);
} else
// we did not find a non-ert version
- handle_ert(os, command, context);
+ output_ert_inset(os, command, context);
}
else if (t.cs() == "\\") {
context.check_layout(os);
if (p.hasOpt())
- handle_ert(os, "\\\\" + p.getOpt(), context);
+ output_ert_inset(os, "\\\\" + p.getOpt(), context);
else if (p.next_token().asInput() == "*") {
p.get_token();
// getOpt() eats the following space if there
// is no optional argument, but that is OK
// here since it has no effect in the output.
- handle_ert(os, "\\\\*" + p.getOpt(), context);
+ output_ert_inset(os, "\\\\*" + p.getOpt(), context);
}
else {
begin_inset(os, "Newline newline");
}
p.popPosition();
if (output) {
- handle_ert(os,
+ output_ert_inset(os,
"\\bibliographystyle{" + bibliographystyle + '}',
context);
}
arg += p.getFullParentheseArg();
arg += p.getFullOpt();
eat_whitespace(p, os, context, false);
- handle_ert(os, arg + '{', context);
+ output_ert_inset(os, arg + '{', context);
parse_text(p, os, FLAG_ITEM, outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
} else {
string special = p.getFullOpt();
special += p.getOpt();
context, t.cs(), special);
else {
eat_whitespace(p, os, context, false);
- handle_ert(os, "\\framebox{", context);
+ output_ert_inset(os, "\\framebox{", context);
parse_text(p, os, FLAG_ITEM, outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
}
}
}
arg += p.getFullParentheseArg();
arg += p.getFullOpt();
eat_whitespace(p, os, context, false);
- handle_ert(os, arg + '{', context);
+ output_ert_inset(os, arg + '{', context);
parse_text(p, os, FLAG_ITEM, outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
} else
//the syntax is: \makebox[width][position]{content}
parse_box(p, os, 0, FLAG_ITEM, outer, context,
t.cs() == "providecommand" ||
t.cs() == "providecommandx" ||
name[name.length()-1] == '*')
- handle_ert(os, ert, context);
+ output_ert_inset(os, ert, context);
else {
context.check_layout(os);
begin_inset(os, "FormulaMacro");
CommandMap::iterator it = known_commands.find(command);
if (it != known_commands.end())
known_commands[t.asInput()] = it->second;
- handle_ert(os, ert, context);
+ output_ert_inset(os, ert, context);
}
else if (t.cs() == "hspace" || t.cs() == "vspace") {
name += '*';
if (valid) {
if (value == 1.0)
- handle_ert(os, name + '{' + unit + '}', context);
+ output_ert_inset(os, name + '{' + unit + '}', context);
else if (value == -1.0)
- handle_ert(os, name + "{-" + unit + '}', context);
+ output_ert_inset(os, name + "{-" + unit + '}', context);
else
- handle_ert(os, name + '{' + valstring + unit + '}', context);
+ output_ert_inset(os, name + '{' + valstring + unit + '}', context);
} else
- handle_ert(os, name + '{' + length + '}', context);
+ output_ert_inset(os, name + '{' + length + '}', context);
}
}
z = p.verbatim_item();
}
cerr << "found ERT: " << s << endl;
- handle_ert(os, s + ' ', context);
+ output_ert_inset(os, s + ' ', context);
*/
else {
string name = t.asInput();
name += '*';
}
if (!parse_command(name, p, os, outer, context))
- handle_ert(os, name, context);
+ output_ert_inset(os, name, context);
}
}