% Format the comments
%\usepackage{pstricks}
\usepackage{graphicx}
\usepackage[xetex]{hyperref}
%\PassOptionsToPackage{pdftex,svgnames,table,hyperref}{xcolor}
\usepackage[svgnames,table,hyperref]{xcolor}

%\newpsstyle{stA}{linestyle=solid}  % make bar chart bars have border
\definecolor{colorfive}{rgb}{.608,.686,.545} % hex=9baf8b
\definecolor{colorfour}{rgb}{.675,.762,.605}  
\definecolor{colorthree}{rgb}{.743,.839,.664}
\definecolor{colortwo}{rgb}{.810,.915,.723}
\definecolor{colorone}{rgb}{.878,.992,.784} % hex=e0fdc8 rgb=224,253,200 color on web page
\definecolor{colorzero}{rgb}{1,1,1}


%\usepackage{color}
\usepackage{colortbl}
\usepackage{longtable}


\usepackage{calc}


% Format the questions
\newcommand{\questiontext}[2]{%
\item[]\textbf{Question~#1.} \textbf{#2}\par\noindent }

% Format the responses
\newcommand{\tablelabelarray}[2]{%
\textrm{\renewcommand{\arraystretch}{.6} 
\begin{tabular}{c}  
  \scriptsize\textsc{#1} \\ 
  \scriptsize\textsc{#2} 
\end{tabular}}}


\newcommand{\barChartLeaderFill}{\leaders\hbox to 1em{\hss.\hss}\hfill}


% Everything done with calc package

% Change this length to make the bars taller or shorter; max is 100 times
\newcommand{\barHeightUnitLength}{.25pt} 

% Change this number to make bars wider or narrower
\newcommand{\barWidthFactor}{50}  

% Change this length to make the frame around bars thicker
\newlength{\barRuleWidth}\setlength{\barRuleWidth}{.3pt}

% These are used for by-bar calculation
\newlength{\barRuleHeight} % Height of vertical part of bar frame 
\newlength{\barHeight} % Height of bar
\newlength{\barWidth}  % Width of bar
\setlength{\barWidth}{\barHeightUnitLength*\barWidthFactor}

% \makeBar  
%  Make one bar for a bar chart
%  #1  optional; if present set the text below the bar
%  #2  number in range 0..100; height of bar
%  #3  color;  color of interior of bar
% Programming note:  The top and bottom rules in the frame stick out 1/2
%  of their width so a 0-tall bar has exactly 1 rule's height
\newcommand{\makeBar}[3][\relax]{%
  \setlength{\unitlength}{\barHeightUnitLength}% for picture environment
  \setlength{\barHeight}{\unitlength*#2}% how tall to make the bar
  \setlength{\barRuleHeight}{\barHeight+\barRuleWidth}% how tall to make vertical parts of frame
  \begin{picture}(\barWidthFactor,100)
    \put(0,0){\color{#3}{\rule{\barWidth}{\barHeight}}}  % colored interior
    \put(0,0){\rule[-\barRuleWidth/2]{\barWidth}{\barRuleWidth}} % bottom rule
    \put(0,0){\makebox[\barRuleWidth/2][r]{\rule[-\barRuleWidth/2]{\barRuleWidth}{\barRuleHeight}}} % left rule; shifted left to stick out by a 1/2 barRuleWidth and shifted down to cover area next to bottom rule
    \put(\barWidthFactor,0){\makebox[\barRuleWidth/2][r]{\rule[-\barRuleWidth/2]{\barRuleWidth}{\barRuleHeight}}} % right rule
    \put(0,#2){\rule[-\barRuleWidth/2]{\barWidth}{\barRuleWidth}} % top rule
  \ifx #1\relax %
  \relax %
  \else\put(0,0){\raisebox{-1.5ex}{\makebox[\barWidth]{\tiny\sc #1}}}\fi%
  \end{picture}}%

% Format the summary over all sections
\newcommand{\summary}[4]{%
\par\noindent\textit{All sections:}~mean=#1, std dev=#2 for~#3~analyzable responses in #4~sections.}

% \fullLine
%   Make a line of material
%   #1  optional length; put that much empty space at start
%   #2  material to put on line
\newcommand{\fullLine}[2][0pt]{\hbox to \linewidth{\hspace*{#1}#2}}
\newcommand{\fullLine@Start}{15pt}

% \chartLine
%  One line showing the table and the bar chart
%  #1 what to show on the left of that line
%  #2 what to show on the right
\newcommand{\chartLine}[2]{\nopagebreak\newline\nopagebreak\vspace{.8ex plus.3ex minus .2ex}\fullLine[\fullLine@Start]{#1\barChartLeaderFill{#2}}\pagebreak[2]}



% Comments that are added onto a question
\newenvironment{additionalcomments}{%
\setlength{\LTpre}{0ex} \setlength{\LTpost}{0ex}%
\pagebreak[3]\vspace{.85ex plus .15ex minus .2ex}%
\par\noindent\textit{Additional comments:}\newline\nopagebreak% \\*[.1ex plus.3ex minus.1ex]%
\rowcolors{1}{white}{lightgray}%
\begin{longtable}[l]{@{\hspace*{.1in}}p{6.4in}@{}}
\endfirsthead\endhead\multicolumn{1}{r}{\textit{(comments continue on the next page)}}\endfoot\endlastfoot%
}{%
\end{longtable}}
% No comments made after the question
\newcommand{\nocomments}{\par\noindent\hspace*{2em}\textit{--No comments--}\par}

% No response were made
\newcommand{\noresponse}{\nopagebreak\vspace{.85 ex plus .15ex minus .2ex}\par\hspace*{2em}\textit{--No responses--}\vspace{.85 ex plus .15ex minus .2ex}\par}


%----
% for displaying grades
\newcommand{\gradePostfix}[1]{$^#1$}
\newcommand{\plusGrade}{\gradePostfix{+}}
\newcommand{\minusGrade}{\gradePostfix{-}}

%................... Question types ....................................
% Format the Strongly Agree .. Strongly Disagree replies
\newcommand{\levelofagreement}[6]{%
\vspace{0ex plus .2ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\begin{tabular}[b]{cccccc}
  \tablelabelarray{Strongly}{Agree}
  &\tablelabelarray{}{Agree}
  &\tablelabelarray{}{Neutral}
  &\tablelabelarray{}{Disagree}
  &\tablelabelarray{Strongly}{Disagree}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3  &#4  &#5  &#6   
\end{tabular}}}

% \levelofagreementbarchart
%   Make a bar chart for a level of agreement question
% #1-#6  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\levelofagreementbarchart}[6]{%
  \hbox{\makeBar[SA]{#1}{colorfive}%
  \makeBar[A]{#2}{colorfour}%
  \makeBar[N]{#3}{colorthree}%
  \makeBar[D]{#4}{colortwo}%
  \makeBar[SD]{#5}{colorone}%
  \makeBar[NR]{#6}{colorzero}%
}}

\newcommand{\levelofagreementsummary}[3]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section the mean is~$#1$ and the standard deviation is $#2$ with $#3$~responses. }


% Format the Agree/Disagree replies
\newcommand{\agreedisagree}[3]{%
\vspace{1ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\begin{tabular}[b]{ccc}
  \tablelabelarray{}{Agree}
  &\tablelabelarray{}{Disagree}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3   
\end{tabular}}}

% \agreedisagreebarchart
%   Make a bar chart for agree-disagree question
% #1-#3  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\agreedisagreebarchart}[3]{%
  \hbox{\makeBar[A]{#1}{colorfive}\hspace{-\barRuleWidth}%
  \makeBar[D]{#2}{colorfour}\hspace{-\barRuleWidth}%
  \makeBar[NR]{#3}{colorzero}% Non-response
}}

\newcommand{\agreedisagreesummary}[2]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section the mean is ~$#2$ for $#1$ responses. }


% Just a comment
\newenvironment{comments}{%
\setlength{\LTpre}{0ex} \setlength{\LTpost}{0ex}%
\pagebreak[3]%
\par\noindent\textit{Responses:}\newline\nopagebreak% \\*[.1ex plus.3ex minus.1ex]%
\rowcolors{1}{white}{lightgray}%
\begin{longtable}[l]{@{\hspace*{.1in}}p{6.4in}@{}}
\endfirsthead\endhead\multicolumn{1}{r}{\textit{(comments continue on the next page)}}\endfoot\endlastfoot%
}{%
\end{longtable}}


% ------------ grade
% Format the grade replies
\newcommand{\grade}[9]{%
\def\grade@A{#1}%
\def\grade@AMinus{#2}%
\def\grade@BPlus{#3}%
\def\grade@B{#4}%
\def\grade@BMinus{#5}%
\def\grade@CPlus{#6}%
\def\grade@C{#7}%
\def\grade@CMinus{#8}%
\def\grade@DPlus{#9}%
\grade@OtherArguments} %
\newcommand{\grade@OtherArguments}[3]{%
\def\grade@D{#1}%
\def\grade@F{#2}%
\def\grade@NR{#3}%
\grade@table }

\newcommand{\grade@table}{%
%\vspace{0ex plus .2ex}\par\noindent
\begin{center}
\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\fullLine[\fullLine@Start]{\begin{tabular}[b]{cccccccccccc}
  \tablelabelarray{}{A}
  &\tablelabelarray{}{A\minusGrade}
  &\tablelabelarray{}{B\plusGrade}
  &\tablelabelarray{}{B}
  &\tablelabelarray{}{B\minusGrade}
  &\tablelabelarray{}{C\plusGrade}
  \\ \hline
  \grade@A &\grade@AMinus &\grade@BPlus &\grade@B &\grade@BMinus &\grade@CPlus
\end{tabular}}
\fullLine[\fullLine@Start]{\hspace*{.05\linewidth}\begin{tabular}[b]{cccccc}
  \tablelabelarray{}{C}
  &\tablelabelarray{}{C\minusGrade}
  &\tablelabelarray{}{D\plusGrade}
  &\tablelabelarray{}{D}
  &\tablelabelarray{}{F}
  &\tablelabelarray{No}{response}
  \\ \hline
  \grade@C &\grade@CMinus &\grade@DPlus &\grade@D &\grade@F &\grade@NR
\end{tabular}}
\end{center}}

% \gradebarchart
%   Make a bar chart for a heavy .. light question
% #1-#11  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\gradebarchart}[9]{%
\def\grade@A{#1}%
\def\grade@AMinus{#2}%
\def\grade@BPlus{#3}%
\def\grade@B{#4}%
\def\grade@BMinus{#5}%
\def\grade@CPlus{#6}%
\def\grade@C{#7}%
\def\grade@CMinus{#8}%
\def\grade@DPlus{#9}%
\gradebarchart@OtherArguments} %
\newcommand{\gradebarchart@OtherArguments}[4]{%
\def\grade@D{#1}%
\def\grade@F{#2}%
\def\grade@Other{#3}%
\def\grade@NR{#4}%
\gradebarchart@bars }

\newcommand{\gradebarchart@bars}{%
  \hbox{\makeBar[A]{\grade@A}{colorfive}%
  \makeBar[A-]{\grade@AMinus}{colorfive}%
  \makeBar[B+]{\grade@BPlus}{colorfour}%
  \makeBar[B]{\grade@B}{colorfour}%
  \makeBar[B-]{\grade@BMinus}{colorfour}%
  \makeBar[C+]{\grade@CPlus}{colorthree}%
  \makeBar[C]{\grade@C}{colorthree}%
  \makeBar[C-]{\grade@CMinus}{colorthree}%
  \makeBar[D+]{\grade@DPlus}{colortwo}%
  \makeBar[D]{\grade@D}{colortwo}%
  \makeBar[F]{\grade@F}{colorone}%
  \makeBar[--]{\grade@Other}{colorzero}%
  \makeBar[NR]{\grade@NR}{colorzero}%
}}

\newcommand{\gradesummary}[3]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section the mean is~$#1$ and the standard deviation is~$#2$ for $#3$~responses. }


% ------------ heavy_to_light
% Format the Heavy .. Light replies
\newcommand{\heavylight}[4]{%
\vspace{0ex plus .2ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\begin{tabular}[b]{cccc}
  \tablelabelarray{}{Heavy}
  &\tablelabelarray{}{Moderate}
  &\tablelabelarray{}{Light}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3  &#4   
\end{tabular}}}

% \heavylightbarchart
%   Make a bar chart for a heavy .. light question
% #1-#4  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\heavylightbarchart}[4]{%
  \hbox{\makeBar[H]{#1}{colorthree}%
  \makeBar[M]{#2}{colortwo}%
  \makeBar[L]{#3}{colorone}%
  \makeBar[NR]{#4}{colorzero}%
}}

\newcommand{\heavylightsummary}[1]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section there were $#1$ responses. }


% ------------ hours_choice
% Format the 12 or more hours .. no hours replies
\newcommand{\hourschoice}[7]{%
\vspace{0ex plus .2ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\begin{tabular}[b]{ccccccc}
  \tablelabelarray{12 or more}{hours}
  &\tablelabelarray{8 to 11}{hours}
  &\tablelabelarray{4 to 9}{hours}
  &\tablelabelarray{2 to 3}{hours}
  &\tablelabelarray{}{1 hour}
  &\tablelabelarray{}{0 hours}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3  &#4  &#5  &#6  &#7   
\end{tabular}}}

% \hourschoicebarchart
%   Make a bar chart for hours choice question
% #1-#7  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\hourschoicebarchart}[7]{%
  \hbox{\makeBar[12+]{#1}{colorfive}%
  \makeBar[8]{#2}{colorfive}%
  \makeBar[4]{#3}{colorfour}%
  \makeBar[2]{#4}{colorthree}%
  \makeBar[1]{#5}{colortwo}%
  \makeBar[0]{#6}{colorone}%
  \makeBar[NR]{#7}{colorzero}%
}}

\newcommand{\hourschoicesummary}[3]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section the mean is~$#1$ and the standard deviation is~$#2$ with $#3$~responses.}


% ------------ times_choice
% Format the 10 or more time .. never replies
\newcommand{\timeschoice}[6]{%
\vspace{0ex plus .2ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\begin{tabular}[b]{cccccc}
  \tablelabelarray{10 or more}{times}
  &\tablelabelarray{5 to 9}{times}
  &\tablelabelarray{2 to 4}{times}
  &\tablelabelarray{}{once}
  &\tablelabelarray{}{never}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3  &#4  &#5  &#6   
\end{tabular}}}

% \timeschoicebarchart
%   Make a bar chart for hours choice question
% #1-#6  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\timeschoicebarchart}[6]{%
  \hbox{\makeBar[10+]{#1}{colorfive}%
  \makeBar[5-9]{#2}{colorfour}%
  \makeBar[2-4]{#3}{colorthree}%
  \makeBar[1]{#4}{colortwo}%
  \makeBar[0]{#5}{colorone}%
  \makeBar[NR]{#6}{colorzero}%
}}

\newcommand{\timeschoicesummary}[3]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section the mean is~$#1$ and the standard deviation is $#2$ with $#3$~responses. }



% ------------ student_year
% Format the first year .. graduate replies
\newcommand{\studentyear}[6]{%
\vspace{0ex plus .2ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\begin{tabular}[b]{cccccc}
  \tablelabelarray{}{First year}
  &\tablelabelarray{}{Sophmore}
  &\tablelabelarray{}{Junior}
  &\tablelabelarray{}{Senior}
  &\tablelabelarray{}{Graduate}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3  &#4  &#5  &#6   
\end{tabular}}}

% \studentyearbarchart
%   Make a bar chart for student year question
% #1-#6  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\studentyearbarchart}[6]{%
  \hbox{\makeBar[FY]{#1}{colorfive}%
  \makeBar[So]{#2}{colorfour}%
  \makeBar[J]{#3}{colorthree}%
  \makeBar[Se]{#4}{colortwo}%
  \makeBar[G]{#5}{colorone}%
  \makeBar[NR]{#6}{colorzero}%
}}

\newcommand{\studentyearsummary}[3]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section there were $#1$~responses. }


% ------------ gender
% Format the female .. male replies
\newcommand{\gender}[3]{%
\vspace{0ex plus .2ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\begin{tabular}[b]{ccc}
  \tablelabelarray{}{Female}
  &\tablelabelarray{}{Male}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3
\end{tabular}}}

% \genderbarchart
%   Make a bar chart for gender question
% #1-#3  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\genderbarchart}[3]{%
  \hbox{\makeBar[F]{#1}{colorfive}%
  \makeBar[M]{#2}{colorthree}%
  \makeBar[NR]{#3}{colorzero}%
}}

\newcommand{\gendersummary}[1]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section there were $#1$~responses. }



% ------------ factors_influence
% Format the LSR .. Other replies
\newcommand{\factorsinfluencechoice}[7]{%
\vspace{0ex plus .2ex}\par\noindent
{\setlength{\tabcolsep}{2pt}
\renewcommand{\arraystretch}{.95}
\begin{tabular}[b]{ccccccc}
  \tablelabelarray{Liberal Studies}{Requirement}
  &\tablelabelarray{Major}{Requirement}
  &\tablelabelarray{Minor}{Requirement}
  &\tablelabelarray{Interest in}{Subject Matter}
  &\tablelabelarray{Reputation of}{Instructor}
  &\tablelabelarray{}{Other}
  &\tablelabelarray{No}{response}
  \\ \hline
  #1  &#2  &#3  &#4  &#5  &#6  &#7   
\end{tabular}}}

% \factorsinfluencebarchart
%   Make a bar chart for factors_influence question
% #1-#7  numbers; percentages 0-100 to adjust the height of the bar
\newcommand{\factorsinfluencebarchart}[7]{%
  \hbox{\makeBar[LSR]{#1}{colorfive}%
  \makeBar[Ma]{#2}{colorfive}%
  \makeBar[Mi]{#3}{colorfour}%
  \makeBar[S]{#4}{colorthree}%
  \makeBar[I]{#5}{colortwo}%
  \makeBar[O]{#6}{colorone}%
  \makeBar[NR]{#7}{colorzero}%
}}

\newcommand{\factorsinfluencesummary}[1]{%
\vspace{.8ex plus.4ex minus .3ex}\par\noindent
In this section there were $#1$~responses. }



%==========================================================
% Sectioning commands

\usepackage[margin=1in]{geometry}

% Make the sectioning commands
\setcounter{secnumdepth}{-1}  % do not number subsections
\setcounter{tocdepth}{0}  % do not show subsection number in table of contents

%\renewcommand{\thesection}{Responses for:}
\renewcommand\section{\clearpage\@startsection
{section}{1}{0em}%  name, level, indent
{12pt}%  beforeskip
{15pt}%  afterskip
{\normalfont\Large\bfseries\noindent Responses for }}

% change the desciption environment for the listings of the questions
\newcommand{\questionslabel}[1]{\textbf{\textit{#1}} }

\newenvironment{questions}{%
\begin{list}{}{\setlength{\labelwidth}{0pt}%
               \setlength{\labelsep}{0pt}
               \setlength{\leftmargin}{.1in}%
               \setlength{\itemindent}{-\leftmargin}%
               \setlength{\itemsep}{4ex}%
               \setlength{\parsep}{0ex}%
               \setlength{\listparindent}{0em}%
               \let\makelabel\questionslabel}
}{%
\end{list}}

% table of contents
\renewcommand{\@dotsep}{1}
\renewcommand{\l@chapter}{\@dottedtocline{0}{0pt}{3em}}

%----- Headers and footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}  % clear fields
\fancyhead[R]{\textit{page \thepage}}
\fancyhead[L]{\textit{\rightmark, \semester}}
\fancyfoot{}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headheight}{15pt}

%------ Title page
\renewcommand\maketitle{\begin{titlepage}%
\let\footnotesize\small
\let\footnoterule\relax
\let \footnote \thanks
\null\vfil
%\vskip 10\p@
\begin{center}\includegraphics{sphyg_masthead.png}\end{center}%
\vskip 50\p@
\begin{center}%
  {\LARGE \@title \par}%
  \vskip 3em%
  {\large
   \lineskip .75em%
    \begin{tabular}[t]{c}%
      \@author
    \end{tabular}\par}%
    \vskip 1.5em%
  {\large \@date \par}%       % Set date in \large size.
\end{center}\par
\@thanks 
\vfil\null
\end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
