commit e3c1fc2ad522d917ca4b9c09527eb1882c199c9b
Author: Thibaut Cuvelier <[email protected]>
Date:   Mon Jan 4 22:36:01 2021 +0100

    Implement \case for AASTeX.
---
 src/LaTeXFeatures.cpp        |    8 ++++++++
 src/mathed/InsetMathFrac.cpp |   28 ++++++++++++++++++++++------
 src/mathed/InsetMathFrac.h   |    1 +
 src/mathed/MathFactory.cpp   |    2 ++
 4 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 95a1a6d..3acbe41 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -73,6 +73,11 @@ static docstring const lyxarrow_def = from_ascii(
        "{\\leavevmode\\,$\\triangleleft$\\,\\allowbreak}\n"
        "{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}}");
 
+static docstring const aastex_case_def = from_ascii(
+               "\\providecommand\\case[2]{\\mbox{$\\frac{#1}{#2}$}}%");
+// Copied from 
https://github.com/AASJournals/AASTeX60/blob/master/cls/aastex63.cls#L1645
+// Adapted to providecommand for compatibility reasons.
+
 // ZERO WIDTH SPACE (ZWSP) is actually not a space character
 // but marks a line break opportunity. Several commands provide a
 // line break opportunity. They differ in side-effects:
@@ -1558,6 +1563,9 @@ TexString LaTeXFeatures::getMacros() const
        if (mustProvide("lyxarrow"))
                macros << lyxarrow_def << '\n';
 
+       if (mustProvide("aastex_case"))
+               macros << aastex_case_def << '\n';
+
        if (mustProvide("lyxzerowidthspace"))
                macros << lyxZWSP_def << '\n';
 
diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp
index 3719904..2ad44fc 100644
--- a/src/mathed/InsetMathFrac.cpp
+++ b/src/mathed/InsetMathFrac.cpp
@@ -140,6 +140,7 @@ MathClass InsetMathFrac::mathClass() const
        case CFRAC:
        case CFRACLEFT:
        case CFRACRIGHT:
+       case AASTEX_CASE:
                mc = MC_INNER;
                break;
        case NICEFRAC:
@@ -239,7 +240,8 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & 
dim) const
        case DFRAC:
        case TFRAC:
        case OVER:
-       case ATOP: {
+       case ATOP:
+       case AASTEX_CASE: {
                int const dy = axis_height(mi.base);
                Changer dummy =
                        // \tfrac is always in text size
@@ -248,7 +250,8 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & 
dim) const
                        (kind_ == CFRAC
                         || kind_ == CFRACLEFT
                         || kind_ == CFRACRIGHT
-                        || kind_ == DFRAC) ? 
mi.base.font.changeStyle(DISPLAY_STYLE) :
+                        || kind_ == DFRAC
+                        || kind_ == AASTEX_CASE) ? 
mi.base.font.changeStyle(DISPLAY_STYLE) :
                        // all others
                                              mi.base.changeFrac();
                Changer dummy2 = mi.base.changeEnsureMath();
@@ -321,7 +324,8 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) 
const
        case DFRAC:
        case TFRAC:
        case OVER:
-       case ATOP: {
+       case ATOP:
+       case AASTEX_CASE: {
                int const dy = axis_height(pi.base);
                Changer dummy =
                        // \tfrac is always in text size
@@ -330,7 +334,8 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) 
const
                        (kind_ == CFRAC
                         || kind_ == CFRACLEFT
                         || kind_ == CFRACRIGHT
-                        || kind_ == DFRAC) ? 
pi.base.font.changeStyle(DISPLAY_STYLE) :
+                        || kind_ == DFRAC
+                        || kind_ == AASTEX_CASE) ? 
pi.base.font.changeStyle(DISPLAY_STYLE) :
                        // all others
                                              pi.base.changeFrac();
                Dimension const dim1 = cell(1).dimension(*pi.base.bv);
@@ -422,6 +427,9 @@ void InsetMathFrac::write(TeXMathStream & os) const
        case CFRACRIGHT:
                os << "\\cfrac[r]{" << cell(0) << "}{" << cell(1) << '}';
                break;
+       case AASTEX_CASE:
+               os << "\\case{" << cell(0) << "}{" << cell(1) << '}';
+               break;
        }
 }
 
@@ -449,9 +457,11 @@ docstring InsetMathFrac::name() const
                return from_ascii("unit");
        case ATOP:
                return from_ascii("atop");
+       case AASTEX_CASE:
+               return from_ascii("case");
+       default:
+               return docstring();
        }
-       // shut up stupid compiler
-       return docstring();
 }
 
 
@@ -509,6 +519,7 @@ void InsetMathFrac::mathmlize(MathMLStream & ms) const
        case CFRAC:
        case CFRACLEFT:
        case CFRACRIGHT:
+       case AASTEX_CASE:
                ms << MTag("mfrac")
                   << MTag("mrow") << cell(0) << ETag("mrow")
                   << MTag("mrow") << cell(1) << ETag("mrow")
@@ -565,6 +576,7 @@ void InsetMathFrac::htmlize(HtmlStream & os) const
        case CFRAC:
        case CFRACLEFT:
        case CFRACRIGHT:
+       case AASTEX_CASE:
                os << MTag("span", "class='frac'")
                         << MTag("span", "class='numer'") << cell(0) << 
ETag("span")
                         << MTag("span", "class='denom'") << cell(1) << 
ETag("span")
@@ -604,12 +616,16 @@ void InsetMathFrac::validate(LaTeXFeatures & features) 
const
        if (kind_ == CFRAC || kind_ == CFRACLEFT || kind_ == CFRACRIGHT
                  || kind_ == DFRAC || kind_ == TFRAC)
                features.require("amsmath");
+       if (kind_ == AASTEX_CASE)
+               features.require("aastex_case");
+
        if (features.runparams().math_flavor == OutputParams::MathAsHTML)
                // CSS adapted from eLyXer
                features.addCSSSnippet(
                        "span.frac{display: inline-block; vertical-align: 
middle; text-align:center;}\n"
                        "span.numer{display: block;}\n"
                        "span.denom{display: block; border-top: thin solid 
#000040;}");
+
        InsetMathNest::validate(features);
 }
 
diff --git a/src/mathed/InsetMathFrac.h b/src/mathed/InsetMathFrac.h
index 87b2306..c2427ec 100644
--- a/src/mathed/InsetMathFrac.h
+++ b/src/mathed/InsetMathFrac.h
@@ -46,6 +46,7 @@ public:
        ///
        enum Kind {
                FRAC,
+               AASTEX_CASE,
                CFRAC,
                CFRACLEFT,
                CFRACRIGHT,
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index 18e4c06..08f0b01 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -624,6 +624,8 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
                return MathAtom(new InsetMathFrac(buf, 
InsetMathFrac::CFRACLEFT));
        if (s == "cfracright")
                return MathAtom(new InsetMathFrac(buf, 
InsetMathFrac::CFRACRIGHT));
+       if (s == "case") // TODO: only if class is aastex(6|62)
+               return MathAtom(new InsetMathFrac(buf, 
InsetMathFrac::AASTEX_CASE));
        //if (s == "infer")
        //      return MathAtom(new MathInferInset);
        if (s == "atop")
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to