Skip to content

Commit

Permalink
First Commit for TeX Live Container
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed May 19, 2016
1 parent 01dd07d commit b4c6bb1
Show file tree
Hide file tree
Showing 13 changed files with 1,062 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.md
Dockerfile
.dockerignore
*/temp*
*/*/temp*
temp?
*/.git*
*/*/.git*
.git?
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/

# other files, potentially created by build tools
/.settings
/.classpath
/bin
/classes
/build
/temp
/tmp
/out
/.gradle
/dependency-reduced-pom.xml
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>docker-texlive</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
674 changes: 674 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# docker-texlive
A docker container containing an installation of texlive as well as several useful scripts.
# thomasWeise/docker-texlive

[![Image Size](https://img.shields.io/imagelayers/image-size/thomasweise/texlive/latest.svg)](https://hub.docker.com/r/thomasweise/texlive/)
[![Image Layers](https://img.shields.io/imagelayers/layers/thomasweise/texlive/latest.svg)](https://hub.docker.com/r/thomasweise/texlive/)
[![Docker Pulls](https://img.shields.io/docker/pulls/thomasweise/texlive.svg)](https://hub.docker.com/r/thomasweise/texlive/)
[![Docker Stars](https://img.shields.io/docker/stars/thomasweise/texlive.svg)](https://hub.docker.com/r/thomasweise/texlive/)

This is a docker container containing an up-to-date TeXLive installation with some support scripts.

## Usage

For compiling some document named `myDocument.tex` in folder `/my/path/to/document/` with `xelatex.sh`, you would do something like:

docker run -v /my/path/to/document/:/doc/ -t -i thomasweise/texlive /bin/bash -l
cd `/doc/`
pdflatex.sh myDocument
exit

You can run this image by using:

docker run -t -i thomasweise/texlive:<VERSION> /bin/bash -l

to look around in the image.

## Components

- [`TeX Live`](http://www.tug.org/texlive/) version 2014
- [`ghostscript`](http://ghostscript.com/) version 9.06

## Scripts

We provide a set of scripts (in `/bin/`) that can be used for compiling LaTeX documents:

- `latex.sh <document>` compile the LaTeX `<document>` with LaTeX (also do BibTeX)
- `pdflatex.sh <document>` compile the LaTeX `<document>` with PdfLaTeX (also do BibTeX)
- `xelatex.sh <document>` compile the LaTeX `<document>` with XeLaTeX (also do BibTeX)
- `eps2pdf.sh <document>` convert the EPS file `<document>` to PDF
- `filterPdf.sh <document>` include as many of the used fonts into a PDF produced from a PS or PDF document `<document>`
9 changes: 9 additions & 0 deletions image/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.md
Dockerfile
.dockerignore
*/temp*
*/*/temp*
temp?
*/.git*
*/*/.git*
.git?
46 changes: 46 additions & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# thomasweise/texlive
#
# This is an image with a basic TeX Live installation.
#
#
FROM debian:8.4
MAINTAINER Thomas Weise <[email protected]>

RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' >> /etc/apt/sources.list.d/jessie-backports.list &&\
export LANG=C.UTF-8 &&\
apt-get clean &&\
apt-get update &&\
apt-get autoclean -y &&\
apt-get autoremove -y &&\
apt-get update &&\
apt-get install -f -y apt-utils &&\
apt-get install -f -y ghostscript=9.06* \
latex-cjk-common=4.8.3* \
latex-cjk-chinese=4.8.3* \
texlive-full=2014.* \
texlive-fonts-extra=2014.* \
texlive-fonts-recommended=2014.* \
texlive-lang-cjk=2014.* \
texlive-luatex=2014.* \
texlive-pstricks=2014.* \
texlive-xetex=2014.* &&\
apt-get purge -f -y texlive-fonts-extra-doc \
texlive-fonts-recommended-doc \
texlive-humanities-doc \
texlive-latex-base-doc \
texlive-latex-extra-doc \
texlive-latex-recommended-doc \
texlive-metapost-doc \
texlive-pictures-doc \
texlive-pstricks-doc \
texlive-science-doc &&\
apt-get clean &&\
apt-get autoclean -y &&\
apt-get autoremove -y &&\
apt-get clean &&\
rm -rf /tmp/* /var/tmp/* &&\
rm -rf /var/lib/apt/lists/* &&\
rm -f /etc/ssh/ssh_host_*

ADD scripts /bin/
11 changes: 11 additions & 0 deletions image/scripts/eps2pdf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

document="$1"

echo "Beginning GhostScript runs in order to convert eps file to pdf file."

gs -q -dEmbedAllFonts=true -dSubsetFonts=true -dCompressFonts=true -dOptimize=true -dPreserveCopyPage=false -dPreserveEPSInfo=false -dPreserveHalftoneInfo=false -dPreserveOPIComments=false -dPreserveOverprintSettings=false -dPreserveSeparation=false -dPreserveDeviceN=false -dMaxBitmap=2147483647 -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dFastWebView=false -dNOPAUSE -dQUIET -dBATCH -dSAFER -sDEVICE=pdfwrite -r720x720 -dEPSCrop -dCompatibilityLevel=1.4 -sOutputFile="$document.pdf" -f "$document.eps" -c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams" -c quit

gs -q -dEmbedAllFonts=true -dSubsetFonts=true -dCompressFonts=true -dOptimize=true -dPreserveCopyPage=false -dPreserveEPSInfo=false -dPreserveHalftoneInfo=false -dPreserveOPIComments=false -dPreserveOverprintSettings=false -dPreserveSeparation=false -dPreserveDeviceN=false -dMaxBitmap=2147483647 -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dFastWebView=false -dNOPAUSE -dQUIET -dBATCH -dSAFER -sDEVICE=pdfwrite -r720x720 -dEPSCrop -dCompatibilityLevel=1.4 -sOutputFile="$document.pdf" -f "$document.eps" -c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams" -c quit

echo "Done converting '${document}.eps' to '${document}.pdf'"
34 changes: 34 additions & 0 deletions image/scripts/filterPdf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash -

# This script filters a PDF file and attempts to include
# as many fonts as possible.

echo "Filtering document '$1' in order to include as many fonts as possible."

source="$1"
name="${source%%.*}"
dest="${name}.pdf"

if [ -f "${dest}" ]; then
useSource="${name}.original.pdf"
echo "Creating backup '${useSource}' of '${dest}'."
cp "${dest}" "${useSource}"
else
useSource="${source}"
fi

echo "Filtering '${useSource}' to '${dest}'."

gs -q -dEmbedAllFonts=true -dSubsetFonts=true -dCompressFonts=true \
-dOptimize=true -dPreserveCopyPage=false -dPreserveEPSInfo=false \
-dPreserveHalftoneInfo=false -dPreserveOPIComments=false \
-dPreserveOverprintSettings=false -dPreserveSeparation=false \
-dPreserveDeviceN=false -dMaxBitmap=2147483647 \
-dDownsampleMonoImages=false -dDownsampleGrayImages=false \
-dDownsampleColorImages=false -dDetectDuplicateImages=true \
-dHaveTransparency=true -dFastWebView=false \
-dNOPAUSE -dQUIET -dBATCH -dSAFER -sDEVICE=pdfwrite \
-dAutoRotatePages=/PageByPage -sOutputFile="${dest}" "${useSource}" \
-c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams"

echo "Done filtering document '$1'."
20 changes: 20 additions & 0 deletions image/scripts/latex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -

## Invoke LaTeX

# strict error handling
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset # set -u : exit the script if you try to use an uninitialised variable
set -o errexit # set -e : exit the script if any statement returns a non-true return value

document="$1"
post=${2:-}

currentDir=`pwd`
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$currentDir"

document="$1"

"$scriptDir/tex.sh" latex "${document}" "$post"
20 changes: 20 additions & 0 deletions image/scripts/pdflatex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -

## Invoke PdfLaTeX

# strict error handling
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset # set -u : exit the script if you try to use an uninitialised variable
set -o errexit # set -e : exit the script if any statement returns a non-true return value

document="$1"
post=${2:-}

currentDir=`pwd`
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$currentDir"

document="$1"

"$scriptDir/tex.sh" pdflatex "${document}" "$post"
145 changes: 145 additions & 0 deletions image/scripts/tex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/bash -

## (Pdf)LaTeX Compiler Script
## $1 executable
## $2 document to compile
## $3 post-processing command, if any, executed as $3 "x" where "x" is produced pdf

echo "Welcome to the LaTeX compiler script."

# strict error handling
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset # set -u : exit the script if you try to use an uninitialised variable
set -o errexit # set -e : exit the script if any statement returns a non-true return value

program="$1"
document="${2%%.*}"
post=${3:-}

currentDir=`pwd`
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$currentDir"
echo "Current dir: '$currentDir'. Script source dir: '$scriptDir'."

echo "Applying program '$program' to source file '$document'."

echo "First cleaning up temporary files from other LaTeX runs."
rm "${document}.aux" || true
rm "${document}.bbl" || true
rm "${document}.blg" || true
rm "${document}.dvi" || true
rm "${document}.ent" || true
rm "${document}.idx" || true
rm "${document}.log" || true
rm "${document}.nav" || true
rm "${document}.out" || true
rm "${document}.out.ps" || true
rm "${document}.pdf" || true
rm "${document}.ps" || true
rm "${document}.snm" || true
rm "${document}.synctex" || true
rm "${document}.synctex.gz" || true
rm "${document}.toc" || true
rm "${document}.vrb" || true

echo "We will perform runs of (Pdf)LaTeX/BibTeX until no internal files change anymore."

auxHash=""
oldAuxHash="old"
bblHash=""
oldBblHash="old"
cycle=0

while [ "$oldAuxHash" != "$auxHash" ] || \
[ "$oldBblHash" != "$bblHash" ]; do
cycle=$((cycle+1))
echo "Now beginning build cycle $cycle."

oldAuxHash=$auxHash
oldBblHash=$bblHash

echo "Running '$program'."
${program} "${document}"
if (("$cycle" > 1)) ; then
echo "This is cycle $cycle, so we need to run '$program' a second time."
${program} "${document}"
fi

for i in *.aux; do
if [ "$i" != "$document"] && \
[ "$i" != "$document.aux"] ; then
echo "Applying 'bibtex' to '$i'."
bibtex "$i"
fi
done
echo "Applying 'bibtex' to '$document'."
bibtex "${document}"

auxHash=""
for i in *.aux; do
auxHashTemp=$(sha256sum "$i")
auxHash="$auxHash$auxHashTemp"
done

bblHash=""
for i in *.bbl; do
bblHashTemp=$(sha256sum "$i")
bblHash="$bblHash$bblHashTemp"
done

echo "Finished build cycle $cycle."

if [ "$cycle" -ge 200 ]; then
echo "Something odd is happening: We have performed $cycle cycles. That's too many. Let's quit."
break
fi
done

echo "The tool chain '$program', bibtex has been executed until nothing changed anymore."
echo "We now ensure that a proper pdf is built."

if [ -f "${document}.pdf" ]; then
echo "Pdf file was produced: filter it in order to include all fonts."
"$scriptDir/filterPdf.sh" "${document}.pdf"
rm "${document}.original.pdf"
else
echo "No pdf file was produced."
if [ ! -f "${document}.ps" ]; then
echo "No postscript (.ps) file was produced."
if [ -f "${document}.dvi" ]; then
echo "A dvi file was produced, converting it to postscript (.ps)."
dvips "${document}"
fi
fi
if [ -f "${document}.ps" ]; then
echo "A postscript (.ps) file was found, converting it to pdf."
"$scriptDir/filterPdf.sh" "${document}.ps"
fi
fi

echo "Now cleaning up temporary files."
rm "${document}.aux" || true
rm "${document}.bbl" || true
rm "${document}.blg" || true
rm "${document}.dvi" || true
rm "${document}.ent" || true
rm "${document}.idx" || true
rm "${document}.log" || true
rm "${document}.nav" || true
rm "${document}.out" || true
rm "${document}.out.ps" || true
rm "${document}.ps" || true
rm "${document}.snm" || true
rm "${document}.synctex" || true
rm "${document}.synctex.gz" || true
rm "${document}.toc" || true
rm "${document}.vrb" || true

if [[ -n "$post" ]]
then
echo "The post-processing command '$post' was specified, executing '$post \"${document}.pdf\"'."
$post "${document}.pdf"
fi

echo "LaTeX compilation finished."
Loading

0 comments on commit b4c6bb1

Please sign in to comment.