Giter VIP home page Giter VIP logo

Comments (3)

G-Ambatte avatar G-Ambatte commented on June 28, 2024

I had a (very) quick stab at this before I had to run out to work this morning, this is the modification to markdown.js that I came up with:

const mathParser = new MathParser({
	operators : {
		// These default to true, but are included to be explicit
		add      : true,
		subtract : true,
		multiply : true,
		divide   : true,
		power    : true,
		round    : true,
		floor    : true,
		ceil     : true,
		abs      : true,

		sin     : false, cos     : false, tan     : false, asin    : false, acos    : false,
		atan    : false, sinh    : false, cosh    : false, tanh    : false, asinh   : false,
		acosh   : false, atanh   : false, sqrt    : false, cbrt    : false, log     : false,
		log2    : false, ln      : false, lg      : false, log10   : false, expm1   : false,
		log1p   : false, trunc   : false, join    : false, sum     : false,
		'-'     : false, '+'     : false, exp     : false, not     : false, length  : false,
		'!'     : false, sign    : false, random  : false, fac     : false, min     : false,
		max     : false, hypot   : false, pyt     : false, pow     : false, atan2   : false,
		'if'    : false, gamma   : false, roundTo : false, map     : false, fold    : false,
		filter  : false, indexOf : false,

		remainder   : false, factorial   : false,
		comparison  : false, concatenate : false,
		logical     : false, assignment  : false,
		array       : false, fndef       : false
	}
});
mathParser.functions.sign = function (a) {
	if(a == 0) return null;
	if(a > 0) {
		return '+';
	} else {
		return '\\-';
	}
};

I was not having any luck getting abs() to actually function in a brew, even after enabling it.
image

On further thought, I believe we could also (or instead) include a signed function that returns the input value as a string with a +/- prefix:

mathParser.functions.signed = function (a) {
	if(a >= 0) {
		return `+${a}`;
	} else {
		return `\\${a}`;
	}
};

(NB: the negative prefix needs to be \\- or else it will be treated as the start of a list when used at the beginning of a line; I have not yet determined any scenarios that require the positive prefix to be handled similarly)

from homebrewery.

G-Ambatte avatar G-Ambatte commented on June 28, 2024

Looks like the variable hasn't been resolved to the value at the time that the function runs:

image

from homebrewery.

G-Ambatte avatar G-Ambatte commented on June 28, 2024

signed works pretty well in it's current iteration:
image

from homebrewery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.