Difference between revisions of "Images - PGML"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 25: Line 25:
 
[!Graph of a circle!]{$TikZ}{250}
 
[!Graph of a circle!]{$TikZ}{250}
   
  +
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.
   
 
== Optional sizes ==
 
== Optional sizes ==

Revision as of 08:00, 28 June 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.

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.