# Why is my beam no propagating beyond the second mirror?

\documentclass[]{revtex4}
\usepackage{pst-optexp}
\usepackage{pst-node}

\begin{document}

\begin{pspicture}[showgrid=true](13,14)
\pnodes(2,10){A}(3,10){MIP}(3,12.5){LIP}(3,13){MIIP}(5,13){LIIP}
\pnodes(8,13){MIIIP}(8,8){MIVP}(14,8){LIIIP}(10,8){LIVP}(12,8){MVP}(12,3){d}
\pnodes(12,1){MVIP}(10,1){LVIP}(6,1){C}

\psset{mirrortype=extended, mirrordepth=0.2}

\begin{optexp}
\optsource[innerlabel, compname = start](A)(MIP){Beam}
\mirror[compname = mi, labelangle=45](A)(MIP)(LIP){$M_1$}
\lens[compname = li, n=1.57](MIP)(LIP){$L_1$}

\mirror[compname= mii, labelangle=-45](LIP)(MIIP)(LIIP){$M_{2}$}

\lens[compname= lii, n=1.517](MIIP)(LIIP){$L_{2}$}

\mirror[compname= miii, labelangle=-45](LIIP)(MIIIP)(MIVP){$M_{3}$}
\mirror[compname= miv, labelangle=45](MIIIP)(MIVP)(LIIIP){$M_{4}$}

\lens[compname= liii, n=1.517](MIVP)(LIIIP){$L_{3}$}

\mirror[compname= mv, labelangle=-45](MIVP)(MVP)(d){$M_{5}$}
\mirror[compname= mvi, labelangle=-45](d)(MVIP)(LVIP){$M_{6}$}

\lens[compname= lensfour, n=1.517](MVIP)(LVIP){$L_{4}$}
\optsource[innerlabel](C)(C){Comp.}
\end{optexp}
\drawwidebeam[beamwidth=0.4, beaminsidelast]{1-5}
\end{pspicture}

\end{document}

• Do you also get an error Error: /stackunderflow in --if-- ... ? – user121799 Feb 14 '18 at 5:27
• I do not get that output. – Enrique Segura Feb 14 '18 at 16:47
• Which compiler do you use? (I get the error when using xelatex to compile your code.) – user121799 Feb 14 '18 at 16:50
• that's the one I am using; I am a beginner though, so if there's a fix that doesn't require me to use xelatex, I am all ears! – Enrique Segura Feb 14 '18 at 16:58
• Just to clarify: in my case, the compilation does not stop, I just get the error message when compiling with xelatex. I do not get an error when compiling with latex, and then converting to ps and then to pdf, but the rest of the beam does not show either. I have experience in this package whatsoever, but just from looking at your setup I could imagine that playing with the distances and/or overall scale may help. – user121799 Feb 14 '18 at 17:22

pst-optexp offers you different debugging possibilities:

• Using \psset{pswarning} you can enable warnings at Postscript level. For your example you get "Warning pst-optexp: The upper beam missed an interface"
• By default pst-optexp respects the numerical aperture of the components. If one of the outer beams does not hit the next interface, the beam drawing stops. With \psset{useNA=false} you can disable this temporarily to see which beam goes wrong. For your setup the result is

You see, that the M3-mirror is too small (or the beam to wide) so the beam path is interrupted.

Possible solution

To tailor the beam to your needs, you can either fine-tune the refractive index n of all lenses, or you can draw the beam piecewise for the parallel and focusing parts, separately.

The recipe is as follows:

1. Draw the first parallel part with \drawwidebeam[beamwidth=0.4, stopinside]{1-3}, which traces the beam until the second interface of the first lens (draws only until the first interface.
2. Now draw the beam between the first and second lens with \drawwidebeam[loadbeampoints, beamdiv=-20, stopinside]{3-5}. This loads the end points of the previous \drawwidebeam call, but allows you to adjust the beam divergence.
3. From the second lens continue with \drawwidebeam[loadbeampoints] to again load the previous beam end points, but continue with parallel rays.

And so on.

\documentclass[pstricks,margin=12pt]{standalone}
\usepackage{pst-optexp}

\begin{document}
\begin{pspicture}[showgrid=true](13,14)
\pnodes(2,10){A}(3,10){MIP}(3,12.5){LIP}(3,13){MIIP}(5,13){LIIP}
\pnodes(8,13){MIIIP}(8,8){MIVP}(14,8){LIIIP}(10,8){LIVP}(12,8){MVP}(12,3){d}
\pnodes(12,1){MVIP}(10,1){LVIP}(6,1){C}

\psset{mirrortype=extended, mirrordepth=0.2}
\psset{mirrorwidth=1.1}
\begin{optexp}
\optsource[innerlabel, compname = start](A)(MIP){Beam}
\mirror[compname = mi, labelangle=45](A)(MIP)(LIP){$M_1$}
\lens[compname = li](MIP)(LIP){$L_1$}
\drawwidebeam[beamwidth=0.4, stopinside]{1-3}

\mirror[compname= mii, labelangle=-45](LIP)(MIIP)(LIIP){$M_{2}$}
\lens[compname= lii](MIIP)(LIIP){$L_{2}$}

\mirror[compname= miii, labelangle=-45](LIIP)(MIIIP)(MIVP){$M_{3}$}
\mirror[compname= miv, labelangle=45](MIIIP)(MIVP)(LIIIP){$M_{4}$}

\lens[compname= liii](MIVP)(LIIIP){$L_{3}$}

\mirror[compname= mv, labelangle=-45](MIVP)(MVP)(d){$M_{5}$}
\mirror[compname= mvi, labelangle=-45](d)(MVIP)(LVIP){$M_{6}$}
\lens[compname= lensfour](MVIP)(LVIP){$L_{4}$}

BTW: Compiling pst-optexp-setups with xelatex doesn't work properly.
• That image is done only by adding \psset{useNA=false}, without any adjustments, yet. But this mode allows you to better see what goes wrong. – Christoph Feb 14 '18 at 21:34