diff --git a/src/pyladoc/__init__.py b/src/pyladoc/__init__.py index 48788af..66bd378 100644 --- a/src/pyladoc/__init__.py +++ b/src/pyladoc/__init__.py @@ -621,7 +621,7 @@ class DocumentWriter(): Args: text: The markdown text to add - section_class: The class for the text section + section_class: The HTML-class and LaTeX-environment name for the text section """ norm_text = _normalize_text_indent(str(text)) diff --git a/src/pyladoc/latex.py b/src/pyladoc/latex.py index e3ff9d8..8b128cc 100644 --- a/src/pyladoc/latex.py +++ b/src/pyladoc/latex.py @@ -191,6 +191,7 @@ def from_html(html_code: str) -> str: self.header_flag = False self.attr_dict: dict[str, str] = {} self.equation_flag = False + self.class_name: str = '' def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None: self.attr_dict = {k: v if v else '' for k, v in attrs} @@ -217,6 +218,10 @@ def from_html(html_code: str) -> str: self.latex_code.append("\n\n\\noindent\\rule[0.5ex]{\\linewidth}{1pt}\n\n") elif tag == 'latex': self.equation_flag = True + elif tag == 'div': + self.class_name = self.attr_dict.get('class', '') + if self.class_name: + self.latex_code.append(f"\n\\begin{{{self.class_name}}}\n") def handle_endtag(self, tag: str) -> None: if tag in html_to_latex: @@ -242,6 +247,9 @@ def from_html(html_code: str) -> str: self.latex_code.append("}") elif tag == 'latex': self.equation_flag = False + elif tag == 'div': + if self.class_name: + self.latex_code.append(f"\n\\end{{{self.class_name}}}\n") def handle_data(self, data: str) -> None: if self.equation_flag: diff --git a/src/pyladoc/templates/default_template.tex b/src/pyladoc/templates/default_template.tex index a37d64a..c7af98d 100644 --- a/src/pyladoc/templates/default_template.tex +++ b/src/pyladoc/templates/default_template.tex @@ -16,11 +16,17 @@ \usepackage{booktabs} % For professional-looking tables \usepackage{pgf} % For using pgf grafics \usepackage{textcomp, gensymb} % provides \degree symbol +\usepackage{xcolor} % For colored text \sisetup{ table-align-text-post = false } +% Define fine print environment +\newenvironment{fineprint} + {\begin{quote}\footnotesize\color{gray}} + {\end{quote}} + % Geometry Settings \geometry{margin=1in} % 1-inch margins diff --git a/src/pyladoc/templates/test_template.html b/src/pyladoc/templates/test_template.html index ace6f5e..e9dd468 100644 --- a/src/pyladoc/templates/test_template.html +++ b/src/pyladoc/templates/test_template.html @@ -21,6 +21,12 @@ padding-bottom: 50px; } + div.fineprint + { + font-size: smaller; + color: grey; + } + div h1 { font-size: 32px; diff --git a/tests/test_rendering_example2_doc.py b/tests/test_rendering_example2_doc.py index 572f01d..6d02adb 100644 --- a/tests/test_rendering_example2_doc.py +++ b/tests/test_rendering_example2_doc.py @@ -81,6 +81,8 @@ def make_document(): doc.add_table(df.style.hide(axis="index"), 'This is a example table', 'example1') + doc.add_text("This is a fine print test text section. It uses smaller text and uses grey color.", section_class='fineprint') + return doc