Merge pull request #4 from Nonannet/dev

section_class value extended to format latex using "environment". Tes…
This commit is contained in:
Nicolas Kruse 2025-09-09 23:10:58 +02:00 committed by GitHub
commit c7123e23d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 25 additions and 1 deletions

View File

@ -140,6 +140,7 @@ jobs:
path: tests/out/test_*_render*.pdf
build-docs:
if: github.event_name == 'push'
needs: build-ubuntu
runs-on: ubuntu-latest
steps:
@ -183,6 +184,7 @@ jobs:
path: docs/build/html
deploy:
if: github.event_name == 'push'
needs: build-docs
runs-on: ubuntu-latest
permissions:

View File

@ -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))

View File

@ -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:

View File

@ -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

View File

@ -21,6 +21,12 @@
padding-bottom: 50px;
}
div.fineprint
{
font-size: smaller;
color: grey;
}
div h1
{
font-size: 32px;

View File

@ -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