summaryrefslogtreecommitdiff
path: root/montgomery.cls
blob: a5f1fd4f1d3a11da060273efd852d5086b81e185 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
% montgomery.cls
%   https://git.benjidial.net/latex-classes
% Written by Benji Dial, 2024
% Released under CC0 1.0
%   https://creativecommons.org/publicdomain/zero/1.0/

\ProvidesClass{montgomery}
\LoadClass{book}

\usepackage{amssymb}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage{amsthm}
\usepackage[svgnames]{xcolor}
\usepackage{thmtools}
\usepackage{unicode-math}
\usepackage{pdftexcmds}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{hyperref}
\usepackage[capitalize]{cleveref}
\usepackage{rotating}
\usepackage{environ}

\setmainfont{CMU Sans Serif}
\setmathfont{Concrete Math}

\makeatletter

\newcommand{\barcolor}[1]{%
  \ifnum\pdf@strcmp{#1}{definition}=0
    DarkBlue%
  \else\ifnum\pdf@strcmp{#1}{example}=0
    DarkGreen%
  \else\ifnum\pdf@strcmp{#1}{exercise}=0
    OrangeRed%
  \else\ifnum\pdf@strcmp{#1}{theorem}=0
    Maroon%
  \else\ifnum\pdf@strcmp{#1}{suggestion}=0
    MediumVioletRed%
  \fi\fi\fi\fi\fi
}

\newcommand{\myenvir}{\@currenvir}

\renewenvironment{proof}[1][\proofname]{
  \par\pushQED{\qed}\normalfont
  \relax{\itshape \bfseries #1\@addpunct{.}}\hspace\labelsep\ignorespaces
}{\popQED\par}

\newcounter{solution}

\newcommand{\solutions}{\setcounter{solution}{0}}

\newcommand{\addsolution}[1]{
  \g@addto@macro\solutions{
    \stepcounter{solution}
    \begin{proof}[\cref{solution-\thesolution-exercise}]
      \par
      \label{solution-\thesolution}
      #1
    \end{proof}
  }
}

\newenvironment{solution}{%
  \unskip%
  \stepcounter{solution}%
  \label{solution-\thesolution-exercise}%
  \textit{Solution: Page \pageref{solution-\thesolution}.}
  \Collect@Body\addsolution
}{}

\makeatother

\declaretheoremstyle[
  spaceabove=0pt,
  spacebelow=0pt,
  headfont=\bfseries,
  notefont=\mdseries,
  bodyfont=\mdseries,
  notebraces={(}{)},
  preheadhook={
    \edef\mycolor{\barcolor{\myenvir}}
    \begin{tcolorbox}[
      enhanced,
      frame hidden,
      interior hidden,
      borderline west={2pt}{0pt}{\mycolor},
      left*=\topsep,
      right*=0pt,
      top=0pt,
      bottom=0pt,
      parbox=false,
      breakable
    ]
  },
  postfoothook={
    \end{tcolorbox}
  }
]{boxedthm}

\declaretheorem[style=boxedthm,numbered=no]{definition}
\declaretheorem[style=boxedthm,numbered=no]{example}
\declaretheorem[style=boxedthm,parent=chapter]{exercise}
\declaretheorem[style=boxedthm,parent=chapter]{theorem}
\declaretheorem[style=boxedthm,numbered=no]{suggestion}

\setlist[itemize]{itemsep=0pt,topsep=0pt}
\setlist[enumerate]{itemsep=0pt,topsep=0pt,label=\alph*)}
\setlist[enumerate,2]{label=\roman*)}

\DeclareMathOperator{\arity}{arity}
\DeclareMathOperator{\free}{free}

\AtBeginDocument{
  \setlength{\parskip}{\topsep}
  \setlength{\parindent}{0pt}
}