Games::Go::Sgf2Dg::Dg2TeX3pm
Convert games::go::sgf2dg::diagrams to tex
Usage
use Games::Go::Sgf2Dg::Dg2TeX
my $dg2tex = B<Games::Go::Sgf2Dg::Dg2TeX-E<gt>new> (options);my $tex = $dg2tex->convertDiagram($diagram);
Overview
A Games::Go::Sgf2Dg::Dg2TeX object converts a Games::Go::Sgf2Dg::Diagram object into TeX source code which can be used stand-alone, or it can be incorporated into larger TeX documents.
New
- my $dg2tex =
Games::Go::Sgf2Dg::Dg2TeX->new(?options?)
A new Games::Go::D2TeX takes the following options:
boardSizeX=> number
boardSizeY=> number-
Sets the size of the board.
Default: 19
doubleDigits=> true | false-
Numbers on stones are wrapped back to 1 after they reach 100. Numbers associated with comments and diagram titles are not affected.
Default: false
topLine=> number (Default: 1)
bottomLine=> number (Default: 19)
leftLine=> number (Default: 1)
rightLine=> number (Default: 19)-
The edges of the board that should be displayed. Any portion of the board that extends beyond these numbers is not included in the output.
diaCoords=> sub { # convert $x, $y to Games::Go::Sgf2Dg::Diagram coordinates }-
This callback defines a subroutine to convert coordinates from
$x,$yto whatever coordinates are used in the Games::Go::Sgf2Dg::Diagram object. The defaultdiaCoordsconverts 1-based$x,$yto the same coordinates used in SGF format files. You only need to define this if you're using a different coordinate system in the Diagram.Default:
sub { my ($x,$y) =@_;
$x= chr($x - 1 + ord('a')); # convert 1 to 'a', etc
$y= chr($y - 1 + ord('a'));
return("$x$y"); }, # concatenate two lettersSee also the
diaCoordsmethod below.
file=> 'filename' | $descriptor | \$string | \@array-
If
fileis defined, the TeX source is dumped into the target. The target can be any of:- filename
-
The filename will be opened using IO::File->new. The filename should include the '>' or '>>' operator as described in 'perldoc IO::File'. TeX source is written into the file.
- descriptor
-
A file descriptor as returned by IO::File->new, or a \*FILE descriptor. TeX source is written into the file.
- reference to a string scalar
-
TeX source is concatenated to the end of the string.
- reference to an array
-
TeX source is split on "\n" and each line is pushed onto the array.
Default: undef
print=> sub { my ($dg2tex, @tex) = @_; ... }-
A user defined subroutine to replace the default printing method. This callback is called from the
printmethod (below) with the reference to theDg2TeXobject and a list of lines that are part of the TeX diagram source.
simple=> true | false-
This generates very simple TeX which may not look so good on the page, but is convenient if you intend to edit the TeX.
Default: false
twoColumn=> true | false-
This generates a two-column format using smaller fonts. This option forces
simpletrue.Default: false
coords=> true | false-
Adds coordinates to right and bottom edges.
Default: false
bigFonts=> true | false-
Use fonts magnified 1.2 times.
Default: false
texComments=> true | false-
Certain characters, when found in comments, are normally remapped as follows:
\ => $\backslash${ => $\lbrace$} => $\rbrace$$ => \$& => \&# => \#^ => $\wedge$_ => \_% => \%~ => $\sim$< => $<$> => $>$| => $|$(see the TeX Book page 38). When
texCommentsis specified, the mappings are suppressed so you can embed normal TeX source (like {\bf change fonts}) directly inside the comments.
floatControl=> controls which side diagrams will float on-
floatControlis a string that controls which side diagrams floats on. An 'l' puts the diagram on the left side (text on the right), 'r' puts the diagram on the right side, 'a' alternates, and any other character places the diagram randomly. The first character is for the first diagram, second character is for the second diagram, and so on. When there is only one character left, that character controls all remaining diagrams.floatControlis used only during 'normal' formatting. It is not used with 'simple' or 'twoColumn' formats.Default: 'rx' # first diagram on the right, all others are random
Default: 12
Interactions between options
If twoColumn is true, simple is turned on (no warning).
Methods
- $dg2tex->
configure(option => value, ?...?) -
Change Dg2TeX options from values passed at
newtime.
- my $coord = $dg2mp->
diaCoords($x, $y) -
Provides access to the
diaCoordsoption (see above). Returns coordinates in the converter's coordinate system for board coordinates ($x,$y). For example, to get a specific intersection structure:my $int = $diagram->get($dg2mp->diaCoords(3, 4));
- $dg2tex->
print($tex ? , ... ?) -
prints raw TeX code tofileas defined atnewtime. Whether or notfilewas defined,printaccumulates the TeX code for later retrieval withconverted.
- my $tex = $dg2tex->
converted($replacement_tex) -
Returns the TeX source code converted so far for the
Dg2TeXobject. If$replacement_texis defined, the accumulated TeX source code is replaced by$replacement_tex.
- $dg2tex->
comment($comment ? , ... ?) -
Inserts the TeX comment character ('%') in front of each line of each comment and
prints it tofile.
- my $tex_source = $dg2tex->
convertDiagram($diagram) -
Converts a Games::Go::Sgf2Dg::Diagram into TeX. If
filewas defined in thenewmethod, the TeX source is dumped into thefile. In any case, the TeX source is returned as a string scalar.
- my $tex = $dg2tex->
convertText($text) -
Converts
$textinto TeX code by changing certain characters that are not available in TeX cmr10 font, and by converting \n\n into \hfil\break.convertTextbehavior is modified bytexCommentsandsimpleoptions.Returns the converted text.
- $dg2tex->
close -
printthe TeX closer (\bye) and close the dg2tex object. Also closesfileif appropriate.
Releases
Unchanged in 3 releases since Debian 11 (Bullseye).