9

I need to use a lot of marginpars and hit "Too many unprocessed floats" as a result. I'm already using the morefloats package with maxfloats set to 100, but it's not enough sometimes. I'm thinking a solution might be to force marginpars to appear where they are declared (like the H option for floats).

Is there a way to do this?

Note: I do need floats for my solution, I cannot use fixed notes, as they have to float in the margin, even if inserted in the middle of a paragraph.

Another note: \FlatBarrier from the placeins package (combined with morefloats) helps, but I need to find how to place it so that it doesn't impact my layout. Typically, I would have to call it only when \marginpar is called at the beginning of a line, and it would probably solve the issue.

3
  • 1
    You might try marginnote package (or even my own not really finished mpnote) \marginpar can't really cope with layouts that have lots of marginal material. – David Carlisle Mar 31 '13 at 20:11
  • marginnote seems promising, but it doesn't seem to support twocolumn (it typesets all the notes to the side of the page — left of left column or right of right column). – raphink Mar 31 '13 at 20:58
  • Oh, I see what it's doing… it's typesetting to a fixed distance of the place where the note is inserted (quite logic, since it's not a float). – raphink Mar 31 '13 at 21:02
6

NOTE:

The \extrafloats command defined below is defined in the latex format for LaTeX releases from 2015 onwards so is available without needing this definition or a package.


morefloats only allocates floats from the classical tex counter range 0-255 and as LaTeX uses many of those registers in the format you only have around 100 at maximum, But as etex is usually available really you can allocate floats from the extended range and so have around 32000 of them if you need them.

This is using figure rather than marginpar but they come from the same pool, so it should work for either.

\documentclass{article}

\makeatletter
\mathchardef\float@count=32767

\def\extrafloats#1{%
\ifnum#1>\z@
\count@\numexpr\float@count-1\relax
\mathchardef\float@count\count@
\expandafter\mathchardef\csname bx@\the\float@count\endcsname\float@count
\@cons\@freelist{\csname bx@\the\float@count\endcsname}%
\expandafter
\extrafloats\expandafter{\numexpr#1-1\relax}%
\fi}
\makeatletter

\extrafloats{500}

%\usepackage[maxfloats=100]{morefloats} not enough



\setcounter{totalnumber}{1}
\def\f{text text\par
       \begin{figure}[t]\rule{1cm}{1cm}
        \caption{fff}\end{figure}}

\def\ff{\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f}

\begin{document}

\ff\ff\ff\ff\ff\ff
\ff\ff\ff\ff\ff\ff

\end{document}
5

With Donald Arseneau's new (MAR 13) tabto package improvements, you can execute the marginpars immediately. I create \imarginpar to do just that. Perhaps it will help. Plus, there is nothing to stop you from marginpar'ing in both margins, just by changing the \tabto arguments.

\documentclass{article}
\usepackage{tabto}
\newcommand\imarginpar[1]{%
  \tabto*{-0.5cm}%
  \smash{\llap{\parbox[t]{1in}%
  {#1}}}%
  \tabto{\TabPrevPos}%
}
\begin{document}

This is blah blahThis is blah blahThis is blah blahThis is blah blahThis
is blah blahThis is blah blahThis is blah blahThis is blah blahThis is
blah blahThis is blah blahThis is blah blahThis is blah blahThis is blah
blahThis is blah blahThis is blah blahThis is blah blahThis is blah
blahThis is blah blahThis is blah blahThis is blah blahThis is blah
is blah blahThis is blah blahThis is blah blahThis is blah
blahThis is blah HERE IS THE TAB \imarginpar{margin note test record}
DONE THE TAB blah This is blah blahThis is blah blahThis is blah
blahThis is blah blahThis is blah blahThis is blah blahThis is blah
blahThis is blah blahThis is blah blahThis is blah blahThis is blah
blahThis is blah blahThis is blah blahThis is blah blah

\end{document}

This is the perhaps provisional version of tabto I have from Mr. Arseneau, containing the new length \TabPrevPos

% tabto.sty
%
% version 1.3  (Mar 2013)
%
% Tabbing to fixed positions in a paragraph.
%
% Copyright 2006,2009,2012,2013 by 
% Donald Arseneau,   Vancouver, Canada (asnd@triumf.ca)
% Permission to use, distribute and modify this software is granted
% under the conditions of the LaTeX Project Public License, either 
% version 1.3 or (at your option) any later version.  The license is
% found at http://www.latex-project.org/lppl.txt, and is part of all 
% recent distributions of LaTeX.
%
% This work has the LPPL maintenance status `maintained' (by author).
%
% Two new text positioning commands are defined: \tabto and \tab.
% 
% \tabto{<length>}
% Tab to a position relative to the left margin in a paragraph (any
% indentation due to a list or \leftskip is part of the `margin' in
% this context). If the text on the line already goes past the desired
% position, the tab starts a new line and moves to the requested
% horizontal position.
%
% \tabto*{<length>}
% Similar to \tabto, except it will perform backspacing, and over-
% print previous text on the line whenever that text is already
% longer than the specified length (i.e., no linebreak is produced).
% Line-breaks are suppressed immediately after \tabto or \tabto*.
%
% The length register "\CurrentLineWidth" will report the width
% of the existing text on the line, and it may be used in the
% <length> argument (using calc.sty, for example). Also, there
% is "\TabPrevPos" which gives the "\CurrentLineWidth" from the
% previous tab command, and can be used to return to that position
% if no line breaks have occurred in between.
%
% \tab
% Tab to the next tab-stop chosen from a list of tab positions, in
% the traditional style of typewriters.  A \tab will always move
% to the next tab stop (or the next line), even if it is already
% exactly at a tab stop. Thus, "\tab" at the beginning of a line,
% or "\tab\tab" elsewhere skips a position. A linebreak is permitted 
% immediately following a \tab, in case the ensuing text does not 
% fit well in the remaining space.
%
% If you do not want to skip positions, use "\tabto{\NextTabStop}"
% instead of "\tab".  This is particularly useful when you want to
% use \tab in some other command, but do not want to skip a column
% for the first item.
%
% The tab-stop positions are declared using either \TabPositions
% or \NumTabs:
%
% \TabPositions{<length>, <length>,...<length>}
% Declares the tab stops as a comma-separated list of positions 
% relative to the left margin. A tab-stop at 0pt is implicit, and 
% need not be listed.
%
% \NumTabs{<number>}
% Declares a list of <number> equally-spaced tabs, starting at the
% left margin and spanning \linewidth.  For example \NumTabs{2} 
% declares tab-stops at 0pt and 0.5\linewidth, the same as
% \TabPositions{0pt, 0.5\linewidth} or \TabPositions{0.5\linewidth}
%
% After these declarations, the list of tab positions is saved in
% \TabStopList, and the next tab position, relative to the current 
% position, is given by \NextTabStop.  You do not normally need
% to access them, but they are available.
%
% Problems:
%
% Tall objects after a tab stop may overlap the line abov, rather
% than forcing a greater separation between lines.

\ProvidesPackage{tabto}[2013/03/25 \space v 1.3 \space 
  Another tabbing mechanism]\relax

\newdimen\CurrentLineWidth
\let\TabPrevPos\z@

\newcommand\tabto[1]{%
 \leavevmode
 \begingroup
 \def\@tempa{*}\def\@tempb{#1}%
 \ifx\@tempa\@tempb % \tab* 
   \endgroup
   \TTo@overlaptrue % ... set a flag and re-issue \tabto to get argument
   \expandafter\tabto
 \else
   \ifinner % in a \hbox, so ignore
   \else % unrestricted horizontal mode
     \null% \predisplaysize will tell the position of this box (must be box)
     \parfillskip\fill
     \everydisplay{}\everymath{}%
     \predisplaypenalty\@M \postdisplaypenalty\@M
     $$% math display so we can test \predisplaysize
      \lineskiplimit=-999pt % so we get pure \baselineskip
      \abovedisplayskip=-\baselineskip \abovedisplayshortskip=-\baselineskip
      \belowdisplayskip\z@skip \belowdisplayshortskip\z@skip
      \halign{##\cr\noalign{%
        % get the width of the line above
        %\message{>>> Line \the\inputlineno\space -- \predisplaydirection\the\predisplaydirection, \predisplaysize\the\predisplaysize, \displayindent\the\displayindent, \leftskip\the\leftskip, \linewidth\the\linewidth. }%
        \ifdim\predisplaysize=\maxdimen % mixed R and L; call the line full
           \message{Mixed R and L, so line is full. }%
           \CurrentLineWidth\linewidth
        \else
           \ifdim\predisplaysize=-\maxdimen % impossible, in vmode; call the line empty
             \message{Not in paragraph, so line is empty. }%
             \CurrentLineWidth\z@
           \else
             \ifnum\TTo@Direction<\z@
               \CurrentLineWidth\linewidth \advance\CurrentLineWidth\predisplaysize
             \else
               \CurrentLineWidth\predisplaysize 
             \fi
             % Correct the 2em offset
             \advance\CurrentLineWidth -2em
             \advance\CurrentLineWidth -\displayindent
             \advance\CurrentLineWidth -\leftskip
        \fi\fi
        \ifdim\CurrentLineWidth<\z@ \CurrentLineWidth\z@\fi
        % Enshrine the tab-to position; #1 might reference \CurrentLineWidth
        \@tempdimb=#1\relax
      \message{*** Tab to \the\@tempdimb, previous width is \the\CurrentLineWidth. ***}%
        % Save width for possible return use
        \xdef\TabPrevPos{\the\CurrentLineWidth}%
        % Build the action to perform
        \protected@xdef\TTo@action{%
           \vrule\@width\z@\@depth\the\prevdepth
           \ifdim\CurrentLineWidth>\@tempdimb
              \ifTTo@overlap\else
                 \protect\newline \protect\null
           \fi\fi
           \protect\nobreak
           \protect\hskip\the\@tempdimb\relax
        }%
        %\message{\string\TTo@action: \meaning \TTo@action. }%
        % get back to the baseline, regardless of its depth.
        \vskip-\prevdepth
        \prevdepth-99\p@
        \vskip\prevdepth
      }}%
      $$
     % Don't count the display as lines in the paragraph
     \count@\prevgraf \advance\count@-4 \prevgraf\count@
     \TTo@action
     %%   \penalty\@m % to allow a penalized line break
   \fi
   \endgroup
   \TTo@overlapfalse
   \ignorespaces
 \fi
}

% \tab -- to the next position
% \hskip so \tab\tab moves two positions
% Allow a (penalized but flexible) line-break right after the tab.
%
\newcommand\tab{\leavevmode\hskip2sp\tabto{\NextTabStop}%
  \nobreak\hskip\z@\@plus 30\p@\penalty4000\hskip\z@\@plus-30\p@\relax}


% Expandable macro to select the next tab position from the list

\newcommand\NextTabStop{%
  \expandafter \TTo@nexttabstop \TabStopList,\maxdimen,>%
}

\def\TTo@nexttabstop #1,{%
    \ifdim#1<\CurrentLineWidth
      \expandafter\TTo@nexttabstop
    \else
      \ifdim#1<0.9999\linewidth#1\else\z@\fi
      \expandafter\strip@prefix
    \fi
}
\def\TTo@foundtabstop#1>{}

\newcommand\TabPositions[1]{\def\TabStopList{\z@,#1}}

\newcommand\NumTabs[1]{%
   \def\TabStopList{}%
   \@tempdimb\linewidth 
   \divide\@tempdimb by#1\relax
   \advance\@tempdimb 1sp % counteract rounding-down by \divide
   \CurrentLineWidth\z@
   \@whiledim\CurrentLineWidth<\linewidth\do {%
     \edef\TabStopList{\TabStopList\the\CurrentLineWidth,}%
     \advance\CurrentLineWidth\@tempdimb
   }%
   \edef\TabStopList{\TabStopList\linewidth}%
}

% default setting of tab positions:
\TabPositions{\parindent,.5\linewidth}

\newif\ifTTo@overlap \TTo@overlapfalse

\@ifundefined{predisplaydirection}{
 \let\TTo@Direction\predisplaysize
 \let\predisplaydirection\@undefined
}{
 \let\TTo@Direction\predisplaydirection
}
3
  • \TabPrevPos doesn't seem to be a defined command (using an up-to-date TL2013). – raphink Mar 31 '13 at 19:08
  • @ℝaphink TeX Live 2013? Did I miss it? ;-) – egreg Mar 31 '13 at 19:58
  • Yeah, I'm from the future (I use TL2012 in fact). – raphink Mar 31 '13 at 20:58

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.