2 @setfilename kpathsea.info
3 @settitle Kpathsea: A library for path searching
6 @set month-year February 2008
8 @c Define new indices for commands, filenames, and options.
13 @c Put everything in one index (arbitrarily chosen to be the concept index).
25 * Kpathsea: (kpathsea). File lookup along search paths.
26 * kpsewhich: (kpathsea)Invoking kpsewhich. TeX file searching.
27 * mktexfmt: (kpathsea)mktex scripts. Format (fmt/base/mem) generation.
28 * mktexlsr: (kpathsea)Filename database. Update ls-R.
29 * mktexmf: (kpathsea)mktex scripts. MF source generation.
30 * mktexpk: (kpathsea)mktex scripts. PK bitmap generation.
31 * mktextex: (kpathsea)mktex scripts. TeX source generation.
32 * mktextfm: (kpathsea)mktex scripts. TeX font metric generation.
36 This file documents the Kpathsea library for path searching.
38 Copyright @copyright{} 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
39 2004, 2005, 2007, 2008 Karl Berry & Olaf Weber.
41 Permission is granted to make and distribute verbatim copies of this
42 manual provided the copyright notice and this permission notice are
43 preserved on all copies.
46 Permission is granted to process this file through TeX and print the
47 results, provided the printed document carries a copying permission
48 notice identical to this one except for the removal of this paragraph
49 (this paragraph not being relevant to the printed manual).
52 Permission is granted to copy and distribute modified versions of this
53 manual under the conditions for verbatim copying, provided that the
54 entire resulting derived work is distributed under the terms of a
55 permission notice identical to this one.
57 Permission is granted to copy and distribute translations of this manual
58 into another language, under the above conditions for modified versions,
59 except that this permission notice may be stated in a translation
60 approved by the Free Software Foundation.
66 @title Kpathsea library
67 @subtitle for version @value{version}
68 @subtitle @value{month-year}
69 @author Karl Berry (@email{kb@@mail.tug.org})
70 @author Olaf Weber (@email{infovore@@xs4all.nl})
73 @vskip 0pt plus 1filll
82 This manual documents how to install and use the Kpathsea library for
83 filename lookup. It corresponds to version @value{version},
84 released in @value{month-year}.
87 * Introduction:: Overview.
88 * Installation:: Compilation, installation, and bug reporting.
90 * Path searching:: How filename lookups work.
91 * TeX support:: Special support for TeX-related file lookups.
93 * Programming:: How to use Kpathsea features in your program.
95 * Index:: General index.
101 @chapter Introduction
104 @cindex fundamental purpose of Kpathsea
106 This manual corresponds to version @value{version} of the Kpathsea
107 library, released in @value{month-year}.
109 The library's fundamental purpose is to return a filename from a list of
110 directories specified by the user, similar to what shells do when
111 looking up program names to execute.
113 @cindex programs using the library
114 The following software, all of which we maintain, uses this library:
117 @item Dviljk (see the @samp{dvilj} man page)
118 @item Dvipsk (@pxref{Top, , Introduction, dvips, Dvips: A DVI driver})
119 @item GNU font utilities (@pxref{Top, , Introduction, fontu, GNU font
121 @item Web2c (@pxref{Top, , Introduction, web2c, Web2c: A @TeX{}
123 @item Xdvik (see the @samp{xdvi} man page)
126 @noindent Other software that we do not maintain also uses it.
128 @cindex interface, not frozen
129 @cindex comments, making
130 @cindex suggestions, making
131 We are still actively maintaining the library (and probably always will
132 be, despite our hopes). If you have comments or suggestions, please send
133 them to us (@pxref{Reporting bugs}).
135 @cindex conditions for use
136 @cindex license for using the library
137 @cindex GNU General Public License
138 We distribute the library under the GNU Library General Public License
139 (LGPL). In short, this means if you write a program using the library,
140 you must (offer to) distribute the source to the library, along with any
141 changes you have made, and allow anyone to modify the library source and
142 distribute their modifications. It does not mean you have to distribute
143 the source to your program, although we hope you will. See the files
144 @file{GPL} and @file{LGPL} for the text of the GNU licenses.
146 @cindex @TeX{} Users Group
147 If you know enough about @TeX{} to be reading this manual, then you (or
148 your institution) should consider joining the @TeX{} Users Group (if
149 you're already a member, great!). TUG produces the periodical
150 @cite{TUGboat}, sponsors an annual meeting and publishes the
151 proceedings, and arranges courses on @TeX{} for all levels of users
152 throughout the world. Anyway, here is the address:
154 @flindex tug@@tug.org
158 Portland OR 97208-2311
160 phone: +1 503 223-9994
162 email: @email{tug@@tug.org}
173 @cindex history of Kpathsea
175 @cindex Knuth, Donald E.
176 (This section is for those people who are curious about how the library
177 came about.) (If you like to read historical accounts of software, we
178 urge you to seek out the GNU Autoconf manual and the ``Errors of
179 @TeX{}'' paper by Don Knuth, published in @cite{Software---Practice and
180 Experience} 19(7), July 1989.)
187 @pindex pxp @r{Pascal preprocessor}
188 @pindex pc @r{Pascal compiler}
189 [Karl writes.] My first ChangeLog entry for Web2c seems to be February
190 1990, but I may have done some work before then. In any case, Tim
191 Morgan and I were jointly maintaining it for a time. (I should mention
192 here that Tim had made Web2c into a real distribution long before I had
193 ever used it or even heard of it, and Tom Rokicki did the original
194 implementation. I was using @code{pxp} and @code{pc} on VAX 11/750's
195 and the hot new Sun 2 machines.)
197 It must have been later in 1990 and 1991 that I started working on
198 @cite{@TeX{} for the Impatient}. Dvips, Xdvi, Web2c, and the GNU
199 fontutils (which I was also writing at the time) all used different
200 environment variables, and, more importantly, had different bugs in
201 their path searching. This became extremely painful, as I was stressing
202 everything to the limit working on the book. I also desperately wanted
203 to implement subdirectory searching, since I couldn't stand putting
204 everything in one big directory, and also couldn't stand having to
205 explicitly specify @file{cm}, @file{pandora}, @dots{} in a path.
208 In the first incarnation, I just hacked separately on each
209 program---that was the original subdirectory searching code in both Xdvi
210 and Dvips, though I think Paul Vojta has completely rewritten Xdvi's
211 support by now. That is, I tried to go with the flow in each program,
212 rather than changing the program's calling sequences to conform to
215 Then, as bugs inevitably appeared, I found I was fixing the same thing
216 three times (Web2c and fontutils were always sharing code, since I
217 maintained those---there was no Dvipsk or Xdvik or Dviljk at this
218 point). After a while, I finally started sharing source files. They
219 weren't yet a library, though. I just kept things up to date with shell
220 scripts. (I was developing on a 386 running ISC 2.2 at the time, and so
221 didn't have symbolic links. An awful experience.)
223 @cindex MacKenzie, David
224 The ChangeLogs for Xdvik and Dvipsk record initial releases of those
225 distributions in May and June 1992. I think it was because I was tired
226 of the different configuration strategies of each program, not so much
227 because of the path searching. (Autoconf was being developed by David
228 MacKenzie and others, and I was adapting it to @TeX{} and friends.)
231 I started to make a separate library that other programs could link with
232 on my birthday in April 1993, according to the ChangeLog. I don't
233 remember exactly why I finally took the time to make it a separate
234 library; a conversation with david zuhn that initiated it. Just seemed
237 @cindex Walsh, Norman
238 @cindex Neumann, Gustaf
239 Dviljk got started in March 1994 after I bought a Laserjet 4. (Kpathsea
240 work got suspended while Norm Walsh and I, with Gustaf Neumann's help,
241 implemented a way for @TeX{} to get at all those neat builtin LJ4 fonts
242 @dots{} such a treat to have something to typeset in besides Palatino!)
244 By spring of 1995, I had implemented just about all the path-searching
245 features in Kpathsea that I plan to, driven beyond my initial goals by
246 Thomas Esser and others. I then started to integrate Web2c with
247 Kpathsea. After the release of a stable Web2c, I hope to be able to stop
248 development, and turn most of my attention back to making fonts for GNU.
249 (Always assuming Micros**t hasn't completely obliterated Unix by then,
250 or that software patents haven't stopped software development by anybody
251 smaller than a company with a million-dollar-a-year legal budget. Which
252 is actually what I think is likely to happen, but that's another
256 [Olaf writes.] At the end of 1997, UNIX is still alive and kicking,
257 individuals still develop software, and Web2c development still
258 continues. Karl had been looking for some time for someone to take up
259 part of the burden, and I volunteered.
262 @include install.texi
264 @include unixtex.texi
269 @chapter Path searching
271 @cindex path searching
273 This chapter describes the generic path searching mechanism Kpathsea
274 provides. For information about searching for particular file types
275 (e.g., @TeX{} fonts), see the next chapter.
278 * Searching overview:: Basic scheme for searching.
279 * Path sources:: Where search paths can be defined.
280 * Path expansion:: Special constructs in search paths.
281 * Filename database:: Using an externally-built list to search.
282 * Invoking kpsewhich:: Standalone path lookup.
286 @node Searching overview
287 @section Searching overview
289 @cindex searching overview
290 @cindex path searching, overview
291 @cindex overview of path searching
293 @cindex search path, defined
294 A @dfn{search path} is a colon-separated list of @dfn{path elements},
295 which are directory names with a few extra frills. A search path can
296 come from (a combination of) many sources; see below. To look up a file
297 @samp{foo} along a path @samp{.:/dir}, Kpathsea checks each element of
298 the path in turn: first @file{./foo}, then @file{/dir/foo}, returning
299 the first match (or possibly all matches).
301 @cindex magic characters
302 @kindex : @r{may not be :}
303 @kindex / @r{may not be /}
304 The ``colon'' and ``slash'' mentioned here aren't necessarily @samp{:}
305 and @samp{/} on non-Unix systems. Kpathsea tries to adapt to other
306 operating systems' conventions.
308 @cindex database search
309 @cindex searching the database
310 To check a particular path element @var{e}, Kpathsea first sees if a
311 prebuilt database (@pxref{Filename database}) applies to @var{e}, i.e.,
312 if the database is in a directory that is a prefix of @var{e}. If so,
313 the path specification is matched against the contents of the database.
315 @cindex floating directories
316 @cindex filesystem search
318 @cindex searching the disk
319 If the database does not exist, or does not apply to this path element,
320 or contains no matches, the filesystem is searched (if this was not
321 forbidden by the specification with @samp{!!} and if the file being
322 searched for must exist). Kpathsea constructs the list of directories
323 that correspond to this path element, and then checks in each for the
324 file being searched for. (To help speed future lookups of files in the
325 same directory, the directory in which a file is found is floated to the
326 top of the directory list.)
329 @cindex VF files, not found
332 The ``file must exist'' condition comes into play with VF files and
333 input files read by the @TeX{} @samp{\openin} command. These files may
334 not exist (consider @file{cmr10.vf}), and so it would be wrong to search
335 the disk for them. Therefore, if you fail to update @file{ls-R} when
336 you install a new VF file, it will never be found.
338 Each path element is checked in turn: first the database, then the disk.
339 If a match is found, the search stops and the result is returned. This
340 avoids possibly-expensive processing of path specifications that are
341 never needed on a particular run. (Unless the search explicitly
342 requested all matches.)
344 @cindex expansion, path element
345 Although the simplest and most common path element is a directory name,
346 Kpathsea supports additional features in search paths: layered default
347 values, environment variable names, config file values, users' home
348 directories, and recursive subdirectory searching. Thus, we say that
349 Kpathsea @dfn{expands} a path element, meaning transforming all the
350 magic specifications into the basic directory name or names. This
351 process is described in the sections below. It happens in the same
352 order as the sections.
354 @cindex absolute filenames
355 @cindex relative filenames
356 @cindex explicitly relative filenames
357 @cindex filenames, absolute or explicitly relative
358 Exception to all of the above: If the filename being searched for is
359 absolute or explicitly relative, i.e., starts with @samp{/} or @samp{./}
360 or @samp{../}, Kpathsea simply checks if that file exists.
362 @cindex permission denied
363 @cindex unreadable files
364 @cindex access warnings
365 @cindex warnings, file access
366 @flindex lost+found @r{directory}
368 Ordinarily, if Kpathsea tries to access a file or directory that cannot
369 be read, it gives a warning. This is so you will be alerted to
370 directories or files that accidentally lack read permission (for
371 example, a @file{lost+found}). If you prefer not to see these warnings,
372 include the value @samp{readable} in the @code{TEX_HUSH} environment
373 variable or config file value.
375 This generic path searching algorithm is implemented in
376 @file{kpathsea/pathsearch.c}. It is employed by a higher-level
377 algorithm when searching for a file of a particular type (@pxref{File
378 lookup}, and @ref{Glyph lookup}).
382 @section Path sources
385 @cindex sources for search paths
387 A search path can come from many sources. In the order in which
392 @cindex environment variable, source for path
393 A user-set environment variable, e.g., @code{TEXINPUTS}.
394 Environment variables with an underscore and the program name appended
395 override; for example, @code{TEXINPUTS_latex} overrides @code{TEXINPUTS}
396 if the program being run is named @samp{latex}.
399 A program-specific configuration file, e.g., an @samp{S /a:/b} line in
400 Dvips' @file{config.ps} (@pxref{Config files,,, dvips, Dvips}).
403 @cindex configuration file, source for path
404 @cindex Kpathsea config file, source for path
405 @flindex texmf.cnf@r{, source for path}
406 A line in a Kpathsea configuration file @file{texmf.cnf}, e.g.,
407 @samp{TEXINPUTS=/c:/d} (see below).
410 @cindex compilation value, source for path
411 The compile-time default (specified in @file{kpathsea/paths.h}).
414 You can see each of these values for a given search path by using the
415 debugging options (@pxref{Debugging}).
417 These sources may be combined via default expansion (@pxref{Default
421 * Config files:: Kpathsea's runtime config files (texmf.cnf).
426 @subsection Config files
429 @flindex texmf.cnf@r{, definition for}
431 @cindex runtime configuration files
433 As mentioned above, Kpathsea reads @dfn{runtime configuration files}
434 named @file{texmf.cnf} for search path and other definitions. The
435 search path used to look for these configuration files is named
436 @code{TEXMFCNF}, and is constructed in the usual way, as described
437 above, except that configuration files cannot be used to define the
438 path, naturally; also, an @file{ls-R} database is not used to search for
441 Kpathsea reads @emph{all} @file{texmf.cnf} files in the search path, not
442 just the first one found; definitions in earlier files override those in
443 later files. Thus, if the search path is @samp{.:$TEXMF}, values from
444 @file{./texmf.cnf} override those from @file{$TEXMF/texmf.cnf}.
446 While (or instead of) reading this description, you may find it helpful
447 to look at the distributed @file{texmf.cnf}, which uses or at least
448 mentions most features. The format of @file{texmf.cnf} files follows:
452 @cindex comments, in @file{texmf.cnf}
453 Comments start with @samp{%} and continue to the end of the line.
456 @cindex blank lines, in @file{texmf.cnf}
457 Blank lines are ignored.
460 @cindex backslash-newline
461 @cindex continuation character
462 @cindex whitespace, not ignored on continuation lines
463 @kindex \@r{, line continuation in @file{texmf.cnf}}
464 A @samp{\} at the end of a line acts as a continuation character, i.e.,
465 the next line is appended. Whitespace at the beginning of continuation
466 lines is not ignored.
468 @item Each remaining line must look like
471 @var{variable} @r{[}. @var{progname}@r{]} @r{[}=@r{]} @var{value}
474 @noindent where the @samp{=} and surrounding whitespace is optional.
477 @cindex identifiers, characters valid in
478 The @var{variable} name may contain any character other than whitespace,
479 @samp{=}, or @samp{.}, but sticking to @samp{A-Za-z_} is safest.
481 @item If @samp{.@var{progname}} is present, the definition only
482 applies if the program that is running is named (i.e., the last
483 component of @code{argv[0]} is) @var{progname} or
484 @file{@var{progname}.exe}. This allows different flavors of @TeX{} to
485 have different search paths, for example.
488 @cindex right-hand side of variable assignments
489 @var{value} may contain any characters except @samp{%} and @samp{@@}.
490 (These restrictions are only necessary because of the processing done on
491 @file{texmf.cnf} at build time, so you can stick those characters in
492 after installation if you have to.) The @samp{$@var{var}.@var{prog}}
493 feature is not available on the right-hand side; instead, you must use
494 an additional variable (see below for example). A @samp{;} in
495 @var{value} is translated to @samp{:} if running under Unix; this is
496 useful to write a single @file{texmf.cnf} which can be used under both
499 @item All definitions are read before anything is expanded, so you can
500 use variables before they are defined (like Make, unlike most other
504 @noindent Here is a configuration file fragment illustrating most of
508 % TeX input files -- i.e., anything to be found by \input or \openin ...
509 latex209_inputs = .:$TEXMF/tex/latex209//:$TEXMF/tex//
510 latex2e_inputs = .:$TEXMF/tex/latex//:$TEXMF/tex//
511 TEXINPUTS = .:$TEXMF/tex//
512 TEXINPUTS.latex209 = $latex209_inputs
513 TEXINPUTS.latex2e = $latex2e_inputs
514 TEXINPUTS.latex = $latex2e_inputs
517 @cindex shell scripts as configuration files
518 @cindex configuration files as shell scripts.
519 Although this format has obvious similarities to Bourne shell
520 scripts---change the comment character to @code{#}, disallow spaces
521 around the @code{=}, and get rid of the @code{.@var{name}} convention,
522 and it could be run through the shell. But there seemed little
523 advantage to doing this, since all the information would have to passed
524 back to Kpathsea and parsed there anyway, since the @code{sh} process
525 couldn't affect its parent's environment.
528 The implementation of all this is in @file{kpathsea/cnf.c}.
532 @section Path expansion
534 @cindex path expansion
535 @cindex expansion, search path
537 Kpathsea recognizes certain special characters and constructions in
538 search paths, similar to that in shells. As a general example:
539 @samp{~$USER/@{foo,bar@}//baz} expands to all subdirectories under
540 directories @file{foo} and @file{bar} in @t{$USER}'s home directory that
541 contain a directory or file @file{baz}. These expansions are explained
542 in the sections below.
545 * Default expansion:: a: or :a or a::b expands to a default.
546 * Variable expansion:: $foo and $@{foo@} expand to environment values.
547 * Tilde expansion:: ~ and ~user expand to home directories.
548 * Brace expansion:: a@{foo,bar@}b expands to afoob abarb.
549 * KPSE_DOT expansion:: . is replaced with $KPSE_DOT if it is defined.
550 * Subdirectory expansion:: a// and a//b recursively expand to subdirs.
554 @node Default expansion
555 @subsection Default expansion
557 @kindex :: @r{expansion}
558 @cindex doubled colons
559 @cindex leading colons
560 @cindex trailing colons
562 @cindex default expansion
563 @cindex expansion, default
565 If the highest-priority search path (@pxref{Path sources}) contains an
566 @dfn{extra colon} (i.e., leading, trailing, or doubled), Kpathsea
567 inserts at that point the next-highest-priority search path that is
568 defined. If that inserted path has an extra colon, the same happens
569 with the next-highest. (An extra colon in the compile-time default
570 value has unpredictable results, so installers beware.)
572 For example, given an environment variable setting
575 setenv TEXINPUTS /home/karl:
578 @noindent and a @code{TEXINPUTS} value from @file{texmf.cnf} of
584 @noindent then the final value used for searching will be:
587 /home/karl:.:$TEXMF//tex
590 Put another way, default expansion works on ``formats'' (search
591 paths), and not directly on environment variables. Example, showing
592 the trailing @samp{:} ignored in the first case and expanded in the second:
595 $ env TTFONTS=/tmp: kpsewhich --expand-path '$TTFONTS'
597 $ env TTFONTS=/tmp: kpsewhich --show-path=.ttf
598 /tmp:.:/home/olaf/texmf/fonts/truetype//:...
601 Since Kpathsea looks for multiple configuration files, it would be
602 natural to expect that (for example) an extra colon in
603 @file{./texmf.cnf} would expand to the path in @file{$TEXMF/texmf.cnf}.
604 Or, with Dvips' configuration files, that an extra colon in
605 @file{config.$PRINTER} would expand to the path in @file{config.ps}.
606 This doesn't happen. It's not clear this would be desirable in all
607 cases, and trying to devise a way to specify the path to which the extra
608 colon should expand seemed truly baroque.
609 @cindex Bach, Johann Sebastian
611 Technicality: Since it would be useless to insert the default value in
612 more than one place, Kpathsea changes only one extra @samp{:} and leaves
613 any others in place (they will eventually be ignored). Kpathsea checks
614 first for a leading @samp{:}, then a trailing @samp{:}, then a doubled
618 You can trace this by debugging ``paths'' (@pxref{Debugging}).
619 Default expansion is implemented in the source file
620 @file{kpathsea/kdefault.c}.
623 @node Variable expansion
624 @subsection Variable expansion
626 @kindex $ @r{expansion}
627 @cindex environment variables in paths
628 @cindex variable expansion
629 @cindex expansion, variable
630 @flindex texmf.cnf@r{, and variable expansion}
632 @samp{$foo} or @samp{$@{foo@}} in a path element is replaced by (1) the
633 value of an environment variable @samp{foo} (if defined); (2) the value
634 of @samp{foo} from @file{texmf.cnf} (if defined); (3) the empty string.
636 If the character after the @samp{$} is alphanumeric or @samp{_}, the
637 variable name consists of all consecutive such characters. If the
638 character after the @samp{$} is a @samp{@{}, the variable name consists
639 of everything up to the next @samp{@}} (braces may not be nested around
640 variable names). Otherwise, Kpathsea gives a warning and ignores the
641 @samp{$} and its following character.
643 @cindex quoting variable values
644 @cindex shell variables
645 You must quote the @t{$}'s and braces as necessary for your shell.
646 @emph{Shell} variable values cannot be seen by Kpathsea, i.e., ones
647 defined by @code{set} in C shells and without @code{export} in Bourne
652 setenv tex /home/texmf
653 setenv TEXINPUTS .:$tex:$@{tex@}prev
655 @noindent the final @code{TEXINPUTS} path is the three directories:
657 .:/home/texmf:/home/texmfprev
660 The @samp{.@var{progname}} suffix on variables and
661 @samp{_@var{progname}} on environment variable names are not implemented
662 for general variable expansions. These are only recognized when search
663 paths are initialized (@pxref{Path sources}).
666 Variable expansion is implemented in the source file
667 @file{kpathsea/variable.c}.
670 @node Tilde expansion
671 @subsection Tilde expansion
673 @kindex ~ @r{expansion}
674 @cindex home directories in paths
675 @cindex tilde expansion
676 @cindex expansion, tilde
678 @vindex HOME@r{, as ~ expansion}
679 @vindex USERPROFILE@r{, as ~ expansion}
680 A leading @samp{~} in a path element is replaced by the value of the
681 environment variable @code{HOME}, or @file{.} if @code{HOME} is not
682 set. On Windows, the environment variable @code{USERPROFILE} is
683 checked instead of @code{HOME}.
685 A leading @samp{~@var{user}} in a path element is replaced by
686 @var{user}'s home directory from the system @file{passwd} database.
690 setenv TEXINPUTS ~/mymacros:
693 @noindent will prepend a directory @file{mymacros} in your home
694 directory to the default path.
696 @cindex @t{root} user
697 @cindex trailing @samp{/} in home directory
698 @kindex /@r{, trailing in home directory}
699 As a special case, if a home directory ends in @samp{/}, the trailing
700 slash is dropped, to avoid inadvertently creating a @samp{//} construct
701 in the path. For example, if the home directory of the user @samp{root}
702 is @samp{/}, the path element @samp{~root/mymacros} expands to just
703 @samp{/mymacros}, not @samp{//mymacros}.
706 Tilde expansion is implemented in the source file @file{kpathsea/tilde.c}.
709 @node Brace expansion
710 @subsection Brace expansion
712 @kindex @{ @r{expansion}
713 @cindex brace expansion
715 @samp{x@{@var{a},@var{b}@}y} expands to @samp{x@var{a}y:x@var{b}y}.
722 @noindent expands to @samp{foo/1/baz:foo/2/baz}. @samp{:} is the path
723 separator on the current system; e.g., on a DOS system, it's @samp{;}.
725 Braces can be nested; for example, @samp{x@{A,B@{1,2@}@}y} expands to
726 @samp{xAy:xB1y:xB2y}.
728 Multiple non-nested braces are expanded from right to left; for example,
729 @samp{x@{A,B@}@{1,2@}y} expands to @samp{x@{A,B@}1y:x@{A,B@}2y}, which
730 expands to @samp{xA1y:xB1y:xA2y:xB2y}.
732 @cindex multiple @TeX{} hierarchies
733 This feature can be used to implement multiple @TeX{} hierarchies, by
734 assigning a brace list to @code{$TEXMF}, as mentioned in
737 You can also use the path separator in stead of the comma. The last
738 example could have been written @samp{x@{A:B@}@{1:2@}y}.
742 Brace expansion is implemented in the source file
743 @file{kpathsea/expand.c}. It is a modification of the Bash sources, and
744 is thus covered by the GNU General Public License, rather than the
745 Library General Public License that covers the rest of Kpathsea.
748 @node KPSE_DOT expansion
749 @subsection @code{KPSE_DOT} expansion
751 @kindex KPSE_DOT @r{expansion}
753 When @code{KPSE_DOT} is defined in the environment, it names a directory
754 that should be considered the current directory for the purpose of
755 looking up files in the search paths. This feature is needed by the
756 @samp{mktex@dots{}} scripts @ref{mktex scripts}, because these
757 change the working directory. You should not ever define it yourself.
760 @node Subdirectory expansion
761 @subsection Subdirectory expansion
764 @cindex subdirectory searching
765 @cindex expansion, subdirectory
767 @cindex alphabetical order, not
768 Two or more consecutive slashes in a path element following a directory
769 @var{d} is replaced by all subdirectories of @var{d}: first those
770 subdirectories directly under @var{d}, then the subsubdirectories under
771 those, and so on. At each level, the order in which the directories are
772 searched is unspecified. (It's ``directory order'', and definitely not
775 If you specify any filename components after the @samp{//}, only
776 subdirectories which match those components are included. For example,
777 @samp{/a//b} would expand into directories @file{/a/1/b}, @file{/a/2/b},
778 @file{/a/1/1/b}, and so on, but not @file{/a/b/c} or @file{/a/1}.
780 You can include multiple @samp{//} constructs in the path.
782 @samp{//} at the beginning of a path is ignored; you didn't really want
783 to search every directory on the system, did you?
785 @cindex trick for detecting leaf directories
786 @cindex leaf directory trick
787 @cindex Farwell, Matthew
788 @cindex MacKenzie, David
789 I should mention one related implementation trick, which I took from GNU
790 find. Matthew Farwell suggested it, and David MacKenzie implemented it.
793 The trick is that in every real Unix implementation (as opposed to the
794 POSIX specification), a directory which contains no subdirectories will
795 have exactly two links (namely, one for @file{.} and one for @file{..}).
796 That is to say, the @code{st_nlink} field in the @samp{stat} structure
797 will be two. Thus, we don't have to stat everything in the bottom-level
798 (leaf) directories---we can just check @code{st_nlink}, notice it's two,
801 But if you have a directory that contains a single subdirectory and 500
802 regular files, @code{st_nlink} will be 3, and Kpathsea has to stat every
803 one of those 501 entries. Therein lies slowness.
806 You can disable the trick by undefining @code{UNIX_ST_LINK} in
807 @file{kpathsea/config.h}. (It is undefined by default except under Unix.)
810 Unfortunately, in some cases files in leaf directories are
811 @code{stat}'d: if the path specification is, say,
812 @samp{$TEXMF/fonts//pk//}, then files in a subdirectory
813 @samp{@dots{}/pk}, even if it is a leaf, are checked. The reason cannot
814 be explained without reference to the implementation, so read
815 @file{kpathsea/elt-dirs.c} (search for @samp{may descend}) if you are
816 curious. And if you can find a way to @emph{solve} the problem, please
820 Subdirectory expansion is implemented in the source file
821 @file{kpathsea/elt-dirs.c}.
824 @node Filename database
825 @section Filename database (@code{ls-R})
827 @cindex filename database
828 @cindex database, for filenames
829 @cindex externally-built filename database
831 Kpathsea goes to some lengths to minimize disk accesses for searches
832 (@pxref{Subdirectory expansion}). Nevertheless, at installations with
833 enough directories, searching each possible directory for a given file
834 can take an excessively long time (depending on the speed of the disk,
835 whether it's NFS-mounted, how patient you are, etc.).
837 In practice, a font tree containing the standard PostScript and PCL
838 fonts is large enough for searching to be noticeably slow on typical
839 systems these days. Therefore, Kpathsea can use an externally-built
840 ``database'' file named @file{ls-R} that maps files to directories, thus
841 avoiding the need to exhaustively search the disk.
843 A second database file @file{aliases} allows you to give additional
844 names to the files listed in @file{ls-R}. This can be helpful to adapt
845 to ``8.3'' filename conventions in source files.
847 The @file{ls-R} and @file{aliases} features are implemented in the
848 source file @file{kpathsea/db.c}.
851 * ls-R:: The main filename database.
852 * Filename aliases:: Aliases for those names.
853 * Database format:: Syntax details of the database file.
858 @subsection @file{ls-R}
860 @flindex ls-R @r{database file}
863 As mentioned above, you must name the main filename database
864 @file{ls-R}. You can put one at the root of each @TeX{} installation
865 hierarchy you wish to search (@code{$TEXMF} by default); most sites have
866 only one hierarchy. Kpathsea looks for @file{ls-R} files along the
867 @code{TEXMFDBS} path, so that should presumably match the list of
870 The recommended way to create and maintain @samp{ls-R} is to run the
871 @code{mktexlsr} script, which is installed in @samp{$(bindir)}
872 (@file{/usr/local/bin} by default). That script goes to some trouble to
873 follow symbolic links as necessary, etc. It's also invoked by the
874 distributed @samp{mktex@dots{}} scripts.
876 @flindex ls-R@r{, simplest build}
877 At its simplest, though, you can build @file{ls-R} with the command
879 cd @var{/your/texmf/root} && ls -LAR ./ >ls-R
884 @flindex /etc/profile @r{and aliases}
885 presuming your @code{ls} produces the right output format (see the
886 section below). GNU @code{ls}, for example, outputs in this format.
887 Also presuming your @code{ls} hasn't been aliased in a system file
888 (e.g., @file{/etc/profile}) to something problematic, e.g., @samp{ls
889 --color=tty}. In that case, you will have to disable the alias before
890 generating @file{ls-R}. For the precise definition of the file format,
891 see @ref{Database format}.
893 Regardless of whether you use the supplied script or your own, you will
894 almost certainly want to invoke it via @code{cron}, so when you make
895 changes in the installed files (say if you install a new La@TeX{}
896 package), @file{ls-R} will be automatically updated.
898 @opindex -A @r{option to @code{ls}}
901 @flindex . @r{directories, ignored}
902 @flindex .tex @r{file, included in @file{ls-R}}
903 The @samp{-A} option to @code{ls} includes files beginning with @samp{.}
904 (except for @file{.} and @file{..}), such as the file @file{.tex}
905 included with the La@TeX{} tools package. (On the other hand,
906 @emph{directories} whose names begin with @samp{.} are always ignored.)
908 @cindex symbolic links, and @file{ls-R}
909 @opindex -L @r{option to @code{ls}}
910 If your system does not support symbolic links, omit the @samp{-L}.
912 @cindex automounter, and @file{ls-R}
913 @cindex NFS and @file{ls-R}
914 @code{ls -LAR @var{/your/texmf/root}} will also work. But using
915 @samp{./} avoids embedding absolute pathnames, so the hierarchy can be
916 easily transported. It also avoids possible trouble with automounters
917 or other network filesystem conventions.
919 @cindex warning about unusable @file{ls-R}
920 @cindex unusable @file{ls-R} warning
921 Kpathsea warns you if it finds an @file{ls-R} file, but the file does
922 not contain any usable entries. The usual culprit is running plain
923 @samp{ls -R} instead of @samp{ls -LR ./} or @samp{ls -R
924 @var{/your/texmf/root}}. Another possibility is some system directory
925 name starting with a @samp{.} (perhaps if you are using AFS); Kpathsea
926 ignores everything under such directories.
928 @kindex !! @r{in path specifications}
929 @cindex disk searching, avoiding
930 Because the database may be out-of-date for a particular run, if a file
931 is not found in the database, by default Kpathsea goes ahead and
932 searches the disk. If a particular path element begins with @samp{!!},
933 however, @emph{only} the database will be searched for that element,
934 never the disk. If the database does not exist, nothing will be
935 searched. Because this can surprise users (``I see the font
936 @file{foo.tfm} when I do an @code{ls}; why can't Dvips find it?''), it
937 is not in any of the default search paths.
940 @node Filename aliases
941 @subsection Filename aliases
943 @cindex filename aliases
944 @cindex aliases, for filenames
946 In some circumstances, you may wish to find a file under several names.
947 For example, suppose a @TeX{} document was created using a DOS system
948 and tries to read @file{longtabl.sty}. But now it's being run on a Unix
949 system, and the file has its original name, @file{longtable.sty}. The
950 file won't be found. You need to give the actual file
951 @file{longtable.sty} an alias @samp{longtabl.sty}.
953 @c As another example, suppose you are creating a @TeX{} distribution on a
954 @c CD-ROM or a DOS system; then the file @file{mf.base} gets stored as
955 @c @file{mf.bas}. But Metafont on Unix wants to find @file{mf.base}. Here
956 @c you need to give the actual file @file{mf.bas} an alias @samp{mf.base}.
958 You can handle this by creating a file @file{aliases} as a companion to
959 the @file{ls-R} for the hierarchy containing the file in question. (You
960 must have an @file{ls-R} for the alias feature to work.)
962 The format of @file{aliases} is simple: two whitespace-separated words
963 per line; the first is the real name @file{longtable.sty}, and second is
964 the alias (@file{longtabl.sty}). These must be base filenames, with no
965 directory components. @file{longtable.sty} must be in the sibling
968 Also, blank lines and lines starting with @samp{%} or @samp{#} are
969 ignored in @file{aliases}, to allow for comments.
971 If a real file @file{longtabl.sty} exists, it is used regardless of any
975 @node Database format
976 @subsection Database format
978 @cindex format of external database
979 @cindex database, format of
981 The ``database'' read by Kpathsea is a line-oriented file of plain
982 text. The format is that generated by GNU (and most other) @code{ls}
983 programs given the @samp{-R} option, as follows.
987 Blank lines are ignored.
990 If a line begins with @samp{/} or @samp{./} or @samp{../} and ends with
991 a colon, it's the name of a directory. (@samp{../} lines aren't useful,
992 however, and should not be generated.)
995 All other lines define entries in the most recently seen directory.
996 @t{/}'s in such lines will produce possibly-strange results.
999 Files with no preceding directory line are ignored.
1002 For example, here's the first few lines of @file{ls-R} (which totals
1003 about 30K bytes) on my system:
1027 @node Invoking kpsewhich
1028 @section @code{kpsewhich}: Standalone path searching
1031 @cindex path searching, standalone
1032 @cindex standalone path searching
1034 The Kpsewhich program exercises the path searching functionality
1035 independent of any particular application. This can also be useful as a
1036 sort of @code{find} program to locate files in your @TeX{} hierarchies,
1037 perhaps in administrative scripts. It is used heavily in the
1038 distributed @samp{mktex@dots{}} scripts.
1042 kpsewhich @var{option}@dots{} @var{filename}@dots{}
1045 The options and filename(s) to look up can be intermixed.
1046 Options can start with either @samp{-} or @samp{--}, and any unambiguous
1047 abbreviation is accepted.
1050 * Path searching options:: Changing the mode, resolution, etc.
1051 * Auxiliary tasks:: Path and variable expansion.
1052 * Standard options:: --help and --version.
1056 @node Path searching options
1057 @subsection Path searching options
1059 @cindex path searching options
1061 Kpsewhich looks up each non-option argument on the command line as a
1062 filename, and returns the first file found.
1064 Various options alter the path searching behavior:
1069 @cindex all matches, finding
1070 Report all matches found, one per line. By default, if there is more
1071 than one match, just one will be reported (chosen effectively at random).
1073 @item --dpi=@var{num}
1074 @opindex --dpi=@var{num}
1075 @opindex -D @var{num}
1076 @cindex resolution, setting
1077 Set the resolution to @var{num}; this only affects @samp{gf} and
1078 @samp{pk} lookups. @samp{-D} is a synonym, for compatibility with
1079 Dvips. Default is 600.
1081 @item --engine=@var{name}
1082 @opindex --engine=@var{name}
1084 Set the engine name to @var{name}. By default it is not set. The
1085 engine name is used in some search paths to allow files with the same
1086 name but used by different engines to coexist.
1088 @item --format=@var{name}
1089 @opindex --format=@var{name}
1090 Set the format for lookup to @var{name}. By default, the format is
1091 guessed from the filename, with @samp{tex} being used if nothing else
1092 fits. The recognized filename extensions (including any leading
1093 @samp{.}) are also allowable @var{name}s.
1095 All formats also have a name, which is the only way to specify formats
1096 with no associated suffix. For example, for Dvips configuration files
1097 you can use @samp{--format="dvips config"}. (The quotes are for the
1102 @flindex pdftexconfig.tex
1103 When the filename being searched for is @file{config.ps}, the format
1104 is automatically switched to @samp{dvips config}. Similarly, when the
1105 filename is @file{pdftex.cfg}, the format is switched to @samp{pdftex
1106 config} (although @file{pdftex.cfg} is not used any more; look for
1107 @file{pdftexconfig.tex} instead.)
1109 Here's the current list of recognized names and the associated suffixes.
1110 @xref{Supported file formats}, for more information on each of these.
1136 graphic/figure: .eps .epsi
1138 TeX system documentation
1141 PostScript header/font: .pro
1144 type1 fonts: .pfa .pfb
1148 truetype fonts: .ttf .ttc
1165 This option and @samp{--path} are mutually exclusive.
1168 @opindex --interactive
1169 @cindex interactive query
1170 After processing the command line, read additional filenames to look up
1171 from standard input.
1173 @item -mktex=@var{filetype}
1174 @itemx -no-mktex=@var{filetype}
1175 @opindex -mktex=@var{filetype}
1176 @opindex -no-mktex=@var{filetype}
1177 Turn on or off the @samp{mktex} script associated with @var{filetype}.
1178 The only values that make sense for @var{filetype} are @samp{pk},
1179 @samp{mf}, @samp{tex}, and @samp{tfm}. By default, all are off in
1180 Kpsewhich. @xref{mktex scripts}.
1182 @item --mode=@var{string}
1183 @opindex --mode=@var{string}
1184 Set the mode name to @var{string}; this also only affects @samp{gf} and
1185 @samp{pk} lookups. No default: any mode will be found. @xref{mktex
1189 @opindex --must-exist
1190 Do everything possible to find the files, notably including searching
1191 the disk. By default, only the @file{ls-R} database is checked, in the
1192 interest of efficiency.
1194 @item --path=@var{string}
1195 @opindex --path=@var{string}
1196 Search along the path @var{string} (colon-separated as usual), instead
1197 of guessing the search path from the filename. @samp{//} and all the
1198 usual expansions are supported (@pxref{Path expansion}). This option
1199 and @samp{--format} are mutually exclusive. To output the complete
1200 directory expansion of a path, instead of doing a one-shot lookup, see
1201 @samp{--expand-path} and @samp{--show-path} in the following section.
1203 @item --progname=@var{name}
1204 @opindex --progname=@var{name}
1205 Set the program name to @var{name}; default is @samp{kpsewhich}. This
1206 can affect the search paths via the @samp{.@var{prognam}} feature in
1207 configuration files (@pxref{Config files}).
1209 @item --subdir=@var{string}
1210 @opindex --subdir=@var{string}
1211 Report only those matches whose directory part @emph{ends} with
1212 @var{string} (compared literally, except case is ignored on a
1213 case-insensitive operating system). For example, suppose there are
1214 two matches for a given name:
1218 @result{} /some/where/foo.sty
1219 /another/place/foo.sty
1223 Then we can narrow the result to what we are interested in with
1227 kpsewhich --subdir=where foo.sty
1228 @result{} /some/where/foo.sty
1230 kpsewhich --subdir=place foo.sty
1231 @result{} /another/place/foo.sty
1235 The string to match must be at the end of the directory part of the
1236 match, and it is taken literally, with no pattern matching:
1239 kpsewhich --subdir=another foo.sty
1244 The string to match may cross directory components:
1247 kpsewhich --subdir=some/where foo.sty
1248 @result{} /some/where/foo.sty
1252 @option{--subdir} implies @option{--all}; if there is more than one
1253 match, they will all be reported (in our example, both @samp{where}
1254 and @samp{place} end in @samp{e}):
1257 kpsewhich --subdir=e
1258 @result{} /some/where/foo.sty
1259 /another/place/foo.sty
1263 Because of the above rules, the presence of a leading @samp{/} is
1264 important, since it ``anchors'' the match to a full component name:
1267 kpsewhich --subdir=/lace foo.sty
1272 However, a trailing @samp{/} is immaterial (and ignored), since the
1273 match always takes place at the end of the directory part:
1276 kpsewhich --subdir=lace/ foo.sty
1277 @result{} /another/place/foo.sty
1281 The purpose of these rules is to make it convenient to find results
1282 only within a particular area of the tree. For instance, a given
1283 script named @file{foo.lua} might exist within both
1284 @file{texmf-dist/scripts/pkg1/} and @file{texmf-dist/scripts/pkg2/}.
1285 By specifying, say, @samp{--subdir=/pkg1}, you can be sure of getting
1286 the one you are interested in.
1288 We only match at the end because a site might happen to install @TeX{}
1289 in @file{/some/coincidental/pkg1/path/}, and we wouldn't want
1290 @file{texmf-dist/scripts/pkg2/} to match that when searching for
1296 @node Auxiliary tasks
1297 @subsection Auxiliary tasks
1299 @cindex auxiliary tasks
1301 Kpsewhich provides some additional features not strictly related to path
1306 @opindex --debug=@var{num}
1307 @samp{--debug=@var{num}} sets the debugging options to @var{num}.
1311 @opindex --var-value=@var{variable}
1312 @samp{--var-value=@var{variable}} outputs the value of @var{variable},
1313 expanding @samp{$} (@pxref{Variable expansion} and @samp{~} (@pxref{Tilde
1314 expansion}) constructs, but not performing other expansions.
1317 @opindex --expand-braces=@var{string}
1318 @samp{--expand-braces=@var{string}} outputs the variable and brace
1319 expansion of @var{string}. @xref{Path expansion}.
1322 @opindex --expand-var=@var{string}
1323 @samp{--expand-var=@var{string}} outputs the variable and tilde
1324 expansion of @var{string}. For example, the @samp{mktex@dots{}}
1325 scripts run @samp{kpsewhich --expand-var='$TEXMF'} to find the root of
1326 the @TeX{} system hierarchy. @xref{Path expansion}.
1329 @opindex --expand-path=@var{string}
1330 @samp{--expand-path=@var{string}} outputs the complete expansion of
1331 @var{string}, with each element separated by the usual path separator
1332 on the current system (@samp{;} on Windows, @samp{:} otherwise).
1333 This may be useful to construct a custom search path for a format not
1334 otherwise supported. To retrieve the search path for a format that is
1335 already supported, see @samp{--show-path}, next.
1337 Nonexistent directories are culled from the output:
1340 $ kpsewhich --expand-path '/tmp'
1342 $ kpsewhich --expand-path '/nonesuch'
1346 For one-shot uses of an arbitrary (not built in to Kpathsea) path, see
1347 @samp{--path} in the previous section.
1350 @opindex --show-path=@var{name}
1351 @samp{--show-path=@var{name}} shows the path that would be used for file
1352 lookups of file type @var{name}. Either a filename extension
1353 (@samp{pk}, @samp{.vf}, etc.) or an integer can be used, just as with
1354 @samp{--format}, described in the previous section.
1359 @node Standard options
1360 @subsection Standard options
1362 @cindex standard options
1364 Kpsewhich accepts the standard GNU options:
1369 @samp{--help} prints a help message on standard output and exits.
1373 @samp{--version} prints the Kpathsea version number and exits.
1378 @chapter @TeX{} support
1380 @cindex @TeX{} support
1382 Although the basic features in Kpathsea can be used for any type of path
1383 searching, it came about (like all libraries) with a specific
1384 application in mind: I wrote Kpathsea specifically for @TeX{} system
1385 programs. I had been struggling with the programs I was using (Dvips,
1386 Xdvi, and @TeX{} itself) having slightly different notions of how to
1387 specify paths; and debugging was painful, since no code was shared.
1389 Therefore, Kpathsea provides some @TeX{}-specific formats and features.
1390 Indeed, many of the supposedly generic path searching features were
1391 provided because they seemed useful in that con@TeX{}t (font lookup,
1394 Kpathsea provides a standard way to search for files of any of the
1395 supported file types; glyph fonts are a bit different than all the rest.
1396 Searches are based solely on filenames, not file contents---if a GF
1397 file is named @file{cmr10.600pk}, it will be found as a PK file.
1400 * Supported file formats:: File types Kpathsea knows about.
1401 * File lookup:: Searching for most kinds of files.
1402 * Glyph lookup:: Searching for bitmap fonts.
1403 * Suppressing warnings:: Avoiding warnings via TEX_HUSH.
1407 @node Supported file formats
1408 @section Supported file formats
1410 @cindex supported file formats
1411 @cindex file formats, supported
1413 @cindex environment variables for @TeX{}
1414 @cindex @TeX{} environment variables
1416 Kpathsea has support for a number of file types. Each file type has a
1417 list of environment and config file variables that are checked to define
1418 the search path, and most have a default suffix that plays a role in
1419 finding files (see the next section). Some also define additional
1420 suffixes, and/or a program to be run to create missing files on the fly.
1422 @cindex program-varying paths
1423 Since environment variables containing periods, such as
1424 @samp{TEXINPUTS.latex}, are not allowed on some systems, Kpathsea looks
1425 for environment variables with an underscore, e.g.,
1426 @samp{TEXINPUTS_latex} (@pxref{Config files}).
1428 The following table lists the above information.
1434 (Adobe font metrics, @pxref{Metric files,,, dvips, Dvips})
1442 (Metafont memory dump, @pxref{Memory dumps,,, web2c, Web2c})
1443 @code{MFBASES}, @code{TEXMFINI};
1444 suffix @samp{.base}.
1450 (Bib@TeX{} bibliography source, @pxref{bibtex invocation,,, web2c, Web2c})
1451 @code{BIBINPUTS}, @code{TEXBIB};
1457 (Bib@TeX{} style file, @pxref{Basic BibTeX style files,, Basic Bib@TeX{}
1458 style files, web2c, Web2c})
1465 (character map files)
1467 suffix @samp{.cmap}.
1472 (Runtime configuration files, @pxref{Config files})
1482 suffixes @samp{.w}, @samp{.web};
1483 additional suffix @samp{.ch}.
1487 @flindex config.ps@r{, search path for}
1488 (Dvips @samp{config.*} files, such as @file{config.ps}, @pxref{Config
1489 files,,, dvips, Dvips})
1503 (@TeX{} memory dump, @pxref{Memory dumps,,, web2c, Web2c})
1504 @code{TEXFORMATS}, @code{TEXMFINI};
1512 (generic font bitmap, @pxref{Glyph files,,, dvips, Dvips})
1513 @code{@var{program}FONTS}, @code{GFFONTS}, @code{GLYPHFONTS}, @code{TEXFONTS};
1516 @item graphic/figure
1521 (Encapsulated PostScript figures, @pxref{PostScript figures,,, dvips, Dvips})
1522 @code{TEXPICTS}, @code{TEXINPUTS};
1523 additional suffixes: @samp{.eps}, @samp{.epsi}.
1527 @vindex TEXINDEXSTYLE
1529 (makeindex style files)
1530 @code{TEXINDEXSTYLE}, @code{INDEXSTYLE};
1536 (ligature definition files)
1543 (Filename databases, @pxref{Filename database})
1549 (Fontmaps, @pxref{Fontmap})
1557 (MetaPost memory dump, @pxref{Memory dumps,,, web2c, Web2c})
1558 @code{MPMEMS}, @code{TEXMFINI};
1561 @item @r{MetaPost support}
1563 (MetaPost support files, used by DMP; @pxref{dmp invocation,,, web2c, Web2c})
1569 (Metafont source, @pxref{mf invocation,,, web2c, Web2c})
1572 dynamic creation program: @code{mktexmf}.
1577 (Metafont program strings, @pxref{pooltype invocation,,, web2c, Web2c})
1578 @code{MFPOOL}, @code{TEXMFINI};
1579 suffix @samp{.pool}.
1584 (@code{MFT} style file, @pxref{mft invocation,,, web2c, Web2c})
1590 (font-related files that don't fit the other categories)
1596 (MetaPost source, @pxref{mpost invocation,,, web2c, Web2c})
1603 (MetaPost program strings, @pxref{pooltype invocation,,, web2c, Web2c})
1604 @code{MPPOOL}, @code{TEXMFINI};
1605 suffix @samp{.pool}.
1610 (Omega compiled process files)
1611 @code{OCPINPUTS}; @*
1613 dynamic creation program: @code{MakeOmegaOCP}.
1618 (Omega font metrics)
1619 @code{OFMFONTS}, @code{TEXFONTS}; @*
1620 suffixes @samp{.ofm}, @samp{.tfm};
1621 dynamic creation program: @code{MakeOmegaOFM}.
1623 @item opentype fonts
1624 @vindex OPENTYPEFONTS
1626 @code{OPENTYPEFONTS}.
1630 (Omega property lists)
1631 @code{OPLFONTS}, @code{TEXFONTS};
1637 (Omega translation process files)
1644 (Omega virtual fonts)
1645 @code{OVFFONTS}, @code{TEXFONTS};
1651 (Omega virtual property lists)
1652 @code{OVPFONTS}, @code{TEXFONTS};
1656 @vindex PDFTEXCONFIG
1657 (PDF@TeX{}-specific configuration files)
1658 @code{PDFTEXCONFIG}.
1666 (packed bitmap fonts, @pxref{Glyph files,,, dvips, Dvips})
1667 @code{@var{PROGRAM}FONTS} (@var{program} being @samp{XDVI}, etc.),
1668 @code{PKFONTS}, @code{TEXPKS}, @code{GLYPHFONTS}, @code{TEXFONTS};
1670 dynamic creation program: @code{mktexpk}.
1672 @item PostScript header
1674 @vindex TEXPSHEADERS
1676 (downloadable PostScript, @pxref{Header files,,, dvips, Dvips})
1677 @code{TEXPSHEADERS}, @code{PSHEADERS};
1678 additional suffix @samp{.pro}.
1680 @item subfont definition files
1683 (subfont definition files)
1690 (@TeX{} source, @pxref{tex invocation,,, web2c, Web2c})
1693 additional suffixes: none, because such a list cannot be complete;
1694 dynamic creation program: @code{mktextex}.
1696 @item TeX system documentation
1699 (Documentation files for the @TeX{} system)
1702 @item TeX system sources
1703 @flindex source files
1705 (Source files for the @TeX{} system)
1709 @vindex TEXMFSCRIPTS
1710 (Architecture-independent executables distributed in the texmf tree)
1711 @code{TEXMFSCRIPTS}.
1716 (@TeX{} program strings, @pxref{pooltype invocation,,, web2c, Web2c})
1717 @code{TEXPOOL}, @code{TEXMFINI};
1718 suffix @samp{.pool}.
1724 (@TeX{} font metrics, @pxref{Metric files,,, dvips, Dvips})
1725 @code{TFMFONTS}, @code{TEXFONTS};
1727 dynamic creation program: @code{mktextfm}.
1731 (Troff fonts, used by DMP; @pxref{DMP invocation,,, web2c, Web2c})
1734 @item truetype fonts
1738 (TrueType outline fonts) @code{TTFONTS}; suffixes @samp{.ttf},
1746 @vindex TEXPSHEADERS
1747 @vindex DVIPSHEADERS
1748 (Type 1 PostScript outline fonts, @pxref{Glyph files,,, dvips, Dvips})
1749 @code{T1FONTS}, @code{T1INPUTS}, @code{TEXPSHEADERS}, @code{DVIPSHEADERS};
1750 suffixes @samp{.pfa}, @samp{.pfb}.
1754 (Type 42 PostScript outline fonts) @code{T42FONTS}.
1760 (virtual fonts, @pxref{Virtual fonts,,, dvips, Dvips})
1761 @code{VFFONTS}, @code{TEXFONTS};
1770 additional suffix @samp{.ch}.
1774 (files specific to the web2c implementation)
1778 There are two special cases, because the paths and environment variables
1779 always depend on the name of the program: the variable name is
1780 constructed by converting the program name to upper case, and then
1781 appending @samp{INPUTS}. Assuming the program is called @samp{foo},
1782 this gives us the following table.
1785 @item other text files
1787 (text files used by @samp{foo})
1790 @item other binary files
1792 (binary files used by @samp{foo})
1796 If an environment variable by these names are set, the corresponding
1797 @file{texmf.cnf} definition won't be looked at (unless, as usual, the
1798 environment variable value has an extra @samp{:}). @xref{Default
1801 For the font variables, the intent is that:
1804 @code{TEXFONTS} is the default for everything.
1807 @code{GLYPHFONTS} is the default for bitmap (or, more precisely,
1811 Each font format has a variable of its own.
1816 Each program has its own font override path as well; e.g.,
1817 @code{DVIPSFONTS} for Dvipsk. Again, this is for bitmaps, not metrics.
1823 @section File lookup
1826 @cindex searching for files
1827 @cindex @TeX{} file lookup
1829 This section describes how Kpathsea searches for most files (bitmap font
1830 searches are the exception, as described in the next section).
1832 Here is the search strategy for a file @var{name}:
1835 If the file format defines default suffixes, and the suffix of
1836 @var{name} name is not already a known suffix for that format, try the
1837 name with each default appended, and use alternative names found in the
1838 fontmaps if necessary. We postpone searching the disk as long as
1839 possible. Example: given @samp{foo.sty}, look for @samp{foo.sty.tex}
1840 before @samp{foo.sty}. This is unfortunate, but allows us to find
1841 @samp{foo.bar.tex} before @samp{foo.bar} if both exist and we were given
1845 Search for @var{name}, and if necessary for alternative names found in
1846 the fontmaps. Again we avoid searching the disk if possible. Example:
1847 given @samp{foo}, we look for @samp{foo}.
1850 If the file format defines a program to invoke to create missing files,
1851 run it (@pxref{mktex scripts}).
1855 @findex kpse_find_file
1856 This is implemented in the routine @code{kpse_find_file} in
1857 @file{kpathsea/tex-file.c}. You can watch it in action with the
1858 debugging options (@pxref{Debugging}).
1862 @section Glyph lookup
1864 @cindex glyph lookup
1865 @cindex searching for glyphs
1866 @cindex @TeX{} glyph lookup
1868 This section describes how Kpathsea searches for a bitmap font in GF or
1869 PK format (or either) given a font name (e.g., @samp{cmr10}) and a
1870 resolution (e.g., 600).
1872 Here is an outline of the search strategy (details in the sections
1873 below) for a file @var{name} at resolution @var{dpi}. The search stops
1874 at the first successful lookup.
1878 Look for an existing file @var{name}.@var{dpi}@var{format} in the
1879 specified format(s).
1881 @item If @var{name} is an alias for a file @var{f} in the fontmap
1882 file @file{texfonts.map}, look for @var{f}.@var{dpi}.
1884 @item Run an external program (typically named @samp{mktexpk}) to
1885 generate the font (@pxref{mktex scripts})
1887 @item Look for @var{fallback}.@var{dpi}, where @var{fallback} is some
1888 last-resort font (typically @samp{cmr10}).
1891 @flindex tex-glyph.c
1892 @findex kpse_find_glyph_format
1893 This is implemented in @code{kpse_find_glyph_format} in
1894 @file{kpathsea/tex-glyph.c}.
1897 * Basic glyph lookup:: Features common to all glyph lookups.
1898 * Fontmap:: Aliases for fonts.
1899 * Fallback font:: Resolutions and fonts of last resort.
1903 @node Basic glyph lookup
1904 @subsection Basic glyph lookup
1906 @cindex basic glyph lookup
1907 @cindex common features in glyph lookup
1909 When Kpathsea looks for a bitmap font @var{name} at resolution @var{dpi}
1910 in a format @var{format}, it first checks each directory in the search
1911 path for a file @samp{@var{name}.@var{dpi}@var{format}}; for example,
1912 @samp{cmr10.600pk}. Kpathsea looks for a PK file first, then a GF file.
1914 If that fails, Kpathsea looks for
1915 @samp{dpi@var{dpi}/@var{name}.@var{format}}; for example,
1916 @samp{dpi600/cmr10.pk}. This is how fonts are typically stored on
1917 filesystems (such as DOS) that permit only three-character extensions.
1919 @cindex tolerance for glyph lookup
1920 @cindex glyph lookup bitmap tolerance
1921 @findex KPSE_BITMAP_TOLERANCE
1922 If that fails, Kpathsea looks for a font with a close-enough @var{dpi}.
1923 ``Close enough'' is defined by the macro @code{KPSE_BITMAP_TOLERANCE} in
1924 @file{kpathsea/tex-glyph.h} to be @code{@var{dpi} / 500 + 1}. This is
1925 slightly more than the 0.2% minimum allowed by the DVI standard
1926 (@url{@var{CTAN:}/dviware/driv-standard/level-0}).
1932 @cindex fontmap files
1933 @cindex font alias files
1934 @cindex aliases for fonts
1936 @flindex texfonts.map
1937 If a bitmap font or metric file is not found with the original name (see
1938 the previous section), Kpathsea looks through any @dfn{fontmap} files
1939 for an @dfn{alias} for the original font name. These files are named
1940 @file{texfonts.map} and searched for along the @code{TEXFONTMAPS}
1941 environment/config file variable. All @file{texfonts.map} files that
1942 are found are read; earlier definitions override later ones.
1944 This feature is intended to help in two respects:
1949 @cindex fontnames, arbitrary length
1950 An alias name is limited in length only by available memory, not by your
1951 filesystem. Therefore, if you want to ask for @samp{Times-Roman}
1952 instead of @file{ptmr}, you can (you get @samp{ptmr8r}).
1955 @cindex circle fonts
1957 A few fonts have historically had multiple names: specifically,
1958 La@TeX{}'s ``circle font'' has variously been known as @file{circle10},
1959 @file{lcircle10}, and @file{lcirc10}. Aliases can make all the names
1960 equivalent, so that it no longer matters what the name of the installed
1961 file is; @TeX{} documents will find their favorite name.
1965 The format of fontmap files is straightforward:
1968 @cindex comments, in fontmap files
1969 @item Comments start with @samp{%} and continue to the end of the line.
1970 @cindex whitespace, in fontmap files
1971 @item Blank lines are ignored.
1972 @item Each nonblank line is broken up into a series of @dfn{words}:
1973 a sequence of non-whitespace characters.
1974 @findex include @r{fontmap directive}
1975 @item If the first word is @samp{include}, the second word is used as
1976 a filename, and it is searched for and read.
1977 @item Otherwise, the first word on each line is the true filename;
1978 @item the second word is the alias;
1979 @item subsequent words are ignored.
1982 If an alias has an extension, it matches only those files with that
1983 extension; otherwise, it matches anything with the same root, regardless
1984 of extension. For example, an alias @samp{foo.tfm} matches only when
1985 @file{foo.tfm} is being searched for; but an alias @samp{foo} matches
1986 @file{foo.vf}, @file{foo.600pk}, etc.
1988 As an example, here is an excerpt from the @file{texfonts.map} in the
1989 Web2c distribution. It makes the circle fonts equivalent and includes
1990 automatically generated maps for most PostScript fonts available from
1991 various font suppliers.
2003 include bitstrea.map
2007 Fontmaps are implemented in the file @file{kpathsea/fontmap.c}.
2008 The Fontname distribution has much more information on font naming
2009 (@pxref{Introduction,,, fontname, Filenames for @TeX{} fonts}).
2013 @subsection Fallback font
2015 @cindex fallback font
2016 @cindex fallback resolutions
2017 @cindex font of last resort
2018 @cindex resolutions, last-resort
2019 @cindex last-resort font
2025 @vindex default_texsizes
2026 If a bitmap font cannot be found or created at the requested size,
2027 Kpathsea looks for the font at a set of @dfn{fallback resolutions}. You
2028 specify these resolutions as a colon-separated list (like search paths).
2029 Kpathsea looks first for a program-specific environment variable (e.g.,
2030 @code{DVIPSSIZES} for Dvipsk), then the environment variable
2031 @code{TEXSIZES}, then a default specified at compilation time (the Make
2032 variable @code{default_texsizes}). You can set this list to be empty if
2033 you prefer to find fonts at their stated size or not at all.
2035 @flindex cmr10@r{, as fallback font}
2036 @vindex kpse_fallback_font
2037 Finally, if the font cannot be found even at the fallback resolutions,
2038 Kpathsea looks for a fallback font, typically @file{cmr10}. Programs
2039 must enable this feature by assigning to the global variable
2040 @code{kpse_fallback_font} or calling @code{kpse_init_prog}
2041 (@pxref{Calling sequence}); the default is no fallback font.
2044 @node Suppressing warnings
2045 @section Suppressing warnings
2047 @cindex warnings, suppressing
2048 @cindex suppressing warnings
2051 Kpathsea provides a way to suppress selected usually-harmless warnings;
2052 this is useful at large sites where most users are not administrators,
2053 and thus the warnings are merely a source of confusion, not a help. To
2054 do this, you set the environment variable or configuration file value
2055 @code{TEX_HUSH} to a colon-separated list of values. Here are the
2060 Suppress everything possible.
2063 @cindex mismatched checksum warnings
2064 Suppress mismatched font checksum warnings.
2067 @cindex missing character warnings
2068 Suppress warnings when a character is missing from a font that a DVI or
2069 VF file tries to typeset.
2072 Don't suppress any warnings.
2075 @cindex unreadable file warnings
2076 Suppress warnings about attempts to access a file whose permissions
2077 render it unreadable.
2080 @cindex unknown special warnings
2081 @findex \special@r{, suppressing warnings about}
2082 Suppresses warnings about an unimplemented or unparsable
2083 @samp{\special} command.
2086 @noindent @file{tex-hush.c} defines the function that checks the
2087 variable value. Each driver implements its own checks where
2092 @chapter Programming
2094 This chapter is for programmers who wish to use Kpathsea.
2095 @xref{Introduction}, for the conditions under which you may do so.
2098 * Overview: Programming overview. Introduction.
2099 * Calling sequence:: Specifics of what to call.
2100 * Program-specific files:: How to handle these.
2101 * Config: Programming with config files. Getting info from texmf.cnf.
2105 @node Programming overview
2106 @section Programming overview
2108 @cindex programming overview
2109 @cindex overview of programming with Kpathsea
2111 Aside from this manual, your best source of information is the source to
2112 the programs I've modified to use Kpathsea (@pxref{Introduction}). Of
2113 those, Dviljk is probably the simplest, and hence a good place to start.
2114 Xdvik adds VF support and the complication of X resources. Dvipsk adds
2115 the complication of its own config files. Web2c is source code I also
2116 maintain, so it uses Kpathsea rather straightforwardly, but is of course
2117 complicated by the Web to C translation. Finally, Kpsewhich is a small
2118 utility program whose sole purpose is to exercise the main
2119 path-searching functionality.
2121 @flindex pathsearch.h
2123 @flindex tex-glyph.h
2125 Beyond these examples, the @file{.h} files in the Kpathsea source
2126 describe the interfaces and functionality (and of course the @file{.c}
2127 files define the actual routines, which are the ultimate documentation).
2128 @file{pathsearch.h} declares the basic searching routine.
2129 @file{tex-file.h} and @file{tex-glyph.h} define the interfaces for
2130 looking up particular kinds of files. In view of the way the headers
2131 depend on each other, it is recommended to use @code{#include
2132 <kpathsea/kpathsea.h>}, which includes every Kpathsea header.
2136 If you want to include only specific headers, you should still consider
2137 including @file{kpathsea/config.h} before including any other Kpathsea
2138 header, as it provides symbols used in the other headers. Note that
2139 @file{kpathsea/config.h} includes @file{kpathsea/c-auto.h}, which is
2140 generated by Autoconf.
2142 @cindex file types, registering new
2143 The library provides no way for an external program to register new file
2144 types: @file{tex-file.[ch]} must be modified to do this. For example,
2145 Kpathsea has support for looking up Dvips config files, even though no
2146 program other than Dvips will likely ever want to do so. I felt this
2147 was acceptable, since along with new file types should also come new
2148 defaults in @file{texmf.cnf} (and its descendant @file{paths.h}), since
2149 it's simplest for users if they can modify one configuration file for
2152 Kpathsea does not parse any formats itself; it barely opens any files.
2153 Its primary purpose is to return filenames. The GNU font utilities does
2154 contain libraries to read TFM, GF, and PK files, as do the programs
2158 @node Calling sequence
2159 @section Calling sequence
2161 @cindex programming with Kpathsea
2162 @cindex calling sequence
2164 The typical way to use Kpathsea in your program goes something like this:
2169 @findex kpse_set_program_name
2171 Call @code{kpse_set_program_name} with @code{argv[0]} as the first
2172 argument; the second argument is a string or @code{NULL}. The second
2173 argument is used by Kpathsea as the program name for the
2174 @code{.@var{program}} feature of config files (@pxref{Config files}).
2175 If the second argument is @code{NULL}, the value of the first argument
2176 is used. This function must be called before any other use of the
2179 @vindex program_invocation_name
2180 @vindex program_invocation_short_name
2181 @vindex kpse_program_name
2182 @vindex KPATHSEA_DEBUG
2185 @cindex SELFAUTOPARENT
2186 @cindex error message macros
2187 @cindex symlinks, resolving
2188 @cindex expanding symlinks
2189 If necessary, @code{kpse_set_program_name} sets the global variables
2190 @code{program_invocation_name} and @code{program_invocation_short_name}.
2191 These variables are used in the error message macros defined in
2192 @file{kpathsea/lib.h}. It sets the global variable
2193 @code{kpse_program_name} to the program name it uses. It also
2194 initializes debugging options based on the environment variable
2195 @code{KPATHSEA_DEBUG} (if that is set). Finally, it sets the variables
2196 @code{SELFAUTOLOC}, @code{SELFAUTODIR} and @code{SELFAUTOPARENT} to the
2197 location, parent and grandparent directory of the executable, removing
2198 @file{.} and @file{..} path elements and resolving symbolic links.
2199 These are used in the default configuration file to allow people to
2200 invoke TeX from anywhere, specifically from a mounted CD-ROM. (You can
2201 use @samp{--expand-var=\$SELFAUTOLOC}, etc., to see the values finds.)
2204 @findex kpse_set_progname
2206 The @code{kpse_set_progname} is deprecated. A call to
2207 @code{kpse_set_progname} with @code{argv[0]} is equivalent to a call of
2208 @code{kpse_set_program_name} with first argument @code{argv[0]} and
2209 second argument @code{NULL}. The function is deprecated because it
2210 cannot ensure that the @code{.@var{program}} feature of config files
2211 will always work (@pxref{Config files}).
2214 @vindex kpathsea_debug @r{variable}
2215 @cindex debugging options, in Kpathsea-using program
2216 Set debugging options. @xref{Debugging}. If your program doesn't have a
2217 debugging option already, you can define one and set
2218 @code{kpathsea_debug} to the number that the user supplies (as in Dviljk
2219 and Web2c), or you can just omit this altogether (people can always set
2220 @code{KPATHSEA_DEBUG}). If you do have runtime debugging already, you
2221 need to merge Kpathsea's options with yours (as in Dvipsk and Xdvik).
2224 @vindex client_path @r{in @code{kpse_format_info}}
2225 @vindex kpse_format_info
2227 @cindex config files, for Kpathsea-using programs
2228 If your program has its own configuration files that can define search
2229 paths, you should assign those paths to the @code{client_path} member in
2230 the appropriate element of the @code{kpse_format_info} array. (This
2231 array is indexed by file type; see @file{tex-file.h}.) See
2232 @file{resident.c} in Dvipsk for an example.
2235 @findex kpse_init_prog
2237 Call @code{kpse_init_prog} (see @file{proginit.c}). It's useful for the
2238 DVI drivers, at least, but for other programs it may be simpler to
2239 extract the parts of it that actually apply. This does not initialize
2240 any paths, it just looks for (and sets) certain environment variables
2241 and other random information. (A search path is always initialized at
2242 the first call to find a file of that type; this eliminates much useless
2243 work, e.g., initializing the Bib@TeX{} search paths in a DVI driver.)
2247 @findex kpse_find_file
2248 The routine to actually find a file of type @var{format} is
2249 @code{kpse_find_@var{format}}, defined in @file{tex-file.h}. These are
2250 macros that expand to a call to @file{kpse_find_file}. You can call,
2251 say, @code{kpse_find_tfm} after doing only the first of the
2252 initialization steps above---Kpathsea automatically reads the
2253 @file{texmf.cnf} generic config files, looks for environment variables,
2254 and does expansions at the first lookup.
2257 To find PK and/or GF bitmap fonts, the routines are @code{kpse_find_pk},
2258 @code{kpse_find_gf} and @code{kpse_find_glyph}, defined in
2259 @file{tex-glyph.h}. These return a structure in addition to the
2260 resultant filename, because fonts can be found in so many ways. See the
2261 documentation in the source.
2264 @findex kpse_open_file
2265 To actually open a file, not just return a filename, call
2266 @code{kpse_open_file}. This function takes the name to look up and a
2267 Kpathsea file format as arguments, and returns the usual @code{FILE *}.
2268 It always assumes the file must exist, and thus will search the disk if
2269 necessary (unless the search path specified @samp{!!}, etc.). In other
2270 words, if you are looking up a VF or some other file that need not
2271 exist, don't use this.
2275 @cindex hash table routines
2276 @cindex memory allocation routines
2277 @cindex string routines
2278 @cindex reading arbitrary-length lines
2279 @cindex input lines, reading
2280 @cindex lines, reading arbitrary-length
2281 Kpathsea also provides many utility routines. Some are generic: hash
2282 tables, memory allocation, string concatenation and copying, string
2283 lists, reading input lines of arbitrary length, etc. Others are
2284 filename-related: default path, tilde, and variable expansion,
2285 @code{stat} calls, etc. (Perhaps someday I'll move the former to a
2289 @pindex autoconf@r{, recommended}
2290 The @file{c-*.h} header files can also help your program adapt to many
2291 different systems. You will almost certainly want to use Autoconf for
2292 configuring your software if you use Kpathsea; I strongly recommend
2293 using Autoconf regardless. It is available from
2294 @url{ftp://prep.ai.mit.edu/pub/gnu/}.
2297 @node Program-specific files
2298 @section Program-specific files
2300 Many programs will need to find some configuration files. Kpathsea
2301 contains some support to make it easy to place them in their own
2302 directories. The Standard @TeX{} directory structure (@pxref{Top,,
2303 Introduction, tds, A Directory Structure for @TeX{} files}), specifies
2304 that such files should go into a subdirectory named after the program,
2305 like @samp{texmf/ttf2pk}.
2307 Two special formats, @samp{kpse_program_text_format} and
2308 @samp{kpse_program_binary_format} exist, which use
2309 @code{.:$TEXMF/@var{program}//} as their compiled-in search path. To
2310 override this default, you can use the variable
2311 @code{@var{PROGRAM}INPUTS} in the environment and/or @samp{texmf.cnf}.
2312 That is to say, the name of the variable is constructed by converting
2313 the name of the program to upper case, and appending @code{INPUTS}.
2315 The only difference between these two formats is whether
2316 @code{kpse_open_file} will open the files it finds in text or binary
2320 @node Programming with config files
2321 @section Programming with config files
2323 @cindex programming with config files
2324 @cindex config files, programming with
2326 You can (and probably should) use the same @code{texmf.cnf}
2327 configuration file that Kpathsea uses for your program. This helps
2328 installers by keeping all configuration in one place.
2330 @findex kpse_var_value
2332 @vindex shell_escape@r{, example for code}
2333 To retrieve a value @var{var} from config files, the best way is to call
2334 @code{kpse_var_value} on the string @code{@var{var}}. This will look
2335 first for an environment variable @var{var}, then a config file value.
2336 The result will be the value found or @samp{NULL}. This function is
2337 declared in @file{kpathsea/variable.h}. For an example, see the
2338 @code{shell_escape} code in @file{web2c/lib/texmfmp.c}.
2340 The routine to do variable expansion in the context of a search path (as
2341 opposed to simply retrieving a value) is @code{kpse_var_expand}, also
2342 declared in @file{kpathsea/variable.h}. It's generally only necessary
2343 to set the search path structure components as explained in the previous
2344 section, rather than using this yourself.
2346 @findex kpse_cnf_get
2348 If for some reason you want to retrieve a value @emph{only} from a
2349 config file, not automatically looking for a corresponding environment
2350 variable, call @code{kpse_cnf_get} (declared in @file{kpathsea/cnf.h})
2351 with the string @var{var}.
2353 No initialization calls are needed.