Skip to main content
Logo image

Section 4.1 The publication file

When illustrating a large project such as a book, you will likely want to create diagrams that have a consistent style. PreFigure constructs some components with default values for the attributes. For instance, a <graph> is stroked blue by default and a <point> is filled red. You may, however, wish to change these default behaviors with a publication file, as shown in Listing 4.1.1
<prefigure>
  <graph stroke="green"/>
  <point style="diamond" size="5" fill="blue" outline="yes"/>
  <macros>
    \newcommand{\deriv}[2]{\displaystyle \frac{d#1}{d#2}}
    \newcommand{\real}{\Bbb R}
  </macros>
</prefigure>
Listing 4.1.1. A sample publication file
The publication file begins with a <prefigure> element whose children describe desired default behaviors for a few graphical components. For instance, this publication file asks that a <graph> be stroked green and that a <point> has a few default attributes. Notice that the publication file also includes a list of macros, given in the <macros> element, that can be used in labels.
To illustrate, Figure 4.1.2 contains a diagram created using this publication file with Listing 4.1.3 showing the PreFigure source.
Figure 4.1.2. A diagram created using the publication file in Listing 4.1.1
<diagram dimensions="(300,300)" margins="5">
  <definition>f(x)=exp(x/3)*cos(x)</definition>
  <coordinates bbox="(-4,-4,4,4)">
    <grid-axes ylabel="\real^2"/>
    <graph function="f"/>
    <repeat parameter="k=-3..3">
      <point p="(k,f(k))"/>
    </repeat>
    <label p="(2,2)" clear-background="yes">
      <m>\deriv{y}{x}</m>
    </label>
    <point p="(-2,2)" fill="red" size="4"/>
  </coordinates>
</diagram>
Listing 4.1.3. The PreFigure source for Figure 4.1.2.
Because the publication file sets the @stroke attribute of <graph> to be green, the graph of the function is stroked green by default. The <point>s on the graph are also created using the attributes given in the publication file. Notice that any attributes given in one of these tags, such as the <point> that is filled red, take precedence over the values in the publication file. This example also demonstrates the use of macros in the labels.
To apply the publication file pub_file.xml to a diagram, use the -p switch when compiling:
prefig build -p pub_file.xml foo.xml    
  
A good way to get started using a publication file for a large project is to say
prefig new    
  
which has the effect of copying an empty publication pf_publication.xml and the diagcess tools into the current directory. If you do not specify a publication file in a build command, PreFigure will look for a pf_publication.xml in the current directory or a parent directory. To disable the use of any publication file, use the -i or --ignore_publication flag with the build command:
prefig build -i foo.xml