1

RESOLUTION with WORKAROUNDS The 2018 TeXLive update --- specifically memoir.cls as updated to 2018/04/04 v3.7g and marginnote.sty as updated to 2018/04/13 v1.3 --- together permit a workaround of both the pagebreak problem and the colorleak problem.

In a nutshell, (1) the \marginpar macro is replaced with a wrapper for the \marginnote macro, and (2) the color leak is repaired by patches to \sidebar and \sidebarform.

The minimal working example (below) has been amended to incorporate these workarounds.

Deep appreciation and heartfelt thanks are extended to the unsung TeX-heroes who are responsible for these continuing improvements!


Memoir-class bug description  In \documentclass{memoir}, whenever \sidebar{<multipage content>} is evaluated first, followed by \marginpar{<short content>} within the span of the typeset sidebar's <multipage content>, then the order of the lines in the typeset <multipage content> is scrambled.

There's a color-bleed bug too  A second, possibly-related bug is that \color{<name>} specifications within \sidebar{<multipage content>} bleed into body-text.

The color-bleed \sidebar-bug is particularly a problem when the colored text of the \sidebar{<multipage content>} is intended for a press-separation that provides spot colors, via (e.g.) \RequirePackage{colorspace} with PANTONE-color specifications.

Background and documentation  To create sidebars whose text spans multiple pages, the LaTeX class memoir provides \sidebar{<multipage content>}. For shorter comments, memoir provides \marginpar{<short content>}. To accommodate a \sidebar and a \marginpar that appear on the same page, in opposing margins, memoir provides positioning commands that include \marginparmargin{inner} and \sidebarmargin{outer}.

Details of \sidebar functionality are specified in the memoir manual, 'memman.pdf', version v3.7f, in which section "12.4 SIDEBARS" begins:

Sidebars are typeset in the margin and usually contain material that is ancilliary to the main text. They may be long and extend for more than one page.

A color-bleed workaround exists  In respect to the color-bleed bug in \sidebar{<multipage content>}, I have found a workaround -- a lamentably complicated workaround -- that for reason of simplicity is not included in the (appended) minimum working example.

The Fix/workaround sought  Sought is a minimum working example in which both the page-break bug and the color-bleed bug are fixed, as simply and robustly as possible, such that \sidebar{<multipage content>} (1) reliably page-breaks even in the presence of \marginpar, and (2) has a font and color that are distinct from the body text, that do not bleed outside of the sidebar.

Minimum working example  Here is a MWE that exhibits both the the page-break bug and the color-bleed bug (now with workarounds that fix them).

% Minimum workarounds for two bugs in in 'memoir.cls':
% (1) '\marginpar{<short comment>}' breaks '\sidebar{<multipage comments>}'
% (2) '\sidebar' colors leak into the body text

\documentclass[9pt,A4]{memoir}[2018-04-01]

