为什么 latex、pdflatex 和 pdftex 二进制文件相同?

为什么 latex、pdflatex 和 pdftex 二进制文件相同?

如果这个问题有点离题,我很抱歉,但我认为这是找到答案的最佳地方。这有点奇怪,让我困惑了好几年。当我运行时,latex -v我得到:

pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014)
kpathsea version 6.2.0
Copyright 2014 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.6.10; using libpng 1.6.10
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with xpdf version 3.03

这与我运行 时看到的内容相同pdflatex -v。深入研究后,我发现:

 ls -l /usr/local/texlive/2014/bin/x86_64-linux/latex
lrwxrwxrwx 1 root root 6 Aug 15  2009 /usr/local/texlive/2014/bin/x86_64-linux/latex -> pdftex*

 ls -l /usr/local/texlive/2014/bin/x86_64-linux/pdflatex
lrwxrwxrwx 1 root root 6 Aug 15  2009 /usr/local/texlive/2014/bin/x86_64-linux/pdflatex -> pdftex*

因此看起来latexpdflatex实际上是一样的。但显然它们不一样。 latex生成 dvi 文件和pdflatexpdf 文件,正如它们应该的那样。这个问题之前被提出来作为“如何”问题: 为什么 latex 和 pdflatex 都是指向同一个可执行文件(pdftex)的符号链接,但行为却不一样?答案是argv[0]

但为什么呢?为什么这些程序都打包在同一个二进制文件中,并且使用相同的版本数据?我想我没有在其他地方遇到过这种方法——它看起来太老套了。为什么不维护单独的可执行文件,而是使用 argv switch-case 来维护单个可执行文件呢?

答案1

这与询问为什么两个 Java 可执行文件使用相同的 Java 运行时没什么不同。纯 tex 和 latex 都需要 tex 引擎来执行代码,它们在加载的格式文件(即定义的内存转储)方面有所不同。通常,这是通过命令行参数tex &plainv指定tex &latex的,但为了方便起见,web2c 实现可以使用程序名称来默认格式。同样,可以在命令行上指定输出格式(dvi 或 pdf)(或在文件中使用 tex 语法),但可以使用程序名称来默认它。

请注意,它实际上不是将两个不同的可执行文件打包成一个,它只是默认命令行参数,例如

pdflatex '\pdfoutput=0 \input' file

或者

pdflatex --output-format=dvi file

使用命令行参数通过 pdflatex 生成 dvi 文件。

行为与

latex file

--output-format如果命令名称是,则会获取不同的默认值latex

相关内容