Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In this examle from pgfmanual p 132, how to use \t the number of intersections point outside \fill command. I tried \def\Nb{\t} but it dosen't work.

\begin{tikzpicture}
\clip (-2,-2) rectangle (2,2);
\draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
\draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2);
\fill [name intersections={of=curve 1 and curve 2, name=i, total=\t}]
      [red, opacity=0.5, every node/.style={above left, black, opacity=1}]
      \foreach \s in {1,...,\t}{(i-\s) circle (2pt) node {\footnotesize\s}};
\end{tikzpicture}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

You may use \pgfextra{\xdef\Nb{\t}} or \pgfextra{\global\let\Nb\t}:

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
  \clip (-2,-2) rectangle (2,2);
  \draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
  \draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2);

  \path [name intersections={of=curve 1 and curve 2, name=i, total=\t}]
  \pgfextra{\xdef\Nb{\t}};

  \fill [red, opacity=0.5, every node/.style={above left, black, opacity=1}]
  \foreach \s in {1,...,\Nb}{(i-\s) circle (2pt) node {\footnotesize\s}};
\end{tikzpicture}
\end{document}
share|improve this answer
    
Possible also \pgfextra{\global\let\t\t} –  Alain Matthes Feb 28 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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