Why is $\tan x$ not a continuous function? My textbook defines a continuous function as follows:
The function $f(x)$ is continuous if, for all $a$ in its domain, $\lim_{x\rightarrow a} f(x)$ exists and is equal to $f(a)$.
However, when I apply this to $f(x)=\tan x$, it seems to show that $\tan x$ is continuous, because:
For all $a$ in the domain of $\tan x$ (i.e. all real numbers except $\frac{(2k+1)\pi}{2}, n\in \mathbb{Z}$), we have that $\lim_{x\rightarrow a} \tan x$ exists and is equal to $\tan a$ (this can be easily seen from the graph of $\tan x$).
So it appears that $\tan x$ is continuous. However, I already know that it isn't continuous at $x=\frac{(2k+1)\pi}{2}$. Does this still mean it is continuous because it agrees with the definition? I'm not sure what to do now.
Edit: Really what I meant to ask is the following:
Here is the wording in the book: "A function $f(x)$ is continuous at $x=a$, if $f(a)$ is defined and $\lim_{x\rightarrow a} f(x)$ is defined and is equal to $f(a)$. A continuous function satisfies this condition for all values of $a$ in its domain, so the graph of a continuous function is unbroken." 
Question: I'm assuming the book's definition is wrong? Because the last sentence seems to imply that $\tan x$ is continuous (which is what had me confused).
 A: The following is a copy-paste of @Brian M. Scott's comment:

The tangent function is continuous on its domain; it isn’t a continuous function on $\Bbb R$ simply because it isn’t defined on all of $\Bbb R$ (and moreover, the discontinuities aren’t even removable)

A: In complex analysis, tangent function can be expressed as an infinite sum of partial fractions about the poles:
$$\tan z=
\sum_{k=0}^{\infty} \frac{2z}{\left( k+\frac{1}{2} \right)^2 \pi^2-z^2}$$
which is continuous for any region without the poles.
A: If you dont mind a short answer. $ \tan.. = \sin../\cos.. $. Sin is continuous but $\cos$ is in the denominator, creating infinities periodically as quotients.
A: The domain of tangent function is the set
$$ \operatorname{im}^{-1} \tan = \bigcup_{j=-\infty}^\infty \left]\pi j - \frac\pi 2,\pi j + \frac\pi 2\right[
$$
Evidently $\tan$ is continuous on this set.
Discussing about the continuity of $\tan$ at the points $\pi/2 + \pi j$ is absurd, since $\tan$ is not defined on these points. (It is not defined as $\infty$ either!)
$\tan$ can be continuously extended to $\mathbb{R}$ by enlarging its image to the one-point compactification $\mathbb{R}^*$ of $\mathbb{R}$, and define
$$ \tan \left( \pi j + \frac{\pi}{2} \right) = \infty, \qquad j \in \mathbb{Z}
$$
Then $\tan:\mathbb{R} \to \mathbb{R}^*$ is continuous.
