summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/meta-tex.mkiv
blob: 03ad5ee398c31e9f3b1122f0a7c01d1dfec548e4 (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
%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 ADE \& \CONTEXT\ Development Team}]
%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}{}

\unprotect

% Ok, we support this in MkIV because Mojca kept the pressure on. It
% looks a bit like a hack. But in fact this method is obsolete and
% eventually might go away.

\installcorenamespace{graphictextext}
\installcorenamespace{graphictexdepth}
\installcorenamespace{graphictexarguments}

\unexpanded\def\startTeXtexts#1\stopTeXtexts
  {#1}

\let\stopTeXtexts\relax

\unexpanded\def\TeXtext
  {\dosingleempty\meta_textext}

\def\meta_textext[#1]#2#3% contrary to mkii we don't process yet but we do expand
  {\setxvalue{\??graphictextext#2}{\meta_textext_indeed{#1}{#3}}}

\unexpanded\def\meta_textext_indeed#1#2%
  {\begingroup
   \setbox\nextbox\hbox{#2}%
   \ifcsname\??graphictexdepth#1\endcsname
     \lastnamedcs
   \else
     \syst_boxes_lower_nextbox_dp
   \fi
   \box\nextbox
   \endgroup}

\def\getTeXtext#1%
  {\begincsname\??graphictextext#1\endcsname}

\letvalue{\??graphictexdepth         d}\syst_boxes_lower_nextbox_dp
\letvalue{\??graphictexdepth  \s!depth}\syst_boxes_lower_nextbox_dp
\letvalue{\??graphictexdepth         n}\donothing
\letvalue{\??graphictexdepth\s!nodepth}\donothing

% \definetextext[framed]{\framed}
%
% \startMPcode
%     draw \sometxt[framed]{black} rotated 45 ;
% \stopMPcode
%
% But Mojca wanted more! Two arguments.
%
% \definetextext[framed]{\framed}
%
% \startMPcode
%     draw \sometxt{This is for} rotated 45 ;
%     draw \sometxt[framed][foregroundstyle=bold]{Mojca's};
%     draw \sometxt[framed]{eyes only!} rotated -45 ;
% \stopMPcode

\unexpanded\def\definetextext[#1]%
  {\def\currenttextext{#1}%
   \doifelsenextoptionalcs\meta_textext_define_one\meta_textext_define_zero}

\def\meta_textext_define_one {\setvalue{\??graphictexarguments1:\currenttextext}}
\def\meta_textext_define_zero{\setvalue{\??graphictexarguments0:\currenttextext}}

\def\sometxt#1#{\meta_some_txt{#1}}

\def\meta_some_txt#1#2% we need to capture embedded quotes (a bit messy as later on textext is filtered
  {textext.drt("\mpsometxt#1{\clf_metapostescaped{#2}}")}

\unexpanded\def\mpsometxt % no _ catcode
  {\doifelsenextoptionalcs\meta_some_txt_indeed_yes\meta_some_txt_indeed_nop}

\def\meta_some_txt_indeed_yes[#1]%
  {\def\currenttextext{#1}%
   \csname\??graphictexarguments
     \ifcsname\??graphictexarguments0:#1\endcsname0\else
     \ifcsname\??graphictexarguments1:#1\endcsname1\else
                                       ?\fi\fi
   \endcsname}

\def\meta_some_txt_indeed_nop
  {}

\setvalue{\??graphictexarguments ?}{}
\setvalue{\??graphictexarguments 0}{\csname\??graphictexarguments\currenttextext\endcsname}
\setvalue{\??graphictexarguments 1}{\dosingleempty\meta_gx_one}

\def\meta_gx_one{\csname\??graphictexarguments1:\currenttextext\endcsname}

% \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}}
%
%       \def\sometxt         #1#{\dosometxt{#1}}  % grab optional [args]
%       \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}}

\unexpanded\def\MPexponent   #1#2{\mathematics{#1\times10^{#2}}}
\unexpanded\def\MPformatted  #1#2{\clf_metapostformatted{#1}{#2}}
\unexpanded\def\MPgraphformat#1#2{\clf_metapostgraphformat{#1}{#2}}

%D Some new fun (but exprimental for a while):

\unexpanded\def\MPLIBoutlinetext#1#2#3% index kind text
  {\begingroup
   \setbox\scratchbox\hbox{#3}%
   \clf_MPLIBconvertoutlinetext\numexpr#1\relax{#2}\scratchbox
   \endgroup}

\protect \endinput