summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/lisp-on-tex/lisp-string.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/lisp-on-tex/lisp-string.sty
Initial commit
Diffstat (limited to 'macros/latex/contrib/lisp-on-tex/lisp-string.sty')
-rw-r--r--macros/latex/contrib/lisp-on-tex/lisp-string.sty76
1 files changed, 76 insertions, 0 deletions
diff --git a/macros/latex/contrib/lisp-on-tex/lisp-string.sty b/macros/latex/contrib/lisp-on-tex/lisp-string.sty
new file mode 100644
index 0000000000..9c0c011a2c
--- /dev/null
+++ b/macros/latex/contrib/lisp-on-tex/lisp-string.sty
@@ -0,0 +1,76 @@
+%% CONCAT : string -> string -> string
+%% (\concat str1 str2) => str1 ++ str2
+\@lisp@env@add@global\concat{\@tlabel@func{\@lisp@func@check@args{+}{\def\@temp@str{}\@str@concat}}}
+\def\@str@concat#1#2#3{%
+ \let\@@next@str\relax
+ \ifx#2\@tlabel@string
+ \expandafter\def
+ \expandafter\@temp@str
+ \expandafter{\@temp@str#3}%
+ \let\@@next@str\@str@concat
+ \else\ifx#2\relax
+ \let\@@next@str\@str@fin
+ \else
+ \errmessage{LISP on TeX [function --- concat]:%
+ Arguments of concat must be strings}%
+ \fi\fi\@@next@str#1}
+\def\@str@fin#1{%
+ \expandafter\gdef\expandafter#1%
+ \expandafter{\expandafter\@tlabel@string\expandafter{\@temp@str}}}
+
+%% INT2STRING : int -> string
+%% (\intTOstring i) -> 'i'
+\@lisp@env@add@global\intTOstring{\@tlabel@func{\@lisp@func@check@args{1}{\@conv@intTOstr}}}
+\def\@conv@intTOstr#1\@tlabel@int#2{\gdef#1{\@tlabel@string{#2}}}
+
+%% IMMEDIATEWRITE : () -> ()
+%% It outputs the output buffer immediately.
+%% It cause error if the buffer is incomplete.
+\@lisp@env@add@global\immediatewrite{\@tlabel@func{\@lisp@func@check@args{0}{\@immediate@write}}}
+\def\@immediate@write#1{%
+ \gdef#1{\@tlabel@nil{}}%
+ \@temp@write@buffer\gdef\@temp@write@buffer{}}
+
+%% GROUP : string -> string
+%% (\group str) -> '{str}'
+\@lisp@env@add@global\group{\@tlabel@func{\@lisp@func@check@args{1}{\@text@group}}}
+\def\@text@group#1#2#3{%
+ \ifx#2\@tlabel@string
+ \gdef#1{\@tlabel@string{{#3}}}%
+ \else
+ \errmessage{LISP on TeX [function --- group]:%
+ The argument of group must be a string.}%
+ \fi}
+
+%% UNGROUP : string -> string
+%% (\group '{str}') -> 'str'
+\@lisp@env@add@global\ungroup{\@tlabel@func{\@lisp@func@check@args{1}{\@text@ungroup}}}
+\def\@text@ungroup#1#2#3{%
+ \ifx#2\@tlabel@string
+ \@@text@ungroup#1#3\@@end
+ \else
+ \errmessage{LISP on TeX [function --- ungroup]:%
+ The argument of ungroup must be a string.}%
+ \fi}
+\def\@@text@ungroup#1#2#3\@@end{%
+ \ifx;#3;%
+ \gdef#1{\@tlabel@string{#2}}%
+ \else
+ \errmessage{LISP on TeX [function --- ungroup]:%
+ The argument of ungroup must be a grouped string.}%
+ \fi}
+
+%% FGETS : () -> string
+%% (\fgets) -> read tokens from standard-in
+\@lisp@env@add@global\fgets{\@tlabel@func{\@lisp@func@check@args{0}{\@text@fgets}}}
+\def\@text@fgets#1{%
+\endlinechar=-1
+\read-1to#1%
+\expandafter\gdef\expandafter#1\expandafter{\expandafter\@tlabel@string\expandafter{#1}}}
+
+%% EXPAND : string -> string
+%% (\expand '<token>') -> '<token+>' where <token+> is expanded tokens of <token>
+\@lisp@env@add@global\expand{\@tlabel@func{\@lisp@func@check@args{1}{\@lot@text@expand}}}
+\def\@lot@text@expand#1\@tlabel@string#2{%
+ \edef\@temp@i{#2}%
+ \xdef#1{\noexpand\@tlabel@string{\@temp@i}}}