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
|
% \iffalse meta-comment
%
% Copyright (C) 2013 by Song Zhiwei <songzw@gmail.com>
% -----------------------------------------------------------
%
% 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 2006/05/20 or later.
%
% \fi
%
% \iffalse
%
%<*driver>
\ProvidesFile{memory.dtx}
%</driver>
%<memory>\NeedsTeXFormat{LaTeX2e}[2003/12/01]
%<memory>\ProvidesPackage{memory}
%<*memory>
[2013/05/13 v1.2 containers for data of object and array in LaTeX]
%</memory>
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{memory}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\OnlyDescription
\begin{document}
\DocInput{memory.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{69}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
% \changes{v1.2}{2013/05/13}{Uses := to set the expanded value to a variable}
% \changes{v1.1}{2013/05/11}{Reports warning when redeclaring a variable}
% \changes{v1.0}{2013/05/10}{Initial version}
%
% \GetFileInfo{memory.dtx}
%
% \DoNotIndex{}
%
% \title{The \textsf{memory} package\thanks{This document
% corresponds to \textsf{memory}~\fileversion, dated \filedate.}}
% \author{Song Zhiwei\\\texttt{songzw@gmail.com}}
%
% \maketitle
%
% \section{Introduction}
%
% The package memory.sty provides an easy way to declare object or array
% containers.
% If you are considering to use an auxiliary file, you really need
% this package rather than the heavy I/O manipulation.
%
% \section{Usage}
% \newcommand\MyDescribeMacro[1]{\marginpar{\raggedleft\strut\MacroFont#1}}
% \DescribeMacro{\newdata\marg{variable}}
% \DescribeMacro{\newdata*\marg{variable}}
% These macros declare data variables locally and globally, respectively.
% The value for star version is also saved globally.
% \begin{verbatim}\newdata{Person} % Note: no backslash for the variable declaration
%\newdata*{Time}\end{verbatim}\newdata{Person} \newdata*{Time}
% Uses = or := to set value. The := version sets the expanded value to variable.
% \MyDescribeMacro{\textbackslash\meta{var}\oarg{p}=\marg{value}}%
% \MyDescribeMacro{\textbackslash\meta{var}\oarg{p}:=\marg{value}}\\[0.5em]
% -- Sets value as a single variable.
% \begin{verbatim}\Person = {Song Zhiwei} % Note: add backslash for declared variable
%\Time := \today\end{verbatim}
% \Person = {Song Zhiwei} \Time := \today
% -- Sets value as an array.
% \begin{verbatim}\Person[1] = {28.3}\end{verbatim}\Person[1] = {28.3}
% -- Sets value as a multiple dimensional array.
% \begin{verbatim}\Time[2,5,\thesection] = {13 May 2013}\end{verbatim}
% \Time[2,5,\thesection] = {13 May 2013}
% -- Sets value as an object.
% \begin{verbatim}\Person[description] = {A Chinese gentleman.}
%\Person[hair] = {black}\end{verbatim}
% \Person[description] = {A Chinese gentleman.}
% \Person[hair] = {black}
% -- Gets values.
% \MyDescribeMacro{\textbackslash\meta{variable}\oarg{p}}
% \begin{center}\newcommand\VRule{\rule[-0.2em]{0.4pt}{1.2em}}
% \verb|\Person|\hfill\VRule\quad\makebox[12em][l]{\Person}\\
% \verb|\Time|\hfill\VRule\quad\makebox[12em][l]{\Time}\\
% \verb|\Person[1]|\hfill\VRule\quad\makebox[12em][l]{\Person[1]}\\
% \verb|\Time[2,5,\thesection]|\hfill\VRule\quad\makebox[12em][l]{\Time[2,5,\thesection]}\\
% \verb|\Person[description]|\hfill\VRule\quad\makebox[12em][l]{\Person[description]}\\
% \verb|\Person[hair]|\hfill\VRule\quad\makebox[12em][l]{\Person[hair]}
% \end{center}
%
% \StopEventually{}
\def\set@memory#1#2=#3{\if#1*\expandafter\gdef\csname#2\endcsname{#3}%
\else\expandafter\def\csname#2\endcsname{#3}\fi}
\def\eset@memory#1#2=#3{\if#1*\expandafter\xdef\csname#2\endcsname{#3}%
\else\expandafter\edef\csname#2\endcsname{#3}\fi}
\def\etest@memory#1#2:{\@ifnextchar={\eset@memory{#1}{#2}}
{\csname #2\endcsname:}}
\def\data@memory#1#2{\@ifnextchar={\set@memory{#1}{@#2@memory}}
{\@ifnextchar:{\etest@memory{#1}{@#2@memory}}
{\csname @#2@memory\endcsname}}}
\def\array@memory#1#2[#3]{\data@memory{#1}{#2@#3}}
\def\newdata@memory#1#2{\@ifundefined{#2}
{\if#1*\expandafter\gdef\csname#2\endcsname{\@ifnextchar[
{\array@memory{#1}{#2}}{\data@memory{#1}{#2}}}%
\else \expandafter\def\csname#2\endcsname{\@ifnextchar[
{\array@memory{#1}{#2}}{\data@memory{#1}{#2}}}\fi}
{\PackageWarningNoLine{memory}{`#2' already defined.
Macro `newdata' ignored!}}}
\def\newdata{\@ifnextchar*{\newdata@memory}{\newdata@memory{}}}
% \Finale
\endinput
|