El resultado de Catchfile no funciona dentro de un entorno tikzpicture

El resultado de Catchfile no funciona dentro de un entorno tikzpicture

Este es un seguimiento de esto.pregunta. Estoy intentando graficar puntos utilizando datos de un archivo externo. Las coordenadas verticales son países y las horizontales son años. Para que esto funcione necesito proporcionar al axismedio ambiente la lista de países como coordenadas simbólicas, y aquí es donde tengo problemas.

En el MWE a continuación, en la primera imagen tikz, proporciono la lista de países manualmente y todo está bien. En la segunda imagen de tikz, proporciono la lista cargada desde un archivo externo usando \CatchFileDefel comando del catchfilepaquete. Esto crea un error a pesar de que el comando \listcountriesparece contener exactamente el mismo texto que el que estaba ingresando manualmente (es decir: AUT,GER,FRA).

¿Puedes explicar por qué \CatchFileDefno funciona en este contexto?

\documentclass{standalone}
\usepackage{filecontents,catchfile}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage{pgfplotstable}

\begin{filecontents}{testcountries.txt}
AUT,GER,FRA
\end{filecontents}

\begin{filecontents}{CountryYears.csv}
    #########################################################
    country,year
    AUT,1998
    AUT,1999
    AUT,2000
    GER,1999
    GER,2000
    GER,2001
    GER,2002
    FRA,2000
    FRA,2001
    FRA,2002
    FRA,2003
    #########################################################
\end{filecontents}

\begin{document}
    \pgfplotstableset{columns/country/.style={string type}}
    \pgfplotstableread[col sep=comma]{CountryYears.csv}\loadeddata

    \CatchFileDef{\listcountries}{testcountries.txt}{}

    This is the list of countries from testcountries.txt:   \listcountries 

    \bigskip

    \begin{tikzpicture}
    \begin{axis}[symbolic y coords={AUT,GER,FRA
    },ytick=data,
    x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed},]
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

    \begin{tikzpicture}
    \begin{axis}[symbolic y coords={\listcountries
        },ytick=data,
    x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed},]
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

\end{document}

Respuesta1

El argumento no se amplía; necesitas expandirlo antes de \begin{axis}que absorba las opciones:

\documentclass{standalone}
\usepackage{filecontents,catchfile}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage{pgfplotstable}

\begin{filecontents}{testcountries.txt}
AUT,GER,FRA
\end{filecontents}

\begin{filecontents}{CountryYears.csv}
    country,year
    AUT,1998
    AUT,1999
    AUT,2000
    GER,1999
    GER,2000
    GER,2001
    GER,2002
    FRA,2000
    FRA,2001
    FRA,2002
    FRA,2003
\end{filecontents}

\begin{document}
    \pgfplotstableset{columns/country/.style={string type}}
    \pgfplotstableread[col sep=comma]{CountryYears.csv}\loadeddata

    \CatchFileDef{\listcountries}{testcountries.txt}{}

    This is the list of countries from testcountries.txt:   \listcountries 

    \bigskip

    \begin{tikzpicture}
    \begin{axis}[
      symbolic y coords={AUT,GER,FRA},
      ytick=data,
      x tick label style={
        /pgf/number format/.cd,
        scaled x ticks = false,
        set thousands separator={},
        fixed
      },
    ]
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

    \begin{tikzpicture}
    \begingroup\edef\x{\endgroup
      \noexpand\begin{axis}[
        symbolic y coords={\unexpanded\expandafter{\listcountries}},
        ytick=data,
        x tick label style={
          /pgf/number format/.cd,%
          scaled x ticks = false,
          set thousands separator={},
          fixed
        },
      ]}\x
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

\end{document}

información relacionada