summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/homework/homework.cls
blob: bf965588a52f89eea5dab41b14d5e324279ffd4f (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
%%
%% Copyright (C) 2023 by Jinwen XU
%% -------------------------------
%%
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version.  The latest version of this
%% license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
\NeedsTeXFormat{LaTeX2e}[2022-06-01]
\ProvidesExplClass
  {homework}
  {2023/09/24} {}
  {Document class for writing homework}

\keys_define:nn { homework }
  {
    , logo        .tl_set:N     = \l__homework_logo_name_tl
    , logo        .initial:n    = { }
    , logo-height .dim_set:N    = \l__homework_logo_height_dim
    , logo~height .dim_set:N    = \l__homework_logo_height_dim
    , logo height .dim_set:N    = \l__homework_logo_height_dim

    , unknown     .code:n       = {
                                    \PassOptionsToClass { \CurrentOption } { minimart }
                                    \PassOptionsToClass { \CurrentOption } { einfart }
                                    \PassOptionsToPackage { \CurrentOption } { ProjLib }
                                  }
  }
\ProcessKeyOptions [ homework ]

%%================================
%%  Load the base class
%%================================

\sys_if_engine_pdftex:TF
  {
    \PassOptionsToClass { use style = classical } { minimart }
    \LoadClass { minimart }
  }
  {
    \PassOptionsToClass { use style = classical } { einfart }
    \LoadClass { einfart }
  }

\RequirePackage { ProjLib }

%%================================
%%  Insert the logo
%%================================

\cs_new_protected:Nn \homework_include_logo:nn
  % #1 = height
  % #2 = name
  {
    \includegraphics [ height = #1 ] { #2 }
  }

\AddToHook { begindocument/end }
  {
    \maketitle

    \tl_if_empty:NF \l__homework_logo_name_tl
      {
        \dim_compare:nNnT { \l__homework_logo_height_dim } < { 1pt }
          {
            \dim_set:Nn \l__homework_logo_height_dim { .6\pagetotal }
          }
        \dim_set:Nn \l_tmpa_dim { \pagetotal + .33\baselineskip }
        \vspace { - \l_tmpa_dim }
        \vspace { .5\l_tmpa_dim - .5\l__homework_logo_height_dim }
        \homework_include_logo:nn { \l__homework_logo_height_dim } { \l__homework_logo_name_tl }
        \vspace { .5\l_tmpa_dim - .5\l__homework_logo_height_dim }
      }
  }

%%================================
%%  Page # of ##
%%================================

\projlib_langauge_define_multilingual_text:Nn \l__homework_page_of_total_tl
  {
    , EN = { Page \nobreakspace \,\thepage\, \nobreakspace of \nobreakspace \,\pageref*{LastPage} }
    , FR = { Page \nobreakspace \,\thepage\, \nobreakspace sur \nobreakspace \,\pageref*{LastPage} }
    , DE = { Seite \nobreakspace \,\thepage\, \nobreakspace von \nobreakspace \,\pageref*{LastPage} }
    , IT = { Pagina \nobreakspace \,\thepage\, \nobreakspace di \nobreakspace \,\pageref*{LastPage} }
    , PT = { Página \nobreakspace \,\thepage\, \nobreakspace de \nobreakspace \,\pageref*{LastPage} }
    , BR = { Página \nobreakspace \,\thepage\, \nobreakspace de \nobreakspace \,\pageref*{LastPage} }
    , ES = { Página \nobreakspace \,\thepage\, \nobreakspace de \nobreakspace \,\pageref*{LastPage} }
    , CN = { 第 \,\thepage\, 页,共 \,\pageref*{LastPage}\, 页 }
    , TC = { 第 \,\thepage\, 頁,共 \,\pageref*{LastPage}\, 頁 }
    , JP = { ページ \nobreakspace \,\thepage\, / \,\pageref*{LastPage} }
    , RU = { Страница \nobreakspace \,\thepage\, \nobreakspace из \nobreakspace \,\pageref*{LastPage} }
  }

\RequirePackage { lastpage }
\fancypagestyle { fancy }
  {
    \rfoot{\small\color{main-text!27!paper} \l__homework_page_of_total_tl }
  }
\pagestyle { fancy }

%%================================
%%  Colored solution environment
%%================================

\projlib_langauge_define_multilingual_text:Nn \l__homework_solution_tl
  {
    , EN = { Solution }
    , FR = { Solution }
    , DE = { Lösung }
    , IT = { Soluzione }
    , PT = { Solução }
    , BR = { Solução }
    , ES = { Solución }
    , CN = { 解 }
    , TC = { 解 }
    , JP = { 解答 }
    , RU = { Решение }
  }

\newcommand\soluline{\bgroup\markoverwith{\rule[-.45ex]{2pt}{.75pt}}\ULon}
\NewDocumentEnvironment { solution } { O{ \l__homework_solution_tl } }
  {
    \setlength\abovedisplayskip{.3\baselineskip}
    \setlength\belowdisplayskip{.3\baselineskip}
    \setlength\abovedisplayshortskip{.3\baselineskip}
    \setlength\belowdisplayshortskip{.3\baselineskip}
    \par\noindent
    \color{cyan!50!blue!90!main-text}
    \soluline{#1}\nobreakspace\nobreakspace
    \let\qedsymbol\customqedsymbol
  }{\pushQED{\qed}\popQED\par}

%%================================
%%  Configuration of the theorems
%%================================

\newcounter{homework}
\SetTheorem{problem,question}{shared counter=homework}
\SetTheorem{lemma,theorem,proposition,fact,remark}{number within=homework}

\endinput
%%
%% End of file `homework.cls'.