Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow rendering of tables to LaTeX (#481)
* Get components in place for LaTeX rendering * Add two `latex*` options in `tab_options()` * Add the `check_quarto()` util function * Define logic in `create_wrap_start_l()` * Add WIP LaTeX table component building fns * Create test_utils_render_latex.py * Tweak logic of performing length conversions * Add WidthDict class to store LaTeX colwidth data * Modify names dealing with colwidth metadata * Use WidthDict class within util fn * Add untranslated code as commented code * Make corrections to fn and arg names * Add several unit tests * Remove print statement * Add logic to derive_table_width_statement_l() * Update LENGTH_TRANSLATIONS_TO_PX dict with px val * Add util functions for LaTeX rendering * Add logic for `create_fontsize_statement_l()` * Add several tests * Add logic for `create_columns_component_l()` * Update .gitignore * Update .gitignore * Add to imports for LaTeX rendering * Remove unneeded code * Remove terminating newline from heading row stmt * Make correction to dict comprehension * Remove terminating newline from table start stmt * Use pass instead of returning "" for a caption * Add logic for creating a LaTeX table heading * Add logic for creating a LaTeX table body * Add logic for creating a LaTeX table footer * Remove unnecessary newlines * Remove unnecessary newlines in tbl start stmt * Remove all newlines in wrap_end stmt * Raise NotImplemented if using a stub or row groups * Remove stmt that creates a caption component * Obtain the 'use_longtable' option * Remove redundant variable from 'finalized_table' * Remove 'caption_component' from built LaTeX table * Make corrections to two LaTeX test cases * Replace non-functional statements with TODOs * Add the `escape_latex()` util function * Add basic tests for `escape_latex()` * Add the `_context_minus_mark()` util fn * Add the `_context_percent_mark()` util fn * Add the `_context_dollar_mark()` util fn * Remove temporary version of `_context_minus_mark()` * Create temp copies of fmt fns for html/latex contexts * Apply `escape_latex()` to column labels * Make correction to erroneous context mark * Define more contexts in `_context_exp_marks()` * Add to imports list * Use context-aware functions for many fmt methods * Replace body of function with 'pass' * Redefine function signature * Remove unneeded variable * Remove unused code from LaTeX column building * Comment unused code * Add GroupRowInfo to imports list * Remove type of Any for `cell_content` * Add LaTeX examples page to docs site * Add LaTeX examples page to top navbar * Move LaTeX examples to lower alphanumeric dir name * Ensure that tinytex is installed after quarto install * Pull table_width from width_dict * Update LaTeX examples .qmd file * Update LaTeX examples .qmd file * Add TODO for UnitStr conversion to LaTeX * Enlarge scope of `process_text()` to multiple contexts * Implement spanners logic in LaTeX tables * Update LaTeX examples .qmd file * Move away from f-string when not necessary * Simplify example with spanner label * Make corrections to spanner formatting in LaTeX * Update LaTeX examples in .qmd file * Add tests for creating LaTeX table heading * Raise NotImplementedError for md-to-latex conversion * Raise NotImplementedError for using units w/ LaTeX * Remove certain TODOs and commented code * Add several tests for spanners in LaTeX outputs * Add complicated test of spanners in LaTeX render * Add several tests for formatting in LaTeX * Add several tests for formatting in LaTeX * Add fn to selectively escape for LaTeX (for pattern str) * Add tests for `escape_pattern_str_latex()` * Add test for `escape_pattern_str_latex()` * Perform LaTeX-escaping of pattern in several fmt methods * Use context-aware fns for more fmt methods * Add example to LaTeX .qmd file * Make correction to LaTeX examples .qmd file * Move `process_string()` fn to `_utils.py` * Add docstring for the `process_string()` util fn * Add docstrings for several LaTeX-rendering fns * Add tests for creation of LaTeX table footer * Add DataFrame fixture for datetime formatting * Add tests for date and time formatting in LaTeX * Add test for datetime formatting in LaTeX * Add the `_latex_escape()` util fn * Use `_latex_escape()` within `_process_text()` * Add the `_get_visible_cells()` util fn * Add `migrate_unformatted_to_output()` util fn * Add to imports list * When building LaTeX table, process unformatted text * Use `_process_text()` when rendering LaTeX * Create test_text.py * Remove unneeded tests * Ensure source notes are processed for LaTeX * Ensure context is set in `_process_text()` call * Modify text in comments * Reorganize LaTeX escaping functions and tests * Make correction to import statement * Move _render_as_latex() out of gt.py * Add docstring * Use variable instead of hardcoded value * Remove unneeded import * Modify docstring of `as_latex()` * Ensure that title/subtitle undergo text processing * Remove unneeded comment * Create and use methods of Text/Md/Html * Update index.qmd * Add tests for generation of tbl fontsize stmt * Add tests for deriving tbl width stmts * Add test for creation of tbl fontsize stmt * Add test for LaTeX tbl width statement * Change main arg of `_render_as_latex()` * Add TODOs to LaTeX body component fn * Add tests for `create_table_end_l()` * Add snapshot test using `as_latex()` * Add snapshot test for `_render_as_latex()` * Modify function call * Add tests for Text, Md, Html class methods * Add tests for `_process_text()` * Add more tests with text processing * Add an `as_latex()` snapshot test * Add more tests for `utils_render_latex.py` * Add test of `UnitStr.to_latex()` * Add more LaTeX fmt tests; check pattern is escaped * Add more complete documentation to `as_latex()` * Add `as_latex()` to the API reference guide * Add to the `as_latex()` limitations docs * Update docs of `as_latex()` method * Remove duplicated test * Add test of `fmt_bytes()` in LaTeX output table * Add to docs of the `as_latex()` method * Remove unused import * Make `_migrate_unformatted_to_output()` a fn * Make fn name more descriptive * Remove unused code * Improve documentation of `process_string()` * Further tweak docstring of `process_string()` * Add more tests of CSS length strings * Add tests that verify stub/group rendering raises * Add snapshot test of floating LaTeX table * Remove unneeded statement * Remove two unneeded statements * Remove several unneeded statements * Add tests for `create_table_start_l()` util fn * Remove unneeded statement * Remove unused `width_dict` arg from LaTeX fns * Allow for partial[FormatFn] type in FormatFns * Refactor formatters to use a double-`partial()` * Refactor formatting with `fmt_by_context()` wrapper * Exit early from `_migrate_...()` fn if not LaTeX output * Move longtable/pos opts to args in LaTeX render fn * Include type annotations for `_migrate_...()` * Create BaseText class and methods * Add tests for BaseText class * Ignore type in test that raises * Use specific types in WidthDict * Add TblWidthLatex class for making a tbl width str * Remove WidthDict as not used currently * Use BaseText type annotation in SpannerInfo * Use BaseText in `tab_spanner()` method * Add docstring for BaseText * Add to LaTeX examples .qmd file * Remove unneeded TblWidthLatex class * Remove unneeded imports * Add more tests of `create_table_start_l()` * Modify ValueError text * Add tests of `_migrate_unformatted_to_output()` * Update example LaTeX .qmd file * Make correction to Polars code * Add docstring to `is_quarto_render()` * Clean up implementation of Text classes * Hide LaTeX examples from top nav * Make changes based on code review * Update .gitignore * Raise when using `fmt_markdown()` in LaTeX context * Correct string used in error message * Make fmt_image() raise NotImplemented for LaTeX * Only warn when using fmt_image() in LaTeX output * Remove fmt_image_not_implemented() * Update docstring for as_latex() * Add more LaTeX examples to existing .qmd file * Fix paths to data files in LaTeX .qmd examples
- Loading branch information