Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to shrink and expand the canvas based on the 2 variables \Base and \Angle. The following code still use a hard-coded value for the ordinate of pspicture, which is equal to 6, for example.

I want to avoid using such a hard-coded value. I want to replace it by something that equals to Angle tan Base mul. Is there any idea to do so?

\documentclass[border=12pt]{standalone}

\usepackage{pstricks-add}

\def\Base{3}
\def\Angle{60}

\pstVerb
{
    /Base \Base\space def
    /Angle \Angle\space def
}

\begin{document}
\begin{pspicture}[showgrid=top](\Base,6)
    \pspolygon[fillcolor=yellow,fillstyle=solid](!Base 0)(!0 Angle tan Base mul)
\end{pspicture}
\end{document}

enter image description here

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

Here is a quick hack:

\documentclass[border=12pt]{standalone}
\usepackage{pstricks-add}
\usepackage{fp}

\def\newconst#1#2{%
    \expandafter\FPeval\csname#1\endcsname{#2}%
    \pstVerb{/#1 \csname#1\endcsname\space def}%
}


% User defined constants
\newconst{Base}{4}
\newconst{Angle}{30}
\newconst{Height}{Base*tan(Angle*pi/180)}


\begin{document}

\begin{pspicture}[showgrid=top](\Base,\Height)
    \pspolygon(!Base 0)(!0 Height)
\end{pspicture}

\end{document}
share|improve this answer
    
see my edit, I used fp, but it is also possible without the fp package –  Herbert Jul 11 '12 at 17:14
    
that was only for testing, makes it easier to see if everthing works well –  Herbert Jul 11 '12 at 18:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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