0.2.9 • Published 2 years ago
mathway-api v0.2.9
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 optionslanguage- 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 topicoptions- Optional, submit optionslanguage- 2-letter code of answers language (See supported languages list below)customData- Custom topic datavariable- 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 optionslanguage- 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 ofMessage. Messages related to the provided request
object TopicsResponse
type- always"topicsResponse"topics- Array ofTopic. Array of suggested topics
object Message
content- String. Content of the message (with HTML tags)genre- Genre/Type of the messagemathway- Solving of the expressionmessage- Self-promotion and other messages not related to the expressionautoresolve-"Not the answer you were looking for?"messagegreeting- Greeting messagesrating- 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 forgetTopicResultcall with current topic. Just usegetResult()instead ofgetTopicResult(expression, subject, topicId, language). customData- Optional, Object. Custom topic data (e.g.variableto specify what variable to act with)
Supported subjects
BasicMathprealgebraalgebratrigonometryprecalculuscalculusstatisticsfinitemathlinearalgebrachemistryphysics
Supported languages
| Language | 2-letter code |
|---|---|
| English | en |
| Arabic | ar |
| Chinese | zh |
| French | fr |
| German | de |
| Hindi | hi |
| Indonesian | id |
| Italian | it |
| Japanese | ja |
| Korean | ko |
| Portuguese | pt |
| Russian | ru |
| Spanish | es |
| Vietnamese | vi |
All others will not work and the answers will be in English