I created a TikZ coordinate system to solve a positioning problem I had. The code is presented below. However, the code doesn't work; if you run it, you will get the

Too many .'s

error message even though there are, in fact, the correct number of dots in each coordinate in the test tikzpicture. Careful investigation reveals that the macro \sidecs@numberofats is not being populated with the correct value: it always ends up being zero.

Since I have used \makeatletter before defining the coordinate system code, but "@" is an "other" character in the tikzpicture where the coordinates appear, my assumption is that this is a catcode issue. This supposition is backed up by the fact that if you change @ to : everywhere it appears (apart from in macro names, obviously), the document compiles successfully and has the expected appearance.

How can I get XString to count the @ characters? Most XString macros have a starred version that (as the manual explains) disregards catcodes, but for whatever reason, \StrCount does not.

(I wanted to use the built-in PGF parsing library to do this rather than XString, but it isn't full-featured enough. Specifically, it appears that you can't provide a rule that works for "any character not amongst those separately specified", and since I want to accept node names - which might contain almost any character at all - this is no good.)


\usepackage{tikz, xstring}


                    { }%
                  { }%

                \errmessage{Too many @'s in side cs coordinate}
                \errmessage{Not enough .'s in side cs coordinate}
                \errmessage{Too many .'s in side cs coordinate}
                \def\sidecs@anchorone{north west}
                \def\sidecs@anchortwo{north east}
                \def\sidecs@anchorone{south west}
                \def\sidecs@anchortwo{south east}
                \def\sidecs@anchorone{north west}
                \def\sidecs@anchortwo{south west}
                \def\sidecs@anchorone{north east}
                \def\sidecs@anchortwo{south east}
                \errmessage{Unknown side}

        \begin{scope}[x = 35mm, y = 3mm, every node/.style = draw]
            \node (x) at (0,  0) {XXXXXXXXXX};

            \node (a) at (1,  7) {AAAAAAAAAA};
            \node (b) at (1,  5) {BBBBBBBBBB};
            \node (c) at (1,  3) {CCCCCCCCCC};
            \node (d) at (1,  1) {DDDDDDDDDD};
            \node (e) at (1, -1) {EEEEEEEEEE};
            \node (f) at (1, -3) {FFFFFFFFFF};
            \node (g) at (1, -5) {GGGGGGGGGG};
            \node (h) at (1, -7) {HHHHHHHHHH};

                      tl/.style = {out = 90, in = 180},
                      bl/.style = {out = 270, in = 180}]
            \draw [tl] (side cs: x.top    @ 0.5) to (side cs: a.left @ 0.5);
            \draw [tl] (side cs: x.top    @ 0.6) to (side cs: b.left @ 0.5);
            \draw [tl] (side cs: x.top    @ 0.7) to (side cs: c.left @ 0.5);
            \draw [tl] (side cs: x.top    @ 0.8) to (side cs: d.left @ 0.5);
            \draw [bl] (side cs: x.bottom @ 0.8) to (side cs: e.left @ 0.5);
            \draw [bl] (side cs: x.bottom @ 0.7) to (side cs: f.left @ 0.5);
            \draw [bl] (side cs: x.bottom @ 0.6) to (side cs: g.left @ 0.5);
            \draw [bl] (side cs: x.bottom @ 0.5) to (side cs: h.left @ 0.5);
  • 3
    – egreg
    May 30, 2015 at 17:03

2 Answers 2


There are several ways to solve the problem.

  1. Since you're under \fullexpandarg you can simply do

    \StrCut{\sidecs@expandedarg}{\string @}{\sidecs@partbeforeat}{\sidecs@pos}
  2. If not under \fullexpandarg, you can use a string of \expandafter

    \@xp\StrCut\@xp{\@xp\sidecs@expandedarg\@xp}\@xp{\string @}{\sidecs@partbeforeat}{\sidecs@pos}

    (where I use \@xp for \expandafter, that's available if you load amsmath)

  3. Alternatively, the \lowercase trick:

    \begingroup\lccode`?=`@ \lowercase{\endgroup

    which exploits the fact that \lowercase doesn't change category code.

Similarly for the \StrCount line:

\StrCount{\sidecs@expandedarg}{\string @}[\sidecs@numberofats]


\@xp\StrCount\@xp{\@xp\sidecs@expandedarg\@xp}\@xp{\string @}[\sidecs@numberofats]


\begingroup\lccode`?=`@ \lowercase{\endgroup

Per comment by user egreg, one possible approach is to use \string on @ in two places in the code for "side cs". This turns it (at execution time) into an "@" with the catcode "other", which is what XString is looking for in this case.

Add the following line at or near the beginning of the code:


Replace the first \StrCount line with the following:

\ea\StrCount\ea{\ea\sidecs@expandedarg\ea}\ea{\string @}[\sidecs@numberofats]

Replace the first \StrCut line (in the conditional) with the following:

\ea\StrCut\ea{\ea\sidecs@expandedarg\ea}\ea{\string @}{\sidecs@partbeforeat}{\sidecs@pos}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.