Testing PGF and TikZ support in DocOnce

Authors:Kristian Gregorius Hustad (krihus at ifi.uio.no)
Date:Aug 5, 2016

Summary. Quick demo of how to make figures with TikZ in DocOnce.

Ideas

TikZ is a very strong tool for making figures in LaTeX. DocOnce supports such figures: if a figure file myfig exists in a version myfig.tikz, DocOnce will, in case of latex or pdflatex output, utilize the myfig.tikz figure directly. The problem is what do to with other output formats. In html format one can use a corresponding SVG version of the figure, and for other formats, one needs a plain PNG file. DocOnce will automatically create such versions of the figure and store them along with myfig.tikz, as is done when other figure formats need automatic conversion.

A modest beginning

_images/line.png

This shape is commonly referred to as a straight line

The most fundamental shape is the line in Figure This shape is commonly referred to as a straight line. See the source code for how this TikZ figure is defined in LaTeX as a file line.tikz (and included in DocOnce through FIGURE: [line, width=500] caption). Such lines can be combined to form other shapes, e.g., a square as in Figure This square is formed by four straight lines, but that figure was created directly by the rectangle TikZ command.

_images/square.png

This square is formed by four straight lines

A grid can also be easily made.

_images/grid.png

This is a grid with 5 x 5 cells

A circle, however, cannot be formed by a finite number of straight lines. It requires special code.

_images/circle.png

This circle is drawn in blue with a dashed line

More advanced figures

_images/maze.png

A maze can be drawn by combining rectangle elements

_images/graph.png

TikZ is quite well suited to draw graphs

Plotting functions

TikZ can be used to plot functions. The next figure will be inlined.

_images/plot1.png

See the source code for how you make this figure.

_images/plot2.png

The functions can even be labeled!

All details are in the source code.