#! /bin/csh -f -e

# Formats the input as a one-page poster, suitable for corkboard 

set tmp = "/tmp/itp$$"

set err = "/tmp/iso-to-poster.log"
# if ( -e /dev/tty ) then
#   if ( -w /dev/tty ) then
#     set err = "/dev/tty"
#   endif
# endif

set latexland = "\textwidth=7.5in \textheight=9in"
set latexwidth = "10cm"
set latexsize = "\Large"
set latexbegmode = "\rm"
set latexendmode = ""
set dvipsland = ""

while ( $#argv > 0 )
  if ( "x$1" == "x-landscape" ) then
    set latexland = "\textwidth=10in \textheight=6.5in"
    set dvipsland = "-t landscape"
    shift
  else if ( "x$1" == "x-portrait" ) then
    set latexland = "\textwidth=7.5in \textheight=9in"
    set dvipsland = ""
    shift
  else if ( "x$1" == "x-verbatim" ) then
    set latexbegmode = "\begin{verbatim}"
    set latexendmode = "\end{verbatim}"
    shift
  else if ( "x$1" == "x-tex" ) then
    set latexbegmode = "\rm"
    set latexendmode = ""
    shift
  else if ( "x$1" == "x-width" ) then
    set latexwidth = "$2"
    shift; shift
  else if ( "x$1" == "x-tiny" ) then
    set latexsize = "\tiny"
    shift
  else if ( ( "x$1" == "x-script" ) || ( "x$1" == "x-scriptsize" ) then
    set latexsize = "\scriptsize"
    shift
  else if ( ( "x$1" == "x-footnote" ) || ( "x$1" == "footnotesize" ) ) then
    set latexsize = "\footnotesize"
    shift
  else if ( ( "x$1" == "x-small" ) || ( "x$1" == "smallsize" ) ) ) then
    set latexsize = "\small"
    shift
  else if ( ( "x$1" == "x-normal" ) || ( "x$1" == "x-normalsize" ) ) then
    set latexsize = "\normalsize"
    shift
  else if ( "x$1" == "x-large" ) then
    set latexsize = "\large"
    shift
  else if ( "x$1" == "x-Large" ) then
    set latexsize = "\Large"
    shift
  else if ( "x$1" == "x-LARGE" ) then
    set latexsize = "\LARGE"
    shift
  else if ( "x$1" == "x-huge" ) then
    set latexsize = "\huge"
    shift
  else if ( "x$1" == "x-Huge" ) then
    set latexsize = "\Huge"
    shift
  else
    echo "unrecognized option: $1" >> ${err}
    exit 1
  endif
end

/bin/cat  <<EOF > ${tmp}.iso
\nonstopmode
\documentstyle[isoaccent,12pt]{artigo}

\topmargin  -0.5in
\oddsidemargin  -0.5in
\evensidemargin -0.5in
\marginparwidth 10pt
\marginparsep 0pt
${latexland}

\begin{document}
\thispagestyle{empty}

  \hrule height0pt
  \vspace*{\fill}
  \begin{minipage}{\textwidth}
    \begin{center}
      \${}\$%
      \begin{minipage}{${latexwidth}}
${latexsize}
${latexbegmode}
EOF

/bin/cat >> ${tmp}.iso

/bin/cat <<EOF >> ${tmp}.iso 
${latexendmode}
      \end{minipage}
    \end{center}
  \end{minipage}
  \vspace*{\fill}
\end{document}
EOF

cd /tmp/
touch ${tmp}.aux
${TEX_PUB}/bin/patex ${tmp}.iso >> ${err}
/usr/local/bin/dvips -f ${dvipsland} > ${tmp}.ps < ${tmp}.dvi

/bin/cat ${tmp}.ps

/bin/rm ${tmp}.{ps,iso,dvi,aux}
