Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 '12 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 '12 at 16:18
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
    
Would \unexpanded help? –  egreg Apr 19 '12 at 21:55
    
@egreg thanks for the hint. It does not seems so (and neither does \noexpand). –  Christian Feuersänger Apr 19 '12 at 22:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.