Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow rendering of tables to LaTeX #481

Draft
wants to merge 85 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
6c1d6b2
Get components in place for LaTeX rendering
rich-iannone Oct 1, 2024
07fc311
Merge branch 'main' into feat-latex-rendering
rich-iannone Oct 1, 2024
f16e9c5
Add two `latex*` options in `tab_options()`
rich-iannone Oct 2, 2024
53477b5
Add the `check_quarto()` util function
rich-iannone Oct 2, 2024
9344487
Define logic in `create_wrap_start_l()`
rich-iannone Oct 2, 2024
84f40c5
Add WIP LaTeX table component building fns
rich-iannone Oct 2, 2024
5af2702
Create test_utils_render_latex.py
rich-iannone Oct 2, 2024
a0b1b8f
Tweak logic of performing length conversions
rich-iannone Oct 2, 2024
b34f7ce
Add WidthDict class to store LaTeX colwidth data
rich-iannone Oct 2, 2024
c22a9b2
Modify names dealing with colwidth metadata
rich-iannone Oct 2, 2024
3dd29bf
Use WidthDict class within util fn
rich-iannone Oct 2, 2024
59c070f
Add untranslated code as commented code
rich-iannone Oct 2, 2024
dbf4951
Make corrections to fn and arg names
rich-iannone Oct 2, 2024
1a81ae1
Add several unit tests
rich-iannone Oct 2, 2024
d185604
Remove print statement
rich-iannone Oct 2, 2024
4296be9
Add logic to derive_table_width_statement_l()
rich-iannone Oct 2, 2024
a19dc8f
Update LENGTH_TRANSLATIONS_TO_PX dict with px val
rich-iannone Oct 3, 2024
ad0c45f
Add util functions for LaTeX rendering
rich-iannone Oct 3, 2024
941b72c
Add logic for `create_fontsize_statement_l()`
rich-iannone Oct 3, 2024
60edef5
Add several tests
rich-iannone Oct 3, 2024
0da0746
Merge branch 'main' into feat-latex-rendering
rich-iannone Oct 3, 2024
1bb1da5
Add logic for `create_columns_component_l()`
rich-iannone Oct 3, 2024
b54e528
Update .gitignore
rich-iannone Oct 15, 2024
a094fb8
Update .gitignore
rich-iannone Oct 15, 2024
d8d5e8f
Add to imports for LaTeX rendering
rich-iannone Oct 15, 2024
856e636
Remove unneeded code
rich-iannone Oct 15, 2024
69e7d6e
Remove terminating newline from heading row stmt
rich-iannone Oct 15, 2024
831299f
Make correction to dict comprehension
rich-iannone Oct 15, 2024
4f25112
Remove terminating newline from table start stmt
rich-iannone Oct 15, 2024
63fdd63
Use pass instead of returning "" for a caption
rich-iannone Oct 15, 2024
5b27b35
Add logic for creating a LaTeX table heading
rich-iannone Oct 15, 2024
7a1040c
Add logic for creating a LaTeX table body
rich-iannone Oct 15, 2024
acf6e87
Add logic for creating a LaTeX table footer
rich-iannone Oct 15, 2024
43345cf
Remove unnecessary newlines
rich-iannone Oct 15, 2024
07ce01f
Remove unnecessary newlines in tbl start stmt
rich-iannone Oct 15, 2024
26e477f
Remove all newlines in wrap_end stmt
rich-iannone Oct 15, 2024
e7f07c3
Raise NotImplemented if using a stub or row groups
rich-iannone Oct 15, 2024
cc8c858
Remove stmt that creates a caption component
rich-iannone Oct 15, 2024
08b6c78
Obtain the 'use_longtable' option
rich-iannone Oct 15, 2024
f5875e4
Remove redundant variable from 'finalized_table'
rich-iannone Oct 15, 2024
269825c
Remove 'caption_component' from built LaTeX table
rich-iannone Oct 15, 2024
350cb9d
Make corrections to two LaTeX test cases
rich-iannone Oct 15, 2024
33c987e
Replace non-functional statements with TODOs
rich-iannone Oct 16, 2024
204f8ef
Merge branch 'main' into feat-latex-rendering
rich-iannone Oct 16, 2024
ad35bdf
Add the `escape_latex()` util function
rich-iannone Oct 16, 2024
ef88710
Add basic tests for `escape_latex()`
rich-iannone Oct 16, 2024
927e4ac
Add the `_context_minus_mark()` util fn
rich-iannone Oct 16, 2024
dd92e10
Add the `_context_percent_mark()` util fn
rich-iannone Oct 16, 2024
09215b6
Add the `_context_dollar_mark()` util fn
rich-iannone Oct 16, 2024
4738acb
Remove temporary version of `_context_minus_mark()`
rich-iannone Oct 16, 2024
fd228a6
Create temp copies of fmt fns for html/latex contexts
rich-iannone Oct 16, 2024
6270957
Apply `escape_latex()` to column labels
rich-iannone Oct 16, 2024
fa596c8
Make correction to erroneous context mark
rich-iannone Oct 16, 2024
b5fb89b
Define more contexts in `_context_exp_marks()`
rich-iannone Oct 16, 2024
33c72a7
Add to imports list
rich-iannone Oct 16, 2024
65a2826
Use context-aware functions for many fmt methods
rich-iannone Oct 16, 2024
6343d98
Replace body of function with 'pass'
rich-iannone Oct 16, 2024
823fdfc
Redefine function signature
rich-iannone Oct 16, 2024
695490d
Remove unneeded variable
rich-iannone Oct 16, 2024
27c1a32
Remove unused code from LaTeX column building
rich-iannone Oct 16, 2024
9811079
Comment unused code
rich-iannone Oct 16, 2024
8f4f490
Add GroupRowInfo to imports list
rich-iannone Oct 16, 2024
f6800b9
Remove type of Any for `cell_content`
rich-iannone Oct 16, 2024
82328f6
Add LaTeX examples page to docs site
rich-iannone Oct 16, 2024
ff8051c
Add LaTeX examples page to top navbar
rich-iannone Oct 16, 2024
82433a2
Move LaTeX examples to lower alphanumeric dir name
rich-iannone Oct 16, 2024
f34f2b1
Ensure that tinytex is installed after quarto install
rich-iannone Oct 16, 2024
0dd0109
Pull table_width from width_dict
rich-iannone Oct 16, 2024
7606069
Update LaTeX examples .qmd file
rich-iannone Oct 16, 2024
30625c4
Update LaTeX examples .qmd file
rich-iannone Oct 16, 2024
8385bd9
Add TODO for UnitStr conversion to LaTeX
rich-iannone Oct 16, 2024
0061441
Enlarge scope of `process_text()` to multiple contexts
rich-iannone Oct 17, 2024
874e792
Implement spanners logic in LaTeX tables
rich-iannone Oct 17, 2024
f9f1a8a
Update LaTeX examples .qmd file
rich-iannone Oct 17, 2024
6835cd5
Move away from f-string when not necessary
rich-iannone Oct 17, 2024
74ea075
Simplify example with spanner label
rich-iannone Oct 17, 2024
1caf472
Make corrections to spanner formatting in LaTeX
rich-iannone Oct 17, 2024
703fa37
Update LaTeX examples in .qmd file
rich-iannone Oct 17, 2024
ad0c4f5
Add tests for creating LaTeX table heading
rich-iannone Oct 17, 2024
98fed5c
Raise NotImplementedError for md-to-latex conversion
rich-iannone Oct 17, 2024
7697bd3
Raise NotImplementedError for using units w/ LaTeX
rich-iannone Oct 17, 2024
934a6dc
Remove certain TODOs and commented code
rich-iannone Oct 17, 2024
e99b512
Add several tests for spanners in LaTeX outputs
rich-iannone Oct 17, 2024
5913f3b
Add complicated test of spanners in LaTeX render
rich-iannone Oct 17, 2024
53cf254
Add several tests for formatting in LaTeX
rich-iannone Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions great_tables/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@
return html_table


def as_latex(self: GT) -> str:
"""
Output a GT object as LaTeX

Get the LaTeX content from a GT object as a string.

Parameters
----------
gt
A GT object.

Returns
-------
str
An LaTeX fragment containing a table.

"""
built_table = self._build_data(context="latex")

Check warning on line 186 in great_tables/_export.py

View check run for this annotation

Codecov / codecov/patch

great_tables/_export.py#L186

Added line #L186 was not covered by tests

latex_table = built_table._render_as_latex()

Check warning on line 188 in great_tables/_export.py

View check run for this annotation

Codecov / codecov/patch

great_tables/_export.py#L188

Added line #L188 was not covered by tests

return latex_table

Check warning on line 190 in great_tables/_export.py

View check run for this annotation

Codecov / codecov/patch

great_tables/_export.py#L190

Added line #L190 was not covered by tests


# Create a list of all selenium webdrivers
WebDrivers: TypeAlias = Literal[
"chrome",
Expand Down
2 changes: 2 additions & 0 deletions great_tables/_gt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,8 @@ class Options:
# page_footer_height: OptionsInfo = OptionsInfo(False, "page", "value", "0.5in")
quarto_disable_processing: OptionsInfo = OptionsInfo(False, "quarto", "logical", False)
quarto_use_bootstrap: OptionsInfo = OptionsInfo(False, "quarto", "logical", False)
latex_use_longtable: OptionsInfo = OptionsInfo(False, "latex", "boolean", False)
latex_tbl_pos: OptionsInfo = OptionsInfo(False, "latex", "value", "!t")

def _get_all_options_keys(self) -> list[str | None]:
return [x.parameter for x in self._options.values()]
Expand Down
9 changes: 9 additions & 0 deletions great_tables/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def tab_options(
row_striping_background_color: str | None = None,
row_striping_include_stub: bool | None = None,
row_striping_include_table_body: bool | None = None,
latex_use_longtable: bool | None = None,
latex_tbl_pos: str | None = None,
) -> GTSelf:
"""
Modify the table output options.
Expand Down Expand Up @@ -473,6 +475,13 @@ def tab_options(
An option for whether to include the stub when striping rows.
row_striping_include_table_body
An option for whether to include the table body when striping rows.
latex_use_longtable
An option to use the `longtable` environment in LaTeX output. This is useful for tables that
span multiple pages.
latex_tbl_pos
The position of the table in the LaTeX output. The default value is `"!t"` which means that
the table is placed at the top of the page. Other valid values are `"!b"` (bottom of the
page), `"!h"` (here), `"!p"` (on a separate page), and `"!H"` (exactly here).

Returns
-------
Expand Down
Loading
Loading