2 @setfilename kpathsea.info
3 @settitle Kpathsea: A library for path searching
6 @set month-year January 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 * mktexmf: (kpathsea)mktex scripts. MF source generation.
28 * mktexpk: (kpathsea)mktex scripts. PK bitmap generation.
29 * mktextex: (kpathsea)mktex scripts. TeX source generation.
30 * mktextfm: (kpathsea)mktex scripts. TeX font metric generation.
31 * mktexlsr: (kpathsea)Filename database. Update ls-R.
35 This file documents the Kpathsea library for path searching.
37 Copyright @copyright{} 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
38 2004, 2005, 2007, 2008 Karl Berry & Olaf Weber.
40 Permission is granted to make and distribute verbatim copies of this
41 manual provided the copyright notice and this permission notice are
42 preserved on all copies.
45 Permission is granted to process this file through TeX and print the
46 results, provided the printed document carries a copying permission
47 notice identical to this one except for the removal of this paragraph
48 (this paragraph not being relevant to the printed manual).
51 Permission is granted to copy and distribute modified versions of this
52 manual under the conditions for verbatim copying, provided that the
53 entire resulting derived work is distributed under the terms of a
54 permission notice identical to this one.
56 Permission is granted to copy and distribute translations of this manual
57 into another language, under the above conditions for modified versions,
58 except that this permission notice may be stated in a translation
59 approved by the Free Software Foundation.
65 @title Kpathsea library
66 @subtitle for version @value{version}
67 @subtitle @value{month-year}
68 @author Karl Berry (@email{kb@@mail.tug.org})
69 @author Olaf Weber (@email{infovore@@xs4all.nl})
72 @vskip 0pt plus 1filll
81 This manual documents how to install and use the Kpathsea library for
82 filename lookup. It corresponds to version @value{version},
83 released in @value{month-year}.
86 * Introduction:: Overview.
87 * Installation:: Compilation, installation, and bug reporting.
89 * Path searching:: How filename lookups work.
90 * TeX support:: Special support for TeX-related file lookups.
92 * Programming:: How to use Kpathsea features in your program.
94 * Index:: General index.
100 @chapter Introduction
103 @cindex fundamental purpose of Kpathsea
105 This manual corresponds to version @value{version} of the Kpathsea
106 library, released in @value{month-year}.
108 The library's fundamental purpose is to return a filename from a list of
109 directories specified by the user, similar to what shells do when
110 looking up program names to execute.
112 @cindex programs using the library
113 The following software, all of which we maintain, uses this library:
116 @item Dviljk (see the @samp{dvilj} man page)
117 @item Dvipsk (@pxref{Top, , Introduction, dvips, Dvips: A DVI driver})
118 @item GNU font utilities (@pxref{Top, , Introduction, fontu, GNU font
120 @item Web2c (@pxref{Top, , Introduction, web2c, Web2c: A @TeX{}
122 @item Xdvik (see the @samp{xdvi} man page)
125 @noindent Other software that we do not maintain also uses it.
127 @cindex interface, not frozen
128 @cindex comments, making
129 @cindex suggestions, making
130 We are still actively maintaining the library (and probably always will
131 be, despite our hopes). If you have comments or suggestions, please send
132 them to us (@pxref{Reporting bugs}).
134 @cindex conditions for use
135 @cindex license for using the library
136 @cindex GNU General Public License
137 We distribute the library under the GNU Library General Public License
138 (LGPL). In short, this means if you write a program using the library,
139 you must (offer to) distribute the source to the library, along with any
140 changes you have made, and allow anyone to modify the library source and
141 distribute their modifications. It does not mean you have to distribute
142 the source to your program, although we hope you will. See the files
143 @file{GPL} and @file{LGPL} for the text of the GNU licenses.
145 @cindex @TeX{} Users Group
146 If you know enough about @TeX{} to be reading this manual, then you (or
147 your institution) should consider joining the @TeX{} Users Group (if
148 you're already a member, great!). TUG produces the periodical
149 @cite{TUGboat}, sponsors an annual meeting and publishes the
150 proceedings, and arranges courses on @TeX{} for all levels of users
151 throughout the world. Anyway, here is the address:
153 @flindex tug@@tug.org
157 Portland OR 97208-2311
159 phone: +1 503 223-9994
161 email: @email{tug@@tug.org}
172 @cindex history of Kpathsea
174 @cindex Knuth, Donald E.
175 (This section is for those people who are curious about how the library
176 came about.) (If you like to read historical accounts of software, we
177 urge you to seek out the GNU Autoconf manual and the ``Errors of
178 @TeX{}'' paper by Don Knuth, published in @cite{Software---Practice and
179 Experience} 19(7), July 1989.)
186 @pindex pxp @r{Pascal preprocessor}
187 @pindex pc @r{Pascal compiler}
188 [Karl writes.] My first ChangeLog entry for Web2c seems to be February
189 1990, but I may have done some work before then. In any case, Tim
190 Morgan and I were jointly maintaining it for a time. (I should mention
191 here that Tim had made Web2c into a real distribution long before I had
192 ever used it or even heard of it, and Tom Rokicki did the original
193 implementation. I was using @code{pxp} and @code{pc} on VAX 11/750's
194 and the hot new Sun 2 machines.)
196 It must have been later in 1990 and 1991 that I started working on
197 @cite{@TeX{} for the Impatient}. Dvips, Xdvi, Web2c, and the GNU
198 fontutils (which I was also writing at the time) all used different
199 environment variables, and, more importantly, had different bugs in
200 their path searching. This became extremely painful, as I was stressing
201 everything to the limit working on the book. I also desperately wanted
202 to implement subdirectory searching, since I couldn't stand putting
203 everything in one big directory, and also couldn't stand having to
204 explicitly specify @file{cm}, @file{pandora}, @dots{} in a path.
207 In the first incarnation, I just hacked separately on each
208 program---that was the original subdirectory searching code in both Xdvi
209 and Dvips, though I think Paul Vojta has completely rewritten Xdvi's
210 support by now. That is, I tried to go with the flow in each program,
211 rather than changing the program's calling sequences to conform to
214 Then, as bugs inevitably appeared, I found I was fixing the same thing
215 three times (Web2c and fontutils were always sharing code, since I
216 maintained those---there was no Dvipsk or Xdvik or Dviljk at this
217 point). After a while, I finally started sharing source files. They
218 weren't yet a library, though. I just kept things up to date with shell
219 scripts. (I was developing on a 386 running ISC 2.2 at the time, and so
220 didn't have symbolic links. An awful experience.)
222 @cindex MacKenzie, David
223 The ChangeLogs for Xdvik and Dvipsk record initial releases of those
224 distributions in May and June 1992. I think it was because I was tired
225 of the different configuration strategies of each program, not so much
226 because of the path searching. (Autoconf was being developed by David
227 MacKenzie and others, and I was adapting it to @TeX{} and friends.)
230 I started to make a separate library that other programs could link with
231 on my birthday in April 1993, according to the ChangeLog. I don't
232 remember exactly why I finally took the time to make it a separate
233 library; a conversation with david zuhn that initiated it. Just seemed
236 @cindex Walsh, Norman
237 @cindex Neumann, Gustaf
238 Dviljk got started in March 1994 after I bought a Laserjet 4. (Kpathsea
239 work got suspended while Norm Walsh and I, with Gustaf Neumann's help,
240 implemented a way for @TeX{} to get at all those neat builtin LJ4 fonts
241 @dots{} such a treat to have something to typeset in besides Palatino!)
243 By spring of 1995, I had implemented just about all the path-searching
244 features in Kpathsea that I plan to, driven beyond my initial goals by
245 Thomas Esser and others. I then started to integrate Web2c with
246 Kpathsea. After the release of a stable Web2c, I hope to be able to stop
247 development, and turn most of my attention back to making fonts for GNU.
248 (Always assuming Micros**t hasn't completely obliterated Unix by then,
249 or that software patents haven't stopped software development by anybody
250 smaller than a company with a million-dollar-a-year legal budget. Which
251 is actually what I think is likely to happen, but that's another
255 [Olaf writes.] At the end of 1997, UNIX is still alive and kicking,
256 individuals still develop software, and Web2c development still
257 continues. Karl had been looking for some time for someone to take up
258 part of the burden, and I volunteered.
261 @include install.texi
263 @include unixtex.texi
268 @chapter Path searching
270 @cindex path searching
272 This chapter describes the generic path searching mechanism Kpathsea
273 provides. For information about searching for particular file types
274 (e.g., @TeX{} fonts), see the next chapter.
277 * Searching overview:: Basic scheme for searching.
278 * Path sources:: Where search paths can be defined.
279 * Path expansion:: Special constructs in search paths.
280 * Filename database:: Using an externally-built list to search.
281 * Invoking kpsewhich:: Standalone path lookup.
285 @node Searching overview
286 @section Searching overview
288 @cindex searching overview
289 @cindex path searching, overview
290 @cindex overview of path searching
292 @cindex search path, defined
293 A @dfn{search path} is a colon-separated list of @dfn{path elements},
294 which are directory names with a few extra frills. A search path can
295 come from (a combination of) many sources; see below. To look up a file
296 @samp{foo} along a path @samp{.:/dir}, Kpathsea checks each element of
297 the path in turn: first @file{./foo}, then @file{/dir/foo}, returning
298 the first match (or possibly all matches).
300 @cindex magic characters
301 @kindex : @r{may not be :}
302 @kindex / @r{may not be /}
303 The ``colon'' and ``slash'' mentioned here aren't necessarily @samp{:}
304 and @samp{/} on non-Unix systems. Kpathsea tries to adapt to other
305 operating systems' conventions.
307 @cindex database search
308 @cindex searching the database
309 To check a particular path element @var{e}, Kpathsea first sees if a
310 prebuilt database (@pxref{Filename database}) applies to @var{e}, i.e.,
311 if the database is in a directory that is a prefix of @var{e}. If so,
312 the path specification is matched against the contents of the database.
314 @cindex floating directories
315 @cindex filesystem search
317 @cindex searching the disk
318 If the database does not exist, or does not apply to this path element,
319 or contains no matches, the filesystem is searched (if this was not
320 forbidden by the specification with @samp{!!} and if the file being
321 searched for must exist). Kpathsea constructs the list of directories
322 that correspond to this path element, and then checks in each for the
323 file being searched for. (To help speed future lookups of files in the
324 same directory, the directory in which a file is found is floated to the
325 top of the directory list.)
328 @cindex VF files, not found
331 The ``file must exist'' condition comes into play with VF files and
332 input files read by the @TeX{} @samp{\openin} command. These files may
333 not exist (consider @file{cmr10.vf}), and so it would be wrong to search
334 the disk for them. Therefore, if you fail to update @file{ls-R} when
335 you install a new VF file, it will never be found.
337 Each path element is checked in turn: first the database, then the disk.
338 If a match is found, the search stops and the result is returned. This
339 avoids possibly-expensive processing of path specifications that are
340 never needed on a particular run. (Unless the search explicitly
341 requested all matches.)
343 @cindex expansion, path element
344 Although the simplest and most common path element is a directory name,
345 Kpathsea supports additional features in search paths: layered default
346 values, environment variable names, config file values, users' home
347 directories, and recursive subdirectory searching. Thus, we say that
348 Kpathsea @dfn{expands} a path element, meaning transforming all the
349 magic specifications into the basic directory name or names. This
350 process is described in the sections below. It happens in the same
351 order as the sections.
353 @cindex absolute filenames
354 @cindex relative filenames
355 @cindex explicitly relative filenames
356 @cindex filenames, absolute or explicitly relative
357 Exception to all of the above: If the filename being searched for is
358 absolute or explicitly relative, i.e., starts with @samp{/} or @samp{./}
359 or @samp{../}, Kpathsea simply checks if that file exists.
361 @cindex permission denied
362 @cindex unreadable files
363 @cindex access warnings
364 @cindex warnings, file access
365 @flindex lost+found @r{directory}
367 Ordinarily, if Kpathsea tries to access a file or directory that cannot
368 be read, it gives a warning. This is so you will be alerted to
369 directories or files that accidentally lack read permission (for
370 example, a @file{lost+found}). If you prefer not to see these warnings,
371 include the value @samp{readable} in the @code{TEX_HUSH} environment
372 variable or config file value.
374 This generic path searching algorithm is implemented in
375 @file{kpathsea/pathsearch.c}. It is employed by a higher-level
376 algorithm when searching for a file of a particular type (@pxref{File
377 lookup}, and @ref{Glyph lookup}).
381 @section Path sources
384 @cindex sources for search paths
386 A search path can come from many sources. In the order in which
391 @cindex environment variable, source for path
392 A user-set environment variable, e.g., @code{TEXINPUTS}.
393 Environment variables with an underscore and the program name appended
394 override; for example, @code{TEXINPUTS_latex} overrides @code{TEXINPUTS}
395 if the program being run is named @samp{latex}.
398 A program-specific configuration file, e.g., an @samp{S /a:/b} line in
399 Dvips' @file{config.ps} (@pxref{Config files,,, dvips, Dvips}).
402 @cindex configuration file, source for path
403 @cindex Kpathsea config file, source for path
404 @flindex texmf.cnf@r{, source for path}
405 A line in a Kpathsea configuration file @file{texmf.cnf}, e.g.,
406 @samp{TEXINPUTS=/c:/d} (see below).
409 @cindex compilation value, source for path
410 The compile-time default (specified in @file{kpathsea/paths.h}).
413 You can see each of these values for a given search path by using the
414 debugging options (@pxref{Debugging}).
416 These sources may be combined via default expansion (@pxref{Default
420 * Config files:: Kpathsea's runtime config files (texmf.cnf).
425 @subsection Config files
428 @flindex texmf.cnf@r{, definition for}
430 @cindex runtime configuration files
432 As mentioned above, Kpathsea reads @dfn{runtime configuration files}
433 named @file{texmf.cnf} for search path and other definitions. The
434 search path used to look for these configuration files is named
435 @code{TEXMFCNF}, and is constructed in the usual way, as described
436 above, except that configuration files cannot be used to define the
437 path, naturally; also, an @file{ls-R} database is not used to search for
440 Kpathsea reads @emph{all} @file{texmf.cnf} files in the search path, not
441 just the first one found; definitions in earlier files override those in
442 later files. Thus, if the search path is @samp{.:$TEXMF}, values from
443 @file{./texmf.cnf} override those from @file{$TEXMF/texmf.cnf}.
445 While (or instead of) reading this description, you may find it helpful
446 to look at the distributed @file{texmf.cnf}, which uses or at least
447 mentions most features. The format of @file{texmf.cnf} files follows:
451 @cindex comments, in @file{texmf.cnf}
452 Comments start with @samp{%} and continue to the end of the line.
455 @cindex blank lines, in @file{texmf.cnf}
456 Blank lines are ignored.
459 @cindex backslash-newline
460 @cindex continuation character
461 @cindex whitespace, not ignored on continuation lines
462 @kindex \@r{, line continuation in @file{texmf.cnf}}
463 A @samp{\} at the end of a line acts as a continuation character, i.e.,
464 the next line is appended. Whitespace at the beginning of continuation
465 lines is not ignored.
467 @item Each remaining line must look like
470 @var{variable} @r{[}. @var{progname}@r{]} @r{[}=@r{]} @var{value}
473 @noindent where the @samp{=} and surrounding whitespace is optional.
476 @cindex identifiers, characters valid in
477 The @var{variable} name may contain any character other than whitespace,
478 @samp{=}, or @samp{.}, but sticking to @samp{A-Za-z_} is safest.
480 @item If @samp{.@var{progname}} is present, the definition only
481 applies if the program that is running is named (i.e., the last
482 component of @code{argv[0]} is) @var{progname} or
483 @file{@var{progname}.exe}. This allows different flavors of @TeX{} to
484 have different search paths, for example.
487 @cindex right-hand side of variable assignments
488 @var{value} may contain any characters except @samp{%} and @samp{@@}.
489 (These restrictions are only necessary because of the processing done on
490 @file{texmf.cnf} at build time, so you can stick those characters in
491 after installation if you have to.) The @samp{$@var{var}.@var{prog}}
492 feature is not available on the right-hand side; instead, you must use
493 an additional variable (see below for example). A @samp{;} in
494 @var{value} is translated to @samp{:} if running under Unix; this is
495 useful to write a single @file{texmf.cnf} which can be used under both
498 @item All definitions are read before anything is expanded, so you can
499 use variables before they are defined (like Make, unlike most other
503 @noindent Here is a configuration file fragment illustrating most of
507 % TeX input files -- i.e., anything to be found by \input or \openin ...
508 latex209_inputs = .:$TEXMF/tex/latex209//:$TEXMF/tex//
509 latex2e_inputs = .:$TEXMF/tex/latex//:$TEXMF/tex//
510 TEXINPUTS = .:$TEXMF/tex//
511 TEXINPUTS.latex209 = $latex209_inputs
512 TEXINPUTS.latex2e = $latex2e_inputs
513 TEXINPUTS.latex = $latex2e_inputs
516 @cindex shell scripts as configuration files
517 @cindex configuration files as shell scripts.
518 Although this format has obvious similarities to Bourne shell
519 scripts---change the comment character to @code{#}, disallow spaces
520 around the @code{=}, and get rid of the @code{.@var{name}} convention,
521 and it could be run through the shell. But there seemed little
522 advantage to doing this, since all the information would have to passed
523 back to Kpathsea and parsed there anyway, since the @code{sh} process
524 couldn't affect its parent's environment.
527 The implementation of all this is in @file{kpathsea/cnf.c}.
531 @section Path expansion
533 @cindex path expansion
534 @cindex expansion, search path
536 Kpathsea recognizes certain special characters and constructions in
537 search paths, similar to that in shells. As a general example:
538 @samp{~$USER/@{foo,bar@}//baz} expands to all subdirectories under
539 directories @file{foo} and @file{bar} in @t{$USER}'s home directory that
540 contain a directory or file @file{baz}. These expansions are explained
541 in the sections below.
544 * Default expansion:: a: or :a or a::b expands to a default.
545 * Variable expansion:: $foo and $@{foo@} expand to environment values.
546 * Tilde expansion:: ~ and ~user expand to home directories.
547 * Brace expansion:: a@{foo,bar@}b expands to afoob abarb.
548 * KPSE_DOT expansion:: . is replaced with $KPSE_DOT if it is defined.
549 * Subdirectory expansion:: a// and a//b recursively expand to subdirs.
553 @node Default expansion
554 @subsection Default expansion
556 @kindex :: @r{expansion}
557 @cindex doubled colons
558 @cindex leading colons
559 @cindex trailing colons
561 @cindex default expansion
562 @cindex expansion, default
564 If the highest-priority search path (@pxref{Path sources}) contains an
565 @dfn{extra colon} (i.e., leading, trailing, or doubled), Kpathsea
566 inserts at that point the next-highest-priority search path that is
567 defined. If that inserted path has an extra colon, the same happens
568 with the next-highest. (An extra colon in the compile-time default
569 value has unpredictable results, so installers beware.)
571 For example, given an environment variable setting
574 setenv TEXINPUTS /home/karl:
577 @noindent and a @code{TEXINPUTS} value from @file{texmf.cnf} of
583 @noindent then the final value used for searching will be:
586 /home/karl:.:$TEXMF//tex
589 Put another way, default expansion works on ``formats'' (search
590 paths), and not directly on environment variables. Example, showing
591 the trailing @samp{:} ignored in the first case and expanded in the second:
594 $ env TTFONTS=/tmp: kpsewhich --expand-path '$TTFONTS'
596 $ env TTFONTS=/tmp: kpsewhich --show-path=.ttf
597 /tmp:.:/home/olaf/texmf/fonts/truetype//:...
600 Since Kpathsea looks for multiple configuration files, it would be
601 natural to expect that (for example) an extra colon in
602 @file{./texmf.cnf} would expand to the path in @file{$TEXMF/texmf.cnf}.
603 Or, with Dvips' configuration files, that an extra colon in
604 @file{config.$PRINTER} would expand to the path in @file{config.ps}.
605 This doesn't happen. It's not clear this would be desirable in all
606 cases, and trying to devise a way to specify the path to which the extra
607 colon should expand seemed truly baroque.
608 @cindex Bach, Johann Sebastian
610 Technicality: Since it would be useless to insert the default value in
611 more than one place, Kpathsea changes only one extra @samp{:} and leaves
612 any others in place (they will eventually be ignored). Kpathsea checks
613 first for a leading @samp{:}, then a trailing @samp{:}, then a doubled
617 You can trace this by debugging ``paths'' (@pxref{Debugging}).
618 Default expansion is implemented in the source file
619 @file{kpathsea/kdefault.c}.
622 @node Variable expansion
623 @subsection Variable expansion
625 @kindex $ @r{expansion}
626 @cindex environment variables in paths
627 @cindex variable expansion
628 @cindex expansion, variable
629 @flindex texmf.cnf@r{, and variable expansion}
631 @samp{$foo} or @samp{$@{foo@}} in a path element is replaced by (1) the
632 value of an environment variable @samp{foo} (if defined); (2) the value
633 of @samp{foo} from @file{texmf.cnf} (if defined); (3) the empty string.
635 If the character after the @samp{$} is alphanumeric or @samp{_}, the
636 variable name consists of all consecutive such characters. If the
637 character after the @samp{$} is a @samp{@{}, the variable name consists
638 of everything up to the next @samp{@}} (braces may not be nested around
639 variable names). Otherwise, Kpathsea gives a warning and ignores the
640 @samp{$} and its following character.
642 @cindex quoting variable values
643 @cindex shell variables
644 You must quote the @t{$}'s and braces as necessary for your shell.
645 @emph{Shell} variable values cannot be seen by Kpathsea, i.e., ones
646 defined by @code{set} in C shells and without @code{export} in Bourne
651 setenv tex /home/texmf
652 setenv TEXINPUTS .:$tex:$@{tex@}prev
654 @noindent the final @code{TEXINPUTS} path is the three directories:
656 .:/home/texmf:/home/texmfprev
659 The @samp{.@var{progname}} suffix on variables and
660 @samp{_@var{progname}} on environment variable names are not implemented
661 for general variable expansions. These are only recognized when search
662 paths are initialized (@pxref{Path sources}).
665 Variable expansion is implemented in the source file
666 @file{kpathsea/variable.c}.
669 @node Tilde expansion
670 @subsection Tilde expansion
672 @kindex ~ @r{expansion}
673 @cindex home directories in paths
674 @cindex tilde expansion
675 @cindex expansion, tilde
677 @vindex HOME@r{, as ~ expansion}
678 @vindex USERPROFILE@r{, as ~ expansion}
679 A leading @samp{~} in a path element is replaced by the value of the
680 environment variable @code{HOME}, or @file{.} if @code{HOME} is not
681 set. On Windows, the environment variable @code{USERPROFILE} is
682 checked instead of @code{HOME}.
684 A leading @samp{~@var{user}} in a path element is replaced by
685 @var{user}'s home directory from the system @file{passwd} database.
689 setenv TEXINPUTS ~/mymacros:
692 @noindent will prepend a directory @file{mymacros} in your home
693 directory to the default path.
695 @cindex @t{root} user
696 @cindex trailing @samp{/} in home directory
697 @kindex /@r{, trailing in home directory}
698 As a special case, if a home directory ends in @samp{/}, the trailing
699 slash is dropped, to avoid inadvertently creating a @samp{//} construct
700 in the path. For example, if the home directory of the user @samp{root}
701 is @samp{/}, the path element @samp{~root/mymacros} expands to just
702 @samp{/mymacros}, not @samp{//mymacros}.
705 Tilde expansion is implemented in the source file @file{kpathsea/tilde.c}.
708 @node Brace expansion
709 @subsection Brace expansion
711 @kindex @{ @r{expansion}
712 @cindex brace expansion
714 @samp{x@{@var{a},@var{b}@}y} expands to @samp{x@var{a}y:x@var{b}y}.
721 @noindent expands to @samp{foo/1/baz:foo/2/baz}. @samp{:} is the path
722 separator on the current system; e.g., on a DOS system, it's @samp{;}.
724 Braces can be nested; for example, @samp{x@{A,B@{1,2@}@}y} expands to
725 @samp{xAy:xB1y:xB2y}.
727 Multiple non-nested braces are expanded from right to left; for example,
728 @samp{x@{A,B@}@{1,2@}y} expands to @samp{x@{A,B@}1y:x@{A,B@}2y}, which
729 expands to @samp{xA1y:xB1y:xA2y:xB2y}.
731 @cindex multiple @TeX{} hierarchies
732 This feature can be used to implement multiple @TeX{} hierarchies, by
733 assigning a brace list to @code{$TEXMF}, as mentioned in
736 You can also use the path separator in stead of the comma. The last
737 example could have been written @samp{x@{A:B@}@{1:2@}y}.
741 Brace expansion is implemented in the source file
742 @file{kpathsea/expand.c}. It is a modification of the Bash sources, and
743 is thus covered by the GNU General Public License, rather than the
744 Library General Public License that covers the rest of Kpathsea.
747 @node KPSE_DOT expansion
748 @subsection @code{KPSE_DOT} expansion
750 @kindex KPSE_DOT @r{expansion}
752 When @code{KPSE_DOT} is defined in the environment, it names a directory
753 that should be considered the current directory for the purpose of
754 looking up files in the search paths. This feature is needed by the
755 @samp{mktex@dots{}} scripts @ref{mktex scripts}, because these
756 change the working directory. You should not ever define it yourself.
759 @node Subdirectory expansion
760 @subsection Subdirectory expansion
763 @cindex subdirectory searching
764 @cindex expansion, subdirectory
766 @cindex alphabetical order, not
767 Two or more consecutive slashes in a path element following a directory
768 @var{d} is replaced by all subdirectories of @var{d}: first those
769 subdirectories directly under @var{d}, then the subsubdirectories under
770 those, and so on. At each level, the order in which the directories are
771 searched is unspecified. (It's ``directory order'', and definitely not
774 If you specify any filename components after the @samp{//}, only
775 subdirectories which match those components are included. For example,
776 @samp{/a//b} would expand into directories @file{/a/1/b}, @file{/a/2/b},
777 @file{/a/1/1/b}, and so on, but not @file{/a/b/c} or @file{/a/1}.
779 You can include multiple @samp{//} constructs in the path.
781 @samp{//} at the beginning of a path is ignored; you didn't really want
782 to search every directory on the system, did you?
784 @cindex trick for detecting leaf directories
785 @cindex leaf directory trick
786 @cindex Farwell, Matthew
787 @cindex MacKenzie, David
788 I should mention one related implementation trick, which I took from GNU
789 find. Matthew Farwell suggested it, and David MacKenzie implemented it.
792 The trick is that in every real Unix implementation (as opposed to the
793 POSIX specification), a directory which contains no subdirectories will
794 have exactly two links (namely, one for @file{.} and one for @file{..}).
795 That is to say, the @code{st_nlink} field in the @samp{stat} structure
796 will be two. Thus, we don't have to stat everything in the bottom-level
797 (leaf) directories---we can just check @code{st_nlink}, notice it's two,
800 But if you have a directory that contains a single subdirectory and 500
801 regular files, @code{st_nlink} will be 3, and Kpathsea has to stat every
802 one of those 501 entries. Therein lies slowness.
805 You can disable the trick by undefining @code{UNIX_ST_LINK} in
806 @file{kpathsea/config.h}. (It is undefined by default except under Unix.)
809 Unfortunately, in some cases files in leaf directories are
810 @code{stat}'d: if the path specification is, say,
811 @samp{$TEXMF/fonts//pk//}, then files in a subdirectory
812 @samp{@dots{}/pk}, even if it is a leaf, are checked. The reason cannot
813 be explained without reference to the implementation, so read
814 @file{kpathsea/elt-dirs.c} (search for @samp{may descend}) if you are
815 curious. And if you can find a way to @emph{solve} the problem, please
819 Subdirectory expansion is implemented in the source file
820 @file{kpathsea/elt-dirs.c}.
823 @node Filename database
824 @section Filename database (@code{ls-R})
826 @cindex filename database
827 @cindex database, for filenames
828 @cindex externally-built filename database
830 Kpathsea goes to some lengths to minimize disk accesses for searches
831 (@pxref{Subdirectory expansion}). Nevertheless, at installations with
832 enough directories, searching each possible directory for a given file
833 can take an excessively long time (depending on the speed of the disk,
834 whether it's NFS-mounted, how patient you are, etc.).
836 In practice, a font tree containing the standard PostScript and PCL
837 fonts is large enough for searching to be noticeably slow on typical
838 systems these days. Therefore, Kpathsea can use an externally-built
839 ``database'' file named @file{ls-R} that maps files to directories, thus
840 avoiding the need to exhaustively search the disk.
842 A second database file @file{aliases} allows you to give additional
843 names to the files listed in @file{ls-R}. This can be helpful to adapt
844 to ``8.3'' filename conventions in source files.
846 The @file{ls-R} and @file{aliases} features are implemented in the
847 source file @file{kpathsea/db.c}.
850 * ls-R:: The main filename database.
851 * Filename aliases:: Aliases for those names.
852 * Database format:: Syntax details of the database file.
857 @subsection @file{ls-R}
859 @flindex ls-R @r{database file}
862 As mentioned above, you must name the main filename database
863 @file{ls-R}. You can put one at the root of each @TeX{} installation
864 hierarchy you wish to search (@code{$TEXMF} by default); most sites have
865 only one hierarchy. Kpathsea looks for @file{ls-R} files along the
866 @code{TEXMFDBS} path, so that should presumably match the list of
869 The recommended way to create and maintain @samp{ls-R} is to run the
870 @code{mktexlsr} script, which is installed in @samp{$(bindir)}
871 (@file{/usr/local/bin} by default). That script goes to some trouble to
872 follow symbolic links as necessary, etc. It's also invoked by the
873 distributed @samp{mktex@dots{}} scripts.
875 @flindex ls-R@r{, simplest build}
876 At its simplest, though, you can build @file{ls-R} with the command
878 cd @var{/your/texmf/root} && ls -LAR ./ >ls-R
883 @flindex /etc/profile @r{and aliases}
884 presuming your @code{ls} produces the right output format (see the
885 section below). GNU @code{ls}, for example, outputs in this format.
886 Also presuming your @code{ls} hasn't been aliased in a system file
887 (e.g., @file{/etc/profile}) to something problematic, e.g., @samp{ls
888 --color=tty}. In that case, you will have to disable the alias before
889 generating @file{ls-R}. For the precise definition of the file format,
890 see @ref{Database format}.
892 Regardless of whether you use the supplied script or your own, you will
893 almost certainly want to invoke it via @code{cron}, so when you make
894 changes in the installed files (say if you install a new La@TeX{}
895 package), @file{ls-R} will be automatically updated.
897 @opindex -A @r{option to @code{ls}}
900 @flindex . @r{directories, ignored}
901 @flindex .tex @r{file, included in @file{ls-R}}
902 The @samp{-A} option to @code{ls} includes files beginning with @samp{.}
903 (except for @file{.} and @file{..}), such as the file @file{.tex}
904 included with the La@TeX{} tools package. (On the other hand,
905 @emph{directories} whose names begin with @samp{.} are always ignored.)
907 @cindex symbolic links, and @file{ls-R}
908 @opindex -L @r{option to @code{ls}}
909 If your system does not support symbolic links, omit the @samp{-L}.
911 @cindex automounter, and @file{ls-R}
912 @cindex NFS and @file{ls-R}
913 @code{ls -LAR @var{/your/texmf/root}} will also work. But using
914 @samp{./} avoids embedding absolute pathnames, so the hierarchy can be
915 easily transported. It also avoids possible trouble with automounters
916 or other network filesystem conventions.
918 @cindex warning about unusable @file{ls-R}
919 @cindex unusable @file{ls-R} warning
920 Kpathsea warns you if it finds an @file{ls-R} file, but the file does
921 not contain any usable entries. The usual culprit is running plain
922 @samp{ls -R} instead of @samp{ls -LR ./} or @samp{ls -R
923 @var{/your/texmf/root}}. Another possibility is some system directory
924 name starting with a @samp{.} (perhaps if you are using AFS); Kpathsea
925 ignores everything under such directories.
927 @kindex !! @r{in path specifications}
928 @cindex disk searching, avoiding
929 Because the database may be out-of-date for a particular run, if a file
930 is not found in the database, by default Kpathsea goes ahead and
931 searches the disk. If a particular path element begins with @samp{!!},
932 however, @emph{only} the database will be searched for that element,
933 never the disk. If the database does not exist, nothing will be
934 searched. Because this can surprise users (``I see the font
935 @file{foo.tfm} when I do an @code{ls}; why can't Dvips find it?''), it
936 is not in any of the default search paths.
939 @node Filename aliases
940 @subsection Filename aliases
942 @cindex filename aliases
943 @cindex aliases, for filenames
945 In some circumstances, you may wish to find a file under several names.
946 For example, suppose a @TeX{} document was created using a DOS system
947 and tries to read @file{longtabl.sty}. But now it's being run on a Unix
948 system, and the file has its original name, @file{longtable.sty}. The
949 file won't be found. You need to give the actual file
950 @file{longtable.sty} an alias @samp{longtabl.sty}.
952 @c As another example, suppose you are creating a @TeX{} distribution on a
953 @c CD-ROM or a DOS system; then the file @file{mf.base} gets stored as
954 @c @file{mf.bas}. But Metafont on Unix wants to find @file{mf.base}. Here
955 @c you need to give the actual file @file{mf.bas} an alias @samp{mf.base}.
957 You can handle this by creating a file @file{aliases} as a companion to
958 the @file{ls-R} for the hierarchy containing the file in question. (You
959 must have an @file{ls-R} for the alias feature to work.)
961 The format of @file{aliases} is simple: two whitespace-separated words
962 per line; the first is the real name @file{longtable.sty}, and second is
963 the alias (@file{longtabl.sty}). These must be base filenames, with no
964 directory components. @file{longtable.sty} must be in the sibling
967 Also, blank lines and lines starting with @samp{%} or @samp{#} are
968 ignored in @file{aliases}, to allow for comments.
970 If a real file @file{longtabl.sty} exists, it is used regardless of any
974 @node Database format
975 @subsection Database format
977 @cindex format of external database
978 @cindex database, format of
980 The ``database'' read by Kpathsea is a line-oriented file of plain
981 text. The format is that generated by GNU (and most other) @code{ls}
982 programs given the @samp{-R} option, as follows.
986 Blank lines are ignored.
989 If a line begins with @samp{/} or @samp{./} or @samp{../} and ends with
990 a colon, it's the name of a directory. (@samp{../} lines aren't useful,
991 however, and should not be generated.)
994 All other lines define entries in the most recently seen directory.
995 @t{/}'s in such lines will produce possibly-strange results.
998 Files with no preceding directory line are ignored.
1001 For example, here's the first few lines of @file{ls-R} (which totals
1002 about 30K bytes) on my system:
1026 @node Invoking kpsewhich
1027 @section @code{kpsewhich}: Standalone path searching
1030 @cindex path searching, standalone
1031 @cindex standalone path searching
1033 The Kpsewhich program exercises the path searching functionality
1034 independent of any particular application. This can also be useful as a
1035 sort of @code{find} program to locate files in your @TeX{} hierarchies,
1036 perhaps in administrative scripts. It is used heavily in the
1037 distributed @samp{mktex@dots{}} scripts.
1041 kpsewhich @var{option}@dots{} @var{filename}@dots{}
1044 The options and filename(s) to look up can be intermixed.
1045 Options can start with either @samp{-} or @samp{--}, and any unambiguous
1046 abbreviation is accepted.
1049 * Path searching options:: Changing the mode, resolution, etc.
1050 * Auxiliary tasks:: Path and variable expansion.
1051 * Standard options:: --help and --version.
1055 @node Path searching options
1056 @subsection Path searching options
1058 @cindex path searching options
1060 Kpsewhich looks up each non-option argument on the command line as a
1061 filename, and returns the first file found.
1063 Various options alter the path searching behavior:
1068 @cindex all matches, finding
1069 Report all matches found, one per line. By default, if there is more
1070 than one match, just one will be reported (chosen effectively at random).
1072 @item --dpi=@var{num}
1073 @opindex --dpi=@var{num}
1074 @opindex -D @var{num}
1075 @cindex resolution, setting
1076 Set the resolution to @var{num}; this only affects @samp{gf} and
1077 @samp{pk} lookups. @samp{-D} is a synonym, for compatibility with
1078 Dvips. Default is 600.
1080 @item --engine=@var{name}
1081 @opindex --engine=@var{name}
1083 Set the engine name to @var{name}. By default it is not set. The
1084 engine name is used in some search paths to allow files with the same
1085 name but used by different engines to coexist.
1087 @item --format=@var{name}
1088 @opindex --format=@var{name}
1089 Set the format for lookup to @var{name}. By default, the format is
1090 guessed from the filename, with @samp{tex} being used if nothing else
1091 fits. The recognized filename extensions (including any leading
1092 @samp{.}) are also allowable @var{name}s.
1094 All formats also have a name, which is the only way to specify formats
1095 with no associated suffix. For example, for Dvips configuration files
1096 you can use @samp{--format="dvips config"}. (The quotes are for the
1101 @flindex pdftexconfig.tex
1102 When the filename being searched for is @file{config.ps}, the format
1103 is automatically switched to @samp{dvips config}. Similarly, when the
1104 filename is @file{pdftex.cfg}, the format is switched to @samp{pdftex
1105 config} (although @file{pdftex.cfg} is not used any more; look for
1106 @file{pdftexconfig.tex} instead.)
1108 Here's the current list of recognized names and the associated suffixes.
1109 @xref{Supported file formats}, for more information on each of these.
1135 graphic/figure: .eps .epsi
1137 TeX system documentation
1140 PostScript header/font: .pro
1143 type1 fonts: .pfa .pfb
1147 truetype fonts: .ttf .ttc
1164 This option and @samp{--path} are mutually exclusive.
1167 @opindex --interactive
1168 @cindex interactive query
1169 After processing the command line, read additional filenames to look up
1170 from standard input.
1172 @item -mktex=@var{filetype}
1173 @itemx -no-mktex=@var{filetype}
1174 @opindex -mktex=@var{filetype}
1175 @opindex -no-mktex=@var{filetype}
1176 Turn on or off the @samp{mktex} script associated with @var{filetype}.
1177 The only values that make sense for @var{filetype} are @samp{pk},
1178 @samp{mf}, @samp{tex}, and @samp{tfm}. By default, all are off in
1179 Kpsewhich. @xref{mktex scripts}.
1181 @item --mode=@var{string}
1182 @opindex --mode=@var{string}
1183 Set the mode name to @var{string}; this also only affects @samp{gf} and
1184 @samp{pk} lookups. No default: any mode will be found. @xref{mktex
1188 @opindex --must-exist
1189 Do everything possible to find the files, notably including searching
1190 the disk. By default, only the @file{ls-R} database is checked, in the
1191 interest of efficiency.
1193 @item --path=@var{string}
1194 @opindex --path=@var{string}
1195 Search along the path @var{string} (colon-separated as usual), instead
1196 of guessing the search path from the filename. @samp{//} and all the
1197 usual expansions are supported (@pxref{Path expansion}). This option
1198 and @samp{--format} are mutually exclusive. To output the complete
1199 directory expansion of a path, instead of doing a one-shot lookup, see
1200 @samp{--expand-path} and @samp{--show-path} in the following section.
1202 @item --progname=@var{name}
1203 @opindex --progname=@var{name}
1204 Set the program name to @var{name}; default is @samp{kpsewhich}. This
1205 can affect the search paths via the @samp{.@var{prognam}} feature in
1206 configuration files (@pxref{Config files}).
1208 @item --subdir=@var{string}
1209 @opindex --subdir=@var{string}
1210 Report only those matches whose directory part @emph{ends} with
1211 @var{string} (compared literally, except case is ignored on a
1212 case-insensitive operating system). For example, suppose there are
1213 two matches for a given name:
1217 @result{} /some/where/foo.sty
1218 /another/place/foo.sty
1222 Then we can narrow the result to what we are interested in with
1226 kpsewhich --subdir=where foo.sty
1227 @result{} /some/where/foo.sty
1229 kpsewhich --subdir=place foo.sty
1230 @result{} /another/place/foo.sty
1234 The string to match must be at the end of the directory part of the
1235 match, and it is taken literally, with no pattern matching:
1238 kpsewhich --subdir=another foo.sty
1243 The string to match may cross directory components:
1246 kpsewhich --subdir=some/where foo.sty
1247 @result{} /some/where/foo.sty
1251 @option{--subdir} implies @option{--all}; if there is more than one
1252 match, they will all be reported (in our example, both @samp{where}
1253 and @samp{place} end in @samp{e}):
1256 kpsewhich --subdir=e
1257 @result{} /some/where/foo.sty
1258 /another/place/foo.sty
1262 Because of the above rules, the presence of a leading @samp{/} is
1263 important, since it ``anchors'' the match to a full component name:
1266 kpsewhich --subdir=/lace foo.sty
1271 However, a trailing @samp{/} is immaterial (and ignored), since the
1272 match always takes place at the end of the directory part:
1275 kpsewhich --subdir=lace/ foo.sty
1276 @result{} /another/place/foo.sty
1280 The purpose of these rules is to make it convenient to find results
1281 only within a particular area of the tree. For instance, a given
1282 script named @file{foo.lua} might exist within both
1283 @file{texmf-dist/scripts/pkg1/} and @file{texmf-dist/scripts/pkg2/}.
1284 By specifying, say, @samp{--subdir=/pkg1}, you can be sure of getting
1285 the one you are interested in.
1287 We only match at the end because a site might happen to install @TeX{}
1288 in @file{/some/coincidental/pkg1/path/}, and we wouldn't want
1289 @file{texmf-dist/scripts/pkg2/} to match that when searching for
1295 @node Auxiliary tasks
1296 @subsection Auxiliary tasks
1298 @cindex auxiliary tasks
1300 Kpsewhich provides some additional features not strictly related to path
1305 @opindex --debug=@var{num}
1306 @samp{--debug=@var{num}} sets the debugging options to @var{num}.
1310 @opindex --var-value=@var{variable}
1311 @samp{--var-value=@var{variable}} outputs the value of @var{variable},
1312 expanding @samp{$} (@pxref{Variable expansion} and @samp{~} (@pxref{Tilde
1313 expansion}) constructs, but not performing other expansions.
1316 @opindex --expand-braces=@var{string}
1317 @samp{--expand-braces=@var{string}} outputs the variable and brace
1318 expansion of @var{string}. @xref{Path expansion}.
1321 @opindex --expand-var=@var{string}
1322 @samp{--expand-var=@var{string}} outputs the variable and tilde
1323 expansion of @var{string}. For example, the @samp{mktex@dots{}}
1324 scripts run @samp{kpsewhich --expand-var='$TEXMF'} to find the root of
1325 the @TeX{} system hierarchy. @xref{Path expansion}.
1328 @opindex --expand-path=@var{string}
1329 @samp{--expand-path=@var{string}} outputs the complete expansion of
1330 @var{string}, with each element separated by the usual path separator
1331 on the current system (@samp{;} on Windows, @samp{:} otherwise).
1332 This may be useful to construct a custom search path for a format not
1333 otherwise supported. To retrieve the search path for a format that is
1334 already supported, see @samp{--show-path}, next.
1336 Nonexistent directories are culled from the output:
1339 $ kpsewhich --expand-path '/tmp'
1341 $ kpsewhich --expand-path '/nonesuch'
1345 For one-shot uses of an arbitrary (not built in to Kpathsea) path, see
1346 @samp{--path} in the previous section.
1349 @opindex --show-path=@var{name}
1350 @samp{--show-path=@var{name}} shows the path that would be used for file
1351 lookups of file type @var{name}. Either a filename extension
1352 (@samp{pk}, @samp{.vf}, etc.) or an integer can be used, just as with
1353 @samp{--format}, described in the previous section.
1358 @node Standard options
1359 @subsection Standard options
1361 @cindex standard options
1363 Kpsewhich accepts the standard GNU options:
1368 @samp{--help} prints a help message on standard output and exits.
1372 @samp{--version} prints the Kpathsea version number and exits.
1377 @chapter @TeX{} support
1379 @cindex @TeX{} support
1381 Although the basic features in Kpathsea can be used for any type of path
1382 searching, it came about (like all libraries) with a specific
1383 application in mind: I wrote Kpathsea specifically for @TeX{} system
1384 programs. I had been struggling with the programs I was using (Dvips,
1385 Xdvi, and @TeX{} itself) having slightly different notions of how to
1386 specify paths; and debugging was painful, since no code was shared.
1388 Therefore, Kpathsea provides some @TeX{}-specific formats and features.
1389 Indeed, many of the supposedly generic path searching features were
1390 provided because they seemed useful in that con@TeX{}t (font lookup,
1393 Kpathsea provides a standard way to search for files of any of the
1394 supported file types; glyph fonts are a bit different than all the rest.
1395 Searches are based solely on filenames, not file contents---if a GF
1396 file is named @file{cmr10.600pk}, it will be found as a PK file.
1399 * Supported file formats:: File types Kpathsea knows about.
1400 * File lookup:: Searching for most kinds of files.
1401 * Glyph lookup:: Searching for bitmap fonts.
1402 * Suppressing warnings:: Avoiding warnings via TEX_HUSH.
1406 @node Supported file formats
1407 @section Supported file formats
1409 @cindex supported file formats
1410 @cindex file formats, supported
1412 @cindex environment variables for @TeX{}
1413 @cindex @TeX{} environment variables
1415 Kpathsea has support for a number of file types. Each file type has a
1416 list of environment and config file variables that are checked to define
1417 the search path, and most have a default suffix that plays a role in
1418 finding files (see the next section). Some also define additional
1419 suffixes, and/or a program to be run to create missing files on the fly.
1421 @cindex program-varying paths
1422 Since environment variables containing periods, such as
1423 @samp{TEXINPUTS.latex}, are not allowed on some systems, Kpathsea looks
1424 for environment variables with an underscore, e.g.,
1425 @samp{TEXINPUTS_latex} (@pxref{Config files}).
1427 The following table lists the above information.
1433 (Adobe font metrics, @pxref{Metric files,,, dvips, Dvips})
1441 (Metafont memory dump, @pxref{Memory dumps,,, web2c, Web2c})
1442 @code{MFBASES}, @code{TEXMFINI};
1443 suffix @samp{.base}.
1449 (Bib@TeX{} bibliography source, @pxref{bibtex invocation,,, web2c, Web2c})
1450 @code{BIBINPUTS}, @code{TEXBIB};
1456 (Bib@TeX{} style file, @pxref{Basic BibTeX style files,, Basic Bib@TeX{}
1457 style files, web2c, Web2c})
1464 (character map files)
1466 suffix @samp{.cmap}.
1471 (Runtime configuration files, @pxref{Config files})
1481 suffixes @samp{.w}, @samp{.web};
1482 additional suffix @samp{.ch}.
1486 @flindex config.ps@r{, search path for}
1487 (Dvips @samp{config.*} files, such as @file{config.ps}, @pxref{Config
1488 files,,, dvips, Dvips})
1502 (@TeX{} memory dump, @pxref{Memory dumps,,, web2c, Web2c})
1503 @code{TEXFORMATS}, @code{TEXMFINI};
1511 (generic font bitmap, @pxref{Glyph files,,, dvips, Dvips})
1512 @code{@var{program}FONTS}, @code{GFFONTS}, @code{GLYPHFONTS}, @code{TEXFONTS};
1515 @item graphic/figure
1520 (Encapsulated PostScript figures, @pxref{PostScript figures,,, dvips, Dvips})
1521 @code{TEXPICTS}, @code{TEXINPUTS};
1522 additional suffixes: @samp{.eps}, @samp{.epsi}.
1526 @vindex TEXINDEXSTYLE
1528 (makeindex style files)
1529 @code{TEXINDEXSTYLE}, @code{INDEXSTYLE};
1535 (ligature definition files)
1542 (Filename databases, @pxref{Filename database})
1548 (Fontmaps, @pxref{Fontmap})
1556 (MetaPost memory dump, @pxref{Memory dumps,,, web2c, Web2c})
1557 @code{MPMEMS}, @code{TEXMFINI};
1560 @item @r{MetaPost support}
1562 (MetaPost support files, used by DMP; @pxref{dmp invocation,,, web2c, Web2c})
1568 (Metafont source, @pxref{mf invocation,,, web2c, Web2c})
1571 dynamic creation program: @code{mktexmf}.
1576 (Metafont program strings, @pxref{pooltype invocation,,, web2c, Web2c})
1577 @code{MFPOOL}, @code{TEXMFINI};
1578 suffix @samp{.pool}.
1583 (@code{MFT} style file, @pxref{mft invocation,,, web2c, Web2c})
1589 (font-related files that don't fit the other categories)
1595 (MetaPost source, @pxref{mpost invocation,,, web2c, Web2c})
1602 (MetaPost program strings, @pxref{pooltype invocation,,, web2c, Web2c})
1603 @code{MPPOOL}, @code{TEXMFINI};
1604 suffix @samp{.pool}.
1609 (Omega compiled process files)
1610 @code{OCPINPUTS}; @*
1612 dynamic creation program: @code{MakeOmegaOCP}.
1617 (Omega font metrics)
1618 @code{OFMFONTS}, @code{TEXFONTS}; @*
1619 suffixes @samp{.ofm}, @samp{.tfm};
1620 dynamic creation program: @code{MakeOmegaOFM}.
1622 @item opentype fonts
1623 @vindex OPENTYPEFONTS
1625 @code{OPENTYPEFONTS}.
1629 (Omega property lists)
1630 @code{OPLFONTS}, @code{TEXFONTS};
1636 (Omega translation process files)
1643 (Omega virtual fonts)
1644 @code{OVFFONTS}, @code{TEXFONTS};
1650 (Omega virtual property lists)
1651 @code{OVPFONTS}, @code{TEXFONTS};
1655 @vindex PDFTEXCONFIG
1656 (PDF@TeX{}-specific configuration files)
1657 @code{PDFTEXCONFIG}.
1665 (packed bitmap fonts, @pxref{Glyph files,,, dvips, Dvips})
1666 @code{@var{PROGRAM}FONTS} (@var{program} being @samp{XDVI}, etc.),
1667 @code{PKFONTS}, @code{TEXPKS}, @code{GLYPHFONTS}, @code{TEXFONTS};
1669 dynamic creation program: @code{mktexpk}.
1671 @item PostScript header
1673 @vindex TEXPSHEADERS
1675 (downloadable PostScript, @pxref{Header files,,, dvips, Dvips})
1676 @code{TEXPSHEADERS}, @code{PSHEADERS};
1677 additional suffix @samp{.pro}.
1679 @item subfont definition files
1682 (subfont definition files)
1689 (@TeX{} source, @pxref{tex invocation,,, web2c, Web2c})
1692 additional suffixes: none, because such a list cannot be complete;
1693 dynamic creation program: @code{mktextex}.
1695 @item TeX system documentation
1698 (Documentation files for the @TeX{} system)
1701 @item TeX system sources
1702 @flindex source files
1704 (Source files for the @TeX{} system)
1708 @vindex TEXMFSCRIPTS
1709 (Architecture-independent executables distributed in the texmf tree)
1710 @code{TEXMFSCRIPTS}.
1715 (@TeX{} program strings, @pxref{pooltype invocation,,, web2c, Web2c})
1716 @code{TEXPOOL}, @code{TEXMFINI};
1717 suffix @samp{.pool}.
1723 (@TeX{} font metrics, @pxref{Metric files,,, dvips, Dvips})
1724 @code{TFMFONTS}, @code{TEXFONTS};
1726 dynamic creation program: @code{mktextfm}.
1730 (Troff fonts, used by DMP; @pxref{DMP invocation,,, web2c, Web2c})
1733 @item truetype fonts
1737 (TrueType outline fonts) @code{TTFONTS}; suffixes @samp{.ttf},
1745 @vindex TEXPSHEADERS
1746 @vindex DVIPSHEADERS
1747 (Type 1 PostScript outline fonts, @pxref{Glyph files,,, dvips, Dvips})
1748 @code{T1FONTS}, @code{T1INPUTS}, @code{TEXPSHEADERS}, @code{DVIPSHEADERS};
1749 suffixes @samp{.pfa}, @samp{.pfb}.
1753 (Type 42 PostScript outline fonts) @code{T42FONTS}.
1759 (virtual fonts, @pxref{Virtual fonts,,, dvips, Dvips})
1760 @code{VFFONTS}, @code{TEXFONTS};
1769 additional suffix @samp{.ch}.
1773 (files specific to the web2c implementation)
1777 There are two special cases, because the paths and environment variables
1778 always depend on the name of the program: the variable name is
1779 constructed by converting the program name to upper case, and then
1780 appending @samp{INPUTS}. Assuming the program is called @samp{foo},
1781 this gives us the following table.
1784 @item other text files
1786 (text files used by @samp{foo})
1789 @item other binary files
1791 (binary files used by @samp{foo})
1795 If an environment variable by these names are set, the corresponding
1796 @file{texmf.cnf} definition won't be looked at (unless, as usual, the
1797 environment variable value has an extra @samp{:}). @xref{Default
1800 For the font variables, the intent is that:
1803 @code{TEXFONTS} is the default for everything.
1806 @code{GLYPHFONTS} is the default for bitmap (or, more precisely,
1810 Each font format has a variable of its own.
1815 Each program has its own font override path as well; e.g.,
1816 @code{DVIPSFONTS} for Dvipsk. Again, this is for bitmaps, not metrics.
1822 @section File lookup
1825 @cindex searching for files
1826 @cindex @TeX{} file lookup
1828 This section describes how Kpathsea searches for most files (bitmap font
1829 searches are the exception, as described in the next section).
1831 Here is the search strategy for a file @var{name}:
1834 If the file format defines default suffixes, and the suffix of
1835 @var{name} name is not already a known suffix for that format, try the
1836 name with each default appended, and use alternative names found in the
1837 fontmaps if necessary. We postpone searching the disk as long as
1838 possible. Example: given @samp{foo.sty}, look for @samp{foo.sty.tex}
1839 before @samp{foo.sty}. This is unfortunate, but allows us to find
1840 @samp{foo.bar.tex} before @samp{foo.bar} if both exist and we were given
1844 Search for @var{name}, and if necessary for alternative names found in
1845 the fontmaps. Again we avoid searching the disk if possible. Example:
1846 given @samp{foo}, we look for @samp{foo}.
1849 If the file format defines a program to invoke to create missing files,
1850 run it (@pxref{mktex scripts}).
1854 @findex kpse_find_file
1855 This is implemented in the routine @code{kpse_find_file} in
1856 @file{kpathsea/tex-file.c}. You can watch it in action with the
1857 debugging options (@pxref{Debugging}).
1861 @section Glyph lookup
1863 @cindex glyph lookup
1864 @cindex searching for glyphs
1865 @cindex @TeX{} glyph lookup
1867 This section describes how Kpathsea searches for a bitmap font in GF or
1868 PK format (or either) given a font name (e.g., @samp{cmr10}) and a
1869 resolution (e.g., 600).
1871 Here is an outline of the search strategy (details in the sections
1872 below) for a file @var{name} at resolution @var{dpi}. The search stops
1873 at the first successful lookup.
1877 Look for an existing file @var{name}.@var{dpi}@var{format} in the
1878 specified format(s).
1880 @item If @var{name} is an alias for a file @var{f} in the fontmap
1881 file @file{texfonts.map}, look for @var{f}.@var{dpi}.
1883 @item Run an external program (typically named @samp{mktexpk}) to
1884 generate the font (@pxref{mktex scripts})
1886 @item Look for @var{fallback}.@var{dpi}, where @var{fallback} is some
1887 last-resort font (typically @samp{cmr10}).
1890 @flindex tex-glyph.c
1891 @findex kpse_find_glyph_format
1892 This is implemented in @code{kpse_find_glyph_format} in
1893 @file{kpathsea/tex-glyph.c}.
1896 * Basic glyph lookup:: Features common to all glyph lookups.
1897 * Fontmap:: Aliases for fonts.
1898 * Fallback font:: Resolutions and fonts of last resort.
1902 @node Basic glyph lookup
1903 @subsection Basic glyph lookup
1905 @cindex basic glyph lookup
1906 @cindex common features in glyph lookup
1908 When Kpathsea looks for a bitmap font @var{name} at resolution @var{dpi}
1909 in a format @var{format}, it first checks each directory in the search
1910 path for a file @samp{@var{name}.@var{dpi}@var{format}}; for example,
1911 @samp{cmr10.600pk}. Kpathsea looks for a PK file first, then a GF file.
1913 If that fails, Kpathsea looks for
1914 @samp{dpi@var{dpi}/@var{name}.@var{format}}; for example,
1915 @samp{dpi600/cmr10.pk}. This is how fonts are typically stored on
1916 filesystems (such as DOS) that permit only three-character extensions.
1918 @cindex tolerance for glyph lookup
1919 @cindex glyph lookup bitmap tolerance
1920 @findex KPSE_BITMAP_TOLERANCE
1921 If that fails, Kpathsea looks for a font with a close-enough @var{dpi}.
1922 ``Close enough'' is defined by the macro @code{KPSE_BITMAP_TOLERANCE} in
1923 @file{kpathsea/tex-glyph.h} to be @code{@var{dpi} / 500 + 1}. This is
1924 slightly more than the 0.2% minimum allowed by the DVI standard
1925 (@url{@var{CTAN:}/dviware/driv-standard/level-0}).
1931 @cindex fontmap files
1932 @cindex font alias files
1933 @cindex aliases for fonts
1935 @flindex texfonts.map
1936 If a bitmap font or metric file is not found with the original name (see
1937 the previous section), Kpathsea looks through any @dfn{fontmap} files
1938 for an @dfn{alias} for the original font name. These files are named
1939 @file{texfonts.map} and searched for along the @code{TEXFONTMAPS}
1940 environment/config file variable. All @file{texfonts.map} files that
1941 are found are read; earlier definitions override later ones.
1943 This feature is intended to help in two respects:
1948 @cindex fontnames, arbitrary length
1949 An alias name is limited in length only by available memory, not by your
1950 filesystem. Therefore, if you want to ask for @samp{Times-Roman}
1951 instead of @file{ptmr}, you can (you get @samp{ptmr8r}).
1954 @cindex circle fonts
1956 A few fonts have historically had multiple names: specifically,
1957 La@TeX{}'s ``circle font'' has variously been known as @file{circle10},
1958 @file{lcircle10}, and @file{lcirc10}. Aliases can make all the names
1959 equivalent, so that it no longer matters what the name of the installed
1960 file is; @TeX{} documents will find their favorite name.
1964 The format of fontmap files is straightforward:
1967 @cindex comments, in fontmap files
1968 @item Comments start with @samp{%} and continue to the end of the line.
1969 @cindex whitespace, in fontmap files
1970 @item Blank lines are ignored.
1971 @item Each nonblank line is broken up into a series of @dfn{words}:
1972 a sequence of non-whitespace characters.
1973 @findex include @r{fontmap directive}
1974 @item If the first word is @samp{include}, the second word is used as
1975 a filename, and it is searched for and read.
1976 @item Otherwise, the first word on each line is the true filename;
1977 @item the second word is the alias;
1978 @item subsequent words are ignored.
1981 If an alias has an extension, it matches only those files with that
1982 extension; otherwise, it matches anything with the same root, regardless
1983 of extension. For example, an alias @samp{foo.tfm} matches only when
1984 @file{foo.tfm} is being searched for; but an alias @samp{foo} matches
1985 @file{foo.vf}, @file{foo.600pk}, etc.
1987 As an example, here is an excerpt from the @file{texfonts.map} in the
1988 Web2c distribution. It makes the circle fonts equivalent and includes
1989 automatically generated maps for most PostScript fonts available from
1990 various font suppliers.
2002 include bitstrea.map
2006 Fontmaps are implemented in the file @file{kpathsea/fontmap.c}.
2007 The Fontname distribution has much more information on font naming
2008 (@pxref{Introduction,,, fontname, Filenames for @TeX{} fonts}).
2012 @subsection Fallback font
2014 @cindex fallback font
2015 @cindex fallback resolutions
2016 @cindex font of last resort
2017 @cindex resolutions, last-resort
2018 @cindex last-resort font
2024 @vindex default_texsizes
2025 If a bitmap font cannot be found or created at the requested size,
2026 Kpathsea looks for the font at a set of @dfn{fallback resolutions}. You
2027 specify these resolutions as a colon-separated list (like search paths).
2028 Kpathsea looks first for a program-specific environment variable (e.g.,
2029 @code{DVIPSSIZES} for Dvipsk), then the environment variable
2030 @code{TEXSIZES}, then a default specified at compilation time (the Make
2031 variable @code{default_texsizes}). You can set this list to be empty if
2032 you prefer to find fonts at their stated size or not at all.
2034 @flindex cmr10@r{, as fallback font}
2035 @vindex kpse_fallback_font
2036 Finally, if the font cannot be found even at the fallback resolutions,
2037 Kpathsea looks for a fallback font, typically @file{cmr10}. Programs
2038 must enable this feature by assigning to the global variable
2039 @code{kpse_fallback_font} or calling @code{kpse_init_prog}
2040 (@pxref{Calling sequence}); the default is no fallback font.
2043 @node Suppressing warnings
2044 @section Suppressing warnings
2046 @cindex warnings, suppressing
2047 @cindex suppressing warnings
2050 Kpathsea provides a way to suppress selected usually-harmless warnings;
2051 this is useful at large sites where most users are not administrators,
2052 and thus the warnings are merely a source of confusion, not a help. To
2053 do this, you set the environment variable or configuration file value
2054 @code{TEX_HUSH} to a colon-separated list of values. Here are the
2059 Suppress everything possible.
2062 @cindex mismatched checksum warnings
2063 Suppress mismatched font checksum warnings.
2066 @cindex missing character warnings
2067 Suppress warnings when a character is missing from a font that a DVI or
2068 VF file tries to typeset.
2071 Don't suppress any warnings.
2074 @cindex unreadable file warnings
2075 Suppress warnings about attempts to access a file whose permissions
2076 render it unreadable.
2079 @cindex unknown special warnings
2080 @findex \special@r{, suppressing warnings about}
2081 Suppresses warnings about an unimplemented or unparsable
2082 @samp{\special} command.
2085 @noindent @file{tex-hush.c} defines the function that checks the
2086 variable value. Each driver implements its own checks where
2091 @chapter Programming
2093 This chapter is for programmers who wish to use Kpathsea.
2094 @xref{Introduction}, for the conditions under which you may do so.
2097 * Overview: Programming overview. Introduction.
2098 * Calling sequence:: Specifics of what to call.
2099 * Program-specific files:: How to handle these.
2100 * Config: Programming with config files. Getting info from texmf.cnf.
2104 @node Programming overview
2105 @section Programming overview
2107 @cindex programming overview
2108 @cindex overview of programming with Kpathsea
2110 Aside from this manual, your best source of information is the source to
2111 the programs I've modified to use Kpathsea (@pxref{Introduction}). Of
2112 those, Dviljk is probably the simplest, and hence a good place to start.
2113 Xdvik adds VF support and the complication of X resources. Dvipsk adds
2114 the complication of its own config files. Web2c is source code I also
2115 maintain, so it uses Kpathsea rather straightforwardly, but is of course
2116 complicated by the Web to C translation. Finally, Kpsewhich is a small
2117 utility program whose sole purpose is to exercise the main
2118 path-searching functionality.
2120 @flindex pathsearch.h
2122 @flindex tex-glyph.h
2124 Beyond these examples, the @file{.h} files in the Kpathsea source
2125 describe the interfaces and functionality (and of course the @file{.c}
2126 files define the actual routines, which are the ultimate documentation).
2127 @file{pathsearch.h} declares the basic searching routine.
2128 @file{tex-file.h} and @file{tex-glyph.h} define the interfaces for
2129 looking up particular kinds of files. In view of the way the headers
2130 depend on each other, it is recommended to use @code{#include
2131 <kpathsea/kpathsea.h>}, which includes every Kpathsea header.
2135 If you want to include only specific headers, you should still consider
2136 including @file{kpathsea/config.h} before including any other Kpathsea
2137 header, as it provides symbols used in the other headers. Note that
2138 @file{kpathsea/config.h} includes @file{kpathsea/c-auto.h}, which is
2139 generated by Autoconf.
2141 @cindex file types, registering new
2142 The library provides no way for an external program to register new file
2143 types: @file{tex-file.[ch]} must be modified to do this. For example,
2144 Kpathsea has support for looking up Dvips config files, even though no
2145 program other than Dvips will likely ever want to do so. I felt this
2146 was acceptable, since along with new file types should also come new
2147 defaults in @file{texmf.cnf} (and its descendant @file{paths.h}), since
2148 it's simplest for users if they can modify one configuration file for
2151 Kpathsea does not parse any formats itself; it barely opens any files.
2152 Its primary purpose is to return filenames. The GNU font utilities does
2153 contain libraries to read TFM, GF, and PK files, as do the programs
2157 @node Calling sequence
2158 @section Calling sequence
2160 @cindex programming with Kpathsea
2161 @cindex calling sequence
2163 The typical way to use Kpathsea in your program goes something like this:
2168 @findex kpse_set_program_name
2170 Call @code{kpse_set_program_name} with @code{argv[0]} as the first
2171 argument; the second argument is a string or @code{NULL}. The second
2172 argument is used by Kpathsea as the program name for the
2173 @code{.@var{program}} feature of config files (@pxref{Config files}).
2174 If the second argument is @code{NULL}, the value of the first argument
2175 is used. This function must be called before any other use of the
2178 @vindex program_invocation_name
2179 @vindex program_invocation_short_name
2180 @vindex kpse_program_name
2181 @vindex KPATHSEA_DEBUG
2184 @cindex SELFAUTOPARENT
2185 @cindex error message macros
2186 @cindex symlinks, resolving
2187 @cindex expanding symlinks
2188 If necessary, @code{kpse_set_program_name} sets the global variables
2189 @code{program_invocation_name} and @code{program_invocation_short_name}.
2190 These variables are used in the error message macros defined in
2191 @file{kpathsea/lib.h}. It sets the global variable
2192 @code{kpse_program_name} to the program name it uses. It also
2193 initializes debugging options based on the environment variable
2194 @code{KPATHSEA_DEBUG} (if that is set). Finally, it sets the variables
2195 @code{SELFAUTOLOC}, @code{SELFAUTODIR} and @code{SELFAUTOPARENT} to the
2196 location, parent and grandparent directory of the executable, removing
2197 @file{.} and @file{..} path elements and resolving symbolic links.
2198 These are used in the default configuration file to allow people to
2199 invoke TeX from anywhere, specifically from a mounted CD-ROM. (You can
2200 use @samp{--expand-var=\$SELFAUTOLOC}, etc., to see the values finds.)
2203 @findex kpse_set_progname
2205 The @code{kpse_set_progname} is deprecated. A call to
2206 @code{kpse_set_progname} with @code{argv[0]} is equivalent to a call of
2207 @code{kpse_set_program_name} with first argument @code{argv[0]} and
2208 second argument @code{NULL}. The function is deprecated because it
2209 cannot ensure that the @code{.@var{program}} feature of config files
2210 will always work (@pxref{Config files}).
2213 @vindex kpathsea_debug @r{variable}
2214 @cindex debugging options, in Kpathsea-using program
2215 Set debugging options. @xref{Debugging}. If your program doesn't have a
2216 debugging option already, you can define one and set
2217 @code{kpathsea_debug} to the number that the user supplies (as in Dviljk
2218 and Web2c), or you can just omit this altogether (people can always set
2219 @code{KPATHSEA_DEBUG}). If you do have runtime debugging already, you
2220 need to merge Kpathsea's options with yours (as in Dvipsk and Xdvik).
2223 @vindex client_path @r{in @code{kpse_format_info}}
2224 @vindex kpse_format_info
2226 @cindex config files, for Kpathsea-using programs
2227 If your program has its own configuration files that can define search
2228 paths, you should assign those paths to the @code{client_path} member in
2229 the appropriate element of the @code{kpse_format_info} array. (This
2230 array is indexed by file type; see @file{tex-file.h}.) See
2231 @file{resident.c} in Dvipsk for an example.
2234 @findex kpse_init_prog
2236 Call @code{kpse_init_prog} (see @file{proginit.c}). It's useful for the
2237 DVI drivers, at least, but for other programs it may be simpler to
2238 extract the parts of it that actually apply. This does not initialize
2239 any paths, it just looks for (and sets) certain environment variables
2240 and other random information. (A search path is always initialized at
2241 the first call to find a file of that type; this eliminates much useless
2242 work, e.g., initializing the Bib@TeX{} search paths in a DVI driver.)
2246 @findex kpse_find_file
2247 The routine to actually find a file of type @var{format} is
2248 @code{kpse_find_@var{format}}, defined in @file{tex-file.h}. These are
2249 macros that expand to a call to @file{kpse_find_file}. You can call,
2250 say, @code{kpse_find_tfm} after doing only the first of the
2251 initialization steps above---Kpathsea automatically reads the
2252 @file{texmf.cnf} generic config files, looks for environment variables,
2253 and does expansions at the first lookup.
2256 To find PK and/or GF bitmap fonts, the routines are @code{kpse_find_pk},
2257 @code{kpse_find_gf} and @code{kpse_find_glyph}, defined in
2258 @file{tex-glyph.h}. These return a structure in addition to the
2259 resultant filename, because fonts can be found in so many ways. See the
2260 documentation in the source.
2263 @findex kpse_open_file
2264 To actually open a file, not just return a filename, call
2265 @code{kpse_open_file}. This function takes the name to look up and a
2266 Kpathsea file format as arguments, and returns the usual @code{FILE *}.
2267 It always assumes the file must exist, and thus will search the disk if
2268 necessary (unless the search path specified @samp{!!}, etc.). In other
2269 words, if you are looking up a VF or some other file that need not
2270 exist, don't use this.
2274 @cindex hash table routines
2275 @cindex memory allocation routines
2276 @cindex string routines
2277 @cindex reading arbitrary-length lines
2278 @cindex input lines, reading
2279 @cindex lines, reading arbitrary-length
2280 Kpathsea also provides many utility routines. Some are generic: hash
2281 tables, memory allocation, string concatenation and copying, string
2282 lists, reading input lines of arbitrary length, etc. Others are
2283 filename-related: default path, tilde, and variable expansion,
2284 @code{stat} calls, etc. (Perhaps someday I'll move the former to a
2288 @pindex autoconf@r{, recommended}
2289 The @file{c-*.h} header files can also help your program adapt to many
2290 different systems. You will almost certainly want to use Autoconf for
2291 configuring your software if you use Kpathsea; I strongly recommend
2292 using Autoconf regardless. It is available from
2293 @url{ftp://prep.ai.mit.edu/pub/gnu/}.
2296 @node Program-specific files
2297 @section Program-specific files
2299 Many programs will need to find some configuration files. Kpathsea
2300 contains some support to make it easy to place them in their own
2301 directories. The Standard @TeX{} directory structure (@pxref{Top,,
2302 Introduction, tds, A Directory Structure for @TeX{} files}), specifies
2303 that such files should go into a subdirectory named after the program,
2304 like @samp{texmf/ttf2pk}.
2306 Two special formats, @samp{kpse_program_text_format} and
2307 @samp{kpse_program_binary_format} exist, which use
2308 @code{.:$TEXMF/@var{program}//} as their compiled-in search path. To
2309 override this default, you can use the variable
2310 @code{@var{PROGRAM}INPUTS} in the environment and/or @samp{texmf.cnf}.
2311 That is to say, the name of the variable is constructed by converting
2312 the name of the program to upper case, and appending @code{INPUTS}.
2314 The only difference between these two formats is whether
2315 @code{kpse_open_file} will open the files it finds in text or binary
2319 @node Programming with config files
2320 @section Programming with config files
2322 @cindex programming with config files
2323 @cindex config files, programming with
2325 You can (and probably should) use the same @code{texmf.cnf}
2326 configuration file that Kpathsea uses for your program. This helps
2327 installers by keeping all configuration in one place.
2329 @findex kpse_var_value
2331 @vindex shell_escape@r{, example for code}
2332 To retrieve a value @var{var} from config files, the best way is to call
2333 @code{kpse_var_value} on the string @code{@var{var}}. This will look
2334 first for an environment variable @var{var}, then a config file value.
2335 The result will be the value found or @samp{NULL}. This function is
2336 declared in @file{kpathsea/variable.h}. For an example, see the
2337 @code{shell_escape} code in @file{web2c/lib/texmfmp.c}.
2339 The routine to do variable expansion in the context of a search path (as
2340 opposed to simply retrieving a value) is @code{kpse_var_expand}, also
2341 declared in @file{kpathsea/variable.h}. It's generally only necessary
2342 to set the search path structure components as explained in the previous
2343 section, rather than using this yourself.
2345 @findex kpse_cnf_get
2347 If for some reason you want to retrieve a value @emph{only} from a
2348 config file, not automatically looking for a corresponding environment
2349 variable, call @code{kpse_cnf_get} (declared in @file{kpathsea/cnf.h})
2350 with the string @var{var}.
2352 No initialization calls are needed.