0

我正在尝试从文件中读取一些坐标,然后使用 TikZ 绘制它们。该文件采用以下格式:

timestamp 1.002132 3.2131231
timestamp 1.332132 2.9120

这是我的代码:

\begin{tikzpicture}

    \draw[step=0.5,black,thin,xshift=0cm,yshift=0cm, opacity=0.3] (0,0) grid (8,4);

    \draw [->](-.5,.5) -- (8.5,.5);
    \draw [->] (4, -.5) -- (4, 4.5);

    % read file and draw coordinates
      \newread\file
      \openin\file=recording2
        \loop
          \read\file to\fileline
          \unless\ifeof\file

            % Fetch coordinates in \coordX and \coordY
            \StrSplit{\fileline}{14}{\ts}{\coords}
            \def\coordX{\StrBefore{\coords}{ }}
            \def\coordY{\StrBehind{\coords}{ }}

            \draw (1,1) node {\coordX}; %this works fine
            \draw (1,1) node {\coordY}; %this works fine
            \draw (\coordX+4,\coordY+0.5) circle(1pt); %this cause the error
        \repeat
      \closein\file

  \end{tikzpicture}

我已经打印了 coordX 和 coordY 的值,它们是正确的。你知道是什么导致了错误吗?我是否必须“转换”这些值才能让 TikZ 将这些值解释为数值?

我试过编辑 LaTeX 的内存设置,但没有运气,所以我认为错误在代码中(duh-uh)。

4

1 回答 1

2

好吧,我想我知道为什么它不起作用了。

xstring包裹:

The macros of this package are not purely expandable

我相信这就是为什么我的coordXcoordY不能被评估为一个论点。

我通过切换解决了

\def\coordX{\StrBefore{\coords}{ }}
\def\coordY{\StrBehind{\coords}{ }}

\StrBefore{\coords}{ }[\coordX]
\StrBehind{\coords}{ }[\coordY]

这显然是要走的路xstring

于 2014-09-01T09:33:20.587 回答