create LaTeX tables from inside node.js
Easily via npm:
$ npm install --save make-latex
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}
*/
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:
- An array of arrays, or more specifically a square matrix (inner arrays must all have equal length).
- An array of objects.
- 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 |
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 |
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.
MIT © Philipp Burckhardt