我需要为一个会议处理大约 100 个 tex 文件。每个文件包含一个演示文稿的摘要,并且有一个作者。我们假设每个文件的相关部分是以下 TeX 或 LaTeX 宏(命令或环境)的参数:
TITLE
% 论文标题
AUTHOR
% 作者(以姓氏、名字表示)
AFFILIATION
% 作者所属单位(包括电子邮件地址)
ABSTRACT
% 演讲摘要
REFERENCES
% 简短的参考文献列表\bibitem
我想要获得一份包含按作者姓氏排序的演示文稿摘要的文档,以及目录和包括其所属关系的参与者的排序列表。
我想到首先剥离作者提交的 tex 文件并仅留下相关信息(如上所述),但我不知道下一步该如何以“算法”方式进行(无需任何手动排序或其他“手动”方法)。
我看了类似的问题这里,但我找不到解决排序问题的方法。
答案1
与此同时,我已经部分解决了该问题,除了排序部分,并想与大家分享,期待您的宝贵意见和建议。
我选择进行“外部”排序,并将结果直接粘贴到主 tex 文件中,因为这似乎是最简单的选项。我曾考虑使用捆绑包datatool
,但使用 TeX 之外的简单文本排序只花了我几秒钟的时间。
数据是使用具有以下结构的简单文本文件从作者处收集的:
\AUTHOR{}{} %% <--- {LastName}{FirstName}
\EMAIL{}
\AFFILIATION{}
\TITLE{}
\ABSTRACT{}
主文件读取这些文件并生成摘要书的内容,如下面的最小示例(我们读取了三个文件)所示,其中宏在外部文件中定义abstractbook.sty
:
\documentclass[a4paper,12pt]{article}
\usepackage{abstractsbook}
\begin{document}
%% ++++++++++ Process submitted files ++++++++++++++++++
\begin{processfiles}
%% ---------------------------------------
\processfile{FirstAuthor}
\processfile{SecondAuthor}
\processfile{ThirdAuthor}
%% First sorted alphabetically outside TeX
\end{processfiles}
\parindent 0pt
%% +++++++++++++++++++ List of Talks ++++++++++++++++++
\listoftalks
%% +++++++++++++++++++ Abstracts ++++++++++++++++++++++
\abstracts
%% +++++++++++++++++++ Index of participants +++++++++++
\listofparticipants
%% +++++++++++++++++++++++++++++++++++++++++++++++++++++
\end{document}
该abstractbook.sty
文件定义了上述所有宏。处理文件时,从与主 tex 文件相同的文件夹中\processfile{NameOfFile}
读取内容。每个文件都会增加一个本地计数器(计数读取文件的数量),并定义以下宏:NameOfFile.tex
\processfile{...}
\author-<x>-LastName
\author-<x>-FirstName
\affiliation-<x>
\email-<x>
\title-<x>
\abstract-<x>
其中<x>
是计数器的当前值。
在排版文档时,我们只需循环计数器的所有值并显示所需的信息。
请参阅下面的一个最小示例abstractbook.sty
。我希望它(不是那么难)可读:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{abstractsbook}
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++
\RequirePackage{ifthen}
%% ----- some shortcuts ------
\let\ea=\expandafter
\let\cs=\csname
\let\ecs=\endcsname
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++
\newenvironment{processfiles}
{\newcount\numabs % <--- TeX local counter that counts
% the number of abstracts
\numabs=0\relax
\newcounter{numabs} % <--- LaTeX global counter
}
{\setcounter{numabs}{\the\numabs}
% < --- saving the final (local) value of \numabs
} % for global later use
\long\def\processfile #1{%
\advance\numabs by 1\relax
\input{#1.tex}
}%
\long\def\AUTHOR #1#2{%
\ea\long\ea\gdef\cs author-\the\numabs-LastName\ecs{#1}%
\ea\long\ea\gdef\cs author-\the\numabs-FirstName\ecs{#2}%
}
\long\def\AFFILIATION #1{%
\ea\long\ea\gdef\cs affiliation-\the\numabs\ecs{#1}
}
\long\def\EMAIL #1{%
\ea\long\ea\gdef\cs email-\the\numabs\ecs{#1}
}
%%
\long\def\TITLE #1{%
\ea\long\ea\gdef\cs title-\the\numabs\ecs{#1}
}
%%
\long\def\ABSTRACT #1{%
\ea\long\ea\gdef\cs abstract-\the\numabs\ecs{#1}
}
% ++++++++++++++ List of Talks ++++++++++++++++++++++++++++++++++++++++++++++
\def\heading #1{\cleardoublepage{\LARGE\scshape #1}\par\hrulefill\vskip 6ex}
\long\def\listoftalks
{
\heading{List of Talks}
\newcount\@i
\@i=1\relax
\whiledo{\the\@i<\numexpr \thenumabs+1\relax}
{\begin{minipage}{\textwidth}
\vskip 1.5ex
\leftskip 0em
\textsc{\cs author-\the\@i-FirstName\ecs}~\MakeUppercase{\cs author-\the\@i-LastName\ecs}
\par\leftskip 2.5em
\textit{\cs title-\the\@i\ecs}\dotfill\pageref{marker-\the\@i}
\end{minipage}
\advance \@i by 1\relax
}%
}
% ++++++++++++++ List of Participants +++++++++++++++++++++++++++++++++++++
\long\def\listofparticipants
{\heading{List of Participants}
\newcount\@i
\@i=1\relax
\whiledo{\the\@i<\numexpr \thenumabs+1\relax}
{\begin{minipage}{\textwidth}
\textbf{\MakeUppercase{\cs author-\the\@i-LastName\ecs}},~\textbf{\cs author-\the\@i-FirstName\ecs}
\vskip 1ex
\textit{\cs affiliation-\the\@i\ecs}
\vskip 0.25ex
\texttt{\cs email-\the\@i\ecs}
\end{minipage}
\vskip 4ex
\advance \@i by 1\relax
}%
}
% +++++++++++++++ Abstracts of Talks +++++++++++++++++++++++++++++++++++++++++
\long\def\abstracts
{\heading{Abstracts of Talks}
\newcount\@i
\@i=1\relax
\whiledo{\the\@i<\numexpr \thenumabs+1\relax}
{%
\begin{minipage}{\textwidth}
\label{marker-\the\@i} % <--- used for later referencing of the page
\begin{center}
\textsc{\Large \cs title-\the\@i\ecs}
\vskip 1.5ex
\textbf{\Large \cs author-\the\@i-FirstName\ecs~\cs author-\the\@i-LastName\ecs}
\vskip 1ex
\normalsize{\cs affiliation-\the\@i\ecs}
\end{center}
\vskip 2.5ex
\cs abstract-\the\@i\ecs
\end{minipage}
\vskip 8ex
\vfill
\advance \@i by 1\relax
}%
}
还请考虑以下摘要文件的最小示例:
FirstAuthor.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\AUTHOR{First}{Author}% <--- {LastName}{FirstName}
%%
\EMAIL{[email protected]}
%%
\AFFILIATION{First University}
%%
\TITLE{The first title}
%%
\ABSTRACT{This is the abstract of the first talk.
And some math: $1+1=2$.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SecondAuthor.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\AUTHOR{Second}{Author}% <--- {LastName}{FirstName}
%%
\EMAIL{[email protected]}
%%
\AFFILIATION{Second University}
%%
\TITLE{The second title}
%%
\ABSTRACT{This is the abstract of the second talk.
And some math:
\[
E=m\mathrm{c}^2.
\]}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ThirdAuthor.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\AUTHOR{Third}{Author}% <--- {LastName}{FirstName}
%%
\EMAIL{[email protected]}
%%
\AFFILIATION{Third University}
%%
\TITLE{The third title}
%%
\ABSTRACT{This is the abstract of the second talk.
And some math:
\[
\mathrm{e}^{i\pi}+1=0.
\]}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
这个最小示例的结果是以下文件: