| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2013 by Song Zhiwei <[email protected]> |
| 4 |
% ----------------------------------------------------------- |
| 5 |
% |
| 6 |
% This file may be distributed and/or modified under the conditions of |
| 7 |
% the LaTeX Project Public License, either version 1.3c of this license |
| 8 |
% or (at your option) any later version. The latest version of this |
| 9 |
% license is in: |
| 10 |
% |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% |
| 13 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 14 |
% version 2006/05/20 or later. |
| 15 |
% |
| 16 |
% \fi |
| 17 |
% |
| 18 |
% \iffalse |
| 19 |
% |
| 20 |
%<*driver> |
| 21 |
\ProvidesFile{memory.dtx} |
| 22 |
%</driver> |
| 23 |
%<memory>\NeedsTeXFormat{LaTeX2e}[2003/12/01] |
| 24 |
%<memory>\ProvidesPackage{memory} |
| 25 |
%<*memory> |
| 26 |
[2013/05/13 v1.2 containers for data of object and array in LaTeX] |
| 27 |
%</memory> |
| 28 |
%<*driver> |
| 29 |
\documentclass[a4paper]{ltxdoc} |
| 30 |
\usepackage{memory} |
| 31 |
\EnableCrossrefs |
| 32 |
\CodelineIndex |
| 33 |
\RecordChanges |
| 34 |
\OnlyDescription |
| 35 |
\begin{document} |
| 36 |
\DocInput{memory.dtx} |
| 37 |
\end{document} |
| 38 |
%</driver> |
| 39 |
% \fi |
| 40 |
% |
| 41 |
% \CheckSum{69} |
| 42 |
% |
| 43 |
% \CharacterTable |
| 44 |
% {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 |
| 45 |
% 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 |
| 46 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 47 |
% Exclamation \! Double quote \" Hash (number) \# |
| 48 |
% Dollar \$ Percent \% Ampersand \& |
| 49 |
% Acute accent \' Left paren \( Right paren \) |
| 50 |
% Asterisk \* Plus \+ Comma \, |
| 51 |
% Minus \- Point \. Solidus \/ |
| 52 |
% Colon \: Semicolon \; Less than \< |
| 53 |
% Equals \= Greater than \> Question mark \? |
| 54 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 55 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 56 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 57 |
% Right brace \} Tilde \~} |
| 58 |
% |
| 59 |
% \changes{v1.2}{2013/05/13}{Uses := to set the expanded value to a variable} |
| 60 |
% \changes{v1.1}{2013/05/11}{Reports warning when redeclaring a variable} |
| 61 |
% \changes{v1.0}{2013/05/10}{Initial version} |
| 62 |
% |
| 63 |
% \GetFileInfo{memory.dtx} |
| 64 |
% |
| 65 |
% \DoNotIndex{} |
| 66 |
% |
| 67 |
% \title{The \textsf{memory} package\thanks{This document |
| 68 |
% corresponds to \textsf{memory}~\fileversion, dated \filedate.}} |
| 69 |
% \author{Song Zhiwei\\\texttt{[email protected]}} |
| 70 |
% |
| 71 |
% \maketitle |
| 72 |
% |
| 73 |
% \section{Introduction} |
| 74 |
% |
| 75 |
% The package memory.sty provides an easy way to declare object or array |
| 76 |
% containers. |
| 77 |
% If you are considering to use an auxiliary file, you really need |
| 78 |
% this package rather than the heavy I/O manipulation. |
| 79 |
% |
| 80 |
% \section{Usage} |
| 81 |
% \newcommand\MyDescribeMacro[1]{\marginpar{\raggedleft\strut\MacroFont#1}} |
| 82 |
% \DescribeMacro{\newdata\marg{variable}} |
| 83 |
% \DescribeMacro{\newdata*\marg{variable}} |
| 84 |
% These macros declare data variables locally and globally, respectively. |
| 85 |
% The value for star version is also saved globally. |
| 86 |
% \begin{verbatim}\newdata{Person} % Note: no backslash for the variable declaration |
| 87 |
%\newdata*{Time}\end{verbatim}\newdata{Person} \newdata*{Time} |
| 88 |
% Uses = or := to set value. The := version sets the expanded value to variable. |
| 89 |
% \MyDescribeMacro{\textbackslash\meta{var}\oarg{p}=\marg{value}}% |
| 90 |
% \MyDescribeMacro{\textbackslash\meta{var}\oarg{p}:=\marg{value}}\\[0.5em] |
| 91 |
% -- Sets value as a single variable. |
| 92 |
% \begin{verbatim}\Person = {Song Zhiwei} % Note: add backslash for declared variable |
| 93 |
%\Time := \today\end{verbatim} |
| 94 |
% \Person = {Song Zhiwei} \Time := \today |
| 95 |
% -- Sets value as an array. |
| 96 |
% \begin{verbatim}\Person[1] = {28.3}\end{verbatim}\Person[1] = {28.3} |
| 97 |
% -- Sets value as a multiple dimensional array. |
| 98 |
% \begin{verbatim}\Time[2,5,\thesection] = {13 May 2013}\end{verbatim} |
| 99 |
% \Time[2,5,\thesection] = {13 May 2013} |
| 100 |
% -- Sets value as an object. |
| 101 |
% \begin{verbatim}\Person[description] = {A Chinese gentleman.} |
| 102 |
%\Person[hair] = {black}\end{verbatim} |
| 103 |
% \Person[description] = {A Chinese gentleman.} |
| 104 |
% \Person[hair] = {black} |
| 105 |
% -- Gets values. |
| 106 |
% \MyDescribeMacro{\textbackslash\meta{variable}\oarg{p}} |
| 107 |
% \begin{center}\newcommand\VRule{\rule[-0.2em]{0.4pt}{1.2em}} |
| 108 |
% \verb|\Person|\hfill\VRule\quad\makebox[12em][l]{\Person}\\ |
| 109 |
% \verb|\Time|\hfill\VRule\quad\makebox[12em][l]{\Time}\\ |
| 110 |
% \verb|\Person[1]|\hfill\VRule\quad\makebox[12em][l]{\Person[1]}\\ |
| 111 |
% \verb|\Time[2,5,\thesection]|\hfill\VRule\quad\makebox[12em][l]{\Time[2,5,\thesection]}\\ |
| 112 |
% \verb|\Person[description]|\hfill\VRule\quad\makebox[12em][l]{\Person[description]}\\ |
| 113 |
% \verb|\Person[hair]|\hfill\VRule\quad\makebox[12em][l]{\Person[hair]} |
| 114 |
% \end{center} |
| 115 |
% |
| 116 |
% \StopEventually{} |
| 117 |
\def\set@memory#1#2=#3{\if#1*\expandafter\gdef\csname#2\endcsname{#3}% |
| 118 |
\else\expandafter\def\csname#2\endcsname{#3}\fi} |
| 119 |
\def\eset@memory#1#2=#3{\if#1*\expandafter\xdef\csname#2\endcsname{#3}% |
| 120 |
\else\expandafter\edef\csname#2\endcsname{#3}\fi} |
| 121 |
\def\etest@memory#1#2:{\@ifnextchar={\eset@memory{#1}{#2}} |
| 122 |
{\csname #2\endcsname:}} |
| 123 |
\def\data@memory#1#2{\@ifnextchar={\set@memory{#1}{@#2@memory}} |
| 124 |
{\@ifnextchar:{\etest@memory{#1}{@#2@memory}} |
| 125 |
{\csname @#2@memory\endcsname}}} |
| 126 |
\def\array@memory#1#2[#3]{\data@memory{#1}{#2@#3}} |
| 127 |
\def\newdata@memory#1#2{\@ifundefined{#2} |
| 128 |
{\if#1*\expandafter\gdef\csname#2\endcsname{\@ifnextchar[ |
| 129 |
{\array@memory{#1}{#2}}{\data@memory{#1}{#2}}}% |
| 130 |
\else \expandafter\def\csname#2\endcsname{\@ifnextchar[ |
| 131 |
{\array@memory{#1}{#2}}{\data@memory{#1}{#2}}}\fi} |
| 132 |
{\PackageWarningNoLine{memory}{`#2' already defined. |
| 133 |
Macro `newdata' ignored!}}} |
| 134 |
\def\newdata{\@ifnextchar*{\newdata@memory}{\newdata@memory{}}} |
| 135 |
% \Finale |
| 136 |
\endinput |