我正在尝试为公众编写一个脚本(Perl),该脚本需要列出所有已安装的某种类型的 TeX 文件,例如.sty
和/或.cls
文件或仅有纯 TeX 文件(.tex
),具体取决于所使用的选项。
我知道我可以使用该程序搜索特定文件kpsewhich
,但它似乎没有“列出全部”模式(这是可以理解的)。我的第二个想法是解析所有ls-R
文件,这应该可行,但工作量会更大。
有没有办法获取所有 TeX 源文件或仅获取ls-R
来自kpsewhich
其他工具的文件?
最好的情况下,这应该适用于所有受支持的操作系统上的 TeX Live 和 MikTeX。但是,我的主要目标是 Linux 下的 TeX Live。作为后备解决方案,我将硬编码默认路径并允许用户使用配置文件更改这些路径。
答案1
这是一个 shell 脚本,它查找所有可以通过 kpsewhich 获得的 bst、sty 和 cls 文件。
#!/bin/sh
# 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 <[email protected]>
#
CLS_STYLEFILE=clsFiles.lst
STY_STYLEFILE=styFiles.lst
BST_STYLEFILE=bstFiles.lst
DIRLIST=TeXtree.lst
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
fi
#
# 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
"cls")
rm -f $CLS_STYLEFILE
touch $CLS_STYLEFILE # create new file
;;
"sty")
rm -f $STY_STYLEFILE
touch $STY_STYLEFILE # create new file
;;
"bst")
rm -f $BST_STYLEFILE
touch $BST_STYLEFILE # create new file
;;
*) # all other
rm -f $CLS_STYLEFILE $STY_STYLEFILE $BST_STYLEFILE
touch $CLS_STYLEFILE $STY_STYLEFILE $BST_STYLEFILE
;;
esac
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
"cls")
find $TEXMFLSR -name *.cls >> $CLS_STYLEFILE
;;
"sty")
find $TEXMFLSR -name *.sty >> $STY_STYLEFILE
;;
"bst")
find $TEXMFLSR -name *.bst >> $BST_STYLEFILE
;;
*)
find $TEXMFLSR -name *.cls >> $CLS_STYLEFILE
find $TEXMFLSR -name *.sty >> $STY_STYLEFILE
find $TEXMFLSR -name *.bst >> $BST_STYLEFILE
;;
esac
echo "done!"
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"
答案2
for t in `kpsewhich --expand-var '$TEXMF' | tr -d '{}!' | tr ',' ' '`; do
find $t -type f -ls
done | grep '\.[sc][tl][ys]$' | awk '{print $NF}'