# Document Layout Styles

I am inviting partial solutions for defining styles for document layouts. The solutions should be capable of defining the font size, leading (interline distance), and type for the running text as well as the style for sectional unit titles. Please see below for a definition of partial solution.

Particular care should be taken that the styles for the sectional unit titles integrate nicely with the style of the running text, so the running text should flow neatly around the titles, making sure the distance between any two lines of running text on any page is always a multiple of the user-defined leading.

There are some partial solutions to this question. For example, the grid package is a good starting point.

I don't have a particular application for any solution (answer) to my question: I posted the question, hoping that others may find the answers interesting. This is why I do not provide an MWE.

To make up for the lack of an MWE, I promise I'll award a 500-reputation bounty in one week for the best current solution, provided it shows some promise. I'll award another 500-reputation bounty in two weeks. (In the unlikely event that I'll have 500 reputation left after two weeks, I'll ward one more 500-reputation bounty in three weeks:-).

**Edit 3 September, 2015. The total 1000 reputation has been awarded. I can't respond to any further comments about this question. Also I won't be able to comment on any further solutions.

Partial Solution A partial solution may assume documents don't have displayed mathematical equations and other user-defined displays because displays may upset the inter-line distance. Furthermore, a partial solution may assume that all floats (figures, tables, etc.) are positioned at the top or bottom of the page.

• I'm expectating about this subject. It will be useful to me, but I don't hace the knowledge to propose solution. It's a too good idea! – karloswitt Aug 24 '15 at 9:41
• Hopefully, grid typesetting will progress thanks to your question. LaTeX only, or is XeLaTeX acceptable as well (say, using free fonts)? If time allows I will try to write a solution. – ienissei Aug 25 '15 at 12:15
• by user-defined displays you mean equations, minipages, tabular...? – touhami Aug 27 '15 at 15:09
• @MarcvanDongen No such thing as a simple solution! – Will Robertson Aug 27 '15 at 23:18
• Would this be a possible candidate for what you're looking for? tex.stackexchange.com/a/35093/3954 – Gonzalo Medina Aug 28 '15 at 13:36

## 1 Answer

Here a partial solution

Update: New solution this is (a new package baseline.sty)

\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{baseline}%

