\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{webwork2}[2024/08/28 version 3]

% packages that are used by webwork2 itself, probably by Hardcopy.pm
\usepackage{path}
\discretionaries |~!@$%^&*()_+`-=#{"}[]:;'<>,.?\/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789|
\usepackage{listings}
\lstset{basicstyle=\ttfamily,breaklines=true,aboveskip=0pt,belowskip=0pt}
\usepackage{pg}

% support for languages and fonts when XeLaTeX in use
% note pg.sty loads iftex package
\ifXeTeX
  \usepackage{fontspec}
  \usepackage{xunicode}
  \usepackage{polyglossia}
  \setdefaultlanguage{english}
\fi

% used in convenience macros below
\usepackage{hyperref}
\usepackage{ifthen}

% These macros may be overridden with WeBWorK environment variables
\def\webworkCourseName{}
\def\webworkCourseTitle{}
\def\webworkCourseURL{}
\def\webworkUserId{}
\def\webworkStudentId{}
\def\webworkFirstName{}
\def\webworkLastName{}
\def\webworkEmailAddress{}
\def\webworkSection{}
\def\webworkRecitation{}
\def\webworkSetId{}
\def\webworkDescription{}
\def\webworkOpenDate{}
\def\webworkReducedScoringDate{}
\def\webworkDueDate{}
\def\webworkAnswerDate{}
\def\webworkPrettySetId{}
\def\webworkProblemId{}
\def\webworkProblemNumber{}
\def\webworkProblemWeight{}

% These words/phrases may be overridden for localization
\def\webworkLocalizeAssignment{Assignment}
\def\webworkLocalizeSet{Set}
\def\webworkLocalizeProblem{Problem}
\def\webworkLocalizeUsername{Username}
\def\webworkLocalizeFullCreditBy{full credit by}
\def\webworkLocalizeCloses{closes}
\def\webworkLocalizeSection{Section}
\def\webworkLocalizeRecitation{Recitation}
\def\webworkLocalizePage{Page}
\def\webworkLocalizePoint{point}

% These can be used in a header or footer and their content can be overrided.
\newcommand{\webworkLeftHeader}
{%
\ifthenelse{\thepage=1}{%
\ifx\webworkSetId\empty\else{%
{\large\bfseries \href{\webworkCourseURL/\webworkSetId}{\webworkPrettySetId}\\}%
\small\ifx\webworkReducedScoringDate\empty\else{\webworkLocalizeFullCreditBy~\webworkReducedScoringDate, }\fi\webworkLocalizeCloses~\webworkDueDate}\fi%
}{}%
}

\newcommand{\webworkCenterHeader}{}

\newcommand{\webworkRightHeader}
{%
\ifthenelse{\thepage=1}{%
\sffamily\ifx\webworkUserId\empty\else{%
\webworkFirstName{} \webworkLastName{} (\webworkUserId)\\}\fi%
\small\ifx\webworkSection\empty\else{\webworkLocalizeSection:~\webworkSection}\fi%
\ifx\webworkRecitation\empty\else{\ifx\webworkSection\empty\else{, }\fi\webworkLocalizeRecitation:~\webworkRecitation}\fi%
}{}%
}

\newcommand{\webworkLeftFooter}{\ifx\webworkCourseTitle\empty\else{\href{\webworkCourseURL}{\scshape\webworkCourseTitle}}\fi}

\newcommand{\webworkCenterFooter}{}

\newcommand{\webworkRightFooter}{\webworkLocalizePage~\thepage}


% These macros declare copyright in the footer of the last page.

% Define the footer components

\newcommand{\webworkSetCopyrightFooterLeft}{%
\raisebox{-0.325cm}{\includegraphics[width=3cm]{webwork_logo.png}}%
}
\newcommand{\webworkSetCopyrightFooterCenter}{%
\small\sffamily Generated by WeBWorK, \copyright~The~WeBWorK~Project.%
}
\newcommand{\webworkSetCopyrightFooterRight}{%
\url{openwebwork.org}%
}

% Define the macro that declares the copyright
% A format if fancyhdr is available
% A format if exam class is available
% Empty otherwise

\AtBeginDocument{%
\newcommand{\webworkSetCopyrightFooter}{\relax}
\makeatletter%

\@ifpackageloaded{fancyhdr}{%
\@ifpackageloaded{tcolorbox}{%
\renewcommand{\webworkSetCopyrightFooter}{%
\fancyfoot[L]{\webworkSetCopyrightFooterLeft}%
\fancyfoot[C]{\webworkSetCopyrightFooterCenter}%
\fancyfoot[R]{\webworkSetCopyrightFooterRight}%
\pagestyle{fancy}%
}%
}%
{%
\renewcommand{\webworkSetCopyrightFooter}{%
\fancyfoot[L]{\webworkSetCopyrightFooterLeft}%
\fancyfoot[C]{\webworkSetCopyrightFooterCenter}%
\fancyfoot[R]{\webworkSetCopyrightFooterRight}%
\pagestyle{fancy}%
\clearpage%
}%
}%
{}%
}%

\@ifclassloaded{exam}%
{%
\renewcommand{\webworkSetCopyrightFooter}{%
\footer%
{\webworkSetCopyrightFooterLeft}%
{\webworkSetCopyrightFooterCenter}%
{\webworkSetCopyrightFooterRight}%
\clearpage
}%
}%
{}%
\makeatother%
}
