1. begin

Pushes a dictionary onto the dictionary stack, making it the current dictionary.

1.1. Syntax

dict begin → –

1.2. Stack Effects

Table 1. Before
Level Object

0

dict (dictionary to push)

Table 2. After
Level Object

(empty)

Dictionary stack increased by one

1.3. Description

begin pushes dict onto the dictionary stack, making it the current dictionary. This dictionary becomes the first one consulted during:

  • Implicit name lookup by the interpreter

  • def - defines in current dictionary

  • load - searches dictionary stack

  • store - searches dictionary stack

  • where - searches dictionary stack

1.4. PostScript Level

Level 1 and later

1.5. Examples

Basic dictionary scope
5 dict begin
  /x 10 def
  /y 20 def
  x y add  % Uses local definitions
end
% x and y no longer in scope
Nested dictionaries
/outer 5 dict def
outer begin
  /outerVar 1 def

  10 dict begin
    /innerVar 2 def
    outerVar innerVar add  % Can access outer scope
  end
end
Configuration block
/config 10 dict def
config begin
  /fontSize 12 def
  /fontName /Helvetica def
  fontName findfont fontSize scalefont setfont
end

1.6. Common Use Cases

1.6.1. Temporary Namespace

/doWork {
  10 dict begin
    % All defs here go into local dict
    /temp1 value1 def
    /temp2 value2 def
    % Work with temp variables
  end
} def

1.6.2. Module Pattern

/MyModule 20 dict def
MyModule begin
  /private-func { % implementation } def
  /public-func { private-func } def
end
/MyModule.public MyModule /public-func get def

1.6.3. Font Manipulation

/Helvetica findfont
dup maxlength dict begin
  { 1 index /FID ne { def } { pop pop } ifelse } forall
  /Encoding ISOLatin1Encoding def
  currentdict
end
/Helvetica-ISO exch definefont pop

1.7. Common Pitfalls

Must Match with end - Every begin must have a corresponding end. Unmatched begins cause [dictstackoverflow].
dict1 begin
dict2 begin
% Missing ends will overflow stack eventually
Dictionary Must Be Readable - Dictionary must not have no-access attribute.
Use gsave/grestore for Safety - When using begin/end with graphics state changes:
gsave
  mydict begin
    % Graphics operations
  end
grestore

1.8. Error Conditions

Error Condition

[dictstackoverflow]

Dictionary stack has grown too large

[invalidaccess]

Dictionary has no-access attribute

[stackunderflow]

No operand on stack

[typecheck]

Operand is not a dictionary

1.9. Implementation Notes

  • Dictionary stack typically allows 20-250 dictionaries

  • Standard stack contains at minimum: systemdict, userdict

  • Level 2 adds globaldict to standard stack

  • Stack operations affect name lookup immediately

1.10. Dictionary Stack Structure

Typical stack (top to bottom)
User dictionary (via begin)
User dictionary (via begin)
...
userdict
globaldict (Level 2)
systemdict

1.11. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.