summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/pgf-spectra/pgf-spectra.sty
blob: 937360aed5e5c9d90eab1f65c883086fda4cf6c3 (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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
% Hugo Gomes @ 15/04/2016 (v1.0)
% Hugo Gomes @ 15/03/2021 (v2.0.0)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{pgf-spectra}[15/03/2021 pgf-spectra v2.0.0]%
\RequirePackage{tikz}%
\DeclareOption{LSE}{\input{./spectra.data.LSE.tex}}%
\DeclareOption{NIST}{\input{./spectra.data.NIST.tex}}%
\ExecuteOptions{NIST}%
\ProcessOptions\relax%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{wlIRcolor}{rgb}{.3157,.2373,.2373}% NEW
\definecolor{wlUVcolor}{rgb}{.3,.2568,.3}% NEW
%
\newif\ifwl@absorption%
\newif\ifcur@elem@exist%
\newif\ifwl@drawaxis%
\newif\ifwl@axislabel%
\newif\ifwl@intensity%
\newif\ifwl@redshift% NEW
\newif\ifwl@RSvalue% NEW
% defining PGF keys
\pgfkeys{/wl/.cd,%
element/.get=\wl@element,%
element/.store in=\wl@element,%
element/.default=NONE,%
width/.get=\wl@width,%
width/.store in=\wl@width,%
width/.default={0.9\textwidth},%
height/.get=\wl@height,%
height/.store in=\wl@height,%
height/.default=1cm,%
back/.get=\wl@back,%
back/.store in=\wl@back,%
back/.default=black,%
backIRUV/.get=\wl@backnotvisible,% NEW
backIRUV/.store in=\wl@backnotvisible,% NEW
backIRUV/.default=black,% NEW
IRcolor/.get=\wl@IRcolor,% NEW
IRcolor/.store in=\wl@IRcolor,% NEW
IRcolor/.default=wlIRcolor,% NEW
UVcolor/.get=\wl@UVcolor,% NEW
UVcolor/.store in=\wl@UVcolor,% NEW
UVcolor/.default=wlUVcolor,% NEW
charge/.get=\wl@charge,%
charge/.store in=\wl@charge,%
charge/.default=0,%
Imin/.get=\wl@intmin,%
Imin/.store in=\wl@intmin,%
Imin/.default=0,%
lines/.get=\wl@lines,%
lines/.store in=\wl@lines,%
lines/.default={},%
line width/.get=\wl@linewidth,%
line width/.store in=\wl@linewidth,%
line width/.default=1pt,%
begin/.get=\wl@begin,%
begin/.store in=\wl@begin,%
begin/.default=380,%
end/.get=\wl@end,%
end/.store in=\wl@end,%
end/.default=780,%
axis step/.get=\wl@axisstep,%
axis step/.store in=\wl@axisstep,%
axis step/.default=20,%
axis ticks/.get=\wl@axisticks,% NEW
axis ticks/.store in=\wl@axisticks,% NEW
axis ticks/.default=0,% NEW
axis color/.get=\wl@axiscolor,%
axis color/.store in=\wl@axiscolor,%
axis color/.default=black,%
axis font/.get=\wl@axisfont,%
axis font/.store in=\wl@axisfont,%
axis font/.default={\tiny},%
axis font color/.get=\wl@axisfontcolor,%
axis font color/.store in=\wl@axisfontcolor,%
axis font color/.default=white,%
label position/.get=\wl@labelposition,%
label position/.store in=\wl@labelposition,%
label position/.default={west},%
label before text/.get=\wl@labelbtext,%
label before text/.store in=\wl@labelbtext,%
label before text/.default={},%
label after text/.get=\wl@labelatext,%
label after text/.store in=\wl@labelatext,%
label after text/.default={},%
label font/.get=\wl@labelfont,%
label font/.store in=\wl@labelfont,%
label font/.default={\bfseries\small},%
label font color/.get=\wl@labelfontcolor,%
label font color/.store in=\wl@labelfontcolor,%
label font color/.default=black,%
gamma/.get=\wl@gamma,%
gamma/.store in=\wl@gamma,%
gamma/.default=0.8,%
brightness/.get=\wl@brightness,%
brightness/.store in=\wl@brightness,%
brightness/.default=1,%
line intensity/.get=\wl@lineint,%
line intensity/.store in=\wl@lineint,%
line intensity/.default=100,%
relative intensity threshold/.get=\wl@relintthresh,%
relative intensity threshold/.store in=\wl@relintthresh,%
relative intensity threshold/.default=0.25,%
absorption/.is if=wl@absorption,%
axis/.is if=wl@drawaxis,%
label/.is if=wl@axislabel,%
relative intensity/.is if=wl@intensity,%
redshift/.get=\wl@redshift,% NEW
redshift/.store in=\wl@redshift,% NEW
redshift/.default={},% NEW
show redshift value/.is if=wl@RSvalue% NEW
}%
% setting keys with default values
\pgfkeys{/wl/.cd,element,width,height,back,backIRUV,IRcolor,UVcolor,charge,Imin,lines,line width,begin,end,% NEW -> backIRUV,IRcolor,UVcolor
axis color,axis font,axis font color,axis step,axis ticks,label position,label before text,label after text,label font,label font color,gamma,brightness,line intensity,%
relative intensity threshold,absorption=false,axis=false,label=false,relative intensity=false,redshift,show redshift value=false}% NEW -> redshift, show redshift value
% strings for \ifx tests
\def\wlN@NE{NONE}%
\def\wl@ll{all}%
\def\wl@visible{visible}%
\def\wl@visible@list{visible,visible5,visible10,visible15,visible20,visible25,visible30,visible35,visible40,visible45,visible50,visible55,visible60,visible65,visible70,visible75,visible80,visible85,visible90,visible95,visible100}%
\def\wl@label@position@list{west,north west,north,north east,east,south east,south,south west}%
\def\wl@redshift@D{D}% NEW
%%%% COMMANDS -------------------------------------------------------------------------------->
% commands ##################################################
\newif\ifpgfspectra@StyleIsDef\pgfspectra@StyleIsDeffalse% NEW
% \pgfspectraStyle[options]% NEW
\def\pgfspectraStyle[#1]{\pgfspectraStyleReset\pgfspectra@StyleIsDeftrue\relax\tikzset{/wl/.cd,#1}%
\def\pgfspectra@DoStyle{\tikzset{/wl/.cd,#1}}% applies storing user style for future use
}% NEW
% \pgfspectraStyleReset% NEW
\def\pgfspectraStyleReset{\pgfspectra@StyleIsDeffalse\tikzset{/wl/.cd,%
element=NONE,width=0.9\textwidth,height=1cm,back=black,backIRUV=black,IRcolor=wlIRcolor,UVcolor=wlUVcolor,%
charge=0,Imin=0,lines={},line width=1pt,begin=380,end=780,axis color=black,axis font=\tiny,axis font color=white,axis step=20,axis ticks=0,label position=west,%
label before text={},label after text={},label font=\bfseries\small,label font color=black,gamma=0.8,brightness=1,line intensity=100,%
relative intensity threshold=0.25,absorption=false,axis=false,label=false,relative intensity=false,redshift={},show redshift value=false}}% NEW
% --------------- The main command to draw the spectra -----------------------------------------
% \pgfspectra[options]
\def\pgfspectra{\@ifnextchar[\wl@pgfspectra@withoptions{\wl@pgfspectra@nooptions}}%
\def\wl@pgfspectra@nooptions{\wl@pgfspectra@continuous(0.9\textwidth,1cm)}%
% ##########################################################
\def\wl@pgfspectra@continuous(#1,#2){\ignorespaces%
\begin{tikzpicture}%
\pgfmathparse{#1/400}\edef\xscale{\pgfmathresult}
\pgfmathparse{1.4*\xscale+.09*\linewidth/\wl@width}\edef\wl@linewidth{\pgfmathresult}% NEW {\xscale} -> {1.4*\xscale+.09*\linewidth/\wl@width}
\foreach \x in {380,...,780}%
        {%
        \wlcolor{\x}%
        \pgfmathparse{(\x-380)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
        \draw[wl@temp,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,#2);%
        }%
\end{tikzpicture}%
}%
% ##########################################################
\def\wl@pgfspectra@withoptions[#1]{\ignorespaces%
% setting default values or user style
\ifpgfspectra@StyleIsDef\pgfspectraStyleReset\pgfspectra@DoStyle\pgfspectra@StyleIsDeftrue\relax\else\pgfspectraStyleReset\relax\fi% NEW
% process options (key values)
\pgfkeys{/wl/.cd,#1}%
% axis height
\setbox0=\hbox{\wl@axisfont\selectfont380}\edef\@wl@axis@height{\the\ht0}%
% process visible background (visible+opacity)
\wl@counta=0%
\wl@countb=-1%
\@for\@myarg:=\wl@visible@list\do{%
            \ifx\wl@back\@myarg\wl@countb=\wl@counta\fi%
            \advance\wl@counta by1%
            }%
\ifnum\wl@countb=-1\edef\@visible@opacity{1}\else% NEW
\ifnum\wl@countb=0\let\wl@back\wl@visible\edef\@visible@opacity{.5}\else%
\ifnum\wl@countb>0\let\wl@back\wl@visible\pgfmathparse{.05*\wl@countb}\edef\@visible@opacity{\pgfmathresult}\fi\fi\fi%
%back color: \wl@back\\ debug
% ----------------------------------------------------------------------------------------------------------
% check limits... % NEW
\ifnum\wl@end<10\relax\def\wldez{10}\let\wl@end\wldez\fi%
\ifnum\wl@end>4000\relax\def\wlquatromil{4000}\let\wl@end\wlquatromil\fi%
\ifnum\wl@begin<10\relax\def\wldez{10}\let\wl@begin\wldez\fi%
\ifnum\wl@begin>4000\relax\def\wlquatromil{4000}\let\wl@begin\wlquatromil\fi%
% ----------------------------------------------------------------------------------------------------------
% verifying redshift key
\ifx\wl@redshift\@empty\relax%
\wl@redshiftfalse%
\else%
\wl@processredshiftkey\wl@redshift\relax%
\fi%
% ----------------------------------------------------------------------------------------------------------
% if no element provided draws continuous spectrum with options or user list of lines
\ifx\wl@element\wlN@NE%no element by the user
    \ifx\wl@elt@chemsym\undefined\else\let\wl@elt@chemsym\undefined\fi%
    \ifx\wl@lines\@empty%no lines by the user => continuous spectrum
    % draws the continuous spectrum width options (default or by the user)
    \begin{tikzpicture}%
        \pgfkeys{/wl/.cd,#1}% NEW
        \pgfmathparse{\wl@width/(abs(\wl@end-\wl@begin))}\edef\xscale{\pgfmathresult}%
        \ifwl@drawaxis%draws the axis
        \wl@utils@draw@axis%
        \fi%\ifwl@drawaxis
        \ifwl@axislabel%put the label
        \wl@utils@put@label%
        \fi%\ifwl@axislabel
        \let\wl@back\wl@visible%
        \let\wl@background@UVcolor\wl@backnotvisible\let\wl@background@IRcolor\wl@backnotvisible\relax%
        \wl@utils@drawbackground{\@visible@opacity*\wl@brightness}%
    \end{tikzpicture}%
    \let\wl@list@@\@empty%
    \else% lines by the user
    \edef\wl@list@@{\wl@lines}%
    \let\wl@background@UVcolor\wl@backnotvisible\let\wl@background@IRcolor\wl@backnotvisible\relax%
    \fi%\wl@lines\@empty
\else%\wl@element\wlN@NE
    % else get element(s) data
    \wl@countc=0%
    \wl@countd=1%
    \@for\@myarg:=\wl@element\do{\advance\wl@countc by1}%count number of elements
    \wl@addt@list{}{}%
    \@for\@myarg:=\wl@element\do{%
            \cur@elem@existtrue%
            \def\wl@elt@chemsym{NOT FOUND!}%
            \def\@search@result@err{NOT FOUND!}%
            \wl@elt@data{\@myarg}\relax%
            % check if element provided exists
            \ifx\@search@result@err\wl@elt@chemsym Element\ ``\@myarg'' with charge ``\wl@charge'' not found!\cur@elem@existfalse\else%
            % if exists, set the wavelength's list
            \wl@set@element@list{\wl@elt@elemdata}{\wl@elt@Imax}%
            \fi%\@search@result@err\wl@elt@chemsym
            \ifcur@elem@exist\ifnum\wl@countd<\wl@countc\wl@addt@list{\wl@list@@}{,}\fi\fi%
            \advance\wl@countd by1%
            }%end do
\fi%\wl@element\wlN@NE
% check if there are lines to draw and make the spectrum
    \ifx\wl@list@@\@empty\ifx\wl@element\wlN@NE\else Element\ ``\wl@element'' with charge ``\wl@charge'' have no lines to display.\fi\else%
        \ifwl@absorption%absortion spectrum
        \begin{tikzpicture}%
                \pgfkeys{/wl/.cd,#1}% NEW
                \pgfmathparse{\wl@width/(abs(\wl@end-\wl@begin))}\edef\xscale{\pgfmathresult}%
                \ifwl@drawaxis%draws the axis
                \wl@utils@draw@axis%
                \fi%\ifwl@drawaxis
                \ifwl@axislabel%put the label
                \wl@utils@put@label%
                \fi%\ifwl@axislabel
                \let\wl@back\wl@visible%
                \let\wl@background@UVcolor\wl@UVcolor\let\wl@background@IRcolor\wl@IRcolor\relax%
                \wl@utils@drawbackground{\wl@brightness}%
                % draws the lines
                \wl@utils@drawabsorptionlines%
        \end{tikzpicture}%
        \else%emission spectrum
        % draws the spectrum
        \ifx\wl@back\wl@visible%visible background
        \begin{tikzpicture}%
                \pgfkeys{/wl/.cd,#1}% NEW
                \pgfmathparse{\wl@width/(abs(\wl@end-\wl@begin))}\edef\xscale{\pgfmathresult}%
                \ifwl@drawaxis%draws the axis
                \wl@utils@draw@axis%
                \fi%\ifwl@drawaxis
                \ifwl@axislabel%put the label
                \wl@utils@put@label%
                \fi%\ifwl@axislabel
                \let\wl@background@UVcolor\wl@backnotvisible\let\wl@background@IRcolor\wl@backnotvisible\relax%
                \wl@utils@drawbackground{\@visible@opacity*\wl@brightness}%
                \wl@utils@drawemissionlines% emission lines
        \end{tikzpicture}%
        \else%without visible background
        \begin{tikzpicture}%
                \pgfkeys{/wl/.cd,#1}% NEW
                \pgfmathparse{\wl@width/(abs(\wl@end-\wl@begin))}\edef\xscale{\pgfmathresult}%
                \ifwl@drawaxis%draws the axis
                \wl@utils@draw@axis%
                \fi%\ifwl@drawaxis
                \ifwl@axislabel%put the label
                \wl@utils@put@label%
                \fi%\ifwl@axislabel
                \let\wl@background@UVcolor\wl@backnotvisible\let\wl@background@IRcolor\wl@backnotvisible\relax%
                \wl@utils@drawbackground{0}% dummy argument
                \wl@utils@drawemissionlines% emission lines
        \end{tikzpicture}%
        \fi%\wl@back\@visible
        \fi%\ifwl@absorption
    \fi% \wl@list@@\@empty
}%
% ##########################################################
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% get individual line data from one element of the array data
\def\wl@get@line@info[#1 #2 #3]{%
\def\@currentline@wl{#1}% return
\def\@currentline@int{#2}% return
\def\@currentline@charge{#3}% return
}%
% ######################################################################
% ################### \wl@set@element@list ####################################
% ######################################################################
%
% \wl@set@element@list{\wl@elt@elemdata}{\wl@elt@Imax}
% RETURN: \wl@list@@ -> (wl1,wl2,...)
%           or if relative intensity true (between 0 and 1)
%                \wl@list@@ -> (wl1/int1,wl2/int2,...)
%
\newif\ifwl@first% for first ocurrence of Imin
\def\wl@set@element@list#1#2{\ignorespaces% \wl@elt@Imax
\wl@firsttrue%
\wl@counta=0%
\wl@countb=1%
\pgfmathparse{int(\wl@intmin*100)}\edef\@wl@intmin{\pgfmathresult}%intensity percentage
\ifnum\@wl@intmin=0% include all intensities
\ifx\wl@ll\wl@charge%ALL lines
\@for\@myarg:=#1\do{\advance\wl@counta by1}%count all entries
        \ifwl@intensity%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \pgfmathparse{\wl@relintthresh+(1-\wl@relintthresh)*\@currentline@int/#2}\edef\wl@intensity@to@list{\pgfmathresult}%
        \ifnum\wl@countb<\wl@counta\wl@addt@list{\wl@list@@}{\@currentline@wl/\wl@intensity@to@list,}\else%
        \wl@addt@list{\wl@list@@}{\@currentline@wl/\wl@intensity@to@list}\fi%
        \advance\wl@countb by1%
        }%END do
        \else%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \ifnum\wl@countb<\wl@counta\wl@addt@list{\wl@list@@}{\@currentline@wl,}\else%
        \wl@addt@list{\wl@list@@}{\@currentline@wl}\fi%
        \advance\wl@countb by1%
        }%END do
        \fi%
\else% lines for one specific charge
\@for\@myarg:=#1\do{\expandafter\wl@get@line@info\@myarg\ifx\@currentline@charge\wl@charge\advance\wl@counta by 1\fi}%count only if is the desired charge
        \ifwl@intensity%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \pgfmathparse{\wl@relintthresh+(1-\wl@relintthresh)*\@currentline@int/#2}\edef\wl@intensity@to@list{\pgfmathresult}%
        \ifx\@currentline@charge\wl@charge%add to list if is the desired charge
            \ifnum\wl@countb<\wl@counta\wl@addt@list{\wl@list@@}{\@currentline@wl/\wl@intensity@to@list,}\else%
            \wl@addt@list{\wl@list@@}{\@currentline@wl/\wl@intensity@to@list}\fi%
        \advance\wl@countb by 1%
        \fi%
        }%END do
        \else%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \ifx\@currentline@charge\wl@charge%add to list if is the desired charge
            \ifnum\wl@countb<\wl@counta\wl@addt@list{\wl@list@@}{\@currentline@wl,}\else%
            \wl@addt@list{\wl@list@@}{\@currentline@wl}\fi%
        \advance\wl@countb by 1%
        \fi%
        }%END do
        \fi%
\fi%
\else%\wl@intmin>0 & \wl@intmin<1
\ifnum\@wl@intmin>100\else%
\pgfmathparse{\wl@intmin*#2}\edef\wl@actual@int{\pgfmathresult}%
\ifx\wl@ll\wl@charge%ALL lines
\@for\@myarg:=#1\do{\advance\wl@counta by 1}%count all entries
        \ifwl@intensity%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \pgfmathparse{notless(\@currentline@int,\wl@actual@int)}\relax\edef\wl@int@result{\pgfmathresult}%
        \ifnum\wl@int@result=1%
            \pgfmathparse{\wl@relintthresh+(1-\wl@relintthresh)*\@currentline@int/#2}\edef\wl@intensity@to@list{\pgfmathresult}%
            \ifwl@first\wl@addt@list{\wl@list@@}{\@currentline@wl/\wl@intensity@to@list}\else%
            \wl@addt@list{\wl@list@@}{,\@currentline@wl/\wl@intensity@to@list}\fi%
            \ifwl@first\wl@firstfalse\fi%
        \fi%
        \advance\wl@countb by 1%
        }%END do
        \else%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \pgfmathparse{notless(\@currentline@int,\wl@actual@int)}\relax\edef\wl@int@result{\pgfmathresult}%
        \ifnum\wl@int@result=1%
            \ifwl@first\wl@addt@list{\wl@list@@}{\@currentline@wl}\else%
            \wl@addt@list{\wl@list@@}{,\@currentline@wl}\fi%
            \ifwl@first\wl@firstfalse\fi%
        \fi%
        \advance\wl@countb by 1%
        }%END do
        \fi%
\else% lines for one specific charge
\@for\@myarg:=#1\do{\expandafter\wl@get@line@info\@myarg\ifx\@currentline@charge\wl@charge\advance\wl@counta by 1\fi}%count only if is the desired charge
        \ifwl@intensity%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \ifx\@currentline@charge\wl@charge%add to list if is the desired charge
            \pgfmathparse{notless(\@currentline@int,\wl@actual@int)}\edef\wl@int@result{\pgfmathresult}%
            \ifnum\wl@int@result=1%
            \pgfmathparse{\wl@relintthresh+(1-\wl@relintthresh)*\@currentline@int/#2}\edef\wl@intensity@to@list{\pgfmathresult}%
            \ifwl@first\wl@addt@list{\wl@list@@}{\@currentline@wl/\wl@intensity@to@list}\else%
            \wl@addt@list{\wl@list@@}{,\@currentline@wl/\wl@intensity@to@list}\fi%
            \ifwl@first\wl@firstfalse\fi%
        \fi%
        \advance\wl@countb by 1%
        \fi%
        }%END do
        \else%
        \@for\@myarg:=#1%
        \do{%
        \expandafter\wl@get@line@info\@myarg%
        \ifx\@currentline@charge\wl@charge%add to list if is the desired charge
            \pgfmathparse{notless(\@currentline@int,\wl@actual@int)}\edef\wl@int@result{\pgfmathresult}%
            \ifnum\wl@int@result=1%
            \ifwl@first\wl@addt@list{\wl@list@@}{\@currentline@wl}\else%
            \wl@addt@list{\wl@list@@}{,\@currentline@wl}\fi%
            \ifwl@first\wl@firstfalse\fi%
        \fi%
        \advance\wl@countb by 1%
        \fi%
        }%END do
        \fi%
\fi%
\fi%
\fi%
}%
% add to list
\def\wl@addt@list#1#2{\edef\wl@list@@{#1#2}}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% internal utils
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\wl@utils@draw@axis{\ignorespaces%
                \ifnum\wl@begin>\wl@end%
                % New xshift={-2.5*\@wl@axis@height} to hold bigger numbers, e.g. 2500
                \draw[draw=none,fill=\wl@axiscolor] ([xshift={2.5*\@wl@axis@height}]0,\wl@height+2.5pt) rectangle ([xshift={-2.5*\@wl@axis@height}]-\wl@width,-2.5*\@wl@axis@height);%
                        % minor ticks -> NEW
                        \ifnum\wl@axisticks>0\relax%
                        \pgfmathparse{\wl@end+\wl@axisstep/(\wl@axisticks+1)}\pgfmathparse{int(\pgfmathresult)}
                        \edef\@axis@list{\wl@end,\pgfmathresult,...,\wl@begin}
                        \foreach \x in \@axis@list%
                        {%
                        \pgfmathparse{(\wl@end-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \draw[\wl@axisfontcolor!80!transparent,line width=.25pt] (\wl@currentx,-.375*\@wl@axis@height) -- ++(0,.375*\@wl@axis@height);
                        }%
                        \fi%
                \pgfmathparse{\wl@end+\wl@axisstep}\pgfmathparse{int(\pgfmathresult)}
                \edef\@axis@list{\wl@end,\pgfmathresult,...,\wl@begin}
                \foreach \x in \@axis@list%
                {%
                \pgfmathparse{(\wl@end-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                \draw[\wl@axisfontcolor,line width=.25pt] (\wl@currentx,-.75*\@wl@axis@height) -- ++(0,.75*\@wl@axis@height);
                \node[\wl@axisfontcolor,font=\wl@axisfont,above,inner sep=0pt] at (\wl@currentx,-2.25*\@wl@axis@height) {\x};
                }%
                \else%
                \draw[draw=none,fill=\wl@axiscolor] ([xshift={-2.5*\@wl@axis@height}]0,\wl@height+2.5pt) rectangle ([xshift={2.5*\@wl@axis@height}]\wl@width,-2.5*\@wl@axis@height);%
                        % minor ticks -> NEW
                        \ifnum\wl@axisticks>0\relax%
                        \pgfmathparse{\wl@begin+\wl@axisstep/(\wl@axisticks+1)}\pgfmathparse{int(\pgfmathresult)}
                        \edef\@axis@list{\wl@begin,\pgfmathresult,...,\wl@end}
                        \foreach \x in \@axis@list%
                        {%
                        \pgfmathparse{(\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \draw[\wl@axisfontcolor!80!transparent,line width=.25pt] (\wl@currentx,-.375*\@wl@axis@height) -- ++(0,.375*\@wl@axis@height);
                        }%
                        \fi%
                \pgfmathparse{\wl@begin+\wl@axisstep}\pgfmathparse{int(\pgfmathresult)}
                \edef\@axis@list{\wl@begin,\pgfmathresult,...,\wl@end}
                \foreach \x in \@axis@list%
                {%
                \pgfmathparse{(\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                \draw[\wl@axisfontcolor,line width=.25pt] (\wl@currentx,-.75*\@wl@axis@height) -- ++(0,.75*\@wl@axis@height);
                \node[\wl@axisfontcolor,font=\wl@axisfont,above,inner sep=0pt] at (\wl@currentx,-2.25*\@wl@axis@height) {\x};
                }%
                \fi%
}%
\def\wl@utils@put@label{\ignorespaces%
                \ifx\wl@elt@chemsym\undefined\def\wl@elt@chemsym{}\fi%
                \wl@get@label@position%
                \ifnum\wl@begin>\wl@end%
                        \ifcase\wl@label@position%
                        %west
                            \ifwl@drawaxis%\ifwl@axislabel%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,left,minimum width=2em,align=right] at (-2.5*\@wl@axis@height-\wl@width,0.5*\wl@height-1.25*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,left,minimum width=2em,align=right] at (-\wl@width,0.5*\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%north west
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,above right,inner xsep=0pt] at (-2.5*\@wl@axis@height-\wl@width,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,above right,inner xsep=0pt] at (-\wl@width,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%north
                        \node[\wl@labelfontcolor,font=\wl@labelfont,above] at (-0.5*\wl@width,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                        \or%north east
                        \ifwl@drawaxis%
                        \node[\wl@labelfontcolor,font=\wl@labelfont,above left,inner xsep=0pt] at (2.5*\@wl@axis@height,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                        \else%
                        \node[\wl@labelfontcolor,font=\wl@labelfont,above left,inner xsep=0pt] at (0,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                        \fi
                        \or%east
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,right] at (2.5*\@wl@axis@height,0.5*\wl@height-1.25*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,right] at (0,0.5*\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%south east
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below left,inner xsep=0pt] at (2.5*\@wl@axis@height,-2.5*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below left,inner xsep=0pt] at (0,0) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%south
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below] at (-0.5*\wl@width,-2.5*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below] at (-0.5*\wl@width,0) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%south west
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below right,inner xsep=0pt] at (-2.5*\@wl@axis@height-\wl@width,-2.5*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below right,inner xsep=0pt] at (-\wl@width,0) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \fi%
                \else%
                        \ifcase\wl@label@position%
                        %west
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,left,minimum width=2em,align=right] at (-2.5*\@wl@axis@height,0.5*\wl@height-1.25*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,left,minimum width=2em,align=right] at (0,0.5*\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%north west
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,above right,inner xsep=0pt] at (-2.5*\@wl@axis@height,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,above right,inner xsep=0pt] at (0,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%north
                        \node[\wl@labelfontcolor,font=\wl@labelfont,above] at (0.5*\wl@width,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                        \or%north east
                        \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,above left,inner xsep=0pt] at (\wl@width+2.5*\@wl@axis@height,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,above left,inner xsep=0pt] at (\wl@width,\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%east
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,right] at ([xshift={2.5*\@wl@axis@height}]\wl@width,0.5*\wl@height-1.25*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,right] at (\wl@width,0.5*\wl@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%south east
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below left,inner xsep=0pt] at (\wl@width+2.5*\@wl@axis@height,-2.5*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below left,inner xsep=0pt] at (\wl@width,0) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%south
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below] at (0.5*\wl@width,-2.5*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below] at (0.5*\wl@width,0) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \or%south west
                            \ifwl@drawaxis%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below right,inner xsep=0pt] at (-2.5*\@wl@axis@height,-2.5*\@wl@axis@height) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \else%
                            \node[\wl@labelfontcolor,font=\wl@labelfont,below right,inner xsep=0pt] at (0,0) {\wl@labelbtext\wl@elt@chemsym\wl@labelatext};%
                            \fi%
                        \fi%
                \fi%
}%
\def\wl@utils@drawbackground#1{\ignorespaces% NEW - in this version draws from UV, VIS to IV -> replaces \wl@utils@visiblespectrum#1
% reprocess visible background (only visible) -> needed because of the override in keys
    \wl@counta=0%
    \wl@countb=-1%
    \@for\@myarg:=\wl@visible@list\do{%
            \ifx\wl@back\@myarg\wl@countb=\wl@counta\fi%
            \advance\wl@counta by1%
            }%
        \ifnum\wl@countb>-1\let\wl@back\wl@visible\fi%
                \pgfmathparse{int(#1*100)}\edef\wl@bright{\pgfmathresult}%
                \pgfmathparse{1.4*\xscale+.09*\linewidth/\wl@width}\edef\wl@linewidth{\pgfmathresult}% NEW {\xscale} -> {1.4*\xscale+.09*\linewidth/\wl@width}
                \ifnum\wl@begin>\wl@end% 0
                    \ifnum\wl@end<380\relax% 1
                        \pgfmathparse{(\wl@end-380)*\xscale}\edef\wl@pointA{\pgfmathresult pt}%
                        \ifnum\wl@begin>780\relax% 2
                            \pgfmathparse{(\wl@end-780)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                            \draw[draw=none,fill=\wl@background@UVcolor] (0,0) rectangle (\wl@pointA,\wl@height);%
                            \draw[draw=none,fill=\wl@background@IRcolor] (\wl@pointB,0) rectangle (-\wl@width,\wl@height);%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {780,...,380}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{\wl@pointB+(780-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (\wl@pointA,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \else% 2
                            \pgfmathparse{(\wl@end-\wl@begin)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                            \draw[draw=none,fill=\wl@background@UVcolor] (0,0) rectangle (\wl@pointA,\wl@height);%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {\wl@begin,...,380}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{\wl@pointB+(\wl@begin-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (\wl@pointA,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \fi% 2
                    \else% 1
                        \ifnum\wl@begin>780\relax% 2
                            \pgfmathparse{(\wl@end-780)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                            \draw[draw=none,fill=\wl@background@IRcolor] (\wl@pointB,0) rectangle (-\wl@width,\wl@height);%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {780,...,\wl@end}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{\wl@pointB+(780-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (0,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \else% 2
                            \pgfmathparse{(\wl@end-\wl@begin)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {\wl@begin,...,\wl@end}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{\wl@pointB+(\wl@begin-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (0,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \fi% 2
                    \fi% 1
                \else% 0
                    \ifnum\wl@begin<380\relax% 1
                        \pgfmathparse{(380-\wl@begin)*\xscale}\edef\wl@pointA{\pgfmathresult pt}%
                        \ifnum\wl@end>780\relax% 2
                            \pgfmathparse{(780-\wl@begin)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                            \draw[draw=none,fill=\wl@background@UVcolor] (0,0) rectangle (\wl@pointA,\wl@height);%
                            \draw[draw=none,fill=\wl@background@IRcolor] (\wl@pointB,0) rectangle (\wl@width,\wl@height);%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {380,...,780}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{\wl@pointB-(780-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (\wl@pointA,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \else% 2
                            \pgfmathparse{(\wl@end-\wl@begin)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                            \draw[draw=none,fill=\wl@background@UVcolor] (0,0) rectangle (\wl@pointA,\wl@height);%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {\wl@end,...,380}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{\wl@pointB-(\wl@end-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (\wl@pointA,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \fi% 2
                    \else% 1
                        \ifnum\wl@end>780\relax% 2
                            \pgfmathparse{(780-\wl@begin)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                            \draw[draw=none,fill=\wl@background@IRcolor] (\wl@pointB,0) rectangle (\wl@width,\wl@height);%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {\wl@begin,...,780}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{(\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (0,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \else% 2
                            \pgfmathparse{(\wl@end-\wl@begin)*\xscale}\edef\wl@pointB{\pgfmathresult pt}%
                                \ifx\wl@back\wl@visible% 3 visible background
                                    \foreach \x in {\wl@begin,...,\wl@end}{%
                                    \wlcolor{\x}%
                                    \colorlet{wlcolor}{wl@temp!\wl@bright!black}%
                                    \pgfmathparse{\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                                    \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);}%
                                \else% 3
                                    \draw[draw=none,fill=\wl@back] (0,0) rectangle (\wl@pointB,\wl@height);%
                                \fi% 3
                        \fi% 2
                    \fi% 1
                \fi%0
}%
\def\wl@utils@drawabsorptionlines{\ignorespaces%
                \ifnum\wl@begin>\wl@end%
                    \ifwl@intensity%
                        \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x/\y in \wl@list@@%
                        {%
                        \pgfmathparse{notless(\x,\wl@end)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@begin)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\wl@end-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \pgfmathparse{int(\y*100)}\edef\wl@black{\pgfmathresult}%
                        \wlcolor{\x}%
                        \colorlet{wlcolor}{black!\wl@black!wl@temp}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                    \else%
                        \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x in \wl@list@@%
                        {%
                        \pgfmathparse{notless(\x,\wl@end)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@begin)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\wl@end-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \wlcolor{\x}%
                        \colorlet{wlcolor}{black!\wl@lineint!wl@temp}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                    \fi%
                \else%
                    \ifwl@intensity%
                        \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x/\y in \wl@list@@%
                        {%
                        \pgfmathparse{notless(\x,\wl@begin)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@end)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \pgfmathparse{int(\y*100)}\edef\wl@black{\pgfmathresult}%
                        \wlcolor{\x}%
                        \colorlet{wlcolor}{black!\wl@black!wl@temp}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                    \else%
                        \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x in \wl@list@@%
                        {%
                        \pgfmathparse{notless(\x,\wl@begin)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@end)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \wlcolor{\x}%
                        \colorlet{wlcolor}{black!\wl@lineint!wl@temp}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                    \fi%
                \fi%
\ifwl@RSvalue% NEW
\ifnum\wl@begin>\wl@end%
\ifwl@drawaxis\pgfmathparse{-\wl@width-2.5*\@wl@axis@height}\edef\wl@redshiftinfo@x{\pgfmathresult pt}%
\else\pgfmathparse{-\wl@width}\edef\wl@redshiftinfo@x{\pgfmathresult pt}\fi%
\else%
\ifwl@drawaxis\pgfmathparse{-2.5*\@wl@axis@height}\edef\wl@redshiftinfo@x{\pgfmathresult pt}%
\else\edef\wl@redshiftinfo@x{0pt}\fi%
\fi%
\ifwl@drawaxis\pgfmathparse{-.75*\@wl@axis@height-1.3*\ht0-2pt}\edef\wl@redshiftinfo@y{\pgfmathresult pt}\else\edef\wl@redshiftinfo@y{0pt}\fi%
\node[below right,inner xsep=0pt,font=\wl@axisfont] at (\wl@redshiftinfo@x,\wl@redshiftinfo@y) {\wl@redshiftinfo};%
\fi% NEW
}%
\def\wl@utils@drawemissionlines{\ignorespaces%
                \ifnum\wl@begin>\wl@end%
                \ifwl@intensity%
                    \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x/\y in \wl@list@@%
                        {%
                        \wlcolor{\x}%
                        \pgfmathparse{notless(\x,\wl@end)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@begin)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\wl@end-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \pgfmathparse{int(\y*100)}\edef\wl@black{\pgfmathresult}%
                        \colorlet{wlcolor}{wl@temp!\wl@black!black}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                \else%
                    \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x in \wl@list@@%
                        {%
                        \wlcolor{\x}%
                        \pgfmathparse{notless(\x,\wl@end)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@begin)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\wl@end-\x)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \colorlet{wlcolor}{wl@temp!\wl@lineint!black}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                \fi%
                \else%
                \ifwl@intensity%
                    \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x/\y in \wl@list@@%
                        {%
                        \wlcolor{\x}%
                        \pgfmathparse{notless(\x,\wl@begin)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@end)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \pgfmathparse{int(\y*100)}\edef\wl@black{\pgfmathresult}%
                        \colorlet{wlcolor}{wl@temp!\wl@black!black}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                \else%
                    \ifwl@redshift\wl@utils@redshift\fi% NEW
                        \foreach \x in \wl@list@@%
                        {%
                        \wlcolor{\x}%
                        \pgfmathparse{notless(\x,\wl@begin)}\edef\wl@x@nl{\pgfmathresult}%
                        \pgfmathparse{notgreater(\x,\wl@end)}\edef\wl@x@ng{\pgfmathresult}%
                        \pgfmathparse{and(\wl@x@nl,\wl@x@ng)}\edef\wl@plot@point{\pgfmathresult}%
                        \ifnum\wl@plot@point=1%
                        \pgfmathparse{(\x-\wl@begin)*\xscale}\edef\wl@currentx{\pgfmathresult pt}%
                        \colorlet{wlcolor}{wl@temp!\wl@lineint!black}%
                        \draw[wlcolor,line width=\wl@linewidth] (\wl@currentx,0) -- ++(0,\wl@height);%
                        \fi%
                        }%
                \fi%
                \fi%
\ifwl@RSvalue% NEW
\ifnum\wl@begin>\wl@end%
\ifwl@drawaxis\pgfmathparse{-\wl@width-2.5*\@wl@axis@height}\edef\wl@redshiftinfo@x{\pgfmathresult pt}%
\else\pgfmathparse{-\wl@width}\edef\wl@redshiftinfo@x{\pgfmathresult pt}\fi%
\else%
\ifwl@drawaxis\pgfmathparse{-2.5*\@wl@axis@height}\edef\wl@redshiftinfo@x{\pgfmathresult pt}%
\else\edef\wl@redshiftinfo@x{0pt}\fi%
\fi%
\ifwl@drawaxis\pgfmathparse{-.75*\@wl@axis@height-1.3*\ht0-2pt}\edef\wl@redshiftinfo@y{\pgfmathresult pt}\else\edef\wl@redshiftinfo@y{0pt}\fi%
\node[below right,inner xsep=0pt,font=\wl@axisfont] at (\wl@redshiftinfo@x,\wl@redshiftinfo@y) {\wl@redshiftinfo};%
\fi% NEW
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% return: integer with position (e.g. '0' for west, ... )
\def\wl@get@label@position{\ignorespaces%
\wl@countc=0%
\@for\@mylabel:=\wl@label@position@list%
            \do{%
            \ifx\@mylabel\wl@labelposition\edef\wl@label@position{\the\wl@countc}\fi%
            \advance\wl@countc by1%
            }%
}%
% NEW ----------------------
% redshift: lambda(obs)=lambda(emit)*{(1+v/c*cos(theta))/sqrt(1-v^2/c^2)} ---> Relativistic Doppler
% vbar-> v/c -> normalized velocity of the source (e.g. '0.9' for v=0.9c )
% theta ->angle between the direction of relative motion of the source and the direction of emission in the observer's frame (zero angle is directly away from the observer)
\def\wl@processredshiftkey#1{\ignorespaces%
\wl@redshiftfalse%
\edef\wl@redshiftkey@expand{#1}% to expand a value passed by a macro (not necessary if the user provided a number...)
\expandafter\wl@redshiftkey@firstchar\wl@redshiftkey@expand\relax%
\ifcat1\wl@@RedShift\relax%
\pgfmathparse{1+#1}\relax%
\edef\wl@UMMAISZ{\pgfmathresult}\wl@redshifttrue%
\edef\wl@redshiftinfo{redshift z=#1}%
\else%
\edef\wl@redshiftkey@expand{#1}%
\expandafter\wl@process@redshift\wl@redshiftkey@expand\relax%
\fi%
}%
\def\wl@redshiftkey@firstchar#1#2\relax{\edef\wl@@RedShift{#1}}%
\def\wl@process@redshift#1=#2/#3\relax{%
\edef\wl@redshifttest{#1}%
\ifx\wl@redshifttest\wl@redshift@D\relax%
\pgfmathparse{(1+#2*cos(#3))/sqrt(1-#2*#2)}%
\edef\wl@UMMAISZ{\pgfmathresult}\wl@redshifttrue%
\pgfmathparse{#2*cos(#3))/sqrt(1-#2*#2)}%
\edef\wl@redshiftinfo{Relativistic Doppler redshift z=\pgfmathresult\ (\mbox{v\hskip.1ex=\hskip.1ex#2\hskip.1exc\hskip.5ex;\hskip.5ex\ensuremath{\theta}\hskip.1ex=\hskip.1ex#3\ensuremath{^\circ}})}%
\fi%
}%
% \wl@utils@redshift ---------------------------------------------------------------------
% returns the wllist with the shift computed
\def\wl@utils@redshift{\ignorespaces%
    \let\wt@backlist@@\wl@list@@\relax%
    \let\wl@list@@\@empty\relax%
    \wl@firsttrue\relax%
    \ifwl@intensity% list (lambda/intensity)
        \foreach \x/\y in \wt@backlist@@{%
            \pgfmathparse{\x*\wl@UMMAISZ}\edef\@currentline@wl{\pgfmathresult}%
            \ifwl@first\global\wl@addt@list{\wl@list@@}{\@currentline@wl/\y}\else%
                \global\wl@addt@list{\wl@list@@}{,\@currentline@wl/\y}\fi%
            \ifwl@first\global\wl@firstfalse\fi%
        }%
    \else% list (lambda)
        \foreach \x in \wt@backlist@@{%
            \pgfmathparse{\x*\wl@UMMAISZ}\edef\@currentline@wl{\pgfmathresult}%
            \ifwl@first\global\wl@addt@list{}{\@currentline@wl}\else%
                \global\wl@addt@list{\wl@list@@}{,\@currentline@wl}\fi%
            \ifwl@first\global\wl@firstfalse\fi%
        }%
    \fi%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% nm2rgb convert nanometer wavelength to rgb
% (380 <= Lambda <= 780 ) -> r,g,b on stack
%
% BASED on FORTRAN Code
% RGB VALUES FOR VISIBLE WAVELENGTHS by Dan Bruton (astro@tamu.edu)
% This program can be found at
% http://www.physics.sfasu.edu/astro/color.html
% and was last updated on February 20, 1996.
% The spectrum is generated using approximate RGB values for visible
% wavelengths between 380 nm and 780 nm.
% The red, green and blue values (RGB) are
% assumed to vary linearly with wavelength (for GAMMA=1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newdimen\wl%wavelength
\newdimen\wl@i%intensity
\newdimen\@wl@gamma%gamma
\newdimen\wlc@lorr%red (0. - 1)
\newdimen\wlc@lorg%green (0. - 1)
\newdimen\wlc@lorb%blue (0. - 1) % wavelength to rgb values
\newcount\wl@counta% tmp counter
\newcount\wl@countb% tmp counter
\newcount\wl@countc% tmp counter
\newcount\wl@countd% tmp counter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \wlcolor{wavelength}
\def\wlcolor#1{\ignorespaces%
\wl=#1pt%
\@wl@gamma=\wl@gamma pt%
% compute the rgb components
\ifdim\wl<10pt\relax\PackageWarning{pgf-spectra}{(#1nm) wavelength out of range ignored. The wavelength must be graeter or equal to 10nm (EUV)...}\else% NEW
\ifdim\wl<379.99999pt\relax\else%% NEW
\ifdim\wl<440pt\wlc@lorr=440pt\advance\wlc@lorr by-\wl\divide\wlc@lorr by60\wlc@lorg=0pt\wlc@lorb=1pt\else%
\ifdim\wl<490pt\wlc@lorr=0pt\wlc@lorg=\wl\advance\wlc@lorg by-440pt\divide\wlc@lorg by50\wlc@lorb=1pt\else%
\ifdim\wl<510pt\wlc@lorr=0pt\wlc@lorg=1pt\wlc@lorb=510pt\advance\wlc@lorb by-\wl\divide\wlc@lorb by20\else%
\ifdim\wl<580pt\wlc@lorr=\wl\advance\wlc@lorr by-510pt\divide\wlc@lorr by70\wlc@lorg=1pt\wlc@lorb=0pt\else%
\ifdim\wl<645pt\wlc@lorr=1pt\wlc@lorg=645pt\advance\wlc@lorg by-\wl\divide\wlc@lorg by65\wlc@lorb=0pt\else%
\ifdim\wl<780.00001pt\wlc@lorr=1pt\wlc@lorg=0pt\wlc@lorb=0pt\else%
\ifdim\wl>4000pt\relax\PackageWarning{pgf-spectra}{invalid wavelength (#1nm). The wavelength must be lesser or equal to 4000nm (NIR)...}% NEW
\relax%
\fi\fi\fi\fi\fi\fi\fi\fi\fi%
% intensity correction at vision limits
\ifdim\wl>700pt\ifdim\wl<780.00001pt\wl@i=780pt\advance\wl@i by-\wl\divide\wl@i by80\multiply\wl@i by7\advance\wl@i by3pt\divide\wl@i by10\fi\else%  NEW
\ifdim\wl<420pt\ifdim\wl>379.99999pt\wl@i=\wl\advance\wl@i by-380pt\divide\wl@i by40\multiply\wl@i by7\advance\wl@i by3pt\divide\wl@i by10\fi\else%
\wl@i=1pt%
\fi\fi%
%apply intensity at vision limits correction and  gamma
\ifdim\wl<380pt\colorlet{wl@temp}{\wl@UVcolor}\else\ifdim\wl>780pt\colorlet{wl@temp}{\wl@IRcolor}\else% NEW
\pgfmathparse{\wlc@lorr*\wl@i^\@wl@gamma}\edef\wl@red{\pgfmathresult}%
\pgfmathparse{\wlc@lorg*\wl@i^\@wl@gamma}\edef\wl@green{\pgfmathresult}%
\pgfmathparse{\wlc@lorb*\wl@i^\@wl@gamma}\edef\wl@blue{\pgfmathresult}%
\definecolor{wl@temp}{rgb}{\wl@red,\wl@green,\wl@blue}%
\fi\fi% NEW
\colorlet{wlcolor}{wl@temp}
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\wl@elt@search#1#2#3#4{\ignorespaces%
% #1 Chemical Symbol, entered by USER
% #2 Chemical Symbol to compare to, e.g. Na
% #3 Emission Lines Data (or error message)
% #4 Imax
\edef\wl@CS@user{#1}\edef\wl@CS@comp{#2}\relax% New
\ifx\wl@CS@user\wl@CS@comp\relax% New -> was \iftthenelse{...
\def\wl@elt@chemsym{#2}%  set chemical symbol
\def\wl@elt@elemdata{#3}%  set element lines data
\def\wl@elt@Imax{#4}%  set element Imax
\fi%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput