expand all
Projects Research Private Contact

Michael Pfeiffer
Imprint, Disclaimer

latex/pdflatex driver for fig2dev for solving the overlaid text problem

As mentioned in the fig2mpdf page there are many pro's for using LaTeX for typesetting figures who are included in LaTeX documents. Everything is working fine by using the pstex and pstex_t driver family of fig2dev as shown in figure 1 except the case that there are overlaid texts in the figure.

  Fig. 1: Normal procedure using fig2dev languages pstex and pstex_t to let latex set all texts in the figure. On the left you can see the two layers who result into the image on the right side, where the text layer was put on top of the remaining stuff.    

Overlaid text problem

If you want to have some text masked by other elements of the figure e.g. to intimate some spatial relations you can use different depths to get the desired result. But if you use the pstex, pstex_t combination you will get bad results. Figure 1 depicts the problem. All text of the figure is collected and processed by latex. latex's result is put on top of all other elements of the figure regardless it's original depth.

  Fig. 2: Example: Part of a created PDF. To get this, the figure is to split in at least three subfigures containing figure elements and text. In each subfigure the text is to put on top.    

To get a correct result the figure has to be split into several pieces concerning the occurance of text in the different layers of the figure. Figure 2 presents a simple example. The at least three different levels of text are splitting the figure in at least three subfigures which are to produce and to overlay. Therefore all these subfigures have to have the same size because there would be no way to get the offsets of the subfigures. I have created two new so called graphics languages for fig2dev. To integrate the functionality into fig2dev is the most effective way because fig2dev has all necessary information for processing everything. In contrast to the pstex/pstex_t solution we have to create more than two files containing the different figure elements.

My filters pdftex_p and pstex_p are producing just two files. The first one is the LaTeX file which contains all texts separated in blocks concerning the used depths. The second one is a shell script with which you can create all necessary graphics and size files who are required for the subsequent latex run. The separated graphics files are containing the figure elements under, between and on top of texts. Because of the number of graphics files isn't constant the names of these files is given as a filename prefix.

Known problems creating PDFs

In contrast to the latex/dvips combination the size of the target document has to be set in the latex file explicitly i.e. before the pdflatex run is performed. Thatfore the pdftex_p driver calculates the bounding box of all figure elements including the special texts set by pdflatex. Here is the problem of the procedure. fig2dev can not determine the right dimensions of the special text included in the figure (imagine a formular can be much higher than the height one normal text line). Normally this isn't a problem. But if the resulting text is bigger than expected so that the text crosses the calculated figure boundaries this becomes a promblem.

In that case you have to increase the size of the figure by inserting one or some invisible figure elements. This can be done with a rectangle which sourounds the entire figure for example. To get the rectangle invisible you have to set the line width to zero. With this trick the object is invisible even if you change the background color.