LaTeX/Cài đặt các gói mở rộng

Trước: Cài đặt Mục lục Tiếp theo: Cơ bản


Các tính năng bổ sung dành cho LaTeX được gọi là các gói (package). Hàng tá trong số này được cài đặt sẵn trong LaTeX và có thể được sử dụng ngay. Tất cả các gói được lưu trữ trong các thư mục con của texmf/tex/latex và đặt tên sau mỗi gói. Ví dụ, tên thư mục "texmf" là viết tắt của “TEX and METAFONT”. Để biết những gói khác có sẵn kèm theo chức năng, bạn nên sử dụng trang Tìm kiếm CTAN bao gồm liên kết đến danh mục gói toàn diện của Graham Williams.

LaTeX

Bắt đầu
  1. Giới thiệu
  2. Cài đặt
  3. Cài đặt các gói mở rộng
  4. Cơ bản
  5. Cách nhận sự trợ giúp

Các yếu tố chung

  1. Cấu trúc Tài liệu
  2. Định dạng Văn bản
  3. Định dạng Đoạn văn
  4. Màu sắc
  5. Phông chữ
  6. Cấu trúc Danh sách
  7. Ký tự Đặc biệt
  8. Quốc tế hóa
  9. Rotations
  10. Tables
  11. Title creation
  12. Page Layout
  13. Customizing Page Headers and Footers‎
  14. Importing Graphics
  15. Floats, Figures and Captions
  16. Footnotes and Margin Notes
  17. Hyperlinks
  18. Labels and Cross-referencing
  19. Initials

Cơ chế

  1. Errors and Warnings
  2. Lengths
  3. Counters
  4. Boxes
  5. Rules and Struts

Văn bản Kỹ thuật

  1. Mathematics
  2. Advanced Mathematics
  3. Theorems
  4. Chemical Graphics
  5. Algorithms
  6. Source Code Listings
  7. Linguistics

Trang Đặc biệt

  1. Indexing
  2. Glossary
  3. Bibliography Management
  4. More Bibliographies

Tài liệu Đặc biệt

  1. Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
  2. Letters
  3. Presentations
  4. Teacher's Corner
  5. Curriculum Vitae
  6. Academic Journals (MLA, APA, etc.)

Tạo Đồ họa

  1. Introducing Procedural Graphics
  2. MetaPost
  3. Picture
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. Creating 3D graphics

Lập trình

  1. Macros
  2. Plain TeX
  3. Creating Packages
  4. Creating Package Documentation
  5. Themes

Linh tinh

  1. Modular Documents
  2. Collaborative Writing of LaTeX Documents
  3. Export To Other Formats

Trợ giúp và Đề xuất

  1. FAQ
  2. Tips and Tricks

Phụ lục

  1. Tác giả
  2. Liên kết
  3. Tham khảo Gói
  4. Tài liệu mẫu LaTeX
  5. Chỉ mục
  6. Bảng thuật ngữ lệnh

edit this boxedit the TOC



Gói là một tập tin hoặc tập hợp các tập tin chứa các lệnh LaTeX bổ sung và chương trình bổ sung các tính năng tạo phong cách mới hoặc sửa đổi các tính năng đã có. Có hai loại tập tin chính: tập tin lớp có phần mở rộng .cls và tập tin phong cách có phần mở rộng .sty. Có thể có các tập tin phụ trợ khác nữa. Khi bạn cố gắng sắp chữ một tài liệu yêu cầu một gói chưa được cài đặt trên hệ thống, LaTeX sẽ cảnh báo bằng một thông báo lỗi rằng nó bị thiếu. Bạn có thể tải xuống các bản cập nhật cho các gói đã có (cả những gói đã được cài đặt cùng với phiên bản LaTeX cũng như những gói bạn đã thêm). Không có giới hạn về số lượng gói có thể cài đặt trên máy tính (ngoài dung lượng ổ đĩa!), nhưng có giới hạn có thể định cấu hình đối với số lượng có thể được sử dụng bên trong bất kỳ tài liệu LaTeX nào cùng một lúc, mặc dù điều đó phụ thuộc vào về độ lớn của mỗi gói. Trên thực tế, không có vấn đề gì khi có vài tá gói đang hoạt động.

