summaryrefslogtreecommitdiff
path: root/tex/context/base/x-fig-00.tex
blob: 8f6899c49581b3650dda244f7b2be840fff33b0b (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
%D \module
%D   [      file=x-fig-00,
%D        version=2001.03.21,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Figure Base Loading,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
%C details. 

%D This module implements an interface to a figure database
%D and file. The database is formatted in \XML\ conforming 
%D the following \DTD: 
%D
%D \typefile{x-fig-00.dtd}
%D
%D A figure base coded this way looks like: 
%D 
%D \starttypen
%D <!-- texexec --pdf --use=fig-01 figtest.xml --> 
%D 
%D <figurelibrary language="nl"> 
%D 
%D   <description>
%D     <organization>PRAGMA Advanced Document Engineering</organization>
%D     <project>Manuals</project>
%D     <product>Beginners Manual</product>
%D     <comment>A bunch of figures.</comment>
%D   </description>
%D 
%D   <figure>
%D     <file>koe.pdf</file>
%D     <label>a dutch cow</label>
%D     <copyright>Corel Draw Suite</copyright>
%D     <comment>I bet that you've seen this cow before.</comment>
%D   </figure>
%D 
%D </figurelibrary> 
%D \stoptypen 
%D 
%D You can convert this base into a \PDF\ file using 
%D \TEXEXEC\ and another module in this suite. 
%D 
%D \starttypen 
%D texexec --pdf --use=fig-01 yourfile.xml
%D \stoptypen 
%D 
%D You can now select a graphic from this file using the 
%D 
%D \starttypen 
%D \externalfigure[a dutch cow][width=4cm]
%D \stoptypen 
%D
%D This module overloads this command so that it first 
%D searched in the list of databases. 
%D 
%D \starttypen 
%D \usefigurebases[yourfile]
%D \stoptypen 
%D 
%D The special keyword \type {reset} can be used to reset 
%D this list.

\startcommands      dutch                            english
                    german                           czech
                    italian                          romanian

     usefigurebase: gebruikfiguurbestand             usefigurebase 
                    usefigurebase                    usefigurebase 
                    usefigurebase                    usefigurebase 

\stopcommands 

\unprotect 

\startXMLnamespace [-] [figbase]

\defineXMLprocess     [figurelibrary]
\defineXMLignore      [description]
\defineXMLignore      [copyright]
\defineXMLignore      [comment]
\defineXMLignore      [status]
\defineXMLpush        [file]
\defineXMLpush        [label]
\defineXMLenvironment [figure] \figbase@StartFigure \figbase@StopFigure

\stopXMLnamespace

\def\figbase@StartFigure%
  {\bgroup}

\def\figbase@StopFigure%
  {\doglobal\increment\figurefilepage
   \doif{\askedlabel}{\XMLpop{label}}
     {\xdef\figurefilename{\XMLpop{file}}\endinput}%
   \egroup}

\def\getfigurefilename#1#2%
  {\startnointerference
     \startXMLnamespace[-][figbase]
       \resetfigurefilebase
       \XMLassign{file} {}
       \XMLassign{label}{}
       \xdef\figurefilebase{#1}%
       \doglobal\newcounter\figurefilepage
       \def\askedlabel{#2}
       \processXMLfile{#1.xml}
     \stopXMLnamespace
   \stopnointerference}

\def\resetfigurefilebase%
  {\global\let\figurefilebase\empty
   \global\let\figurefilename\empty
   \global\let\figurefilepage\empty}

\let\normalcalculateexternalfigure\calculateexternalfigure

\def\calculateexternalfigure[#1][#2][#3][#4][#5][#6]%
  {\resetfigurefilebase
   \ifx\figurebaselist\empty 
     \normalcalculateexternalfigure
       [#1][#2][#3][#4][#5][#6]%
   \else
     \def\docommando##1%
       {\getfigurefilename{##1}{#3}%
        \ifx\figurefilename\empty\else\quitcommalist\fi}%
     \processcommacommand[\figurebaselist]\docommando
     \ifx\figurefilename\empty
       \stripspaces\from#3\to\figurefilename % to be sure 
       \normalcalculateexternalfigure
         [#1][#2][\figurefilename][#4][#5][#6]%
     \else
        \normalcalculateexternalfigure
          [#1][#2][\figurefilebase.pdf][\c!pagina=\figurefilepage,#4][#5][#6]%
     \fi
   \fi}

\let\figurebaselist\empty

\def\usefigurebase[#1]%
  {\doifelse{#1}{\v!reset}
     {\let\figurebaselist\empty}
     {\appendcommacommand{#1}\figurebaselist}}

\endinput 

\usefigurebase[figtest]

\externalfigure[koetje]             [width=3cm]
\externalfigure[de molen op de dijk][width=3cm]
\externalfigure[de molen op de dijk][width=2cm]
\externalfigure[weet ik veel]       [width=3cm]
\externalfigure[weet ik veel]       [width=2cm]
\externalfigure[weet ik wat]        [width=2cm]
\externalfigure[koe]                [width=2cm]