Skip to content

Commit

Permalink
BUG: option to avoid latex in qtconsole
Browse files Browse the repository at this point in the history
closes #12182
closes #12275
  • Loading branch information
chris-b1 authored and jreback committed Feb 10, 2016
1 parent 358da56 commit d207679
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/source/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ 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.repr False Whether to produce a latex DataFrame
representation for jupyter frontends
that support it.
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
Expand Down
13 changes: 12 additions & 1 deletion doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ See the `xarray full-documentation here <http://xarray.pydata.org/en/stable/>`__
* major_axis (major_axis) int64 0 1 2
* minor_axis (minor_axis) int64 0 1 2 3

Latex Representation
^^^^^^^^^^^^^^^^^^^^

``DataFrame`` has gained a ``._repr_latex_()`` method in order to allow for conversion to latex in a ipython/jupyter notebook using nbconvert. (:issue:`11778`)

Note that this must be activated by setting the option ``display.latex.repr`` to ``True`` (issue:`12182`)

For example, if you have a jupyter notebook you plan to convert to latex using nbconvert, place the statement ``pd.set_option('display.latex.repr', True)`` in the first cell to have the contained DataFrame output also stored as latex.

Options ``display.latex.escape`` and ``display.latex.longtable`` have also been added to the configuration and are used automatically by the ``to_latex``
method. See the :ref:`options documentation<options>` for more info.

.. _whatsnew_0180.enhancements.other:

Other enhancements
Expand All @@ -355,7 +367,6 @@ Other enhancements
- add support for ``AWS_S3_HOST`` env variable when reading from s3 (:issue:`12198`)
- A simple version of ``Panel.round()`` is now implemented (:issue:`11763`)
- For Python 3.x, ``round(DataFrame)``, ``round(Series)``, ``round(Panel)`` will work (:issue:`11763`)
- ``DataFrame`` has gained a ``_repr_latex_`` method in order to allow for automatic conversion to latex in a ipython/jupyter notebook using nbconvert. Options ``display.latex.escape`` and ``display.latex.longtable`` have been added to the configuration and are used automatically by the ``to_latex`` method. (:issue:`11778`)
- ``sys.getsizeof(obj)`` returns the memory usage of a pandas object, including the
values it contains (:issue:`11597`)
- ``Series`` gained an ``is_unique`` attribute (:issue:`11946`)
Expand Down
9 changes: 9 additions & 0 deletions pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@
(default: False)
"""

pc_latex_repr_doc = """
: boolean
Whether to produce a latex DataFrame representation for jupyter
environments that support it.
(default: False)
"""

pc_line_width_deprecation_warning = """\
line_width has been deprecated, use display.width instead (currently both are
identical)
Expand Down Expand Up @@ -314,6 +321,8 @@ def mpl_style_cb(key):
pc_east_asian_width_doc, validator=is_bool)
cf.register_option('unicode.ambiguous_as_wide', False,
pc_east_asian_width_doc, validator=is_bool)
cf.register_option('latex.repr', False,
pc_latex_repr_doc, validator=is_bool)
cf.register_option('latex.escape', True, pc_latex_escape,
validator=is_bool)
cf.register_option('latex.longtable', False, pc_latex_longtable,
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ def _repr_latex_(self):
Returns a LaTeX representation for a particular Dataframe.
Mainly for use with nbconvert (jupyter notebook conversion to pdf).
"""
return self.to_latex()
if get_option('display.latex.repr'):
return self.to_latex()
else:
return None

@property
def style(self):
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ def test_latex_repr(self):
\bottomrule
\end{tabular}
"""
with option_context("display.latex.escape", False):
with option_context("display.latex.escape", False,
'display.latex.repr', True):
df = DataFrame([[r'$\alpha$', 'b', 'c'], [1, 2, 3]])
self.assertEqual(result, df._repr_latex_())

# GH 12182
self.assertIsNone(df._repr_latex_())

def test_info(self):
io = StringIO()
self.frame.info(buf=io)
Expand Down

0 comments on commit d207679

Please sign in to comment.