blob: 2496440c700365372451945e4f38bc7c8d345dc4 (
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
|
%D \module
%D [ file=meta-tex,
%D version=2006.06.07,
%D title=\CONTEXT\ Support Macros,
%D subtitle=\METAPOST\ fast text insertion,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\registerctxluafile{meta-tex}{1.001}
\unprotect
% Ok, we support this in MkIV because Mojca kept the pressure on. It
% looks a bit like a hack.
\long\def\startTeXtexts#1\stopTeXtexts
{#1}
\long\def\TeXtext
{\dosingleempty\doTeXtext}
\long\def\doTeXtext[#1]#2#3% contrary to mkii we don't process yet but we do expand
{\long\setxvalue{@@st@@::#2}{\noexpand\dodoTeXtext{#1}{#3}}}
\long\def\dodoTeXtext#1#2%
{\begingroup
\setbox\nextbox\hbox{\executeifdefined{textext@@#1}\firstofoneargument{#2}}%
\executeifdefined{textext::#1}{\getvalue{textext::depth}}%
\box\nextbox
\endgroup}
\def\getTeXtext#1%
{\getvalue{@@st@@::#1}}
\setvalue{textext::d}{\setbox\nextbox\hbox{\lower\dp\nextbox\box\nextbox}} % unchecked
\setvalue{textext::n}{} % unchecked
\setvalue {textext::depth}{\getvalue{textext::d}}
\setvalue{textext::nodepth}{\getvalue{textext::n}}
% \definetextext[framed]{\framed}
%
% \startMPcode
% draw \sometxt[framed]{black} rotated 45 ;
% \stopMPcode
% \unexpanded\def\definetextext[#1]#2{\setvalue{@@st@@[#1]}{#2}\setvalue{@@st@@[#1] }{#2}} % we don't grab spaces after [#1]
% \long\def\sometxt #1#{\dosometxt{#1}} % grab optional [args]
% \long\def\dosometxt #1#2{textext.drt("\ifcsname @@st@@#1\endcsname\csname @@st@@#1\endcsname{#2}\else#2\fi")}
% But Mojca wanted more! Two arguments.
%
% \definetextext[framed]{\framed}
%
% \startMPcode
% draw \sometxt{This is for} rotated 45 ;
% draw \sometxt[framed][ss,16pt]{Mojca's};
% draw \sometxt[framed]{eyes only!} rotated -45 ;
% \stopMPcode
% a tex one:
%
% \unexpanded\def\definetextext [#1]#2{\setvalue{@@st@@#1}{#2}}
% \def\sometxt #1#{\dosometxt{#1}}
% \def\dosometxt #1#2{textext.drt("\dodosometxt#1{#2}")}
%
% \unexpanded\def\dodosometxt {\doifnextoptionalelse\dododosometxt\relax}
% \def\dododosometxt [#1]{\dodododosometxt{#1}}
% \def\dodododosometxt #1{\doifnextoptionalelse{\dododododosometxt{#1}}{\getsometxt{#1}}}
% \def\dododododosometxt #1[#2]{\switchtobodyfont[#2]\getsometxt{#1}}
% \def\getsometxt #1#2{\csname @@st@@#1\endcsname{#2}}
%
% or:
%
% \unexpanded\def\dodosometxt {\dodoubleempty\dododosometxt}
% \def\dododosometxt {\ifsecondargument
% \expandafter\dododosometxtA
% \else\iffirstargument
% \expandafter\expandafter\expandafter\dododosometxtB
% \else
% \expandafter\expandafter\expandafter\dododosometxtC
% \fi\fi}
% \def\dododosometxtA[#1][#2]#3{\getsometxt{#1}{\switchtobodyfont[#2]#3}}
% \def\dododosometxtB[#1][#2]#3{\getsometxt{#1}{#3}}
% \def\dododosometxtC[#1][#2]#3{#3}
% \def\getsometxt #1#2{\csname @@st@@#1\endcsname{#2}}
%
% a nicer variant:
\unexpanded\def\definetextext[#1]%
{\def\currenttextext{#1}%
\dosingleempty\dodefinetextext}
\def\dodefinetextext
{\iffirstargument
\expandafter\dodefinetextextone
\else
\expandafter\dodefinetextextzero
\fi}
\def\dodefinetextextone {\setvalue{@@st@@one\currenttextext}}
\def\dodefinetextextzero[#1]{\setvalue{@@st@@zero\currenttextext}}
\def\sometxt#1#%
{\dosometxt{#1}}
\def\dosometxt#1#2% we need to capture embedded quotes (a bit messy as later on textext is filtered
{textext.drt("\dodosometxt#1{\ctxlua{metapost.escaped(\!!bs#2\!!es)}}")}
\unexpanded\def\dodosometxt
{\dosingleempty\dododosometxt}
\def\dododosometxt
{\iffirstargument
\expandafter\dosometxtsome
\else
\expandafter\dosometxtzero
\fi}
\def\dosometxtsome[#1]%
{\def\currenttextext{#1}%
\csname @@st@@%
\ifcsname @@st@@one#1\endcsname one\else
\ifcsname @@st@@zero#1\endcsname zero\else
none\fi\fi
\endcsname}
\def\dosometxtzero[#1]%
{}
\def\@@st@@one {\dosingleempty\do@@st@@one}
\def\do@@st@@one{\csname @@st@@one\currenttextext\endcsname}
\def\@@st@@zero {\csname @@st@@zero\currenttextext\endcsname}
\def\@@st@@none {}
% \definetextext[framed][#1]#2{\framed[width=4cm]{\switchtobodyfont[#1]#2}}
% \definetextext[simple]{\framed[width=8cm]}
%
% \starttext
%
% \startMPcode
% draw \sometxt{This is for} rotated 45 ;
% draw \sometxt [framed] [ss,16pt] {Mojca's};
% draw \sometxt[framed]{eyes only!} rotated -45 ;
% draw \sometxt[simple]{Quotes "indeed" work!} rotated 180 ;
% \stopMPcode
%
% \stoptext
%
% a lua one:
%
% \unexpanded\def\definetextext[#1]#2{\setvalue{@@st@@#1}{#2}}
%
% \long\def\sometxt #1#{\dosometxt{#1}} % grab optional [args]
% \long\def\dosometxt #1#2{\ctxlua{metapost.sometxt(\!!bs#1\!!es,\!!bs#2\!!es)}}
%
% \def\sometxta #1{textext.drt("#1")}
% \def\sometxtb #1#2{textext.drt("\getvalue{@@st@@#1}{#2}")}
% \def\sometxtc #1#2#3{textext.drt("\getvalue{@@st@@#1}{\switchtobodyfont[#2]#3}")}
% Best use the mp macro instead since it provides positioning.
%
% \startuseMPgraphic{testgraphic}
% draw \sometxt{\ruledhbox{\strut hans hagen}} scaled 3;
% % draw textext.drt("\ruledhbox{\strut hans hagen}") scaled 3;
% % draw textext.dlft("\ruledhbox{\strut hans hagen}") scaled 3;
% % draw textext.lft("\ruledhbox{\strut hans hagen}") scaled 3;
% draw llcorner currentpicture -- urcorner currentpicture withcolor yellow;
% draw lrcorner currentpicture -- ulcorner currentpicture withcolor yellow;
% draw boundingbox currentpicture withcolor blue ;
% draw origin withcolor red withpen pencircle scaled 1pt;
% \stopuseMPgraphic
%
% {\showstruts\useMPgraphic{testgraphic}}
\protect \endinput
|