While it is clear to me why time from submission to acceptance can vary a lot (given that this involves that most fickle of creature: the reviewer), it is less clear what determines how long it takes for an accepted paper to be published.
Is this purely a matter of all accepted papers being put in a queue and then the journal selects from the top until they fill out each issue (possible going a bit further down to make the page counts fit)? Or is it common that papers are "pushed" forward in the queue based on various factors (and if so, which factors)?
If it makes a difference, I am mostly interested in math journals, but I am also curious about possible dependency on the field.