Keywords: Software

sgf2dg, whose manpage has been included below, is available from [ext] CPAN


sgf2dg - convert Smart Go Format (SGF) files to diagrams similar to those seen in Go books and magazines.


 sgf2dg [ option ... ] file[.sgf|.mgt]


sgf2dg takes a Smart Go Format (SGF) file *filename* or *filename*.sgf or *filename*.mgt and produces a diagram file *filename*.suffix where suffix is determined by the converter (see below).

The default converter is !Dg2TeX which converts the Diagram to TeX source code (sgf2dg is a superset replacement for the sgf2tex script and package). If you have the GOOE fonts (provided in the same package as sgf2dg) correctly installed on your system you will be able to TeX *filename*.tex to produce a .dvi file. You can of course embed all or parts of *filename*.tex into other TeX documents.


 -h | -help

Print a help message and quit.

 -i | -in <filename> | <filename>.sgf | <filename>.mgt

Specifies the input filename. (STDIN or none for standard input.) This option is not needed in ordinary use.

 -o | -out <filename>

Specifies the output file. ('STDOUT' for standard output.) If the input file is <filename>, <filename>.sgf or <filename>.mgt, then <filename>.*converter* is the default (see the converter option). This option is not needed in ordinary usage.

 -t | -top <top line number>

Specifies the top line to print. Default is 1.

 -b | -bottom <bottom line number>

Specifies the bottom line to print. Default is 19.

 -l | -left <left line number>

Specifies the leftmost line to print. Default is 1.

 -r | -right <right line number>

Specifies the rightmost line to print. Default is 19.

 -break | -breakList <break list>

'break list' is a list of moves, separated by comma, with no spaces. These are breakpoints: each will be the last move in one diagram.

 -m | -movesPerDiagram <moves per diagram>

'moves per diagram' is a positive integer, specifying the maximal number of moves per diagram. Default is 50 unless -break or -breakList is set, in which case the default is set to a very large number (10,000). The two options -breakList and -movesPerDiagram may be used together.

 -n | -newNumbers

Begin each diagram with the number 1. The actual move numbers are still used in the label.

-newNumbers and -doubleDigits are alternative schemes for avoiding three-digit numbers in the diagrams. They should probably not be used together.

 -d | -doubleDigits

If the first move of a diagram exceeds 100, the move number is reduced modulo 100. The actual move numbers are still used in the label.

-newNumbers and -doubleDigits are alternative schemes for avoiding three-digit numbers in the diagrams. They should probably not be used together.

 -rl | -repeatLast

The last move in each diagram is the first move in the next. This emulates a common style for annotating Go games.

 -il | -ignoreLetters

Letters embedded in the SGF with the L or LB property are ignored.

 -im | -ignoreMarks

Marks embedded in the SGF with the M or MA property are ignored.

 -ip | -ignorePass

Passes are ignored. In sgf, a pass is a move at the fictitious point tt. Without this option, sgf2dg indicates passes in the diagram comments.

 -ia | -ignore all

Ignore SGF letters, marks, variations and passes.

 -firstDiagram <diagram number>

Specifies the first diagram to print. Default is 1.

 -lastDiagram <diagram number>

Specifies the last diagram to print. Default is to print all diagrams until the end.


Generates a coordinate grid. This option may not be used with -twoColumn.


Print diagnostic messages as the conversion proceeds. Most SGF properties produce some kind of message.

 -converter | -convert

Selects different output converter plugins. Converters available with the current distribution package are:

   Games::Go::Dg2TeX TeX source (default)
   Games::Go::Dg2Mp MetaPost embedded in TeX
   Games::Go::Dg2ASCII simple ASCII diagrams
   Games::Go::Dg2PDF Portable Document Format (PDF)
   Games::Go::Dg2Ps PostScript
   Games::Go::Dg2Tk Perl/Tk NoteBook/Canvas
   Games::Go::Dg2TkPs PostScript via Dg2Tk (Dg2Ps is prefered)

maruseru: Games::Go::Dg2SL, the converter that outputs Sensei's Library format is not part of this package yet, but it has its own page.

converters are quite easy to write - should take just a few hours if you are already conversant with the conversion target. If you would like to create a converter plugin module, the easiest way is probably to grab a copy of (for example) and modify it. Once it's working, please be sure to send us a copy so we can add it to the distribution.

Converters are always prepended with 'Games::Go::Dg2', so to select the ASCII converter instead of the default TeX converter, use:

 -converter ASCII

Converter names are case sensitive.

