This manual documents how to install and use the Kpathsea library for filename lookup. It corresponds to version 6.1.0, released in May 2012.
This manual corresponds to version 6.1.0 of the Kpathsea library, released in May 2012.
The library's fundamental purpose is to return a filename from a list of directories specified by the user, similar to what shells do when looking up program names to execute.
The following software, all of which we maintain, uses this library:
Other software that we do not maintain also uses it.
We are still actively maintaining the library (and probably always will be, despite our hopes). If you have comments or suggestions, please send them to us (see Reporting bugs).
We distribute the library under the GNU Library General Public License (LGPL). In short, this means if you write a program using the library, you must (offer to) distribute the source to the library, along with any changes you have made, and allow anyone to modify the library source and distribute their modifications. It does not mean you have to distribute the source to your program, although we hope you will. See the accompanying files for the text of the GNU licenses.
If you know enough about TeX to be reading this manual, then you (or your institution) should consider joining the TeX Users Group (if you're already a member, thanks!). TUG produces the periodical TUGboat, sponsors an annual meeting and publishes the proceedings, and arranges courses on TeX for all levels of users throughout the world. See http://tug.org for information.
(This section is for those people who are curious about how the library came about.) (If you like to read historical accounts of software, we urge you to seek out the GNU Autoconf manual and the “Errors of TeX” paper by Don Knuth, published in Software—Practice and Experience 19(7), July 1989.)
[Karl writes.] My first ChangeLog entry for Web2c seems to be February
1990, but I may have done some work before then. In any case, Tim
Morgan and I were jointly maintaining it for a time. (I should mention
here that Tim had made Web2c into a real distribution long before I had
ever used it or even heard of it, and Tom Rokicki did the original
implementation. I was using pxp
and pc
on VAX 11/750's
and the hot new Sun 2 machines.)
It must have been later in 1990 and 1991 that I started working on TeX for the Impatient. Dvips, Xdvi, Web2c, and the GNU fontutils (which I was also writing at the time) all used different environment variables, and, more importantly, had different bugs in their path searching. This became extremely painful, as I was stressing everything to the limit working on the book. I also desperately wanted to implement subdirectory searching, since I couldn't stand putting everything in one big directory, and also couldn't stand having to explicitly specify cm, pandora, ... in a path.
In the first incarnation, I just hacked separately on each program—that was the original subdirectory searching code in both Xdvi and Dvips, though I think Paul Vojta has completely rewritten Xdvi's support by now. That is, I tried to go with the flow in each program, rather than changing the program's calling sequences to conform to common routines.
Then, as bugs inevitably appeared, I found I was fixing the same thing three times (Web2c and fontutils were always sharing code, since I maintained those—there was no Dvipsk or Xdvik or Dviljk at this point). After a while, I finally started sharing source files. They weren't yet a library, though. I just kept things up to date with shell scripts. (I was developing on a 386 running ISC 2.2 at the time, and so didn't have symbolic links. An awful experience.)
The ChangeLogs for Xdvik and Dvipsk record initial releases of those distributions in May and June 1992. I think it was because I was tired of the different configuration strategies of each program, not so much because of the path searching. (Autoconf was being developed by David MacKenzie and others, and I was adapting it to TeX and friends.)
I started to make a separate library that other programs could link with on my birthday in April 1993, according to the ChangeLog. I don't remember exactly why I finally took the time to make it a separate library; a conversation with david zuhn that initiated it. Just seemed like it was time.
Dviljk got started in March 1994 after I bought a Laserjet 4. (Kpathsea work got suspended while Norm Walsh and I, with Gustaf Neumann's help, implemented a way for TeX to get at all those neat builtin LJ4 fonts ... such a treat to have something to typeset in besides Palatino!)
By spring of 1995, I had implemented just about all the path-searching features in Kpathsea that I plan to, driven beyond my initial goals by Thomas Esser and others. I then started to integrate Web2c with Kpathsea. After the release of a stable Web2c, I hope to be able to stop development, and turn most of my attention back to making fonts for GNU. (Always assuming Micros**t hasn't completely obliterated Unix by then, or that software patents haven't stopped software development by anybody smaller than a company with a million-dollar-a-year legal budget. Which is actually what I think is likely to happen, but that's another story...)
[Olaf writes.] At the end of 1997, UNIX is still alive and kicking, individuals still develop software, and Web2c development still continues. Karl had been looking for some time for someone to take up part of the burden, and I volunteered.
(A copy of this chapter is in the distribution file kpathsea/INSTALL.)
The procedure for Kpathsea (and Web2c, etc.) configuration and installation follows. If you encounter trouble, see Common problems, a copy of which is in the file kpathsea/BUGS.
Installing TeX and friends for the first time can be a daunting experience. Thus, you may prefer to skip this whole thing and just get precompiled executables: see unixtex.ftp.
This section explains what to do if you wish to take the defaults for everything, and generally to install in the simplest possible way. Most steps here refer to corresponding subsection in the next section which explains how to override defaults and generally gives more details.
By default everything will be installed under /usr/local and the following discussion assumes this. However, if you already have TeX installed, its location is used to derive the directory under which everything is to be installed.
These archives are mirrored on the CTAN hosts, in the systems/web2c directory.
0 0 * * * cd /usr/local/share/texmf && /bindir/mktexlsr
mktexpk
(and added to the filename database).
This will take some time. Don't be alarmed; they will created only this
first time (unless something is wrong with your path definitions).
By default, mktexpk
will create these fonts in a hierarchy
under /var/tmp/texfonts; it simply assumes that /var/tmp
exists and is globally writable. If you need a different arrangement,
see mktex configuration.
See mktex scripts.
Most sites need to modify the default installation procedure in some
way, perhaps merely changing the prefix from ‘/usr/local’, perhaps
adding extra compiler or loader options to work around configure
bugs. This section explains how to override default choices. For
additional distribution-specific information:
These instructions are for Unix systems. Other operating-system specific distributions have their own instructions. The code base itself supports Amiga, DOS, OS/2, and VMS.
Following are the same steps as in the previous section (which describes the simplest installation), but with much more detail.
Here is a table showing the disk space needed for each distribution (described in the next section). The `(totals)' line reflects the ‘texk’ source distribution and ‘texklib’; the individual distributions don't enter into it. Sizes are in megabytes. All numbers are approximate.
Distribution | .tar.gz | Unpacked | Compiled | Installed
|
dviljk | .9 | 3.8 |
| |
dvipsk | .9 | 3.2 |
| |
xdvik | .7 | 2.5 |
| |
web2c | 1.3 | 5.0 |
| |
web | 1.9 | 6.5 | - | -
|
texk | 7.5 | 32.1 | 95.3 | 33.5
|
texklib | 6.3 | 15.0 | - | 15.0
|
(totals) | 14.6 | 47.1 | 95.3 | 48.5
|
The archive ftp://ftp.tug.org/tex/texk.tar.gz contains all of the Kpathsea applications I maintain, and the library itself. For example, since NeXT does not generally support X11, you'd probably want to skip ‘xdvik’ (or simply remove it after unpacking texk.tar.gz. If you are not interested in all of them, you can also retrieve them separately:
If you want to use the Babel LaTeX package for support of non-English typesetting, you may need to retrieve additional files. See the file install.txt in the Babel distribution.
If the search paths for your installation differ from the standard
TeX directory structure (see Introduction), edit the file kpathsea/texmf.in
as desired, before running configure
. For example, if you have
all your fonts or macros in one big directory.
You may also wish to edit the file mktex.cnf, either before or
after installation, to control various aspects of mktexpk
and
friends. See mktex configuration.
You do not need to edit texmf.in to change the default
top-level or other installation directories (only the paths).
You can and should do that when you run configure
(next step).
You also do not need to edit texmf.in if you are willing to rely on texmf.cnf at runtime to define the paths, and let the compile-time default paths be incorrect. Usually there is no harm in doing this.
The section below explains default generation in more detail.
The purpose of having all the different files described in the section
above is to avoid having the same information in more than one place. If
you change the installation directories or top-level prefix at
configure
-time, those changes will propagate through the whole
sequence. And if you change the default paths in texmf.in,
those changes are propagated to the compile-time defaults.
The Make definitions are all repeated in several Makefile's; but changing the top-level Makefile should suffice, as it passes down all the variable definitions, thus overriding the submakes. (The definitions are repeated so you can run Make in the subdirectories, if you should have occasion to.)
By default, the bitmap font paths end with ‘/$MAKETEX_MODE’, thus including the device name (usually a Metafont mode name such as ‘ljfour’). This distinguishes two different devices with the same resolution—a write/white from a write/black 300dpi printer, for example.
However, since most sites don't have this complication, Kpathsea
(specifically, the kpse_init_prog
function in
kpathsea/proginit.c) has a special case: if the mode has not been
explicitly set by the user (or in a configuration file), it sets
MAKETEX_MODE
to /
. This makes the default PK path, for
example, expand into .../pk//
, so fonts will be found even if
there is no subdirectory for the mode (if you arranged things that way
because your site has only one printer, for example) or if the program
is mode-independent (e.g., pktype
).
To make the paths independent of the mode, simply edit texmf.in before installation, or the installed texmf.cnf, and remove the ‘$MAKETEX_MODE’.
See mktex script arguments, for how this interacts with mktexpk
.
See TeX directory structure, for a description of the default arrangement of the input files that comprise the TeX system.
This section describes how the default paths are constructed.
You may wish to ignore the whole mess and simply edit texmf.cnf after it is installed, perhaps even copying it into place beforehand so you can complete the installation, if it seems necessary.
To summarize the chain of events that go into defining the default paths:
$(var)
for a
string @var@
. The variables in question are the one that
define the installation directories.
#define
's in
paths.h. These values will be the compile-time defaults; they
are not used at runtime unless no texmf.cnf file can be found.
(That's a lie: the compile-time defaults are what any extra :'s in texmf.cnf expand into; but the paths as distributed have no extra :'s, and there's no particular reason for them to.)
configure
Run sh configure
options (in the top-level directory, the
one containing kpathsea/), possibly using a shell other than
sh
(see configure shells).
configure
adapts the source distribution to the present system
via #define
's in */c-auto.h, which are created from the
corresponding c-auto.in. It also creates a Makefile from
the corresponding Makefile.in, doing ‘@var@’ and
‘ac_include’ substitutions).
configure
is the best place to control the configuration,
compilation, and installed location of the software, either via
command-line options, or by setting environment variables before
invoking it. For example, you can disable mktexpk
by default
with the option ‘--disable-mktexpk’.
See configure options.
configure
shells
Considerable effort has gone into trying to ensure that the
configure
scripts can be run by most Bourne shell variants.
If sh
runs into trouble, your best bet is to use Bash, the GNU
Bourne-again shell (see Top).
Bourne shell variants for which problems have been reported in the past are:
ksh
ash
/bin/sh
configure
options
For a complete list of all configure
options, run ‘configure
--help’ or see Running configure
scripts, (a copy is in the file kpathsea/README.CONFIGURE).
The generic options are listed first in the ‘--help’ output, and
the package-specific options come last. The environment variables
configure
pays attention to are listed below.
Options particularly likely to be useful are ‘--prefix’, ‘--datadir’, and the like; see configure scenarios.
This section gives pointers to descriptions of the ‘--with’ and
‘--enable’ options to configure
that Kpathsea-using programs
accept.
configure
environmentconfigure
uses the value of the following environment variables in
determining your system's characteristics, and substitutes for them in
Makefile's:
gcc
if it's installed, otherwise
cc
.
gcc
,
‘-g’ otherwise. CFLAGS
comes after any other options. You
may need to include -w
here if your compilations commonly have
useless warnings (e.g., NULL redefined
), or configure
may
fail to detect the presence of header files (it takes the messages on
standard error to mean the header file doesn't exist).
configure
script often does only preprocessing (e.g., to check for the existence
of #include files), and CFLAGS
is not used for this. You may
need to set this to something like
‘-I/usr/local/include/wwwhatever’ if you have the libwww library
installed for hyper-xdvik (see xdvik/INSTALL).
configure
.
Provided for enabling or disabling program features, as documented in
the various program-specific installation instructions. DEFS
comes before any compiler options included by the distribution
Makefiles or by configure
.
LDFLAGS
comes before
any other linker options.
configure
scenariosHere are some common installation scenarios:
configure --with-x
configure
:
configure --prefix=/here/texmf --datadir=/here
lndir
script from the X11
distribution, or with the ‘--srcdir’ option:
configure --srcdir=srcdir
configure --prefix=texmf --datadir=texmf \ --bindir=texmf/arch/bin --libdir=texmf/arch/lib make texmf=texmf
(Unless you make provisions for architecture-specific files in other ways, e.g., with Depot or an automounter.)
env CFLAGS="-g -O" sh configure ...
For a potential problem if you optimize, see TeX or Metafont failing.
You can compile Kpathsea as a shared library on a few systems, by specifying the option ‘--enable-shared’ when you run ‘configure’.
The main advantage in doing this is that the executables can then share the code, thus decreasing memory and disk space requirements.
On some systems, you can record the location of shared libraries in a
binary, usually by giving certain options to the linker. Then
individual users do not need to set their system's environment variable
(e.g., LD_LIBRARY_PATH
) to find shared libraries. If you want to
do this, you will need to add the necessary options to LDFLAGS
yourself; for example, on Solaris, include something like
‘-R${prefix}/lib’, on IRIX or Linux, use
‘-rpath${prefix}/lib’. (Unfortunately, making this happen by
default is very difficult, because of interactions with an existing
installed shared library.)
make
make
(still in the top-level directory). This also creates the
texmf.cnf and paths.h files that define the default search
paths, and (by default) the ‘plain’ and ‘latex’ TeX formats.
You can override directory names and other values at make
-time.
make/paths.make lists the variables most commonly reset. For
example, ‘make default_texsizes=600’ changes the list of fallback
resolutions.
You can also override each of configure
's environment variables
(see configure environment). The Make variables have the same names.
Finally, you can supply additional options via the following variables.
(configure
does not use these.)
make
's. You may need
to include assignments to the other variables here via XMAKEARGS
;
for example: ‘make XMAKEARGS="CFLAGS=-O XDEFS=-DA4"’.
It's generally a bad idea to use a different compiler (‘CC’) or
libraries (LIBS
) for compilation than you did for configuration,
since the values configure
determined may then be incorrect.
Adding compiler options to change the “universe” you are using
(typically BSD vs. system V) is generally a cause of trouble. It's
best to use the native environment, whatever that is; configure
and the software usually adapt best to that. In particular, under
Solaris 2.x, you should not use the BSD-compatibility library
(libucb) or include files (ucbinclude).
If you want to use the Babel LaTeX package for support of non-English typesetting, you need to modify some files before making the LaTeX format. See the file install.txt in the Babel distribution.
The basic command is the usual make install
. For security
issues, see Security.
The first time you install any manual in the GNU Info system, you should add a line (you choose where) to the file dir in your ‘$(infodir)’ directory. Sample text for this is given near the top of the Texinfo source files (kpathsea/kpathsea.texi, dvipsk/dvips.texi, and web2c/doc/web2c.texi). If you have a recent version of the GNU Texinfo distribution installed (ftp://prep.ai.mit.edu/pub/gnu/texinfo-3.9.tar.gz or later), this should happen automatically.
On the offchance that this is your first Info installation, the dir file I use is included in the distribution as etc/dir-example.
You may wish to use one of the following targets, especially if you are installing on multiple architectures:
make install-exec
to install in architecture-dependent
directories, i.e., ones that depend on the $(exec_prefix)
Make
variable. This includes links to binaries, libraries, etc., not just
“executables”.
make install-data
to install in architecture-independent
directories, such as documentation, configuration files, pool files, etc.
If you use the Andrew File System, the normal path (e.g.,
prefix/bin) only gets you to a read-only copy of the files, and
you must specify a different path for installation. The best way to do this
is by setting the ‘prefix’ variable on the make
command
line. The sequence becomes something like this:
configure --prefix=/whatever make make install prefix=/afs/.system.name/system/1.3/@sys/whatever
With AFS, you will definitely want to use relative filenames in ls-R (see Filename database), not absolute filenames. This is done by default, but check anyway.
The basic command is make distclean
. This removes all files
created by the build.
Alternatively,
make mostlyclean
if you intend to compile on another
architecture. For Web2C, since the generated C files are portable,
they are not removed. If the lex
vs. flex
situation
is going to be different on the next machine, rm
web2c/lex.yy.c
.
make clean
to remove files created by compiling, but leave
configuration files and Makefiles.
make maintainer-clean
to remove everything that the Makefiles can
rebuild. This is more than ‘distclean’ removes, and you should
only use it if you are thoroughly conversant with (and have the necessary
versions of) Autoconf.
make extraclean
to remove other junk, e.g., core files, log
files, patch rejects. This is independent of the other ‘clean’
targets.
You will probably want to set up a cron
entry on the appropriate
machine(s) to rebuild the filename database nightly or so, as in:
0 0 * * * cd texmf && /bindir/mktexlsr
See Filename database.
Although the mktex...
scripts make every effort to add
newly-created files on the fly, it can't hurt to make sure you get a
fresh version every so often.
If Kpathsea cannot otherwise find a file, for some file types it is
configured by default to invoke an external program to create it
dynamically (see mktex configuration). These are collectively
known as mktex
scripts, since most of them are named
mktex...
.
For example, this is useful for fonts (bitmaps, TFM's, and arbitrarily-sizable Metafont sources such as the Sauter and EC fonts), since any given document can use fonts never before referenced. Building all fonts in advance is therefore impractical, if not impossible.
It is also useful for the TeX ‘.fmt’ (and Metafont ‘.base’ and Metapost ‘.mem’ files, see Memory dumps), where pre-generating every format consumes a lot of both time and space.
The script is passed the name of the file to create and possibly other arguments, as explained below. It must echo the full pathname of the file it created (and nothing else) to standard output; it can write diagnostics to standard error.
The list of file types and program names that can run an external
program to create missing files is listed in the next section. In the
absence of configure
options specifying otherwise, everything
but mktextex will be enabled by default. The configure
options to change the defaults are:
--without-mktexfmt-default --without-mktexmf-default --without-mktexocp-default --without-mktexofm-default --without-mktexpk-default --without-mktextfm-default --with-mktextex-default
The configure
setting is overridden if the environment variable
or configuration file value named for the script is set; e.g.,
MKTEXPK (see mktex script arguments).
mktexfmt
reads a file fmtutil.cnf, typically located in
texmf/web2c/ to glean its configuration information. The rest
of the files and features in this section are primarily intended for
the font generation scripts.
As distributed, all the scripts source a file texmf/web2c/mktex.cnf if it exists, so you can override various defaults. See mktex.opt, for instance, which defines the default mode, resolution, some special directory names, etc. If you prefer not to change the distributed scripts, you can simply create mktex.cnf with the appropriate definitions (you do not need to create it if you have nothing to put in it). mktex.cnf has no special syntax; it's an arbitrary Bourne shell script. The distribution contains a sample mktex.cnf for you to copy and modify as you please (it is not installed anywhere).
In addition, you can configure a number of features with the
MT_FEATURES
variable, which you can define:
If none of the options below are enabled, mktexpk
,
mktextfm
, and mktexmf
follow the following procedure to
decide where fonts should be installed. Find the tree where the font's
sources are, and test the permissions of the ‘fonts’ directory of
that tree to determine whether it is writable. If it is, put the files
in the tree in appropriate locations. If it isn't writable, see whether
the tree is a system tree (named in SYSTEXMF
). If so, the
VARTEXFONTS
tree is used. In all other cases the working
directory is used.
The ‘appendonlydir’ option is enabled by default.
mktexdir
to create directories append-only, i.e., set
their sticky bit (see Mode Structure). This feature is silently ignored on non-Unix platforms
(e.g. Windows/NT and MS-DOS) which don't support similar functionality.
This feature is enabled by default.
This feature is turned on by default on MS-DOS. If you do not wish
‘dosnames’ to be set on an MS-DOS platform, you need to set the
MT_FEATURES
environment variable to a value that doesn't include
‘dosnames’. You can also change the default setting by editing
mktex.opt, but only if you use the mktex shell scripts;
the emulation programs don't consult mktex.opt.
VARTEXFONTS
tree instead. The
default value in kpathsea/Makefile.in is
/var/tmp/texfonts. The Linux File System Standard
recommends /var/tex/fonts.
The ‘varfonts’ setting in MT_FEATURES
is overridden by the
USE_VARTEXFONTS
environment variable: if set to ‘1’, the
feature is enabled, and if set to ‘0’, the feature is disabled.
SYSTEXMF
) into TEXMFVAR
. Starting with teTeX-3.0, the
variable TEXMFVAR
is always set. The ‘varfonts’ feature takes
precedence if also set.
The ‘texmfvar’ setting in MT_FEATURES
is overridden by the
USE_TEXMFVAR
environment variable: if set to ‘1’, the
feature is enabled, and if set to ‘0’, the feature is disabled.
The following table shows the default name of the script for each of the file types which support runtime generation.
These names can be overridden by an environment variable specific
to the program—for example, DVIPSMAKEPK
for Dvipsk.
If a mktex...
script fails, the invocation is appended to a
file missfont.log (by default) in the current directory. You can
then execute the log file to create the missing files after fixing the
problem.
If the current directory is not writable and the environment variable or
configuration file value TEXMFOUTPUT
is set, its value is
used. Otherwise, nothing is written. The name ‘missfont.log’ is
overridden by the MISSFONT_LOG
environment variable or
configuration file value.
The first argument to a mktex script is always the name of the file to be created.
In the default mktexpk implementation, additional arguments may also be passed:
mag
variable.
This must match the combination of bdpi and dpi being used.
Besides the tests listed in Simple installation, you can try running ‘make check’. This includes the torture tests (trip, trap, and mptrap) that come with Web2c (see Triptrap).
None of the programs in the TeX system require any special system privileges, so there's no first-level security concern of people gaining illegitimate root access.
A TeX document, however, can write to arbitrary files, e.g., ~/.rhosts, and thus an unwitting user who runs TeX on a random document is vulnerable to a trojan horse attack. This loophole is closed by default, but you can be permissive if you so desire in texmf.cnf. See tex invocation. MetaPost has the same issue.
Dvips, Xdvi, and TeX can also execute shell commands under some circumstances. To disable this, see the ‘-R’ option in Option details, the xdvi man page, and tex invocation, respectively.
Another security issue arises because it's very useful—almost
necessary—to make arbitrary fonts on user demand with mktexpk
and friends. Where do these files get installed? By default, the
mktexpk
distributed with Kpathsea assumes a world-writable
/var/tmp directory; this is a simple and convenient approach, but
it may not suit your situation because it means that a local cache of
fonts is created on every machine.
To avoid this duplication, many people consider a shared, globally
writable font tree desirable, in spite of the potential security
problems. To do this you should change the value of VARTEXFONTS
in texmf.cnf to refer to some globally known directory.
See mktex configuration.
The first restriction you can apply is to make newly-created directories under texmf be append-only with an option in mktex.cnf. See mktex configuration.
Another approach is to establish a group (or user) for TeX files,
make the texmf tree writable only to that group (or user), and
make mktexpk
et al. setgid to that group (or setuid to that
user). Then users must invoke the scripts to install things. (If
you're worried about the inevitable security holes in scripts, then you
could write a C wrapper to exec the script.)
The mktex... scripts install files with the same read and write permissions as the directory they are installed in. The executable, sgid, suid, and sticky bits are always cleared.
Any directories created by the mktex... scripts have the
same permissions as their parent directory, unless the
appendonlydir
feature is used, in which case the sticky bit is
always set.
This section describes the default installation hierarchy of the distribution. It conforms to both the GNU coding standards and the TeX directory structure (TDS) standard. For rationale and further explanation, please see those documents. The GNU standard is available as ftp://prep.ai.mit.edu/pub/gnu/standards/standards.texi and mirrors. The TDS document is available from CTAN:/tex-archive/tds (see unixtex.ftp).
You can change the default paths in many ways (see Changing search paths). One common desire is to put everything (binaries and all) under a single top-level directory such as /usr/local/texmf or /opt/texmf—in the terms used below, make prefix and texmf the same. For specific instructions on doing that, see configure scenarios.
Here is a skeleton of the default directory structure, extracted from the TDS document:
prefix/ installation root (/usr/local by default) bin/ executables man/ man pages include/ C header files info/ GNU info files lib/ libraries (libkpathsea.*) share/ architecture-independent files texmf/ TDS root bibtex/ BibTeX input files bib/ BibTeX databases base/ base distribution (e.g., ‘xampl.bib’) misc/ single-file databases pkg/ name of a package bst/ BibTeX style files base/ base distribution (e.g., ‘plain.bst’, ‘acm.bst’) misc/ single-file styles pkg/ name of a package doc/ additional documentation dvips/ ‘.pro’, ‘.ps’, ‘psfonts.map’ fonts/ font-related files type/ file type (e.g., ‘tfm’, ‘pk’) mode/ type of output device (types ‘pk’ and ‘gf’ only) supplier/ name of a font supplier (e.g., ‘public’) typeface/ name of a typeface (e.g., ‘cm’) dpinnn/ font resolution (types ‘pk’ and ‘gf’ only) metafont/ Metafont (non-font) input files base/ base distribution (e.g., ‘plain.mf’) misc/ single-file packages (e.g., ‘modes.mf’) pkg/ name of a package (e.g., ‘mfpic’) metapost/ MetaPost input files base/ base distribution (e.g., ‘plain.mp’) misc/ single-file packages pkg/ name of a package support/ support files for MetaPost-related utilities (e.g., ‘trfonts.map’) mft/ ‘MFT’ inputs (e.g., ‘plain.mft’) tex/ TeX input files format/ name of a format (e.g., ‘plain’) base/ base distribution for format (e.g., ‘plain.tex’) misc/ single-file packages (e.g., ‘webmac.tex’) local/ local additions to or local configuration files for format pkg/ name of a package (e.g., ‘graphics’, ‘mfnfss’) generic/ format-independent packages hyphen/ hyphenation patterns (e.g., ‘hyphen.tex’) images/ image input files (e.g., Encapsulated PostScript) misc/ single-file format-independent packages (e.g., ‘null.tex’). pkg/ name of a package (e.g., ‘babel’) web2c/ implementation-dependent files (.pool, .fmt, texmf.cnf, etc.)
Some concrete examples for most file types:
/usr/local/bin/tex /usr/local/man/man1/xdvi.1 /usr/local/info/kpathsea.info /usr/local/lib/libkpathsea.a /usr/local/share/texmf/bibtex/bst/base/plain.bst /usr/local/share/texmf/fonts/pk/ljfour/public/cm/cmr10.600pk /usr/local/share/texmf/fonts/source/public/pandora/pnr10.mf /usr/local/share/texmf/fonts/tfm/public/cm/cmr10.tfm /usr/local/share/texmf/fonts/type1/adobe/utopia/putr.pfa /usr/local/share/texmf/metafont/base/plain.mf /usr/local/share/texmf/metapost/base/plain.mp /usr/local/share/texmf/tex/plain/base/plain.tex /usr/local/share/texmf/tex/generic/hyphen/hyphen.tex /usr/local/share/texmf/web2c/tex.pool /usr/local/share/texmf/web2c/tex.fmt /usr/local/share/texmf/web2c/texmf.cnf
This is ftp://ftp.tug.org/tex/unixtex.ftp, last updated 13 June 2010. Also available as http://www.tug.org/unixtex.ftp. Email tex-k@tug.org with comments or questions.
The principal free TeX distribution for Unix-like systems is TeX Live, on the web at http://tug.org/texlive. The pages there describe many ways to acquire TeX, over the Internet or on physical media, both the sources and precompiled binaries for many systems, either standalone or as part of various operating system distributions.
Web2C, Kpathsea, Dvips, and Dviljk are no longer released as a separate packages. Their sources are now maintained as part of TeX Live.
The host ftp.cs.stanford.edu is the original source for the files for which Donald Knuth is directly responsible: tex.web, plain.tex, etc. However, unless you want to build your TeX library tree ab initio, it is more reliable and less work to retrieve these files as part of a larger package. In any case, that ftp site is not the canonical source for anything except what was created as part of Stanford TeX project, so do not rely on the other files available there being up-to-date.
(A copy of this chapter is in the file kpathsea/BUGS.)
If you have problems or suggestions, please report them to tex-k@tug.org using the bug checklist below.
Please report bugs in the documentation; not only factual errors or inconsistent behavior, but unclear or incomplete explanations, typos, wrong fonts, ...
Before reporting a bug, please check below to be sure it isn't already known (see Common problems).
Bug reports should be sent via electronic mail to tex-k@tug.org.
The general principle is that a good bug report includes all the information necessary for reproduction. Therefore, to enable investigation, your report should include the following:
make
program you are using (the output of uname -a
is a
start on the first two, though often incomplete). If the bug involves
the X window system, include X version and supplier information as well
(examples: X11R6 from MIT; X11R4 from HP; OpenWindows 3.3 bundled with
SunOS 4.1.4).
configure
. This is recorded in the
config.status files.
If you are reporting a bug in ‘configure’ itself, it's probably
system-dependent, and it will be unlikely the maintainers can do
anything useful if you merely report that thus-and-such is broken.
Therefore, you need to do some additional work: for some bugs, you can
look in the file config.log where the test that failed should
appear, along with the compiler invocation and source program in
question. You can then compile it yourself by hand, and discover why
the test failed. Other ‘configure’ bugs do not involve the
compiler; in that case, the only recourse is to inspect the
configure
shell script itself, or the Autoconf macros that
generated configure
.
KPATHSEA_DEBUG
to ‘-1’ before running the program. Please look at the log
yourself to make sure the behavior is really a bug before reporting it;
perhaps “old” environment variable settings are causing files not to
be found, for example.
NULL
value being dereferenced, for
example), please send the details along. If the program involved is
TeX or Metafont, and the crash is happening at apparently-sound code,
however, the bug may well be in the compiler, rather than in the program
or the library (see TeX or Metafont failing).
Web2c and Kpathsea in general are discussed on the mailing list tex-k@tug.org. To join, email tex-k-request@tug.org with a line consisting of
subscribe you@your.preferred.email.address
in the body of the message.
You do not need to join to submit a report, nor will it affect whether you get a response. There is no Usenet newsgroup equivalent (if you can be the one to set this up, email ‘tex-k-request’). Traffic on the list is fairly light, and is mainly bug reports and enhancement requests to the software. The best way to decide if you want to join or not is read some of the archives from ftp://ftp.tug.org/mail/archives/tex-k/.
Be aware that large data files are sometimes included in bug reports. If this is a problem for you, do not join the list.
If you are looking for general TeX help, such as how to use LaTeX, please use the mailing list texhax@tug.org mailing list (http://lists.tug.org/texhax) which is gatewayed to the ‘comp.text.tex’ Usenet newsgroup (or post to the newsgroup; the gateway is bidirectional).
Kpathsea provides a number of runtime debugging options, detailed below by their names and corresponding numeric values. When the files you expect aren't being found, the thing to do is enable these options and examine the output.
You can set these with some runtime argument (e.g., ‘-d’) to the program; in that case, you should use the numeric values described in the program's documentation (which, for Dvipsk and Xdvik, are different than those below). It's best to give the ‘-d’ (or whatever) option first, for maximal output. Dvipsk and Xdvik have additional program-specific debugging options as well.
You can also set the environment variable KPATHSEA_DEBUG
; in this
case, you should use the numbers below. If you run the program under a
debugger and set the instance variable kpse->debug
, also use the numbers
below.
In any case, by far the simplest value to use is ‘-1’, which will turn on all debugging output. This is usually better than guessing which particular values will yield the output you need.
Debugging output always goes to standard error, so you can redirect it easily. For example, in Bourne-compatible shells:
dvips -d -1 ... 2>/tmp/debug
It is sometimes helpful to run the standalone Kpsewhich utility (see Invoking kpsewhich), instead of the original program.
In any case, you can not use the names below; you must always use somebody's numbers. (Sorry.) To set more than one option, just sum the corresponding numbers.
KPSE_DEBUG_STAT
(1)KPSE_DEBUG_HASH
(2)KPSE_DEBUG_FOPEN
(4)KPSE_DEBUG_PATHS
(8)kpse_format_info_type
structure defined in
tex-file.h.
KPSE_DEBUG_EXPAND
(16)KPSE_DEBUG_SEARCH
(32)KPSE_DEBUG_VARS
(64)GSFTOPK_DEBUG
(128)gsftopk
program.
MAKETEX_DEBUG
(512)mktex
programs instead of the
traditional shell scripts, this will report the name of the site file
(mktex.cnf by default) which is read, directories created by
mktexdir
, the full path of the ls-R database built by
mktexlsr
, font map searches, MT_FEATURES
in effect,
parameters from mktexnam
, filenames added by
mktexupd
, and some subsidiary commands run by the programs.
MAKETEX_FINE_DEBUG
(1024)mktex
programs are used, this will print
additional debugging info from functions internal to these programs.
Debugging output from Kpathsea is always written to standard error, and
begins with the string ‘kdebug:’. (Except for hash table buckets,
which just start with the number, but you can only get that output
running under a debugger. See comments at the hash_summary_only
variable in kpathsea/db.c.)
Kpathsea can record the time and filename found for each successful search. This may be useful in finding good candidates for deletion when your filesystem is full, or in discovering usage patterns at your site.
To do this, define the environment or config file variable
TEXMFLOG
. The value is the name of the file to append the
information to. The file is created if it doesn't exist, and appended
to if it does.
Each successful search turns into one line in the log file: two words
separated by a space. The first word is the time of the search, as the
integer number of seconds since “the epoch”, i.e., UTC midnight 1
January 1970 (more precisely, the result of the time
system
call). The second word is the filename.
For example, after setenv TEXMFLOG /tmp/log
, running Dvips on
story.dvi appends the following lines:
774455887 /usr/local/share/texmf/dvips/config.ps 774455887 /usr/local/share/texmf/dvips/psfonts.map 774455888 /usr/local/share/texmf/dvips/texc.pro 774455888 /usr/local/share/texmf/fonts/pk/ljfour/public/cm/cmbx10.600pk 774455889 /usr/local/share/texmf/fonts/pk/ljfour/public/cm/cmsl10.600pk 774455889 /usr/local/share/texmf/fonts/pk/ljfour/public/cm/cmr10.600pk 774455889 /usr/local/share/texmf/dvips/texc.pro
Only filenames that are absolute are recorded, to preserve some semblance of privacy.
In addition to this Kpathsea-specific logging, pdftex provides an option -recorder to write the names of all files accessed during a run to the file basefile.fls.
Finally, most systems provide a general tool to output each system call, thus including opening and closing files. It might be named strace, truss, struss, or something else.
Here are some common problems with configuration, compilation, linking, execution, ...
If a program complains it cannot find fonts (or other input files), any of several things might be wrong. In any case, you may find the debugging options helpful. See Debugging.
Unfortunately, Kpathsea's subdirectory searching has an irremediable deficiency: If a directory d being searched for subdirectories contains plain files and symbolic links to other directories, but no true subdirectories, d will be considered a leaf directory, i.e., the symbolic links will not be followed. See Subdirectory expansion.
You can work around this problem by creating an empty dummy subdirectory in d. Then d will no longer be a leaf, and the symlinks will be followed.
The directory immediately followed by the ‘//’ in the path specification, however, is always searched for subdirectories, even if it is a leaf. Presumably you would not have asked for the directory to be searched for subdirectories if you didn't want it to be.
mktexpk
(or
mktexmf
or mktextfm
) will try to create them. If
these rather complicated shell scripts fail, you'll eventually get an
error message saying something like ‘Can't find font
fontname’. The best solution is to fix (or at least report) the
bug in mktexpk
; the workaround is to generate the necessary
fonts by hand with Metafont, or to grab them from a CTAN site
(see unixtex.ftp).
If your program takes an excessively long time to find fonts or other input files, but does eventually succeed, here are some possible culprits:
It is best to have only directories (and perhaps a README) in the upper levels of the directory structure, and it's very important to have only files, and no subdirectories, in the leaf directories where the dozens of TFM, PK, or whatever files reside.
In any case, you may find the debugging options helpful in determining precisely when the disk or network is being pounded. See Debugging.
Metafont outputs fonts in bitmap format, tuned for a particular device at a particular resolution, in order to allow for the highest-possible quality of output. Some DVI-to-whatever programs, such as Dvips, try to generate these on the fly when they are needed, but this generation may fail in several cases.
If mktexpk
runs, but fails with this error:
mktexpk: Can't guess mode for nnn dpi devices. mktexpk: Use a config file to specify the mode, or update me.
you need to ensure the resolution and mode match; just
specifying the resolution, as in -D 360
, is not enough.
You can specify the mode name with the -mode
option on the
Dvips command line, or in a Dvips configuration file (see Config files), such as config.ps in your document
directory, ~/.dvipsrc in your home directory, or in a system
directory (again named config.ps). (Other drivers use other
files, naturally.)
For example, if you need 360dpi fonts, you could include this in a configuration file:
D 360 M lqmed
If Metafont runs, but generates fonts at the wrong resolution or for
the wrong device, most likely mktexpk
's built-in guess for the
mode is wrong, and you should override it as above.
See ftp://ftp.tug.org/tex/modes.mf for a list of resolutions and mode names for most devices (additional submissions are welcome).
If Metafont runs but generates fonts at a resolution of 2602dpi
(and prints out the name of each character as well as just a character
number, and maybe tries to display the characters), then your Metafont
base file probably hasn't been made properly. (It's using the default
proof
mode, instead of an actual device mode.) To make a proper
plain.base, assuming the local mode definitions are contained in
a file modes.mf, run the following command (assuming Unix):
inimf "plain; input modes; dump"
Then copy the plain.base file from the current directory to where the base files are stored on your system (/usr/local/share/texmf/web2c by default), and make a link (either hard or soft) from plain.base to mf.base in that directory. See inimf invocation.
If mf
is a command not found at all by mktexpk
, then you
need to install Metafont (see unixtex.ftp).
If TeX or Metafont get a segmentation fault or otherwise fail while running a normal input file, the problem is usually a compiler bug (unlikely as that may sound). Even if the trip and trap tests are passed, problems may lurk. Optimization occasionally causes trouble in programs other than TeX and Metafont themselves, too.
Insufficient swap space may also cause core dumps or other erratic behavior.
For a workaround, if you enabled any optimization flags, it's best to omit optimization entirely. In any case, the way to find the facts is to run the program under the debugger and see where it's failing.
Also, if you have trouble with a system C compiler, I advise trying the GNU C compiler. And vice versa, unfortunately; but in that case I also recommend reporting a bug to the GCC mailing list; see Bugs.
To report compiler bugs effectively requires perseverance and perspicacity: you must find the miscompiled line, and that usually involves delving backwards in time from the point of error, checking through TeX's (or whatever program's) data structures. Things are not helped by all-too-common bugs in the debugger itself. Good luck.
One known cause of trouble is the way arrays are handled. Some of the Pascal arrays have a lower index other than 0, and the C code will take the pointer to the allocated memory, subtract the lower index, and use the resulting pointer for the array. While this trick often works, ANSI C doesn't guarantee that it will. It it known to fail on HP-UX 10 machines when the native compiler is used, unless the ‘+u’ compiler switch was specified. Using GCC will work on this platform as well.
On some systems (NetBSD, FreeBSD, AIX 4.1, and Mach10), configure
may fail to properly create the Makefiles. Instead, you get an error
which looks something like this:
prompt$ ./configure ... creating Makefile sed: 1: "\\@^ac_include make/pat ...": \ can not be used as a string delimiter
So far as I know, the bug here is in /bin/sh
on these systems. I
don't have access to a machine running any of them, so if someone can
find a workaround that avoids the quoting bug, I'd be most
grateful. (Search for ac_include
in the configure
script
to get to the problematic code.)
It should work to run bash configure
, instead of using
/bin/sh
. You can get Bash from
ftp://prep.ai.mit.edu/pub/gnu and mirrors.
Another possible cause (reported for NeXT) is a bug in the sed
command. In that case the error may look like this:
Unrecognized command: \@^ac_include make/paths.make@r make/paths.make
In this case, installing GNU sed
should solve the problem. You
can get GNU sed
from the same places as Bash.
XtStrings
You may find that linking X programs results in an error from the linker that ‘XtStrings’ is undefined, something like this:
gcc -o virmf ... .../x11.c:130: undefined reference to `XtStrings'
This generally happens because of a mismatch between the X include files with which you compiled and the X libraries with which you linked; often, the include files are from MIT and the libraries from Sun.
The solution is to use the same X distribution for compilation and
linking. Probably ‘configure’ was unable to guess the proper
directories from your installation. You can use the configure
options ‘--x-includes=path’ and
‘--x-libraries=path’ to explicitly specify them.
dlopen
(This section adapted from the file dlsym.c in the X distribution.)
The Xlib
library uses the standard C function wcstombs
.
Under SunOS 4.1, wcstombs
uses the ‘dlsym’ interface defined
in libdl.so. Unfortunately, the SunOS 4.1 distribution does not
include a static ‘libdl.a’ library.
As a result, if you try to link an X program statically under SunOS, you
may get undefined references to dlopen
, dlsym
, and
dlclose
. One workaround is to include these definitions
when you link:
void *dlopen() { return 0; } void *dlsym() { return 0; } int dlclose() { return -1; }
These are contained in the dlsym.c file in the MIT X distribution.
ShellWidgetClass
(This section adapted from the comp.sys.sun.admin FAQ.)
If you are linking with Sun's OpenWindows libraries in SunOS 4.1.x, you
may get undefined symbols _get_wmShellWidgetClass
and
_get_applicationShellWidgetClass
when linking. This problem does
not arise using the standard MIT X libraries under SunOS.
The cause is bugs in the Xmu
shared library as shipped from Sun.
There are several fixes:
Xmu
library into the executable.
Xmu
at all. If you are compiling
Metafont, see Online Metafont graphics. If you are
compiling Xdvi, see the -DNOTOOL
option in xdvik/INSTALL.
Here is the information for getting the two patches:
Patch ID: 100512-02 Bug ID's: 1086793, 1086912, 1074766 Description: 4.1.x OpenWindows 3.0libXt
jumbo patch Patch ID: 100573-03 Bug ID: 1087332 Description: 4.1.x OpenWindows 3.0 undefined symbols when using sharedlibXmu
.
The way to statically link with libXmu
depends on whether you are
using a Sun compiler (e.g., cc
) or gcc
. If the latter,
alter the x_libs
Make variable to include
-static -lXmu -dynamic
If you are using the Sun compiler, use ‘-Bstatic’ and ‘-Bdynamic’.
When compiling with old C compilers, you may get some warnings about “illegal pointer combinations”. These are spurious; just ignore them. I decline to clutter up the source with casts to get rid of them.
This chapter describes the generic path searching mechanism Kpathsea provides. For information about searching for particular file types (e.g., TeX fonts), see the next chapter.
A search path is a colon-separated list of path elements, which are directory names with a few extra frills. A search path can come from (a combination of) many sources; see below. To look up a file ‘foo’ along a path ‘.:/dir’, Kpathsea checks each element of the path in turn: first ./foo, then /dir/foo, returning the first match (or possibly all matches).
The “colon” and “slash” mentioned here aren't necessarily ‘:’ and ‘/’ on non-Unix systems. Kpathsea tries to adapt to other operating systems' conventions.
To check a particular path element e, Kpathsea first sees if a prebuilt database (see Filename database) applies to e, i.e., if the database is in a directory that is a prefix of e. If so, the path specification is matched against the contents of the database.
If the database does not exist, or does not apply to this path element, or contains no matches, the filesystem is searched (if this was not forbidden by the specification with ‘!!’ and if the file being searched for must exist). Kpathsea constructs the list of directories that correspond to this path element, and then checks in each for the file being searched for. (To help speed future lookups of files in the same directory, the directory in which a file is found is floated to the top of the directory list.)
The “file must exist” condition comes into play with VF files and input files read by the TeX ‘\openin’ command. These files might very well not exist (consider cmr10.vf), and so it would be wrong to search the disk for them. Therefore, if you fail to update ls-R when you install a new VF file, it will not be found.
Each path element is checked in turn: first the database, then the disk. If a match is found, the search stops and the result is returned. This avoids possibly-expensive processing of path specifications that are never needed on a particular run. (Unless the search explicitly requested all matches.)
Although the simplest and most common path element is a directory name, Kpathsea supports additional features in search paths: layered default values, environment variable names, config file values, users' home directories, and recursive subdirectory searching. Thus, we say that Kpathsea expands a path element, meaning transforming all the magic specifications into the basic directory name or names. This process is described in the sections below. It happens in the same order as the sections.
Exception to all of the above: If the filename being searched for is absolute or explicitly relative, i.e., starts with ‘/’ or ‘./’ or ‘../’, Kpathsea simply checks if that file exists.
Ordinarily, if Kpathsea tries to access a file or directory that
cannot be read, it gives a warning. This is so you will be alerted to
directories or files that accidentally lack any read permission (for
example, a lost+found directory). If you prefer not to see
these warnings, include the value ‘readable’ in the
TEX_HUSH
environment variable or config file value.
This generic path searching algorithm is implemented in kpathsea/pathsearch.c. It is employed by a higher-level algorithm when searching for a file of a particular type (see File lookup, and Glyph lookup).
A search path can come from many sources. In the order in which Kpathsea uses them:
TEXINPUTS
.
Environment variables with an underscore and the program name appended
override; for example, TEXINPUTS_latex
overrides TEXINPUTS
if the program being run is named ‘latex’.
You can see each of these values for a given search path by using the debugging options (see Debugging).
These sources may be combined via default expansion (see Default expansion).
As mentioned above, Kpathsea reads runtime configuration files
named texmf.cnf for search path and other definitions. The
search path used to look for these configuration files is named
TEXMFCNF
, and is constructed in the usual way, as described
above, except that configuration files cannot be used to define the
path, naturally; also, an ls-R database is not used to search for
them.
Kpathsea reads all texmf.cnf files in the search path, not just the first one found; definitions in earlier files override those in later files. Thus, if the search path is ‘.:$TEXMF’, values from ./texmf.cnf override those from $TEXMF/texmf.cnf.
If Kpathsea cannot find any texmf.cnf file, it reports a warning including all the directories it checked. If you don't want to see this warning, set the environment variable KPATHSEA_WARNING to the single character ‘0’ (zero, not oh).
While (or instead of) reading this description, you may find it helpful to look at the distributed texmf.cnf, which uses or at least mentions most features. The format of texmf.cnf files follows:
% this is a comment var = a%b % but the value of var will be "a%b".
variable [. progname] [=] value
where the ‘=’ and surrounding whitespace is optional.
argv[0]
is) progname or
progname.{exe,bat,cmd,...}. Most notably, this allows
different flavors of TeX to have different search paths.
Here is a configuration file fragment illustrating most of these points:
% TeX input files -- i.e., anything to be found by \input or \openin ... latex209_inputs = .:$TEXMF/tex/latex209//:$TEXMF/tex// latex2e_inputs = .:$TEXMF/tex/latex//:$TEXMF/tex// TEXINPUTS = .:$TEXMF/tex// TEXINPUTS.latex209 = $latex209_inputs TEXINPUTS.latex2e = $latex2e_inputs TEXINPUTS.latex = $latex2e_inputs
This format has obvious similarities to Bourne shell scripts—change
the comment character to #
, disallow spaces around the
=
, and get rid of the .
name convention, and it
could be run through the shell. However, there seemed little
advantage in this, since all the information would have to passed back
to Kpathsea and parsed there anyway, since the sh
process
couldn't affect its parent's environment.
The implementation of all this is in kpathsea/cnf.c.
Kpathsea recognizes certain special characters and constructions in search paths, similar to that in shells. As a general example: ‘~$USER/{foo,bar}//baz’ expands to all subdirectories under directories foo and bar in $USER's home directory that contain a directory or file baz. These expansions are explained in the sections below.
If the highest-priority search path (see Path sources) contains an extra colon (i.e., leading, trailing, or doubled), Kpathsea inserts at that point the next-highest-priority search path that is defined. If that inserted path has an extra colon, the same happens with the next-highest. (An extra colon in the compile-time default value has unpredictable results, so installers beware.)
For example, given an environment variable setting
setenv TEXINPUTS /home/karl:
and a TEXINPUTS
value from texmf.cnf of
.:$TEXMF//tex
then the final value used for searching will be:
/home/karl:.:$TEXMF//tex
Put another way, default expansion works on “formats” (search paths), and not directly on environment variables. Example, showing the trailing ‘:’ ignored in the first case and expanded in the second:
$ env TTFONTS=/tmp: kpsewhich --expand-path '$TTFONTS' /tmp $ env TTFONTS=/tmp: kpsewhich --show-path=.ttf /tmp:.:/home/olaf/texmf/fonts/truetype//:...
Since Kpathsea looks for multiple configuration files, it would be natural to expect that (for example) an extra colon in ./texmf.cnf would expand to the path in $TEXMF/texmf.cnf. Or, with Dvips' configuration files, that an extra colon in config.$PRINTER would expand to the path in config.ps. This doesn't happen. It's not clear this would be desirable in all cases, and trying to devise a way to specify the path to which the extra colon should expand seemed truly baroque. Technicality: Since it would be useless to insert the default value in more than one place, Kpathsea changes only one extra ‘:’ and leaves any others in place (they will eventually be ignored). Kpathsea checks first for a leading ‘:’, then a trailing ‘:’, then a doubled ‘:’.
You can trace this by debugging “paths” (see Debugging). Default expansion is implemented in the source file kpathsea/kdefault.c.
‘$foo’ or ‘${foo}’ in a path element is replaced by (1) the value of an environment variable ‘foo’ (if defined); (2) the value of ‘foo’ from texmf.cnf (if defined); (3) the empty string.
If the character after the ‘$’ is alphanumeric or ‘_’, the variable name consists of all consecutive such characters. If the character after the ‘$’ is a ‘{’, the variable name consists of everything up to the next ‘}’ (braces may not be nested around variable names). Otherwise, Kpathsea gives a warning and ignores the ‘$’ and its following character.
You must quote the $'s and braces as necessary for your shell.
Shell variable values cannot be seen by Kpathsea, i.e., ones
defined by set
in C shells and without export
in Bourne
shells.
For example, given
setenv tex /home/texmf setenv TEXINPUTS .:$tex:${tex}prev
the final TEXINPUTS
path is the three directories:
.:/home/texmf:/home/texmfprev
The ‘.progname’ suffix on variables and ‘_progname’ on environment variable names are not implemented for general variable expansions. These are only recognized when search paths are initialized (see Path sources).
Variable expansion is implemented in the source file kpathsea/variable.c.
A leading ‘~’ in a path element is replaced by the value of the
environment variable HOME
, or . if HOME
is not
set. On Windows, the environment variable USERPROFILE
is
checked instead of HOME
.
A leading ‘~user’ in a path element is replaced by user's home directory from the system passwd database.
For example,
setenv TEXINPUTS ~/mymacros:
will prepend a directory mymacros in your home directory to the default path.
As a special case, if a home directory ends in ‘/’, the trailing slash is dropped, to avoid inadvertently creating a ‘//’ construct in the path. For example, if the home directory of the user ‘root’ is ‘/’, the path element ‘~root/mymacros’ expands to just ‘/mymacros’, not ‘//mymacros’.
Tilde expansion is implemented in the source file kpathsea/tilde.c.
‘x{a,b}y’ expands to ‘xay:xby’. For example:
foo/{1,2}/baz
expands to ‘foo/1/baz:foo/2/baz’. ‘:’ is the path separator on the current system; e.g., on a DOS system, it's ‘;’.
Braces can be nested; for example, ‘x{A,B{1,2}}y’ expands to ‘xAy:xB1y:xB2y’.
Multiple non-nested braces are expanded from right to left; for example, ‘x{A,B}{1,2}y’ expands to ‘x{A,B}1y:x{A,B}2y’, which expands to ‘xA1y:xB1y:xA2y:xB2y’.
This feature can be used to implement multiple TeX hierarchies, by
assigning a brace list to $TEXMF
, as mentioned in
texmf.in.
You can also use the path separator instead of the comma. The last example could have been written ‘x{A:B}{1:2}y’.
Brace expansion is implemented in the source file kpathsea/expand.c.
KPSE_DOT
expansion
When KPSE_DOT
is defined in the environment, it names a directory
that should be considered the current directory for the purpose of
looking up files in the search paths. This feature is needed by the
‘mktex...’ scripts mktex scripts, because these
change the working directory. You should not ever define it yourself.
Two or more consecutive slashes in a path element following a directory d is replaced by all subdirectories of d: first those subdirectories directly under d, then the subsubdirectories under those, and so on. At each level, the order in which the directories are searched is unspecified. (It's “directory order”, and definitely not alphabetical.)
If you specify any filename components after the ‘//’, only subdirectories which match those components are included. For example, ‘/a//b’ would expand into directories /a/1/b, /a/2/b, /a/1/1/b, and so on, but not /a/b/c or /a/1.
You can include multiple ‘//’ constructs in the path.
‘//’ at the beginning of a path is ignored; you didn't really want to search every directory on the system, did you?
I should mention one related implementation trick, which I took from GNU find. Matthew Farwell suggested it, and David MacKenzie implemented it.
The trick is that in every real Unix implementation (as opposed to the
POSIX specification), a directory which contains no subdirectories will
have exactly two links (namely, one for . and one for ..).
That is to say, the st_nlink
field in the ‘stat’ structure
will be two. Thus, we don't have to stat everything in the bottom-level
(leaf) directories—we can just check st_nlink
, notice it's two,
and do no more work.
But if you have a directory that contains a single subdirectory and 500
regular files, st_nlink
will be 3, and Kpathsea has to stat every
one of those 501 entries. Therein lies slowness.
You can disable the trick by undefining ST_NLINK_TRICK
in
kpathsea/config.h. (It is undefined by default except under Unix.)
Unfortunately, in some cases files in leaf directories are
stat
'd: if the path specification is, say,
‘$TEXMF/fonts//pk//’, then files in a subdirectory
‘.../pk’, even if it is a leaf, are checked. The reason cannot
be explained without reference to the implementation, so read
kpathsea/elt-dirs.c (search for ‘may descend’) if you are
curious. And if you can find a way to solve the problem, please
let me know.
Subdirectory expansion is implemented in the source file kpathsea/elt-dirs.c.
ls-R
)Kpathsea goes to some lengths to minimize disk accesses for searches (see Subdirectory expansion). Nevertheless, in practice searching each possible directory in typical TeX installations takes an excessively long time.
Therefore, Kpathsea can use an externally-built filename database file named ls-R that maps files to directories, thus avoiding the need to exhaustively search the disk.
A second database file aliases allows you to give additional names to the files listed in ls-R. This can be helpful to adapt to “8.3” filename conventions in source files.
The ls-R and aliases features are implemented in the source file kpathsea/db.c.
As mentioned above, you must name the main filename database
ls-R. You can put one at the root of each TeX installation
hierarchy you wish to search ($TEXMF
by default); most sites have
only one hierarchy. Kpathsea looks for ls-R files along the
TEXMFDBS
path, so that should presumably match the list of
hierarchies.
The recommended way to create and maintain ‘ls-R’ is to run the
mktexlsr
script, which is installed in ‘$(bindir)’
(/usr/local/bin by default). That script goes to some trouble to
follow symbolic links as necessary, etc. It's also invoked by the
distributed ‘mktex...’ scripts.
At its simplest, though, you can build ls-R with the command
cd /your/texmf/root && ls -LAR ./ >ls-R
presuming your ls
produces the right output format (see the
section below). GNU ls
, for example, outputs in this format.
Also presuming your ls
hasn't been aliased in a system file
(e.g., /etc/profile) to something problematic, e.g., ‘ls
--color=tty’. In that case, you will have to disable the alias before
generating ls-R. For the precise definition of the file format,
see Database format.
Regardless of whether you use the supplied script or your own, you will
almost certainly want to invoke it via cron
, so when you make
changes in the installed files (say if you install a new LaTeX
package), ls-R will be automatically updated.
The ‘-A’ option to ls
includes files beginning with ‘.’
(except for . and ..), such as the file .tex
included with the LaTeX tools package. (On the other hand,
directories whose names begin with ‘.’ are always ignored.)
If your system does not support symbolic links, omit the ‘-L’.
ls -LAR
/your/texmf/root will also work. But using
‘./’ avoids embedding absolute pathnames, so the hierarchy can be
easily transported. It also avoids possible trouble with automounters
or other network filesystem conventions.
Kpathsea warns you if it finds an ls-R file, but the file does not contain any usable entries. The usual culprit is running plain ‘ls -R’ instead of ‘ls -LR ./’ or ‘ls -R /your/texmf/root’. Another possibility is some system directory name starting with a ‘.’ (perhaps if you are using AFS); Kpathsea ignores everything under such directories.
Because the database may be out-of-date for a particular run, if a file
is not found in the database, by default Kpathsea goes ahead and
searches the disk. If a particular path element begins with ‘!!’,
however, only the database will be searched for that element,
never the disk. If the database does not exist, nothing will be
searched. Because this can surprise users (“I see the font
foo.tfm when I do an ls
; why can't Dvips find it?”), it
is not in any of the default search paths.
In some circumstances, you may wish to find a file under several names. For example, suppose a TeX document was created using a DOS system and tries to read longtabl.sty. But now it's being run on a Unix system, and the file has its original name, longtable.sty. The file won't be found. You need to give the actual file longtable.sty an alias ‘longtabl.sty’.
You can handle this by creating a file aliases as a companion to the ls-R for the hierarchy containing the file in question. (You must have an ls-R for the alias feature to work.)
The format of aliases is simple: two whitespace-separated words per line; the first is the real name longtable.sty, and second is the alias (longtabl.sty). These must be base filenames, with no directory components. longtable.sty must be in the sibling ls-R.
Also, blank lines and lines starting with ‘%’ or ‘#’ are ignored in aliases, to allow for comments.
If a real file longtabl.sty exists, it is used regardless of any aliases.
The “database” read by Kpathsea is a line-oriented file of plain
text. The format is that generated by GNU (and most other) ls
programs given the ‘-R’ option, as follows.
For example, here's the first few lines of ls-R (which totals about 30K bytes) on my system:
bibtex dvips fonts ls-R metafont metapost tex web2c ./bibtex: bib bst doc ./bibtex/bib: asi.bib btxdoc.bib ...
kpsewhich
: Standalone path searching
The Kpsewhich program exercises the path searching functionality
independent of any particular application. This can also be useful as a
sort of find
program to locate files in your TeX hierarchies,
perhaps in administrative scripts. It is used heavily in the
distributed ‘mktex...’ scripts.
Synopsis:
kpsewhich option... filename...
The options and filename(s) to look up can be intermixed. Options can start with either ‘-’ or ‘--’, and any unambiguous abbreviation is accepted.
Kpsewhich looks up each non-option argument on the command line as a filename, and returns the first file found.
Various options alter the path searching behavior:
In particular, since the memory dump files
(.fmt/.base/.mem) are now stored in
subdirectories named for the engine (tex, pdftex,
xetex, etc.), you must specify an engine name in order to find
them. For example, cont-en.fmt typically exists for both
pdftex and xetex. With the default path settings, you
can use ‘--engine=/’ to look for any dump file, regardless of
engine; if a dump file exists for more than one engine, it's
indeterminate which one is returned. (The ‘/’ ends up specifying
a normal recursive search along the path where the dumps are stored,
namely ‘$TEXMF/web2c{/$engine,}’.)
All formats also have a name, which is the only way to specify formats with no associated suffix. For example, for Dvips configuration files you can use ‘--format="dvips config"’. (The quotes are for the sake of the shell.)
Here's the current list of recognized names and the associated suffixes. See Supported file formats, for more information on each of these.
The strings in parentheses are abbreviations recognized only by
kpsewhich
(not the underlying library calls). They are
provided when it would otherwise require an argument containing a
space to specify the format, to simplify quoting of calls from shells.
gf: gf pk: pk bitmap font (bitmapfont): tfm: .tfm afm: .afm base: .base bib: .bib bst: .bst cnf: .cnf ls-R: ls-R ls-r fmt: .fmt map: .map mem: .mem mf: .mf mfpool: .pool mft: .mft mp: .mp mppool: .pool MetaPost support (mpsupport): ocp: .ocp ofm: .ofm .tfm opl: .opl .pl otp: .otp ovf: .ovf .vf ovp: .ovp .vpl graphic/figure: .eps .epsi tex: .tex .sty .cls .fd .aux .bbl .def .clo .ldf TeX system documentation (doc): texpool: .pool TeX system sources (source): .dtx .ins PostScript header: .pro Troff fonts (trofffont): type1 fonts: .pfa .pfb vf: .vf dvips config (dvipsconfig): ist: .ist truetype fonts: .ttf .ttc .TTF .TTC .dfont type42 fonts: .t42 .T42 web2c files (web2c): other text files (othertext): other binary files (otherbin): misc fonts (miscfont): web: .web .ch cweb: .w .web .ch enc files: .enc cmap files (cmap): subfont definition files: .sfd opentype fonts: .otf pdftex config (pdftexconfig): lig files: .lig texmfscripts: lua: .luc .luctex .texluc .lua .luatex .texlua font feature files: .fea cid maps: .cid .cidmap mlbib: .mlbib .bib mlbst: .mlbst .bst clua: .dll .so ris: .ris bltxml: .bltxml
This option and ‘--path’ are mutually exclusive.
--must-exist
. See mktex scripts.
kpsewhich foo.sty ⇒ /some/where/foo.sty /another/place/foo.sty
Then we can narrow the result to what we are interested in with --subdir:
kpsewhich --subdir=where foo.sty ⇒ /some/where/foo.sty kpsewhich --subdir=place foo.sty ⇒ /another/place/foo.sty
The string to match must be at the end of the directory part of the match, and it is taken literally, with no pattern matching:
kpsewhich --subdir=another foo.sty ⇒
The string to match may cross directory components:
kpsewhich --subdir=some/where foo.sty ⇒ /some/where/foo.sty
--subdir implies --all; if there is more than one match, they will all be reported (in our example, both ‘where’ and ‘place’ end in ‘e’):
kpsewhich --subdir=e ⇒ /some/where/foo.sty /another/place/foo.sty
Because of the above rules, the presence of a leading ‘/’ is important, since it “anchors” the match to a full component name:
kpsewhich --subdir=/lace foo.sty ⇒
However, a trailing ‘/’ is immaterial (and ignored), since the match always takes place at the end of the directory part:
kpsewhich --subdir=lace/ foo.sty ⇒ /another/place/foo.sty
The purpose of these rules is to make it convenient to find results only within a particular area of the tree. For instance, a given script named foo.lua might exist within both texmf-dist/scripts/pkg1/ and texmf-dist/scripts/pkg2/. By specifying, say, ‘--subdir=/pkg1’, you can be sure of getting the one you are interested in.
We only match at the end because a site might happen to install TeX in /some/coincidental/pkg1/path/, and we wouldn't want to match texmf-dist/scripts/pkg2/ that when searching for ‘/pkg1’.
kpsewhich recognizes a few special filenames on the command line and defaults to using the `known' file formats for them, merely to save the time and trouble of specifying the format. This is only a feature of kpsewhich; when using the Kpathsea library itself, none of these special filenames are recognized, and it's still up to the caller to specify the desired format.
Here is the list of special filenames to kpsewhich, along with their corresponding format:
dvips config
A user-specified format will override the above defaults.
Another useful configuration file in this regard is tcfmgr.map, found in texmf/texconfig/tcfmgr.map, which records various information about the above configuration files (among others).
Kpsewhich provides some additional features not strictly related to path lookup:
Nonexistent directories are culled from the output:
$ kpsewhich --expand-path '/tmp' ⇒ /tmp $ kpsewhich --expand-path '/nonesuch' ⇒
For one-shot uses of an arbitrary (not built in to Kpathsea) path, see ‘--path’ in the previous section.
Kpsewhich accepts the standard GNU options:
Although the basic features in Kpathsea can be used for any type of path searching, it came about (like all libraries) with a specific application in mind: I wrote Kpathsea specifically for TeX system programs. I had been struggling with the programs I was using (Dvips, Xdvi, and TeX itself) having slightly different notions of how to specify paths; and debugging was painful, since no code was shared.
Therefore, Kpathsea provides some TeX-specific formats and features. Indeed, many of the supposedly generic path searching features were provided because they seemed useful in that conTeXt (font lookup, particularly).
Kpathsea provides a standard way to search for files of any of the supported file types; glyph fonts are a bit different than all the rest. Searches are based solely on filenames, not file contents—if a GF file is named cmr10.600pk, it will be found as a PK file.
Kpathsea has support for a number of file types. Each file type has a list of environment and config file variables that are checked to define the search path, and most have a default suffix that plays a role in finding files (see the next section). Some also define additional suffixes, and/or a program to be run to create missing files on the fly.
Since environment variables containing periods, such as ‘TEXINPUTS.latex’, are not allowed on some systems, Kpathsea looks for environment variables with an underscore, e.g., ‘TEXINPUTS_latex’ (see Config files).
The following table lists the above information.
AFMFONTS
;
suffix ‘.afm’.
MFBASES
, TEXMFINI
;
suffix ‘.base’.
BIBINPUTS
, TEXBIB
;
suffix ‘.bib’.
BSTINPUTS
;
suffix ‘.bst’.
CMAPFONTS
;
suffix ‘.cmap’.
TEXMFCNF
;
suffix ‘.cnf’.
CWEBINPUTS
;
suffixes ‘.w’, ‘.web’;
additional suffix ‘.ch’.
TEXCONFIG
.
ENCFONTS
;
suffix ‘.enc’.
TEXFORMATS
, TEXMFINI
;
suffix ‘.fmt’.
FONTCIDMAPS
suffix ‘.cid’.
FONTFEATURES
suffix ‘.fea’.
FONTS
, GFFONTS
, GLYPHFONTS
, TEXFONTS
;
suffix ‘gf’.
TEXPICTS
, TEXINPUTS
;
additional suffixes: ‘.eps’, ‘.epsi’.
TEXINDEXSTYLE
, INDEXSTYLE
;
suffix ‘.ist’.
LIGFONTS
;
suffix ‘.lig’.
TEXMFDBS
.
TEXFONTMAPS
;
suffix ‘.map’.
MPMEMS
, TEXMFINI
;
suffix ‘.mem’.
MPSUPPORT
.
MFINPUTS
;
suffix ‘.mf’;
dynamic creation program: mktexmf
.
MFPOOL
, TEXMFINI
;
suffix ‘.pool’.
MFT
style file, see mft invocation)
MFTINPUTS
;
suffix ‘.mft’.
MISCFONTS
MLBIBINPUTS
, BIBINPUTS
, TEXBIB
;
suffixes ‘.mlbib’, ‘.mlbib’.
MLBSTINPUTS
, BSTINPUTS
;
suffixes ‘.mlbst’, ‘.bst’.
MPINPUTS
;
suffix ‘.mp’.
MPPOOL
, TEXMFINI
;
suffix ‘.pool’.
OCPINPUTS
; MakeOmegaOCP
.
OFMFONTS
, TEXFONTS
; MakeOmegaOFM
.
OPENTYPEFONTS
.
OPLFONTS
, TEXFONTS
;
suffix ‘.opl’.
OTPINPUTS
;
suffix ‘.otp’.
OVFFONTS
, TEXFONTS
;
suffix ‘.ovf’.
OVPFONTS
, TEXFONTS
;
suffix ‘.ovp’.
PDFTEXCONFIG
.
FONTS
(program being ‘XDVI’, etc.),
PKFONTS
, TEXPKS
, GLYPHFONTS
, TEXFONTS
;
suffix ‘pk’;
dynamic creation program: mktexpk
.
TEXPSHEADERS
, PSHEADERS
;
additional suffix ‘.pro’.
SFDFONTS
suffix ‘.sfd’.
TEXINPUTS
;
suffix ‘.tex’;
additional suffixes: none, because such a list cannot be complete;
dynamic creation program: mktextex
.
TEXDOCS
.
TEXSOURCES
.
TEXMFSCRIPTS
.
TEXPOOL
, TEXMFINI
;
suffix ‘.pool’.
TFMFONTS
, TEXFONTS
;
suffix ‘.tfm’;
dynamic creation program: mktextfm
.
TRFONTS
.
TTFONTS
; suffixes ‘.ttf’ and
‘.TTF’, ‘.ttc’ and ‘.TTC’, ‘.dfont’.
T1FONTS
, T1INPUTS
, TEXPSHEADERS
, DVIPSHEADERS
;
suffixes ‘.pfa’, ‘.pfb’.
T42FONTS
.
VFFONTS
, TEXFONTS
;
suffix ‘.vf’.
WEBINPUTS
;
suffix ‘.web’;
additional suffix ‘.ch’.
WEB2C
.
There are two special cases, because the paths and environment variables always depend on the name of the program: the variable name is constructed by converting the program name to upper case, and then appending ‘INPUTS’. Assuming the program is called ‘foo’, this gives us the following table.
FOOINPUTS
.
FOOINPUTS
.
If an environment variable by these names are set, the corresponding texmf.cnf definition won't be looked at (unless, as usual, the environment variable value has an extra ‘:’). See Default expansion.
For the font variables, the intent is that:
TEXFONTS
is the default for everything.
GLYPHFONTS
is the default for bitmap (or, more precisely,
non-metric) files.
DVIPSFONTS
for Dvipsk. Again, this is for bitmaps, not metrics.
This section describes how Kpathsea searches for most files (bitmap font searches are the exception, as described in the next section).
Here is the search strategy for a file name:
The order in which we search for “suffixed” name (item 1) or the “as-is” name (item 2) is controlled by the try_std_extension_first configuration value. The default set in texmf.cnf is true, since common suffixes are already recognized: ‘babel.sty’ will only look for ‘babel.sty’, not ‘babel.sty.tex’, regardless of this setting.
When the suffix is unknown (e.g., ‘foo.bar’), both names are always tried; the difference is the order in which they are tried.
try_std_extension_first only affects names being looked up which *already* have an extension. A name without an extension (e.g., ‘tex story’) will always have an extension added first.
This algorithm is implemented in the function
kpathsea_find_file
in the source file
kpathsea/tex-file.c. You can watch it in action with the
debugging options (see Debugging).
This section describes how Kpathsea searches for a bitmap font in GF or PK format (or either) given a font name (e.g., ‘cmr10’) and a resolution (e.g., 600).
Here is an outline of the search strategy (details in the sections below) for a file name at resolution dpi. The search stops at the first successful lookup.
This is implemented in kpathsea_find_glyph
in
kpathsea/tex-glyph.c.
When Kpathsea looks for a bitmap font name at resolution dpi in a format format, it first checks each directory in the search path for a file ‘name.dpiformat’; for example, ‘cmr10.600pk’. Kpathsea looks for a PK file first, then a GF file.
If that fails, Kpathsea looks for ‘dpidpi/name.format’; for example, ‘dpi600/cmr10.pk’. This is how fonts are typically stored on filesystems (such as DOS) that permit only three-character extensions.
If that fails, Kpathsea looks for a font with a close-enough dpi.
“Close enough” is defined by the macro KPSE_BITMAP_TOLERANCE
in
kpathsea/tex-glyph.h to be dpi / 500 + 1
. This is
slightly more than the 0.2% minimum allowed by the DVI standard
(CTAN:/dviware/driv-standard/level-0).
If a bitmap font or metric file is not found with the original name (see
the previous section), Kpathsea looks through any fontmap files
for an alias for the original font name. These files are named
texfonts.map and searched for along the TEXFONTMAPS
environment/config file variable. All texfonts.map files that
are found are read; earlier definitions override later ones.
This feature is intended to help in two respects:
The format of fontmap files is straightforward:
If an alias has an extension, it matches only those files with that extension; otherwise, it matches anything with the same root, regardless of extension. For example, an alias ‘foo.tfm’ matches only when foo.tfm is being searched for; but an alias ‘foo’ matches foo.vf, foo.600pk, etc.
As an example, here is an excerpt from the texfonts.map in the Web2c distribution. It makes the circle fonts equivalent and includes automatically generated maps for most PostScript fonts available from various font suppliers.
circle10 lcircle10 circle10 lcirc10 lcircle10 circle10 lcircle10 lcirc10 lcirc10 circle10 lcirc10 lcircle10 ... include adobe.map include apple.map include bitstrea.map ...
Fontmaps are implemented in the file kpathsea/fontmap.c. The Fontname distribution has much more information on font naming (see Introduction).
If a bitmap font cannot be found or created at the requested size,
Kpathsea looks for the font at a set of fallback resolutions. You
specify these resolutions as a colon-separated list (like search paths).
Kpathsea looks first for a program-specific environment variable (e.g.,
DVIPSSIZES
for Dvipsk), then the environment variable
TEXSIZES
, then a default specified at compilation time (the Make
variable default_texsizes
). You can set this list to be empty if
you prefer to find fonts at their stated size or not at all.
Finally, if the font cannot be found even at the fallback resolutions,
Kpathsea looks for a fallback font, typically cmr10. Programs
must enable this feature by calling kpathsea_init_prog
(see Calling sequence); the default is no fallback font.
Kpathsea provides a way to suppress selected usually-harmless warnings;
this is useful at large sites where most users are not administrators,
and thus the warnings are merely a source of confusion, not a help. To
do this, you set the environment variable or configuration file value
TEX_HUSH
to a colon-separated list of values. Here are the
possibilities:
tex-hush.c defines the function that checks the variable value. Each driver implements its own checks where appropriate.
This chapter is for programmers who wish to use Kpathsea. See Introduction, for the conditions under which you may do so.
Aside from this manual, your best source of information is the source to the programs that use Kpathsea (see Introduction). Of those, Dviljk is probably the simplest, and hence a good place to start. Xdvik adds VF support and the complication of X resources. Dvipsk adds the complication of its own config files. Web2c is source code I also maintain, so it uses Kpathsea rather straightforwardly, but is of course complicated by the Web to C translation. Finally, Kpsewhich is a small utility program whose sole purpose is to exercise the main path-searching functionality.
When looking at these program sources, you should know that previous
versions of the library had a different programming interface, to
support re-entrancy. In that interface the library function names
were prefixed with kpse_
instead of kpathsea_
, and they
did not need an instance variable as first argument. This change was
made in 2009. Some of the programs mentioned above may still be using
the previous interface.
Beyond these examples, the .h files in the Kpathsea source
describe the interfaces and functionality (and of course the .c
files define the actual routines, which are the ultimate documentation).
pathsearch.h declares the basic searching routine.
tex-file.h and tex-glyph.h define the interfaces for
looking up particular kinds of files. In view of the way the headers
depend on each other, it is recommended to use #include
<kpathsea/kpathsea.h>
, which includes every Kpathsea header.
If you want to include only specific headers, you should still consider including kpathsea/config.h before including any other Kpathsea header, as it provides symbols used in the other headers. Note that kpathsea/config.h includes kpathsea/c-auto.h, which is generated by Autoconf.
The library provides no way for an external program to register new file types: tex-file.[ch] must be modified to do this. For example, Kpathsea has support for looking up Dvips config files, even though no program other than Dvips will likely ever want to do so. I felt this was acceptable, since along with new file types should also come new defaults in texmf.cnf (and its descendant paths.h), since it's simplest for users if they can modify one configuration file for all kinds of paths.
Kpathsea does not parse any formats itself; it barely opens any files. Its primary purpose is to return filenames. The GNU font utilities does contain libraries to read TFM, GF, and PK files, as do the programs above, of course.
The typical way to use Kpathsea in your program goes something like this:
kpathsea_new
to create a new library instance. This variable
must be passed as the first argument to all the following library functions.
The rest of this manual will be using kpse
as a placeholder for
the name of this variable.
kpathsea_set_program_name
with argv[0]
as the second
argument; the third argument is a string or NULL
. The third
argument is used by Kpathsea as the program name for the
.
program feature of config files (see Config files).
If the third argument is NULL
, the value of the second argument
is used. This function must be called before any other use of the
Kpathsea library.
kpathsea_set_program_name
always sets the variables
kpse->invocation_name
and kpse->invocation_short_name
.
These variables are used in the error message macros defined in
kpathsea/lib.h. It sets the variable
kpse->program_name
to the program name it uses.
It also initializes debugging options based on the environment
variable KPATHSEA_DEBUG
(if that is set).
Finally, it sets the environment variables SELFAUTOLOC
, SELFAUTODIR
and SELFAUTOPARENT
to the location, parent and grandparent
directory of the executable, removing . and .. path
elements and resolving symbolic links. These are used in the default
configuration file to allow people to invoke TeX from anywhere. You
can use ‘kpsewhich --expand-var=\$SELFAUTOLOC’, etc., to see the
values.
kpse->debug
to the number that the user supplies (as in Dviljk
and Web2c), or you can just omit this altogether (people can always set
KPATHSEA_DEBUG
). If you do have runtime debugging already, you
need to merge Kpathsea's options with yours (as in Dvipsk and Xdvik).
client_path
member in
the appropriate element of the kpse->format_info
array. (This
array is indexed by file type; see tex-file.h.) See
resident.c in Dvipsk for an example.
kpathsea_init_prog
(see proginit.c). It's useful for the
DVI drivers, at least, but for other programs it may be simpler to
extract the parts of it that actually apply. This does not initialize
any paths, it just looks for (and sets) certain environment variables
and other random information. (A search path is always initialized at
the first call to find a file of that type; this eliminates much useless
work, e.g., initializing the BibTeX search paths in a DVI driver.)
kpathsea_find_file
after doing only the first and second of the
initialization steps above—Kpathsea automatically reads the
texmf.cnf generic config files, looks for environment variables,
and does expansions at the first lookup.
kpathsea_find_glyph
, defined in
tex-glyph.h. This returns a structure in addition to the
resultant filename, because fonts can be found in so many ways. See the
documentation in the source.
kpathsea_open_file
. This function takes the name to look up and a
Kpathsea file format as arguments, and returns the usual FILE *
.
It always assumes the file must exist, and thus will search the disk if
necessary (unless the search path specified ‘!!’, etc.). In other
words, if you are looking up a VF or some other file that need not
exist, don't use this.
\openout
primitive; this opens
a security hole vulnerable to Trojan horse attack: an unwitting user could
run a TeX program that overwrites, say, ~/.rhosts. Analogous
security holes exist for many other programs. To alleviate this, there is a
configuration variable openout_any
, which selects one of three levels
of security. When it is set to ‘a’ (for “any”), no restrictions are
imposed. When it is set to ‘r’ (for “restricted”), filenames
beginning with ‘.’ are disallowed (except .tex because LaTeX
needs it). When it is set to ‘p’ (for “paranoid”) additional
restrictions are imposed: an absolute filename must refer to a file in (a
subdirectory) of TEXMFOUTPUT
, and any attempt to go up a directory
level is forbidden (that is, paths may not contain a ‘..’ component).
The paranoid setting is the default. (For backwards compatibility, ‘y’
and ‘1’ are synonyms of ‘a’, while ‘n’ and ‘0’ are
synonyms for ‘r’.) The function kpathsea_out_name_ok
, with a
filename as second argument, returns true
if that filename is
acceptable to be opend for output or false
otherwise.
kpathsea_in_name_ok
, with a filename as
second argument, returns true
if that filename is acceptable to be
opend for input or false
otherwise, depending on the value of the
configuration variable openin_any
(with ‘a’ as default).
kpathsea_finish
. This function closes any open log files and
frees the memory used by the instance.
Kpathsea also provides many utility routines. Some are generic: hash
tables, memory allocation, string concatenation and copying, string
lists, reading input lines of arbitrary length, etc. Others are
filename-related: default path, tilde, and variable expansion,
stat
calls, etc. (Perhaps someday I'll move the former to a
separate library.)
The c-*.h header files can also help your program adapt to many different systems. You will almost certainly want to use Autoconf and probably Automake for configuring and building your software if you use Kpathsea; I strongly recommend using Autoconf and Automake regardless. They are available from ftp://ftp.gnu.og/pub/gnu/.
Many programs will need to find some configuration files. Kpathsea contains some support to make it easy to place them in their own directories. The Standard TeX directory structure (see Introduction), specifies that such files should go into a subdirectory named after the program, like ‘texmf/ttf2pk’.
Two formats, ‘kpse_program_text_format’ and
‘kpse_program_binary_format’, use .:$TEXMF/
program//
as their compiled-in search path. To override this default, you can
use the variable PROGRAMINPUTS
in the environment and/or
‘texmf.cnf’. That is to say, the name of the variable is
constructed by converting the name of the program to upper case, and
appending INPUTS
.
The only difference between these two formats is whether
kpathsea_open_file
will open the files it finds in text or binary
mode.
You can (and probably should) use the same texmf.cnf
configuration file that Kpathsea uses for your program. This helps
installers by keeping all configuration in one place.
To retrieve a value var from config files, the best way is to call
kpathsea_var_value
on the string var. This will look
first for an environment variable var, then a config file value.
The result will be the value found or ‘NULL’. This function is
declared in kpathsea/variable.h. For an example, see the
shell_escape
code in web2c/lib/texmfmp.c.
The routine to do variable expansion in the context of a search path (as
opposed to simply retrieving a value) is kpathsea_var_expand
, also
declared in kpathsea/variable.h. It's generally only necessary
to set the search path structure components as explained in the previous
section, rather than using this yourself.
If for some reason you want to retrieve a value only from a
config file, not automatically looking for a corresponding environment
variable, call kpathsea_cnf_get
(declared in kpathsea/cnf.h)
with the string var.
No initialization calls are needed.
!!
in path specifications: ls-R$
expansion: Variable expansion--all
: Path searching options--color=tty
: ls-R--debug=
num: Auxiliary tasks--disable-static
: configure options--dpi=
num: Path searching options--enable
options: configure options--enable-maintainer-mode
: configure options--enable-shared
: Shared library--enable-shared
: configure options--engine=
name: Path searching options--expand-braces=
string: Auxiliary tasks--expand-path=
string: Auxiliary tasks--expand-var=
string: Auxiliary tasks--format=
name: Path searching options--help
: Standard options--interactive
: Path searching options--mktex=
filetype: Path searching options--mode=
string: Path searching options--must-exist
: Path searching options--no-mktex=
filetype: Path searching options--path=
string: Path searching options--progname=
name: Path searching options--safe-in-name=
name: Path searching options--safe-out-name=
name: Path searching options--show-path=
name: Auxiliary tasks--srcdir
, for building multiple architectures: configure scenarios--subdir=
string: Path searching options--var-value=
variable: Auxiliary tasks--version
: Standard options--with
options: configure options--with-mktextex-default
: mktex configuration--without-mktexfmt-default
: mktex configuration--without-mktexmf-default
: mktex configuration--without-mktexocp-default
: mktex configuration--without-mktexofm-default
: mktex configuration--without-mktexpk-default
: mktex configuration--without-mktextfm-default
: mktex configuration-1
debugging value: Debugging-A
option to ls
: ls-R-Bdynamic
: ShellWidgetClass-Bstatic
: ShellWidgetClass-D
num: Path searching options-dynamic
: ShellWidgetClass-g
, compiling without: configure scenarios-L
option to ls
: ls-R-O
, compiling with: configure scenarios-static
: ShellWidgetClass.
directories, ignored: ls-R.
files: ls-R.2602gf
: Unable to generate fonts.afm
: Supported file formats.base
: Supported file formats.bib
: Supported file formats.bst
: Supported file formats.cid
: Supported file formats.cmap
: Supported file formats.cnf
: Supported file formats.enc
: Supported file formats.eps
: Supported file formats.epsi
: Supported file formats.fea
: Supported file formats.fmt
: Supported file formats.ist
: Supported file formats.lig
: Supported file formats.map
: Supported file formats.mem
: Supported file formats.mf
: Supported file formats.mft
: Supported file formats.mlbib
: Supported file formats.mlbst
: Supported file formats.mp
: Supported file formats.ocp
: Supported file formats.ofm
: Supported file formats.opl
: Supported file formats.otp
: Supported file formats.ovf
: Supported file formats.ovp
: Supported file formats.pfa
: Supported file formats.pfb
: Supported file formats.pk
: Supported file formats.pool
: Supported file formats.pro
: Supported file formats.rhosts
, writable by TeX: Security.sfd
: Supported file formats.tex
: Supported file formats.tex
file, included in ls-R: ls-R.tfm
: Supported file formats.ttc
: Supported file formats.ttf
: Supported file formats.vf
: Supported file formats.w
: Supported file formats.web
: Supported file formats/
may not be /: Searching overview/
, trailing in home directory: Tilde expansion//
: Subdirectory expansion/afs/...
, installing into: Installing files/etc/profile
: Unable to find files/etc/profile
and aliases: ls-R/var/tmp/texfonts
: mktex configuration2602gf
: Unable to generate fonts:
may not be :: Searching overview::
expansion: Default expansion\
, line continuation in texmf.cnf: Config files\openin
: Searching overview\special
, suppressing warnings about: Suppressing warningsac_include
, Autoconf extension: Running configureAFMFONTS
: Supported file formatsconfigure
error: Empty Makefilesconfigure
: configure shellsall
: Suppressing warningsmktexpk
: Securityappendonlydir
: mktex configurationargv[0]
: Calling sequenceash
, losing with configure
: configure shellsautoconf
, recommended: Calling sequencebash
, recommended for running configure
: configure shellsBIBINPUTS
: Supported file formatsbsh
, ok with configure
: configure shellsBSTINPUTS
: Supported file formatsc-*.h
: Calling sequencec-auto.h
: Programming overviewc-auto.in
: Running configureCC
: configure environmentcc
warnings: Pointer combination warningscc
, compiling with: configure environmentCFLAGS
: configure environmentChangeLog
entry: Bug checklistchecksum
: Suppressing warningsclean
Make target: Cleaning upclient_path
in kpse->format_info
: Calling sequenceCMAPFONTS
: Supported file formatscmr10
, as fallback font: Fallback fontcmr10.vf
: Searching overviewcnf.c
: Config filescnf.h
: Programming with config filescomp.sys.sun.admin
FAQ: ShellWidgetClasscomp.text.tex
: Mailing listsconfig.h
: Programming overviewconfig.log
: Bug checklistconfig.ps
: Specially-recognized filesconfig.ps
, search path for: Supported file formatsconfig.status
: Bug checklistconfigure
error from sed
: Empty Makefilesconfigure
options: configure optionsconfigure
options for mktex scripts: mktex configurationconfigure
, running: Running configureCPPFLAGS
: configure environmentCWEBINPUTS
: Supported file formatsdebug.h
: Debuggingconfigure
: configure shellsdefault_texsizes
: Fallback fontDEFS
: configure environmentdepot
: configure scenariosdistclean
Make target: Cleaning updlclose
: dlopendlopen
: dlopendlsym
: dlopendlsym.c
: dlopendoc files
: Supported file formatsdosnames
: mktex configurationdpi
nnn directories
: mktex configurationDVILJMAKEPK
: mktex script namesDVILJSIZES
: Fallback fontdvipdfmx.cfg
: Specially-recognized filesDVIPSFONTS
: Supported file formatsDVIPSHEADERS
: Supported file formatsDVIPSMAKEPK
: mktex script namesDVIPSSIZES
: Fallback fontelt-dirs.c
: Subdirectory expansionENCFONTS
: Supported file formatsexpand.c
: Brace expansionextraclean
Make target: Cleaning upmktex...
script invocation: mktex script namesfmtutil
: mktex script namesfmtutil.cnf
: Specially-recognized filesfmtutils.cnf
: mktex configurationFONTCIDMAPS
: Supported file formatsFONTFEATURES
: Supported file formatsfontmaps
: mktex configurationFOOINPUTS
: Supported file formatsfopen
, redefined: Debuggingconfigure
error: Empty Makefilesconfigure
: configure shellsftp.cs.stanford.edu
: unixtex.ftpftp.tug.org
: unixtex.ftpgcc
, compiling with: configure environmentgdb
, recommended: Bug checklistget_applicationShellWidgetClass
: ShellWidgetClassget_wmShellWidgetClass
: ShellWidgetClassgf
: Supported file formatsGFFONTS
: Supported file formatsGLYPHFONTS
: Supported file formatsglyphlist.txt
: Specially-recognized filesGSFTOPK_DEBUG
(128): Debugginghash_summary_only
variable for debugging: DebuggingHOME
, as ~ expansion: Tilde expansioninclude
fontmap directive: FontmapINDEXSTYLE
: Supported file formatsinfo-tex@shsu.edu
: Mailing listsinstall-data
Make target: Installing filesinstall-exec
Make target: Installing fileskdefault.c
: Default expansionconfigure
: configure shellskpathsae_var_value
: Programming with config fileskpathsea.h
: Programming overviewkpathsea/README.CONFIGURE
: Running configurekpathsea_cnf_get
: Programming with config filesKPATHSEA_DEBUG
: Calling sequenceKPATHSEA_DEBUG
: Debuggingkpathsea_find_file
: Calling sequencekpathsea_find_file
: File lookupkpathsea_find_glyph
: Glyph lookupkpathsea_finish
: Calling sequencekpathsea_in_name_ok
: Calling sequencekpathsea_init_prog
: Calling sequencekpathsea_init_prog
: Fallback fontkpathsea_new
: Calling sequencekpathsea_open_file
: Calling sequencekpathsea_out_name_ok
: Calling sequencekpathsea_set_program_name
: Calling sequenceKPATHSEA_WARNING
: Config fileskpse->debug
: Debuggingkpse->debug
variable: Calling sequencekpse->format_info
: Calling sequencekpse->invocation_name
: Calling sequencekpse->invocation_short_name
: Calling sequencekpse->program_name
: Calling sequenceKPSE_BITMAP_TOLERANCE
: Basic glyph lookupKPSE_DEBUG_EXPAND
(16): DebuggingKPSE_DEBUG_FOPEN
(4): DebuggingKPSE_DEBUG_HASH
(2): DebuggingKPSE_DEBUG_PATHS
(8): DebuggingKPSE_DEBUG_SEARCH
(32): DebuggingKPSE_DEBUG_STAT
(1): DebuggingKPSE_DEBUG_VARS
(64): DebuggingKPSE_DOT
expansion: KPSE_DOT expansionkpse_format_info_type
: Debuggingkpse_init_prog
, and MAKETEX_MODE
: Default path featureskpsewhich
: Invoking kpsewhichksh
, losing with configure
: configure shellslcircle10
: FontmapLDFLAGS
: configure environmentlibdl.a
: dlopenLIBS
: configure environmentlibucb
, avoiding: Running makeLIGFONTS
: Supported file formatsconfigure
: configure shellslndir
for building symlink trees: configure scenarioslost+found
directory: Searching overviewlostchar
: Suppressing warningsls-R
: Supported file formatsls-R
and AFS: Installing filesls-R
database file: ls-Rls-R
, simplest build: ls-Rconfigure
error: Empty Makefilesmaintainer-clean
Make target: Cleaning upmake
, running: Running makeMakefile.in
: Running configureMAKETEX_DEBUG
(512): DebuggingMAKETEX_FINE_DEBUG
(1024): DebuggingMAKETEX_MODE
: Default path featuresMFBASES
: Supported file formatsMFINPUTS
: Supported file formatsMFPOOL
: Supported file formatsMFTINPUTS
: Supported file formatsMISCFONTS
: Supported file formatsmissfont.log
: mktex script namesMISSFONT_LOG
: mktex script namesmkocp
: mktex script namesmkofm
: mktex script namesmktex.cnf
: Specially-recognized filesmktex.cnf
: mktex configurationmktex.opt
: mktex configurationmktexdir
: mktex configurationmktexfmt
: mktex script namesmktexmf
: mktex script namesmktexpk
: mktex script namesmktexpk
, initial runs: Simple installationmktexpk
can't guess mode: Unable to generate fontsmktextex
: mktex script namesmktextfm
: mktex script namesMLBIBINPUTS
: Supported file formatsMLBSTINPUTS
: Supported file formatsmostlyclean
Make target: Cleaning upMPINPUTS
: Supported file formatsMPMEMS
: Supported file formatsMPPOOL
: Supported file formatsMPSUPPORT
: Supported file formatsMT_FEATURES
: mktex configurationconfigure
error: Empty Makefilesconfigure
: configure shellssed
error: Empty Makefilesnomfdrivers
: mktex configurationnomode
: mktex configurationnone
: Suppressing warningsOCPINPUTS
: Supported file formatsOFMFONTS
: Supported file formatsOPENTYPEFONTS
: Supported file formatsconfigure
: configure optionsOTPINPUTS
: Supported file formatsOVFFONTS
: Supported file formatsOVPFONTS
: Supported file formatspaths.h
: Default path generationpaths.h
, creating: Running makepathsearch.h
: Programming overviewpc
Pascal compiler: Historypdfglyphlist.txt
: Specially-recognized filespdftex.cfg
: Specially-recognized filesPDFTEXCONFIG
: Supported file formatspdftexconfig.tex
: Specially-recognized filesPKFONTS
: Supported file formatsplain.base
: Unable to generate fontsproginit.c
: Default path featuresproginit.h
: Calling sequencePSHEADERS
: Supported file formatspxp
Pascal preprocessor: Historyreadable
: Suppressing warningsREADME.CONFIGURE
: Running configureresident.c
: Calling sequencesed
error from configure
: Empty MakefilesSFDFONTS
: Supported file formatssh5
, ok with configure
: configure shellsshell_escape
, example for code: Programming with config filesconfigure
: configure shellsmktex...
: mktex configurationsource files
: Supported file formatsspecial
: Suppressing warningsst_nlink
: Subdirectory expansionST_NLINK_TRICK
: Subdirectory expansiondlsym
: dlopenstrip
: mktex configurationstripsupplier
: mktex configurationstriptypeface
: mktex configurationT1FONTS
: Supported file formatsT1INPUTS
: Supported file formatsT42FONTS
: Supported file formatstcfmgr.map
: Specially-recognized filestex-file.c
: File lookuptex-file.h
: Programming overviewtex-glyph.c
: Glyph lookuptex-glyph.h
: Programming overviewtex-k-request@tug.org
: Mailing liststex-k@tug.org
(bug address): Reporting bugstex.web
: unixtex.ftpTEX_HUSH
: Suppressing warningsTEX_HUSH
: Searching overviewTEXBIB
: Supported file formatsTEXCONFIG
: Supported file formatsTEXDOCS
: Supported file formatsTEXFONTMAPS
: Supported file formatsTEXFONTS
: Supported file formatstexfonts.map
: FontmapTEXFORMATS
: Supported file formatsTEXINDEXSTYLE
: Supported file formatsTEXINPUTS
: Supported file formatsTEXMF
: TeX directory structuretexmf.cnf
: Specially-recognized filestexmf.cnf
, and variable expansion: Variable expansiontexmf.cnf
, creating: Running maketexmf.cnf
, definition for: Config filestexmf.cnf
, generated: Default path generationtexmf.cnf
, source for path: Path sourcestexmf.in
: Default path generationtexmf.in
, editing: Changing search pathstexmf.sed
: Default path generationTEXMFCNF
: Supported file formatsTEXMFCNF
: Config filesTEXMFDBS
: Supported file formatsTEXMFDBS
: ls-RTEXMFINI
: Supported file formatsTEXMFLOG
: LoggingTEXMFOUTPUT
: mktex script namesTEXMFSCRIPTS
: Supported file formatsTEXMFVAR
: mktex configurationtexmfvar
: mktex configurationTEXPICTS
: Supported file formatsTEXPKS
: Supported file formatsTEXPOOL
: Supported file formatsTEXPSHEADERS
: Supported file formatsTEXSIZES
: Fallback fontTEXSOURCES
: Supported file formatsTFMFONTS
: Supported file formatstilde.c
: Tilde expansiontime
system call: LoggingTRFONTS
: Supported file formatstry_std_extension_first
: File lookupTTFONTS
: Supported file formatstug.org
: unixtex.ftpucbinclude
, avoiding: Running makeconfigure
: configure shellsuname
: Bug checklistunixtex.ftp
: unixtex.ftpUSE_TEXMFVAR
: mktex configurationUSE_VARTEXFONTS
: mktex configurationUSERPROFILE
, as ~ expansion: Tilde expansionvarfonts
: mktex configurationvariable.c
: Variable expansionvariable.h
: Programming with config filesVARTEXFONTS
: mktex configurationVFFONTS
: Supported file formatswcstombs
: dlopenWEB2C
: Supported file formatsWEBINPUTS
: Supported file formatswww.tug.org
: unixtex.ftpXCFLAGS
: Running makeXCPPFLAGS
: Running makeXDEFS
: Running makeXDvi
: Specially-recognized filesXDVIFONTS
: Supported file formatsXDVIMAKEPK
: mktex script namesXDVISIZES
: Fallback fontXLDFLAGS
: Running makeXLOADLIBES
: Running makeXMAKEARGS
: Running makeXmu
library problems: ShellWidgetClassXtStrings
: XtStrings{
expansion: Brace expansion~
expansion: Tilde expansion