Creating an Envelope from Commandline Using LaTeX

This small piece of code will create an envelope from commandline…


MYADDRESS = “Mr X // Street 1 // ZIP”

usage() {
   echo “$0 – print envelopes using LaTeX”
   echo ”   address:   Mr. A // Street 123 // ZIP City, State // Country”
   echo ”   -f <a4,c4,c5,c6,dl> default: $fomat”
   echo ”         a4: a4              “
   echo ”         c4: a4              “
   echo ”         c5: a4 folded in 1/2″
   echo ”         c6: a4 folded in 1/4″
   echo ”         dl: a4 folded in 1/3″
   exit 0

while getopts “f:h” opt; do
   case $opt in
      f) format=$OPTARG; ;;
      h) usage; ;;
shift $(($OPTIND -1))

if [[ $format == c6 ]]; then
elif [[ $format == c5 ]]; then
elif [[ $format == a4 ]]; then
elif [[ $format == c4 ]]; then
elif [[ $format == dl ]]; then
   exit 1


[[ -z $ADDRESS ]] && usage

TMP=$(mktemp -d /tmp/envelope-XXXXXX)
cd $TMP

cat << eof > envelope.tex




pdflatex envelope.tex
lpr -o Duplex=None -o Manualfeed=On -o InputSlot=Envelope -o PageSize=Custom.${lx/mm/}x${ly} -o PageRegion=Custom.${lx/mm/}x${ly} -Penvelope envelope.pdf
rm -rf $TMP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s