Another body text in the margin

A very rough approach, collecting the material for the other book in a vertical box, and using \vsplit to split the top part of that box and put it on the left of the main text. Admittedly, the result is not good, but it might be possible to polish it.

\documentclass{article}
\textwidth=200pt\relax %??
\usepackage{xgalley,xparse}
\usepackage{lipsum}

\ExplSyntaxOn\makeatletter
\box_new:N \l_otext_tmpa_box
\box_new:N \g_otext_box
\dim_new:N \g_otext_prevdepth_dim
\skip_new:N \l_otext_sep_skip
\skip_set:Nn \l_otext_sep_skip { 20 pt }
\dim_new:N \g_otext_side_width_dim
\dim_gset:Nn \g_otext_side_width_dim { 100 pt }
\NewDocumentEnvironment{otext}{}
  {
    \vbox_gset:Nw \g_otext_box
      \color_group_begin:
        \vbox_unpack_clear:N \g_otext_box
        \dim_gset_eq:NN \tex_prevdepth:D \g_otext_prevdepth_dim
        \dim_set_eq:NN \l_galley_width_dim \g_otext_side_width_dim
        \galley_level:
        \bool_gset_false:N \g_galley_omit_next_indent_bool
        \raggedleft
  }
  {
      \color_group_end:
      \dim_gset_eq:NN \g_otext_prevdepth_dim \tex_prevdepth:D
    \vbox_set_end:
  }
% Patch \output.
\tl_set:Nx \l_tmpa_tl { \the\output }
\tl_put_left:Nn \l_tmpa_tl
  {
    \vbox_set_split_to_ht:NNn \l_otext_tmpa_box \g_otext_box
      { \box_ht:N \@cclv + \box_dp:N \@cclv }
    \vbox_set:Nn \@cclv
      {
        \hbox:n
          {
            \box_use_drop:N \l_otext_tmpa_box
            \skip_horizontal:N \l_otext_sep_skip
            \box_use_drop:N \@cclv
          }
      }
  }
\exp_args:No \output \l_tmpa_tl
\makeatother\ExplSyntaxOff

\begin{document}
\raggedright

\begin{otext}
  \section{Paragraphs 1 and 2}
  \lipsum[1-2]
\end{otext}

\begin{otext}
  \section{Paragraphs 3 and 4}
  \lipsum[3-4]
\end{otext}

\section{Paragraphs 11 to 13}
\lipsum[11-13]

\begin{otext}
  \section{Paragraphs 5 to 7}
  \lipsum[5-7]
\end{otext}

\section{Paragraphs 14 to 27}
\lipsum[14-27]

\end{document}

You can use \marginpar to put the second book in the margin. I prepared a sample that shows a figure, a table and some text. The sidefigure and sidetable environments are taken from the sidenotes package. It would be possible to put a whole book in the margin.

Two things would have to be addressed: How are the 'two books' synchronized, i.e. where are the page breaks and what happens if your first book fits on the page, but the one in the margin does not. It would even be possible to float the second book in the margin across pages, lets say for a chapter. You could use the marginfix package for that. If you want to try that, first put the complete chapter of the second book in the margin, then put the first book. You might have to use the morefloats package as well.

The second thing is the numbering. How are the figures and tables supposed to be numbered? Independently with a prefix, subsequently or something else?

Please change the filename in the \includegraphics macro to try the sample.

Also, it turns out that marginfix needs the paragraphs in the second document one at a time. So instead of \marginpar{\lipsum[1-2]} it wants \marginpar{\lipsum[1]}\marginpar{\lipsum[2]}.

\documentclass[]{article}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{morefloats}
\usepackage{marginfix}

\usepackage[paperwidth=170mm, paperheight=240mm, left=40pt, top=40pt, textwidth=220pt, marginparsep=20pt, marginparwidth=160pt, textheight=560pt, footskip=40pt]{geometry}

\makeatletter
\newsavebox{\@sidenotes@sidefigurebox}
\newenvironment{sidefigure}[1][]%
{\begin{lrbox}{\@sidenotes@sidefigurebox}%
\begin{minipage}{\marginparwidth}%
\captionsetup{type=figure}}%
{ \end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@sidenotes@sidefigurebox}}}
\newsavebox{\@sidenotes@sidetablebox}
\newenvironment{sidetable}[1][]%
{\begin{lrbox}{\@sidenotes@sidetablebox}%
\begin{minipage}{\marginparwidth}%
\captionsetup{type=table}}%
{ \end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@sidenotes@sidetablebox}}}
\makeatother

\begin{document}
%% this is document 2
\marginpar{\lipsum[4]}

\begin{sidefigure}
\includegraphics{broken_loop}
\caption{This is the caption}
\label{alabel}
\end{sidefigure}


\begin{sidetable}
  \centering
 % \fontfamily{ppl}\selectfont
  \begin{tabular}{lllll}
    \toprule
     Hg&Sn&Pb&Cd&Tl \\
    \midrule
    0.50&0.47&0.48&0.5&0.5\\
    \bottomrule
  \end{tabular}
\caption{A table}
\end{sidetable}

\marginpar{\lipsum[2]}

\marginpar{\lipsum[3]}
\marginpar{\lipsum[4]}
\marginpar{\lipsum[5]}
\marginpar{\lipsum[6]}

%% this is document 1

\lipsum[1-9]


\end{document}

Tags:

Margins