如何为Tex Live安装LaTeX包?

显然我正在使用Tex Live作为我的LaTeX发行版。
martin@martin-XPS-8300:~$ pdflatex -v

pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian) kpathsea version
6.1.0 Copyright 2012 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.2.49; using libpng 1.2.49 Compiled with zlib 1.2.7;
using zlib 1.2.7 Compiled with poppler version 0.20.5

我想使用这个指南来安装额外的软件包。
他们说:

如果手动安装了TeX Live,可以使用tlmgr来单独管理软件包。

tlmgr install <package1> <package2> ... 
tlmgr remove <package1> <package2> ...

但是当我尝试的时候:
tlmgr install algorithm2e

我明白。
tlmgr: command not found

我似乎也没有一个`~/texmf`文件夹,只有一个`~/.texmf-var`文件夹。是我的安装损坏了还是我做错了什么?
/usr/local/share/texmf

编辑2:

指令:

apt-cache policy texlive

结果为:

texlive:
  Installed: 2012.20120611-5
  Candidate: 2012.20120611-5
  Version table:
 *** 2012.20120611-5 0
        500 http://jp.archive.ubuntu.com/ubuntu/ raring/main amd64 Packages
        100 /var/lib/dpkg/status

文件夹。

你是怎么安装Tex Live的? - Braiam
很抱歉,但我真的不记得了。我想可能是通过命令行或者是预装好的。我没有使用软件包管理工具。 - Martin Drozdik
apt-cache policy texlive的输出是什么? - Braiam
1如果你把我提供链接的软件包放在 /usr/local/share/texmf 目录下,应该也能行。然后运行 sudo texhash 命令。 - Minos
@MartinSchröder 谢谢!就是这样。我把文件放到 ~/texmf/tex/latex/commonstuff 目录下,它就可以工作了。甚至不需要运行 texhash - Martin Drozdik
我推荐这个答案如何在Linux系统上安装单个软件包?,其中第一个答案有很好的描述。 - user706142
4个回答

如果您从Ubuntu软件中心安装TeXLive,则不会安装tlmgr,因为所有的包都应该使用系统的包管理工具'apt-get'。因此您会收到以下错误信息:
tlmgr: command not found

所以你需要手动安装这个软件包:

在这里下载algorithm2e.sty

然后,进入文件夹~/texmf或者~/.texmf,如果不存在就创建它:

mkdir ~/texmf

将algorithm2e.sty复制到该文件夹中。然后运行:
sudo texhash

在需要时输入根密码。

不幸的是,Ubuntu中的TexLive软件包更新频率不高,因此可能会出现一些错误。

另一种选择是手动安装整个TexLive发行版,并按照您发布的指南进行操作。

希望能有所帮助。


谢谢!我尝试过将它放入/usr/local/share/texmf,还创建了自己的texmf文件夹并运行了texhash命令,但都没有成功。但是当我直接将algorithm2e.sty文件包含在与我正在编译的.tex文件相同的文件夹中时,它就可以工作了。 - Martin Drozdik
2规范答案是http://tex.stackexchange.com/questions/1137/where-do-i-place-my-own-sty-files-to-make-them-available-to-all-my-tex-files - Martin Schröder
你能试试把它放在/usr/local/texlive/texmf-local目录下吗?如果可以的话,我会更新我的回答。 - Minos

TeXLive被分为“集合”。每个TeXLive包属于一个(且仅属于一个)集合,例如包algorithm2e属于集合science。为了简化起见,大多数发行版(包括Ubuntu)没有针对每个单独的TeXLive包提供软件包,而是将所有TeXLive包组合在一起,并将整个集合作为单个软件包进行分发。
在Ubuntu中,TeXLive集合foo被分发为Ubuntu软件包texlive-foo,因此例如集合science被分发为Ubuntu软件包texlive-science。因此,关于如何安装TeXLive包algorithm2e的问题,Ubuntu的答案是您需要安装Ubuntu软件包texlive-science。(当然,副作用是它还会安装science集合中的所有其他软件包。)
确定TeXLive包属于哪个集合的标准方法是使用tlmgr
$ tlmgr info algorithm2e
package:     algorithm2e
category:    Package
shortdesc:   Floating algorithm environment with algorithmic keywords.
longdesc:    Algorithm2e is an environment for writing algorithms. An algorithm becomes a floating object (like figure, table, etc.). The package provides macros that allow you to create different keywords, and a set of predefined key words is provided; you can change the typography of the keywords. The package allows vertical lines delimiting a block of instructions in an algorithm, and defines different sorts of algorithms such as Procedure or Function; the name of these functions may be reused in the text or in other algorithms.
installed:   Yes
revision:    28749
sizes:       doc: 661k, run: 137k
relocatable: Yes
cat-version: 5.0
cat-date:    2013-01-06 21:16:44 +0100
cat-license: lppl
collection:  collection-science

但在Ubuntu中,没有安装tlmgr。我喜欢使用apt-file
$ apt-file search algorithm2e.sty
texlive-science: /usr/share/texlive/texmf-dist/tex/latex/algorithm2e/algorithm2e.sty

或者您可以在http://packages.ubuntu.com/的“搜索软件包内容”部分进行搜索。

去Ubuntu软件中心,安装TeX Live软件:附加字体。

1这个指向软件中心是正确的(至少对于某些软件包来说)- 但问题是关于任何软件包,而不仅仅是字体。 - guntbert

我找到的最简单的方法是,在Ubuntu软件中心搜索包。例如,我需要的包是“braket”,我只需在软件中心中输入它,搜索结果会显示“TeX Live: LaTeX additional packages”,其中包含“braket”包以及一堆其他包,我安装了它,现在很满意。
或者:
要充分利用Texlive,最好的方法是按照以下说明安装Telxlive原版。

https://tex.stackexchange.com/a/95373/63118

这可能会解决与包裹和其他一切有关的所有问题。