
我需要為一個會議處理大約 100 個 tex 檔。每個文件都包含簡報的摘要,並且有一位作者。讓我們假設每個檔案的相關部分是以下 TeX 或 LaTeX 巨集(指令或環境)的參數:
TITLE
% 論文標題
AUTHOR
% 作者(給出為:LastName、FirstName)
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.
\]}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
這個最小範例的結果是以下文件: