Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to write a script (Perl) for the general public which would need to have a list of all installed TeX files of a certain type, e.g. .sty and/or .cls files or only plainTeX files (.tex), depending on the used options.

I know I can search for specific files using the kpsewhich program, but it seems to have no 'list all' mode (which is understandable). My second idea was to parse all ls-R files which should work, but would be more work.

Is there a way to get all TeX source files or only the ls-R files from kpsewhich or another tool?

At best this should work for both TeX Live and MikTeX on all supported operation systems. However, my main target is TeX Live under Linux. As fall-back solution I would hard code the default paths and allow the user to change these using a configuration file.

share|improve this question
This is not my area of knowledge, but MacTeX provides a program called TeX Live Utility which is a GUI for tlmgr which can list all the installed packages: tug.org/texlive/doc/… Maybe you could utilise its approach. –  Harold Cavendish Jul 22 '11 at 17:03
Or you could probably use shell find /usr/local/texlive -name "*.sty". –  Harold Cavendish Jul 22 '11 at 17:14
Thanks @Harrold, I know about such possibilities. I'm trying to avoid them and #use the official tools to get the official paths. –  Martin Scharrer Jul 22 '11 at 17:20
You might want to use the fact that in modern TeX distributions, texlua is a standalone lua interpreter. –  mbork Jul 22 '11 at 17:28
@mbork: So call texlua with Lua code from inside a Perl script??? Or are your trying to tell me to not use Perl at all but Lua? –  Martin Scharrer Jul 22 '11 at 17:33
show 3 more comments

2 Answers

up vote 2 down vote accepted

here is a shell script, which finds all bst,sty, and cls files which are available with kpsewhich.

# file: ~/bin/TeXFiles.sh
# lists all available 
# TeX class files   -> option cls 
# TeX style files   -> option sty
# bibtex style files    -> option bst
# with the help
# of kpsewhich and creates a 
# bstFiles.lst, clsFiles.lst, styFiles.lst
# without any parameter all files are created.
# Herbert Voss <hvoss@tug.org>
version='$Id: TeXFiles.sh,v 0.1 2001/08/13'
progname=`echo $0 | sed 's%.*/%%'`
echo "$version"
usage="Usage: TeXFiles.sh [-version | cls | sty | bst] 
       Default is without any Parameters,
       so that all files will be created"

# MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use ';' to separate
# directories in path lists whereas Unixes uses ':'.
# $SEP holds the right character to be used by the scripts.
if test -z "$COMSPEC" && test -z "$ComSpec"; then SEP=':'; else SEP=';'; fi
# Add the location of the script to the PATH if necessary.  This must
# be done before kpsewhich can be called, and thus cannot be put into
# mktex.opt.
dirname=`echo $0 | sed 's%/*[^/][^/]*$%%'`
echo "Actual Dir: $dirname"
case $dirname in            # $dirname correct?
  "")                   # Do nothing
  /* | [A-z]:/*)            # / -> Absolute name 
      PATH="$dirname$SEP$PATH" ;;
   *)                   # other -> Relative name
      PATH="`pwd`/$dirname$SEP$PATH" ;;
esac                    # end of case
# A copy of some stuff from mktex.opt, so we can run in the presence of
# terminally damaged ls-R files.
if test "x$1" = x--help || test "x$1" = x-help; then
  echo "$usage"
  exit 0
elif test "x$1" = x--version || test "x$1" = x-version; then
  echo "`basename $0` $version"
  kpsewhich --version
  exit 0
# find the directories with locate. teTeX has files ls-R to hold
# the tex-tree
test $# = 0 && {
  OIFS=$IFS; IFS=$SEP; set x `kpsewhich --show-path=ls-R 2>/dev/null`; shift; IFS=$OIFS
echo 'Delete old *files.lst, if present'
case "$1" in
    rm -f $CLS_STYLEFILE
    touch $CLS_STYLEFILE        # create new file
    rm -f $STY_STYLEFILE
    touch $STY_STYLEFILE        # create new file
    rm -f $BST_STYLEFILE
    touch $BST_STYLEFILE        # create new file
    *)                  # all other
echo "looking for all *-style files in the latex tree";
#locate ls-R > $DIRLIST
#for TEXMFLSR in `cat $DIRLIST`; do     # go through the dirs
for TEXMFLSR in $@ ; do     # go through the dirs
  echo "Dir: <$TEXMFLSR>"
case "$1" in                # list all files with suffix bst
    find $TEXMFLSR -name *.cls >> $CLS_STYLEFILE
    find $TEXMFLSR -name *.sty >> $STY_STYLEFILE
    find $TEXMFLSR -name *.bst >> $BST_STYLEFILE
    find $TEXMFLSR -name *.cls >> $CLS_STYLEFILE
    find $TEXMFLSR -name *.sty >> $STY_STYLEFILE
    find $TEXMFLSR -name *.bst >> $BST_STYLEFILE

  echo "done!"
#echo "list saved in $STYLEFILE"
#echo `wc -l $CLS_STYLEFILE`        # only for information
# this is the end my friends ... Jim Morrison and the Doors in "The End"
share|improve this answer
add comment
for t in `kpsewhich --expand-var '$TEXMF' | tr -d '{}!' | tr ',' ' '`; do
  find $t -type f -ls
done | grep '\.[sc][tl][ys]$' | awk '{print $NF}'
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.