将乳胶文档合并为单个pdf
latexpages的Python项目详细描述
这个工具自动编译乳胶文档集(对于工作文件, 使用pdfpages包将过程等)转换为单个组合的pdf文件。
创建一个ini文件给出集合和生成的名称和部分 它使用latexpages命令行实用程序。
latexpages将为每个核心启动一个并行排版过程 加速。
由于每个部分都是独立排版的,因此可以合并 无法合并到单个主控文档中(使用不兼容的 包装/选件、Latex-DVIPS-PS2PDF与PDFlatex等)。
链接
安装
这个包在python 2.7和3.5+下运行,使用pip安装:
$ pip install latexpages
编译需要tex分布(例如TeX Live或MikTeX),并且 系统上提供了latexmk或miktex的texify实用程序。
可选的自动页码(见下文)要求 pdfinfo命令行实用程序(包含在poppler-utils中, miktex-poppler-bin、xpdf)或pdftk命令行实用程序(两者 可跨平台使用)
用法
创建一个工作目录,保存带有最新expages的纯文本ini文件 配置。将所有文档放入与 相应的.tex文件:
collection/ latexpages.ini article1/ article1.tex references.bib article2/ article2.tex ...
注意:目录名不能包含空格
编辑ini文件以配置部件、它们的顺序和各种其他 选项:
[make]name=MY_COLLdirectory=_output[parts]mainmatter= article1 article2
下面将对所有部分进行排版,将它们的PDF复制到输出目录, 把它们合并成一个pdf文件。默认情况下,这也会创建一个2-up 版本:
$ latexpages latexpages.ini
检查源发行版中的example directory是否有工作 完整的例子。
调用
检查latexpages命令的用法:
$ latexpages --help usage: latexpages [-h][--version][-c {latexmk,texify}][--keep][--only <part>][--processes <n>][filename] Compiles and combines LaTeX docs into a single PDF file positional arguments: filename INI file configuring the parts and output options (default: latexpages.ini in the current directory) optional arguments: -h, --help show this help message and exit --version show program's version number and exit -c {latexmk,texify} use latexmk.pl or texify (default: guess from platform) --keep keep combination document(s) and their auxiliary files --only <part> compile the given part without combining --processes <n> number of parallel processes (default: one per core)
分页
下面的命令遍历所有主文档,更新页面 源的第一行\setcounter{page}{<number>}中的数字。 根据前面文档编译的PDF的页数。
$ latexpages-paginate latexpages.ini
确保pdfinfo命令行工具(poppler/xpdf)或 pdftk来自pdftk的可执行文件位于系统路径上。
要使用不同的模式查找\setcounter行,请设置 ^在ini文件的paginate部分中的{tt10}$选项 regular expression。
[paginate]update=\\setcounter\{page\}\{(\d+)\}
要同时更新目录中的页码,请将 在ini文件的paginate部分中对应的部件名。
目录结构:
collection/ latexpages.ini prelims/ prelims.tex article1/ article1.tex ...
配置:
[parts]frontmatter= prelimsmainmatter= article1 article2[paginate]contents=prelims
默认情况下,latexpages-paginate将搜索并更新 \startpage{<number>}行。要将其用作标记,请定义并 在目录中使用相应的latex命令,例如。 \newcommand{\startpage}[1]{#1}。一个完整的例子在example directory
要使用不同的模式查找目录行,请更改 replace选项中的regular expression
[paginate]replace=\\startpage\{(\d+)\}
检查latexpages-paginate命令的用法:
$ latexpages-paginate --help usage: latexpages-paginate [-h][--version][filename] Computes and updates start page numbers in compiled parts and contents positional arguments: filename INI file configuring the parts and paginate options (default: latexpages.ini in the current directory) optional arguments: -h, --help show this help message and exit --version show program's version number and exit
高级选项
下面是带注释的ini文件部分,其中显示了默认选项 可用的配置设置。
make部分为 结果:
[make]name=COLL # name of the resulting PDF filedirectory=_output # directory to copy/put the resultstwo_up=__%(name)s_2up # name of the 2-up version PDF filemake_two_up=true # create a 2-up version (yes/no)# templates for the name of the copied part PDF files for each# of the three possible groups (frontmatter, mainmatter, extras)# available substitutions:# (note that the percent-sign must be doubled here)# %%(name)s name of the result file (see above)# %%(part)s name of the part directory/filename# %%(index0)d zero-based index inside group# %%(index1)d one-based index inside groupfrontmatter=_%%(name)s_%%(part)smainmatter=%%(name)s_%%(index1)02d_%%(part)sextras=%(frontmatter)s
parts节给出了空格分隔的要编译的部件列表 和/或包括:
[parts]frontmatter=# include at the beginning, roman page numberingmainmatter=# include after frontmatter, arabic page numberingextras=# compile and copy only (e.g. a separate cover page)use_dvips=# use latex -> dvips -> ps2pdf for these parts # instead of pdflatex (e.g. pstricks usage)# pull the first mainmatter part into the roman page numbering areafirst_to_front=false
substitute部分填充用于创建 组合文档。对于默认模板,这允许设置pdf 元数据:
[substitute]# options for \usepackage{hyperref}author=# pdfauthortitle=# pdftitlesubject=# pdfsubjectkeywords=# pdfkeywords
template部分允许自定义组合的详细信息 文档:
[template]filename=# use a custom templatefilename_two_up=# different template for 2-up versionclass=scrartcl # use this documentclass# documentclass options for combination and 2-up versionoptions=paper=a5options_two_up=paper=a4,landscape# includepdfmerge options for combination and 2-up versioninclude=fitpaperinclude_two_up=nup=2x1,openright
compile部分允许更改 使用的编译命令。
[compile]latexmk=-silent # less verbosetexify=--batch --verbose --quiet # halt on error, less verbose# only used with texify (latexmk calls these automatically)dvips=-qps2pdf=
最后,paginate部分控制latexpages-paginate(见上文)。
[paginate]update=\\setcounter\{page\}\{(\d+)\} # search/update regexcontents=# part with table of contentsreplace=\\startpage\{(\d+)\} # toc line search/update regex
另请参见
许可证
latexpages分布在MIT license下。