TeXblog

 Typography with TeX and LaTeX

Archive for the 'Graphics' Category

TikZ: shaded cube

10 August 2008 by Stefan Kottwitz

With just a few lines of code you can create a drawing of a cube with a 3D impression, though if it’s not really perspective or raytraced:

\begin{tikzpicture}[on grid]
  \shade[yslant=-0.5,right color=gray!10, left color=black!50]
    (0,0) rectangle +(3,3);
  \draw[yslant=-0.5] (0,0) grid (3,3);
  \shade[yslant=0.5,right color=gray!70,left color=gray!10]
    (3,-3) rectangle +(3,3);
  \draw[yslant=0.5] (3,-3) grid (6,0);
  \shade[yslant=0.5,xslant=-1,bottom color=gray!10,
    top color=black!80] (6,3) rectangle +(-3,-3);
  \draw[yslant=0.5,xslant=-1] (3,0) grid (6,3);
\end{tikzpicture}

This example uses the positioning tikz library.

Output screenshot:

pgf/TikZ 3D cube

By adding some slanted numbers we will get a Sudoku 3D cube:

pgf/TikZ sudoku 3D

TeX source code and pdf output are provided.

I’ve programmed it to answer a question posted on matheplanet.de. At first I wanted to use the matrix tikz library but it seemed to me that matrices of nodes cannot be slanted, at least I didn’t find a way.

Category: pgf/TikZ | 4 Comments »

pgf/TikZ 3D drawings

7 August 2008 by Stefan Kottwitz

Today Tomek posted very impressive 3D drawings made with pgf/TikZ in the LaTeX Community Forum.

Here’s one of the drawings showing a cylindrical projection:

pgf/TikZ 3D example

More examples and their complete sourcecode by Tomasz M. Trzeciak can be found in the corresponding posting in the LaTeX Community Forum.

For even more examples demonstrating the capabilities of pgf/TikZ visit the TikZ example gallery provided by Kjell Magne Fauske.

Category: pgf/TikZ, Mathematics | 2 Comments »

Jpgfdraw example

7 August 2008 by Stefan Kottwitz

Here’s an example illustration made with Jpgfdraw following a drawing in Singer/Thorpe Lecture Notes in Elementary Topology and Geometry, I made freehand it to illustrate homotopy of paths in my notes.

Screenshot:

Jpgfdraw example homotopy

Output in pdf format: homotopy.pdf
Jpgfdraw binary file: homotopy.jdr
exported tex file: homotopy.tex

LaTeX main document:

\documentclass[a4paper,10pt]{article}
\usepackage[landscape]{geometry}
\usepackage{amsmath,pgf}
\pagestyle{empty}
\begin{document}
\centering
\input{homotopy}
\end{document}

Category: Tools for LaTeX, IDEs and Editors, Graphics, Mathematics | No Comments »

Jpgfdraw 0.5b released

2 August 2008 by Stefan Kottwitz

The vector graphics application for LaTeX users Jpgfdraw beta version 0.5b has been released today.

The author Nicola Talbot announced:

    Jpgfdraw is a graphics application written in Java. You can use Jpgfdraw to:

  • Construct shapes using lines, moves and cubic Bezier segments;
  • Edit shapes by changing the defining control points;
  • Incorporate text and bitmap images (for annotation and background effects);
  • Extract the parameters for TeX’s \parshape command and for \shapepar (defined in the shapepar package);
  • Construct frames for use with the flowfram package;
  • Pictures can be saved in Jpgfdraw’s native binary format (JDR) or native ascii format (AJR) or can be exported as:
    • a pgfpicture environment for use in LaTeX documents with the pgf package;
    • a LaTeX2e package based on the flowfram package;
    • an encapsulated postscript file;
    • a PNG image file;
    • an SVG image file;
  • Incorporate text and bitmap images (for annotation and background effects);
  • Alternative text may be specified for use when exporting to a LaTeX file (e.g. if the text contains symbols or if it should be set in maths mode);
  • Mappings may be used to specify what LaTeX font declarations should be used when exporting to a LaTeX file.

That sounds very promising. I made a quick test today with Ubuntu Linux 8.04. After installing sun-java6-jre I downloaded and installed jpgfdraw-0.5b-us. It worked immediately. For the test I created a drawing and exported it into a pgf picture, tex format. After including it into a tex document and compiling I got the error Illegal unit of measure (pt inserted). It was caused by the numbers of the export file, they were using a comma instead of a decimal point. That problem is mentioned in the Jpgfdraw FAQ, but contrary to the FAQ it is still occuring with version 0.5b as I noticed using the locale de_DE.UTF-8.
After correction It worked perfectly, the drawing was displayed with high quality. Jpgfdraw could establish itself as a very useful tool.

Links:

Category: Tools for LaTeX, IDEs and Editors, Graphics | 1 Comment »

Adobe Reader: unwanted color change

14 July 2008 by Stefan Kottwitz

If you include a picture within a pdf document and view it with the Adobe Reader you may notice a change of color under certain circumstances. Let’s test this png file:

pdf color test original

This short example will be enough to produce a pdf by pdflatex:

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{test}
\end{document}

You may compile by yourself or look at the pdf output. Here’s a screenshot of the Adobe Reader:

pdf color test Adobe Reader

Nice blue color, but not the original one. Compare this color with a screenshot of the open source pdf viewer Evince:

pdf color test Evince

Because most people use the freely available Adobe Reader it may be necessary to fix this issue. I found a solution by converting the color mode from RGB to an indexed palette using the freely available open source software GIMP. Here is the changed png file, and here the pdf file, finally the screenshot:

pdf color test Adobe Reader

Using GIMP it’s possible to automate the conversion by GIMP’s batch mode using the procedure gimp-image-convert-indexed.

