astropy icon indicating copy to clipboard operation
astropy copied to clipboard

Issue with underscores in strings when writing out LaTeX tables

Open astrofrog opened this issue 3 years ago • 0 comments

Description

When writing out a Table with string columns containing an underscore to LaTeX, underscores are not escaped, which can cause issues.

Steps to Reproduce

First run:

from astropy.table import Table
t = Table()
t['a'] = ['a_a', 'b_b', 'c_c']
t.write('table.tex')

then try and typeset the following LaTeX document:

\documentclass[11pt]{article}
\begin{document}
\input{table}
\end{document}

which fails with:

! Missing $ inserted.
<inserted text> 
                $
l.4 a_

I guess this is a tricky one because people might already have worked around this by escaping things like underscores in the strings, or using math mode if relevant, but it would be nice to have a simple option to escape any characters that might be considered LaTeX (underscore, dollar, backslash).

astrofrog avatar Sep 02 '22 09:09 astrofrog