forked from simurgh9/hw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hwcmd.sty
84 lines (77 loc) · 2.73 KB
/
hwcmd.sty
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
% Tashfeen's complicated macros
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{hwcmd}[2023/01/01 hwcmd]
\RequirePackage{graphicx} % figures
\RequirePackage[caption=false]{subfig}
\RequirePackage{graphicx, pgffor, ifthen} % for loops and if statements
\RequirePackage[tableposition=below]{caption} % https://tex.stackexchange.com/a/424725/215221
\newlength{\unitskipamount}
\setlength{\unitskipamount}{\medskipamount}
\gdef\@unitname{Question}
\newcounter{UnitCounter}
\newcommand{\setunitname}[1]{\gdef\@unitname{#1}}
\newcommand{\question}[1][\arabic{UnitCounter}]{%
\Needspace*{8\baselineskip}%
\addvspace{\unitskipamount}%
\def\@currentlabel{#1}%
\ifthenelse{\equal{#1}{\value{UnitCounter}}}{\stepcounter{UnitCounter}}{}%
\setcounter{section}{0}%
\renewcommand{\thesection}{#1.\arabic{section}}%
\renewcommand{\theHsection}{#1.\the\value{section}}%
\addcontentsline{toc}{part}{#1. \@unitname{}}%
\noindent\textbf{\@unitname{} #1. }\ignorespaces%
}
\newcommand{\fig}[4][0.4]{
\begin{figure}[hbtp]
\foreach \path in {#2} {
\begin{minipage}{#1\textwidth}
\centering % don't introduce new lines in \subfloat{...}
\subfloat{\includegraphics[width=\linewidth]{\path}}
\end{minipage} % minipage for easy centring
}
\caption{#3}\label{#4}
\end{figure}
\PackageWarning{hwcmd}{\noexpand\fig is deprecated, use \noexpand\img instead}
}
\ExplSyntaxOn
\NewDocumentCommand\img{d<>O{0.4}mm} {%
\begin{figure}[hbtp]%
\foreach \path [count=\i] in {#4} {%
\ifthenelse{\equal{\i}{1}}{}{\hspace{0.25cm}}%
\begin{minipage}{#2\textwidth}%
\centering% don't introduce new lines in \subfloat{...}
\subfloat{\includegraphics[width=\linewidth]{\path}}%
\end{minipage}%
}%
\caption{#3}\IfValueT{#1}{\label{#1}}%
\end{figure}%
}
\NewDocumentCommand\tbl{d<>mm} {%
\begin{table}[hbtp]%
\centering%
\scribe_tbl:n { #3 }%
\caption{#2}%
\IfValueT{#1}{\label{#1}}%
\end{table}%
}
\seq_new:N \l__scribe_tbl_body_seq
\seq_new:N \l__scribe_tbl_row_seq
\int_new:N \l__scribe_tbl_cols_int
\cs_new_protected:Nn \scribe_tbl:n {
\seq_set_split:Nnn \l__scribe_tbl_body_seq { \\ } { #1 }
\seq_pop_right:NN \l__scribe_tbl_body_seq \l_tmpa_tl
\tl_if_empty:NF \l_tmpa_tl { \seq_put_right:NV \l__scribe_tbl_body_seq \l_tmpa_tl }
\int_zero:N \l__scribe_tbl_cols_int
\seq_map_inline:Nn \l__scribe_tbl_body_seq {
\seq_set_split:Nnn \l__scribe_tbl_row_seq { & } { ##1 }
\int_set:Nn \l__scribe_tbl_cols_int {
\int_max:nn { \l__scribe_tbl_cols_int } { \seq_count:N \l__scribe_tbl_row_seq }
}
}
\begin{tabular}{ ||*{\l__scribe_tbl_cols_int}{c|}| }
\hline
\seq_use:Nn \l__scribe_tbl_body_seq { \\ \hline }
\\ \hline
\end{tabular}
}
\ExplSyntaxOff