[Tex/LaTex] What does “circle through” do with its argument


The tikz library through can be used to draw a circle from a center coordinate A through another coordinate B like so:

\node [draw] at (A) [circle through=(B)] {};

When attempting to specify the coordinate to go through directly, i.e. without a named through coordinate

\node [draw] at (A) [circle through=(2,2)] {};

and compiling my document with pdflatex not only does that not work it also doesn't return and so gives no error message.

What does circle through do with its argument and is there a way to prevent endless compiling and come to some error message without rewriting a tikz library?

The way that works is to specify the coordinate in curly brackets

\node [draw] at (A) [circle through={(2,2)}] {};

I'm guessing through wasn't able to correctly retrieve its argument the other way.

Note that the pgfmanual 2.10
doesn't speak to that issue. The call is described as /tikz/circle through=<coordinate> (p. 474) and whenever it is used in examples named nodes are used.

I'm using TeXstudio 2.3 which runs

pdflatex -synctex=1 -interaction=nonstopmode "test-tikzcirclethrough".tex

Here is a test document:

\coordinate (A) at (1,2);
\coordinate (B) at (2,2);
% Works
\node [draw] at (A) [circle through={(B)}] {};
\node [draw] at (A) [circle through=(B)] {};
\node [draw] at (A) [circle through={(2,2)}] {};
% Doesn't work
\node [draw] at (A) [circle through=(2,2)] {};

Best Answer

(Summarising the comments)

The problem here is that the string circle through=(2,2) is processed through the pgfkeys mechanism. This uses commas to separate items and this splitting is done first of all before the individual keys are processed. (In this respect, it differs a little from what might be deemed usual TeX behaviour which is "greedy" and would start processing from the left only splitting off the next key when it is done with the current one.)

So circle through=(2,2) gets split into circle through=(2 and 2), neither of which is going to work. The first is a valid key but its argument doesn't match what it is expecting, and the second is not even a valid key.

To get round this, we need to protect the comma in (2,2) so that it doesn't get mistaken for a separator. The method of doing so in pgfkeys is to ensure that it is inside a TeX group. That is to say, it is in braces. So circle through={(2,2)} is the right way to do this.

(Incidentally, this is a problem encountered by any system that has special characters. When one wants to use a literal character, one has to ensure that it is not interpreted as a special character. We see this in TeX, just search on this site, but also with escape characters in other programming languages and - relevant for this situation - in the CSV spreadsheet format.)