  We study the single parton fragmentation functions (FFs) at the input
factorization scale $\mu_0\gtrsim 2m_Q$, with heavy quark mass $m_Q$, in the
soft gluon factorization (SGF) approach. We express the FFs in terms of
perturbatively calculable short distance hard parts for producing a heavy
quark-antiquark pair in all possible states, convoluted with corresponding soft
gluon distribution for the hadronization of the pair to a heavy quarkonium. We
compute the perturbative short distance hard parts for producing a heavy quark
pair in all possible $S$-wave and $P$-wave states up to $O(\alpha_s^2)$. With
our results, the SGF can be further used to study the heavy quarkonium
production at the hadron colliders and heavy quarkonium production within a
jet.
