0.2.9 • Published 3 months ago

mathway-api v0.2.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

MathWay API

An unofficial API package for MathWay

Documentation

To use the package import it using require keyword:

const mathway = require("mathway-api");

function submit

Submit an expression to MathWay and return the response. Arguments:

  • expression - Expression to submit (in LaTeX format)
  • subject - Answers subject (See all subjects list below)
  • options - Optional, submit options
    • language - 2-letter code of answers language (See supported languages list below)

Return value is a MessagesResponse or TopicsResponse object

Example:

mathway.submit('\\sqrt(16) + x = 5', 'algebra', { language: 'en' }).then(answer => {
    if (answer.type === `topicsResponse`) { // Checking if the answer is TopicsResponse
        answer.topics[0].getResult().then(result => { // Getting MessagesResponse by the first topic
            console.log(result.messages[0].content); // Log content of the first message
        });
    }
});

function getTopicResult

Get an MessagesResponse result for given topic manually. Arguments:

  • expression - Expression to submit (in LaTeX format)
  • subject - Answers subject (See all subjects list below)
  • topicId - ID of the topic
  • options - Optional, submit options
    • language - 2-letter code of answers language (See supported languages list below)
    • customData - Custom topic data
      • variable - Variable to act with

Return value is a MessagesResponse object

Example:

const topicId = 1; // ID of the "Solve for x" topic
const answer = await mathway.getTopicResult('x + 1 = 2', 'algebra', topicId);

function greet

Sends greeting request to MathWay. Arguments:

  • subject - Answers subject (See all subjects list below)
  • options - Optional, submit options
    • language - 2-letter code of answers language (See supported languages list below)

Return value is a MessagesResponse object

Example:

console.log((await mathway.greet('precalculus', { language: 'es' })).messages[0].content);
// Output is: ¿Cómo puedo ayudarte?

function getGlossaryTerm

Get glossary term definition. Arguments:

  • termId - ID of the term

Return value is a definition string.\ Can throw an error which is a string with the error message.

Example:

mathway.getGlossaryTerm(416).then(definition => {
    console.log("Definition:", definition);
}).catch(errorMessage => {
    console.error("Error:", errorMessage);
});

object MessagesResponse

  • type - always "messagesResponse"
  • messages - Array of Message. Messages related to the provided request

object TopicsResponse

  • type - always "topicsResponse"
  • topics - Array of Topic. Array of suggested topics

object Message

  • content - String. Content of the message (with HTML tags)
  • genre - Genre/Type of the message
    • mathway - Solving of the expression
    • message - Self-promotion and other messages not related to the expression
    • autoresolve - "Not the answer you were looking for?" message
    • greeting - Greeting messages
    • rating - Messages asking to rate the solution
  • timestamp - Message timestamp

object Topic

  • id - Number. Unique ID of the topic.
  • score - Number. Number between 0 and 1. Probability that this topic was meant.
  • text - String. Topic text.
  • function getResult - shorthand for getTopicResult call with current topic. Just use getResult() instead of getTopicResult(expression, subject, topicId, language).
  • customData - Optional, Object. Custom topic data (e.g. variable to specify what variable to act with)

Supported subjects

  • BasicMath
  • prealgebra
  • algebra
  • trigonometry
  • precalculus
  • calculus
  • statistics
  • finitemath
  • linearalgebra
  • chemistry
  • physics

Supported languages

Language2-letter code
Englishen
Arabicar
Chinesezh
Frenchfr
Germande
Hindihi
Indonesianid
Italianit
Japaneseja
Koreanko
Portuguesept
Russianru
Spanishes
Vietnamesevi

All others will not work and the answers will be in English

0.2.9

3 months ago

0.2.8

3 months ago

0.2.7

8 months ago

0.2.6

8 months ago