\documentclass[10pt,twoside]{report}
\usepackage{etex}
\reserveinserts{28}
\usepackage[left=6cm,right=1cm,showframe=false, % page settings (showframe is useful!)
textheight=27cm,
top=1.5cm,bottom=1.5cm,asymmetric=true,bindingoffset=1cm]{geometry}
\usepackage{amsmath} % mathematical content
\usepackage{amssymb} % mathematical content
\usepackage[amsmath,standard,framed,thmmarks]{ntheorem} % custom enumerations *Needs to stay here, otherwise cross references can go wrong*
\usepackage{ifthen} % conditionals
\usepackage{xcolor} % colour
\usepackage{answers} % solutions to problems done *beautifully*
%\usepackage[nosolutionfiles]{answers}
\usepackage{framed} % needed for putting boxes round theorems, examples
\usepackage[explicit]{titlesec}
\usepackage{multicol} % multicols
\usepackage{changepage} % needed for hanging paragraphs
\usepackage{calc} % calculations (such as \textwidth/2)
\usepackage{fancyhdr} % headers & footers
\usepackage[small,bf]{caption} % figures/tables in margins, and not floating
\usepackage{subcaption} % subfigures, subtables (replaces subfig)
\usepackage{xstring} % needed to determine if problems are odd or even
\usepackage{enumitem} % enumerate & itemize
\usepackage{placeins} % FloatBarrier
\usepackage{minitoc} % mini-table of contents
\usepackage{marginfix} % fixes margin notes (otherwise they can cut through pages)
\usepackage{needspace} % needed to keep problems looking good (stops ugly pagebreaks)
\usepackage{xargs} % helps with optional arguments for environments
\usepackage{booktabs} % used with tables (allows \toprulewidth etc)
\usepackage{flafter} % ensures that floats don't appear until after their placement in the text
% pstricks
\usepackage[pdf]{pstricks}
\usepackage{pstricks-add}
% load the hyperref last
\usepackage{hyperref} % to allow hyper refs in the final pdf document
% hyperref NEEDS TO STAY AT THE END!
\usepackage[all]{hypcap} % needed to help hyperlinks direct correctly;
% note that this needs to be loaded AFTER
% the hyperref package; the option [all]
% makes hyperlinks to figures & tables go
% to the top
\usepackage{cleveref} % needs to be loaded after hyperref
% hyperref settings- it seemed to work better here rather than
% as options to the \usepackage call above
\hypersetup{colorlinks=true,
linkcolor=blue%,breaklinks=true
}
\psset{algebraic=true} % set up options for PS figures
% custom ps options
\newpsobject{pccpsplot}{psplot}{linecolor=blue,plotstyle=curve,%
linewidth=1pt,arrows=<->}
\newpsobject{pccgridline}{psline}{linecolor=black!20,linestyle=dashed}
\newpsobject{pccpsframe}{psframe}{linecolor=gray,linewidth=0pt}
\newpsobject{pccpsSolDot}{psdots}{linecolor=blue,dotsize=0.25}
\newpsobject{pccpsHolDot}{psdots}{linecolor=blue,dotsize=0.25,dotstyle=o}
\newpsobject{pccasymptote}{psline}{linestyle=dotted,linecolor=red}
% grid stuff
\newcommand{\drawXgrid}[3]{%
\multido{\nx=#1+#2}{#3}%
{%
\pccgridline(\nx,\ymin)(\nx,\ymax)
}%
}
\newcommand{\drawYgrid}[3]{%
\multido{\ny=#1+#2}{#3}%
{%
\pccgridline(\xmin,\ny)(\xmax,\ny)
}%
}
% set figure width
\newlength{\figurewidth}
% setwindow command: takes 6 arguments (1st is optional)
% [1]. aspect ratio (height = aspect ratio * width) default=1
% 2. xmin (number)
% 3. ymin (number)
% 4. xmax (number)
% 5. ymax (number)
% 6. figurewidth (length)
\makeatletter
\newcommand{\setwindow}[6][1]{\def\xmin{#2}%
\def\ymin{#3}%
\def\xmax{#4}%
\def\ymax{#5}%
% set up xunit
\pstFPsub\viewingwidth{#4}{#2}%
\pstFPdiv\result{\strip@pt#6}{\viewingwidth}%
\psset{xunit=\result pt}
% set up yunit
\pstFPsub\viewingheight{#5}{#3}%
\pstFPdiv\result{\strip@pt#6}{\viewingheight}%
% set up aspect ratio
\pstFPmul\result{\result}{#1}%
\psset{yunit=\result pt}%
}
\makeatother
% caption settings
\captionsetup[table]{skip=0pt}
\captionsetup[subfigure]{labelformat=parens,labelsep=colon,labelfont=normal}
\captionsetup[subtable]{labelformat=parens,labelsep=colon,labelfont=normal}
% enumerate settings
\setlist{itemsep=0.05em,topsep=0.01em}
% paragraph settings
\setlength{\parskip}{3.0mm}
\setlength{\parindent}{0.0mm}
% use left margin
\reversemarginpar
\setlength{\marginparwidth}{5cm}
% Define fix command
% - it puts a comment in the margin
% - it writes to a file with a list of things that need fixing
\newcommand{\fixthis}[1]%
{%
\marginpar{\huge \color{red} \framebox{FIX}}%
\typeout{FIXTHIS: p\thepage : #1^^J}%
}
% BEGIN CLEVEREF
% standard environments
\crefname{table}{Table}{Tables}
\Crefname{table}{Table}{Tables}
\crefname{figure}{Figure}{Figures}
\Crefname{figure}{Figure}{Figures}
\crefname{section}{Section}{Sections}
\Crefname{section}{Section}{Sections}
\crefname{equation}{Equation}{Equations}
\Crefname{equation}{Equation}{Equations}
% custom environments
\crefname{problem}{Problem}{Problems}
\Crefname{problem}{Problem}{Problems}
\crefname{pccdefinition}{Definition}{Definitions}
\Crefname{pccdefinition}{Definition}{Definitions}
\crefname{pccexample}{Example}{Examples}
\Crefname{pccexample}{Example}{Examples}
\crefname{enumi}{Problem}{Problems}
\Crefname{enumi}{Problem}{Problems}
% conjunction between range; e.g Figures 1.2-1.3
\newcommand{\crefrangeconjunction}{|}
% BEGIN MARGIN ENVIRONMENTS (shamelessly copied from tufte documentclass)
\makeatletter
% Margin float environment
\newsavebox{\@tufte@margin@floatbox}
\newenvironment{@tufte@margin@float}[2][-1.2ex]%
{\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
\begin{lrbox}{\@tufte@margin@floatbox}%
\begin{minipage}{\marginparwidth}%
\def\@captype{#2}%
\hbox{}\vspace*{#1}%
\noindent%
}
{\end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@tufte@margin@floatbox}}%
}
% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{figure}%
\capstart\endgraf}% <-- Hyperlink jumps to start of 'marginfigure'
{\end{@tufte@margin@float}}
% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{table}%
\capstart\endgraf}% <-- Hyperlink jumps to start of 'margintable'
{\end{@tufte@margin@float}}
\makeatother
% END MARGIN ENVIRONMENTS
% BEGIN SOLUTIONS TO PROBLEMS
% open the answer files (short, long, and hints)
\Opensolutionfile{shortsolutions}
\Newassociation{shortsolution}{shortSoln}{shortsolutions}
% put titles in the solution files
\begin{Filesave}{shortsolutions}
% SHORT SOLUTIONS FILE
% Begin by (re-)setting the chapter counter to 0
% which is used for hyperlinks from solutions to questions
%
% This allows us to put Problem 1, 2, 3, etc in every chapter
% as the hyperlinks have the form \hypertarget{soln:#1\thechapter}{}
\section*{Answers}
\setcounter{chapter}{0}
\end{Filesave}
% END SOLUTIONS TO PROBLEMS
% BEGIN CUSTOM THEOREMS (for problems, subproblems)
% set up showoddsolns and showEVEN
\newboolean{showoddsolns}
\setboolean{showoddsolns}{true}
\newboolean{showevensolns}
\setboolean{showevensolns}{true}
% this boolean is used in the problem and subproblem definition
\newboolean{showSolution}
\setboolean{showSolution}{true}
% PROBLEM environment
% \begin{problem}[1][2]
% ...
% \end{problem}
%
% [1]: description of the problem
% [2]: special
%
% Both arguments are optional; the second argument
% can be left off, empty, or special. If it is non-empty
% and anything other than special (case-sensitive), it
% will be ignored.
\newcounter{problem}
\newcommand{\specialsymbol}{$\bigstar$ }
\newlength{\specialsymbollength}
\settowidth{\specialsymbollength}{\specialsymbol}
\newenvironmentx{problem}[2][1={},2={},usedefault]{%
\refstepcounter{problem}%
\Writetofile{shortsolutions}{\protect\hypertarget{soln:\theproblem:\thechapter}{}}%
\needspace{\baselineskip}%
\ifthenelse{\isodd{\theproblem}}%
{%
\ifthenelse{\boolean{showoddsolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
{%
\ifthenelse{\boolean{showevensolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
\ifthenelse{\equal{#2}{}}%
{% NOT special problem
% if no second argument (special or not)
\ifthenelse{\equal{#1}{}}%
{% Problem withOUT description
\ifthenelse{\boolean{showSolution}}%
{%
{\hypertarget{prob:\theproblem:\thechapter}{}%
{{\bfseries Problem \hypersetup{linkcolor=black}\hyperlink{soln:\theproblem:\thechapter}{\theproblem}}}\newline}%
}%
{%
{\bfseries Problem \theproblem}\newline%
}%
}%
{% Problem with description
\ifthenelse{\boolean{showSolution}}%
{%
{\hypertarget{prob:\theproblem:\thechapter}{}%
{{\bfseries Problem \hypersetup{linkcolor=black}\hyperlink{soln:\theproblem:\thechapter}{\theproblem} \,(#1)}}\newline}%
}%
{%
{\bfseries Problem \theproblem\, (#1) }\newline%
}%
}%
}%
{% special problem
\ifthenelse{\equal{#2}{special}}%
{%
% write problem number to specialfile
\addcontentsline{prb}{}{\theproblem}%
\ifthenelse{\equal{#1}{}}%
{% special problem with no description
\ifthenelse{\boolean{showSolution}}%
{%
{\hypertarget{prob:\theproblem:\thechapter}{}%
{\hspace{-\specialsymbollength}\specialsymbol{\bfseries Problem \hypersetup{linkcolor=black}\hyperlink{soln:\theproblem:\thechapter}{\theproblem}}}\newline}%
}%
{%
\hspace{-\specialsymbollength}\specialsymbol{\bfseries Problem \theproblem}\newline%
}%
}%
{% special problem with description
\ifthenelse{\boolean{showSolution}}%
{% with links
{\hypertarget{prob:\theproblem:\thechapter}{}%
{\hspace{-\specialsymbollength}\specialsymbol{\bfseries Problem \hypersetup{linkcolor=black}\hyperlink{soln:\theproblem:\thechapter}{\theproblem} \,(#1)}}\newline}%
}%
{% no links
\hspace{-\specialsymbollength}\specialsymbol{\bfseries Problem \theproblem\, (#1) }\newline%
}%
}%
}{ \textbf{Problem} \theproblem \, (#1) {\bf\huge\color{red}special?}\par}%
}%
}%
{%
}%
% subproblem environment
\newcounter{subproblem}[problem]
\newboolean{specialproblemYesNo}
\setboolean{specialproblemYesNo}{false}
\newenvironment{subproblem}[1][]{%
\refstepcounter{subproblem}%
\ifthenelse{\isodd{\theproblem}}%
{%
\ifthenelse{\boolean{showoddsolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
{%
\ifthenelse{\boolean{showevensolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
\ifthenelse{\equal{#1}{special}}%
{%
\setboolean{specialproblemYesNo}{true}%
}%
{%
\setboolean{specialproblemYesNo}{false}%
}%
\ifthenelse{\boolean{specialproblemYesNo}}%
{% special problem
\addcontentsline{prb}{}{\theproblem.\thesubproblem}%
\ifthenelse{\boolean{showSolution}}%
{% hyperlink to solution
\hypertarget{prob:{\theproblem.\thesubproblem}:\thechapter}{}%
\hypersetup{linkcolor=black}%
\begin{enumerate}[label=\llap{$\bigstar$ }\bfseries\protect\hyperlink{soln:{\theproblem.\thesubproblem}:\thechapter}{\theproblem.\thesubproblem},ref=\theproblem.\thesubproblem,leftmargin=*]
\item%
}%
{% no hyperlink
\begin{enumerate}[label=\llap{$\bigstar$ }\bfseries\theproblem.\thesubproblem,ref=\theproblem.\thesubproblem,leftmargin=*]
\item%
}%
}%
{% NOT special problem
\ifthenelse{\boolean{showSolution}}%
{% hyperlink to solution
\hypertarget{prob:{\theproblem.\thesubproblem}:\thechapter}{}%
\hypersetup{linkcolor=black}%
\begin{enumerate}[label=\bfseries\protect\hyperlink{soln:{\theproblem.\thesubproblem}:\thechapter}{\theproblem.\thesubproblem},ref=\theproblem.\thesubproblem,leftmargin=*]
\item%
}%
{% no hyperlink
\begin{enumerate}[label=\bfseries\theproblem.\thesubproblem,ref=\theproblem.\thesubproblem,leftmargin=*]
\item%
}%
}%
}{\end{enumerate}}
% definition
\theoremstyle{break}
\theoremsymbol{}
\theoremseparator{}
\theoremprework{\FloatBarrier}
\def\theoremframecommand{%
\psshadowbox[fillstyle=solid,fillcolor=yellow,linecolor=black]}
\newshadedtheorem{pccdefinition}{Definition}%[chapter]
% END CUSTOM THEOREMS (for examples, problems)
% BEGIN special PROBLEMS
\newcounter{probSectCounter}
\setcounter{probSectCounter}{-1}
\newcounter{probCounter}
\setcounter{probCounter}{0}%
\newcounter{echo}
\newread\File
% redefine the \section command to increment probSectCounter
% note that this could also be done for \subsection if desired
\let\oldsection\section
\renewcommand\section{%
\stepcounter{probSectCounter}%
%\addcontentsline{prb}{heading\theprobSectCounter}%
\addcontentsline{prb}{}{heading\theprobSectCounter}%
\oldsection}
\makeatletter
% need a command to bring the \contentsline
% into the problemlist environment
\let\pcc@contentslist\contentsline%
\newenvironment{problemlist}%
{%
% renew the \contentsline command so that it just gives
% the problem number as a hyperlink (and no page number)
%
% if we renewed the command outside of the environment, it would
% affect \tableofcontents, \minitoc, and perhaps more- bad!
\let\contentsline\pcc@contentslist%
\let\Contentsline\contentsline%
\renewcommand\contentsline[4]{%
\StrCount{##2}{heading}[\heading]%
\ifthenelse{\heading>0}%
{%
\StrCount{##2}{heading\theprobSectCounter}[\heading]%
\ifthenelse{\heading>0}%
{%
\setcounter{echo}{1}%
\setcounter{probCounter}{0}%
}%
{%
\setcounter{echo}{0}%
}%
}%
{%
\ifthenelse{\equal{\theecho}{1}}%
{%
\stepcounter{probCounter}%
\ifthenelse{\equal{\theprobCounter}{1}}%
{%
% if we're at the beginning, no comma
Special problems in this section (\specialsymbol\unskip): \Contentsline{##1}{##2}{}{##4}%
}%
{%
% otherwise put a comma and a space
\unskip, \Contentsline{##1}{##2}{}{##4}%
}%
}%
{}%
}%
}%
}%
{}
\def\listspecialproblems{%
% open the appropriate file do everything in a
% new environment so that we can renew the
% \contentsline command locally
\begin{problemlist}
\par%
\openin\File=\jobname.prb%
\loop\unless\ifeof\File%
\read\File to\fileline%
\fileline%
\repeat%
\closein\File%
\end{problemlist}
}%
% enable the \jobname.prb file
% (hacked from the ntheorem package)
\def\prb@enablelistofproblems{%
\begingroup%
\makeatletter%
\if@filesw%
\expandafter\newwrite\csname tf@prb\endcsname%
\immediate\openout \csname tf@prb\endcsname \jobname.prb\relax%
\fi%
\@nobreakfalse%
\endgroup}%
% enable the \jobname.prb<counter> files at the end
% of the document
\AtEndDocument{\prb@enablelistofproblems}
\makeatother
% END special PROBLEMS
% BEGIN TABLE STYLES
\renewcommand{\heavyrulewidth}{0.2em}
\renewcommand{\lightrulewidth}{0.1em}
\renewcommand{\cmidrulewidth}{0.1em}
% horizontal lines
\renewcommand{\aboverulesep}{0cm}
\renewcommand{\belowrulesep}{0cm}
\newcommand*\heading[1]{\hfill{#1}\hfill}
\newcommand*\beforeheading{\toprule}
\newcommand*\afterheading{\midrule}
%\newcommand*\normalline{\hline}
\newcommand*\normalline{}
\newcommand*\lastline{\bottomrule}
% END TABLE STYLES
% BEGIN CUSTOMIZE SECTIONS
% custom chapter
\titleformat{\chapter}[display]
{\normalfont\Large\filcenter\bf}
{\titlerule[1pt]%
\vspace{1pt}%
\titlerule
\LARGE\MakeUppercase{#1} \psshadowbox{\Huge\thechapter}}
{1pc}
{\titlerule
\Huge}
% write to the solutions files to step the chapter counter
\let\oldchapter\chapter
\renewcommand{\chapter}{\Writetofile{shortsolutions}{\protect\stepcounter{chapter}}%
\oldchapter}
% From the titlesec package
% \titlespacing{command}{left spacing}{before spacing}{after spacing}[right]
% spacing: how to read {12pt plus 4pt minus 2pt}
% 12pt is what we would like the spacing to be
% plus 4pt means that TeX can stretch it by at most 4pt
% minus 2pt means that TeX can shrink it by at most 2pt
% This is one example of the concept of, 'glue', in TeX
\titlespacing{\chapter}{0pt}{*4}{-0.1cm}
\titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{-5pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{-6pt plus 2pt minus 2pt}
\titlespacing\subsubsection{0pt}{12pt plus 4pt minus 2pt}{-6pt plus 2pt minus 2pt}
% END CUSTOMIZE SECTIONS
%====================================
% BEGIN DOCUMENT
%====================================
\begin{document}
\renewcommand{\labelenumi}{(\alph{enumi})}
% needed for the mini-tableofcontents
\dominitoc
\faketableofcontents
\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO,RE]{\tiny\leftmark}
\pagestyle{fancy}
\include{polynomialfunctions}
%=======================
% BEGIN SOLUTIONS
%=======================
% change to one-sided mode
% change the pagestyle to plain
% change the page geometry using \newgeometry
\setboolean{@twoside}{false}
\pagestyle{plain}
\newgeometry{left=1cm,right=1cm,showframe=true,
textheight=27cm,
top=1.5cm,bottom=1.5cm,bindingoffset=1cm}
% close the solutions files
\Closesolutionfile{shortsolutions}
% SHORT solution to problem (show only odd, even, all)
% Note: this renewenvironment needs to go here
% so that the answers package can still
% display correctly to the page if needed
\newboolean{oddproblemnumber}
\renewenvironment{shortSoln}[1]{%
\exploregroups % needed to ignore {}
% before the environment starts - this is a stretchable space
\vskip 0.1cm plus 2cm minus 0.1cm%
\fullexpandarg % need this line so that '.' are counted
%
% either problems, or subproblems, e.g: 3.1 or 3.1.4 respectively
% determine which one by counting the '.'
\StrCount{#1}{.}[\numberofdecimals]
%
% find the problem number by splitting the string
\ifthenelse{\numberofdecimals=0}%
{%
% problems, such as 4, 5, 6, ...
\def\problemnumber{#1}%
}%
{}%
\ifthenelse{\numberofdecimals=1}%
{%
% problems, such as 4.3, 1.2, 10.5
\StrBefore{#1}{.}[\problemnumber]%
}%
{}%
\ifthenelse{\numberofdecimals=2}%
{%
% subproblems such as 1.3.1, 1.2.4, 7.5.6
\StrBehind{#1}{.}[\newbit]%
\StrBefore{\newbit}{.}[\problemnumber]%
}%
{}%
%
% determine if the problem number is odd or even
% and depending on our choices above, display or not
\ifthenelse{\isodd{\problemnumber}}%
{%
% set a boolean that says the problem number is odd (used later)
\setboolean{oddproblemnumber}{true}%
% display or not
\ifthenelse{\boolean{showoddsolns}}%
{%
% if we want to show the odd problems
{\bfseries \hypertarget{soln:#1:\thechapter}{}\hyperlink{prob:#1:\thechapter}{#1}.}%
}%
{%
% otherwise don't show them!
\expandafter\comment%
}%
}%
{%
% even numbered problem, set the boolean (used later)
\setboolean{oddproblemnumber}{false}%
\ifthenelse{\boolean{showevensolns}}%
{%
% if we want to show the even problems
{\itshape \hypertarget{soln:#1:\thechapter}{}\hyperlink{prob:#1:\thechapter}{#1}.}%
}%
{%
% otherwise don't show them!
\expandafter\comment%
}%
}%
}%
{%
% after the environment finishes
\ifthenelse{\boolean{oddproblemnumber}}%
{%
% odd numbered problems
\ifthenelse{\boolean{showoddsolns}}%
{%
% if we want to show the odd problems
% then the environment is finished
}%
{%
% otherwise we need to finish the comment
\expandafter\endcomment%
}%
}%
{%
% even numbered problems
\ifthenelse{\boolean{showevensolns}}%
{%
% if we want to show the even problems
% then the environment is finished
}%
{%
% otherwise we need to finish the comment
\expandafter\endcomment%
}%
}%
}
\clearpage
% set solution figure width
\newlength{\solutionfigurewidth}
\setlength{\solutionfigurewidth}{3cm}
% input the SHORT solutions file
\IfFileExists{shortsolutions.tex}{\input{shortsolutions.tex}}{}
%=======================
% END SOLUTIONS
%=======================
\end{document}