Difference between revisions of "Using Graphics"

From Wiki
Jump to navigation Jump to search
(add http proxy)
Line 75: Line 75:
  
 
{{cmd|starthangaround}} is influenced by {{cmd|setuphanging}}[distance=...]</cmd> (distance may even be negative!), but takes no parameters itself.
 
{{cmd|starthangaround}} is influenced by {{cmd|setuphanging}}[distance=...]</cmd> (distance may even be negative!), but takes no parameters itself.
 +
 +
Update, December 11, 2012:
 +
Now there are options for {{cmd|starthangaround}}. If you want to have the image to the right, you can do:
 +
<texcode>
 +
\setuppapersize[A5]
 +
\starttext
 +
\starthanging[right]{\externalfigure[cow][width=4cm]}
 +
    \input tufte
 +
\stophanging
 +
\stoptext
 +
</texcode>
 +
 +
There are even more options:
 +
<texcode>
 +
\setuppapersize[A5]
 +
\starttext
 +
\starthanging[location=right,n=2,distance=1cm]{\externalfigure[cow][width=4cm]}
 +
    \input tufte
 +
\stophanging
 +
\stoptext
 +
</texcode>
  
 
== Pictures as [[Floating Objects]] ==
 
== Pictures as [[Floating Objects]] ==

Revision as of 06:05, 11 December 2012

< Graphics | Combinations | Supported Media File Formats | Including pages from PDF documents | Animation >

Direct use of an image

This way you can use your image mypic.pdf :

\externalfigure[mypic]

Additional parameters:

\externalfigure[file or reference name][key=value, key=value, ...]
  • scale = scaling value
  • factor = max, fit, broad
  • wfactor, hfactor = max, fit, broad, value
  • width, height = dimension
  • frame = on, off
  • preset, preview, repeat, object = yes, no
  • display = file name
  • type, method = eps, mps, pdf, tif, png, jpg, mov, tex

If only one dimension is given, scaling is proportional.

Where ConTeXt finds your picture files

ConTeXt looks in the current and parent directory plus those given in texmf.cnf.

You can define your own image directory with:

\setupexternalfigures[directory={../pictures}]

or even for multiple directories:

\setupexternalfigures[directory={../drawings,../bitmaps}]

You can define the path relative or absolute, but use always forward slashes!

Referenced Pictures

Declaration of all used pictures in your environment, project or header file is better than direct use of file names in your code.

\useexternalfigure[reference name][file name][options]

Same options as above. You can even inherit them like this:

\useexternalfigure[dummy][nofile][width=\textwidth]
\useexternalfigure[myone][my_pic_one][dummy]
\useexternalfigure[mytwo][my_pic_two][dummy]

Somewhere in your text there's \externalfigure[myone].

Place picture in the text

You can directly place a figure in a text using \externalfigure[cow]. If you want to align it not to the baseline, but lower you can try whether \bbox{\externalfigure[cow]} does the right thing, otherwise you have to tweek \smash{\lower24pt\hbox{\externalfigure[cow]}}

Flow text around a picture

That's an undocumented feature Hans told us about in a mail from 2008-06-24.

It's in the source.

\setuppapersize[A5]
\setupexternalfigures[location={local,default}]
\starthangaround{\externalfigure[cow][width=4cm]}
\input tufte
\stophangaround

\starthangaround is influenced by \setuphanging[distance=...]</cmd> (distance may even be negative!), but takes no parameters itself.

Update, December 11, 2012: Now there are options for \starthangaround. If you want to have the image to the right, you can do:

\setuppapersize[A5]
\starttext
\starthanging[right]{\externalfigure[cow][width=4cm]}
    \input tufte
\stophanging
\stoptext

There are even more options:

\setuppapersize[A5]
\starttext
\starthanging[location=right,n=2,distance=1cm]{\externalfigure[cow][width=4cm]}
    \input tufte
\stophanging
\stoptext

Pictures as Floating Objects

Floats are numbered and placed by ConTeXt, and they can get a caption.

\placefigure[place]{My Caption}{\externalfigure[myone]}

place is one of: left, right, here, top, bottom, inleft, inright, inmargin, margin, page, opposite, always, force, tall

You get no caption with none. You get a table of figures with \showexternalfigures[alternative=a]. Alternatives (styles) a, b and c are predefined.

The second brackets of \placefigure can contain any command, e.g. \getbuffer.

You find more about floats (Floating Objects) in the manual.

Floating graphics with an enlarged, shaded background

To place a figure in, say, the right margin with a shaded background that is slightly larger than the figure (to give a bit of breathing room):

\setupcolors[state=start]
\placefigure[right,high,none]{}{\framed[frame=on, offset=10pt, framecolor=lightgray,
    background=color, backgroundcolor=lightgray]%
  {\externalfigure[sample/cow.pdf][scale=500]}}
\input knuth

Movies

Movies aren't recognized automatically yet, you need a more verbose declaration:

\externalfigure[demo.mov][label=demo,width=4cm,height=4cm,preview=yes]

preview=yes shows the first image as preview. You find more about interactive Elements in mwidget-s.pdf

Unfortunately, people who are fond of Linux cannot embed movies because the linux release of acroread doesn't support that. An alternative solution consists in launching your prefered player (MPlayer) from acroread:

\defineprogram[dummy.mpeg][dummy.mpeg.sh]

\starttext
\goto{\externalfigure[dummy-preview][width=0.48\textwidth]}[program(dummy.mpeg{})]
\stoptext

The script dummy.mpeg.sh should contain:

FILE=$(basename "$0"); mplayer -fs -zoom ${FILE/.sh/}

Full page images

Picture with hyperlink

This is an example of how to make a picture interactive. When the user clicks it, it invokes the user's browser to a given URL.

\setupinteraction[state=start]

\starttext
This is a cow: \goto{\externalfigure[cow][height=2ex]}[url(http://en.wikipedia.org/wiki/Cow)]
\stoptext 

HTTP Proxy

To use an http proxy for fetching images, the http variable (LuaSocket) has to be set up as follows:

\ctxlua{http = require("socket.http"); http.PROXY = "http://proxy.example.com:3128"}

Replace "http://proxy.example.com:3128" with the proxy URL.


To disable the proxy again:

\ctxlua{http = require("socket.http"); http.PROXY = nil}

See also