#include "FloatList.h"
#include "LaTeXPackages.h"
#include "Layout.h"
-#include "Length.h"
#include "Preamble.h"
#include "insets/ExternalTemplate.h"
#include "support/convert.h"
#include "support/FileName.h"
#include "support/filetools.h"
+#include "support/Length.h"
#include "support/lstrings.h"
#include "support/lyxtime.h"
namespace {
-void output_arguments(ostream &, Parser &, bool, bool, string, Context &,
+void output_arguments(ostream &, Parser &, bool, bool, const string &, Context &,
Layout::LaTeXArgMap const &);
}
void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
- Context const & context, InsetLayout const * layout,
- string const rdelim)
+ Context & context, InsetLayout const * layout,
+ string const & rdelim)
{
bool const forcePlainLayout =
layout ? layout->forcePlainLayout() : false;
newcontext.layout = &context.textclass.plainLayout();
else
newcontext.font = context.font;
+ // Inherit commands to pass through
+ newcontext.pass_thru_cmds = context.pass_thru_cmds;
+ // and table cell
+ newcontext.in_table_cell = context.in_table_cell;
if (layout)
output_arguments(os, p, outer, false, string(), newcontext,
layout->latexargs());
output_arguments(os, p, outer, false, "post", newcontext,
layout->postcommandargs());
newcontext.check_end_layout(os);
+ context.cell_align = newcontext.cell_align;
}
void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
Context const & context, string const & name,
- string const rdelim = string())
+ string const & rdelim = string())
{
InsetLayout const * layout = 0;
DocumentClass::InsetLayouts::const_iterator it =
context.textclass.insetLayouts().find(from_ascii(name));
if (it != context.textclass.insetLayouts().end())
layout = &(it->second);
- parse_text_in_inset(p, os, flags, outer, context, layout, rdelim);
+ Context newcontext = context;
+ parse_text_in_inset(p, os, flags, outer, newcontext, layout, rdelim);
}
/// parses a paragraph snippet, useful for example for \\emph{...}
char const * const known_tex_extensions[] = {"tex", 0};
/// spaces known by InsetSpace
-char const * const known_spaces[] = { " ", "space", ",",
-"thinspace", "quad", "qquad", "enspace", "enskip",
-"negthinspace", "negmedspace", "negthickspace", "textvisiblespace",
-"hfill", "dotfill", "hrulefill", "leftarrowfill", "rightarrowfill",
-"upbracefill", "downbracefill", 0};
+char const * const known_spaces[] = { " ", "space",
+",", "thinspace",// \\, = \\thinspace
+"quad", "qquad", "enspace", "enskip",
+";", ">", "medspace",// \\; = \\> = \\medspace
+":", "thickspace",// \\: = \\thickspace
+"!", "negthinspace",// \\! = \\negthinspace
+"negmedspace", "negthickspace",
+"textvisiblespace", "hfill", "dotfill", "hrulefill", "leftarrowfill",
+"rightarrowfill", "upbracefill", "downbracefill", 0};
/// the same as known_spaces with .lyx names
char const * const known_coded_spaces[] = { "space{}", "space{}",
-"thinspace{}", "thinspace{}", "quad{}", "qquad{}", "enspace{}", "enskip{}",
-"negthinspace{}", "negmedspace{}", "negthickspace{}", "textvisiblespace{}",
-"hfill{}", "dotfill{}", "hrulefill{}", "leftarrowfill{}", "rightarrowfill{}",
-"upbracefill{}", "downbracefill{}", 0};
+"thinspace{}", "thinspace{}",
+"quad{}", "qquad{}", "enspace{}", "enskip{}",
+"medspace{}", "medspace{}", "medspace{}",
+"thickspace{}", "thickspace{}",
+"negthinspace{}", "negthinspace{}",
+"negmedspace{}", "negthickspace{}",
+"textvisiblespace{}", "hfill{}", "dotfill{}", "hrulefill{}", "leftarrowfill{}",
+"rightarrowfill{}", "upbracefill{}", "downbracefill{}", 0};
/// known TIPA combining diacritical marks
char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut",
/// If we have ambiguous quotation marks, make a smart guess
/// based on main quote style
-string guessQuoteStyle(string in, bool const opening)
+string guessQuoteStyle(string const & in, bool const opening)
{
string res = in;
if (prefixIs(in, "qr")) {// straight quote
res = "brs";
else if (preamble.quotesStyle() == "french")
res = "frs";
+ else if (preamble.quotesStyle() == "hungarian")
+ res = "hrd";
else if (preamble.quotesStyle() == "swedish")
res = opening ? "sld" : "srd";
} else if (in == "els") {// `
res = "fld";
else if (preamble.quotesStyle() == "russian")
res = "rld";
+ else if (preamble.quotesStyle() == "hungarian")
+ res = "hrs";
} else if (in == "ald") {// <<
if (preamble.quotesStyle() == "swiss")
res = "crd";
res = "frd";
else if (preamble.quotesStyle() == "russian")
res = "rrd";
+ else if (preamble.quotesStyle() == "hungarian")
+ res = "hls";
} else if (in == "ars") {// >
if (preamble.quotesStyle() == "swiss")
res = "cls";
} else if (in == "gld") {// ,,
if (preamble.quotesStyle() == "polish")
res = "pld";
+ else if (preamble.quotesStyle() == "hungarian")
+ res = "hld";
else if (preamble.quotesStyle() == "russian")
res = "rls";
} else if (in == "gls") {// ,
}
-string const fromPolyglossiaEnvironment(string const s)
+string const fromPolyglossiaEnvironment(string const & s)
{
// Since \arabic is taken by the LaTeX kernel,
// the Arabic polyglossia environment is upcased
}
-string uncapitalize(string const s)
+string uncapitalize(string const & s)
{
docstring in = from_ascii(s);
char_type t = lowercase(s[0]);
}
-bool isCapitalized(string const s)
+bool isCapitalized(string const & s)
{
docstring in = from_ascii(s);
char_type t = uppercase(s[0]);
/// try to convert \p s to a valid InsetCommand argument
/// without trying to recode macros.
-string convert_literate_command_inset_arg(string s)
+string convert_literate_command_inset_arg(string const & s)
{
// LyX cannot handle newlines in a latex command
return subst(s, "\n", " ");
void output_ert(ostream & os, string const & s, Context & context)
{
context.check_layout(os);
- for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- if (*it == '\\')
+ for (char const c : s) {
+ if (c == '\\')
os << "\n\\backslash\n";
- else if (*it == '\n') {
+ else if (c == '\n') {
context.new_paragraph(os);
context.check_layout(os);
} else
- os << *it;
+ os << c;
}
context.check_end_layout(os);
}
}
-void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, string const prefix,
+void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, string const & prefix,
Context & context, Layout::LaTeXArgMap const & latexargs)
{
if (context.layout->latextype != LATEX_ITEM_ENVIRONMENT || !prefix.empty()) {
os << "use_makebox " << (inner_type == "makebox") << '\n';
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 special
+ // for values like "1.5\width" LyX uses "1.5in" as width and sets "width" as special
else if (contains(width_unit, '\\'))
os << "width \"" << width_value << "in" << "\"\n";
else
os << "wide " << convert<string>(is_starred)
<< "\nsideways false"
<< "\nstatus open\n\n";
+ set<string> pass_thru_cmds = parent_context.pass_thru_cmds;
+ if (unstarred_name == "algorithm")
+ // in algorithm, \; has special meaning
+ parent_context.pass_thru_cmds.insert(";");
parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+ if (unstarred_name == "algorithm")
+ parent_context.pass_thru_cmds = pass_thru_cmds;
end_inset(os);
// We don't need really a new paragraph, but
// we must make sure that the next item gets a \begin_layout.
eat_whitespace(p, os, parent_context, false);
parent_context.check_layout(os);
begin_inset(os, "IPA\n");
+ set<string> pass_thru_cmds = parent_context.pass_thru_cmds;
+ // These commands have special meanings in IPA
+ parent_context.pass_thru_cmds.insert("!");
+ parent_context.pass_thru_cmds.insert(";");
+ parent_context.pass_thru_cmds.insert(":");
parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+ parent_context.pass_thru_cmds = pass_thru_cmds;
end_inset(os);
p.skip_spaces();
preamble.registerAutomaticallyLoadedPackage("tipa");
}
-void copy_file(FileName const & src, string dstname)
+void copy_file(FileName const & src, string const & dstname)
{
if (!copyFiles())
return;
void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
- Context & context, string const rdelim)
+ Context & context, string const & rdelim)
{
Layout const * newlayout = 0;
InsetLayout const * newinsetlayout = 0;
begin_inset(os, "IPA\n");
bool merging_hyphens_allowed = context.merging_hyphens_allowed;
context.merging_hyphens_allowed = false;
+ set<string> pass_thru_cmds = context.pass_thru_cmds;
+ // These commands have special meanings in IPA
+ context.pass_thru_cmds.insert("!");
+ context.pass_thru_cmds.insert(";");
+ context.pass_thru_cmds.insert(":");
parse_text_in_inset(p, os, FLAG_ITEM, outer, context);
+ context.pass_thru_cmds = pass_thru_cmds;
context.merging_hyphens_allowed = merging_hyphens_allowed;
end_inset(os);
preamble.registerAutomaticallyLoadedPackage("tipa");
continue;
}
+ if (t.cs() == "endgraf" && context.in_table_cell) {
+ context.new_paragraph(os);
+ context.check_layout(os);
+ skip_spaces_braces(p);
+ continue;
+ }
+
if (t.cs() == "input" || t.cs() == "include"
|| t.cs() == "verbatiminput"
|| t.cs() == "lstinputlisting"
// the code for the alignment was put here
// put them in their own if if this is fixed
if (t.cs() == "fboxrule" || t.cs() == "fboxsep"
- || t.cs() == "shadowsize"
- || t.cs() == "raggedleft" || t.cs() == "centering"
- || t.cs() == "raggedright") {
+ || t.cs() == "shadowsize") {
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();
+ }
+ continue;
+ }
+
+ if (t.cs() == "raggedleft" || t.cs() == "centering" || t.cs() == "raggedright") {
+ if (context.in_table_cell) {
+ if (t.cs() == "raggedleft")
+ context.cell_align = 'r';
+ else if (t.cs() == "centering")
+ context.cell_align = 'c';
+ else if (t.cs() == "raggedright")
+ context.cell_align = 'l';
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);
}
continue;
}
- if ((where = is_known(t.cs(), known_spaces))) {
+ if ((where = is_known(t.cs(), known_spaces))
+ && (context.pass_thru_cmds.find(t.cs()) == context.pass_thru_cmds.end())) {
context.check_layout(os);
begin_inset(os, "space ");
os << '\\' << known_coded_spaces[where - known_spaces]
<< '\n';
end_inset(os);
// LaTeX swallows whitespace after all spaces except
- // "\\,". We have to do that here, too, because LyX
+ // "\\,", "\\>", "\\!", "\\;", and "\\:".
+ // We have to do that here, too, because LyX
// adds "{}" which would make the spaces significant.
- if (t.cs() != ",")
+ if (!contains(",>!;:", t.cs()))
eat_whitespace(p, os, context, false);
// LyX adds "{}" after all spaces except "\\ " and
// "\\,", so we have to remove "{}".
if (t.cs() == "newpage" ||
(t.cs() == "pagebreak" && !p.hasOpt()) ||
t.cs() == "clearpage" ||
- t.cs() == "cleardoublepage") {
+ t.cs() == "cleardoublepage" ||
+ t.cs() == "nopagebreak") {
context.check_layout(os);
begin_inset(os, "Newpage ");
os << t.cs();
} else if (unit == "\\bigskipamount") {
unit = "bigskip";
known_vspace = true;
+ } else if (length == "\\baselineskip") {
+ unit = "fullline";
+ known_vspace = true;
} else if (unit == "\\fill") {
unit = "vfill";
known_vspace = true;
}
}
}
+ if (value == 0.5 && t.cs()[0] != 'h' && unit == "\\baselineskip") {
+ unit = "halfline";
+ known_vspace = true;
+ }
if (!known_hspace && !known_vspace) {
switch (unitFromString(unit)) {
case Length::SP: