| Deutsch English Français Italiano |
|
<vb328v$20a9j$1@solani.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: Ulrich D i e z <ud.usenetcorrespondence@web.de>
Newsgroups: comp.text.tex
Subject: Re: [LaTeX][PGF/TikZ] Undefined control sequence error for PGF
intersections.
Date: Mon, 2 Sep 2024 02:52:46 +0200
Message-ID: <vb328v$20a9j$1@solani.org>
References: <10c8b515e70ecda9ad95fc1529ff3b102da812e4.camel@tilde.green>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 2 Sep 2024 00:52:48 -0000 (UTC)
Injection-Info: solani.org;
logging-data="2107699"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.9.0
Cancel-Lock: sha1:Yhq9xNrdjqsVmfhJQ2hwohVLE78=
Content-Language: en-US
X-User-ID: eJwFwQkBACAIBLBK8h0QR0D6R3AzAaFdYVBb28g4Uv2YQw6PpgSvI7as8DDbE0WXm1xu7vsP7BFB
In-Reply-To: <10c8b515e70ecda9ad95fc1529ff3b102da812e4.camel@tilde.green>
Bytes: 7086
Lines: 172
Annada Behera wrote:
> \documentclass{standalone}
> \usepackage{tikz, amsmath}
> \usetikzlibrary{intersections}
> \begin{document}\begin{tikzpicture}
>
> % Plots
> \draw[very thick, smooth, samples=20, domain=-6.28:6.28]
> [red, name path=line] (0,0) plot (\x, \x);
> \draw[very thick, smooth, samples=20, domain=-6.28:6.28]
> [blue, name path=sine] (0,0) plot (\x, {\x + sin(\x r)});
>
> % Drawing the dots
> \fill[name intersections={of=line and sine, name=i, total=\t}, black]
> \foreach \s in {1,...,\t} {(i-\s) circle (2pt)};
>
> \end{tikzpicture}\end{document}
>
> Now this code works as expected. But I also wanted to draw dashed lines from
> the intersections to each axes.
>
> % Axes
> \draw [<->](-6.28, 0) -- (6.28, 0);
> \draw [<->](0, -6.28) -- (0, 6.28);
>
> % Mark intersection points and draw dashed lines
> \foreach \n in {1,...,\t} {
> \path ({i-\n}) coordinate (i\n); % <--- Error Here
> \fill[black] (i\n) circle (2pt);
> \draw[dashed] (i\n) -- (i\n |- 0,0);
> \draw[dashed] (i\n) -- (0,0 -| i\n);
> }
>
> In this part, pdflatex (my distro is TeX Live 2024) throws an error what
> I don't understand,
>
> ! Undefined control sequence.
> \UseTextAccent ...p \@firstofone \let \@curr@enc
> \cf@encoding \@use@text@en...
> l.28 }
>
> What is undefined?
When you say
\errorcontextlines=10000
\documentclass{...
, the error-message is:
! Undefined control sequence.
\UseTextAccent ...p \@firstofone \let \@curr@enc
\cf@encoding
\@use@text@en...
\?-cmd ...sname \csname ?\string #1\endcsname \fi
\csname \cf@encoding
\stri...
\pgffor@dots@charcheck ...@dots@charcheck@temp {#1
}\expandafter
\expandafter...
\pgffor@dots@value@process ...value \pgffor@@stop
\ifpgffor@alphabeticsequen...
\pgffor@dotsscanend ...@process {\pgffor@dotsend }
\pgffor@dots@value@process...
\pgffor@values ->1,...,\t ,
\pgffor@stop ,
l.27 }
and you see that \t in "\foreach \n in {1,...,\t} {...}" is undefined,
The problem is that the macro \t comes into being while a TikZ-path is
evaluated - \fill is a macro which expands to "\path..." - while TikZ
does not do control-sequence-evaluation/macro-expansion as usual while
parsing/evaluating/carrying out a TikZ-path-directive.
So you face the nice problem that \t being defined is restricted to the
scope of that TikZ-path-directive while inside TikZ-path-directives you
cannot easily use macros/control-sequences as directives for saving \t
away as a global macro which is available outside the scope of the
\fill-path-directive also.
As \t denotes a natural number, you can work around this problem by as a
component of the TikkZ-path-directive specifying a TikZ-coordinate where
one component (either the X-component or the Y-component) comes from \t,
using the measurement-unit sp (scaled point) and later retrieving that
component of the TikZ-coordinate and using it with \number, hereby
taking into account that using a TeX-\dimen or a TeX-\skip or a
LaTeX-length with \number directly yields the numerical value which
belongs to the quantity in question when it is expressed as a multiple
of the measurement-unit sp (scaled point):
%\errorcontextlines=10000
\documentclass{standalone}
\usepackage{tikz, amsmath}
\usetikzlibrary{intersections}
\newlength\scratchlength
\begin{document}
\begin{tikzpicture}
% Plots
\draw[very thick, smooth, samples=20, domain=-6.28:6.28]
[red, name path=line] (0,0) plot (\x, \x);
\draw[very thick, smooth, samples=20, domain=-6.28:6.28]
[blue, name path=sine] (0,0) plot (\x, {\x + sin(\x r)});
% Draw the dots and use \t for saving a coordinate so that
% \t can later be retrieved outside the scope of the \fill-path
% as well:
\fill [name intersections={of=line and sine, name=i, total=\t},
black]
\foreach \s in {1,...,\t} {(i-\s) circle (2pt)}
% Before ending with a semicolon (;) the path-specifica-
% tion started via \fill, let's save total/\t as the
% y-value of a TikZ-coordinate whose name is "total";
% specify the unit sp (scaled point) as all lengths in
% TeX internally are calculated/rounded to be integer
% multiples of 1sp; thus when specifying sp you don't get
% rounding-errors when later retrieving the value:
coordinate (total) at (0pt, \t sp);
% Extraxt to \scratchlength the y-coordinate of the pgfpoint
% which forms the center-anchor of the coordinate-node whose
% name is "total" :
\pgfextracty{\scratchlength}{\pgfpointanchor{total}{center}}%
% When you use a TeX-\dimen or TeX-\skip/LaTeX-length with
% \number directly, you get the numerical value which belongs
% to the (unstretched and unshrinked) quantity in question
% when it is expressed as a multiple of the measurement-unit
% sp(scaled point).
% So we are lucky as in the begin dimensions for coordinates
% were provided with measurement unit sp:
\edef\t{\number\scratchlength}%
% Now we have \t defined outside the scope of the \fill-path
% and can use it in next \foreach-loop.
%\show\t
% Axes
\draw [<->](-6.28, 0) -- (6.28, 0);
\draw [<->](0, -6.28) -- (0, 6.28);
% Mark intersection points and draw dashed lines
\foreach \n in {1,...,\t} {
\path ({i-\n}) coordinate (i\n); % <--- Error Here
\fill[black] (i\n) circle (2pt);
\draw[dashed] (i\n) -- (i\n |- 0,0);
\draw[dashed] (i\n) -- (0,0 -| i\n);
}
\end{tikzpicture}
\end{document}
Sincerely
Ulrich