Return to previous page

Contents of file 'eqnum.php':



    1   <?php
    2   //============================================================================
    3   // File:        eqnum.php [PHP script]
    4   // Created:     June 20, 2011 [v.1.0]
    5   // Last change: June 20, 2011 [v.1.0]
    6   // Author:      Fredrik Jonsson <http://jonsson.eu/>
    7   //
    8   // DESCRIPTION
    9   //  The EQNUM script provides the two functions eqdef($tag) and eqref($tag)
   10   //  for the automatic generation and referencing of equation numbers. The
   11   //  input argument $tag is a text string 'tagging' the equation, leaving the
   12   //  actual equation numbering decoupled from the running text, thus enabling
   13   //  easily incorporated additions later on without the need for manually
   14   //  re-ordering the references.
   15   //
   16   //  The eqdef($tag) and eqref($tag) functions provide the server-side engine
   17   //  for the automatic generation of all equation numbers of mathematical
   18   //  hypertext documents found at jonsson.eu.
   19   //
   20   // EXAMPLE OF USAGE (http://jonsson.eu/research/lectures/lect1/web/)
   21   //
   22   //       < ? php include $siteroot."/php/eqnum.php"; ? >
   23   //       <p>
   24   //       From an all-classical point-of-view, the calculation of the
   25   //       electric polarization density of metals and plasmas, containing
   26   //       a free electron gas, can be performed using the model of free
   27   //       charges acting under the Lorenz force of an electromagnetic field,
   28   //       </p>
   29   //       <div class="center">
   30   //       <img class="center" src="lect1_eq_disp_001.png"
   31   //        alt="Some text describing the equation, e.g. TeX-code" />
   32   //       < ? php eqdef("lorentz_motion"); ? >
   33   //       </div>
   34   //       <p>
   35   //       where <b>E</b>(<i>t</i>) and <b>B</b>(<i>t</i>) are all-classical
   36   //       electric and magnetic fields of the electromagnetic field of the
   37   //       light. In forming the equation < ? php eqref("lorentz_motion"); ? >
   38   //       for the motion of the electron, the origin was chosen to coincide
   39   //       with the center of the nucleus.
   40   //       </p>
   41   //
   42   //  Copyright (C) 2011, Fredrik Jonsson <http://jonsson.eu/>
   43   //  Non-commercial copying welcome.
   44   //============================================================================
   45   $equation_number=0; // Global; reset for each new inclusion of 'eqnum.php'
   46   $lookup_table[]=array(); // Global lookup table for equation tags
   47   
   48   function eqdef($eqtag) {
   49     //
   50     // Definition of a new equation => Increment the globally defined equation
   51     // number.
   52     //
   53     $GLOBALS['equation_number']++;
   54   
   55     //
   56     // Add the 'tag' to the global lookup table, to be used later on in any
   57     // referencing of the equation.
   58     //
   59     $GLOBALS['lookup_table'][$eqtag]=$GLOBALS['equation_number'];
   60   
   61     //
   62     // Generate the tagged equation number (see the eqdef() routine for the
   63     // referencing of the equation).
   64     //
   65     echo "<span id=\"".$eqtag."\" class=\"eqdef\">";
   66     echo "(".$GLOBALS['equation_number'].")";
   67     echo "</span>"; // No trailing newline, as there may follow a ","...
   68   }
   69   
   70   function eqref($eqtag) {
   71     //
   72     // Simply read and display the equation number corresponding to the 'tag'
   73     // to the globally defined lookup table.
   74     //
   75     $tmp=$GLOBALS['lookup_table'][$eqtag];
   76   
   77     //
   78     // Generate the hyperlinked reference to the tagged equation.
   79     //
   80     echo "<span class=\"eqref\">";
   81     if (empty($tmp)) { // If no such entry in the global lookup table
   82       echo "(Error: No equation tagged '".$eqtag."'!)";
   83     } else {
   84       echo "(<a href=\"#".$eqtag."\">".$tmp."</a>)";
   85     }
   86     echo "</span>"; // No trailing newline, as there may follow a ","...
   87   }
   88   ?>
   89   

Return to previous page

Generated by ::viewsrc::

Last modified Wednesday 15 Feb 2023