Answers.Body: <p>The PGN (Portable Game Notation) format has its origins in a text document from 1994. It contains a specification and copious examples.</p>
  
  <p>The best location to read the original text transformed into a web-optimized format is at <a href="http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm" rel="nofollow noreferrer">this link</a>. The Colophon near the beginning discusses the different iterations the original text went through before finding its way to that website.</p>
  
  <p>Different PGN readers have implemented various aspects of this format and taken liberties of their own. Still, this is the closest you'll find to an official standard.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-17T18:48:52.397Z
Answers.LastActivityDate: 2017-07-17T18:48:52.397Z
Answers.UserDisplayName: James Tomasino
Answers.Body: <p>PGN is not a rigorous file format. Everything in the wikipedia link (posted by @Ghotir) applies, but nothing is "mandatory".</p>
  
  <p>The most common headers are:</p>
  
  <ul>
  <li>Event</li>
  <li>Site</li>
  <li>Date</li>
  <li>Round</li>
  <li>White</li>
  <li>Black</li>
  <li>Result</li>
  </ul>
  
  <p>But they are not mandatory. For example, you can get away by not specifying the player names.</p>
  
  <p>Most chess programs only require you to define a header, but it can be anything. You have to define something because that's how chess programs parse the file - it expects the <code>[</code> character.</p>
  
  <p>Your PGN parser <strong>must</strong> be robust and handle invalid PGN scenarios. I personally deliver PGN softwares, and I know what I'm talking about. Common PGN errors:</p>
  
  <ul>
  <li>"o", '0' in castling (e.g: "o-o", "0-0"). Correct is "O-O", but many people confuse the letters.</li>
  <li>"{" instead of "["</li>
  <li>"1-o" or "1-O" instead of "1-0"</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-17T14:44:09.777Z
Answers.LastActivityDate: 2017-07-17T14:44:09.777Z
Answers.UserDisplayName: SmallChess
Body: <p>I want to build a program that makes and reads PGNs. What is valid PGN? What arguments are valid in the header?
  What values are mandatory, what can be omitted?</p>
  
  <p>Can I find somewhere rules for composing PGNs?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-17T13:56:26.320Z
Comments.Text: Basic rules can be found on wikipedia (https://en.wikipedia.org/wiki/Portable_Game_Notation) - but I don't know if there is a more "official" or more "detailed" answer.  I'm also not sure how comprehensive it is on edge conditions.  (All of which is why this is a comment, not an answer.)
Comments.UserDisplayName: Ghotir
Tags: <pgn>
Title: What is valid PGN?
ThreadText: # What is valid PGN?
  
  (Asked by: username_0 on 2017-07-17)
  
  I want to build a program that makes and reads PGNs. What is valid PGN? What arguments are valid in the header?
  What values are mandatory, what can be omitted?
  
  Can I find somewhere rules for composing PGNs?
  
  **Tags:** pgn
  
  > **Comments:**
  > **username_1**: Basic rules can be found on wikipedia (https://en.wikipedia.org/wiki/Portable_Game_Notation) - but I don't know if there is a more "official" or more "detailed" answer.  I'm also not sure how comprehensive it is on edge conditions.  (All of which is why this is a comment, not an answer.)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-07-17. Score: 4 | Accepted answer
  
  PGN is not a rigorous file format. Everything in the wikipedia link (posted by @username_1) applies, but nothing is "mandatory".
  
  The most common headers are:
  
  * Event
  * Site
  * Date
  * Round
  * White
  * Black
  * Result
  
  But they are not mandatory. For example, you can get away by not specifying the player names.
  
  Most chess programs only require you to define a header, but it can be anything. You have to define something because that's how chess programs parse the file - it expects the `[` character.
  
  Your PGN parser **must** be robust and handle invalid PGN scenarios. I personally deliver PGN softwares, and I know what I'm talking about. Common PGN errors:
  
  * "o", '0' in castling (e.g: "o-o", "0-0"). Correct is "O-O", but many people confuse the letters.
  * "{" instead of "["
  * "1-o" or "1-O" instead of "1-0"
  
  
  ---
  
  ### Answer by username_2 on 2017-07-17. Score: 2
  
  The PGN (Portable Game Notation) format has its origins in a text document from 1994. It contains a specification and copious examples.
  
  The best location to read the original text transformed into a web-optimized format is at [this link](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm). The Colophon near the beginning discusses the different iterations the original text went through before finding its way to that website.
  
  Different PGN readers have implemented various aspects of this format and taken liberties of their own. Still, this is the closest you'll find to an official standard.
  
  
  ---
  
  