Difference between revisions of "TikZImages"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 119: Line 119:
<li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/ nameOfMacro.pl.html]</li>
<li>POD documentation: [http://webwork.maa.org/pod/pg/PGtikz.html/ nameOfMacro.pl]</li>
<li>PG macro: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/#dirlist nameOfMacro.pl]</li>
<li>PG macro: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/#dirlist nameOfMacro.pl]</li>

Revision as of 23:37, 14 April 2021

Graphic Images, TikZImages

This example shows how to create an image/plot using Tikz.

Problem Techniques Index

PG problem file Explanation

Initialization: It is important to include the PGtikz.pl macro.

$graph_image = createTikZImage();

\draw[<->,thick] (-11,0) -- (11,0) node[above left,outer sep=2pt]{\(x\)};
\draw[<->,thick] (0,-11) -- (0,11) node[below right,outer sep=2pt]{\(y\)};
\foreach \x in {-10,-8,...,-2,2,4,...,10} \draw[thin] (\x,5pt) -- (\x,-5pt) node[below]{\(\x\)};
\foreach \y in {-10,-8,...,-2,2,4,...,10} \draw[thin] (5pt,\y) -- (-5pt,\y) node[left]{\(\y\)};
\draw[<->,red] plot[domain={-3.2+$a}:{3.2+$a}] (\x,{pow(\x-$a,2)+$b});


  • The createTikZImage() function creates an image to be built using tikz.
  • By default an 'svg' image will be generated, which will generally look better than a 'png image.
  • In certain cases the 'svg' creation methods do not give the correct output, and so in those cases a 'png' image may be generated instead by adding $graph_image->ext('png');.
  • The $graph_image->tikzLibraries("arrows.meta"); will load the arrows.meta Tikz library.
  • The actual tikz image is built between $graph_image->BEGIN_TIKZ and END_TIKZ
  • Notes: on using this and related Contexts.


[@ image(insertGraph($graph_image), width => 300, tex_size => 1000) @]*


Main Text: This is how to insert the tikz image. Note the width and tex_size parameters can change the size of the image on the web and as hardcopy.


This doesn't have a question, so we aren't checking an answer.

Problem Techniques Index