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:

# 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
if [ -d images ]; then # Only add images to path if an image folder is present
    export TEXINPUTS=`pwd`/images//:$TEXINPUTS
# Set BIBTeX search path to be the same

# Create a build directory
if [ ! -d build ]; then
    echo Making build directory 
    mkdir build

# 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 + "\references" + ";" + $TEXINPUTS
if(Test-Path -Path .\templates){
    $TEXINPUTS = ".\templates" + ";" + $TEXINPUTS
if(Test-Path -Path .\images){
    $TEXINPUTS = ".\images//" + ";" + $TEXINPUTS

# Set BIBTeX search path to be the same
$BIBCURRENT = kpsewhich.exe -var-value=BIBINPUTS
$BIBCURRENT = kpsewhich.exe -var-value=BSTINPUTS

# 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.

1 Answer 1


I use a Makefile with


and ran into the same problem. My Makefile exports TEXINPUTS but that has no effect and every *tex run fails. It turns out, that not only TEXINPUTS is affected, but about every env-var I like to use.

To remedy the situation I replaced every call to (for example) pdflatex.exe in my recepies with a variable, i.e. $(RUN_PDFLATEX).

First I build the variables, as you do in your PS script and then I put the definition of RUN_PDFLATEX, such that it defines the environment right before the call to the compiler.

My definition of RUN_PDFLATEX in the Makefile:


In a Makefile $(<variable name>) yields the content of a variable and $$ yields a single $. So everytime I use $(RUN_PDFLATEX) I actually issue the powershell command

$TEXINPUTS="/my/paths//:/some/more/paths//"; $BIBINPUTS="/my/paths//:/some/more/paths//"; $BSTINPUITS="/my/paths//:/some/more/paths//"; $OSFONTDIR="/my/paths//:/some/more/paths//"; pdflatex.exe

This does the trick for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .