[Tex/LaTex] How is line spacing usually calculated

fontsline-spacing

Hello there! I don't know as much about fonts as I could, and I was wondering if some of the people at Tex, who know so much about Typography, could give me a hand.

Basically, I have some questions on how to calculate the line spacing between lines in a Docx file, and I think my problem may be from parsing fonts. First let me explain the whole dilemma.

My requirement is to exactly match Word, not necessarily the OOXML spec, in the spacing between lines in a simple paragraph.

In order to try to do this, I have built a tool to analyze the differences between my layout and Word's layout. To do so it does the following:

  1. First it generates a (or many) docx files.
  2. Next it creates PDFs from the docx files. It uses Word to render the docx to PDF, and my program to render the docx to PDF. "word.pdf", and "me.pdf"
  3. Then it analyzes the resulting PDFs for differences in layout.

So, my tool would say:

  1. Create a document "template.docx" with 1000 "a" characters in a single run of text with the same properties.
  2. Make a "word.pdf" and "me.pdf" from this docx
  3. Calculate info from the PDFs, in particular, calculating the line spacing in terms of the calculated leading between a line's ascent and the previous line's descent (our "Ascent + Descent" are almost identical, so all that differs is the whitespace between lines). I often think of it as the line's whitespace…

This tool showed me that the leading varies greatly from font to font.

To depict this, I used the tool to make thousands of these comparisons, in particular generating for:

  1. For each font in system
  2. For "a", "y", and a mix of letters and spaces.
  3. For different font sizes.
  4. For different line spacing types (Single, One and a half, and Double)

I was hoping to find groupings, such as "this type of font has 1.3 times my calculation of leading".

I was able to conclude far less than I had hoped, and was wondering if you could help me further with the issue of calculating line spacing. I'm providing you with a file that is best downloaded and opened in Excel while using the filters in the header row. Note that its not totally complete, there are missing entries, but I doubt they will be a problem for anyone, and I'm going to regenerate it soon but its pretty slow, so I'm finishing up some changes to it first.

Here is a comparison of the layout of our software, vs the layout of Word's for every font installed on my system, etc.

I'm not positive, but I believe the issue could be one of the following:

  1. Word is using a different process than we are to calculate the "leading" of a font. We don't parse the font files ourselves, instead rely on libraries to get font sizing information, and perhaps in the "world of font files" I am missing something, and word is parsing the fonts directly and differently.
  2. Word has some sort of lookup table that handles groups of fonts, or an algorithm, that scales a font's leading up or down based on some criteria I am unaware of.
  3. Word is using an additional criteria besides leading, ascent, and descent, to determine line spacing.

What do you think? Do you think this could be an issue in parsing font files or something related to fonts? Am I missing a key piece of understanding? Thanks so much!

Please feel free to email me: nathanb at windward dot net

Thank you so much for your time!

Best Answer

Almost always in tex the baseline spacing is set by the document class independent of the font.

So for example in the default article class, \normalsize is 10pt font on a 12pt baseline, as a result of the marked line of code (from size10.clo)

\renewcommand\normalsize{%
   \@setfontsize\normalsize\@xpt\@xiipt%   <<<< here 10pt on 12pt baseline
   \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
   \abovedisplayshortskip \z@ \@plus3\p@
   \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
   \belowdisplayskip \abovedisplayskip
   \let\@listi\@listI}

This setting is not normally changed, even if you change the default font from computer modern to some other font family.