Compare commits

...

3 Commits

4 changed files with 11 additions and 7 deletions

View File

@ -277,7 +277,6 @@ def inject_to_template(fields_dict: dict[str, str],
raise Exception('No template provided')
def replace_field(match: re.Match[str]) -> str:
print('--->', match.group(0))
return fields_dict.get(match.group(1), match.group(0))
return re.sub(r"(?:\%+\s*)?\<!--(.*?)-->", replace_field, template, 0, re.MULTILINE)

View File

@ -131,7 +131,7 @@ def render_pandas_styler_table(df_style: Styler, caption: str = '', label: str =
yield '\\centering\n'
# Guess column type
numeric = re.compile('^[<>-\u2212]?\\s*(?:\\d+,?)+(?:\\.\\d+)?(?:\\s\\D.*)?$')
numeric = re.compile('^[<>\\-\u2212]?\\s*(?:\\d+,?)+(?:\\.\\d+)?(?:\\s\\D.*)?$')
formats = ['S' if all(
(numeric.match(line[ci]['display_value'].strip()) for line in table['body'])
) else 'l' for ci in range(len(table['body'][0])) if table['body'][0][ci]['is_visible']]

View File

@ -68,7 +68,8 @@ unicode_to_latex_dict = {
'£': r'{\pounds}',
'¥': r'{\yen}',
'\u00A0': r'~', # Non-breaking space
'\u2007': ' ' # Figure space
'\u2007': ' ', # Figure space
'\u2212': '-' # Unicode minus sign
}
latex_escape_dict = {

View File

@ -71,11 +71,11 @@ def make_document():
mydataset = {
'Row1': ["Line1", "Line2", "Line3", "Line4", "Line5"],
'Row2': [120, '95 km/h', 110, '105 km/h', 130],
'Row3': ['12 g/km', '> 150 g/km', '110 g/km', '1140 g/km', '13.05 g/km'],
'Row3': ['12 g/km', '> 150 g/km', '-110 g/km', '1140 g/km', '\u221213.05 g/km'],
'Row4': ['5 stars', '4 stars', '5 stars', '4.5 stars', '5 stars'],
'Row5': [3.5, 7.8, 8.5, 6.9, 4.2],
'Row6': ['1850 kg', '1500 kg', '1400 kg', '1600 kg', '1700 kg'],
'Row7': ['600 Nm', '250 Nm', '280 Nm', '320 Nm', '450 Nm']
'Row6': ['1850 kg', '150 kg', '140 kg', '1600 kg', '17.55 kg'],
'Row7': ['600 Nm', '250 Nm', '280,8 Nm', '320 Nm', '450 Nm']
}
df = pd.DataFrame(mydataset)
@ -98,9 +98,13 @@ def test_html_render():
def test_latex_render():
doc = make_document()
latex_code = doc.to_latex()
assert r'\begin{tabular}{lSSSSSS}' in latex_code, "Table format not correct in LaTeX output"
if WRITE_RESULT_FILES:
with open('tests/out/test_html_render2.tex', 'w', encoding='utf-8') as f:
f.write(doc.to_latex())
f.write(latex_code)
assert doc.to_pdf('tests/out/test_latex_render2.pdf', font_family='serif')
else: