7

I would like to place some LaTeX math code in the columns of a file to be read by pgfplotstable. Unlike How to use underscores with pgfplotstable?, I would like the columns to be formatted so LaTeX will interpret the subscripts and symbols that it contains. For example, I have a data file that looks like:

{Time}   {$\theta$}   {Fit to $C_a \tan 3\theta$}
0        0.2          0.195
...

Every time I try to read a file like this with pgfplotstable, I get an error:

! Missing \endcsname inserted.
<to be read again>
                   \mathop
l.101       }
             ^^M

Is it possible to have the formatting embedded in the column headings of a data file? If so, how?

2
  • In what context to you want to use the LaTeX code contained in the tables? In a table printed using \pgfplotstabletypeset, or as a legend in a PGFplots plot?
    – Jake
    Apr 18, 2012 at 15:05
  • @Jake: Let's say I'd like to use it in a legend. I figure if I change how the column is generated, I'm more likely to change the column name than the LaTeX code generating the plot.
    – sappjw
    Apr 18, 2012 at 16:18

1 Answer 1

7

pgfplotstable assumes that column names do not contain expandable material.

Its way of dealing with "display names" is to provide the display names explicitly using the column name key which is used during \pgfplotstabletypeset.

Protecting expandable material in column names is unsupported. It is unlikely that pgfplotstable will support such protection automatically in the future (because protection cannot be done during \edef which is a common use case of access to columns).

So, the answer is: no, this is generally unsupported. Period.

You can hack the processing such that it does basic escaping - on your own risk. You should skip this section unless you know what you are doing and you know why you are doing it. Do not blame me. This here would work if you wanted to typeset the table:

\let\ESCAPE=\string
\pgfplotstabletypeset[
    every head row/.style={before row={\global\let\ESCAPE=\relax}},
]{
{Time}   {$\ESCAPE\theta$}   {Fit to $C_a \ESCAPE\tan 3\ESCAPE\theta$}
0        0.2          0.195
}

It is based on the fact that \string\macro yields the string sequence "\ m a c r o" . Clearly, you would need to change the header of your input table for such an approach.

2
  • Would \unexpanded help?
    – egreg
    Apr 19, 2012 at 21:55
  • @egreg thanks for the hint. It does not seems so (and neither does \noexpand). Apr 19, 2012 at 22:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .