https://github.com/planeshifter/node-make-latex
convert JS objects to LaTeX tables from inside node.js
https://github.com/planeshifter/node-make-latex
Last synced: 4 months ago
JSON representation
convert JS objects to LaTeX tables from inside node.js
- Host: GitHub
- URL: https://github.com/planeshifter/node-make-latex
- Owner: Planeshifter
- License: mit
- Created: 2015-02-26T05:39:39.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-20T04:30:00.000Z (over 11 years ago)
- Last Synced: 2025-06-02T11:07:03.865Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 219 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![Dependencies][dependencies-image]][dependencies-url]
# make-latex
> create LaTeX tables from inside node.js
## Install
Easily via npm:
```sh
$ npm install --save make-latex
```
## Usage
```js
var makeLatex = require('make-latex');
var mat = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
makeLatex(mat);
/*
returns:
\begin{table}
\centering
\begin{tabular}{ccc}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
\end{table}
*/
```
## API
### makeLatex(obj [, options])
Main function which takes a JavaScript object `obj` and converts it to LaTeX.
The function returns a string which can be directly embedded in LaTeX.
Currently, the following types of objects are supported:
1. An array of arrays, or more specifically a square matrix (inner arrays must all
have equal length).
2. An array of objects.
3. An object
The function accepts an optional options object which governs the created LaTeX output.
The options object can have the following keys:
| Key | Description | Default Value |
| ------------- |:-------------:| -----:|
| caption | Caption of the created table | none |
| label | Label of the created table | none |
| captionPlacement | Position of Caption, either "bottom" or "top" | "bottom" |
| colnames | If supplied, first row in table prints names of columns | Object.keys() for Array of Objects, ["Key", "Value"] for Object |
| spec | See Spec section | centered, no vertical lines
| pos | See Positions section | none |
| digits | Number of decimial places for numeric values | none |
#### Spec
In LaTeX, the spec argument determines the alignment which is used
in each column and where to insert vertical lines.
| Key | Description |
| ------------- |:-------------:|
| l | left-justified column |
| c | centered column |
| r | right-justified column |
| \| | vertical line |
| \|\| | double vertical line |
#### Positions
| Key | Description |
| ------------- |:-------------:|
| h | allowed to be placed inline |
| t | go into top area |
| b | go into a bottom area |
| p | go on a float page or column area |
Appending `!` to either of those positions will force LaTeX to ignore restrictions related to number of floats
that can be placed in an array or the size an array can occupy.
## License
MIT © [Philipp Burckhardt](http://www.philipp-burckhardt.com)
[npm-url]: https://npmjs.org/package/make-latex
[npm-image]: https://badge.fury.io/js/make-latex.svg
[travis-url]: https://travis-ci.org/Planeshifter/node-make-latex
[travis-image]: https://travis-ci.org/Planeshifter/node-make-latex.svg?branch=master
[coveralls-image]: https://img.shields.io/coveralls/Planeshifter/node-make-latex/master.svg
[coveralls-url]: https://coveralls.io/r/Planeshifter/node-make-latex?branch=master
[dependencies-image]: https://david-dm.org/Planeshifter/node-make-latex.svg
[dependencies-url]: https://david-dm.org/Planeshifter/node-make-latex