Adjunction for varieties with higher codimension For $X \subseteq \mathbb{P}^n$ a smooth hypersurface, the canonical divisor $K_X$ can be computed as
$$
K_X = (K_{\mathbb{P}^n} + X)|_X.
$$
Is there a similar formula where $X$ is of higher codimension?
If necessary we can assume $X$ to be a surface over the complex numbers, in particular it is a complex analytic manifold.
Thanks!
 A: The principle of adjunction is much more general than just a formula for the canonical class, it holds at the level of total Chern classes for any submanifold $X$ of a complex manifold $Z$ (the canonical class is just the negative of the first Chern class of $X$). More precisely, the more general form of adjunction at the level of Chern classes is $$c(X)=c(Z)/c(N),$$ where $N$ is the normal bundle to $X$ in $Z$ (this follows from the exact sequence of vector bundles in Georges' answer along with the fact that Chern classes are multiplicative with respect to exact sequences). In the special case $X\subset \mathbb{P}^n$ is a complete intersection (i.e., $X$ is the zero locus of the system $F_1=\cdots =F_k=0$ and $X$ has codimension $k$), adjunction easily yields a nice formula for the total Chern class of $X$, from which can you can extract (among other invariants) not only the canonical class of $X$ but it's topological Euler characteristic as well. In particular (if you know a little bit about Chern classes, or if not see chapter 3 of Fulton's "Intersection theory"), if we denote the class of a hyperplane in $\mathbb{P}^n$ by $H$ and the degree of the hypersurface $F_i=0$ by $d_i$, then $c(\mathbb{P}^n)=(1+H)^{n+1}$ and $c(N)=(1+d_1H)\cdots(1+d_kH)$, thus $$c(X)=\frac{(1+H)^{n+1}}{(1+d_1H)\cdots(1+d_kH)}\cdot d_1\cdots d_kH^k$$ (we multiply by $d_1\cdots d_kH^k$ as this is the class of $X$ in $\mathbb{P}^n$). The $i$th Chern class of $X$ is then just the term of degree $k+i$ in the power series expansion of $\frac{(1+H)^{n+1}}{(1+d_1H)\cdots(1+d_kH)}\cdot d_1\cdots d_kH^k$. In particular, $K_X=-(n+1-d_1-\cdots - d_k)H^{k+1}$ and the topological Euler characteristic is the degree of the $(n-k)$th Chern class of $X$, namely the coefficient of $H^n$ in the power series expansion of $c(X)$.
As I stated earlier, all of this can be found in much greater detail in chapter 3 of Fulton's book.
A: The adjunction formula is a very general, pleasant, result valid for any complex submanifold $X\subset Z$ of codimension $r$ of any complex manifold $Z$ (projectivity is irrelevant).
It computes the canonical bundle $K_X=\wedge ^{dim X}(TX)^*$ of the submanifold $X$ and reads  $$   K_X=K_Z|X\otimes \wedge^r N         $$ where $N=N_Z(X)$ is the normal bundle of $X$ in $Z$, defined by  $N=\frac{TZ|X}{TX}$.    
Ah, you will say, such a beautiful, extremely general theorem, must be quite difficult to prove, must it not?
Not at all! As is surprisingly often the case, the theorem boils down to (multi)linear algebra: any exact sequence of vector spaces $0\to F\to E\to Q\to$ gives rise to a canonical isomorphism between determinants $$det E=det F\otimes det Q$$ ( where $det E=\wedge ^{dim E}E$, etc.)
We can globalize this formula to vector bundles, apply it to the exact sequence $$0\to N^*\to T^*Z|X\to T^*X\to 0$$ (which is the dual of the sequence defining the normal bundle) and obtain $$ K_Z|X=\wedge^rN^*\otimes K_X         $$ Tensoring both sides with $\wedge^r N$, the dual line bundle to $\wedge^rN^*$,  then immediately gives the promised adjunction formula $K_X=K_Z|X\otimes \wedge^r N$.
Et voilà!
