# Is it possible to construct spectral lines with TeX?

I would like to demonstrate shifts in spectral line diagrams. I was wondering whether TeX was able to produce spectral line plots. I am aware of its functionality regarding energy level diagrams for which it is very useful. Thanks in advance.

-
Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Could you provide a link to the type of thing you're trying to produce? – cmhughes Oct 1 '13 at 17:43
Short: Yes. Long: Yes but I don't know how to do it. – Svend Tveskæg Oct 1 '13 at 18:22
If you could explain to us (me) what “spectral line diagrams“ are and how they look and how you want to input certain data, we (I) could help you better. – Qrrbrbirlbel Oct 1 '13 at 18:24
I mean spectral lines as on a graph of Intensity versus frequency, say. I cannot attach an image using this facility to make my point illustratively. – stars83clouds Oct 1 '13 at 20:22

Although, you already solved your problem. Here is a relatively easy solution using pgfplots:

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[width=8cm, height=5cm,
xlabel=$\lambda$ (nm), ylabel=Intensity (a. u.),
ytick = \empty,
xmin = 300, xmax=700, ymin = 0
]
(({364.6*t^2/(t^2-4)}, {1/t});
\end{axis}
\end{tikzpicture}
\end{document}


The values are calculated here and the intensity calculation is just a wild guest, but you can of course also plot data points instead.

-
This is great help but how do you install pgfplots with Tikz? – stars83clouds Oct 1 '13 at 23:56
Afaik pgfplots is part of texlive and MikTeX, and certainly of MacTex as well. So you should already have it installed, except you have a very old version of those distributions. Then an update might be a solution. – quinmars Oct 2 '13 at 0:08
I'm on Linux using Kile...i've used MikTeX before but my current system only has a Kile interface, which i know is only the frontend. – stars83clouds Oct 2 '13 at 0:11
Kile is only the editor. So can you compile the above example? If not your Tex distribution is too old. For a long time ubuntu only had packages for texlive 2009, which would be too old. You might want check which texlive version your Linux distribution has. – quinmars Oct 2 '13 at 13:03

With PSTricks just for fun!

\documentclass[pstricks,border=12pt]{standalone}

%Mluque5130@aol.com
%Juin 2 000
\makeatletter
\def\psYoungR{\pst@object{psYoungR}}
\def\psYoungR@i{\@ifnextchar({\psYoungR@do}{\psYoungR@do(0,0)}}
\def\psYoungR@do(#1)#2#3#4#5{%
\begin@ClosedObj
\pst@@getcoor{#1}%
\pst@coor
translate
/bornexpt  400 def
bornexpt neg 1 bornexpt{
/abscissept exch def
% x en m
/abscisse abscissept 2845 div def
/DistanceEcran #3 def
/EcartFentes #2 def
/largeurFentes #4 def
/lambdaR #5 def
/argumentDeg abscisse 180 mul largeurFentes mul DistanceEcran div def
/argumentRad argumentDeg 180 div Pi mul def
/sinCR argumentRad 0 eq {1} {argumentDeg lambdaR div sin argumentRad div lambdaR mul} ifelse def
180 EcartFentes mul abscisse mul lambdaR div DistanceEcran div cos dup mul
sinCR dup  mul mul
0
0
setrgbcolor 2 setlinewidth
abscissept -40  moveto abscissept 40 lineto stroke}
for }%
\end@ClosedObj\ignorespaces%
}
\def\psYoungRVB{\pst@object{psYoungRVB}}
\def\psYoungRVB@i{\@ifnextchar({\psYoungRVB@do}{\psYoungRVB@do(0,0)}}
\def\psYoungRVB@do(#1)#2#3#4{
\begin@ClosedObj
\pst@@getcoor{#1}%
\pst@coor
translate
/bornexpt  400 def
bornexpt neg 1 bornexpt{
/abscissept exch def
% x en m
/abscisse abscissept 2845 div def
/lambdaB 436e-9 def
/lambdaV 546e-9 def
/lambdaR 700e-9 def
/DistanceEcran #3 def
/EcartFentes #2 def
/largeurFentes #4 def
/argumentDeg abscisse 180 mul largeurFentes mul DistanceEcran div def
/argumentRad argumentDeg 180 div Pi mul def
/sinCR argumentRad 0 eq {1} {argumentDeg lambdaR div sin argumentRad div lambdaR mul}
ifelse def
/sinCV argumentRad 0 eq {1} {argumentDeg lambdaV div sin argumentRad div lambdaV mul}
ifelse def
/sinCB argumentRad 0 eq {1} {argumentDeg lambdaB div sin argumentRad div lambdaB mul}
ifelse def
180 EcartFentes mul abscisse mul lambdaR div DistanceEcran div cos dup mul
sinCR dup  mul mul
180 EcartFentes mul abscisse mul lambdaV div DistanceEcran div cos dup mul
sinCV dup  mul mul
180 EcartFentes mul abscisse mul lambdaB div DistanceEcran div cos dup mul
sinCB dup  mul mul
setrgbcolor 2 setlinewidth
abscissept -40  moveto abscissept 40 lineto stroke}
for}
\end@ClosedObj
}
\pagestyle{empty}
\makeatother
\begin{document}

\begin{pspicture*}(-8.5,-1.5)(8.5,1.5)
\psYoungRVB(0,0){50e-6}{2}{10e-6}
\end{pspicture*}
\end{document}

-