# Is it possible to use ALT 227 (π) as a PostScript constant?

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

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
\begin{document}
\pspicture(\psPiTwo,4)
\pstVerb{/2π {2 Pi mul} def}
\psplot{0}{2π}{2-cos(x/2)}
\endpspicture
\end{document}


# Edit:

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.

• 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
• 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
==
quit


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

GPL Ghostscript 9.21 (2017-03-16)

• 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
• 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