Assume $f \in \mathbb{C}[x,y]$ a polynomial such that the affine algebraic curve $X=V(f)$ has no singular points. Then there is a natural structure of non-compact Riemann surface on $X$, which can be made into compact Riemann surface by adding several (finitely many) points.
Question:
Is this compactification the same thing as taking projective closure of the curve $X$? If so, how does one generally define the holomorphic maps in the neighborhoods of the "points at infinity"?
Up until now I have thought so. However, I came across the following example (I will further assume that the projective closure is indeed the compactification):
Consider a polynomial
$$f(x,y)=x^ 2-g(y), $$
where $g(y)$ is a complex polynomial of an even degree $k, \; k>2$ and, for simplicity's sake, leading coefficient $1$. Assume further that $g$ has $k$ distinct roots. Say I want to compute the genus of the compactification of $V(f)$.
Then the projective closure of $V(f)$ is $V_{proj}(f^{*}),$ where
$$f^{*}(x,y,z)=x^2z^{k-2}-y^k-(\text{other monomials of }g\text{ multiplied by some nonzero power of }z)$$
Now I want to compute the points at infinity, this leads to the equation $y^k=0,$ hence $y=0$ and thus, there is only one such point: $(1:0:0)$.
However, consider the holomorphic map $\pi: V_{proj}(f^*) \rightarrow \mathbb{S}$ defined by $\pi(x:y:1)=y, \pi(1:0:0)=\infty$. Then it is easy to compute that the degree of $\pi$ is $2$ and that $b(\pi)=k+1$ (where $b(\pi):= \sum_{P \in V_{proj}(f^*)}(e_P-1)$ and $e_P$ denotes the ramification index at the point $P$). So by Riemann-Hurwitz formula I get
$$g(V_{proj}(f^*))=1+(g(\mathbb{S})-1)\deg \pi +\frac{1}{2}b(\pi)=\frac{k+1}{2}-1,$$
which is not an integer. (Note that if tha considered curve had two points at infinity, the number $b(\pi)$ would be even and everything would work fine).
So additional question is:
If the compactification can really be obtained via the projective closure, where is the mistake in the previous example?
Thanks in advance for any help.
The compactification (= completion) $\bar X$ of a smooth affine irreducible algebraic curve $X\subset \mathbb A^2(\mathbb C)$ is the closure of $X$ in $\mathbb P^2(\mathbb C)$ .
Strangely but pleasantly the closure is the same in the Zariski or the transcendental topology of $\mathbb P^2(\mathbb C)$.
That closure is however in general non-smooth (more about that below) and is thus not the Riemann surface associated to $X$.
However there is a canonical way to obtain that Riemann surface:
Take the normalization $\nu:Y \to \bar X$ of $\bar X$. You obtain a normal irreducible complete algebraic curve $Y$ and the good news is that in dimension one normality is equivalent to smoothness.
So the required Riemann surface compactifying $X$ is just the complex manifold associated to the algebraic curve $Y$ .
A complement
That the compactification $\bar X$ is not smooth in general is easy to check on simple examples, as in Pavel's question.
But there is a more theoretical reason:
A smooth projective curve of degree $d$ in $\mathbb P^2$ has genus $g=\frac{(d-1)(d-2)}{2}$.
The integers of the form $\frac{(d-1)(d-2)}{2}$ are quite scarce in $\mathbb N$ whereas any integer is the genus $g$ of some complete smooth curve (for example, one lying on $\mathbb P^1(\mathbb C)\times \mathbb P^1(\mathbb C)$).
So most compact Riemann surfaces cannot be embedded in $\mathbb P^2 (\mathbb C)$ at all: this is one reason why the compactifcation in $\mathbb P^2$ of an affine plane smooth curve cannot in general be its associated compact Riemann surface.