#!/usr/bin/perl
#=======================================================================
# Copyright (c) 2000-2001 Daniele Giacomini daniele@swlibero.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#=======================================================================
# alml-sp2be
#
# Back-end for post-SP to back-end format elaboration.
#
# This separate Perl program is necessary because, if included inside
# the main program, it will take away all system resources, without
# releasing them. In practice: after the call to &sgml_post_sp_elab(),
# we are not able to run makeinfo or info2dvi. The worse thing is
# that these programs die without giving valid explanations: it seems
# that there is a mistake inside the Texinfo generated source, but
# there is none.
#=======================================================================

use POSIX;
use Locale::gettext;
setlocale (LC_MESSAGES, "");
textdomain ("alml");

#sub gettext
#{
#    return $_[0];
#}

# Program executable without path.
$program_executable = $0;
$program_executable =~ m{([^/]*)$};
$program_executable = $1;

# List of other temporary files that must be deleted at the end of
# elaboration.
$temp_files_list = "";

# Temporary file name prefix.
$temporary_file_name_prefix = "";

#-----------------------------------------------------------------------
# Max.
sub max {
    local ( $x ) = $_[0];
    local ( $y ) = $_[1];
    if ( $x > $y ) {
        return $x;
    } else {
        return $y;
    }
}

#-----------------------------------------------------------------------
# Define a temporary file.
#
# &temporary_file ( <prefix> )
#
sub temporary_file
{
    local( $file_prefix ) = $_[0];
    local( $temp_dir ) = "";
    local( $random_number ) = 0;
    local( $random_file_name ) = "";

    # Check file prefix.
    if ( $file_prefix ne "" )
      {
        $file_prefix = $file_prefix . "_";
      }

    # Check for temp dir.
    $temp_dir = &temporary_dir ();
    
    # Moved into a function.
    #if (-d $ENV{TEMPDIR}
    #    && -r $ENV{TEMPDIR}
    #    && -w $ENV{TEMPDIR}
    #    && -x $ENV{TEMPDIR})
    #  {
    #    # This directory is good.
    #    $temp_dir = $ENV{TEMPDIR};
    #  }
    #elsif (-d "/tmp" && -r "/tmp" && -w "/tmp" && -x "/tmp")
    #  {
    #    # This other directory is good.
    #    $temp_dir = "/tmp";
    #  }
    #elsif (-r "." && -w "." && -x ".")
    #  {
    #    # Current directory is good.
    #    $temp_dir = ".";
    #  }
    #else
    #  {
    #    # We cannot use any temporary file!
    #    printf STDERR (gettext ("%s: cannot create any temporary file!\n"),
    #                   $program_executable);
    #    exit 1;
    #  }

    # If we are here, we have a valid temporary directory.
    # We try to find a good name for the file.
    while (1)
      {
        # Define the random number (six digits).
        $random_number = int ((rand) * 1000000);
        # Define the random file name: TF...tmp.
        $random_file_name = "$temp_dir/$file_prefix" . "TF${random_number}tmp";
        # Check if it is new.
        if (-e $random_file_name)
          {
            # The file exists already.
            next;
          }
        else
          {
            if (open (TEMP_FILE, "> $random_file_name"))
              {
                # It works.
                close( TEMP_FILE );
                last;
              }
            else
              {
                # Don't know what to do.
                printf STDERR
                  (gettext ("%s: cannot create the temporary file %s\n"),
                   $program_executable, $random_file_name);
                next;
              }

            # This point cannot be reached.
            printf STDERR
              (gettext ("%s: function %s unknown error 1\n"),
               $program_executable, "&temporary_file($file_prefix)");
          }

        # This point cannot be reached.
        printf STDERR
          (gettext ("%s: function %s unknown error 2\n"),
           $program_executable, "&temporary_file($file_prefix)");
      }         

    # Return the file name.
    return ("$random_file_name");
}

#-----------------------------------------------------------------------
# Define a temporary directory according with function &temporary_file().
#
# &temporary_dir ()
#
sub temporary_dir
{
    local ($temp_dir) = "";

    # Check for temp dir.
    if (-d $ENV{TEMPDIR}
        && -r $ENV{TEMPDIR}
        && -w $ENV{TEMPDIR}
        && -x $ENV{TEMPDIR})
      {
        # This directory is good.
        $temp_dir = $ENV{TEMPDIR};
      }
    elsif (-d "/tmp" && -r "/tmp" && -w "/tmp" && -x "/tmp")
      {
        # This other directory is good.
        $temp_dir = "/tmp";
      }
    elsif (-r "." && -w "." && -x ".")
      {
        # Current directory is good.
        $temp_dir = ".";
      }
    else
      {
        # We cannot use any temporary file!
        printf STDERR (gettext ("%s: cannot create any temporary file!\n"),
                       $program_executable);
        exit 1;
      }

    # Return the file name.
    return ("$temp_dir");
}

#-----------------------------------------------------------------------
# Determinate the file name without extention.
#
# &root_name (FILE_NAME, EXTENTION)
#
sub root_name
{
    local( $file_name ) = $_[0];
    local( $extention_name ) = $_[1];
    local( $root_name ) = "";
    
    $file_name =~ m/^(.*)$extention_name$/;
    $root_name = $1;
    if ($root_name eq "")
      {
        # The extention is not the same.
        $root_name = $file_name;
      }
    return ("$root_name");
} # &root_name

#-----------------------------------------------------------------------
# Define a space string.
#
# &spaces (N)
#
sub spaces
{
    local( $n ) = $_[0];
    local( $spaces ) = "";

    while ($n > 0)
      {
        $spaces = $spaces . " ";
        $n--;
      }
    return ("$spaces");
} # &spaces

#-----------------------------------------------------------------------
# Translate a positive integer into an alphabet sequence:
# from A to CZ.
#
# &integer_to_alphabet (INTEGER)
#
sub integer_to_alphabet
{
    local ($n) = $_[0];

    #-------------------------------------------------------------------
    # Generate an alphabet digit.
    # 1 -> A, 2 -> B,... 26 -> Z
    #
    # &aphabet_digit (1-26)
    #
    sub alphabet_digit
    {
        local ($digit) = $_[0];

        if ($digit == 0)
          {
            return ("");
          }
        elsif ($digit == 1){
            return ("A");
          }
        elsif ($digit == 2)
          {
            return ("B");
          }
        elsif ($digit == 3)
          {
            return ("C");
          }
        elsif ($digit == 4)
          {
            return ("D");
          }
        elsif ($digit == 5)
          {
            return ("E");
          }
        elsif ($digit == 6)
          {
            return ("F");
          }
        elsif ($digit == 7)
          {
            return ("G");
          }
        elsif ($digit == 8)
          {
            return ("H");
          }
        elsif ($digit == 9)
          {
            return ("I");
          }
        elsif ($digit == 10)
          {
            return ("J");
          }
        elsif ($digit == 11)
          {
            return ("K");
          }
        elsif ($digit == 12)
          {
            return ("L");
          }
        elsif ($digit == 13)
          {
            return ("M");
          }
        elsif ($digit == 14)
          {
            return ("N");
          }
        elsif ($digit == 15)
          {
            return ("O");
          }
        elsif ($digit == 16)
          {
            return ("P");
          }
        elsif ($digit == 17)
          {
            return ("Q");
          }
        elsif ($digit == 18)
          {
            return ("R");
          }
        elsif ($digit == 19)
          {
            return ("S");
          }
        elsif ($digit == 20)
          {
            return ("T");
          }
        elsif ($digit == 21)
          {
            return ("U");
          }
        elsif ($digit == 22)
          {
            return ("V");
          }
        elsif ($digit == 23)
          {
            return ("W");
          }
        elsif ($digit == 24)
          {
            return ("X");
          }
        elsif ($digit == 25)
          {
            return ("Y");
          }
        elsif ($digit == 26)
          {
            return ("Z");
          }
    }

    # Analyse the number.
    if ($n <= 0)
      {
        # We cannot translate zero or negative numbers.
        $return = "##<A##";

        &diag_output (sprintf (gettext ("%s: cannot translate into letters %s\n"),
                               $program_executable, $n));
      }
    elsif ($n <= 26)
      {
        # We have only one letter.
        $return = &alphabet_digit($n);
      }
    elsif ($n <= 52)
      {
        # We have two letters: Ax.
        $n = $n - 26;
        $return = "A" . &alphabet_digit($n);
      }
    elsif ($n <= 78)
      {
        # We have two letters: Bx.
        $n = $n - 52;
        $return = "B" . &alphabet_digit($n);

      }
    elsif ($n <= 104)
      {
        # We have two letters: Cx.
        $n = $n - 78;
        $return = "C" . &alphabet_digit($n);
      }
    else
      {
        # The number is too big.
        $return = "##>CZ##";

        &diag_output (sprintf (gettext ("%s: cannot translate into letters %s\n"),
                               $program_executable, $n));
      }
} # &integer_to_alphabet

#-----------------------------------------------------------------------
# Translate a positive integer into a roman string.
#
# &integer_to_roman (INTEGER)
#
sub integer_to_roman
{
    local ( $n ) = $_[0];
    local ( $digit_1 ) = 0;
    local ( $digit_2 ) = 0;
    local ( $digit_3 ) = 0;
    local ( $digit_4 ) = 0;

    #-------------------------------------------------------------------
    # First digit into roman: 1-9
    #
    sub digit_1_to_roman
    {
        local ( $digit ) = $_[0];

        if ($digit == 0)
          {
            return ("");
          }
        elsif ($digit == 1)
          {
            return ("I");
          }
        elsif ($digit == 2)
          {
            return ("II");
          }
        elsif ($digit == 3)
          {
            return ("III");
          }
        elsif ($digit == 4)
          {
            return ("IV");
          }
        elsif ($digit == 5)
          {
            return ("V");
          }
        elsif ($digit == 6)
          {
            return ("VI");
          }
        elsif ($digit == 7)
          {
            return ("VII");
          }
        elsif ($digit == 8)
          {
            return ("VIII");
          }
        elsif ($digit == 9)
          {
            return ("IX");
          }
    }

    #-------------------------------------------------------------------
    # Second digit into roman: 10-90
    #
    sub digit_2_to_roman
    {
        local ($digit) = $_[0];

        if ($digit == 0)
          {
            return ("");
          }
        elsif ($digit == 1)
          {
            return ("X");
          }
        elsif ($digit == 2)
          {
            return ("XX");
          }
        elsif ($digit == 3)
          {
            return ("XXX");
          }
        elsif ($digit == 4)
          {
            return ("XL");
          }
        elsif ($digit == 5)
          {
            return ("L");
          }
        elsif ($digit == 6)
          {
            return ("LX");
          }
        elsif ($digit == 7)
          {
            return ("LXX");
          }
        elsif ($digit == 8)
          {
            return ("LXXX");
          }
        elsif ($digit == 9)
          {
            return ("XC");
          }
    }

    #-------------------------------------------------------------------
    # Third digit into roman: 100-900
    #
    sub digit_3_to_roman
    {
        local ($digit) = $_[0];

        if ($digit == 0)
          {
            return ("");
          }
        elsif ($digit == 1)
          {
            return ("C");
          }
        elsif ($digit == 2)
          {
            return ("CC");
          }
        elsif ($digit == 3)
          {
            return ("CCC");
          }
        elsif ($digit == 4)
          {
            return ("CD");
          }
        elsif ($digit == 5)
          {
            return ("D");
          }
        elsif ($digit == 6)
          {
            return ("DC");
          }
        elsif ($digit == 7)
          {
            return ("DCC");
          }
        elsif ($digit == 8)
          {
            return ("DCCC");
          }
        elsif ($digit == 9)
          {
            return ("CM");
          }
    }

    #-------------------------------------------------------------------
    # Fourth digit into roman: 1000-9000
    #
    sub digit_4_to_roman
    {
        local ($digit) = $_[0];

        if ($digit == 0)
          {
            return ("");
          }
        elsif ($digit == 1)
          {
            return ("M");
          }
        elsif ($digit == 2)
          {
            return ("MM");
          }
        elsif ($digit == 3)
          {
            return ("MMM");
          }
        elsif ($digit == 4)
          {
            return ("MMMM");
          }
        elsif ($digit == 5)
          {
            return ("MMMMM");
          }
        elsif ($digit == 6)
          {
            return ("MMMMMM");
          }
        elsif ($digit == 7)
          {
            return ("MMMMMMM");
          }
        elsif ($digit == 8)
          {
            return ("MMMMMMMM");
          }
        elsif ($digit == 9)
          {
            return ("MMMMMMMMM");
          }
    }

    # Start the work.
    $digit_4 = int( $n / 1000 );
    $n = ($n - $digit_4*1000);
    $digit_3 = int( $n / 100 );
    $n = ($n - $digit_3*100);
    $digit_2 = int( $n / 10 );
    $n = ($n - $digit_2*10);
    $digit_1 = $n;

    return (&digit_4_to_roman($digit_4)
            . &digit_3_to_roman($digit_3)
            . &digit_2_to_roman($digit_2)
            . &digit_1_to_roman($digit_1));
}

#-----------------------------------------------------------------------
# Diagnostic output; it depends on the following global variables:
#   $verbose
#   $root_file_name
#
sub diag_output
{
    local ($string)    = $_[0];

    # Append to the diagnostic file.
    open (DIAG, ">> $root_file_name.diag");
    
    if ($verbose)
      {
        print STDOUT ($string);
      }
    # In any case, print it on the DIAG file
    print DIAG ($string);

    # Close the file.
    close (DIAG);

}

#-----------------------------------------------------------------------
# Give page x,y sizes with big point units
#-----------------------------------------------------------------------
sub page_size
{
    local ($page) = $_[0];
    local (@width) = ();

    $page = lc ($page);    

    if ($page eq "11x17")
      {
        $width[0] = 11*72;
	$width[1] = 17*72;
      }
    elsif ($page eq "a0")
      {
        $width[0] = 33.0556*72;
	$width[1] = 46.7778*72;
      }
    elsif ($page eq "a10")
      {
	$width[0] = 1.02778*72;
	$width[1] = 1.45833*72;
      }
    elsif ($page eq "a1")
      {
	$width[0] = 23.3889*72;
	$width[1] = 33.0556*72;
      }
    elsif ($page eq "a2")
      {
	$width[0] = 16.5278*72;
	$width[1] = 23.3889*72;
      }
    elsif ($page eq "a3")
      {
	$width[0] = 11.6944*72;
	$width[1] = 16.5278*72;
      }
    elsif ($page eq "a4")
      {
	$width[0] = 8.26389*72;
	$width[1] = 11.6944*72;
      }
    elsif ($page eq "a5")
      {
	$width[0] = 5.84722*72;
	$width[1] = 8.26389*72;
      }
    elsif ($page eq "a6")
      {
	$width[0] = 4.125*72;
	$width[1] = 5.84722*72;
      }
    elsif ($page eq "a7")
      {
	$width[0] = 2.91667*72;
	$width[1] = 4.125*72;
      }
    elsif ($page eq "a8")
      {
	$width[0] = 2.05556*72;
	$width[1] = 2.91667*72;
      }
    elsif ($page eq "a9")
      {
	$width[0] = 1.45833*72;
	$width[1] = 2.05556*72;
      }
    elsif ($page eq "archa")
      {
	$width[0] = 9*72;
	$width[1] = 12*72;
      }
    elsif ($page eq "archb")
      {
	$width[0] = 12*72;
	$width[1] = 18*72;
      }
    elsif ($page eq "archc")
      {
	$width[0] = 18*72;
	$width[1] = 24*72;
      }
    elsif ($page eq "archd")
      {
	$width[0] = 24*72;
	$width[1] = 36*72;
      }
    elsif ($page eq "arche")
      {
	$width[0] = 36*72;
	$width[1] = 48*72;
      }
    elsif ($page eq "b0")
      {
	$width[0] = 39.3889*72;
	$width[1] = 55.6667*72;
      }
    elsif ($page eq "b1")
      {
	$width[0] = 27.8333*72;
	$width[1] = 39.3889*72;
      }
    elsif ($page eq "b2")
      {
	$width[0] = 19.6944*72;
	$width[1] = 27.8333*72;
      }
    elsif ($page eq "b3")
      {
	$width[0] = 13.9167*72;
	$width[1] = 19.6944*72;
      }
    elsif ($page eq "b4")
      {
	$width[0] = 9.84722*72;
	$width[1] = 13.9167*72;
      }
    elsif ($page eq "b5")
      {
	$width[0] = 6.95833*72;
	$width[1] = 9.84722*72;
      }
    elsif ($page eq "flsa")
      {
	$width[0] = 8.5*72;
	$width[1] = 13*72;
      }
    elsif ($page eq "flse")
      {
	$width[0] = 8.5*72;
	$width[1] = 13*72;
      }
    elsif ($page eq "halfletter")
      {
	$width[0] = 5.5*72;
	$width[1] = 8.5*72;
      }
    elsif ($page eq "ledger")
      {
	$width[0] = 17*72;
	$width[1] = 11*72;
      }
    elsif ($page eq "legal")
      {
	$width[0] = 8.5*72;
	$width[1] = 14*72;
      }
    elsif ($page eq "letter")
      {
	$width[0] = 8.5*72;
	$width[1] = 11*72;
      }
    elsif ($page eq "note")
      {
	$width[0] = 7.5*72;
	$width[1] = 10*72;
      }
    else
      {
        &diag_output (sprintf (gettext ("%s: invalid page name: %s !!!!\n"),
                               $program_executable,
			       $page));
	$width[0] = 0;
	$width[1] = 0;
      }
    return @width;
}

#-----------------------------------------------------------------------
# Extract length value.
#-----------------------------------------------------------------------
sub length_value
{
    local ($length) = $_[0];
    $length =~ m/([0-9.,-]+)\s*([a-zA-Z]*)/;
    $length = $1;
    $length =~ s/,/./;
    return ($length);
}

#-----------------------------------------------------------------------
# Extract unit.
#-----------------------------------------------------------------------
sub length_unit
{
    local ($length) = $_[0];
    local ($unit) = $_[0];
    $length =~ m/([0-9.,-]+)\s*([a-zA-Z]*)/;
    $unit = $2;
    return ($unit);
}

#-----------------------------------------------------------------------
# Sum length.
#-----------------------------------------------------------------------
sub length_sum
{
    local ($length1) = $_[0];
    local ($length2) = $_[1];
    local ($unit1) = 0;
    local ($unit2) = 0;

    $length1 =~ m/([0-9.,-]+)\s*([a-zA-Z]*)/;
    $length1 = $1;
    $length1 =~ s/,/./;
    $unit1 = $2;

    $length2 =~ m/([0-9.,-]+)\s*([a-zA-Z]*)/;
    $length2 = $1;
    $length2 =~ s/,/./;
    $unit2 = $2;

    if ($unit1 eq "mm")
      {
        # ok
	;
      }
    elsif ($unit1 eq "cm")
      {
	$length1 = ($length1 * 10);
      }
    elsif ($unit1 eq "in")
      {
	$length1 = ($length1 * 25.4);
      }
    elsif ($unit1 eq "pt")
      {
	$length1 = (($length1 / 72.27) * 25.4);
      }
    elsif ($unit1 eq "bp")
      {
	$length1 = (($length1 / 72) * 25.4);
      }
    elsif ($unit1 eq "pc")
      {
	$length1 = ($length1 * 25.4 * 72/6);
      }

    if ($unit2 eq "mm")
      {
        # ok
	;
      }
    elsif ($unit2 eq "cm")
      {
	$length2 = ($length2 * 10);
      }
    elsif ($unit2 eq "in")
      {
	$length2 = ($length2 * 25.4);
      }
    elsif ($unit2 eq "pt")
      {
	$length2 = (($length2 / 72.27) * 25.4);
      }
    elsif ($unit2 eq "bp")
      {
	$length2 = (($length2 / 72) * 25.4);
      }
    elsif ($unit2 eq "pc")
      {
	$length2 = ($length2 * 25.4 * 72/6);
      }

    return (($length1+$length2) . "mm");
}

#-----------------------------------------------------------------------
# Subtract length.
#-----------------------------------------------------------------------
sub length_sub
{
    local ($length1) = $_[0];
    local ($length2) = $_[1];
    local ($unit1) = 0;
    local ($unit2) = 0;

    $length1 =~ m/([0-9.,-]+)\s*([a-zA-Z]*)/;
    $length1 = $1;
    $length1 =~ s/,/./;
    $unit1 = $2;

    $length2 =~ m/([0-9.,-]+)\s*([a-zA-Z]*)/;
    $length2 = $1;
    $length2 =~ s/,/./;
    $unit2 = $2;

    if ($unit1 eq "mm")
      {
        # ok
	;
      }
    elsif ($unit1 eq "cm")
      {
	$length1 = ($length1 * 10);
      }
    elsif ($unit1 eq "in")
      {
	$length1 = ($length1 * 25.4);
      }
    elsif ($unit1 eq "pt")
      {
	$length1 = (($length1 / 72.27) * 25.4);
      }
    elsif ($unit1 eq "bp")
      {
	$length1 = (($length1 / 72) * 25.4);
      }
    elsif ($unit1 eq "pc")
      {
	$length1 = ($length1 * 25.4 * 72/6);
      }

    if ($unit2 eq "mm")
      {
        # ok
	;
      }
    elsif ($unit2 eq "cm")
      {
	$length2 = ($length2 * 10);
      }
    elsif ($unit2 eq "in")
      {
	$length2 = ($length2 * 25.4);
      }
    elsif ($unit2 eq "pt")
      {
	$length2 = (($length2 / 72.27) * 25.4);
      }
    elsif ($unit2 eq "bp")
      {
	$length2 = (($length2 / 72) * 25.4);
      }
    elsif ($unit2 eq "pc")
      {
	$length2 = ($length2 * 25.4 * 72/6);
      }

    return (($length1 - $length2) . "mm");
}

#---------------------------------------------------------------
# Convert into millimeter without adding the unit of measure.
#
# &convert_to_mm_as_number (VALUE)
#
#---------------------------------------------------------------
sub convert_to_mm_as_number
{
    local ($value) = $_[0];
    local ($number) = 0;
    local ($unit) = "";

    $value =~ m/([0-9-]*) *(\S*)/;
    $number = $1;
    $unit = $2;

    if ($unit eq "pt")
      {
        return (1/72.27 * 25.4 * $number);
      }
    elsif ($unit eq "bp")
      {
        return (1/72 * 25.4 * $number);
      }
    elsif ($unit eq "in")
      {
        return (1 * 25.4 * $number);
      }
    elsif ($unit eq "pc")
      {
        return (1/6 * 25.4 * $number);
      }
    elsif ($unit eq "cm")
      {
        return (1 * 10 * $number);
      }
    elsif ($unit eq "mm")
      {
        return (1 * $number);
      }
    else
      {
        # problem
        return (0);
      }
}

#-----------------------------------------------------------------------
# Find a bounding box or page size inside a PS or EPS file and return
# x and y width in PostScript's points
#
# ps_x_y_size (PS_FILE_NAME) --> (X_WIDTH, Y_HEITGT)
#-----------------------------------------------------------------------
sub ps_x_y_size
{
    local ($file_name) = $_[0];
    local (@width) = ();
    local ($line) = "";
    local ($page) = "";

    open (PS_INPUT_FILE, "< $file_name");

    while ($line = <PS_INPUT_FILE>)
      {
	#---------------------------------------------------------------
	# Scan the file to find:
	#    %%BoundingBox: X_OFFSET Y_OFFSET X_MAX Y_MAX
	# or:
	# %%DocumentPaperSizes: PAPER_NAME
	#
	# If there is no more % at the first column, terminate
	# the search.
	#---------------------------------------------------------------

	if ($line !~ m/^\%/)
	  {
	    #-----------------------------------------------------------
	    # There are no more % comments, so close the loop.
	    #-----------------------------------------------------------
    	    last;
	  }


	if ($line =~ m/^\%\%BoundingBox:\s+([0-9+-]+)\s+([0-9+-]+)\s+([0-9+-]+)\s+([0-9+-]+)/)
	  {
	    $width[0] = $3 - $1;
	    $width[1] = $4 - $2;
	    last;
	  }
	elsif ($line =~ m/^\%\%DocumentPaperSizes:\s+([a-zA-Z0-9]+)/)
	  {
	    $page = $1;
	    @width = &page_size ($page);
	    last;
	  }    	
      }
    close (PS_INPUT_FILE);
    return @width;
}

#-----------------------------------------------------------------------
# Return the LaTeX name for the language system
#
# latex_language_name (LANG) --> NAME
#-----------------------------------------------------------------------
sub latex_language_name
{
    local ($lang) = lc ($_[0]);

    if ($lang eq "en")
      {
        return ("english");
      }
    elsif ($lang eq "eo")
      {
        return ("esperanto");
      }
    elsif ($lang eq "et")
      {
        return ("estonian");
      }
    elsif ($lang eq "fi")
      {
        return ("finnish");
      }
    elsif ($lang eq "fi")
      {
        return ("finnish");
      }
    elsif ($lang eq "fr")
      {
        return ("french");
      }
    elsif ($lang eq "gl")
      {
        return ("galician");
      }
    elsif ($lang eq "de")
      {
        return ("german");
      }
    elsif ($lang eq "el")
      {
        return ("greek");
      }
    elsif ($lang eq "he"
	   || $lang eq "iw")
      {
        return ("hebrew");
      }
    elsif ($lang eq "hu")
      {
        return ("hungarian");
      }
    elsif ($lang eq "ga")
      {
        return ("irish");
      }
    elsif ($lang eq "it")
      {
        return ("italian");
      }
    elsif ($lang eq "no")
      {
        return ("norsk");
      }
    elsif ($lang eq "pl")
      {
        return ("polish");
      }
    elsif ($lang eq "pt")
      {
        return ("portuguese");
      }
    elsif ($lang eq "ro")
      {
        return ("romanian");
      }
    elsif ($lang eq "ru")
      {
        return ("russian");
      }
    elsif ($lang eq "gd")
      {
        return ("scottish");
      }
    elsif ($lang eq "es")
      {
        return ("spanish");
      }
    elsif ($lang eq "sk")
      {
        return ("slovak");
      }
    elsif ($lang eq "sl")
      {
        return ("slovene");
      }
    elsif ($lang eq "sv")
      {
        return ("swedish");
      }
    elsif ($lang eq "tr")
      {
        return ("turkish");
      }
    elsif ($lang eq "uk")
      {
        return ("ukrainian");
      }
    else
      {
        return "";
      }
}


#-----------------------------------------------------------------------
# SGML post-SP elaboration.
#
# This function elaborate a post-SP output (the SGML parser), and
# take actions.
#
# &sgml_post_sp_elab (INPUT-POST-SP,
#                     TYPESETTING,
#                     TARGET,
#                     DRAFT,
#                     PAGE-NUMBERING,
#                     COMPACT,
#                     LONG,
#                     ORIGINAL_FILE_NAME,
#                     ROOT-NAME)
#
sub sgml_post_sp_elab
{
    #-------------------------------------------------------------------
    # Arguments.
    #-------------------------------------------------------------------
    local ($input_file)         = $_[0];
    local ($typesetting)        = $_[1];
    local ($target)             = $_[2];
    local ($draft)              = $_[3];
    local ($page_numbering)     = $_[4];
    local ($compact)            = $_[5];
    local ($long)               = $_[6];
    local ($original_file_name) = $_[7];
    local ($root_file_name)     = $_[8];
    local ($paper_width)        = $_[9];
    local ($paper_height)       = $_[10];

    #-------------------------------------------------------------------
    # More local variables.
    #-------------------------------------------------------------------

    # We need to define a reference for an input stream.
    # The choiche to use the same file names is just one way to
    # be shure to have ever different names.
    # We could use a random number, maybe.
    # This is useful for recursive call; for this function, there is no
    # need to use this technique; this is only a way to use uniform code.
    local ($input_stream) = "$input_file";

    # This is a reference for the current output stream.
    # This reference is used by the output() subfunction.
    local ($current_output_stream) = "";
    local ($current_output_stream_2) = "";

    # Output stack for controlling the output stream.
    @output_stack = ();
    @output_stack_2 = ();

    # The line read.
    local ($line) = "";

    # Parsed character text.
    local ($pcdata) = "";

    # An associative array to receive the SGML element attribute.
    %element_attribute = ();

    # HTML file extension. Default is ".html"
    $html_ext = ".html";

    #-------------------------------------------------------------------
    # Index
    #-------------------------------------------------------------------
    $index_entry_active = 0;
    $index_name = "";
    $index_emph = "";

    #-------------------------------------------------------------------
    # Local variables specific for the back-end composition process.
    #-------------------------------------------------------------------

    # Title counters.
    local ($h1section_absolute_counter) = 0;
    local ($intro) = 0;
    local ($tome) = 0;
    local ($part) = 0;
    local ($part_present) = 0;	# Boolean
    local ($chapter) = 0;
    local ($unnumbered_chapter) = 0;
    local ($appendix) = 0;
    local ($sect1) = 0;         
    local ($sect2) = 0;         
    local ($sect3) = 0;         
    local ($index) = 0;
    local ($unnumbered) = 0;
    local ($table) = 0;
    local ($absolute_table) = 0;
    local ($figure) = 0;
    local ($absolute_figure) = 0;
    local ($listing) = 0;
    local ($absolute_listing) = 0;
    
    # Current level:
    #       intro-h1                1
    #         intro-h2              2
    #           intro-h3            3
    #             intro-h4          4
    #   tome                       -1
    #     part                      0
    #       chapter-h1              1
    #         chapter-h2            2
    #           chapter-h3          3
    #             chapter-h4        4
    #       unnumbered-h1           1
    #         unnumbered-h2         2
    #           unnumbered-h3       3
    #             unnumbered-h4     4
    #       appendix-h1             1
    #         appendix-h2           2
    #           appendix-h3         3
    #             appendix-h4       4
    #       index-h1                1
    #         index-h2              2
    #           index-h3            3
    #             index-h4          4
    local ($current_level) = "";
    local ($current_level_by_number) = 9999;
    
    # Current document position:
    #   head
    #   intro
    #   body
    #   appendix
    #   index
    local ($document_position) = "";
        
    # Head informations.
    local ($document_description) = "";      # it can be empty.
    local ($document_keywords) = "";         # it can be empty.
    local ($current_language) = "";          # it can be empty.
    local ($document_language) = "";         # it can be empty.
    local ($tome_language) = "";             # it can be empty.
    local ($part_language) = "";             # it can be empty.
    local ($chapter_language) = "";          # it can be empty.
    local ($document_spacing) = "";          # it can be empty.
    local ($document_chapter_definition) = "";     # it can be empty.
    local ($document_part_definition) = "";        # it can be empty.
    local ($document_tome_definition) = "";        # it can be empty.
    local ($printed_font_size_title) = "";        # initially, must be empty.
    local ($printed_font_height_title) = "";        # initially, must be empty.
    local ($printed_font_size_tomeheading) = "";        # initially, must be empty.
    local ($printed_font_height_tomeheading) = "";        # initially, must be empty.
    local ($printed_font_size_h0) = "";        # initially, must be empty.
    local ($printed_font_height_h0) = "";        # initially, must be empty.
    local ($printed_font_size_h1) = "";        # initially, must be empty.
    local ($printed_font_height_h1) = "";        # initially, must be empty.
    local ($printed_font_size_h2) = "";        # initially, must be empty.
    local ($printed_font_height_h2) = "";        # initially, must be empty.
    local ($printed_font_size_h3) = "";        # initially, must be empty.
    local ($printed_font_height_h3) = "";        # initially, must be empty.
    local ($printed_font_size_h4) = "";        # initially, must be empty.
    local ($printed_font_height_h4) = "";        # initially, must be empty.
    local ($printed_font_size_normal)   = "10pt";
    local ($printed_font_height_normal) = "12pt";
    local ($printed_font_size_table) = "";        # initially, must be empty.
    local ($printed_font_height_table) = "";        # initially, must be empty.
    local ($printed_top_margin)         = "2.5cm";
    local ($printed_bottom_margin)      = "2.5cm";
    local ($printed_internal_margin)    = "3.5cm";
    local ($printed_body_width)         = "15cm";

    # HTML meta tags.
    #
    # $html_meta_tag[x][0]        name
    # $html_meta_tag[x][1]        lang
    # $html_meta_tag[x][2]        content
    #
    local ($html_meta_tag) = ();

    # HTML human readable file names.
    local ($html_human_readable_file_name_list) = ();

    # Titlepage.
    local ($title) = "";
    local (@subtitles) = ();
    local ($abstract) = "";
    local (@authors) = ();
    local ($date) = "";
    local ($edition) = "";
    local ($version) = "";
    local ($front_cover_picture_file) = "";
    local ($front_cover_picture_width) = "";
    local ($front_cover_picture_height) = "";
    local ($front_cover_text) = "";
    local ($back_cover_picture_file) = "";
    local ($back_cover_picture_width) = "";
    local ($back_cover_picture_height) = "";
    local ($back_cover_text) = "";
    local ($extra_text_before_legal) = "";
    local ($legal_text) = "";
    local ($dedications) = "";
    local ($extra_text_after_dedications) = "";

    # Table of contents.
    #
    # $contents_list[x][0]        level                 -1..4
    # $contents_list[x][1]        tome number
    # $contents_list[x][2]        part number
    # $contents_list[x][3]        chapter number                
    # $contents_list[x][4]        level-description     1.2.3
    # $contents_list[x][5]        title
    # $contents_list[x][6]        html page number
    # $contents_list[x][7]        intro number
    #
    local ($main_contents) = 0;         # True, False
    local ($main_contents_nopages) = 0; # True, False
    local ($contents_levels) = 0;       # chapters and sections per default (2) as defined inside the DTD.
    local ($contents_title) = "";       # the title to present the toc.
    local ($contents_counter) = -1;
    local ($last_contents_level) = 0;
    local (@contents_list) = ();

    # Standard cross reference list.
    #
    # $cross_reference_list[x][0]        level                  -1..4
    # $cross_reference_list[x][1]        tome number
    # $cross_reference_list[x][2]        part number
    # $cross_reference_list[x][3]        chapter number         
    # $cross_reference_list[x][4]        table absolute number          
    # $cross_reference_list[x][5]        figure absolute number         
    # $cross_reference_list[x][6]        level-description      1.2.3
    # $cross_reference_list[x][7]        title
    # $cross_reference_list[x][8]        table level-description
    # $cross_reference_list[x][9]        figure level-description
    # $cross_reference_list[x][10]       original anchor id
    # $cross_reference_list[x][11]       html page number
    # $cross_reference_list[x][12]       listing absolute number         
    # $cross_reference_list[x][13]       listing level-description
    #
    local (@cross_reference_list) = ();
    local ($cross_reference_counter) = -1;

    # Indexes.
    #
    # $index_list[x][0]        index name
    # $index_list[x][1]        emphasis
    # $index_list[x][2]        entry
    # $index_list[x][3]        array of links
    # $index_list[x][4]        array of html page numbers
    # $index_list[x][5]        array of level-descriptions
    # $index_list[x][6]        entry with formatting
    # $index_list[x][7]        array of tomes
    # $index_list[x][8]        array of parts
    # $index_list[x][9]        array of chapters (absolute)
    #
    local ($index_entry_counter) = 0;
    local (@index_list) = ();

    # Headers title informations.
    local ($tome_heading_title) = "";
    local ($tome_heading_id) = "";
    local ($h0_title) = "";
    local ($h0_id) = "";
    local ($h1_title) = "";
    local ($h1_id) = "";
    local ($h2_title) = "";
    local ($h2_id) = "";
    local ($h3_title) = "";
    local ($h3_id) = "";
    local ($h4_title) = "";
    local ($h4_id) = "";

    # Last useful information.
    local ($last_heading_title) = "";
    local ($last_anchor_id) = "";
    local ($last_table_id) = "";
    local ($last_figure_id) = "";
    local ($last_listing_id) = "";
    local ($last_normal_uri) = "";
    local ($last_quote_uri) = "";
    local ($last_html_page_title) = "";

    # Table and figures.
    local ($table_caption) = "";
    local ($figure_caption) = "";
    local ($listing_caption) = "";
    local ($table_position) = "";
    local ($figure_position) = "";
    local ($listing_position) = "";
    local ($figure_separation) = "";
    local ($listing_separation) = "";

    # Table columns width.
    #
    # $table_columns_width[x][0]        first column width
    # $table_columns_width[x][1]        second column width
    # ...
    # $table_columns_width[x][n]        (n+1)th column width
    #
    local (@table_columns_width) = ();
    local ($table_columns_width_counter) = -1;
    local ($table_column_counter) = -1;

    # Workinfo list.
    #
    # $workinfo_list[x][0]        work name
    # $workinfo_list[x][1]        work license
    # $workinfo_list[x][2]        work license text
    # $workinfo_list[x][3]        work notes
    #
    local (@workinfo_list)         = ();
    local ($workinfo_name)         = "";
    local ($workinfo_license)      = "";
    local ($workinfo_license_text) = "";

    # No modificable sections.
    #
    # $nomod_sections_list[x][0]    level         -1..4
    # $nomod_sections_list[x][1]    description   section 1.2
    # $nomod_sections_list[x][2]    title
    # $nomod_sections_list[x][3]    html page
    #
    local (@nomod_sections_list)      = ();
    local ($nomod_sections_counter)   = -1;

    # doc info list.
    #
    # $docinfo_list[x][0]       level           -1..4
    # $docinfo_list[x][1]       description     section 1.2
    # $docinfo_list[x][2]       title
    # $docinfo_list[x][3]       origin note
    # $docinfo_list[x][4]       revision note
    # $docinfo_list[x][5]       notes
    # $docinfo_list[x][6][y][0] revision date           OBSOLETE
    # $docinfo_list[x][6][y][1] revision author         OBSOLETE
    # $docinfo_list[x][6][y][2] revision email          OBSOLETE
    # $docinfo_list[x][6][y][3] revision description    OBSOLETE
    # $docinfo_list[x][7]       html page number
    # $docinfo_list[x][8][z]    z-th author
    #
    # This array, is used directly, without the help of a specific
    # function!
    #
    local ($docinfo_list)        = ();
    local ($docinfo_counter)     = -1;

    # PS handling.
    $ps_picture_counter          = 0;

    # HTML handling.
    $html_page_counter           = 0;
    $html_max_page               = 0;
    $html_back_cover_page        = 0;
    $html_picture_counter        = 0;
    $html_footnote               = "";
    @html_footnote_list          = ();
    @html_page_tome_link_list    = ();
    @html_page_part_link_list    = ();

    # $html_page_fixed_link_list[x][0]        html page number
    # $html_page_fixed_link_list[x][1]        link description
    @html_page_fixed_link_list   = ();

    # Preformatted width.
    $preformatted_column_width   = "";  # Usually, default is 80.

    # Every section header start a "{\samapage" that must be closed with a "}".
    $header_to_be_closed   = 0;	# boolean
    $next_element_after_header_to_be_closed   = "";	# element name
    $next_element_after_header_to_be_closed_nest_level = 0; # the same element inside a nest

    #-------------------------------------------------------------------
    # This is for SHEETH1 and SLIDEH1 to be kept on a page.
    #-------------------------------------------------------------------
    local ($slide_to_be_closed)   = 0;	# boolean

    #-------------------------------------------------------------------
    # Current tabular informations.
    #-------------------------------------------------------------------
    local ($current_tabular_border) = "0";
    local (@current_tabular_columnfractions_list) = ();
    local ($current_tabular_column_index) = 0;

    #-------------------------------------------------------------------
    # Language list.
    #-------------------------------------------------------------------
    local (@language_list) = "()";

    #-------------------------------------------------------------------
    # Indented text.
    #-------------------------------------------------------------------
    local ($text_indent_level) = 0;
    local ($floating_block) = 0;

    #-------------------------------------------------------------------
    # Sub functions.
    #-------------------------------------------------------------------

    #-------------------------------------------------------------------
    # This function is like print, but may redirect output to a stack
    # waiting to have more data.
    #
    # &output ( STRING );
    #
    sub output
    {
        local ($output_line) = $_[0];

        if ($#output_stack >= 0)
          {
            # Output must be added to the top element of the stack.
            $output_stack[$#output_stack] = $output_stack[$#output_stack]
                                            . $output_line;
          }
        else
          {
            # Output is sent to the output stream.
            print $current_output_stream ($output_line);
          }
    }

    #-------------------------------------------------------------------
    # This function is like print, but may redirect output to a stack
    # waiting to have more data.
    #
    # &output_2 (STRING);
    #
    sub output_2
    {
        local ($output_line) = $_[0];

        if ($#output_stack_2 >= 0)
          {
            # Output must be added to the top element of the stack.
            $output_stack_2[$#output_stack_2]
              = $output_stack_2[$#output_stack_2]
                . $output_line;
          }
        else
          {
            # Output is sent to the output stream.
            print $current_output_stream_2 ($output_line);
          }
    }

    #-------------------------------------------------------------------
    # Direct the output stream into another stack level.
    #
    # &push_output ();
    #
    sub push_output
    {
        # Add one empty element at the top of the stack.
        $output_stack[$#output_stack+1]     = "";
    }

    #-------------------------------------------------------------------
    # Direct the output stream into another stack level.
    #
    # &push_output_2 ();
    #
    sub push_output_2
    {
        # Add one empty element at the top of the stack.
        $output_stack_2[$#output_stack_2+1] = "";
    }

    #-------------------------------------------------------------------
    # Extract the last stack level.
    #
    # &pop_output ();
    #
    sub pop_output
    {
        # Check if it is possible.
        if ($#output_stack >= 0)
          {
            # Extract one element at the top of the stack.
            local ($output_line) = $output_stack[$#output_stack];
            $#output_stack--;
            return ($output_line);
          }
        else
          {
            # The stack is empty.
            return ("");
          }
    }

    #-------------------------------------------------------------------
    # Extract the last stack level.
    #
    # &pop_output_2 ();
    #
    sub pop_output_2
    {
        # Check if it is possible.
        if ($#output_stack_2 >= 0)
          {
            # Extract one element at the top of the stack.
            local ($output_line) = $output_stack_2[$#output_stack_2];
            $#output_stack_2--;
            return ($output_line);
          }
        else
          {
            # The stack is empty.
            return ("");
          }
    }

    #-------------------------------------------------------------------
    # Translate some definitions into different languages.
    #
    # We cannot use gettext(), because this is controlled by a
    # command inside the text, and we cannot change the language
    # from here. The text may be written in a different language
    # than the actual locale configuration.
    #-------------------------------------------------------------------
    sub tome_def
    {
        # This definition might be modified inside the SGML source:
        if ($document_tome_definition ne "")
          {
            return ($document_tome_definition);
          }
        else
          {  
            if ($current_language eq "it")
              {
                return ("tomo");
              }
            else
              {
                return ("tome");
              }
          }  
    }
    #-------------------------------------------------------------------
    sub part_def
    {
        # This definition might be modified inside the SGML source:
        if ($document_part_definition ne "")
          {
            return ($document_part_definition);
          }
        else
          {  
            if ($current_language eq "it")
              {
                return ("parte");
              }
            else
              {
                return ("part");
              }
          }  
    }
    #-------------------------------------------------------------------
    sub intro_def
    {
        if ($current_language eq "it")
          {
            return "introduzione";
          }
        else
          {
            return "introduction";
          }
    }
    #-------------------------------------------------------------------
    sub chapter_def
    {
        # This definition might be modified inside the SGML source:
        if ($document_chapter_definition ne "")
          {
            return ($document_chapter_definition);
          }
        else
          {  
            if ($current_language eq "it")
              {
                return ("capitolo");
              }
            else
              {
                return ("chapter");
              }
          }  
    }
    #-------------------------------------------------------------------
    sub presentation_slide_def
    {
        if ($current_language eq "it")
          {
            return "diapositiva";
          }
        else
          {
            return "slide";
          }
    }
    #-------------------------------------------------------------------
    sub summary_sheet_def
    {
        if ($current_language eq "it")
          {
            return "scheda riassuntiva";
          }
        else
          {
            return "summary sheet";
          }
    }
    #-------------------------------------------------------------------
    sub appendix_def
    {
        if ($current_language eq "it")
          {
            return "appendice";
          }
        else
          {
            return "appendix";
          }
    }
    #-------------------------------------------------------------------
    sub appendixes_def
    {
        if ($current_language eq "it")
          {
            return "appendici";
          }
        else
          {
            return "appendixes";
          }
    }
    #-------------------------------------------------------------------
    sub section_def
    {
        if ($current_language eq "it")
          {
            return "sezione";
          }
        else
          {
            return "section";
        }
    }
    #-------------------------------------------------------------------
    sub subsection_def
    {
        if ($current_language eq "it")
          {
            return "sottosezione";
          }
        else
          {
            return "subsection";
          }
    }
    #-------------------------------------------------------------------
    sub subsubsection_def
    {
        if ($current_language eq "it")
          {
            return "sotto-sottosezione";
          }
        else
          {
            return "sub-subsection";
          }
    }
    #-------------------------------------------------------------------
    sub contents_def
    {
        if ($current_language eq "it")
          {
            return "indice generale";
          }
        else
          {
            return "contents";
          }
    }
    #-------------------------------------------------------------------
    sub index_def
    {
        if ($current_language eq "it")
          {
            return "indice analitico";
          }
        else
          {
            return "index";
          }
    }
    #-------------------------------------------------------------------
    sub page_def
    {
        if ($current_language eq "it")
          {
            return "pagina";
          }
        else
          {
            return "page";
          }
    }
    #-------------------------------------------------------------------
    sub short_page_def
    {
        if ($current_language eq "it")
          {
            return "pag.";
          }
        else
          {
            return "p.";
          }
    }
    #-------------------------------------------------------------------
    sub command_continue_on_the_next_line_def
    {
        if ($current_language eq "it")
          {
            return "segue";
          }
        else
          {
            return "continue";
          }
    }

    #-------------------------------------------------------------------
    sub next_page_def
    {
        if ($current_language eq "it")
          {
            return "successivo";
          }
        else
          {
            return "next";
          }
    }

    #-------------------------------------------------------------------
    sub previous_page_def
    {
        if ($current_language eq "it")
          {
            return "precedente";
          }
        else
          {
            return "previous";
          }
    }

    #-------------------------------------------------------------------
    sub top_page_def
    {
        if ($current_language eq "it")
          {
            return "inizio";
          }
        else
          {
            return "top";
          }
    }

    #-------------------------------------------------------------------
    sub last_page_def
    {
        if ($current_language eq "it")
          {
            return "fine";
          }
        else
          {
            return "last";
          }
    }
    #-------------------------------------------------------------------
    sub may_link_to_human_readable_name_def
    {
        if ($current_language eq "it")
          {
            return ("Dovrebbe essere possibile fare riferimento a questa "
                    . "pagina anche con il nome ");
          }
        else
          {
            return ("It should be possibile to link to this page also "
                    . "with the name ");
          }
    }
    #-------------------------------------------------------------------
    sub picture_def
    {
        if ($current_language eq "it")
          {
            return ("immagine");
          }
        else
          {
            return ("picture");
          }
    }

    #-------------------------------------------------------------------
    # Create the string corresponding to the section number.
    #-------------------------------------------------------------------
    sub current_section_number
    {
        local ($section_number_string) = "";

        if ($current_level eq "intro-h1")
          {
            $section_number_string = "i"
                                     . $intro;
          }
        elsif ($current_level eq "intro-h2")
          {
            $section_number_string = "i"
                                     . $intro
                                     . "."
                                     . $sect1;
          }
        elsif ($current_level eq "intro-h3")
          {
            $section_number_string = "i"
                                     . $intro
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2;
          }
        elsif ($current_level eq "intro-h4")
          {
            $section_number_string = "i"
                                     . $intro
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2
                                     . "."
                                     . $sect3;
          }
        elsif ($current_level eq "tome")
          {
            $section_number_string = uc &integer_to_roman ($tome);
          }
        elsif ($current_level eq "part")
          {
            $section_number_string = lc &integer_to_roman ($part);
          }
        elsif ($current_level eq "chapter-h1")
          {
            $section_number_string = $chapter;
          }
        elsif ($current_level eq "chapter-h2")
          {
            $section_number_string = $chapter
                                     . "."
                                     . $sect1;
          }
        elsif ($current_level eq "chapter-h3")
          {
            $section_number_string = $chapter
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2;
          }
        elsif ($current_level eq "chapter-h4")
          {
            $section_number_string = $chapter
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2
                                     . "."
                                     . $sect3;
          }
        elsif ($current_level eq "unnumbered-h1")
          {
            $section_number_string = "u"
                                     . $unnumbered_chapter;
          }
        elsif ($current_level eq "unnumbered-h2")
          {
            $section_number_string = "u"
                                     . $intro
                                     . "."
                                     . $sect1;
          }
        elsif ($current_level eq "unnumbered-h3")
          {
            $section_number_string = "i"
                                     . $unnumbered_chapter
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2;
          }
        elsif ($current_level eq "unnumbered-h4")
          {
            $section_number_string = "i"
                                     . $unnumbered_chapter
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2
                                     . "."
                                     . $sect3;
          }
        elsif ($current_level eq "appendix-h1")
          {
            $section_number_string = uc &integer_to_alphabet ($appendix);
          }
        elsif ($current_level eq "appendix-h2")
          {
            $section_number_string = uc &integer_to_alphabet ($appendix)
                                     . "."
                                     . $sect1;
          }
        elsif ($current_level eq "appendix-h3")
          {
            $section_number_string = uc &integer_to_alphabet ($appendix)
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2;
          }
        elsif ($current_level eq "appendix-h4")
          {
            $section_number_string = uc &integer_to_alphabet ($appendix)
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2
                                     . "."
                                     . $sect3;
          }
        elsif ($current_level eq "index-h1")
          {
            $section_number_string = "x"
                                     . $index;
          }
        elsif ($current_level eq "index-h2")
          {
            $section_number_string = "x"
                                     . $index
                                     . "."
                                     . $sect1;
          }
        elsif ($current_level eq "index-h3")
          {
            $section_number_string = "x"
                                     . $index
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2;
          }
        elsif ($current_level eq "index-h4")
          {
            $section_number_string = "x"
                                     . $index
                                     . "."
                                     . $sect1
                                     . "."
                                     . $sect2
                                     . "."
                                     . $sect3;
          }
        else
          {
            $section_number_string = "##unknown-level##";
          }

        return $section_number_string;
    }

    #-------------------------------------------------------------------
    # Create the string corresponding to the definition and section
    # number.
    #-------------------------------------------------------------------
    sub current_section_number_complete
    {
        local ($section_number_complete_string) = "";

        if ($current_level eq "intro-h1"
            || $current_level eq "intro-h2"
            || $current_level eq "intro-h3"
            || $current_level eq "intro-h4")
          {
            $section_number_complete_string
              = &intro_def
                . " "
                . &current_section_number ();
          }
        elsif ($current_level eq "tome")
          {
            $section_number_complete_string
              = &tome_def ()
                . " "
                . &current_section_number ();
          }
        elsif ($current_level eq "part")
          {
            $section_number_complete_string
              = &part_def ()
                . " "
                . &current_section_number ();
          }
        elsif ($current_level eq "chapter-h1")
          {
            $section_number_complete_string
              = &chapter_def ()
                . " "
                . &current_section_number ();
          }
        elsif ($current_level eq "chapter-h2"
               || $current_level eq "chapter-h3"
               || $current_level eq "chapter-h4")
          {
            $section_number_complete_string
              = &section_def ()
                . " "
                . &current_section_number ();
          }
        elsif ($current_level eq "unnumbered-h1"
            || $current_level eq "unnumbered-h2"
            || $current_level eq "unnumbered-h3"
            || $current_level eq "unnumbered-h4")
          {
            $section_number_complete_string
              = &section_def
                . " "
                . &current_section_number ();
          }
        elsif ($current_level eq "appendix-h1"
               || $current_level eq "appendix-h2"
               || $current_level eq "appendix-h3"
               || $current_level eq "appendix-h4")
          {
            $section_number_complete_string
              = &appendix_def
                . " "
                . &current_section_number ();
          }
        elsif ($current_level eq "index-h1"
               || $current_level eq "index-h2"
               || $current_level eq "index-h3"
               || $current_level eq "index-h4")
          {
            $section_number_complete_string
              = &index_def
                . " "
                . &current_section_number ();
          }
        else
          {
            $section_number_complete_string = "##unknown-section##";
          }

        return $section_number_complete_string;
    }

    #-------------------------------------------------------------------
    # Create the string corresponding to the table number.
    #-------------------------------------------------------------------
    sub current_table_number
    {
        local ($table_number_string) = "";

        if ($current_level eq "intro-h1"
            || $current_level eq "intro-h2"
            || $current_level eq "intro-h3"
            || $current_level eq "intro-h4")
          {
            $table_number_string = "i"
                                     . $intro
                                     . "."
                                     . $table;
          }
        elsif ($current_level eq "tome")
          {
            $table_number_string = uc &integer_to_roman ($tome)
                                   . "."
                                   . $table;
          }
        elsif ($current_level eq "part")
          {
            $table_number_string = lc &integer_to_roman ($part)
                                   . "."
                                   . $table;
          }
        elsif ($current_level eq "chapter-h1"
               || $current_level eq "chapter-h2"
               || $current_level eq "chapter-h3"
               || $current_level eq "chapter-h4")
          {
            $table_number_string = $chapter
                                   . "."
                                   . $table;
          }
        elsif ($current_level eq "unnumbered-h1"
            || $current_level eq "unnumbered-h2"
            || $current_level eq "unnumbered-h3"
            || $current_level eq "unnumbered-h4")
          {
            $table_number_string = "u"
                                     . $chapter_unnumbered
                                     . "."
                                     . $table;
          }
        elsif ($current_level eq "appendix-h1"
               || $current_level eq "appendix-h2"
               || $current_level eq "appendix-h3"
               || $current_level eq "appendix-h4")
          {
            $table_number_string = uc &integer_to_alphabet ($appendix)
                                   . "."
                                   . $table;
          }
        elsif ($current_level eq "index-h1"
               || $current_level eq "index-h2"
               || $current_level eq "index-h3"
               || $current_level eq "index-h4")
          {
            $table_number_string = "x"
                                   . $index
                                   . "."
                                   . $table;
          }
        else
          {
            $table_number_string = "0"
                                   . $absolute_table;
          }

        return $table_number_string;
    }

    #-------------------------------------------------------------------
    # Create the string corresponding to the figure number.
    #-------------------------------------------------------------------
    sub current_figure_number
    {
        local ($figure_number_string) = "";

        if ($current_level eq "intro-h1"
            || $current_level eq "intro-h2"
            || $current_level eq "intro-h3"
            || $current_level eq "intro-h4")
          {
            $figure_number_string = "i"
                                     . $intro
                                     . "."
                                     . $figure;
          }
        elsif ($current_level eq "tome")
          {
            $figure_number_string = uc &integer_to_roman ($tome)
                                   . "."
                                   . $figure;
          }
        elsif ($current_level eq "part")
          {
            $figure_number_string = lc &integer_to_roman ($part)
                                   . "."
                                   . $figure;
          }
        elsif ($current_level eq "chapter-h1"
               || $current_level eq "chapter-h2"
               || $current_level eq "chapter-h3"
               || $current_level eq "chapter-h4")
          {
            $figure_number_string = $chapter
                                   . "."
                                   . $figure;
          }
        elsif ($current_level eq "unnumbered-h1"
               || $current_level eq "unnumbered-h2"
               || $current_level eq "unnumbered-h3"
               || $current_level eq "unnumbered-h4")
          {
            $figure_number_string = "u"
                                     . $chapter_unnumbered
                                     . "."
                                     . $figure;
          }
        elsif ($current_level eq "appendix-h1"
               || $current_level eq "appendix-h2"
               || $current_level eq "appendix-h3"
               || $current_level eq "appendix-h4")
          {
            $figure_number_string = uc &integer_to_alphabet ($appendix)
                                   . "."
                                   . $figure;
          }
        elsif ($current_level eq "index-h1"
               || $current_level eq "index-h2"
               || $current_level eq "index-h3"
               || $current_level eq "index-h4")
          {
            $figure_number_string = "x"
                                   . $index
                                   . "."
                                   . $figure;
          }
        else
          {
            $figure_number_string = "0"
                                   . $absolute_figure;
          }

        return $figure_number_string;
    }

    #-------------------------------------------------------------------
    # Create the string corresponding to the listing number.
    #-------------------------------------------------------------------
    sub current_listing_number
    {
        local ($listing_number_string) = "";

        if ($current_level eq "intro-h1"
            || $current_level eq "intro-h2"
            || $current_level eq "intro-h3"
            || $current_level eq "intro-h4")
          {
            $listing_number_string = "i"
                                     . $intro
                                     . "."
                                     . $listing;
          }
        elsif ($current_level eq "tome")
          {
            $listing_number_string = uc &integer_to_roman ($tome)
                                   . "."
                                   . $listing;
          }
        elsif ($current_level eq "part")
          {
            $listing_number_string = lc &integer_to_roman ($part)
                                   . "."
                                   . $listing;
          }
        elsif ($current_level eq "chapter-h1"
               || $current_level eq "chapter-h2"
               || $current_level eq "chapter-h3"
               || $current_level eq "chapter-h4")
          {
            $listing_number_string = $chapter
                                   . "."
                                   . $listing;
          }
        elsif ($current_level eq "unnumbered-h1"
               || $current_level eq "unnumbered-h2"
               || $current_level eq "unnumbered-h3"
               || $current_level eq "unnumbered-h4")
          {
            $listing_number_string = "u"
                                     . $chapter_unnumbered
                                     . "."
                                     . $listing;
          }
        elsif ($current_level eq "appendix-h1"
               || $current_level eq "appendix-h2"
               || $current_level eq "appendix-h3"
               || $current_level eq "appendix-h4")
          {
            $listing_number_string = uc &integer_to_alphabet ($appendix)
                                   . "."
                                   . $listing;
          }
        elsif ($current_level eq "index-h1"
               || $current_level eq "index-h2"
               || $current_level eq "index-h3"
               || $current_level eq "index-h4")
          {
            $listing_number_string = "x"
                                   . $index
                                   . "."
                                   . $listing;
          }
        else
          {
            $listing_number_string = "0"
                                   . $absolute_listing;
          }

        return $listing_number_string;
    }

    #---------------------------------------------------------------
    # Sort workinfo array, with bubble sort algorithm.
    #
    # &sort_workinfo_list (LOW_ELEMENT, UP_ELEMENT)
    #
    sub sort_workinfo_list
    {
        local ($a) = $_[0];        # lower index
        local ($z) = $_[1];        # upper index 

        local ($k) = 0;
        local ($exchange) = "";

        # $workinfo_list[x][0]        work name
        # $workinfo_list[x][1]        work license
        # $workinfo_list[x][2]        work license text
        # $workinfo_list[x][3]        work notes
        #
        if ($a < $z)
          {
            # Scan the array to place the right element inside $a
            # index.
            for ($k = $a+1; $k <= $z; $k++)
              {
                if (uc ($workinfo_list[$k][0]) lt uc ($workinfo_list[$a][0]))
                  {
                    # Exchange sub-arrays.
                    $exchange          = $workinfo_list[$k];
                    $workinfo_list[$k] = $workinfo_list[$a];
                    $workinfo_list[$a] = $exchange;
                  }
              }
            &sort_workinfo_list ($a+1, $z);
          }
    }

    #---------------------------------------------------------------
    # Delete double items inside workinfo array.
    #
    # &delete_doubles_workinfo_list ()
    #
    sub delete_doubles_workinfo_list
    {
        local ($i) = 0;        # scan index

        local ($last_work_name) = "";

        # $workinfo_list[x][0]        work name
        # $workinfo_list[x][1]        work license
        # $workinfo_list[x][2]        work license text
        # $workinfo_list[x][3]        work notes
        #

        # Scan the array to find duplicates.
        for ($i = 0; $i <= $#workinfo_list; $i++)
          {
            if ((uc ($workinfo_list[$i][0]) eq $last_work_name)
                && $workinfo_list[$i][0] ne "")
              {
                # Eliminate previous element (the last is the best).
                &diag_output (sprintf (gettext ("%s: work name %s already declared\n"),
                                       $program_executable, $last_work_name));
                splice (@workinfo_list, ($i-1), 1);
                # $i index must be decremented as it will incremented
                # anyway from the for loop. In fact, $i should remain
                # as is, within the next loop.
                $i--;
              }
            else
              {
                $last_work_name = uc ($workinfo_list[$i][0]);
              }
          }
    }


    #---------------------------------------------------------------
    # Sort index array, only one index name, with bubble sort
    # algorithm.
    #
    # $index_list[x][0]        index name
    # $index_list[x][1]        emphasis
    # $index_list[x][2]        entry
    # $index_list[x][3]        array of links
    # $index_list[x][4]        array of html page numbers
    # $index_list[x][5]        array of level-descriptions
    # $index_list[x][6]        entry with formatting
    # $index_list[x][7]        array of tomes
    # $index_list[x][8]        array of parts
    # $index_list[x][9]        array of chapters (absolute)
    #
    # &sort_index_list (INDEX_NAME ,LOW_ELEMENT, UP_ELEMENT)
    #
    sub sort_index_list
    {
        local ($name) = $_[0];        # analytic index name
        local ($a)    = $_[1];        # lower index
        local ($z)    = $_[2];        # upper index 

        local ($k) = 0;
        local ($exchange) = "";

        if ($a < $z)
          {
            if ($index_list[$a][0] eq $name)
              {
                # Ok, this is still the same analytic index name.

                # Scan the array to place the right element inside $a
                # index.
                for ($k = $a+1; $k <= $z; $k++)
                  {
                    if ($index_list[$k][0] ne $name)
                      {
                        next;
                      }
                    elsif (uc ($index_list[$k][2]) lt uc ($index_list[$a][2]))
                      {
                        # Exchange sub-arrays.
                        $exchange          = $index_list[$k];
                        $index_list[$k]    = $index_list[$a];
                        $index_list[$a]    = $exchange;
                      }
                  }
                &sort_index_list ($name, $a+1, $z);
              }
            else
              {
                # Try next element.
                &sort_index_list ($name, $a+1, $z);
              }
          }
    }

    #---------------------------------------------------------------
    # Sort index array, completely, with bubble sort algorithm.
    #
    # $index_list[x][0]        index name
    # $index_list[x][1]        emphasis
    # $index_list[x][2]        entry
    # $index_list[x][3]        array of links
    # $index_list[x][4]        array of html page numbers
    # $index_list[x][5]        array of level-descriptions
    # $index_list[x][6]        entry with formatting
    # $index_list[x][7]        array of tomes
    # $index_list[x][8]        array of parts
    # $index_list[x][9]        array of chapters (absolute)
    #
    # &sort_index_list_completely (LOW_ELEMENT, UP_ELEMENT)
    #
    sub sort_index_list_completely
    {
        local ($a)    = $_[0];        # lower index
        local ($z)    = $_[1];        # upper index 

        local ($k) = 0;
        local ($exchange) = "";

        if ($a < $z)
          {
            # Scan the array to place the right element inside $a
            # index.
            for ($k = $a+1; $k <= $z; $k++)
              {
                if ((uc ($index_list[$k][0]) lt uc ($index_list[$a][0]))
	    	    || (uc ($index_list[$k][0]) eq uc ($index_list[$a][0])
		        && uc ($index_list[$k][2]) lt uc ($index_list[$a][2])))
                  {
                    # Exchange sub-arrays.
                    $exchange          = $index_list[$k];
                    $index_list[$k]    = $index_list[$a];
                    $index_list[$a]    = $exchange;
                  }
              }
            &sort_index_list_completely ($a+1, $z);
          }
    }

    #---------------------------------------------------------------
    # Change from 12345 to 12 345
    #
    # &integer_to_string (INTEGER_TO_BE_SPLITTED, SEPARATION_STRING)
    #
    sub integer_to_string
    {
        local ($integer) = $_[0];
        local ($sep) = $_[1];
        local ($upper) = "";
        local ($lower) = "";

        if ($integer eq "")
          {
            # No more upper decomposition.
            return ("");
          }
        elsif ($integer =~ m/^[0-9]{1,3}$/)
          {
            # No more upper decomposition.
            return ($integer);
          }
        elsif ($integer =~ m/^([0-9]+)([0-9][0-9][0-9])$/)
          {
            # Split recusively.
            $upper = $1;
            $lower = $2;
            return (&integer_to_string ($upper, $sep) . $sep . $lower);
          }
        else
          {
            # There is a mistake. Return as-is.
            return ($integer);
          }
    }

    #---------------------------------------------------------------
    # Change from 12345 to 123 45
    #
    # &decimal_to_string (DECIMAL_TO_BE_SPLITTED, SEPARATION_STRING)
    #
    sub decimal_to_string
    {
        local ($decimal) = $_[0];
        local ($sep) = $_[1];
        local ($upper) = "";
        local ($lower) = "";
        if ($decimal eq "")
          {
            # No more lower decomposition.
            return ("");
          }
        elsif ($decimal =~ m/^[0-9]{1,3}$/)
          {
            # No more upper decomposition.
            return ($decimal);
          }
        elsif ($decimal =~ m/^([0-9][0-9][0-9])([0-9]+)$/)
          {
            # Split recusively.
            $upper = $1;
            $lower = $2;
            return ($upper . $sep . &decimal_to_string ($lower, $sep));
          }
        else
          {
            # There is a mistake. Return as-is.
            return ($decimal);
          }
    }

    #---------------------------------------------------------------
    # Generate a human readable unique file name, using the
    # array @human_readable_file_name_list.
    #
    # &human_readable_file_name (STARTING_NAME)
    #
    sub human_readable_file_name
    {
        local ($starting_name) = $_[0];
        local ($adapted_name) = "";
        local ($extention_counter) = 0;
        local ($extention) = "";
        local ($max_name_length) = 60;
        local ($n) = 0;

        # Join multiple lines.
        $adapted_name = $starting_name;
        $adapted_name =~ s/\n/ /ms;

        # To lower case.
        $adapted_name = lc ($adapted_name);

        # Eliminate HTML elements.
        $adapted_name =~ s/<(.*?)>//g;
        
        # Adapt the rest.
        $adapted_name =~ tr/a-z0-9/\_/c;

        # Eliminate too mani "_".
        $adapted_name =~ s/\_+/_/g;
        $adapted_name =~ s/^\_//;
        $adapted_name =~ s/_$//;

	# Reduce to 60 characters max.
	# It must be done because Joliet file system cannot
	# distinguish names after the first 64 characters.
        $adapted_name =~ m/^(.{1,$max_name_length})/;
        $adapted_name = $1;

        # Scan @human_readable_file_name_list.
        for ($n = 0 ; $n <= $#human_readable_file_name_list ; $n++)
          { 
            if ($human_readable_file_name_list[$n]
                eq ($adapted_name . $extention))
              {
                # This name already exists.
                $extention_counter++;
                $extention = "_" . $extention_counter;

                # Next loop.
                next;
              }
          }

        # Finally add the name.
        $#human_readable_file_name_list++;
        $human_readable_file_name_list[$#human_readable_file_name_list]
          = $adapted_name . $extention;

        return ($adapted_name . $extention);
    }

    #---------------------------------------------------------------
    # Convert into pixel, meant to be 2 times the typographical
    # point.
    #
    # &convert_to_pixel (VALUE)
    #
    sub convert_to_pixel
    {
        local ($value) = $_[0];
        local ($number) = 0;
        local ($unit) = "";

        $value =~ m/([0-9]*) *(\S*)/;
        $number = $1;
        $unit = $2;

        if ($number <= 0)
          {
            # problem
            return (0);
          }
        elsif ($unit eq "pt")
          {
            return (int (2*($number * (72/72.27))));
          }
        elsif ($unit eq "bp")
          {
            return (int (2*($number * 1)));
          }
        elsif ($unit eq "in")
          {
            return (int (2*($number * 72)));
          }
        elsif ($unit eq "pc")
          {
            return (int (2*($number * 72/6)));
          }
        elsif ($unit eq "cm")
          {
            return (int (2*(($number / 2.54) * 72)));
          }
        elsif ($unit eq "mm")
          {
            return (int (2*(($number / 25.4) * 72)));
          }
        else
          {
            # problem
            return (0);
          }
    }

    #-------------------------------------------------------------------
    # Literal environment transformation for LaTeX.
    #-------------------------------------------------------------------
    sub latex_literal_step_0 {
        local ($pre) = $_[0];

        #---------------------------------------------------------------
	# Change "-" into "\mbox{\texttt{-}" to avoid LaTeX reducing
	# it.
	#---------------------------------------------------------------
        $pre =~ s/-/\\mbox{\\texttt{-}}/mg;

        #---------------------------------------------------------------
        # Data is returned.
	#---------------------------------------------------------------
        return ($pre);
    }
    sub latex_literal_step_1 {
        local ($pre) = $_[0];

	#---------------------------------------------------------------
	# Change "," into ",{}".
	#---------------------------------------------------------------
        $pre =~ s/,/,\{\}/mg;

	#---------------------------------------------------------------
        # Change "'" into "'{}".
	#---------------------------------------------------------------
        $pre =~ s/\'/\'\{\}/mg;

	#---------------------------------------------------------------
        # Data is returned.
	#---------------------------------------------------------------
        return ($pre);
    }
    sub latex_literal_step_2 {
        local ($pre) = $_[0];

	#---------------------------------------------------------------
        # Change new line code into \newline.
	#---------------------------------------------------------------
        $pre =~ s/$/\\newline/mg;

	#---------------------------------------------------------------
        # Delete last \newline.
	#---------------------------------------------------------------
        $pre =~ s/\\newline$//;

	#---------------------------------------------------------------
        # Change the beguinning of every line.
	#---------------------------------------------------------------
        $pre =~ s/^/\\nopagebreak[1]\\hspace{0pt}/mg;

	#---------------------------------------------------------------
        # Data is returned.
	#---------------------------------------------------------------
        return ($pre);

    }
    sub latex_literal_step_3 {
        local ($pre) = $_[0];

	#---------------------------------------------------------------
        # Change space into ~, that is: nbsp.
        # It is better than \obeyspaces
	#---------------------------------------------------------------
        $pre =~ tr/ /\~/;

	#---------------------------------------------------------------
        # Data is returned.
        #-----------------------------------------------------------
        return ($pre);
    }

    #---------------------------------------------------------------
    # Translate a URI or PATH name or FILE name, so that it can
    # be broken into different lines with LaTeX.
    #---------------------------------------------------------------
    sub latex_uri_adaptation
    {
        local ($uri) = $_[0];

        #---------------------------------------------------------------
        # Change "/" into "/\hspace{0pt}" so that the text
        # can be broken at it,
        # but delete last one and the first one, if any.
        #---------------------------------------------------------------
        $uri =~ s/\//\/\\hspace{0pt}/mg;
        $uri =~ s/\\hspace{0pt}$//;
        $uri =~ s/^\/\\hspace{0pt}/\//;

        #---------------------------------------------------------------
        # Change "\textbackslash{}" into
        # "\textbackslash\hspace{0pt}" so that the text
        # can be broken at it,
        # but delete last one and the first one, if any.
        #---------------------------------------------------------------
        $uri =~ s/\\textbackslash\{\}/\\textbackslash\\hspace{0pt}/mg;
        $uri =~ s/\\hspace{0pt}$//;
        $uri =~ s/^\\textbackslash\\hspace{0pt}/\\textbackslash\{\}/;

        #---------------------------------------------------------------
        # Change "=" into "=\hspace{0pt}" so that the text
        # can be broken at it,
        # but delete last one and the first one, if any.
        #---------------------------------------------------------------
        $uri =~ s/=/=\\hspace{0pt}/mg;
        $uri =~ s/\\hspace{0pt}$//;
        $uri =~ s/^=\\hspace{0pt}/=/;

        #---------------------------------------------------------------
        # Change "-" into "\mbox{\texttt{-}\hspace{0pt}"
        # to avoid LaTeX reducing it and let the text
        # can be broken at it.
        #---------------------------------------------------------------
        $uri =~ s/-/\\mbox{\\texttt{-}}\\hspace{0pt}/mg;

        #---------------------------------------------------------------
	# Use \mbox around unbreakable pieces.
        #---------------------------------------------------------------
        $uri =  "\\mbox{" . $uri . "}";
        $uri =~ s/\\hspace{0pt}/}\\hspace{0pt}\\mbox{/mg;

        #---------------------------------------------------------------
	# Change something for good printing as literal.
        #---------------------------------------------------------------
	$uri = &latex_literal_step_0 ($uri);
	$uri = &latex_literal_step_1 ($uri);

        #---------------------------------------------------------------
	# Return the transformed URI string.
        #---------------------------------------------------------------
	return ($uri);
    }

    #-------------------------------------------------------------------
    # This is the pre-elaboration process to save generic cross
    # reference information.
    #
    # &sgml_tag_elab_first_pass (TYPE, ELEMENT, %ATTRIBUTES,
    #                            TYPESETTING,
    #                            TARGET,
    #                            DRAFT,
    #                            PAGE-NUMBERING,
    #                            COMPACT,
    #                            LONG,
    #                            ORIGINAL_NAME,
    #                            ROOT_FILE_NAME)
    #
    sub sgml_tag_elab_first_pass
    {
        #---------------------------------------------------------------
        # Function arguments.
        #---------------------------------------------------------------
        local ($type)               = $_[0];
        local ($element)            = $_[1];
        local ($attributes)         = $_[2];
        local ($typesetting)        = $_[3];
        local ($target)             = $_[4];
        local ($draft)              = $_[5];
        local ($page_numbering)     = $_[6];
        local ($compact)            = $_[7];
        local ($long)               = $_[8];
        local ($original_file_name) = $_[9];
        local ($root_file_name)     = $_[10];
        local ($paper_width)        = $_[11];
	local ($paper_height)       = $_[12];

        #---------------------------------------------------------------
        # Add a cross reference inside the cross reference array.
        sub add_cross_reference_list
        {
            local ($n) = 0;

            # $cross_reference_list[x][0]        level                  -1..4
            # $cross_reference_list[x][1]        tome number
            # $cross_reference_list[x][2]        part number
            # $cross_reference_list[x][3]        chapter number         
            # $cross_reference_list[x][4]        table absolute number          
            # $cross_reference_list[x][5]        figure absolute number         
            # $cross_reference_list[x][6]        level-description      1.2.3
            # $cross_reference_list[x][7]        title
            # $cross_reference_list[x][8]        table level-description
            # $cross_reference_list[x][9]        figure level-description
            # $cross_reference_list[x][10]       original anchor id
            # $cross_reference_list[x][11]       html page number
            # $cross_reference_list[x][12]       listing absolute number         
	    # $cross_reference_list[x][13]       listing level-description

            # Scan to see if already exists.
            for ($n = 0;
                 $n <= $#cross_reference_list;
                 $n++)
              {
                if ($last_anchor_id ne ""
                    && $cross_reference_list[$n][10] eq $last_anchor_id)
                  {
                    # The same anchor was already found.
                    # This is an error that must be shown.
                    &diag_output (sprintf (gettext ("%s: anchor already used %s !!!!\n"),
                                           $program_executable, $last_anchor_id));
                  }
              }
            # Add anyway the anchor.
            $#cross_reference_list++;
            $cross_reference_list[$#cross_reference_list] = ();
            $cross_reference_list[$#cross_reference_list][0]
              = $current_level_by_number;
            $cross_reference_list[$#cross_reference_list][1]
              = $tome;
	    if ($part_present)
	      {
                $cross_reference_list[$#cross_reference_list][2]
	          = $part;
	      }
	    else
	      {
                $cross_reference_list[$#cross_reference_list][2]
	          = 0;
	      }
            $cross_reference_list[$#cross_reference_list][3]
              = $chapter;
            $cross_reference_list[$#cross_reference_list][4]
              = $table;
            $cross_reference_list[$#cross_reference_list][5]
              = $figure;
            $cross_reference_list[$#cross_reference_list][6]
              = &current_section_number ();
            $cross_reference_list[$#cross_reference_list][7]
              = $last_heading_title;
            $cross_reference_list[$#cross_reference_list][8]
              = &current_table_number ();
            $cross_reference_list[$#cross_reference_list][9]
              = &current_figure_number ();
            $cross_reference_list[$#cross_reference_list][10]
              = $last_anchor_id;
            $cross_reference_list[$#cross_reference_list][11]
              = $html_page_counter;
            $cross_reference_list[$#cross_reference_list][12]
              = $listing;
            $cross_reference_list[$#cross_reference_list][13]
              = &current_listing_number ();
        }

        #---------------------------------------------------------------
        # Add an item inside the main toc array.
        #---------------------------------------------------------------
        sub add_contents_list
        {

            # $contents_list[x][0]        level                 -1..4
            # $contents_list[x][1]        tome number
            # $contents_list[x][2]        part number
            # $contents_list[x][3]        chapter number                
            # $contents_list[x][4]        level-description     1.2.3
            # $contents_list[x][5]        title
            # $contents_list[x][6]        html page number
            # $contents_list[x][7]        h1 section absolute counter

            # Save into main toc.
            $#contents_list++;
            $contents_list[$#contents_list] = ();
            $contents_list[$#contents_list][0]
              = $current_level_by_number;
            $contents_list[$#contents_list][1]
              = $tome;
	    if ($part_present)
	      {
                $contents_list[$#contents_list][2]
	          = $part;
	      }
	    else
	      {
                $contents_list[$#contents_list][2]
	          = 0;
	      }
            $contents_list[$#contents_list][3]
              = $chapter;
            $contents_list[$#contents_list][4]
              = &current_section_number ();
            $contents_list[$#contents_list][5]
              = $last_heading_title;
            $contents_list[$#contents_list][6]
              = $html_page_counter;
            $contents_list[$#contents_list][7]
              = $h1section_absolute_counter;
        }

        #---------------------------------------------------------------
        # Add an item inside the index list.
        #---------------------------------------------------------------
        sub add_index_list
        {
            local ($name) = $_[0];
            local ($emph) = $_[1];
            local ($emph_entry) = $_[2];
            local ($entry) = $_[3];
            local ($number) = $_[4];
            local ($html_page) = $_[5];
            local ($current_level) = $_[6];
            local ($current_tome) = $_[7];
            local ($current_part) = $_[8];
            local ($current_chapter) = $_[9];

            local ($n) = 0;

            # Scan the @index_list to find the same entry.
            #
            # $index_list[x][0]        index name
            # $index_list[x][1]        emphasis
            # $index_list[x][2]        entry
            # $index_list[x][3]        array of links
            # $index_list[x][4]        array of html page numbers
            # $index_list[x][5]        array of level-descriptions
            # $index_list[x][6]        entry with formatting
	    # $index_list[x][7]        array of tomes
	    # $index_list[x][8]        array of parts
	    # $index_list[x][9]        array of chapters (absolute)
            #

            for ($n = 0;
                 $n <= $#index_list;
                 $n++)
              {
                if ($index_list[$n][0] eq $name
                    && $index_list[$n][1] eq $emph
                    && $index_list[$n][2] eq $entry
                    && $index_list[$n][6] eq $emph_entry)
                  {
                    # There is already the same entry.
                    # Add a new link to the sub-array.
                    $#{$index_list[$n][3]}++;
                    $index_list[$n][3][$#{$index_list[$n][3]}] = $number;
                    $#{$index_list[$n][4]}++;
                    $index_list[$n][4][$#{$index_list[$n][4]}] = $html_page;
                    $#{$index_list[$n][5]}++;
                    $index_list[$n][5][$#{$index_list[$n][5]}] = $current_level;
                    $#{$index_list[$n][7]}++;
                    $index_list[$n][7][$#{$index_list[$n][7]}] = $current_tome;
                    $#{$index_list[$n][8]}++;
                    $index_list[$n][8][$#{$index_list[$n][7]}] = $current_part;
                    $#{$index_list[$n][9]}++;
                    $index_list[$n][9][$#{$index_list[$n][7]}] = $current_chapter;

            	    &diag_output (sprintf (gettext ("%s:%s: index \"%s\": added again \"%s\"\n"),
                                           $program_executable, $original_file_name,
                                           $name, $entry));
                    last;
                  }
              }
            # if the entry wasn't found, add it.
            if ($n > $#index_list)
              {
                $#index_list++;
                $index_list[$n][0] = $name;
                $index_list[$n][1] = $emph;
                $index_list[$n][2] = $entry;
                $index_list[$n][3] = ();
                $index_list[$n][3][0] = $number;
                $index_list[$n][4] = ();
                $index_list[$n][4][0] = $html_page;
                $index_list[$n][5] = ();
                $index_list[$n][5][0] = $current_level;
                $index_list[$n][6] = $emph_entry;
                $index_list[$n][7] = ();
                $index_list[$n][7][0] = $current_tome;
                $index_list[$n][8] = ();
                $index_list[$n][8][0] = $current_part;
                $index_list[$n][9] = ();
                $index_list[$n][9][0] = $current_chapter;

            	&diag_output (sprintf (gettext ("%s:%s: index \"%s\": added \"%s\"\n"),
                                       $program_executable, $original_file_name,
                                       $name, $entry));
              }
        }

        #---------------------------------------------------------------
        # Chech if the index entry is contained inside the current tome
	# part or chapter.
        sub valid_section_index_entry
        {
            local ($array_pointer)   = $_[0];
            local ($index_context)   = $_[1];
            local ($current_tome)    = $_[2];
            local ($current_part)    = $_[3];
            local ($current_chapter) = $_[4];
            local ($n) = 0;

            # $index_list[x][0]        index name
            # $index_list[x][1]        emphasis
            # $index_list[x][2]        entry
            # $index_list[x][3]        array of links
            # $index_list[x][4]        array of html page numbers
            # $index_list[x][5]        array of level-descriptions
            # $index_list[x][6]        entry with formatting
	    # $index_list[x][7]        array of tomes
	    # $index_list[x][8]        array of parts
	    # $index_list[x][9]        array of chapters (absolute)

	    if ($index_context eq "all")
	      {
	        # Good in any way.
		return (1);
	      }
	    elsif ($index_context eq "tome")
	      {
		# Scan sub array.
        	for ($n = 0;
            	     $n <= $#{$index_list[$n][7]};
                     $n++)
	          {
		    if ($index_list[$array_pointer][7][$n] == $current_tome)
		      {
		        # OK.
			return (1);
		      }
		  }
	      }
	    elsif ($index_context eq "part")
	      {
		# Scan sub array.
        	for ($n = 0;
            	     $n <= $#{$index_list[$n][8]};
                     $n++)
	          {
		    if ($index_list[$array_pointer][8][$n] == $current_part)
		      {
		        # OK.
			return (1);
		      }
		  }
	      }
	    elsif ($index_context eq "chapter")
	      {
		# Scan sub array.
        	for ($n = 0;
            	     $n <= $#{$index_list[$n][9]};
                     $n++)
	          {
		    if ($index_list[$array_pointer][9][$n] == $current_chapter)
		      {
		        # OK.
			return (1);
		      }
		  }
	      }
	    else
	      {
	        # Something went wrong.
            	&diag_output (sprintf (gettext ("%s:%s: wrong index context: \"%s\" !!!!\n"),
                                       $program_executable,
				       $original_file_name,
                                       $index_context));
		return (0);
	      }
	    # If we are here, no match was found.
	    return (0);
        }

        #---------------------------------------------------------------
        # Add an item inside the workinfo array.
        #---------------------------------------------------------------
        sub add_workinfo_list
        {
            # $workinfo_list[x][0]        work name
            # $workinfo_list[x][1]        work license
            # $workinfo_list[x][2]        work license text
            # $workinfo_list[x][3]        work notes

            # Save into the array.
            $#workinfo_list++;
            $workinfo_list[$#workinfo_list] = ();
            $workinfo_list[$#workinfo_list][0] = $workinfo_name;
            $workinfo_list[$#workinfo_list][1] = $workinfo_license;
            $workinfo_list[$#workinfo_list][2] = $workinfo_license_text;
            $workinfo_list[$#workinfo_list][3] = $workinfo_notes;
        }
        #---------------------------------------------------------------
        # Add an item inside the nomod sections array.
        sub add_nomod_sections_list
        {
            # $nomod_sections_list[x][0]    level         -1..4
            # $nomod_sections_list[x][1]    description   section 1.2
            # $nomod_sections_list[x][2]    title
            # $nomod_sections_list[x][3]    html page
            #
            $#nomod_sections_list++;
            $nomod_sections_list[$#nomod_sections_list] = ();
            $nomod_sections_list[$#nomod_sections_list][0]
              = $current_level_by_number;
            $nomod_sections_list[$#nomod_sections_list][1]
              = &current_section_number_complete ();
            $nomod_sections_list[$#nomod_sections_list][2]
              = $last_heading_title;
            $nomod_sections_list[$#nomod_sections_list][3]
              = $html_page_counter;
        }

        #---------------------------------------------------------------
        # Add an item inside the language array.
        #---------------------------------------------------------------
        sub add_language_list
        {
	    local ($lang) = lc ($_[0]);
	    local ($n) = 0;

	    for ($n = 0; $n <= $#language_list; $n++)
	      {
	        if ($language_list[$n] eq $lang)
		  {
		    #---------------------------------------------------
		    # There is no need to add again the language.
		    #---------------------------------------------------
		    return;
		  }	    
	      }

	    #-----------------------------------------------------------
	    # If we are here, the new language must be added.
	    #-----------------------------------------------------------
            $#language_list++;
            $language_list[$#language_list] = $lang;

	    return;
        }

        #---------------------------------------------------------------
        # Element handlers.
        # Element names and attribute names are uppercase.
        #---------------------------------------------------------------

        if ($element eq "ALML")
          {
            if ($type eq "start")
              {
                # Reset all counters.
                $intro = 0;
                $tome = 0;
                $part = 0;
	        $part_present = 0;
                $chapter = 0;
                $h1section_absolute_counter = 0;
                $appendix = 0;
                $sect1 = 0;         
                $sect2 = 0;         
                $sect3 = 0;         
                $index = 0;
                $table = 0;
                $absolute_table = 0;
                $picture =  0;
                $absolute_figure = 0;
                $absolute_listing = 0;
                $unnumbered = 0;
                $current_level = "";
                $current_level_by_number = 9999;
                $document_position = "";
                $html_page_counter = 0;
                
                # Save administrative information.
                $current_language = ${$attributes}{'LANG'};
                $document_language = $current_language;
                $tome_language = $current_language;
                $part_language = $current_language;
                $chapter_language = $current_language;
                $document_spacing = lc ${$attributes}{'SPACING'};
                
                ## Check $document_chapter_definition
                #if ($document_chapter_definition eq "")
                #  {
                #    $document_chapter_definition = &chapter_def ();
                #  }
                ## Check $document_part_definition
                #if ($document_part_definition eq "")
                #  {
                #    $document_part_definition = &part_def ();
                #  }
                ## Check $document_part_definition
                #if ($document_tome_definition eq "")
                #  {
                #    $document_tome_definition = &tome_def ();
                #  }

		#-------------------------------------------------------
		# Add inside the language array.
		#-------------------------------------------------------
		&add_language_list ($current_language);
              }
            else
              {
                # Nothing to do here.
                ;
              }
          }
        elsif ($element eq "HEAD")
          {
            if ($type eq "start")
              {
                # Save the document position.
                $document_position = "head";
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "MAINCONTENTS")
          {
            if ($type eq "start")
              {
                local ($nopages) = lc (${$attributes}{'NOPAGES'});

                # As there is the table of contents, the
                # HTML page counter is incremented.
                $html_page_counter++;

                # Activate main table of contents.
                # This is used to know how to handle the html page counter.
                $main_contents = 1;
                if ($nopages eq "true")
                  {
                    $main_contents_nopages = 1;
                  }
                else
                  {
                    $main_contents_nopages = 0;
                  }

                # Save navigation link information.
                #
                # $html_page_fixed_link_list[x][0]        html page number
                # $html_page_fixed_link_list[x][1]        link description
                $#html_page_fixed_link_list++;
                $html_page_fixed_link_list[$#html_page_fixed_link_list][0]
                  = $html_page_counter;
                $html_page_fixed_link_list[$#html_page_fixed_link_list][1]
                  = &contents_def ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "INTRO")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "intro";
              }
            else
              {
                # Reset current level by number
                $current_level_by_number = 9999;

                # Nothing else to do.
                ;
              }
          }
        elsif ($element eq "BODY")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "body";
                # Reset intro counter;
                $intro = 0;
              }
            else
              {
                # Reset current level by number
                $current_level_by_number = 9999;

                # Nothing else to do.
                ;
              }
          }
        elsif ($element eq "APPENDIX")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "appendix";
                # Reset chapter, part and tome counter;
                $chapter = 0;
                $part = 0;
		$part_present = 0;
                $tome = 0;
              }
            else
              {
                # Reset current level by number
                $current_level_by_number = 9999;

                # Nothing else to do.
                ;
              }
          }
        elsif ($element eq "INDEX")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "index";
                # Reset appendix, chapter, part and tome counter;
                $appendix = 0;
                $chapter = 0;
                $part = 0;
		$part_present = 0;
                $tome = 0;
              }
            else
              {
                # Reset current level by number
                $current_level_by_number = 9999;

                # Nothing else to do.
                ;
              }
          }
        elsif ($element eq "NAVLINK")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($navlink) = "";
                $navlink = &pop_output ();
                # Save navigation link information.
                #
                # $html_page_fixed_link_list[x][0]        html page number
                # $html_page_fixed_link_list[x][1]        link description
                $#html_page_fixed_link_list++;
                $html_page_fixed_link_list[$#html_page_fixed_link_list][0]
                  = $html_page_counter;
                $html_page_fixed_link_list[$#html_page_fixed_link_list][1]
                  = $navlink;
              }
          }
        elsif ($element eq "TOMEHEADING")
          {
            if ($type eq "start")
              {
                # Increment HTML page counter an save into tome list.
                $html_page_counter++;
                $#html_page_tome_link_list++;
                $html_page_tome_link_list[$#html_page_tome_link_list]
                  = $html_page_counter;

                # Save anchor information.
                $tome_heading_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                
		#-------------------------------------------------------
                # Save and set language information.
		#-------------------------------------------------------
                $current_language = ${$attributes}{'LANG'};
                if ($current_language eq "")
                  {
                    $current_language = $document_language;
                  }
                $tome_language = $current_language;
                $part_language = $current_language;
                $chapter_language = $current_language;

		#-------------------------------------------------------
		# Add inside the language array.
		#-------------------------------------------------------
		&add_language_list ($current_language);
                
                # Here start a tome. Do some preparations.
                # Tome happens only inside a body.
                $current_level = "tome";
                $current_level_by_number = -1;
                $tome++;
		$part_present = 0;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                # part counter doesnt change.
                # chapter counter doesnt change.
                $sect1 = 0;             
                $sect2 = 0;             
                $sect3 = 0;             

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $tome_heading_title = &pop_output ();
                $last_heading_title = $tome_heading_title;
                # Save into main toc.
                &add_contents_list ();
                # Save into cross reference list.
                &add_cross_reference_list ();
                
                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H0")
          {
            if ($type eq "start")
              {
                # Increment HTML page counter an save into part list.
                $html_page_counter++;
                $#html_page_part_link_list++;
                $html_page_part_link_list[$#html_page_part_link_list]
                  = $html_page_counter;

                # Save anchor information.
                $h0_id = ${$attributes}{'ID'};
                $last_anchor_id = $h0_id;

                # Save and set language information.
                $current_language = ${$attributes}{'LANG'};
                if ($current_language eq "")
                  {
                    $current_language = $tome_language;
                  }
                $part_language = $current_language;
                $chapter_language = $current_language;

		#-------------------------------------------------------
		# Add inside the language array.
		#-------------------------------------------------------
		&add_language_list ($current_language);

                # Here start a part. Do some preparations.
                # Tome happens only inside a body.
                $current_level = "part";
                $current_level_by_number = 0;
                $part++;
		$part_present = 1;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                # chapter counter doesnt change.
                $sect1 = 0;             
                $sect2 = 0;             
                $sect3 = 0;             

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $h0_title = &pop_output ();
                $last_heading_title = $h0_title;
                # Save into main toc.
                &add_contents_list ();
                # Save into cross reference list.
                &add_cross_reference_list ();

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H1"
               || $element eq "SLIDEH1"
               || $element eq "SHEETH1"
               || $element eq "UNNUMBEREDH1")
          {
            if ($type eq "start")
              {
                # Increment HTML page counter.
                $html_page_counter++;

                # Save anchor information.
                $h1_id = ${$attributes}{'ID'};
                $last_anchor_id = $h1_id;

                # Save and set language information.
                $current_language = ${$attributes}{'LANG'};
                if ($current_language eq "")
                  {
                    $current_language = $part_language;
                  }
                $chapter_language = $current_language;

		#-------------------------------------------------------
		# Add inside the language array.
		#-------------------------------------------------------
		&add_language_list ($current_language);

                # Here start a chapter. Do some preparations.
                $current_level_by_number = 1;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                if ($element eq "UNNUMBEREDH1")
                  {
                    $current_level = "unnumbered-h1";
                    $unnumbered_chapter++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "intro")
                  {
                    $current_level = "intro-h1";
                    $intro++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
                    $current_level = "chapter-h1";
                    $chapter++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
                    $current_level = "appendix-h1";
                    $appendix++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h1";
                    $index++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;
                    $sect2 = 0;
                    $sect3 = 0;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $h1_title = &pop_output ();
                $last_heading_title = $h1_title;
                # Save into main toc.
                &add_contents_list ();
                # Save into cross reference list.
                &add_cross_reference_list ();

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H2"
               || $element eq "FAQH2")
          {
            if ($type eq "start")
              {
                # Save anchor information.
                $h2_id = ${$attributes}{'ID'};
                $last_anchor_id = $h2_id;

                # Here start a section. Do some preparations.
                $current_level_by_number = 2;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h2";
                    $sect1++;           
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h2";
		      }
		    else
		      {
                	$current_level = "chapter-h2";
		      }
                    $sect1++;           
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h2";
		      }
		    else
		      {
                	$current_level = "appendix-h2";
		      }
                    $sect1++;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h2";
                    $sect1++;
                    $sect2 = 0;
                    $sect3 = 0;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $h2_title = &pop_output ();
                $last_heading_title = $h2_title;
                # Save into main toc.
                &add_contents_list ();
                # Save into cross reference list.
                &add_cross_reference_list ();
              }
          }
        elsif ($element eq "H3"
               || $element eq "FAQH3")
          {
            if ($type eq "start")
              {
                # Save anchor information.
                $h3_id = ${$attributes}{'ID'};
                $last_anchor_id = $h3_id;

                # Here start a section. Do some preparations.
                $current_level_by_number = 3;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h3";
                    $sect2++;           
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "chapter-h3";
		      }
                    $sect2++;           
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "appendix-h3";
		      }
                    $sect2++;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h3";
                    $sect2++;
                    $sect3 = 0;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $h3_title = &pop_output ();
                $last_heading_title = $h3_title;
                # Save into main toc.
                &add_contents_list ();
                # Save into cross reference list.
                &add_cross_reference_list ();
              }
          }
        elsif ($element eq "H4")
          {
            if ($type eq "start")
              {
                # Save anchor information.
                $h4_id = ${$attributes}{'ID'};
                $last_anchor_id = $h4_id;

                # Here start a section. Do some preparations.
                $current_level_by_number = 4;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h4";
                    $sect3++;           
                  }
                elsif ($document_position eq "body")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "chapter-h4";
		      }
                    $sect3++;
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "appendix-h4";
		      }
                    $sect3++;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h4";
                    $sect3++;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $h4_title = &pop_output ();
                $last_heading_title = $h4_title;
                # Save into main toc.
                &add_contents_list ();
                # Save into cross reference list.
                &add_cross_reference_list ();
              }
          }
        elsif ($element eq "ANCHOR")
          {
            if ($type eq "start")
              {
                # Save anchor information.
                $last_anchor_id = ${$attributes}{'ID'};
                # Save into cross reference list.
                &add_cross_reference_list ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "TABLE")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                # Increment and reset table counters.
                $table++;
                $absolute_table++;
                $table_columns_width_counter = ($absolute_table -1);
                $#table_columns_width++;
                $table_columns_width[$#table_columns_width] = ();
                # Save anchor information.
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "table" . $absolute_table;
                  }
                $last_table_id = $id;
                $last_anchor_id = $id;
                # Save into cross reference list.
                &add_cross_reference_list ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "TROW")
          {
            if ($type eq "start")
              {
                # Here start a new raw, so, also clumns counter is reset.
                $table_column_counter = -1;
                # Save output.
                &push_output ();
              }
            else
              {
                local ($cell) = "";
                local ($cell_length) = 0;
                # Recall output (if any).
                $cell = &pop_output ();

                # Eliminate residual tag
                # (but need to save an emergency space, for elements that
                # translate into some strings).
                $cell =~ s/<.*?>/\_/ig;
                # Substitute residual SGML/HTML macro with "?".
                $cell =~ s/&[a-z]+;/\?/ig;
                # Calculate the string length.
                $cell_length = length ($cell);

                # Save the bigger.
                $table_column_counter++;
                $table_columns_width[$#table_columns_width][$table_column_counter]
                  = &max ($table_columns_width[$#table_columns_width][$table_column_counter],
                          $cell_length);
              }
          }
        elsif ($element eq "COLSEP")
          {
            if ($type eq "start")
              {
                local ($cell) = "";
                local ($cell_length) = 0;
                # Recall output (if any).
                $cell = &pop_output ();

                # Eliminate residual tag
                # (but need to save an emergency space, for elements that
                # translate into some strings).
                $cell =~ s/<.*?>/\_/ig;
                # Substitute residual SGML/HTML macro with "?".
                $cell =~ s/&[a-z]+;/\?/ig;
                # Calculate the string length.
                $cell_length = length ($cell);

                # Save the bigger.
                $table_column_counter++;
                $table_columns_width[$#table_columns_width][$table_column_counter]
                  = &max ($table_columns_width[$#table_columns_width][$table_column_counter],
                          $cell_length);
              }
            else
              {
                # Save output.
                &push_output ();
              }
          }
        elsif ($element eq "FIGURE")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                # Increment and reset figure counters.
                $figure++;
                $absolute_figure++;
                # Save anchor information.
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "figure" . $absolute_figure;
                  }
                $last_figure_id = $id;
                $last_anchor_id = $id;
                # Save into cross reference list.
                &add_cross_reference_list ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "LISTING")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                # Increment and reset figure counters.
                $listing++;
                $absolute_listing++;
                # Save anchor information.
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "listing" . $absolute_listing;
                  }
                $last_listing_id = $id;
                $last_anchor_id = $id;
                # Save into cross reference list.
                &add_cross_reference_list ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "INDEXENTRY")
          {
            if ($type eq "start")
              {
		# The index entry is scanned.
	        $index_entry_active = 1;

		# Save index attributes.
                $index_name = ${$attributes}{'INDEX'};
                $index_emph = lc ${$attributes}{'EMPH'};

		# Save INDEXENTRY element.
                &push_output ();
              }
            else
              {
                local ($n) = 0;
                local ($entry) = "";
		local ($emph_entry) = "";

                $emph_entry = &pop_output ();

		# Need some elaboration to eliminate typesetting code.
		if ($typesetting eq "LATEX")
		  {
		    $entry = $emph_entry;
		    $entry =~ s/\\AlmlIndexEntryCode\{(.*?)}/$1/mg;
		  }
		elsif ($typesetting eq "HTML")
		  {
		    $entry = $emph_entry;
		    $entry =~ s/<\/?CODE>//mg;
		  }
		else
		  {
		    $entry = $emph_entry;
		  }

                # Increment the index entry counter.
                $index_entry_counter++;

                # Save the index entry inside the index list.
                &add_index_list ($index_name, $index_emph, $emph_entry, $entry, $index_entry_counter, $html_page_counter, &current_section_number (), $tome, $part, $h1section_absolute_counter);

		# The index entry scan is terminated.
	        $index_entry_active = 0;
              }
          }
        elsif ($element eq "SPECIAL")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                local ($n) = 0;
                local ($special) = "";
                local ($emph) = "normal";
                local ($entry) = "";
                $special = ${$attributes}{'SPECIAL'};
                # Recall output (if any).
                $entry = &pop_output ();

                # Print the entry (maybe it is inside an index or other
                # sort of information).
                #
                # We need to see these "special" things on draft typesetting.
                if ($typesetting eq "LATEX")
                  {
                    &output ("\\AlmlSpecial{$entry}{$special}");
                  }
                else
                  {
                    &output ($entry);
                  }

                # increment the index entry counter.
                $index_entry_counter++;

                # save the index entry inside the index list.
                &add_index_list ($special, $emph, $entry, $entry, $index_entry_counter, $html_page_counter, &current_section_number (), $tome, $part, $h1section_absolute_counter);
                
              }
          }
#        elsif ($element eq "DFN")
#          {
#            if ($type eq "start")
#              {
#                # Save output.
#                &push_output ();
#              }
#            else
#              {
#               local ($n) = 0;
#               local ($name) = "dfn";
#               local ($emph) = "normal";
#               local ($entry) = "";
#                # Recall output (if any).
#                $entry = &pop_output ();
#
#                # increment the index entry counter.
#                $index_entry_counter++;
#
#                # save the index entry inside the index list.
#                &add_index_list ($name, $emph, $entry, $entry, $index_entry_counter, $html_page_counter, &current_section_number (), $tome, $part, $h1section_absolute_counter);
#              }
#          }
        elsif ($element eq "WORKINFO")
          {
            if ($type eq "start")
              {
                # Reset global variables.
                $workinfo_name         = "";
                $workinfo_license      = "";
                $workinfo_license_text = "";
                $workinfo_notes        = "";
              }
            else
              {
                # Add the workinfo insiede the array.
                &add_workinfo_list ();
              }
          }
        elsif ($element eq "WORKNAME")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_name = &pop_output ();
              }
          }
        elsif ($element eq "WORKLICENSE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_license = &pop_output ();
              }
          }
        elsif ($element eq "WORKLICENSETEXT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_license_text = &pop_output ();
              }
          }
        elsif ($element eq "WORKNOTES")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_notes = &pop_output ();
              }
          }
        elsif ($element eq "NOMOD")
          {
            if ($type eq "start")
              {
                # Just add inside the @nomod_sections_list array.
                &add_nomod_sections_list ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "DOCINFO")
          {
            if ($type eq "start")
              {
                # Add a new element inside the docinfo array an
                # prepare it with default values.
                #
                # $docinfo_list[x][0]       level               -1..4
                # $docinfo_list[x][1]       description     section 1.2
                # $docinfo_list[x][2]       title
                # $docinfo_list[x][3]       origin note
                # $docinfo_list[x][4]       revision note
                # $docinfo_list[x][5]       notes
                # $docinfo_list[x][6][y][0] revision date               OBSOLETE
                # $docinfo_list[x][6][y][1] revision author             OBSOLETE
                # $docinfo_list[x][6][y][2] revision email              OBSOLETE
                # $docinfo_list[x][6][y][3] revision description        OBSOLETE
                # $docinfo_list[x][7]       html page number
                # $docinfo_list[x][8][z]    z-th author
                #
                $#docinfo_list++;
                $docinfo_list[$#docinfo_list] = ();
                $docinfo_list[$#docinfo_list][0]
                  = $current_level_by_number;
                $docinfo_list[$#docinfo_list][1]
                  = &current_section_number_complete ();
                $docinfo_list[$#docinfo_list][2]
                  = $last_heading_title;
                $docinfo_list[$#docinfo_list][3] = "";
                $docinfo_list[$#docinfo_list][4] = "";
                $docinfo_list[$#docinfo_list][5] = "";
                $docinfo_list[$#docinfo_list][6] = ();  # OBSOLETE
                $docinfo_list[$#docinfo_list][7] = $html_page_counter;
                $docinfo_list[$#docinfo_list][8] = ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "DOCAUTHOR")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $#{$docinfo_list[$#docinfo_list][8]}++;
                $docinfo_list[$#docinfo_list][8][$#{$docinfo_list[$#docinfo_list][8]}]
                  = &pop_output ();
              }
          }
        elsif ($element eq "DOCORIGINNOTE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $docinfo_list[$#docinfo_list][3] = &pop_output ();
              }
          }
        elsif ($element eq "DOCREVISIONNOTE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $docinfo_list[$#docinfo_list][4] = &pop_output ();
              }
          }
        elsif ($element eq "DOCNOTES")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $docinfo_list[$#docinfo_list][5] = &pop_output ();
              }
          }
#        elsif ($element eq "DOCREVISION")
#          {
#            if ($type eq "start")
#              {
#                local ($date) = "";
#                local ($author) = "";
#                local ($email) = "";
#                local ($description) = "";
#                # Save attributes.
#                $date = ${$attributes}{'DATE'};
#                $author = ${$attributes}{'AUTHOR'};
#                $email = ${$attributes}{'EMAIL'};
#                $description = ${$attributes}{'DESCRIPTION'};
#                # Add to the dofinfo array.
#                # Note that $#{$docinfo_list[$#docinfo_list][6]} is the
#                # last sub element of $docinfo_list[$#docinfo_list][6].
#                $#{$docinfo_list[$#docinfo_list][6]}++;
#                $docinfo_list[$#docinfo_list][6][$#{$docinfo_list[$#docinfo_list][6]}][0]
#                  = $date;
#                $docinfo_list[$#docinfo_list][6][$#{$docinfo_list[$#docinfo_list][6]}][1]
#                  = $author;
#                $docinfo_list[$#docinfo_list][6][$#{$docinfo_list[$#docinfo_list][6]}][2]
#                  = $email;
#                $docinfo_list[$#docinfo_list][6][$#{$docinfo_list[$#docinfo_list][6]}][3]
#                  = $description;
#              }
#            else
#              {
#                # Nothing to do.
#                ;
#              }
#          }
        elsif ($element eq "DESCRIPTION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $document_description = &pop_output ();
              }
          }
        elsif ($element eq "KEYWORDS")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $document_keywords = &pop_output ();
              }
          }
        elsif ($element eq "HTMLMETA")
          {
            if ($type eq "start")
              {
                local ($name) = "";
                local ($lang) = "";
                $name = (${$attributes}{'NAME'});
                $lang = (${$attributes}{'LANG'});

                # HTML meta tags.
                #
                # $html_meta_tag[x][0]        name
                # $html_meta_tag[x][1]        lang
                # $html_meta_tag[x][2]        content
                #
                $#html_meta_tag++;
                $html_meta_tag[$#html_meta_tag] = ();
                $html_meta_tag[$#html_meta_tag][0] = $name;
                $html_meta_tag[$#html_meta_tag][1] = $lang;

                # Save output.
                &push_output ();
              }
            else
              {
                local ($content) = "";
                # Recall the meta-content.
                $content = &pop_output ();
                $html_meta_tag[$#html_meta_tag][2] = $content;
              }
          }
        elsif ($element eq "CHAPTERDEFINITION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $document_chapter_definition = &pop_output ();
              }
          }
        elsif ($element eq "PARTDEFINITION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $document_part_definition = &pop_output ();
              }
          }
        elsif ($element eq "TOMEDEFINITION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $document_tome_definition = &pop_output ();
              }
          }
        elsif ($element eq "PRINTEDFONTSIZE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                local ($type) = "";
                local ($size) = "";
                local ($unit) = "";
                $type = (${$attributes}{'TYPE'});

		#-------------------------------------------------------
                # Recall the font size.
		# Modify "," with ".".
		#-------------------------------------------------------
                $size = &pop_output ();
		$size =~ m/([0-9.,]+)\s*([a-zA-Z]*)/;
		$size = $1;
		$unit = $2;
		$size =~ s/,/./;

                if ($unit eq "")
		  {
		    &diag_output (sprintf (gettext ("%s:%s PRINTEDFONTSIZE must have a unit of measure !!!!\n"),
                                           $program_executable,
					   $original_file_name));
		    $unit = "bp";
		  }

                if ($type eq "TITLE")
                  {
                    $printed_font_size_title = $size . $unit;
                    $printed_font_height_title = ($size * 1.2) . $unit;
                  }
                elsif ($type eq "TOMEHEADING")
                  {
                    $printed_font_size_tomeheading = $size . $unit;
                    $printed_font_height_tomeheading = ($size * 1.2) . $unit;
                  }
                elsif ($type eq "H0")
                  {
                    $printed_font_size_h0 = $size . $unit;
                    $printed_font_height_h0 = ($size * 1.2) . $unit;
                  }
                elsif ($type eq "H1")
                  {
                    $printed_font_size_h1 = $size . $unit;
                    $printed_font_height_h1 = ($size * 1.2) . $unit;
                  }
                elsif ($type eq "H2")
                  {
                    $printed_font_size_h2 = $size . $unit;
                    $printed_font_height_h2 = ($size * 1.2) . $unit;
                  }
                elsif ($type eq "H3")
                  {
                    $printed_font_size_h3 = $size . $unit;
                    $printed_font_height_h3 = ($size * 1.2) . $unit;
                  }
                elsif ($type eq "H4")
                  {
                    $printed_font_size_h4 = $size . $unit;
                    $printed_font_height_h4 = ($size * 1.2) . $unit;
                  }
                elsif ($type eq "NORMAL")
                  {
                    $printed_font_size_normal = $size . $unit;
                    $printed_font_height_normal = ($size * 1.2) . $unit;
                  }                 
                elsif ($type eq "TABLE")
                  {
                    $printed_font_size_table = $size . $unit;
                    $printed_font_height_table = ($size * 1.2) . $unit;
                  }
                else
                  {
                    &diag_output (sprintf (gettext ("%s:%s wrong type inside printedfontsize element: %s !!!!\n"),
                                           $program_executable,
					   $original_file_name,
					   $type));
                  }
              }
          }
        elsif ($element eq "PRINTEDPAGESIZE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                local ($type) = "";
                local ($size) = "";
                local ($unit) = "";
                $type = (${$attributes}{'TYPE'});

		#-------------------------------------------------------
                # Recall the font size.
		# Modify "," with ".".
		#-------------------------------------------------------
                $size = &pop_output ();
		$size =~ m/([0-9.,]+)\s*([a-zA-Z]*)/;
		$size = $1;
		$unit = $2;
		$size =~ s/,/./;

                if ($type eq "TOPMARGIN")
                  {
                    $printed_top_margin = $size . $unit;
                  }
                elsif ($type eq "BOTTOMMARGIN")
                  {
                    $printed_bottom_margin = $size . $unit;
                  }
                elsif ($type eq "INTERNALMARGIN")
                  {
                    $printed_internal_margin = $size . $unit;
                  }
                elsif ($type eq "BODYWIDTH")
                  {
                    $printed_body_width = $size . $unit;
                  }
              }
          }
        else
          {
            if ($typesetting eq "LATEX")
              {
                # Call the basic %block; and %inline; sub process for LaTeX.
                &sgml_tag_elab_latex_basic
                    ($type,
                     $element,
                     $attributes,
                     $typesetting,
                     $target,
                     $draft,
                     $page_numbering,
                     $compact,
                     $long,
                     $original_file_name,
                     $root_file_name,
		     $paper_width,
		     $paper_height);
              }
            elsif ($typesetting eq "HTML")
              {
                # Call the basic %block; and %inline; sub process for LaTeX.
                &sgml_tag_elab_html_basic
                    ($type,
                     $element,
                     $attributes,
                     $typesetting,
                     $target,
                     $draft,
                     $page_numbering,
                     $compact,
                     $long,
                     $original_file_name,
                     $root_file_name,
		     $paper_width,
		     $paper_height);
              }
          }

    } # sgml_tag_elab_first_pass

    #-------------------------------------------------------------------
    # This is the sub elaboration process specific, for basic %block;
    # and %inline; elements, for the LaTeX back-end.
    #
    # &sgml_tag_elab_latex_basic (TYPE, ELEMENT, %ATTRIBUTES,
    #                             TYPESETTING,
    #                             TARGET,
    #                             DRAFT,
    #                             PAGE-NUMBERING,
    #                             COMPACT,
    #                             LONG,
    #                             ORIGINAL_NAME,
    #                             ROOT_FILE_NAME)
    #
    sub sgml_tag_elab_latex_basic
    {
        #---------------------------------------------------------------
        # Function arguments.
        #---------------------------------------------------------------
        local ($type)               = $_[0];
        local ($element)            = $_[1];
        local ($attributes)         = $_[2];
        local ($typesetting)        = $_[3];
        local ($target)             = $_[4];
        local ($draft)              = $_[5];
        local ($page_numbering)     = $_[6];
        local ($compact)            = $_[7];
        local ($long)               = $_[8];
        local ($original_file_name) = $_[9];
        local ($root_file_name)     = $_[10];
        local ($paper_width)        = $_[11];
	local ($paper_height)       = $_[12];

        #---------------------------------------------------------------
        # Element handlers.
        # Element names and attribute names are uppercase.
        #---------------------------------------------------------------
        if ($element eq "P")
          {
            if ($type eq "start")
              {
                local ($font_size) = 0;
                local ($font_height) = 0;
                local ($unit) = "";
                $font_size = ${$attributes}{'PRINTEDFONTSIZE'};

		#-------------------------------------------------------
                # Extract the font size.
		# Modify "," with ".".
		#-------------------------------------------------------
		if ($font_size ne "")
		  {
		    $font_size =~ m/([0-9.,]+)\s*([a-zA-Z]*)/;
		    $font_size = $1;
		    $unit = lc ($2);
		    $font_size =~ s/,/./;
		    $font_size = $font_size . $unit;
            	    $font_height = ($font_size * 1.2) . $unit;
		  }

	        #-------------------------------------------------------
		# Start the paragraph.
	        #-------------------------------------------------------
                &output ("\n");
            	&output ("{\n");
		
	        #-------------------------------------------------------
		# Change the font size if required.
	        #-------------------------------------------------------
		if ($font_size ne "")
		  {		
    	    	    #---------------------------------------------------
		    # Need an extra empty line.
    	    	    #---------------------------------------------------
            	    &output ("\n");

    	    	    #---------------------------------------------------
		    # Set the font size.
    	    	    #---------------------------------------------------
                    &output ("\\fontsize{$font_size}{$font_height}\\selectfont\n");
		  }		
              }
            else
              {
	        #-------------------------------------------------------
		# The extra empty line is inserted to close the
		# paragraph inside the font definition (inside the curly
		# brakets); otherwise, the base line spacing will not be
		# taken into consideration.
	        #-------------------------------------------------------
                &output ("\n");
                &output ("\n");
            	&output ("}\n");
                &output ("\n");
              }
          }
        elsif ($element eq "FOOTNOTE")
          {
            if ($type eq "start")
              {
                &output ("\\footnote{");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "BLOCKFOOTNOTE")
          {
            if ($type eq "start")
              {
                &output ("\\footnote{");
              }
            else
              {
                &output ("}\n");
              }
          }
        elsif ($element eq "QUOTEINFO")
          {
            if ($type eq "start")
              {
                &output ("\\footnote{");
              }
            else
              {
                &output ("}\n");
              }
          }
        elsif ($element eq "BR")
          {
            if ($type eq "start")
              {
                &output ("\\newline{}");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "URI")
          {
            if ($type eq "start")
              {
                # Save the index type name.
                $last_normal_uri = ${$attributes}{'URI'};

                &push_output ();
              }
            else
              {
                local ($uri_element) = "";
                $uri_element = &pop_output ();

                if ($uri_element eq "")
                  {
                    # We use the attribute URI that is literal.
                    # OBSOLETE.
                    &output ("\$<\${\\fontsize{0.8em}{1.3em}\\selectfont\\slshape{}");
                    &output ("\\url{$last_normal_uri}");
                    &output ("\\/}\$>\$");
                  }
                else
                  {
		    #---------------------------------------------------
		    # The URI string need adaptations.
		    #---------------------------------------------------
		    $uri_element = &latex_uri_adaptation ($uri_element);

		    #---------------------------------------------------
                    # Print it out.
		    #---------------------------------------------------
                    &output ("{");
                    &output ("\$<\${\\fontsize{0.8em}{1.3em}\\selectfont\\slshape{}");
                    &output ("$uri_element");
                    &output ("\\/}\$>\$");
                    &output ("}");
                  }
              }
          }
        elsif ($element eq "MAN")
          {
            if ($type eq "start")
              {
                &output ("\\mbox{");
                &output ("{");
                &output ("\\itshape{}");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "MANSECT")
          {
            if ($type eq "start")
              {
                &output ("\\/}");
                &output ("\\rmfamily{}(");
              }
            else
              {
                &output (")");
              }
          }
        elsif ($element eq "BIBREF")
          {
            if ($type eq "start")
              {
                &output ("{\\itshape{}");
              }
            else
              {
                &output ("\\/}");
              }
          }
        elsif ($element eq "EM")
          {
            if ($type eq "start")
              {
                &output ("{\\itshape{}");
              }
            else
              {
                &output ("\\/}");
              }
          }
        elsif ($element eq "BIG")
          {
            if ($type eq "start")
              {
                &output ("{\\fontsize{1.2em}{2em}\\selectfont{}");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "SMALL")
          {
            if ($type eq "start")
              {
                &output ("{\\fontsize{0.8em}{1.3em}\\selectfont{}");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "STRONG")
          {
            if ($type eq "start")
              {
                &output ("{\\bfseries{}");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "ACRONYM")
          {
            if ($type eq "start")
              {
                &output ("{\\scshape{}");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "DACRONYM")
          {
            if ($type eq "start")
              {
                &output ("{\\itshape{}");
              }
            else
              {
                &output ("\\/}");
              }
          }
        elsif ($element eq "KBD")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($kbd) = "";
                $kbd = &pop_output ();

                # Replace "-" with \mbox{\texttt{-}}.
                $kbd =~ s/-/\\mbox{\\texttt{-}}/g;

                &output ("\\mbox{\\fontsize{0.8em}{1.3em}\\selectfont\[\\hspace{2pt}{\\itshape{}");
                &output ("$kbd");
                &output ("\\/}\\hspace{2pt}\]}");
              }
          }
        elsif ($element eq "REVISION")
          {
            if ($type eq "start")
              {
                &output ("\[{\\itshape{}");
              }
            else
              {
                &output ("}\]");
              }
          }
        elsif ($element eq "BUTTON")
          {
            if ($type eq "start")
              {
                &output ("\\fbox{\\fontsize{0.8em}{1.3em}\\selectfont\\scshape\\ttfamily{}");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "MENUITEM")
          {
            if ($type eq "start")
              {
                &output ("\\underline{\\fontsize{0.8em}{1.3em}\\selectfont\\slshape\\ttfamily{}");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "ASCIICODE")
          {
            if ($type eq "start")
              {
                &output ("{\\itshape\\fontsize{0.8em}{1.3em}\\selectfont\$<\$");
              }
            else
              {
                &output ("\$>\$}");
              }
          }
        elsif ($element eq "CODE")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($code) = "";
                $code = &pop_output ();

		#-------------------------------------------------------
		# There is a different implementation if
		# we are inside a INDEXENTRY element.
		#-------------------------------------------------------
		if ($index_entry_active)
		  {
            	    &output ("\\AlmlIndexEntryCode{");
            	    &output ("$code");
            	    &output ("}");
		  }
		else
		  {
		    #---------------------------------------------------
            	    # Do some transformations for good printing.
		    #---------------------------------------------------
		    $code = &latex_literal_step_0 ($code);
		    $code = &latex_literal_step_1 ($code);

            	    &output ("\\mbox{");
            	    &output ("{");
            	    &output ("\\fontsize{0.9em}{1.3em}\\selectfont");
            	    &output ("\\bfseries\\ttfamily{}");
            	    &output ("$code");
            	    &output ("}");
            	    &output ("}");
		  }
              }
          }
        elsif ($element eq "SAMP")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($samp) = "";
                $samp = &pop_output ();

		#-------------------------------------------------------
                # Do some transformations for good printing.
		#-------------------------------------------------------
		$samp = &latex_literal_step_0 ($samp);
		$samp = &latex_literal_step_1 ($samp);

    		#---------------------------------------------------------------
		# Use \mbox around unbreakable pieces.
    		#---------------------------------------------------------------

    		$samp =  "\\mbox{" . $samp . "}";
    		$samp =~ s/ /} \\mbox{/mg;

                &output ("{");
                &output ("\\fontsize{0.9em}{1.3em}\\selectfont{}");
                &output ("`");
                &output ("{");
                &output ("\\bfseries\\ttfamily{}");
                &output ("$samp");
                &output ("}");
                &output ("'");
                &output ("}");

              }
          }
        elsif ($element eq "STRDFN")
          {
            if ($type eq "start")
              {
                &output ("\\AlmlStrDef{");
              }
            else
              {
                &output ("}");
              }
          }
        elsif ($element eq "KERNELOPTION")
          {
            if ($type eq "start")
              {
                &output ("{\\itshape{}");
              }
            else
              {
                &output ("\\/}");
              }
          }
        elsif ($element eq "FILE")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($file) = "";
                $file = &pop_output (); 

		#-------------------------------------------------------
		# The URI string need adaptations.
		#-------------------------------------------------------
		$file = &latex_uri_adaptation ($file);

		#-------------------------------------------------------
                # Print it out.
		#-------------------------------------------------------
                &output ("{");
                &output ("\\fontsize{0.9em}{1.3em}\\selectfont{}");
                &output ("`");
                &output ("\\nolinebreak");
                &output ("\\begin{ttfamily}$file\\end{ttfamily}");
                &output ("\\nolinebreak");
                &output ("'");
                &output ("}");
              }
          }
        elsif ($element eq "URISTR")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($file) = "";
                $file = &pop_output (); 

		#-------------------------------------------------------
		# The URI string need adaptations.
		#-------------------------------------------------------
		$file = &latex_uri_adaptation ($file);

		#-------------------------------------------------------
                # Print it out.
		#-------------------------------------------------------
                &output ("{");
                &output ("\\begin{ttfamily}\\begin{slshape}$file\\end{slshape}\\end{ttfamily}\\/");
                &output ("}");
              }
          }
        elsif ($element eq "SUP")
          {
            if ($type eq "start")
              {
                &output ("{\\raise.75ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{");
              }
            else
              {
                &output ("}}}");
              }
          }
        elsif ($element eq "SUB")
          {
            if ($type eq "start")
              {
                &output ("{\\lower.25ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{");
              }
            else
              {
                &output ("}}}");
              }
          }
        elsif ($element eq "PWR")
          {
            if ($type eq "start")
              {
                &output ("{\\raise.75ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{");
              }
            else
              {
                &output ("}}}");
              }
          }
        elsif ($element eq "EXA")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                &output ("{\\lower.25ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{16}}}");
              }
          }
        elsif ($element eq "DEC")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                &output ("{\\lower.25ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{10}}}");
              }
          }
        elsif ($element eq "OCT")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                &output ("{\\lower.25ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{8}}}");
              }
          }
        elsif ($element eq "BIN")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                &output ("{\\lower.25ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{2}}}");
              }
          }
        elsif ($element eq "NUM")
          {
            if ($type eq "start")
              {
                # Save data here.
                push_output ();
              }
            else
              {
                local ($num) = "";
                local ($int) = "";
                local ($dec) = "";
                local ($point) = "";
                local ($sep) = "";
                local ($plus) = "";
                local ($minus) = "";

                # Recall output.
                $num = &pop_output ();

                # The separator is a thin space.
                $sep = "\\hbox{\\hspace{0.2ex}}";
                $plus = "+";
                $minus = "\\AlmlMinus{}";

                # Now, start elaboration, to separate each three digits.
                if ($num =~ m/^([+-]?)([0-9]*)([.,]?)([0-9]*)$/)
                  {
                    $sign  = $1;
                    $int   = $2;
                    $point = $3;
                    $dec   = $4;
                    $int   = &integer_to_string ($int, $sep);
                    $dec   = &decimal_to_string ($dec, $sep);

                    # Correct integer side if necessary.
                    if ($int eq "")
                      {
                        $int = "0";
                      }

                    # Set the sign prefix.
                    if ($sign eq "+")
                      {
                        $sign = $plus;
                      }
                    elsif ($sign eq "-")
                      {
                        $sign = $minus;
                      }
                    else
                      {
                        $sign = "";
                      }

                    if ($dec eq "")
                      {
                        # Nothing after the decimal marker.
                        &output ("\\AlmlSpecial{");
                        &output ($sign . $int);
                        &output ("}{}");
                      }
                    else
                      {
                        &output ("\\AlmlSpecial{");
                        &output ($sign . $int . $point . $dec);
                        &output ("}{}");
                      }
                  }
                else
                  {
                    # This is not a valid number.
                    &diag_output (sprintf (gettext ("%s: wrong number %s !!!!\n"),
                                  $program_executable, $num));
                    # Anyway, print it out.
                    &output ($num);
                  }
              }
          }
        elsif ($element eq "TEX")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                # Nothing to do here;
                ;
              }
          }
        elsif ($element eq "IFTEX")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                # Nothing to do here;
                ;
              }
          }
        elsif ($element eq "EPSIMG")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($eps_code) = "";
                local ($eps_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local (@dim) = ();
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                # Restore the EPS back-end code.
                $eps_code = $eps_code . &pop_output ();

                # Prepare the EPS temporary file.
                $eps_temp_file = &temporary_file ($temporary_file_name_prefix);
                # Save the empty temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                       . " ${eps_temp_file}";

                open (EPS_TEMP_FILE, "> ${eps_temp_file}.eps ");
                print EPS_TEMP_FILE ($eps_code);
                print EPS_TEMP_FILE ("\n");
                close (EPS_TEMP_FILE);

                # Save the temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                   . " ${eps_temp_file}.eps";

                # Convert to PNG if target is PDF.
                if ($target eq "PDF")
                  {
		    #---------------------------------------------------
		    # The 300x300 density must be corrected later.
		    # Please note that the density cannot be too high,
		    # otherwise, the PDF file will be too big.
		    #---------------------------------------------------
                    system ("convert -density 300x300 ${eps_temp_file}.eps ${eps_temp_file}.png");
		    # Adjust dimensions if necessry, because of 300x300 density.
            	    if ($height eq ""
		        && $width eq "")
		      {
		        @dim = &ps_x_y_size ("${eps_temp_file}.eps");
			$width = $dim[0] . "bp";
			$height = $dim[1] . "bp";
		      }
                  }

                # Print picture file.
                if ($target eq "PDF")
                  {
                    # Include the PNG picture.
                    &output ("\\epsfig{file=${eps_temp_file}.png");
                  }
                else
                  {
		    $ps_picture_counter++;
		    # Include the PostScript picture.
		    system ("cp ${eps_temp_file}.eps ${ps_picture_counter}.ps");
                    &output ("\\epsfig{file=${ps_picture_counter}.ps");
                  }
                if ($height ne "")
                  {
                    &output (",height=$height");
                  }
                if ($width ne "")
                  {
                    &output (",width=$width");
                  }
                &output (",angle=0}");
        
              }
          }
        elsif ($element eq "TEXIMG")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($tex_code) = "";
                local ($tex_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local (@dim) = ();
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                # Restore the TeX back-end code.
                $tex_code = $tex_code . &pop_output ();

                # Prepare the TeX temporary file.
                $tex_temp_file = &temporary_file ($temporary_file_name_prefix);
                # Save the empty temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                   . " ${tex_temp_file}";

                open (TEX_TEMP_FILE, "> ${tex_temp_file}.tex");
                print TEX_TEMP_FILE ("\\nonstopmode\n");
                print TEX_TEMP_FILE ("\\nopagenumbers\n");
                print TEX_TEMP_FILE ($tex_code);
                print TEX_TEMP_FILE ("\n");
                print TEX_TEMP_FILE ("\\bye\n");
                close (TEX_TEMP_FILE);

                # Typeset.
                system ("tex ${tex_temp_file}.tex");
                system ("dvips -E -o ${tex_temp_file}.ps ${tex_temp_file}.dvi");

                # Save the temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                   . " ${tex_temp_file}.dvi"
				   . " ${tex_temp_file}.tex"
                                   . " ${tex_temp_file}.ps";

                # Convert to PNG if target is PDF.
                if ($target eq "PDF")
                  {
		    #---------------------------------------------------
		    # Only first scene.
		    #
		    # The 300x300 density must be corrected later.
		    #
		    # Please note that the density cannot be too high,
		    # otherwise, the PDF file will be too big.
		    #---------------------------------------------------
                    system ("convert -density 300x300 ${tex_temp_file}.ps[0] ${tex_temp_file}.png");
		    # Adjust dimensions if necessry, because of 300x300 density.
            	    if ($height eq ""
		        && $width eq "")
		      {
		        @dim = &ps_x_y_size ("${tex_temp_file}.ps");
			$width = $dim[0] . "bp";
			$height = $dim[1] . "bp";
		      }
                  }

                # Print picture file.
                if ($target eq "PDF")
                  {
                    # Include the PNG picture.
                    &output ("\\epsfig{file=${tex_temp_file}.png");
                  }
                else
                  {
		    $ps_picture_counter++;
		    # Include the PostScript picture.
		    system ("cp ${tex_temp_file}.ps ${ps_picture_counter}.ps");
                    &output ("\\epsfig{file=${ps_picture_counter}.ps");
                  }
                if ($height ne "")
                  {
                    &output (",height=$height");
                  }
                if ($width ne "")
                  {
                    &output (",width=$width");
                  }
                &output (",angle=0}");
        
              }
          }
        elsif ($element eq "HTML")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Loose HTML content.
                &pop_output ();
              }
          }
        elsif ($element eq "IFHTML")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Loose HTML content.
                &pop_output ();
              }
          }
        elsif ($element eq "BLOCKQUOTE")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{quote}\n");

		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level++;
              }
            else
              {
		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level--;

                &output ("\n\\end{quote}\n");
              }
          }
        elsif ($element eq "FRAME")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{center}\n");
                &output ("\\fboxsep=0.4em");
                &output ("\\fbox{\\noindent");
                &output ("\\begin{minipage}{0.97\\linewidth}");
              }
            else
              {
                &output ("\n\n\\end{minipage}}");
                &output ("\\end{center}\n");
              }
          }
        elsif ($element eq "PRE")
          {
            if ($type eq "start")
              {
                # Save column width.
                $preformatted_column_width = ${$attributes}{'WIDTH'};
                # Correct min and max.
                if ($preformatted_column_width eq "")
                  {
                    $preformatted_column_width = 80;
                  }
                elsif ($preformatted_column_width < 50)
                  {
                    $preformatted_column_width = 50;
                  }
                elsif ($preformatted_column_width > 200)
                  {
                    $preformatted_column_width = 200;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($pre) = "";
		local ($indent_factor) = 0;
		if ($floating_block)
		  {
    		    $indent_factor = 1;
		  }
		else
		  {
    		    $indent_factor = 0.94**$text_indent_level;
		  }
                local ($font_size) =
		    (int ((46.9 * $indent_factor
		                * &convert_to_mm_as_number ($printed_body_width))
		          / $preformatted_column_width)) / 10;
                local ($font_spacing) = $font_size*1.2;
                # The normal mode for output() function is re-established.
                $pre = &pop_output ();

		#-------------------------------------------------------
                # Do some transformations for good printing.
	        #-------------------------------------------------------
		$pre = &latex_literal_step_0 ($pre);
		$pre = &latex_literal_step_1 ($pre);
		$pre = &latex_literal_step_2 ($pre);
		$pre = &latex_literal_step_3 ($pre);
                
		#-------------------------------------------------------
		# The \par at the beguinning and at the end, is
		# necessary because the font change is inside {...},
		# and without the last one the base line skip does not
		# take affect. So, the first \par is there for simmetry.
		#-------------------------------------------------------
                &output ("\n");
                &output ("{\n");
                &output ("\\par\n");
                &output ("\\fontsize{$font_size}{$font_spacing}\\selectfont\n");
                &output ("{");
                &output ("\\begin{ttfamily}\n");
                &output ("$pre\n");
                &output ("\\end{ttfamily}");
                &output ("}");
                &output ("\\par\n");
                &output ("}\n");
              }
          }
        elsif ($element eq "PNEWLINE")
          {
            if ($type eq "start")
              {

		#-------------------------------------------------------
		# This commented code puts a word inside a parentesys
		# at the end of the line, but for the printed
		# typesetting it is better another option.
		#-------------------------------------------------------

                #&output ("{~~\\hfill\\normalfont\\scriptsize\\slshape{}("
                #         . &command_continue_on_the_next_line_def ()
                #         . ")}\\newline");
                #&output ("  ");

		#-------------------------------------------------------
		# This other code, put a kind of visual guide to
		# the new line, at the beguinning.
		#-------------------------------------------------------

                #&output ("\\newline");
                #&output ("{");
                #&output ("\\hbox{");
                #&output ("\\normalfont");
                #&output ("\\fontsize{0.7em}{1em}\\selectfont");
                #&output ("\\sffamily");
                #&output ("\\bfseries{}");
                #&output ("~`->~");
                #&output ("}");
                #&output ("}");


		#-------------------------------------------------------
		# Please note that there cannot be any space inside
		# the LaTeX command, because spaces are changed into
		# unbreakable spaces. So, "\lower0.5ex" must be so.
		#-------------------------------------------------------
                &output ("{\\lower0.5ex\\hbox{\$\\hookleftarrow\$}}");
                &output ("\\newline");
                &output ("{\\raise0.5ex\\hbox{\$\\hookrightarrow\$}}");

              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "VERBATIMPRE")
          {
            if ($type eq "start")
              {
                # Save column width.
                $preformatted_column_width = ${$attributes}{'WIDTH'};
                # Correct min and max.
                if ($preformatted_column_width eq "")
                  {
                    $preformatted_column_width = 80;
                  }
                elsif ($preformatted_column_width < 50)
                  {
                    $preformatted_column_width = 50;
                  }
                elsif ($preformatted_column_width > 200)
                  {
                    $preformatted_column_width = 200;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($pre) = "";
		local ($indent_factor) = 0;
		if ($floating_block)
		  {
    		    $indent_factor = 1;
		  }
		else
		  {
    		    $indent_factor = 0.94**$text_indent_level;
		  }
                local ($font_size) =
		    (int ((46.9 * $indent_factor
		                * &convert_to_mm_as_number ($printed_body_width))
		          / $preformatted_column_width)) / 10;
                local ($font_spacing) = $font_size*1.2;

                # The normal mode for output() function is re-established.
                $pre = &pop_output ();

		#-------------------------------------------------------
                # Do some transformations for good printing.
	        #-------------------------------------------------------
		$pre = &latex_literal_step_0 ($pre);
		$pre = &latex_literal_step_1 ($pre);
		$pre = &latex_literal_step_2 ($pre);
		$pre = &latex_literal_step_3 ($pre);
                
                &output ("\n");
                #&output ("\\begin{AlmlScreensize}");

		#-------------------------------------------------------
		# The \par at the beguinning and at the end, is
		# necessary because the font change is inside {...},
		# and without the last one the base line skip does not
		# take affect. So, the first \par is there for simmetry.
		#-------------------------------------------------------
                &output ("{\n");
                &output ("\\par\n");
                &output ("\\fontsize{$font_size}{$font_spacing}\\selectfont\n");
                &output ("{");
                &output ("\\begin{ttfamily}\n");
                &output ("$pre\n");
                &output ("\\end{ttfamily}");
                &output ("}");
                &output ("\\par\n");
                &output ("}\n");
                #&output ("\\end{AlmlScreensize}");
              }
          }
        elsif ($element eq "SYNTAX")
          {
            if ($type eq "start")
              {
                # Save column width.
                $preformatted_column_width = ${$attributes}{'WIDTH'};
                # Correct min and max.
                if ($preformatted_column_width eq "")
                  {
                    $preformatted_column_width = 80;
                  }
                elsif ($preformatted_column_width < 50)
                  {
                    $preformatted_column_width = 50;
                  }
                elsif ($preformatted_column_width > 200)
                  {
                    $preformatted_column_width = 200;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($syntax) = "";
		local ($indent_factor) = 0;
		if ($floating_block)
		  {
    		    $indent_factor = 1;
		  }
		else
		  {
    		    $indent_factor = 0.94**$text_indent_level;
		  }
                local ($font_size) =
		    (int ((46.9 * $indent_factor
		                * &convert_to_mm_as_number ($printed_body_width))
		          / $preformatted_column_width)) / 10;
                local ($font_spacing) = $font_size*1.2;
                # The normal mode for output() function is re-established.
                $syntax = &pop_output ();

		#-------------------------------------------------------
                # Do some transformations for good printing.
	        #-------------------------------------------------------
		$syntax = &latex_literal_step_0 ($syntax);
		$syntax = &latex_literal_step_1 ($syntax);
		$syntax = &latex_literal_step_2 ($syntax);
		$syntax = &latex_literal_step_3 ($syntax);

                &output ("\n");
                &output ("% <". "$element" . ">\n");
                &output ("{\\samepage\n");
                #&output ("\\begin{AlmlScreensize}");
                &output ("{\\fontsize{$font_size}{$font_spacing}\\selectfont\n");
                #&output ("\\vspace{-0.7em}");
                &output ("{");
                &output ("\\begin{ttfamily}");
                &output ("$syntax");
                &output ("\\end{ttfamily}");
                &output ("\\nopagebreak");
                &output ("}");
                &output ("\\nopagebreak");
                #&output ("\\vspace{-0.7em}");
                &output ("\\par}");
                #&output ("\\end{AlmlScreensize}");
                #&output ("\\nopagebreak");
                #&output ("\\vspace{-1em}");
                &output ("\n");
                &output ("}% samepage-end from $element\n");
                &output ("% </". "$element" . ">\n");
              }
          }
        elsif ($element eq "SNEWLINE")
          {
            if ($type eq "start")
              {

		#-------------------------------------------------------
		# This commented code puts a word inside a parentesys
		# at the end of the line, but for the printed
		# typesetting it is better another option.
		#-------------------------------------------------------

                #&output ("{~~\\hfill\\normalfont\\scriptsize\\slshape{}("
                #         . &command_continue_on_the_next_line_def ()
                #         . ")}\\newline");
                #&output ("  ");

		#-------------------------------------------------------
		# This other code, put a kind of visual guide to
		# the new line, at the beguinning.
		#-------------------------------------------------------

                #&output ("\\newline");
                #&output ("{");
                #&output ("\\hbox{");
                #&output ("\\normalfont");
                #&output ("\\fontsize{0.7em}{1em}\\selectfont");
                #&output ("\\sffamily");
                #&output ("\\bfseries{}");
                #&output ("~`->~");
                #&output ("}");
                #&output ("}");

                &output ("{\\lower0.5ex\\hbox{\$\\hookleftarrow\$}}");
                &output ("\\newline");
                &output ("{\\raise0.5ex\\hbox{\$\\hookrightarrow\$}}");

              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "DL")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{list}{}{}");
              }
            else
              {
                &output ("\n\\end{list}\n");
              }
          }
        elsif ($element eq "DT")
          {
            if ($type eq "start")
              {
                &output ("\n\\item\\hspace{-0,25in}");
              }
            else
              {
                &output ("\\nopagebreak\n");
              }
          }
        elsif ($element eq "DD")
          {
            if ($type eq "start")
              {
                &output ("");

		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level++;
              }
            else
              {
		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level--;

                &output ("");
              }
          }
        elsif ($element eq "OL")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{enumerate}");
              }
            else
              {
                &output ("\n\\end{enumerate}\n");
              }
          }
        elsif ($element eq "UL")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{itemize}");
              }
            else
              {
                &output ("\n\\end{itemize}\n");
              }
          }
        elsif ($element eq "LI")
          {
            if ($type eq "start")
              {
                &output ("\n\\item ");

		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level++;

              }
            else
              {

		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level--;

                &output ("");
              }
          }
        elsif ($element eq "SEGMENT")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{list}{}{}");

		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level++;

              }
            else
              {

		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level--;

                &output ("\n\\end{list}\n");
              }
          }
        elsif ($element eq "SEGMENTHEAD")
          {
            if ($type eq "start")
              {
	      	#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level--;

                &output ("\n\\item\\hspace{-0,25in}\\begin{sffamily}");
              }
            else
              {
                &output ("\\end{sffamily}\\nopagebreak\n");

		#-------------------------------------------------------
		# Text indent level.
		#-------------------------------------------------------
		$text_indent_level++;

              }
          }
        elsif ($element eq "IMG")
          {
            if ($type eq "start")
              {
                local ($imgfile) = "";
                local ($alt) = "";
                local ($width) = "";
                local ($heght) = "";
                # Save picture information.
                $imgfile = ${$attributes}{'IMGFILE'};
                $alt = ${$attributes}{'ALT'};
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                # New picture.
                
                # If target is PDF there is non need to convert to EPS.
                if ($target eq "PDF")
                  {
                    &output ("\\epsfig{file=$imgfile");
                    if ($height ne "")
                      {
                        &output (",height=$height");
                      }
                    if ($width ne "")
                      {
                        &output (",width=$width");
                      }
                    &output (",angle=0}");
                  }
                else
                  {
                    $ps_picture_counter++;
                    if (-r "$imgfile.png")
                      {
                        #system ("convert $imgfile.png EPSI:$ps_picture_counter.ps");
                        system ("convert $imgfile.png EPS:$ps_picture_counter.ps");
                        &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                               $program_executable,
                                               $original_file_name,
                                               "$imgfile.png",
                                               "$ps_picture_counter.ps"));
                      }
                    else
                      {
                        &diag_output (sprintf (gettext ("%s: cannot convert %s to %s !!!!\n"),
                                               $program_executable,
                                               "$imgfile.png",
                                               "$ps_picture_counter.ps"));
                      }
                    &output ("\\epsfig{file=$ps_picture_counter");
                    if ($height ne "")
                      {
                        &output (",height=$height");
                      }
                    if ($width ne "")
                      {
                        &output (",width=$width");
                      }
                    &output (",angle=0}");
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "EMBIMG")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($img_code) = "";
                local ($img_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                # Restore the base64 code.
                $img_code = $img_code . &pop_output ();

                # Prepare the temporary file.
                $img_temp_file = &temporary_file ($temporary_file_name_prefix);
                # Save the empty temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}";

                open (IMG_TEMP_FILE, "> ${img_temp_file}.uuencode ");
                print IMG_TEMP_FILE ("begin-base64 664 dummy\n");
                print IMG_TEMP_FILE ($img_code);
                print IMG_TEMP_FILE ("\n");
                print IMG_TEMP_FILE ("====\n");
                close (IMG_TEMP_FILE);

                # Get the picture with uudecode.
                system ("uudecode -o ${img_temp_file}.uudecode ${img_temp_file}.uuencode");

                # Convert to PNG if target is PDF.
                if ($target eq "PDF")
                  {
                    system ("convert ${img_temp_file}.uudecode ${img_temp_file}.png");
                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uuencode";
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uudecode";
                  }
                else
                  {
                    $ps_picture_counter++;
                    #system ("convert ${img_temp_file}.uudecode EPSI:${ps_picture_counter}.eps");
                    system ("convert ${img_temp_file}.uudecode EPS:${ps_picture_counter}.eps");
                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uuencode";
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uudecode";
                  }

                # Print picture file.
                if ($target eq "PDF")
                  {
                    # Include the PNG picture.
                    &output ("\\epsfig{file=${img_temp_file}.png");
                  }
                else
                  {
                    # Include the PostScript picture.
                    &output ("\\epsfig{file=${img_temp_file}.eps");
                  }
                if ($height ne "")
                  {
                    &output (",height=$height");
                  }
                if ($width ne "")
                  {
                    &output (",width=$width");
                  }
                &output (",angle=0}");
        
              }
          }
        elsif ($element eq "VAR")
          {
            if ($type eq "start")
              {
                # The extra space before and after the VAR element
                # is necessary to separate more VAR elements for
                # the reader.
                &output ("\\mbox{\\nolinebreak\\hspace{0.05em}}\\nolinebreak\\AlmlVar{");
              }
            else
              {
                # The extra space before and after the VAR element
                # is necessary to separate more VAR elements for
                # the reader.
                &output ("}\\nolinebreak\\mbox{\\hspace{0.05em}\\nolinebreak}");
              }
          }
        elsif ($element eq "SYNSQB")
          {
            if ($type eq "start")
              {
                &output ("\\AlmlSynLsqb{}");
              }
            else
              {
                # The \hspace{0pt} is used to let a line break be there.
                &output ("\\AlmlSynRsqb\\hspace{0pt}");
              }
          }
        elsif ($element eq "SYNCUB")
          {
            if ($type eq "start")
              {
                &output ("\\AlmlSynLcub{}");
              }
            else
              {
                # The \hspace{0pt} is used to let a line break be there.
                &output ("\\AlmlSynRcub\\hspace{0pt}");
              }
          }
        elsif ($element eq "SYNVERBAR")
          {
            if ($type eq "start")
              {
                # The \hspace{0pt} is used to let a line break be there.
                &output ("\\hspace{0pt}\\AlmlSynVerbar{}");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SYNELLIPSIS")
          {
            if ($type eq "start")
              {
                &output ("\\AlmlSynEllipsis{}");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SYNSTAR")
          {
            if ($type eq "start")
              {
                &output ("\\AlmlSynStar{}");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "HR")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("\\rule{\\linewidth}{0.5pt}\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "NEWPAGE")
          {
            if ($type eq "start")
              {
                &output ("\\AlmlNewPage{}\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "BOTTOMPAGE")
          {
            if ($type eq "start")
              {
                &output ("\\AlmlVfill\n");
              }
            else
              {
                &output ("\\AlmlNewPage\n");
              }
          }
        elsif ($element eq "COMMAND")
          {
            if ($type eq "start")
              {
                # Save column width.
                $preformatted_column_width = ${$attributes}{'WIDTH'};
                # Correct min and max.
                if ($preformatted_column_width eq "")
                  {
                    # Default command is a little bigger than syntax and
                    # preformatted text.
                    $preformatted_column_width = 70;
                  }
                elsif ($preformatted_column_width < 50)
                  {
                    $preformatted_column_width = 50;
                  }
                elsif ($preformatted_column_width > 200)
                  {
                    $preformatted_column_width = 200;
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($command) = "";
		local ($indent_factor) = 0;
		if ($floating_block)
		  {
    		    $indent_factor = 1;
		  }
		else
		  {
    		    $indent_factor = 0.94**$text_indent_level;
		  }
                local ($font_size) =
		    (int ((46.9 * $indent_factor
		                * &convert_to_mm_as_number ($printed_body_width))
		          / $preformatted_column_width)) / 10;
                local ($font_spacing) = $font_size*1.2;
                # The normal mode for output() function is re-established.
                $command = &pop_output ();

                # Print the command.
                &output ("\n");
                &output ("\\vspace{0.3em}");
                &output ("{\\fontsize{$font_size}{$font_spacing}\\selectfont\n");
                &output ("{");
                &output ("$command");
                &output ("}");
                &output ("\\par}");
                &output ("\\vspace{0.3em}\n");
              }
          }
        elsif ($element eq "PROMPT")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($prompt) = "";
                $prompt = &pop_output ();

                # Replace "-" with \mbox{\texttt{-}}.
                $prompt =~ s/-/\\mbox{\\texttt{-}}/g;

                &output ("\\begin{ttfamily}");

                &output ("$prompt");

                &output ("\\end{ttfamily}");
              }
          }
        elsif ($element eq "TYPE")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($type) = "";
                $type = &pop_output ();

                # Replace "-" with \mbox{\texttt{-}}.
                $type =~ s/-/\\mbox{\\texttt{-}}/g;

                &output ("{\\bfseries\\ttfamily{}");

                &output ("$type");

                &output ("\\/}");
              }
          }
        elsif ($element eq "CNEWLINE")
          {
            if ($type eq "start")
              {

		#-------------------------------------------------------
		# This commented code put a word inside a parentesys
		# at the end of the line, but for the printed
		# typesetting it is better another option.
		#-------------------------------------------------------

                #&output ("{~~\\hfill\\normalfont\\scriptsize\\slshape{}("
                #         . &command_continue_on_the_next_line_def ()
                #         . ")}\\newline");
                #&output ("\\hbox{\\hspace{2em}}");

		#-------------------------------------------------------
		# This other code, put a kind of visual guide to
		# the new line, at the beguinning.
		#-------------------------------------------------------

                #&output ("\\newline");
                #&output ("{");
                #&output ("\\hbox{");
                #&output ("\\normalfont");
                #&output ("\\fontsize{0.7em}{1em}\\selectfont");
                #&output ("\\sffamily");
                #&output ("\\bfseries{}");
                #&output ("~`->~");
                #&output ("}");
                #&output ("}");

                &output ("{\\lower0.5ex\\hbox{\$\\hookleftarrow\$}}");
                &output ("\\newline");
                &output ("{\\raise0.5ex\\hbox{\$\\hookrightarrow\$}}");
                #&output ("{");
                #&output ("\\normalfont");
                #&output ("\\fontsize{0.7em}{1em}\\selectfont");
                #&output ("\\sffamily");
                #&output ("\\bfseries{}");
                #&output ("~`->~");
                #&output ("}");
                #&output ("}");


              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "ENDOFCHAPTER")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("\\AlmlVfillHalf\\nopagebreak{\\scriptsize\\slshape{}");
              }
            else
              {
		#-------------------------------------------------------
	        # It is necessary to close the paragraph before the
		# closing "}" to have the right base line skip.
		#-------------------------------------------------------
                &output ("\\par}\n");
              }
          }
        elsif ($element eq "BACKCOVERPICTURE")
          {
            if ($type eq "start")
              {
                # Save picture information.
                $back_cover_picture_file = ${$attributes}{'IMGFILE'};
                $back_cover_picture_width = ${$attributes}{'WIDTH'};
                $back_cover_picture_height = ${$attributes}{'HEIGHT'};
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "BACKCOVERTEXT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $back_cover_text = &pop_output ();

                # With %block; elements, there is a line feed character
                # at the top of the string. I don't know why.
                # Anyway, we have to delete this extra line feed.
                $back_cover_text =~ s/^\n?(.*)$/$1/s;
              }
          }

    } # sgml_tag_elab_latex_basic

    #-------------------------------------------------------------------
    # This is the elaboration process specific for the LaTeX back-end.
    #
    # &sgml_tag_elab_latex (TYPE, ELEMENT, %ATTRIBUTES,
    #                       TYPESETTING,
    #                       TARGET,
    #                       DRAFT,
    #                       PAGE-NUMBERING,
    #                       COMPACT,
    #                       LONG,
    #                       ORIGINAL_NAME,
    #                       ROOT_FILE_NAME)
    #
    sub sgml_tag_elab_latex
    {
        #---------------------------------------------------------------
        # Function arguments.
        #---------------------------------------------------------------
        local ($type)               = $_[0];
        local ($element)            = $_[1];
        local ($attributes)         = $_[2];
        local ($typesetting)        = $_[3];
        local ($target)             = $_[4];
        local ($draft)              = $_[5];
        local ($page_numbering)     = $_[6];
        local ($compact)            = $_[7];
        local ($long)               = $_[8];
        local ($original_file_name) = $_[9];
        local ($root_file_name)     = $_[10];
        local ($paper_width)        = $_[11];
	local ($paper_height)       = $_[12];

        #---------------------------------------------------------------
	# Before the true analisys, we have to check if there
	# is a block of "{\samepage", made by a section header,
	# that must be closed with a "}".
	# Othere block like these might be after all the if/elsif block.
        #---------------------------------------------------------------

        #---------------------------------------------------------------
	# Headers
        #---------------------------------------------------------------
        if ($type eq "start")
	  {
	    if ($header_to_be_closed)
	      {
		# This element happens just after an header.
	        if ($element eq "P"
		    || $element eq "SYNTAX"
		    || $element eq "COMMAND")
		  {
		    # That's ok.
		    $next_element_after_header_to_be_closed = $element;
		    # Reset.
		    $header_to_be_closed = 0;
		    $next_element_after_header_to_be_closed_nest_level = 0;
		  }
		else
		  {
		    # Don't do it.
                    &output ("}% samepage-end Sorry\n");
		    # Reset.
		    $next_element_after_header_to_be_closed = "";
		    $header_to_be_closed = 0;
		    $next_element_after_header_to_be_closed_nest_level = 0;
		  }
	      }
	    elsif ($next_element_after_header_to_be_closed eq $element)
	      {
	        # This means that the element that is to be closed
		# has now a new nest level
		# (should not happen if it is only P, SYNTAX or COMMAND).
		$next_element_after_header_to_be_closed_nest_level++;
	      }
	  }

        #---------------------------------------------------------------
	# SHEETH1 and SLIDEH1 all in a page.
        #---------------------------------------------------------------
        if (($type eq "start" && ($element eq "H1"
	                          || $element eq "SHEETH1"
	                          || $element eq "SLIDEH1"
	                          || $element eq "UNNUMBEREDH1")
	    )
	    ||($type ne "start" && ($element eq "INTRO"
	                          || $element eq "BODY"
	                          || $element eq "APPENDIX"
	                          || $element eq "INDEX")
	      )
	   )
	  {
	    if ($slide_to_be_closed)
	      {
		# Then close the slide.
                &output ("}% samepage-end for a SLIDEH1 or SHEETH1\n");
		# Reset.
		$slide_to_be_closed = 0;
	      }
	  }


        #---------------------------------------------------------------
        # Element handlers.
        # Element names and attribute names are uppercase.
        #---------------------------------------------------------------
        if ($element eq "ALML")
          {
            if ($type eq "start")
              {
                # Reset all counters and flags.
                $intro = 0;
                $tome = 0;
                $part = 0;
		$part_present = 0;
                $chapter = 0;
                $unnumbered_chapter = 0;
                $h1section_absolute_counter = 0;
                $appendix = 0;
                $sect1 = 0;         
                $sect2 = 0;         
                $sect3 = 0;         
                $index = 0;
                $table = 0;
                $absolute_table = 0;
                $picture =  0;
                $absolute_figure = 0;
                $absolute_listing = 0;
                $unnumbered = 0;
                $current_level = "";
                $document_position = "";

                $index_entry_counter = 0;

                # Save administrative information.
                $current_language = ${$attributes}{'LANG'};
                $document_language = $current_language;
                $tome_language = $current_language;
                $part_language = $current_language;
                $chapter_language = $current_language;
                $document_spacing = lc ${$attributes}{'SPACING'};

		# Moved outside this function.
		## Sort index entries.
                #&diag_output (sprintf (gettext ("%s:%s: sorting %s index entries.\n"),
                #                       $program_executable,
                #                       $original_file_name,
		#		       $#index_list));
                #&sort_index_list_completely (0, $#index_list);

                ## Check $document_chapter_definition
                #if ($document_chapter_definition eq "")
                #  {
                #    $document_chapter_definition = &chapter_def ();
                #  }
                ## Check $document_part_definition
                #if ($document_part_definition eq "")
                #  {
                #    $document_part_definition = &part_def ();
                #  }
                ## Check $document_part_definition
                #if ($document_tome_definition eq "")
                #  {
                #    $document_tome_definition = &tome_def ();
                #  }
              }
            else
              {
                # Print back cover page.
                if ($back_cover_picture_file ne ""
                    || $back_cover_text ne "")
                  {
                    # Need a back cover page.

                    # Set language information to document language.
                    $current_language = $document_language;

                    &output ("\\AlmlNewPage\n");
                    &output ("\\ifodd \\arabic{page}\n");
                    &output ("    % need another withe page\n");
                    &output ("    \\AlmlStylePageEmpty\n");
                    &output ("    ~\n");
                    &output ("    \\AlmlNewPage\n");
                    &output ("\\else\n");
                    &output ("    % need other two withe pages\n");
                    &output ("    \\AlmlStylePageEmpty\n");
                    &output ("    ~\n");
                    &output ("    \\AlmlNewPage\n");
                    &output ("    ~\n");
                    &output ("    \\AlmlNewPage\n");
                    &output ("\\fi\n");
                    &output ("\\AlmlStylePageEmpty\n");
                    &output ("\n\\null");
                    #&output ("\n\\vspace{1cm}");
                    if ($back_cover_picture_file ne "")
                      {
                        # New picture.

                        # If target is PDF there is non need to convert to EPS.
                        if ($target eq "PDF")
                          {
                            &output ("\n\\begin{center}");
                            &output ("\n\\epsfig{file=$back_cover_picture_file");
                            if ($back_cover_picture_height ne "")
                              {
                                &output (",height=$back_cover_picture_height");
                              }
                            if ($back_cover_picture_width ne "")
                              {
                                &output (",width=$back_cover_picture_width");
                              }
                            &output (",angle=0}");
                            &output ("\n\\end{center}");
                          }
                        else
                          {

                            $ps_picture_counter++;
                            if (-r "$back_cover_picture_file.png")
                              {
                                #system ("convert $back_cover_picture_file.png EPSI:$ps_picture_counter.ps");
                                system ("convert $back_cover_picture_file.png EPS:$ps_picture_counter.ps");
                                &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                                       $program_executable,
                                                       $original_file_name,
                                                       "$back_cover_picture_file.png",
                                                       "$ps_picture_counter.ps"));
                              }
                            else
                              {
                                &diag_output (sprintf (gettext ("%s: cannot convert %s to %s !!!!\n"),
                                                       $program_executable,
                                                       "$back_cover_picture_file.png",
                                                       "$ps_picture_counter.ps"));
                              }
                            &output ("\n\\begin{center}");
                            &output ("\n\\epsfig{file=$ps_picture_counter");
                            if ($back_cover_picture_height ne "")
                              {
                                &output (",height=$back_cover_picture_height");
                              }
                            if ($back_cover_picture_width ne "")
                              {
                                &output (",width=$back_cover_picture_width");
                              }
                            &output (",angle=0}");
                            &output ("\n\\end{center}");
                          }
                      }
                    if ($back_cover_text ne "")
                      {
                        &output ("$back_cover_text");
                      }
                  }

                &output ("    % Save page location.\n");
                &output ("    \\immediate\\write\\AlmlAuxPageLocation{eof{}pageoffset{\\arabic{pageoffset}}relativepage{\\arabic{page}}}\n");

		# Close the Page location output (with a final diag record.
                &output ("\\immediate\\write\\AlmlAuxPageLocation{EOF}\n");
                &output ("\\immediate\\closeout\\AlmlAuxPageLocation\n");

		# Close the Page references output (with a final diag record.
                &output ("\\immediate\\write\\AlmlAuxPageRef{EOF}\n");
                &output ("\\immediate\\closeout\\AlmlAuxPageRef\n");

                # Close the LaTeX source
                &output ("\n\\end{document}");

              }
          }
        elsif ($element eq "HEAD")
          {
            if ($type eq "start")
              {
                # Save the document position.
                $document_position = "head";
              }
            else
              {
		#-------------------------------------------------------
                # End of header: compose into LaTeX.
		#-------------------------------------------------------
                local ($n) = 0;
                local ($line) = "";
                local ($headheight) = "";
                local ($headsep) = "";
                local ($footskip) = "";
                local ($topmargin) = "";
                local ($textheight) = "";
                local ($oddsidemargin) = "";
                local ($evensidemargin) = "";

		#-------------------------------------------------------
                # This is a book with Babel support for all available
		# languages.
		#-------------------------------------------------------
                &output ("\\documentclass{book}\n");
                &output ("\\usepackage[");
		for ($n = 0; $n <= $#language_list; $n++)
	          {
	    	    if (&latex_language_name($language_list[$n]) ne "")
		      {
            		&output (&latex_language_name($language_list[$n]));
            		&output (",");
		      }
		  }
                &output ("]{babel}\n");

		#-------------------------------------------------------
		# Use LaTeX symbols
		#-------------------------------------------------------
                &output ("\\usepackage{latexsym}\n");

		#-------------------------------------------------------
		# Use Euro symbol
		#-------------------------------------------------------
                &output ("\\usepackage{eurosym}\n");

		#-------------------------------------------------------
                # Define the book title.
		#-------------------------------------------------------
                &output ("\\newcommand\\AlmlTitle{$title}\n");

		#-------------------------------------------------------
                # Set page format.
		#-------------------------------------------------------
                &output ("\\setlength\\paperwidth{$paper_width}\n");
                &output ("\\setlength\\paperheight{$paper_height}\n");

                # Never stop on errors. Look inside log file instead.
                &output ("\\nonstopmode\n");

                # Control warnings.
                #&output ("\\tracingstats=1\n");

                # Include some TeX packages.
                &output ("\\usepackage{url}\n");
                &output ("\\usepackage\[latin1\]{inputenc}\n");
                &output ("\\usepackage{epsfig}\n");
                &output ("\\usepackage\[T1\]{fontenc}\n");
                &output ("\\usepackage{textcomp}\n");

                # Internal configuration starts here.
                &output ("\n");
                &output ("% Internal configuration\n");

                # Save space commands.
                if ($compact == 1)
                  {
                    &output ("\\newcommand\\AlmlNewPageHalf{\\par\\vspace{2cm}}\n");
                    &output ("\\newcommand\\AlmlNewPage{\\par\\vspace{2cm}}\n");
                    &output ("\\newcommand\\AlmlDoubleNewPage{\\par\\vspace{2cm}}\n");
                    &output ("\\newcommand\\AlmlEndOfPage{\\par}\n");
                    &output ("\\newcommand\\AlmlVfill{\\par}\n");
                    &output ("\\newcommand\\AlmlVfillHalf{\\par}\n");
                    &output ("\\newcommand\\AlmlStylePageEmpty{\\pagestyle{plain}}\n");
                    &output ("\\newcommand\\AlmlStylePageNormal{\\pagestyle{plain}}\n");
                    &output ("\\newcommand\\AlmlStylePageHeader{\\pagestyle{plain}}\n");
                  }
                elsif ($compact == 0.5)
                  {
                    &output ("\\newcommand\\AlmlNewPageHalf{\\par\\vspace{2cm}}\n");
                    &output ("\\newcommand\\AlmlNewPage{\\clearpage}\n");
                    &output ("\\newcommand\\AlmlDoubleNewPage{\\cleardoublepage}\n");
                    &output ("\\newcommand\\AlmlEndOfPage{\\newpage}\n");
                    &output ("\\newcommand\\AlmlVfill{~\n\n\\vfill}\n");
                    &output ("\\newcommand\\AlmlVfillHalf{\\par}\n");
                    &output ("\\newcommand\\AlmlStylePageEmpty{\\pagestyle{empty}}\n");
                    &output ("\\newcommand\\AlmlStylePageNormal{\\pagestyle{plain}}\n");
                    &output ("\\newcommand\\AlmlStylePageHeader{\\pagestyle{myheadings}}\n");
                  }
                else
                  {
                    &output ("\\newcommand\\AlmlNewPageHalf{\\clearpage}\n");
                    &output ("\\newcommand\\AlmlNewPage{\\clearpage}\n");
                    &output ("\\newcommand\\AlmlDoubleNewPage{\\cleardoublepage}\n");
                    &output ("\\newcommand\\AlmlEndOfPage{\\newpage}\n");
                    &output ("\\newcommand\\AlmlVfill{~\n\n\\vfill}\n");
                    &output ("\\newcommand\\AlmlVfillHalf{~\n\n\\vfill}\n");
                    &output ("\\newcommand\\AlmlStylePageEmpty{\\pagestyle{empty}}\n");
                    &output ("\\newcommand\\AlmlStylePageNormal{\\pagestyle{plain}}\n");
                    &output ("\\newcommand\\AlmlStylePageHeader{\\pagestyle{myheadings}}\n");
                  }

                # Special words or names.
                &output ("\n");
                if ($draft)
                  {
                    &output ("\\newcommand{\\AlmlSpecial}[2]{\\underline{{#1}}{\\lower.25ex\\hbox{\\fontsize{0.6em}{1em}\\selectfont{#2}}}}\n");
                  }
                else
                  {
                    &output ("\\newcommand{\\AlmlSpecial}[2]{{{#1}}}\n");
                  }

                # Stranger definition.
                &output ("\n");
                &output ("\\newcommand{\\AlmlStrDef}[1]{{\\textit{#1}}}\n");

                # Typewriter minus.
                &output ("\n");
                &output ("\\newcommand{\\AlmlMinus}{\\mbox{\\texttt{-}}}\n");

                # Metasyntactic variable.
                &output ("\n");
                &output ("\\newcommand{\\AlmlVar}[1]{{\\mbox{\\normalfont\\bfseries\\itshape{}#1\\/}}}\n");

                # Syntax symbols.
                &output ("\n");
                &output ("\\newcommand\\AlmlSynLsqb{\\mbox{\\hspace{3pt}{\\normalfont\\fontsize{1.7em}{2.8em}\\selectfont{\\leavevmode\\hbox{\\kern-.2em\\lower.25ex\\hbox{[}\\kern-.2em}}}\\hspace{3pt}}}\n");
                &output ("\\newcommand\\AlmlSynRsqb{\\mbox{\\hspace{3pt}{\\normalfont\\fontsize{1.7em}{2.8em}\\selectfont{\\leavevmode\\hbox{\\kern-.2em\\lower.25ex\\hbox{]}\\kern-.2em}}}\\hspace{3pt}}}\n");
                &output ("\\newcommand\\AlmlSynLcub{\\mbox{\\hspace{3pt}{\\normalfont\\fontsize{1.7em}{2.8em}\\selectfont{\\leavevmode\\hbox{\\kern-.2em\\lower.25ex\\hbox{\\{}\\kern-.2em}}}\\hspace{3pt}}}\n");
                &output ("\\newcommand\\AlmlSynRcub{\\mbox{\\hspace{3pt}{\\normalfont\\fontsize{1.7em}{2.8em}\\selectfont{\\leavevmode\\hbox{\\kern-.2em\\lower.25ex\\hbox{\\}}\\kern-.2em}}}\\hspace{3pt}}}\n");
                &output ("\\newcommand\\AlmlSynVerbar{\\mbox{\\hspace{3pt}{\\normalfont\\fontsize{1.7em}{2.8em}\\selectfont{\\leavevmode\\hbox{\\kern-.2em\\lower.25ex\\hbox{|}\\kern-.2em}}}\\hspace{3pt}}}\n");
                &output ("\\newcommand\\AlmlSynEllipsis{{\\normalfont\\fontsize{0.8em}{1.3em}\\selectfont{}...}}\n");
                #&output ("\\newcommand\\AlmlSynStar{{\\normalfont\\fontsize{1.7em}{2.8em}\\selectfont{}*}}\n");
                &output ("\\newcommand\\AlmlSynStar{{\\normalfont\\fontsize{1.7em}{2.8em}\\selectfont{\\leavevmode\\hbox{\\lower0.66ex\\hbox{*}}}}}\n");

                # Need to define a CODE command to be able to delete it from
		# indexes
                &output ("\n");
                #&output ("\\newcommand{\\AlmlIndexEntryCode}[1]{{\\fontsize{0.9em}{1.3em}\\selectfont\\texttt{#1}}}\n");
                &output ("\\newcommand{\\AlmlIndexEntryCode}[1]{{\\texttt{#1}}}\n");

		#-------------------------------------------------------
		# No hyphenation:
		#
		# for unknown reasons, \hyphenation{nohyphenation}
		# does not work. So, we use high \lefthyphenmin and
		# \righthyphenmin values. But it seems to work only
		# for block of text, so it is useless.
		#-------------------------------------------------------
                #&output ("\n");
                #&output ("\\newcommand{\\AlmlNoHyphenation}{\\lefthyphenmin=100 \\righthyphenmin=100}\n");

		#-------------------------------------------------------
                # Margins and spaces.
		#-------------------------------------------------------

                #&output ("\n");
                #&output ("\\marginparwidth 0.0 in\n");
                #&output ("\\parindent 0.0 in\n");
                #&output ("\\topmargin -0.66 in % reduce top margin\n");
                #&output ("\\setlength{\\textheight}{\\paperheight}\n");
                #&output ("\\addtolength{\\textheight}{-1.66 in} % Reduce bottom margin\n");
                #&output ("\\advance\\headsep 2 ex\n");
                #&output ("\\advance\\textheight -2 ex\n");
                #&output ("\n");

                &output ("\n");
                &output ("\\marginparwidth 0.0 in\n");
                &output ("\\parindent 0.0 in\n");
                &output ("% Headers are made with the \"normal\" size.\n");
		$headheight = (&length_value ($printed_font_size_normal)
		               * 1.3)
			      . &length_unit ($printed_font_size_normal);
                &output ("\\headheight $headheight\n");
		$headsep = (&length_value ($printed_font_size_normal)
		            * 1.9)
			   . &length_unit ($printed_font_size_normal);
                &output ("\\headsep $headsep\n");
		$footskip = (&length_value ($printed_font_size_normal)
		             * 2.7)
			    . &length_unit ($printed_font_size_normal);
                &output ("\\footskip $footskip\n");
                &output ("% Calculate top margin subtracting the 1 inch standard and the header size.\n");
		$topmargin = $printed_top_margin;
		$topmargin = &length_sub ($topmargin, "1in");
		$topmargin = &length_sub ($topmargin, $headheight);
		$topmargin = &length_sub ($topmargin, $headsep);
                &output ("\\topmargin $topmargin\n");
                &output ("% Calculate body text length.\n");
		$textheight = $paper_height;
		$textheight = &length_sub ($textheight, "1in");
		$textheight = &length_sub ($textheight, $headheight);
		$textheight = &length_sub ($textheight, $headsep);
		$textheight = &length_sub ($textheight, $printed_bottom_margin);
		$textheight = &length_sum ($textheight, "1.5cm"); # don't know why I need this extra length.
                &output ("\\textheight $textheight\n");
                &output ("\n");

		#-------------------------------------------------------
                # H margins.
		#-------------------------------------------------------
                if ($long)
                  {
		    #---------------------------------------------------
		    # Horizontal equal margins.
		    #---------------------------------------------------
                    &output ("\\textwidth $printed_body_width\n");

		    $oddsidemargin = $paper_width;
    		    $oddsidemargin = &length_sub ($oddsidemargin, $printed_body_width);
		    $oddsidemargin = (&length_value ($oddsidemargin) / 2)
			             . &length_unit ($oddsidemargin);
    		    $oddsidemargin = &length_sub ($oddsidemargin, "1in");
                    &output ("\\oddsidemargin $oddsidemargin\n");

		    $evensidemargin = $paper_width;
    		    $evensidemargin = &length_sub ($evensidemargin, $printed_body_width);
		    $evensidemargin = (&length_value ($evensidemargin) / 2)
			              . &length_unit ($evensidemargin);
    		    $evensidemargin = &length_sub ($evensidemargin, "1in");
                    &output ("\\evensidemargin $evensidemargin\n");
                  }
                else
                  {
		    #---------------------------------------------------
		    # Using internal margin for rigth and left pages.
		    #---------------------------------------------------
                    &output ("\\textwidth $printed_body_width\n");

		    $oddsidemargin = $printed_internal_margin;
    		    $oddsidemargin = &length_sub ($oddsidemargin, "1in");
                    &output ("\\oddsidemargin $oddsidemargin\n");

		    $evensidemargin = $paper_width;
    		    $evensidemargin = &length_sub ($evensidemargin, $printed_body_width);
    		    $evensidemargin = &length_sub ($evensidemargin, $printed_internal_margin);
    		    $evensidemargin = &length_sub ($evensidemargin, "1in");
                    &output ("\\evensidemargin $evensidemargin\n");
                  }

		#-------------------------------------------------------
                # This is for DVIPS.
		#-------------------------------------------------------
                &output ("\\special{papersize=$paper_width,$paper_height} % for DVIPS\n");

                &output ("\n");
                &output ("\\renewcommand{\\baselinestretch}{1}\n");
                &output ("\\addtolength{\\parskip}{1.5 ex}\n");

                # \framebox configuration.
                &output ("\n");
                &output ("\\fboxrule 0.2 bp\n");
                &output ("\\fboxsep 1 bp\n");

                # Less troubles about text line break and vertical space.
                &output ("\n");
                &output ("\\sloppy\n");
                &output ("\\raggedbottom\n");

                # Configure the \url package: use the same external
                # formatting.
                &output ("\n");
                &output ("\\urlstyle{same}");

                # Create and set the page offset counter.
                &output ("\n");
                &output ("\\newcounter{pageoffset}\n");
                &output ("\\setcounter{pageoffset}{0}\n");

                # Create and set the tome counter.
                &output ("\n");
                &output ("\\newcounter{tome}\n");
                &output ("\\setcounter{tome}{0}\n");

                # Define the starting page numbering.
                &output ("\n");
                if ($page_numbering eq "plain")
                  {
                    &output ("\\pagenumbering{arabic}\n");
                    &output ("\\setcounter{page}{1}\n");
                  }
                else
                  {
                    &output ("\\pagenumbering{Roman}\n");
                    &output ("\\setcounter{page}{1}\n");
                  }

                # Define how does it work the \AlmlContent command.
                &output ("\n");
                if ($page_numbering eq "plain")
                  {
                    &output ("\\newcommand{\\AlmlContent}{}\n");
                  }
                else
                  {
                    &output ("\\newcommand{\\AlmlContent}\n");
                    &output ("{\n");
                    &output ("    \\ifodd \\arabic{page}\n");
                    &output ("        \\AlmlDoubleNewPage\n");
                    &output ("    \\else\n");
                    &output ("        \\AlmlNewPage\n");
                    &output ("    \\fi\n");
                    &output ("    \\addtocounter{pageoffset}{\\arabic{page}}\n");
                    &output ("    \\addtocounter{pageoffset}{-1}\n");
                    &output ("    \\AlmlStylePageEmpty\n");
                    &output ("    \\pagenumbering{arabic}\n");
                    &output ("    \\setcounter{page}{1}\n");
                    &output ("}\n");
                  }

                # Define standard fonts dimentions.
                &output ("\n");
                
                # Normalfont, used inside normal text.
                if ($printed_font_size_normal eq "")
                  {
                    &output ("\\renewcommand{\\normalsize}{\\fontsize{10}{12}\\selectfont}\n");
                  }
                else
                  {
                    &output ("\\renewcommand{\\normalsize}{\\fontsize{$printed_font_size_normal}{$printed_font_height_normal}\\selectfont}\n");
                  }

                # Footnote size, used inside \footnote{...}
                &output ("\\renewcommand{\\footnotesize}{\\normalsize\\fontsize{0.8em}{0.96em}\\selectfont}\n");

                # Table size, used inside tables
                if ($printed_font_size_table eq "")
                  {
                    &output ("\\newcommand{\\AlmlTablesize}{\\normalsize\\fontsize{0.9em}{1.1em}\\selectfont}\n");
                  }
                else
                  {
                    &output ("\\newcommand{\\AlmlTablesize}{\\fontsize{$printed_font_size_table}{$printed_font_height_table}\\selectfont}\n");
                  }

                # Caption size, used after tables and pictures
                &output ("\\newcommand{\\AlmlCaptionsize}{\\normalsize\\fontsize{0.8em}{1em}\\selectfont}\n");
        
                # Title size, used for the big title of the document
		if ($printed_font_size_title eq "")
                  {
                    &output ("\\newcommand{\\AlmlTitlesize}{\\normalsize\\fontsize{40}{50}\\selectfont}\n");
                  }
                else
                  {
                    &output ("\\newcommand{\\AlmlTitlesize}{\\normalsize\\fontsize{$printed_font_size_title}{$printed_font_height_title}\\selectfont}\n");
                  }

                # More traditional font sizes
                &output ("\\renewcommand{\\Huge}{\\fontsize{25}{30}\\selectfont}\n");
                &output ("\\renewcommand{\\huge}{\\fontsize{20}{25}\\selectfont}\n");
                &output ("\\renewcommand{\\LARGE}{\\fontsize{17}{22}\\selectfont}\n");
                &output ("\\renewcommand{\\Large}{\\fontsize{14}{18}\\selectfont}\n");
                &output ("\\renewcommand{\\large}{\\fontsize{12}{14}\\selectfont}\n");
                &output ("\\renewcommand{\\small}{\\fontsize{9}{10}\\selectfont}\n");
                &output ("\\renewcommand{\\scriptsize}{\\fontsize{7}{8}\\selectfont}\n");
                #&output ("\\renewcommand{\\tiny}{\\fontsize{5}{6}\\selectfont}\n"); #NOT USED

                # Activate the default size.
                &output ("\n");
                &output ("\\normalsize\n");

                # Define some standard distances.
                &output ("\n");
                &output ("\\setlength\\smallskipamount{2pt}\n");
                &output ("\\setlength\\medskipamount{4pt}\n");
                &output ("\\setlength\\bigskipamount{6pt}\n");
                &output ("\\setlength\\headheight{12pt}\n");
                &output ("\\setlength\\headsep{0.25in}\n");
                &output ("\\setlength\\topskip{5pt}\n");
                &output ("\\setlength\\footskip{0.25in}\n");

                # Define new TeX report file for page references.
                &output ("\\newwrite\\AlmlAuxPageRef\n");
                # Open the file: jobnape + .pageref.
                &output ("\\immediate\\openout\\AlmlAuxPageRef\\jobname.pageref\n");
                # Write something for debugging purposes.
                &output ("\\immediate\\write\\AlmlAuxPageRef{BOF}\n");

                # Define new TeX report file for page locations.
                &output ("\\newwrite\\AlmlAuxPageLocation\n");
                # Open the file: jobnape + .pagelocation.
                &output ("\\immediate\\openout\\AlmlAuxPageLocation\\jobname.pageloc\n");
                # Write something for debugging purposes.
                &output ("\\immediate\\write\\AlmlAuxPageLocation{BOF}\n");

                # Define a Label function.
                &output ("% It is important to have the following definition all in one line\n");
                &output ("\\newcommand{\\AlmlLabel}[1]{\\immediate\\write\\AlmlAuxPageRef{\\string\\AlmlNewLabel{#1}{\\thepage}}}\n");
		# Define the special command that will be used to put page numbers.
		# This command is parsed from the alml front-end
		# \AlmlPageRef{0}{000}{label}
                &output ("\\newcommand{\\AlmlPageRef}[3]{#2}\n");

                # Define the tome.
                &output ("\n");
                &output ("\\newcommand{\\AlmlTome}[1]\n");
                &output ("{\n");
                &output ("    % Clear and new page if not already done.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % If the page is odd, we can stay here.\n");
                &output ("    \\ifodd \\arabic{page}\n");
                &output ("        % Ok, start from here.\n");
                &output ("    \\else\n");
                &output ("        % Need to print something to be able to jump to another page.\n");
                &output ("        ~\n");
                &output ("        \\AlmlNewPage\n");
                &output ("    \\fi\n");
                &output ("    % Define the header also if unused.\n");
                &output ("    \\markboth{}{}\n");
                &output ("    % Starting and following tome pages must be plain.\n");
                &output ("    \\AlmlStylePageNormal\n");
                &output ("    \\stepcounter{tome}\n");
                &output ("    % Save page location.\n");
                &output ("    \\immediate\\write\\AlmlAuxPageLocation{tome{\\arabic{tome}}pageoffset{\\arabic{pageoffset}}relativepage{\\arabic{page}}}\n");
                &output ("    % Print the titles.\n");
                &output ("    \\par\n");
                &output ("    \\begin{flushright}\n");
                &output ("        \\normalfont\n");
		if ($printed_font_size_h2 eq "")
                  {
            	    &output ("        \\LARGE");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h2}{$printed_font_height_h2}\\selectfont\n");
                  }
                if ($edition eq "")
                  {
                    &output ("        \\sffamily\\AlmlTitle ~~\n");
                  }
                else
                  {
                    &output ("        \\sffamily\\AlmlTitle ~~\n");
                  }
                &output ("        {\\fontsize{0.8em}{1em}\\selectfont $version $edition}\n");
                &output ("        \\par\n");
                &output ("        ");
                &output (ucfirst (&tome_def ()));
                &output ("~~\\rmfamily\\Roman{tome}\n");
                &output ("        \\par\n");
		if ($printed_font_size_tomeheading eq "")
                  {
            	    &output ("        \\Huge\n");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_tomeheading}{$printed_font_height_tomeheading}\\selectfont\n");
                  }
                &output ("        \\sffamily #1\n");
                &output ("    \\end{flushright}\n");
                &output ("    \\par\n");
                &output ("}\n");

                # Define the part
                &output ("\n");
                &output ("\\newcommand{\\AlmlPart}[1]\n");
                &output ("{\n");
                &output ("    % Clear and new page if not already done.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % If the page is odd, we can stay here.\n");
                &output ("    \\ifodd \\arabic{page}\n");
                &output ("        % Ok, start from here.\n");
                &output ("    \\else\n");
                &output ("        % Need to print something to be able to jump to another page.\n");
                &output ("        ~\n");
                &output ("        \\AlmlNewPage\n");
                &output ("    \\fi\n");
                &output ("    % Define the header also if unused.\n");
                &output ("    \\markboth{}{}\n");
                &output ("    % Starting and following tome pages must be plain.\n");
                &output ("    \\AlmlStylePageNormal\n");
                &output ("    \\stepcounter{part}\n");
                &output ("    % Save page location.\n");
                &output ("    \\immediate\\write\\AlmlAuxPageLocation{part{\\arabic{part}}pageoffset{\\arabic{pageoffset}}relativepage{\\arabic{page}}}\n");
                &output ("    % Print the titles.\n");
                &output ("    \\par\n");
                &output ("    \\begin{flushright}\n");
                &output ("        \\normalfont\n");
		if ($printed_font_size_h2 eq "")
                  {
            	    &output ("        \\LARGE");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h2}{$printed_font_height_h2}\\selectfont\n");
                  }
                ## Non si pu mettere il titolo dell'opera nelle parti perch
                ## portrebbero appartenere ad altri documenti inclusi come tomi.
                &output ("        ");
                &output (ucfirst (&part_def ()));
                &output ("~~\\rmfamily\\roman{part}\n");
                &output ("        \\par\n");
		if ($printed_font_size_h0 eq "")
                  {
            	    &output ("        \\Huge\n");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h0}{$printed_font_height_h0}\\selectfont\n");
                  }
                &output ("        \\sffamily #1\n");
                &output ("    \\end{flushright}\n");
                &output ("    \\par\n");
                &output ("}\n");

                # Define the introduction page to appendixes.
                &output ("\n");
                &output ("\\newcommand{\\AlmlAppendixes}\n");
                &output ("{\n");
                &output ("    % Clear and new page if not already done.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % If the page is odd, we can stay here.\n");
                &output ("    \\ifodd \\arabic{page}\n");
                &output ("        % Ok, start from here.\n");
                &output ("    \\else\n");
                &output ("        % Need to print something to be able to jump to another page.\n");
                &output ("        ~\n");
                &output ("        \\AlmlNewPage\n");
                &output ("    \\fi\n");
                &output ("    % Define the header also if unused.\n");
                &output ("    \\markboth{}{}\n");
                &output ("    % Save page location.\n");
                &output ("    \\immediate\\write\\AlmlAuxPageLocation{appendix{}pageoffset{\\arabic{pageoffset}}relativepage{\\arabic{page}}}\n");
                &output ("    % This page must be plain.\n");
                &output ("    \\thispagestyle{plain}\n");
                &output ("    % Print the title.\n");
                &output ("    \\begin{flushright}\n");
                &output ("        \\normalfont\n");
		if ($printed_font_size_h0 eq "")
                  {
            	    &output ("        \\Huge\n");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h0}{$printed_font_height_h0}\\selectfont\n");
                  }
                &output ("        \\sffamily\n");
                &output ("        ");
                &output (ucfirst (&appendixes_def ()));
                &output ("\\par\n");
                &output ("    \\end{flushright}\n");
                &output ("    % Terminate the current page.\n");
                &output ("    \\AlmlEndOfPage\n");
                &output ("    % Start now the appendix.\n");
                &output ("    \\appendix\n");
                &output ("}\n");

                # Define an introduction chapter.
                &output ("\n");
                &output ("\\newcommand{\\AlmlChapterIntro}[1]\n");
                &output ("{\n");
                &output ("    % New page, left or right.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % First page should be plain.\n");
                &output ("    \\thispagestyle{plain}\n");
                &output ("    % Define the header also if unused.\n");
                if ($draft)
		  {
		    # It is better to avoid showing index entry items;
		    # so, it is better do avoid to have page headers.
            	    &output ("    \\markboth{}{}\n");
		  }
		else
		  {
            	    &output ("    \\markboth{\\normalfont\\sffamily #1}{\\normalfont\\sffamily #1}\n");
		  }
                &output ("    % Print chapter title.\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily #1\\par\n");
                &output ("    \\vspace{5pt}\n");
                &output ("    \\normalsize\n");
                &output ("    \\normalfont\n");
                &output ("    % Next pages remain plain.\n");
                &output ("    \\AlmlStylePageNormal\n");
                &output ("}\n");

                # Define an index chapter.
                &output ("\n");
                &output ("\\newcommand{\\AlmlChapterIndex}[1]\n");
                &output ("{\n");
                &output ("    % New page, left or right.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % First page should be plain.\n");
                &output ("    \\thispagestyle{plain}\n");
                &output ("    % Define the header also if unused.\n");
                if ($draft)
		  {
		    # It is better to avoid showing index entry items;
		    # so, it is better do avoid to have page headers.
            	    &output ("    \\markboth{}{}\n");
		  }
		else
		  {
            	    &output ("    \\markboth{\\normalfont\\sffamily #1}{\\normalfont\\sffamily #1}\n");
		  }
                &output ("    % Print chapter title.\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily #1\\par\n");
                &output ("    \\vspace{5pt}\n");
                &output ("    \\normalsize\n");
                &output ("    \\normalfont\n");
                &output ("    % Next pages are with headers.\n");
                &output ("    \\AlmlStylePageHeader\n");
                &output ("}\n");

                # Define a numbered chapter.
                &output ("\n");
                &output ("\\newcommand{\\AlmlChapterNumbered}[1]\n");
                &output ("{\n");
                &output ("    % New page, left or right.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % Increment chapter counter.\n");
                &output ("    \\stepcounter{chapter}\n");
                &output ("    % Define the header also if unused.\n");
                if ($draft)
		  {
		    # It is better to avoid showing index entry items;
		    # so, it is better do avoid to have page headers.
            	    &output ("    \\markboth{}{}\n");
		  }
		else
		  {
            	    &output ("    \\markboth{\\normalfont\\sffamily #1}{\\normalfont\\sffamily #1}\n");
		  }
                &output ("    % First page should be plain.\n");
                &output ("    \\thispagestyle{plain}\n");
                &output ("    % Move a little bit up.\n");
                &output ("    \\vspace*{-0.7in}\n");
                &output ("    % Print the chapter number.\n");
                &output ("    \\begin{flushright}\n");
                &output ("        \\small\\rmfamily\\itshape\n");
                &output (ucfirst (&chapter_def ()));
                &output ("        ~ \\normalfont\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily\n");
                &output ("        \\arabic{chapter}\n");
                &output ("        \\nobreak\n");
                &output ("    \\end{flushright}\\nobreak\n");
                &output ("    \\nobreak\\vspace{-10pt}\\nobreak\n");
                &output ("    % Print chapter title.\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily #1");
                &output ("    \\par\\nobreak\n");
                &output ("    \\vspace{5pt}\n");
                &output ("    \\normalsize\n");
                &output ("    \\normalfont\n");
                &output ("    % Next pages are with headers.\n");
                &output ("    \\AlmlStylePageHeader\n");
                &output ("}\n");

                # Define an unnumbered chapter.
                &output ("\n");
                &output ("\\newcommand{\\AlmlChapterUnnumbered}[1]\n");
                &output ("{\n");
                &output ("    % New page, left or right.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % Define the header also if unused.\n");
                if ($draft)
		  {
		    # It is better to avoid showing index entry items;
		    # so, it is better do avoid to have page headers.
            	    &output ("    \\markboth{}{}\n");
		  }
		else
		  {
            	    &output ("    \\markboth{\\normalfont\\sffamily #1}{\\normalfont\\sffamily #1}\n");
		  }
                &output ("    % First page should be plain.\n");
                &output ("    \\thispagestyle{plain}\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily #1\\par\n");
                &output ("    \\vspace{5pt}\n");
                &output ("    \\normalsize\n");
                &output ("    \\normalfont\n");
                &output ("    % Next pages remain plain.\n");
                &output ("    \\AlmlStylePageNormal\n");
                &output ("}\n");

                # Define a presentation slide or overhead transparency.
                &output ("\n");
                &output ("\\newcommand{\\AlmlChapterPresentationSlide}[1]\n");
                &output ("{\n");
                &output ("    % New page, left or right.\n");
                &output ("    % Cannot use half new page because the {\\samepage...}\n");
                &output ("    % does not work well for big blocks.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % Increment chapter counter.\n");
                &output ("    \\stepcounter{chapter}\n");
                &output ("    % Pages should be empty or plain.\n");
                &output ("    \\AlmlStylePageEmpty{}\n");
                &output ("    % Move a little bit up.\n");
                &output ("    \\vspace*{-0.7in}\n");
                &output ("    % Print the chapter number.\n");
                &output ("    \\begin{flushright}\n");
                #&output ("        \\small\\rmfamily\\itshape\n");
                #&output (ucfirst (&chapter_def ()));
                &output ("        ~ \\normalfont\n");
                &output ("        \\Large\\sffamily\n");
                &output ("        \\arabic{chapter}\n");
                &output ("        ~ \\small\\rmfamily\\itshape\n");
                &output (lc (&presentation_slide_def ()));
                &output ("        \\normalfont\n");
                &output ("        \\nobreak\n");
                &output ("    \\end{flushright}\\nobreak\n");
                &output ("    \\nobreak\\vspace{-10pt}\\nobreak\n");
                &output ("    % Print chapter title.\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily #1");
                &output ("    \\par\\nobreak\n");
                &output ("    \\vspace{5pt}\n");
                &output ("    \\normalsize\n");
                &output ("    \\normalfont\n");
                &output ("}\n");

                # Define a summary sheet.
                &output ("\n");
                &output ("\\newcommand{\\AlmlChapterSummarySheet}[1]\n");
                &output ("{\n");
                &output ("    % New page, left or right.\n");
                &output ("    % Cannot use half new page because the {\\samepage...}\n");
                &output ("    % does not work well for big blocks.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % Increment chapter counter.\n");
                &output ("    \\stepcounter{chapter}\n");
                &output ("    % Pages should be empty or plain.\n");
                &output ("    \\AlmlStylePageEmpty{}\n");
                &output ("    % Move a little bit up.\n");
                &output ("    \\vspace*{-0.7in}\n");
                &output ("    % Print the chapter number.\n");
                &output ("    \\begin{flushright}\n");
                #&output ("        \\small\\rmfamily\\itshape\n");
                #&output (ucfirst (&chapter_def ()));
                &output ("        ~ \\normalfont\n");
                &output ("        \\Large\\sffamily\n");
                &output ("        \\arabic{chapter}\n");
                &output ("        ~ \\small\\rmfamily\\itshape\n");
                &output (lc (&summary_sheet_def ()));
                &output ("        \\normalfont\n");
                &output ("        \\nobreak\n");
                &output ("    \\end{flushright}\\nobreak\n");
                &output ("    \\nobreak\\vspace{-10pt}\\nobreak\n");
                &output ("    % Print chapter title.\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily #1");
                &output ("    \\par\\nobreak\n");
                &output ("    \\vspace{5pt}\n");
                &output ("    \\normalsize\n");
                &output ("    \\normalfont\n");
                &output ("}\n");

                # Define an appendix chapter.
                &output ("\n");
                &output ("\\newcommand{\\AlmlChapterAppendix}[1]\n");
                &output ("{\n");
                &output ("    % New page, left or right.\n");
                &output ("    \\AlmlNewPage\n");
                &output ("    % Increment chapter counter.\n");
                &output ("    \\stepcounter{chapter}\n");
                &output ("    % Define the header also if unused.\n");
                if ($draft)
		  {
		    # It is better to avoid showing index entry items;
		    # so, it is better do avoid to have page headers.
            	    &output ("    \\markboth{}{}\n");
		  }
		else
		  {
            	    &output ("    \\markboth{\\normalfont\\sffamily #1}{\\normalfont\\sffamily #1}\n");
		  }
                &output ("    % First page should be plain.\n");
                &output ("    \\thispagestyle{plain}\n");
                &output ("    % Move a little bit up.\n");
                &output ("    \\vspace*{-0.7in}\n");
                &output ("    % Print the chapter number.\n");
                &output ("    \\begin{flushright}\n");
                &output ("        \\small\\rmfamily\\itshape\n");
                &output (ucfirst (&appendix_def ()));
                &output ("        ~ \\normalfont\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily\n");
                &output ("        \\Alph{chapter}\n");
                &output ("        \\nobreak\n");
                &output ("    \\end{flushright}\\nobreak\n");
                &output ("    \\nobreak\\vspace{-10pt}\\nobreak\n");
                &output ("    % Print chapter title.\n");
		if ($printed_font_size_h1 eq "")
                  {
            	    &output ("        \\Huge");
                  }
                else
                  {
            	    &output ("        \\fontsize{$printed_font_size_h1}{$printed_font_height_h1}\\selectfont");
                  }
                &output ("\\sffamily #1");
                &output ("    \\par\\nobreak\n");
                &output ("    \\vspace{5pt}\n");
                &output ("    \\normalsize\n");
                &output ("    \\normalfont\n");
                &output ("    % Next pages remain plain.\n");
                &output ("    \\AlmlStylePageHeader\n");
                &output ("}\n");

                # Define sections.
                &output ("\n");
                &output ("\\newcommand{\\AlmlSectionNumbered}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{section}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h2 eq "")
                  {
            	    &output ("    \\LARGE");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h2}{$printed_font_height_h2}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\arabic{chapter}.\\arabic{section} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");
                &output ("\\newcommand{\\AlmlSectionUnnumbered}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h2 eq "")
                  {
            	    &output ("    \\LARGE");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h2}{$printed_font_height_h2}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("#1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");

                &output ("\\newcommand{\\AlmlSectionFAQ}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{section}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h2 eq "")
                  {
            	    &output ("    \\LARGE");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h2}{$printed_font_height_h2}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\arabic{chapter}.\\arabic{section} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");

                &output ("\\newcommand{\\AlmlUnnumberedSectionFAQ}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{section}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h2 eq "")
                  {
            	    &output ("    \\LARGE");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h2}{$printed_font_height_h2}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\arabic{section} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");

                &output ("\n");
                &output ("\\newcommand{\\AlmlSectionAppendix}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{section}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h2 eq "")
                  {
            	    &output ("    \\LARGE");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h2}{$printed_font_height_h2}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\Alph{chapter}.\\arabic{section} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");
                &output ("\\newcommand{\\AlmlSubsectionNumbered}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{subsection}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h3 eq "")
                  {
            	    &output ("    \\Large");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h3}{$printed_font_height_h3}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\arabic{chapter}.\\arabic{section}.\\arabic{subsection} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");
                &output ("\\newcommand{\\AlmlSubsectionUnnumbered}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h3 eq "")
                  {
            	    &output ("    \\Large");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h3}{$printed_font_height_h3}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("#1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");

                &output ("\\newcommand{\\AlmlSubsectionFAQ}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{subsection}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_normal eq "")
                  {
            	    &output ("    \\normalsize");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_normal}{$printed_font_height_normal}\\selectfont");
                  }
                &output ("    \\normalfont\\bfseries\n");
                &output ("    % Define space above.\n");
                &output ("    \\vspace{0.5em}\n");
                &output ("    \\begin{flushleft}\n");
		#-------------------------------------------------------
		# FAQH3 is like this:
		#
		# 1.2.3) What is... ?
		#-------------------------------------------------------
                &output ("\\arabic{chapter}.\\arabic{section}.\\arabic{subsection}) #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");

                &output ("\\newcommand{\\AlmlUnnumberedSubsectionFAQ}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{subsection}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_normal eq "")
                  {
            	    &output ("    \\normalsize");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_normal}{$printed_font_height_normal}\\selectfont");
                  }
                &output ("    \\normalfont\\bfseries\n");
                &output ("    % Define space above.\n");
                &output ("    \\vspace{0.5em}\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\arabic{section}.\\arabic{subsection} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");

                &output ("\n");
                &output ("\\newcommand{\\AlmlSubsectionAppendix}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{subsection}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h3 eq "")
                  {
            	    &output ("    \\Large");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h3}{$printed_font_height_h3}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\Alph{chapter}.\\arabic{section}.\\arabic{subsection} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");
                &output ("\\newcommand{\\AlmlSubSubsectionNumbered}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{subsubsection}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h4 eq "")
                  {
            	    &output ("    \\large");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h4}{$printed_font_height_h4}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\arabic{chapter}.\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");
                &output ("\\newcommand{\\AlmlSubSubsectionUnnumbered}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h4 eq "")
                  {
            	    &output ("    \\large");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h4}{$printed_font_height_h4}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("#1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");
                &output ("\\newcommand{\\AlmlSubSubsectionAppendix}[1]\n");
                &output ("{\n");
                &output ("    % This paragraph is important, otherwise,\n");
                &output ("    % the other paragraphs will have strange spaceing.\n");
                &output ("    \\par\n");
                &output ("    % Increment section counter.\n");
                &output ("    \\stepcounter{subsubsection}\n");
                &output ("    % Change font.\n");
		if ($printed_font_size_h4 eq "")
                  {
            	    &output ("    \\large");
                  }
                else
                  {
            	    &output ("    \\fontsize{$printed_font_size_h4}{$printed_font_height_h4}\\selectfont");
                  }
                &output ("    \\normalfont\\sffamily\n");
                &output ("    \\begin{flushleft}\n");
                &output ("\\Alph{chapter}.\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection} #1\n");
                &output ("    \\end{flushleft}\n");
                &output ("    % Reset font.\n");
                &output ("    \\normalfont\\normalsize\n");
                &output ("}\n");
                &output ("\n");

                # Font selection.
                &output ("\n");
                if ($target eq "PDF")
                  {
                    # For maximum compatibility, we need a simple
                    # helvetica, although it works well the one from
                    # newcent.sty, with GNU/Linux.
                    &output ("\\renewcommand{\\sfdefault}{phv} % times.sty\n");
                  }
                else
                  {
                    # Use a better font.
                    &output ("\\renewcommand{\\sfdefault}{pag} % newcent.sty\n");
                  }
                &output ("\\renewcommand{\\rmdefault}{ptm} % times.sty\n");
                &output ("\\renewcommand{\\ttdefault}{pcr} % times.sty\n");

                # Incorporate global configuration.
                if (-e "/etc/alml-tex.sty")
                  {
                    &output ("\n");
                    open (TEXCONFIG, "< /etc/alml-tex.sty");
                    while ($line = <TEXCONFIG>)
                      {
                        &output ("$line");
                      }
                    close (TEXCONFIG);
                  }
                # Incorporate local configuration.
                if (-e ".alml-tex.sty")
                  {
                    &output ("\n");
                    open (TEXCONFIG, "< .alml-tex.sty");
                    while ($line = <TEXCONFIG>)
                      {
                        &output ("$line");
                      }
                    close (TEXCONFIG);
                  }

                # Use headings per default.
                &output ("\n");
                &output ("\\pagestyle{myheadings}\n");

                # print @frenchspacing only if supplied.
                if ($document_spacing eq "french"
                    | $document_spacing eq "uniform")
                  {
                    &output ("\n");
                    &output ("\\frenchspacing\n");
                  }

		#-------------------------------------------------------
                # Start the document and then the title page.
		#-------------------------------------------------------
                &output ("\n");
                &output ("\\begin{document}\n");

		#-------------------------------------------------------
		# Select the language.
		#-------------------------------------------------------
                &output ("\\selectlanguage{"
		         . &latex_language_name ($current_language)
			 . "}\n");
                #&output ("\\hyphenation{"
		#         . &latex_language_name ($current_language)
		#	 . "}\n");

		#-------------------------------------------------------
		# Begin the front cover page.
		#-------------------------------------------------------
                &output ("\n\\AlmlStylePageNormal");

                &output ("\n\\begin{titlepage}");
                &output ("\n");
		#-------------------------------------------------------
		# Don't put a \null command, otherwise an empty
		# paragraph will be placed here.
		#-------------------------------------------------------
                #&output ("\\null");
                &output ("\n\\vspace{1cm}");
                if ($front_cover_picture_file ne "")
                  {
                    # New picture.
                    
                    # If target is PDF there is non need to convert to EPS.
                    if ($target eq "PDF")
                      {
                        &output ("\n\\begin{center}");
                        &output ("\n\\epsfig{file=$front_cover_picture_file");
                        if ($front_cover_picture_height ne "")
                          {
                            &output (",height=$front_cover_picture_height");
                          }
                        if ($front_cover_picture_width ne "")
                          {
                            &output (",width=$front_cover_picture_width");
                          }
                        &output (",angle=0}");
                        &output ("\n\\end{center}");
                      }
                    else
                      {   

                        $ps_picture_counter++;
                        if (-r "$front_cover_picture_file.png")
                          {
                            #system ("convert $front_cover_picture_file.png EPSI:$ps_picture_counter.ps");
                            system ("convert $front_cover_picture_file.png EPS:$ps_picture_counter.ps");
                            &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                                   $program_executable,
                                                   $original_file_name,
                                                   "$front_cover_picture_file.png",
                                                   "$ps_picture_counter.ps"));
                          }
                        else
                          {
                            &diag_output (sprintf (gettext ("%s: cannot convert %s to %s !!!!\n"),
                                                   $program_executable,
                                                   "$front_cover_picture_file.png",
                                                   "$ps_picture_counter.ps"));
                          }
                        &output ("\n\\begin{center}");
                        &output ("\n\\epsfig{file=$ps_picture_counter");
                        if ($front_cover_picture_height ne "")
                          {
                            &output (",height=$front_cover_picture_height");
                          }
                        if ($front_cover_picture_width ne "")
                          {
                            &output (",width=$front_cover_picture_width");
                          }
                        &output (",angle=0}");
                        &output ("\n\\end{center}");
                      }
                  }

                &output ("\n\\rule{\\linewidth}{5pt}\n");
                &output ("\\begin{AlmlTitlesize}\n");
                &output ("\\sffamily $title\n");
                &output ("\n");
                &output ("\\end{AlmlTitlesize}\n");
                &output ("\n");
                &output ("\\rule{\\linewidth}{5pt}\n");
                if ($#subtitles > -1)
                  {
                    &output ("\n\\begin{center}");
                    &output ("\n\\large\\bfseries\\sffamily");
                    for ($n = 0 ; $n <= $#subtitles ; $n++)
                      { 
                        if ($n > 0)
                          {
                            &output ("\n\\par");
                          }
                        &output ("\n$subtitles[$n]");
                      }
                    &output ("\n\\end{center}\n");
                    &output ("\n\\rule{\\linewidth}{2pt}");
                  }
                &output ("\n\\begin{flushright}");
                &output ("\n\\large\\sffamily ");
                for ($n = 0 ; $n <= $#authors ; $n++)
                  { 
                    if ($n > 0)
                      {
                        &output ("\n\\par\n");
                      }
                    &output ("$authors[$n]");
                  }
                &output ("\n\\end{flushright}\n");
                &output ("\n\\vspace{0.5cm}");
                &output ("\n\\begin{flushright}");
                if ($edition eq "")
                  {
                    &output ("\n\\Huge\\sffamily $version $date");
                  }
                else
                  {
                    &output ("\n\\Huge\\sffamily $version $edition");
                  }
                &output ("\n\\end{flushright}\n");
                &output ("\n");
                if ($front_cover_text ne "")
                  {
                    &output ("$front_cover_text");
                  }
                &output ("\n\\end{titlepage}");

                &output ("\n\\setcounter{footnote}{0}");
                &output ("\n\\AlmlEndOfPage");

                &output ("\n\\AlmlStylePageNormal\n");

                if ($extra_text_before_legal ne "")
                  {
                    &output ("$extra_text_before_legal");
                  }

                if ($legal_text ne "")
                  {
                    &output ("\\AlmlVfill\n");
                    &output ("$legal_text");
                  }

                if ($dedications ne "")
                  {
                    &output ("\\AlmlEndOfPage\n");
                    &output ("$dedications");
                  }
                  
                if ($extra_text_after_dedications ne "")
                  {
                    &output ("\\AlmlEndOfPage\n");
                    &output ("$extra_text_after_dedications");
                  }

                &output ("\n");

                # Main table of contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #
                if ($main_contents)
                  {
                    # The main table of contents is required.
                    &diag_output (sprintf (gettext ("%s:%s: inserting the main contents.\n"),
                                           $program_executable, $original_file_name));

                    &output ("\n\\AlmlEndOfPage");

                    &output ("\n{\\Huge\\sffamily $contents_title}\n");

                    &output ("\n\\begin{list}{}{}");
                    $last_contents_level = 1;
                    for ($n = 0 ; $n <= $#contents_list ; $n++)
                      { 
                        if ($contents_list[$n][0] == -1)
                          {
                            # Tome
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            &output ("\\begin{Large}");
                            &output (ucfirst (&tome_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                            &output ($contents_list[$n][5]);
                            &output ("\\end{Large}");
                            if (!$main_contents_nopages)
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 0)
                          {
                            # part
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            &output ("\\begin{large}");
                            &output (ucfirst (&part_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                            &output ($contents_list[$n][5]);
                            &output ("\\end{large}");
                            if (!$main_contents_nopages)
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 1
                               && ($contents_levels >= 1
                                   || $contents_list[$n][4] =~ m/^[ixu][0-9]/
                                   || $contents_list[$n][4] =~ m/^[A-Z]/))
                          {
                            # chapter
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                              {
                                # This is an appendix.
                                &output (ucfirst (&appendix_def ()));
                                &output (" ");
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            else
                              {
                                # This is a standard chapter.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!$main_contents_nopages)
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 2
                               && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!$main_contents_nopages)
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                            &output ($contents_list[$n][5]);
                            if (!$main_contents_nopages)
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!$main_contents_nopages)
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("\n\\end{list}");
                  }
              }
          }
        elsif ($element eq "ADMIN")
          {
            # the ADMIN element is scanned at the very first pass,
            # identical for all backends.
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Discard output.
                &pop_output ();
              }
          }
        elsif ($element eq "TITLE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $title = &pop_output ();
              }
          }
        elsif ($element eq "SUBTITLE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $subtitles[$#subtitles+1] = &pop_output ();
              }
          }
        elsif ($element eq "ABSTRACT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $abstract = &pop_output ();

                # With %block; elements, there is a line feed character
                # at the top of the string. I don't know why.
                # Anyway, we have to delete this extra line feed.
                $abstract =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "AUTHOR")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $authors[$#authors+1] = &pop_output ();
              }
          }
        elsif ($element eq "DATE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $date = &pop_output ();
              }
          }
        elsif ($element eq "EDITION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $edition = &pop_output ();
              }
          }
        elsif ($element eq "VERSION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $version = &pop_output ();
              }
          }
        elsif ($element eq "FRONTCOVERPICTURE")
          {
            if ($type eq "start")
              {
                # Save picture information.
                $front_cover_picture_file = ${$attributes}{'IMGFILE'};
                $front_cover_picture_width = ${$attributes}{'WIDTH'};
                $front_cover_picture_height = ${$attributes}{'HEIGHT'};
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "FRONTCOVERTEXT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $front_cover_text = &pop_output ();

                # With %block; elements, there is a line feed character
                # at the top of the string. I don't know why.
                # Anyway, we have to delete this extra line feed.
                $front_cover_text =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "TEXTBEFORELEGAL")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $extra_text_before_legal = &pop_output ();

                # With %block; elements, there is a line feed character
                # at the top of the string. I don't know why.
                # Anyway, we have to delete this extra line feed.
                $extra_text_before_legal =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "LEGAL")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $legal_text = &pop_output ();

                # With %block; elements, there is a line feed character
                # at the top of the string. I don't know why.
                # Anyway, we have to delete this extra line feed.
                $legal_text =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "DEDICATIONS")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $dedications = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$dedications =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "TEXTAFTERDEDICATIONS")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $extra_text_after_dedications = &pop_output ();

                # With %block; elements, there is a line feed character
                # at the top of the string. I don't know why.
                # Anyway, we have to delete this extra line feed.
                $extra_text_after_dedications =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "MAINCONTENTS")
          {
            if ($type eq "start")
              {
                local ($nopages) = lc (${$attributes}{'NOPAGES'});

                # Activate main table of contents.
                # This is used to know how to handle the html page counter.
                $main_contents = 1;
                if ($nopages eq "true")
                  {
                    $main_contents_nopages = 1;
                  }
                else
                  {
                    $main_contents_nopages = 0;
                  }

                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $contents_title = &pop_output ();
              }
          }
        elsif ($element eq "INTRO")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "intro";
              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "BODY")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "body";
                # Start the body.
                &output ("\n\\AlmlContent");
              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "APPENDIX")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "appendix";
                # Tell that the appendix starts.
                &output ("\n\\AlmlAppendixes\n");
              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "INDEX")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "index";
                
                #if ($page_numbering eq "plain")
                #  {
                #    # Nothing to do;
                #    ;
                #  }
                #else
                #  {
                #    &output ("\\ifodd \\arabic{page}\n");
                #    &output ("    \\AlmlDoubleNewPage\n");
                #    &output ("\\else\n");
                #    &output ("    \\AlmlNewPage\n");
                #    &output ("\\fi\n");
                #    &output ("\\AlmlStylePageNormal\n");
                #    &output ("\\pagenumbering{roman}\n");
                #    &output ("\\setcounter{page}{1}\n");
                #  }
                &output ("% Clear and new page if not already done.\n");
                &output ("\\AlmlNewPage\n");
                &output ("% If the page is odd, we can stay here.\n");
                &output ("\\ifodd \\arabic{page}\n");
                &output ("    % Ok, start from here.\n");
                &output ("\\else\n");
                &output ("    % Need to print something to be able to jump to another page.\n");
                &output ("    ~\n");
                &output ("    \\AlmlNewPage\n");
                &output ("\\fi\n");

                if ($page_numbering eq "plain")
                  {
                    # Nothing else to do;
                    ;
                  }
                else
                  {
                    &output ("\\addtocounter{pageoffset}{\\arabic{page}}\n");
                    &output ("\\addtocounter{pageoffset}{-1}\n");
                    &output ("\\AlmlStylePageNormal\n");
                    &output ("\\pagenumbering{roman}\n");
                    &output ("\\setcounter{page}{1}\n");
                  }

                &output ("    % Save page location.\n");
                &output ("    \\immediate\\write\\AlmlAuxPageLocation{index{}pageoffset{\\arabic{pageoffset}}relativepage{\\arabic{page}}}\n");

              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "NAVLINK")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                &pop_output ();
              }
          }
        elsif ($element eq "TOMEHEADING")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $tome_heading_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;

                # Save and set language information.
                $current_language = ${$attributes}{'LANG'};
                if ($current_language eq "")
                  {
                    $current_language = $document_language;
                  }
                $tome_language = $current_language;
                $part_language = $current_language;
                $chapter_language = $current_language;

                # Here start a tome. Do some preparations.
                # Tome happens only inside a body.
                $current_level = "tome";
                $current_level_by_number = -1;
                $tome++;
		$part_present = 0;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                # part counter doesnt change.
                # chapter counter doesnt change.
                $sect1 = 0;             
                $sect2 = 0;             
                $sect3 = 0;             
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $tome_heading_title = &pop_output ();
                $last_heading_title = $tome_heading_title;

                &output ("\n");
                &output ("\n");
                &output ("% <". "$element" . ">\n");

		if ($compact >=1)
		  {
		    # Start a \samepage block.
		    $header_to_be_closed = 1;
            	    &output ("{\\samepage\n");
		  }
		else
		  {
		    # There is no need for a \samepage block.
		    ;
		  }

		#-------------------------------------------------------
                # Print the tome header and select the language.
		#-------------------------------------------------------
                &output ("\n");
		&output ("\\selectlanguage{"
		         . &latex_language_name ($current_language)
			 . "}\n");
                &output ("\\AlmlTome{");
                &output ("\\AlmlLabel{title$contents_counter}");
                &output ("\\AlmlLabel{anchor$cross_reference_counter}");
                &output ("$tome_heading_title");
                &output ("}\n");
                &output ("% </". "$element" . ">\n");

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H0")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h0_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;

                # Save and set language information.
                $current_language = ${$attributes}{'LANG'};
                if ($current_language eq "")
                  {
                    $current_language = $tome_language;
                  }
                $part_language = $current_language;
                $chapter_language = $current_language;

                # Here start a part. Do some preparations.
                # Tome happens only inside a body.
                $current_level = "part";
                $current_level_by_number = 0;
                $part++;
		$part_present = 1;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                # chapter counter doesnt change.
                $sect1 = 0;             
                $sect2 = 0;             
                $sect3 = 0;             
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H0_title = &pop_output ();
                $last_heading_title = $H0_title;

                &output ("\n");
                &output ("\n");
                &output ("% <". "$element" . ">\n");

		if ($compact >=1)
		  {
		    # Start a \samepage block.
		    $header_to_be_closed = 1;
            	    &output ("{\\samepage\n");
		  }
		else
		  {
		    # There is no need for a \samepage block.
		    ;
		  }

		#-------------------------------------------------------
                # Print the part header and select the language
		#-------------------------------------------------------
                &output ("\n");
		&output ("\\selectlanguage{"
		         . &latex_language_name ($current_language)
			 . "}\n");
                &output ("\\AlmlPart{");
                &output ("\\AlmlLabel{title$contents_counter}");
                &output ("\\AlmlLabel{anchor$cross_reference_counter}");
                &output ("$H0_title");
                &output ("}\n");
                &output ("% </". "$element" . ">\n");

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H1"
               || $element eq "SLIDEH1"
               || $element eq "SHEETH1"
               || $element eq "UNNUMBEREDH1")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h1_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;

                # Save and set language information.
                $current_language = ${$attributes}{'LANG'};
                if ($current_language eq "")
                  {
                    $current_language = $part_language;
                  }
                $chapter_language = $current_language;

                # Here start a chapter. Do some preparations.
                $current_level_by_number = 1;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                if ($element eq "UNNUMBEREDH1")
                  {
                    $current_level = "unnumbered-h1";
                    $unnumbered_chapter++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "intro")
                  {
                    $current_level = "intro-h1";
                    $intro++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
                    $current_level = "chapter-h1";
                    $chapter++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
                    $current_level = "appendix-h1";
                    $appendix++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h1";
                    $index++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H1_title = &pop_output ();
                $last_heading_title = $H1_title;

                &output ("\n");
                &output ("\n");
                &output ("% <". "$element" . ">\n");

                # Print the chapter header.
                if ($element eq "UNNUMBEREDH1")
                  {
		    if ($compact >=1)
		      {
			# Start a \samepage block.
			$header_to_be_closed = 1;
            		&output ("{\\samepage\n");
		      }
		    else
		      {
			# There is no need for a \samepage block
			# that might give troubles with headers.
			;
		      }

            	    &output ("\n");
		    &output ("\\selectlanguage{"
			     . &latex_language_name ($current_language)
			     . "}\n");

                    &output ("\\AlmlChapterUnnumbered{");
                  }
                elsif ($document_position eq "intro")
                  {
		    if ($compact >=1)
		      {
			# Start a \samepage block.
			$header_to_be_closed = 1;
            		&output ("{\\samepage\n");
		      }
		    else
		      {
			# There is no need for a \samepage block
			# that might give troubles with headers.
			;
		      }

            	    &output ("\n");
		    &output ("\\selectlanguage{"
			     . &latex_language_name ($current_language)
			     . "}\n");

                    &output ("\\AlmlChapterIntro{");
                  }
                elsif ($document_position eq "appendix")
                  {
		    if ($compact >=1)
		      {
			# Start a \samepage block.
			$header_to_be_closed = 1;
            		&output ("{\\samepage\n");
		      }
		    else
		      {
			# There is no need for a \samepage block
			# that might give troubles with headers.
			;
		      }

            	    &output ("\n");
		    &output ("\\selectlanguage{"
			     . &latex_language_name ($current_language)
			     . "}\n");

                    &output ("\\AlmlChapterAppendix{");
                  }
                elsif ($document_position eq "index")
                  {
		    if ($compact >=1)
		      {
			# Start a \samepage block.
			$header_to_be_closed = 1;
            		&output ("{\\samepage\n");
		      }
		    else
		      {
			# There is no need for a \samepage block
			# that might give troubles with headers.
			;
		      }

            	    &output ("\n");
		    &output ("\\selectlanguage{"
			     . &latex_language_name ($current_language)
			     . "}\n");

                    &output ("\\AlmlChapterIndex{");
                  }
                else
                  {
                    if ($element eq "SLIDEH1")
                      {
			if ($compact > 0)
		          {
			    # Start a \samepage block.
    			    $header_to_be_closed = 1;
            		    &output ("{\\samepage\n");
		          }
			else
		          {
			    # There is no need for a \samepage block
			    # that might give troubles with headers.
			    ;
		          }

            		&output ("\n");
			&output ("\\selectlanguage{"
			         . &latex_language_name ($current_language)
				 . "}\n");

                        # Presentation slide or overhead transparency
                        &output ("\\AlmlChapterPresentationSlide{");
                      }
                    elsif ($element eq "SHEETH1")
                      {
			if ($compact > 0)
		          {
			    # Start a \samepage block.
    			    $header_to_be_closed = 1;
            		    &output ("{\\samepage\n");
		          }
			else
		          {
			    # There is no need for a \samepage block
			    # that might give troubles with headers.
			    ;
		          }

    	        	&output ("\n");
			&output ("\\selectlanguage{"
			     . &latex_language_name ($current_language)
			     . "}\n");

                        # Summary sheet
                        &output ("\\AlmlChapterSummarySheet{");
                      }
                    else
                      {
			if ($compact >= 1)
		          {
			    # Start a \samepage block.
    			    $header_to_be_closed = 1;
            		    &output ("{\\samepage\n");
		          }
			else
		          {
			    # There is no need for a \samepage block
			    # that might give troubles with headers.
			    ;
		          }

            		&output ("\n");
			&output ("\\selectlanguage{"
			     . &latex_language_name ($current_language)
			     . "}\n");

                        # Usual chapter
                        &output ("\\AlmlChapterNumbered{");
                      }
                  }
                &output ("\\AlmlLabel{title$contents_counter}");
                &output ("\\AlmlLabel{anchor$cross_reference_counter}");
                &output ("$H1_title");
                &output ("}\n");
                &output ("% </". "$element" . ">\n");

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H2"
               || $element eq "FAQH2")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h2_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                # Here start a chapter. Do some preparations.
                $current_level_by_number = 2;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h2";
                    $sect1++;           
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
		    # If previously was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h2";
		      }
		    else
		      {
                	$current_level = "chapter-h2";
		      }
                    $sect1++;           
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previously was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h2";
		      }
		    else
		      {
                	$current_level = "appendix-h2";
		      }
                    $sect1++;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h2";
                    $sect1++;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H2_title = &pop_output ();
                $last_heading_title = $H2_title;

                &output ("\n");
                &output ("\n");
                &output ("% <". "$element" . ">\n");
                &output ("\\pagebreak[0] % So the previous text will not be kept attached to the beguinning of the section\n");
                &output ("\n");

		# Start a \samepage block.
            	&output ("{\\samepage\n");
		$header_to_be_closed = 1;
		$next_element_after_header_to_be_closed = "";

                # Print the section header.
		if ($element eq "FAQH2"
		    && ($document_position eq "intro"
		        || $document_position eq "index"
		        || $current_level eq "unnumbered-h2"))
		  {
                    # This is an "unnumbered" FAQ section.
                    &output ("\\AlmlUnnumberedSectionFAQ{");
		  }
		elsif ($element eq "FAQH2")
                  {
                    # This is a normal FAQ section.
                    &output ("\\AlmlSectionFAQ{");
                  }
		elsif ($current_level eq "unnumbered-h2")
		  {
                    &output ("\\AlmlSectionUnnumbered{");
	          }
                elsif ($document_position eq "intro")
                  {
                    &output ("\\AlmlSectionUnnumbered{");
                  }
                elsif ($document_position eq "appendix")
                  {
                    &output ("\\AlmlSectionAppendix{");
                  }
                else
                  {
                    &output ("\\AlmlSectionNumbered{");
                  }
                &output ("\\AlmlLabel{title$contents_counter}");
                &output ("\\AlmlLabel{anchor$cross_reference_counter}");
                &output ("$H2_title");
                &output ("}\n");
                &output ("% </". "$element" . ">\n");
              }
          }
        elsif ($element eq "H3"
               || $element eq "FAQH3")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h3_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                # Here start a chapter. Do some preparations.
                $current_level_by_number = 3;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h3";
                    $sect2++;           
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
		    # If previously was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "chapter-h3";
		      }
                    $sect2++;           
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previously was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "appendix-h3";
		      }
                    $sect2++;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h3";
                    $sect2++;
                    $sect3 = 0;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H3_title = &pop_output ();
                $last_heading_title = $H3_title;

		#-------------------------------------------------------
		# FAQH3 is like this:
		#
		# 1.2.3) What is... ?
		#-------------------------------------------------------

                &output ("\n");
                &output ("\n");
                &output ("% <". "$element" . ">\n");
                &output ("\\pagebreak[0] % So the previous text will not be kept attached to the beguinning of the section\n");
                &output ("\n");

		# Start a \samepage block.
            	&output ("{\\samepage\n");
		$header_to_be_closed = 1;
		$next_element_after_header_to_be_closed = "";

                # Print the subsection header.
		if ($element eq "FAQH3"
		    && ($document_position eq "intro"
		        || $document_position eq "index"
		        || $current_level eq "unnumbered-h3"))
		  {
                    # This is an "unnumbered" FAQ subsection.
                    &output ("\\AlmlUnnumberedSubsectionFAQ{");
		  }
		elsif ($element eq "FAQH3")
                  {
                    # This is a normal FAQ section.
                    &output ("\\AlmlSubsectionFAQ{");
                  }
		elsif ($current_level eq "unnumbered-h3")
		  {
                    &output ("\\AlmlSubsectionUnnumbered{");
	          }
                elsif ($document_position eq "intro")
                  {
                    &output ("\\AlmlSubsectionUnnumbered{");
                  }
                elsif ($document_position eq "appendix")
                  {
                    &output ("\\AlmlSubsectionAppendix{");
                  }
                else
                  {
                    &output ("\\AlmlSubsectionNumbered{");
                  }
                &output ("\\AlmlLabel{title$contents_counter}");
                &output ("\\AlmlLabel{anchor$cross_reference_counter}");
                &output ("$H3_title");
                &output ("}\n");
                &output ("% </". "$element" . ">\n");
              }
          }
        elsif ($element eq "H4")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h4_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                # Here start a chapter. Do some preparations.
                $current_level_by_number = 4;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h4";
                    $sect3++;           
                  }
                elsif ($document_position eq "body")
                  {
		    # If previously was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h4";
		      }
		    else
		      {
                	$current_level = "chapter-h4";
		      }
                    $sect3++;
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previously was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h4";
		      }
		    else
		      {
                	$current_level = "appendix-h4";
		      }
                    $sect3++;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h4";
                    $sect3++;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H4_title = &pop_output ();
                $last_heading_title = $H4_title;

                &output ("\n");
                &output ("\n");
                &output ("% <". "$element" . ">\n");
                &output ("\\pagebreak[0] % So the previous text will not be kept attached to the beguinning of the section\n");
                &output ("\n");

		# Start a \samepage block.
            	&output ("{\\samepage\n");
		$header_to_be_closed = 1;
		$next_element_after_header_to_be_closed = "";

                # Print the chapter header.
		if ($current_level eq "unnumbered-h4")
		  {
                    &output ("\\AlmlSubSubsectionUnnumbered{");
	          }
                elsif ($document_position eq "intro")
                  {
                    &output ("\\AlmlSubSubsectionUnnumbered{");
                  }
                elsif ($document_position eq "appendix")
                  {
                    &output ("\\AlmlSubSubsectionAppendix{");
                  }
                else
                  {
                    &output ("\\AlmlSubSubsectionNumbered{");
                  }
                &output ("\\AlmlLabel{title$contents_counter}");
                &output ("\\AlmlLabel{anchor$cross_reference_counter}");
                &output ("$H4_title");
                &output ("}\n");
                &output ("% </". "$element" . ">\n");
              }
          }
        elsif ($element eq "EXTRAMAINCONTENTS")
          {
            if ($type eq "start")
              {
                local ($nopages) = lc (${$attributes}{'NOPAGES'});
                local $contents_levels = ${$attributes}{'LEVELS'};
                local $last_contents_level = 0;

                # Main table of contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # An extra main table of contents is required.
                &diag_output (sprintf (gettext ("%s:%s: inserting an extra main contents of level %s.\n"),
                                       $program_executable, $original_file_name, $contents_levels));

                &output ("\n\\begin{list}{}{}");
                $last_contents_level = 1;
                for ($n = 0 ; $n <= $#contents_list ; $n++)
                  { 
                    if ($contents_list[$n][0] == -1)
                      {
                        # Tome
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        &output ("\n\\item\\hspace{-0,25in}");
                        &output ("\\begin{Large}");
                        &output (ucfirst (&tome_def ()));
                        &output (" ");
                        &output ($contents_list[$n][4]);
                        &output (" ~ ");
                        &output ($contents_list[$n][5]);
                        &output ("\\end{Large}");
                        if (!($nopages eq "true"))
                          {
                            # Output page number only if required.
                            &output ("\\dotfill");
                            #&output ("\\pageref{title$n}");
                            &output ("\\AlmlPageRef{0}{000}{title$n}");
                          }
                        &output ("\n");
                        $last_contents_level = 1;
                      }
                    elsif (($contents_list[$n][0] == 0)
                           && ($contents_levels >= 0))
                      {
                        # part
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        &output ("\n\\item\\hspace{-0,25in}");
                        &output ("\\begin{large}");
                        &output (ucfirst (&part_def ()));
                        &output (" ");
                        &output ($contents_list[$n][4]);
                        &output (" ~ ");
                        &output ($contents_list[$n][5]);
                        &output ("\\end{large}");
                        if (!($nopages eq "true"))
                          {
                            # Output page number only if required.
                            &output ("\\dotfill");
                            #&output ("\\pageref{title$n}");
                            &output ("\\AlmlPageRef{0}{000}{title$n}");
                          }
                        &output ("\n");
                        $last_contents_level = 1;
                      }
                    elsif ($contents_list[$n][0] == 1
                           && $contents_levels >= 1)
                      {
                        # chapter
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        &output ("\n\\item\\hspace{-0,25in}");
                        if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                          {
                            # This is an introduction, an index or an unnumbered.
                            # So, don't add the number.
                            ;
                          }
                        elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                          {
                            # This is an appendix.
                            &output (ucfirst (&appendix_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                          }
                        else
                          {
                            # This is a standard chapter.
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                          }
                        &output ($contents_list[$n][5]);
                        if (!($nopages eq "true"))
                          {
                            # Output page number only if required.
                            &output ("\\dotfill");
                            #&output ("\\pageref{title$n}");
                            &output ("\\AlmlPageRef{0}{000}{title$n}");
                          }
                        &output ("\n");
                        $last_contents_level = 1;
                      }
                    elsif ($contents_list[$n][0] == 2
                           && $contents_levels >= 2)
                      {
                        # section
                        if ($last_contents_level == 1)
                          {
                            # We have to add an indent level.
                            &output ("\n\\begin{list}{}{}");
                          }
                        if ($last_contents_level > 2)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 2)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        &output ("\n\\item\\hspace{-0,25in}");
                        if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                          {
                            # This is an introduction, an index or an unnumbered.
                            # So, don't add the number.
                            ;
                          }
                        else
                          {
                            # This is a standard section.
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                          }
                        &output ($contents_list[$n][5]);
                        if (!($nopages eq "true"))
                          {
                            # Output page number only if required.
                            &output ("\\dotfill");
                            #&output ("\\pageref{title$n}");
                            &output ("\\AlmlPageRef{0}{000}{title$n}");
                          }
                        &output ("\n");
                        $last_contents_level = 2;
                      }
                    elsif ($contents_list[$n][0] == 3
                           && $contents_levels >= 3)
                      {
                        # subsection
                        if ($last_contents_level == 2)
                          {
                            # We have to add an indent level.
                            &output ("\n\\begin{list}{}{}");
                          }
                        if ($last_contents_level > 3)
                          {
                            # We have to subtract an indent level.
                            &output ("\n\\end{list}");
                            $last_contents_level--;
                          }
                        &output ("\n\\item\\hspace{-0,25in}");
                        &output ($contents_list[$n][4]);
                        &output (" ~ ");
                        &output ($contents_list[$n][5]);
                        if (!($nopages eq "true"))
                          {
                            # Output page number only if required.
                            &output ("\\dotfill");
                            #&output ("\\pageref{title$n}");
                            &output ("\\AlmlPageRef{0}{000}{title$n}");
                          }
                        &output ("\n");
                        $last_contents_level = 3;
                      }
                    elsif ($contents_list[$n][0] == 4
                           && $contents_levels >= 4)
                      {
                        # sub-subsection
                        if ($last_contents_level == 3)
                          {
                            # We have to add an indent level.
                            &output ("\n\\begin{list}{}{}");
                          }
                        &output ("\n\\item\\hspace{-0,25in}");
                        if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                          {
                            # This is an introduction, an index or an unnumbered.
                            # So, don't add the number.
                            ;
                          }
                        else
                          {
                            # This is a standard section.
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                          }
                        &output ($contents_list[$n][5]);
                        if (!($nopages eq "true"))
                          {
                            # Output page number only if required.
                            &output ("\\dotfill");
                            #&output ("\\pageref{title$n}");
                            &output ("\\AlmlPageRef{0}{000}{title$n}");
                          }
                        &output ("\n");
                        $last_contents_level = 4;
                      }
                  }
                # Close levels.
                if ($last_contents_level > 1)
                  {
                    # We have to subtract an indent level.
                    &output ("\n\\end{list}");
                    $last_contents_level--;
                  }
                if ($last_contents_level > 1)
                  {
                    # We have to subtract an indent level.
                    &output ("\n\\end{list}");
                    $last_contents_level--;
                  }
                if ($last_contents_level > 1)
                  {
                    # We have to subtract an indent level.
                    &output ("\n\\end{list}");
                    $last_contents_level--;
                  }
                # Close the very last level.
                &output ("\n\\end{list}");
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "TOMECONTENTS")
          {
            if ($type eq "start")
              {
                local ($nopages) = lc (${$attributes}{'NOPAGES'});

                &diag_output (sprintf (gettext ("%s:%s: inserting a tome contents.\n"),
                                       $program_executable, $original_file_name));

                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};

                # Insert a tome contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # Scan the @contents_list to find the right tome.
                for ($n = 0 ;
                     $n <= $#contents_list && $contents_list[$n][1] < $tome ;
                     $n++)
                  { 
                    # Do nothing; just jump it.
                    ;
                  }

                # Now $n is on the first tome entry, or after the end of
                # the array.
                if($n > $#contents_list)
                  {
                    # The array is finisced, and there is no tome.
                    ;
                  }
                elsif ($contents_list[$n][1] == $tome)
                  {
                    # OK, just jump this entry, that is obvious.
                    $n++;

                    &output ("\n\\begin{list}{}{}");
                    $last_contents_level = 1;
                    for ($n = $n ;
                         $n <= $#contents_list && $contents_list[$n][1] == $tome;
                         $n++)
                      { 
                        if ($contents_list[$n][0] == 0)
                          {
                            # part
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            &output ("\\begin{large}");
                            &output (ucfirst (&part_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                            &output ($contents_list[$n][5]);
                            &output ("\\end{large}");
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 1)
                          {
                            # chapter
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                              {
                                # This is an appendix.
                                &output (ucfirst (&appendix_def ()));
                                &output (" ");
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            else
                              {
                                # This is a standard chapter.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 2
                               && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("\n\\end{list}");
                  }
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "PARTCONTENTS")
          {
            if ($type eq "start")
              {
                local ($nopages) = lc (${$attributes}{'NOPAGES'});

                &diag_output (sprintf (gettext ("%s:%s: inserting a part contents.\n"),
                                       $program_executable, $original_file_name));

                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};

                # Insert a part contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # Scan the @contents_list to find the right part.
                for ($n = 0 ;
                     $n <= $#contents_list && $contents_list[$n][2] < $part ;
                     $n++)
                  { 
                    # Do nothing; just jump it.
                    ;
                  }

                # Now $n is on the first part entry, or after the end of
                # the array.
                if($n > $#contents_list)
                  {
                    # The array is finished, and there is no part.
                    ;
                  }
                elsif ($contents_list[$n][2] == $part)
                  {
                    # OK, just jump this entry, that is obvious.
                    $n++;

                    &output ("\n\\begin{list}{}{}");
                    $last_contents_level = 1;
                    for ($n = $n ;
                         $n <= $#contents_list && $contents_list[$n][2] == $part;
                         $n++)
                      {
                        if ($contents_list[$n][0] == 1)
                          {
                            # chapter
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                              {
                                # This is an appendix.
                                &output (ucfirst (&appendix_def ()));
                                &output (" ");
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            else
                              {
                                # This is a standard chapter.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 2
                               && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("\n\\end{list}");
                  }
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "CHAPTERCONTENTS")
          {
            if ($type eq "start")
              {
                local ($nopages) = lc (${$attributes}{'NOPAGES'});

                &diag_output (sprintf (gettext ("%s:%s: inserting a chapter contents.\n"),
                                       $program_executable, $original_file_name));

                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};

                # Insert a part contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # Scan the @contents_list to find the right chapter.
                for ($n = 0 ;
                     $n <= $#contents_list && $contents_list[$n][7] < $h1section_absolute_counter ;
                     $n++)
                  { 
                    # Do nothing; just jump it.
                    ;
                  }

                # Now $n is on the first chapter entry, or after the end of
                # the array.
                if($n > $#contents_list)
                  {
                    # The array is finished, and there is no part.
                    ;
                  }
                elsif ($contents_list[$n][7] == $h1section_absolute_counter)
                  {
                    # OK, just jump this entry, that is obvious.
                    $n++;

                    &output ("\n\\begin{list}{}{}");
                    $last_contents_level = 2;
                    for ($n = $n ;
                         $n <= $#contents_list && $contents_list[$n][7] == $h1section_absolute_counter ;
                         $n++)
                      { 
                        if ($contents_list[$n][0] == 2
                            && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("\n\\end{list}");
                                $last_contents_level--;
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            &output ($contents_list[$n][4]);
                            &output (" ~ ");
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("\n\\begin{list}{}{}");
                              }
                            &output ("\n\\item\\hspace{-0,25in}");
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" ~ ");
                              }
                            &output ($contents_list[$n][5]);
                            if (!($nopages eq "true"))
                              {
                                # Output page number only if required.
                                &output ("\\dotfill");
                                #&output ("\\pageref{title$n}");
                                &output ("\\AlmlPageRef{0}{000}{title$n}");
                              }
                            &output ("\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 2)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 2)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 2)
                      {
                        # We have to subtract an indent level.
                        &output ("\n\\end{list}");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("\n\\end{list}");
                  }
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "INDEXENTRY")
          {
            if ($type eq "start")
              {
		# Save index attributes.
                $index_name = ${$attributes}{'INDEX'};
                $index_emph = lc ${$attributes}{'EMPH'};

                # increment the index entry counter.
                $index_entry_counter++;
    
                # Insert an index anchor.
                &output ("\\AlmlLabel{index$index_entry_counter}");
    
                # Eliminate the index entry.
                &push_output ();
              }
            else
              {
                local ($entry) = "";

                # Recall the index entry for draft typesetting.
                $entry = &pop_output ();

                if ($draft)
                  {
                    &output (" {\\fontsize{0.6em}{1em}\\selectfont\\textrm{\[");
                    &output (&index_def ());
                    &output (":$index_name: ");
                    if ($emph eq "code")
                      {
                        &output ("\\texttt{$entry}");
                      }
                    else
                      {
                        &output ("$entry");
                      }
                    &output ("\]}}");
                  }
              }
          }
        elsif ($element eq "PRINTINDEX")
          {
            if ($type eq "start")
              {
                local ($n) = 0;
                local ($m) = 0;
                local ($idxname) = "";
                local ($idxtype) = "";
                local ($idxcontext) = "";
                local ($index_file) = "";
                local ($output_stream);
                local ($input_stream);
                local ($line);

                # Save the index type name.
                $idxname = ${$attributes}{'INDEX'};
                $idxtype = lc (${$attributes}{'INDEXREF'});
                $idxcontext = lc (${$attributes}{'INDEXCONTEXT'});

                # Sort only the elements for the actual index name.
		# Now it is done at the beguinning, with ALML start
		# tag.
                #&sort_index_list ($idxname, 0, $#index_list);

                # Scan the index array.
                #
                # $index_list[x][0]        index name
                # $index_list[x][1]        emphasis
                # $index_list[x][2]        entry
                # $index_list[x][3]        array of links
                # $index_list[x][4]        array of html page numbers
                # $index_list[x][5]        array of level-descriptions
        	# $index_list[x][6]        entry with formatting
		# $index_list[x][7]        array of tomes
	        # $index_list[x][8]        array of parts
	        # $index_list[x][9]        array of chapters (absolute)
                #
                &output ("\n");
                for ($n = 0;
                     $n <= $#index_list;
                     $n++)
                  {
                    if ($index_list[$n][0] eq $idxname
		        && &valid_section_index_entry
			     ($n, $idxcontext, $tome, $part, $h1section_absolute_counter))
		      {
                        # Write the index record.
                        if ($index_list[$n][1] eq "code")
                          {
                            &output
                              ("\\texttt{$index_list[$n][6]}");
                          }
                        else
                          {
                            &output
                              ("$index_list[$n][6]");
                          }
                        # Scan the links.
                        for ($m = 0;
                             $m <= $#{$index_list[$n][3]};
                             $m++)
                          {
			    # Check if this link is ok for the context
			    if ($idxcontext eq "tome"
			        && $index_list[$n][7][$m] != $tome)
			      {
				# This link is not related to the tome.
				next;
			      }
			    elsif ($idxcontext eq "part"
			        && $index_list[$n][8][$m] != $part)
			      {
				# This link is not related to the part.
				next;
			      }
			    elsif ($idxcontext eq "chapter"
			        && $index_list[$n][9][$m] != $h1section_absolute_counter)
			      {
				# This link is not related to the chapter.
				next;
			      }

			    # Otherwise it is ok. :-)				  

                            if ($idxtype eq "section")
                              {
                                &output
                                  (", "
                                   . $index_list[$n][5][$m]);
                              }
                            else
                              {
                                #&output
                                #  (", \\pageref{index"
                                #   . $index_list[$n][3][$m]
                                #   . "}");
                                &output
                                  (", \\AlmlPageRef{0}{000}{index"
                                   . $index_list[$n][3][$m]
                                   . "}");
                              }
                          }
                        &output ("\\newline\n");
                      }
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "ANCHOR")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};

                # Use the counter to know the right number
                # inside the array.
                $cross_reference_counter++;
                # Print the reference anchor.
                &output ("\\AlmlLabel{anchor$cross_reference_counter}");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "TABLE")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                local ($pos) = "";

		#-------------------------------------------------------
                # Save attributes.
		#-------------------------------------------------------
                $id = ${$attributes}{'ID'};
                $pos = lc ${$attributes}{'POS'};
                $table_position = $pos;

		#-------------------------------------------------------
                # Increment some counters.
		#-------------------------------------------------------
                $table++;
                $absolute_table++;
                $cross_reference_counter++;

                # Save table id.
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "table" . $absolute_table;
                  }
                $last_table_id = $id;

                # Reset table caption.
                $table_caption = "";

                # Print the table border.
                if ($pos eq "float")
                  {
		    #---------------------------------------------------
		    # Floating block.
		    #---------------------------------------------------
		    $floating_block++;

                    &output ("\n");
                    &output ("\\begin{table}[htbp]\n");
                  }
                else
                  {
                    &output ("\n");
                    &output ("\\begin{minipage}{\\linewidth}\n");
                  }

                &output ("\\AlmlLabel{anchor$cross_reference_counter}\n");
              }
            else
              {
		#-------------------------------------------------------
		# Leave an empty line.
		#-------------------------------------------------------
                &output ("\n");

		#-------------------------------------------------------
                # Caption.
		#-------------------------------------------------------
                if ($table_caption ne "")
                  {
                    &output ("\\begin{center}\n");
                    &output ("\\begin{AlmlCaptionsize}\n");
                    &output ("\\textsf{$table_caption}\n");
                    &output ("\\end{AlmlCaptionsize}\n");
                    &output ("\\end{center}\n");
                  }

		#-------------------------------------------------------
                # Close the table.
		#-------------------------------------------------------
                if ($table_position eq "float")
                  {
                    &output ("\\end{table}\n");

		    #---------------------------------------------------
		    # Floating block.
		    #---------------------------------------------------
		    $floating_block--;
                  }
                else
                  {
                    &output ("\\end{minipage}\n");
                  }
              }
          }
        elsif ($element eq "TCAPTION")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $table_caption = &pop_output ();
              }
          }
        elsif ($element eq "TABULAR")
          {
            if ($type eq "start")
              {
                local ($col) = "";
                local ($font_size) = 0;
                local ($font_height) = 0;
                local ($columnfractions) = 0;
                local ($n) = 0;
                local ($zoom) = 0;
                local ($unit) = "";

		#-------------------------------------------------------
                # Save attributes.
		#-------------------------------------------------------
                $col = ${$attributes}{'COL'};
                $columnfractions = ${$attributes}{'COLUMNFRACTIONS'};
                $font_size = ${$attributes}{'PRINTEDFONTSIZE'};
                $current_tabular_border = ${$attributes}{'BORDER'};

		#-------------------------------------------------------
                # Extract the font size.
		# Modify "," with ".".
		#-------------------------------------------------------
		if ($font_size ne "")
		  {
		    $font_size =~ m/([0-9.,]+)\s*([a-zA-Z]*)/;
		    $font_size = $1;
		    $unit = lc ($2);
		    $font_size =~ s/,/./;
		    $font_size = $font_size . $unit;
            	    $font_height = ($font_size * 1.2) . $unit;
		  }

		#-------------------------------------------------------
		# Analyze column fractions.
		#-------------------------------------------------------
		@current_tabular_columnfractions_list = ();
		if ($columnfractions eq "")
		  {
		    # Default columns width.
		    for ($n = 0; $n <= $col; $n++)
		      {
		        $current_tabular_columnfractions_list[$n] = 0;
		      }
		  }
		else
		  {
		    # Take the column fractions from the string.
		    $n = 0;
		    while ($columnfractions =~ m/^\s*([0-9.,]+)\s*(.*)$/)
		      {
		        $current_tabular_columnfractions_list[$n] = $1;
			$columnfractions = $2;
			
			# Replace comma with point.
		        $current_tabular_columnfractions_list[$n] =~ s/,/./g;

			$n++;
		      }
		  }

		# Calculate some comumn zoom.
		$zoom = 1 - ($col * 0.03);

                &output ("\n");
                &output ("\\begin{center}\n");
                &output ("\\begin{AlmlTablesize}\n");
                &output ("{\n");
		# Check font size.
		if ($font_size > 0)
		  {
            	    &output ("\\normalsize\\fontsize{$font_size}{$font_height}\\selectfont\n");
		  }
                # Rebuilding the string of "l".
                &output ("\\begin{tabular}{");
		
		# Left frame border.
		if ($current_tabular_border eq "1")
		  {
            	    &output ("|");
		  }
		
                $n = 0;
                while ($col > 0)
                  {
		    if ($current_tabular_columnfractions_list[$n] == 0)
		      {
                	&output ("l");
		      }
		    else
		      {
		        # The "* $zoom" is there to reduce a little
		    	# the width, as also the column separation
		    	# must be taken into consideration.
		    	# It would be better to subtract the column
		    	# separation space exactly.
            	    	&output ("p{"
			         . ($current_tabular_columnfractions_list[$n]*$zoom)
				 ."\\textwidth}" );
		      }
                    $col--;
                    $n++;
			
		    # Column rules.
		    if ($current_tabular_border eq "1" && $col > 0)
		      {
            		&output ("|");
		      }

                  }

		# Right frame border.
		if ($current_tabular_border eq "1")
		  {
            	    &output ("|");
		  }

                &output ("}\n");
              }
            else
              {
                &output ("\\end{tabular}\n");
                &output ("}\n");
                &output ("\\end{AlmlTablesize}\n");
                &output ("\\end{center}\n");
              }
          }
        elsif ($element eq "THEAD")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("\\hline\n");
              }
            else
              {
		# Rows rules, one more line.
		if ($current_tabular_border eq "1")
		  {
            	    &output ("\n");
            	    &output ("\\hline\n");
		  }
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "TBODY")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("\\hline\n");
              }
            else
              {
                &output ("\n");
                &output ("\\hline\n");
              }
          }
        elsif ($element eq "TROW")
          {
            if ($type eq "start")
              {
                local ($zoom) = 0;

		# This is the first column
	        $current_tabular_column_index = 0;

		# Calculate some comumn zoom.
		$zoom = 1 - ($col * 0.03);
	        # The "* $zoom" is there to reduce a little
		# the width, as also the column separation
		# must be taken into consideration.
		# It would be better to subtract the column
		# separation space exactly.
		#
		# It is not used because it doesen't work well
		# with borders around.
		#
		# KEEP IT!
		#if ($current_tabular_columnfractions_list[$current_tabular_column_index] > 0)
		#  {
            	#    &output ("\\parbox{"
		#             . ($current_tabular_columnfractions_list[$current_tabular_column_index]*$zoom)
		#	     ."\\textwidth}");
		#  }

                # This is always necessary for special situations,
                # when some special symbols on the first column
                # may have a special meaning.
		# This curly bracket remains also if parbox above is no
		# more used.
                &output ("{");

              }
            else
              {
                &output ("}");
                &output ("\\\\\n");
		
		# Rows rules.
		if ($current_tabular_border eq "1")
		  {
            	    &output ("\\hline\n");
		  }
		
              }
          }
        elsif ($element eq "COLSEP")
          {
            if ($type eq "start")
              {
                local ($zoom) = 0;

		# Close previous column.
                &output ("}");

		# Open next column.
                &output ("&");

		# This is the first column
	        $current_tabular_column_index++;

		# Calculate some comumn zoom.
		$zoom = 1 - ($col * 0.03);
	        # The "* $zoom" is there to reduce a little
		# the width, as also the column separation
		# must be taken into consideration.
		# It would be better to subtract the column
		# separation space exactly.
		#
		# It is not used because it doesen't work well
		# with borders around.
		#
		# KEEP IT!
		#if ($current_tabular_columnfractions_list[$current_tabular_column_index] > 0)
		#  {
            	#    &output ("\\parbox{"
		#             . ($current_tabular_columnfractions_list[$current_tabular_column_index]*$zoom)
		#	     ."\\textwidth}");
		#  }

                # This is always necessary for special situations,
                # when some special symbols on the first column
                # may have a special meaning.
		# This curly bracket remains also if parbox above is no
		# more used.
                &output ("{");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "FIGURE")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                local ($pos) = "";
                local ($sep) = "";
                # Save attributes.
                $id = ${$attributes}{'ID'};
                $pos = lc ${$attributes}{'POS'};
                $sep = lc ${$attributes}{'SEP'};
                $figure_position = $pos;
                $figure_separation = $sep;

                # Increment some counters.
                $figure++;
                $absolute_figure++;
                $cross_reference_counter++;

                # Save table id.
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "figure" . $absolute_figure;
                  }
                $last_figure_id = $id;

                # Reset table caption.
                $figure_caption = "";

		#-------------------------------------------------------
                # Print the figure border.
		#-------------------------------------------------------
                if ($figure_position eq "float")
                  {
		    #---------------------------------------------------
		    # Floating block.
		    #---------------------------------------------------
		    $floating_block++;

                    &output ("\n");
                    &output ("\\begin{figure}[htbp]\n");
                  }
                else
                  {
                    &output ("\n");
                    &output ("\\begin{minipage}{\\linewidth}\n");
                  }

                if ($figure_separation eq "rule")
                  {
                    &output ("\\rule{\\linewidth}{0.5pt}\n");
            	    &output ("\\vspace{-2ex}");
                  }
		elsif ($figure_separation eq "box"
		       || $figure_separation eq "border")
                  {
            	    &output ("\\fboxsep=1mm");
            	    &output ("\\fbox");
            	    &output ("{");
            	    &output ("\\noindent");
                    &output ("\\begin{minipage}{0.99\\linewidth}\n");
                  }

                &output ("\\AlmlLabel{anchor$cross_reference_counter}\n");
              }
            else
              {
		#-------------------------------------------------------
		# Leave an empty line.
		#-------------------------------------------------------
                &output ("\n");

		#-------------------------------------------------------
                # Print the figure border.
		#-------------------------------------------------------
                if ($figure_separation eq "rule")
                  {
            	    &output ("\\vspace{-1ex}\n");
                    &output ("\\rule{\\linewidth}{0.5pt}\n");
                  }
		elsif ($figure_separation eq "box"
		       || $figure_separation eq "border")
                  {
            	    &output ("\n");
            	    &output ("\n\\end{minipage}");
            	    &output ("}\n");
                  }

		#-------------------------------------------------------
                # Caption.
		#-------------------------------------------------------
                if ($figure_caption ne "")
                  {
		    if ($figure_separation eq "rule")
		      {
			#-----------------------------------------------
			# There is also a separation line.
			# Do something to go back some vertical space.
			#-----------------------------------------------
	                &output ("\n");
                	&output ("\\vspace{-2ex}\n");
		      }
		    elsif ($figure_separation eq "box"
			   || $figure_separation eq "border")
		      {
			#-----------------------------------------------
			# There is also a separation border.
			# Do something to go back some vertical space.
			#-----------------------------------------------
	                &output ("\n");
                	&output ("\\vspace{-1ex}\n");
		      }
		    else
		      {
			#-----------------------------------------------
			# There is a little vertical correction to
			# do also when no rules and no boxes are there.
			# Must be a compromise between pictures and
			# verbatim text.
			#-----------------------------------------------
	                &output ("\n");
                	&output ("\\vspace{-2ex}\n");
		      }

		    #---------------------------------------------------
		    # Normal caption code.
		    #---------------------------------------------------
                    &output ("\\begin{center}\n");
                    &output ("\\begin{AlmlCaptionsize}\n");
                    &output ("\\textsf{$figure_caption}\n");
                    &output ("\\end{AlmlCaptionsize}\n");
                    &output ("\\end{center}\n");
                  }

		#-------------------------------------------------------
                # Close figure.
		#-------------------------------------------------------
                if ($figure_position eq "float")
                  {
                    &output ("\\end{figure}\n");

		    #---------------------------------------------------
		    # Floating block.
		    #---------------------------------------------------
		    $floating_block--;
                  }
                else
                  {
                    &output ("\\end{minipage}\n");
                  }
              }
          }
        elsif ($element eq "FCAPTION")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $figure_caption = &pop_output ();
              }
          }
        elsif ($element eq "LISTING")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                local ($pos) = "";
                local ($sep) = "";
                # Save attributes.
                $id = ${$attributes}{'ID'};
                $pos = lc ${$attributes}{'POS'};
                $sep = lc ${$attributes}{'SEP'};
                $listing_position = $pos;
                $listing_separation = $sep;

                # Increment some counters.
                $listing++;
                $absolute_listing++;
                $cross_reference_counter++;

                # Save table id.
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "listing" . $absolute_listing;
                  }
                $last_listing_id = $id;

                # Reset table caption.
                $listing_caption = "";

		#-------------------------------------------------------
                # Print the figure border.
		#-------------------------------------------------------
                if ($listing_position eq "float")
                  {

		    #---------------------------------------------------
		    # Floating block.
		    #---------------------------------------------------
		    $floating_block++;

                    &output ("\n");
                    &output ("\\begin{figure}[htbp]\n");
                  }
                else
                  {
                    &output ("\n");
                    &output ("\\begin{minipage}{\\linewidth}\n");
                  }

                if ($listing_separation eq "rule")
                  {
                    &output ("\\rule{\\linewidth}{0.5pt}\n");
            	    &output ("\\vspace{-2ex}");
                  }
		elsif ($listing_separation eq "box"
		       || $listing_separation eq "border")
                  {
            	    &output ("\\fboxsep=1mm");
            	    &output ("\\fbox");
            	    &output ("{");
            	    &output ("\\noindent");
                    &output ("\\begin{minipage}{0.99\\linewidth}\n");
                  }

                &output ("\\AlmlLabel{anchor$cross_reference_counter}\n");
              }
            else
              {
		#-------------------------------------------------------
		# Leave an empty line.
		#-------------------------------------------------------
                &output ("\n");

		#-------------------------------------------------------
                # Print the figure border.
		#-------------------------------------------------------
                if ($listing_separation eq "rule")
                  {
            	    &output ("\\vspace{-1ex}\n");
                    &output ("\\rule{\\linewidth}{0.5pt}\n");
                  }
		elsif ($listing_separation eq "box"
		       || $listing_separation eq "border")
                  {
            	    &output ("\n");
            	    &output ("\n\\end{minipage}");
            	    &output ("}\n");
                  }

		#-------------------------------------------------------
                # Caption.
		#-------------------------------------------------------
                if ($listing_caption ne "")
                  {
		    if ($listing_separation eq "rule")
		      {
			#-----------------------------------------------
			# There is also a separation line.
			# Do something to go back some vertical space.
			#-----------------------------------------------
	                &output ("\n");
                	&output ("\\vspace{-2ex}\n");
		      }
		    elsif ($listing_separation eq "box"
			   || $listing_separation eq "border")
		      {
			#-----------------------------------------------
			# There is also a separation border.
			# Do something to go back some vertical space.
			#-----------------------------------------------
	                &output ("\n");
                	&output ("\\vspace{-1ex}\n");
		      }
		    else
		      {
			#-----------------------------------------------
			# There is a little vertical correction to
			# do also when no rules and no boxes are there.
			# Must be a compromise between pictures and
			# verbatim text.
			#-----------------------------------------------
	                &output ("\n");
                	&output ("\\vspace{-2ex}\n");
		      }

		    #---------------------------------------------------
		    # Normal caption code.
		    #---------------------------------------------------
                    &output ("\\begin{center}\n");
                    &output ("\\begin{AlmlCaptionsize}\n");
                    &output ("\\textsf{$listing_caption}\n");
                    &output ("\\end{AlmlCaptionsize}\n");
                    &output ("\\end{center}\n");
                  }

		#-------------------------------------------------------
                # Close figure.
		#-------------------------------------------------------
                if ($listing_position eq "float")
                  {
                    &output ("\\end{figure}\n");

		    #---------------------------------------------------
		    # Floating block.
		    #---------------------------------------------------
		    $floating_block--;
                  }
                else
                  {
                    &output ("\\end{minipage}\n");
                  }
              }
          }
        elsif ($element eq "LCAPTION")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $listing_caption = &pop_output ();
              }
          }
        elsif ($element eq "IMAGE")
          {
            if ($type eq "start")
              {
                local ($imgfile) = "";
                local ($width) = "";
                local ($heght) = "";
                # Save picture information.
                $imgfile = ${$attributes}{'IMGFILE'};
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                # New picture.

                # If target is PDF there is non need to convert to EPS.
                if ($target eq "PDF")
                  {
                    &output ("\n");
                    &output ("\\begin{center}\n");
                    &output ("\\epsfig{file=$imgfile");
                    if ($height ne "")
                      {
                        &output (",height=$height");
                      }
                    if ($width ne "")
                      {
                        &output (",width=$width");
                      }
                    &output (",angle=0}\n");
                    &output ("\\end{center}\n");
                  }             
                else
                  {
                    
                    $ps_picture_counter++;
                    if (-r "$imgfile.png")
                      {
                        #system ("convert $imgfile.png EPSI:$ps_picture_counter.ps");
                        system ("convert $imgfile.png EPS:$ps_picture_counter.ps");
                        &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                               $program_executable,
                                               $original_file_name,
                                               "$imgfile.png",
                                               "$ps_picture_counter.ps"));
                      }
                    else
                      {
                        &diag_output (sprintf (gettext ("%s: cannot convert %s to %s !!!!\n"),
                                               $program_executable,
                                               "$imgfile.png",
                                               "$ps_picture_counter.ps"));
                      }
                    &output ("\n");
                    &output ("\\begin{center}\n");
                    &output ("\\epsfig{file=$ps_picture_counter");
                    if ($height ne "")
                      {
                        &output (",height=$height");
                      }
                    if ($width ne "")
                      {
                        &output (",width=$width");
                      }
                    &output (",angle=0}\n");
                    &output ("\\end{center}\n");
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "EMBIMAGE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($img_code) = "";
                local ($img_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                # Restore the base64 code.
                $img_code = $img_code . &pop_output ();

                # Prepare the temporary file.
                $img_temp_file = &temporary_file ($temporary_file_name_prefix);
                # Save the empty temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}";

                open (IMG_TEMP_FILE, "> ${img_temp_file}.uuencode ");
                print IMG_TEMP_FILE ("begin-base64 664 dummy\n");
                print IMG_TEMP_FILE ($img_code);
                print IMG_TEMP_FILE ("\n");
                print IMG_TEMP_FILE ("====\n");
                close (IMG_TEMP_FILE);

                # Get the picture with uudecode.
                system ("uudecode -o ${img_temp_file}.uudecode ${img_temp_file}.uuencode");

                # Convert to PNG if target is PDF.
                if ($target eq "PDF")
                  {
                    system ("convert ${img_temp_file}.uudecode ${img_temp_file}.png");
                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uuencode";
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uudecode";
                  }
                else
                  {
		    $ps_picture_counter++;
                    #system ("convert ${img_temp_file}.uudecode EPSI:${ps_picture_counter}.ps");
                    system ("convert ${img_temp_file}.uudecode EPS:${ps_picture_counter}.ps");
                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uuencode";
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uudecode";
                  }

                # Print picture file.
                &output ("\n");
                &output ("\\begin{center}\n");
                if ($target eq "PDF")
                  {
                    # Include the PNG picture.
                    &output ("\\epsfig{file=${img_temp_file}.png");
                  }
                else
                  {
                    # Include the PostScript picture.
                    &output ("\\epsfig{file=${ps_picture_counter}.ps");
                  }
                if ($height ne "")
                  {
                    &output (",height=$height");
                  }
                if ($width ne "")
                  {
                    &output (",width=$width");
                  }
                &output (",angle=0}");
                &output ("\n\\end{center}\n");
              }
          }
        elsif ($element eq "EPSIMAGE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($eps_code) = "";
                local ($eps_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local (@dim) = ();
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                # Restore the EPS back-end code.
                $eps_code = $eps_code . &pop_output ();

                # Prepare the EPS temporary file.
                $eps_temp_file = &temporary_file ($temporary_file_name_prefix);
                # Save the empty temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                       . " ${eps_temp_file}";

                open (EPS_TEMP_FILE, "> ${eps_temp_file}.eps ");
                print EPS_TEMP_FILE ($eps_code);
                print EPS_TEMP_FILE ("\n");
                close (EPS_TEMP_FILE);

                # Convert to PNG if target is PDF.
                if ($target eq "PDF")
                  {
		    #---------------------------------------------------
		    # The 300x300 density must be corrected later.
		    #
		    # Please note that the density cannot be too high,
		    # otherwise, the PDF file will be too big.
		    #---------------------------------------------------
                    system ("convert -density 300x300 ${eps_temp_file}.eps ${eps_temp_file}.png");
		    # Adjust dimensions if necessry, because of 300x300 density.
            	    if ($height eq ""
		        && $width eq "")
		      {
		        @dim = &ps_x_y_size ("${eps_temp_file}.eps");
			$width = $dim[0] . "bp";
			$height = $dim[1] . "bp";
		      }
                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${eps_temp_file}.eps";
                  }

                # Print picture file.
                &output ("\n");
                &output ("\\begin{center}\n");
                if ($target eq "PDF")
                  {
                    # Include the PNG picture.
                    &output ("\\epsfig{file=${eps_temp_file}.png");
                  }
                else
                  {
		    $ps_picture_counter++;
		    # Include the PostScript picture.
		    system ("cp ${eps_temp_file}.eps ${ps_picture_counter}.ps");
                    &output ("\\epsfig{file=${ps_picture_counter}.ps");
                  }
                if ($height ne "")
                  {
                    &output (",height=$height");
                  }
                if ($width ne "")
                  {
                    &output (",width=$width");
                  }
                &output (",angle=0}");
                &output ("\n\\end{center}\n");
              }
          }
        elsif ($element eq "TEXIMAGE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($tex_code) = "";
                local ($tex_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local (@dim) = ();
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                # Restore the TeX back-end code.
                $tex_code = $tex_code . &pop_output ();

                # Prepare the TeX temporary file.
                $tex_temp_file = &temporary_file ($temporary_file_name_prefix);
                # Save the empty temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                   . " ${tex_temp_file}";

                open (TEX_TEMP_FILE, "> ${tex_temp_file}.tex");
                print TEX_TEMP_FILE ("\\nonstopmode\n");
                print TEX_TEMP_FILE ("\\nopagenumbers\n");
                print TEX_TEMP_FILE ($tex_code);
                print TEX_TEMP_FILE ("\n");
                print TEX_TEMP_FILE ("\\bye\n");
                close (TEX_TEMP_FILE);

                # Typeset.
		# Consider that tex can accept a file name with path,
		# but will generate a file DVI on current directory.
		# That's why I am doing this cd and basename.
                system ("cd " . &temporary_dir () . " ; tex `basename ${tex_temp_file}.tex`");
                system ("dvips -E -o ${tex_temp_file}.ps ${tex_temp_file}.dvi");

                # Save the temporary file name inside the list.
                $temp_files_list = $temp_files_list
                                   . " ${tex_temp_file}.dvi"
				   . " ${tex_temp_file}.tex"
                                   . " ${tex_temp_file}.ps";

                # Convert to PNG if target is PDF.
                if ($target eq "PDF")
                  {
		    #---------------------------------------------------
		    # Only first scene.
		    #
		    # The 300x300 density must be corrected later.
		    #
		    # Please note that the density cannot be too high,
		    # otherwise, the PDF file will be too big.
		    #---------------------------------------------------
                    system ("convert -density 300x300 ${tex_temp_file}.ps[0] ${tex_temp_file}.png");
		    # Adjust dimensions if necessry, because of 300x300 density.
            	    if ($height eq ""
		        && $width eq "")
		      {
		        @dim = &ps_x_y_size ("${tex_temp_file}.ps");
			$width = $dim[0] . "bp";
			$height = $dim[1] . "bp";
		      }
                  }

                # Print picture file.
                &output ("\n");
                &output ("\\begin{center}\n");
                if ($target eq "PDF")
                  {
                    # Include the PNG picture.
                    &output ("\\epsfig{file=${tex_temp_file}.png");
                  }
                else
                  {
		    $ps_picture_counter++;
		    # Include the PostScript picture.
		    system ("cp ${tex_temp_file}.ps ${ps_picture_counter}.ps");
                    &output ("\\epsfig{file=${ps_picture_counter}.ps");
                  }
                if ($height ne "")
                  {
                    &output (",height=$height");
                  }
                if ($width ne "")
                  {
                    &output (",width=$width");
                  }
                &output (",angle=0}");
                &output ("\n\\end{center}\n");
              }
          }
        elsif ($element eq "SECTIONREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};
                $id_latex = $id;
                $id_latex =~ s/[^a-zA-Z0-9]/ /g;

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number             
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    # The reference was found at $n-th position.
                    &output ($cross_reference_list[$n][6]);
                  }
                else
                  {
                    # There is no reference.
                    &output ("??$id_latex??");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "TABLEREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Replace with last.
                    $id = $last_table_id;
                  }
                $id_latex = $id;
                $id_latex =~ s/[^a-zA-Z0-9]/ /g;

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number             
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    # The reference was found at $n-th position.
                    &output ($cross_reference_list[$n][8]);
                  }
                else
                  {
                    # There is no reference.
                    &output ("??$id_latex??");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "FIGUREREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Replace with last.
                    $id = $last_figure_id;
                  }
                $id_latex = $id;
                $id_latex =~ s/[^a-zA-Z0-9]/ /g;

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    # The reference was found.
                    &output ($cross_reference_list[$n][9]);
                  }
                else
                  {
                    # There is no reference.
                    &output ("??$id_latex??");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "LISTINGREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Replace with last.
                    $id = $last_listing_id;
                  }
                $id_latex = $id;
                $id_latex =~ s/[^a-zA-Z0-9]/ /g;

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    # The reference was found.
                    &output ($cross_reference_list[$n][13]);
                  }
                else
                  {
                    # There is no reference.
                    &output ("??$id_latex??");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SPECIAL")
          {
            if ($type eq "start")
              {
                # Increment the index entry counter.
                $index_entry_counter++;
                # Typeset properly.
                &output ("\\AlmlLabel{index$index_entry_counter}\\AlmlSpecial{");
              }
            else
              {
                local ($special) = "";
                $special = ${$attributes}{'SPECIAL'};
                &output ("}{$special}");
              }
          }
        elsif ($element eq "DFN")
          {
            if ($type eq "start")
              {
		#-------------------------------------------------------
                # Typeset properly.
		#-------------------------------------------------------
                &output ("{\\bfseries\\itshape{}");
              }
            else
              {
                &output ("\\/}");
              }
          }
        elsif ($element eq "WORKINFO")
          {
            if ($type eq "start")
              {
                # Reset global variables.
                $workinfo_name         = "";
                $workinfo_license      = "";
                $workinfo_license_text = "";
                $workinfo_notes        = "";
              }
            else
              {
                # Print a footnote.
                &output ("\\footnote{");
                &output ("\\textbf{$workinfo_name}");
                &output (" ~ ");
                &output ($workinfo_license);
                &output ("}");
              }
          }
        elsif ($element eq "WORKNAME")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_name = &pop_output ();
              }
          }
        elsif ($element eq "WORKLICENSE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_license = &pop_output ();
              }
          }
        elsif ($element eq "WORKLICENSETEXT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_license_text = &pop_output ();
              }
          }
        elsif ($element eq "WORKNOTES")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_notes = &pop_output ();
              }
          }
        elsif ($element eq "PRINTWORKINFO")
          {
            if ($type eq "start")
              {
                local ($n) = 0;

                # Sort workinfo array.
                &sort_workinfo_list (0, $#workinfo_list);

                # Eliminate duplicates.
                &delete_doubles_workinfo_list ();

                # Insert workinfo array.
                &output ("\n");
                &output ("\\begin{list}{}{}\n");

                # Workinfo list.
                #
                # $workinfo_list[x][0]        work name
                # $workinfo_list[x][1]        work license
                # $workinfo_list[x][2]        work license text
                # $workinfo_list[x][3]        work notes
                #
                for ($n = 0; $n <= $#workinfo_list; $n++)
                  {
                    &output ("\n\\item\\hspace{-0,25in}");
                    &output ("\\begin{large}");
                    &output ($workinfo_list[$n][0]);
                    &output ("\\end{large}");
                    &output ("\n");
                    if ($workinfo_list[$n][2] =~ m/^[^a-z0-9]*$/is)
                      {
                        # There is no license text. So, print just
                        # the license name or definition.
                        &output ("\n");
                        &output ($workinfo_list[$n][1]);
                        &output ("\n");
                       }
                    else
                      {
                        # There is the license text. Print it!
                        &output ($workinfo_list[$n][2]);
                       }
                    if ($workinfo_list[$n][3] =~ m/^[^a-z0-9]*$/is)
                      {
                        # There are some notes. Print them.
                        &output ($workinfo_list[$n][3]);
                       }
                  }
                &output ("\\end{list}\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "NOMOD")
          {
            if ($type eq "start")
              {
                # Increment the counter.
                $nomod_sections_counter++;
                # Insert an anchor.
                &output ("\\AlmlLabel{nomod$nomod_sections_counter}");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "PRINTNOMOD")
          {
            if ($type eq "start")
              {
                local ($n) = 0;

                # Insert nomod array.
                &output ("\n");
                &output ("\\begin{list}{}{}\n");

                # $nomod_sections_list[x][0]    level     -1..4
                # $nomod_sections_list[x][1]    description   section 1.2
                # $nomod_sections_list[x][2]    title
                # $nomod_sections_list[x][3]    html page
                #
                for ($n = 0; $n <= $#nomod_sections_list; $n++)
                  {
                    &output ("\\item");
                    &output (" ");
                    &output ($nomod_sections_list[$n][1]);
                    &output (", ");
                    &output ("\\textit{");
                    &output ($nomod_sections_list[$n][2]);
                    &output ("}");
                    &output (", ");
                    &output (&short_page_def ());
                    &output (" ");
                    #&output ("\\pageref{nomod$n}\n");
                    &output ("\\AlmlPageRef{0}{000}{nomod$n}\n");
                  }
                &output ("\\end{list}\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SPECIALCONDITION")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{flushright}\\textsf{");
              }
            else
              {
                &output ("}\\end{flushright}\n");
              }
          }
        elsif ($element eq "DOCINFO")
          {
            if ($type eq "start")
              {
                # Increment the docinfo counter.
                $docinfo_counter++;
                # Print an anchor.
                &output ("\\AlmlLabel{docinfo$docinfo_counter}");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "DOCAUTHOR")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Discard output.
                &pop_output ();
              }
          }
        elsif ($element eq "DOCORIGINNOTE")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{flushright}\\textsf{");
              }
            else
              {
                &output ("}\\end{flushright}\n");
              }
          }
        elsif ($element eq "DOCREVISIONNOTE")
          {
            if ($type eq "start")
              {
                &output ("\n\\begin{flushright}\\textsf{");
              }
            else
              {
                &output ("}\\end{flushright}\n");
              }
          }
        elsif ($element eq "DOCNOTES")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Discard output.
                &pop_output ();
              }
          }
        elsif ($element eq "PRINTDOCINFO")
          {
            if ($type eq "start")
              {
                local ($n) = 0;
                local ($m) = 0;

                # Insert docinfo array.
                &output ("\n");
                &output ("\\begin{list}{}{}\n");

                # $docinfo_list[x][0]       level               -1..4
                # $docinfo_list[x][1]       description     section 1.2
                # $docinfo_list[x][2]       title
                # $docinfo_list[x][3]       origin note
                # $docinfo_list[x][4]       revision note
                # $docinfo_list[x][5]       notes
                # $docinfo_list[x][6][y][0] revision date               OBSOLETE
                # $docinfo_list[x][6][y][1] revision author             OBSOLETE
                # $docinfo_list[x][6][y][2] revision email              OBSOLETE
                # $docinfo_list[x][6][y][3] revision description        OBSOLETE
                # $docinfo_list[x][7]       html page number
                # $docinfo_list[x][8][z]    z-th author
                #
                for ($n = 0; $n <= $#docinfo_list; $n++)
                  {
                    if ($docinfo_list[$n][1] ne "##unknown-section##")
                      {
                        # This is a usual section

                        &output ("\\item\\hspace{-0,25in}");
                        &output ($docinfo_list[$n][1]);
                        &output (", ");
                        &output ("\\textit{");
                        &output ($docinfo_list[$n][2]);
                        &output ("}");
                        &output (", ");
                        &output (&short_page_def ());
                        &output (" ");
                        #&output ("\\pageref{docinfo$n}\n");
                        &output ("\\AlmlPageRef{0}{000}{docinfo$n}\n");

                        if ($#{$docinfo_list[$n][8]} >= 0)
                          {
                            &output ("\\begin{list}{}{}\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][8]}; $m++)
                              {
                                &output ("\\item");
                                &output (" ");
                                &output ($docinfo_list[$n][8][$m]);
                                &output ("\n");
                              }
                            &output ("\\end{list}\n");
                          }
                        if ($docinfo_list[$n][5] ne "")
                          {
                            &output ($docinfo_list[$n][5]);
                          }
                        if ($#{$docinfo_list[$n][6]} >= 0)      # OBSOLETE
                          {
                            &output ("\\begin{itemize}\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][6]}; $m++)
                              {
                                &output ("\\item");
                                &output (" ");
                                &output ($docinfo_list[$n][6][$m][0]);
                                &output (" ~ ");
                                &output ($docinfo_list[$n][6][$m][1]);
                                &output (" ~ ");
                                &output ($docinfo_list[$n][6][$m][2]);
                                &output ("\n");
                                &output ("\n");
                                &output ($docinfo_list[$n][6][$m][3]);
                                &output ("\n");
                              }
                            &output ("\\end{itemize}\n");
                          }
                      }
                    else
                      {
                        # This is external of usual sections

                        &output ("\\item\\hspace{-0,25in}");
                        &output (&short_page_def ());
                        &output (" ");
                        #&output ("\\pageref{docinfo$n}\n");
                        &output ("\\AlmlPageRef{0}{000}{docinfo$n}\n");

                        if ($#{$docinfo_list[$n][8]} >= 0)
                          {
                            &output ("\\begin{list}{}{}\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][8]}; $m++)
                              {
                                &output ("\\item");
                                &output (" ");
                                &output ($docinfo_list[$n][8][$m]);
                                &output ("\n");
                              }
                            &output ("\\end{list}\n");
                          }
                        if ($docinfo_list[$n][5] ne "")
                          {
                            &output ($docinfo_list[$n][5]);
                          }
                        if ($#{$docinfo_list[$n][6]} >= 0)      # OBSOLETE
                          {
                            &output ("\\begin{itemize}\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][6]}; $m++)
                              {
                                &output ("\\item");
                                &output (" ");
                                &output ($docinfo_list[$n][6][$m][0]);
                                &output (" ~ ");
                                &output ($docinfo_list[$n][6][$m][1]);
                                &output (" ~ ");
                                &output ($docinfo_list[$n][6][$m][2]);
                                &output ("\n");
                                &output ("\n");
                                &output ($docinfo_list[$n][6][$m][3]);
                                &output ("\n");
                              }
                            &output ("\\end{itemize}\n");
                          }
                      }
                  }
                &output ("\\end{list}\n");
              }
            else
              {
    		#-------------------------------------------------------
                # Nothing to do.
    		#-------------------------------------------------------
                ;
              }
          }
        elsif ($element eq "HTML")
          {
            if ($type eq "start")
              {
    		#-------------------------------------------------------
                # Send the output stream to a new stack level.        
    		#-------------------------------------------------------
                &push_output ();
              }
            else
              {
                local ($html_code) = "";
                local ($html_temp_file) = "";
                local ($html_css_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

    		#-------------------------------------------------------
                # Restore the HTML back-end code.
    		#-------------------------------------------------------
                $html_code = $html_code . &pop_output ();

    		#-------------------------------------------------------
                # Prepare the HTML temporary file.
    		#-------------------------------------------------------
                $html_temp_file = &temporary_file ($temporary_file_name_prefix);
    		#-------------------------------------------------------
                # Save the empty temporary file name inside the list.
    		#-------------------------------------------------------
                $temp_files_list = $temp_files_list
                                       . " ${html_temp_file}";

                open (HTML_TEMP_FILE, "> ${html_temp_file}.html ");
                print HTML_TEMP_FILE ("<html>\n");
                print HTML_TEMP_FILE ("<body>\n");
                print HTML_TEMP_FILE ($html_code);
                print HTML_TEMP_FILE ("\n");
                print HTML_TEMP_FILE ("</body>\n");
                print HTML_TEMP_FILE ("</html>\n");
                close (HTML_TEMP_FILE);

    		#-------------------------------------------------------
                # Prepare the CSS temporary file.
    		#-------------------------------------------------------
                $html_css_temp_file = &temporary_file ($temporary_file_name_prefix);

                open (HTML_CSS_TEMP_FILE, "> ${html_css_temp_file}.css ");
                print HTML_CSS_TEMP_FILE ("\@page {\n");
                print HTML_CSS_TEMP_FILE ("size 21cm 100cm; ");
                print HTML_CSS_TEMP_FILE ("margin-top: 0cm; ");
                print HTML_CSS_TEMP_FILE ("margin-bottom: 0cm; ");
                print HTML_CSS_TEMP_FILE ("margin-right: 0cm; ");
                print HTML_CSS_TEMP_FILE ("margin-left: 0cm;");
                print HTML_CSS_TEMP_FILE ("}\n");
                close (HTML_CSS_TEMP_FILE);

		#-------------------------------------------------------
		# Use HTML2ps to get the HTML code converted into
		# PostScript.
		#
		# It is better to create an empty file ./.html2psrc,
		# otherwise an error will be shown.
		#-------------------------------------------------------
                system ("touch .html2psrc");
                system ("html2ps -f:${html_css_temp_file}.css -D -o ${html_temp_file}.ps ${html_temp_file}.html");

		#-------------------------------------------------------
                # Save the temporary file name inside the list.
		#-------------------------------------------------------
                $temp_files_list = $temp_files_list
                                   . " ${html_temp_file}.html"
                                   . " ${html_temp_file}.ps";

		#-------------------------------------------------------
                # If we are producing a PDF output, we need a PNG picture.
		#-------------------------------------------------------
                if ($target eq "PDF")
                  {
		    #---------------------------------------------------
		    # The 300x300 density must be corrected later.
		    #
		    # Please note that the density cannot be too high,
		    # otherwise, the PDF file will be too big.
		    #---------------------------------------------------
                    system ("convert -density 300x300 ${html_temp_file}.ps[0] ${html_temp_file}.png");
		    #---------------------------------------------------
		    # Adjust dimensions if necessry, because of 300x300 density.
		    #---------------------------------------------------
            	    if ($height eq ""
		        && $width eq "")
		      {
		        @dim = &ps_x_y_size ("${html_temp_file}.ps");
			$width = $dim[0] . "bp";
			$height = $dim[1] . "bp";
		      }
                  }

		#-------------------------------------------------------
                # Print picture file.
		#-------------------------------------------------------
                if ($target eq "PDF")
                  {
		    #---------------------------------------------------
                    # Include the PNG picture.
		    #---------------------------------------------------
                    &output ("\\epsfig{file=${html_temp_file}.png");
                  }
                else
                  {
		    #---------------------------------------------------
		    # A new numbered PostScript file.
		    #---------------------------------------------------
		    $ps_picture_counter++;
		    #---------------------------------------------------
		    # Include the PostScript picture.
		    #---------------------------------------------------
		    system ("cp ${html_temp_file}.ps ${ps_picture_counter}.ps");
                    &output ("\\epsfig{file=${ps_picture_counter}.ps");
                  }
                if ($height ne "")
                  {
                    &output (",height=$height");
                  }
                if ($width ne "")
                  {
                    &output (",width=$width");
                  }
                &output (",angle=0}");
        
              }
          }
        else
          {
            # Call the basic %block; and %inline; sub process.
            &sgml_tag_elab_latex_basic
                ($type,
                 $element,
                 $attributes,
                 $typesetting,
                 $target,
                 $draft,
                 $page_numbering,
                 $compact,
                 $long,
                 $original_file_name,
                 $root_file_name,
		 $paper_width,
		 $paper_height);
          }

        #---------------------------------------------------------------
	# Aftere the true analisys, we have to check if there
	# is a block of "{\samepage", made by a section header,
	# that must be closed with a "}"
	# Another block like this is before all the if/elsif block
        #---------------------------------------------------------------
        if ($type ne "start"
	    && $element eq $next_element_after_header_to_be_closed)
	  {
	    if ($next_element_after_header_to_be_closed_nest_level <= 0)
	      {
		# It is right to close the header "same page" block.
        	&output ("}% samepage-end from an H* element\n");
		# Reset the element name.
		$next_element_after_header_to_be_closed = "";
	      }
	    else
	      {
		$next_element_after_header_to_be_closed_nest_level--;
	      }
	  }
    } # sgml_tag_elab_latex

    #-------------------------------------------------------------------
    # This is the sub elaboration process specific, for basic %block;
    # and %inline; elements, for the HTML back-end.
    #
    # &sgml_tag_elab_html_basic (TYPE, ELEMENT, %ATTRIBUTES,
    #                            TYPESETTING,
    #                            TARGET,
    #                            DRAFT,
    #                            PAGE-NUMBERING,
    #                            COMPACT,
    #                            LONG,
    #                            ORIGINAL_NAME,
    #                            ROOT_FILE_NAME)
    #
    sub sgml_tag_elab_html_basic
    {
        #---------------------------------------------------------------
        # Function arguments.
        #---------------------------------------------------------------
        local ($type)               = $_[0];
        local ($element)            = $_[1];
        local ($attributes)         = $_[2];
        local ($typesetting)        = $_[3];
        local ($target)             = $_[4];
        local ($draft)              = $_[5];
        local ($page_numbering)     = $_[6];
        local ($compact)            = $_[7];
        local ($long)               = $_[8];
        local ($original_file_name) = $_[9];
        local ($root_file_name)     = $_[10];
        local ($paper_width)        = $_[11];
	local ($paper_height)       = $_[12];

        #---------------------------------------------------------------
        # Element handlers.
        # Element names and attribute names are uppercase.
        #---------------------------------------------------------------
        if ($element eq "P")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<P>");
              }
            else
              {
                &output ("</P>\n");
              }
          }
        elsif ($element eq "BR")
          {
            if ($type eq "start")
              {
                &output ("<BR>\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "URI")
          {
            if ($type eq "start")
              {
                # Save the index type name.
                $last_normal_uri = ${$attributes}{'URI'};

                &push_output ();
              }
            else
              {
                local ($uri_element) = "";
                $uri_element = &pop_output ();

                if ($uri_element ne "")
                  {
                    $last_normal_uri = $uri_element;
                  }

                &output ("&lt;<EM><A HREF=\""
                         . $last_normal_uri
                         . "\">"
                         . $last_normal_uri
                         . "</A></EM>&gt;");
              }
          }
        elsif ($element eq "MAN")
          {
            if ($type eq "start")
              {
                &output ("<EM>");
              }
            else
              {
                &output ("");
              }
          }
        elsif ($element eq "MANSECT")
          {
            if ($type eq "start")
              {
                &output ("</EM>(");
              }
            else
              {
                &output (")");
              }
          }
        elsif ($element eq "BIBREF")
          {
            if ($type eq "start")
              {
                &output ("<EM>");
              }
            else
              {
                &output ("</EM>");
              }
          }
        elsif ($element eq "EM")
          {
            if ($type eq "start")
              {
                &output ("<EM>");
              }
            else
              {
                &output ("</EM>");
              }
          }
        elsif ($element eq "BIG")
          {
            if ($type eq "start")
              {
                &output ("<BIG>");
              }
            else
              {
                &output ("</BIG>");
              }
          }
        elsif ($element eq "SMALL")
          {
            if ($type eq "start")
              {
                &output ("<SMALL>");
              }
            else
              {
                &output ("</SMALL>");
              }
          }
        elsif ($element eq "STRONG")
          {
            if ($type eq "start")
              {
                &output ("<STRONG>");
              }
            else
              {
                &output ("</STRONG>");
              }
          }
        elsif ($element eq "ACRONYM")
          {
            if ($type eq "start")
              {
                &output ("<ACRONYM>");
              }
            else
              {
                &output ("</ACRONYM>");
              }
          }
        elsif ($element eq "DACRONYM")
          {
            if ($type eq "start")
              {
                &output ("<EM>");
              }
            else
              {
                &output ("</EM>");
              }
          }
        elsif ($element eq "KBD")
          {
            if ($type eq "start")
              {
                &output ("[<KBD>");
              }
            else
              {
                &output ("</KBD>]");
              }
          }
        elsif ($element eq "REVISION")
          {
            if ($type eq "start")
              {
                &output ("[<EM>");
              }
            else
              {
                &output ("</EM>]");
              }
          }
        elsif ($element eq "BUTTON")
          {
            if ($type eq "start")
              {
                &output ("&lt;<CODE>");
              }
            else
              {
                &output ("</CODE>&gt;");
              }
          }
        elsif ($element eq "MENUITEM")
          {
            if ($type eq "start")
              {
                &output ("{<CODE>");
              }
            else
              {
                &output ("</CODE>}");
              }
          }
        elsif ($element eq "ASCIICODE")
          {
            if ($type eq "start")
              {
                &output ("&lt;<EM>");
              }
            else
              {
                &output ("</EM>&gt;");
              }
          }
        elsif ($element eq "CODE")
          {
            if ($type eq "start")
              {
                &output ("<CODE>");
              }
            else
              {
                &output ("</CODE>");
              }
          }
        elsif ($element eq "SAMP")
          {
            if ($type eq "start")
              {
                &output ("<SAMP>");
              }
            else
              {
                &output ("</SAMP>");
              }
          }
        elsif ($element eq "STRDFN")
          {
            if ($type eq "start")
              {
                &output ("<EM>");
              }
            else
              {
                &output ("</EM>");
              }
          }
        elsif ($element eq "KERNELOPTION")
          {
            if ($type eq "start")
              {
                &output ("<EM>");
              }
            else
              {
                &output ("</EM>");
              }
          }
        elsif ($element eq "FILE")
          {
            if ($type eq "start")
              {
                &output ("<CODE>");
              }
            else
              {
                &output ("</CODE>");
              }
          }
        elsif ($element eq "URISTR")
          {
            if ($type eq "start")
              {
                &output ("<CODE>");
              }
            else
              {
                &output ("</CODE>");
              }
          }
        elsif ($element eq "SUP")
          {
            if ($type eq "start")
              {
                &output ("<SUP>");
              }
            else
              {
                &output ("</SUP>");
              }
          }
        elsif ($element eq "SUB")
          {
            if ($type eq "start")
              {
                &output ("<SUB>");
              }
            else
              {
                &output ("</SUB>");
              }
          }
        elsif ($element eq "PWR")
          {
            if ($type eq "start")
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output ("^");
                  }
                else
                  {
                    &output ("<SUP>");
                  }
              }
            else
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output ("");
                  }
                else
                  {
                    &output ("</SUP>");
                  }
              }
          }
        elsif ($element eq "EXA")
          {
            if ($type eq "start")
              {
                if ($target eq "HTML-TEXT")
                  {
                    #&output ("0x");
                    &output ("(");
                  }
                else
                  {
                    # Nothing to do;
                    ;
                  }
              }
            else
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output (")_16");
                  }
                else
                  {
                    &output ("<SUB>16</SUB>");
                  }
              }
          }
        elsif ($element eq "DEC")
          {
            if ($type eq "start")
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output ("(");
                  }
                else
                  {
                    # Nothing to do;
                    ;
                  }
              }
            else
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output (")_10");
                  }
                else
                  {
                    &output ("<SUB>10</SUB>");
                  }
              }
          }
        elsif ($element eq "OCT")
          {
            if ($type eq "start")
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output ("(");
                  }
                else
                  {
                    # Nothing to do;
                    ;
                  }
              }
            else
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output (")_8");
                  }
                else
                  {
                    &output ("<SUB>8</SUB>");
                  }
              }
          }
        elsif ($element eq "BIN")
          {
            if ($type eq "start")
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output ("(");
                  }
                else
                  {
                    # Nothing to do;
                    ;
                  }
              }
            else
              {
                if ($target eq "HTML-TEXT")
                  {
                    &output (")_2");
                  }
                else
                  {
                    &output ("<SUB>2</SUB>");
                  }
              }
          }
        elsif ($element eq "NUM")
          {
            if ($type eq "start")
              {
                # Save data here.
                push_output ();
              }
            else
              {
                local ($num) = "";
                local ($int) = "";
                local ($dec) = "";
                local ($point) = "";
                local ($sep) = "";
                local ($plus) = "";
                local ($minus) = "";

                # Recall output.
                $num = &pop_output ();

                # The separator is a &nbsp;.
                $sep = "&nbsp;";
                $plus = "+";
                $minus = "-";

                # Now, start elaboration, to separate each three digits.
                if ($num =~ m/^([+-]?)([0-9]*)([.,]?)([0-9]*)$/)
                  {
                    $sign  = $1;
                    $int   = $2;
                    $point = $3;
                    $dec   = $4;
                    $int   = &integer_to_string ($int, $sep);
                    $dec   = &decimal_to_string ($dec, $sep);

                    # Correct integer side if necessary.
                    if ($int eq "")
                      {
                        $int = "0";
                      }

                    # Set the sign prefix.
                    if ($sign eq "+")
                      {
                        $sign = $plus;
                      }
                    elsif ($sign eq "-")
                      {
                        $sign = $minus;
                      }
                    else
                      {
                        $sign = "";
                      }

                    if ($dec eq "")
                      {
                        # Nothing after the decimal marker.
                        &output ($sign . $int);
                      }
                    else
                      {
                        &output ($sign . $int . $point . $dec);
                      }
                  }
                else
                  {
                    # This is not a valid number.
                    &diag_output (sprintf (gettext ("%s: wrong number %s !!!!\n"),
                                  $program_executable, $num));
                    # Anyway, print it out.
                    &output ($num);
                  }
              }
          }
        elsif ($element eq "TEX")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Loose the TeX back-end code.
                &pop_output ();
              }
          }
        elsif ($element eq "IFTEX")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Loose the TeX back-end code.
                &pop_output ();
              }
          }
        elsif ($element eq "EPSIMG")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($eps_code) = "";
                local ($eps_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                if ($alt eq "")
                  {
                    $alt = &picture_def ();
                  }

                # Restore the EPS back-end code.
                $eps_code = $eps_code . &pop_output ();

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {
                    # Prepare the EPS temporary file.
                    $eps_temp_file = &temporary_file ($temporary_file_name_prefix);
                    # Save the empty temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${eps_temp_file}";

                    open (EPS_TEMP_FILE, "> ${eps_temp_file}.eps ");
                    print EPS_TEMP_FILE ($eps_code);
                    print EPS_TEMP_FILE ("\n");
                    close (EPS_TEMP_FILE);

                    # New HTML picture
                    $html_picture_counter++;

                    # Convert picture geometry
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width}x$height! ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width} ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -density 300x300 -geometry x${height} ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
			# It is obtained with the -density option.
			# The 140x140 gives the double of the original
			# dimension.
                        system ("convert -density 140x140 ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "${eps_temp_file}.eps",
                                           "$html_picture_counter.jpg"));

                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${eps_temp_file}.eps";

                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                      }
                  }
              }
          }
        elsif ($element eq "TEXIMG")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($tex_code) = "";
                local ($tex_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                if ($alt eq "")
                  {
                    $alt = &picture_def ();
                  }

                # Restore the TeX back-end code.
                $tex_code = $tex_code . &pop_output ();

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {
                    # Prepare the TeX temporary file.
                    $tex_temp_file = &temporary_file ($temporary_file_name_prefix);
                    # Save the empty temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${tex_temp_file}";

                    open (TEX_TEMP_FILE, "> ${tex_temp_file}.tex");
	            print TEX_TEMP_FILE ("\\nonstopmode\n");
    	    	    print TEX_TEMP_FILE ("\\nopagenumbers\n");
            	    print TEX_TEMP_FILE ($tex_code);
            	    print TEX_TEMP_FILE ("\n");
            	    print TEX_TEMP_FILE ("\\bye\n");
            	    close (TEX_TEMP_FILE);

        	    # Typeset.
		    # Consider that tex can accept a file name with path,
    		    # but will generate a file DVI on current directory.
		    # That's why I am doing this cd and basename.
            	    system ("cd " . &temporary_dir () . " ; tex `basename ${tex_temp_file}.tex`");
            	    system ("dvips -E -o ${tex_temp_file}.ps ${tex_temp_file}.dvi");

            	    # Save the temporary file name inside the list.
            	    $temp_files_list = $temp_files_list
                	               . " ${tex_temp_file}.dvi"
			    	       . " ${tex_temp_file}.tex"
                        	       . " ${tex_temp_file}.ps";

                    # New HTML picture
                    $html_picture_counter++;

                    # Convert picture geometry
		    # Must tell the first scene number as [0] after the file name.
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width}x$height! ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width} ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -density 300x300 -geometry x${height} ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
			# It is obtained with the -density option.
			# The 140x140 gives the double of the original
			# dimension.
                        system ("convert -density 140x140 ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "${tex_temp_file}.ps",
                                           "$html_picture_counter.jpg"));

                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                      }
                  }
              }
          }
        elsif ($element eq "HTML")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                # Nothing to do here;
                ;
              }
          }
        elsif ($element eq "IFHTML")
          {
            if ($type eq "start")
              {
                # Nothing to do here;
                ;
              }
            else
              {
                # Nothing to do here;
                ;
              }
          }
        elsif ($element eq "BLOCKQUOTE")
          {
            if ($type eq "start")
              {
                &output ("<BLOCKQUOTE>\n");

                # Save the URI.
                $last_quote_uri = ${$attributes}{'URI'};
              }
            else
              {
                if ($last_quote_uri ne "")
                  {
                    local ($n) = 0;

                    # Put the URI at a footnote.

                    # Prepare a new element inside the footnote array.
                    $#html_footnote_list++;
                    $n = $#html_footnote_list +1;

                    # Insert the footnote link.
                    &output ("<P><SUP><A HREF=\"#footnote$n\" NAME=\"footnote-ref$n\">($n)</A></SUP></P>");

                    # Insert the footnote inside the array.
                    $html_footnote_list[$#html_footnote_list]
                      = "<A HREF=\"$last_quote_uri\">$last_quote_uri</A>";
                  }
                &output ("\n");
                &output ("</BLOCKQUOTE>\n");
              }
          }
        elsif ($element eq "FRAME")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<TABLE BORDER=\"3\" "
                         . "WIDTH=\"100%\">\n");
                &output ("<TR><TD>\n");
              }
            else
              {
                &output ("\n");
                &output ("</TD></TR>\n");
                &output ("</TABLE>\n");
              }
          }
        elsif ($element eq "PRE")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<PRE>");
              }
            else
              {
                &output ("</PRE>\n");
              }
          }
        elsif ($element eq "PNEWLINE")
          {
            if ($type eq "start")
              {
                &output ("&nbsp;<STRONG><EM>("
                         . &command_continue_on_the_next_line_def ()
                         . ")</EM></STRONG><BR>");
                &output ("&nbsp;&nbsp;");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "VERBATIMPRE")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<PRE>");
              }
            else
              {
                &output ("</PRE>\n");
              }
          }
        elsif ($element eq "SYNTAX")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($syntax) = "";
                # The normal mode for output() function is re-established.
                $syntax = &pop_output ();
                # Change new line code into <BR>.
                $syntax =~ s/$/\n<BR>/mg;
                # Change space into "" (160=nbsp).
                $syntax =~ tr/ //;

                # Change last <BR> into nothing.
                $syntax =~ s/<BR>$//;

                &output ("\n");
                &output ("<P class=\"syntax\">");
                &output ("<CODE>");
                &output ("$syntax");
                &output ("</CODE>");
                &output ("</P>\n");
              }
          }
        elsif ($element eq "SNEWLINE")
          {
            if ($type eq "start")
              {
                #&output ("&nbsp;<SUB><EM>("
                #         . &command_continue_on_the_next_line_def ()
                #         . ")</EM></SUB><BR>");
                #&output ("&nbsp;&nbsp;");
                &output ("</CODE><SUB><STRONG>&lt;-'</STRONG></SUB><BR>");
                &output ("<SUP><STRONG>`-&gt;</STRONG></SUP><CODE>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "DL")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<DL>\n");
              }
            else
              {
                &output ("</DL>\n");
              }
          }
        elsif ($element eq "DT")
          {
            if ($type eq "start")
              {
                &output ("<DT>");
              }
            else
              {
                &output ("</DT>\n");
              }
          }
        elsif ($element eq "DD")
          {
            if ($type eq "start")
              {
                &output ("<DD>\n");
              }
            else
              {
                &output ("</DD>\n");
              }
          }
        elsif ($element eq "OL")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<OL>\n");
              }
            else
              {
                &output ("</OL>\n");
              }
          }
        elsif ($element eq "UL")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<UL>\n");
              }
            else
              {
                &output ("</UL>\n");
              }
          }
        elsif ($element eq "LI")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<LI>\n");
              }
            else
              {
                &output ("</LI>\n");
              }
          }
        elsif ($element eq "SEGMENT")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<DL>\n");
              }
            else
              {
                &output ("</DD>\n");
                &output ("</DL>\n");
              }
          }
        elsif ($element eq "SEGMENTHEAD")
          {
            if ($type eq "start")
              {
                &output ("<DT><STRONG>");
              }
            else
              {
                &output ("</STRONG></DT>\n");
                &output ("<DD>\n");
              }
          }
        elsif ($element eq "IMG")
          {
            if ($type eq "start")
              {
                local ($imgfile) = "";
                local ($alt) = "";
                local ($width) = "";
                local ($heght) = "";
                # Save picture information.
                $imgfile = ${$attributes}{'IMGFILE'};
                $alt = ${$attributes}{'ALT'};
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                if ($alt eq "")
                  {
                    $alt = &picture_def ();
                  }

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {
                    $html_picture_counter++;

                    # Convert picture geometry
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -geometry ${width}x$height! $imgfile.png $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -geometry ${width} $imgfile.png $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -geometry x${height} $imgfile.png $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
                        system ("convert -geometry 200% $imgfile.png $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "$imgfile.png",
                                           "$html_picture_counter.jpg"));
                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                      }
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "EMBIMG")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($img_code) = "";
                local ($img_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                if ($alt eq "")
                  {
                    $alt = &picture_def ();
                  }

                # Restore the base64 code.
                $img_code = $img_code . &pop_output ();

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {

                    # Prepare the temporary file.
                    $img_temp_file = &temporary_file ($temporary_file_name_prefix);
                    # Save the empty temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}";

                    open (IMG_TEMP_FILE, "> ${img_temp_file}.uuencode ");
                    print IMG_TEMP_FILE ("begin-base64 664 dummy\n");
                    print IMG_TEMP_FILE ($img_code);
                    print IMG_TEMP_FILE ("\n");
                    print IMG_TEMP_FILE ("====\n");
                    close (IMG_TEMP_FILE);

                    # Get the picture with uudecode.
                    system ("uudecode -o ${img_temp_file}.uudecode ${img_temp_file}.uuencode");

                    # New HTML picture
                    $html_picture_counter++;

                    # Convert picture geometry
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -geometry ${width}x$height! ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -geometry ${width} ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -geometry x${height} ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
                        system ("convert -geometry 200% ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "${img_temp_file}.uudecode",
                                           "$html_picture_counter.jpg"));

                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uudecode";
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uuencode";

                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                      }
                  }
              }
          }
        elsif ($element eq "VAR")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                local ($var) = "";
                $var = &pop_output ();

                if ($target eq "HTML-TEXT")
                  {
                    # It would be fine to put it under upper case, but
                    # it isn't possibile: sub element names will be translated
                    # into upper case too, with attributes; but the worse
                    # thing is that also entities would be changed,
                    # and this is not possibile!
                    $var = "&lt;$var&gt;";
                    &output ("<VAR>$var</VAR>");
                  }
                else
                  {
                    # &output ("&thinsp;<VAR>$var</VAR>&thinsp;");
                    # &thinsp; does not work because it requires Unicode!
                    # The problem of <var>...</var><var>...</var> remains,
                    # so that the two variables might seem one different
                    # bigger variable.
                    &output ("<VAR>$var</VAR>");
                  }
              }
          }
        elsif ($element eq "SYNSQB")
          {
            if ($type eq "start")
              {
                &output ("<STRONG><BIG>[</BIG></STRONG>");
              }
            else
              {
                &output ("<STRONG><BIG>]</BIG></STRONG>");
              }
          }
        elsif ($element eq "SYNCUB")
          {
            if ($type eq "start")
              {
                &output ("<STRONG><BIG>{</BIG></STRONG>");
              }
            else
              {
                &output ("<STRONG><BIG>}</BIG></STRONG>");
              }
          }
        elsif ($element eq "SYNVERBAR")
          {
            if ($type eq "start")
              {
                &output ("<STRONG><BIG>|</BIG></STRONG>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SYNELLIPSIS")
          {
            if ($type eq "start")
              {
                &output ("...");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SYNSTAR")
          {
            if ($type eq "start")
              {
                &output ("<STRONG><BIG>*</BIG></STRONG>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "HR")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<HR>\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "NEWPAGE")
          {
            if ($type eq "start")
              {
                # Nothing to do.
                ;
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "BOTTOMPAGE")
          {
            if ($type eq "start")
              {
                # Nothing to do.
                ;
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "COMMAND")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<P class=\"command\">");
              }
            else
              {
                &output ("</P>\n");
              }
          }
        elsif ($element eq "PROMPT")
          {
            if ($type eq "start")
              {
                &output ("<CODE>");
              }
            else
              {
                &output ("</CODE>");
              }
          }
        elsif ($element eq "TYPE")
          {
            if ($type eq "start")
              {
                &output ("<STRONG><CODE>");
              }
            else
              {
                &output ("</CODE></STRONG>");
              }
          }
        elsif ($element eq "CNEWLINE")
          {
            if ($type eq "start")
              {
                #&output ("&nbsp;<SUB><EM>("
                #         . &command_continue_on_the_next_line_def ()
                #         . ")</EM></SUB><BR>");
                #&output ("&nbsp;&nbsp;");
                &output ("</CODE></STRONG><SUB>&lt;-'</SUB><BR>");
                &output ("<SUP>`-&gt;</SUP><STRONG><CODE>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "ENDOFCHAPTER")
          {
            if ($type eq "start")
              {
                # Nothing to do.
                ;
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "BACKCOVERPICTURE")
          {
            if ($type eq "start")
              {
                # Save picture information.
                $back_cover_picture_file = ${$attributes}{'IMGFILE'};
                $back_cover_picture_width = ${$attributes}{'WIDTH'};
                $back_cover_picture_height = ${$attributes}{'HEIGHT'};
                # Fix HTML page counter.
                $html_back_cover_page = 1;
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "BACKCOVERTEXT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $back_cover_text = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$front_cover_text =~ s/^\n?(.*)$/$1/s;

                # Fix HTML page counter.
                $html_back_cover_page = 1;
              }
          }

    } # sgml_tag_elab_html_basic

    #-------------------------------------------------------------------
    # This is the elaboration process specific for the HTML back-end.
    #
    # &sgml_tag_elab_html (TYPE, ELEMENT, %ATTRIBUTES,
    #                      TYPESETTING,
    #                      TARGET,
    #                      DRAFT,
    #                      PAGE-NUMBERING,
    #                      COMPACT,
    #                      LONG,
    #                      ORIGINAL_NAME,
    #                      ROOT_FILE_NAME)
    #
    sub sgml_tag_elab_html
    {
        #---------------------------------------------------------------
        # Function arguments.
        #---------------------------------------------------------------
        local ($type)               = $_[0];
        local ($element)            = $_[1];
        local ($attributes)         = $_[2];
        local ($typesetting)        = $_[3];
        local ($target)             = $_[4];
        local ($draft)              = $_[5];
        local ($page_numbering)     = $_[6];
        local ($compact)            = $_[7];
        local ($long)               = $_[8];
        local ($original_file_name) = $_[9];
        local ($root_file_name)     = $_[10];
        local ($paper_width)        = $_[11];
	local ($paper_height)       = $_[12];

        #---------------------------------------------------------------
        # Prepare the HTML header.
        #
        # &html_standard_page_top (ROOT_FILE_NAME,
        #                          CURRENT_PAGE_NUMBER,
        #                          MAX_PAGE,
        #                          HTML_EXT,
        #                          HTML_LANGUAGE,
        #                          META_HTTP_EQUIV,
        #                          META_DESCRIPTION,
        #                          META_KEYWORDS,
        #                          META_AUTHOR,
        #                          META_DATE,
        #                          TITLE)
        #
        sub html_standard_page_top
        {
            local ($name)        = $_[0];
            local ($page)        = $_[1];
            local ($max_page)    = $_[2];
            local ($html_ext)    = $_[3];
            local ($lang)        = $_[4];
            local ($http_equiv)  = $_[5];
            local ($description) = $_[6];
            local ($keywords)    = $_[7];
            local ($author)      = $_[8];
            local ($date)        = $_[9];
            local ($title)       = $_[10];

            local ($current)     = "";
            local ($previous)    = "";
            local ($next)        = "";
            local ($up)          = "";
            local ($last)        = "";
            local ($next_page)     = $page + 1;
            local ($previous_page) = $page - 1;

            local ($n)         = 0;
            local ($m)         = 0;

            local ($tome_up)       = "";
            local ($part_up)       = "";
            local ($navigation_up) = "";

            # Calculate link pages.
            if ($page == 0)
              {
                $current = $name . $html_ext;
              }
            else
              {
                $current = $name . $page . $html_ext;
              }

            if ($page > 1)
              {
                $previous = $name . $previous_page . $html_ext;
              }
            else
              {
                $previous = $name . $html_ext;
              }
            if ($page < $max_page)
              {
                $next = $name . $next_page . $html_ext;
              }
            else
              {
                $next = $name . $page . $html_ext;
              }
            $up = $name . $html_ext;
            $last = $name . $max_page . $html_ext;

            # Print Header.
            &output ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"");
            &output ("    \"http://www.w3.org/TR/html4/strict.dtd\">\n");
            &output ("<HTML LANG=\"$lang\">\n");
            &output ("<HEAD>\n");
            &output ("    <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"$http_equiv\">\n");
            &output ("    <META NAME=\"Generator\" CONTENT=\"Alml\">\n");
            if ($description ne "")
              {
                &output ("    <META NAME=\"Description\" CONTENT=\"$description\">\n");
              }
            if ($keywords ne "")
              {
                &output ("    <META NAME=\"Keywords\" CONTENT=\"$keywords\">\n");
              }
            &output ("    <META NAME=\"Author\" CONTENT=\"$author\">\n");
            &output ("    <META NAME=\"Date\" CONTENT=\"$date\">\n");
            # HTML meta tags.
            #
            # $html_meta_tag[x][0]        name
            # $html_meta_tag[x][1]        lang
            # $html_meta_tag[x][2]        content
            for ($n = 0 ; $n <= $#html_meta_tag ; $n++)
              { 
                &output ("    <META NAME=\""
                         . $html_meta_tag[$n][0]
                         . "\" ");
                if ($html_meta_tag[$n][1] ne "")
                  {
                    &output ("LANG=\""
                             . $html_meta_tag[$n][1]
                             . "\" ");
                  }
                if ($html_meta_tag[$n][2] ne "")
                  {
                    &output ("CONTENT=\""
                             . $html_meta_tag[$n][2]
                             . "\" ");
                  }
                &output (">\n");
              }
            #&output ("    <META NAME=\"Resource-type\" LANG=\"en\" CONTENT=\"Document\">\n");
            #&output ("    <META NAME=\"Revisit-after\" LANG=\"en\" CONTENT=\"2 days\">\n");
            #&output ("    <META NAME=\"Robots\" CONTENT=\"ALL\">\n");
            &output ("    <TITLE>$title</TITLE>\n");
            &output ("    <LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$name.css\">\n");
            &output ("    <LINK REL=\"Start\" TITLE=\"Start\" HREF=\"$up\">\n");
            &output ("    <LINK REL=\"Prev\" TITLE=\"Previous\" HREF=\"$previous\">\n");
            &output ("    <LINK REL=\"Next\" TITLE=\"Next\" HREF=\"$next\">\n");
            &output ("</HEAD>\n");
            &output ("<BODY>\n");
            &output ("<P>\n");
            &output ("<A HREF=\"$next\">[" . &next_page_def () . "]</A>\n");
            &output ("<A HREF=\"$previous\">[" . &previous_page_def () . "]</A>\n");
            &output ("<A HREF=\"$up\">[" . &top_page_def () . "]</A>\n");
            &output ("<A HREF=\"$last\">[" . &last_page_def () . "]</A>\n");

            # Insert fixed navigation links.
            #
            # $html_page_fixed_link_list[x][0]        html page number
            # $html_page_fixed_link_list[x][1]        link description
            for ($n = 0; $n <= $#html_page_fixed_link_list; $n++)
              {
                $navigation_up = $name
                                 . $html_page_fixed_link_list[$n][0]
                                 . $html_ext;
                &output ("<A HREF=\"$navigation_up\">["
                         . $html_page_fixed_link_list[$n][1]
                         . "]</A>\n");
              }

            if ($document_position eq "body"
                && $tome > 0)
              {
                # Need to extract tome page number.
                # Remember that arrays have starting index 0.
                $tome_up = $name
                           . $html_page_tome_link_list[$tome-1]
                           . $html_ext;
                
                &output ("<A HREF=\"$tome_up\">[" . &tome_def () . "]</A>\n");
              }
            if ($document_position eq "body"
                && $part > 0
		&& $part_present)
              {
                # Need to extract part page number.
                # Remember that arrays have starting index 0.
                $part_up = $name
                           . $html_page_part_link_list[$part-1]
                           . $html_ext;

                &output ("<A HREF=\"$part_up\">[" . &part_def () . "]</A>\n");
              }
            &output ("</P>\n");
            &output ("<HR>\n");
            &output ("<DIV>\n");
        }

        #---------------------------------------------------------------
        # Prepare the HTML footer.
        #
        # &html_standard_page_bottom (ROOT_FILE_NAME,
        #                             CURRENT_PAGE_NUMBER,
        #                             MAX_PAGE,
        #                             HTML_EXT)
        #
        sub html_standard_page_bottom
        {
            local ($name)       = $_[0];
            local ($page)       = $_[1];
            local ($max_page)   = $_[2];
            local ($html_ext)   = $_[3];

            local ($current)    = "";
            local ($previous)   = "";
            local ($next)       = "";
            local ($up)         = "";
            local ($last)       = "";
            local ($next_page)     = $page + 1;
            local ($previous_page) = $page - 1;

            local ($n)         = 0;
            local ($m)         = 0;

            local ($tome_up)       = "";
            local ($part_up)       = "";

            local ($human_readable_file_name) = "";

            # Calculate link pages.
            if ($page == 0)
              {
                $current = $name . $html_ext;
              }
            else
              {
                $current = $name . $page . $html_ext;
              }

            if ($page > 1)
              {
                $previous = $name . $previous_page . $html_ext;
              }
            else
              {
                $previous = $name . $html_ext;
              }
            if ($page < $max_page)
              {
                $next = $name . $next_page . $html_ext;
              }
            else
              {
                $next = $name . $page . $html_ext;
              }
            $up = $name . $html_ext;
            $last = $name . $max_page . $html_ext;

            # Print footnotes.
            &html_standard_footnotes ();

            # Print Footer.
            &output ("</DIV>\n");
            &output ("<HR>\n");

            # Fix human readable file name.
            $human_readable_file_name
              = &human_readable_file_name ($last_html_page_title)
                . $html_ext;
            system ("ln -s $current $human_readable_file_name");

            &output ("<P>"
                     . &may_link_to_human_readable_name_def ()
                     . " <A HREF=\"$human_readable_file_name\">"
                     . $human_readable_file_name
                     . "</A></P>\n");

            &output ("<P>\n");
            &output ("<A HREF=\"$next\">[" . &next_page_def () . "]</A>\n");
            &output ("<A HREF=\"$previous\">[" . &previous_page_def () . "]</A>\n");
            &output ("<A HREF=\"$up\">[" . &top_page_def () . "]</A>\n");
            &output ("<A HREF=\"$last\">[" . &last_page_def () . "]</A>\n");

            # Insert fixed navigation links.
            #
            # $html_page_fixed_link_list[x][0]        html page number
            # $html_page_fixed_link_list[x][1]        link description
            for ($n = 0; $n <= $#html_page_fixed_link_list; $n++)
              {
                $navigation_up = $name
                                 . $html_page_fixed_link_list[$n][0]
                                 . $html_ext;
                &output ("<A HREF=\"$navigation_up\">["
                         . $html_page_fixed_link_list[$n][1]
                         . "]</A>\n");
              }

            # The bottom page links about tome and part is difficult
            # to fix, because the tome and the part might be changed.
            #if ($document_position eq "body"
            #    && $tome > 0)
            #  {
            #    # Need to extract tome page number.
            #    # Remember that arrays have starting index 0.
            #    $tome_up = $name
            #              . $html_page_tome_link_list[$tome-1]
            #              . $html_ext;
            #
            #   &output ("<A HREF=\"$tome_up\">[" . &tome_def () . "]</A>\n");
            #  }
            #if ($document_position eq "body"
            #    && $part > 0)
            #  {
            #    # Need to extract tome page number.
            #    # Remember that arrays have starting index 0.
            #    $part_up = $name
            #              . $html_page_part_link_list[$part-1]
            #              . $html_ext;
            #
            #   &output ("<A HREF=\"$part_up\">[" . &part_def () . "]</A>\n");
            #  }

            &output ("</P>\n");
            
            &output ("</BODY>\n");
            &output ("</HTML>\n");
        }

        #---------------------------------------------------------------
        # Print HTML footnotes and clear footnote list
        #
        # &html_standard_footnotes ()
        #
        sub html_standard_footnotes
        {
            # Print footnotes.
            if ($#html_footnote_list >= 0)
              {
                &output ("<HR>\n");
                for ($n = 0; $n <= $#html_footnote_list; $n++)
                  {
                    $m = $n +1;
                    &output ("\n");
                    &output ("<P>");
                    &output ("<A HREF=\"#footnote-ref$m\" NAME=\"footnote$m\">$m)</A> ");
                    &output ($html_footnote_list[$n]);
                    &output ("</P>\n");
                  }
              }
            # Reset footnote list.
            @html_footnote_list = ();
        }

        #---------------------------------------------------------------
        # Prepare a new HTML page: close the previous and start the next.
        # It is better not to use this function, because it is difficult
        # to have complete data to build the bottom of the previous
        # HTML page.
        #
        # &html_new_page (ROOT_FILE_NAME,
        #                 MAX_PAGE,
        #                 HTML_EXT,
        #                 HTML_LANGUAGE,
        #                 META_HTTP_EQUIV,
        #                 META_DESCRIPTION,
        #                 META_KEYWORDS,
        #                 META_AUTHOR,
        #                 META_DATE,
        #                 TITLE)
        #
        sub html_new_page
        {
            local ($name)         = $_[0];
            local ($max_page)     = $_[1]; # True or false
            local ($html_ext)     = $_[2];
            local ($lang)         = $_[3];
            local ($http_equiv)   = $_[4];
            local ($description)  = $_[5];
            local ($keywords)     = $_[6];
            local ($author)       = $_[7];
            local ($date)         = $_[8];
            local ($title)        = $_[9];

            # Print bottom HTML page.
            &html_standard_page_bottom ($name,
                                        $html_page_counter,
                                        $max_page,
                                        $html_ext);

            # Close output stream.
            close ($current_output_stream);

            # Increment the HTML page counter (global variable)
            $html_page_counter++;
            # Reopen
            $current_output_stream = $name . $html_page_counter . $html_ext;
            open ($current_output_stream, "> " . $name . $html_page_counter . $html_ext);

            # Print top HTML page.
            &html_standard_page_top ($root_file_name,
                                     $html_page_counter,
                                     $max_page,
                                     $html_ext,
                                     $current_language,
                                     "text/html",
                                     $description,
                                     $keywords,
                                     $author,
                                     $date,
                                     $title);
        }


        #---------------------------------------------------------------
        # Determinate the right string to fenerate for a text table
        # element.
        #
        # The problem is that we know the final number of columns
        # that we want, but actually the cell has also HTML
        # markup. Some calculation is neaded.
        #
        # &html_table_cell_string (CELL, WIDTH)
        #
        sub html_table_cell_string
        {
            local ($cell)  = $_[0];
            local ($width) = $_[1];
            local ($elab_cell)    = "";
            local ($gross_length) = 0;
            local ($net_length)   = 0;
            local ($diff_length)  = 0;

            $elab_cell = $cell;
            # Calculate the actual gross length.
            $gross_length = length ($elab_cell);
            #
            # Reduce the string, eliminating HTML elements and
            # extra HTML entities, just like it was done
            # when calculating originally the length.
            #
            # Remember that at the first scan, some element are
            # just absent: SPECIAL, DFN, ANCHOR and INDEXENTRY.
            # At this moments, these elements are translated
            # into A elements. These A elements must be
            # just discarded.
            #
            $elab_cell =~ s/<A .*?>//ig;
            $elab_cell =~ s/<\/A>//ig;
            #
            # VAR elements have an additional "<" and ">" added.
            # This addition must be considered while counting
            # the net string length.
            #
            $elab_cell =~ s/<VAR>&lt;/_/ig;
            $elab_cell =~ s/&gt;<\/VAR>/_/ig;
            #
            # Other elements are treated as a single character
            #
            $elab_cell =~ s/<.*?>/_/ig;
            #
            # Entities are meant to be single letters.
            #
            $elab_cell =~ s/&[a-z]+;/\?/ig;
            # Calculate net length.
            $net_length = length ($elab_cell);
            # Calculate the difference.
            $diff_length = $gross_length - $net_length;

            $cell = $cell . &spaces (200);
            $cell = substr ($cell, 0, $width + $diff_length);

            return $cell;

        }

        #---------------------------------------------------------------
        # Element handlers.
        # Element names and attribute names are uppercase.
        #---------------------------------------------------------------
        if ($element eq "ALML")
          {
            if ($type eq "start")
              {
                # Reset all counters.
                $intro = 0;
                $tome = 0;
                $part = 0;
		$part_present = 0;
                $chapter = 0;
                $h1section_absolute_counter = 0;
                $appendix = 0;
                $sect1 = 0;         
                $sect2 = 0;         
                $sect3 = 0;         
                $index = 0;
                $table = 0;
                $absolute_table = 0;
                $picture =  0;
                $absolute_figure = 0;
                $absolute_listing = 0;
                $unnumbered = 0;
                $current_level = "";
                $document_position = "";
                $index_entry_counter = 0;
                $html_max_page          = $html_page_counter + $html_back_cover_page;
                $html_page_counter      = 0;
                $html_picture_counter   = 0;
                @html_footnote_list     = ();

                # Save administrative information.
                $current_language = ${$attributes}{'LANG'};
                $document_language = $current_language;
                $tome_language = $current_language;
                $part_language = $current_language;
                $chapter_language = $current_language;
                $document_spacing = lc ${$attributes}{'SPACING'};

                # Reset the human readable file name list.
                $html_human_readable_file_name_list = ();

              }
            else
              {
                # If back cover page...
                if ($back_cover_picture_file ne ""
                    || $back_cover_text ne "")
                  {
                    # There is another final page.
                    
                    # New HTML page now.
                    if ($target eq "HTML-TEXT")
                      {
                        # Nothing to do here; footnotes are
                        # printed at the very last as the counter
                        # cannot be reset befor the end of this
                        # big HTML page.
                        ;
                      }
                    else
                      {
                        #
                        # Close the previous HTML page
                        #
                        # &html_standard_page_bottom (ROOT_FILE_NAME,
                        #                             CURRENT_PAGE_NUMBER,
                        #                             MAX_PAGE,
                        #                             HTML_EXT)
                        #
                        &html_standard_page_bottom
                          ($root_file_name,
                           $html_page_counter,
                           $html_max_page,
                           $html_ext);

                        # Close output stream.
                        close ($current_output_stream);

                        # Increment the HTML page counter (global variable)
                        $html_page_counter++;

                        # Set language information to document language.
                        $current_language = $document_language;

                        # Reopen
                        $current_output_stream = $root_file_name
                                                 . $html_page_counter
                                                 . $html_ext;
                        open ($current_output_stream,
                              "> "
                              . $root_file_name
                              . $html_page_counter
                              . $html_ext);

                        # Print top HTML page.
                        #
                        # &html_standard_page_top (ROOT_FILE_NAME,
                        #                          CURRENT_PAGE_NUMBER,
                        #                          MAX_PAGE,
                        #                          HTML_EXT,
                        #                          HTML_LANGUAGE,
                        #                          META_HTTP_EQUIV,
                        #                          META_DESCRIPTION,
                        #                          META_KEYWORDS,
                        #                          META_AUTHOR,
                        #                          META_DATE,
                        #                          TITLE)
                        #
                        &html_standard_page_top ($root_file_name,
                                                 $html_page_counter,
                                                 $html_max_page,
                                                 $html_ext,
                                                 $current_language,
                                                 "text/html",
                                                 $document_description,
                                                 $document_keywords,
                                                 "@authors",
                                                 $date,
                                                 $title);
                      }
                  }
                # Back cover picture.
                if ($back_cover_picture_file ne "")
                  {
                    local ($width) = 0;
                    local ($height) = 0;
                    if ($target eq "HTML-TEXT")
                      {
                        # No pictures here. Nothing to do.
                        ;
                      }
                    else
                      {
                        # Convert to pixel somehow.
                        $width = &convert_to_pixel ($back_cover_picture_width);
                        $height = &convert_to_pixel ($back_cover_picture_height);
                      
                        $html_picture_counter++;
                        # Convert picture geometry
                        if ($width > 0 && $height > 0)
                          {
                            system ("convert -geometry ${width}x$height! $back_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        elsif ($width > 0)
                          {
                            system ("convert -geometry ${width} $back_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        elsif ($height > 0)
                          {
                            system ("convert -geometry x${height} $back_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        else
                          {
                            system ("convert $back_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                               $program_executable,
                                               $original_file_name,
                                               "$back_cover_picture_file.png",
                                               "$html_picture_counter.jpg"));
                        &output ("\n");
                        &output ("<P>");
                        if ($width > 0 && $height > 0)
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                          }
                        elsif ($width > 0)
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                          }
                        elsif ($height > 0)
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                          }
                        else
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                          }
                        &output ("</P>\n");
                      }
                }
                &output ("\n");
                if ($back_cover_text ne "")
                  {
                    &output ("$back_cover_text");
                  }

                # Close the HTML source
                if ($target eq "HTML-TEXT")
                  {
                    # This is the end of the file. It is time
                    # to print footnotes.
                    &html_standard_footnotes ();
                    &output ("</BODY>\n");
                    &output ("</HTML>\n");
                  }
                else
                  {
                    # &html_standard_page_bottom (ROOT_FILE_NAME,
                    #                             CURRENT_PAGE_NUMBER,
                    #                             MAX_PAGE,
                    #                             HTML_EXT)
                    &html_standard_page_bottom ($root_file_name,
                                                $html_page_counter,
                                                $html_max_page,
                                                $html_ext);
                  }
              }
          }
        elsif ($element eq "HEAD")
          {
            if ($type eq "start")
              {
                # Save the document position.
                $document_position = "head";
              }
            else
              {
                # End of header: compose into HTML.
                local ($n) = 0;
                local ($line) = "";

                if ($target eq "HTML-TEXT")
                  {
                    &output ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"");
                    &output ("    \"http://www.w3.org/TR/html4/strict.dtd\">\n");
                    &output ("<HTML LANG=\"$current_language\">\n");
                    &output ("<HEAD>\n");
                    &output ("    <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html\">\n");
                    &output ("    <META NAME=\"Generator\" CONTENT=\"Alml\">\n");
                    if ($document_description ne "")
                      {
                        &output ("    <META NAME=\"Description\" CONTENT=\"$document_description\">\n");
                      }
                    if ($document_keywords ne "")
                      {
                        &output ("    <META NAME=\"Keywords\" CONTENT=\"$document_keywords\">\n");
                      }
                    &output ("    <META NAME=\"Author\" CONTENT=\"@authors\">\n");
                    &output ("    <META NAME=\"Date\" CONTENT=\"$date\">\n");
                    # HTML meta tags.
                    #
                    # $html_meta_tag[x][0]        name
                    # $html_meta_tag[x][1]        lang
                    # $html_meta_tag[x][2]        content
                    for ($n = 0 ; $n <= $#html_meta_tag ; $n++)
                      { 
                        &output ("    <META NAME=\""
                                 . $html_meta_tag[$n][0]
                                 . "\" ");
                        if ($html_meta_tag[$n][1] ne "")
                          {
                            &output ("LANG=\""
                                     . $html_meta_tag[$n][1]
                                     . "\" ");
                          }
                        if ($html_meta_tag[$n][2] ne "")
                          {
                            &output ("CONTENT=\""
                                     . $html_meta_tag[$n][2]
                                     . "\" ");
                          }
                        &output (">\n");
                      }
                    #&output ("    <META NAME=\"Resource-type\" LANG=\"en\" CONTENT=\"Document\">\n");
                    #&output ("    <META NAME=\"Revisit-after\" LANG=\"en\" CONTENT=\"2 days\">\n");
                    #&output ("    <META NAME=\"Robots\" CONTENT=\"ALL\">\n");
                    &output ("    <TITLE>$title</TITLE>\n");
                    &output ("</HEAD>\n");
                    &output ("<BODY>\n");
                  }
                else
                  {
                    # &html_standard_page_top (ROOT_FILE_NAME,
                    #                          CURRENT_PAGE_NUMBER,
                    #                          MAX_PAGE,
                    #                          HTML_EXT,
                    #                          HTML_LANGUAGE,
                    #                          META_HTTP_EQUIV,
                    #                          META_DESCRIPTION,
                    #                          META_KEYWORDS,
                    #                          META_AUTHOR,
                    #                          META_DATE,
                    #                          TITLE)
                    &html_standard_page_top ($root_file_name,
                                             $html_page_counter,
                                             $html_max_page,
                                             $html_ext,
                                             $current_language,
                                             "text/html",
                                             $document_description,
                                             $document_keywords,
                                             "@authors",
                                             $date,
                                             $title);
                  }

                # Front cover picture.
                if ($front_cover_picture_file ne "")
                  {
                    local ($width) = 0;
                    local ($height) = 0;

                    if ($target eq "HTML-TEXT")
                      {
                        # No pictures here. Nothing to do.
                        ;
                      }
                    else
                      {

                        # Convert to pixel somehow.
                        $width = &convert_to_pixel ($front_cover_picture_width);
                        $height = &convert_to_pixel ($front_cover_picture_height);
                      
                        $html_picture_counter++;
                        # Convert picture geometry
                        if ($width > 0 && $height > 0)
                          {
                            system ("convert -geometry ${width}x$height! $front_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        elsif ($width > 0)
                          {
                            system ("convert -geometry ${width} $front_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        elsif ($height > 0)
                          {
                            system ("convert -geometry x${height} $front_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        else
                          {
                            system ("convert $front_cover_picture_file.png $html_picture_counter.jpg");
                          }
                        &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                               $program_executable,
                                               $original_file_name,
                                               "$front_cover_picture_file.png",
                                               "$html_picture_counter.jpg"));
                        &output ("\n");
                        &output ("<P>");
                        if ($width > 0 && $height > 0)
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                          }
                        elsif ($width > 0)
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                          }
                        elsif ($height > 0)
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                          }
                        else
                          {
                            &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                          }
                        &output ("</P>\n");
                      }
                }
                &output ("\n");
                &output ("<HR>\n");
                &output ("<H1>$title</H1>\n");
                &output ("<HR>\n");
                if ($#subtitles > -1)
                  {
                    for ($n = 0 ; $n <= $#subtitles ; $n++)
                      { 
                        &output ("<H2>$subtitles[$n]</H2>\n");
                      }
                    &output ("<HR>\n");
                  }
                for ($n = 0 ; $n <= $#authors ; $n++)
                  { 
                    &output ("<P>$authors[$n]</P>\n");
                  }
                if ($edition eq "")
                  {
                    &output ("<P>$version $date</P>\n");
                  }
                else
                  {
                    &output ("<P>$version $edition</P>\n");
                  }
                &output ("\n");
                if ($front_cover_text ne "")
                  {
                    &output ("$front_cover_text");
                  }

                # Pseudo new page.
                &output ("\n");
                # Print footnotes.
                &html_standard_footnotes ();
                &output ("<HR>\n");
                &output ("<HR>\n");

                if ($extra_text_before_legal ne "")
                  {
                    &output ("$extra_text_before_legal");
                  }

                if ($legal_text ne "")
                  {
                    &output ("\n");
                    &output ("<HR>\n");
                    &output ("$legal_text");
                  }

                if ($dedications ne "")
                  {
                    # Pseudo new page.
                    &output ("\n");
                    # Print footnotes.
                    &html_standard_footnotes ();
                    &output ("<HR>\n");
                    &output ("<HR>\n");
                    &output ("$dedications");
                  }
                  
                if ($extra_text_after_dedications ne "")
                  {
                    # Pseudo new page.
                    &output ("\n");
                    # Print footnotes.
                    &html_standard_footnotes ();
                    &output ("<HR>\n");
                    &output ("<HR>\n");
                    &output ("$extra_text_after_dedications");
                  }

                &output ("\n");

                # Main table of contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #
                if ($main_contents)
                  {
                    # The main table of contents is required.
                    &diag_output (sprintf (gettext ("%s:%s: inserting the main contents.\n"),
                                           $program_executable, $original_file_name));

                    # New HTML page now.
                    if ($target eq "HTML-TEXT")
                      {
                        # Nothing to do here; footnotes are
                        # printed at the very last as the counter
                        # cannot be reset befor the end of this
                        # big HTML page.
                        ;
                      }
                    else
                      {
                        # Close the previous HTML page
                        #
                        # &html_standard_page_bottom (ROOT_FILE_NAME,
                        #                             CURRENT_PAGE_NUMBER,
                        #                             MAX_PAGE,
                        #                             HTML_EXT)
                        #
                        &html_standard_page_bottom
                          ($root_file_name,
                           $html_page_counter,
                           $html_max_page,
                           $html_ext);

                        # Close output stream.
                        close ($current_output_stream);

                        # Increment the HTML page counter (global variable)
                        $html_page_counter++;

                        # Set language information to document language.
                        $current_language = $document_language;

                        # Reopen
                        $current_output_stream = $root_file_name
                                                 . $html_page_counter
                                                 . $html_ext;
                        open ($current_output_stream,
                              "> "
                              . $root_file_name
                              . $html_page_counter
                              . $html_ext);

                        # Print top HTML page.
                        #
                        # &html_standard_page_top (ROOT_FILE_NAME,
                        #                          CURRENT_PAGE_NUMBER,
                        #                          MAX_PAGE,
                        #                          HTML_EXT,
                        #                          HTML_LANGUAGE,
                        #                          META_HTTP_EQUIV,
                        #                          META_DESCRIPTION,
                        #                          META_KEYWORDS,
                        #                          META_AUTHOR,
                        #                          META_DATE,
                        #                          TITLE)
                        #
                        &html_standard_page_top ($root_file_name,
                                                 $html_page_counter,
                                                 $html_max_page,
                                                 $html_ext,
                                                 $current_language,
                                                 "text/html",
                                                 $document_description,
                                                 $document_keywords,
                                                 "@authors",
                                                 $date,
                                                 $title);
                      }

                    # Save the page title
                    $last_html_page_title = $contents_title;

                    # Now the table of contents.
                    &output ("\n");
                    &output ("<H1>$contents_title</H1>\n");
                    &output ("\n");
                    &output ("<UL>\n");
                    $last_contents_level = 1;
                    for ($n = 0 ; $n <= $#contents_list ; $n++)
                      { 
                        if ($contents_list[$n][0] == -1)
                          {
                            # Tome
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            &output ("<BIG><STRONG>");
                            &output (ucfirst (&tome_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                            &output ($contents_list[$n][5]);
                            &output ("</STRONG></BIG>");
                            &output ("</A>");
                            &output ("</P>\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 0)
                          {
                            # part
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            &output ("<STRONG>");
                            &output (ucfirst (&part_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                            &output ($contents_list[$n][5]);
                            &output ("</STRONG>");
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 1
                               && ($contents_levels >= 1
                                   || $contents_list[$n][4] =~ m/^[ixu][0-9]/
                                   || $contents_list[$n][4] =~ m/^[A-Z]/))
                          {
                            # chapter
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                              {
                                # This is an appendix.
                                &output (ucfirst (&appendix_def ()));
                                &output (" ");
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            else
                              {
                                # This is a standard chapter.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 2
                               && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("</UL>\n");
                  }
              }
          }
        elsif ($element eq "ADMIN")
          {
            # the ADMIN element is scanned at the very first pass,
            # identical for all backends.
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Discard output.
                &pop_output ();
              }
          }
        elsif ($element eq "TITLE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $title = &pop_output ();
                $last_html_page_title = $title;

              }
          }
        elsif ($element eq "SUBTITLE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $subtitles[$#subtitles+1] = &pop_output ();
              }
          }
        elsif ($element eq "ABSTRACT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $abstract = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$abstract =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "AUTHOR")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $authors[$#authors+1] = &pop_output ();
              }
          }
        elsif ($element eq "DATE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $date = &pop_output ();
              }
          }
        elsif ($element eq "EDITION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $edition = &pop_output ();
              }
          }
        elsif ($element eq "VERSION")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $version = &pop_output ();
              }
          }
        elsif ($element eq "FRONTCOVERPICTURE")
          {
            if ($type eq "start")
              {
                # Save picture information.
                $front_cover_picture_file = ${$attributes}{'IMGFILE'};
                $front_cover_picture_width = ${$attributes}{'WIDTH'};
                $front_cover_picture_height = ${$attributes}{'HEIGHT'};
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "FRONTCOVERTEXT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $front_cover_text = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$front_cover_text =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "TEXTBEFORELEGAL")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $extra_text_before_legal = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$extra_text_before_legal =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "LEGAL")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $legal_text = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$legal_text =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "DEDICATIONS")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $dedications = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$dedications =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "TEXTAFTERDEDICATIONS")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output.
                $extra_text_after_dedications = &pop_output ();

                ## With %block; elements, there is a line feed character
                ## at the top of the string. I don't know why.
                ## Anyway, we have to delete this extra line feed.
                #$extra_text_after_dedications =~ s/^\n?(.*)$/$1/s;
              }
          }
        elsif ($element eq "MAINCONTENTS")
          {
            if ($type eq "start")
              {
                # Activate main table of contents.
                $main_contents = 1;
                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $contents_title = &pop_output ();
              }
          }
        elsif ($element eq "INTRO")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "intro";
              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "BODY")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "body";
              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "APPENDIX")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "appendix";
              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "INDEX")
          {
            if ($type eq "start")
              {
                # Save the information.
                $document_position = "index";
              }
            else
              {
                # Do nothing;
                ;
              }
          }
        elsif ($element eq "NAVLINK")
          {
            if ($type eq "start")
              {
                &push_output ();
              }
            else
              {
                &pop_output ();
              }
          }
        elsif ($element eq "TOMEHEADING")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $tome_heading_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;

                # Here start a tome. Do some preparations.
                # Tome happens only inside a body.
                $current_level = "tome";
                $current_level_by_number = -1;
                $tome++;
		$part_present = 0;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                # part counter doesnt change.
                # chapter counter doesnt change.
                $sect1 = 0;             
                $sect2 = 0;             
                $sect3 = 0;             

                # New HTML page now.
                if ($target eq "HTML-TEXT")
                  {
                    # Nothing to do here; footnotes are
                    # printed at the very last as the counter
                    # cannot be reset befor the end of this
                    # big HTML page.
                    ;
                  }
                else
                  {
                    # Close the previous HTML page
                    #
                    # &html_standard_page_bottom (ROOT_FILE_NAME,
                    #                             CURRENT_PAGE_NUMBER,
                    #                             MAX_PAGE,
                    #                             HTML_EXT)
                    #
                    &html_standard_page_bottom
                      ($root_file_name,
                       $html_page_counter,
                       $html_max_page,
                       $html_ext);

                    # Close output stream.
                    close ($current_output_stream);

                    # Increment the HTML page counter (global variable)
                    $html_page_counter++;

                    # Save and set language information.
                    $current_language = ${$attributes}{'LANG'};
                    if ($current_language eq "")
                      {
                        $current_language = $document_language;
                      }
                    $tome_language = $current_language;
                    $part_language = $current_language;
                    $chapter_language = $current_language;

                    # Reopen
                    $current_output_stream = $root_file_name
                                             . $html_page_counter
                                             . $html_ext;
                    open ($current_output_stream,
                          "> "
                          . $root_file_name
                          . $html_page_counter
                          . $html_ext);

                    # Print top HTML page.
                    #
                    # &html_standard_page_top (ROOT_FILE_NAME,
                    #                          CURRENT_PAGE_NUMBER,
                    #                          MAX_PAGE,
                    #                          HTML_EXT,
                    #                          HTML_LANGUAGE,
                    #                          META_HTTP_EQUIV,
                    #                          META_DESCRIPTION,
                    #                          META_KEYWORDS,
                    #                          META_AUTHOR,
                    #                          META_DATE,
                    #                          TITLE)
                    #
                    &html_standard_page_top ($root_file_name,
                                             $html_page_counter,
                                             $html_max_page,
                                             $html_ext,
                                             $current_language,
                                             "text/html",
                                             $document_description,
                                             $document_keywords,
                                             "@authors",
                                             $date,
                                             $title);
                  }
                
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $tome_heading_title = &pop_output ();
                $last_heading_title = $tome_heading_title;
                $last_html_page_title = $tome_heading_title;

                # Print the tome header.
                &output ("<H1>");
                &output ("<A NAME=\"title$contents_counter\"></A>");
                &output ("<A NAME=\"anchor$cross_reference_counter\"></A>\n");
                &output (ucfirst (&tome_def ()));
                &output (" ");
                &output (&current_section_number ());
                &output (". &nbsp; ");
                &output ("$tome_heading_title");
                &output ("</H1>\n");

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H0")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h0_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;

                # Here start a part. Do some preparations.
                # Tome happens only inside a body.
                $current_level = "part";
                $current_level_by_number = 0;
                $part++;
		$part_present = 1;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                # chapter counter doesnt change.
                $sect1 = 0;             
                $sect2 = 0;             
                $sect3 = 0;             

                # New HTML page now.
                if ($target eq "HTML-TEXT")
                  {
                    # Nothing to do here; footnotes are
                    # printed at the very last as the counter
                    # cannot be reset befor the end of this
                    # big HTML page.
                    ;
                  }
                else
                  {
                    # Close the previous HTML page
                    #
                    # &html_standard_page_bottom (ROOT_FILE_NAME,
                    #                             CURRENT_PAGE_NUMBER,
                    #                             MAX_PAGE,
                    #                             HTML_EXT)
                    #
                    &html_standard_page_bottom
                      ($root_file_name,
                       $html_page_counter,
                       $html_max_page,
                       $html_ext);

                    # Close output stream.
                    close ($current_output_stream);

                    # Increment the HTML page counter (global variable)
                    $html_page_counter++;

                    # Save and set language information.
                    $current_language = ${$attributes}{'LANG'};
                    if ($current_language eq "")
                      {
                        $current_language = $tome_language;
                      }
                    $part_language = $current_language;
                    $chapter_language = $current_language;

                    # Reopen
                    $current_output_stream = $root_file_name
                                             . $html_page_counter
                                             . $html_ext;
                    open ($current_output_stream,
                          "> "
                          . $root_file_name
                          . $html_page_counter
                          . $html_ext);

                    # Print top HTML page.
                    #
                    # &html_standard_page_top (ROOT_FILE_NAME,
                    #                          CURRENT_PAGE_NUMBER,
                    #                          MAX_PAGE,
                    #                          HTML_EXT,
                    #                          HTML_LANGUAGE,
                    #                          META_HTTP_EQUIV,
                    #                          META_DESCRIPTION,
                    #                          META_KEYWORDS,
                    #                          META_AUTHOR,
                    #                          META_DATE,
                    #                          TITLE)
                    #
                    &html_standard_page_top ($root_file_name,
                                             $html_page_counter,
                                             $html_max_page,
                                             $html_ext,
                                             $current_language,
                                             "text/html",
                                             $document_description,
                                             $document_keywords,
                                             "@authors",
                                             $date,
                                             $title);
                  }

                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H0_title = &pop_output ();
                $last_heading_title = $H0_title;
                $last_html_page_title = $H0_title;

                # Print the part header.
                &output ("<H1>");
                &output ("<A NAME=\"title$contents_counter\"></A>");
                &output ("<A NAME=\"anchor$cross_reference_counter\"></A>\n");
                &output (ucfirst (&part_def ()));
                &output (" ");
                &output (&current_section_number ());
                &output (". &nbsp; ");
                &output ("$H0_title");
                &output ("</H1>\n");

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H1"
               || $element eq "SLIDEH1"
               || $element eq "SHEETH1"
               || $element eq "UNNUMBEREDH1")
          {
            if ($type eq "start")
              {
                # New HTML page now.
                if ($target eq "HTML-TEXT")
                  {
                    # Nothing to do here; footnotes are
                    # printed at the very last as the counter
                    # cannot be reset befor the end of this
                    # big HTML page.
                    ;
                  }
                else
                  {
                    # Close the previous HTML page
                    #
                    # &html_standard_page_bottom (ROOT_FILE_NAME,
                    #                             CURRENT_PAGE_NUMBER,
                    #                             MAX_PAGE,
                    #                             HTML_EXT)
                    #
                    &html_standard_page_bottom
                      ($root_file_name,
                       $html_page_counter,
                       $html_max_page,
                       $html_ext);

                    # Close output stream.
                    close ($current_output_stream);

                    # Increment the HTML page counter (global variable)
                    $html_page_counter++;

                    # Save and set language information.
                    $current_language = ${$attributes}{'LANG'};
                    if ($current_language eq "")
                      {
                        $current_language = $part_language;
                      }
                    $chapter_language = $current_language;

                    # Reopen
                    $current_output_stream = $root_file_name
                                             . $html_page_counter
                                             . $html_ext;
                    open ($current_output_stream,
                          "> "
                          . $root_file_name
                          . $html_page_counter
                          . $html_ext);

                    # Print top HTML page.
                    #
                    # &html_standard_page_top (ROOT_FILE_NAME,
                    #                          CURRENT_PAGE_NUMBER,
                    #                          MAX_PAGE,
                    #                          HTML_EXT,
                    #                          HTML_LANGUAGE,
                    #                          META_HTTP_EQUIV,
                    #                          META_DESCRIPTION,
                    #                          META_KEYWORDS,
                    #                          META_AUTHOR,
                    #                          META_DATE,
                    #                          TITLE)
                    #
                    &html_standard_page_top ($root_file_name,
                                             $html_page_counter,
                                             $html_max_page,
                                             $html_ext,
                                             $current_language,
                                             "text/html",
                                             $document_description,
                                             $document_keywords,
                                             "@authors",
                                             $date,
                                             $title);
                  }

                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h1_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                # Here start a chapter. Do some preparations.
                $current_level_by_number = 1;
                # tables and figures are reset.
                $table = 0;
                $figure = 0;
                $listing = 0;
                if ($element eq "UNNUMBEREDH1")
                  {
                    $current_level = "unnumbered-h1";
                    $unnumbered_chapter++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "intro")
                  {
                    $current_level = "intro-h1";
                    $intro++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
                    $current_level = "chapter-h1";
                    $chapter++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;         
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
                    $current_level = "appendix-h1";
                    $appendix++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h1";
                    $index++;
                    $h1section_absolute_counter++;
                    $sect1 = 0;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H1_title = &pop_output ();
                $last_heading_title = $H1_title;
                $last_html_page_title = $H1_title;
                # Print the chapter header.
                if ($element eq "UNNUMBEREDH1")
                  {
                    &output ("<H1>");
                  }
                elsif ($document_position eq "intro")
                  {
                    &output ("<H1>");
                  }
                elsif ($document_position eq "appendix")
                  {
                    &output ("<H1>");
                    &output (ucfirst (&appendix_def ()));
                    &output (" ");
                    &output (&current_section_number ());
                    &output (". &nbsp; ");
                  }
                elsif ($document_position eq "index")
                  {
                    &output ("<H1>");
                  }
                else
                  {
                    &output ("<H1>");
                    &output (ucfirst (&chapter_def ()));
                    &output (" ");
                    &output (&current_section_number ());
                    if ($element eq "SLIDEH1")
                      {
                        &output (", ");
                        &output (lc (&presentation_slide_def ()));
                        &output ("<BR>");
                      }
                    elsif ($element eq "SHEETH1")
                      {
                        &output (", ");
                        &output (lc (&summary_sheet_def ()));
                        &output ("<BR>");
                      }
                    else
                      {
                        &output (". &nbsp; ");
                      }
                  }
                &output ("<A NAME=\"title$contents_counter\"></A>");
                &output ("<A NAME=\"anchor$cross_reference_counter\"></A>");
                &output ("$H1_title");
                &output ("</H1>\n");

                &diag_output (sprintf (gettext ("%s:%s: %s\n"),
                                       $program_executable, $original_file_name,
                                       &current_section_number_complete ()));
              }
          }
        elsif ($element eq "H2"
               || $element eq "FAQH2")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h2_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                # Here start a chapter. Do some preparations.
                $current_level_by_number = 2;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h2";
                    $sect1++;           
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h2";
		      }
		    else
		      {
                	$current_level = "chapter-h2";
		      }
                    $sect1++;           
                    $sect2 = 0;         
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h2";
		      }
		    else
		      {
                	$current_level = "appendix-h2";
		      }
                    $sect1++;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h2";
                    $sect1++;
                    $sect2 = 0;
                    $sect3 = 0;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H2_title = &pop_output ();
                $last_heading_title = $H2_title;
                # Print the section header.
                if ($element eq "FAQH2"
		       && ($current_level eq "unnumbered-h2"
		           || $document_position eq "intro"))
                  {
                    &output ("\n");
                    &output ("<H2>$sect1");
                    &output (" &nbsp; ");
                  }
                elsif ($element eq "FAQH2")
                  {
                    &output ("\n");
                    &output ("<H2>");
                    &output (&current_section_number ());
                    &output (" &nbsp; ");
                  }
                elsif ($document_position eq "intro")
                  {
                    &output ("\n");
                    &output ("<H2>");
                  }
                elsif ($current_level eq "unnumbered-h2")
                  {
                    &output ("\n");
                    &output ("<H2>");
                  }
                elsif ($current_level eq "chapter-h2"
		       || $current_level eq "appendix-h2")
                  {
                    &output ("\n");
                    &output ("<H2>");
                    &output (&current_section_number ());
                    &output (" &nbsp; ");
                  }
                else
                  {
            	    &diag_output (sprintf (gettext ("%s:%s:%s: anomalous current section string: \"%s\" !!!!\n"),
                                           $program_executable,
					   $original_file_name,
					   $element,
					   $current_level));
                    &output ("\n");
                    &output ("<H2>");
                    &output (&current_section_number ());
                    &output (" &nbsp; ");
                  }
                &output ("<A NAME=\"title$contents_counter\"></A>");
                &output ("<A NAME=\"anchor$cross_reference_counter\"></A>\n");
                &output ("$H2_title");
                &output ("</H2>\n");
              }
          }
        elsif ($element eq "H3"
               || $element eq "FAQH3")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h3_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                # Here start a chapter. Do some preparations.
                $current_level_by_number = 3;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h3";
                    $sect2++;           
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "body")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "chapter-h3";
		      }
                    $sect2++;           
                    $sect3 = 0;         
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h3";
		      }
		    else
		      {
                	$current_level = "appendix-h3";
		      }
                    $sect2++;
                    $sect3 = 0;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h3";
                    $sect2++;
                    $sect3 = 0;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H3_title = &pop_output ();
                $last_heading_title = $H3_title;
                # Print the subsection header.
                if ($element eq "FAQH3"
		       && ($current_level eq "unnumbered-h3"
		           || $document_position eq "intro"))
                  {
                    &output ("\n");
                    &output ("<P><STRONG>$sect1.$sect2");
                    &output (")&nbsp;&nbsp;");
                  }
                elsif ($element eq "FAQH3")
                  {
                    &output ("\n");
                    &output ("<P><STRONG>");
                    &output (&current_section_number ());
                    &output (")&nbsp;&nbsp;");
                  }
                elsif ($document_position eq "intro")
                  {
                    &output ("\n");
                    &output ("<H3>");
                  }
                elsif ($current_level eq "unnumbered-h3")
                  {
                    &output ("\n");
                    &output ("<H3>");
                  }
                else
                  {
                    &output ("\n");
                    &output ("<H3>");
                    &output (&current_section_number ());
                    &output (" &nbsp; ");
                  }
                &output ("<A NAME=\"title$contents_counter\"></A>");
                &output ("<A NAME=\"anchor$cross_reference_counter\"></A>\n");
                &output ("$H3_title");
                if ($element eq "FAQH3")
                  {
                    &output ("</STRONG></P>\n");
                  }
                else
                  {
                    &output ("</H3>\n");
                  }
              }
          }
        elsif ($element eq "H4")
          {
            if ($type eq "start")
              {
                # Increment some counters.
                $contents_counter++;
                $cross_reference_counter++;
                # Save anchor information.
                $h4_id = ${$attributes}{'ID'};
                $last_anchor_id = $tome_heading_id;
                # Here start a chapter. Do some preparations.
                $current_level_by_number = 4;
                if ($document_position eq "intro")
                  {
                    $current_level = "intro-h4";
                    $sect3++;           
                  }
                elsif ($document_position eq "body")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h4";
		      }
		    else
		      {
                	$current_level = "chapter-h4";
		      }
                    $sect3++;
                  }
                elsif ($document_position eq "appendix")
                  {
		    # If previous level was unnumbered, remains unnumbered.
		    if ($current_level =~ m/unnumbered-h[1-9]/)
		      {
                	$current_level = "unnumbered-h4";
		      }
		    else
		      {
                	$current_level = "appendix-h4";
		      }
                    $sect3++;
                  }
                elsif ($document_position eq "index")
                  {
                    $current_level = "index-h4";
                    $sect3++;
                  }
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # The header information is recalled and saved.
                # The normal mode for output() function is re-established.
                $H4_title = &pop_output ();
                $last_heading_title = $H4_title;
                # Print the subsubsection header.
                if ($document_position eq "intro")
                  {
                    &output ("\n");
                    &output ("<H4>");
                  }
                elsif ($current_level eq "unnumbered-h4")
                  {
                    &output ("\n");
                    &output ("<H4>");
                  }
                else
                  {
                    &output ("\n");
                    &output ("<H4>");
                    &output (&current_section_number ());
                    &output (" &nbsp; ");
                  }
                &output ("<A NAME=\"title$contents_counter\"></A>");
                &output ("<A NAME=\"anchor$cross_reference_counter\"></A>");
                &output ("$H4_title");
                &output ("</H4>\n");
              }
          }
        elsif ($element eq "EXTRAMAINCONTENTS")
          {
            if ($type eq "start")
              {
                local $contents_levels = ${$attributes}{'LEVELS'};
                local $last_contents_level = 0;

                # Main table of contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # An extra main table of contents is required.
                &diag_output (sprintf (gettext ("%s:%s: inserting an extra main contents of level %s.\n"),
                                       $program_executable, $original_file_name, $contents_levels));

                &output ("\n");
                &output ("<UL>\n");
                $last_contents_level = 1;
                for ($n = 0 ; $n <= $#contents_list ; $n++)
                  { 
                    if ($contents_list[$n][0] == -1)
                      {
                        # Tome
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        &output ("<LI><P>");
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<A HREF=\"#title$n\">");
                          }
                        else
                          {
                            &output ("<A HREF=\"$root_file_name");
                            &output ($contents_list[$n][6]);
                            &output ("$html_ext#title$n\">");
                          }
                        &output ("<BIG><STRONG>");
                        &output (ucfirst (&tome_def ()));
                        &output (" ");
                        &output ($contents_list[$n][4]);
                        &output (" &nbsp; ");
                        &output ($contents_list[$n][5]);
                        &output ("</STRONG></BIG>");
                        &output ("</A>");
                        &output ("</P>\n");
                        $last_contents_level = 1;
                      }
                    elsif ($contents_list[$n][0] == 0
                           && $contents_levels >= 0)
                      {
                        # part
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        &output ("<LI><P>");
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<A HREF=\"#title$n\">");
                          }
                        else
                          {
                            &output ("<A HREF=\"$root_file_name");
                            &output ($contents_list[$n][6]);
                            &output ("$html_ext#title$n\">");
                          }
                        &output ("<STRONG>");
                        &output (ucfirst (&part_def ()));
                        &output (" ");
                        &output ($contents_list[$n][4]);
                        &output (" &nbsp; ");
                        &output ($contents_list[$n][5]);
                        &output ("</STRONG>");
                        &output ("</A>\n");
                        &output ("</P>\n");
                        $last_contents_level = 1;
                      }
                    elsif ($contents_list[$n][0] == 1
                           && $contents_levels >= 1)
                      {
                        # chapter
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 1)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        &output ("<LI><P>");
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<A HREF=\"#title$n\">");
                          }
                        else
                          {
                            &output ("<A HREF=\"$root_file_name");
                            &output ($contents_list[$n][6]);
                            &output ("$html_ext#title$n\">");
                          }
                        if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                          {
                            # This is an introduction, an index or an unnumbered.
                            # So, don't add the number.
                            ;
                          }
                        elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                          {
                            # This is an appendix.
                            &output (ucfirst (&appendix_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                          }
                        else
                          {
                            # This is a standard chapter.
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                          }
                        &output ($contents_list[$n][5]);
                        &output ("</A>\n");
                        &output ("</P>\n");
                        $last_contents_level = 1;
                      }
                    elsif ($contents_list[$n][0] == 2
                           && $contents_levels >= 2)
                      {
                        # section
                        if ($last_contents_level == 1)
                          {
                            # We have to add an indent level.
                            &output ("<UL>\n");
                          }
                        if ($last_contents_level > 2)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        if ($last_contents_level > 2)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        &output ("<LI><P>");
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<A HREF=\"#title$n\">");
                          }
                        else
                          {
                            &output ("<A HREF=\"$root_file_name");
                            &output ($contents_list[$n][6]);
                            &output ("$html_ext#title$n\">");
                          }
                        if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                          {
                            # This is an introduction, an index or an unnumbered.
                            # So, don't add the number.
                            ;
                          }
                        else
                          {
                            # This is a standard section.
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                          }
                        &output ($contents_list[$n][5]);
                        &output ("</A>\n");
                        &output ("</P>\n");
                        $last_contents_level = 2;
                      }
                    elsif ($contents_list[$n][0] == 3
                           && $contents_levels >= 3)
                      {
                        # subsection
                        if ($last_contents_level == 2)
                          {
                            # We have to add an indent level.
                            &output ("<UL>\n");
                          }
                        if ($last_contents_level > 3)
                          {
                            # We have to subtract an indent level.
                            &output ("</UL>\n");
                            $last_contents_level--;
                          }
                        &output ("<LI><P>");
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<A HREF=\"#title$n\">");
                          }
                        else
                          {
                            &output ("<A HREF=\"$root_file_name");
                            &output ($contents_list[$n][6]);
                            &output ("$html_ext#title$n\">");
                          }
                        &output ($contents_list[$n][4]);
                        &output (" &nbsp; ");
                        &output ($contents_list[$n][5]);
                        &output ("</A>\n");
                        &output ("</P>\n");
                        $last_contents_level = 3;
                      }
                    elsif ($contents_list[$n][0] == 4
                           && $contents_levels >= 4)
                      {
                        # sub-subsection
                        if ($last_contents_level == 3)
                          {
                            # We have to add an indent level.
                            &output ("<UL>\n");
                          }
                        &output ("<LI><P>");
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<A HREF=\"#title$n\">");
                          }
                        else
                          {
                            &output ("<A HREF=\"$root_file_name");
                            &output ($contents_list[$n][6]);
                            &output ("$html_ext#title$n\">");
                          }
                        if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                          {
                            # This is an introduction, an index or an unnumbered.
                            # So, don't add the number.
                            ;
                          }
                        else
                          {
                            # This is a standard section.
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                          }
                        &output ($contents_list[$n][5]);
                        &output ("</A>\n");
                        &output ("</P>\n");
                        $last_contents_level = 4;
                      }
                  }
                # Close levels.
                if ($last_contents_level > 1)
                  {
                    # We have to subtract an indent level.
                    &output ("</UL>\n");
                    $last_contents_level--;
                  }
                if ($last_contents_level > 1)
                  {
                    # We have to subtract an indent level.
                    &output ("</UL>\n");
                    $last_contents_level--;
                  }
                if ($last_contents_level > 1)
                  {
                    # We have to subtract an indent level.
                    &output ("</UL>\n");
                    $last_contents_level--;
                  }
                # Close the very last level.
                &output ("</UL>\n");
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "TOMECONTENTS")
          {
            if ($type eq "start")
              {
                &diag_output (sprintf (gettext ("%s:%s: inserting a tome contents.\n"),
                                       $program_executable, $original_file_name));

                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};

                # Insert a tome contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # Scan the @contents_list to find the right tome.
                for ($n = 0 ;
                     $n <= $#contents_list && $contents_list[$n][1] < $tome ;
                     $n++)
                  { 
                    # Do nothing; just jump it.
                    ;
                  }

                # Now $n is on the first tome entry, or after the end of
                # the array.
                if($n > $#contents_list)
                  {
                    # The array is finisced, and there is no tome.
                    ;
                  }
                elsif ($contents_list[$n][1] == $tome)
                  {
                    # OK, just jump this entry, that is obvious.
                    $n++;

                    &output ("\n");
                    &output ("<UL>\n");
                    $last_contents_level = 1;
                    for ($n = $n ;
                         $n <= $#contents_list && $contents_list[$n][1] == $tome;
                         $n++)
                      { 
                        if ($contents_list[$n][0] == 0)
                          {
                            # part
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            &output (ucfirst (&part_def ()));
                            &output (" ");
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 1)
                          {
                            # chapter
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                              {
                                # This is an appendix.
                                &output (ucfirst (&appendix_def ()));
                                &output (" ");
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            else
                              {
                                # This is a standard chapter.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 2
                               && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("</UL>\n");
                  }
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "PARTCONTENTS")
          {
            if ($type eq "start")
              {
                &diag_output (sprintf (gettext ("%s:%s: inserting a part contents.\n"),
                                       $program_executable, $original_file_name));

                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};

                # Insert a part contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # Scan the @contents_list to find the right tome.
                for ($n = 0 ;
                     $n <= $#contents_list && $contents_list[$n][2] < $part ;
                     $n++)
                  { 
                    # Do nothing; just jump it.
                    ;
                  }
                # Now $n is on the first part entry, or after the end of
                # the array.
                if($n > $#contents_list)
                  {
                    # The array is finished, and there is no part.
                    ;
                  }
                elsif ($contents_list[$n][2] == $part)
                  {
                    # OK, just jump this entry, that is obvious.
                    $n++;

                    &output ("\n");
                    &output ("<UL>\n");
                    $last_contents_level = 1;
                    for ($n = $n ;
                         $n <= $#contents_list && $contents_list[$n][2] == $part;
                         $n++)
                      { 
                        if ($contents_list[$n][0] == 1)
                          {
                            # chapter
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 1)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            elsif ($contents_list[$n][4] =~ m/^[A-Z]/)
                              {
                                # This is an appendix.
                                &output (ucfirst (&appendix_def ()));
                                &output (" ");
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            else
                              {
                                # This is a standard chapter.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 1;
                          }
                        elsif ($contents_list[$n][0] == 2
                               && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 1)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("</UL>\n");
                  }
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "CHAPTERCONTENTS")
          {
            if ($type eq "start")
              {
                &diag_output (sprintf (gettext ("%s:%s: inserting a chapter contents.\n"),
                                       $program_executable, $original_file_name));

                # Save how many levels are required.
                $contents_levels = ${$attributes}{'LEVELS'};

                # Insert a part contents.
                #
                # $contents_list[x][0]  level                   -1..4
                # $contents_list[x][1]  tome number
                # $contents_list[x][2]  part number
                # $contents_list[x][3]  chapter number          
                # $contents_list[x][4]  level-description       1.2.3
                # $contents_list[x][5]  title
                # $contents_list[x][6]  html page number
                # $contents_list[x][7]  h1 section absolute counter
                #

                # Scan the @contents_list to find the right chapter.
                for ($n = 0 ;
                     $n <= $#contents_list && $contents_list[$n][7] < $h1section_absolute_counter ;
                     $n++)
                  { 
                    # Do nothing; just jump it.
                    ;
                  }

                # Now $n is on the first chapter entry, or after the end of
                # the array.
                if($n > $#contents_list)
                  {
                    # The array is finished, and there is no part.
                    ;
                  }
                elsif ($contents_list[$n][7] == $h1section_absolute_counter)
                  {
                    # OK, just jump this entry, that is obvious.
                    $n++;

                    &output ("\n");
                    &output ("<UL>\n");
                    $last_contents_level = 2;
                    for ($n = $n ;
                         $n <= $#contents_list && $contents_list[$n][7] == $h1section_absolute_counter ;
                         $n++)
                      { 
                        if ($contents_list[$n][0] == 2
                               && $contents_levels >= 2)
                          {
                            # section
                            if ($last_contents_level == 1)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            if ($last_contents_level > 2)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 2;
                          }
                        elsif ($contents_list[$n][0] == 3
                               && $contents_levels >= 3)
                          {
                            # subsection
                            if ($last_contents_level == 2)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            if ($last_contents_level > 3)
                              {
                                # We have to subtract an indent level.
                                &output ("</UL>\n");
                                $last_contents_level--;
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            &output ($contents_list[$n][4]);
                            &output (" &nbsp; ");
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 3;
                          }
                        elsif ($contents_list[$n][0] == 4
                               && $contents_levels >= 4)
                          {
                            # sub-subsection
                            if ($last_contents_level == 3)
                              {
                                # We have to add an indent level.
                                &output ("<UL>\n");
                              }
                            &output ("<LI><P>");
                            if ($target eq "HTML-TEXT")
                              {
                                &output ("<A HREF=\"#title$n\">");
                              }
                            else
                              {
                                &output ("<A HREF=\"$root_file_name");
                                &output ($contents_list[$n][6]);
                                &output ("$html_ext#title$n\">");
                              }
                            if ($contents_list[$n][4] =~ m/^[ixu][0-9]/)
                              {
                                # This is an introduction, an index or an unnumbered.
                                # So, don't add the number.
                                ;
                              }
                            else
                              {
                                # This is a standard section.
                                &output ($contents_list[$n][4]);
                                &output (" &nbsp; ");
                              }
                            &output ($contents_list[$n][5]);
                            &output ("</A>\n");
                            &output ("</P>\n");
                            $last_contents_level = 4;
                          }
                      }
                    # Close levels.
                    if ($last_contents_level > 2)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 2)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    if ($last_contents_level > 2)
                      {
                        # We have to subtract an indent level.
                        &output ("</UL>\n");
                        $last_contents_level--;
                      }
                    # Close the very last level.
                    &output ("</UL>\n");
                  }
              }
            else
              {
                # Do nothing.
                ;
              }
          }
        elsif ($element eq "INDEXENTRY")
          {
            if ($type eq "start")
              {
		# Save index attributes.
                $index_name = ${$attributes}{'INDEX'};
                $index_emph = lc ${$attributes}{'EMPH'};

                # increment the index entry counter.
                $index_entry_counter++;
                
                # Insert an index anchor.
                &output ("<A NAME=\"index$index_entry_counter\"></A>");

                # Eliminate the index entry.
                &push_output ()
              }
            else
              {
                # Eliminate the index entry.
                &pop_output ()
              }
          }
        elsif ($element eq "PRINTINDEX")
          {
            if ($type eq "start")
              {
                local ($n) = 0;
                local ($m) = 0;
                local ($idxname) = "";
                local ($idxtype) = "";
                local ($idxcontext) = "";
                local ($index_file) = "";
                local ($output_stream);
                local ($input_stream);
                local ($line);

                # Save the index type name.
                $idxname = ${$attributes}{'INDEX'};
                $idxtype = lc (${$attributes}{'INDEXREF'});
                $idxcontext = lc (${$attributes}{'INDEXCONTEXT'});

                # Sort only the elements for the actual index name.
		# Now it is done at the beguinning, with ALML start
		# tag.
                #&sort_index_list ($idxname, 0, $#index_list);

                # Scan the index array.
                #
                # $index_list[x][0]        index name
                # $index_list[x][1]        emphasis
                # $index_list[x][2]        entry
                # $index_list[x][3]        array of links
                # $index_list[x][4]        array of html page numbers
                # $index_list[x][5]        array of level-descriptions
        	# $index_list[x][6]        entry with formatting
		# $index_list[x][7]        array of tomes
	        # $index_list[x][8]        array of parts
	        # $index_list[x][9]        array of chapters (absolute)
                #
                &output ("\n");
                &output ("<UL>\n");

                #for ($n = 0;
                #     $n <= $#index_list;
                #     $n++)
		#  {
		#    &diag_output (sprintf (gettext ("%s:%s: index %s == %s\n"),
                #                           $program_executable, $original_file_name,
                #                           $n, $index_list[$n][2]));
 		#  }

                for ($n = 0;
                     $n <= $#index_list;
                     $n++)
                  {
                    if ($index_list[$n][0] eq $idxname
		        && &valid_section_index_entry
			     ($n, $idxcontext, $tome, $part, $h1section_absolute_counter))
                      {

                        # Write the index record.
                        if ($index_list[$n][1] eq "code")
                          {
                            &output
                              ("<LI><P><CODE>$index_list[$n][6]</CODE>");
                          }
                        else
                          {
                            &output
                              ("<LI><P>$index_list[$n][6]");
                          }
                        # Scan the links.
                        for ($m = 0;
                             $m <= $#{$index_list[$n][3]};
                             $m++)
                          {
			    # Check if this link is ok for the context
			    if ($idxcontext eq "tome"
			        && $index_list[$n][7][$m] != $tome)
			      {
				# This link is not related to the tome.
				next;
			      }
			    elsif ($idxcontext eq "part"
			        && $index_list[$n][8][$m] != $part)
			      {
				# This link is not related to the part.
				next;
			      }
			    elsif ($idxcontext eq "chapter"
			        && $index_list[$n][9][$m] != $h1section_absolute_counter)
			      {
				# This link is not related to the chapter.
				next;
			      }

			    # Otherwise it is ok. :-)				  

                            if ($target eq "HTML-TEXT")
                              {
                                &output
                                  (", <A HREF=\"#index"
                                   . $index_list[$n][3][$m]
                                   . "\">"
                                   . $index_list[$n][5][$m]
                                   . "</A>");
                              }
                            else
                              {
                                &output
                                  (", <A HREF=\"$root_file_name"
                                   . $index_list[$n][4][$m]
                                   . $html_ext
                                   . "#index"
                                   . $index_list[$n][3][$m]
                                   . "\">"
                                   . $index_list[$n][5][$m]
                                   . "</A>");
                              }
                          }
                        &output ("</P></LI>\n");
                      }
		    else
		      {
			#&diag_output (sprintf (gettext ("%s:%s: index %s == %s\n"),
                        #                   $program_executable, $original_file_name,
                        #                   $index_list[$n][0], $index_list[$n][6]));

			# Nothing to do here.
			;
		      }
                  }
                &output ("</UL>\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "ANCHOR")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};

                # Use the counter to know the right number
                # inside the array.
                $cross_reference_counter++;
                # Print the reference anchor.
                &output ("<A NAME=\"anchor$cross_reference_counter\"></A>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "TABLE")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                local ($pos) = "";
                # Save attributes.
                $id = ${$attributes}{'ID'};
                $pos = lc ${$attributes}{'POS'};
                $table_position = $pos;

                # Increment some counters.
                $table++;
                $absolute_table++;
                $cross_reference_counter++;
                $table_columns_width_counter = $absolute_table -1;

                # Save table id.
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "table" . $absolute_table;
                  }
                $last_table_id = $id;

                # Reset table caption.
                $table_caption = "";

		#-------------------------------------------------------
                # Print the table anchor.
		#-------------------------------------------------------
                &output ("\n");
                &output ("<P ID=\"anchor$cross_reference_counter\"><!--\n");
		&output ("    This is just an anchor for the next table.\n");
		&output ("--></P>\n");
                ####&output ("<TABLE ID=\"anchor$cross_reference_counter\" BORDER=\"3\">\n");
              }
            else
              {
		#-------------------------------------------------------
                # The caption is outside the table, although it is not
		# so nice, but there might be table not made of
		# columns and elements.
		#-------------------------------------------------------

                # Print the table border.
                ##########&output ("</TABLE>\n");

                # Caption.
                if ($table_caption ne "")
                  {
                    &output ("\n");
                    &output ("<P><EM>$table_caption</EM></P>\n");
                  }

              }
          }
        elsif ($element eq "TCAPTION")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $table_caption = &pop_output ();
              }
          }
        elsif ($element eq "TABULAR")
          {
            if ($type eq "start")
              {
                local ($col) = "";
                local ($columnfractions) = "";
	        local (@columnfractions_list) = ();
                local ($n) = "";

                # Save attributes.
                $col = ${$attributes}{'COL'};
                $columnfractions = ${$attributes}{'COLUMNFRACTIONS'};

		# Analyze column fractions.
		if ($columnfractions eq "")
		  {
		    # Default columns width.
		    for ($n = 0; $n <= $col; $n++)
		      {
		        $columnfractions_list[$n] = 0;
		      }
		  }
		else
		  {
		    # Take the column fractions from the string.
		    $n = 0;
		    while ($columnfractions =~ m/^\s*([0-9.,]+)\s*(.*)$/)
		      {
		        $columnfractions_list[$n] = $1;
			$columnfractions = $2;
			
			# Replace comma with point.
		        $columnfractions_list[$n] =~ s/,/./g;

			$n++;
		      }
		  }

		#-------------------------------------------------------
		# Start only here the true table definition.
		# The anchor was already defined before.
		#-------------------------------------------------------
                &output ("<TABLE BORDER=\"3\">\n");

		#-------------------------------------------------------
		# Although specified inside the standard
		# HTML DTD, it is not recognised from
		# common browsers; so it is placed
		# commented inside the HTML source.
		#-------------------------------------------------------

		# Use a colgroup to describe column width.
            	&output ("\n");
            	&output ("<!--<COLGROUP>");
            	$n = 0;
            	while ($col > 0)
                  {
		    if ($columnfractions_list[$n] == 0)
		      {
            	        &output ("<COL>");
		      }
		    else
		      {
            	        &output ("<COL width=\"");
            	        &output ($columnfractions_list[$n]);
            	        &output ("*\">");
		      }
                    $col--;
                    $n++;
	          }
            	&output ("</COLGROUP>-->\n");
              }
            else
              {
		#-------------------------------------------------------
                # Close the table. The caption is outside the table,
		# but it must be remembered that there might be also
		# strange kind of tables.
		#-------------------------------------------------------
                &output ("</TABLE>\n");
              }
          }
        elsif ($element eq "THEAD")
          {
            if ($type eq "start")
              {
                #if ($target eq "HTML-TEXT")
                #  {
                #    # Nothing to do.
                #    ;
                #  }
                #else
                #  {
                    &output ("\n");
                    &output ("<THEAD>\n");
                #  }
              }
            else
              {
                #if ($target eq "HTML-TEXT")
                #  {
                #    # A new line to separate the header from the body.
                #    &output ("\n");
                #  }
                #else
                #  {
                    &output ("</THEAD>\n");
                #  }
              }
          }
        elsif ($element eq "TBODY")
          {
            if ($type eq "start")
              {
                #if ($target eq "HTML-TEXT")
                #  {
                #     # Nothing to do.
                #    ;
                #  }
                #else
                #  {
                    &output ("\n");
                    &output ("<TBODY>\n");
                #  }
              }
            else
              {
                #if ($target eq "HTML-TEXT")
                #  {
                #    # Nothing to do.
                #    ;
                #  }
                #else
                #  {
                    &output ("</TBODY>\n");
                #  }
              }
          }
        elsif ($element eq "TROW")
          {
            if ($type eq "start")
              {
                $table_column_counter = -1; # Before the first element

                #if ($target eq "HTML-TEXT")
                #  {
                #    # Nothing to do.
                #    ;
                #  }
                #else
                #  {
                    &output ("<TR><TD>");
                #  }
                push_output ();
              }
            else
              {
                local ($cell) = "";
                $cell = pop_output ();
                $table_column_counter++; # Next element
                #if ($target eq "HTML-TEXT")
                #  {
                #    $cell = &html_table_cell_string
                #              ($cell,
                #               $table_columns_width[$table_columns_width_counter][$table_column_counter]);
                #    &output ("$cell\n");
                #  }
                #else
                #  {
                    &output ("$cell</TD></TR>\n");
                #  }
              }
          }
        elsif ($element eq "COLSEP")
          {
            if ($type eq "start")
              {
                local ($cell) = "";
                $cell = pop_output ();
                $table_column_counter++; # Next element
                #if ($target eq "HTML-TEXT")
                #  {
                #    $cell = &html_table_cell_string
                #              ($cell,
                #               $table_columns_width[$table_columns_width_counter][$table_column_counter]);
                #    &output ("$cell");
                #  }
                #else
                #  {
                    &output ("$cell</TD><TD>");
                #  }
                push_output ();
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "FIGURE")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                local ($pos) = "";
                local ($sep) = "";
                # Save attributes.
                $id = ${$attributes}{'ID'};
                $pos = lc ${$attributes}{'POS'};
                $sep = lc ${$attributes}{'SEP'};
                $figure_position = $pos;
                $figure_separation = $sep;

                # Increment some counters.
                $figure++;
                $absolute_figure++;
                $cross_reference_counter++;

                # Save table id.
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "figure" . $absolute_figure;
                  }
                $last_figure_id = $id;

                # Reset table caption.
                $figure_caption = "";

                # Put it inside an invisible table with anchor.
                &output ("\n");
                &output ("<TABLE ID=\"anchor$cross_reference_counter\"");
                if ($figure_separation eq "box"
		    || $figure_separation eq "border")
                  {
                    &output ("BORDER=\"1\"");
                  }
		else
                  {
                    &output ("BORDER=\"0\"");
                  }
                &output ("WIDTH=\"100%\">\n");
                &output ("<TR><TD>\n");

                # Print rule border
                if ($figure_separation eq "rule")
                  {
                    &output ("<HR>\n");
                  }
              }
            else
              {

                # Print rule border
                if ($figure_separation eq "rule")
                  {
                    &output ("<HR>\n");
                  }

                # Caption.
                if ($figure_caption ne "")
                  {
                    &output ("\n");
                    &output ("<P class=\"caption\">$figure_caption</P>\n");
                  }

                # Close the invisible table area.
                &output ("\n");
                &output ("</TD></TR>\n");
                &output ("</TABLE>\n");

              }
          }
        elsif ($element eq "FCAPTION")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $figure_caption = &pop_output ();
              }
          }
        elsif ($element eq "LISTING")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                local ($pos) = "";
                local ($sep) = "";
                # Save attributes.
                $id = ${$attributes}{'ID'};
                $pos = lc ${$attributes}{'POS'};
                $sep = lc ${$attributes}{'SEP'};
                $listing_position = $pos;
                $listing_separation = $sep;

                # Increment some counters.
                $listing++;
                $absolute_listing++;
                $cross_reference_counter++;

                # Save table id.
                if ($id eq "")
                  {
                    # Define a unique label.
                    $id = "listing" . $absolute_listing;
                  }
                $last_listing_id = $id;

                # Reset table caption.
                $listing_caption = "";

                # Put it inside an invisible table with anchor.
                &output ("\n");
                &output ("<TABLE ID=\"anchor$cross_reference_counter\"");
                if ($figure_separation eq "box"
		    || $figure_separation eq "border")
                  {
                    &output ("BORDER=\"1\"");
                  }
		else
                  {
                    &output ("BORDER=\"0\"");
                  }
                &output ("WIDTH=\"100%\">\n");
                &output ("<TR><TD>\n");

                # Print rule border
                if ($listing_separation eq "rule")
                  {
                    &output ("<HR>\n");
                  }
              }
            else
              {
                # Print rule border
                if ($listing_separation eq "rule")
                  {
                    &output ("<HR>\n");
                  }

                # Caption.
                if ($listing_caption ne "")
                  {
                    &output ("\n");
                    &output ("<P class=\"caption\">$listing_caption</P>\n");
                  }

                # Close the invisible table area.
                &output ("\n");
                &output ("</TD></TR>\n");
                &output ("</TABLE>\n");

              }
          }
        elsif ($element eq "LCAPTION")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                # Recall output.
                $listing_caption = &pop_output ();
              }
          }
        elsif ($element eq "IMAGE")
          {
            if ($type eq "start")
              {
                local ($imgfile) = "";
                local ($width) = "";
                local ($heght) = "";
                # Save picture information.
                $imgfile = ${$attributes}{'IMGFILE'};
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                # Print picture file.
                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {
                    $html_picture_counter++;

                    # Convert picture geometry
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -geometry ${width}x$height! $imgfile.png $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -geometry ${width} $imgfile.png $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -geometry x${height} $imgfile.png $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
                        system ("convert -geometry 200% $imgfile.png $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "$imgfile.png",
                                           "$html_picture_counter.jpg"));
                    &output ("\n");
                    &output ("<P>");
                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$imgfile\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$imgfile\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$imgfile\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$imgfile\">");
                      }
                    &output ("</P>\n");
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "EMBIMAGE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($img_code) = "";
                local ($img_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                if ($alt eq "")
                  {
                    $alt = &picture_def ();
                  }

                # Restore the base64 code.
                $img_code = $img_code . &pop_output ();

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {

                    # Prepare the temporary file.
                    $img_temp_file = &temporary_file ($temporary_file_name_prefix);
                    # Save the empty temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}";

                    open (IMG_TEMP_FILE, "> ${img_temp_file}.uuencode ");
                    print IMG_TEMP_FILE ("begin-base64 664 dummy\n");
                    print IMG_TEMP_FILE ($img_code);
                    print IMG_TEMP_FILE ("\n");
                    print IMG_TEMP_FILE ("====\n");
                    close (IMG_TEMP_FILE);

                    # Get the picture with uudecode.
                    system ("uudecode -o ${img_temp_file}.uudecode ${img_temp_file}.uuencode");

                    # New HTML picture
                    $html_picture_counter++;

                    # Convert picture geometry
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -geometry ${width}x$height! ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -geometry ${width} ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -geometry x${height} ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
                        system ("convert -geometry 200% ${img_temp_file}.uudecode $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "${img_temp_file}.uudecode",
                                           "$html_picture_counter.jpg"));

                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uudecode";
                    $temp_files_list = $temp_files_list
                                       . " ${img_temp_file}.uuencode";

                    &output ("\n");
                    &output ("<P>");
                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                      }
                    &output ("\n");
                    &output ("</P>");
                  }
              }
          }
        elsif ($element eq "EPSIMAGE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($eps_code) = "";
                local ($eps_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                if ($alt eq "")
                  {
                    $alt = &picture_def ();
                  }

                # Restore the EPS back-end code.
                $eps_code = $eps_code . &pop_output ();

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {
                    # Prepare the EPS temporary file.
                    $eps_temp_file = &temporary_file ($temporary_file_name_prefix);
                    # Save the empty temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${eps_temp_file}";

                    open (EPS_TEMP_FILE, "> ${eps_temp_file}.eps ");
                    print EPS_TEMP_FILE ($eps_code);
                    print EPS_TEMP_FILE ("\n");
                    close (EPS_TEMP_FILE);

                    # New HTML picture
                    $html_picture_counter++;

                    # Convert picture geometry
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width}x$height! ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width} ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -density 300x300 -geometry x${height} ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
			# It is obtained with the -density option.
			# The 140x140 gives the double of the original
			# dimension.
                        system ("convert -density 140x140 ${eps_temp_file}.eps $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "${eps_temp_file}.eps",
                                           "$html_picture_counter.jpg"));

                    # Save the temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${eps_temp_file}.eps";

                    &output ("\n");
                    &output ("<P>");
                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                      }
                    &output ("\n");
                    &output ("</P>");
                  }
              }
          }
        elsif ($element eq "TEXIMAGE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($tex_code) = "";
                local ($tex_temp_file) = "";
                local ($height) = "";
                local ($width) = "";
                local ($alt) = "";
                $width = ${$attributes}{'WIDTH'};
                $height = ${$attributes}{'HEIGHT'};
                $alt = ${$attributes}{'ALT'};

                if ($alt eq "")
                  {
                    $alt = &picture_def ();
                  }

                # Restore the TeX back-end code.
                $tex_code = $tex_code . &pop_output ();

                # Convert to pixel somehow.
                $width = &convert_to_pixel ($width);
                $height = &convert_to_pixel ($height);

                if ($target eq "HTML-TEXT")
                  {
                    # No pictures here. Nothing to do.
                    ;
                  }
                else
                  {
                    # Prepare the TeX temporary file.
                    $tex_temp_file = &temporary_file ($temporary_file_name_prefix);
                    # Save the empty temporary file name inside the list.
                    $temp_files_list = $temp_files_list
                                       . " ${tex_temp_file}";

                    open (TEX_TEMP_FILE, "> ${tex_temp_file}.tex");
	            print TEX_TEMP_FILE ("\\nonstopmode\n");
    	    	    print TEX_TEMP_FILE ("\\nopagenumbers\n");
            	    print TEX_TEMP_FILE ($tex_code);
            	    print TEX_TEMP_FILE ("\n");
            	    print TEX_TEMP_FILE ("\\bye\n");
            	    close (TEX_TEMP_FILE);

            	    # Typeset.
		    # Consider that tex can accept a file name with path,
		    # but will generate a file DVI on current directory.
		    # That's why I am doing this cd and basename.
            	    system ("cd " . &temporary_dir () . " ; tex `basename ${tex_temp_file}.tex`");
            	    system ("dvips -E -o ${tex_temp_file}.ps ${tex_temp_file}.dvi");

            	    # Save the temporary file name inside the list.
            	    $temp_files_list = $temp_files_list
                	               . " ${tex_temp_file}.dvi"
			    	       . " ${tex_temp_file}.tex"
                        	       . " ${tex_temp_file}.ps";

                    # New HTML picture
                    $html_picture_counter++;

                    # Convert picture geometry.
		    # Must tell the first scene number as [0] after the file name.
                    if ($width > 0 && $height > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width}x$height! ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    elsif ($width > 0)
                      {
                        system ("convert -density 300x300 -geometry ${width} ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    elsif ($height > 0)
                      {
                        system ("convert -density 300x300 -geometry x${height} ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    else
                      {
		        # Default dimension is x2 as it happens with the
			# &convert_to_pixel () function.
			# It is obtained with the -density option.
			# The 140x140 gives the double of the original
			# dimension.
                        system ("convert -density 140x140 ${tex_temp_file}.ps[0] $html_picture_counter.jpg");
                      }
                    &diag_output (sprintf (gettext ("%s:%s: picture %s converted to %s\n"),
                                           $program_executable,
                                           $original_file_name,
                                           "${tex_temp_file}.ps",
                                           "$html_picture_counter.jpg"));

                    &output ("\n");
                    &output ("<P>");
                    if ($width > 0 && $height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\" WIDTH=\"$width\" >");
                      }
                    elsif ($width > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" WIDTH=\"$width\" >");
                      }
                    elsif ($height > 0)
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\" HEIGHT=\"$height\">");
                      }
                    else
                      {
                        &output ("<IMG SRC=\"$html_picture_counter.jpg\" ALT=\"$alt\">");
                      }
                    &output ("\n");
                    &output ("</P>");
                  }
              }
          }
        elsif ($element eq "SECTIONREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number             
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    if ($target eq "HTML-TEXT")
                      {
                        # The reference was found at $n-th position.
                        &output ("<A HREF=\"#anchor$n\">");
                        &output ($cross_reference_list[$n][6]);
                        &output ("</A>");
                      }
                    else
                      {
                        # The reference was found at $n-th position.
                        &output ("<A HREF=\"");
                        &output ($root_file_name);
                        &output ($cross_reference_list[$n][11]);
                        &output ($html_ext);
                        &output ("#anchor$n");
                        &output ("\">");
                        &output ($cross_reference_list[$n][6]);
                        &output ("</A>");
                      }
                  }
                else
                  {
                    # There is no reference.
                    &output ("##$id##");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "TABLEREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Replace with last.
                    $id = $last_table_id;
                  }

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number             
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    if ($target eq "HTML-TEXT")
                      {
                        # The reference was found at $n-th position.
                        &output ("<A HREF=\"#anchor$n\">");
                        &output ($cross_reference_list[$n][8]);
                        &output ("</A>");
                      }
                    else
                      {
                        # The reference was found at $n-th position.
                        &output ("<A HREF=\"");
                        &output ($root_file_name);
                        &output ($cross_reference_list[$n][11]);
                        &output ($html_ext);
                        &output ("#anchor$n");
                        &output ("\">");
                        &output ($cross_reference_list[$n][8]);
                        &output ("</A>");
                      }
                  }
                else
                  {
                    # There is no reference.
                    &output ("##$id##");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "FIGUREREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Replace with last.
                    $id = $last_figure_id;
                  }

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    if ($target eq "HTML-TEXT")
                      {
                        # The reference was found.
                        &output ("<A HREF=\"#anchor$n\">");
                        &output ($cross_reference_list[$n][9]);
                        &output ("</A>");
                      }
                    else
                      {
                        # The reference was found.
                        &output ("<A HREF=\"");
                        &output ($root_file_name);
                        &output ($cross_reference_list[$n][11]);
                        &output ($html_ext);
                        &output ("#anchor$n");
                        &output ("\">");
                        &output ($cross_reference_list[$n][9]);
                        &output ("</A>");
                      }
                  }
                else
                  {
                    # There is no reference.
                    &output ("##$id##");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "LISTINGREF")
          {
            if ($type eq "start")
              {
                local ($id) = "";
                $id = ${$attributes}{'ID'};
                if ($id eq "")
                  {
                    # Replace with last.
                    $id = $last_listing_id;
                  }

                # Find the anchor inside the array
                #
                # $cross_reference_list[x][0]        level                      -1..4
                # $cross_reference_list[x][1]        tome number
                # $cross_reference_list[x][2]        part number
                # $cross_reference_list[x][3]        chapter number             
                # $cross_reference_list[x][4]        table absolute number              
                # $cross_reference_list[x][5]        figure absolute number             
                # $cross_reference_list[x][6]        level-description  1.2.3
                # $cross_reference_list[x][7]        title
                # $cross_reference_list[x][8]        table level-description
                # $cross_reference_list[x][9]        figure level-description
                # $cross_reference_list[x][10]       original anchor id
                # $cross_reference_list[x][11]       html page number
                # $cross_reference_list[x][12]       listing absolute number
		# $cross_reference_list[x][13]       listing level-description
                #
                for ($n = 0;
                     $n <= $#cross_reference_list
                       && $cross_reference_list[$n][10] ne $id;
                     $n++)
                  {
                    # Do nothing, just scan.
                    ;
                  }
                if ($n <= $#cross_reference_list)
                  {
                    if ($target eq "HTML-TEXT")
                      {
                        # The reference was found.
                        &output ("<A HREF=\"#anchor$n\">");
                        &output ($cross_reference_list[$n][13]);
                        &output ("</A>");
                      }
                    else
                      {
                        # The reference was found.
                        &output ("<A HREF=\"");
                        &output ($root_file_name);
                        &output ($cross_reference_list[$n][11]);
                        &output ($html_ext);
                        &output ("#anchor$n");
                        &output ("\">");
                        &output ($cross_reference_list[$n][13]);
                        &output ("</A>");
                      }
                  }
                else
                  {
                    # There is no reference.
                    &output ("##$id##");

                    &diag_output (sprintf (gettext ("%s:%s: broken link to %s !!!!\n"),
                                           $program_executable, $original_file_name, $id));
                  }
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SPECIAL")
          {
            if ($type eq "start")
              {
                # Increment the index entry counter.
                $index_entry_counter++;
                # Typeset properly.
                # Notice that it is better to let it empty, because
                # we want avoid recursive A element, wich are not
                # allowed.
                &output ("<A NAME=\"index$index_entry_counter\"></A>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "DFN")
          {
            if ($type eq "start")
              {
#                # Increment the index entry counter.
#                $index_entry_counter++;
                # Typeset properly.
                &output ("<STRONG><EM>");
                # Notice that it is better to let the A element empty,
                # because we want avoid recursive A element, wich are
                # not allowed.
#                &output ("<A NAME=\"index$index_entry_counter\"></A>");
              }
            else
              {
                &output ("</EM></STRONG>");
              }
          }
        elsif ($element eq "WORKINFO")
          {
            if ($type eq "start")
              {
                # Reset global variables.
                $workinfo_name         = "";
                $workinfo_license      = "";
                $workinfo_license_text = "";
                $workinfo_notes        = "";
              }
            else
              {
                local ($n) = 0;

                # Prepare a new element inside the footnote array.
                $#html_footnote_list++;
                $n = $#html_footnote_list +1;

                # Insert the footnote link.
                &output ("<SUP><A HREF=\"#footnote$n\" NAME=\"footnote-ref$n\">($n)</A></SUP>");

                # Insert the footnote inside the array.
                $html_footnote_list[$#html_footnote_list]
                  = "<STRONG>$workinfo_name</STRONG>"
                    . " &nbsp; "
                    . $workinfo_license;
              }
          }
        elsif ($element eq "WORKNAME")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_name = &pop_output ();
              }
          }
        elsif ($element eq "WORKLICENSE")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_license = &pop_output ();
              }
          }
        elsif ($element eq "WORKLICENSETEXT")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_license_text = &pop_output ();
              }
          }
        elsif ($element eq "WORKNOTES")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Recall output (if any).
                $workinfo_notes = &pop_output ();
              }
          }
        elsif ($element eq "PRINTWORKINFO")
          {
            if ($type eq "start")
              {
                local ($n) = 0;

                # Sort workinfo array.
                &sort_workinfo_list (0, $#workinfo_list);

                # Eliminate duplicates.
                &delete_doubles_workinfo_list ();

                # Insert workinfo array.
                &output ("\n");
                &output ("<DL>\n");

                # Workinfo list.
                #
                # $workinfo_list[x][0]        work name
                # $workinfo_list[x][1]        work license
                # $workinfo_list[x][2]        work license text
                # $workinfo_list[x][3]        work notes
                #
                for ($n = 0; $n <= $#workinfo_list; $n++)
                  {
                    &output ("<DT>");
                    &output ("<STRONG>");
                    &output ($workinfo_list[$n][0]);
                    &output ("</STRONG>");
                    &output ("</DT>\n");
                    &output ("<DD>\n");
                    if ($workinfo_list[$n][2] =~ m/^[^a-z0-9]*$/is)
                      {
                        # There is no license text. So, print just
                        # the license name or definition.
                        &output ($workinfo_list[$n][1]);
                       }
                    else
                      {
                        # There is the license text. Print it!
                        &output ($workinfo_list[$n][2]);
                       }
                    if ($workinfo_list[$n][3] =~ m/^[^a-z0-9]*$/is)
                      {
                        # There are some notes. Print them.
                        &output ($workinfo_list[$n][3]);
                       }
                    &output ("</DD>\n");
                  }
                &output ("</DL>\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "NOMOD")
          {
            if ($type eq "start")
              {
                # Increment the counter.
                $nomod_sections_counter++;
                # Insert an anchor.
                &output ("<A NAME=\"nomod$nomod_sections_counter\"></A>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "PRINTNOMOD")
          {
            if ($type eq "start")
              {
                local ($n) = 0;

                # Insert nomod array.
                &output ("\n");
                &output ("<UL>\n");

                # $nomod_sections_list[x][0]    level     -1..4
                # $nomod_sections_list[x][1]    description   section 1.2
                # $nomod_sections_list[x][2]    title
                # $nomod_sections_list[x][3]    html page
                #
                for ($n = 0; $n <= $#nomod_sections_list; $n++)
                  {
                    if ($target eq "HTML-TEXT")
                      {
                        &output ("<LI><P><A HREF=\"#nomod$n\">"
                                 . $nomod_sections_list[$n][1]
                                 . ", "
                                 . "<EM>"
                                 . $nomod_sections_list[$n][2]
                                 . "</EM></A></P>\n");
                      }
                    else
                      {
                        &output ("<LI><P><A HREF=\"$root_file_name"
                                 . $nomod_sections_list[$n][3]
                                 . $html_ext
                                 . "#nomod$n\">"
                                 . $nomod_sections_list[$n][1]
                                 . ", "
                                 . "<EM>"
                                 . $nomod_sections_list[$n][2]
                                 . "</EM></A></P>\n");
                      }
                  }
                &output ("</UL>\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "SPECIALCONDITION")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<P><EM>");
              }
            else
              {
                &output ("</EM></P>\n");
              }
          }
        elsif ($element eq "DOCINFO")
          {
            if ($type eq "start")
              {
                # Increment the docinfo counter.
                $docinfo_counter++;
                # Print an anchor.
                &output ("<P><A NAME=\"docinfo$docinfo_counter\"></A>");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "DOCAUTHOR")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Discard output.
                &pop_output ();
              }
          }
        elsif ($element eq "DOCORIGINNOTE")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<EM>");
              }
            else
              {
                &output ("</EM><BR>\n");
              }
          }
        elsif ($element eq "DOCREVISIONNOTE")
          {
            if ($type eq "start")
              {
                &output ("\n");
                &output ("<EM>");
              }
            else
              {
                &output ("</EM><BR>\n");
              }
          }
        elsif ($element eq "DOCNOTES")
          {
            if ($type eq "start")
              {
                # Save output.
                &push_output ();
              }
            else
              {
                # Discard output.
                &pop_output ();
              }
          }
        elsif ($element eq "PRINTDOCINFO")
          {
            if ($type eq "start")
              {
                local ($n) = 0;
                local ($m) = 0;

                # Insert docinfo array.
                &output ("\n");
                &output ("<UL>\n");

                # $docinfo_list[x][0]       level               -1..4
                # $docinfo_list[x][1]       description     section 1.2
                # $docinfo_list[x][2]       title
                # $docinfo_list[x][3]       origin note
                # $docinfo_list[x][4]       revision note
                # $docinfo_list[x][5]       notes
                # $docinfo_list[x][6][y][0] revision date               OBSOLETE
                # $docinfo_list[x][6][y][1] revision author             OBSOLETE
                # $docinfo_list[x][6][y][2] revision email              OBSOLETE
                # $docinfo_list[x][6][y][3] revision description        OBSOLETE
                # $docinfo_list[x][7]       html page number
                # $docinfo_list[x][8][z]    z-th author
                #
                for ($n = 0; $n <= $#docinfo_list; $n++)
                  {
                    if ($docinfo_list[$n][1] ne "##unknown-section##")
                      {
                        # This is a usual section
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<LI><P><A HREF=\"#docinfo$n\">"
                                     . $docinfo_list[$n][1]
                                     . ", "
                                     . "<EM>"
                                     . $docinfo_list[$n][2]
                                     . "</EM>"
                                     . "</A></P>");
                          }
                        else
                          {
                            &output ("<LI><P><A HREF=\""
                                     . $root_file_name
                                     . $docinfo_list[$n][7]
                                     . $html_ext
                                     . "#docinfo$n\">"
                                     . $docinfo_list[$n][1]
                                     . ", "
                                     . "<EM>"
                                     . $docinfo_list[$n][2]
                                     . "</EM>"
                                     . "</A></P>");
                          }
                        if ($#{$docinfo_list[$n][8]} >= 0)
                          {
                            &output ("\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][8]}; $m++)
                              {
                                &output ("<P>"
                                         . $docinfo_list[$n][8][$m]
                                         . "</P>\n");
                               }
                            &output ("\n");
                          }
                        if ($docinfo_list[$n][5] ne "")
                          {
                            &output ($docinfo_list[$n][5]);
                          }
                        if ($#{$docinfo_list[$n][6]} >= 0)      # OBSOLETE
                          {
                            &output ("<UL>\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][6]}; $m++)
                              {
                                &output ("<LI><P>"
                                         . $docinfo_list[$n][6][$m][0]
                                         . " &nbsp; "
                                         . $docinfo_list[$n][6][$m][1]
                                         . " &nbsp; "
                                         . $docinfo_list[$n][6][$m][2]
                                         . "</P>\n"
                                         . "\n"
                                         . "<P>"
                                         . $docinfo_list[$n][6][$m][3]
                                         . "</P>\n");
                              }
                            &output ("</UL>\n");
                          }
                      }
                    else
                      {
                        # This is outside usual sections
                        if ($target eq "HTML-TEXT")
                          {
                            &output ("<LI><P><A HREF=\"#docinfo$n\">"
                                     . "#$n"
                                     . "</A></P>");
                          }
                        else
                          {
                            &output ("<LI><P><A HREF=\""
                                     . $root_file_name
                                     . $docinfo_list[$n][7]
                                     . $html_ext
                                     . "#docinfo$n\">"
                                     . "#$n"
                                     . "</A></P>");
                          }
                        if ($#{$docinfo_list[$n][8]} >= 0)
                          {
                            &output ("\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][8]}; $m++)
                              {
                                &output ("<P>"
                                         . $docinfo_list[$n][8][$m]
                                         . "</P>\n");
                               }
                            &output ("\n");
                          }
                        if ($docinfo_list[$n][5] ne "")
                          {
                            &output ($docinfo_list[$n][5]);
                          }
                        if ($#{$docinfo_list[$n][6]} >= 0)      # OBSOLETE
                          {
                            &output ("<UL>\n");
                            # Scan the sub array.
                            for ($m = 0; $m <= $#{$docinfo_list[$n][6]}; $m++)
                              {
                                &output ("<LI><P>"
                                         . $docinfo_list[$n][6][$m][0]
                                         . " &nbsp; "
                                         . $docinfo_list[$n][6][$m][1]
                                         . " &nbsp; "
                                         . $docinfo_list[$n][6][$m][2]
                                         . "</P>\n"
                                         . "\n"
                                         . "<P>"
                                         . $docinfo_list[$n][6][$m][3]
                                         . "</P>\n");
                              }
                            &output ("</UL>\n");
                          }
                      }
                  }
                &output ("</UL>\n");
              }
            else
              {
                # Nothing to do.
                ;
              }
          }
        elsif ($element eq "FOOTNOTE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($n) = 0;

                # Recall output (if any).
                $html_footnote = &pop_output ();

                # Prepare a new element inside the footnote array.
                $#html_footnote_list++;
                $n = $#html_footnote_list +1;

                # Insert the footnote link.
                &output ("<SUP><A HREF=\"#footnote$n\" NAME=\"footnote-ref$n\">($n)</A></SUP>");

                # Insert the footnote inside the array.
                $html_footnote_list[$#html_footnote_list] = $html_footnote;
              }
          }
        elsif ($element eq "BLOCKFOOTNOTE")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($n) = 0;

                # Recall output (if any).
                $html_footnote = &pop_output ();

                # Prepare a new element inside the footnote array.
                $#html_footnote_list++;
                $n = $#html_footnote_list +1;

                # Insert the footnote link.
                &output ("<P><SUP><A HREF=\"#footnote$n\" NAME=\"footnote-ref$n\">($n)</A></SUP>");

                # Insert the footnote inside the array.
                $html_footnote_list[$#html_footnote_list] = $html_footnote;

                # Close footnote block.
                &output ("</P>\n");
              }
          }
        elsif ($element eq "QUOTEINFO")
          {
            if ($type eq "start")
              {
                # Send the output stream to a new stack level.        
                &push_output ();
              }
            else
              {
                local ($n) = 0;

                # Recall output (if any).
                $html_footnote = &pop_output ();

                # Prepare a new element inside the footnote array.
                $#html_footnote_list++;
                $n = $#html_footnote_list +1;

                # Insert the footnote link.
                &output ("<P><SUP><A HREF=\"#footnote$n\" NAME=\"footnote-ref$n\">($n)</A></SUP>");

                # Insert the footnote inside the array.
                $html_footnote_list[$#html_footnote_list] = $html_footnote;

                # Close footnote block.
                &output ("</P>\n");
              }
          }
        else
          {
            # Call the basic %block; and %inline; sub process.
            &sgml_tag_elab_html_basic
                ($type,
                 $element,
                 $attributes,
                 $typesetting,
                 $target,
                 $draft,
                 $page_numbering,
                 $compact,
                 $long,
                 $original_file_name,
                 $root_file_name,
		 $paper_width,
		 $paper_height);
          }

    } # sgml_tag_elab_html


    #===================================================================
    # Start.
    #===================================================================

    #-------------------------------------------------------------------
    # First, start the scan for cross references.
    #-------------------------------------------------------------------

    # Output from output() is sent to /dev/null
    $current_output_stream = "/dev/null";
    open ($current_output_stream, "> /dev/null");

    # Open input file.
    open ($input_stream, "< $input_file");

    &diag_output (sprintf (gettext ("%s:%s: scanning post-SP searching for cross references.\n"),
                           $program_executable, $original_file_name));

    # Scan the post-SP output.
    while ($line = <$input_stream>)
      {
        # Determinate what kind of SP record is.
        if ($line =~ m/^A([a-z]*) ([a-z]*) ?(.*)$/i)
          {
            # This is an attribute record: $1 is the attribute name;
            # $2 is the attrybute type; $3 is the attribute value.
            # We save the name and the value.
            %element_attribute = (%element_attribute, "$1", "$3");

          }
        elsif ($line =~ m/^\((.*)$/i)
          {
            # This is an element start: $1.
            &sgml_tag_elab_first_pass
                ("start", $1, \%element_attribute,
                $typesetting,
                $target,
                $draft,
                $page_numbering,
                $compact,
                $long,
                $original_file_name,
                $root_file_name,
		$paper_width,
		$paper_height);
          }
        elsif ($line =~ m/^\)(.*)$/i)
          {
            # This is an element end: $1.
            &sgml_tag_elab_first_pass
                ("end", $1, \%element_attribute,
                $typesetting,
                $target,
                $draft,
                $page_numbering,
                $compact,
                $long,
                $original_file_name,
                $root_file_name,
		$paper_width,
		$paper_height);

            # Reset %element_attribute associative array.
            %element_attribute = ();
          }
        elsif ($line =~ m/^\-(.*)$/i)
          {
            # This is parsed character text: $1.
            $pcdata = $1;

            # This text must be transformed if necessary.
            #
            # Notice that the \\ to \bsol translation and back is just
            # an hack to resolve this problem inside SP records.
            #
            # Suppose we have:
            #   bla bla bla \\no bla bla bla.
            # If we tranlsate the two \\ into a single \, we will have
            #   bla bla bla \no bla bla bla.
            # and then we will have a new line there. If the check
            # the new line before, we will have
            #   bla bla bla \
            #   o bla bla bla.
            # with a resitual \.
            # But we wanted exacty.
            #   bla bla bla \no bla bla bla.
            # 
            if ($pcdata =~ s/\\\|(\[[a-zA-Z0-9 ]+\])\\\|/$1/g)        # \\|[hiphen]\\|       --> [hiphen]
	      {
		&diag_output (sprintf (gettext ("%s:%s: warning: cannot handle SGML entity %s.\n"),
                              $program_executable,
                              $original_file_name,
			      $1));
	      }
            $pcdata =~ s/\\\\\|/\\bsol|/g;        # \\|           --> A true "\|" sequence
            if ($pcdata =~ s/\\\|//g)             # \|            --> "" (SDATA residual delimiters)
	      {
		&diag_output (sprintf (gettext ("%s:%s: there is a residual \"\\|\" here and it should not happen. !!!!\n"),
                              $program_executable,
                              $original_file_name));
		&diag_output (sprintf ("$pcdata\n"));
	      }
            $pcdata =~ s/\\\\/\\bsol/g;           # \\            --> \bsol
            $pcdata =~ s/\\n/\n/g;                # \n            --> new line
            $pcdata =~ s/\\bsol/\\/g;             # \bsol         --> \
            
            # The text is released.
            &output ($pcdata);
          }
        elsif ($line =~ m/^\C$/i)
          {
            # The file is OK.
            # Nothing to do.
            ;
          }
        else
          {
            # This is an unknown rercord type.
            printf STDERR (gettext ("%s: unknown post-SP record: %s"),
                           $program_executable, $line);
          }

      } # while

    # Close input file.
    close ($input_stream);

    # Close output stream and reset @output_stack.
    close ($current_output_stream);
    @output_stack = ();

    #-------------------------------------------------------------------
    # Second, another scan depending on the back-end target.
    #-------------------------------------------------------------------

    # Sort index entries.
    &diag_output (sprintf (gettext ("%s:%s: sorting %s index entries.\n"),
                           $program_executable,
                           $original_file_name,
			   $#index_list));
    &sort_index_list_completely (0, $#index_list);

    &diag_output (sprintf (gettext ("%s:%s: scanning post-SP again searching for typesetting.\n"),
                           $program_executable, $original_file_name));

    if ($typesetting eq "LATEX")
      {
        # Output from output() is sent to a LaTeX source file.
        $current_output_stream = $root_file_name . ".tex";
        open ($current_output_stream, "> $root_file_name.tex");

        # Open input file.
        open ($input_stream, "< $input_file");

        # Scan the post-SP output.
        while ($line = <$input_stream>)
          {
            # Determinate what kind of SP record is.
            if ($line =~ m/^A([a-z]*) ([a-z]*) ?(.*)$/i)
              {
                # This is an attribute record: $1 is the attribute name;
                # $2 is the attrybute type; $3 is the attribute value.
                # We save the name and the value.
                %element_attribute = (%element_attribute, "$1", "$3");
              }
            elsif ($line =~ m/^\((.*)$/i)
              {
                # This is an element start: $1.
                &sgml_tag_elab_latex
                  ("start", $1, \%element_attribute,
                    $typesetting,
                    $target,
                    $draft,
                    $page_numbering,
                    $compact,
                    $long,
                    $original_file_name,
                    $root_file_name,
		    $paper_width,
		    $paper_height);
              }
            elsif ( $line =~ m/^\)(.*)$/i )
              {
                # This is an element end: $1.
                &sgml_tag_elab_latex
                  ("end", $1, \%element_attribute,
                    $typesetting,
                    $target,
                    $draft,
                    $page_numbering,
                    $compact,
                    $long,
                    $original_file_name,
                    $root_file_name,
		    $paper_width,
		    $paper_height);
                # Reset %element_attribute associative array.
                %element_attribute = ();
              }
            elsif ($line =~ m/^\-(.*)$/i)
              {
                # This is parsed character text: $1.
                $pcdata = $1;

                # This text must be transformed if necessary.
                #
                # Notice that the \\ to \bsol translation and back is just
                # an hack to resolve this problem inside SP records.
                #
                # Suppose we have:
                #       bla bla bla \\no bla bla bla.
                # If we tranlsate the two \\ into a single \, we will have
                #       bla bla bla \no bla bla bla.
                # and then we will have a new line there. If the check
                # the new line before, we will have
                #       bla bla bla \
                #   o bla bla bla.
                # with a resitual \.
                # But we wanted exacty.
                #       bla bla bla \no bla bla bla.
                # 
        	if ($pcdata =~ s/\\\|(\[[a-zA-Z0-9 ]+\])\\\|/$1/g)        # \\|[hiphen]\\|       --> [hiphen]
	          {
		    &diag_output (sprintf (gettext ("%s:%s: warning: cannot handle SGML entity %s.\n"),
                    	          $program_executable,
                                  $original_file_name,
			          $1));
		  }
        	$pcdata =~ s/\\\\\|/\\bsol|/g;        # \\|           --> A true "\|" sequence
        	if ($pcdata =~ s/\\\|//g)             # \|            --> "" (SDATA residual delimiters)
	          {
		    &diag_output (sprintf (gettext ("%s:%s: there is a residual \"\\|\" here and it should not happen. !!!!\n"),
                                  $program_executable,
                                  $original_file_name));
		    &diag_output (sprintf ("$pcdata\n"));
	          }
                $pcdata =~ s/\\\\/\\bsol/g;           # \\            --> \bsol
                $pcdata =~ s/\\n/\n/g;                # \n            --> new line
                $pcdata =~ s/\\bsol/\\/g;             # \bsol         --> \
            
                # The text is released.
                &output ($pcdata);
              }
            elsif ($line =~ m/^\C$/i)
              {
                # The file is OK.
                # Nothing to do.
                ;
              }
            else
              {
                # This is an unknown record type.
                &diag_output (sprintf (gettext ("%s: unknown post-SP record: %s !!!!"),
                                       $program_executable, $line));
              }
          } # while

        # Close input file.
        close ($input_stream);

        # Close output stream and reset @output_stack.
        close ($current_output_stream);
        @output_stack = ();
      }
    elsif ($typesetting eq "HTML")
      {
        # Output from output() is sent to a starting HTML file.
        $current_output_stream = $root_file_name . $html_ext;
        open ($current_output_stream, "> " . $root_file_name . $html_ext);

        # Open input file.
        open ($input_stream, "< $input_file");

        # Scan the post-SP output.
        while ($line = <$input_stream>)
          {
            # Determinate what kind of SP record is.
            if ($line =~ m/^A([a-z]*) ([a-z]*) ?(.*)$/i)
              {
                # This is an attribute record: $1 is the attribute name;
                # $2 is the attrybute type; $3 is the attribute value.
                # We save the name and the value.
                %element_attribute = (%element_attribute, "$1", "$3");
              }
            elsif ($line =~ m/^\((.*)$/i)
              {
                # This is an element start: $1.
                &sgml_tag_elab_html
                  ("start", $1, \%element_attribute,
                    $typesetting,
                    $target,
                    $draft,
                    $page_numbering,
                    $compact,
                    $long,
                    $original_file_name,
                    $root_file_name,
		    $paper_width,
		    $paper_height);
              }
            elsif ( $line =~ m/^\)(.*)$/i )
              {
                # This is an element end: $1.
                &sgml_tag_elab_html
                  ("end", $1, \%element_attribute,
                    $typesetting,
                    $target,
                    $draft,
                    $page_numbering,
                    $compact,
                    $long,
                    $original_file_name,
                    $root_file_name,
		    $paper_width,
		    $paper_height);
                # Reset %element_attribute associative array.
                %element_attribute = ();
              }
            elsif ($line =~ m/^\-(.*)$/i)
              {
                # This is parsed character text: $1.
                $pcdata = $1;

                # This text must be transformed if necessary.
                #
                # Notice that the \\ to \bsol translation and back is just
                # an hack to resolve this problem inside SP records.
                #
                # Suppose we have:
                #       bla bla bla \\no bla bla bla.
                # If we tranlsate the two \\ into a single \, we will have
                #       bla bla bla \no bla bla bla.
                # and then we will have a new line there. If the check
                # the new line before, we will have
                #       bla bla bla \
                #   o bla bla bla.
                # with a resitual \.
                # But we wanted exacty.
                #       bla bla bla \no bla bla bla.
                # 
        	if ($pcdata =~ s/\\\|(\[[a-zA-Z0-9 ]+\])\\\|/$1/g)        # \\|[hiphen]\\|       --> [hiphen]
	          {
		    &diag_output (sprintf (gettext ("%s:%s: warning: cannot handle SGML entity %s.\n"),
                    	          $program_executable,
                                  $original_file_name,
			          $1));
		  }
        	$pcdata =~ s/\\\\\|/\\bsol|/g;        # \\|           --> A true "\|" sequence
        	if ($pcdata =~ s/\\\|//g)             # \|            --> "" (SDATA residual delimiters)
	          {
		    &diag_output (sprintf (gettext ("%s:%s: there is a residual \"\\|\" here and it should not happen. !!!!\n"),
                	          $program_executable,
                    	          $original_file_name));
		    &diag_output (sprintf ("$pcdata\n"));
		  }
                $pcdata =~ s/\\\\/\\bsol/g;           # \\            --> \bsol
                $pcdata =~ s/\\n/\n/g;                # \n            --> new line
                $pcdata =~ s/\\bsol/\\/g;             # \bsol         --> \

                # The text is released.
                &output ($pcdata);
              }
            elsif ($line =~ m/^\C$/i)
              {
                # The file is OK.
                # Nothing to do.
                ;
              }
            else
              {
                # This is an unknown rercord type.
                printf STDERR (gettext ("%s: unknown post-SP record: %s"),
                               $program_executable, $line);
              }

          } # while

        # Close input file.
        close ($input_stream);

        # Close output stream and reset @output_stack.
        close ($current_output_stream);
        @output_stack = ();

      }
    else
      {
        # This is an unknown typesetting type.
        printf STDERR (gettext ("%s: unknown typesetting: %s"),
                       $program_executable, $typesetting);
      }

} # sgml_post_sp_elab


#======================================================================
# Start of back-end program.
#----------------------------------------------------------------------

local ($sp_file_name)       = $ARGV[0];
local ($typesetting)        = $ARGV[1];
local ($target)             = $ARGV[2];
local ($draft)              = $ARGV[3];
local ($page_numbering)     = $ARGV[4];
local ($compact)            = $ARGV[5];
local ($long)               = $ARGV[6];
local ($original_file_name) = $ARGV[7];
local ($root_file_name)     = $ARGV[8];
local ($verbose)            = $ARGV[9];
local ($paper_width)        = $ARGV[10];
local ($paper_height)       = $ARGV[11];

# Define temporary file name prefix.
$temporary_file_name_prefix = $program_executable . "_" . $root_file_name;

# We have to elaborate the post-SP output 
# This elaboration will generate different results, depending on the target.
#
&sgml_post_sp_elab ($sp_file_name,
                    $typesetting,
                    $target,
                    $draft,
                    $page_numbering,
                    $compact,
                    $long,
                    $original_file_name,
                    $root_file_name,
		    $paper_width,
		    $paper_height);

# Delete temporary files.
# It is strange, but sometimes, unlink() doesn't work as expected.
# This is because we use "rm" instead.
system ("rm -f $temp_files_list");
    

#======================================================================

