## WeBWorK Main Forum

### Re: TikZ graph subroutine in PGcourse.pl produces errors

by Glenn Rice -
Number of replies: 0

Any macro file should define an init method.  It needs to be named _filename_init.  The PGcourse.pl macro does this too.  It is used by webwork to prevent the macro from being loaded more than once.

The line

$graph->addToPreamble("\\pgfplotsset{compat=1.16}"); adds "\pgfplotset{compat=1.16}" to the preamble of the generated tex file used to create the image. Any time you use the pgfplots package you should set the compat level. See the pgfplots documentation about that. The "$graph->addToPreamble" part is not a TikZ thing.  That is a PGtikz.pl macro thing.  It is documented in that file and in the PGlateximage.pl macro (both of which use the same underlying module -- LaTeXImage.pm).  See https://webwork.maa.org/pod/pg/macros/PGtikz.html.