Результат Catchfile не работает внутри среды tikzpicture

Результат Catchfile не работает внутри среды tikzpicture

Это продолжение этоговопрос. Я пытаюсь получить точки для графического отображения с использованием данных из внешнего файла. Вертикальные координаты — это страны, а горизонтальные — годы. Чтобы это работало, мне нужно предоставить среде axisсписок стран в виде символических координат, и вот тут у меня проблемы.

В MWE ниже, в первой tikzpicture я вручную предоставляю список стран, и все в порядке. Во второй tikzpicture я предоставляю список, загруженный из внешнего файла с помощью \CatchFileDefкоманды из catchfileпакета. Это создает ошибку, хотя команда, \listcountriesкажется, содержит тот же самый текст, что и тот, который я вставлял вручную (а именно: AUT,GER,FRA).

Можете ли вы объяснить, почему \CatchFileDefэто не работает в данном контексте?

\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}

решение1

Аргумент не расширен; его необходимо расширить, прежде чем \begin{axis}впитать варианты:

\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}

Связанный контент