The production of $J/\psi$ mesons in proton-proton collisions at a centre-of-mass energy of $\sqrt{s}=13$ TeV is studied with the \lhcb detector. Cross-section measurements are performed as a function of the transverse momentum $p_\mathrm{T}$ and the rapidity $y$ of the $J/\psi$ meson in the region $p_\mathrm{T}<14\mathrm{GeV}/c$ and $2.0<y<4.5$, for both prompt $J/\psi$ mesons and $J/\psi$ mesons from $b$-hadron decays. The production cross-sections integrated over the kinematic coverage are $15.03\pm 0.03\pm 0.94$ $\mu$b for prompt $J/\psi$ and $2.25\pm 0.01\pm 0.14$ $\mu$b for $J/\psi$ from $b$-hadron decays, assuming zero polarization of the $J/\psi$ meson. The first uncertainties are statistical and the second systematic. The cross-section reported for $J/\psi$ mesons from $b$-hadron decays is used to extrapolate to a total $b\bar{b}$ cross-section. The ratios of the cross-sections with respect to $\sqrt{s}=8$ TeV are also determined.
Measurements of the differential production cross-sections of prompt and non-prompt $J/\psi$ and $\psi(2$S$)$ mesons with transverse momenta between 8 and 360 GeV and rapidity in the range $|y|<2$ are reported. Furthermore, measurements of the non-prompt fractions of $J/\psi$ and $\psi(2$S$)$, and the prompt and non-prompt $\psi(2$S$)$-to-$J/\psi$ production ratios, are presented. The analysis is performed using 140 fb$^{-1}$ of $\sqrt{s}=13$ TeV $pp$ collision data recorded by the ATLAS detector at the LHC during the years 2015-2018.