mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
support for the LaTeX commands \x***arrow
- this patch supports the \x***arrow commands provided by the mathtool package - fileformat change
This commit is contained in:
parent
1e1c2ed1d1
commit
94a9c127e3
@ -85,7 +85,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
|
||||
("1_6", range(277,346), minor_versions("1.6" , 10)),
|
||||
("2_0", range(346,414), minor_versions("2.0", 8)),
|
||||
("2_1", range(414,475), minor_versions("2.1", 0)),
|
||||
("2_2", range(475,478), minor_versions("2.2", 0))
|
||||
("2_2", range(475,479), minor_versions("2.2", 0))
|
||||
]
|
||||
|
||||
####################################################################
|
||||
|
@ -30,7 +30,7 @@ import sys, os
|
||||
# find_token_backwards, is_in_inset, get_value, get_quoted_value, \
|
||||
# del_token, check_token, get_option_value
|
||||
|
||||
#from lyx2lyx_tools import add_to_preamble, insert_to_preamble, \
|
||||
from lyx2lyx_tools import add_to_preamble#, insert_to_preamble, \
|
||||
# put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \
|
||||
# revert_font_attrs, hex2ratio, str2bool
|
||||
|
||||
@ -292,11 +292,52 @@ def revert_swissgerman(document):
|
||||
j = j + 1
|
||||
|
||||
|
||||
def revert_use_package(document, pkg, commands, oldauto):
|
||||
# oldauto defines how the version we are reverting to behaves:
|
||||
# if it is true, the old version uses the package automatically.
|
||||
# if it is false, the old version never uses the package.
|
||||
regexp = re.compile(r'(\\use_package\s+%s)' % pkg)
|
||||
i = find_re(document.header, regexp, 0)
|
||||
value = "1" # default is auto
|
||||
if i != -1:
|
||||
value = get_value(document.header, "\\use_package" , i).split()[1]
|
||||
del document.header[i]
|
||||
if value == "2": # on
|
||||
add_to_preamble(document, ["\\usepackage{" + pkg + "}"])
|
||||
elif value == "1" and not oldauto: # auto
|
||||
i = 0
|
||||
while True:
|
||||
i = find_token(document.body, '\\begin_inset Formula', i)
|
||||
if i == -1:
|
||||
return
|
||||
j = find_end_of_inset(document.body, i)
|
||||
if j == -1:
|
||||
document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
|
||||
i += 1
|
||||
continue
|
||||
code = "\n".join(document.body[i:j])
|
||||
for c in commands:
|
||||
if code.find("\\%s" % c) != -1:
|
||||
add_to_preamble(document, ["\\usepackage{" + pkg + "}"])
|
||||
return
|
||||
i = j
|
||||
|
||||
|
||||
mathtools_commands = ["xhookrightarrow", "xhookleftarrow", "xRightarrow", \
|
||||
"xrightharpoondown", "xrightharpoonup", "xrightleftharpoons", \
|
||||
"xLeftarrow", "xleftharpoondown", "xleftharpoonup", \
|
||||
"xleftrightarrow", "xLeftrightarrow", "xleftrightharpoons", \
|
||||
"xmapsto"]
|
||||
def revert_xarrow(document):
|
||||
"remove use_package mathtools"
|
||||
revert_use_package(document, "mathtools", mathtools_commands, False)
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
|
||||
supported_versions = ["2.2.0","2.2"]
|
||||
supported_versions = ["2.2.0", "2.2"]
|
||||
convert = [
|
||||
[475, [convert_separator]],
|
||||
# nothing to do for 476: We consider it a bug that older versions
|
||||
@ -304,9 +345,11 @@ convert = [
|
||||
# want to hardcode amsmath off.
|
||||
[476, []],
|
||||
[477, []],
|
||||
[478, []]
|
||||
]
|
||||
|
||||
revert = [
|
||||
[477, [revert_xarrow]],
|
||||
[476, [revert_swissgerman]],
|
||||
[475, [revert_smash]],
|
||||
[474, [revert_separator]]
|
||||
|
@ -2127,8 +2127,21 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
|
||||
globals.push_back(from_ascii("\\framebox"));
|
||||
globals.push_back(from_ascii("\\makebox"));
|
||||
globals.push_back(from_ascii("\\kern"));
|
||||
globals.push_back(from_ascii("\\xhookrightarrow"));
|
||||
globals.push_back(from_ascii("\\xhookleftarrow"));
|
||||
globals.push_back(from_ascii("\\xrightarrow"));
|
||||
globals.push_back(from_ascii("\\xRightarrow"));
|
||||
globals.push_back(from_ascii("\\xrightharpoondown"));
|
||||
globals.push_back(from_ascii("\\xrightharpoonup"));
|
||||
globals.push_back(from_ascii("\\xrightleftharpoons"));
|
||||
globals.push_back(from_ascii("\\xleftarrow"));
|
||||
globals.push_back(from_ascii("\\xLeftarrow"));
|
||||
globals.push_back(from_ascii("\\xleftharpoondown"));
|
||||
globals.push_back(from_ascii("\\xleftharpoonup"));
|
||||
globals.push_back(from_ascii("\\xleftrightarrow"));
|
||||
globals.push_back(from_ascii("\\xLeftrightarrow"));
|
||||
globals.push_back(from_ascii("\\xleftrightharpoons"));
|
||||
globals.push_back(from_ascii("\\xmapsto"));
|
||||
globals.push_back(from_ascii("\\split"));
|
||||
globals.push_back(from_ascii("\\gathered"));
|
||||
globals.push_back(from_ascii("\\aligned"));
|
||||
|
@ -80,8 +80,38 @@ void InsetMathXArrow::normalize(NormalStream & os) const
|
||||
|
||||
void InsetMathXArrow::mathmlize(MathStream & ms) const
|
||||
{
|
||||
char const * const arrow = name_ == "xleftarrow"
|
||||
? "←" : "→";
|
||||
char const * arrow;
|
||||
|
||||
if (name_ == "xleftarrow")
|
||||
arrow = "←";
|
||||
else if (name_ == "xrightarrow")
|
||||
arrow = "→";
|
||||
else if (name_ == "xhookleftarrow")
|
||||
arrow = "↩";
|
||||
else if (name_ == "xhookrightarrow")
|
||||
arrow = "↪";
|
||||
else if (name_ == "xLeftarrow")
|
||||
arrow = "⇐";
|
||||
else if (name_ == "xRightarrow")
|
||||
arrow = "⇒";
|
||||
else if (name_ == "xleftrightarrow")
|
||||
arrow = "↔";
|
||||
else if (name_ == "xLeftrightarrow")
|
||||
arrow = "⇔";
|
||||
else if (name_ == "xleftharpoondown")
|
||||
arrow = "↽";
|
||||
else if (name_ == "xleftharpoonup")
|
||||
arrow = "↼";
|
||||
else if (name_ == "xleftrightharpoons")
|
||||
arrow = "⇋";
|
||||
else if (name_ == "xrightharpoondown")
|
||||
arrow = "⇁";
|
||||
else if (name_ == "xrightharpoonup")
|
||||
arrow = "⇀";
|
||||
else if (name_ == "xrightleftharpoons")
|
||||
arrow = "⇌";
|
||||
else if (name_ == "xmapsto")
|
||||
arrow = "↦";
|
||||
ms << "<munderover accent='false' accentunder='false'>"
|
||||
<< arrow << cell(1) << cell(0)
|
||||
<< "</munderover>";
|
||||
@ -90,8 +120,38 @@ void InsetMathXArrow::mathmlize(MathStream & ms) const
|
||||
|
||||
void InsetMathXArrow::htmlize(HtmlStream & os) const
|
||||
{
|
||||
char const * const arrow = name_ == "xleftarrow"
|
||||
? "←" : "→";
|
||||
char const * arrow;
|
||||
|
||||
if (name_ == "xleftarrow")
|
||||
arrow = "←";
|
||||
else if (name_ == "xrightarrow")
|
||||
arrow = "→";
|
||||
else if (name_ == "xhookleftarrow")
|
||||
arrow = "↩";
|
||||
else if (name_ == "xhookrightarrow")
|
||||
arrow = "↪";
|
||||
else if (name_ == "xLeftarrow")
|
||||
arrow = "⇐";
|
||||
else if (name_ == "xRightarrow")
|
||||
arrow = "⇒";
|
||||
else if (name_ == "xleftrightarrow")
|
||||
arrow = "↔";
|
||||
else if (name_ == "xLeftrightarrow")
|
||||
arrow = "⇔";
|
||||
else if (name_ == "xleftharpoondown")
|
||||
arrow = "↽";
|
||||
else if (name_ == "xleftharpoonup")
|
||||
arrow = "↼";
|
||||
else if (name_ == "xleftrightharpoons")
|
||||
arrow = "⇋";
|
||||
else if (name_ == "xrightharpoondown")
|
||||
arrow = "⇁";
|
||||
else if (name_ == "xrightharpoonup")
|
||||
arrow = "⇀";
|
||||
else if (name_ == "xrightleftharpoons")
|
||||
arrow = "⇌";
|
||||
else if (name_ == "xmapsto")
|
||||
arrow = "↦";
|
||||
os << MTag("span", "class='xarrow'")
|
||||
<< MTag("span", "class='xatop'") << cell(0) << ETag("span")
|
||||
<< MTag("span", "class='xabottom'") << arrow << ETag("span")
|
||||
@ -101,7 +161,10 @@ void InsetMathXArrow::htmlize(HtmlStream & os) const
|
||||
|
||||
void InsetMathXArrow::validate(LaTeXFeatures & features) const
|
||||
{
|
||||
features.require("amsmath");
|
||||
if (name_ == "xleftarrow" || name_ == "xrightarrow")
|
||||
features.require("amsmath");
|
||||
else
|
||||
features.require("mathtools");
|
||||
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
||||
// CSS adapted from eLyXer
|
||||
features.addCSSSnippet(
|
||||
|
@ -466,7 +466,14 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
|
||||
|
||||
if (s == "Diagram")
|
||||
return MathAtom(new InsetMathDiagram(buf));
|
||||
if (s == "xrightarrow" || s == "xleftarrow")
|
||||
if (s == "xrightarrow" || s == "xleftarrow" ||
|
||||
s == "xhookrightarrow" || s == "xhookleftarrow" ||
|
||||
s == "xRightarrow" || s == "xLeftarrow" ||
|
||||
s == "xleftrightarrow" || s == "xLeftrightarrow" ||
|
||||
s == "xrightharpoondown" || s == "xrightharpoonup" ||
|
||||
s == "xleftharpoondown" || s == "xleftharpoonup" ||
|
||||
s == "xleftrightharpoons" || s == "xrightleftharpoons" ||
|
||||
s == "xmapsto")
|
||||
return MathAtom(new InsetMathXArrow(buf, s));
|
||||
if (s == "split" || s == "alignedat")
|
||||
return MathAtom(new InsetMathSplit(buf, s));
|
||||
|
@ -1492,6 +1492,18 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
||||
}
|
||||
|
||||
else if (t.cs() == "xhookrightarrow" || t.cs() == "xhookleftarrow" ||
|
||||
t.cs() == "xRightarrow" || t.cs() == "xLeftarrow" ||
|
||||
t.cs() == "xleftrightarrow" || t.cs() == "xLeftrightarrow" ||
|
||||
t.cs() == "xrightharpoondown" || t.cs() == "xrightharpoonup" ||
|
||||
t.cs() == "xleftharpoondown" || t.cs() == "xleftharpoonup" ||
|
||||
t.cs() == "xleftrightharpoons" || t.cs() == "xrightleftharpoons" ||
|
||||
t.cs() == "xmapsto") {
|
||||
cell->push_back(createInsetMath(t.cs(), buf));
|
||||
parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
|
||||
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
||||
}
|
||||
|
||||
else if (t.cs() == "ref" || t.cs() == "eqref" || t.cs() == "prettyref"
|
||||
|| t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") {
|
||||
cell->push_back(MathAtom(new InsetMathRef(buf, t.cs())));
|
||||
|
@ -113,6 +113,95 @@ double const brace[] = {
|
||||
};
|
||||
|
||||
|
||||
double const mapsto[] = {
|
||||
2, 3,
|
||||
0.75, 0.015, 0.95, 0.5, 0.75, 0.985,
|
||||
1, 0.015, 0.475, 0.945, 0.475,
|
||||
1, 0.015, 0.015, 0.015, 0.985,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const lhook[] = {
|
||||
2, 3,
|
||||
0.25, 0.015, 0.05, 0.5, 0.25, 0.985,
|
||||
1, 0.015, 0.475, 0.7, 0.475,
|
||||
2, 5,
|
||||
0.7, 0.015, 0.825, 0.15, 0.985, 0.25,
|
||||
0.825, 0.35, 0.7, 0.475,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const rhook[] = {
|
||||
2, 3,
|
||||
0.75, 0.015, 0.95, 0.5, 0.75, 0.985,
|
||||
1, 0.3, 0.475, 0.985, 0.475,
|
||||
2, 5,
|
||||
0.3, 0.015, 0.175, 0.15, 0.05, 0.25,
|
||||
0.175, 0.35, 0.3, 0.475,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const LRArrow[] = {
|
||||
2, 3,
|
||||
0.25, 0.015, 0.05, 0.5, 0.25, 0.985,
|
||||
2, 3,
|
||||
0.75, 0.015, 0.95, 0.5, 0.75, 0.985,
|
||||
1, 0.2, 0.8, 0.8, 0.8,
|
||||
1, 0.2, 0.2, 0.8, 0.2,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const LArrow[] = {
|
||||
2, 3,
|
||||
0.25, 0.015, 0.05, 0.5, 0.25, 0.985,
|
||||
1, 0.2, 0.8, 0.985, 0.8,
|
||||
1, 0.2, 0.2, 0.985, 0.2,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const lharpoondown[] = {
|
||||
2, 2,
|
||||
0.015, 0.5, 0.25, 0.985,
|
||||
1, 0.02, 0.475, 0.985, 0.475,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const lharpoonup[] = {
|
||||
2, 2,
|
||||
0.25, 0.015, 0.015, 0.5,
|
||||
1, 0.02, 0.525, 0.985, 0.525,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const lrharpoons[] = {
|
||||
2, 2,
|
||||
0.25, 0.015, 0.015, 0.225,
|
||||
1, 0.02, 0.23, 0.985, 0.23,
|
||||
2, 2,
|
||||
0.75, 0.985, 0.985, 0.775,
|
||||
1, 0.02, 0.7, 0.980, 0.7,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const rlharpoons[] = {
|
||||
2, 2,
|
||||
0.75, 0.015, 0.985, 0.225,
|
||||
1, 0.02, 0.23, 0.985, 0.23,
|
||||
2, 2,
|
||||
0.25, 0.985, 0.015, 0.775,
|
||||
1, 0.02, 0.7, 0.980, 0.7,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
double const arrow[] = {
|
||||
4, 7,
|
||||
0.0150, 0.7500, 0.2000, 0.6000, 0.3500, 0.3500,
|
||||
@ -283,23 +372,36 @@ struct named_deco_struct {
|
||||
|
||||
named_deco_struct deco_table[] = {
|
||||
// Decorations
|
||||
{"widehat", angle, 3 },
|
||||
{"widetilde", tilde, 0 },
|
||||
{"underbar", hline, 0 },
|
||||
{"underline", hline, 0 },
|
||||
{"overline", hline, 0 },
|
||||
{"underbrace", brace, 1 },
|
||||
{"overbrace", brace, 3 },
|
||||
{"overleftarrow", arrow, 1 },
|
||||
{"overrightarrow", arrow, 3 },
|
||||
{"overleftrightarrow", udarrow, 1 },
|
||||
{"xleftarrow", arrow, 1 },
|
||||
{"xrightarrow", arrow, 3 },
|
||||
{"underleftarrow", arrow, 1 },
|
||||
{"underrightarrow", arrow, 3 },
|
||||
{"underleftrightarrow", udarrow, 1 },
|
||||
{"undertilde", tilde, 0 },
|
||||
{"utilde", tilde, 0 },
|
||||
{"widehat", angle, 3 },
|
||||
{"widetilde", tilde, 0 },
|
||||
{"underbar", hline, 0 },
|
||||
{"underline", hline, 0 },
|
||||
{"overline", hline, 0 },
|
||||
{"underbrace", brace, 1 },
|
||||
{"overbrace", brace, 3 },
|
||||
{"overleftarrow", arrow, 1 },
|
||||
{"overrightarrow", arrow, 3 },
|
||||
{"overleftrightarrow", udarrow, 1 },
|
||||
{"xhookleftarrow", lhook, 0 },
|
||||
{"xhookrightarrow", rhook, 0 },
|
||||
{"xleftarrow", arrow, 1 },
|
||||
{"xLeftarrow", LArrow, 0 },
|
||||
{"xleftharpoondown", lharpoondown, 0 },
|
||||
{"xleftharpoonup", lharpoonup, 0 },
|
||||
{"xleftrightharpoons", lrharpoons, 0 },
|
||||
{"xleftrightarrow", udarrow, 1 },
|
||||
{"xLeftrightarrow", LRArrow, 0 },
|
||||
{"xmapsto", mapsto, 0 },
|
||||
{"xrightarrow", arrow, 3 },
|
||||
{"xRightarrow", LArrow, 2 },
|
||||
{"xrightharpoondown", lharpoonup, 2 },
|
||||
{"xrightharpoonup", lharpoondown, 2 },
|
||||
{"xrightleftharpoons", rlharpoons, 0 },
|
||||
{"underleftarrow", arrow, 1 },
|
||||
{"underrightarrow", arrow, 3 },
|
||||
{"underleftrightarrow", udarrow, 1 },
|
||||
{"undertilde", tilde, 0 },
|
||||
{"utilde", tilde, 0 },
|
||||
|
||||
// Delimiters
|
||||
{"(", parenth, 0 },
|
||||
|
@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// independent branches. Instead add your own.
|
||||
#define LYX_FORMAT_LYX 477 // spitz: support for swissgerman
|
||||
#define LYX_FORMAT_TEX2LYX 477
|
||||
#define LYX_FORMAT_LYX 478 // uwestoehr: mathtools' x***arrow commands
|
||||
#define LYX_FORMAT_TEX2LYX 478
|
||||
|
||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||
#ifndef _MSC_VER
|
||||
|
Loading…
Reference in New Issue
Block a user