2

I needed some custom document format and stumbled on this issue. DocBook does it this way

<chapter>
    <title>Chapter 1</title>
    <para>Hello world!</para>
    <para>I hope that your day is proceeding <emphasis>splendidly</emphasis>!</para>
</chapter>
<chapter>
    <title>Chapter 2</title>
    <para>Hello again, world!</para>
</chapter>

And LaTeX and HTML like (with the same elements as DocBook):

<chapter>Chapter 1</chapter>
<para>Hello world!</para>
...
<chapter>Chapter 2</chapter>
<para>Hello again, world!</para>

Yes \chapter is not an LaTeX environment but I guess this is the most accurate mapping between LaTeX and XML.

When are these different document models to prefer in different cases? In the DocBook case, I can take one chapter out, and it becomes a well-formed document by itself, but there has to be some reason for LaTeX and HTML to not enclose chapters and sections like DocBook does.

4
  • This depends entirely on the requirements for your individual project - but I can tell you this: try to stick to one if possible.
    – Zibbobz
    Commented Jun 12, 2015 at 17:56
  • @Zibboz Yes, stick to one. Give some examples of how requirements maps to different solutions.
    – user877329
    Commented Jun 12, 2015 at 18:00
  • No, I'm telling you to stick to one - the fewer document template models you're going to have to work with, the easier it will be to implement in the future. Which one you use is a matter of your individual project requirements - and telling you which one is 'best' would make this a shopping rec question.
    – Zibbobz
    Commented Jun 12, 2015 at 18:06
  • So where can I find pros and cons?
    – user877329
    Commented Jun 13, 2015 at 7:13

1 Answer 1

2

I would suggest this difference is simply an anachronism from the age of HTML and LaTeX.

HTML, having evolved out of SGML (as did Docbook), actually got a lot of it's structural elements (i.e. <h1>, etc) from IBM's GML/GMLguide languages. In GML, as with LaTeX, the focus of the language designers was on the presentation of content, rather than the communication of the structural composition of that content.

IBM's GML was designed with requirements such as dox-matrix printers (which only had one dot-size). Hence, a Heading-1 needed to look different some other way from heading-2, etc. As such, the height of a line of text was dependant upon what content role it played (i.e. as a heading). To prevent presentation-corruption, programs printing GML documents to dot-matrix line printers needed to know if there were enough lines (of dots) available for a heading, etc.

Since HTML borrowed most of these things from GML, it kept the idea of a fairly flat, presentation-oriented document structure. Where the floating paragraph under a (sibling) header was inferred as it's child since it was presented later in the (structured) document.

With the advancements on the web and rising ubiquity of the Internet, by the time XML came into the fray (mid-to late 90's, standardised in early 2000's), the communication (rather than presentation) of the content was what mattered. As such, XML document designs are usually much deeper than those of SGML/HTML/GML.


Now, as for an answer to your (somewhat broad?) question... I would agree with @Zibbobz's comment - that it does indeed depend entirely upon the requirements for your individual project. As a rough guideline, situations where you are dealing with limited hardware (printers, etc), the shallower a structure the better. But also, in situations where whatever your document is representing is clearly a composition, then use the composing nature of XML and make things nested!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.