6

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:

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\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)] {};
\end{tikzpicture}
\end{document}
  • 8
    This is because commas separate keys, so circle through=(2,2) is split into circle through=(2 and 2) before TikZ starts figuring out what the key means. Thus the argument to circle through is just (2 and that doesn't make a lot of sense. Putting the coordinate in braces protects the comma from the key splitter, preserving it so that it is still there when TikZ starts looking for a coordinate. – Loop Space Jul 1 '13 at 14:40
  • 1
    What @AndrewStacey wrote is correct. This has nothing to do with through or circle through. You neither can re-write the library. This is the core of the underlying PGFkeys system (and it is the same way with every other key=value system). circle through={(2,2)} is the only correct way to use that option with that value. In various other situations you also need to enclose = , :, ) or ]. – Qrrbrbirlbel Jul 1 '13 at 14:59
  • For explanations, look at \pgfkeys, p. 484 of pgfmanual (v2.10) – Paul Gaborit Jul 1 '13 at 15:01
  • 2
    Extract from pgfmanual: "Especially putting the value in curly braces needs to be done quite often, namely whenever the value contains an equal-sign or a comma." – Paul Gaborit Jul 1 '13 at 15:01
  • 2
    @valid <coordinate> is in fact a placeholder for an expression such as (name) or (value1, value2) or (value1:value2) (polar coordinates) or a lot of other variants. But if the particular instance of the coordinate you use contains a comma, and it is used as a value for a key, then the whole coordinate has to be "protected" by curly braces, because of the way in which keys are parsed. The parser which interprets keys and assigns values is implemented in pgfkeys, hence the remark by PaulGaborit. – JLDiaz Jul 1 '13 at 15:44
7

(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.)

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.