Annada Behera
2024-08-30 07:59:14 UTC
Consider this minimal working example. I have two functions, f(x) = x
and g(x) = x+sin(x). I want to draw them with PGF and at the intersection
points, I want put black dots. Here is the TikZ code,
\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 \@***@enc
\***@encoding \@***@text@en...
l.28 }
What is undefined? I am pretty sure the name=i in \fill command populates
the namespace with i-1, 1-2 and 1-3, because \fill has drawn them. I
have even tried to help the parser with extra braces, {i-\n} and {i\n}
but that also doesn't help. Anybody know the reason why I get the error
and how to fix them?
and g(x) = x+sin(x). I want to draw them with PGF and at the intersection
points, I want put black dots. Here is the TikZ code,
\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 \@***@enc
\***@encoding \@***@text@en...
l.28 }
What is undefined? I am pretty sure the name=i in \fill command populates
the namespace with i-1, 1-2 and 1-3, because \fill has drawn them. I
have even tried to help the parser with extra braces, {i-\n} and {i\n}
but that also doesn't help. Anybody know the reason why I get the error
and how to fix them?