Skip to main content

The PreTeXt Guide

Subsection 7.1.7 Images

Subsubsection 7.1.7.1 Using a Local image file

Planned.

Subsubsection 7.1.7.2 Using TikZ

In a problem statement (or hint, or solution), you may use an <image> with a <latex-image> child, as long as the host WeBWorK server is version 2.16 or later. See Subsubsection 4.14.3.2 for generalities about using <latex-image>.
However, if a <latex-image> is inside a <webwork>, you must use \(...\) instead of $...$ to encase any inline math in the image. And if you have display math, that should use \[...\] instead of $$...$$.
Your latex-image code can use variables that you defined in the <pg-code> section. Scalar variables may be used simply by using their perl names including the dollar sign sigil. For example, \draw ($a,$b) -- ($c,$d); where $a, $b, $c, and $d are variables. However, any instance of \$ in code will be interpreted as an escaped dollar sign first, so rare situations may require you to be more explicit. The alternative is to include variables just as you would anywhere else in a problem statement, using a <var> element like <var name="$a"/>. You would also need to use a <var> element if you would like to insert a perl array, for example <var name="@a"/>.
In perl, $, @, and % each have special meaning. So you may wonder about using them in your latex-image code. The short answer is that you should use them just as you would use them in a regular document. So when you would like a dollar sign, write \$. For a percent sign, use \%. An “at” character does not need escaping, so write @.
As mentioned above, do not use a dollar sign to encase math. If you want to put a comment in the code, you may write it in the usual way like % This is a comment.
Your project’s <docinfo> may contain a <latex-image-preamble> element. If so, and if that preamble content should affect the latex-images inside the <webwork>, then you need to get that preamble content up on the WeBWorK host course. In many cases, you will need to get that preamble content up on the host course for the image to even compile. See Section 38.3.
See the WeBWorK sample chapter for examples.

Subsubsection 7.1.7.3 Using @pg-name

In a problem statement (or hint, or solution), you may use an <image> with a @pg-name. This attribute’s values should be the name of an image created in the <pg-code> section. For example, an image created using init_graph from PGgraphmacros.pl.
See the WeBWorK sample chapter for examples.