22

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.

  • 1
    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 09:41
  • 2
    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
  • 2
    Would this be a possible candidate for what you're looking for? http://tex.stackexchange.com/a/35093/3954 – Gonzalo Medina Aug 28 '15 at 13:36
  • @MarcvanDongen I could add a preliminary version allowing this (of course, not as elaborate as the one provided by titlesec, for example). – Gonzalo Medina Aug 28 '15 at 16:40
  • @MarcvanDongen Two questions (though I have no time to answer for the foreseeable future). – Should it work with consecutive headings (i.e. no text between them)? And how about footnotes? I see no harmonious solution except to stick them at the bottom with their own leading and alignment. Same with headings that span over several lines… the only harmonious solution is to break the grid (though with sufficient leading, one can have everything up to the section ≤ \baselineskip). – ienissei Sep 01 '15 at 16:45
  • @MarcvanDongen I can't see why you consider my solution is not working :-( well :-) – touhami Sep 01 '15 at 23:15
  • @Johannes_B Is what a bug? – cfr Sep 02 '15 at 02:10
  • @cfr The comment i answered to is deleted now, my own deleted as well. :-) – Johannes_B Sep 02 '15 at 14:48
  • @ienissei Ideally it should work with LaTeX. You may assume there are no footnotes, but if you do implement them, they should not interfere with the inter-line spacing of the running text. You may also assume there are no consecutive headings. –  Dec 29 '15 at 13:49
  • @GonzaloMedina Looks nice but from the examples it's not clear whether it's easy to change the style for sectional units. –  Dec 29 '15 at 13:54

1 Answers1

18

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}

enter image description here

enter image description here

touhami
  • 19,520
  • 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. –  Aug 28 '15 at 23:39
  • @MarcvanDongen I'll try. for example the user need only to set \renewcommand{\secfnt}{<styleofsection>} styleofsection default is \sffamily\bfseries – touhami Aug 28 '15 at 23:44
  • I note that it's impossible to change the size of the type in the sectional unit headings. Changing the size of the type should be possible (and to any size). Perhaps I'm missing something. A well-defined interface would help to understand the implementation as well as the API. –  Aug 28 '15 at 23:50
  • 1
    @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
  • (I overlooked something earlier on.) I don't think this is what I'm looking for. For example if I do, \renewcommand\subsecfnt{\tikz\draw (0,0) rectangle (1,1);\Large\bfseries}\section{Hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello}\subsection{World hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello} this affects the leading for the sectional unit titles. I would have hoped it wouldn't change. Also it would be nicer if there was a key-value API. –  Aug 31 '15 at 10:33
  • @MarcvanDongen sorry, I am not sure I understand you correctly but the fontsize \Large by default is 14.4pt so bigger than the unite baseline =12pt that's why it change. Try \renewcommand\subsecfnt{\tikz\draw (0,0) rectangle (1,1);\large\bfseries}. Please informe me. – touhami Aug 31 '15 at 11:00
  • Any size should be allowed. There are plenty of books that have sectional unit titles that don't fit the normal inter line spacing. For example, see LaTeX and Friends. –  Aug 31 '15 at 11:32
  • I think this is not so difficult, but I don't recommand it. I will see. – touhami Aug 31 '15 at 16:07
  • note \setlength\lineskiplimit{-\maxdimen} means that if the math takes up more space than three lines then it will over-print the following text. – David Carlisle Aug 31 '15 at 18:11
  • I know it's not difficult. I implemented it myself:) All I'm looking for is something that's useful for the TeX community. –  Aug 31 '15 at 18:20
  • @DavidCarlisle thank you, this is exactly what I was waiting for. I mean I know that this will cause problem, but what? thank you again, any advice? – touhami Aug 31 '15 at 19:27
  • @MarcvanDongen see http://justpaste.it/nf80 – touhami Aug 31 '15 at 19:35
  • 2
    @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
  • @DavidCarlisle (+1) I think you're right. That's about how I did it when I implemented this myself (but my solution isn't useful for the general public). –  Aug 31 '15 at 23:10
  • @touhami Please notice that there's no need to prove your solution works with (math) displays. It's stated explicitly in my question. –  Aug 31 '15 at 23:11
  • @MarcvanDongen I figured it probably isn't what you mean. But I think you are making it sound rather simpler than it is. It is not just section headings, after all: at least you have to worry about the title etc., floats at the top of pages, lists, footnotes etc. And the results have to look nice. Moreover, a user might, of course, switch font or fontsize without that being part of a custom display (i.e. not using a center environment or a minipage or \parbox which I assume are ruled out). Moreover, inline maths can also affect the spacing between lines, can it not? – cfr Sep 02 '15 at 02:45
  • 1
    @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 02 '15 at 02:48
  • @MarcvanDongen And I would be sorry if you stopped contributing. Please do not (stop, that is). – cfr Sep 02 '15 at 02:52
  • @MarcvanDongen I thought the question was fine. I just thought you were being a bit hard on touhami. – cfr Sep 02 '15 at 03:20
  • @cfr For me it's not about difficulty it's about (sense?) I still don't understand what the OP mean about font size changing. – touhami Sep 02 '15 at 06:59
  • @MarcvanDongen please see my comment to cfr – touhami Sep 02 '15 at 06:59
  • @touhami I am not sure how to explain this better than I did in my question. –  Sep 02 '15 at 11:35
  • @MarcvanDongen I excuse you. maybe it's me, I have the problem of explaining. But make sure you can use any size you want, if the font size is big of course the baseline will change (double or 3x, ...) in your comment you made subsection in Large so you make it as section style, if you think the baseline was changed because of \tikz no, you can try without it. did you see https://justpaste.it/nf80 – touhami Sep 02 '15 at 11:49
  • 1
    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 02 '15 at 12:53
  • @cfr (+1) That's exactly what I meant. –  Sep 02 '15 at 13:08
  • @MarcvanDongen and that is exactly what i do (I propose) in (last) page https://justpaste.it/nf80 – touhami Sep 02 '15 at 13:10
  • @cfr please see my last comment – touhami Sep 02 '15 at 13:11
  • @touhami That would be with further modifications, right? (That is, the last case shown in the paste.) If so, yes, that's how I understood it although, as I say, I'm not sure how run-in titles are supposed to be handled. But it would seem to me reasonable for those to impose \normalsize since the running text cannot flow around them nicely otherwise ;). – cfr Sep 02 '15 at 13:19
  • @cfr you're right. – touhami Sep 02 '15 at 14:36
  • @touhami It doesn't work as expected: after \renewcommand\secfnt{\Large\bfseries} the leading of the section title is twice that of what you'd get if you used \Large\bfseries in the running text. Also (IMHO) a key-value interface would be easier for the user. –  Sep 03 '15 at 08:46
  • please try this \documentclass{article} \usepackage{baseline}\begin{document} \Large\bfseries the leading of the section title is twice that of what you'd get if you used the leading of the section title is twice that of what you'd get if you used the leading of the section title is twice that of what you'd get if you used \end{document} Manipulation of baselineskip is not so easy, for example, if you type bla bla {\huge bla} bla in standard latex document (without baseline.sty) the baselieskip will not change you need to start (or to end) a paragraph. – touhami Sep 03 '15 at 09:08
  • Comments are not for extended discussion; this conversation has been moved to chat. – Joseph Wright Sep 04 '15 at 09:40