Compare commits

..

No commits in common. "b3c2f5e384a27b117189c1c6220015e6d4901478" and "c9086026577caa3cd6297f6d4abfaf2c342f8861" have entirely different histories.

4 changed files with 7 additions and 22 deletions

View File

@ -673,8 +673,7 @@ class DocumentWriter():
def to_pdf(self, file_path: str,
font_family: Literal[None, 'serif', 'sans-serif'] = None,
table_renderer: TRenderer = 'simple',
latex_template_path: str = '',
engine: latex.LatexEngine = 'pdflatex') -> bool:
latex_template_path: str = '') -> bool:
"""
Export the document to a PDF file using LaTeX.
@ -684,7 +683,6 @@ class DocumentWriter():
latex_template_path: Path to a LaTeX template file. The
expression <!--CONTENT--> will be replaced by the generated content.
If no path is provided a default template is used.
engine: LaTeX engine (pdflatex, lualatex, xelatex or tectonic)
Returns:
True if the PDF file was successfully created
@ -695,7 +693,7 @@ class DocumentWriter():
if font_family == 'sans-serif':
latex_code = latex.inject_latex_command(latex_code, '\\renewcommand{\\familydefault}{\\sfdefault}')
success, errors, warnings = latex.compile(latex_code, file_path, engine=engine)
success, errors, warnings = latex.compile(latex_code, file_path)
if not success:
print('Errors:')

View File

@ -1,5 +1,5 @@
from html.parser import HTMLParser
from typing import Generator, Any, Literal, get_args
from typing import Generator, Any
from pandas.io.formats.style import Styler
import re
import os
@ -9,9 +9,6 @@ import tempfile
from .latex_escaping import unicode_to_latex_dict, latex_escape_dict
LatexEngine = Literal['pdflatex', 'lualatex', 'xelatex', 'tectonic']
def basic_formatter(value: Any) -> str:
return escape_text(str(value))
@ -251,7 +248,7 @@ def from_html(html_code: str) -> str:
return ''.join(parser.latex_code)
def compile(latex_code: str, output_file: str = '', encoding: str = 'utf-8', engine: LatexEngine = 'pdflatex') -> tuple[bool, list[str], list[str]]:
def compile(latex_code: str, output_file: str = '', encoding: str = 'utf-8') -> tuple[bool, list[str], list[str]]:
"""
Compiles LaTeX code to a PDF file.
@ -259,7 +256,6 @@ def compile(latex_code: str, output_file: str = '', encoding: str = 'utf-8', eng
latex_code: The LaTeX code to compile.
output_file: The output file path.
encoding: The encoding of the LaTeX code.
engine: LaTeX engine (pdflatex, lualatex, xelatex or tectonic)
Returns:
A tuple with three elements:
@ -268,13 +264,8 @@ def compile(latex_code: str, output_file: str = '', encoding: str = 'utf-8', eng
- A list of warnings.
"""
assert engine in get_args(LatexEngine), "engine must be pdflatex, lualatex, xelatex or tectonic"
with tempfile.TemporaryDirectory() as tmp_path:
if engine == 'tectonic':
command = ['tectonic', '--outdir', tmp_path, '-']
else:
command = [engine, '--halt-on-error', '--output-directory', tmp_path]
command = ['pdflatex', '-halt-on-error', '--output-directory', tmp_path]
errors: list[str] = []
warnings: list[str] = []

View File

@ -168,9 +168,7 @@ def test_latex_render():
with open('tests/out/test_html_render1.tex', 'w', encoding='utf-8') as f:
f.write(doc.to_latex())
assert doc.to_pdf('tests/out/test_latex_render1.pdf', font_family='serif')
else:
assert doc.to_pdf('', font_family='serif') # Write only to temp folder
assert doc.to_pdf('tests/out/test_latex_render1.pdf', font_family='serif')
if __name__ == '__main__':

View File

@ -102,9 +102,7 @@ def test_latex_render():
with open('tests/out/test_html_render2.tex', 'w', encoding='utf-8') as f:
f.write(doc.to_latex())
assert doc.to_pdf('tests/out/test_latex_render2.pdf', font_family='serif')
else:
assert doc.to_pdf('', font_family='serif') # Write only to temp folder
assert doc.to_pdf('tests/out/test_latex_render2.pdf', font_family='serif')
if __name__ == '__main__':