Clarification on how objects are converted to strings
Hi, I have been looking for something like this project for quite some time, finding it has been great!
I tried to define some classes for mathematical objects (with the class definitions nested within a class implementing IModule
, since you noted that classes not implementing API interfaces are not usable). These classes also defined a toString
method. I then created an instance using a method of the containing class:
// ./tstex_modules/mymodule.ts
import { IModule, IResolver } from "./_api";
export class M implements IModule {
_resolver: IResolver;
MathObject = class {
readonly latex: String;
toString() {
return this.latex;
}
constructor(latex: String) {
this.latex = latex;
}
}
_init(resolver: IResolver) {
//do some stuff when your module gets loaded or refreshed
this._resolver = resolver;
// this._resolver.register(this, "MyModule");
}
math_object(name: string) {
return new this.MathObject(name)
}
}
This was then called from a myLatexDoc.tex
file to be built with ts-tex:
\documentclass{article}
\begin{document}
\this.m.math_object("M")
\end{document}
But this builds the following .build.myLatexDoc.tex
:
% !TEX program
\documentclass{article}
\begin{document}
{"latex":"M"}
\end{document}
Changing the math_object
method in the above typescript code to
math_object(name: string) {
return (new this.MathObject(name)).toString()
}
results in the expected output
% !TEX program
\documentclass{article}
\begin{document}
M
\end{document}
Did I misunderstand the documentation? Should the parser not call .toString()
on the MathObject
object? Or did I make a mistake somewhere? (I don't really have a lot of experience with JS/TS).