Skip to content

io.ascii latex tables - take unit from inout table if given #2870

Closed

Description

@hamogu

Inspired by #2869

LaTeX and AASTex already have a mechanism to print units, but only if explicetly passed in. If no units are given, those writers could use the units already defined in the table column - we have a latex representation for that.

This works:

from astropy.table import Table, Column
import astropy
from copy import deepcopy
COSobs = Table([Column(name='date', data=['a','b']),
                Column(name='NUV exp.time', data=[1,2]),
                ])
latexdict = deepcopy(astropy.io.ascii.latexdicts['AA'])
latexdict['units'] = {'NUV exp.time':'s', 'FUV ext.time':'s'}
COSobs.write(sys.stdout, format='ascii.aastex', latexdict=latexdict,
             caption=r"\label{tab:obsCOS}Observations log of \emph{HST}/COS observations")

out:

\begin{table}{cc}
\tablecaption{\label{tab:obsCOS}Observations log of \emph{HST}/COS observations}
\tablehead{\colhead{date} & \colhead{NUV exp.time}\\ \colhead{ } & \colhead{s}}
\startdata
a & 1 \\
b & 2 \\
\enddata
\end{table}

But this should probably also work:

COSobs = Table([Column(name='date', data=['a','b']),
                Column(name='NUV exp.time', data=[1,2], unit=astropy.units.s),
                ])
COSobs.write(sys.stdout, format='ascii.aastex')

No units in output:

\begin{deluxetable}{cc}
\tablehead{\colhead{date} & \colhead{NUV exp.time}}
\startdata
a & 1 \\
b & 2 \\
\enddata
\end{deluxetable}

Activity

  1. modified the milestones: v0.4.2, v1.0.0 on Sep 21, 2014
  2. mdmueller commented on Oct 30, 2014

    @mdmueller
    Contributor

    I just tried implementing this and found that changing the unit functionality will break certain tests in test_write.py. @hamogu - Do you have a sense for whether this will cause significant compatibility issues?

  3. hamogu commented on Oct 30, 2014

    @hamogu
    MemberAuthor

    Here we explicitly want a change in behaviour. If units are specified in a table, then they shall also be in the output. Since we don't have that now, all tests that use a table with units will have to change.

    Yes, this is a slight change in API, but I am totally fine with it for three reasons:

    • The current behaviour could be considered a bug (it implicitly drops information) that should be fixed.
    • LaTeX tables are almost never used to exchange data between applications. They are only written as really final output at the end of a toolchain when everything is ready for publication. Thus, we are not going to break someones analysis script, we are only going to change the appearance of the table on page 3 (or whatever) of the book he is writing.
    • We never promised that LaTeX tables round-trip and the docs definitely warn that the LaTeX reader is not feature complete in the sense that many LaTeX tables will not be read by this reader, although they are totally valid (e.g. tables where the data row are broken over different lines in the file - I suggest to fix some of those in io.ascii.Latex and AASTex: Make reading more flexible #1525, but there are many LaTeX commands that we will never read such as \multicolumn).

    We should however think about reading tables with units and see if we can at least read the tables that we write (it's not a required feature to round-trip LaTeX tables, but would be nice).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions