Skip to content

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

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions