1.0.10 • Published 5 years ago

ts2latex v1.0.10

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

ts2latex

Convert TypeScript to LaTeX algorithm format. Supports only a small subset of the general TS syntax, and is intended to be an easier way to write psuedocode for LaTeX-written academic documents.

Installation

To use from the command line, install globally:

npm i -g ts2latex

To use as a library, save as a dependency:

npm i ts2latex --save-dev

Usage

If installed globally, the following (e.g) will work:

ts2latex test/1.ts

The API is a single function which takes in correctly formatted TypeScript code, and returns, optionally, both the JSON and LaTeX conversions of the code.

const ts2latex = require("ts2latex");

ts2latex(
  data,
  json => {
    console.log(json);
  },
  latex => {
    console.log(latex);
  }
);

You will of course need supplementary LaTeX syntax (i.e. the appropriate packages) before the generated LaTeX code will compile.

Syntax

The syntax is a strict subset of TypeScript, requiring some annotated documentation in a modified JSDoc style to supply needed captions, labels, etc. For example:

/**
 * @name alg:always
 * @input Array of reals $x, y$ of size $n$
 * @return Array of reals, size $n$
 * @desc 'Always' operator.  Resultant array is true up until $x_i$ is false.
 */
function A(x: Array<number>, y) {
  let alpha: boolean = true;
  alpha = false;
  for (let x_i of x) {
    alpha = x_i && alpha;
    x_i = Number(alpha);
  }
  return x;
}

Some greek name variables will be converted to their respective LaTeX symbol. If more are needed for your application, feel free to make a pull request.

License

MIT.

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.0

5 years ago