# Problem importing a table containing dollar signs in pgfplots

I use pgfplot for plotting (obviously). I load a table from a file, but I have the problem that my columns can have a dollar sign in them and then LaTeX complains:

! Extra }, or forgotten $. \documentclass{beamer} \usepackage{pgfplots} \pgfplotsset{compat=1.5} \def\myplot#1{ \foreach \file in {#1} { \begingroup \pgfplotstableread{\file}\report \pgfplotstableforeachcolumn \report \as {\colname}{ \ifnum\pgfplotstablecol=0 % \else \begin{frame} \begin{tikzpicture} \begin{axis}[ title=\file, xlabel={Recall}, ylabel={Precision}, ymin=0, ymax=1, legend entries={\colname}, ] \addplot table[ y = \colname] {\file}; \end{axis} \end{tikzpicture} \end{frame} \fi } \endgroup } } \begin{document} \myplot{reports/report.csv} \end{document}  Report.csv: Recall org/apache/tools/ant/helper/ProjectHelperImpl$ProjectHandler/results.json
0.0 1.0
0.1 0.5252788975806337
0.2 0.5242015649572856
0.30000000000000004 0.5212258417099329
0.4 0.5148570391086534
0.5 0.5132710775465511
0.6000000000000001  0.4835666797890683
0.7000000000000001  0.4736173712634098
0.8 0.4705726571519701
0.9 0.46958229692873316
1.0 0.46958229692873316


I tried using \texttt, but then it complains as well with a different message:

! Missing \endcsname inserted.

It seems to me that I somehow need to escape the $, but how, seeing that I get them from a file? - Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. – Jubobs Jun 14 '13 at 12:00 This is a shot in the dark, since you didn't post any minimal working example (MWE) we could work on, but perhaps substituting \expandafter\detokenize\colname for \texttt\colname would solve the problem. – Jubobs Jun 14 '13 at 12:05 It would be great if you could edit your question and complete the code to form a complete minimal example document (starting from \documentclass, and including an example data file). – Jake Jun 14 '13 at 12:09 ## 1 Answer The problem is that the dollar sign opens math mode, but it's never closed. Since you only want to print the dollar sign, you'll somehow want to replace the $ in the string with \string$. You can do this using the xstring package by writing \StrSubstitute{\colname}{$}{\string$}[\stripped]. \documentclass{beamer} \usepackage{pgfplots} \pgfplotsset{compat=1.5} \usepackage{xstring} \def\myplot#1{ \foreach \file in {#1} { \begingroup \pgfplotstableread{\file}\report \pgfplotstableforeachcolumn \report \as {\colname}{ \ifnum\pgfplotstablecol=0 % \else \StrSubstitute{\colname}{$}{\string$}[\stripped] \begin{frame} \begin{tikzpicture} \begin{axis}[ title=\file, xlabel={Recall}, ylabel={Precision}, ymin=0, ymax=1, legend entries={\stripped}, legend style={font=\tiny, anchor=north, yshift=-8ex, at={(current axis.south)}}, ] \addplot table[ y = \colname] {\report}; \end{axis} \end{tikzpicture} \end{frame} \fi } \endgroup } } \begin{document} \myplot{report.csv} \end{document}  - Although your code solves the problem, I don't get any dollar sign in the caption when I compile it. I use PGF version: 2.10. – Jubobs Jun 14 '13 at 12:50 @Jubobs: Hm, that's strange. I'm using the TikZ CSV version, but I don't think it's an issue with that. Can you try using the article class (remove the frame environment for that) and printing the content of \stripped before the tikzpicture? – Jake Jun 14 '13 at 12:59 Just say \StrSubstitute{\colname}{$}{\string\$}[\stripped] – egreg Jun 14 '13 at 13:02
@egreg: Nice, that's much better. Thanks! – Jake Jun 14 '13 at 13:07
@Jake sorry my bad, just ignore that last comment – kutschkem Jun 14 '13 at 13:26