We have a custom LaTeX build script that was written for bash many years ago. It's nice because it uses the // notation on $texinputs to recursively add image locations (allowing us to use sub-folders without having to type them in each time) and it picks up local templates so they don't have to be installed on the system (which is a real pain when using custom templates with many distributed users). It lets everything be put in one folder where it's self contained and easy shared.
This bash script is below:
#!/bin/bash
# Usage: ./makepdf.sh $tex_file
# Add the files to the search path
export TEXINPUTS=`pwd`:
export TEXINPUTS=`pwd`/references:$TEXINPUTS
if [ -d templates ]; then # Only add templates to path if a template folder is present
export TEXINPUTS=`pwd`/templates:$TEXINPUTS
fi
if [ -d images ]; then # Only add images to path if an image folder is present
export TEXINPUTS=`pwd`/images//:$TEXINPUTS
fi
# Set BIBTeX search path to be the same
export BIBINPUTS=$TEXINPUTS
export BSTINPUTS=$TEXINPUTS
# Create a build directory
if [ ! -d build ]; then
echo Making build directory
mkdir build
fi
# Copy files to the build directory
echo Copying files to build directory
cp $1 ./build
# Calcuate run variables
INPUT=`echo $1 | sed -e 's/.tex//'`
# Run bibtex
cd ./build
echo Running BibTeX
bibtex $INPUT.aux
cd -
# Run latex
# This produces a .dvi file
cd ./build
echo Runnung LaTeX...
latex $1
# Produce a PDFExpress compatible PDF
dvips -Ppdf -G0 -tletter $INPUT.dvi
ps2pdf -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMAxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sPAPERSIZE=letter $INPUT.ps
cd -
# Moving output files
mv ./build/$INPUT.pdf .
# Display the produced file
acroread -openInNewWindow $INPUT.pdf &
It works very well and has for a long time. However, for various (unavoidable) reasons we now have to do development on Windows. I'd like to move the above script to Powershell to allow LaTeX builds to be done in the same way. The current version of this is:
# Usage
# .\makepdf.ps1 -filename $filename.tex
# Set up input arguments
param (
[string]$FILENAME = $(throw "-filename is required.")
)
# Add the files to the search path
$TEXCURRENT = kpsewhich.exe -var-value=TEXINPUTS
$HERE = Get-Location
$TEXINPUTS = $HERE.Path + ";" + $TEXCURRENT
$TEXINPUTS = $HERE.Path + "\references" + ";" + $TEXINPUTS
if(Test-Path -Path .\templates){
$TEXINPUTS = ".\templates" + ";" + $TEXINPUTS
}
if(Test-Path -Path .\images){
$TEXINPUTS = ".\images//" + ";" + $TEXINPUTS
}
Write-Host $TEXINPUTS
# Set BIBTeX search path to be the same
$BIBCURRENT = kpsewhich.exe -var-value=BIBINPUTS
$BIBINPUTS = $TEXINPUTS + ";" + $BIBCURRENT
$BIBCURRENT = kpsewhich.exe -var-value=BSTINPUTS
$BSTINPUTS = $TEXINPUTS + ";" + $BSTCURRENT
# Create a build directory
if(!(Test-Path -Path .\build)){
Write-Host “Making build directory”
New-Item -ItemType directory -Path ".\build" | Out-Null
}
# Copy files to the build directory
Write-Host “Copying files to build directory”
cp "*.tex" .\build
# Calculate run variables
$INPUT = [System.IO.Path]::GetFileNameWithoutExtension($FILENAME)
# Run Biber
cd .\build
biber.exe $INPUT
cd ..\
# Run LuaLaTeX
cd .\build
lualatex.exe $INPUT
cd ..\
# Move output files
cp -Force ".\build\$INPUT.pdf" .\
# Display output file
Start-Process "$INPUT.pdf"
However I can't get the texinputs environment variable to be recognised. It can't add an image folder, nevermind a recursive one, and it doesn't pick up the suggested templates folder.
I understand that there are some negatives on directly modifying texinputs like this. I'm open to other suggestions, as long as the end result is they work in the same way. Presumably I'm supposed to modify it through kpsewhich.exe, but I can't figure out how.
Any suggestions would be appreciated.