0

I'm trying to read some coordinates from a file and then draw them using TikZ. The file is on this format:

timestamp 1.002132 3.2131231
timestamp 1.332132 2.9120

This is the code I have:

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

I have printed both the values of coordX and coordY and they are correct. Do you have any idea what is causing the error? Do I have to "cast" the values in order for TikZ to interpret the values as numeric values?

I have tried editing the memory settings for LaTeX with no luck, so I assume the error is in the code(duh-uh).

tshepang
  • 12,111
  • 21
  • 91
  • 136
msfoster
  • 2,474
  • 1
  • 17
  • 19

1 Answers1

2

Well, I think I figured out why it didn't work.

xstring package:

The macros of this package are not purely expandable

I believe that's why my coordX and coordY couldn't be evaluated as an argument.

I solved it by switching

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

to

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

This is apparantly the way to go with xstring.

msfoster
  • 2,474
  • 1
  • 17
  • 19