修補wrappig以使用行而不是段落

修補wrappig以使用行而不是段落

我想我知道如何緩解以下一些問題:

連續兩個浮動包裝圖形

但我不知道如何實施它。浮動問題的一個重要部分似乎與堅持將包裝圖放在段落開頭有關。如何放寬此限制?

例如,我在中間有分頁符號的段落之前放置了一個wrappig。該wrapfig將浮動到下一個段落(例如,該段落可能太小——在該部分結束之前——或被另一個wrapfig使用),完全忽略當前段落。但是,如果我將段落分成行大小的小段落,那麼包裝無花果將一有機會就開始。我不想拆分成小段落(或每次文件更改時手動將 wrapfig 放置在段落內),而是想解除段落限制。


編輯

下面的評論讓我好奇:

低階乳膠-需要改造嗎?

答案1

您可能會發現這很有趣。這是一種應用於\parshape多個段落和方程式的嘗試。

\documentclass{article}
\usepackage{mwe}
\usepackage{showframe}
\tracingmacros=1

% global varaibles
\newtoks\MSeverypar
\newcounter{MScount}
\newcounter{MSlines}
\newlength{\MSleft}
\newlength{\MSright}
\newlength{\MSvert}
\newsavebox{\MSbox}
\newif{\ifMSdone}
\newif{\ifMSnext}
\newcommand{\MSparshape}{}% reserve global name
\newcommand{\MSnextshape}{}% reserve gloval name

\newenvironment{minishape}[1]% #1 = shape blocks (left,right,vert)
 {\MSeverypar=\expandafter{\the\everypar}
  \def\END{\END}% token only. Do not expand!
  \setcounter{MScount}{0}%
  \xdef\MSlastleft{0pt}%
  \xdef\MSlastright{0pt}%
  \MSparse#1\empty\END% save instructions as macros
  \edef\MStotal{\theMScount}%
  \setcounter{MScount}{0}%
  \MSnext
  \everypar{\MSparagraph}}{}

\def\MSparse#1(#2,#3,#4)#5\END{% #1=throwaway #2=left, #3=right, #4=vert, #5=next
  \ifx!#4\relax
    \xdef\MSlastleft{#2}%
    \xdef\MSlastright{#3}%b
  \else
    \stepcounter{MScount}%
    \expandafter\xdef\csname MSleft\theMScount\endcsname{#2}%
    \expandafter\xdef\csname MSright\theMScount\endcsname{#3}%
    \expandafter\xdef\csname MSvert\theMScount\endcsname{#4}%
  \fi
  \ifx\empty#5\relax\else\expandafter\MSparse#5\END\fi}
  
\newcommand{\MSmerge}[2]{\edef\MSshape{#1 #2}}

\long\def\MSparagraph#1\par{% \everypar#2)
  \setcounter{MSlines}{1}%
  \global\let\MSparshape=\MSnextshape
  \MSdonefalse
  \loop
    \MSmakebox{#1}%
    \MSsplitbox
  \ifMSdone\else\repeat
  \global\advance\MSvert by -\parskip
  \ifnum\value{MScount}>\MStotal\relax
    \stepcounter{MSlines}%
    \MSmerge{\MSparshape}{\MSnextshape}%
    \global\let\MSparshape=\MSshape
  \fi
  \MSmerge{\theMSlines}{\MSparshape}%
  \parshape=\MSshape #1\par}
  
\newcommand{\MSmakebox}[1]% #1 = paragraph
{\bgroup
  \clubpenalty=0
  \widowpenalty=0
  \displaywidowpenalty=0
  \predisplaypenalty=0
  \postdisplaypenalty=0
  \interlinepenalty=0
  \everypar=\expandafter{\the\MSeverypar}
  \MSmerge{\theMSlines}{\MSparshape}%
  \global\setbox\MSbox=\vbox{\parshape=\MSshape \strut#1\strut}%
\egroup}

\newcommand{\MSsplitbox}% extend \MSparshape
{\bgroup% local varaibles and loops
  \countdef\count=1
  \dimendef\delta=0
  \dimendef\test=1
  \count=1
  \loop\ifnum\count<\value{MSlines}%
    \advance\count by 1
    \global\setbox0=\vsplit\MSbox to \baselineskip%
  \repeat
  \MSnextfalse
  \loop
    \delta=\ht\MSbox
    \advance\delta by \dp\MSbox
    \ifdim\delta>0pt\relax
      \global\setbox0=\vsplit\MSbox to \baselineskip%
      \advance\delta by -\ht\MSbox
      \advance\delta by -\dp\MSbox
      \ifdim\delta>\MSvert
        \count=\value{MScount}%
        \ifnum\count<\MStotal\relax
          \advance\count by 1
          \ifdim\MSleft<\csname MSleft\the\count\endcsname\relax \MSnext
          \else
            \ifdim\MSright<\csname MSright\the\count\endcsname\relax \MSnext\fi
          \fi
        \fi
      \fi
      \stepcounter{MSlines}% global
      \MSmerge{\MSparshape}{\MSnextshape}%
      \global\let\MSparshape=\MSshape
      \global\advance\MSvert by -\delta
      \ifdim\MSvert>0pt\relax\else\MSnext\fi
    \else
      \global\MSdonetrue
      \MSnexttrue
    \fi
  \ifMSnext\else\repeat
\egroup}

\newcommand{\MSnext}{% at end of block
  \MSnexttrue
  \ifnum\value{MScount}<\MStotal\relax
    \stepcounter{MScount}%
    \global\advance\MSvert by \csname MSvert\theMScount\endcsname\relax%
    \global\MSleft=\csname MSleft\theMScount\endcsname%
    \global\MSright=\csname MSright\theMScount\endcsname%
  \else
    \stepcounter{MScount}%
    \global\MSdonetrue
    \global\MSleft=\MSlastleft\relax
    \global\MSright=\MSlastright\relax
  \fi
  \MSmerge{\the\MSleft}{\the\dimexpr\linewidth-\MSleft-\MSright}%
  \global\let\MSnextshape=\MSshape
}

\begin{document}

\begin{minishape}{(.25in,.25in,1in) (.5in,.5in,1.5in)}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus
eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium
quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. 
Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.

Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna,
vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse
ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et
magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna.
Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris.

\end{minishape}

\end{document}

相關內容