  A metrized complex of algebraic curves is a finite metric graph together with
a collection of marked complete nonsingular algebraic curves, one for each
vertex, the marked points being in bijection with incident edges. We establish
a Riemann-Roch theorem for metrized complexes of curves which generalizes both
the classical Riemann-Roch theorem and its graph-theoretic and tropical
analogues due to Baker-Norine, Gathmann-Kerber, and Mikhalkin-Zharkov. We also
establish generalizations of the second author's specialization lemma and its
weighted graph analogue due to Caporaso and the first author, showing that the
rank of a divisor cannot go down under specialization from curves to metrized
complexes. As an application of these considerations, we formulate a
generalization of the Eisenbud-Harris theory of limit linear series to
semistable curves which are not necessarily of compact type.
