Difference between revisions of "Images - PGML"

From WeBWorK_wiki
Jump to navigation Jump to search
 
Line 26: Line 26:
   
 
If a WWPlot, LaTeXImage or GraphTool is created, it can be added in the same way. See [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/Images.html a sample problem] for a full problem that shows this.
 
If a WWPlot, LaTeXImage or GraphTool is created, it can be added in the same way. See [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/Images.html a sample problem] for a full problem that shows this.
  +
  +
== Storing Alternate Text in a variable ==
  +
  +
If you store alternate text in a variable (which often will occur with a dynamic image), you will need to bracket your variable. For example
  +
  +
$alt_text = 'This is some alternate text.';
  +
  +
and then in the PGML image call
  +
  +
[! [$alt_text] !]{$TikZ}{250}
   
 
== Optional sizes ==
 
== Optional sizes ==

Latest revision as of 15:43, 25 July 2023

Static Images

Images can be inserted into a PGML block with

 [!alt text!]{'image_file'}{width (optional)}{height (optional)}

Image files are local to the problem (either in the same directory or a sub directory) or as a URL. Standard image types of gif, jpeg and png are supported.

Dynamically Created Images

Images can be created with macros as well. These include WWPlot, TikZ, LaTeXImage, or graphtool plots.

For example, consider a TikZ image created with

 loadMacros('PGtikz.pl')
 
 $TikZ = createTikZImage();
 $TikZ->BEGIN_TIKZ
 \draw (0,0) circle[radius=1.5];
 END_TIKZ
 

This can be added with

 [!Graph of a circle!]{$TikZ}{250}

If a WWPlot, LaTeXImage or GraphTool is created, it can be added in the same way. See a sample problem for a full problem that shows this.

Storing Alternate Text in a variable

If you store alternate text in a variable (which often will occur with a dynamic image), you will need to bracket your variable. For example

 $alt_text = 'This is some alternate text.';

and then in the PGML image call

 [! [$alt_text] !]{$TikZ}{250}

Optional sizes

The width and height can be added optionally.

  • The width will be the width of the image in pixels. If not given, 100 is given as the default.
  • The height will be the height of the image in pixels. If not given, it is determined by the natural (based on aspect ratio) value of the image.

Note: For hardcopy output, there is a tex_size that is set automatically based on the formula width*1000/6000 to indicate a scale of the width as a proportion of the width of the page or column where 1000 mean 100% of the width.