[Tex/LaTex] How to get a % sign in symbolic x coords in pgfplots

pgfplots

I have some data I want to plot in a bar chart where the name on the x-axis should have a % sign in it. So this works:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    ybar,
    symbolic x coords={10 perc,20 perc},
    ]
    \addplot coordinates {(10 perc,10) (20 perc,20)};
  \end{axis}
\end{tikzpicture}
\end{document}

But if I try something like:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    ybar,
    symbolic x coords={10\%,20\%},
    ]
    \addplot coordinates {(10\%,10) (20\%,20)};
  \end{axis}
\end{tikzpicture}
\end{document}

I get the following error:

ERROR: Missing \endcsname inserted.

--- TeX said ---
<to be read again> 
                   \%
l.8         ]

This happens in and out of math mode.

\\\% causes pdflatex to hang.

Thanks in advance!

Best Answer

LaTeX has a safe percent macro but it uses an @ name so first give it a name without an @.

\documentclass{article}
\usepackage{pgfplots}
\makeatletter
\let\percent\@percentchar
\makeatother

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    ybar,
    symbolic x coords={10\percent,20\percent},
    ]
    \addplot coordinates {(10\percent,10) (20\percent,20)};
  \end{axis}
\end{tikzpicture}
\end{document}