\edef\mtf@size{\f@size}
\edef\mtf@baselineskip{\f@baselineskip}
\renewcommand\normalsize{%
\@setfontsize\normalsize\mtf@size\mtf@baselineskip
\abovedisplayskip \mtf@baselineskip
\abovedisplayshortskip \abovedisplayskip
\belowdisplayshortskip \abovedisplayskip
\belowdisplayskip \abovedisplayskip
\let\@listi\@listI}
\normalsize%
%%%
\newcounter{nbs}
\newlength\mttempa
\let\mtset@fontsize\set@fontsize
\def\set@fontsize#1#2#3{%
\ifdim #2 pt<\mtf@baselineskip
\mtset@fontsize{#1}{#2}{\mtf@baselineskip}%
\else
\PackageWarning{baseline}{may be the font is used with modified baseline}%
\setcounter{nbs}{0}%
\setlength{\mttempa}{#2 pt}%
\loop
\stepcounter{nbs}%
\addtolength\mttempa{-\mtf@baselineskip}%
\ifdim\mttempa>0pt
\repeat%
\setlength{\mttempa}{\mtf@baselineskip}%
\loop
\addtocounter{nbs}{-1}%
\ifnum\value{nbs}>0
\addtolength\mttempa{\mtf@baselineskip}%
\repeat%
\mtset@fontsize{#1}{#2}{\mttempa}%
\fi}
%%%
\setlength\smallskipamount{\z@}
\setlength\medskipamount{\mtf@baselineskip}
\setlength\bigskipamount{\mtf@baselineskip}
\setlength\footnotesep{\z@}
\setlength{\skip\footins}{\mtf@baselineskip}
\setlength\floatsep    {\mtf@baselineskip}
\setlength\textfloatsep{\mtf@baselineskip}
\setlength\intextsep   {\mtf@baselineskip}
\setlength\dblfloatsep    {\mtf@baselineskip}
\setlength\dbltextfloatsep{\mtf@baselineskip}
\setlength\@fptop{\z@}
\setlength\@fpsep{\mtf@baselineskip}
\setlength\@fpbot{\z@}
\setlength\@dblfptop{\z@}
\setlength\@dblfpsep{\mtf@baselineskip}
\setlength\@dblfpbot{\z@}
\setlength\partopsep{\z@}
\def\@listi{\leftmargin\leftmargini
\parsep \z@  \topsep \z@ \itemsep\z@}
\let\@listI\@listi
\@listi
\def\@listii {\leftmargin\leftmarginii
\labelwidth\leftmarginii
\advance\labelwidth-\labelsep
\parsep \z@  \topsep \z@ \itemsep\z@}
\def\@listiii{\leftmargin\leftmarginiii
\labelwidth\leftmarginiii
\advance\labelwidth-\labelsep
\parsep \z@  \topsep \z@ \itemsep\z@}
\def\@listiv {\leftmargin\leftmarginiv
\labelwidth\leftmarginiv
\advance\labelwidth-\labelsep}
\def\@listv  {\leftmargin\leftmarginv
\labelwidth\leftmarginv
\advance\labelwidth-\labelsep}
\def\@listvi {\leftmargin\leftmarginvi
\labelwidth\leftmarginvi
\advance\labelwidth-\labelsep}
\setlength\lineskip{\z@}
\setlength\normallineskip{\z@}
\setlength\lineskiplimit{-\maxdimen}
\setlength\parskip{\z@}
\jot=\mtf@baselineskip
\newcommand{\partlabelfnt}{\Large\bfseries}
\newcommand{\partfnt}{\huge\bfseries}
\newcommand{\secfnt}{\Large\bfseries}
\newcommand{\subsecfnt}{\large\bfseries}
\newcommand{\subsubsecfnt}{\normalsize\bfseries}
\newcommand{\paragraphfnt}{\normalsize\bfseries}
\newcommand{\subparagraphfnt}{\normalsize\bfseries}
\renewcommand\part{%
\if@noskipsec \leavevmode \fi
\par
\addvspace{2\mtf@baselineskip}%
\@afterindentfalse
\secdef\@part\@spart}

\def\@part[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
{\parindent \z@ \raggedright
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >\m@ne
\partlabelfnt \partname\nobreakspace\thepart
\par\nobreak
\fi
\partfnt #2%
\markboth{}{}\par}%
\nobreak
\vskip \mtf@baselineskip
\@afterheading}
\def\@spart#1{%
{\parindent \z@ \raggedright
\interlinepenalty \@M
\normalfont
\partfnt #1\par}%
\nobreak
\vskip \mtf@baselineskip
\@afterheading}
\renewcommand\section{\@startsection {section}{1}{\z@}%
{-\mtf@baselineskip}%
{\mtf@baselineskip}%
{\normalfont\secfnt}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
{-\mtf@baselineskip}%
{1sp}%
{\normalfont\subsecfnt}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
{-\mtf@baselineskip}%
{-1em}%
{\normalfont\subsubsecfnt}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{-\mtf@baselineskip}%
{-1em}%
{\normalfont\paragraphfnt}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
{-\mtf@baselineskip}%
{-1em}%
{\normalfont\subparagraphfnt}}
\setlength\abovecaptionskip{\mtf@baselineskip}
\setlength\belowcaptionskip{\mtf@baselineskip}
\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{#1: #2}%
\ifdim \wd\@tempboxa >\hsize
#1: #2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
\renewcommand*\l@part[2]{%
\ifnum \c@tocdepth >-2\relax
\addpenalty\@secpenalty
\setlength\@tempdima{3em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
{\leavevmode
\large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
\nobreak
\if@compatibility
\global\@nobreaktrue
\everypar{\global\@nobreakfalse\everypar{}}%
\fi
\endgroup
\fi}
\renewcommand*\l@section[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup
\fi}
\renewcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.3em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{3.8em}{3.2em}}
\renewcommand*\l@paragraph{\@dottedtocline{4}{7.0em}{4.1em}}
\renewcommand*\l@subparagraph{\@dottedtocline{5}{10em}{5em}}
\renewcommand\indexspace{\par \vskip\mtf@baselineskip\relax}
\renewcommand\footnoterule{%
\hrule\@width.4\columnwidth
\kern3.5\p@}

\endinput

MWE

\documentclass{article}

\usepackage{baseline}
%----------------------------------
%              just for the example
\newtheorem{theorem}{Theorem}[section]
\usepackage{blindtext}
%----------------------------------
%                 just for the show
\usepackage{tikz}
\usepackage{eso-pic}
\AddToShipoutPicture{%
\begin{tikzpicture}[overlay,remember picture]
\draw[blue!20!white,thin]
(current page.south west) grid [ystep=12pt,xstep=\paperwidth] (current page.north east);
\end{tikzpicture}}
%----------------------------------
\begin{document}
\tableofcontents
\blindmathtrue
\blindtext
\begin{center}
Lorem ipsum dolor sit amet,
\end{center}
\begin{theorem}
\blindtext
$\bar x = \frac{1}{n}\sum_{i=1}^{i=n} x_i = \frac{x_1 + x_2 + \dots{} + x_n}{n}$
\end{theorem}
\Blinddocument

\end{document}

User guide guide user interface:

1) The package uses default font size from class 10pt, 11pt, 12pt or 9pt, 14pt, 17pt if allowed, for example if extarticle is used but the user can also do

\documentclass{article}
\fontsize{15pt}{18pt}\selectfont
\usepackage{baseline}

2) The package use default setting from class article for section like heading (shape, size ...) but not vertical spacing of course. If the use want to change this setting, the pacckage provides commands for this

\renewcommand{\partlabelfnt}{......}   % default {\Large\bfseries}
\renewcommand{\partfnt}{......}   % default {\huge\bfseries}
\renewcommand{\secfnt}{......}   % default {\Large\bfseries}
\renewcommand{\subsecfnt}{......}   % default {\large\bfseries}
\renewcommand{\subsubsecfnt}{......}   % default {\normalsize\bfseries}
\renewcommand{\paragraphfnt}{......}   % default {\normalsize\bfseries}
\renewcommand{\subparagraphfnt}{......}   % default {\normalsize\bfseries}

• This may be a good start and the output looks good, but this solution does not have a particularly easy API for beginners. It would be nice if you could separate isolate the API in a separate style file and provide a key-value interface that lets the user define the style for the sectional unit headings. Ideally, the API should be monkey proof. E.g. it should only allow multiples of "standard leadings" for the (temporary) leading. – user10274 Aug 28 '15 at 23:39
• @MarcvanDongen I'll update my answer by adding a new solution. I'll back to my original idea. – touhami Aug 29 '15 at 22:48
• @touhami I think for display things you have to intercept and add the right spacing "by hand" either by trapping the display in a box and measuring (the classic way) or by using \pdfsavepos (or wrappers such as tikzmark) to measure the vertical position after the display and adjust on the next run, or something else.... – David Carlisle Aug 31 '15 at 20:12
• @MarcvanDongen I didn't really mean it that way. It was a point about how you were saying it. I didn't think that you meant it to come across as you did. And I didn't mean my comment to come across as it obviously did either. So I'm sorry that you understood it that way. I'll delete it but it was intended to be a point about communication rather than content. But, sadly, my communication is clearly no good either. – cfr Sep 2 '15 at 2:48
• I thought the idea was that the code would adjust in that case to ensure that the body text still started on a standard baseline. For example, if the definition of \subsection boxed the title, measured the height and then added some space to make it up to a multiple of \baselineskip or whatever. The title text would not necessarily be on the baseline but the requirement, as I understand it, is only for the running text to be. However, that approach would obviously fail for run-in titles. (But changing their size is dodgy anyway, I think.) – cfr Sep 2 '15 at 12:53