christianp / asciimath2tex Goto Github PK
View Code? Open in Web Editor NEWJavaScript library to convert AsciiMath to TeX
License: Apache License 2.0
JavaScript library to convert AsciiMath to TeX
License: Apache License 2.0
I have the following AsciiMath expression:
P(B|A) = (P(A|B) * P(B))/(P(A))
Which this library converts to:
P \left( B \left \lvert A \right ) = \left( P \frac{A \left \lvert B \right ) \cdot P \left( B \right )}{P \left( A \right )} \right. \right.
Then rendering it via KaTeX I get:
While instead I should get:
I'm no TeX expert, I guess the generated TeX isn't quite right? ๐ค
When I'm trying to parse this string:
{\displaystyle \frac{{m}}{{n}},\quad\text{gdzie}\quad{m},{\;n}\in{{{\mathbb{Z}}}}\quad\text{oraz}\quad{n}\ne{0}}
the output is:
\left\lbrace d i s p l a y s t y \le \frac{\left\lbrace m \right \rbrace}{\left\lbrace n \right \rbrace} , \quad \text{gdzie} \quad \left\lbrace m \right \rbrace , \left\lbrace ; n \right \rbrace \in \left\lbrace \left\lbrace \left\lbrace \mathbb{Z} \right \rbrace \right \rbrace \right \rbrace \quad \text{oraz} \quad \left\lbrace n \right \rbrace \ne \left\lbrace 0 \right \rbrace \right \rbrace
Am I doing something wrong, or the string is wrong?
To use asciimath2tex in a TypeScript project, we need type definitions. The following works for me and may be a solution for you too:
In packages.json, specify the type definitions file:
"typings": "type.d.ts",
Add file type.d.ts:
export as namespace asciimath2tex;
class AsciiMathParser {
constructor();
parse(str): string;
}
export default AsciiMathParser;
With the type definitions in place, I can do:
import AsciiMathParser from 'asciimath2tex';
...
...
const parser = new AsciiMathParser();
const tex = parser.parse("int_(i=1)^10 x^2/2 dx");
Hello!
I use your parser as an ECMAScript module and I see that I cannot pass an expression that contains ',,' (or simply ',' as the whole expression). The exception occurs:
asciimath2tex.js:455 Uncaught Error: Didn't EOF:
at AsciiMathParser.consume (asciimath2tex.js:455)
at AsciiMathParser.parse (asciimath2tex.js:420)
else if(!this.eof(pos)) {
throw(new Error("Didn't EOF: ",this.source(pos)));
}
However, if I include the parser as a CommonJS module taking the source code directly from the repository, the expressions are parsed fine, as in asciimath2tex.js the exception is not thrown for the same case. Instead, there are:
else if (!this.eof(t)) {
var h = this.source(t, t + 1);
a.push({tex: h, pos: t, ttype: "character"}), (e += h), (t += 1);
}
Could you explain, please, why there is a difference between the scripts and what behavior of the parser is correct?
!in
renders as \not\in
. There should be similar commands for \not\exists
and \not\subset
.
In fact, maybe !
before any relation should render as \not
. Ideally, this should go in the official AsciiMath too.
Hey I'd like to give this a try, could you publish it to NPM and add a proper license (MIT perhaps)?
I suspect that in the method strip_space
the regex should be corrected in /^(\s|\\(?!\\\s))*/
. As it is now, the sequence \
is simply stripped, instead of being translated in \,
(that is the thin space). The rendering in MathML seem to confirm that this is what should happen, and also MathJax does so. The examples in the tests where \
is used seem on the contrary not correct. Am I right?
It has new Parser();
instead of new AsciiMathParser();
Christian, could you please bump the version number of the npm package? That way the recent packages.json with typing definitions will be installed and the build performed with the types definition file. Working on the npm package is above my pay grade :)
It would be useful to have a CommonJS export, so that this library can be easily imported in CommonJS environments (like Node.js).
Hi all. I'm working on implement LaTeX output support support for asciidoctor/asciimath, which is quite similar to what you guys are doing in here.
As stated in here, KaTeX does not support the \twoheadrightarrowtail
macro (neither do vanilla LaTeX, amsmath
or amssymb
). In fact, I was surprised that I couldn't find a TeX package that supports this specific symbol.
Did you guys have any luck with this? I believe we should exchange information about this issue.
There's another similar implementation here, have you tried? If so could we write a short comparison between the two?
I'm using [email protected]. There seems to be something funky going on if I wrap a matrix in parentheses. I noticed this when trying to mark up a matrix determinant with the following input:
parser.parse('det([[a,b],[c,d]])');
Expected output:
'\det{\left ( \left [ \begin{matrix} a & b \\ c & d \end{matrix} \right ] \right )}'
Actual output:
'\det{\left ( \begin{matrix} \left [ a , b \right ] & \left [ c , d \right ] \end{matrix} \right )}'
It seems that the minimal test case that fails is
parser.parse('([[a],[b]])');
Expected output:
'\left ( \left [ \begin{matrix} a \\ b \end{matrix} \right ] \right )'
Actual output:
'\left ( \begin{matrix} \left [ a \right ] & \left [ b \right ] \end{matrix} \right )'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.