Skip to content

ascii.latex.AASTex: don't include new line characters after last row of data #3888

Closed

Description

@jrka

Very minor issue: writing a table in AASTex (deluxetable) format includes new line characters at the end of each line, including the last one. This results in a blank line at the end of each table. The last row of a table before "\enddata" should not include the "\" characters.

Example:

from astropy.io import ascii
from astropy.table import Table
import sys    
t = Table([[1,2],[1.234e9,2.34e-12]], names = ('a','b'))
ascii.write(t,sys.stdout,Writer=ascii.latex.AASTex)

Result:

\begin{deluxetable}{cc}
 \tablehead{\colhead{a} & \colhead{b}}
\startdata
1 & 1234000000.0 \\
2 & 2.34e-12 \\
\enddata
\end{deluxetable}

Which looks like:
image

But if you got rid of the "\" after 2.34e-12, you'd get:
image

Activity

  1. embray commented on Jun 26, 2015

    @embray
    Member

    Confirmed, and definitely worth fixing.

  2. taldcroft commented on Jun 30, 2015

    @taldcroft
    Member

    I personally think this is an upstream issue in LaTeX, but I agree we can fix this here. 😄

    Here is a brutal hack that does the trick. Can you think of a better way @hamogu ?

    diff --git a/astropy/io/ascii/latex.py b/astropy/io/ascii/latex.py
    index 187cf99..c05e986 100644
    --- a/astropy/io/ascii/latex.py
    +++ b/astropy/io/ascii/latex.py
    @@ -385,6 +385,7 @@ class AASTexData(LatexData):
         def write(self, lines):
             lines.append(self.data_start)
             core.BaseData.write(self, lines)
    +        lines[-1] = lines[-1][:-2]  # strip off final '\\' of last data line
             lines.append(self.data_end)
             add_dictval_to_list(self.latex, 'tablefoot', lines)
             lines.append(r'\end{' + self.latex['tabletype'] + r'}')
    
  3. taldcroft commented on Jun 30, 2015

    @taldcroft
    Member

    Oh, does plain LaTeX have the same problem? The table output has the same final trailing \\ but I don't know if this is a problem for plain tables.

  4. hamogu commented on Jun 30, 2015

    @hamogu
    Member

    @taldcroft : I think that's fine. This is a very specialized reader/writer where we can do these "ad-hoc" solutions.
    Do you want to convert this into a PR? I would ask you to add a comment to the code above the line that you added that explains what it does. It's not immediately obvious for future maintainers.

    Also, I just checked regular LaTeX. That does not have this problem; it seems to be specific to ApJ's deluxetable package.

  5. taldcroft commented on Jun 30, 2015

    @taldcroft
    Member

    @jrka - do you want to take a crack at this? In any case I'm leaving this open as low-hanging fruit for the upcoming astropy sprint at scipy 2015.

  6. jrka commented on Jun 30, 2015

    @jrka
    Author

    @taldcroft , since scipy is just next week I'll keep it on the back burner for now. But if no one gets to it, I will do so!

  7. shwetamore1295 commented on Jan 26, 2016

    @shwetamore1295

    If this issue isn't fixed, can I work on this issue?

  8. taldcroft commented on Jan 26, 2016

    @taldcroft
    Member

    @shwetamore1295 - go for it!

  9. anchitjain1234 commented on Feb 4, 2016

    @anchitjain1234
    Contributor

    Please check #4561.

  10. added 4 commits that reference this issue on Feb 5, 2016
    bda5d51
    d142624
    848f2ba
    8c34517
  11. added 2 commits that reference this issue on Jun 12, 2016
    8882649
    9a8b9a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions