Measurements of the production cross sections of prompt ${\rm D^0}$, ${\rm D^+}$, ${\rm D^{\ast +}}$, ${\rm D_s^+}$, ${\rm \Lambda_{c}^{+}}$, and ${\rm \Xi_{c}^{+}}$ charm hadrons at midrapidity in proton$-$proton collisions at $\sqrt{s}=13$ TeV with the ALICE detector are presented. The D-meson cross sections as a function of transverse momentum ($p_{\rm T}$) are provided with improved precision and granularity. The ratios of $p_{\rm T}$-differential meson production cross sections based on this publication and on measurements at different rapidity and collision energy provide a constraint on gluon parton distribution functions at low values of Bjorken-$x$ ($10^{-5}-10^{-4}$). The measurements of ${\rm \Lambda_{c}^{+}}$ (${\rm \Xi_{c}^{+}}$) baryon production extend the measured $p_{\rm T}$ intervals down to $p_{\rm T}=0(3)$~GeV$/c$. These measurements are used to determine the charm-quark fragmentation fractions and the ${\rm c\overline{c}}$ production cross section at midrapidity ($|y|<0.5$) based on the sum of the cross sections of the weakly-decaying ground-state charm hadrons ${\rm D^0}$, ${\rm D^+}$, ${\rm D_s^+}$, ${\rm \Lambda_{c}^{+}}$, ${\rm \Xi_{c}^{0}}$ and, for the first time, ${\rm \Xi_{c}^{+}}$, and of the strongly-decaying J/$psi$ mesons. The first measurements of ${\rm \Xi_{c}^{+}}$ and ${\rm \Sigma_{c}^{0,++}}$ fragmentation fractions at midrapidity are also reported. A significantly larger fraction of charm quarks hadronising to baryons is found compared to e$^+$e$^-$ and ep collisions. The ${\rm c\overline{c}}$ production cross section at midrapidity is found to be at the upper bound of state-of-the-art perturbative QCD calculations.
The transverse momentum ($p_{\rm T}$) differential production cross section of the promptly produced charm-strange baryon $\Xi_{\rm c}^{0}$ (and its charge conjugate $\overline{\Xi_{\rm c}^{0}}$) is measured at midrapidity via its hadronic decay into ${\rm \pi^{+}}\Xi^{-}$ in p$-$Pb collisions at a centre-of-mass energy per nucleon$-$nucleon collision $\sqrt{s_{\mathrm{NN}}}~=~5.02$ TeV with the ALICE detector at the LHC. The $\Xi_{\rm c}^{0}$ nuclear modification factor ($R_{\rm pPb}$), calculated from the cross sections in pp and p$-$Pb collisions, is presented and compared with the $R_{\rm pPb}$ of $\Lambda_{\rm c}^{+}$ baryons. The ratios between the $p_{\rm T}$-differential production cross section of $\Xi_{\rm c}^{0}$ baryons and those of $\mathrm {D^0}$ mesons and $\Lambda_{\rm c}^{+}$ baryons are also reported and compared with results at forward and backward rapidity from the LHCb Collaboration. The measurements of the production cross section of prompt $\Xi^0_{\rm c}$ baryons are compared with a model based on perturbative QCD calculations of charm-quark production cross sections, which includes only cold nuclear matter effects in p$-$Pb collisions, and underestimates the measurement by a factor of about 50. This discrepancy is reduced when the data is compared with a model that includes string formation beyond leading-colour approximation or in which hadronisation is implemented via quark coalescence. The $p_{\rm T}$-integrated cross section of prompt $\Xi^0_{\rm c}$-baryon production at midrapidity extrapolated down to $p_{\rm T}$ = 0 is also reported. These measurements offer insights and constraints for theoretical calculations of the hadronisation process. Additionally, they provide inputs for the calculation of the charm production cross section in p$-$Pb collisions at midrapidity.