Đa số các bản cài đặt LaTeX đi kèm với một bộ lớn các gói phong cách được cài đặt sẵn, vì vậy bạn có thể sử dụng trình quản lý gói của bản phân phối TeX hoặc gói trên hệ thống để quản lý chúng. Xem cài đặt tự động. Nhưng nhiều hơn nữa có sẵn trên mạng. Nơi chủ yếu để tìm các gói phong cách trên Internet là [1]. Khi bạn đã xác định được gói mình cần không có trong bản phân phối, hãy sử dụng các chỉ mục trên bất kỳ máy chủ CTAN nào để tìm gói đó và thư mục nơi có thể tải xuống. Xem cài đặt thủ công.

Cài đặt tự động sửa

Nếu một hệ điều hành có trình quản lý gói hoặc cây vận chuyển (portage tree), bạn thường có thể tìm thấy các gói trong kho lưu trữ.

Với MikTeX, có một trình quản lý gói cho phép bạn chọn từng gói mong muốn. Là một tính năng tiện lợi, khi biên dịch một tập tin yêu cầu các gói chưa được cài đặt, MikTeX sẽ tự động nhắc cài đặt các gói còn thiếu.

Với TeX Live, thông thường việc phân phối được đóng gói thành một vài gói lớn. Ví dụ: để cài đặt thứ gì đó liên quan đến quốc tế hóa, bạn có thể phải cài đặt gói như texlive-lang. Với TeX Live được cài đặt thủ công, hãy sử dụng tlmgr để quản lý các gói riêng lẻ.

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

Việc sử dụng tlmgr được đề cập ở chương Cài đặt.

Nếu bạn không thể tìm thấy gói mong muốn bằng bất kỳ phương pháp nào được nêu ra trước đây, hãy xem phần cài đặt thủ công.

Hướng dẫn dành cho các hệ điều hành cụ thể sửa

Ở Ubuntu, với các bản phát hành như Trusty, bạn có thể sử dụng các gói texlive và texlive-extra, ví dụ: texlive-full, texlive-latex-extra, texlive-math-extra, texlive-plain-extra, texlive-bibtex-extra, texlive-generic-extra và các gói ngôn ngữ, tất cả đều có sẵn .com/trusty/tex/ tại đây trên trang web gói Ubuntu, cũng như tại đây để cập nhật Trusty. Bạn có thể cài đặt các gói này bằng lệnh sudo apt-get install <tên gói ở đây>.

Cài đặt bằng tay sửa

Tải các gói sửa

Hai thứ bạn cần tìm thường là một tập tin có đuôi .dtx và tập tin còn lại có đuôi .ins. Đầu tiên là tập tin DOCTeX, tập tin này kết hợp chương trình gói và tài liệu của nó trong một tập tin duy nhất. Thứ hai là thói quen cài đặt. Bạn phải luôn tải xuống cả hai tập tin. Nếu hai tập tin không có ở đó, điều đó có nghĩa là:

  • hoặc gói này là một phần của gói lớn hơn nhiều mà thông thường bạn không nên cập nhật trừ khi muốn thay đổi phiên bản LaTeX LaTeX;
  • hoặc đó là một gói cũ hơn hoặc tương đối đơn giản được viết bởi một tác giả không sử dụng tệp .dtx.

Tải xuống các tập tin gói vào một thư mục tạm thời. Thường sẽ có một readme.txt với mô tả ngắn gọn về gói. Tất nhiên, bạn nên đọc tập tin này đầu tiên.

Cài đặt một gói sửa

There are five steps to installing a LaTeX package. (These steps can also be used on the pieces of a complicated package you wrote yourself; in this case, skip straight to Step 3.)

