2

Feeding latex with

\documentclass{article}
\pagestyle{empty}
\usepackage{pstricks}
\begin{document}
{1:
\begin{pspicture}(-.1,-1)(.1,5)
  \psline(0,0)(0,5)
\end{pspicture}}
{$10^{-4}$: \psset{yunit=.0001}%
\begin{pspicture}(-.1,-10000)(.1,50000)
  \psline(0,0)(0,50000)
\end{pspicture}}
{$10^{-5}$: \psset{yunit=.00001}%
\begin{pspicture}(-.1,-100000)(.1,500000)
  \psline(0,0)(0,500000)
\end{pspicture}}
{$10^{-6}$: \psset{yunit=.000001}%
\begin{pspicture}(-.1,-1000000)(.1,5000000)
  \psline(0,0)(0,5000000)
\end{pspicture}}
\end{document}

then applying dvips to the resulting DVI file and opening the resulting Postscript file in gv should show, in my understanding, four vertical 5-cm-long line segments whose lowest point is 1 cm above the baseline. However, we get three line segments only, and they vary both in length and in the lowest point:

output of latex-dvips-gv

Is LaTeX with PSTricks really so imprecise, or is there a bug (e.g., a silent overflow/underflow) hiding anywhere? The log and console don't warn us.

8
  • 1
    tex uses fixed point arithmetic for lengths (that is integer arithmetic with scaled points) so you have about 5dp at most \dimen0=0.00001pt \showthe\dimen0 shows 0.2pt and \dimen0=0.000001pt \showthe\dimen0 shows 0pt Commented Apr 28 at 9:27
  • @DavidCarlisle What is “dp”? Decimal point? Why have you written pt? I thought that the default unit of measure in pstricks is cm. Further, can pstricks be instructed to calculate more precisely (say, delegate the calculations to Postscript or to a floating-point library)?
    – AlMa1r
    Commented Apr 28 at 10:18
  • 1
    "dp" meant decimal places there, sorry. for pstricks calculations are a mixture of tex and postscript arithmetic but at some point everything has to be a tex length to make sizes of boxes. whether you enter a length using cm or pt it is always stored as an integer multiple of sp (scaled points) and tex will always show the value in pt. I haven't traced exactly what is happening in your example but it's not at all surprising. you are using values that are small enough that you only have rounding error and no actual data value. Commented Apr 28 at 10:23
  • @DavidCarlisle I see. As the MWE above doesn't store numerical values in \dimen𝑛, my hope is that (for such a mature package as pstricks) the intermediate calculations to determine the box height (if everything is computed in scaling points, then, e.g., 0.00001 cm ⋅ 500000 ⋅ (7227/254 ⋅ 65536 sp/cm) or a mathematically associative and commutative rearranging thereof) could be given to someone else.
    – AlMa1r
    Commented Apr 28 at 10:40
  • 2
    you are specifying the overall size of the box \begin{pspicture}(-.1,-100000)(.1,500000) by dangerously scaled tex calculations before postscript is used at all. Commented Apr 28 at 10:55

2 Answers 2

4

TeX uses fixed point arithmetic and \psset{yunit=.000001}% gets saved as an internal dimen register, \psyunit=0.000001cm which is equivalent to setting it to 0pt. The end result is that the final pspicture has height 0pt (and the heights of all of them are essentially arbitrary just depending on rounding error)

\tracingall\psset{yunit=.0001}\tracingnone

shows

\psyunit=\dimen166
...
{into \dimen166=0.00304pt}

so yunit is already at the limit of reasonable tex values, your final setting

\tracingall\psset{yunit=.000001}\tracingnone

shows

{into \dimen166=0.0pt}

so the yunit is set to 0pt.

3
  • @AlMa1r try for yourself: $ tex '\dimen0=0.000001cm\showthe\dimen0' This is TeX, Version 3.141592653 (TeX Live 2024) (preloaded format=tex) > 0.0pt. <*> \dimen0=0.000001cm\showthe\dimen0 Commented Apr 28 at 18:01
  • that is you are right that the value is interpreted as cm not pt but it makes no difference as it's 0 anyway. (I didn't check but it probably always stores first as pt then multiplies by a factor to get the right unit, but if that first assignment is 0 then the unit makes no difference @AlMa1r Commented Apr 28 at 18:03
  • 1
    @AlMa1r I edited to say 0.000001cm is 0 (rather than 0.000001pt as originally) Commented Apr 28 at 18:31
2

Do all calculations on PS-Level and let the TeX box (pspicture) in the TeX-friendly unit:

\DocumentMetadata{}
\documentclass{article}
\pagestyle{empty}
\usepackage{pstricks}
\def\myLine(#1,#2)(#3,#4){%
  \psline(#1,#2)(!#3 #4 yunit mul)}

\begin{document}
{1:
    \begin{pspicture}(-.1,-1)(.1,5)
        \psline(0,0)(0,5)
\end{pspicture}}
{$10^{-4}$: \pstVerb{/yunit 0.0001 def}%
    \begin{pspicture}(-.1,-1)(.1,5)
        \myLine(0,0)(0,50000)
\end{pspicture}}
{$10^{-5}$: \pstVerb{/yunit 0.00001 def}%
    \begin{pspicture}(-.1,-1)(.1,5)
        \myLine(0,0)(0,500000)
\end{pspicture}}
{$10^{-6}$: \pstVerb{/yunit 0.000001 def}%
    \begin{pspicture}(-.1,-1)(.1,5)
        \myLine(0,0)(0,5000000)
\end{pspicture}}
\end{document}

enter image description here

You must log in to answer this question.

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