-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Missing _repr_latex_ method for latex/pdf conversion in jupyter notebooks #11778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -1556,6 +1565,7 @@ def to_latex(self, buf=None, columns=None, col_space=None, colSpace=None, | |||
Use a longtable environment instead of tabular. Requires adding | |||
a \\usepackage{longtable} to your LaTeX preamble. | |||
escape : boolean, default True | |||
escape : boolean, default True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are duping here
pls add a whatsnew note, otherwise looks pretty good. |
I will make the changes this evening. However, I do not know exactly where to add the whatsnew note. Do I simply edit the pandas/doc/source/whatsnew/v0.18.0.txt file? |
yep |
@@ -20,7 +20,9 @@ Check the :ref:`API Changes <whatsnew_0180.api>` and :ref:`deprecations <whatsne | |||
New features | |||
~~~~~~~~~~~~ | |||
|
|||
|
|||
- The Dataframe class got 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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use double backticks around display.latex.escape
(and also around DataFrame._repr_latex_
)
I made the changes. I did not add example code for the Jupyter notebook, because the changes are only visible when the notebook is converted to latex. |
Returns a LaTeX representation for a particular Dataframe. | ||
Mainly for use with nbconvert (jupyter notebook conversion to pdf). | ||
""" | ||
is_escaped = get_option("display.latex.escape") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these options should instead be in .to_latex
(replace the current defaults with None
, then use these)
The user can override or use the default options as the defaults.
update the .to_latex doc-string as well
@bkasel can you update according to comments |
Yes, I will do asap. I don't have a lot of free time right now. (Hopefully the WE will be better) |
OK, I think I did the adjustments the way I understood your comments. However there seem to be some conflicts. Is there a way for me to see what the conflicts are? |
@bkasel rebasing on latest master should let you solve the conflicts:
|
I get an error:
|
@@ -33,6 +33,7 @@ Other enhancements | |||
|
|||
- Handle truncated floats in SAS xport files (:issue:`11713`) | |||
- ``read_excel`` now supports s3 urls of the format ``s3://bucketname/filename`` (:issue:`11447`) | |||
- - ``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`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A -
too much at the beginning of the line
you should then replace |
I didn't call it anything. I forked the repo on github and the cloned from the forked repo to my laptop.
but I can't rebase |
Ah, yes, you have to add this yourself, see also our contributing guide where this is explained: http://pandas.pydata.org/pandas-docs/stable/contributing.html#forking
If you need more help, we also have a dev chat channel: https://gitter.im/pydata/pandas that is sometimes easier for quick help on these things |
OK, the rebase was a bit messy, since it is the first one I have done, so I had to fix it. Seems to be OK now. Thanks for your help. |
@bkasel rebase did indeed work! We also ask to squash the commits to have a cleaner history, see http://pandas.pydata.org/pandas-docs/stable/contributing.html#combining-commits |
I think I did the rebase and squashing succesfully. |
squashing should yield 1 commit. you need to push with a |
… the Jupyter/Ipython notebook. The method simply uses the existing to_latex method of the Dataframe class. The _repr_latex_ method looks for newly created options: - display.latex_escape - display.latex_longtable which are passed as arguments to the to_latex method. a simple test has been added to check if the conversion works. However, if the implementation of the to_latex method changes, the test function would also have to be updated. - fixed style problems - renamed display.latex options - remove duplicate line - added whatsnew note Merged during rebase - fixed spelling mistake in config_init.py - the defaults for the display.latex.escape option has been changed to the defaults of the to_latex method - the to_latex method now gets these defaults from the configuration - the _repr_latex_ method now simply calls the to latex method without any options - documentation has been changed accordingly - removed one``-`` from documentation fixed bad merge during rebase - fixed test_repr_latex using new defaults
Yes, I had some trouble getting the squashing done. Should only be a single commit now. |
excellent! ping when green. |
@jreback ping |
Missing _repr_latex_ method for latex/pdf conversion in jupyter notebooks
thanks! |
Nice! Thanks for the help! |
@bkasel do you know if there's an easy way to add borders to the output latex table? |
@AlJohri I don't have an easy way to do this, since it would require |
Hello, this is my very first pull request on github. I added latex/pdf conversion capabilities to the dataframe when used in a Jupyter/Ipython notebook. The method simply uses the existing to_latex method of the Dataframe class. I believe teh following Issues or PR have already attempted this, but they seem closed: #11399 and #9821
The repr_latex method looks for newly created options:
- display.latex_escape
- display.latex_longtable
which are passed as arguments to the to_latex method.
a simple test has been added to check if the conversion works. However, if the
implementation of the to_latex method changes, the test function would also have to be updated.