10

Trawling through the PGN standard, I was surprised by two of the specifications:

An escape mechanism triggered by % at the start of a new line:

There is a special escape mechanism for PGN data. This mechanism is triggered by a percent sign character ("%") appearing in the first column of a line; the data on the rest of the line is ignored by publicly available PGN scanning software. This escape convention is intended for the private use of software developers and researchers to embed non-PGN commands and data in PGN streams.

A percent sign appearing in any other place other than the first position in a line does not trigger the escape mechanism.

A "rest of line" comment initiated by a semicolon ;:

Comment text may appear in PGN data. There are two kinds of comments. The first kind is the "rest of line" comment; this comment type starts with a semicolon character and continues to the end of the line. [...]

They surprised me because I have never encountered them in any PGNs I've found "in the wild", so to speak. Has anyone encountered PGNs where these (escape mechanism or semicolon comments) are used?

2 Answers 2

6

You can use the percent sign to comment out a line of text in your PGN file (similar to Latex). For example, if you'd like to include personal comments that categorize the games within the database, such as % Games to study later. All such lines starting with % will not be interpreted by a PGN parser, so you can safely leave self-notes or other comments (that you might want to later parse in a script) in a PGN database.

An example of such a PGN file:

% Interesting games from Wijk aan zee

1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. d3 d6 5. c3 a6 6. Ba4 Be7 7. O-O O-O 8. Re1
Re8 9. Nbd2 Bf8 10. h3 b5 11. Bc2 Bb7 12. d4 g6 13. a3 Nb8 14. d5 c6 15. c4 Nbd7
16. a4 Qc7 17. b3 Rec8 18. Ra2 bxc4 19. bxc4 a5 20. Nf1 Ba6 21. Ne3 Nc5 22. Nd2
cxd5 23. cxd5 Rab8 24. Ba3 Qd8 25. Qf3 h5 26. Raa1 Bh6 27. Rab1 Rxb1 28. Rxb1
Kg7 29. Nef1 h4 30. Ne3 Bf4 31. Nef1 Qc7 32. g3 hxg3 33. fxg3 Bh6 34. h4 Qd7 35.
Kg2 Nxa4 36. Bxa4 Qxa4 37. Bxd6 Qd4 38. Qf2 Qxf2+ 39. Kxf2 Bxf1 0-1


% Caro-Kann games:

1. e4 c6 2. Nf3 d5 3. Nc3 Bg4 4. h3 Bxf3 5. Qxf3 Nf6 6. Be2 e6 7. O-O dxe4 8.
Nxe4 Nxe4 9. Qxe4 Nd7 10. d4 Nf6 11. Qd3 Qc7 12. Rd1 Be7 13. c4 O-O 14. Be3 Rfd8
15. Qb3 Rd7 16. Bf3 Rad8 17. a3 h6 18. g3 b6 19. Kg2 c5 20. Qc3 a5 21. Rac1 cxd4
22. Bxd4 Ne8 23. h4 Bf6 24. Bxf6 Nxf6 25. b4 axb4 26. axb4 Rxd1 27. Rxd1 Rxd1
28. Bxd1 Kf8 29. Bf3 Ke7 30. c5 bxc5 31. bxc5 Kf8 32. Qb4 Ne8 33. Qb6 Qe5 34.
Bc6 Ke7 35. Bxe8 Kxe8 36. c6 Qd6 37. Kg1 g5 38. h5 f5 39. Qb7 Qd1+ 40. Kg2 Qd5+
41. Kh2 Qd4 42. Kg1 Qd1+ 43. Kg2 Qd5+ 44. Kh2 Qd4 45. Kg1 1/2-1/2

You can experiment with this by loading the PGN file (like the above) on for example chesstempo in order to sanity check the parsing, and see that those lines are indeed correctly ignored.


As for annotations and the use of the semicolon see this answer by Andrew.

Briefly, the semicolon is another way of indicating move annotations but it's not efficient as it requires including redundant characters and line-skips per annotation, e.g.:

1. d4; closed system 
1...d5 2. c4 

instead of 1. d4 {closed system} d5 2. c4. And the semicolon notation is rarely supported by PGN parsers. So the use of curly brackets {} is always recommended, as it's well supported, simple and intuitive to use and less prone to mistakes in the notation.

3
  • I already understand how these work simply from reading the documentation. I'm more interested in how often these are used in practice -- the bit about the semicolon being rarely supported is interesting. (I'm actually preparing to write my own parser and want to know what it should conform to, then I ran into these things.)
    – Remellion
    Commented Jan 28, 2020 at 17:50
  • 3
    @Remellion how often cannot really be meaningfully answered as these things tend to be a question of style. Personally, I use % very frequently to add meta-information to my databases and personalize them (like the suggestions in my answer), and I also use it a lot to send commented PGN files to my students, classifying the games for them and including the question/exercise statements within the PGN file, such as: % Find the positional mistakes by white in this game. I do the same when I prepare openings for a student and do not want to over-annotate,then I use comments to discuss plans.
    – Ellie
    Commented Jan 28, 2020 at 19:15
  • 1
    Fair enough; but sensible anecdotal evidence is enough to convince me there is a use case for these tokens. And therefore that I need to parse these correctly. >.<
    – Remellion
    Commented Feb 2, 2020 at 12:18
0

I do not know about the semicolon, as ChessBase does not seem to use it, but based on the standard, that may be an either/or thing, and everyone has just opted for the braces, {}, when programming.

On the other hand, the percent sign is used regularly by ChessBase preceding the moves of an annotated game, and sometimes within the annotations also. I am not going to give entire games since they are copyrighted, but if you go to Mega2020, and click on "Annotated Games", select a game, and then click Home>Copy game, and paste it into Notepad, you will find that most, if not all, have something like what is below before move one. I have not found one that does not have it, but I am not going to do this for many thousands of games just to be positive.

I have no idea what it all means, but this might be what you are talking about. If not, please comment, and I will delete my answer.

{[%evp 17,89,-32,13,-6,21,-7,12,-12,30,10,24,-7,20,-20,27,12,27,-19,0,-30,33,0, 0,-56,-20,-86,17,6,17,0,27,-52,-32,-59,62,-86,10,-2,48,0,47,34,53,0,8,0,124,66, 141,72,227,206,535,535,751,746,748,748,740,740,742,745,736,740,800,801,29988, 29989,29989,29990,29990,29982,29991,29980]} 1. e4 c5 2. Nc3 Nc6 3. Nge2 g6 4. d4 cxd4 5. Nxd4 Bg7 6. Nb3 Nf6 7. Be2 d6 8. O-O O-O 9. Re1 b6 {etcetera - PhishMaster}

Here was another example with times.

{[%evp 0,9,32,32,13,-10,-5,6,25,35,23,7]} 1. d4 {[%emt 0:00:03]} d5 {[%emt 0: 00:28]} 2. c4 {[%emt 0:00:08]} e6 {[%emt 0:00:00]} 3. Nc3 {[%emt 0:00:07]} c5 { [%emt 0:00:05]} 4. cxd5 {[%emt 0:00:09]} exd5 {[%emt 0:00:19]} 5. dxc5 { [%emt 0:00:05]} d4 {[%emt 0:04:20]} 6. Na4 {[%emt 0:00:07]} Bxc5 {[%emt 0:04: 40]}

3
  • 5
    The percentage sign usage you state is not what I describe in the question. (Don't delete the answer!) What you highlight is a sort of standard for engine annotation in comments or time information in comments.
    – Remellion
    Commented Jan 28, 2020 at 17:43
  • @Remellion That is why I do not typically answer these types of questions, but your question looked so "lonely" having been up for 5+ hours with no answers. :) I guess I did not fully understand the differences, but knew I had seen the % used many times. Commented Jan 28, 2020 at 17:57
  • The one question I asked and really want answered went unanswered for 7 months, and only recently got a partial answer by... me. Which is not even the full answer I want. It's fine to have unanswered questions here. Anyway, the % character in your answer is in a brace comment, and so not the escape mechanism I was referring to, but it highlights an interesting "workaround" of the ancient standard to include further parsable information in comments.
    – Remellion
    Commented Jan 28, 2020 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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