I am definitely unfamiliar with both beamer
and tikz
(do not quite get what the \only
are supposed to do) but perhaps this could go in the direction you want:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
% helper macro:
\long\def\GobToSemiColon #1;{}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};
\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};
\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};
\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}
Percusse has answered accordingly to the question. (I think his answer should be marked as "accepted", by the way). I took the liberty to propose a MetaPost solution, however.
Until quite recently, this kind of function drawing would have been impossible to do with MetaPost, since it was based only on quite limited fixed-point numerics. But since its version 1.8 the user can switch to floating-point numerics at will, by setting the internal variable numbersystem
to double
. It's still a bit rough around the edges (the default units has not yet been adapted, for example) but it's quite functional, and I couldn't resist to use it for this problem. The following program makes use of LuaLaTeX and its luamplib
package as a very convenient interface to MetaPost. It calls the Metafun format of MetaPost, which defines the necessary auxiliary functions (cos, sin, exp…)
\documentclass[11pt]{standalone}
\usepackage{unicode-math}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\mplibnumbersystem{double}
\begin{document}
\begin{mplibcode}
input mpcolornames;
% pi, cm (and mm) as accurate as possible
%(defaults settings are too inaccurate: pi = 3.14159265, cm = 28.34645)
pi:= 3.141592653589793;
cm := 3600/127; mm := 360/127;
% Unit lengths
u = .5cm; v = mm;
% Graphs boundaries
xmin = -6pi; xmax = -xmin; xsep = (xmax - xmin)/1000; ymin = -80; ymax = 100;
% Axes settings
Xmin = -20; Xmax = -Xmin; Ymin = -85; Ymax = 110;
% Macro building the graph of a given function f
vardef graph_of_function (suffix f) (expr xmin, xmax, xsep) =
for x = xmin step xsep until xmax: (x, f(x)) .. endfor (xmax, f(xmax))
enddef ;
% Functions to be graphed
vardef e(expr x) = cos(pi/2 + 3x) + x*sin 3x enddef;
vardef f(expr x) = -.25(x**2)*cos x - x*sin x enddef;
vardef g(expr x) = x + cos x enddef;
vardef h(expr x) = .5(-cos x + 3sin x + 1e-11exp -3x) enddef;
vardef i(expr x) = 1e-15exp 3x enddef;
%
beginfig(0);
% Drawing of the given functions
pickup pencircle scaled 1.25bp;
draw (graph_of_function(e)(xmin, xmax, xsep)) xyscaled (u, v) withcolor yellow;
draw (graph_of_function(f)(xmin, xmax, xsep)) xyscaled (u, v) withcolor Orange;
draw (graph_of_function(g)(xmin, xmax, xsep)) xyscaled (u, v) withcolor green;
draw (graph_of_function(h)(xmin, xmax, xsep)) xyscaled (u, v) withcolor magenta;
draw (graph_of_function(i)(xmin, xmax, xsep)) xyscaled (u, v) withcolor blue;
% Clipping
clip currentpicture to
((xmin, ymin) -- (xmax, ymin) -- (xmax, ymax) -- (xmin, ymax) -- cycle)
xyscaled (u, v);
% Axes and labels
pickup pencircle scaled .5bp;
drawarrow (Xmin*u, 0) -- (Xmax*u, 0); drawarrow (0, Ymin*v) -- (0, Ymax*v);
label.llft("$O$", origin);
label.lft("$y$", (0, Ymax*v)); label.bot("$x$", (Xmax*u, 0));
% Marking…
labeloffset := 6bp;
% … on the horizontal axis
draw (u*pi, -3bp) -- (u*pi, 3bp); draw (-u*pi, -3bp) -- (-u*pi, 3bp);
label.bot("$\pi$", (pi*u, 0)); label.bot("$-\pi$", (-pi*u, 0));
for i = 2 upto 6:
draw (i*pi*u, -3bp)-- (i*pi*u, 3bp);
label.bot("$" & decimal i & "\pi$", (i*pi*u, 0));
draw (-i*pi*u, -3bp)-- (-i*pi*u, 3bp);
label.bot("$" & decimal -i & "\pi$", (-i*pi*u, 0));
endfor;
% … on the vertical axis
for i = 20 step 20 until 80:
label.lft("$" & decimal i & "$", (0, i*v));
label.lft("$" & decimal -i & "$", (0, -i*v));
draw (-3bp, i*v) -- (3bp, i*v);
draw (-3bp, -i*v) -- (3bp, -i*v);
endfor;
label.lft("$100$", (0, 100v)); draw (-3bp, 100v) -- (3bp, 100v);
% Preventing possible cropping of labels at the figure boundaries
setbounds currentpicture to boundingbox currentpicture enlarged .5cm;
endfig;
\end{mplibcode}
\end{document}
Best Answer
A minimal example still exhibiting the error is
My guess is that computing the arc causes some overflow; in fact, your picture has a size in the range of one or more square meters.
Since you scale your picture by a factor of 0.075 anyway, I suggest to use a scale factor of 0.75 and reduce the numbers by a factor of 10. The command
gives no error.
Here is your modified document and the corresponding output. Seems to work.