The default output filename suffix is determined by the converter: the converter name is lower-cased to become the suffix, so the ASCII converter produces <filename>.ascii from <filename>.sgf.

You can also select different converters by changing the name of the sgf2dg script (or better, make symbolic links, or copies if your system can't handle links). The converter name is extracted from the name with this regular expression:


Anything after 'sgf2' is assumed to be the name of a converter module. For example, let's create a link to the script:

 $ cd /usr/local/bin
 $ ln -s sgf2dg sgf2Xyz


 $ sgf2Xyz foo.sgf [ options ]

attempts to use Games::Go::Dg2Xyz as the converter. The converter name extracted from the script name is case sensitive.

Note that three extracted names are treated specially:


These three names (when extracted from the script name) always attempt to use Games::Go::Dg2TeX as the converter.

Converter Options

Converters may be added dynamically as plugins, so this list only includes converter plugin modules that are included with the Sgf2Dg distribution.

Converter options are prepended with the converter name so that option xyz for converter Games::Go::Dg2Abc is written on the command line as:

 $ sgf2dg ... -Abc-xyz ...

Converter options that take arguments must be quoted so that the shell passes the option and any arguments as a single ARGV. For example, if the xyz option for converter Dg2Abc takes 'foo' and 'bar' as additional arguments, the command line would be:

 $ sgf2dg ... "-Abc-xyz foo bar" ...

or a more realistic example of changing the background color:

 $ sgf2dg genan-shuwa -converter Tk "-Tk-bg #d2f1b4bc8c8b"

Since Sgf2Dg is a super-set replacement for the Sgf2TeX package, TeX holds the default position for converters. Because of this historically priviledged position, the Dg2TeX options below do not need to be prepended with 'TeX-'. All of the following options apply to the Dg2TeX converter.

Other plugins available at the time of release are Dg2Mp, Dg2ASCII, Dg2PDF, Dg2Ps, Dg2Tk and Dg2TkPs. Dg2ASCII and Dg2TkPs take no additional options. Dg2Tk doesn't explicitly accept options, but it attempts to pass unrecognized options to the Tk::Canvas widgets at creation time (which is why the example above works).

For more information about converter-specific options, please refer to the perldoc or manual pages:

 $ perldoc Games::Go::Dg2PDF


 $ man Games::Go::Dg2Ps

Dg2TeX options


(Dg2TeX) In its default usage, the comments to each diagram comprise an unbreakable vbox---they must all appear on one page. This can cause problems if the comments are very extensive. This option generates more complicated TeX macros which allow the comments to be broken across pages. This option may not be used with -simple or -longComments.


(Dg2TeX) This generates very simple TeX which may not look so good on the page, but is convenient if you intend to edit the TeX. This option should not be used with -longComments.


(Dg2TeX) This generates a two-column format using smaller fonts. This option may not be used with -longComments or -coords.


(Dg2TeX) Use fonts magnified 1.2 times.


(Dg2TeX) If this option is NOT used then the characters {, } and \ found in comments are replaced by [, ] and /, since TeX roman fonts do not have these characters. If this option is used, these substitutions are not made, so you can embed TeX source (like {\bf change fonts}) directly inside the comments.


(Dg2TeX) The vertical gap (in points) between diagrams. Default is 12 points.

See Also

  • sgfsplit(1) - splits a .sgf file into its component variations


sgf2dg was written by Reid Augustin.

The GOOE fonts and TeX macros were designed by Daniel Bump. Daniel hosts the GOOE and [ext] sgf2dg home page

tsi: Example: ear reddening game, to fit on a single A4 paper sheet recto-verso, with big diagrams:

  $ wget [ext]
  $ sgf2dg -movesPerDiagram 82 -convert PDF "-PDF-pageSize a4" "-PDF-stone_fontSize 9" "-PDF-stone_fontName Helvetica-Bold" Ear-red.sgf
  $ xpdf Ear-red.pdf

xela: sdf2dg will work on any system that can support [ext] Perl, right? The above example looks great for anyone using linux, but might be a bit confusing for Windows users...

tsi: Perl and TeX are required. The SGF2DG tarball contains installation instructions for DOS/Windows systems too, see bundled INSTALL.DOS file.

sgf2dg last edited by Unkx80 on November 26, 2009 - 17:34
RecentChanges · StartingPoints · About
Edit page ·Search · Related · Page info · Latest diff
[Welcome to Sensei's Library!]
Search position
Page history
Latest page diff
Partner sites:
Go Teaching Ladder
Login / Prefs
Sensei's Library