我想编写一本科学会议摘要集。我预计会收到大约 650 篇文章。假设所有文章都属于同一文档类别,并且都具有以下结构(可以随意更改其结构):
\documentclass{article}
\usepackage{lipsum}% just for this example
\newcommand{\university}[1]{\\ \itshape #1}
\title{Title of the first article}
\author{Author 1 \university{Foo University}}
\date{}
\begin{document}
\maketitle
\begin{abstract}
\lipsum[1]
\end{abstract}
\section{Introduction}
Here goes some text ...
\end{document}
我想提取文章的标题、作者、大学和摘要,并将它们分别放在我的“摘要集”的同一页面上,如下所示:
由于文章数量众多,我想自动地做这个。是否有一个包或者模板可以做到这一点?
请记住,我已经仔细搜索过该网站,但没有找到自动化的方法。
编辑
请假设“征文”将在下个月进行,因此如果它有助于找到更好的解决方案,我们仍然可以更改上面的源代码。
答案1
这只是 wipet 在批处理模式下提出的解决方案。您只需将此 .bat 放在文章的同一目录中并运行它(单击两次),您将获得包含 651 个 .tex 文件的 abstract.tex 和 abstract.pdf 测试
@echo off
set path=C:/texlive/2014/bin/win32;%path%
(
echo \documentclass{article}
echo \usepackage{lipsum}
echo \newcommand{\university}[1]{\cr \itshape #1}
echo.
echo \def\onlyabstracts{%
echo \long\def\documentclass##1##2\title##3##4\begin##5{\title{##3}##4}
echo \def\title##1{\vskip5ex{\centering\LARGE##1\par}}
echo \let\author=\authorX \let\and=\andX
echo \def\date##1{}
echo \let\maketitle=\relax
echo \let\abstractX=\abstract
echo \def\abstract{\abstractX \aftergroup\endinput}
echo }
echo \def\authorX#1{\medskip{\leftskip=0pt plus1fill \rightskip=\leftskip \lineskip=8pt
echo \noindent\andA#1\crcr\egroup\egroup\par}}
echo \def\andA{\vtop\bgroup\baselineskip=14pt\halign\bgroup\hfil\large##\unskip\hfil\cr}
echo \def\andX{\crcr\egroup\egroup\hskip3em plus1em\andA}
echo.
echo \begin{document}
echo \onlyabstracts
) > abstract.tet
for %%a in (*.tex) do echo \input %%a >> abstract.tet
echo \end{document} >> abstract.tet
ren abstract.tet abstract.tex
pdflatex abstract.tex
for %%a in (*.tet, *.aux, *.log, *.lof, *.lot, *.toc, *.idx, *.ilg, *.ind, *sync*, *.out, *.bbl, *.blg, *.thm) do del %%a
答案2
您可以尝试以下操作:
\documentclass{article}
\usepackage{lipsum}% just for this example
\newcommand{\university}[1]{\cr \itshape #1}
\def\onlyabstracts{%
\long\def\documentclass##1##2\title##3##4\begin##5{\title{##3}##4}
\def\title##1{\vskip5ex{\centering\LARGE##1\par}}
\let\author=\authorX \let\and=\andX
\def\date##1{}
\let\maketitle=\relax
\let\abstractX=\abstract
\def\abstract{\abstractX \aftergroup\endinput}
}
\def\authorX#1{\medskip{\leftskip=0pt plus1fill \rightskip=\leftskip \lineskip=8pt
\noindent\andA#1\crcr\egroup\egroup\par}}
\def\andA{\vtop\bgroup\baselineskip=14pt\halign\bgroup\hfil\large##\unskip\hfil\cr}
\def\andX{\crcr\egroup\egroup\hskip3em plus1em\andA}
\begin{document}
\onlyabstracts
\input article1
\input article2
\input article3
...
\input article169
\end{document}
如果你不想写 169 次,\input article<number>
你可以使用\loop
。例如:
\newcount\tmpnum
\loop \advance\tmpnum by1 \input article\the\tmpnum\relax \ifnum\tmpnum<169 \repeat
答案3
我写了一个简短的pythontex
解决方案:
\documentclass{article}
\usepackage{lipsum}
\usepackage{pythontex}
\newcommand{\university}[1]{{\centering\itshape\large #1\par}\vskip5ex}
\newcommand{\abstitle}[1]{{\centering\LARGE #1\par}\vskip3ex}
\newcommand{\absauthor}[1]{{\centering\large #1\par}}
\newcommand{\absname}{{\centering\bfseries\abstractname\par}\vskip1ex}
\begin{document}
\begin{pycode}
from __future__ import print_function
import os
os.chdir("..") #delete this for standalone script
content = open("content.tex", "w+")
path = os.getcwd() + "/abstracts" #directory for abstract tex files
for file in os.listdir(path):
if file.endswith(".tex"):
with open(path + "/" + file) as input_data:
for line in input_data:
if "\\title{" in line:
line = line.replace("\\title{","\\abstitle{")
print(line, file=content)
if "\\author{" in line:
line = line.replace("\\author{","\\absauthor{")
print(line, file=content)
if "\\university{" in line:
print(line, file=content)
print("\\absname\n", file=content)
if line.strip() == "\\begin{abstract}":
break
for line in input_data:
if line.strip() == "\\end{abstract}":
break
print(line, file=content)
#additional stuff after abstract content
\end{pycode}
\IfFileExists{content.tex}{
\input{content.tex}
}{Test}
\end{document}
将所有 .tex 文件放在文件夹中abstracts
(或简单地更改路径)并运行:
pdflatex filename.tex
pythontex filename.tex
pdflatex filename.tex
您确实必须注意缩进。以下命令不能嵌套:
\title{...}
\author{...}
\university{...}
否则,它们会出现两次。
您可以自定义 LaTeX 中的所有内容,或者使用 python 打印功能添加一些其他内容。
答案4
我的解决方案是使用pdfpages
包。
主要思想是:
.tex
1)按方案创建单独的摘要pdf
(没有页眉和页脚摘要TeX
代码应该将文章信息(标题、作者或其他)写入.dat
。有关详细信息,请这里
2)创建.tex
-合并,将摘要集中到摘要包中pdfpages
,为页面添加页眉和页脚pdf
,并创建目录(使用之前创建的.dat
-file)。有关更多详细信息,请查看这里。
插入pdf页面的代码:
%------------Macro for insertinf PDF---------------------
\newcommand\papertitle{}% initialize
\newcommand\paperauthors{}% initialize
\newcommand{\thispapertitle}[1]{\renewcommand\papertitle{#1}}
\newcommand{\insertpaper}[1]%
{% #1 is the file name (without extension)
\clearpage
\renewcommand\papertitle{}% reinitialize
\renewcommand\paperauthors{}% reinitialize
\input{#1.dat}%
\phantomsection
\addcontentsline{toc}{chapter}{\papertitle}
\chapterprecistoc{\paperauthors}
\includepdf[pages=-, link, pagecommand={\pagestyle{plain}}]{#1.pdf}%
}
\makeatletter
\newcommand{\thispaperauthor}[2]{%
\g@addto@macro\paperauthors{#1}%
\ifx#2\finishauthors
% no more authors
\else
\g@addto@macro\paperauthors{, }%
\expandafter\thispaperauthor % reinsert the swallowed token
\fi
}
\makeatother
\def\InsertNumArticles#1#2{%
\edef\fold{#2}
\newcount\i
\i1
\newcount\f
\f#1
\advance\f by1
\loop \ifnum\i<\the\f \insertpaper{\fold/paper\the\i/paper\the\i} \advance\i by1 \repeat
}
在-combine中使用此宏.tex
:
\part*{Name of section 1}
\InsertNumArticles{2}{1Plenar}
% here `2` -- is a number of the abstracts
% `1Plenar` -- folder, which is contain `pdf` and `dat` files, source of abstract `.tex`, `.aux` and so on.
\part{Name of section 2}
\InsertNumArticles{3}{Astrophysics}
\part{Name of section 3}
\InsertNumArticles{3}{Geo science}