%  --- header of the log file -----------------------------------------
%  This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) 
%  (preloaded format=pdflatex)
%  restricted \write18 enabled.
%  entering extended mode
%  (./workaround.tex
%  LaTeX2e <2018-04-01> patch level 3
%  Babel <3.20> and hyphenation patterns for 84 language(s) loaded.
%  (/usr/local/texlive/2018/texmf-dist/tex/latex/memoir/memoir.cls
%  Document Class: memoir 2018/04/04 v3.7g configurable book, report, 
%  article document class
%  (etc.)
%  --------------------------------------------------------------------
%  Note: no very evident errors are reported in log file ...

% load packages
\RequirePackage{xcolor}
\RequirePackage{ragged2e}
\RequirePackage{calc}
\RequirePackage{lipsum}

%  --- begin memoir/sidebar/marginpar adjustments -------------
%  note: details of these appearance-options seemingly are 
%        immaterial to the \sidebar{...} wrap-bug

%  set and check the page dimensions
%  preparing for \marginparwidth = 11em
%                  \sidebarwidth = 14em
\normalfont%
\setlrmarginsandblock{11em+1em+2cm}{14em+1em+2cm}{*}
\checkandfixthelayout

%  adjust the \marginpar parameters
\marginparmargin{inner}
\setmarginnotes% {<hsep>}{<width>}{<push>}
  {1em}%                    specify  <hsep> => \marginparsep
  {\spinemargin-1em-2cm}%   specify <width> => \marginparwidth
  {\onelineskip}%           specify  <push> => \marginparpush

%  adjust the \sidebar parameters
\sidebarmargin{outer}
\setsidebars% {<hsep>}{<width>}{<vsep>}{<topsep>}{<font>}{<height>}
  {1em}% specify <hsep>
  {\foremargin-1em-2cm}%    specify  <width> => \sidebarwidth
  {\onelineskip}%           specify   <vsep> => \sidebarvsep 
  {0pt}%                    specify <topsep> => \sidebartopsep
  {\sffamily\footnotesize%  specify the <font> parameters
      % BUG: the following '\color{...}' bleeds into the body
      \color{blue}}%           (optionally including a color)
  {\textheight}%            specify <height> => \sidebarheight 
\DeclareRobustCommand{\sidebarform}{\justifying}
%  --- end memoir/sidebar/marginpar adjustments -------------

%  --- begin marginpar workaround -------------
\RequirePackage{xparse}
\RequirePackage{marginnote}[2018/04/13]
\RenewDocumentCommand{\marginpar}{+o+m}{%
    \IfNoValueTF{#1}%
        {\marginnote{#2}}%
        {\marginnote[#1]{#2}}%
}
%  --- end marginpar workaround -------------

%  --- begin color 'leak' workaround -------------
\RequirePackage{xparse}
\let\originalsidebar\sidebar
\RenewDocumentCommand{\sidebar}{+o+m}{%
    \IfNoValueTF{#1}%
        {\originalsidebar{#2}\color{black}}%
        {\originalsidebar[#1]{#2}\color{black}}%
}
\let\nativesidebarform\sidebarform
\RenewDocumentCommand{\sidebarform}{}{%
    \nativesidebarform\color{black}}
%  --- end color 'leak' workaround -------------

\begin{document}
\textbf{This is the first paragraph of a 
multipage memoir-class document.}

\lipsum[2]%
\marginpar{
    Marginal comments like this one,
    when they come \textsc{before}
    a multipage sidebar,
    \textsc{have never} induced a wrap-error.
}

\lipsum[3]%
\sidebar{\strictpagecheck%
    \textbf{TEST: this sidebar paragraph should 
    appear on page 1, at the top of the fore-margin.}
    \par
    \lipsum[2-11]
    \par
    \textbf{TEST: this sidebar paragraph should 
    appear as the bottom-most fore-margin
    paragraph, as the final paragraph
    (namely the 12th paragraph)
    of a multipage sidebar.}
}%

\lipsum[4]%
\marginpar{\strictpagecheck%
     \textsc{Hurrah!!!}\dots marginal 
    comments like this one,
    that are specified \textsc{after}
    a multipage sidebar,
    \textsc{no longer} induce a wrap-error.
}

\lipsum[5-8]%

\lipsum[9]%
\marginpar{\strictpagecheck%
    \textsc{Hurrah!}\dots this marginal 
    comment too, appearing
    on the second page of 
    a multipage sidebar,
    no longer induces a wrap-error.
}

\lipsum[10-19]

\textbf{This is the final body-text 
paragraph (namely the 20th paragraph) 
of a multipage document.}

\end{document}
\endininput
  • 1
    getting colours right after a split footnote (or here marginnote) strains at the limit of what is feasible in classic tex, If you want all sidebar coloured in the same colour that's easier as you can move the colour setting into the output routine as the sidebar is added to the page, but if you need to detect colour changes within a note that may be split it's much harder (however I'd start by looking at the extra colour stacks in the pdfcol package (sorry no time to look at your example today) – David Carlisle Nov 23 '17 at 14:07
  • Thank you David. Oddly enough, getting typecolors and fonts to work right (in split \sidebars) has been EASIER than getting the lineorder/pagebreaks right (in those same split \sidebars). I've also mastered arcane arts (arcane at my skill level anyway) like extending the font ebgaramond to encompass boldface, and specifying spotcolors for color separation. Right now everything is working right EXCEPT split-page \sidebar text (frustrating) ... so if a workaround is found, then I'll post the whole set of memoir extensions. – John Sidles Nov 23 '17 at 17:53
  • If you have a solution, you should provide an answer, rather than modifying that way the question. – egreg May 3 '18 at 20:43
  • We'd like to keep answers separate from questions, so you should write a separate answer instead of editing your answer into the question. Self-answers are perfectly admissible, and a well-written answer may earn you additional reputation. – CarLaTeX Jun 3 '18 at 2:26
1

TeXLive 2018 provided package updates that suffice to work around both the page-break problem and the color-leak problem ... the minimal working example has been updated to demonstrate these workarounds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.