picture
LaTeX's picture environment draws diagrams from coordinates: lines, arrows,
circles, curves and polygons, with text and maths placed wherever they are needed. fxTeX Pro
draws each picture as SVG, inside the equation, so a labelled triangle, a vector or a pair of axes
can sit in a sentence or beside an equation like any other piece of maths. The labels stay live:
in the editor below, each one is typed in place, and an empty one is a box waiting to be filled.
The picture panel holds ready-made shapes, and its first button opens the picture editor, to draw
a picture of your own. Click any example on this page to open it there.
Compiling the same pictures in LaTeX? Everything on this page is standard
LaTeX — the picture environment, pict2e's extras, and graphicx's
\scalebox and \rotatebox for symbols and turned text — with two small
additions: dashed and dotted lines, and \providesavebox for symbols. Those come from
fxpicture.sty, our package for LaTeX, which loads pict2e and graphicx itself. Add
\usepackage{fxpicture} to your preamble and every picture made here compiles in
pdfLaTeX, LuaLaTeX or XeLaTeX, on Overleaf or your own machine, drawn the same as it is on this
page. More about fxpicture.
Adding picture to your page
In fxTeX Pro, name picture when you render the page:
fxTeXPro.ready.then(() => {
fxTeXPro.unlock('fx_pk_your-key-here');
fxTeXPro.autoRender({ packages: ['picture'] });
});
In the equation editor, name it to EqEditor.init() and add the
picture panel to the toolbar. This is the editor above:
<script src="https://fxeditor.codecogs.com/fxeditor.api.min.js"></script>
<div id="toolbar"></div>
<div id="mathview"></div>
<div id="latex"></div>
<script>
const ready = EqEditor.init({
licence: 'fx_pk_your-key-here',
packages: ['picture']
});
const toolbar = EqEditor.Toolbar.link('toolbar', [
['picture', 'geometry', 'operators_core', 'brackets', 'arrows'],
['greeklower', 'greekupper', 'relations', 'symbols', 'accents', 'spaces', 'colors']
]);
ready.then(() => {
const latex = EqEditor.LaTeXView.link('latex');
const mathview = EqEditor.MathView.link('mathview').addLaTeXView(latex);
toolbar.addLaTeXView(latex).addMathView(mathview);
mathview.setLatex('\\begin{picture}(50,50)(-25,-25)\\put(0,0){\\circle{50}}\\end{picture}');
});
</script>
The picture panel has triangles, quadrilaterals, circles, axes, grids and solids,
each with its labels left empty to fill in, and a button that opens the picture editor on a new
picture or on the one the caret is in. picture adds 77 kB gzipped: name it only on the pages
that use it. See Using packages for more on both steps.
The picture editor
To draw a picture of your own, or change one, open the picture editor: press the first button
of the picture panel, click a picture's lines in the equation, or double-click anywhere on it. A
page can open it on its own with EqEditor.PictureEditor.open(latex), which resolves
with the new LaTeX, or null if the reader cancels.
The side panel has three tabs: Edit, with the picture's and the selected shape's settings (4 to 6 below), Symbols, and Library, ready-made figures to start from.
- Zoom and close. Zoom out and in (or Ctrl+wheel), Fit to show the whole picture, and × to close without saving. Drag the title bar to move the dialog, and its corner to resize it.
- Tools. Select, then line, arrow, circle, dot, oval, box, text, quadratic and cubic curves, polygon, arc and grid. Each has a key: hover over a tool to see it.
- The drawing. Drag with a tool to draw, or click for a shape of a sensible size. Drag a shape to move it, or one of its handles to move that point; the arrow keys nudge. Points snap to the grid, and to other shapes' corners, so lines meet. Shift+click, or a box dragged round them, selects several shapes. Right-click a shape or a handle (press and hold, on a touch screen) to type its exact values. A dashed box is a label left empty, which the reader fills in later, in the equation.
- Picture. The size of the picture and its lower-left corner, the unit its numbers are in, and the grid and snap. Fit frame to drawing sizes the picture to what is drawn.
- Shape. Everything about the selected shape: its points, whether it is closed or filled, its line style, width and colour - and buttons to duplicate or delete it, and move it in front of or behind the others. A label has its text here, with a Maths box to set it in maths, and a Turn to turn it.
- LaTeX. The picture as it will go into the equation. Edit it here and the drawing follows.
- Status. The pointer's position, in the picture's units, and a hint for the tool in use. Update (or Insert, for a new picture) puts the picture into the equation; Cancel leaves it as it was.
Symbols
The Symbols tab holds more than a hundred ready-made symbols: arrows, shapes, flowchart boxes, graph pieces such as axes, waves, a spring, a brace and a ruler, and circuit symbols, from resistors, capacitors and switches to transistors, logic gates and waveforms. Each is drawn with the picture environment's own lines and curves, and each goes into a picture as one object: it moves, scales, stretches and turns as a whole.
- The tab. Symbols sits between Edit and Library.
- Search and groups. Type a name or a tag (resistor, and gate, arrow), or choose a group: Arrows, Shapes, Flowchart, Graphs, Electrical, or Mine, your own.
- The symbols. Click one to put it in the middle of the picture, selected, ready to drag into place.
- Scale and stretch. A selected symbol has a handle at each corner and on each side. Drag a corner to scale it (hold Shift to scale it freely), or a side to stretch it one way; drag past the other side to flip it. Its exact size, turn and position are on the Edit tab, with buttons to flip it.
- Turn. Drag the orange handle to turn it about its middle, in steps of 15° (hold Alt to turn it freely).
- Turned text. A label turns the same way: select it and drag its orange handle, or type its Turn. An empty label stays a box to type into, turned with the picture.
A symbol takes a colour, a line width and a line style like any other shape. To change its lines one by one, press Ungroup on the Edit tab: they become the picture's own. It can be ungrouped turned by a quarter, or scaled the same both ways; a circle stretched, or text turned, cannot be written as the picture's own shapes.
Symbols of your own
Select the shapes that make a symbol — Shift+click, or drag a box round them — and
press Make symbol: they become one symbol, in their place. Give it a name and press
Save to My symbols, and it appears under Mine in the Symbols tab, for
the next picture. Your symbols are kept in the browser; a page using the editor can keep them
with each reader's account as well, with the onSaveSymbol option of
EqEditor.PictureEditor.open().
In LaTeX
Each symbol is saved once in the picture with \savebox, and drawn wherever it is used
with \usebox, scaled and turned with graphicx's \scalebox and
\rotatebox. A symbol used with a different line width is saved again under a second
name, as LaTeX fixes a box's lines when it is saved. Click the example to open it in the editor:
\begin{picture}(130,45)\providesavebox{\symResistor}\savebox{\symResistor}(40,8)[bl]{\Line(0,4)(10,4)\polygon(10,0)(30,0)(30,8)(10,8)\Line(30,4)(40,4)}\put(0,35){\usebox{\symResistor}}\put(50,35){\scalebox{1.5}[1]{\usebox{\symResistor}}}\put(120,0){\rotatebox{90}{\usebox{\symResistor}}}{\color{red}\put(20,0){\rotatebox{30}{\usebox{\symResistor}}}}\end{picture}One resistor, saved once: as it is, stretched, turned a quarter, and turned and coloured.\providesavebox is fxpicture's: it declares the box unless it already is one, so
a picture can appear more than once in a LaTeX document. See
fxpicture.sty.
Lines and arrows
\begin{picture}(w,h) sets the picture's size, and (x0,y0) after it,
if given, its lower-left corner. \put(x,y){...} places anything at a point.
\line(a,b){len} and \vector(a,b){len} take a slope and a length;
pict2e's \Line(x1,y1)(x2,y2) joins two points.
\begin{picture}(60,40)\put(0,0){\line(1,0){60}}\put(0,0){\line(3,2){60}}\put(0,0){\vector(0,1){40}}\end{picture}Lines and an arrow, from one point.
\begin{picture}(60,40)\Line(0,0)(60,40)\Line(0,40)(60,0)\end{picture}\Line: from one point to another.
\begin{picture}(70,50)(-5,-5)\thicklines\put(0,0){\vector(1,0){60}}\put(0,0){\vector(0,1){40}}\thinlines\put(62,-2){$x$}\put(-2,42){$y$}\qbezier(0,0)(30,40)(60,0)\end{picture}Axes, labelled, with a curve.
\begin{picture}(60,30)\multiput(0,0)(10,0){7}{\line(0,1){30}}\multiput(0,0)(0,10){4}{\line(1,0){60}}\end{picture}\multiput: the same thing, again and again.
Circles, ovals and polygons
\circle{d} is a circle of diameter d, \circle* a filled
one. \oval(w,h) has rounded corners, and [t], [bl] and
the like draw only part of it. \arc[a1,a2]{r}, \polygon and
\polyline are pict2e's.
\begin{picture}(50,50)(-25,-25)\put(0,0){\circle{50}}\put(0,0){\circle*{3}}\put(0,0){\line(1,0){25}}\put(10,2){$r$}\end{picture}A circle, its centre and its radius.
\begin{picture}(80,50)\put(40,25){\oval(70,40)}\put(40,25){\oval(40,20)[t]}\end{picture}An oval, and the top half of another.
\begin{picture}(50,50)\polygon(0,0)(50,0)(25,43)\polygon*(20,10)(30,10)(25,19)\put(25,20){\arc[0,180]{15}}\end{picture}A triangle, a filled one inside it, and an arc.
\begin{picture}(60,30)\polyline(0,0)(15,30)(30,0)(45,30)(60,0)\end{picture}\polyline: a path through the points, left open.
Curves
\qbezier is a quadratic Bézier curve, through its first and last points and
pulled towards the middle one; pict2e's \cbezier is a cubic one, with two. A number
in square brackets draws the curve as that many dots.
\begin{picture}(80,40)\cbezier(0,0)(20,40)(60,-20)(80,20)\put(0,0){\circle*{2}}\put(80,20){\circle*{2}}\end{picture}A cubic curve, its ends marked.
\begin{picture}(60,30)\qbezier[20](0,0)(30,40)(60,0)\end{picture}A curve drawn as 20 dots.
Labels and boxes
What \put places is text, as in LaTeX: put maths in $...$.
\makebox, \framebox and \dashbox set text in a box of a
given size; \color colours what follows it. A picture can sit inside an equation, on
its baseline. Text turns with graphicx's \rotatebox: in
\makebox(0,0), a box that takes no room, it turns about its middle.
\begin{picture}(58,54)(-11,-12)\polygon(0,0)(45,0)(0,40)\polyline(4,0)(4,4)(0,4)\put(-9,17){$a$}\put(20,-10){$b$}\put(25,23){$c$}\end{picture}A right-angled triangle, its sides labelled.
x + \begin{picture}(40,20)\put(0,0){\framebox(40,20){box}}\end{picture} = yA picture in an equation.
\begin{picture}(60,40)\put(0,0){\makebox(60,40)[tl]{TL}}\put(0,0){\makebox(60,40)[br]{BR}}\put(0,0){\dashbox{3}(60,40){$\frac{a}{b}$}}\end{picture}Text placed in a box's corners, and maths in a dashed box.
\begin{picture}(66,44)\put(0,0){\vector(3,2){60}}\put(27,24){\rotatebox{33.7}{\makebox(0,0){$v = 3$}}}\put(64,30){\rotatebox{90}{\makebox(0,0){${}$}}}\end{picture}Text turned along an arrow, and beside it a turned label left empty, to type into.\begin{picture}(60,40)\color{red}\put(0,0){\line(1,1){40}}{\color{blue}\put(10,30){blue text}}\put(40,0){\circle{10}}\end{picture}Colour, kept to its group.
Dashed and dotted lines
The one thing here that is not in LaTeX already. \linestyle{dashed},
dotted or dashdot — or \dashpattern{on}{off}, a pattern
of your own — applies to every line, curve and outline after it, to the end of its group,
the way \linethickness does. \linestyle{solid} goes back to solid
lines. To compile these in LaTeX, load fxpicture.
\begin{picture}(60,40){\linestyle{dashed}\put(10,10){\line(1,0){40}}\put(10,20){\oval(40,10)}\put(10,30){\qbezier(0,0)(20,15)(40,0)}}\end{picture}Dashed: a line, an oval and a curve.
\begin{picture}(80,40)\linestyle{dotted}\put(0,35){\line(1,0){80}}\put(15,15){\circle{24}}\thicklines\linestyle{dashdot}\put(35,5){\vector(1,0){45}}\put(35,20){\vector(2,1){30}}\end{picture}Dotted, then dash-dot arrows.
\begin{picture}(80,40)\dashpattern{3pt}{2pt}\polygon(0,0)(30,0)(15,25)\put(55,15){\arc[0,270]{12}}\linestyle{solid}\put(0,35){\line(1,0){80}}\end{picture}A pattern of your own, then solid again.
Grids
\grid(w,h)(dx,dy) draws lines every dx across and every dy up;
with [x0,y0] after it, each line is numbered, counting from there. It is epic's
\grid, which fxpicture provides in LaTeX too.
\begin{picture}(60,40)\put(0,0){\grid(60,40)(10,10)}\put(9,27){\line(1,1){21}}\end{picture}A grid to draw on.
\begin{picture}(60,40)\put(0,0){\grid(60,40)(10,10)[0,0]}\end{picture}Numbered from 0.
Units and coordinates
A bare number is a multiple of \unitlength, 1pt unless it is set; a length with a
unit is that length. Lengths can be added, subtracted, multiplied and divided.
\setlength{\unitlength}{1mm}\begin{picture}(30,20)\put(0,0){\line(3,2){30}}\put(15,10){\circle{5}}\end{picture}Measured in millimetres.
\begin{picture}(2cm,1cm)\put(0,0){\line(1,0){2cm}}\put(1cm,0.5cm){\circle*{3pt}}\put(0.5cm+2pt,0){\line(0,1){1cm}}\end{picture}Lengths with units, and a sum.
Not read, and drawn as nothing: \graphpaper, pict2e's path commands
(\moveto, \lineto, \strokepath), \bezier,
\savebox and \usebox.
fxpicture.sty: the same pictures in LaTeX
A picture made here is LaTeX, and compiles in a LaTeX document. Most of it needs nothing more
than LaTeX itself and two standard packages that every current TeX distribution has: pict2e, for
lines and curves, and graphicx, whose \scalebox and \rotatebox scale and
turn symbols and turned text. The exception is line styles: LaTeX
draws every line solid, and has no way to dash one. fxpicture is our package that
adds them — a small change on top of pict2e. It adds \linestyle and
\dashpattern as an option; a picture that does not use them comes out exactly as
pict2e draws it, and so does every solid line in one that does. It also adds
\providesavebox, which the editor uses to declare symbols, and loads pict2e and graphicx,
so it is the one package a picture needs.
\documentclass{article}
\usepackage{fxpicture} % loads pict2e (passing on any options) and graphicx
\begin{document}
\begin{picture}(60,40)
{\linestyle{dashed}
\put(10,10){\line(1,0){40}}
\put(10,20){\oval(40,10)}
}
\put(10,30){\line(1,0){40}} % solid again, after the group
\end{picture}
% A symbol, as the editor writes one: saved once, then scaled and turned with graphicx
\begin{picture}(60,30)
\providesavebox{\symResistor}
\savebox{\symResistor}(40,8)[bl]{\Line(0,4)(10,4)\polygon(10,0)(30,0)(30,8)(10,8)\Line(30,4)(40,4)}
\put(0,0){\usebox{\symResistor}}
\put(50,0){\rotatebox{90}{\scalebox{0.75}{\usebox{\symResistor}}}}
\end{picture}
\end{document}
Without fxpicture? A picture with no dashed or dotted lines compiles with
\usepackage{pict2e,graphicx} instead; replace each \providesavebox with
\newsavebox, and declare each symbol only once in the document.
| Declaration | Draws lines |
|---|---|
\linestyle{solid} | solid, as LaTeX does — the default |
\linestyle{dashed} | 3pt on, 3pt off |
\linestyle{dotted} | a dot as long as the line is thick, every 2pt |
\linestyle{dashdot} | a dash, then a dot |
\dashpattern{on}{off} | a pattern of your own, eg \dashpattern{3pt}{2pt} |
The patterns are TikZ's, so a picture and a TikZ drawing side by side match. fxpicture also
gives LaTeX epic's \grid, as above, and leaves epic's own
in place if a document loads epic. For symbols it loads graphicx and
adds \providesavebox{\name}: \newsavebox, unless \name is a
box already, so that a picture declaring its symbols can appear more than once in a document. It works with each of pict2e's drivers: pdfTeX, LuaTeX, XeTeX,
dvips and dvipdfm(x).
To install it, put fxpicture.sty beside your .tex file, or in
TEXMFHOME/tex/latex/fxpicture/ to use it in every document. It needs pict2e 0.4b
(2020) or later. The zip holds the package, its README and its documentation, as source and PDF.
fxpicture is free, under the LaTeX Project Public License 1.3c.
Download fxpicture.zip or just fxpicture.sty
The LaTeX manuals
This page covers the parts of the picture environment used most. Its full description is in LaTeX's own documentation, and pict2e's manual has the commands it adds:
pict2e on CTAN — \Line, \polygon, \arc, \cbezier and slopes of any size; its manual is linked there.
picture on CTAN — lengths with units in a picture's coordinates.
epic and eepic on CTAN — where \grid comes from.
More
chemfig — chemical structures, also drawn as SVG.
Using packages — turning packages on, and their panels.
Design — build a toolbar with the picture panel, and copy its code.
