mirror of https://github.com/Nonannet/pyladoc.git
section_class value extended to format latex using "environment". Test added and default updated with a "fineprint" class/environment
This commit is contained in:
parent
3098226c75
commit
65b9a300b9
|
@ -621,7 +621,7 @@ class DocumentWriter():
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text: The markdown text to add
|
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))
|
norm_text = _normalize_text_indent(str(text))
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,7 @@ def from_html(html_code: str) -> str:
|
||||||
self.header_flag = False
|
self.header_flag = False
|
||||||
self.attr_dict: dict[str, str] = {}
|
self.attr_dict: dict[str, str] = {}
|
||||||
self.equation_flag = False
|
self.equation_flag = False
|
||||||
|
self.class_name: str = ''
|
||||||
|
|
||||||
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
|
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}
|
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")
|
self.latex_code.append("\n\n\\noindent\\rule[0.5ex]{\\linewidth}{1pt}\n\n")
|
||||||
elif tag == 'latex':
|
elif tag == 'latex':
|
||||||
self.equation_flag = True
|
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:
|
def handle_endtag(self, tag: str) -> None:
|
||||||
if tag in html_to_latex:
|
if tag in html_to_latex:
|
||||||
|
@ -242,6 +247,9 @@ def from_html(html_code: str) -> str:
|
||||||
self.latex_code.append("}")
|
self.latex_code.append("}")
|
||||||
elif tag == 'latex':
|
elif tag == 'latex':
|
||||||
self.equation_flag = False
|
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:
|
def handle_data(self, data: str) -> None:
|
||||||
if self.equation_flag:
|
if self.equation_flag:
|
||||||
|
|
|
@ -16,11 +16,17 @@
|
||||||
\usepackage{booktabs} % For professional-looking tables
|
\usepackage{booktabs} % For professional-looking tables
|
||||||
\usepackage{pgf} % For using pgf grafics
|
\usepackage{pgf} % For using pgf grafics
|
||||||
\usepackage{textcomp, gensymb} % provides \degree symbol
|
\usepackage{textcomp, gensymb} % provides \degree symbol
|
||||||
|
\usepackage{xcolor} % For colored text
|
||||||
|
|
||||||
\sisetup{
|
\sisetup{
|
||||||
table-align-text-post = false
|
table-align-text-post = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
% Define fine print environment
|
||||||
|
\newenvironment{fineprint}
|
||||||
|
{\begin{quote}\footnotesize\color{gray}}
|
||||||
|
{\end{quote}}
|
||||||
|
|
||||||
% Geometry Settings
|
% Geometry Settings
|
||||||
\geometry{margin=1in} % 1-inch margins
|
\geometry{margin=1in} % 1-inch margins
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,12 @@
|
||||||
padding-bottom: 50px;
|
padding-bottom: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.fineprint
|
||||||
|
{
|
||||||
|
font-size: smaller;
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
|
||||||
div h1
|
div h1
|
||||||
{
|
{
|
||||||
font-size: 32px;
|
font-size: 32px;
|
||||||
|
|
|
@ -81,6 +81,8 @@ def make_document():
|
||||||
|
|
||||||
doc.add_table(df.style.hide(axis="index"), 'This is a example table', 'example1')
|
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
|
return doc
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue