zauguin / luapstricks

8 stars 0 forks source link

Support for `pst-tools` package #28

Closed pablgonz closed 3 years ago

pablgonz commented 3 years ago

The pst-tools package is loaded by the pst-plot package (one of the "Big Four" along with pstricks, pstricks-add and pst-node) and several others, at the moment it is partially supported.

\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{uncompress} % only for the test examples, can later be empty
\documentclass[parskip=half-,DIV=13]{scrartcl}
\usepackage{pstricks}
\usepackage{pst-plot}
\usepackage{pst-tools}
\pagestyle{empty}
\begin{document}
% OK
\begin{pspicture}(6,3)
\psgrid[style=mmpaper](6,3)
\end{pspicture}
\begin{pspicture}(6,3)
\psgrid[style=mmpaper,
gridcolor=blue,subgridcolor=blue!80](6,3)
\end{pspicture}

% OK
\psRegisterList{Color}{yellow,blue,green,red}% defines macro \Color
\begin{pspicture}(-7,-4.5)(7,5.5)
\psaxes{->}(0,0)(-6.5,-4.5)(6.75,5)
\psset{plotpoints=400,algebraic,linewidth=1pt,fillstyle=solid,opacity=0.4}
\multido{\iA=1+1}{4}{%
\psplot[linecolor=\Color{\iA},
fillcolor=\Color{\iA}!60]{-6.283}{6.283}{\iA*sin(\iA*x)}}%
\psset{plotpoints=400,algebraic}
\psforeach{\iA}{1,2,3,4}{%
\psplot[linecolor=\Color{\iA}]{-6.28}{6.28}{\iA*sin(\iA*x)}}
\end{pspicture}

% Error
\begin{center}
\psset{fontscale=12}
\makebox[2em]{x(deg)} \makebox[5em]{$\sin x$} \makebox[4em]{$\cos x$}\hspace{1em}
\makebox[5em]{$\sqrt x$}\makebox[7em]{$\sin x+\cos x$}\makebox[6em]{$\sin^2 x+\cos^2 x$}\\[3pt]
\multido{\iA=0+10}{18}{
  \makebox[1em]{\iA}
  \makebox[5em]{\psPrintValue[PSfont=NimbusRomNo9L-Regu,xShift=-10]{\iA\space sin}}
  \makebox[4em][r]{\psPrintValue[PSfont=NimbusMonL-Regu,fontscale=10,decimals=3,xShift=-20]{\iA\space cos}}\hspace{1em}
  \makebox[5em]{\psPrintValue[valuewidth=15,linecolor=blue,PSfont=NimbusSanL-Regu]{\iA\space sqrt}}
  \makebox[7em]{\psPrintValue[comma,PSfont=NimbusRomNo9L-ReguItal]{\iA\space dup sin exch cos add}}
  \makebox[6em]{\psPrintValue[PSfont=Palatino-Roman]{\iA\space dup sin dup mul exch cos dup mul add}}\\}
\end{center}

\begin{center}
\psset{fontscale=12}
\makebox[2em]{x(deg)} \makebox[5em]{$\sin x$} \makebox[4em]{$\cos x$}\hspace{1em}
\makebox[5em]{$\sqrt x$}\makebox[7em]{$\sin x+\cos x$}\makebox[6em]{$\sin^2 x+\cos^2 x$}\\[3pt]
\multido{\iA=0+10}{18}{
  \makebox[1em]{\iA}
  \makebox[5em]{\psPrintValue[PSfont=NimbusRomNo9L-Regu,xShift=-10]{\iA\space sin}}
  \makebox[4em][r]{\psPrintValue[PSfont=NimbusMonL-Regu,fontscale=10,decimals=3,xShift=-20]{\iA\space cos}}\hspace{1em}
  \makebox[5em]{\psPrintValue[valuewidth=15,linecolor=blue,PSfont=NimbusSanL-Regu]{\iA\space sqrt}}
  \makebox[7em]{\psPrintValue[comma,PSfont=NimbusRomNo9L-ReguItal]{\iA\space dup sin exch cos add}}
  \makebox[6em]{\psPrintValue[PSfont=Palatino-Roman]{\iA\space dup sin dup mul exch cos dup mul add}}\\}
\end{center}
\end{document}
) [1{c:/texlive/2021/texmf-var/fonts/map/pdftex/updmap/pdftex.map}./luapstricks
.lua:1211: rangecheck
stack traceback:
        [C]: in function 'error'
        ./luapstricks.lua:1211: in function <./luapstricks.lua:1182>
        (...tail calls...)
        ./luapstricks.lua:2842: in upvalue 'execute_ps'
        ./luapstricks.lua:2903: in function <./luapstricks.lua:2900>
        [C]: in function 'vf.node'
        ./luapstricks.lua:2893: in function <./luapstricks.lua:2884>.
<inserted text> BAD

Expected output:

test-pst-tools-crop-1 test-pst-tools-crop-2

NOTE: Font problem solved in https://github.com/zauguin/luapstricks/commit/f63f471d87950224f64eb4dfc7a3dbb67a98b0aa

hvoss49 commented 3 years ago

The example works fine with PS where we have only six decimals by default! But Lua has some more, so you need to modify valuewidth which is preset to 10 which is too less here. Or you have to limit the number of decimals. I'll have a closer look tomorrow. However, see test1111 on https://hvoss.org/PSTexa/

zauguin commented 3 years ago

The example works fine with PS where we have only six decimals by default! But Lua has some more, so you need to modify valuewidth which is preset to 10 which is too less here. Or you have to limit the number of decimals. I'll have a closer look tomorrow. However, see test1111 on https://hvoss.org/PSTexa/

I changed the number formatting to only use 6 significant digits for now. Feel free to revert that if you come up with a better solution.

pablgonz commented 3 years ago

@zauguin On win10

 [1{c:/texlive/2021/texmf-var/fonts/map/pdftex/updmap/pdftex.map}./luapstricks
.lua:1249: rangecheck
stack traceback:
        [C]: in function 'error'
        ./luapstricks.lua:1249: in function <./luapstricks.lua:1217>
        (...tail calls...)
        ./luapstricks.lua:2926: in upvalue 'execute_ps'
        ./luapstricks.lua:2987: in function <./luapstricks.lua:2984>
        [C]: in function 'vf.node'
        ./luapstricks.lua:2977: in function <./luapstricks.lua:2968>.
<inserted text> BAD

l.47 \end{center}

?

Font name problem?

(dvips>ps2pdf OK)

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
EFRDCM+NimbusRomNo9L-ReguItal        Type 1C           WinAnsi          yes yes yes     25  0
LRNOLL+NimbusSanL-Regu               Type 1C           WinAnsi          yes yes yes     23  0
NMRYAS+Palatino-Roman                Type 1C           WinAnsi          yes yes yes     27  0
RHFXTB+CMR8                          Type 1C           WinAnsi          yes yes no      17  0
PQRSOF+CMMI10                        Type 1C           WinAnsi          yes yes no      15  0
QMCRNC+NimbusRomNo9L-Regu            Type 1C           WinAnsi          yes yes yes     19  0
UFIGRG+CMSY10                        Type 1C           Custom           yes yes no      11  0
IXTCRV+CMR10                         Type 1C           WinAnsi          yes yes yes      9  0
TDRURT+NimbusMonL-Regu               Type 1C           WinAnsi          yes yes yes     21  0
zauguin commented 3 years ago

@zauguin On win10

 [1{c:/texlive/2021/texmf-var/fonts/map/pdftex/updmap/pdftex.map}./luapstricks
.lua:1249: rangecheck
stack traceback:
        [C]: in function 'error'
        ./luapstricks.lua:1249: in function <./luapstricks.lua:1217>
        (...tail calls...)
        ./luapstricks.lua:2926: in upvalue 'execute_ps'
        ./luapstricks.lua:2987: in function <./luapstricks.lua:2984>
        [C]: in function 'vf.node'
        ./luapstricks.lua:2977: in function <./luapstricks.lua:2968>.
<inserted text> BAD

l.47 \end{center}

?

Font name problem? (dvips>ps2pdf OK)

No, it's still a number formatting problem, here caused by slight rounding in cos messing things up. Basically calculating cos(90) in Lua involves converting 90 degrees in radians and then calculating the cosine in radians. Normally this isn't an issue, but 90 degree in radians is pi/2 which has to be rounded in order to be stored as a floating point value. Then the cosine of this rounded value is calculated which is roughly 6.12323*10^{-17} formatted as 6.12323e-17.(This is the same way GhostScript would format this value, so that isn't the issue) This again has more than 10 digits. (The fun of working with floating point values...) I guess values like 90 degree have to be special cased to give more precise answers.

pablgonz commented 3 years ago

No, it's still a number formatting problem, here caused by slight rounding in cos messing things up. Basically calculating cos(90) in Lua involves converting 90 degrees in radians and then calculating the cosine in radians. Normally this isn't an issue, but 90 degree in radians is pi/2 which has to be rounded in order to be stored as a floating point value. Then the cosine of this rounded value is calculated which is roughly 6.12323*10^{-17} formatted as 6.12323e-17.(This is the same way GhostScript would format this value, so that isn't the issue) This again has more than 10 digits. (The fun of working with floating point values...) I guess values like 90 degree have to be special cased to give more precise answers.

More fun :D

zauguin commented 3 years ago

Should be better now.

pablgonz commented 3 years ago

Done!