Outils pour utilisateurs

Outils du site


issue215:latex

Ceci est une ancienne révision du document !


Welcome back to Full Circle and to Latex. This time, I am going to explain a few ways to install new packages to Latex on Linux. My “development” machine runs Mint 22.1, which is a Ubuntu derivative. This information is to alert you to the possibility the locations of my files on my machine may not match the locations of the same files on your machine.

In last month’s column, I reviewed the history of Tex and indicated why it was written using packages. In addition to the very limited computing resources available when it was developed, the package structure points out most people who write have specialized needs. They are primarily mathematicians or chemists or chefs or translators or whatever. Most people do not need or use all the tools available in Latex or word processors. Most use a set of the same features in almost every document. With Tex / Latex, it is easy to make a template that includes all of the required packages and then generate the same kind of document every time. For example, if you never use graphs in documents then do not fill up computer memory with software that generates graphs.

There are a few thousand packages described in the two volumes of The Latex Companion (ISBN 978-0-13-465894-0). There are many more packages available at ctan.org. You should be able to find at least one package that will help you get the result you want. First you need to know if a desired package is already installed.

I use a tool to help me find files. The command is “locate”. If I remember correctly it is not part of recent standard Linux installations. If it does not exist on your system, it is a very small bit of code, easy to install from a terminal using apt or whatever method your operating system uses. It searches a database of file names so, before you use it the first time, type “sudo updatedb”. The locate database should be updated regularly. It is a good candidate for the root cron. Once the database is built or updated you can use locate to find the package you want to use.

Another way to find out if the package you need has been installed is to search for it using tlmgr (TexLive manager). You need to know the name of the package so do a search at CTAN to find a package that fits your needs. On the command line, type tlmgr info package-name. It takes a few seconds and then generates several lines of information about the package. You could also use locate or find to do the same task.

If you have use of tlmgr, it will normally do the work necessary to install any extra package you need. It is similar to apt (or any standard system upgrading and installation program). An easy way to check if tlmgr is installed and/or usable is to run tlmgr update –list. It will go through the installed packages on your device and list all those which need to be updated. Since it checks your complete TexLive/Latex installation, this is not an instantaneous action. It takes a few seconds before you will see results. Of course if it is not installed or you do not have rights to use it, then you should see the error message quickly. The help available for tlmgr is extensive. When I imported it into OpenOffice Writer it spanned thirty-five pages.

Once you have done a couple of searches for Latex files you will see the general structure of the tex directory tree. If you record the location of the major file groups, you may decide you do not need to use locate. I use locate because it is easy for me.

On my Mint system, Latex packages tend to get installed in one of three places, either in /usr/local/texlive/2024/bin/x86_64-linux or in /usr/share/texlive/texmf-dist/tex/latex or in /usr/local/texlive/2024/texmf-dist/tex/latex. As you might guess, “2024” indicates the release year of texlive/Linux I use. On my system /usr/local/texlive/2024 is essentially the root of the tex directory tree.

What happens if you use the usepackage {name of desired package} command, and the package is not installed? That depends on what interface you use to write Latex/Tex files. If I write Latex files with a text editor then I find out about a missing package during the compile phase, when the Tex file is converted to a PDF file. If a package is missing then the Tex file will not generate a PDF file. Instead an error will be generated saying there is a missing package.

If I use TexStudio (which I usually do), then I can see immediately if a new package is required. When I type \usepackage{ TexStudio shows me a list of all the packages available on my system. Obviously if I want to use a package not on the list I must install it before the compile will be error-free. Then I use tlmgr in a terminal to install it:

tlmgr install name-of-desired-package.

Sometimes the package on ctan.org is not structured in a way that tlmgr can use. This seems to happen most frequently with old packages. That is when the locate utility I mentioned becomes useful. Most packages add one (occasionally more than one) style file (.sty) to the tex directories. Some packages add a class file (.cls) instead. Here is the process I have used to install old packages that will not install with tlmgr: • Download the package zip from ctan.org. • Unpack the zip file and read all the documentation if it exists. This will tell me two things: 1) will the package do what I need and 2) is there anything special or complicated about the installation.

There is a WikiBooks page entitled Latex_Installing_Extra_Packages from 2022 September. It says Latex packages are installed in subdirectories in texmf/tex/latex named after each package. If in doubt about where packages are installed find “texmf/tex/latex” (or texmf/tex-dist/latex) on your system.

Some old packages require the first four steps in the process listed in WikiBooks and shown below. I avoid those packages if possible. Other old packages will contain some short documentation plus either a .sty file or a .cls file. Then I follow the steps below: • I use locate to find the installed .sty / .cls files, or I look for the piece of paper that I wrote this location on. • I make a new directory in the part of the tree that has the other .sty /. cls directories. I name this new directory the name of the package. • I copy the .sty / .cls file into the new directory. • I run texhash to rebuild the Tex directory database.

The instructions from WikiBooks (2022) for installing new packages involve these steps: • Extract the files. Run Latex on the supplied ins file. (See Comments below.) • Generate the documentation. Run Latex on the .dtx file. This will make a dvi file or a pdf if you have pdfLatex installed. (See Comments below.) • Install the files to a local directory in the ~/texmf part of the tree (probably ~/texmf/tex/latex/local). Using a local directory prevents any of the new package files from writing over the standard TexLive installation. To be consistent, name the directory for the new package the same as the package. Usually there is only a ty file to move into that new directory. • Update the Latex index of files. Most Important and easy to do. Simply run the command texhash and wait for it to complete. If you forget to run texhash, Latex will not know where the new file or files are and none of them will be available to use. • If the installation involved fonts, you also need to update the font map. Fonts can be installed in the system-wide directory and/or in the local (personal) directory. There are two different ways to update the Latex font map. (The newfont.map file will be provided with the font package.)

System-wide: updmap-sys - -force - - enable Map=newfont.map

Local: I direct you to www.tug.org/fotts/fontinstall-personal.html for detailed instructions. TUG discourages users from installing fonts locally. The process is more complicated and forces the use of updmap-sys every time after updmap-user is run in order for all fonts on the device to be recognized.

Whether installed locally or system-wide, the system file name database has to be updated after fonts are installed. You can use mktexslr (or texhash) to do that. If you installed Latex as root (not recommended), then you must use sudo -H mktexlsr. Comments on the Four / Five Step process above.

The Wikibooks steps are unnecessarily complicated. Perhaps they were necessary in the past. For most packages there is a simple two-step installation process. • In a terminal tlmgr install name-of-package • texhash

If you use tlmgr update - -all the mktexslr command mentioned with fonts runs automatically once the update is finished. That is very convenient. I also run sudo texhash after the update just to be certain.

This has been sufficient for almost all the packages I have installed while writing these columns. Unlike the Wikibooks 5 Steps, I have used this two step process for font packages with no problems.

If you wish to (or need to) use the manual process instead of using tlmgr, then save yourself time and energy and read the documentation for the package. Usually packages built in the last ten years are complete with PDF documentation, and only require Step 3 and Step 4. It is unlikely you will need to do Step 1 or Step 2. It is unlikely you will need to generate any files or build a documentation file. This is generally true for all reasonably recent packages at CTAN. However, for some old packages this may be necessary. If you find a package on CTAN that requires Step 1 and Step 2, I suggest you search for a more up-to-date package that does what you need.

That is enough for this column. I hope you try to add a few new packages in the near future. Let me know if you have questions or comments. I will talk to you next time about more packages from ctan.

issue215/latex.1743256474.txt.gz · Dernière modification : 2025/03/29 14:54 de auntiee