diff --git a/doc/source/options.rst b/doc/source/options.rst index 1b125fa76f68b..0b2ba03a441a2 100644 --- a/doc/source/options.rst +++ b/doc/source/options.rst @@ -307,6 +307,10 @@ display.large_repr truncate For DataFrames exceeding max_rows/max_co or switch to the view from df.info() (the behaviour in earlier versions of pandas). allowable settings, ['truncate', 'info'] +display.latex.escape True Escapes special caracters in Dataframes, when + using the to_latex method. +display.latex.longtable False Specifies if the to_latex method of a Dataframe + uses the longtable format. display.line_width 80 Deprecated. Use `display.width` instead. display.max_columns 20 max_rows and max_columns are used in __repr__() methods to decide if @@ -498,3 +502,5 @@ Enabling ``display.unicode.ambiguous_as_wide`` lets pandas to figure these chara pd.set_option('display.unicode.east_asian_width', False) pd.set_option('display.unicode.ambiguous_as_wide', False) + + diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index 21e3e86e07f37..cc7d357eb3dbd 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -26,7 +26,6 @@ Check the :ref:`API Changes ` and :ref:`deprecations `__ e.g 'rcl' for 3 columns - longtable : boolean, default False + longtable : boolean, default will be read from the pandas config module + default: False Use a longtable environment instead of tabular. Requires adding a \\usepackage{longtable} to your LaTeX preamble. - escape : boolean, default True + escape : boolean, default will be read from the pandas config module + default: True When set to False prevents from escaping latex special characters in column names. @@ -1565,7 +1574,12 @@ def to_latex(self, buf=None, columns=None, col_space=None, colSpace=None, warnings.warn("colSpace is deprecated, use col_space", FutureWarning, stacklevel=2) col_space = colSpace - + # Get defaults from the pandas config + if longtable is None: + longtable = get_option("display.latex.longtable") + if escape is None: + escape = get_option("display.latex.escape") + formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns, col_space=col_space, na_rep=na_rep, header=header, index=index, diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 70548b7c9f42f..45f528ceec02b 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -4752,6 +4752,21 @@ def test_to_dict(self): for k2, v2 in compat.iteritems(v): self.assertEqual(v2, recons_data[k2][k]) + def test_latex_repr(self): + result=r"""\begin{tabular}{llll} +\toprule +{} & 0 & 1 & 2 \\ +\midrule +0 & $\alpha$ & b & c \\ +1 & 1 & 2 & 3 \\ +\bottomrule +\end{tabular} +""" + with option_context("display.latex.escape",False): + df=DataFrame([[r'$\alpha$','b','c'],[1,2,3]]) + self.assertEqual(result,df._repr_latex_()) + + def test_to_dict_timestamp(self): # GH11247