Skip to content

Commit 33ef5e8

Browse files
committed
ENH: start latex
1 parent 76e0588 commit 33ef5e8

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

pandas/formats/style.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,20 @@ def _highlight_extrema(data, color='yellow', max_=True):
815815
index=data.index, columns=data.columns)
816816

817817

818+
class LatexStyler(BaseStyler):
819+
820+
environment = Environment(
821+
block_start_string="((*",
822+
block_end_string="*))",
823+
variable_start_string="(((",
824+
variable_end_string=")))",
825+
comment_start_string="((=",
826+
comment_end_string="=))",
827+
loader=PackageLoader('pandas', 'formats/templates')
828+
)
829+
template = environment.get_template('latex.j2')
830+
831+
818832
def _maybe_wrap_formatter(formatter):
819833
if com.is_string_like(formatter):
820834
return lambda x: formatter.format(x)

pandas/formats/templates/latex.j2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
((* block header *))
2+
3+
\begin{tabular}
4+
((* for r in head *))
5+
6+
((* endfor *))
7+
8+
\hline
9+
10+
((* for row in body *))
11+
((* for cell in row *))
12+
((* if loop.last *))
13+
((( cell ))) \\
14+
((* else *))
15+
((( cell ))) &
16+
((* endif *))
17+
((* endfor *))
18+
((* endfor *))
19+
\end{tabular}
20+
21+
((* endblock header *))
22+

pandas/tests/formats/test_style.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,11 @@ def test_background_gradient(self):
555555
result = (df.style.background_gradient(subset=pd.IndexSlice[1, 'A'])
556556
._compute().ctx)
557557
self.assertEqual(result[(1, 0)], ['background-color: #fff7fb'])
558+
559+
class TestLatexStyler(TestCase):
560+
561+
def test_smoke(self):
562+
df = pd.DataFrame(np.arange(12).reshape(4, 3))
563+
from pandas.formats.style import LatexStyler
564+
style = LatexStyler(df)
565+
style.template.render()

0 commit comments

Comments
 (0)