Is it possible to use π as a PS constant in my attempt below?

\pstVerb{/2π {2 Pi mul} def}


I input the π by pressing and holding the ALT key and press 2, 2 and 7 on the numeric pad. My OS is Microsoft Windows. See this document.

  • 3
    For those who are wondering, 227 is the codepoint for lower-case pi in code page 437. – Henning Makholm Jan 15 '18 at 20:32
  • 3
    Someone with edit privs should edit the title, since this is not ASCII. – R.. Jan 15 '18 at 20:42
  • I assumed from the context that the OP meant character 960 (U+03C0) which is what is actually posted above as π not Unicode 227 which is ã – David Carlisle Jan 15 '18 at 21:11

As far as I can see (postscript manual page 45 names have to be characters and characters have to be "printable ascii" and there are no ascii characters above 127. As noted in comments elsewhere the manual clarifies that the restriction to ASCII (that is characters below 128) is only a recommendation.

A quick test with ghostscript shows that /Pi {3.14} def /2π {2 Pi mul} def 2π is a syntax error but /Pi {3.14} def /zz {2 Pi mul} def zz works (leaves 6.28 on the stack)

In the above I assumed that π was encoded as in the question on this site in UTF-8 and used the same encoding in my test file. Unicode π is U+03C0 (character 960) not 227.

To test character 227 I saved the test file in latin-1 encoding and used ã then it does work in ghostscript.

If you save

/Pi {3.14} def /2ã {2 Pi mul} def 2ã

/Pi {3.14} def /zz {2 Pi mul} def zz

as latin1 (iso-8859-1) not UTF-8 and execute with gs then teh terminal shows

GPL Ghostscript 9.21 (2017-03-16)
Copyright (C) 2017 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.

showing both expressions evaluated 2pi.

  • The manual doesn't really rule it out. Page 27 says: "All characters besides the white-space characters and delimiters are referred to as regular characters. These include nonprinting characters that are outside the recommended PostScript ASCII character set." – alexis Jan 15 '18 at 20:51
  • @alexis I was trying to find a definitive statement about non ascii terms, which is one reason I originally just posted as a comment not an answer. In any case the suggested expression doesn't work in ghostscript so I doubt the Op wants to use it. thanks for the correction though. – David Carlisle Jan 15 '18 at 21:07
  • Indeed, the interpreter is always the final authority on these things! My reading of the PostScript book is that it should be possible, since <227> counts as a "regular character" and "Any token that consists entirely of regular characters and cannot be interpreted as a number is treated as a name object (more precisely, an executable name)." That's cold comfort to the OP, I'm sure. – alexis Jan 15 '18 at 21:14
  • @alexis updated answer better? – David Carlisle Jan 15 '18 at 21:25
  • With all due respect, I'm not too sure! :-) The new part of your answer shows that byte 227 can be used in this way in ghostscript input. This directly contradicts the first part of the answer, so I think that part really needs an edit. More importantly, how do you make it work with pstricks, as in the OP's example? I tried adding \usepackage[latin1]{inputenc}, but it was not enough. – alexis Jan 15 '18 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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