使用 verse 时,xintools 的非矩形体几何形状失败

使用 verse 时,xintools 的非矩形体几何形状失败

我使用“非矩形车身几何形状verse“由(已删除)用户 @user4686 编写,但当它到达正文中的环境时渲染失败:

数学家协会

因为我只需要文档部分的非矩形形状而不是宽文档,所以我删除了\cnta重复命令:

\documentclass[a4paper,12pt]{article}

\def\LINESPERPAGE{45}
\usepackage[textheight=\LINESPERPAGE\baselineskip]{geometry}

\usepackage{lipsum}
\usepackage{xinttools}% requires version 1.09m or later
\usepackage{poemscol}


% let's divide by two the sizes of the undulation.
\edef\MOCKSINE {%
{1.5em \the\dimexpr\textwidth-1.5em}%
{2em \the\dimexpr\textwidth-2em}%
{2.5em \the\dimexpr\textwidth-2.5em}%
{2.875em \the\dimexpr\textwidth-2.875em}%
{3em \the\dimexpr\textwidth-3em}%
{2.875em \the\dimexpr\textwidth-2.875em}%
{2.5em \the\dimexpr\textwidth-2.5em}%
{2em \the\dimexpr\textwidth-2em}%
{1.5em \the\dimexpr\textwidth-1.5em}%
{1em \the\dimexpr\textwidth-1em}%
{.5em \the\dimexpr\textwidth-.5em}%
{0.125em \the\dimexpr\textwidth-0.125em}%
{0em \the\dimexpr\textwidth-0em}%
{0.125em \the\dimexpr\textwidth-0.125em}%
{.5em \the\dimexpr\textwidth-.5em}%
{1em \the\dimexpr\textwidth-1em}%
}


\makeatletter

\edef\MCK@LINESPERPAGE {\the\numexpr \LINESPERPAGE\relax }

\def\MCK@LINECOUNT {0}

\def\SETUPPARSHAPE {%
  \xdef\MCK@tmpB {\the\numexpr \pagetotal/\baselineskip}%
  \ifnum\MCK@tmpA>\MCK@tmpB
  % assume we are on a new page. !!!Something more robust should be done here!!!
  \xdef\MCK@LINECOUNT
   {\the\numexpr\MCK@LINECOUNT+\MCK@tmpB-\MCK@tmpA+\MCK@LINESPERPAGE}%
  \else
  \xdef\MCK@LINECOUNT {\the\numexpr\MCK@LINECOUNT+\MCK@tmpB-\MCK@tmpA}%
  \fi
  \global\let\MCK@tmpA\MCK@tmpB   
  \edef\STARTINDEX {\the\numexpr\MCK@LINECOUNT+16-16*((\MCK@LINECOUNT+8)/16)}%
  \parshape 16 \xintListWithSep { }{\xintTrim \STARTINDEX\MOCKSINE}
               \xintListWithSep { }{\xintKeep \STARTINDEX\MOCKSINE} \relax
}

\def\STARTUNDULATIONS {\def\MCK@LINECOUNT {0}\def\MCK@tmpA {0}%
    \def\par {\oldpar \SETUPPARSHAPE }\SETUPPARSHAPE }
\def\STOPUNDULATIONS {\let\par\oldpar }
\makeatother

\let\oldpar\par
\AtBeginDocument {\STARTUNDULATIONS }

\begin{document}
\section{This is a section}
\lipsum %[\cnta-\numexpr\cnta+3\relax]


\begin{verse}
This is a verse \\
This is a verse \\
This is a verse \\
This is a verse \\
This is a verse \\
\end{verse}

\lipsum

\end{document}

渲染

用诗句来渲染

正如我所说的,除了到达环境时,形状在整个文档中都得到正确应用verse

目标

目标是强制将形状应用于包括环境在内的整个身体verse并继续下去,除非我使用\STOPUNDULATIONS命令。

那么我该如何修补代码来强制verse环境遵循形状呢?

答案1

最简单的方法是定义一个不依赖段落形状的诗句环境,这样你就不需要合并了。在这里我只是简单地定义它来添加一些垂直空间,并局部定义\\为段落的结尾。我强制在这里用点填充额外的缩进,以使起伏的边距更清晰,你不能通过省略来缩进或缩进空格\dotfill

在此处输入图片描述

\documentclass[a4paper,12pt]{article}

\def\LINESPERPAGE{45}
\usepackage[textheight=\LINESPERPAGE\baselineskip]{geometry}

\usepackage{lipsum}
\usepackage{xinttools}% requires version 1.09m or later
\renewenvironment{verse}
{\par\parindent=0pt\smallskip\everypar{\makebox[25pt]{\dotfill}}\let\\\par}
{\par\smallskip}


% let's divide by two the sizes of the undulation.
\edef\MOCKSINE {%
{1.5em \the\dimexpr\textwidth-1.5em}%
{2em \the\dimexpr\textwidth-2em}%
{2.5em \the\dimexpr\textwidth-2.5em}%
{2.875em \the\dimexpr\textwidth-2.875em}%
{3em \the\dimexpr\textwidth-3em}%
{2.875em \the\dimexpr\textwidth-2.875em}%
{2.5em \the\dimexpr\textwidth-2.5em}%
{2em \the\dimexpr\textwidth-2em}%
{1.5em \the\dimexpr\textwidth-1.5em}%
{1em \the\dimexpr\textwidth-1em}%
{.5em \the\dimexpr\textwidth-.5em}%
{0.125em \the\dimexpr\textwidth-0.125em}%
{0em \the\dimexpr\textwidth-0em}%
{0.125em \the\dimexpr\textwidth-0.125em}%
{.5em \the\dimexpr\textwidth-.5em}%
{1em \the\dimexpr\textwidth-1em}%
}


\makeatletter

\edef\MCK@LINESPERPAGE {\the\numexpr \LINESPERPAGE\relax }

\def\MCK@LINECOUNT {0}

\def\SETUPPARSHAPE {%
  \xdef\MCK@tmpB {\the\numexpr \pagetotal/\baselineskip}%
  \ifnum\MCK@tmpA>\MCK@tmpB
  % assume we are on a new page. !!!Something more robust should be done here!!!
  \xdef\MCK@LINECOUNT
   {\the\numexpr\MCK@LINECOUNT+\MCK@tmpB-\MCK@tmpA+\MCK@LINESPERPAGE}%
  \else
  \xdef\MCK@LINECOUNT {\the\numexpr\MCK@LINECOUNT+\MCK@tmpB-\MCK@tmpA}%
  \fi
  \global\let\MCK@tmpA\MCK@tmpB   
  \edef\STARTINDEX {\the\numexpr\MCK@LINECOUNT+16-16*((\MCK@LINECOUNT+8)/16)}%
  \parshape 16 \xintListWithSep { }{\xintTrim \STARTINDEX\MOCKSINE}
               \xintListWithSep { }{\xintKeep \STARTINDEX\MOCKSINE} \relax
}

\def\STARTUNDULATIONS {\def\MCK@LINECOUNT {0}\def\MCK@tmpA {0}%
    \def\par {\oldpar \SETUPPARSHAPE }\SETUPPARSHAPE }
\def\STOPUNDULATIONS {\let\par\oldpar }
\makeatother

\let\oldpar\par
\AtBeginDocument {\STARTUNDULATIONS }

\begin{document}
\section{This is a section}
\lipsum %[\cnta-\numexpr\cnta+3\relax]


\begin{verse}
This is a verse \\
This is a verse \\
This is a verse \\
This is a verse \\
This is a verse \\
\end{verse}

\lipsum

\end{document}

相关内容