_.mixin(_.str.exports());

var add = function (vals) {
    return vals.join("+");
};

var x = function (first, second) {
    return first+"\\cdot "+second;
};

var pl = function (first, second) {
    return first+" + "+second;
};


var fr = function (first, second) {
    return "\\frac{"+first+"}{ "+second + "}";
};

var sq = function (first) {
    return "\\sqrt{"+first+"}";
};
var par = function (first) {
    return "("+first+")";
};


var uu = function (rest) {
    return " \\underline{ \\underline{"+rest+"} } ";
};

var u = function (rest) {
    return "  \\underline{"+rest+"}";
};

var pwr = function (base, exp) {
    return base + "^{"+exp+"}";
};
var red = function (rest) {
    return "\\color{red}{"+rest+"}";
};

var eqnl = function (left, rigth) {
    if (rigth) {
     return "{"+left+"} = \\\\{"+rigth+"}";
 } else {
     return  "{"+left+"} = ";
 }
};


var eq = function (left, rigth) {
    if (rigth) {
     return "{"+left+"} = {"+rigth+"}";
 } else {
     return  "{"+left+"} = ";
 }
};

var subs = function (val,subscript) {
    return val+"_{"+subscript+"} ";
};

var sups = function (val,superscript) {
    return val+"^{"+superscript+"} ";
};

var interval = function (valArr) {
    return "["+valArr[0]+", "+ valArr[1]+ "\\rangle ";
};



function num_size(val) {
  return Math.floor(Math.log(val) / Math.LN10);
}

var o = function (num) {

    if (Math.abs(num)< 0.000000001) {  return "0"}

    var numstr;

    var size = num_size(num);

    if ( size< 0) {
        size = Math.min(-size, 9)
        return _.rtrim(_.numberFormat(num, size + 2, ".", "\\space "),"0.");
    } else {


    // returner pene tall....
    numstr = _.numberFormat(num, 2, ".", "\\space ")

 //   console.log("numstr"+ num+"**"+numstr);
    if (_.str.include(numstr, ".")) {
        return _.rtrim(_.rtrim(numstr,"0"),  ".");
    }

    return numstr;

    }
}

var om = function(num) {
    if (num < 0) {
        return "(" + o(num) + ")";
    } else {
        return o(num);
    }
}

function capitaliseFirstLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}