# 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
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
# want to hardcode amsmath off.
[476, []],
[477, []],
+ [478, []]
]
revert = [
+ [477, [revert_xarrow]],
[476, [revert_swissgerman]],
[475, [revert_smash]],
[474, [revert_separator]]
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>";
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")
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(
};
+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,
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 },