8

What exactly does "separate content from formatting (style)" mean?

And if it's "necessary", how do I do it practically?

After reading many LaTeX documents and TeX Stack Exchange, I keep seeing reference to separating the content from the formatting, but this makes no sense to me.

If, for example, I have pictures, tables, or diagrams, I can't just disregard their positioning, size, or even coloring. To me, content is linked to formatting. Formatting isn't just aesthetic. It is often an integral part of presenting information (think Tufte Book, for example).

The only way I see this being feasible is if the writer and the typesetter are different. But if I am both, then I see no way to "just type" my content and worry about formatting later.

6
  • 6
    Compare In Figure 3, to In Figure~\ref{fg:myimg}. The former (bad) has you accounting for the formatting when you enter the content (it has you counting prior figures in the document), whereas the latter (good) avoids specifying the formatting. A late-edit figure addition will screw up the former, but not the latter approach. – Steven B. Segletes Jun 2 '15 at 13:37
  • 5
    In LaTeX you can focus on the logical structure of the document, not on the formatting instructions. For the title of a section I hope you write \section{...} and not \vspace*{2\baselineskip} \bfseries\fontsize{14}{17}\selectfont \refstepcounter{section} ... \vspace*{\baselineskip}. – Guido Jun 2 '15 at 13:43
  • 6
    It means try to avoid to write \textbf{some fact} but use instead \newcommand\important[1]{\textbf{#1}} and \important{some fact}. By separating the visual from the meaning it is easier to adjust the visual later, e.g. to make everything important in red instead of bold. – Ulrike Fischer Jun 2 '15 at 13:48
  • 3
    So, it seems that I have in fact been separating content form formatting. I just didn't realize this is how you did it. The documentation I've read seems to suggest that you completely disregard formatting. Perhaps a better way of saying it is "let LaTeX worry about the formatting by telling it what you want (not how you want to do it)". For example, when I tell it I want footnotes, I thought I was being concerned with formatting, but since I'm not manually placing them or counting the numbers, I'm not... correct? – Kevin P. Kilburn Jun 2 '15 at 14:10
  • 1
    Yes, because you can redefine the \footnote macro to produce endnotes, or margin notes, or nothing. The ideal for many of us is that between \begin{document} and \end{document}, there would only be plain text marked up with hopefully minimal semantic commands. The places where this gets harder is tables, figures, and math. I don't write about math, but for the others I almost always put these in separate files and \input them into the main document. – musarithmia Jun 2 '15 at 14:49
10

Seperating the content from its form, or better its visual representation means that you declare the functions of a certain formatting element logically (i.e. logical markup is the basic principle involved here -- that not only (La)TeX employs!).

There is no compelling reason for doing so, but it is very convenient, as I try to point out later. First, consider that TeX was written by a mathematician and that logical markup somehow reflects the basic principle of mathematical definitions that you don't specify what the defined object is, rather than what it does. In analogy logical markup does not inform you about how a typographical element looks like, but instead which role it plays in the document.

A few examples:

  • You mark up logically by writing \section{Some Title} instead of {\centering\Large\bfseries Some Title}, or
  • \begin{proof} <proof body> \end{proof} instead of {\itshape Proof.} <proof body> \unskip\hspace*{1em plus 1 fill}\nolinebreak[3]\hfill\mbox{\blacksquare}, or
  • \tableofcontents instead of ... well ...

(And the first counterexample still lacks in vertical spacing and ensuring that the section heading does not remain alone in the last line of a page.)

The obvious advantage is directly concluded from the notion how the examples and their counterexamples differ in length. You save time! Consider furthermore a scenario in which you need to change the formatting of every section heading. If you would have used hard-coding -- the "opposite" of marking up logically -- in this scenario you would be cycling through your whole document and change every instance by hand. But, if you had seperated the section titles from its formatting, you would just go to the original definition of \section and just change it to your needs. This procedure is less error-prone (obious why!?), you are less likely to get frustrated and again you save time. And the famous argument for it "that you can focus on the content alone" holds to a certain degree because you are using simple utf8-chars of 1 byte lenght (basically ASCII), and thus are forced to focus on what you say -- the pure content and its logical development, which is not too bad sometimes.

Now, you are right that content and its visual representation are correlated. That's why I would limit the impact of the last mentioned argument. However, let's be honest. Do you really have in mind the final formatting when you start composing your paper, book or whatever? And additionally you need to keep in mind that in TeX you are able to change the layout while or even before writing your content. By seperating the layers you gain the freedom to delay certain descisions. That does not prevent you from taking those before the content is finalised.

What are the downsides then? A light one clearly is that a small set of actions is performed way slower if you don't hard-code or don't manually draw them. (Think about tables; some of them can be a nightmare.) The main drawback is, in my opinion, that the original definitions of the markup instructions are not easily accessable in general. Most of them are quite easy to reach and manipulate (which also depends on how deep you want to dip into the TeX universe), but some are undoubtedly not. So, you must be willing to spend time studying documentations, asking friends or puting questions on TeX.SX.

In conclusion you can say that you save time and avoid annoyance when seperating content and form because you don't have to deal with torturous mechanical work. Moreover it will incentivise a certain behaviour that can be regarded as beneficial for writing content. On the other hand you will most likely lose some of the scooped time by tweaking your document to your needs. In the end it's up to you to decide how exactly you want to spend your time.

2
  • 1
    Nice answer. There is a very interesting point I like to show students when they ask me about LaTeX vs Word. I like to ask them, who work with Word, how they do a Title and format it. They normally do it manually over each title (sometimes using Format Painter). I ask them abut Styles, and only a few know what it is or even how to use it. Although Word has some tools to separate formatting and content, Word is not a software that endorse this attitude. LaTeX on the other hand slaps you in your face since the very beginning with its \documentclasses and \begin{document}s and so on. – FHZ Apr 14 '20 at 21:42
  • 1
    @FHZ -- The (La)TeX learning curve is quite steep indeed. On the other hand, I used to be a hardcore MS Word basher. I liked the way you put it, i.e. Word does not motivate you to adopt a more abstract way to think about your document. Although, in the mean time I saw very good examples of nicely structured .docs with logical markup and all the good stuff. Maybe there should be more serious Word advocats and communicators - which is prety strange to write on tex.sx beeing a TeX fanboy :) – Ruben Apr 15 '20 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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