Jump to: Site Navigation

NAME - Insert images into problems that are generated using LaTeX and TikZ.


This is a convenience macro for utilizing the TikZImage object to insert TikZ images into problems. Create a TikZ image as follows:

    $image = createTikZImage();
    \draw (-2,0) -- (2,0);
    \draw (0,-2) -- (0,2);
    \draw (0,0) circle[radius=1.5];

Then insert the image into the problem with



There are several TikZImage parameters that may need to be set for the TikZImage object return by createTikZImage to generate the desired image.

    $image->tex()              Add the tikz commands that define the image.
                               This takes a single string parameter.  It is
                               generally best to use single quotes around the
                               string.  Escaping of special characters may be
                               needed in some cases.

    $image->tikzOptions()      Add options that will be passed to
                               \begin{tikzpicture}.  This takes a single
                               string parameter.
                               For example:
                                   "x=.5cm,y=.5cm,declare function={f(\x)=sqrt(\x);}"

    $image->tikzLibraries()    Add additional tikz libraries to load.  This
                               takes a single string parameter.
                               For example:

    $image->texPackages()      Add tex packages to load.  This takes an array for
                               its parameter.  Each element of this array should
                               either be the package name as a string, or an
                               array with two elements, the first of which is the
                               package name as a string and the second of which
                               is a string containing the options for the package.
                               For example:
                                   ["hf-tikz", "customcolors"],
                                   ["xcolor", "cmyk,table"]

    $image->addToPreamble()    Additional commands to add to the TeX preamble.
                               This takes a single string parameter.

    $image->ext()              Set the file type to be used for the image.
                               The valid image types are 'png', 'gif', 'svg',
                               and 'pdf'.  The default is an 'svg' image.  You
                               should determine if an 'svg' image works well with
                               the TikZ code that you utilize.  If not, then use
                               this method to change the exension to 'png' or

                               This macro sets the extension to 'pdf' when a
                               hardcopy is generated.

    $image->convertOptions()   If ImageMagick's convert command is used to build
                               the output image (presently only done for 'png'
                               output) these input and output options will be
                               used. For example:
                                   input => {density => 300},
                                   output => {quality => 100, resize => "500x500"}
                               For a complete list of options, see:

Site Navigation