4

I am drawing some setup using Pstricks and pst-optexp.

I want to know what the following example means. Also I can't find a detailed description of how to use \pstVerb and tx@addDict.

\multido{\i=0+1}{60}{%
\pstVerb{%
\i\space 650 400 sub 59 div mul 400 add
tx@addDict begin wavelengthToRGB end }%
\drawbeam[beamangle=\i\space 0.1 mul 3 sub]{2-}%
}%
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Adam Liter Oct 26 '14 at 23:09
3

\pstVerb{...} - The argument is included as verbatim PostScript, not grouped by (g)save and (g)restore. The currentpoint should be TeX's currentpoint.

\i\space - is needed to get the looping variable and a following space

tx@addDict begin ... end - is needed to use the special PostScript dictionary, in this case the one from pstricks-add

You'll find some more examples in the package documentations

2

Admittedly, that is not the best example from a didactical point of view. Here is an alternative version, with some additional explanations. What you are missing in your snippet is the color definition, which is the reason for all that \pstVerb stuff:

\documentclass[pstricks, margin=5pt]{standalone}
\usepackage{pst-optexp}
\begin{document}
\begin{pspicture}(3,3)
  \pnodes(-1,0){A}(1,2.2){B}(3,0){C}
  \optplane(0,2.15)
  \optprism[prismalign=center, prismangle=59](A)(B)(C)
  \optplane(C)
  \definecolor[ps]{bl}{rgb}{%
    tx@addDict begin tx@OptexpDict begin
      Wavelength wavelengthToRGB 
      Red Green Blue 
    end end }%
  \addtopsstyle{Beam}{linecolor=bl, linewidth=0.4\pslinewidth, beamalign=abs}
  \multido{\iLambda=400+4}{60}{%
    \pstVerb{/Wavelength \iLambda\space def }%
    \drawbeam[n=Wavelength Sellmaier]{-}%
  }%
\end{pspicture}
\end{document}

The syntax \definecolor[ps]... allows you to use some values computed at Postscript level for the actual color definition (see the xcolor documentation). In your example, the values Red, Green, and Blue are recalculated in every iteration and their values are used to draw the following beam.

In my changed version it may (or may not) become a bit more apparent: in every iteration I define a new Wavelength which is then both used to calculate a new refractive index and a new color triple for the next beam.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.