我创建了一个懒惰逐项列出命令。部分原因在于我这样做只是为了好玩:看看我是否可以创建一个命令来执行我想要它做的事情。部分原因在于尝试更好地理解它如何\par
运作\everypar
。
背后的基本思想懒惰逐项列出命令的要点是,每一项都是一个段落:换句话说,懒惰列表实际上根本不是一个列表,而是一个特殊格式的段落。
以下是我似乎可以单独运行的代码:
\documentclass{article}
\usepackage{lipsum}
%% definig the *lazy list*: which really isn't a list at all!
\usepackage{pgfkeys}
\makeatletter
%% a macro to set parameters for the *lazy list*
\newcommand\aelistset[1]{\pgfkeys{/ae/list/setter/.cd,#1}}
%% key interface for setting *lazy list* parameters
\pgfkeys{/ae/list/setter/.cd,
item mark/.code=\def\ae@item@mark{#1},
item sep/.code=\setlength\ae@lazylist@sep{#1},
left margin/.code={\setlength\ae@lazylist@lm{#1}},
right margin/.code={\setlength\ae@lazylist@rm{#1}},
margins/.code={\setlength\ae@lazylist@lm{#1}%%
\setlength\ae@lazylist@rm{#1}},%%
}
%% *lazy list* parameters
\newlength\ae@lazylist@sep
\newlength\ae@lazylist@lm
\newlength\ae@lazylist@rm
\newcommand\ae@item@mark{}
%% setting default *lazy list* parameters
\aelistset{%%
item mark=$\bullet$,
item sep=1ex,
margins=2em}
%% conditional to determine whether current *lazy item*
%% is preceded by another *lazy item*
\newif\if@is@ae@lazyitem
%% *lazy item* command
\newcommand\lazyitem{%%
\if@is@ae@lazyitem
\else
\global\let\ae@old@par\par
\fi
\bgroup
\gdef\par{\if@is@ae@lazyitem\fi
\vspace{\ae@lazylist@sep}\ae@old@par\noindent
\gdef\par{\vspace{\ae@lazylist@sep}\ae@old@par
\@is@ae@lazyitemfalse
\global\let\par\ae@old@par}}%%
\par
\makebox[\ae@lazylist@lm]{\ae@item@mark}%%
\gdef\ae@parshape{%%
\parshape 2 0pt \dimexpr\columnwidth-\ae@lazylist@rm\relax
\ae@lazylist@lm \dimexpr\columnwidth-\ae@lazylist@lm-\ae@lazylist@rm\relax}%%
\global\@is@ae@lazyitemtrue
\aftergroup\ae@parshape
\egroup
}
\makeatother
\aelistset{%%
item mark=$\star$,
item sep=2ex,
margins=2em,
right margin=0pt}
\begin{document}
Hello world this is my test case for an \verb=\lazyitem=
\lipsum[3]
\lazyitem His rebus adducti et auctoritate Orgetorigis permoti
constituerunt ea quae ad proficiscendum pertinerent comparare,
iumentorum et carrorum quam maximum numerum coemere, sementes
quam maximas facere, ut in itinere copia frumenti suppeteret,
cum proximis civitatibus pacem et amicitiam confirmare.
\lazyitem Ad eas res conficiendas biennium sibi satis esse duxerunt; in
tertium annum profectionem lege confirmant. Ad eas res
conficiendas Orgetorix deligitur. Is sibi legationem ad
civitates suscipit. In eo itinere persuadet Castico,
Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis
multos annos obtinuerat et a senatu populi Romani amicus
appellatus erat, ut regnum in civitate sua occuparet, quod pater
ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui
eo tempore principatum in civitate obtinebat ac maxime plebi
acceptus erat, ut idem conaretur persuadet eique filiam suam in
matrimonium dat.
\lazyitem Perfacile factu esse illis probat conata perficere, propterea
quod ipse suae civitatis imperium obtenturus esset: non esse
dubium quin totius Galliae plurimum Helvetii possent; se suis
copiis suoque exercitu illis regna conciliaturum confirmat. Hac
oratione adducti inter se fidem et ius iurandum dant et regno
occupato per tres potentissimos ac firmissimos populos totius
Galliae sese potiri posse sperant.
\lipsum[1-2]
\lazyitem Hello there.
\end{document}
我知道这里的\bgroup
and\egroup
并没有起到什么作用,因为组内部的所有内容都是全球化的,但我的意图是潜在在此组中执行破坏性操作,我不想影响文档的其余部分。因此,尽管对于此 MWE 来说不是必需的,但我还是保留了它们。
但是如果嵌入在常规列表环境中则效果不佳:
Hello world this is my test case for an \verb=\lazyitem=
\lipsum[3]
\begin{itemize}
\item this is the first
\lazyitem His rebus adducti et auctoritate Orgetorigis permoti
constituerunt ea quae ad proficiscendum pertinerent comparare,
iumentorum et carrorum quam maximum numerum coemere, sementes
quam maximas facere, ut in itinere copia frumenti suppeteret,
cum proximis civitatibus pacem et amicitiam confirmare.
\lazyitem Ad eas res conficiendas biennium sibi satis esse duxerunt; in
tertium annum profectionem lege confirmant. Ad eas res
conficiendas Orgetorix deligitur. Is sibi legationem ad
civitates suscipit. In eo itinere persuadet Castico,
Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis
multos annos obtinuerat et a senatu populi Romani amicus
appellatus erat, ut regnum in civitate sua occuparet, quod pater
ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui
eo tempore principatum in civitate obtinebat ac maxime plebi
acceptus erat, ut idem conaretur persuadet eique filiam suam in
matrimonium dat.
\lazyitem Perfacile factu esse illis probat conata perficere, propterea
quod ipse suae civitatis imperium obtenturus esset: non esse
dubium quin totius Galliae plurimum Helvetii possent; se suis
copiis suoque exercitu illis regna conciliaturum confirmat. Hac
oratione adducti inter se fidem et ius iurandum dant et regno
occupato per tres potentissimos ac firmissimos populos totius
Galliae sese potiri posse sperant.
\item this is the second
\item this is the third
\end{itemize}
\lipsum[1-2]
\lazyitem Hello there.
这里有几件事情出了问题,但我唯一担心的是普通的(非惰性)LaTeXitemize
忘记左边距在哪里。
我尝试通过将我的嵌入到他们自己的群组中来解决这个问题lazy items
。以下是我尝试这样做的方法:
%% *lazy item* command
\newcommand\lazyitem{%%
\if@is@ae@lazyitem
\else
\global\let\ae@old@par\par
\fi
%\bgroup
\gdef\par{\if@is@ae@lazyitem\egroup\fi
\vspace{\ae@lazylist@sep}\ae@old@par\noindent\bgroup%%
\gdef\par{\vspace{\ae@lazylist@sep}\egroup\ae@old@par%%
\@is@ae@lazyitemfalse
\global\let\par\ae@old@par}}%%
\par
\makebox[\ae@lazylist@lm]{\ae@item@mark}%%
\gdef\ae@parshape{%%
\parshape 2 0pt \dimexpr\columnwidth-\ae@lazylist@rm\relax
\ae@lazylist@lm \dimexpr\columnwidth-\ae@lazylist@lm-\ae@lazylist@rm\relax}%%
\global\@is@ae@lazyitemtrue
%\aftergroup
\ae@parshape
%\egroup
}
但是使用这个定义我得到一个关于括号太多的错误。
有人能指出这是怎么发生的吗?