summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gradientframe/gradientframe.dtx
blob: 881840956bca4b990129a06019f364103cdc48d9 (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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
% \iffalse The license starting three lines down applies to this file.
%<*batchfile>
{\obeylines\obeyspaces \gdef\thepreamble{

LaTeX package gradientframe for simple rectangular gradient frames around objects.

Copyright (C) Christian Raue, 2011
Send feedback to christian°raue@gmail°com (after being exposed to gravity).

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

and version 1.3c or later is part of all distributions of
LaTeX version 2005/12/01 or later.

This work has the LPPL maintenance status "maintained".

The Current Maintainer of this work is Christian Raue.

This work consists of gradientframe.dtx and the derived file
gradientframe.sty.

}}

\begingroup
\input{docstrip}
\keepsilent
\usedir{tex/latex/\jobname}
\expandafter\preamble\thepreamble\endpreamble
\askforoverwritefalse
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
\endgroup

\documentclass{ltxdoc}
\usepackage[american]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{charter}
\usepackage[%
	inner=55mm,%
	outer=10mm,%
	top=20mm,%
	bottom=20mm,%
]{geometry}
\usepackage{color}
\usepackage[%
	pdftitle={the \jobname{} package},%
	pdfauthor={Christian Raue},%
	pdfsubject={LaTeX package documentation},%
	pdfkeywords={\jobname{} LaTeX rectangular gradient frame border around object table figure},%
 	pdfproducer={LaTeX},%
 	pdfcreator={LaTeX},%
	pdfborder={0 0 0},%
	pdfpagemode={UseOutlines},%
	pdfstartview={FitH},%
	pdfview={FitH},%
	pdfdisplaydoctitle=true,%
	]{hyperref}
\usepackage{tabularx}
\usepackage{listings}
\definecolor{lightgray}{gray}{.95}
\lstset{%
	frame=trbl,%
	framerule=0pt,%
	basicstyle=\footnotesize\ttfamily,%
	breaklines=true,%
	tabsize=4,%
	numbers=left,%
	numberstyle=\tiny,%
	backgroundcolor=\color{lightgray},%
}
\usepackage{emp}
\ifx\pdftexversion\undefined
	\usepackage[dvips]{graphicx}
\else
	\usepackage{graphicx}
	\DeclareGraphicsRule{*}{mps}{*}{}
\fi
\usepackage{\jobname}

\DoNotIndex{\def}

%\CodelineIndex
%\EnableCrossrefs
%\RecordChanges
%\OnlyDescription
%\setcounter{IndexColumns}{2}
\GetFileInfo{\jobname.sty}

\newcommand{\supdot}{%
	\scalebox{1.2}{$\dot{~}$}%
}
\newcommand{\package}[1]{%
	\texttt{#1}%
}
\newcommand{\resultarrow}{%
	\begin{center}
		\scalebox{2}{%
			\begin{picture}(9,10)
				\put(5,10){\vector(0,-4){10}}
			\end{picture}%
		}
	\end{center}%
}
\newcommand{\face}{%
	\begingroup
		\setlength{\fboxsep}{5px}%
		\scalebox{2}{\fbox{%
			\Huge
			$\ddot\smile$%
		}}%
	\endgroup
}
\newcommand{\command}[1]{%
	\texttt{\textbackslash{}#1}%
}

\title{the \package{\jobname} package\thanks{This document corresponds to \package{\jobname}~\fileversion, dated \filedate.}\\[1em]}
\author{Christian Raue\\[1em]\texttt{christian\supdot{}raue@gmail\supdot{}com}\\(after being exposed to gravity)\\[2em]}
\date{\filedate}

\begin{document}
\maketitle


\phantomsection
\addcontentsline{toc}{section}{\abstractname}
\begin{abstract}
\noindent
The \package{\jobname} package provides a command, \command{gradientframe}, for simple and discreet rectangular grayscale
gradient frames around objects, such as figures or tables, to set them apart from the surrounding text.
\end{abstract}


\phantomsection
\addcontentsline{toc}{section}{\contentsname}
\tableofcontents
\clearpage


\section{Introduction}
The \package{gradientframe} package is loaded in the usual way, i.e. by putting the line
\begin{quote}
	|\usepackage{gradientframe}|
\end{quote}
in the document's preamble. The \package{gradientframe} package depends on the \package{color} package which is loaded
by the \package{gradientframe} package if not already done so far in the document's preamble.


\section{Usage}
\DescribeMacro\gradientframe
To frame an object, such as figure, table, etc., use the \command{gradientframe\marg{object}} command.
By using \command{gradientframe\oarg{name=value,\ldots}\marg{object}}, the result can be influenced by providing the
following options by name:
\begin{itemize}
	\item
		\texttt{linewidth} (default value: \texttt{0.3px})\\
		defines each color's line width
	\item
		\texttt{padding} (default value: \texttt{0mm})\\
		defines space between the object and the frame (applies to all four sides)
\end{itemize}
Also take a look at the following examples.


\section{Examples}
\subsection{Frame surrounding a figure}
\begin{lstlisting}
	\begin{center}
		\gradientframe{\includegraphics{image.jpg}}
	\end{center}
\end{lstlisting}
\resultarrow
\begin{center}
	\gradientframe{\face}
\end{center}


\subsection{Frame surrounding a figure with additional space}
\begin{lstlisting}
	\begin{center}
		\gradientframe[padding=5mm]{\includegraphics{image.jpg}}
	\end{center}
\end{lstlisting}
\resultarrow
\begin{center}
	\gradientframe[padding=5mm]{\face}
\end{center}


\subsection{Frame surrounding a figure with thicker frame lines and additional space}
\begin{lstlisting}
	\begin{center}
		\gradientframe[linewidth=1px,padding=5mm]{\includegraphics{image.jpg}}
	\end{center}
\end{lstlisting}
\resultarrow
\begin{center}
	\gradientframe[padding=5mm,linewidth=1px]{\face}
\end{center}


\subsection{Frame surrounding a table}
\begin{lstlisting}
	\begin{center}
		\gradientframe{%
			\begin{tabular}{r|l}
				\textbf{column A}	& \textbf{column B}	\\\hline
				cell 1A				& cell 1B			\\\hline
				cell 2A				& cell 2B			\\\hline
				cell 3A				& cell 3B			\\
			\end{tabular}%
		}
	\end{center}
\end{lstlisting}
\resultarrow
\begin{center}
	\gradientframe{%
		\begin{tabular}{r|l}
			\textbf{column A}	& \textbf{column B}	\\\hline
			cell 1A				& cell 1B			\\\hline
			cell 2A				& cell 2B			\\\hline
			cell 3A				& cell 3B			\\
		\end{tabular}%
	}
\end{center}
Be careful not to produce unintentional space when breaking lines. Add comments at line endings if needed to prevent
this, as shown in lines 2 and 8. Otherwise the result will look like this:
\begin{center}
	\gradientframe{
		\begin{tabular}{r|l}
			\textbf{column A}	& \textbf{column B}	\\\hline
			cell 1A				& cell 1B			\\\hline
			cell 2A				& cell 2B			\\\hline
			cell 3A				& cell 3B			\\
		\end{tabular}
	}
\end{center}


\clearpage
\subsection{Frame surrounding a MetaPost figure}
If you want to draw a frame around a MetaPost (or in the case of this example, MetaUML) generated figure, use the
\command{empuse} command.
\begin{lstlisting}
	\begin{center}
		\begin{empfile}
			\begin{empcmds}
				input metauml;
			\end{empcmds}
			\begin{empdef}[unique_name](0,0)
				save start, end;
				Begin.start;
				End.end;
				leftToRight(15)(start, end);
				drawObjects(start, end);
				clink(transition)(start, end);
			\end{empdef}
			\gradientframe[padding=5mm]{\empuse{unique_name}}
		\end{empfile}
	\end{center}
\end{lstlisting}
\resultarrow
\begin{center}
	\begin{empfile}
		\begin{empcmds}
			input metauml;
		\end{empcmds}
		\begin{empdef}[unique_name](0,0)
			save start, end;
			Begin.start;
			End.end;
			leftToRight(15)(start, end);
			drawObjects(start, end);
			clink(transition)(start, end);
		\end{empdef}
		\gradientframe[padding=5mm]{\empuse{unique_name}}
	\end{empfile}
\end{center}
Alternatively, you could outsource both, the \texttt{empdef} environment and the \command{empuse} command to a separate
file, and use \command{input\marg{filename}} as argument to the \command{gradientframe} command.


\section{Known issues}
\DescribeMacro\pagecolor
When using a page color different than white in combination with a (partially) transparent object, the transparent area
inside the frame will be white. To avoid this, a \command{colorbox} has to be drawn around the object. So instead of
\begin{quote}
	\command{pagecolor\marg{color}}\\
	\command{gradientframe\marg{object}}
\end{quote}
one should use
\begin{quote}
	\command{pagecolor\marg{color}}\\
	\command{gradientframe\{\command{colorbox}\marg{color}\marg{object}\}}
\end{quote}
This issue will hopefully be addressed in a future version.


\StopEventually{
	\typeout{****************************************************}
	\typeout{* To finish the installation, you have to move the}
	\typeout{* following file into a directory searched by TeX:}
	\typeout{*}
	\typeout{* \space\space \jobname.sty}
	\typeout{*}
	\typeout{* Documentation is in \jobname.\ifpdf pdf\else dvi\fi.}
	\typeout{*}
	\typeout{* Happy TeXing!}
	\typeout{****************************************************}
	\end{document}
}


\clearpage
\DocInput{\jobname.dtx}


\clearpage
%\phantomsection
%\addcontentsline{toc}{section}{Change history}
%\PrintChanges
\section{Change history}

\newlength{\notewidth}
\settowidth{\notewidth}{Note: }
\newcommand{\noteindent}{\hspace*{\notewidth}}
\begin{tabularx}{\textwidth}{|l|l|X|}
	\hline
	v0.1	& 2011/02/10	&	Initial version.
	\\\hline
	v0.1a	& 2011/02/10	&	Changed file encoding to ISO-8859-1 due to issues on CTAN.
	\\\hline
	v0.2	& 2011/02/13	&	Applied several code improvements.\newline
								Added key/value options for more flexibility.\newline
								Note: This breaks backward compatibility, so change calls in the form\newline
								\noteindent \command{gradientframe[\meta{width}]\marg{object}}\newline
								\noteindent to\newline
								\noteindent \command{gradientframe[padding=\meta{width}]\marg{object}}\newline
								\noteindent in case of an update from previous versions.
	\\\hline
\end{tabularx}


%\phantomsection
%\addcontentsline{toc}{section}{Index}
%\PrintIndex


\Finale
%</batchfile>
% \fi
%
% \section{Implementation}
%
%
% \subsection{Package header}
%	\begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{gradientframe}[2011/02/13 v0.2 simple gradient frames around objects]
\RequirePackage{color}
\RequirePackage{keyval}
%    \end{macrocode}%^^A must be exactly 4 spaces
%
% \subsection{Options for the \command{gradientframe} command}
% The \package{keyval} package is used to handle options given to the \command{gradientframe} command by name. These
% options are:
% \begin{itemize}
%	\item \texttt{linewidth} -- defines each color's line width
%	\begin{macrocode}
\define@key{gradientframe}{linewidth}{%
	\newdimen\gradientframe@linewidth%
	\setlength{\gradientframe@linewidth}{#1}%
}%
%    \end{macrocode}%^^A must be exactly 4 spaces
%
%	\item \texttt{padding} -- defines space between the object and the innermost frame line
%	\begin{macrocode}
\define@key{gradientframe}{padding}{%
	\newdimen\gradientframe@padding%
	\setlength{\gradientframe@padding}{#1}%
}%
%    \end{macrocode}%^^A must be exactly 4 spaces
% \end{itemize}
%
%^^A \define@key{gradientframe}{outercolor}{}
%^^A \define@key{gradientframe}{innercolor}{}
%
% \begin{macro}{\gradientframe@defaults}
% The default values for these options are defined as follows:
%	\begin{macrocode}
\newcommand{\gradientframe@defaults}{%
	\setkeys{gradientframe}{%
		linewidth=0.3px,%
		padding=0mm%
	}%
}%
%    \end{macrocode}%^^A must be exactly 4 spaces
% \end{macro}
%
% \subsection{Commands}
% \begin{macro}{\gradientframe@origlinewidth}
% This dimension is used internally to preserve the original line width defined by \command{fboxrule}.
%	\begin{macrocode}
\newdimen\gradientframe@origlinewidth%
%    \end{macrocode}%^^A must be exactly 4 spaces
% \end{macro}
%
% \begin{macro}{\gradientframe@drawbox}
% This command uses two colors, for border and background, and draws one frame line.
%	\begin{macrocode}
\newcommand{\gradientframe@drawbox}[3]{%
	\fcolorbox[gray]{#1}{#2}{%
		#3%
	}%
}%
%    \end{macrocode}%^^A must be exactly 4 spaces
% \end{macro}
%
% \begin{macro}{\gradientframe}
% This command draws the grayscale gradient frame around objects. This is achieved by drawing multiple frame lines side
% by side, each with a slightly different color.
%	\begin{macrocode}
\newcommand{\gradientframe}[2][]{%
	\gradientframe@defaults% apply defaults
	\setkeys{gradientframe}{#1}%
%
	\begingroup% limit redefinitions to this block
		% backup original \fboxrule value
		\setlength{\gradientframe@origlinewidth}{\fboxrule}%
%
		\setlength{\fboxrule}{\gradientframe@linewidth}%
		\setlength{\fboxsep}{\gradientframe@linewidth}% space between frame and object
		\gradientframe@drawbox{.98}{.96}{%
			\gradientframe@drawbox{.94}{.92}{%
				\gradientframe@drawbox{.90}{.88}{%
					\gradientframe@drawbox{.86}{.84}{%
						\gradientframe@drawbox{.82}{.80}{%
							\gradientframe@drawbox{.78}{.76}{%
								\gradientframe@drawbox{.74}{.72}{%
									\setlength{\fboxrule}{\gradientframe@origlinewidth}% restore original \fboxrule value
									\setlength{\fboxsep}{\gradientframe@padding}%
									\gradientframe@drawbox{.70}{1}{#2}%
								}%
							}%
						}%
					}%
				}%
			}%
		}%
	\endgroup%
}%
%    \end{macrocode}%^^A must be exactly 4 spaces
% \end{macro}
%
\endinput
% \endinput