Skip to content

Instantly share code, notes, and snippets.

@jfbu
Created December 14, 2018 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfbu/d88ad9ac67eb2bf56d36f009b9b954c8 to your computer and use it in GitHub Desktop.
Save jfbu/d88ad9ac67eb2bf56d36f009b9b954c8 to your computer and use it in GitHub Desktop.
\documentclass{article}
\usepackage{showframe} %% <- show boundary of text area
\usepackage{tikz} %% <- To draw the red brackets
\usepackage{tikzpagenodes} %% <- to place them correctly
% variant from the \insertvbox of https://tex.stackexchange.com/a/463739/4686
\newcommand*\unvtop[1]{% #1 is a \vtop !
\par
\begingroup
\setbox2=\vbox{\unvcopy#1}% %% <- box2 is a vbox
%
% cf TeX by Topic, explanations of TeX mechanism at bottom of page 186
% (in 15.1 Interline glue) and taking into account in particular:
% "the \prevdepth is not updated by an \unvbox or \unvcopy command"
% page 81, 5.7 Unboxing
% Beware of the following subtlety: unboxing in vertical mode does not add
% interline glue between the box contents and any preceding item. Also,
% the value of \prevdepth is not changed,
%
\dimen0=\dimexpr\baselineskip-\prevdepth-\ht#1\relax % #1 is a \vtop!
\ifdim\dimen0<\lineskiplimit
\vskip\lineskip
\else
\vskip\glueexpr\baselineskip-\dimexpr\baselineskip-\dimen0\relax\relax
\fi
\unvcopy#1% allows pagebreaks and in fact may recompute interline glue
\prevdepth\dp2
\endgroup
}
\parskip=0pt %% <- default value is "0pt plus 1pt"
\newcommand\redbracket{% %% <- for the little red brackets in the left margin
\begin{tikzpicture}[remember picture, overlay,]
\draw[red] (current page text area.north west) -- +(-2pt,0)
-- node[left]{\texttt{\detokenize{\topskip}}} +(-2pt,-\topskip) -- +(0,-\topskip);
\foreach \X in {0, ..., 7} {
\draw[red] ([yshift=-\topskip-\X\baselineskip]current page text area.north west) -- +(-2pt,0)
-- node[left]{\texttt{\detokenize{\baselineskip}}} +(-2pt,-\baselineskip) -- +(0,-\baselineskip);
}
\end{tikzpicture}%
}
\begin{document}
\newsavebox{\TitleBox}
\newsavebox{\BodyBox}
\setbox\TitleBox=\vtop{\noindent\textbf{A title that takes\\up more than\\two lines}}
\setbox\BodyBox=\vtop{\noindent Lorem\\ipsum\rule[-3pt]{1cm}{3pt}}
\vspace*{16.5cm}% testing breaking across pages
\unvtop\TitleBox
\unvtop\BodyBox
\unvtop\BodyBox
\unvtop\BodyBox
%\the\prevdepth
\redbracket
\clearpage
\noindent\textbf{A title that takes\\up more than\\two lines}
\noindent Lorem\\ipsum \par\noindent Lorem\\ipsum \par\noindent Lorem\\ipsum
\redbracket
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment