Welcome to Data2LaTeX’s documentation!
This project is a part of my bachelor thesis which deals with data representation using Python and LaTeX. You can find the source code on my GitHub.
The idea behind this package prototype is that generating LaTeX documents containing scientific data from Python should not be difficult and require many steps. Currently the package supports the creation of simple tables and two types of plots: scatter plots and line plots. The package uses the PyLaTeX package to handle the document creation and compilation process. The main data sources are arrays and data tables from the popular packages numpy
and pandas
. A major inspiration for the module syntax is the matplotlib.pyplot
module, which allows plots to be created in a few lines of code. The tables are created using the tblr
environment from the tabularray
package. The plots are created using the tikzpicture
/ axis
environment from the tikz
/ pgfplots
package.
Examples
Simple features
Data2LaTeX offers two basic features: sections and plain text. If you need other features or environments, you can use PyLaTeX to create the features and insert them into the document object manually.
import data2latex as dtol
dtol.section("Data2LaTeX")
dtol.text("This project is part of my bachelor thesis which deals with data representation using Python and LaTeX.")
dtol.finish("simple_features")
Simple table
import data2latex as dtol
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
dtol.table(data)
dtol.finish("simple_table")
Simple plot
import data2latex as dtol
X = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Y = [84, 13, 94, 37, 80, 89, 90, 45, 55, 26, 92]
dtol.plot(X, Y, line="-", mark="*")
dtol.finish("simple_plot")
Table from numpy.ndarray
import data2latex as dtol
import numpy as np
data = np.random.normal(0, 1000, (8, 4))
dtol.table(data, "#", r"Data from \texttt{numpy.random.normal}", escape_caption=False)
dtol.finish("table_from_numpy_ndarray")
Table from pandas.DataFrame
import data2latex as dtol
import pandas as pd
data = pd.DataFrame(
[[True, 0.1, "red"], [True, 0.9, "blue"], [False, 0.6, "black"]],
["First", "Second", "Third"],
["bool", "float", "str"])
dtol.table(
data, "o", r"Data from \texttt{pandas.DataFrame}",
escape_caption=False, float_format="{:0.1f}",
left_head_bold=True, left_head_col_align="r",
top_head_bold=True)
dtol.finish("table_from_pandas_dataframe")
Table cells with macros
Here we are using Package
and NoEscape
from PyLaTeX to add a new package and a custom macro into our document preamble. More about PyLaTeX features here. We can get the document instance with function gd()
from Data2LaTeX.
import data2latex as dtol
import pylatex as tex
dtol.gd().packages.add(tex.Package("xcolor"))
dtol.gd().packages.add(tex.utils.NoEscape(
r"\newcommand{\RGB}[3]{\fcolorbox{black}%" + "\n"
r"{rgb,255:red,#1;green,#2;blue,#3}%" + "\n"
r"{\makebox[47pt][r]{\textcolor{white}%" + "\n"
r"{{#1|#2|#3}}}}}%"))
data = [[r"\RGB{%s}{%s}{%s}" % ((x, 0, y)) for y in range(0, 256, 51)]
for x in range(0, 256, 51)]
dtol.table(
data, "", "RGB boxes with varying R and B channels",
use_siunitx=False, escape_cells=False)
dtol.finish("table_cells_with_macros")
Multiple scatter plots
import data2latex as dtol
import numpy as np
X = [np.random.normal(loc, scale, 100) for loc, scale in [(50, 20), (50, 40), (100, 10)]]
Y = [np.random.normal(loc, scale, 100) for loc, scale in [(50, 20), (100, 40), (75, 10)]]
dtol.plot(
X, Y, r"Scatter plots from \texttt{np.random.normal}",
"Variable $a$ [-]", "Variable $b$ [-]", "#", escape_caption=False,
line=None, mark="*", mark_fill_opacity=0.7)
dtol.finish("multiple_scatter_plots")
Multiple line plots
import data2latex as dtol
import numpy as np
X = np.linspace(0, 100, 30)
Y = np.cumsum(np.random.normal(10, 10, (3, 30)), axis=1)
dtol.plot(
[X] * 3, Y, r"Line plots from \texttt{np.random.normal}",
"Time $t$ [s]", "Variable $b$ [-]", escape_caption=False,
line=["-", "--", "-."], line_color="black", mark=None,
legend=["A", "B", "C"], legend_pos="top left",
xlimits="exact", ylimits=(0, None))
dtol.finish("multiple_line_plots")
Line plots with semi-log scale
import data2latex as dtol
import numpy as np
X = np.linspace(0, 2, 50)
Y = [np.exp(X) + np.random.uniform(0, 0.2, 50),
(2 * X + 1) + np.random.uniform(0, 0.3, 50)]
dtol.plot(
[X] * 2, Y, r"Line plots with semi-log scale",
"Variable $x$ [-]", "Variable $y$ [-]",
line="-", mark=None, mode=("lin", "log"),
legend=[r"$e^x+\epsilon_1(x)$", r"$5x+1+\epsilon_2(x)$"],
legend_pos="top left", legend_entry_align="l",
xlimits="exact", ylimits=(1, None),
precision=1, zerofill=(False, True))
dtol.finish("line_plots_semilog_scale")
Plots from pandas.DataFrame
Because pandas.DataFrame
is currently not supported as valid input data type for plot
function, we must prepare the data ourselfs. Please note that we must convert the column names into list (tolist()
) for it to work correctly as legend input. Also note that data from “column-based” dataframes must be transposed (__array__().T
).
x |
A |
B |
---|---|---|
0 |
0.0367 |
0.3447 |
1 |
0.8942 |
0.9806 |
2 |
1.1932 |
1.9215 |
3 |
1.5006 |
2.0402 |
4 |
1.6435 |
2.3271 |
5 |
1.9531 |
2.7670 |
6 |
2.6498 |
3.6242 |
7 |
2.6637 |
3.9957 |
8 |
3.5884 |
4.0811 |
9 |
3.6901 |
5.0544 |
10 |
4.6011 |
5.1315 |
from io import StringIO
import data2latex as dtol
import pandas as pd
data = pd.read_csv(StringIO("""\
x,A,B
0,0.0367,0.3447
1,0.8942,0.9806
2,1.1932,1.9215
3,1.5006,2.0402
4,1.6435,2.3271
5,1.9531,2.7670
6,2.6498,3.6242
7,2.6637,3.9957
8,3.5884,4.0811
9,3.6901,5.0544
10,4.6011,5.1315
"""))
X = data[data.columns[0]]
legend = data.columns[1:].tolist()
Y = data[legend].__array__().T
dtol.plot(
[X] * len(legend), Y, legend=legend, grid="_1",
legend_pos="top left", line="-", mark=["o", "x"],
mark_fill_color=None, mark_stroke_opacity=1.0,
mark_stroke_color=["blue", "red"])
dtol.finish("plots_from_dataframe")
Implemented features
- data2latex.gd() Document
Get current PyLaTeX document.
- Returns:
Current PyLaTeX document
- Return type:
Document
- data2latex.gdm() DocumentManager
Get current document manager instance.
- Returns:
Current document manager instance
- Return type:
DocumentManager
- data2latex.setup(document_class: str = 'article', document_class_options: List[str] = [], font_size: Literal['10pt', '11pt', '12pt'] = '12pt', spacing: Literal['1x', '1.5x', '2x'] | None = '1.5x', par_indent: str | None = '2em', par_skip: str | None = '0.5em', horizontal_margin: str | None = '2cm', vertical_margin: str | None = '2cm', page_numbers: bool = False, additional_packages: List[LatexObject | str] = []) None
Optional setup for the LaTeX document. This must be called first and cannot be combined with
use_standalone...
functions.- Parameters:
document_class (str, optional) – Document class, defaults to
"article"
.document_class_options (List[str], optional) – Options for the document class, defaults to
[]
.font_size (Literal["10pt", "11pt", "12pt"], optional) – Main font size with unit, defaults to
"12pt"
.spacing (Optional[Literal["1x", "1.5x", "2x"]], optional) – Size of spacing between lines. Uses
setspace
package. Defaults to"1.5x"
.par_indent (Optional[str], optional) – Length of paragraph indentation with unit. Uses
indentfirst
package. Defaults to"2em"
.par_skip (Optional[str], optional) – Size of gap between paragraphs with unit. Uses
parskip
package. Defaults to"0.5em"
horizontal_margin (Optional[str], optional) – Horizontal page margin with unit. Uses
geometry
package and is incompatible withstandalone
document class. Defaults to"2cm"
.vertical_margin (Optional[str], optional) – Vertical page margin with unit. Uses
geometry
package and is incompatible withstandalone
document class. Defaults to"2cm"
.page_numbers (bool, optional) –
True
for numbering pages, defaults toFalse
.additional_packages (List[LatexObject | str], optional) – Additional packages or commands which will be placed into the document preamble, defaults to
[]
.
- Raises:
RuntimeError – Cannot call this setup function if document manager has been already used.
- data2latex.use_one_page_standalone(horizontal_border: str = '5pt', vertical_border: str = '5pt') None
Optional setup for
standalone
document class with compilation into one cropped page. This is experimental feature and it can be incompatible with some other settings, e.g.geometry
package andtrim axis
options for TikZ axis.- Parameters:
horizontal_border (str, optional) – Horizontal page border with unit, defaults to
"5pt"
.vertical_border (str, optional) – Vertical page border with unit, defaults to
"5pt"
.
- data2latex.use_multi_page_standalone(horizontal_border: str = '5pt', vertical_border: str = '5pt') None
Optional setup for
standalone
document class with compilation into many cropped pages. Each table and plot is placed on its own page. This can be used for generating all the figures into one long pdf and then using\includegraphics[page=...]{...}
in LaTeX to include the figures into your main document with sections, text, etc. This is experimental feature and it can be incompatible with some other settings, e.g.geometry
package andtrim axis
options for TikZ axis.- Parameters:
horizontal_border (str, optional) – Horizontal page border with unit, defaults to
"5pt"
.vertical_border (str, optional) – Vertical page border with unit, defaults to
"5pt"
.
- data2latex.section(title: str, numbering: bool = False, label: str | None = None) None
Insert a section into the document.
- Parameters:
title (str) – Section text.
numbering (bool, optional) –
True
for numbering this section, defaults toFalse
.label (Optional[str], optional) – Label for later referencing, use format
"prefix:label"
or just"label"
with automatic prefix"sec"
, defaults toNone
.
- data2latex.text(content: str, escape: bool = True) None
Add a paragraph of solid text.
- Parameters:
content (str) – Content for the paragraph.
escape (bool, optional) –
True
for replacing special LaTeX characters, defaults toTrue
.
- data2latex.plot(_X: Any, _Y: Any, caption: str | None = None, xlabel: str | None = None, ylabel: str | None = None, grid: str | None = None, mode: Literal['lin', 'log'] | Tuple[Literal['lin', 'log'], Literal['lin', 'log']] = ('lin', 'lin'), legend: None | str | List[None | str] = None, legend_pos: Literal['top left', 'top left out', 'top right', 'down left', 'down right'] = 'top right', legend_entry_align: Literal['l', 'c', 'r'] = 'c', width: str | None = None, height: str | None = None, equal_axis: bool = False, xlimits: Tuple[float | None, float | None] | Literal['exact'] | None = None, ylimits: Tuple[float | None, float | None] | Literal['exact'] | None = None, precision: int | Tuple[int, int] = (2, 2), zerofill: bool | Tuple[bool, bool] = (False, False), label: str | None = None, caption_pos: Literal['above', 'below'] = 'below', escape_caption: bool = True, position: str = 'H', center: bool = True, line: None | Literal['-', '--l', '--', '--d', '.l', '.', '.d', '-.l', '-.', '-.d', '-..l', '-..', '-..d'] | List[None | Literal['-', '--l', '--', '--d', '.l', '.', '.d', '-.l', '-.', '-.d', '-..l', '-..', '-..d']] = None, line_width: str | List[str] = '0.75pt', line_color: None | Literal['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black', 'gray', 'white', 'darkgray', 'lightgray', 'brown', 'lime', 'olive', 'orange', 'pink', 'purple', 'teal', 'violet'] | Tuple[int, int, int] | Tuple[float, float, float] | List[None | Literal['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black', 'gray', 'white', 'darkgray', 'lightgray', 'brown', 'lime', 'olive', 'orange', 'pink', 'purple', 'teal', 'violet'] | Tuple[int, int, int] | Tuple[float, float, float]] = ['blue', 'red', 'black'], line_opacity: float | List[float] = 1.0, mark: None | Literal['*', 'x', '+', '-', '|', 'o', 'asterisk', 'star', '10-pointed star', 'oplus', 'oplus*', 'otimes', 'otimes*', 'square', 'square*', 'triangle', 'triangle*', 'diamond', 'diamond*', 'halfdiamond*', 'halfsquare*', 'halfsquare right*', 'halfsquare left*', 'Mercedes star', 'Mercedes star flipped', 'halfcircle', 'halfcircle*', 'pentagon', 'pentagon*', 'ball'] | List[None | Literal['*', 'x', '+', '-', '|', 'o', 'asterisk', 'star', '10-pointed star', 'oplus', 'oplus*', 'otimes', 'otimes*', 'square', 'square*', 'triangle', 'triangle*', 'diamond', 'diamond*', 'halfdiamond*', 'halfsquare*', 'halfsquare right*', 'halfsquare left*', 'Mercedes star', 'Mercedes star flipped', 'halfcircle', 'halfcircle*', 'pentagon', 'pentagon*', 'ball']] = '*', mark_size: str | List[str] = '2pt', mark_fill_color: None | Literal['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black', 'gray', 'white', 'darkgray', 'lightgray', 'brown', 'lime', 'olive', 'orange', 'pink', 'purple', 'teal', 'violet'] | Tuple[int, int, int] | Tuple[float, float, float] | List[None | Literal['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black', 'gray', 'white', 'darkgray', 'lightgray', 'brown', 'lime', 'olive', 'orange', 'pink', 'purple', 'teal', 'violet'] | Tuple[int, int, int] | Tuple[float, float, float]] = ['blue', 'red', 'black'], mark_stroke_color: None | Literal['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black', 'gray', 'white', 'darkgray', 'lightgray', 'brown', 'lime', 'olive', 'orange', 'pink', 'purple', 'teal', 'violet'] | Tuple[int, int, int] | Tuple[float, float, float] | List[None | Literal['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black', 'gray', 'white', 'darkgray', 'lightgray', 'brown', 'lime', 'olive', 'orange', 'pink', 'purple', 'teal', 'violet'] | Tuple[int, int, int] | Tuple[float, float, float]] = None, mark_fill_opacity: float | List[float] = 1.0, mark_stroke_opacity: float | List[float] = 0.0) None
Generate LaTeX scatter or line plot from input data. The plot is created with
pgfplots
package (tikzpicture
+axis
environment). Data can be in the form of a list or an array of numbers for single line. For plotting more data sets, input data should be in the form of list of lists as shown below:X = [[dataset1_x], [dataset2_x]] Y = [[dataset1_y], [dataset2_y]] legend = ["dataset1", "dataset2"]
Some input parameters can take single value or list of values. If list is given, the plot generator will cycle through the values as shown below:
line = "-" # Every plot will have solid line; mark = ["*", None] # 1st, 3rd, 5th... plot will have marks; 2nd, 4th, 6th... plot will have no mark;
Inputing empty data in valid format should run and compile without an error. For plotting data from
pandas.DataFrame
: convert the dataframe intonumpy.array
and extract the column names for the plot legend.Examples of usage
import data2latex as dtol X = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Y = [84, 13, 94, 37, 80, 89, 90, 45, 55, 26, 92] dtol.plot(X, Y, line="-", mark="*") dtol.finish()
import data2latex as dtol import numpy as np data = np.random.normal(0, 100, (2, 100)) dtol.plot(data[0], data[1], grid="#", line=None, mark="*") dtol.finish()
- Parameters:
_X (Any) – X coordinates for plotting. Does not have a type hint because the data validity is checked before plotting. Should be
List[Number]
,List[List[Number]]
ornumpy.ndarray
with one or two dimensions._Y (Any) – Y coordinates for plotting. Does not have a type hint because the data validity is checked before plotting. Should be
List[Number]
,List[List[Number]]
ornumpy.ndarray
with one or two dimensions.caption (Optional[str], optional) – Caption text, defaults to
None
.xlabel (Optional[str], optional) – Label for x axis, defaults to
None
.ylabel (Optional[str], optional) – Label for y axis, defaults to
None
.grid (Optional[str], optional) – Custom code for configuring major/minor grid, defaults to
None
. Symbol|
turns on major vertical grid lines, symbol_
turns on major horizontal grid lines,#
symbols turns both directions of major grid lines. If the symbol is followed up by a number, the number is interpreted as number of minor grid lines inbetween the major grid lines in given direction. The symbols can be combined to obtain desired grid settings. Does not work well with logaritmic axis!mode (Union[AxisMode, Tuple[AxisMode, AxisMode]], optional) – Axis scale: the first tuple element for x axis, the second one for y axis. If single value is given, it will be used for both axis. Defaults to
("lin", "lin")
.legend (Union[None, str, List[Union[None, str]]], optional) – Legend entries: input
None
if dataset should not have an entry. Defaults toNone
.legend_pos (LegendPosition, optional) – Legend position: available string literals start with vertical position (e.g. top) followed by horizontal position (e.g. right). Defaults to
"top right"
.legend_entry_align (Literal[
l
,c
,r
], optional) – Horizontal text alignment of legend entries, defaults to"c"
.width (Optional[str], optional) – Width of the plot with unit, defaults to
None
.height (Optional[str], optional) – Height of the plot with unit, defaults to
None
.equal_axis (bool, optional) –
True
for equal scale on both axis. You must find a good working combo with settingsequal_axis
,x/ylimits
andwidth/height
. Defaults toFalse
.xlimits (Optional[Union[Tuple[Optional[float], Optional[float]], Literal[
exact
]]], optional) – Limits for x axis: either two numbers (min, max) in tuple or"exact"
literal for setting the limits to minimum and maximum of the datasets. Defaults toNone
.ylimits (Optional[Union[Tuple[Optional[float], Optional[float]], Literal[
exact
]]], optional) – Limits for y axis: either two numbers (min, max) in tuple or"exact"
literal for setting the limits to minimum and maximum of the datasets. Defaults toNone
.precision (Union[int, Tuple[int, int]], optional) – Precision of the displayed tick labels in the form of (x axis tick labels, y axis tick labels). Defaults to
(2, 2)
.zerofill (Union[bool, Tuple[bool, bool]], optional) –
True
for padding decimal numbers (tick labels) with zeros to satisfy given precision, defaults to(False, False)
.label (Optional[str], optional) – Label for later referencing, use format
"prefix:label"
or just"label"
with automatic prefix"plot"
, defaults toNone
.caption_pos (Literal[
above
,below
], optional) – Position caption above or below the table, defaults to"below"
.escape_caption (bool, optional) –
True
for escaping special LaTeX symbols in caption text, defaults toTrue
.position (str, optional) – Float position on the page for
table
environment, defaults to"H"
.center (bool, optional) –
True
for centering the table on the page, defaults toTrue
.line (Union[None, LineStyle, List[Union[None, LineStyle]]], optional) – Line style:
None
for no line or some string valid literal, defaults toNone
.line_width (Union[str, List[str]], optional) – Line width with unit, defaults to
"0.75pt"
.line_color (Union[None, Color, List[Union[None, Color]]], optional) – Line color in the form of tuple with three int (0-255) or float (0.0-1.0) values, a named color or a string with hex value. Defaults to
["blue", "red", "black"]
.line_opacity (Union[float, List[float]], optional) – Line color opacity (0.0-1.0), defaults to
1.0
.mark (Union[None, MarkStyle, List[Union[None, MarkStyle]]], optional) – Mark style, can be
None
for no marks. Defaults to"*"
.mark_size (Union[str, List[str]], optional) – Mark size with unit, defaults to
"2pt"
.mark_fill_color (Union[None, Color, List[Union[None, Color]]], optional) – Mark fill (area) color in the form of tuple with three int (0-255) or float (0.0-1.0) values, a named color or a string with hex value. Can be
None
for no fill. Defaults to["blue", "red", "black"]
.mark_stroke_color (Union[None, Color, List[Union[None, Color]]], optional) – Mark stroke (outline) color in the form of tuple with three int (0-255) or float (0.0-1.0) values, a named color or a string with hex value. Can be
None
for no stroke. Defaults toNone
.mark_fill_opacity (Union[float, List[float]], optional) – Mark fill opacity (0.0-1.0), defaults to
1.0
.mark_stroke_opacity (Union[float, List[float]], optional) – Mark stroke opacity (0.0-1.0), defaults to
0.0
.
- data2latex.table(data: ~typing.Sequence[~typing.Sequence[~typing.Any]] | ~data2latex.iter_protocols.OuterKnownLengthIterable | ~data2latex.iter_protocols.DataFrameOuterIterator | ~data2latex.iter_protocols.DataFrameLike | ~data2latex.iter_protocols.NDArrayLike, rules: str = '', caption: str | None = None, caption_pos: ~typing.Literal['above', 'below'] = 'above', escape_caption: bool = True, label: str | None = None, position: str = 'H', center: bool = True, float_format: str = '{:0.3f}', str_format: str = '{{{{{{{:s}}}}}}}', str_convertor: ~typing.Callable[[~typing.Any], str] = <class 'str'>, str_try_number: bool = True, escape_cells: bool = True, col_align: ~typing.Literal['l', 'c', 'r', 'j'] = 'c', row_align: ~typing.Literal['t', 'm', 'b', 'h', 'f'] = 'm', left_head_bold: bool = False, left_head_col_align: ~typing.Literal['l', 'c', 'r', 'j'] | None = None, top_head_bold: bool = False, top_head_col_align: ~typing.Literal['l', 'c', 'r', 'j'] | None = None, use_adjustbox: bool = True, use_siunitx: bool = True, dataframe_column_names: bool = True, dataframe_row_names: bool = True) None
Generate LaTeX table from input data. The table is created with
tabularray
package (tblr
environment) with optionalsiunitx
usage for decimal number alignment. Table can be automatically scaled down withadjustbox
package. Inputing empty data in valid format should run and compile without an error.Examples of usage
import data2latex as dtol data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] dtol.table(data) dtol.finish()
import data2latex as dtol import pandas as pd data = pd.DataFrame( [["purple", "cyan"], ["blue", "yellow"]], ["C1", "C2"], ["R1", "R2"] ) dtol.table( data, caption="Data from pandas.DataFrame", rules="|2_2", top_head_bold=True, left_head_bold=True, ) dtol.finish()
- Parameters:
data (Union[Sequence2D, KnownLengthIterable2D, DataFrameIterator, DataFrameLike, NDArrayLike]) – 2D structure holding your data. Supported data types are
List[List[Any]]
,numpy.ndarray{ndim >= 2}
andpandas.DataFrame
.rules (str, optional) –
Rule settings using custom syntax, defaults to
""
.Symbol
Meaning
|
Select the vertical rules.
_
Select the horizontal rules.
1
Apply rule before header in selected direction.
2
Apply rule after header in selected direction.
3
Apply rule after table body in selected direction.
A
Apply every rule in selected direction.
a
Apply every rule in selected direction except the border ones.
B
Apply every rule in table body in selected direction.
b
Apply every rule in table body in selected direction except the border ones.
#
Apply every rule in both direction, every cell has full border.
O
Apply every rule around table.
o
Apply every rule around table body.
Symbols
#
,O
,o
don’t need selected direction.caption (Optional[str], optional) – Caption text, defaults to
None
.caption_pos (Literal["above", "below"], optional) – Position caption above or below the table, defaults to
"above"
.escape_caption (bool, optional) –
True
for escaping special LaTeX symbols in caption text, defaults toTrue
.label (Optional[str], optional) – Label for later referencing, use format
"prefix:label"
or just"label"
with automatic prefix"table"
, defaults toNone
.position (str, optional) – Float position on the page for
table
environment, defaults to"H"
.center (bool, optional) –
True
for centering the table on the page, defaults toTrue
.float_format (str, optional) – Format for formatting
float
numbers withstr.format()
. Here you can change the number of printed decimal places,int
numbers are printed without any format, defaults to"{:0.3f}"
.str_format (str, optional) – Format for formatting strings with
str.format()
. Text must be enclosed in triple curly brackets if you use thesiunitx
package, defaults to"{{{{{{{:s}}}}}}}"
.str_convertor (Callable[[Any], str]) – Function for converting objects into strings, defaults to
str
.str_try_number (bool, optional) –
True
for trying to convertstr
toint
andfloat
. This process is done after formatting numbers and converting objects into strings. Turn this off if you do not need it. Defaults toTrue
.escape_cells (bool, optional) –
True
for escaping every cells content, defaults toTrue
.col_align (Literal["l", "c", "r", "j"], optional) – Classic column (horizontal) contenet alignment setting, defaults to
"c"
.row_align (Literal["t", "m", "b", "h", "f"], optional) – Classis row (vertical) content alignment setting, defaults to
"m"
.left_head_bold (bool, optional) –
True
for bold left header text, defaults toFalse
.left_head_col_align (Optional[Literal["l", "c", "r", "j"]], optional) – Left header text vertical alignment setting, defaults to
None
.top_head_bold (bool, optional) –
True
for bold top header text, defaults toFalse
.top_head_col_align (Optional[Literal["l", "c", "r", "j"]], optional) – Top header text vertical alignment setting, defaults to
None
.use_adjustbox (bool, optional) –
True
for wrapping the wholetblr
environment inadjustbox
macro, which will shrink the table if it is wider thenlinewidth
, defaults toTrue
.use_siunitx (bool, optional) –
True
for usingsiunitx
package for aligning numbers. To allow custom vertical alignment, we must know max number of digits each column will store. There is currently implemented some sort of heuristic approach for obtaining this information. Turn this off if you do not need it. It does not work with numbers in scientific notation. Defaults toTrue
.dataframe_column_names (bool, optional) –
True
for showing column names if the input data ispandas.DataFrame
, defaults toTrue
.dataframe_row_names (bool, optional) –
True
for showing row names if the input data ispandas.DataFrame
, defaults toTrue
.
- Raises:
ValueError – Input data must have at least two dimensions.
ValueError – Unknown input data type. Supporting
List[List[Any]]
,numpy.ndarray{ndim >= 2}
andpandas.DataFrame
.
- data2latex.finish(filepath: str = 'document', generate_tex: bool = True, compile_tex: bool = True, compiler: Literal['pdflatex', 'latexmk'] | None = 'pdflatex') None
Generate LaTeX source code and compile the document.
- Parameters:
filepath (str, optional) – File name or file path without extension, defaults to
"document"
.generate_tex (bool, optional) –
True
for generating .tex file, defaults toTrue
.compile_tex (bool, optional) –
True
for compiling the document into .pdf file, defaults toTrue
.compiler (Optional[Literal["pdflatex", "latexmk"]], optional) – Compiler name,
pdflatex
could be faster thenlatexmk
, defaults to"pdflatex"
.
- data2latex.latex(filepath: str = 'document') None
Generate LaTeX source code.
- Parameters:
filepath (str, optional) – File name or file path without extension, defaults to
"document"
.
- data2latex.pdf(filepath: str = 'document', compiler: Literal['pdflatex'] | None = 'pdflatex') None
Compile the document without saving the .tex file.
- Parameters:
filepath (str, optional) – File name or file path without extension, defaults to
"document"
.compiler (Optional[Literal["pdflatex", "latexmk"]], optional) – Compiler name,
pdflatex
could be faster thenlatexmk
, defaults to"pdflatex"
.
- data2latex.reset() None
Reset the current document. This will remove all the content which has been appended. You can use the setup functions after calling this, e.g. compile two documents with different document class in one script.