Virtually any professional desktop publishing package could do that with the judicious use of formatting tags and templates. That's how most commercial magazines do get assembled. But in order to automate the formatting, you'd need to understand a bit about layout, typography, template creation -
and how your specific publishing software works - and keep that all in mind when creating your source text and graphic files - or it won't happen smoothly.
Publishing software can do amazing things. But it can't read your mind or make judgement calls. As with as any other program you're running, the adage about "Garbage In = Garbage Out" is especially true when it comes to this type of application. So you'll need to meet it half way,
and spoon feed it your source materials in the way it expects to see them, or it's all to no avail. And that usually means there's NO formatting or pretty anything done to the source text. All the stylistic elements and formatting needs to be handled by the publishing package, NOT the word processing or other text creation software.
Which I guess is a long way of saying that it's
doable - but there's nothing out there AFAIK that will handle it
completely automatically unless you did some preplanning and set up your original materials to be used in that fashion.
Luck!
Addendum: You might want to experiment with some free "book creation" software like
Sigil to see if that will work for your purposes. Many successful magazines publish using the EPUB format rather than paper. You can find out more about it
here.
If you're looking to
also publish to paper, you'd probably be better off going with something like Adobe InDesign.
If you have some time and want to see how the process works in InDesign using a professionally designed template, you can watch the whole thing in this video:
As you might notice, there's a lot of things and terminology you'll need to familiarize yourself with in order to work efficiently with this sort of software.