梅威瑟:

梅威瑟:

我想通过在正文中标记文本作为摘要的一部分,在章节/节的末尾自动创建摘要节/小节。有没有可以做到这一点的软件包?

我正在尝试手动执行此操作。摘要部分/小节中的文本是从正文中的标记文本复制而来的。我使用了collect包来做到这一点(灵感来自 Gonzalo 的回答)。

到目前为止我遇到了一些问题:

  • 环境内的文本collect*放置在主文本中其自己的段落内。
  • 包的beforecol和参数通过一个标记与文本条目分开,即使我没有明确提供它。我不想这样。我希望它们是同一段的一部分,除非明确说明。aftercolcollect\par
  • \par如果我在 的末尾不提供aftercol,则其aftercol内容和begincol后续合集的内容将合并为一个。
  • 我不确定如何\includecollectionenumerate这样的环境中使用,使得每个都\begin{collect*} ... \end{collect*}成为一个\itemenumerate现在,整个集合被视为一个大的\item
  • 自动化。我想我真正想要的是能够使用类似\summary[Before text.][After text.]{Text within main text}排版的东西并收集通常在正文中插入正文,收集前后部分,并在每个章节/部分末尾生成一个摘要部分/小节,其中每个部分\summary\item在一个enumerate环境中。不过这是我最不关心的。:-)

以下是我目前所得到的。第二个摘要小节是我想要得到的。

梅威瑟:

\documentclass{article}
\usepackage{collect}
\usepackage{multicol}

%% Gonzalo's answer: https://tex.stackexchange.com/a/166978/32206

\makeatletter
\newenvironment{summary}[2]
  {\@nameuse{collect*}{thesummary}{}{}{{#1}}{{#2}}}
  {\@nameuse{endcollect*}}
\makeatother

\definecollection{thesummary} % Collect summary content here.

\begin{document}

\section{El Section}
% This part should be in the summary, with some text before.
\begin{summary}{Some text before.}{}
Far quitting dwelling graceful the likewise received building. An fact so to that show am shed sold cold.
\end{summary}
Unaffected remarkably get yet introduced excellence terminated led. Result either design saw she esteem and. On ashamed no inhabit ferrars it ye besides resolve. Own judgment directly few trifling.
% This part should be in the summary, with some text after.
\begin{summary}{}{Some text after.}
Elderly as pursuit at regular do parlors. Rank what has into fond she.
\end{summary}
%% End of paragraph 1.

% This part should be in the summary, with some text before and after.
\begin{summary}{Some text before.}{Some text after.}
Lose away off why half led have near bed. At engage simple father of period others except.
\end{summary}
My giving do summer of though narrow marked at. Spring formal no county ye waited.
%% End of paragraph 2.

% Generate summary subsection. Split into two columns and enumerate.
\subsection*{Summary}
\begin{multicols}{2}
  \begin{enumerate}
    \item \includecollection{thesummary}
  \end{enumerate}
\end{multicols}

% Ideal outcome.
\subsection*{Summary}
\begin{multicols}{2}
  \begin{enumerate}
    \item Some text before. Far quitting dwelling graceful the likewise received building. An fact so to that show am shed sold cold.
    \item Elderly as pursuit at regular do parlors. Rank what has into fond she. Some text after.
    \item Some text before. Lose away off why half led have near bed. At engage simple father of period others except. Some text after.
  \end{enumerate}
\end{multicols}

\end{document}

输出:

输出

答案1

它并不完全符合您的要求,但也许您可以根据您的需要进行调整:

\documentclass{article}
\usepackage{framed, blindtext}

%%%%%%%%%%%%%%%%
\newcommand\lorname{\mdseries\textit{List of recommendations:}}%list of recommendations
\newcommand\lorext{lor} % another aux-file is needed
\newcommand\lortmp{}
\newcounter{recommendations}
\newcommand{\Empf}[2][\empty]{%
  \textit{Recommendations
    \refstepcounter{recommendations}\therecommendations{}:}%
  \vspace{-0.75\baselineskip} \begin{framed} #2 \end{framed}%
  \ifx#1\empty\renewcommand\lortmp{\footnotesize #2 }\else\renewcommand\lortmp{\footnotesize #1}\fi%
  \addcontentsline{\lorext}{subsection}{\therecommendations\quad\lortmp}
}
\makeatletter
  \newcommand\listofrecommendations{%
    \footnotesize
    \section*{\lorname}
    \markboth{\lorname}{}
    \@starttoc{\lorext}
  }
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\section{whatever}
\label{sec:whatever}

\blindtext
\Empf{Remember this}
\blindtext
\Empf{Remember that}
\blindtext

\listofrecommendations{}

\end{document}

在此处输入图片描述

答案2

我发现,我的大多数问题都可以通过更新环境和(a)禁用和参数collect*的使用来解决;(b)删除环境末尾的标记,这意味着每个调用都放在其自己的段落内。preenvpostenv\parcollect*

我可能违反了书上的所有规则,但是现在必须这样做!

已续订collect*

%% Renew collect* environment to ignore `preenv` and `postenv`, both in
%% the file collected and in the file typeset. Also, remove final `\par`
%% so that the environment content is not necessarily in its own paragraph.
\makeatletter
\renewenvironment{collect*}[5]{%
\global\toks@{}%
\def\CE@file{#1}%
\def\CE@preenv{#2}%
\def\CE@postenv{#3}%
\def\CE@prefileenv{#4}%
\def\CE@postfileenv{#5}%
\CE@get@env@body@start%
}{%
\CE@ensure@opened{\CE@file}%
\edef\@tempa{\csname CE@@\CE@file @out\endcsname}%
\immediate\write\@tempa{\CE@meaning\CE@prefileenv}%
% \immediate\write\@tempa{\CE@meaning\CE@preenv}%
\immediate\write\@tempa{\the\toks@}%
% \immediate\write\@tempa{\CE@meaning\CE@postenv}%
\immediate\write\@tempa{\CE@meaning\CE@postfileenv}%
\immediate\openout\CE@tmp@out=\jobname.tmp%
% \immediate\write\CE@tmp@out{\CE@meaning\CE@preenv}%
\immediate\write\CE@tmp@out{\the\toks@}%
% \immediate\write\CE@tmp@out{\CE@meaning\CE@postenv}%
\immediate\closeout\CE@tmp@out%
\@input{\jobname.tmp}%
% \par%
}
\makeatother

summary环境:

然后,我们可以创建自己的环境和集合,以接受beforecolaftercol参数。感谢 Gonzalo 的出色回答

\makeatletter
\newenvironment{summary}[2]
  {\@nameuse{collect*}{thesummary}{}{}{\item #1}{#2}}
  {\@nameuse{endcollect*}}
\makeatother

\definecollection{thesummary} % Collect summary content here.

摘要enumerate

通过在beforecol参数 ( #1)前面加上\item,收集的数据适合在\enumerate\itemize环境中使用,如下所示:

  \begin{enumerate}
    \includecollection{thesummary}
  \end{enumerate}

输出:

输出

解决方案:

\documentclass[a4paper,10pt]{article}
\usepackage{multicol}
\usepackage[draft]{graphicx}
\usepackage[colorlinks,linkcolor={blue}]{hyperref}
\usepackage[nameinlink,capitalise,noabbrev]{cleveref}

\usepackage{collect}

%% Renew collect* environment to ignore `preenv` and `postenv`, both in
%% the file collected and in the file typeset. Also, remove final `\par`
%% so that the environment content is not necessarily in its own paragraph.
\makeatletter
\renewenvironment{collect*}[5]{%
\global\toks@{}%
\def\CE@file{#1}%
\def\CE@preenv{#2}%
\def\CE@postenv{#3}%
\def\CE@prefileenv{#4}%
\def\CE@postfileenv{#5}%
\CE@get@env@body@start%
}{%
\CE@ensure@opened{\CE@file}%
\edef\@tempa{\csname CE@@\CE@file @out\endcsname}%
\immediate\write\@tempa{\CE@meaning\CE@prefileenv}%
% \immediate\write\@tempa{\CE@meaning\CE@preenv}%
\immediate\write\@tempa{\the\toks@}%
% \immediate\write\@tempa{\CE@meaning\CE@postenv}%
\immediate\write\@tempa{\CE@meaning\CE@postfileenv}%
\immediate\openout\CE@tmp@out=\jobname.tmp%
% \immediate\write\CE@tmp@out{\CE@meaning\CE@preenv}%
\immediate\write\CE@tmp@out{\the\toks@}%
% \immediate\write\CE@tmp@out{\CE@meaning\CE@postenv}%
\immediate\closeout\CE@tmp@out%
\@input{\jobname.tmp}%
% \par%
}
\makeatother

%% Gonzalo's answer: https://tex.stackexchange.com/a/166978/32206

\makeatletter
\newenvironment{summary}[2]
  {\@nameuse{collect*}{thesummary}{}{}{\item #1}{#2}}
  {\@nameuse{endcollect*}}
\makeatother

\definecollection{thesummary} % Collect summary content here.

\begin{document}

\section{El Section}
% This part should be in the summary, with some text before.
\begin{summary}{Text before.}{}
Far away whatever it was quitting dwelling graceful the likewise received building. An fact so to that show am shed sold cold.
\end{summary}
Unaffected remarkably get yet introduced excellence terminated led. Result either design saw she esteem and. On ashamed no inhabit ferrars it ye besides resolve. Own judgment directly few trifling.
% This part should be in the summary, with some text after.
\begin{summary}{}{See \cref{fig:elfigure}.}
Elderly as pursuit at regular do parlors. Rank what has into fond she.
\end{summary}

\begin{figure}
\centering
\includegraphics[width=0.3\textwidth]{./figure.pdf}
\caption{El caption}
\label{fig:elfigure}
\end{figure}

% This part should be in the summary, with some text before and after.
\begin{summary}{Text before.}{Text after.}
Lose away off why half led have near bed. At engage simple father of period others except.
\end{summary}
My giving do summer of though narrow marked at. Spring formal no county ye waited.

% Generate summary subsection. Split into two columns and enumerate.
\subsection*{Summary}
Actual outcome:
\begin{multicols}{2}
  \begin{enumerate}
    \includecollection{thesummary}
  \end{enumerate}
\end{multicols}

\subsection*{Summary}
Ideal outcome:
\begin{multicols}{2}
  \begin{enumerate}
    \item Text before. Far away whatever it was quitting dwelling graceful the likewise received building. An fact so to that show am shed sold cold.
    \item Elderly as pursuit at regular do parlors. Rank what has into fond she. See \cref{fig:elfigure}.
    \item Text before. Lose away off why half led have near bed. At engage simple father of period others except. Text after.
  \end{enumerate}
\end{multicols}

\end{document}

相关内容