1. Extract the files Run LaTeX on the .ins file. That is, open the file in your editor and process it as if it were a LaTeX document (which it is), or if you prefer, type latex followed by the .ins filename in a command window in your temporary directory. This will extract all the files needed from the .dtx file (which is why you must have both of them present in the temporary directory). Note down or print the names of the files created if there are a lot of them (read the log file if you want to see their names again).

2. Create the documentation Run LaTeX on the .dtx file. You might need to run it twice or more, to get the cross-references right (just like any other LaTeX document). This will create a .dvi file of documentation explaining what the package is for and how to use it. If you prefer to create PDF then run pdfLaTeX instead. If you created a .idx as well, it means that the document contains an index, too. If you want the index to be created properly, follow the steps in the indexing section. Sometimes you will see that a .glo (glossary) file has been produced. Run the following command instead:

makeindex -s gglo.ist -o name.gls name.glo

3. Install the files While the documentation is printing, move or copy the package files from your temporary directory to the right place[s] in your TeX local installation directory tree. Packages installed by hand should always be placed in your "local" directory tree, not in the directory tree containing all the pre-installed packages. This is done to a) prevent your new package accidentally overwriting files in the main TeX directories; and b) avoid your newly-installed files being overwritten when you next update your version of TeX.

For a TDS(TeX Directory Structure)-conformant system, your "local installation directory tree" is a folder and its subfolders. The outermost folder should probably be called texmf-local/ or texmf/. Its location depends on your system:

  • MacTeX: Users/username/Library/texmf/.
  • Unix-type systems: Usually ~/texmf/. If you use TexMaker on Ubuntu 18 it may be in /usr/share/texmf/
  • MikTeX: Your local directory tree can be any folder you like, as long as you then register it as a user-managed texmf directory (see http://docs.miktex.org/manual/localadditions.html#id573803)

The "right place" sometimes causes confusion, especially if your TeX installation is old or does not conform to the TeX Directory Structure(TDS). For a TDS-conformant system, the "right place" for a LaTeX .sty file is a suitably-named subdirectory of texmf/tex/latex/. "Suitably-named" means sensible and meaningful (and probably short). For a package like paralist, for example, I'd call the directory texmf/tex/latex/paralist.

Often there is just a .sty file to move, but in the case of complex packages there may be more, and they may belong in different locations. For example, new BibTeX packages or font packages will typically have several files to install. This is why it is a good idea to create a sub-directory for the package rather than dump the files into misc along with other unrelated stuff. If there are configuration or other files, read the documentation to find out if there is a special or preferred location to move them to.

Where to put files from packages
Type Directory (under texmf/ or texmf-local/) Description
.afm fonts/afm/foundry/typeface Adobe Font Metrics for Type 1 fonts
.bib bibtex/bib/bibliography BibTeX bibliography
.bst bibtex/bst/packagename BibTeX style
.cls tex/latex/base Document class file
.dvi doc package documentation
.enc fonts/enc Font encoding
.fd tex/latex/mfnfss Font Definition files for METAFONT fonts
.fd tex/latex/psnfss Font Definition files for PostScript Type 1 fonts
.map fonts/map Font mapping files
.mf fonts/source/public/typeface METAFONT outline
.pdf doc package documentation
.pfb fonts/type1/foundry/typeface PostScript Type 1 outline
.sty tex/latex/packagename Style file: the normal package content
.tex doc TeX source for package documentation
.tex tex/plain/packagename Plain TeX macro files
.tfm fonts/tfm/foundry/typeface TeX Font Metrics for METAFONT and Type 1 fonts
.ttf fonts/truetype/foundry/typeface TrueType font
.vf fonts/vf/foundry/typeface TeX virtual fonts
others tex/latex/packagename other types of file unless instructed otherwise

For most fonts on CTAN, the foundry is public.

4. Update your index Finally, run your TeX indexer program to update the package database. This program comes with every modern version of TeX and has various names depending on the LaTeX distribution you use. (Read the documentation that came with your installation to find out which it is, or consult http://www.tug.org/fonts/fontinstall.html#fndb):

  • teTeX, TeX Live, fpTeX: texhash
  • web2c: mktexlsr
  • MacTeX: MacTeX appears to do this for you.
  • MikTeX: initexmf --update-fndb (or use the GUI)
  • MiKTeX 2.7 or later versions, installed on Windows XP through Windows 7: Start -> All Programs -> MikTex -> Settings. In Windows 8 use the keyword Settings and choose the option of Settings with the MiKTex logo. In Settings menu choose the first tab and click on Refresh FNDB-button (MikTex will then check the Program Files directory and update the list of File Name DataBase). After that just verify by clicking 'OK'.

5. Update font maps If your package installed any TrueType or Type 1 fonts, you need to update the font mapping files in addition to updating the index. Your package author should have included a .map file for the fonts. The map updating program is usually some variant on updmap, depending on your distribution:

  • TeX Live and MacTeX: updmap --enable Map=mapfile.map (if you installed the files in a personal tree) or updmap-sys --enable Map=mapfile.map (if you installed the files in a system directory).
  • MikTeX: Run initexmf --edit-config-file updmap, add the line "Map mapfile.map to the file that opens, then run initexmf --mkmaps.

See http://www.tug.org/fonts/fontinstall.html.

The reason this process has not been automated widely is that there are still thousands of installations which do not conform to the TDS, such as old shared Unix systems and some Microsoft Windows systems, so there is no way for an installation program to guess where to put the files: you have to know this. There are also systems where the owner, user, or installer has chosen not to follow the recommended TDS directory structure, or is unable to do so for political or security reasons (such as a shared system where the user cannot write to a protected directory). The reason for having the texmf-local directory (called texmf.local on some systems) is to provide a place for local modifications or personal updates, especially if you are a user on a shared or managed system (Unix, Linux, VMS, Windows NT/2000/XP, etc.) where you may not have write-access to the main TeX installation directory tree. You can also have a personal texmf subdirectory in your own login directory. Your installation must be configured to look in these directories first, however, so that any updates to standard packages will be found there before the superseded copies in the main texmf tree. All modern TeX installations should do this anyway, but if not, you can edit texmf/web2c/texmf.cnf yourself.

Checking package status sửa

The universal way to check if a file is available to TeX compilers is the command-line tool kpsewhich.

$ kpsewhich tikz
/usr/local/texlive/2012/texmf-dist/tex/plain/pgf/frontendlayer/tikz.tex

kpsewhich will actually search for files only, not for packages. It returns the path to the file. For more details on a specific package use the command-line tool tlmgr (TeX Live only):

tlmgr info <package>

The tlmgr tool has lot more options. To consult the documentation:

tlmgr help

Package documentation sửa

To find out what commands a package provides (and thus how to use it), you need to read the documentation. In the texmf/doc subdirectory of your installation there should be directories full of .dvi files, one for every package installed. This location is distribution-specific, but is typically found in:

Distribution Path
MacTeX /Library/TeX/Documentation/texmf-doc/latex
MiKTeX %MIKTEX_DIR%\doc\latex
TeX Live $TEXMFDIST/doc/latex

Generally, most of the packages are in the latex subdirectory, although other packages (such as BibTeX and font packages) are found in other subdirectories in doc. The documentation directories have the same name of the package (e.g. amsmath), which generally have one or more relevant documents in a variety of formats (dvi, txt, pdf, etc.). The documents generally have the same name as the package, but there are exceptions (for example, the documentation for amsmath is found at latex/amsmath/amsdoc.dvi). If your installation procedure has not installed the documentation, the DVI files can all be downloaded from CTAN. Before using a package, you should read the documentation carefully, especially the subsection usually called "User Interface", which describes the commands the package makes available. You cannot just guess and hope it will work: you have to read it and find out.

You can usually automatically open any installed package documentation with the texdoc command:

texdoc <package-name>

Các nguồn tài nguyên bên ngoài sửa

Cách tốt nhất để tìm các gói LaTeX là sử dụng CTAN: Tìm kiếm. Một số tài nguyên bổ sung danh mục TeX trực tuyến:

Xem thêm sửa


Trước: Cài đặt Mục lục Tiếp theo: Cơ bản