3

I am using TeXShop v 2.47 on a MAC (OSX 10.6.8) and trying to learn TikZ; which is very powerful but not the easiest package to get to master. I have been getting very strange behaviour with the \foreach command; in that it works sometimes and then does not, with what looks as identical code. I have tried to track the problem down and get the error in its simplest form; stripping the LaTeX document right down. I have used a simple example from p37 of pgfmanualCVS2012-11-04. Which works fine

\documentclass[11pt, oneside]{article}      
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}[]
    \tikz \foreach \x in {1,...,10} 
    \draw (\x,0) circle (0.4cm);
  \end{tikzpicture}
\end{document}

and produces 10 circles as expected. However if I try to edit this it very often fails. If for example I replace the 0 in the {1,...,10} by a 0 [by either highlighting the 0 and typing 0 or by deleting 0 and typing 0] the code fails and I get an error: .\error.tex:6 Package PGF Math Error: Unknown operator '...' or '...@' (in '...') see PGF Math Package documentation. Possibly the TeXShop editor is adding some control characters?

Edit added 12:59 GMT Here is the failing code. With the TeXShop editor they look identical. However I notice here that the ... spacing looks different? Possibly TexShop is doing something with the ...?

\documentclass[11pt, oneside]{article}      
\usepackage{tikz}
    \begin{document}
     \begin{tikzpicture}[]
     \tikz \foreach \x in {1,…,10}
     \draw (\x,0) circle (0.4cm);
  \end{tikzpicture}
\end{document}
  • Here ,..., is important. If you miss say , then it won't work. –  Sep 06 '14 at 11:50
  • And \tikz in \tikz \foreach \x in {1,...,10} is not needed and wrong, delete it. –  Sep 06 '14 at 11:56
  • @HarishKumar many thanks. I used the \tikz – Sean Danaher Sep 06 '14 at 12:24
  • @HarishKumar many thanks. I used \tikz as the example is a direct cut and paste from p37 of the manual. This seems to be optional but with respect if Till Tantau uses it then I am not sure thai it can be wrong - optional perhaps? – Sean Danaher Sep 06 '14 at 12:32
  • I think this would clarify a bit why it usually fails http://tex.stackexchange.com/a/132162/3235. And \tikz is a shorthand for the environment. If it has one command it understands it otherwise it stops in the first occurence of ;. So you don't need it if yo uare already inside a TikZ environment. – percusse Sep 06 '14 at 12:33
  • @percusse many thanks for your explanation of \tikz - this is very helpful. I as still stuck with the very erratic behaviour of ,..., with respect to minor edits (or what I think is no change at all!). If I simply enumerate as in {1,2,3,4,5,6,7,8,9,10} there is no problem. – Sean Danaher Sep 06 '14 at 12:54
  • Try to fail again and put the failing code. The error is often raised, when ... is not preceded or followed by a comma so it is taken as a literal instruction. See also how sensitive it is to being literally the same http://tex.stackexchange.com/a/114288/3235 – percusse Sep 06 '14 at 12:57

1 Answers1

2

Your ,…, are not three dots! It is a (one) unicode character for the ellipses. Replace it with ,..., and it will work.

 \tikz \foreach \x in {1,...,10}
  • You are absolutely correct! It seems when I do any edit with TeXShop it automatically converts 3 dots to an ellipses. I'm not sure how to turn this behaviour off. – Sean Danaher Sep 06 '14 at 13:40
  • maybe http://tug.org/pipermail/macostex-archives/attachments/20120308/e0bc4619/attachment-0001.pdf helps (section 3.3) –  Sep 06 '14 at 13:48
  • I have tracked the problem down to my Apple system Preferences and unticked the replace '...' by an ellipses. Within TeXShop in Edit menu, Substitutions, Text Preferences. – Sean Danaher Sep 06 '14 at 14:45