zauguin / luapstricks

8 stars 0 forks source link

Support for `\fnode` #14

Closed pablgonz closed 3 years ago

pablgonz commented 3 years ago

I was trying to check compatibility with pst-node and I have encountered the following problem:

% arara: latex
% arara: dvips
% arara: ps2pdf: { options : [ -dALLOWPSTRANSPARENCY -dPDFSETTINGS=/prepress ] }
% arara: clean: { extensions : [ aux, log, dvi, ps ] }
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}
\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}
\pagestyle{empty}
\begin{document}
% from doc
\begin{pspicture}(3,2)
  \fnode{A}
  \fnode*[framesize=1 5pt](2,2){B}
%\ncline[nodesep=3pt]{A}{B}
\end{pspicture}
\end{document}
) [1./luapstricks.lua:1336: linewidth has to be set before it is queried
stack traceback:
    [C]: in function 'assert'
    ./luapstricks.lua:1336: in function <./luapstricks.lua:1335>
    (...tail calls...)
    ./luapstricks.lua:2545: in function <./luapstricks.lua:2543>
    (...tail calls...)
    ./luapstricks.lua:2545: in function <./luapstricks.lua:2543>
    (...tail calls...)
    ./luapstricks.lua:2545: in upvalue 'execute_ps'
    ./luapstricks.lua:2606: in function <./luapstricks.lua:2603>
    [C]: in function 'vf.node'
    ./luapstricks.lua:2596: in function <./luapstricks.lua:2587>.
<argument> ...not:N \tex_shipout:D \box_use:N \l_shipout_box 
                                                  \__shipout_drop_firstpage_...

l.18 \end{document}

? 

The rest of what I have tested works. Complete test file:

% arara: latex
% arara: dvips
% arara: ps2pdf: { options : [ -dALLOWPSTRANSPARENCY -dPDFSETTINGS=/prepress ] }
% arara: clean: { extensions : [ aux, log, dvi, ps ] }
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}
\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\addtolength{\hoffset}{-1.5cm}
% short
\newcommand{\BSS}[1]{\textbf{\textbackslash{#1}}}
\newcommand{\AC}[1]{\{#1\}}
\newcommand{\BS}[1]{$\backslash$#1}
\begin{document}
% Adadted from visualpstricks
\psset{llx=-.5cm,lly=-.5cm,urx=.2cm,ury=.2cm,xAxisLabel={}, yAxisLabel={}}
\psset{fillcolor=yellow,linecolor=blue}
\section{Nodes}

\subsection{Types of nodes}

\subsubsection{With coordinates}

\begin{tabular}{|c|c|c|}
\hline
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \dotnode(.5,0.5){A}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \fnode(.5,0.5){B}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \fnode[framesize=.5 5pt](.5,0.5){B}
\end{psgraph*} \\
\hline
\BSS{dotnode}(.5,0.5)\AC{A} & \BSS{fnode}(.5,0.5)\AC{B} & \BSS{fnode}[\textcolor{red}{framesize}=.5 5pt](.5,0.5)\AC{B} \\
\hline
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \dotnode*(.5,0.5){A}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \fnode*(.5,0.5){B}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \fnode*[framesize=.5 5pt](.5,0.5){B}
\end{psgraph*} \\
\hline
\BSS{dotnode}*(.5,0.5)\AC{A} & \BSS{fnode}*(.5,0.5)\AC{B} & \BSS{fnode}*[\textcolor{red}{framesize}=.5 5pt](.5,0.5)\AC{B} \\
\hline
\end{tabular}

\begin{tabular}{|c|c|c|}
\hline
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \pnode(.5,0.5){A}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \cnode(.5,0.5){.2cm}{A}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \Cnode[radius=.2cm](.5,0.5){A}
\end{psgraph*} \\
\hline
\BSS{pnode}(.5,0.5)\AC{A} & \BSS{cnode}(.5,0.5)\AC{.2cm}\AC{A} & \BSS{Cnode}[radius=.2cm](.5,0.5)\AC{A} \\
\hline
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \cnode*(.5,0.5){.2cm}{A}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \Cnode*[radius=.2cm](.5,0.5){A}
\end{psgraph*}
\\
\hline
%\BSS{pnode}*(.5,0.5)\AC{A}
&
\BSS{cnode}*(.5,0.5)\AC{.2cm}\AC{A} & \BSS{Cnode}*[radius=.2cm](.5,0.5)\AC{A} \\
\hline
\end{tabular}

\bigskip

\begin{tabular}{|c|c|c|}
\hline
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \psnode(.5,0.5){A}{content}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \cnodeput{45}(.5,0.5){M}{content}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \Cnodeput[radius=1cm]{45}(.5,0.5){M}{content}
\end{psgraph*} \\
\hline
\BSS{psnode}(.5,0.5)\AC{A}\AC{content} & \BSS{cnodeput}\AC{45}(.5,0.5) & \BSS{Cnodeput}[radius=1cm] \\
&
\AC{M}\AC{content} & \AC{45}(2,0)\AC{M}\AC{content} \\
\hline

\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \psnode*(.5,0.5){A}{content}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \cnodeput*{45}(.5,0.5){M}{content}
\end{psgraph*}
&
\begin{psgraph*}[axesstyle=none,xticksize= 0 1 ,yticksize=0 1 , subticks=0, dx=.5,Dx=.5, dy=.5,Dy=.5 ](0,0)(0,0)(1,1){2cm}{2cm }
  \Cnodeput*[radius=1cm]{45}(.5,0.5){M}{content}
\end{psgraph*} \\
\hline
\BSS{psnode}*(.5,0.5)\AC{A}\AC{content} & \BSS{cnodeput}*\AC{45}(.5,0.5) & \BSS{Cnodeput}*[radius=1cm] \\
&
\AC{M}\AC{content} & \AC{45}(2,0)\AC{M}\AC{content}\\
\hline
\end{tabular}

\vspace{1cm}

\begin{tabular}{|c|}
\hline
Text \Cnodeput*[radius=1cm]{45}(0,0){M}{content} text \\
\hline\\ \\
Text \BS{Cnodeput}*[radius=1cm]\AC{45}(0,0)\AC{M}\AC{content} text \\
{\red {These nodes do not have dimension} !} \\
\hline
\end{tabular}

\end{document}
zauguin commented 3 years ago

) [1./luapstricks.lua:1336: linewidth has to be set before it is queried

@hvoss49 The issue here is that luapstricks can't easily query the current linewidth if it has been set by other code (e.g. the fonthandline, TikZ, ...), so currently it doesn't allow the currentlinewidth command until it can determine the current linewidth (meaning until setlinewidth has been called for the current graphic state. (Similarly for some other graphic state parameters.) I was hoping that this turns out not to be an issue since pstricks always sets it's current linewidth anyway, but it seems that I was mistaken. What is the behavior which would be the most helpful from pstricks's point of view? The options I see are

  1. The current behavior of breaking and complaining to the user.
  2. Guessing some default value and just reporting it without regard to what might be the actual value.
  3. Like 2., but automatically running a corresponding setlinewidth to ensure that going forward, this value is correct.
hvoss49 commented 3 years ago

) [1./luapstricks.lua:1336: linewidth has to be set before it is queried

  1. The current behavior of breaking and complaining to the user.
  2. Guessing some default value and just reporting it without regard to what might be the actual value.
  3. Like 2., but automatically running a corresponding setlinewidth to ensure that going forward, this value is correct.

I suppose that it doesn't hurt if I did a global setlinewidth at the beginning of any PS code. A first test was ok. Try it with

bash-3.2$ diff -u /usr/local/texlive/texmf-dist/tex/generic/pstricks/pstricks.tex pstricks.tex
--- /usr/local/texlive/texmf-dist/tex/generic/pstricks/pstricks.tex 2021-08-28 00:38:46.000000000 +0200
+++ pstricks.tex    2021-08-28 20:27:19.148764328 +0200
@@ -4399,6 +4399,7 @@
   \ifshowgrid\ifnum\showgridp@s=0\psgrid[style=gridstyle]\fi\fi
 % ----------- 1.10/12 end hv -------------------
   \ignorespaces%           % 2008-12-07
+  \pstVerb{\number\pslinewidth\space setlinewidth}%
   \ifPst@pgffunctions\pstVerb{ pgffunctions }\fi% hv 2013-04-17
 }
 \def\pic@coor{(0,0)(0,0)(10,10)}
zauguin commented 3 years ago

I suppose that it doesn't hurt if I did a global setlinewidth at the beginning of any PS code. A first test was ok. Try it with

bash-3.2$ diff -u /usr/local/texlive/texmf-dist/tex/generic/pstricks/pstricks.tex pstricks.tex
--- /usr/local/texlive/texmf-dist/tex/generic/pstricks/pstricks.tex   2021-08-28 00:38:46.000000000 +0200
+++ pstricks.tex  2021-08-28 20:27:19.148764328 +0200
@@ -4399,6 +4399,7 @@
   \ifshowgrid\ifnum\showgridp@s=0\psgrid[style=gridstyle]\fi\fi
 % ----------- 1.10/12 end hv -------------------
   \ignorespaces%         % 2008-12-07
+  \pstVerb{\number\pslinewidth\space setlinewidth}%
   \ifPst@pgffunctions\pstVerb{ pgffunctions }\fi% hv 2013-04-17
 }
 \def\pic@coor{(0,0)(0,0)(10,10)}

My tests looked good after that change too. (FYI I'll temporarily add patched versions of pstricks.tex and pstricks.pro (for #15) to this repo to simplify testing)

pablgonz commented 3 years ago

@zauguin @hvoss49 Can attach the modified versions of pstricks.tex and pstricks.pro?

zauguin commented 3 years ago

Can attach the modified versions of pstricks.tex and pstricks.pro?

I forgot to push earlier, but now you should see the modified files in the repo.

pablgonz commented 3 years ago

Work with patch version

zauguin commented 3 years ago

bash-3.2$ diff -u /usr/local/texlive/texmf-dist/tex/generic/pstricks/pstricks.tex pstricks.tex --- /usr/local/texlive/texmf-dist/tex/generic/pstricks/pstricks.tex 2021-08-28 00:38:46.000000000 +0200 +++ pstricks.tex 2021-08-28 20:27:19.148764328 +0200 @@ -4399,6 +4399,7 @@ \ifshowgrid\ifnum\showgridp@s=0\psgrid[style=gridstyle]\fi\fi % ----------- 1.10/12 end hv ------------------- \ignorespaces% % 2008-12-07

  • \pstVerb{\number\pslinewidth\space setlinewidth}% \ifPst@pgffunctions\pstVerb{ pgffunctions }\fi% hv 2013-04-17 } \def\pic@coor{(0,0)(0,0)(10,10)}

@hvoss49 I just noticed that this sets the linewidth to very high values. (\pslinewidth is a dimension, so \number\pslinewidth provides the value in scaled points and not normal points. So for \pslinewidth set to 0.8pt (which are 52429sp) this sets the linewidth to more than 18 meter). I don't have any examples where this actually has an influence since mostly the linewidth gets overwritten anyway, but I think it should be fixed nonetheless.

hvoss49 commented 3 years ago
  • \pstVerb{\number\pslinewidth\space setlinewidth}%

@hvoss49 I just noticed that this sets the linewidth to very high values. (\pslinewidth is a dimension, so \number\pslinewidth provides the value in scaled points and not normal points. So for \pslinewidth set to 0.8pt (which are 52429sp) this sets the linewidth to more than 18 meter). I don't have any examples where this actually has an influence since mostly the linewidth gets overwritten anyway, but I think it should be fixed nonetheless.

fixed, should be \pst@number and also added 0 setgray to have a currentcolor