Using EPS and SVG images

My blogging frequency has gone done drastically so I thought I will post something about a basic feature of ConTeXt, which might not be well known.

How do you include an EPS image in ConTeXt MkIV?

\externalfigure[filename]

ConTeXt does the conversion behind the scenes (using ghostscript).

And how do you include a SVG image?

\externalfigure[filename]

Again, ConTeXt does the conversion behind the scenes using inkscape.

In both cases, a m_k_i_iv filename.pdf file is created in the current directory.

You do not need to include the file extension. ConTeXt will automatically try eps and svg extensions. The order in which different file formats are tried are:

  • pdf (.pdf )
  • mps (.mps and .\d+)
  • jpg (.jpg and .jpeg)
  • png (.png )
  • jbig (.jbig, .jbig2, and .jb2)
  • svg (.svg and .svgz)
  • eps (.eps and .ai)
  • gif (.gif)
  • mov (.mov and .flv)
  • buffer (.tmp, .buffer, .buf)
  • tex (.tex)

You may wonder, why allow tex as an extension. This is something which is useful for user manuals. If you want to show the output of an example file, you can just say

\externalfigure[example]

ConTeXt takes care of compiling the file and including the result. So, if you want to display the source code and the output of the example side-by-side, you can say

\placesidebyside
  {\framed[align=normal,width=0.5\textwidth]{\typefile{example}}}
  {\externalfigure[example][width=0.5\textwidth, frame=on]}

\placesidebyside is another one of those macros in ConTeXt that just work.

Advertisements