Skip to content

Instantly share code, notes, and snippets.

@wtsnjp
Last active June 18, 2018 12:03
Show Gist options
  • Select an option

  • Save wtsnjp/2bf9551f381d25657e9521f17881b4ea to your computer and use it in GitHub Desktop.

Select an option

Save wtsnjp/2bf9551f381d25657e9521f17881b4ea to your computer and use it in GitHub Desktop.
Installing LaTeX packages to your local TEXMF tree (TEXMFHOME)
#
# This is file 'ltxpkg-install.zsh'.
#
# Copyright (c) 2018 Takuto ASAKURA (wtsnjp)
# GitHub: https://github.com/wtsnjp
# Twitter: @wtsnjp
#
# This package is distributed under the MIT License.
#
function ltxpkg-install() {
# general variables
local PWD=$(pwd)
local PKG_NAME=$(basename $PWD)
local TEXMFHOME=$(kpsewhich -var-value=TEXMFHOME)
# install targets
local RUN_DIR=${TEXMFHOME}/tex/latex/${PKG_NAME}
local DOC_DIR=${TEXMFHOME}/doc/latex/${PKG_NAME}
# local functions
local function mkdir-p() {
echo mkdir -p $1
mkdir -p $1
}
local function ln-s() {
if [ ! -e $2 ]; then
echo ln -s $1 $2
ln -s $1 $2
fi
}
# install runs
local runs=(
{,lib/,cls/}*.cls(.N)
{,lib/,sty/}*.sty(.N)
{,lib/,def/}*.def(.N)
{,lib/,fd/}*.fd(.N)
)
if [ $#runs -gt 0 ]; then
mkdir-p $RUN_DIR
for r in $runs; do
ln-s ${PWD}/${r} ${RUN_DIR}/$(basename $r)
done
fi
# install docs
local docs=(
README(.N)
LICENSE(.N)
{,doc/,sample/}*.txt(.N)
{,doc/,sample/}*.md(.N)
{,doc/,sample/}*.pdf(.N)
)
if [ $#docs -gt 0 ]; then
mkdir-p $DOC_DIR
for d in $docs; do
ln-s ${PWD}/${d} ${DOC_DIR}/$(basename $d)
done
fi
}
@wtsnjp
Copy link
Author

wtsnjp commented Jun 18, 2018

This script is a kind of meta-Makefile. It works only for general LaTeX packages.

Installation

Write following line to your .zshrc:

source path/to/your/ltxpkg-install.zsh

Usage

cd path/to/a/latex/package
ltxpkg-install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment