-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
awesomebox-compat.sty
188 lines (159 loc) · 6.42 KB
/
awesomebox-compat.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{awesomebox-compat}[2019/07/27 v0.6]
% Awesome Box has been written by Étienne Deparis and is released under
% the WTFPL (http://www.wtfpl.net/txt/copying/).
% A copy of this license is distributed in this package.
%
% Contributors:
% v0.2: Vincent Goulet https://github.com/vigou3
% v0.3: Gilbert Fuerer https://github.com/foreachthing
% * Remove xelatex/luatex requirement and add pdflatex compatibility
% v0.4: Marcel Krüger https://github.com/zauguin
% * Fontawesome5 compatibility
% Gilbert Fuerer
% * Custom vertical rule color
% v0.5: Georger Araújo https://github.com/georgerbr
% * Horizontal rules at top and bottom, title
% v0.6: Vincent Goulet https://github.com/vigou3
% * Improving table cell rendering
% Georger Araújo
% * awesomebox-compat
% https://ctan.org/pkg/fontawesome
\RequirePackage{fontawesome}
% Compatibility with old version of this package
\def\abIconCheck{\faCheck}
\def\abIconInfoCircle{\faInfoCircle}
\def\abIconFire{\faFire}
\def\abIconExclamationCircle{\faExclamationCircle}
\def\abIconExclamationTriangle{\faExclamationTriangle}
\def\abIconCogs{\faCogs}
\def\abIconThumbsUp{\faThumbsUp}
\def\abIconThumbsDown{\faThumbsDown}
\def\abIconCertificate{\faCertificate}
\def\abIconLightBulb{\faLightbulb[regular]}
\def\abIconTwitter{\faTwitter}
\def\abIconGithub{\faGithub}
\RequirePackage{ifxetex,ifluatex}
\newif\ifawesomebox@notxetex\awesomebox@notxetextrue
\ifxetex
\awesomebox@notxetexfalse
\else
\ifluatex
\awesomebox@notxetexfalse
\fi
\fi
\ifawesomebox@notxetex
\PackageError{awesomebox-compat}{%
You are trying to use awesomebox\MessageBreak
with something else than xelatex or luatex
}{%
Please abort now with <ctrl+d>
}
\fi
% This package heavily uses the work of Honza Ustohal, known under the
% name FontAwesome bindings for (Xe)LaTeX:
% https://gist.github.com/sway/3101743
\RequirePackage{xltxtra}
\newfontfamily{\ABFamily}{FontAwesome}
% https://ctan.org/pkg/xcolor
\RequirePackage{xcolor}
% Some basic colors
\definecolor{abnote}{RGB}{25,64,122}
\definecolor{abcaution}{RGB}{188,50,0}
\definecolor{abwarning}{RGB}{188,103,0}
\definecolor{abimportant}{RGB}{188,0,0}
\definecolor{abvrulecolor}{RGB}{221,221,216}
% Customizable length
\newlength{\aweboxleftmargin}
\newlength{\aweboxcontentwidth}
\newlength{\aweboxvskip}
\setlength{\aweboxvskip}{5mm}
\newlength{\aweboxsignraise}
\setlength{\aweboxsignraise}{-5mm}
\newlength{\aweboxrulewidth}
\setlength{\aweboxrulewidth}{2pt}
\AtBeginDocument{%
\setlength{\aweboxleftmargin}{0.12\linewidth}%
\setlength{\aweboxcontentwidth}{0.88\linewidth}}
\RequirePackage{array}
% To allow for more than one optional argument
\RequirePackage{xparse}
% Horizontal rule definitions used with second optional argument [hrule]
\def\abShortLine{\cline{2-2}}
\def\abLongLine{\hline}
% The following commands are used to adjust and restore awesome boxes
% content width in respect to the current environment (e.g. lists).
\RequirePackage{ifthen}
\newlength{\aweboxlinewidthvar}
\setlength{\aweboxlinewidthvar}{0pt}
\newlength{\aweboxlinewidthref}
\AtBeginDocument{\setlength{\aweboxlinewidthref}{\linewidth}}
\newcommand{\awesomeboxadjustcontentwidth}{%
\ifthenelse{\lengthtest{\linewidth=\aweboxlinewidthref}}{}{%
\setlength{\aweboxlinewidthvar}{\dimexpr\aweboxlinewidthref-\linewidth}%
\setlength{\aweboxcontentwidth}{\dimexpr\aweboxcontentwidth-\aweboxlinewidthvar}}}%
%\aweboxdebug}}
\newcommand{\awesomeboxrestorecontentwidth}{%
\ifthenelse{\lengthtest{\linewidth=\textwidth}}{}{%
\setlength{\aweboxcontentwidth}{\dimexpr\aweboxcontentwidth+\aweboxlinewidthvar}%
\setlength{\aweboxlinewidthvar}{0pt}}}
% Commands API
% \awesomebox[vrulecolor][hrule][title]{vrulewidth}{icon}{iconcolor}{content}
\NewDocumentCommand \awesomebox { O{abvrulecolor} O{} o m m m +m }{%
{\vskip \aweboxvskip}\noindent\awesomeboxadjustcontentwidth%
\begin{tabular}%
{@{}>{\centering\arraybackslash}%
p{\aweboxleftmargin}@{}!{\color{#1}\vrule width #4}%
p{\dimexpr\aweboxcontentwidth-#4-\tabcolsep}@{}}
\IfValueTF {#3}
{ & #3 \\ #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} & #7 \\ #2}
{ #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} & #7 \\ #2}
\end{tabular}{\vskip \aweboxvskip}\awesomeboxrestorecontentwidth}
\newcommand{\notebox}[1]{%
\awesomebox[abnote]{\aweboxrulewidth}{\faInfoCircle}{abnote}{#1}}
\newcommand{\tipbox}[1]{%
\awesomebox{\aweboxrulewidth}{\faLightbulbO}{black}{#1}}
\newcommand{\warningbox}[1]{%
\awesomebox[abwarning]{\aweboxrulewidth}{\faExclamationTriangle}{abwarning}{#1}}
\newcommand{\cautionbox}[1]{%
\awesomebox[abcaution]{\aweboxrulewidth}{\faFire}{abcaution}{#1}}
\newcommand{\importantbox}[1]{%
\awesomebox[abimportant]{\aweboxrulewidth}{\faExclamationCircle}{abimportant}{#1}}
% Environments API
% \begin{awesomeblock}[vrulecolor][hrule][title]{vrulewidth}{icon}{iconcolor}
% content
% \end{awesomeblock}
\NewDocumentEnvironment{awesomeblock}{ O{abvrulecolor} O{} o m m m }
{{\vskip \aweboxvskip}\noindent\awesomeboxadjustcontentwidth%
\begin{tabular}%
{@{}>{\centering\arraybackslash}%
p{\aweboxleftmargin}@{}!{\color{#1}\vrule width #4}%
p{\dimexpr\aweboxcontentwidth-#4-\tabcolsep}@{}}
\IfValueTF {#3}
{ & #3 \\ #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} &}
{ #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} &}}
{\\ #2 \end{tabular}{\vskip \aweboxvskip}\awesomeboxrestorecontentwidth}
\newenvironment{noteblock}%
{\begin{awesomeblock}[abnote]{\aweboxrulewidth}{\faInfoCircle}{abnote}}
{\end{awesomeblock}}
\newenvironment{tipblock}%
{\begin{awesomeblock}{\aweboxrulewidth}{\faLightbulbO}{black}}
{\end{awesomeblock}}
\newenvironment{warningblock}%
{\begin{awesomeblock}[abwarning]{\aweboxrulewidth}{\faExclamationTriangle}{abwarning}}
{\end{awesomeblock}}
\newenvironment{cautionblock}%
{\begin{awesomeblock}[abcaution]{\aweboxrulewidth}{\faFire}{abcaution}}
{\end{awesomeblock}}
\newenvironment{importantblock}%
{\begin{awesomeblock}[abimportant]{\aweboxrulewidth}{\faExclamationCircle}{abimportant}}
{\end{awesomeblock}}
\newcommand{\aweboxdebug}{%
\typeout{**************************}%
\typeout{Line width: \the\linewidth}%
\typeout{Reference line width: \the\aweboxlinewidthref\space(text width: \the\textwidth)}%
\typeout{Width difference: \the\aweboxlinewidthvar}%
\typeout{Margin width: \the\aweboxleftmargin}%
\typeout{Content width: \the\aweboxcontentwidth}%
\typeout{**************************}}
\endinput