summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pst-spectra/pst-spectra.tex
blob: 8bc83a9540ed032b7c7d4f24e9b140ba579063d3 (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
%% BEGIN pst-spectra.tex
%%
%% This extension try to deals with wavelength in optics.
%% Beginning with spectra
%%
%% COPYRIGHT 2005,2006 by Arnaud Schmittbuhl
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%%
\csname PSTwlLoaded\endcsname
\let\PSTwlLoaded\endinput
%
\def\pstwlfileversion{0.91}
\def\pstwlfiledate{2006/01/01}
\message{`pst-spectra'  v\pstwlfileversion, \pstwlfiledate\space (AS)}
%
% Requires pstricks, multido, pst-xkey
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTXKeyLoaded\endinput\else\input pst-xkey \fi
\ifx\MultidoLoaded\endinput\else\input multido.tex\fi
%
%
\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11\relax
%
%%% Stolen code from LaTeX file: latex.ltx (coming from ltcntrl.dtx)
\def\@nnil{\@nil}
\def\@empty{}
\def\@fornoop#1\@@#2#3{}
\long\def\@for#1:=#2\do#3{%
  \expandafter\def\expandafter\@fortmp\expandafter{#2}%
  \ifx\@fortmp\@empty \else
    \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}\fi}
\long\def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
      #5\def#4{#2}\ifx #4\@nnil \else#5\@iforloop #3\@@#4{#5}\fi\fi}
\long\def\@iforloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
      \expandafter\@fornoop \else
      #4\relax\expandafter\@iforloop\fi#2\@@#3{#4}}
%
%
%% Prologue for postscript
\pstheader{pst-spectra.pro}
%
\SpecialCoor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% display a continuum spectrum or lines?
%% default is spectrum
\newif\ifpst@psspectrum@spectrum \pst@psspectrum@spectrumtrue
\newif\ifpst@psspectrum@lines    \pst@psspectrum@linesfalse
\newif\ifpst@psspectrum@element  \pst@psspectrum@elementfalse
\newif\ifpst@psspectrum@emission
\newif\ifpst@psspectrum@axe
\pst@addfams{pst-wl}
\define@key[psset]{pst-wl}{begin}{\pst@checknum{#1}\psk@psspectrum@begin}
\define@key[psset]{pst-wl}{end}{\pst@checknum{#1}\psk@psspectrum@end}
\define@key[psset]{pst-wl}{axe}[true]{\@nameuse{pst@psspectrum@axe#1}}
\define@key[psset]{pst-wl}{wlangle}{\pst@checknum{#1}\psk@psspectrum@wlangle}
\define@key[psset]{pst-wl}{axecolor}{\edef\psk@psspectrum@axecolor{#1}}
%% wlcmd must be \def, not \edef
\define@key[psset]{pst-wl}{wlcmd}{\def\psk@psspectrum@wlcmd{#1}}
\define@key[psset]{pst-wl}{axewidth}{\pst@getlength{#1}\psk@psspectrum@axewidth}
\define@key[psset]{pst-wl}{Dl}{\pst@checknum{#1}\psk@psspectrum@Dl}
\define@key[psset]{pst-wl}{brightness}{\pst@checknum{#1}\psk@psspectrum@brightness}
\define@key[psset]{pst-wl}{gamma}{\pst@checknum{#1}\psk@psspectrum@gamma}
\define@key[psset]{pst-wl}{Imin}{\pst@checknum{#1}\psk@psspectrum@UserImin}
\define@key[psset]{pst-wl}{element}{\pst@psspectrum@elementtrue\edef\psk@psspectrum@element{#1}}
\define@key[psset]{pst-wl}{lines}{\pst@psspectrum@linestrue\edef\psk@psspectrum@lines{#1}}
\define@key[psset]{pst-wl}{emission}[true]{\@nameuse{pst@psspectrum@emission#1}}
\def\@temp@wl@ii{true}%
\define@key[psset]{pst-wl}{absorption}[true]%
 {\def\@temp@wl@i{#1}%
   \ifx\@temp@wl@i\@temp@wl@ii\@nameuse{pst@psspectrum@emissionfalse}%
   \else\@nameuse{pst@psspectrum@emissiontrue}%
   \fi}
\define@key[psset]{pst-wl}{lwidth}{\pst@getlength{#1}\psk@psspectrum@lwidth}
\define@key[psset]{pst-wl}{numlines}{\pst@getint{#1}\psk@psspectrum@numlines}
%\define@key[psset]{pst-wl}{showlines}{\edef\psk@psspectrum@showlines{#1}}
%\define@key[psset]{pst-wl}{redshift}{\pst@checknum{#1}\psk@psspectrum@redshift}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% default values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\psset{begin=380, end=780, numlines=250, brightness=1, gamma=0.8, lwidth=0.02
 ,emission=true
 ,axe=false, Dl=20, wlangle=0, axecolor=black, axewidth=0.05
 ,wlcmd={\small\sffamily\bfseries}
 ,Imin=0}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Scan the name of the element to know if it is a neutral element or a cation
% and to get the number of charge
% output : \element@name and \element@charge
\def\analyse@elt#1{%
  \def\analyse@elt@arg{#1}%
  \ifx\analyse@elt@arg\empty%
  \else\analyse@elt@b#1\empty\empty\empty\analyse@elt@e%
  \fi}
\def\analyse@elt@b#1#2#3#4\analyse@elt@e{%
 \gdef\element@name{}%
 \gdef\element@charge{}%
 \ifx#4\empty%
  \ifx#3\empty%
   \ifx#2\empty%
     % One letter element
     \gdef\element@name{#1}%
     \gdef\element@charge{-2}%
   \else%
    \ifx0#2%
      % Neutral one letter element
      \gdef\element@name{#1}%
      \gdef\element@charge{0}%
    \else\ifx+#2%
           % One letter single ionized element
           \gdef\element@name{#1}%
           \gdef\element@charge{1}%
         \else \ifcat#2z%
                 % Two letters element
                 \gdef\element@name{#1#2}%
                 \gdef\element@charge{-2}%
               \else % Problem
                 \@pstrickserr{Bad element or cation name: #1#2}\@ehpa
               \fi%
         \fi%
    \fi%
   \fi%
  \else%
   \ifx0#3%
     % Neutral two letters element
     \gdef\element@name{#1#2}%
     \gdef\element@charge{0}%
   \else\ifx+#3\ifcat#2z%
                  % Two letter single ionized element
                  \gdef\element@name{#1#2}%
                  \gdef\element@charge{1}%
                \else%
                  % One letter multiple ionized element
                  \gdef\element@name{#1}%
                  \gdef\element@charge{#2}%
                \fi%
        \else% Problem
          \@pstrickserr{Bad element or cation name: #1#2#3}\@ehpa
        \fi%
   \fi%
  \fi%
 \else%
 \ifx+#4%
%\ifcat1#3% <-- does not always work as expected
           % Multiple ionized two letters element
           \gdef\element@name{#1#2}%
           \gdef\element@charge{#3}%
%          \else% Problem
%          \fi%
  \else% Problem
    \@pstrickserr{Bad element or cation name: #1#2#3#4}\@ehpa
  \fi%
 \fi%
\ignorespaces}

\newdimen\pstwl@DeltaX
\newdimen\pstwl@DeltaL
\def\pst@wl@getint#1.#2\endpst@wl@getint{\def\psk@wl@int{#1}}

%% \psspectrum
\def\psspectrum{\def\pst@par{}\pst@object{psspectrum}}
\def\psspectrum@i{%
  \@ifnextchar({\psspectrum@ii}{\psspectrum@iii(0,0)(12,1.5)}}
\def\psspectrum@ii(#1){%
  \@ifnextchar({\psspectrum@iii(#1)}{\psspectrum@iii(0,0)(#1)}}
\def\psspectrum@iii(#1,#2)(#3,#4){{%
  \begin@SpecialObj
    \use@par%           Really needed ?
    \pssetxlength\pst@dima{#1}
    \pssetylength\pst@dimb{#2}
    \pssetxlength\pst@dimc{#3}
    \pssetylength\pst@dimd{#4}
    \pst@getcoor{#1,#2}\pst@tempa%            coordinate in pst@tempa
    \pst@@getcoor{#3,#4}%                      coordinate in pst@coor
    %% emission spectrum
    \ifpst@psspectrum@emission%                      emission is true
    %% ...with lines
      \ifpst@psspectrum@lines%                     drawing user lines
        \pst@psspectrum@spectrumfalse\pst@psspectrum@linesfalse
        \@for\lines@loop:=\psk@psspectrum@lines\do{%
         \addto@pscode{[[\lines@loop\space 0 -2]] 1
                        \psk@psspectrum@UserImin -2
                         \psk@psspectrum@lwidth
                          \pst@tempa \pst@coor
                           \psk@psspectrum@gamma \psk@psspectrum@brightness
                            \psk@psspectrum@end \psk@psspectrum@begin
                             tx@PstWLDict begin tx@rays end}%
        }%
      \fi
    %% ...with element
      \ifpst@psspectrum@element%            drawing lines of elements
        \pst@psspectrum@spectrumfalse\pst@psspectrum@elementfalse
         \@for\element@loop:=\psk@psspectrum@element\do{%
          \expandafter\analyse@elt\expandafter{\element@loop}
            \addto@pscode{tx@PstWLDict begin wl@elt@\element@name\space end
                           \psk@psspectrum@UserImin \element@charge\space
                            \psk@psspectrum@lwidth
                             \pst@tempa \pst@coor
                              \psk@psspectrum@gamma \psk@psspectrum@brightness
                               \psk@psspectrum@end \psk@psspectrum@begin
                                tx@PstWLDict begin tx@rays end}%
         }%
      \fi
      \ifpst@psspectrum@spectrum% drawing a spectrum
        \addto@pscode{\pst@tempa \pst@coor \psk@psspectrum@gamma
                       \psk@psspectrum@brightness \psk@psspectrum@numlines
                         \psk@psspectrum@end \psk@psspectrum@begin
                          tx@PstWLDict begin tx@psspectrum end}%
      \fi
    %% absorption spectrum
    \else% emission is false, then draw a spectrum and set brightness to 0
      \addto@pscode{\pst@tempa \pst@coor \psk@psspectrum@gamma
                     \psk@psspectrum@brightness \psk@psspectrum@numlines
                      \psk@psspectrum@end \psk@psspectrum@begin
                       tx@PstWLDict begin tx@psspectrum end}%
      \pst@checknum{0}\psk@psspectrum@brightness%
      \ifpst@psspectrum@lines% absorption lines
        \pst@psspectrum@linesfalse
        \@for\lines@loop:=\psk@psspectrum@lines\do{%
          \addto@pscode{[[\lines@loop\space 0 -2]] 1
                         \psk@psspectrum@UserImin -2
                          \psk@psspectrum@lwidth
                           \pst@tempa \pst@coor
                            \psk@psspectrum@gamma \psk@psspectrum@brightness
                             \psk@psspectrum@end \psk@psspectrum@begin
                              tx@PstWLDict begin tx@rays end}%
         }%
      \fi
      \ifpst@psspectrum@element% absorption element
        \pst@psspectrum@elementfalse
         \@for\element@loop:=\psk@psspectrum@element\do{%
          \expandafter\analyse@elt\expandafter{\element@loop}
            \addto@pscode{tx@PstWLDict begin wl@elt@\element@name\space end
                           \psk@psspectrum@UserImin \element@charge\space
                            \psk@psspectrum@lwidth
                             \pst@tempa \pst@coor
                              \psk@psspectrum@gamma \psk@psspectrum@brightness
                               \psk@psspectrum@end \psk@psspectrum@begin
                                tx@PstWLDict begin tx@rays end}%
         }%
      \fi
    \fi
    \ifpst@psspectrum@axe
      %% Calcul the number of ticks
      %% (LambdaEnd - LambdaBegin) / DL
      \pst@dimg=\z@
      \advance\pst@dimg by  \psk@psspectrum@end\p@
      \advance\pst@dimg by -\psk@psspectrum@begin\p@
      \ifnum\pst@dimg>0
        \advance\pst@dimg by \psk@psspectrum@Dl\p@
      \else
        \advance\pst@dimg by -\psk@psspectrum@Dl\p@
      \fi
      \pst@divide{\pst@dimg}{\psk@psspectrum@Dl\p@}\real@numofticks
      %% integer number of ticks is stored in \psk@wl@int
      \expandafter\pst@wl@getint\real@numofticks\endpst@wl@getint
      %% Calcul the difference between the wavelengths
      \pstwl@DeltaL=\z@
      \advance\pstwl@DeltaL by  \psk@psspectrum@end\p@
      \advance\pstwl@DeltaL by -\psk@psspectrum@begin\p@
      %% Calcul the difference between the x-coordinate
      \pstwl@DeltaX=\z@
      \advance\pstwl@DeltaX by  \pst@dimc% in pt
      \advance\pstwl@DeltaX by -\pst@dima% in pt
      %% Calcul dx
      \pst@divide{\pstwl@DeltaX}{\the\psxunit}\pst@tempa
      \pst@divide{\pstwl@DeltaL}{\pst@tempa\p@}\pst@tempb
      \pst@divide{\psk@psspectrum@Dl\p@}{\pst@tempb\p@}\dx%
      \ifdim\pst@dimd>\pst@dimb
        \def\pst@wl@angle{-90}%
        \def\pst@wl@signe{-1\space}%
      \else
        \def\pst@wl@angle{90}%
        \def\pst@wl@signe{1\space}%
      \fi
      \pst@divide{\psk@psspectrum@axewidth\p@}{28.4526\p@}\pst@tempa
      \psline[linewidth=\pst@tempa,linecolor=\psk@psspectrum@axecolor,arrows=c-c]
             (\pst@dima,\pst@dimb)(\pst@dimc,\pst@dimb)
      \edef\pst@tempb{\pst@number\pst@dima}%
      \pst@divide{\pst@tempb\p@}{\the\psxunit}\pst@tempa
      \multido{\nL=\psk@psspectrum@begin+\psk@psspectrum@Dl,\rx=\pst@tempa+\dx}
        {\psk@wl@int}%
        {\psline[linecolor=\psk@psspectrum@axecolor]
                (!\rx\space                                    % rx in cm
                 \pst@number\pst@dimb \pst@number\psyunit div) % in pt !
                (!\rx\space
                 \pst@number\pst@dimb \pst@number\psyunit div
                 0.2 \pst@wl@signe mul add)
         \uput{0.3}[\pst@wl@angle]
              (!\rx\space
               \pst@number\pst@dimb \pst@number\psyunit div
               0.1 \pst@wl@signe mul add)
              {\rput{\psk@psspectrum@wlangle}{\psk@psspectrum@wlcmd\nL}}}%
    \fi
    \pst@psspectrum@spectrumtrue
  \end@SpecialObj
}}%

\catcode`\@=\PstAtCode\relax
\endinput
%% END pst-spectra.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%