This topic was discussed in the LaTeX Community Forum.

Category: Graphics | 2 Comments »

PSTricks package update: pst-fun

23 June 2008 by Stefan Kottwitz

Today an update of the PSTricks related package pst-fun was released. pst-fun is aimed at drawing funny objects like bird, fish, ant, kangaroo, dog and faces, of course with different size, rotation etc. It may be useful for testing other PSTricks macros and could be more entertaining than simple dots or geometrical shapes. I’ve made a simple compilable example for testing:

\documentclass[a4paper,10pt]{article}
\usepackage[margin=3.5cm]{geometry}
\usepackage{pst-fun}
\begin{document}
\begin{pspicture}[showgrid=true](0,-1.5)(13,4)
  \put(1,1){\psBill}
  \put(3,2){\psBird[Branch]}
\end{pspicture}
\end{document}

And here’s a screenshot of the output:

pst-fun test output

If you want to see it in vector graphics quality you can find the corresponding pdf output here.

In the documentation to pst-fun you will find more explanation accompanied by examples.

Category: Graphics | No Comments »

New TikZ package: tikz-inet

18 June 2008 by Stefan Kottwitz

The today released package tikz-inet extends TikZ with commands for drawing interaction nets. At least Version 2.0 of pgf/TikZ is required.

For imformation about interaction nets see “Interaction Nets” by Y.Lafont, in POPL’90, 95-108 or for example the Diploma of Simon Gay, 1991.

Here is a small code example similar to one given in the documentation:

\documentclass[a4paper,10pt]{article}
\usepackage[fancy]{tikz-inet}
\renewcommand*\inetcolor{blue!25}
\begin{document}
\begin{tikzpicture}
\inetcell{A}
\inetprombox{(A)}(pa)
\inetcell[at=(bpa.east),right=5pt]{B}
\inetwire(B.middle pax)(A.middle pax)
\inetprombox{(bpa)(pa)(B)}(p)
\inetwire(A.pal)(pa.middle pax)
\inetwirefree(pa.pal)
\inetwirefree(p.pal)
\inetwire(B.pal)(p.middle pax)
\end{tikzpicture}
\end{document}

A screenshot of the output:

tikz interaction nets

Category: pgf/TikZ | No Comments »

Prevent floating of figures or tables

13 June 2008 by Stefan Kottwitz

Often images are embedded using the figure environment, they can get a caption, a label for reference and they will get numbered and appear in the list of figures. Figure environments are intended to float, but sometimes it is needed to place an image exactly at a specific position, still wanting to benefit from the other mentioned features of the figure environment. A similar problem is the exact placement of tables where usually the table environment is used.

One possibility that may not always prevent floating is to set more positioning parameter:

\begin{figure}[!htbp]
\includegraphics{filename}%
\caption{text}%
\end{figure}

This may work well, but not in all cases.

To prevent floating at all we must not use the figure environment. The caption package gives a way to get all the other features. It provides the command \captionof that takes a counter (figure or table) as argument and of course the caption text, for example:

\usepackage{caption}
...
\begin{center}
\includegraphics{filename}%
\captionof{figure}{text}\label{labelname}%
\end{center}

The figure counter is used for numbering and the image will be listed by the \listoffigures command.

The caption package is very recommendable, it has a lot of features and is very well documented. But if you don’t want to use it there’s still the alternative package capt-of that provides \captionof too. It is very small, actually beside comments it contains just one line of code:

\newcommand\captionof[1]{\def\@captype{#1}\caption}

The float package provides another very easy alternative for preventing floating: just use the H positioning parameter:

\usepackage{float}
...
\begin{figure}[H]
...
\end{figure}

If the other features of float are not needed then I would recommend to use caption instead. Of course this works with tables too, just use tabular etc. together with \captionof{table}{…} and perhaps \center or \centering.

This topic was discussed in the LaTeX Community Forum and on the MatheBoard.

Category: Graphics | No Comments »

EPS file with incorrect BoundingBox

10 June 2008 by Stefan Kottwitz

If an included eps image does not show up at the right position the coordinates of the BoundingBox may be incorrect. You could get an impression of if you open the image with an external viewer like gsview (Evince).

epstool provides a quick solution in two steps:

  1. it generates a TIFF4 preview raster image and calculates the BoundingBox coordinates from it,
  2. it creates the eps image with the right BoundingBox but without TIFF4 preview.

The temporary eps file including the preview can be deleted afterwards. For options/ parameters of epstool see its manpage (man epstool in the shell) or the epstool homepage.

Here are the command I used:

epstool -b -t4 --output tempfile.eps wrongfile.eps
epstool -p --output corrected.eps tempfile.eps
rm tempfile.eps

If you have many eps files with incorrect BoundingBox you could create a shell script for correction, you even could combine it with the use of the find utility.

To install epstool on Debian Linux or Ubuntu Linux you could use apt-get:

sudo apt-get install epstool

On Ubuntu Linux you also could use Synaptic to install epstool, you will find it in the section Graphics (universe) or by the search button.

Discussed in the LaTeX Community Forum.

Category: Tools for LaTeX, Graphics, Linux/ Ubuntu Linux | No Comments »

pgf version 2.00 debian package released

7 May 2008 by Stefan Kottwitz

On my Ubuntu 8.04 (”Hardy Heron”) the pgf/TikZ graphics package version 1.18 was installed. The pgf version 2.0 offers new features and is needed by newer documents and packages. A debian package of that version is now available.

For information and download see pgf (2.00-1) on packages.debian.org.

Installation on Debian and Ubuntu Linux:
sudo dpkg -i pgf_2.00-1_all.deb

Category: pgf/TikZ, Linux/ Ubuntu Linux | No Comments »