7

Assume I have defined a constant \valueA as

\def\valueA{25 2 sqrt sqrt mul }

I would like to devide this value by the square root of 2, so I tried

\pstFPdiv\valueB{\valueA}{2 sqrt}

but this is not valid notation. What is the correct way to define the constant \valueB as \valueA/sqrt(2)?

2 Answers 2

7

The defined constants can be used in both TeX world and PS world.

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

\usepackage[nomessages]{fp}
% #1: (optional) the number of digits after decimal point, the default is 6 
% #2: (mandatory) the name of variable to create
% #3: (mandatory) mathematics expression in infix form
\newcommand\const[3][6]{%
    \edef\temporary{round(#3}%
    \expandafter\FPeval\csname#2\expandafter\endcsname
        \expandafter{\temporary:#1)}%
        \pstVerb{/#2 \csname#2\endcsname\space def}%
}

\const{valueA}{3*root(root(2,2),2)}
\const{valueB}{valueA/root(2,2)}


\begin{document}
\begin{pspicture}[showgrid](10,10)
    \rput(!valueA valueB){(\valueA,\valueB)}
\end{pspicture}
\end{document}

enter image description here

2
  • @DavidCarlisle: My answer here had actually been invented, reviewed, and improved by you and egreg several decades ago (in my own questions). Accepting this answer implies accepting yours and egreg's as well. :-) Commented Sep 15, 2013 at 10:19
  • @PGFTricks I thought I recognised that code:-) Commented Sep 15, 2013 at 10:21
4
\valueA  2 sqrt div

would work once passed to the PS interpreter, so if I understand correctly you just want

\edef\valueB{\valueA  2 sqrt div }
3
  • Okay. This (with \def instead of \edef) was actually what I did at first; I just assumed that \pstFPdiv was somehow 'better' to use inside a pspicture environment. Thank you, David. Commented Sep 15, 2013 at 9:59
  • @SvendTveskæg I knew pstricks well (and last looked at the manual) around 1990, I can still make it do stuff, but don't rely on me to know the best way these days:-) Commented Sep 15, 2013 at 10:06
  • 1
    Well, I know you are a TeXpert; your suggestions are normally the best way to do TeX stuff. :) Commented Sep 15, 2013 at 10:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .