% tex tex4ht-htcmd   or   ht tex tex4ht-htcmd
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tex4ht-htcmd.tex                                       %
% Copyright (C) 2000--            Eitan M. Gurari        %
%                                                        %
% This work may be distributed and/or modified under the %
% conditions of the LaTeX Project Public License, either %
% version 1.3 of this license or (at your option) any    %
% later version. The latest version of this license is   %
% in                                                     %
%   http://www.latex-project.org/lppl.txt                %
% and version 1.3 or later is part of all distributions  %
% of LaTeX version 2003/12/01 or later.                  %
%                                                        %
% This work has the LPPL maintenance status "maintained".%
%                                                        %
% This Current Maintainer of this work                   %
% is Eitan M. Gurari.                                    %
%                                                        %
% If you modify this file your changing the signature    %
% in \message{(signature)} below will be appreciated.    %
%                                                        %
%                             gurari@cse.ohio-state.edu  %
%                 http://www.cse.ohio-state.edu/~gurari  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
\message{(<signature>)}


\newcount\tmpcnt  \tmpcnt\time  \divide\tmpcnt  60
\edef\temp{\the\tmpcnt}
\multiply\tmpcnt  -60 \advance\tmpcnt  \time

\edef\version{\the\year-\ifnum \month<10 0\fi
  \the\month-\ifnum \day<10 0\fi\the\day
   -\ifnum \temp<10 0\fi \temp
   :\ifnum \tmpcnt<10 0\fi\the\tmpcnt}
\def\CopyYear.#1.{%
   \ifnum #1=\year #1\space\space\space\space\space\space
    \else          #1--\the\year\fi
}


\input tex4ht.sty    

\Preamble{xhtml,th4,sections+,xhtml}\EndPreamble    

   \input ProTex.sty
   \AlProTex{c,<<<>>>,`,title,list,_^}


\Comment{   
}{}
\def\CodeId#1#2{}


\def\UnderLine#1{\ifHtml
   \HCode{<strong>}#1\HCode{</strong>}\else\underbar{#1}\fi}
\let\CModifyShowCode=\ModifyShowCode
\let\CModifyOutputCode=\ModifyOutputCode
\def\ModifyShowCode{\def\[##1({##1\UnderLine{(}}\def
                        \;{\UnderLine{;}}\CModifyShowCode}
   \catcode`\^=7  \catcode`\@=6  \catcode`\#=12 \catcode`\^^M=13\relax%
\def\ModifyOutputCode{%
\def\;{ SEP }%
\def\[@@1(@@2)@@3;{@@1
#ifdef ANSI
#define SEP  ,
(@@3)
#undef  SEP  
#else
#define SEP  ;
(@@2)@@3;
#undef  SEP  
#endif
}%
\CModifyOutputCode}%
   \catcode`\^^M=5 \catcode`\@=12 \catcode`\#=6 \catcode`\^=13




\let\'=\Verb
\def\`{\expandafter\expandafter\expandafter\qts\Verb}
\def\qts#1{`#1\aftergroup'}

\def\FTP{http://www.cse.ohio-state.edu/\string~gurari/tpf/}


 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<htcmd.c\><<<
/**********************************************************/
/* htcmd.c                               `version */
/* Copyright (C) `CopyYear.1996.    Eitan M. Gurari            */
/*                                                        */
/* This work may be distributed and/or modified under the */
/* conditions of the LaTeX Project Public License, either */
/* version 1.3 of this license or (at your option) any    */
/* later version. The latest version of this license is   */
/* in                                                     */
/*   http://www.latex-project.org/lppl.txt                */
/* and version 1.3 or later is part of all distributions  */
/* of LaTeX version 2003/12/01 or later.                  */
/*                                                        */
/* This work has the LPPL maintenance status "maintained".*/
/*                                                        */
/* This Current Maintainer of this work                   */
/* is Eitan M. Gurari.                                    */
/*                                                        */
/* If you modify this program your changing its signature */
/* with a directive of the following form will be         */
/* appreciated.                                           */
/*      #define PLATFORM "signature"                      */
/*                                                        */
/*                             gurari@cse.ohio-state.edu  */
/*                 http://www.cse.ohio-state.edu/~gurari  */
/**********************************************************/
`<htcmd.h`>
`<defines`>
`<vars`>
`<header functions`>
`<functions`>
`[
int `<CDECL`> main(argc, argv)
       int  argc`;  
       Q_CHAR **argv
;{ `<main's vars`> 
   `<set signals`>
#ifdef PLATFORM
   (IGNORED) printf("htcmd.c (`version %s)\n",PLATFORM);
#else
   (IGNORED) printf("htcmd.c (`version)\n");
#endif
  `<main's init`> 
  `<command = job args`>
  `<make system call`>
   return 0;
}
>>>



\<htcmd.h\><<<
/* **********************************************
    Compiler options                            *
    (uncommented | command line)                *
------------------------------------------------*
        Clasic C (CC)             default
#define ANSI                      ansi-c, c++
#define DOS_C
#define HAVE_STRING_H             <string.h>
#define HAVE_DIRENT_H             <dirent.h>
#define HAVE_SYS_NDIR_H           <sys/ndir.h>
#define HAVE_SYS_DIR_H            <sys/dir.h>
#define HAVE_NDIR_H               <ndir.h>
#define HAVE_IO_H                 <io.h>
#define HAVE_UNISTD_H             <unistd.h>
#define WIN32
#define KPATHSEA             
#define SYSTEM_FUNCTION_OK 
#define CDECL                    ..........
#define BCC32                    bordland c++

*************************************************
    Tex4ht variables                            *
    (uncommented | command line)                *
----------------------------------------------- */
`<h-defines`>
/* ******************************************** */
`<define MSVC-1-52`>
`<bordland: bcc32 -DBCC32 htcmd`>
`<bordland: bcc -DBCC tex4ht`>
`<DJGPP`>
#ifdef DOS_C
#define DOS
#endif
#ifdef DOS
#define DOS_WIN32
#ifndef HAVE_STRING_H
#define HAVE_STRING_H
#endif
#endif
#ifdef WIN32
#define DOS_WIN32
#endif
`<h-defines DOS-WIN32`>
`<h-defines KWIN32`>
`<h-include`>
`<h-defines 2`>
>>>

\<htcmd.h\><<<
#ifdef DOS
#define PROTOTYP
#endif
#ifdef ANSI
#define PROTOTYP
#endif
#ifdef KWIN32
#define PROTOTYP
#endif
>>>


\<htcmd.h\><<<
#ifdef KPATHSEA
#ifdef WIN32
#undef CDECL
#define CDECL                     __cdecl
#else
#define CDECL
#endif
#endif
>>>

\<h-defines KWIN32\><<<
#ifdef KPATHSEA
#ifdef WIN32
#define KWIN32  
#endif
#endif
>>>



\''open(file, ..._FLAGS)': All
text files should be opened with "r" or "w"; all binary files with "rb"
or "wb". This is the portable way and will work both under Unix and DOS;
as Unix doesn't distinguish between text and binary files, its compilers
will simply ignore the "b" part.

  On the subject of the .lg file: you open the tex4ht.env file in binary
mode ("rb"), which results in strange line endings in the .lg file
(CR/CR/LF). Changing the mode to "r" fixes this.


\<htcmd.h\><<<
#if defined(DOS_WIN32) || defined(__MSDOS__)
#define READ_BIN_FLAGS "rb"
#define READ_TEXT_FLAGS "r"
#define WRITE_BIN_FLAGS "wb"
#define WRITE_TEXT_FLAGS "w"
#else
#define READ_BIN_FLAGS "r"
#define READ_TEXT_FLAGS "r"
#define WRITE_BIN_FLAGS "w"
#define WRITE_TEXT_FLAGS "w"
#endif
>>>

\<defines\><<<
#define Q_CHAR char
#define U_CHAR char
#define C_CHAR char
#define Q_NULL (Q_CHAR *) 0
#define U_NULL (U_CHAR *) 0
#define C_NULL (C_CHAR *) 0
>>>


\<defines\><<<
#define IGNORED void
>>>

\<defines\><<<
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
>>>



\<defines\><<<
#ifdef PROTOTYP
#define VOID void
#define ARG_I(x) x
#define ARG_II(x,y) x,y
#define ARG_III(x,y,z) x,y,z
#define ARG_IV(x,y,z,w) x,y,z,w
#define ARG_V(x,y,z,w,u) x,y,z,w,u
#else
#define VOID 
#define ARG_I(x) 
#define ARG_II(x,y) 
#define ARG_III(x,y,z) 
#define ARG_IV(x,y,z,w) 
#define ARG_V(x,y,z,w,u) 
#endif
>>>



\<defines\><<<
struct sys_call_rec{
  Q_CHAR * filter;
  struct sys_call_rec *next;
};
>>>


\<vars\><<<
static BOOL system_yes;
>>>


\<defines\><<<
struct script_struct{
  Q_CHAR *command;
  struct script_struct *next;
};
>>>

\<defines\><<<
#define NULL_SCRIPT (struct script_struct *) 0
>>>


\SubSection{Signals}

\<h-include\><<<
#include <signal.h>
>>>

\<header functions\><<<
static void 
`<CDECL`>
sig_err(ARG_I(int));
>>>




\<functions\><<<
`[
static void
`<CDECL`>
sig_err(s)  int s
;{
  (void) signal(s,SIG_IGN);  `%ignore the signal`%
  switch( s ){
#ifdef SIGSEGV
    case SIGSEGV: err_i(2); 
#endif
    case SIGFPE : err_i(3);  
#if defined(SIGINT) && !defined(WIN32)
    case SIGINT : err_i(4);
#endif
  } 
  `<DJGPP signals`>
}
>>>




Forgetting \`'_pascal' and \`'_cdecl' modifiers: Each C function may
be either \`'_pascal' or \`'_cdecl'. This modifier defines how
parameters are passed to it. Default for Smalltalk definition is
\`'_cdecl'. Default for C functions depends on compiler settings, and
you can use other types uncompatible with Smalltalk. In Windows API
16-bit functions are \`'_pascal' and 32-bit \`'_cdecl'.
 


\<CDECL\><<< 
#ifdef CDECL
CDECL
#endif
>>>
 



\<set signals\><<<

#ifdef SIGSEGV
  (void) signal(SIGSEGV,sig_err);
#endif
  (void) signal(SIGFPE,sig_err);
#ifdef KWIN32
  `<KWIN32 signals`>
#else 
#ifdef SIGINT
  (void) signal(SIGINT,sig_err);    `%Control-c, user interrupt`%
#endif
#endif
>>>



SIGFPE is handled by the C library, SIGSEGV too but not generated by
the system, so it does nothing but is harmless 

SetConsoleCtrlHandler is need to catch Ctrl+C and Ctrl+Break under
win32, SIGINT is not generated by the system.
 
\<KWIN32 signals\><<<
SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
>>>



SIGSEGV, SIGILL, SIGTERM not implemented in MS-DOS. They are supplied just for
compatibility. Looks like that SIGINT is defined for windows but not for dos.

\<vars\><<<
static int system_return;
>>>

\<main's vars\><<<
int i;
BOOL slash, dslash;
char *in_command, *command, *p, *q;
>>>

\<command = job args\><<<
  in_command = (char *) malloc(1024);  
  command = (char *) malloc(1024);  
  in_command[0] = '\0';
  `<kpathsea arg 0`>
  if( argc == 1 ){ bad_arg; }
  slash = eq_str(argv[1],"-slash") ;
  dslash = eq_str(argv[1],"-dslash") ;
  for(i=1+slash+dslash; i<argc; i++){
     (IGNORED) printf("%s ", argv[i]);
     (IGNORED) strct(in_command,argv[i]);
     (IGNORED) strct(in_command," ");
  }
  (IGNORED) printf("\n");     
>>>


\<make system call\><<<
p = in_command;
q = command;
do{
  if( (*p != '"' ) && (*p != '\'' ) && (*p != '``' ) ){ 
    if(slash && (*p == '/')) {
      *(q++) = '\\'; 
    } 
    else if(dslash && (*p == '/')) {
      *(q++) = '\\'; 
      *(q++) = '\\'; 
    } 
    else { *(q++) =  *p;  }
  }
} while (*(p++) != '\0');
(IGNORED) call_sys(command);
>>>


\SubSection{PreProcessor Directives}


Symantec C++ for wid95:
\''sc htcmd.c -mn -o+time -WA -3 -a8 -c -D_CONSOLE=1 -ohtcmd.obj'






\<bordland: bcc32 -DBCC32 htcmd\><<<
#ifdef BCC32
#define WIN32 
#define ANSI       
#define HAVE_IO_H
#define HAVE_STRING_H
#define PLATFORM "ms-win32"
#endif
>>>

% 

\<bordland: bcc -DBCC tex4ht\><<<
#ifdef BCC
#define DOS_C
#define ANSI       
#define HAVE_IO_H
#define PLATFORM "ms-dos"
#endif
>>>


\<h-include\><<<
#include <stdio.h>   `% EOF, FILE `%
#include <stdlib.h>  `% EXIT_FAILURE `%
>>>



  Under ANSI C, all malloc stuff is declared in \`'<stdlib.h>' (which you
also include), hence this non-standard header is redundant.





\<h-include\><<<
#ifdef HAVE_STRING_H
#include <string.h>
#endif
>>>






\<h-defines DOS-WIN32\><<<
#ifdef DOS_WIN32
#define STRUCT_DIRENT
#endif
>>>


\<h-include\><<<
#ifdef HAVE_DIRENT_H
`<needs dirent.h`>
#else
#ifndef STRUCT_DIRENT
#define STRUCT_DIRECT
#endif
`<needs simulated dirent.h`>
#endif 
>>>



\<needs dirent.h\><<<
#include <dirent.h>
>>>


\<needs simulated dirent.h\><<<
#ifdef HAVE_SYS_NDIR_H
#include <sys/ndir.h>
#endif
#ifdef HAVE_SYS_DIR_H
#include <sys/dir.h>
#endif
#ifdef HAVE_NDIR_H
#include <ndir.h>
#endif
>>>


REPLACE EXIT with somthing that DOS also accept.







\SubSection{KPATHSEA}

\<h-defines 2NO\><<<
`<h-include before KPATHSEA`>
#ifdef KPATHSEA
#ifndef HAVE_STRCHR
#define  strchr  index
#endif
#ifndef HAVE_STRRCHR
#define  strrchr  rindex
#endif
#include <kpathsea/config.h>
#include <kpathsea/c-errno.h>
#include <kpathsea/c-ctype.h>
#include <kpathsea/c-fopen.h>
#include <kpathsea/c-pathmx.h>
#include <kpathsea/proginit.h>
#include <kpathsea/tex-file.h>
#include <kpathsea/tex-make.h>
#include <signal.h>
#if !defined(_AMIGA) && !defined(WIN32)
#include <sys/time.h>
#endif
#include <fcntl.h>
#include <setjmp.h>
#endif `%/* KPATHSEA */`%
`<h-include after KPATHSEA`>
>>>

\<h-defines 2\><<<
`<h-include before KPATHSEA`>
#ifdef KPATHSEA
#include <kpathsea/config.h>
#include <kpathsea/c-errno.h>
#include <kpathsea/c-ctype.h>
#include <kpathsea/c-fopen.h>
#include <kpathsea/c-pathmx.h>
#include <kpathsea/proginit.h>
#include <kpathsea/tex-file.h>
#include <kpathsea/tex-make.h>
#include <signal.h>
#if !defined(_AMIGA) && !defined(WIN32)
#include <sys/time.h>
#endif
#include <fcntl.h>
#include <setjmp.h>
#endif `%/* KPATHSEA */`%
`<h-include after KPATHSEA`>
>>>


The \`'__cdecl' is defined in KPATHSEA: kpathsea/c-protos.h 
is defined to nothing for compilers
other than MS.







\<DJGPP\><<<
#ifdef __DJGPP__
#define DOS_WIN32
#define ANSI
#endif
>>>




\<DJGPP signals\><<<
#ifdef __DJGPP__
  if (s != SIGINT && s != SIGQUIT)
    exit(EXIT_FAILURE);
#endif
>>>



\<h-include before KPATHSEA\><<<
#ifndef __DJGPP__         
`<h-include near KPATHSEA`>
#endif
>>>



The following is because \`'<unistd.h>
defines F_OK in DJGPP'.

\<h-include after KPATHSEA\><<<
#ifdef __DJGPP__         
`<h-include near KPATHSEA`>
#endif
>>>

\<h-include near KPATHSEANO\><<<
#ifndef F_OK
#ifdef DOS_WIN32
#define  F_OK 0               `% does file exist `%
#endif
#ifndef DOS_WIN32
#define HAVE_UNISTD_H
#endif
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>    
#endif
>>>

\<h-include near KPATHSEA\><<<
#ifndef F_OK
#ifdef DOS_WIN32
#define  F_OK 0               `% does file exist `%
#endif
#ifndef KPATHSEA  
#ifndef DOS_WIN32
#define HAVE_UNISTD_H
#endif
#endif
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifndef KPATHSEA  
#ifdef HAVE_UNISTD_H
#include <unistd.h>    
#endif
#endif
>>>


\<defines\><<<
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef BOOL
#define BOOL int
#endif
>>>




\<defines\><<<
#define bad_arg            err_arg(0)
#define bad_mem             err_i(1)
>>>






\<header functions\><<<
static void err_i( ARG_I(int) );
>>>

\<functions\><<<
`[
static void err_i(n)      int  n

;{  (IGNORED) fprintf(stderr,"--- error --- ");
   (IGNORED) fprintf(stderr, warn_err_mssg[n]);
   exit(EXIT_FAILURE);  
}
>>>



\<header functions\><<<
static void err_arg( ARG_I(int) );
>>>

\<functions\><<<
`[
static void err_arg(n)      int  n

;{  (IGNORED) fprintf(stderr,"--- error --- ");
   (IGNORED) fprintf(stderr, warn_err_mssg[n]);
   exit(EXIT_FAILURE);  
}
>>>



\<vars\><<<
static C_CHAR *warn_err_mssg[]={ `<warn and err messages`> "" };
>>>



\<warn and err messages\><<<
"\n---------------------------------------------------------------\n\
htcmd optional-flag command-line\n\n\
   optional-flag:\n\
        -slash     translate '/' into '\\'\n\
        -dslash    translate '/' into '\\\\'\n\n\
Example: \n\
   htcmd t4ht name -d/WWW/temp/ -etex4ht-32.env -m644\n\
---------------------------------------------------------------\n"
>>>





\<system exist?\><<<
#ifdef SYSTEM_FUNCTION_OK
0
#else
system( yes ) != 0
#endif
>>>








\<header functions\><<<
static void call_sys(ARG_I(Q_CHAR *));
>>>

\<functions\><<<
`[
static void call_sys(command)  Q_CHAR * command
;{
   if( *command ){
      (IGNORED) printf("htcmd calls: %s\n", command);
      system_return = system_yes?  (int) system(command) : -1;
      (IGNORED) printf("%shtcmd returns: %d\n",
            system_return? "--- Warning --- " : "", system_return );
   }
}
>>>





strcat should be in string.h, but c++ doesn't find it there.
We use it just for concatenating an extension of 
file name. Should have the interface
\`'char *strcat( ARG_II(C_CHAR *, const Q_CHAR *) );'.

\<header functions\><<<
static void strct( ARG_II(C_CHAR *, C_CHAR *) );
>>>

\<functions\><<<
`[
static void strct( str1, str2 ) 
     Q_CHAR * str1`;
     Q_CHAR * str2

;{   Q_CHAR * ch;
   ch = str1 + (int) strlen(str1);
   (IGNORED) strcpy( ch, str2 );
}
>>>



\<main's init\><<<
{                   C_CHAR   *yes = NULL;
  system_yes = (`<system exist?`>);
}
>>>

\<defines\><<<
#define eq_str(x,y) (!strcmp(x,y))
>>>






%----------------------------------------------------

\OutputCodE\<htcmd.c\>


\bye

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





\<header functions\><<<
static void* r_alloc(ARG_II(void *, size_t));
>>>

\<functions\><<<
`[
static void* r_alloc( q, n ) 
      void   *q`;
      size_t  n
;{    void*   p;
   if((p = (void *) realloc( q, (size_t) n)) == NULL) bad_mem;
   return p;
}
>>>











\<main's body\><<<
`<load env file`>
}
>>>








\LikeChapter{htcmd: postprocessor for tex4ht}

The compilation of this file requires the packages
\Link[\FTP ProTex.sty]{}{}Pro\TeX\EndLink{}
and \Link[\FTP AlProTex.sty]{}{}AlPro\TeX\EndLink.

\TableOfContents[Section,SubSection] 



\Section{Outline}




The post-processor \`'tex4ht.c' prepares a \`'.lg' file in which it
lists the pictures that need to be generated, and the entries
encountered in \''\Needs{...}'.  The \`'.log' file contains the
entries encountered in the \''\Needs-{...}'.  The htcmd.perl script
treats as commands the entries that are enclosed between double-quote
(\''"') characters, and the other entries as comments. It first works
on the \`'.lg' file and then on the \`'.log' file.









\<mv html and css to dir and chmod\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {              
   status = scan_str("File: ", TRUE, lg_file);
   status = scan_until_end_str("", 1, status, lg_file);
   if( status && !eq_str(match[1],"tex4ht.tmp") ){
      if( dir ){                          
         (void) execute_script(copy_script, match[1], 
                               dir? dir :"",".","");
      }
      if( ch_mod ){
         (void) execute_script(chmod_script, ch_mod,
                               dir? dir:"",match[1], "");
      }
}  }
>>>






\SubSection{char, signed char, unsigned char (gcc man)}:


 Each kind of machine has a default for what char should
          be.  It is either like unsigned char by default or like
          signed char by default.

          Ideally, a portable program should  always  use  signed
          char or unsigned char when it depends on the signedness
          of an object.  But many programs have been  written  to
          use plain char and expect it to be signed, or expect it
          to be unsigned, depending on  the  machines  they  were
          written  for.   This  option,  and its inverse, let you
          make such a program work with the opposite default.

          The type char is always a distinct type  from  each  of
          signed char and unsigned char, even though its behavior
          is always just like one of those two.




\<definesNO\><<<
#define Q_CHAR signed char
#define U_CHAR unsigned char
#define C_CHAR char
#define Q_NULL (Q_CHAR *) 0
#define U_NULL (U_CHAR *) 0
#define C_NULL (C_CHAR *) 0
>>>

Pointers to strings must use  \`'C_CHAR', since we don't 
know how string constants are treated there.




\SubSection{EOF Character}


\<vars\><<<
static int eoln_ch;
>>>

\Verbatim
OBTW: when compiling htcmd.c, I get messages about the uselessness of comparing
chars (which are unsigned, at least on a IRIX 6.5) to EOF which is defined as
-1 in stdio.h).... and indeed it program loops endlessly.
Adding the lines
   #undef EOF
   #define EOF 255
after the last #include gets the effect that you probably want (or perhaps
better would be to define a constant EOFCHAR or something.)
\EndVerbatim

The getc returns the next character as an unsigned char converted to int.
This is so to allow all characters to be return as well as end-of-file
indicators (-1 in stdio) and error indicator.



\SubSection{Comments}

\Verbatim
Date: Sun, 25 Oct 1998 00:52:22 +0100
X-Mailer: emacs 19.34.6 (via feedmail 9-beta-3 Q)
From: Sebastian Rahtz <s.rahtz@elsevier.co.uk>
To: te@informatik.uni-hannover.de, popineau@esemetz.ese-metz.fr,
        infovore@xs4all.nl
cc: gurari@cse.ohio-state.edu, michel.GOOSSENS@CERN.ch
Subject: change to texmf.cnf for tex4ht

Can you change your default setups to add the following line to
texmf.cnf?

HTCMDINPUTS = .;$TEXMF/tex4ht//;$TEXMF/tex/latex/tex4ht

this is because Eitan Gurari has added a new C program, htcmd, to the
TeX4ht setup, which does some Kpathsea work.

I'll be distributing a revised set of files for tex4htk shortly; if
its in your kits, it'll need a complete revision, as the sources and
support files are all changed.

If you picked up TeX4ht already from CTAN (this includes you,
Michel), do not proceed with that. htcmd.c needs some changes for
Kpathsea compilation which I have sent back to Eitan to merge in
\EndVerbatim

\Section{Platform-dependent Code}






















\SubSection{Compilers}


\List{}
\item {BCC32}  

For Win 95.

Options (\''bcc32' comamnd):

\Verbatim
Borland C++ 5.0 for Win32 Copyright (c) 1993, 1996 Borland International
Syntax is: BCC32 [ options ] file[s]     * = default; -x- = turn switch x off
  -3    * 80386 Instructions        -4      80486 Instructions
  -Ax     Disable extensions        -B      Compile via assembly
  -C      Allow nested comments     -Dxxx   Define macro
  -Exxx   Alternate Assembler name  -Hxxx   Use pre-compiled headers
  -Ixxx   Include files directory   -K      Default char is unsigned
  -Lxxx   Libraries directory       -M      Generate link map
  -N      Check stack overflow      -Ox     Optimizations
  -P      Force C++ compile         -R      Produce browser info
  -RT   * Generate RTTI             -S      Produce assembly output
  -Txxx   Set assembler option      -Uxxx   Undefine macro
  -Vx     Virtual table control     -X      Suppress autodep. output
  -aN     Align on N bytes          -b    * Treat enums as integers
  -c      Compile only              -d      Merge duplicate strings
  -exxx   Executable file name      -fxx    Floating point options
  -gN     Stop after N warnings     -iN     Max. identifier length
  -jN     Stop after N errors       -k    * Standard stack frame
  -lx     Set linker option         -nxxx   Output file directory
  -oxxx   Object file name          -p      Pascal calls
  -tWxxx  Create Windows app        -u    * Underscores on externs
  -v      Source level debugging    -wxxx   Warning control
  -xxxx   Exception handling        -y      Produce line number info
  -zxxx   Set segment names
\EndVerbatim


\item {BCC}

For DOS.

\item {MSVC++}

For DOS.

\`'c:\msvc\bin\cl  -Ic:\msvc\include -DDOS  htcmd.c'

In tex-live \`' cl  -D_X86_=1 -DWINVER=0x0400 -DWIN32 -D_WIN32 
-DWIN32_LEAN_AND_MEAN -D_MT -D_DLL  -DKPATHSEA 
-D_IMPORT -DANSI -I. -I.   -I.. -IG:\fptex\source\web2c-7.2  -c -W3 
-DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo  -O2x -G5rs -Gy  
-c /Fodynamic\htcmd.obj .\htcmd.c'

The following are the available flags (\''c:\msvc\bin\cl -help').

\Verbatim
                         C COMPILER OPTIONS

                            -MEMORY MODEL-
/AS small model (default)               /AC compact model
/AM medium model                        /AL large model
/AH huge model                          /AT tiny model (.COM files)
/A<string> (custom memory model)
                            -OPTIMIZATION-
/O enable optimization (same as /Ot)    /O1 minimize space
/O2 maximize speed                      /Oa assume no aliasing
/Ob<n> inline expansion (default n=0)   /Oc local common subexpression opt.
/Od disable optimization (default)      /Oe enable registers allocation
/Of[-] toggle p-code quoting            /Og global common subexpression opt.
/Oi enable intrinsic functions          /Ol enable loop optimizations
/On disable ``unsafe'' optimizations      /Oo[-] toggle post code-gen. opt.
/Op[-] improve floating-pt consistency  /Oq enable maximum p-code optimization
/Or gen. common exit code (CodeView)    /Os favor code size
/Ot favor code speed                    /Ov[-] toggle p-code frame sorting
/OV<n> control inlining by func. size   /Ow assume cross-function aliasing
/Ox maximum opts. (/Ob1cegilnot /Gs)    /Oz enable ``unsafe'' optimizations
                          -CODE GENERATION-
/G0 8086 instructions (default)         /G1  186 instructions
/G2  286 instructions                   /G3  386 instructions
  (press <return> to continue)
/GA protected-mode Win entry/exit code  /GD protected-mode Win entry/exit code
/GE<x> customize Windows entry/exit     /Gq backwards compatibility with v. 6
/Gc Pascal style calling conventions    /Gd C style calling conventions
/Ge use stack-check calls               /Gf enable string pooling
/Ge use stack-check calls               /Gf enable string pooling
/Gs remove stack-check calls            /Gn remove p-code native entry points
/Gp<num> specify p-code entry tables    /Gr _fastcall style calling convention
/Gt[num] data size threshold            /GW real-mode Windows entry/exit code
/Gw real-mode Windows entry/exit code   /Gx assume that data is near
/Gx- assume that data is far            /Gy separate functions for linker
/Zr check null pointers (/f only)
                            -OUTPUT FILES-
/Fa[file] name assembly listing file    /Fc[file] name source/object listing
/Fd[file] name .PDB filename            /Fe<file> name executable filename
/Fl[file] name object listing filename  /Fm[file] name map filename
/Fo<file> name object filename          /Fr[file] name .SBR filename
/Fp<file> name .PCH filename            /FR[file] name extended .SBR filename
/Fs[file] name source listing filename
                            -PREPROCESSOR-
/C don't strip comments                 /D<name>[=|#text] define macro
/E preprocess to stdout                 /EP same as /E but no #line
/I<directory> add #include path         /P preprocess to file
/U<name> remove predefined macro        /u remove all defined macros
  (press <return> to continue)
/X ignore "standard places"
                              -LANGUAGE-
/vd{0|1} disable/enable vtordisp        /vm<x> type of pointers to members
/Z7 C 7 style CodeView information      /Za disable extensions (implies /Op)
/Zd line number information             /Ze enable extensions (default)
/Zg generate function prototypes        /Zi prepare for debugging (CodeView)
/Zl omit default library name in .OBJ   /Zp[n] pack structs on n-byte boundary
/Zs check syntax only
                           -FLOATING POINT-
/FPa calls with altmath                 /FPc calls with emulator
/FPc87 calls with 8087 library          /FPi inline with emulator (default)
/FPi87 inline with 8087
                          -SOURCE LISTING-
/Sl<columns> set line width             /Sp<lines> set page length
/St<string> set title string            /Ss<string> set subtitle string
                           -MISCELLANEOUS-
/batch specify batch mode compilation   /Bm<num> set compiler's available mem.
/c compile only, no link                /H<num> external name length
/J default char type is unsigned        /f select fast compiler (default)
/f- select optimizing compiler          /Yc create .PCH file
/Yd put debug info in .PCH file         /Yu use .PCH file
/YX automatic precompiled header        /nologo suppress copyright message
  (press <return> to continue)
/Mq compile for QuickWin                /ND<name> name data segment
/NM<name> name code segment             /NQ<name> combine p-code temp segments
/NT<name> name code segment             /NV<name> name far v-table segment
/Tc<file> compile file without .c       /Tp<file> compile file without .cpp
/V<string> set version string           /W<n> warning level (default n=1)
/w disable all warnings                 /WX treat all warnings as errors
/Zn turn off SBRPACK for .SBR files
                            -MASM SUPPORT-
/MA<MASM switch>                        /Ta<file> assemble file without .asm
                              -LINKING-
/F <hex_num> stack size (hex. bytes)    /Lr append 'r' to default lib in .OBJ
/link [lib] give lib name to linker     /Ln do not link CRT.LIB
/Ld select dynamically-linked library   /Lw select statically-linked library
\EndVerbatim


\EndList

\SubSection{DJGPP}




\Verbatim
1998-10-22  Eli Zaretskii  <eliz@is.elta.co.il>

        * tex4ht.c [__DJGPP__] (ANSI, DOS_GIF_FILE): Define.
        (WRITE_BIN_FLAGS, READ_BIN_FLAGS): Use binary mode with DJGPP.
        (dos_file_names): New variable.
        (sig_err): If got fatal signal other than SIGINT or SIGQUIT, don't
        return to caller, since the program will be aborted otherwise.
        (main) [KPATHSEA]: If input is from stdin which is not a console
        device, switch it to binary mode.  Set dos_file_names to TRUE for
        all DOS platforms, FALSE on Unix and WIN32, and compute at runtime
        for DJGPP.  Simplify logic of finding the init file by pushing
        HOME=C: into environment if $HOME isn't defined on DOSISH systems.
\EndVerbatim



\SubSection{Slashes n Directory Pathes}




\<defines\><<<
#if defined(DOS_WIN32) || defined(__DJGPP__)
#define dir_path_slash(str) (is_forward_slash(str)? '/' : '\\')
#else
#define dir_path_slash(str)  '/' 
#endif
>>>



\<header functions\><<<
#if defined(DOS_WIN32) || defined(__DJGPP__)
   static BOOL is_forward_slash( ARG_I(Q_CHAR *) );
#endif
>>>

\<functions\><<<
#if defined(DOS_WIN32) || defined(__DJGPP__)
`[ 
static BOOL is_forward_slash(str)
                                    Q_CHAR * str
;{   
   while( *str ){  if( *(str++) == '/' ) { return TRUE; } }
   return FALSE;
}
#endif
>>>








\Section{Command-Line Options}


\SubSection{Available Options}

\List{disc}
\item  \`'.../'---Directory where files should be sent
\item \`'-mXXX'---\`'chmod XXX' for files
\item \`'-e...'---Name of invisible gif 
\item \`'-d'---Directory for config files
\item \`'-p'---Ignore pictures (but not pictorial symbols)
\item \`'-i'---Debugging info
\item     Other---Name of dvi file
\EndList


\Verbatim
   dvips -mode ibmvga -D 110 -f foo.idv -pp 92  > tmp.ps
   convert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps foo.gif
   mv foo.gif /WWW/temp/.
   cp foo.html /WWW/temp/.
   chmod 644 /WWW/temp/foo.*
\EndVerbatim


\<command line options\><<<
"\n---------------------------------------------------------------\n\
htcmd filename ...\n\
  -d...  directory for output files       (default:  current)\n\
  -e...  location of tex4ht.env\n\
  -i     debugging info\n\
  -m...  chmod ... for output files\n\
  -p     don't convert pictures           (default:  convert)\n\
  -S...  permission for system calls: *-always, filter\n\
  -X...  script for files\n\n\
Example: \n\
   htcmd name -d/WWW/temp/ -etex4ht-32.env -m644\n\
---------------------------------------------------------------\n"
>>>


If option \`'-e' is present, empty pictures are replaced
with the named file (e.g., \`'empty.gif').





\SubSection{Scanning the Options}





\Verbatim
I found that I couldn't compile htcmd.c with KPATHSEA defined, and then noticed
that it doesn't include any of the kpathsea headers.  So I have patched htcmd.c
to create two versions:  one with the necessary kpathsea headers and one
without.  This is the output produced by 'diff'.  Let me know if you want to
merge my changes into your htcmd.c, and/or if you notice any errors!  I have
changed the second argument of 'kpse_set_program_name' from NULL (which would
effectively mean argv[0]) to 'tex4ht', as that saves having to add a
'HTCMDINPUTS' (or 'HTCMDKINPUTS') variable into the kpathsea configuration file
'texmf.cnf' pointing to the same place for 'tex4ht.env' as the 'TEX4HTINPUTS'
variable.

For htcmd.c, the kpathsea library is only useful for locating the tex4ht.env
configuration file.  But as it can be used for this purpose for tex4ht.c, it
seems a pity not to enable it for its companion program too.

> 94a99,102
> > #ifdef KPATHSEA
> > #include <kpathsea/progname.h>
> > #include <kpathsea/tex-file.h>
> > #endif
> 943c951
> <    kpse_set_program_name (argv[0], NULL);
> ---
> >    kpse_set_program_name (argv[0], "tex4ht");
\EndVerbatim

\<kpathsea arg 0\><<<
#ifdef KPATHSEA
   kpse_set_program_name (argv[0], NULL);
#endif
>>>



If \`'strlen( argv[i] ) == 2' the switch is followed by a
space to be deleted when more input is awaited.


\<scan flaged args\><<<
if( (int) strlen( argv[i] ) == 2 ){
   if( (*(p+1)!='i')  && (*(p+1) != 'p') )        
     { if( ++i == argc ) bad_arg; }
   q = argv[i]; 
} else q = p+2;
switch( *(p+1) ){
  case 'd':{ dir = q;  break; }
  case 'e':{ `<get .env directory from com ln`> break; }
  case 'i':{ debug = q-1;  break;}
  case 'm':{ ch_mod = q;  break; }
  case 'p':{ nopict = q-1;  break;}
  case 'S':{ `<permission for system calls`> break; }
  case 'X':{ Xrecord = q;  break;}
   default:{ bad_arg;  }
}
>>>



\Section{Loading Style for htf Fonts}

\SubSection{Loading from a Style File}


\<htfcss from lg\><<<
{                     struct htf_struct *last_rec, *p;
   last_rec = (struct htf_struct *) 0;
   eoln_ch = (int) 'x';
   while( eoln_ch != EOF ) {              
      status = scan_str("htfcss: ", TRUE, lg_file);
      status = scan_until_end_str("", 1, status, lg_file);
      if( status ){                          Q_CHAR *key, *body;
         body = key = match[1];  
         `<process htfcss line`>
   }  }
}
>>>


\<process htfcss line\><<<
while( *body && (*body != ' ') ){ body++; }
if( *body == ' ' ){ *(body++) = '\0'; }
if( *body ){  
  if( *key ){ `<add new htfcss rec`> }
  else if( last_rec ){ `<append prev htfcss rec`> }
}
>>>

\<add new htfcss rec\><<<
p = m_alloc(struct htf_struct, 1);
p->next =  (struct htf_struct *) 0;
p->key =   m_alloc(char, (int) strlen(key) + 1);
(IGNORED) strcpy( p->key, key );
p->body =   m_alloc(char, (int) strlen(body) + 1);
(IGNORED) strcpy( p->body, body );
if( last_rec ){
   last_rec->next = p;  last_rec = p;
} else {
   htf_rec = last_rec = p;
}
if( debug ){
   (IGNORED) printf(".......%s...%s\n", key, body);
}
>>>

\<append prev htfcss rec\><<<
last_rec->body = (Q_CHAR *)  r_alloc((void *) last_rec->body,
      (size_t) strlen(last_rec->body) 
    + (size_t) strlen(body) 
    + 2);
(IGNORED) strct(last_rec->body,"\n");
(IGNORED) strct(last_rec->body,body);
if( debug ){
   (IGNORED) printf(".......%s\n", body);
}
>>>



  
\<defines\><<<
struct htf_struct{
  Q_CHAR *key,  *body;
  struct htf_struct *next;
};
>>>

\<vars\><<<
static struct htf_struct *htf_rec = (struct htf_struct *) 0;
>>>



\SubSection{From lg File}


The command \`'\Configure{htf-css}{cmmi}{font-style: italic;}'
provides in the lg file an entry of the form 
\`'Font_Css_Plus cmmi font-style: italic;'.

\<font=(...) from lg\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {              
   status = scan_str("Font_Css_Plus ", TRUE, lg_file);
   status = scan_until_str(" ", 1, status, lg_file);
   status = scan_until_end_str("", 2, status, lg_file);
   if( status ){                          Q_CHAR *key;
      key = match[1];  
      *(key + (int) strlen(key) - 1) = '\0';
      `<store font style of lg`>
} } 
>>>



\<store font style of lg\><<<
if( (*key != '\0') && (*key != '\n') ) { 
                            struct htf_struct *p;    
   p = m_alloc(struct htf_struct, 1);
   p->next =  htf_rec;  
   htf_rec = p;
   p->key =   m_alloc(char, (int) strlen(key) + 1);
   (IGNORED) strcpy( p->key, key );
   p->body =   m_alloc(char, (int) strlen(match[2]) + 1);
   (IGNORED) strcpy( p->body, match[2] );
   if( debug ){
      (IGNORED) printf(".......%s...%s\n", key, match[2]);
} }
>>>







\Section{Identify the Empty Pictures}


Messages about figures that don't exist are treated as requests for
empty figures. Typically, they shouldn't be present unless they are
programmed into \''\setbox'-like commands. tex4ht-c identifies in the
\''.lg' file the empty figures it finds.

The messages in the ``.lg'' file look like
\`'--- empty picture --- aa.idv[1] ---'.



\<identify the empty pictures\><<<
{                             struct empty_pic_struct *last;    
   last = empty_pic = (struct empty_pic_struct *) 0;
   while( TRUE ) {              
      status = scan_str("--- empty picture --- ", TRUE, lg_file);
      status = scan_until_str( ".idv[" , 1, status, lg_file);
      status = scan_until_end_str("] ---", 1, status, lg_file);
      if( status ){ `<add empty pic`> } 
      if ( eoln_ch == EOF ){ break; }      
   }
   `<add empty pic`>
   last->next = (struct empty_pic_struct *) 0;
   last->n = 100000;    
}
>>>


\<add empty pic\><<<
if( last == (struct empty_pic_struct *) 0 ){
   last = empty_pic = (struct empty_pic_struct *) 
                   m_alloc(struct empty_pic_struct, (int) 1);   
} else { 
   last = last->next = (struct empty_pic_struct *) 
                   m_alloc(struct empty_pic_struct, (int) 1);   
}
last->next = (struct empty_pic_struct *) 0;
last->n = get_long_int(match[1]);    
>>>


\<main's vars\><<<
struct empty_pic_struct *empty_pic;    
>>>
  
\<defines\><<<
struct empty_pic_struct{
  long int n;
  struct empty_pic_struct *next;
};
>>>



The list of empty pictures is stored in \`'emptypic'.

\Section{Process Gifs}

\Verbatim
l. 10 --- needs --- ignore ---
l. 11 --- needs --- end ignore ---
--- needs --- aa.idv[80] ==> aa79x.gif ---
--- characters ---
\EndVerbatim

\<process gif's\><<<
{                               BOOL characters, skip;
   characters = skip = FALSE;
   while( TRUE ) {              
      status = scan_until_str("--- ", 1, TRUE, lg_file);
      status = scan_until_str( " ---" , 2, status, lg_file);
      if( status ) {
        if( eq_str(match[1],"--- ") ){
           if( eq_str(match[2],"needs ---") ){
                `<--- needs ---...`>
           } else if( eq_str(match[2],"characters ---") ){
              `<--- characters ---...`>
           } else { `<--- ??? ---...`> }
        } else { `<???--- needs ---...`> }
      }
      if ( eoln_ch == EOF ){ break; }      
   }
}
>>>


\<--- ??? ---...\><<<
status = scan_until_end_str("", 1, status, lg_file);
>>>

\<???--- ??? ---...\><<<
status = scan_until_end_str("", 1, status, lg_file);
>>>


\<--- characters ---...\><<<
status = scan_until_end_str("", 1, status, lg_file);
characters = eq_str(match[1],"");
>>>


\SubSection{Identifying the requests}



\<--- needs ---...\><<<
status = scan_until_str(" ", 1, status, lg_file);
status = scan_until_str(".idv", 1, status, lg_file);
status = scan_until_str("[", 2, status, lg_file);
status = scan_until_str("] ==> ", 2, status, lg_file);
status = scan_until_str(" ", 3, status, lg_file);
   *(match[3] + (int) strlen(match[3]) - 1) = '\0';
status = scan_until_end_str("---", 4, status, lg_file);
if( status ) {
               long int gif_i;
               Q_CHAR *p;
   gif_i = get_long_int(match[2]);
   p = match[2];  
   *(p + (int) strlen(p) - 6) = '\0';
   if( characters ){
      `<translate symbol gifs`>
   } else { `<translate non-symbol gifs`> }
}
>>>


\SubSection{General Pictures}


\`'--- needs --- aa.idv[80] ==> aa79x.gif ---'

\<translate non-symbol gifs\><<<
if( gif_i == `<empty picture`> ) {
  `<insert empty picture`>
} else { `<insert non-empty picture`> }
>>>


\<insert non-empty picture\><<<
if( !nopict && !skip ){
   `<dvi into gif`>
}
>>>


\<insert empty picture\><<<
if( !skip ){
   (void) execute_script(empty_fig_script,
                           dir? dir :"", match[3],"","");
   if( ch_mod && !system_return ){
     (void) execute_script(chmod_script, ch_mod, 
                           dir?dir:"",match[3], "");
   }
}
empty_pic = empty_pic->next; 
>>>



\<empty picture\><<<
empty_pic->n
>>>



\SubSection{Pictorial Symbols}


\<translate symbol gifs\><<<
                  Q_CHAR filename[255];
                  FILE* file;
(IGNORED) strcpy(filename, "");
if( dir ){ (IGNORED) strct(filename, dir); }
(IGNORED) strct(filename, match[3]);
file  = fopen(filename, READ_TEXT_FLAGS);  
if( !file ){
   `<dvi symbols into gif`>
} else { 
   (IGNORED) fclose(file);  
   (IGNORED) printf("%s already in %s\n", match[3], 
                           dir? dir : "current directory" );
}
>>>



\SubSection{The Conversion Code}


\<dvi into gif\><<<
(void) execute_script(dvigif_script,match[1],match[2],match[3],"");
if( dir && !system_return ){
  (void) execute_script(move_script,match[3],dir,".","");
}
if( ch_mod && !system_return ){
  (void) execute_script(chmod_script, ch_mod, dir?dir:"",match[3], "");
}
>>>

\<dvi symbols into gif\><<<
(void) execute_script(dvigif_glyp_script? 
   dvigif_glyp_script : dvigif_script,match[1],match[2],match[3],"");
if( dir && !system_return ){
  (void) execute_script(move_script,match[3],dir,".","");
}
if( ch_mod && !system_return ){
  (void) execute_script(chmod_script, ch_mod, dir?dir:"",match[3], "");
}
>>>



\ifHtml[\HPage{more}\Verbatim
> But isn't there a downside to this?  If you work with -d  then indeed all
> necessary files are transferred (and this may be a good thing).  But on the
> other hand, it looks to me as if you lose ALL efficiency in re-making the
> gifs: that is, if you re-run tex4ht with the -d option in htcmd, then all
> gifs are re-made (even the glyph-gifs) every time, whether they exist in
> the current directory, the directory pointed to, by -d, or both.

I'll have to recheck the behavior of htcmd, because from the above
description it looks like the fixed htcmd doesn't do the right job.

The -d flag should specify a target directory, where the output html
and gif files are to be stored. If not given, the work directory is
taken to be the target directory. htcmd should compile a new glyph-gif
only if the gif does not already exist in the target directory.  That
is, the glyph-gifs should be created the first time they are needed in
the target directory, but not in consecutive compilations.


 > files; my point is that at least for the glyph-gifs this isn't needed,
 > since (if I understand correctly) any time that tex4ht asks for (eg)
 > cmex10-21.gif it will always represent the same character, no matter what
 > TeX document is being processed. (If this is wrong, then my whole theory
 > collapses). 

The understanding is correct.

 > So it would make sense --- and also be space-efficient, since the glyph-gif
 > files tend to be tiny, on the order of 500 bytes, while the .ps files can
 > be quite a bit larger especially if a complicated re-encoding vector needs
 > to be included --- to check first in some central location to see if this
 > glyph-gif has already been make, and if so, to just copy it into the
 > current directory.  That's the essence of my FLIB suggestion.

I placed a newer version of htcmd on the web. It allows to specify in
tex4ht.env a F-script (similar to the G-script) for translating glyphs
into gifs.  If the F-script is not provided, the glyphs are to be
translated to gifs under the G-script.

-eitan




Example
========
 A version of
\Link[\shareHOME htcmd.c]{}{}htcmd.c\EndLink{} with a time stamp of at least
1998-11-20-13-18 is required for resolving a bug in a detection
mechanism that {\bf checks for existing gifs of glyphs} before
creating new ones.

A version with a time stamp of at least 1998-11-23-17-30 allows
also the use of
specialized F-scripts for translating glyphs into gifs, instead
of the general purpose G-scripts found in \''tex4ht.env'. (The 
new scripts may maintain global caches of such gifs for
cutting down on recompilation time.)
%
% 
% Scripts within tex4ht.env
% -------------------------
% 
% GDEL tmp.ps
% Gdvips -mode ibmvga -D 110 -f %%1 -pp %%2  -o tmp.ps
% GDEL %%3
% Gconvert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps %%3
% Fglyphgif %%1 %%2 %%3
% 
% File glyphgif.bat
% -----------------
% 
% if exist c:/cache/%3
% COPY c:/cache/%3 %3 
% goto done
% DEL tmp.ps
% dvips -mode ibmvga -D 110 -f %1 -pp %2  -o tmp.ps
% DEL %3
% convert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps %3
% COPY %3 c:/cache/%3
% :done
%

\EndVerbatim\EndHPage{}]\fi
























\<header functions\><<<
static void execute_script( 
  ARG_V(struct script_struct*,Q_CHAR *,char *,Q_CHAR *,Q_CHAR *) );
>>>

\<functions\><<<
`[
static void execute_script(script,match_1,match_2,match_3,match_4)  
                    struct script_struct* script`;
                    Q_CHAR * match_1`;
                    Q_CHAR * match_2`;
                    Q_CHAR * match_3`;
                    Q_CHAR * match_4

;{                               struct script_struct* temp;
                                 Q_CHAR *p, *q, *t;
   temp = script;  system_return = 0;
   while( temp ){
      `<command = temp-command`>
      if( (command[0] != '\0') && !system_return ){
         `<execute system command`> }
      temp = temp->next;
}  }
>>>


We went to \`'%%%', \`'%%1', ... instead of  \`'%%', \`'%1', ... 
to accomodate some needds of dos.  Example (yet, where exactly the
conflict is?):

\Verbatim
if exist %1.dvi goto yes_dvi
goto end
yes_dvi:
DEL tmp.ps
call dvips32  -f %1 -p %2 -l %2 -o tmp.ps  -mode ibmvga -D 110
DEL %3
call convert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps %3
end:
\EndVerbatim



\<command = temp-command\><<<
p = temp->command;
q = command;
while( *p != '\0' ){
  *q = *(p++);
  if( (*q == '%') && (*p == '%') 
     && ((*(p+1) == '%')  || ( (*(p+1) > '0') && (*(p+1) < '5') ) )
  ){  p++;
    switch( *(p++) ){
      case '%':{  q++; break; }
      case '1':{  t = match_1;
            while( *t != '\0' ){ *(q++) = *(t++); }  break; }
      case '2':{  t = match_2;
            while( *t != '\0' ){ *(q++) = *(t++); }  break; }
      case '3':{  t = match_3;
            while( *t != '\0' ){ *(q++) = *(t++); }  break; }
      case '4':{  t = match_4;
            while( *t != '\0' ){ *(q++) = *(t++); }  break; }
      default: {  }
  }} else { q++; }
}
*q = '\0';
>>>







\Verbatim

>  > help tinkering with the code.  If you'll have a chance at some
>  > point to pass on the kind of changes you are doing, I'll be interested
>  > to hardwire them in the code as compile/run-time options.
> for instance, I add -Pem to the dvips command line to access the EM
> fonts instead of EC (faster)
> 
> i also change the name of "convert.exe" to "iconvert.exe" because it
> conflicts with a native NT utility to convert file systems :-}

\EndVerbatim

\Verbatim
dvips -mode $mf -D $density -f $_[0] -pp $_[1] > tmp.ps
\EndVerbatim

\<defines\><<<      
#ifndef HTFDIR
#define HTFDIR      ""
#endif
>>>





Was \''dvips -f $_[0] $magnification -pp $_[1] > tmp.ps'

\ifHtml[\HPage{more}\Verbatim
> Before you investigate too much time let me tell you that this is
> definitely not a problem of tex4ht or the generation process. It's
> just the rare case that someone (me ;-) ) uses too small fonts which
> fail to render at resolution 110 dpi. As I'm an HTML writer it was
> easier to solve the problem in HTML than to change the .tex file.

My guess this problem should be trivial to fix, just by changing the
values of

    $density = "110";    $mf = "ibmvga";

in the perl script, to another pair of values in compliance with those
available through the `modes.mf' file.   These values are sent 
to dvips, which in turn calls Metafont to create the fonts.

I'll be interested to introduce a switch in the command line, for
requesting such a change on a global and/or local basis.  My interest
in your file is to get a better understanding of the problem.

\EndVerbatim\EndHPage{}]\fi




A scaling by integer s in dvips, $10 \le s \le 100000$, asks for
magnification of $s/1000$ and it overrides the one specified in the
.dvi file. According to the TeXbook ``you can't use magnification
unless your printing device happens to have the fonts that you need at
magnification you desire''.




\ifHtml[\HPage{more}\Verbatim
>   - Find out what Metafont modes you have available. I found that teTeX
> uses `modes.mf'. In this file, search for a mode with a resolution of
> around 100 dpi. In `modes.mf', applicable modes are e.g. atarins (96
> dpi) and ibmvga (110 dpi). For my tests, I chose ibmvga.

/n/candy/0/tex/teTeX/texmf/metafont/misc/modes.mf

\EndVerbatim\EndHPage{}]\fi







\Verbatim
convert -crop 0x0 -density $density"."x"."$density"
                 ." -transparent #FFFFFF tmp.ps $_[2]"

convert -crop 0x0 -transparent '#'FFFFFF "."$density  tmp.ps $_[2]
\EndVerbatim






\List{*}
\item
NOTE-1: For newer converts. \`'BTW, it looks like the argument is
 -transparent according to the docs I have on convert.  Seems a silly
 change.  But, what useful things one can see in the docs.  '.
 NOTE-2:  input-file-name should be the first ac=fter convert.

\`@         $command = "giftrans -t '#'ffffff tmp.gif > \n";
         if( &system_command($_[2]) ){@

\item Crop removes the edges of the background color, and it should appear 
before that color is made transparent.

\item
The following error occurs when the picture is outside the boundaries
of the page.

\Verbatim
convert   -dither -monochrome tmp.ps tmp.gif
convert: Unable to crop image (geometry does not contain image).
\EndVerbatim
\EndList




\ifHtml[\HPage{quality}
\Link[ftp://204.183.81.131/pub/ImageMagick/www/Magick.html\#C22]{}{}q+a\EndLink
\Verbatim
When I convert Postscript to another format, how can I improve the appearance of the text? 

     Simple. Increase the dots-per-inch when converting and sub-sample: 

    convert -density 288 -geometry 25% image.ps image.gif

Change the density to 144 and geometry to 50% if the above command fails due to insufficient memory. Alternatively, see the Ghostscript
documentation about using high-quality fonts. 

The -density option increases the number of pixels (or dots) generated by Ghostscript when processing the input postscript file.
However as all other images formats are generally displayed on screens which are typically about 72 to 100 dots per inch, the output image
will be larger. 

The -geometry option reduces the large image output of ghostscript image back to a normal 72 dpi resolution (25% of 288 dpi gives 72 dpi)
but in the process anti-aliases (or smooths) the fonts and lines of the image so as to remove the jaggies you would otherwise get from a
normal postscript to image conversion. 

\EndVerbatim\EndHPage{}]\fi
{} --
\ifHtml[\HPage{latex graphics companion 457-459}\Verbatim
gs -dNOPAUSE -q -r100 -s DEVICE=pnm -sOutputFile=-
    -dTextAlphaBits=4 -dGraphicsAlphaBits=4 tmp.ps -c quit |
    ppmtogif  -interlace -transparent \#ffffff > xx.gif
\EndVerbatim\EndHPage{}]\fi
{} --
\ifHtml[\HPage{ppmtogif}\Verbatim
ppmtogif(1)                                                     ppmtogif(1)
                                 30 June 1993

 NAME
      ppmtogif - convert a portable pixmap into a GIF file

 SYNOPSIS
      ppmtogif [-interlace] [-sort] [-map mapfile] [-transparent color]
      [ppmfile]

 DESCRIPTION
      Reads a portable pixmap as input.  Produces a GIF file as output.

 OPTIONS
      -interlace
           Tells the program to produce an interlaced GIF file.

      -sort
           Produces a GIF file with a sorted color map.

      -map mapfile
           Uses the colors found in the mapfile to create the colormap in
           the GIF file, instead of the colors from ppmfile.  The mapfile
           can be any ppm file; all that matters is the colors in it. If the
           colors in ppmfile do not match those in mapfile , they are
           matched to a "best match". A (much) better result can be obtained
           by using the following filter in advance:

           ppmquant -floyd -map mapfile

      -transparent color
           Mark the given color as transparent in the GIF file.  The color
           is specified as in ppmmake(1).  Note that this option outputs a
           GIF89a format file which might not be understood by your
           software.

      All flags can be abbreviated to their shortest unique prefix.

 SEE ALSO
      giftoppm(1), ppmquant(1), ppm(5)

 AUTHOR
      Based on GIFENCOD by David Rowley <mgardi@watdcsu.waterloo.edu>.
      Lempel-Ziv compression based on "compress".
\EndVerbatim\EndHPage{}]\fi
{} --
\ifHtml[\HPage{Ghostscript}\Verbatim
 NAME
      gs - Aladdin Ghostscript interpreter/previewer

 SYNOPSIS
      gs [ options ] [ files ] ...

 DESCRIPTION
      Ghostscript is an implementation of Adobe Systems' PostScript (tm)
      language, which is in turn similar to Forth.  Gs reads files in
      sequence and executes them as Ghostscript programs.  After doing this,
      it reads further input from the standard input stream (normally the
      keyboard).  Each line is interpreted separately.  To exit from the
      interpreter, enter the `quit' command.  The interpreter also exits
      gracefully if it encounters end-of-file.  Typing the interrupt
      character (e.g. Control-C) is also safe.

      The interpreter recognizes several switches described below, which may
      appear anywhere in the command line and apply to all files thereafter.

      You can get a help message by invoking Ghostscript with the -h or -?
      option.  This message also lists the available devices.


      Ghostscript may be built with multiple output devices.  Ghostscript
      normally opens the first one and directs output to it.  To use device
      xyz as the initial output device, include the switch
           -sDEVICE=xyz
      in the command line.  Note that this switch must precede the first .ps
      file, and only its first invocation has any effect.  For example, for
      printer output in a normal configuration that includes an Epson
      printer driver, you might use the shell command
           gs -sDEVICE=epson myfile.ps
      instead of just
           gs myfile.ps
      Alternatively, you can type
           (epson) selectdevice
           (myfile.ps) run
      All output then goes to the printer instead of the display until
      further notice.  You can switch devices at any time by using the
      selectdevice procedure, e.g.,
           (vga) selectdevice
      or
           (epson) selectdevice
  As yet a third alternative, you can define an environment variable
      GS_DEVICE as the desired default device name.  The order of precedence
      for these alternatives, highest to lowest, is:
           selectdevice
           (command line)
           GS_DEVICE
           (first device in build list)

      To select the density on a printer, use

                                    - 1 -       Formatted:  October 11, 1998

 GS(1)                                                                 GS(1)
                              23 September 1996

           gs -sDEVICE=<device> -r<xres>x<yres>
      For example, on a 9-pin Epson-compatible printer, you can get the
      lowest-density (fastest) mode with
           gs -sDEVICE=epson -r60x72
      and the highest-density mode with
           gs -sDEVICE=epson -r240x72.

      If you select a printer as the output device, Ghostscript also allows
      you to control where the device sends its output.  Normally, output
      goes directly to a scratch file on Unix systems.  To send the output
      to a series of files foo1.xyz, foo2.xyz, ..., use the switch
           -sOutputFile=foo%d.xyz
      The %d is a printf format specification; you can use other formats
      like %02d.  Each file will receive one page of output.  Alternatively,
      to send the output to a single file foo.xyz, with all the pages
      concatenated, use the switch
           -sOutputFile=foo.xyz

      On Unix systems, you can send the output directly to a pipe.  For
      example, to pipe the output to the command `lpr' (which, on many Unix
      systems, is the command that spools output for a printer), use the
      switch
           -sOutputFile=\|lpr
      You can also send output to stdout for piping with the switch
           -sOutputFile=-
      In this case you must also use the -q switch, to prevent Ghostscript
      from writing messages to stdout.

      To find out what devices are available, type
           devicenames ==
      after starting up Ghostscript.  Alternatively, you can use the -h or
 after starting up Ghostscript.  Alternatively, you can use the -h or
      -? switch in the command line; the help message also lists the
      available devices.

      To select a different paper size, use the command line switch
              -sPAPERSIZE=a_known_paper_size
      e.g.,
              -sPAPERSIZE=a4
      or
              -sPAPERSIZE=legal
      As of this printing, the known paper sizes, defined in gs_statd.ps,
      are:
           PAPERSIZE    X"         Y"         X cm      Y cm
           -----------------------------------------------------
      11x17        11"        17"        27.94     43.18
      a0           33.0556"   46.7778"   83.9611   118.816
      a10          1.02778"   1.45833"   2.61056   3.70417
      a1           23.3889"   33.0556"   59.4078   83.9611
      a2           16.5278"   23.3889"   41.9806   59.4078
      a3           11.6944"   16.5278"   29.7039   41.9806

      a4           8.26389"   11.6944"   20.9903   29.7039
      a5           5.84722"   8.26389"   14.8519   20.9903
      a6           4.125"     5.84722"   10.4775   14.8519
      a7           2.91667"   4.125"     7.40833   10.4775
      a8           2.05556"   2.91667"   5.22111   7.40833
      a9           1.45833"   2.05556"   3.70417   5.22111
   archA        9"         12"        22.86     30.48
      archB        12"        18"        30.48     45.72
      archC        18"        24"        45.72     60.96
      archD        24"        36"        60.96     91.44
      archE        36"        48"        91.44     121.92
      b0           39.3889"   55.6667"   100.048   141.393
      b1           27.8333"   39.3889"   70.6967   100.048
      b2           19.6944"   27.8333"   50.0239   70.6967
      b3           13.9167"   19.6944"   35.3483   50.0239
      b4           9.84722"   13.9167"   25.0119   35.3483
      b5           6.95833"   9.84722"   17.6742   25.0119
      flsa         8.5"       13"        21.59     33.02
      flse         8.5"       13"        21.59     33.02
      halfletter   5.5"       8.5"       13.97     21.59
      ledger       17"        11"        43.18     27.94
      legal        8.5"       14"        21.59     35.56
      letter       8.5"       11"        21.59     27.94
      note         7.5"       10"        19.05     25.4

 INITIALIZATION FILES
   When looking for the initialization files (gs_*.ps), the files related
      to fonts, or the file for the `run' operator, Ghostscript first tries
      opening the file with the name as given (i.e., using the current
      working directory if none is specified).  If this fails, and the file
      name doesn't specify an explicit directory or drive (i.e., doesn't
      begin with `/' on Unix systems), Ghostscript will try directories in
      the following order:

      1.   The directory/ies specified by the -I switch(es) in the command
           line (see below), if any;

      2.   The directory/ies specified by the GS_LIB environment variable,
           if any;

      3.   The directory/ies specified by the GS_LIB_DEFAULT macro in the
           Ghostscript makefile (which has been set to
           "/usr/local/share/ghostscript/M.N:/usr/local/share/ghostscript/fonts"
           where M.N is the Ghostscript version number).

      Each of these (GS_LIB_DEFAULT, GS_LIB, and -I parameter) may be either
      a single directory, or a list of directories separated by a `:'.

 X RESOURCES
      Ghostscript looks for the following resources under the program name
      `Ghostscript':

      borderWidth
           The border width in pixels (default = 1).

      borderColor
           The name of the border color (default = black).

      geometry

                                    - 3 -       Formatted:  October 11, 1998

 ()                                                                       ()

           The window size and placement, WxH+X+Y (default is NULL).

      xResolution
           The number of x pixels per inch (default is computed from
           WidthOfScreen and WidthMMOfScreen).

      yResolution
           The number of y pixels per inch (default is computed from
         The number of y pixels per inch (default is computed from
           HeightOfScreen and HeightMMOfScreen).

      useBackingPixmap
           Determines whether backing store is to be used for saving display
           window (default = true).

      See the file `use.txt' for a more complete list of resources.

      To set these resources, put them in a file (such as ~/.Xresources) in
      the following form:

                Ghostscript*geometry: 612x792-0+0
                Ghostscript*xResolution: 72
                Ghostscript*yResolution: 72

      Then load the defaults into the X server:

                % xrdb -merge ~/.Xresources

 OPTIONS
      -- filename arg1 ...
           Takes the next argument as a file name as usual, but takes all
           remaining arguments (even if they have the syntactic form of
           switches) and defines the name ARGUMENTS in userdict (not
           systemdict) as an array of those strings, before running the
           file.  When Ghostscript finishes executing the file, it exits
           back to the shell.

      -Dname=token
      -dname=token
           Define a name in systemdict with the given definition.  The token
           must be exactly one token (as defined by the `token' operator)
           and must not contain any whitespace.

      -Dname
      -dname
           Define a name in systemdict with value=null.

      -Sname=string
      -sname=string
           Define a name in systemdict with a given string as value.  This
           is different from -d.  For example, -dname=35 is equivalent to
           the program fragment

                                           /name 35 def
           whereas -s name=35 is equivalent to
                                           /name (35) def

      -q   Quiet startup - suppress normal startup messages, and also do the
           equivalent of -dQUIET.

      -gnumber1xnumber2
           Equivalent to -dDEVICEWIDTH=number1 and -dDEVICEHEIGHT=number2.
           This is for the benefit of devices (such as X11 windows) that
           require (or allow) width and height to be specified.

      -rnumber
      -rnumber1xnumber2
           Equivalent to -dDEVICEXRESOLUTION=number1 and
           -dDEVICEYRESOLUTION=number2.  This is for the benefit of devices
           (such as printers) that support multiple X and Y resolutions.
           (If only one number is given, it is used for both X and Y
           resolutions.)

      -Idirectories
           Adds the designated list of directories at the head of the search
           path for library files.

      -    This is not really a switch.  It indicates to Ghostscript that
           the standard input is coming from a file or a pipe.  Ghostscript
           reads from stdin until reaching end-of-file, executing it like
           any other file, and then continues processing the command line.
           At the end of the command line, Ghostscript exits rather than
           going into its interactive mode.

      Note that gs_init.ps makes systemdict read-only, so the values of
      names defined with -D/d/S/s cannot be changed (although, of course,
      they can be superseded by definitions in userdict or other
      dictionaries.)

 SPECIAL NAMES
      -dDISKFONTS
           Causes individual character outlines to be loaded from the disk
           the first time they are encountered.  (Normally Ghostscript loads
           all the character outlines when it loads a font.)  This may allow
           loading more fonts into RAM, at the expense of slower rendering.

      -dNOCACHE

       Disables character caching.  Only useful for debugging.

      -dNOBIND
           Disables the `bind' operator.  Only useful for debugging.

      -dNODISPLAY
           Suppresses the normal initialization of the output device.  This

                                    - 5 -       Formatted:  October 11, 1998

 ()                                                                       ()

           may be useful when debugging.

      -dNOPAUSE
           Disables the prompt and pause at the end of each page.  This may
           be desirable for applications where another program is `driving'
           Ghostscript.

      -dNOPLATFONTS
           Disables the use of fonts supplied by the underlying platform
           (e.g. X Windows).  This may be needed if the platform fonts look
           undesirably different from the scalable fonts.

      -dSAFER
           Disables the deletefile and renamefile operators, and the ability
           to open files in any mode other than read-only.  This may be
           desirable for spoolers or other sensitive environments.

      -dWRITESYSTEMDICT
           Leaves systemdict writable.  This is necessary when running
           special utility programs such as font2c and pcharstr, which must
           bypass normal PostScript access protection.

      -sDEVICE=device
           Selects an alternate initial output device, as described above.

      -sOutputFile=filename
           Selects an alternate output file (or pipe) for the initial output
           device, as described above.

 FILES
      /usr/local/share/ghostscript/M.N/*
           Startup-files, utilities, and basic font definitions.

      /usr/local/share/ghostscript/fonts/*

      -sOutputFile=filename
           Selects an alternate output file (or pipe) for the initial output
           device, as described above.

 FILES
      /usr/local/share/ghostscript/M.N/*
           Startup-files, utilities, and basic font definitions.

      /usr/local/share/ghostscript/fonts/*
           Additional font definitions.

      /usr/local/share/ghostscript/M.N/examples/*
           Demo Ghostscript files.

      /usr/local/share/ghostscript/M.N/doc/*
           Assorted document files.

 ENVIRONMENT
      GS_OPTIONS
           String of options to be processed before the command line
           options.

      GS_DEVICE
           Used to define the device used.

      GS_FONTPATH
()                                                                       ()

           Path names used to search for fonts

      GS_LIB
           Path names for initialization files and fonts

      TEMP Where temporary files are made

 SEE ALSO
      The various Ghostscript document files (above).

 BUGS
      See the network news group `comp.lang.postscript'.

\EndVerbatim\EndHPage{}]\fi
{} --
\Link[http://www.fourmilab.ch/webtools/textogif/textogif.html]{}{}dvi to
gif (John Walker)
\EndLink{} --
\ifHtml[\HPage{more}\Verbatim
I tried to get a feel of how ppm behaves on pc's, using the attached
script.  The script works fine for me, if I hand insert the commands
one by one in a sequence.  However, if I put the script in a .bat file
and call it, ppmtogif jumps in before gswin32 ends its job.  

If the problem is trivial to fix, I'll appreciate your advice.
Otherwise, please ignore this email. 

-eitan




if exist tmp.ps DEL tmp.ps 
if exist tmp.ppm DEL tmp.ppm
if exist tmp.gif DEL tmp.gif
c:\texlive3\tex\bin\win32\dvips.exe  -f vii.idv -pp 1  -o tmp.ps  
c:\texlive3\gs\gs5.10\gswin32.exe  -Ic:\texlive3\gs\gs5.10  -dbatch  -dNOPAUSE -sDEVICE=ppm -sOutputFile=tmp.ppm -q  -c  -dquit  tmp.ps 
c:\src\netpbm\miktex\bin\ppmtogif   tmp.ppm    tmp.gif
dir tmp*

\EndVerbatim\EndHPage{}]\fi {} --
\ifHtml[\HPage{dvips + gs}\Verbatim
#!/bin/sh
dvitogif ()
{
  density=100
  T=/tmp/`basename $2 .dvi`.ps
  O=`basename $2 .dvi`_$1.gif
#  dvips -h bullet.pro -h name.pro -h border.pro -pp $1 $2 > $T
  dvips -h bullet.pro -pp $1 $2 > $T
  gs -q -r$density -sDEVICE=ppm -sOutputFile=- $T <&- |
                  pnmcrop | ppmtogif -transparent rgbi:1.0/1.0/1.0 > $O
  rm $T
}
for i in 1 2 3 4 ; do
  dvitogif $i resume
done


\EndVerbatim\EndHPage{}]\fi{} --
\ifHtml[\HPage{cropping}\Verbatim

> but how
> could you crop the image without knowing the size of it ? Do you include such
> informations, at least I don't see you using it in your scripts.

I can't locate any reference, but I believe convert is set to crop white
margins.

pnmcrop trims white margins in the default setting, and has a command
line switch to request trimming of black margins (pnmcrop -h).


\EndVerbatim\EndHPage{}]\fi {} --
\ifHtml[\HPage{more}\Verbatim
Script for ps2gif:
     #!/bin/sh
     #ps2gif script by Ian Hutchinson 1997; use at your own risk.
     #You need Ghostscript and the pbmplus utilities installed. 
     if [ $# != 2 ] ; then
     echo " Usage: $0 " 1>&2
     exit 1
     else 
     echo "Calling ghostscript to convert, please wait ..." >&2
     gs -sDEVICE=ppm -sOutputFile=- -sNOPAUSE -q $1 -c showpage -c quit | 
     pnmcrop| pnmmargin 10 | ppmtogif >$2
     fi


Script for antialiased gif files:
     gs -q -dNOPAUSE -dSAFER -sDEVICE=ppmraw -r360x360 -sOutputFile=- INPUTFILE.ps | \
     pnmscale 0.2 | ppmquant 256 | ppmtogif > OUTPUTFILE.gif 

     The basic idea in UNIX is to make gif files via something like
     gs -q -dNOPAUSE -dSAFER -sDEVICE=ppmraw -sOutputFile=- - | ppmtogif

     The former code works well for me, with 72dpi screen resolution. For 100dpi screen resolution, try
     the setting 500x500. The scale operation does the anti-aliasing. Multiple page postscript is dealt
     with via "%" expansions in the outputfilename, followed by a loop to do the rest of the pipeline
     for each image. 

pstoepsi: Script that with -bbonly option places a BoundingBox comment in your PostScript file. 


Image Magick: free C/C++ source code for ps2jpg conversion. Needs and uses ghostscript for the
     conversions. 



psutils: a set of useful utilities for multipage PostScript documents, including psresize (alter page
     size), psselect (select pages), pstops (rearrangement), psnup (many pages to one), psbook (pages
     into signatures), epsffit (fts to bounding box)
          psutils source code 
          Download psutils source code via ftp 
          Download psutils source code via ftp 
          MSDOS executable for psutils 
          MSDOS executable for psutils from CTAN mirror site psutils: a set of useful utilities for multipage PostScript documents, including psresize (alter page
     size), psselect (select pages), pstops (rearrangement), psnup (many pages to one), psbook (pages
     into signatures), epsffit (fts to bounding box)
          psutils source code 
          Download psutils source code via ftp 
          Download psutils source code via ftp 
          MSDOS executable for psutils 
          MSDOS executable for psutils from CTAN mirror site 



Peter Kleiweg's PostScript utilities: It includes a GNU emacs set-up for editing PostScript files,
     ps2ppm, a font2ps C program, psselect and pspages (C programs for separating pages and adding
     page info in PostScript files), and other goodies. 


Converting PostScript to Pixelmap 
onverting PostScript to Pixelmap

ps2ppm (© P. Kleiweg) is a Perl5 script for converting PostScript to color images such as GIF. It works
under Unix, using ghostscripthttp://odur.let.rug.nl/~kleiweg/postscript/utils.html


 3.2 How can I convert PostScript to a bitmap or pixmap? 

    Use Ghostscript, and build the devices under gs pbmraw, pbm.dev, 
    etc. (See devs.mak under the sources for gs) The following converts 
    file.ps in file.ppm: 

    gs -sDEVICE=ppmraw -sOutputFile=file.ppm file.ps 

    Or try using the Ghostscript tools ps2image.ps or pstoppm.ps. Or 
    use the NETPBM tool pstopnm. Netpbm (a descendant of the PBMPLUS 
    utilities) can then convert that image into whatever format you 
    want. 

    You can also use the ImageMagick-tools program ``convert''. Try 
    ftp.x.org in contrib/ImageMagick.tar.Z. 

    If you have the new xv installed, it can now read PostScript files, 
    and it stores them to any format. 



You can use the ppmtogif program (part of the Unix libgr-progs
     package) to create a set of GIF's with identical color tables. Merging them
     with GIFMerge creates an animated GIF with identical color maps in one
     GIF. In this case, use gifstrip.




# External programs needed
# ------------------------
$gs         = "gs";
$tmpdir     = ".";
$tmpppmfile = "$tmpdir/pstoeps$$.ppm";
$tmppsfile  = "$tmpdir/pstoeps$$.ps";
$gsargs     = "-q -sDEVICE=ppmraw -r72 -dNOPAUSE -dSAFER -sOutputFile=$tmpppmfile --";
$pnmfile    = "pnmfile";
$pnmcrop    = "pnmcrop";


    # Run pnmcrop to get information about empty space.
    # We need to capture sdterr for that.  It requires a shell, so this may
    # fail on systems which don't have one.


Encapsulated PostScript (EPS) files
\EndVerbatim\EndHPage{}]\fi
\ifHtml[\HPage{more}\Verbatim
The \`'-mode ibmvga -D 110' flags of the dvips command, within tex4ht.env,
are provided to control the quality of the bitmaps produced for the
pictures.  Users might find other values to fit better their needs.

The \''ibmvga' mode is tailored for resolution of 110 dots per inch;
the characteristics of that mode are shown in the file modes.mf of
Metafont.  If the switch \`'-mode ibmvga' is omitted, a mode is
guessed from the resolution, with the outcome likely to be degrades a
little.


I'm trying to get dvips to use a non-standard configuration file (instead of 
the default config.pls which is by default set up to use the ljfour 
printer) under MiKTeX 1.11 under win nt 4.  Specifically, I'd like it to call 
metafont to generate some fonts in ibmvga mode (110x110 dpi) for use with 
Eitan Gurari's tex4ht. 

I can get it to run metfont correectly only if I alter the standard config.ps 
and change the printer name from "ljfour" to "ibmvga" and the dpi value from 
600 to 110. So dvips and metafont seem to be set up correctly. But I'd 
like to be able to do this with a job-specific configuration file, 
while retaining the settings in the default config.

My understanding of the dvips documentation says that if I create a file 
config.ibmvga and call dvips with the parameter -P ibmvga, it should find that 
file and over-ride config.ps.  I've tried this, but  I can't get this to 
work. Questions:

1. is my understanding correct? -P ibmvga should cause dvips to look for 
config.ibmvga?

2. is this file supposed to be anywhere special?  (I've been putting it in the 
same directory as config.ps). 

Thanks for any help on this!

Philip A. Viton
------------------
City Planning, Ohio State University
pviton@magnus.acs.ohio-state.edu



From piet@cs.uu.nl Wed Oct 28 12:36:50 EST 1998
Article: 151256 of comp.text.tex
Path: news.cse.ohio-state.edu!news.maxwell.syr.edu!news-ge.switch.ch!surfnet.nl!ruu.nl!cs.uu.nl!not-for-mail
From: Piet van Oostrum <piet@cs.uu.nl>
Newsgroups: comp.text.tex
Subject: Re: dvips config under miktex/win nt
Date: 28 Oct 1998 16:16:19 +0100
Organization: Dept of Computer Science, Utrecht University, The Netherlands
Lines: 40
Sender: piet@kemmel.cs.uu.nl
Message-ID: <wz4ssora2k.fsf@kemmel.cs.uu.nl>
References: <pviton.462.000A039F@magnus.acs.ohio-state.edu>
NNTP-Posting-Host: kemmel.cs.uu.nl
X-Newsreader: Gnus v5.4.62/Emacs 19.34
Xref: news.cse.ohio-state.edu comp.text.tex:151256

>>>>> pviton@magnus.acs.ohio-state.edu (Philip A. Viton) (PAV) writes:

PAV> I'm trying to get dvips to use a non-standard configuration file
PAV> (instead of the default config.pls which is by default set up to use
PAV> the ljfour printer) under MiKTeX 1.11 under win nt 4. Specifically,
PAV> I'd like it to call metafont to generate some fonts in ibmvga mode
PAV> (110x110 dpi) for use with Eitan Gurari's tex4ht.

PAV> I can get it to run metfont correectly only if I alter the standard
PAV> config.ps and change the printer name from "ljfour" to "ibmvga" and
PAV> the dpi value from 600 to 110. So dvips and metafont seem to be set up
PAV> correctly. But I'd like to be able to do this with a job-specific
PAV> configuration file, while retaining the settings in the default
PAV> config.

PAV> My understanding of the dvips documentation says that if I create a
PAV> file config.ibmvga and call dvips with the parameter -P ibmvga, it
PAV> should find that file and over-ride config.ps. I've tried this, but I
PAV> can't get this to work. Questions:

PAV> 1. is my understanding correct? -P ibmvga should cause dvips to look for 
PAV> config.ibmvga?

Yes.

PAV> 2. is this file supposed to be anywhere special? (I've been putting it
PAV> in the same directory as config.ps).

Yes.

BUT: for the mode to be correct you have to insert a line M ibmvga in the
file config.ibmvga.



From cottrell@ricardo.ecn.wfu.edu Thu Oct 29 00:34:02 EST 1998
Organization: Wake Forest University

> 1. is my understanding correct? -P ibmvga should cause dvips to look for
> config.ibmvga?

Yes.

> 2. is this file supposed to be anywhere special?  (I've been putting it in the
> same directory as config.ps).

In the same directory as config.ps ought to work (and it does with
web2c, which is ported to win32).  There might be some special
command required to rebuild the database of configuration files,
after you add a new one.  I suppose this would be mentioned in the
MikTeX documentation.

-- 
Allin Cottrell
Department of Economics
Wake Forest University, NC


-P printername
              Sets up the output for the appropriate  printer.
              This    is   implemented   by   reading   in   con-
              fig.printername , which can  then  set  the  output
              pipe (as in, !lpr -Pprintername as well as the font
              paths and any other  config.ps  defaults  for  that
              printer  only.   Note that config.ps is read before
              config.printername In addition, another file called
              ~/.dvipsrc  is  searched for immediately after con-
              fig.ps; this file is intended  for  user  defaults.
              If no -P command is given, the environment variable
              PRINTER is checked.  If that variable exists, and a
              corresponding  configuration file exists, that con-
              figuration file is read in.
\EndVerbatim\EndHPage{}]\fi{} --
\ifHtml[\HPage{more}\Verbatim
> - how to automate conversion from TeX source to EPS and various bitmap
> formats

This is trivial with a script (.BAT) file:

   latex $1.tex
   dvips -E -o $1.eps %1.dvi
   gs -sDEVICE=foo -sOutputFile=%1.foo -q %1.eps

You can add various footoppm and pnmtofoo commands, and things like 
giftrans.
\EndVerbatim\EndHPage{}]\fi{} --
\ifHtml[\HPage{in latex2html}\Verbatim
postscript image with ghostview and to grab the
image with xv. The grabbed image can be modified with xv and can be stored in GIF format. Another
method is to use ghostscript. Here is an example for an image conversion with ghostscript. 

                gs file.ps
                gs> (file) ppm24run
                gs> quit
                ppmtogif file.ppm >file.gif
                rm file.ppm
\EndVerbatim\EndHPage{}]\fi{} --
\ifHtml[\HPage{delegate.mgk}\Verbatim
# ImageMagick delegates for Unix.  The format is as follows.  Each
# delegate begins with a tag and/or format separated by a operation
# tag (see below).  This line must be followed by one or more commands
# preceded with a tab (\t) character.  If a command exceeds the length
# of a line, use the backslash continuation character.  End the
# command with an ampersand (&) to execute the command in the
# background.
#
# Optionally you can include the image filename, type, width, height, or
# other image attributes by embedding special format characters=>
# 
#   %b   file size
#   %d   directory
#   %e   filename extention
#   %f   filename
#   %h   height
#   %l   label
#   %m   magick
#   %p   page number
#   %s   scene number
#   %t   top of filename
#   %u   unique temporary filename
#   %w   width
#   %x   x resolution
#   %y   y resolution
# 
# There are two types of delegates: decode and encode.  Decode delegates
# begin with a image format (tag) specified (e.g. mpeg) followed with a
# equal-greater sign (=>).  The delegate is invoked whenever ImageMagick
# attempts to read an image whose format specifier or filename extension
# matches the tag (e.g.  image.mpg for tag mpg=>).  The delegate must write
# an image to the file designated by %o in an image format that ImageMagick
# understands (e.g. pnm).
# 
# An encode delegate begins with an image format, a less-equal sign (<=),
# and a tag.  The delegate is invoked whenever ImageMagick attempts to write
# an image whose format specifier or filename extension matches the tag
# (e.g. image.mpg for tag <=mpg).  ImageMagick writes to a temporary file
# in the format you specify.  The delegate can then read this file and
# convert it to a format it supports and pesumably ImageMagick does not.
# 
# If you use a less-equal-greater sign (<=>) the delegate is bi-directional.
# Delegates must be separated with a blank line.
#
# Lines that begin with a pound sign (#) are comments and are ignored.
# 
# There are a number of delegates used by ImageMagick for special
# circumstances.  For example, the print or Ghostscript delegate.  Don't
# remove these or ImageMagick may behave strangely.
# 
# ImageMagick looks for the delegate configurarion file in this order:
#
#     /usr/local/share/ImageMagick/delegates.mgk
#     DELEGATE_PATH/delegates.mgk
#     HOME/.magick/delegates.mgk
#     ./delegates.mgk
#
# Where DELEGATE_PATH and HOME are environment variables.
#
# Like entries in the later two directory overrides the specification
# in the system-wide delegates file.
# 

<=bzip
        |/usr/local/bin/bzip2 -f > %o

<=compress
        |/usr/bin/compress -c > %o

<=gs-eps
        /usr/local/bin/gs -sDEVICE=epswrite -q -dNOPAUSE -dSAFER \
          -sOutputFile="%s" -- "%s" -c quit

<=gs-pdf
        /usr/local/bin/gs -sDEVICE=pdfwrite -q -dNOPAUSE -dSAFER \
          -sOutputFile="%s" -- "%s" -c quit

<=gs-ps
        /usr/local/bin/gs -sDEVICE=pswrite -q -dNOPAUSE -dSAFER \
          -sOutputFile="%s" -- "%s" -c quit

<=zip
        |/usr/local/bin/gzip -cf > %o

browse=>
        /usr/local/bin/netscape http://www.wizards.dupont.com/cristy/ImageMagick.html &

bzip=>
        |/usr/local/bin/bzip2 -cd %i

cgm=>
        /usr/local/bin/ralcgm -d ps %i %o %u
        /usr/bin/mv %o.ps %o
        /usr/bin/rm -f %u

compress=>
        |/usr/bin/uncompress -c %i

dvi=>
        /usr/local/bin/dvips -q -o %o %i

edit=>
        /usr/X11R6.4/bin/xterm -title "Edit Image Comment" -e vi %i

file=>
        /usr/local/bin/GET %m:%i > %o 2>&1

fig=>
        /usr/local/bin/fig2dev -L ps %i %o

ftp=>
        /usr/local/bin/GET %m:%i > %o 2>&1

gs-color=>
        /usr/local/bin/gs -sDEVICE=pnmraw -q -dNOPAUSE -dSAFER \
          -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -g%s -r%s %s \
          -sOutputFile="%s" -- "%s" -c quit

gs-mono=>
        /usr/local/bin/gs -sDEVICE=pbmraw -q -dNOPAUSE -dSAFER \
          -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -g%s -r%s %s \
          -sOutputFile="%s" -- "%s" -c quit

hpgl=>
        /usr/local/bin/hp2xx -q -m eps -f %i %o

htm=>
        /usr/local/bin/html2ps -o %o %i

html=>
        /usr/local/bin/html2ps -o %o %i

http=>
        /usr/local/bin/GET %m:%i > %o 2>&1

launch=>pnm
        /usr/local/bin/gimp %i

mpg=>
        /usr/local/bin/mpeg2decode -q -b %i -f -r -o3 %o%%d
        /usr/local/bin/convert %o*.ppm %o
        /usr/bin/rm -f %o*.ppm

m2v=>
        /usr/local/bin/mpeg2decode -q -b %i -f -r -o3 %o%%d
        /usr/local/bin/convert %o*.ppm %o
        /usr/bin/rm -f %o*.ppm

pgp=>
        /usr/local/bin/pgpv -fq %i

pnm<=win
        /usr/local/bin/display -immutable %i

print=>ps
        /usr/bin/lp -c -s %i

rad=>
        /usr/local/bin/ra_ppm -g 1.0 %i %o

rgba<=rle
        /usr/local/bin/mogrify -flip -size %wx%h rgba:%i
        /usr/local/bin/rawtorle -w %w -h %h -n 4 -o %o %i

scan=>
        scanimage  -d %i > %o

show=>%m
        /usr/local/bin/display -immutable -window_group %g -title "%l of %f" tmp:%i &

shtml=>
        /usr/local/bin/html2ps -o %o %i

yuv<=m2v
        /usr/local/bin/mpeg2encode %u %o
        /usr/bin/rm -f %i*.yuv %u*

yuv<=mpg
        /usr/local/bin/mpeg2encode %u %o
        /usr/bin/rm -f %i*.yuv %u*

zip=>
        |/usr/local/bin/gzip -cdfq %i

\EndVerbatim\EndHPage{}]\fi {} --
\ifHtml[\HPage{dvi->gif}\Verbatim
Previously, I asked about how to convert the images from .dvi
files into gif/jpeg for inclusion in web pages.

My own system is a minimalist one; it is based on linux, which perhaps
should have been made clear in my initial post.

I have X Free86 operating, and a few other things, but was trying to
aviod loading in too many more packages.

The packages I ended up using were : tex, dvips, ghostscript, xpaint and
perhaps cjpeg. dvips and ghostscript were necessary add-ons, requiring
a decent number of files.  Dvips does not work on my system, as I'm
trying to figure out the minimum number of font packages needed to get
it going.  But its being used on a remote system.

In any case, here are the steps involved :

1. Use tex to convert the tex file into .dvi
2. Use dvips to convert the .dvi file into .ps (postscript)
3. Use the ghoscript command
   gs -sDEVICE=ppm -sOutputFile=file%d.ppm file.ps 
   To convert the ps file to a ppm file which xpaint can read.
4. Run X and startup xpaint. The successive pages of the document
   will have been converted to numbered ppm files. Load each in
   sucession into xpaint. Use the region command to mark out a
   region encompassing each formula, and save as .gif file.
5. Refer to each formula file generated within the HTML document.

This works. I suspect there may be a way of "grabbing" the raw the
X screen output when using xdvi to look at the document, and process
the contents, but I don't know enough to do this.

An alternate approach, using slightly different packages, which I have
not tried, is described in Chapter 11.6 (p.455) of the LaTeX Graphics
Companion (Goossens, Rahts, Mittelbach, 1997, ISBN 0-201-85469-4).

Basically the steps are:
1 put each equation in a separate file/page
2 process with dvips to get a postscript file
3 process with Ghostscript to get a pbm file
4 use the netpbm utility pbmcrop to trim white space (or epsfit)
5 use ppmtogif to get a gif file or cjpeg to get a jpeg file.

Ideally, it would be nice to convert .dvi directly into html files,
automatically generating the graphics files and referencing them. Some
people did suggest there were ways of doing this, but they involved
loading in different extra packages which are not part of my current
system.

In spite of my enthusiasm for such direct conversion, I'll be using the above
method until I can get my brain around all this better, being new to linux,
tex, X and all these different file formats, which are presently just
buzzwords.

Two "automatic" methods mentioned involved were based on latex2html 
and hyperlatex.

latex2html requires perl and hyperlatex requires emacs.  Both will
require the pbmutilities and ghostscript, possibly giftrans.  
latex2html will do a full conversion of your document so it will
generate equation in gif format.  hyperlatex will require that you
indicate that you want an equation converted to gif, otherwise it will
create a textual approximation.

Web pages containing these are :
Hyperlatex      ftp://iphthf.physik.uni-mainz.de/pub/gv/unix
latex2html      http://www-dsed.llnl.gov/files/programs/unix/latex2html/

They sound interesting, but necessitate loading in extra packages.

A system using translated .tex is :

    http://www.cse.ohio-state.edu/~gurari/TeX4ht/mn.html

More information is obtainable in :

  ftp://ftp.cse.ohio-state.edu/pub/tex/osu/gurari/TeX4ht/dos/port/readme.html

This document outlines a dos version of the conversion package. It is quite
enlightening, particularly when you don't know too much of the jargon to do
with tex and variants. It provides some general information about what tools
exist to generate what bitmap files from what other files, and was quite
interesting.

The particular package outlined apparently uses LaTeX, which I don't have
any familiarity with, and am anxious about needed still more libraries and
"background operation files".

Presumably, the dos version is of a much more stand alone nature, but not
using a dos system its not something I've taken much interest in.

As for more general issues, it was noted that :

There was, in fact, an official version of HTML, namely 3.0, that did
support some math.  But although W3 even wrote a browser (Arena) for it,
it didn't catch on.  IBM produces a ("free") browser plugin called
Techexplorer which can handle certain TeX and LaTeX documents directly. 

        .... Latest word is that the plugin will be made to work 
        in Netscape on operating systems other than just Win-95. I believe 
        it currently works on just Win-95 with Netscape or Microsoft's 
        Internet Explorer. I am hoping the next release will work in 
        Netscape on Linux.

        The plugin is called "techexplorer." 

        Downloads and information are available at:
        http://www.ics.raleigh.ibm.com/ics/techexp.htm

A suggestion was made to use PDF instead of HTML .... I don't know what
PDF is, and I thought HTML was the standard. Apparently there is a version
of TeX called pdftex which outputs PDF directly.

Thanks to Pierre Girard, Eitan Gurari, Ed Russell, Steve Whitlatch,
James Youngman and hymie! for replying/posting by the time I prepared
this summary. Some text has been lifted directly from documents
originated by them.


\EndVerbatim\EndHPage{}]\fi{} --
\ifHtml[\HPage{images to GIF}\Verbatim
From kbigelow@www.play-hookey.com Sat Oct 12 19:36:41 EDT 1996
Article: 107602 of comp.infosystems.www.authoring.html
Path: news.cse.ohio-state.edu!math.ohio-state.edu!howland.erols.net!feed1.news.erols.com!news
From: Ken Bigelow <kbigelow@www.play-hookey.com>
Newsgroups: comp.infosystems.www.authoring.html
Subject: Re: Converting many graphics/images to GIF format
Date: Sat, 12 Oct 1996 17:25:36 +0000
Organization: Erol's Internet Services
Lines: 55
Message-ID: <325FD490.57F6@www.play-hookey.com>
References: <52p0em$4dn@nadine.teleport.com>
Reply-To: kbigelow@www.play-hookey.com
NNTP-Posting-Host: kenjb05.play-hookey.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.0 (Win16; U)

Joann Taylor wrote:
> 
> Greetings.  I have a quick question re: saving graphics to GIF format.
> I am using a Mac to pull together a large html-based help utility and
> need to integrate graphics.  I have LOTS that I have used prior in PICT,
> TIFF, and random application formats (Canvas, Kaleidagraph, Photoshop,
> ...ya dee ya...).  When I try to save these as GIF files for my html
> pages - most of the graphics get hosed - resolution is very poor and color
> gets trampled on.  I expect some degredation but this seems very
> excessive...I have got to be forgetting something. My Canvas 5
> application gives me the impression it is building the appropriate color
> table during the "save" but the resulting image says differently. I am
> not very familiar with the GIF format, so I am not sure of the source of the
> problem.  Can any one suggest how I might address this problem or where
> I might find some pointers to a solution?
> 
> Many thanks,
> 
> Joann

Hi, Joann!

The problem you're having here has to do with color resolution in the
various methods used to compress graphic data when saving the image
file. I won't go into technical details here, but the two main formats
used currently in Web pages are JPEG (*.jpg) and GIF (*.gif).

JPEGs are saved in 24-bit or 32-bit format. This means they store images
with up to 16.7 million colors or 4 billion colors. As a result, they
are suitable for imaged photographs and similar applications.

GIFs, however, are saved in 8-bit or 4-bit format. These images contain
either 256 colors or even as few as 16 colors. This is very satisfactory
for drawings and for many "ordinary" computer-generated images.

Unfortunately, when you save a high-resolution image (as in TIFF) in GIF
format, you lose most of your colors. The program should be willing to
either "dither" the image or otherwise find the closest match available,
but there's no hope for it -- the image quality will suffer to one
degree or another.

One possible way to handle the problem is to put the GIFs on your page,
since they will be smaller files and will load fairly quickly, and use
them as links to the "real" JPEGs on your server, so the user still has
access to the larger and slower-loading, but far more accurate JPEGs.

Just remember to save your TIFF images in JPEG format first, and then
convert them to GIFs. Going from GIF to JPEG won't improve the
appearance of the image; it's already been degraded.
-- 
Ken

Are you interested in   |
byte-sized education    |   http://www.play-hookey.com
over the Internet?      |
\EndVerbatim\EndHPage{}]\fi
{} --
\ifHtml[\HPage{quick conversion}
Provide a fast option


\Verbatim
> I think I'll probably write my own Perl script to hanlde
> image conversion.  I think it can be made faster than 
> using the *.lg file you provide by doing multiple 
> conversions at once.
> 
> dvips [arguments] file.idv  -o temp.ps
> 
> will write a single .ps file with multiple pages, one for
> each image.  
> 
> convert temp.ps [arguments] image%03d.gif
> 
> will take that file and produce one image gif per page
> The names of the files are image000.gif, image001.gif, etc.
> 
> Thus it looks like I can invoke dvips and convert just
> once each and then simply pass through at correct filenames.
> I imagine that will be faster than invoking the two 
> programs once per image.

This will be a superior approach, provided you have access 
to sufficient memory.  It is rarely the case for me :-(

\EndVerbatim









\Verbatim
From: Douglas Bonar <bonard@ms.com>
Date: Wed, 25 Feb 1998 18:29:12 -0500 (EST)
In-Reply-To: Eitan Gurari <gurari@cse.ohio-state.edu>
        "Re: And some more ..." (Feb 25,  1:22pm)
References: <199802251822.NAA03524@sunkist.cse.ohio-state.edu>
X-Mailer: Z-Mail Lite (3.2.0 5jul94)
To: Eitan Gurari <gurari@cse.ohio-state.edu>
Subject: Mass conversion
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii


The perl script enclosed below seems to be faster than
simply running file.lg through the shell.

Doug



#!/ms/dist/perl5/bin/perl5 -sw
#

if (!@ARGV || !($#ARGV==0)) {
    die "readLog takes one argument, the file to be read.\n";
}

$file = $ARGV[0];

if (! -e $file || ! -r $file || !open(INPUT,"<$file")) {
    die "The specified file does not exist or cannot be opened.\n";
}

# 2-state machine passing through the input file looking for
# lines with dvips or convert information.
$state = undef;
@names = ();  
for (<INPUT>) {
    if (/^dvips\s+(.*)\s+-pp\s+(\d+)/) {
        $dvipsargs = $1;   # should be the same ever pass
        if (! defined $state) {
            $state = $2;   # save the index
        } else {
            die "Error:Input file $file, two dvips lines, no convert.\n";
        }
        next;
    }
    if (/^convert\s+tmp\.ps\s+(.*)\s+(.*)\.gif/) {
        $convertargs = $1;  # should be the same every time
        if (! defined $state) {
            die "Error:Input file $file, convert line with no dvips line.\n";
        } else {
            $names[$state] = $2;  # store the file name with its number
            $state = undef;  # reset the machine
        }
    }
}

system "dvips $dvipsargs -o temp.ps";
system "convert  temp.ps $convertargs temp\%03d.gif";
for $i (1..($#names)) { # page numbers in the ps file start at one.
    rename sprintf("temp%03d.gif",$i), "$names[$i].gif";
}

\EndVerbatim




{Shell Note}

\Verbatim
> From: Douglas Bonar <bonard@ms.com>
> Date: Fri, 27 Feb 1998 09:21:13 -0500 (EST)
> X-Mailer: Z-Mail Lite (3.2.0 5jul94)
> To: gurari@cse.ohio-state.edu
> Subject: the continuing saga
> Mime-Version: 1.0
> Content-Type: text/plain; charset=us-ascii
> 
> 
> I finally figured out why I was having problems with 
> transparency.  You write a script file doc.lg, which
> you then execute.  But the 
>       convert (arguments) tmp.ps out.gif
> acts differently for different shells.  In particular,
> I use ksh and the '#' in the transparent number comments
> out the rest of the line.  That's why I had to move
> tmp.ps forward in the line and why I never could get
> the -transparent flag to work.
> 
> You might write  
>       #!/bin/sh 
> as the first line of the file.lg file.  That would 
> avoid such problems for most people.  
> 
> I'm having little sucess with getting larger images, but
> I'll keep trying.  

\EndVerbatim

{MF Mode}


\Verbatim


Well, I back down from thinking that you can mass convert the 
images.  You do end up with gif files, but the cropping doesn't
work, and scale seems to be lost as well.  

BTW, I ended up liking the output I got from 
 -mode iw -D 144 -x 800
I would have just used one of the 120 pixels_per_inch modes, 
but they didn't go through mf very well for me.  Note that 
the size problems I was having were partly due to trying
to mass convert things.  Doing that ends up with output
smaller than doing each file seperately (it seems).  


\EndVerbatim
\EndHPage{}]\fi
{} --
\ifHtml[\HPage{more}\Verbatim
--------------------------------------------------------
The best output for larger fonts/scaling of formulas that I can reach
involves the following steps:

a. Find a metafont mode of higher density within your modes.mf file
   (in my unix environment the file has the address
    .../tex/teTeX/texmf/metafont/misc/modes.mf)

   My personal default setting relies on the following entry.
    
    
    mode_def ibmvga =                       %\[ IBM VGA monitor (110 dpi)
      mode_param (pixels_per_inch, 110);
      mode_param (blacker, .3);
      mode_param (fillin, 0);
      mode_param (o_correction, 0);
      mode_common_setup_;
    enddef;

b. Inform  the mode and its density to dvips through the switches
   `mode' and `D'.   In my default setting this means 
    
         dvips -mode ibmvga -D 110 ...

c. Inform convert what density is in use.  In my default setting
   this means

       convert -density 110x110 ...

The conversion process is slow also on my site.

Well, the above is all I know about this topic.  Hope it helps.  In
case you'll end up with better solutions, I'll appreciate your input.

-eitan

> i have one need, larger gifs. my formulas need to be inline with html
> text and i need to control the size of the resulting image. i ran
> convert with a 200% geometry and it ran forever, and generated larger
> gifs but with fuzzy dithered edges. how can i select larger fonts/scaling
> in your system in a clean way? would selecting a different mode be
> right? i tried that with no improvement.

--------------------------------------------------------






\EndVerbatim\EndHPage{}]\fi {} --
\ifHtml[\HPage{more}\Verbatim
GIF has no resolution info.  It is fixed at 75 dot per inch.
>  > Good to know. I was not aware of this fact. This, I think, might
>  > finally explain me why higher densities end up in larger pictures.
> indeed, true. you need JPEG or PNG to get resolution info (if the
> browser bothers to read it)

\EndVerbatim\EndHPage{}]\fi{} --
\ifHtml[\HPage{more}\Verbatim
 and the density of the bitmap
 pictures.  The bitmaps in Figure~\ref{Fig:EG:exdvi} have a density of
 110 dots per inch;  Figure~\ref{EGf:exdvi-1} shows the corresponding
 display of the last picture with a density of 144 dots per inch.
(The \emph{density} refers to the number of bits sampling each inch
in the source dvi picture.)

\EndVerbatim\EndHPage{}]\fi
{} --
\ifHtml[\HPage{more}\Verbatim
 >> 0x12aaa8: 0x02 dict --Lwrx--- 0x0000 0x0012fb10
 >> 0x12aab0: 0x02 dict --Gwrx--- 0x0000 0x0012ac00
 >>
 >> Has anybody else experienced similar difficulties?

This is probably a gs problem.
gs only allows 80 character input files, and since latex2html uses the
whole path as file name, it easily gets up to this length.
This should be solved by next version of gs (allows 128 character
filenames).

\EndVerbatim\EndHPage{}]\fi{} --
\ifHtml[\HPage{more}\Verbatim
> 2) display and giftrans are not very good (many errors, screen's
> gestion...) I tried with netpbm which is given with latex2html, and I
> replace in convert.bat the last commands by :
>
> echo Creating .ppm file
> pcxtoppm tmp00%2.pcx > ppm00%2.ppm   =20
> echo Cropping it
> pnmcrop ppm00%2.ppm > ppm10%2.ppm
> echo Creating .gif (transparent) file
> ppmtogif -transparent 1,1,1 ppm10%2.ppm > %3
>
> It seems to do a good work...


\EndVerbatim\EndHPage{}]\fi {} --
\ifHtml[\HPage{about convert}\Verbatim

     Postscript 

          ImageMagick requires Ghostscript software to read the
          PostScript or the Portable Document format. It is used to
          annotate an image when an X server is not available. See the
          FreeType library above for another means to annotate an
          image. Note, Ghostscript must support the ppmraw device
          (type gs -h to verify). If Ghostscript is unavailable, the
          Display Postscript extension is used to rasterize a
          Postscript document (assuming you define HasDPS). The DPS
          extension is less robust than Ghostscript in that it will
          only rasterize one page of a multi-page document.
\EndVerbatim\EndHPage{}]\fi {} --
%
[\HPage{reuseable}\Verbatim
#/bin/sh
#
#  Usage
#    tex4ht.makegif basename pagenumber destination
#
####################################################
#
# Produce the image in postscript form, as $3.new.ps
#
dvips -mode ibmvga -D 110 -f $1.idv -pp $2 > $3.new.ps
#
#
# Check to see if a previous use of this script has left behind a $3.ps file
#
if test -r $3.ps
then
#
#  If so, and if the $3.ps and $3.new.ps files are identical, then the
#  $3.gif file from that previous execution can be retained, and we can avoid
#  the time-consuming ps->gif conversion.
#
  if cmp -s $3.ps $3.new.ps
  then
    echo $3 is unchanged.
    rm $3.new.ps
  fi
fi
#
#
# But if no old file exists, or the .ps files were different, then
# use the new.ps file to produce the .gif image.  Retain the $3.new.ps
# file as $3.ps for possible future reuse.
#
if test -r $3.new.ps
then
  mv $3.new.ps $3.ps
  convert -crop 0x0 -density 110x110  -transparent '#FFFFFF' $3.ps $3
fi

\EndVerbatim\EndHPage{}]
%
[\HPage{redundancy}\Verbatim
#!/bin/sh

  reduceGifs base

    Compares all files of form $base*.gif to one another
    For each pair of identical .gif files are found, the files
    $base*.htm* are edited so that references to these separate
    but equal files are replaced by repeated references to the
    same file.

    This can speed up the loading of some html files by a significant
    amount.

echo > reduceGifs.sed
uplicatesFound=0
for fileA in $1*.gif
do
 Adone=0
 for fileB in $1*.gif
%  do
    if test $fileA = $fileB
    then
      Adone=1
    fi
    if test $Adone = 0
    then
       if cmp -s $fileA $fileB
       then
          echo s/$fileA/$fileB/g >> reduceGifs.sed
          duplicatesFound=1
          Adone=1
          echo $fileA and $fileB are duplicates.
          rm $fileA
       fi
    fi
  done
done
#
if test $duplicatesFound = 1
then
  for fileA in $1*.htm*
  do
    mv $fileA $fileA.bak
    echo >> $fileA.bak
    sed -f reduceGifs.sed < $fileA.bak > $fileA
  done
fi
\EndVerbatim\EndHPage{}]
%
\ifHtml[\HPage{more}\Verbatim

%     * The most time-consuming part of the conversion is generating the
%       .gif images. I've tried to speed this up a bit:
%          + My script for generating the .gif files (1) saves the old .ps
%            file. After the new .ps file for the image has been created,
%            it is compared to the old one. If unchanged, then the .gif
%            file previously generated for that image is reused, rather
%            than take the time to produce a new one.
%          + After all the .gifs have been produced, this  script (2) compares
%            the .gifs. If duplicates are found (For example, my STL
%            Containers document produces many, many images for the same
%            mathmatical expressions e.g., log N), then the .html files
%            are edited to use only one of the duplicate .gifs. This can
%            significantly reduce the time required to load a document, as
%            the repeated references to the same .gif will be served from
%            the browser's cache rather than being repeatedly retrieved
%            from over the net.
%     * Both of the above scripts could be made more portable by rewriting
%       them in Perl. Perl could easily replace the use of the sed tool as
%       well. Replacing the use of cmp would be more of a problem.Another
%       possibility would be to follow the route taken by latex2html and
%       use dbm to maintain a content-based ps->gif map. But the use of
%       dbm seems to be one of the sticking points in latex2html's
%       portability to Win32 systems. By contrast, one can easily obtain
%       bash, sed, and cmp as part of the gnuwin32 (4) release, allowing the
%       use of these scripts with little or no change.





% >  > OK, start laughing, but I don't understand what you mean.  If 2htm.bat
% >  > is in directory X, and f is a file in a subdirectory of X, doesn't
% >  > this put 2htm.bat in the path of f?
% >
% >   I'm most certainly not laughing - I know exactly how it feels to be in
% > the dark about an operating system and it's peculiarities.  I'm only
% > slowly beginning to feel a little bit at home on this Linux system.  I'm
% > having a little difficulty understanding exactly what you're asking
% > here, though.
% >
% >   The path I was referring to is the executable search path as specified
% > in the path environment variable. The DOS executable search system is
% > similar to Unix's.  First, the current directory is searched (note that
% > this is different under Unix), then all directories mentioned in the
% > path variable.  These directories are the only ones searched, and
% > subdirectories thereof are not searched, just like under Unix.
% >
% >   The basic problem here is that programs under DOS are not, like under
% > Unix, all dumped in one directory, but generally each are installed in
% > their own directory.  If the path environment variable arch path. (On my system, this directory is called
% > d:\tools\batch).  These startup batch files can then e.g. change to the
% > appropriate directory before starting up the program.
% >
% >   This way, you keep a small path environment variable, and still have
% > easy access to all programs.  The port manual tries to suggest to place
% > 2htm.bat in a directory in the executable search path; I will change the
% > wording a little to make this more clear.
% >


%----------------------------------------------- features ------------


% %---------------------------------------------------------
% 
%      *
% Some links to `convert'  are dead. Use instead the following address
% 
%    ftp://ftp.wizards.dupont.com/pub/ImageMagick/
% 
% Also, you'll probably need
% 
%    -transparent #FFFFFF
% 
% instead of the following
% 
%    -transparent #FFFFFF
% 
% in the call to  convert.
%        The `convert' utility is part of the distribution of ImageMagick.
%        It is recommended for use by TeX4ht, to translate postscript
%        pictures to gif (or other formats).
%      * Once TeX4ht is installed, you might want to consider making a
%        transition to the next (not yet complete) version
%        manual
%        files (a small back-end utility is still missing for the html4.0
%        mode of output in DOS).
% 
% 
% 
% The changes should be minor, but I can't introduce them here without
% having the win32 installation.  the script is just an interpreter of
% the .lg file, making calls to 'convert' and a few other system
% commands (e.g., move file, change protection mode). If you are
% interested, I be glad to modify the script to work on your system, but
% I'll need your advise along the way.
% 
% 
% 
% 
% Doug, Convert is one of many tools within the distribution.  I would
% recommend that you download the zip file, and compile just the source
% of convert.  -eitan
% 
% 
% >     From that directory, what should i grab?  There
% > didn't appear to be anything named 'convert'.  Do I need
% > the full ImageMagick distribution?  Or is there one part
% > of it that is used?
% 
% 
% 
% 
% 
% Doug, Convert is one of many tools within the distribution.  I would
% recommend that you download the zip file, and compile just the source
% of convert.  -eitan
% 
% 
% >     From that directory, what should i grab?  There
% > didn't appear to be anything named 'convert'.  Do I need
% > the full ImageMagick distribution?  Or is there one part
% > of it that is used?
% 
% 
% 
\EndVerbatim\EndHPage{}]\fi
{} --
\ifHtml[\HPage{more}\HCode{
<H2>Tools That Tgif Uses:</H2>
<DL COMPACT>
<DT><IMG ALT="o" SRC="whitedot.gif"><DD><A
    NAME=netpbm><STRONG>Netpbm</STRONG></A> --
    a toolkit for conversion of images between a variety of different
    formats, as well as to allow a few basic image operations.
    <P>
    Tgif uses netpbm to import/export GIF files, generate trailing TIFF
    image for DOS/Windows EPS files, etc.
    Please see the IMPORT RASTER GRAPHICS and
    GENERATING MICROSOFT WINDOWS EPSI FILES sections of <A
    HREF="http://bourbon.cs.umd.edu:8001/tgif/current.html\#man">
`<    tgif's man pages</A>.
    <P>
    The official release of netpbm is <A
    HREF="ftp://ftp.x.org/R5contrib/netpbm-1mar1994.tar.gz">
    ftp://ftp.x.org/R5contrib/netpbm-1mar1994.tar.gz</A>.  Since <A
    HREF="ftp://ftp.x.org/">ftp.x.org</A> is very difficult to get on,
    a copy it is placed at <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/netpbm/netpbm-1mar1994.tar.gz">
    ftp://bourbon.cs.umd.edu/pub/tgif/netpbm/netpbm-1mar1994.tar.gz</A>.
    A <A HREF="ftp://bourbon.cs.umd.edu/pub/tgif/netpbm/README.15nov1997">
    modified version</A> of it is placed at <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/netpbm/netpbm-15nov1997.tar.gz">
    ftp://bourbon.cs.umd.edu/pub/tgif/netpbm/netpbm-15nov1997.tar.gz</A>.
<P>
<DT><IMG ALT="o" SRC="whitedot.gif"><DD><A
    NAME=pstoepsi><STRONG>Pstoepsi</STRONG></A> --
    Script to convert an arbitrary PostScript image to an encapsulated
    PostScript image with a bitmap, suitable for incorporation into
    FrameMaker, LaTeX, troff, etc.
    <P>
    Pstoepsi is similar to ps2epsi distributed with <A
    HREF="http://www.cs.wisc.edu/\string~ghost/">ghostscript</A>.  In some cases,
    pstoepsi does a little better than ps2epsi.
    <P>
    Tgif uses pstoepsi in the <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/samples_tgif/latex.tar.Z">
    LaTeX Equation Package</A>.  If you are having problems with installing
    this package, please look at the <A HREF="faq/latex.html">FAQ on this
    topic</A>.
    <P>
    A release can be found in either <A
    HREF="ftp://ftp.x.org/R5contrib/pstoepsi.tar.Z">
    ftp://ftp.x.org/R5contrib/pstoepsi.tar.Z</A> or <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/pstoepsi.tar.gz">
    ftp://bourbon.cs.umd.edu/pub/tgif/pstoepsi.tar.gz</A>.
    However, if any of the above mentioned netpbm releases is used,
    all you need is a <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/pstoepsi/pstoepsi">pstoepsi
    shell script</A> with <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/pstoepsi/README.this-site">some
    modifications</A>.
    <P>
    Pstoepsi requires <A
    HREF="http://www.cs.wisc.edu/\string~ghost/">ghostscript</A> and <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/netpbm/netpbm-15nov1997.tar.gz">
    netpbm</A>.
<P>
<DT><IMG ALT="o" SRC="whitedot.gif"><DD><A
    NAME=ghostscript><STRONG>Ghostscript</STRONG></A> --
    <A HREF="http://www.cs.wisc.edu/\string~ghost/">Aladdin Ghostscript</A>
    interpreter/previewer.
<P>
<DT><IMG ALT="o" SRC="whitedot.gif"><DD><A
    NAME=jpeg><STRONG>Jpeg</STRONG></A> --
    <A HREF="ftp://ftp.uu.net/graphics/jpeg/">The
    Independent JPEG Group's JPEG software</A> (source distribution
    is jpegsrc.*.tar.gz).
    <P>
    Tgif can use djpeg from the JPEG package to convert a JPEG file into
    a GIF file then use giftopnm and ppmtoxpm from the <A
    HREF="ftp://bourbon.cs.umd.edu/pub/tgif/netpbm/netpbm-15nov1997.tar.gz">
    netpbm</A> package to import it into tgif.
    Please see the IMPORT RASTER GRAPHICS section of <A
    HREF="http://bourbon.cs.umd.edu:8001/tgif/current.html\#man">
    tgif's man pages</A>.
</DL>
}\EndHPage{}]\fi
{} --
[\HPage{translation of 
dvi} \ExitHPage{}


Kaz Kylheku \''<kaz@helios.crest.nt.com>', August 7, 1997:

\Verbatim
One possible path for doing this is to render the dvi to PostScript using
dvips. Once you have the PostScript, you can use GhostScript to render a
bitmapped image of each page to whatever resolution you want. Using an image
converting program, you can convert these bitmaps to GIF, or whatever you want.
A good image converting program should let you convert the black and white
bitmapped image to a GIF image _and_ scale it down with grayscale anti-aliasing
in the same step. I think ImageMagick is probably able to do it, though I would
have to check.
\EndVerbatim

\HCode{<HR>}

July, 1997 (author?):

\Verbatim
My own system is a minimalist one; it is based on linux, which perhaps
should have been made clear in my initial post.

I have X Free86 operating, and a few other things, but was trying to
aviod loading in too many more packages.

The packages I ended up using were : tex, dvips, ghostscript, xpaint and
perhaps cjpeg. dvips and ghostscript were necessary add-ons, requiring
a decent number of files.  Dvips does not work on my system, as I'm
trying to figure out the minimum number of font packages needed to get
it going.  But its being used on a remote system.

In any case, here are the steps involved :

1. Use tex to convert the tex file into .dvi
2. Use dvips to convert the .dvi file into .ps (postscript)
3. Use the ghoscript command
   gs -sDEVICE=ppm -sOutputFile=file%d.ppm file.ps 
   To convert the ps file to a ppm file which xpaint can read.
4. Run X and startup xpaint. The successive pages of the document
   will have been converted to numbered ppm files. Load each in
   sucession into xpaint. Use the region command to mark out a
   region encompassing each formula, and save as .gif file.
5. Refer to each formula file generated within the HTML document.

This works. I suspect there may be a way of "grabbing" the raw the
X screen output when using xdvi to look at the document, and process
the contents, but I don't know enough to do this.

An alternate approach, using slightly different packages, which I have
not tried, is described in Chapter 11.6 (p.455) of the LaTeX Graphics
Companion (Goossens, Rahts, Mittelbach, 1997, ISBN 0-201-85469-4).

Basically the steps are:
1 put each equation in a separate file/page
2 process with dvips to get a postscript file
3 process with Ghostscript to get a pbm file
4 use the netpbm utility pbmcrop to trim white space (or epsfit)
5 use ppmtogif to get a gif file or cjpeg to get a jpeg file.

Two "automatic" methods...

latex2html requires perl and hyperlatex requires emacs.  Both will
require the pbmutilities and ghostscript, possibly giftrans.  
latex2html will do a full conversion of your document so it will
generate equation in gif format.  hyperlatex will require that you
indicate that you want an equation converted to gif, otherwise it will
create a textual approximation.

Web pages containing these are :
Hyperlatex      ftp://iphthf.physik.uni-mainz.de/pub/gv/unix
latex2html      http://www-dsed.llnl.gov/files/programs/unix/latex2html/

They sound interesting, but necessitate loading in extra packages.

A system using translated .tex is :

    http://www.cse.ohio-state.edu/~gurari/TeX4ht/mn.html

More information is obtainable in :

  ftp://ftp.cse.ohio-state.edu/pub/tex/osu/gurari/TeX4ht/dos/port/readme.html

This document outlines a dos version of the conversion package. It is quite
enlightening, particularly when you don't know too much of the jargon to do
with tex and variants. It provides some general information about what tools
exist to generate what bitmap files from what other files, and was quite
interesting.
\EndVerbatim
   
\EndHPage{}] -- 
 \ifHtml[\HPage{more}\Verbatim
Gif exist  tmp.ps DEL tmp.ps 
Gif exist tmp.ppm DEL tmp.ppm
Gdvips -f %%1 -pp %%2  -o tmp.ps
Ggswin32c -sDEVICE=ppm -sOutputFile=tmp.ppm -q -dbatch -dNOPAUSE tmp.ps -c quit
%  Gdvips -mode ibmvga -D 110 -f %%1 -pp %%2  -o tmp.ps
%  Ggswin32c -r110 -sDEVICE=ppm -sOutputFile=tmp.ppm -q -dbatch -dNOPAUSE tmp.ps -c quit
GMOVE /y tmp.ppm temp.ppm
Gpnmcrop  temp.ppm > tmp.ppm
Gif exist %%3 DEL %%3
Gppmtogif -interlace -transparent 1,1,1 tmp.ppm > %%3
\EndVerbatim

The \`'-c quit' must be at the end of gswin32c--it quits the execution
from the batch mode of execution. The postscript file(s) must come
just before it.

\EndHPage{}]\fi





\SubSection{Ignore/Noignore Commands}


\<???--- ??? ---...\><<<
status = scan_until_end_str("", 1, status, lg_file);
>>>


\Verbatim
l. 10 --- needs --- ignore ---
l. 11 --- needs --- end ignore ---
\EndVerbatim


We didn't check below the \`'l. dddd ' part.

\<???--- needs ---...\><<<
status = scan_until_end_str(" ignore ---", 2, status, lg_file);
if( status ){
  skip =  eq_str(match[2]," ignore ---") ? TRUE :
            ( eq_str(match[2]," end ignore ---") ? FALSE : skip );
}
>>>

\Section{post-process files}


\<post-process files\><<<
if( file_script ){
   eoln_ch = (int) 'x';
   while( eoln_ch != EOF ) {
      status = scan_str("File: ", TRUE, lg_file);
      status = scan_until_str(".", 1, status, lg_file);
      status = scan_until_end_str("", 2, status, lg_file);
      if( status ){                         Q_CHAR *p;
         p = match[1];
         *(p + (int) strlen(p) - 1) = '\0';
         (void) execute_script(file_script, match[1], 
                             match[2], Xrecord? Xrecord : "", "");
}  }  }
>>>


\Section{User Commands}

\`'l. 10 --- needs --- "ls *" ---'

\<process user commands\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {              Q_CHAR *command, ch;
                                       int n;
                                       struct sys_call_rec *p;
                                       BOOL flag;
   status = scan_str("l. ", TRUE, lg_file);
   status = scan_until_str(" --- needs --- \"", 1, status, lg_file);
   status = scan_until_str("\" ---", 2, status, lg_file);
   if( status ){
      command = match[2];
      *(command + (int) strlen(command) - 5) = '\0'; 
      `<flag = permission for system calls`>
      if( flag ){
        `<execute system command`>
      } else { (IGNORED) printf(
          "No permission for system call: %s\n", command); }
}  }
>>>


\<env permissions for system calls\><<<
{     struct sys_call_rec *q;
  q = m_alloc(struct sys_call_rec, 1);
  q->next = system_calls;
  q->filter = match[1];
              match[1] = (Q_CHAR *) malloc(70);  max_match[1] = 70;
  system_calls = q;
if( debug ){  
   (IGNORED) printf(".......'S' script: '%s'\n", 
                                q->filter); }
}
>>>

\<permission for system calls\><<<
{     struct sys_call_rec *q;
  q = m_alloc(struct sys_call_rec, 1);
  q->next = system_calls;
  q->filter = p + 2;
  system_calls = q;
}
>>>


\<flag = permission for system calls\><<<
flag = FALSE;
p = system_calls;
while( p ){                    
  if( (n = (int) strlen(p->filter)) == 1 ) {
     if( *(p->filter) == '*' ){
         flag = TRUE; break;
     }
  } 
  if( strlen(command) >= (unsigned int) n ) {
      ch = command[n]; command[n] = '\0';
      flag = flag || eq_str(p->filter,command);
      command[n] = ch;
  }
  p = p->next;
}
>>>






From log files \`'l. # --- needs --- "command" ---'













\Section{The Css (Cascade Style Sheets) File}




%Css: TD.caption{white-space: nowrap; }
%Font("cmex","10","100")
%Font("cmmi","10","100")
%Font("cmmi","5","100")
%Font("cmmi","7","100")
%Font("cmr","10","100")
%Font("cmr","5","100")
%Font("cmr","7","100")
%Font("cmsy","10","100")
%Font("cmsy","7","100")
%Font("cmti","10","100")
%Font("cmtt","10","100")
%Font_Class(1,""): <IMG SRC=""ALT=""CLASS="%s%s-%d--%x">
%Font_Class(3,"mva"): <IMG SRC=""ALT=""CLASS="%s-%d--%x"ALIGN="MIDDLE">
%Font_Class(6,"ul"): <SPAN CLASS="underline"></SPAN>
%Font_Css("sc"): .small-caps{font-variant: small-caps; }
% Font_Css("ul"): .underline{text-decoration:underline; }




\<process css\><<<
{
                               Q_CHAR   css_name[255], *p;
                               FILE   *css_file, *tmp_file;
                               BOOL   css_sty;
   `<css-file = open file ...`>
   if( css_file ){
      (IGNORED) printf ("Entering %s\n", css_name);
      tmp_file = fopen("tex4ht.tmp", WRITE_TEXT_FLAGS);
      if( !tmp_file ) {
         (IGNORED) warn_i_str(5,"tex4ht.tmp");
      } else { `<c: tex4ht.tmp := css file`> }
      tmp_file = open_file("tex4ht.tmp", ".tmp");
      css_file = fopen(css_name, WRITE_TEXT_FLAGS);
      if( !tmp_file ) {
         (IGNORED) warn_i_str(5,"tex4ht.tmp");
      } else if( !css_file ) {
         (IGNORED) warn_i_str(5,css_name);
      } else { 
        `<c: css file = header of tex4ht.tmp`>
        if( css_sty ){
           `<css file = css.sty`>
           `<c: css file = tail of tex4ht.tmp`>
        }
      }
      (IGNORED) fclose(tmp_file);
      (IGNORED) fclose(css_file);
}  }
>>>


\SubSection{Preliminary Processing}

\<c: tex4ht.tmp := css file\><<<
                   int ch;
while( (ch = getc(css_file)) != EOF ) {
  (IGNORED) putc( ch, tmp_file );        
}
(IGNORED) fclose(tmp_file);
(IGNORED) fclose(css_file);
>>>


\<css-file = open file ...\><<<
(IGNORED) strcpy( css_name, lg_name);
p = css_name;
while( *p  ){
   if( *p == '.' ){ *p = '\0';  break; }
   p++;
}
(IGNORED) strct(css_name, ".css");
css_file = fopen(css_name, READ_TEXT_FLAGS);  
>>>

\SubSection{Cotributors to the Css File}

Copy until insertion point:

\`'/* css.sty */'

\<c: css file = header of tex4ht.tmp\><<<
css_sty = FALSE;
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {
  status = scan_until_end_str("", 1, TRUE, tmp_file);
  `<match[2] := compressed match[1]`>
  if( eq_str(match[2], "/*css.sty*/") ){ css_sty = TRUE;  break; }
  (IGNORED) fprintf(css_file, "%s\n", match[1]);
}
>>>

\<vars\><<<
static BOOL status;
>>>



\<match[2] := compressed match[1]\><<<
{                          Q_CHAR *p, *q;
                           int  n;
  n = 0;  p = match[1];    q = match[2];  
  while ( (*p != '\0') ){ 
    if (n == 13) { *(q-10) = '\0';  break;}
    if( *p != ' ' ){ *(q++) = *p; n++; }
    p++;
  }
  *q = '\0';
}
>>>

Contribution from lg File



\<css file = css.sty\><<<
(IGNORED) fprintf(css_file, "/* start css.sty */\n");
`<rewind lg file`>  `<process Font_Size: ...`> 
`<rewind lg file`>  `<process Font(...)`> 
`<rewind lg file`>  `<process Font_Css(...):...`> 
`<rewind lg file`>  `<process Css:...`>
(IGNORED) fprintf(css_file, "/* end css.sty */\n");
>>>


The \`'<process Css:...>' should be after the other two's to allow 
the user to overide with \''\Css' commands the the
other contributions.




We want to remove the non-leading \`'/* css.sty */', just
in case htcmd.perl is called consequtively more than once.

\<css file = tail of tex4ht.tmp\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {
  status = scan_until_end_str("", 1, TRUE, tmp_file);
  `<match[2] := compressed match[1]`>
  if( !eq_str(match[2], "/*css.sty*/") ){ 
     (IGNORED) fprintf(css_file, "%s\n", match[1]);
  }
}
>>>


\SubSection{Contributions from /Css Commands}

\`'Css: P.noindent { text-indent: 0em }'

\<process Css:...\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {              
   status = scan_str("Css: ", TRUE, lg_file);
   status = scan_until_end_str("", 1, status, lg_file);
   if( status ){
      (IGNORED) fprintf(css_file, "%s\n", match[1]);
} } 
>>>

\SubSection{Contributions From Font-Size}


\`'\Needs{"Font_Size: 12"}'



\<process Font_Size: ...\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {              
   status = scan_str("Font_Size: ", TRUE, lg_file);
   status = scan_until_end_str("", 1, status, lg_file);
   if( status ){
      base_font_size = (int) get_long_int(match[1]);
} } 
>>>


\<vars\><<<
static int base_font_size = 10;
>>>




\SubSection{Contributions to Fonts}

\`'Font("cmr","10","100")'
\`'Font("aptmri","8t","100")'

\<process Font(...)\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {              
   status = scan_str("Font(\"", TRUE, lg_file);
   status = scan_until_str("\",\"", 1, status, lg_file);
   status = scan_until_str("\",\"", 2, status, lg_file);
   status = scan_until_str("\",\"", 3, status, lg_file);
   status = scan_until_end_str("\")", 4, status, lg_file);
   if( status ){
                      Q_CHAR *p;
                      struct htf_struct *font_sty;
                      int second;
      p = match[1]; 
      *(p + (int) strlen(p) - 3) = '\0'; 
      p = match[2]; 
      *(p + (int) strlen(p) - 3) = '\0'; 
      p = match[3]; 
      *(p + (int) strlen(p) - 3) = '\0'; 
      p = match[4]; 
      *(p + (int) strlen(p) - 2) = '\0'; 
      `<get font style`>
      `<get font size`>
      if( font_sty || (second != 100) ){
         `<print font style css`> 
}  }  } 
>>>



\<get font size\><<<
{                                                  Q_CHAR *p;
   second =   (int) 
              (  (int) get_long_int(match[3])
               * (int) get_long_int(match[4])
               / base_font_size
              );
   while( second > 700 ){  second /= 10; }
   p = match[3];
   while( *p != '\0' ){
     if( (*p < '0') || (*p > '9') ){ second = 100; break; }
     p++;
   }  
}
>>>




\<get font style\><<<
font_sty = htf_rec;
while ( font_sty  ) {
  if( eq_str(font_sty->key,match[1]) ){ break; }
  font_sty = font_sty->next;
}
>>>







\<print font style css\><<<
(IGNORED) fprintf(css_file, ".%s-%s", match[1], match[2]);
if( !eq_str(match[4],"100") ){ 
   (IGNORED) fprintf(css_file, "--%s", match[4]);
}
(IGNORED) fprintf(css_file, "{");
if( second != 100 ){
   (IGNORED) fprintf(css_file, "font-size:%d%c;", second, '%');
}
if( font_sty  ) {
   (IGNORED) fprintf(css_file, font_sty->body);
}
(IGNORED) fprintf(css_file, "}\n");
>>>



\SubSection{Font-Css Contributions}

\`'Font_Css("4"): .small-caps{font-variant: small-caps; }'

\<process Font_Css(...):...\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {              
   status = scan_str("Font_Css(\"", TRUE, lg_file);
   status = scan_until_str("\"): ", 1, status, lg_file);
   status = scan_until_end_str("", 1, status, lg_file);
   if( status ){
      (IGNORED) fprintf(css_file, "%s\n", match[1]);
}  }
>>>







\Section{load env file}


\SubSection{Retrieve Info}

\<load env file\><<<
{                                FILE* file;
                                 U_CHAR  env_loc[512];
   env_loc[0] = '\0';
   `<find tex4ht.env`>
   if( file ){  
      (IGNORED) printf("Entering %s\n", env_loc[0]? &env_loc[0] 
                                                  :"tex4ht.env"); 
      `<get info from env file`>
      (IGNORED) fclose(file);
}  }
>>>



\<get info from env file\><<<
eoln_ch = (int) 'x';
while( eoln_ch != EOF ) {                Q_CHAR ch;
  ch = (char) (eoln_ch = getc(file));          
  if( eoln_ch != (int) '\n' ){
     status = scan_until_end_str("", 1, TRUE, file);
     if( status ){
       switch( ch ){
         case 'A':{ `<script for chmod`>  break;}
         case 'C':{ `<script for copy`>  break;}
         case 'E':{ `<script for empty gifs`>  break;}
         case 'F':{ `<script for dvigif of glyps`>   break;}
         case 'G':{ `<script for dvigif`>   break;}
         case 'M':{ `<script for move`>  break;}
         case 'S':{ `<env permissions for system calls`>  break;}
         case 'X':{ `<script for file`>  break;}
         default:{ }
} }  }  }
>>>


\<script for dvigif\><<<
if( debug ){  
      (IGNORED) printf(".......'G' script\n"); }
dvigif_script = add_script(dvigif_script);
>>>


\<script for dvigif of glyps\><<<
if( debug ){  
      (IGNORED) printf(".......'F' script\n"); }
dvigif_glyp_script = add_script(dvigif_glyp_script);
>>>


\<script for move\><<<
if( debug ){  
      (IGNORED) printf(".......'M' script\n"); }
move_script = add_script(move_script);
>>>


\<script for copy\><<<
if( debug ){  
      (IGNORED) printf(".......'C' script\n"); }
copy_script = add_script(copy_script);
>>>





\<script for file\><<<
if( debug ){  
      (IGNORED) printf(".......'X' script\n"); }
file_script = add_script(file_script);
>>>




\<script for chmod\><<<
if( debug ){  
      (IGNORED) printf(".......'A' script\n"); }
chmod_script = add_script(chmod_script);
>>>

\<script for empty gifs\><<<
if( debug ){  
      (IGNORED) printf(".......'E' script\n"); }
empty_fig_script = add_script(empty_fig_script);
>>>





\<header functions\><<<
static struct script_struct * add_script( ARG_I(struct script_struct *) );
>>>

\<functions\><<<
`[
static struct script_struct * add_script(script) 
                           struct script_struct * script

;{ 
   struct script_struct* temp, * q;
   temp = (struct script_struct *) 
                      m_alloc(struct script_struct, (int) 1);   
   temp->command = match[1];
   if( debug ){  
      (IGNORED) printf(".......   %s\n", temp->command); }
   temp->next = NULL_SCRIPT;
   match[1] = (Q_CHAR *) malloc(70);
   max_match[1] = 70;
   if( script ){
      q = script;
      while( q->next ){ q = q->next; }
      q->next = temp;
   } else {
      script = temp;
   }
   return script;
}
>>>








  


\<vars\><<<
static struct script_struct 
    * dvigif_script = NULL_SCRIPT,
    * dvigif_glyp_script = NULL_SCRIPT,
    * move_script = NULL_SCRIPT,
    * empty_fig_script = NULL_SCRIPT,
    * copy_script = NULL_SCRIPT,
    * file_script = NULL_SCRIPT,
    * chmod_script = NULL_SCRIPT;
>>>










%          case 'H':{ `<env-htf-sty = htfcss.env file`> break;}
% 
% \<env-htf-sty = htfcss.env file\><<<
% env_htf_sty = match[1];
% match[1] = (Q_CHAR *) malloc(70);
% max_match[1] = 70;
% if( debug ){  
%    (IGNORED) printf(".......'H' script: '%s'\n",
%                             env_htf_sty); }
% >>>
% 
% \<vars\><<<
% static Q_CHAR* env_htf_sty = Q_NULL;
% >>>



\Verbatim
%   dvips -mode ibmvga -D 110 -f foo.idv -pp 92  > tmp.ps
%   convert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps foo.gif
Gdvips -mode ibmvga -D 110 -f %1 -pp %2  > tmp.ps
Gconvert -crop 0x0 -density 110x110 -transparent '#FFFFFF' tmp.ps %3
% htcmd -d%2 
Mmv %1 %2%3
Ccp %1 %2%3
% htcmd -d%2 -m%1 
Achmod %1 %2%3
H/n/gold/5/gurari/tex4ht.dir/
\EndVerbatim



\SubSection{Open Directory}


\<find tex4ht.env\><<<
{         Q_CHAR  str[512], *HOME_DIR;
   `<env file from command switch`>
   if( !file ) {  file = fopen("tex4ht.env", READ_TEXT_FLAGS);
       (IGNORED) strcpy(&env_loc[0],"tex4ht.env");
       if( debug && file ){  
         (IGNORED) printf(".......Open: ./tex4ht.env\n"); }
   }
   if( !file ) { `<env file from prog loc`> }
#ifndef DOS_WIN32
   if( !file ) {  file = fopen(".tex4ht", READ_TEXT_FLAGS);
       (IGNORED) strcpy(&env_loc[0],".tex4ht");
       if( debug && file ){  
         (IGNORED) printf(".......Open: ./.tex4ht\n"); }
   }
#endif
   `<env file at root dir`>
#ifdef ENVFILE
   if( !file ) {
      file = fopen( ENVFILE,READ_TEXT_FLAGS);
       (IGNORED) strcpy(&env_loc[0],ENVFILE);
       if( debug && file ){  
         (IGNORED) printf(".......Open: %s\n", ENVFILE); }
   }
#endif
   `<kpathsea env file`>
   if( !file ) warn_i_str( 5, `<warn 1`>);
}
>>>






\<h-defines\><<<
#ifndef ENVFILE

#endif
>>>



\<warn 1\><<<
#ifdef  DOS_WIN32
   "tex4ht.env"
#endif
#ifndef  DOS_WIN32
   "tex4ht.env | .tex4ht" 
#endif
>>>




\<kpathsea env file\><<<
#ifdef KPATHSEA
if( !file )  {
   file = kpse_open_file ("tex4ht.env", kpse_program_text_format);
   if( debug && file ){  
      (IGNORED) printf(".......Open kpathsea tex4ht.env\n"); }
}
#endif
>>>



\SubSection{Root Directory}

\<env file at root dir\><<<
if( !file ){                
  HOME_DIR = getenv("HOME");
  if( HOME_DIR ){ (IGNORED) sprintf(str,`<"s/tex4ht.env"`>, HOME_DIR);
     file = fopen(str,READ_TEXT_FLAGS);     
     (IGNORED) strcpy(&env_loc[0],str);
     if( debug && file ){  
        (IGNORED) printf(".......Open: %s\n", str); }
  }
}
#ifndef DOS_WIN32
  if( !file ){        
     if( HOME_DIR ){ 
          (IGNORED) sprintf(str,"%s/.tex4ht", HOME_DIR);   
          file = fopen(str,READ_TEXT_FLAGS);     
          (IGNORED) strcpy(&env_loc[0],str);
      }
  }
#endif
#if defined(DOS_WIN32) || defined(__MSDOS__)
   if( !file ){                
      file = fopen("C:/tex4ht.env",READ_TEXT_FLAGS);     
       (IGNORED) strcpy(&env_loc[0],"C:/tex4ht.env");
   }
#endif
>>>

\<"s/tex4ht.env"\><<<
#if defined(DOS_WIN32) || defined(__DJGPP__)
  is_forward_slash(HOME_DIR)?  "%s/tex4ht.env" :  "%s\\tex4ht.env"
#else
  "%s/tex4ht.env"
#endif
>>>











\SubSection{Env File from Command Line}

\<env file from command switch\><<<
file = tex4ht_env_file?
      fopen( tex4ht_env_file, READ_TEXT_FLAGS ) : NULL;
if( tex4ht_env_file ){
    (IGNORED) strcpy(&env_loc[0],tex4ht_env_file);
}
if( debug && file ){  
      (IGNORED) printf(".......Open: %s\n", tex4ht_env_file); }
>>>

\<env file from prog loc\><<<
if( dos_env_file ){
   file =  fopen( dos_env_file, READ_TEXT_FLAGS ) ;
   (IGNORED) strcpy(&env_loc[0],dos_env_file);
   if( debug && file ){  
      (IGNORED) printf(".......Open: %s\n", dos_env_file); }
}
>>>



Search along the path: command line file $\rightarrow$ work
directory $\rightarrow$ home directory $\rightarrow$ system file.

\<get .env directory from com ln\><<<
if( !access(p+2,F_OK) ) tex4ht_env_file = q; 
else warn_i_str(6,q);
>>>



The function \`'int access(const char *pathname, int mode)', and the mode
\`'F_OK' that tests for the existence of file, are defined in the
following directory. The function returns 0 if ok and -1 on error .

Where access comes from in dos?


\SubSection{Env File from Location of htcmd.c}

\<main's vars\><<<
Q_CHAR * tex4ht_env_file = (Q_CHAR *) 0;
Q_CHAR * dos_env_file =
#if defined(DOS_WIN32) || defined(__MSDOS__)
  `<get dos env file`>;
#endif
#if !defined(DOS_WIN32) && !defined(__MSDOS__)
  (Q_CHAR *) 0;
#endif

>>>

  Under DOS, argv[0] usually includes the full path to the program -
even if it wasn't typed in. This can be used to find the program's own
directory, and hence the configuration file. I've implemented this
already as follows:

\<get dos env file\><<<
get_env_dir(argv[0])
>>>

\<functions\><<<
#if defined(DOS_WIN32) || defined(__MSDOS__)
`<get tex4ht.env in dos`>
#endif
>>>

\<get tex4ht.env in dos\><<<
`[
char *get_env_dir(progname) 
      Q_CHAR *progname

;{    int  i;
      Q_CHAR *p;
  if(! progname || ! *progname)  return NULL;  `% Safety `%
  i = (int) strlen(progname);
  while( (progname[--i] != dir_path_slash(progname) )
        && i > 0) ;                               `%Search for slash`%
  if(i == 0)  return NULL;                        `%Not found? Give up`%
  p = (Q_CHAR *) malloc(i+12);
  if(p == NULL)  return NULL;     `%Space for new extention after dot`%
  strncpy(p, progname, i+1);                         `%Copy up to slash`%
  strcpy(&p[i+1],"tex4ht.env");                       `%Append new extention`%
  return p;
}
>>>






The 12 above is for accomodating \''tex4ht.env'.

  Then, in main(), I changed:

\`''char* tex4ht_env_file = (Q_CHAR *) 0;'

  to:

\`'char* tex4ht_env_file = get_env_dir(argv[0]);'

  This works like a charm here, and allows me to use tex4ht from a
different directory without typing a single commandline option.




\Section{Open Files}





\SubSection{General}

\<header functions\><<<
static FILE* open_file( ARG_II(C_CHAR *, C_CHAR *) );
>>>

\<functions\><<<
`[
static FILE* open_file(name,ext)     
                         Q_CHAR *name`; Q_CHAR *ext
;{                       FILE* file;
                         C_CHAR filename[255], *p;
   (IGNORED) strcpy( filename,name );   
   p = filename;
   while( TRUE ){
     if( *p == '.' ){ 
       if( eq_str( ext,LG_EXT ) ) { *p = '\0'; }
       else { break; }
     }
     if( *p == '\0' ){ (IGNORED) strcpy(p, ext); break; }
     p++;
   }
   file  = fopen(filename, READ_TEXT_FLAGS);  
   if( !file ) {
      (IGNORED) warn_i_str(5,filename);
   } else { (IGNORED) printf ("Entering %s\n", filename); }

   return file;
}
>>>


We have here a little inconsistency with tex4ht.c. There the input file
name is appended with the extension .dvi, allowing double extensions. 
Here, if an extension is present, we remove it before putting .lg on
top of the name. Should we fix that?




\<defines\><<<
#define LG_EXT ".lg"
>>>





% 
% \SubSection{htfcss.env}
% 
% 
% \<file = open htfcss.env\><<<
% if( htf_cfg ){
%    file  = open_file(htf_cfg, ".env");  
% } else {                                  C_CHAR filename[255];
%    file  = fopen("htfcss.env", READ_TEXT_FLAGS);            
%    if ( !file && env_htf_sty ){
%       (IGNORED) strcpy(filename, env_htf_sty);
%       (IGNORED) strct(filename, "htfcss.env");
%       file = fopen(filename, READ_TEXT_FLAGS);
%    }
%    if ( !file ){
%       (IGNORED) strcpy(filename, HTFDIR );
%       (IGNORED) strct(filename, "htfcss.env");
%       file = fopen(filename, READ_TEXT_FLAGS);
%    }  
%    `<htfcss.env in KPATHSEA`>
%    if( !file ) { (IGNORED) warn_i_str(5,"htfcss.env"); }
%    else { (IGNORED) printf ("Entering htfcss.env\n"); }
% }
% >>>
% 
% 



\<mark start lg file\><<<
begin_lg_file = ftell(lg_file);
>>>

\<rewind lg file\><<<
(IGNORED)  fseek(lg_file, begin_lg_file, `<abs file addr`>);
>>>

\<abs file addr\><<<
0>>>




\<vars\><<<
static FILE* lg_file;
static long  begin_lg_file;
>>>





\Verbatim
I've been held up a bit by a
bug in tex4ht.c that caused emTeX to complain that the created .idv file
was corrupt:

*** Fatal error 2106: corrupt DVI file (postamble not found)

  I found the cause, though: you open it with mode "w", which is text
mode. Changing this to "wb" solved the problem.
\EndVerbatim









\Section{Utilities}



\SubSection{Error and Warning Messages}

\<signals messages: 2--4\><<<
"Illegal storage address\n", `%2 segmentation`%
"Floating-point\n",          `%3 `%
"Interrupt with Cntr-C\n",   `%4 `% 
>>>

\<warn and err messages\><<<
`<command line options`>,                            `%0`%
"Insufficient memory\n",                                `%1`%
`<signals messages: 2--4`>
"Can't find/open file ``%s'\n",                         `%5`%
"Can't access directory ``%s\n'",                     `%6`%
>>>


\ifHtml[\HPage{more}\Verbatim
To: Eitan Gurari <gurari@cse.ohio-state.edu>
Subject: Re: texk4ht.c, small patch for win32
References: <199803130718.CAA17393@sunkist.cse.ohio-state.edu>
From: Fabrice POPINEAU <popineau@esemetz.ese-metz.fr>
Date: 13 Mar 1998 14:05:50 +0100
In-Reply-To: Eitan Gurari's message of "Fri, 13 Mar 1998 02:18:58 -0500 (EST)"
Lines: 43
X-Mailer: Quassia Gnus v0.37/Emacs 19.34
X-Emacs: 19.34
MIME-Version: 1.0 (generated by SEMI MIME-Edit 0.98 - "Sodani")
Content-Type: text/plain; charset=US-ASCII

>>>>> "Eitan" == Eitan Gurari <gurari@cse.ohio-state.edu> writes:

    Eitan> I also wonder whether the WIN32 really needs to discard the
    Eitan> following code fragment.

signal() is supported through the standard libc, but is mostly
ineffective. An example of the kind of code needed is attached.

Thanks for the mods,

Fabrice

/* Interrupt handler. mt_exit() is a cleanup_and_exit function */
#ifdef _WIN32
BOOL sigint_handler(DWORD dwCtrlType)
{
  mt_exit(3);
  return FALSE;      /* return value obligatory */
}
#else
void sigint_handler (int sig)
{
  mt_exit(3);
}
#endif

  /* Catch signals, so we clean up if the child is interrupted.
     This emulates "trap 'whatever' 1 2 15".  */
#ifdef _WIN32
  SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
#else
# ifdef SIGINT
  signal (SIGINT, sigint_handler);
# endif
# ifdef SIGHUP
  signal (SIGHUP, sigint_handler);
# endif
# ifdef SIGTERM
  signal (SIGTERM, sigint_handler);
# endif
#endif
\EndVerbatim\EndHPage{}]\fi

Msvc recommends not using printf, but we ignoring this recommendation
here with the assumption that the recommendation relates to I/O
interrupts that are not considered here.




\<header functions\><<<
#ifdef KWIN32
static BOOL sigint_handler(ARG_I(DWORD));
#endif
>>>

\<functions\><<<
#ifdef KWIN32
`[
static BOOL sigint_handler(dwCtrlType)     DWORD dwCtrlType
;{
  err_i(32);
  return FALSE;      `% return value obligatory `%
}
#endif
>>>


\SubSection{System Calls}



\<vars\><<<
static Q_CHAR command[255];
static 
>>>


The library \`'<stdlib.h>' includes a function
\`'int system(const char *cmdstring);'.   When cmdstring is NULL,
the return value is 0 iff the platform does not support system calls.


\<vars\><<<
static BOOL system_yes;
>>>

Solaris-? issues the command \`'-c: bad option(s)' if we check for the
presence of the system function.



\SubSection{Strings Concat and compare}



\<defines\><<<
#define eq_str(x,y) (!strcmp(x,y))
>>>






\SubSection{String into Int}

\<header functions\><<<
static long int get_long_int( ARG_I(Q_CHAR *) );
>>>

\<functions\><<<
`[
static long int get_long_int(str)     
                         Q_CHAR   *str
;{                  long int    i;
                         Q_CHAR   *ch;
   ch = str;   i = 0;
   while( (*ch>= '0') && (*ch <='9') ){
     i = 10*i + *(ch++) - '0';
   }
   return i;
}
>>>




\SubSection{Pattern Recognition Functions}


When  failure (false \''status') arises, the input line is consumed to
its end. 
The \''_until' functions place in ''match[i]' the string found.

\<header functions\><<<
static BOOL scan_until_end_str( ARG_IV(C_CHAR *, int, BOOL, FILE *) );
>>>

\<functions\><<<
`[
static BOOL  scan_until_end_str(str,n,flag,file)     
                         Q_CHAR   *str`;
                         int    n`;
                         BOOL   flag`;
                         FILE*  file
;{                       Q_CHAR   *p; 
                         int i;             
   if( !flag ) { return flag; }
   p = match[n];  i = 0;
   while( TRUE ){
     if( (i+1) >= max_match[n] ){
        max_match[n] += 10;
        p = match[n] = (Q_CHAR *)
                     r_alloc((void *) match[n], (size_t) max_match[n]);
     }
     p[i] = (char) (eoln_ch = getc(file));
     if( (eoln_ch == (int) '\n') || (eoln_ch == EOF) ){  break; }
     i++;
   }
   p[i] = '\0';
   i -= (int) strlen(str);
   if( i>= 0 ){  return eq_str(p+i,str);   }
   return FALSE;
}
>>>



\<vars\><<<
static Q_CHAR* match[10];
static int   max_match[10];
>>>


\<main's init\><<<
{          int i;
  for( i=0;  i<=9; i++){
    match[i] = (Q_CHAR *) malloc(70);
    max_match[i] = 70;
  }
}
>>>


\<header functions\><<<
static BOOL scan_until_str( ARG_IV(C_CHAR *, int, BOOL, FILE *) );
>>>

\<functions\><<<
`[
static BOOL  scan_until_str(str,n,flag,file)     
                         Q_CHAR   *str`;
                         int    n`;
                         BOOL   flag`;
                         FILE*  file
;{                       Q_CHAR   *p, ch;              
                         int i, j;             
   if( !flag ) { return flag; }
   p = match[n];  i = 0;
   while( TRUE ){
     ch =  (char) (eoln_ch = getc(file));
     if( (eoln_ch == (int) '\n') || (eoln_ch == EOF) ){  return FALSE; }
     if( (i+1) >= max_match[n] ){
        max_match[n] += 10;
        p = match[n] = (Q_CHAR *)
                     r_alloc((void *) match[n], (size_t) max_match[n]);
     }
     p[i++] = ch;
     j =  i - (int) strlen(str);
     if( j>= 0 ){
       p[i] = '\0';
       if( eq_str(p+j,str) ) { return TRUE;  }
     }
   }
}
>>>






\<header functions\><<<
static BOOL scan_str( ARG_III(C_CHAR *, BOOL, FILE *) );
>>>

\<functions\><<<
`[
static BOOL  scan_str(str,flag,file)     
                         Q_CHAR   *str`;
                         BOOL   flag`;
                         FILE*  file
;{                       Q_CHAR *p;
                         int temp_eoln_ch;              
   if( !flag ) { return flag; }
   p = str;
   while( *p != '\0' ){
     if( *(p++) != (temp_eoln_ch = getc(file)) ) {
        while( (temp_eoln_ch != (int) '\n')
            && (temp_eoln_ch != EOF) ){ temp_eoln_ch = getc(file); }
        eoln_ch = temp_eoln_ch;  return FALSE;
     }
   }
   return TRUE;
}
>>>
































\SubSection{Shorthands and Mnemonics}




\<defines\><<<
#define eq_str(x,y) (!strcmp(x,y))
>>>



\Section{Info}

\SubSection{str inconsistently in lint}

\Link[file://localhost/usr/lib/llib-lc]{}{}llib-lc\EndLink

\SubSection{About DOS}


\Link[http://www.ku.edu.tr/text/help/dos62\string_adv.html]{}{}%
DOS\EndLink,
\HCode{<LI><a href="http://www.csulb.edu/~murdock/easydosinfo.html">DOS the Easy Way</a>,
<LI><a href="http://www.csulb.edu/~murdock/dosindex.html">The Web-Based Guide to DOS</a>
}


\Verbatim
                               DOS 6.2: Advanced
                                       
What Are Batch Files?

     Batch files are user-written "mini-programs" in which each line is
     a DOS command. Such files are processed line-by-line, executing
     commands that have been batched together. Most of the time batch
     files are created to avoid having to type in a series of
     commonly-used commands. A simple example might be the following:
     CLS
     C:
     CD\WINDOWS
     DIR *.DOC
     This batch file will clear the screen, go to the c: drive,
     change directories to Windows, and list all the files .DOC
     extensions. If you carry out these four commands on a regular
     basis, and you're tired of typing them in each time, a batch file
     is your solution.
     
     Batches, however, can be quite complicated, executing a long chain
     of commands. One command in the chain might run a whole new batch
     file. It is even possible to create smart "batches" that test for
     certain conditions. For example, the above batch file might be
     written in such a way that it checks first for the existence of
     files with .DOC extensions before listing them.
     
Batch File Names

     Batch files are always given a filename with a .BAT extension. From
     that point on, the filename is considered a DOS command. When you
     type it, the series or batch of commands is immediately executed.
     For example, the above file might be given the name WINLIST.BAT.
     That way, whenever the user wants to see the .DOC documents in
     Windows, he or she just needs to type the command WINLIST and hit
     <ENTER>. It's not necessary to type in the .BAT extension. It's a
     very good idea to use file names that easily indicate the purpose
     of the "batch" and are easy to remember. Also, keep in mind these
     DOS conventions when creating batch files:
     * The filename must be eight characters or less in length.
     * Don't use capitalization, spaces, or punctuation marks in the
       filename.
     * Remember to add a .BAT extension.
     * Keep in mind that the full filename, such as WINLIST.BAT, has two
       parts, a main name and an extension, separated by a period. This
       will be important later when you are using the DIR command to list
       the batch files or the TYPE command to view them.
       
The AUTOEXEC.BAT file

     The AUTOEXEC.BAT is a special-purpose batch file that runs each
     time you start your computer. It is the most important batch file
     on your computer and must be treated with extreme care. If you
     accidentally delete you will crash your computer.
     
Displaying Batch Files

     It is possible to display the contents of a batch file without
     actually executing it. To display the contents of a batch, use the
     TYPE command. Example: TYPE AUTOEXEC.BAT <Enter>
     
     Batch files may also be loaded into a program called the DOS editor
     or into your favorite word processor for viewing, editing and
     printing. When you save a batch file with a word processor. though,
     you must remember to save the file as unformatted "DOS text" or
     "ASCII text."
     
Storing Batch Files

     In order to find your batch files quickly and to access them no
     matter what drive or directory you are currently using, group them
     together in a directory. Later, we will discuss how to include this
     directory in what is called the "command path". The "path" is
     simply a single statement in the AUTOEXEC.BAT file which tells your
     computer where to look for commands.
     
     When you type in a command your computer starts at the beginning of
     the path and works it's way to the end till it comes to the
     requested command. By the way, the AUTOEXEC.BAT must be in the root
     directory, which is always the beginning of the path, in order to
     automatically execute at startup. See "Writing an AUTOEXEC.BAT"
     later in this handout.
     
Creating Batch Files

     Batch files may be written a couple of ways:
    1. The EDIT command starts up a program called the "DOS editor." You
       can think of it as a very simple word processor that allows you to
       create files which are stripped of formatting. When you save a
       batch file with the DOS editor, it is saved as "DOS text" or
       "ASCII text", meaning that there are no word processing formatting
       codes attached to it. It's bare bones text.
    2. Better yet, use a word processor to create and edit your batch
       file. Wordperfect for Windows and Word for Windows are especially
       popular ones, because they have easy options to save the file as
       "DOS text" or "ASCII text". Wordperfect for DOS (Version 5.2)
       allows the same function when you save with CTRL + F5.
       
Common Batch File Commands

     Some typical DOS commands found in batch files are the following:
     * CLS -- Clears the screen; resets cursor at upper left of screen.
     DATE -- Sets the system date.
     TIME -- Sets the system time.
     C:-- Goes to the C: drive.
     A:-- Goes to the A: drive.
     CD-- Changes directories.
     DIR -- Lists files in the current directory.
     FORMAT A: -- Initializes a blank diskette in the A drive.
     PATH -- Lists directories to be searched for command files.
     PROMPT $P$G -- Shows the current drive, directory and subdirectory
       (which is known as the current "path").
     COPY -- copies a file to a specified location.
     REN -- renames a file.
     DEL -- deletes a file.
     TYPE -- prints the contents of a file to the screen.
     EDIT -- starts up the DOS editor, allowing you to edit a specified
       file.
     PRINT -- prints a specified file.
       
Batch File Subcommands--ECHO, REM, PAUSE

     Besides basic DOS commands, batch files can contain various
     subcommands typically used only in batch files. These subcommands
     provide the ability to print messages on the screen, permitting the
     user to type in conditions, allow "command loops" which execute a
     series of commands a certain number of times, or even branch off to
     execute other subsections of the batch file--all of which make the
     batch more efficient.
     
    ECHO
    
     The ECHO subcommand controls the display of batch file commands as
     they are executed. Normally, ECHO is "on". That means that as a
     batch file runs, the individual commands are displayed, along with
     the computer's response to those commands. For example, if you run
     the batch file WINLIST.BAT created earlier, the commands C:,
     CD:\WINDOWS, and DIR *.DOC would have appeared on screen at the DOS
     prompt, followed by the output of that command. Naturally, C: and
     C:\WINDOWS won't provide any output. But, DIR *.DOC will show both
     the command and the output. Now, even though the default setting
     has ECHO turned on, you can turn it off by entering the command
     ECHO OFF. From that point on, the commands will not show up on the
     screen. Don't worry, the output will still show. This, of course,
     will keep your screen looking neat and uncluttered. The following
     are examples of how the ECHO command is used:
     * ECHO Shows the current status of ECHO, whether it is turned on or
       off.
     ECHO OFF Turns off the display of commands. This command is usually
       put at the beginning of a batch file to suppress the commands in
       order to show output only.
     ECHO ON Turns on the display of commands.
     @ECHO The @ is used to prevent the words immediately following it
       from showing up on screen. So, if you wanted to turn off the ECHO,
       but you didn't even want the words ECHO OFF to appear on the
       screen, you would create the batch file command @ECHO OFF.
     ECHO [text] Displays the text following the ECHO command on the
       screen. This is a way to send messages to the user.
     ECHO. ECHO followed by a period inserts a blank line.
     ECHO >PRN Routes commands that would normally appear on the screen
       to the printer.
       
     Here's an example of how the ECHO command might be used in the
     WINLIST.BAT file created above:
     CLS
     ECHO OFF
     ECHO This is a list of files in Windows with .doc extensions.
     ECHO.
     C:
     CD\WINDOWS
     DIR *.DOC
     
    PAUSE
    
     The PAUSE command temporarily halts the batch file and prompts the
     user to hit a key to continue. In fact, PAUSE causes the line
     "Strike a key when ready..." to be printed on screen. But you can
     add another message to tell a user what to do next. Example: PAUSE
     CHECK PRINTER
     
    REM
    
     A REM subcommand indicates a remark. Remarks are non-executing
     lines of the batch file, intended for information only. Type the
     command REM, followed by a string of up to 123 characters. If ECHO
     is turned off, REM statements will not show up on the screen when
     the batch file is executed. Most of the time, users add REM
     statements as notes to themselves. For example, we can add a REM to
     our earlier batch: REM This batch file shows the documents in the
     Windows directory.
     CLS
     ECHO OFF
     ECHO This is a list of files in Windows with .doc extensions.
     ECHO.
     C:
     CD\WINDOWS
     DIR *.DOC
     
Replaceable Parameters

     Up to this point, the batch files you have written have performed
     an operation on drives, directories, file names and extensions
     specified within the batch commands. The result might be somewhat
     limited, though.
     
    What Are Parameters?
    
     Fortunately, DOS allows something known as a replaceable parameter,
     a.k.a. a "dummy parameter" or "variable." That is, if you
     substitute a % for a drive, directory, file name or extension in
     your batch file, DOS will understand the % to be a blank space.
     When you execute the batch, you will need to type in the batch file
     command immediately followed by the drive, directory, file name or
     extension you want to fill in the blank.
     
     This setup allows your batch files much greater flexibility. For
     example, the batch called WINLIST.BAT will only show you files
     ending with a .DOC extension. To make this batch file more
     efficient, you could substitute the .DOC with a % character
     followed by a number (1-9). This will allow you to type in a
     different extension when you type in the batch file command:REM
     This batch file shows specified items in the Windows directory.
     CLS
     ECHO OFF
     ECHO This is a list of files in Windows, extensions based on your
     parameter.
     ECHO.
     C:
     CD\WINDOWS
     DIR *.%1
     Now, when you want to use the batch file command, you must
     type the following:WINLIST DOC - to show files with .DOC
     extensions.
     WINLIST XLS - to show files with .XLS extensions.Note: There is a
     space between the command and the extension here, not a period.
     
    Multiple Parameters
    
     As you can see, the dummy parameter is a % followed by a number
     (1-9). You might want to add more than one parameter to a batch
     file, though. If so, start by using %1, and increase by increments
     of one. For example, the above batch could be revised to show two
     lists of documents based on two separate variables:
     REM This batchfile shows two lists of specified items in the Windows directory.
     CLS
     ECHO OFF
     ECHO Here are two lists of files in Windows specified by your parameter.
     ECHO.
     C:
     CD\WINDOWS
     DIR *.%1
     DIR *.%2
     When you enter the batch file command, you would add the
     two extensions to the command line, separated by a space. For
     example: WINLIST DOC XLS This would show you two separate lists: A
     list of .DOC files immediately followed by an inventory of .XLS
     files.
     
Invoking Other Batch Files

     One interesting feature of batch files is that a command embedded
     inside one batch can run a whole new batch file with a different
     name. This is commonly used in creating "menu" batch files. For
     example, you might have one batch file called MENU.BAT used to
     print a menu on the screen with options A, B, and C. Each of these
     letters might, in turn, be separate batch files with the file names
     A.BAT, B.BAT, C.BAT. That way a user can select option A, B, or C,
     and by typing in a single letter he or she can start up a different
     batch. For example, the A.BAT batch might start up Windows, the
     B.BAT might run Lotus, and the C.BAT might start Paintshop Pro.
     
CALL

     In a similar way the CALL subcommand can be used to link separate
     batch files. To use the command, add the line CALL immediately
     followed by the new batch. The current batch file will branch off
     to execute the other batch, and return later to finish any
     subsequent commands. For example, let's say you wanted to break the
     WINLIST.BAT into two separate batch files, a main one and a
     secondary one called DOCS.BAT. Let's suppose you wanted to do this
     because the DOCS.BAT file is a generic one that lists the documents
     with .DOC extensions in whichever is the current directory. In that
     case, your primary batch file, WINLIST.BAT, would look like
     this:
     REM This batch file goes into WINDOWS and calls DOCS.BAT
     CLS
     ECHO OFF
     ECHO.
     C:
     CD\WINDOWS
     CALL C:\DOCS.BAT
     ECHO There are no more documents.
     The CD\WINDOWS command will take
     you into the Windows directory, and then the batch file called
     DOCS.BAT will start up. It might look like this:
     ECHO Here are the .DOC documents in whichever is the current directory.
     DIR *.DOC
     Note that the syntax for the CALL command is CALL [Drive:]
     [Path] [Filename]. It is not necessary to include the extension
     .BAT after a filename used with CALL. Here the main batch file will
     branch off to execute the batch called DOCS.BAT, but afterward the
     last line of WINLIST.BAT will be executed, printing the message on
     screen "There are no more documents."
     
IF Conditional Statement

     The IF subcommand allows condition testing within a batch file. In
     effect, it allows the batch file to "make decisions" as it runs and
     to execute appropriate command accordingly. The syntax is IF
     [Condition] [Command]. The condition must be something that can be
     evaluated as either true or false. When the condition is true, the
     command is executed. When it's false, the command is skipped and
     the next line of the batch file is executed. Let's look at a simple
     example using WINLIST.BAT. Say you wanted to test this condition:
     If the user asks to see documents with a .DOC extension, then list
     them. If not, don't bother. Write it this way:
     REM This batch file tests to see if the user wants .DOC documents first, BEFORE calling DOCS.BAT
     CLS
     ECHO OFF
     ECHO.
     C:
     CD\WINDOWS
     IF %1 = DOC CALL C:\DOCS.BAT
     ECHO There are no more documents.
     
Redirection of Input/Output

     Normally, DOS allows your computer prints output to the screen.
     However, you can choose to redirect output to a the printer or to a
     file. To do so, use the > character. Usually, this character is are
     used together with the commands TYPE and DIR.
     
    To the Printer
    
     Directing output to the printer means you are sending it out
     through a port such as LPT1 and LPT2 (for parallel printers, like a
     dot matrix) or COM1 and or COM2 (for serial printers like a Laser
     Jet). As an alternative, send the output to the PRN, which stands
     for "printer." For example:TYPE LETTER.DOC > PRN - prints
     LETTER.DOC on the printer.
     DIR *.DOC > LPT1 - prints a list of .DOC documents on the printer
     hooked up to port LPT1.
     
    To a File
    
     Directing output to a file is the same as saving it to a file.
     Sometimes, for example, you may want to save a list of documents to
     review or print later. For example:DIR *.DOC > MYDOCS.LST - saves
     the list of .DOC documents to a file called MYDOCS.LST.To append
     output to an existing file, add the >> sign.DIR *.DOC >>FILES.TXT -
     attaches the list to an existing list of documents in the file
     called FILES.TXT
     
Writing an AUTOEXEC.BAT

     An autoexec.bat is a special-purpose batch file that runs each time
     you boot your computer. The name stands for "automatically
     executing." Every time you start your computer, DOS will search for
     an AUTOEXEC.BAT in the root directory. It is important to store
     your AUTOEXEC.BAT in this directory.
     
    What Should I Include In My AUTOEXEC.BAT File?
    
     Since it runs each time your boot the computer, an AUTOEXEC.BAT is
     useful for setting system parameters and startup tasks. The
     following are common commands:
     * PATH -- sets a search path for commands or other batch files. In
       effect, it tells the computer where to look for commands. It will
       start looking in the first directory and work its way to the end
       of the path. Each directory in the path is separated by a
       semicolon. See the example below.
     PROMPT $P$G-- sets the prompt to show you which drive and directory
       is currently "active".
       
    Creating An AUTOEXEC.BAT
    
     In order to create a practice AUTOEXEC.BAT, use the A: drive. DON'T
     MESS WITH YOUR ORIGINAL. If you put one on the A: drive, you will
     be able to turn off your computer and restart it with the disk in
     drive A: DOS will look for AUTOEXEC.BAT there first. Use the EDIT
     command to run the DOS Editor and type this simple example:
     ECHO OFF
     CLS
     PROMPT $P$G
     PATH=C:\;C:\DOS;C:\WINDOWS
     MENU
     
    Creating a Menu
    
     The last command in this practice AUTOEXEC.BAT automatically
     invokes another batch file called MENU.BAT. You would, of course,
     create this second batch with the DOS Editor. It might look like
     this:
     CLS
     ECHO OFF
     ECHO Main Menu
     ECHO.
     ECHO 1 - Windows
     ECHO.
     ECHO 2 - Word for Windows
     ECHO.
     ECHO 3 - Wordperfect for Windows
     
   This batch file doesn't really do anything. It just displays a menu on
   the screen and allows the user to select an option: 1, 2, or 3. Now
   you need to create separate batch files for each of the menu items.
   Each batch file should be named with a number corresponding to one of
   the menu choices. For example, 1.BAT is as follows:
   
     C:
     CD\WINDOWS
     WIN
     
   That will start up the program Windows when the user enters the number
   1. Note: The command WIN, which doesn't require the extension .EXE, is
   actually located in the C:\WINDOWS directory. However, if you have
   included C:\WINDOWS in the path statement of your AUTOEXEC.BAT file,
   you don't need to include it here in the 1.BAT batch file.
   
Hard Disk Considerations

    Size
    
     The size of a hard disk is now measured in megabytes and gigabytes.
     One thousand megabytes = 1 gigabyte. Hard disks usually come no
     smaller than 20 megabytes and can be as large as a gigabyte or
     more. Of course, the most important consideration when purchasing a
     hard drive is the size requirement of your software. The
     documentation will tell you, for example, "This product needs 33
     megabytes of free disk space." If you want to check the capacity of
     your hard disk, and the space available, use the CHKDSK command.
     
    Speed
    
     Speed is always an important factor to consider when you are
     purchasing a hard disk. The faster a hard disk, the more it costs.
     Here are some important questions to ask the salesperson:

Speed Factor          Explanation
Average Access Time       The average amount of time,usually measured in
                          milliseconds, it takes for the computer to
                          locate information on the hard disk.
Transfer Rate             How fast the computer can read from and write to
                          the hard disk.
Disk Cache                Refers to the speed at which the computer can
                          temporarily use part of your hard disk for
                          extra processing memory.

    Hard Disk Care
    
    1. Whenever you are moving a computer or hard disk, take great care
       not to jolt the hardware. Disk heads inside the device may rub
       against the actual disk and cause damage to the disk--sometimes
       irreparable--if the disk is moved suddenly. Never move a hard disk
       while the computer is turned on.
    2. Do not turn the hard disk or CPU containing a hard disk on its
       side without consulting your User's Manual.
    3. Place the drive on a sturdy and level surface.
    4. Do not use the hard disk at temperatures below 50 degrees
       Fahrenheit and above 104 degrees Fahrenheit.
    5. Do not use the hard disk if the relative humidity is not between
       20 and 80 percent.
    6. Keep food, drinks, cigarette smoke, and cleaning agents with
       vapors away from the drive.
       
Formatting a New Hard Disk

    Plug and Play Disks
    
     Some hard disks come already formatted with DOS installed. All you
     need to do is plug them in. If you turn on your computer without a
     diskette in drive A: or B: and the computer boots up successfully,
     then your disk has already been set up and formatted.
     
    Unformatted Hard Disks
    
     If your disk does not come formatted, you will have to format it
     yourself. Usually, the computer will come with the software
     necessary to format your disk. Usually the disk is labeled Install
     or Setup, and you would need to put that disk in drive A: or B: and
     type in the appropriate command (Install or Setup).
     
    When NOT To Format The Hard Disk
    
     Do not format the hard disk if the computer boots successfully and
     you see a DOS prompt or some other program come up. Remember,
     formatting erases all data from the disk.
     
    When To Format The Hard Disk
    
     If you just bought the hard disk and it has not been formatted, you
     should format it.
     
    Formatting As A Startup Disk
    
     To format the hard disk and transfer the DOS system files so you
     can start the computer from your hard disk, type: format c:/s
     
Partitioning the Hard Disk

     Before you can format a hard disk, you must partition it. Partition
     means to divide the disk into two or more separate sections. It's
     usually done so that the computer can run operating systems other
     than DOS. UNIX or XENIX, for example.
     
     However, let's say that you are just running DOS on your computer,
     and no other operating system. Then you still might consider
     partitioning your hard disk to divide it up into separate sections
     for better organization of your files. These sections are called
     "logical drives." The first partition is called the "active
     partition" is always located on the C: drive and contains three
     very important files needed to run DOS. These are IO.SYS, MSDOS.SYS
     and COMMAND.COM. The second partition is the one you would divide
     up into logical drives, giving each a separate letter designation,
     D - Z. That allows you a total of 23 extra logical drives. Each one
     of these is like a separate file cabinet that contains it's own
     group of directories. How you organize your hard disk is up to you.
     
     You can set up partitions on your hard disk before or after you
     format it--or during the installation of DOS. In any of these three
     cases, you use the FDISK command. If you have not formatted the
     disk, start the system with your DOS diskette in drive A:. At the
     DOS prompt, type FDISK. Obviously, if you have formatted the disk,
     you can just type the command at the DOS prompt. A menu comes up
     allowing you the following options:
    1. Create DOS Partition or Logical DOS Drive
    2. Set Active Partition
    3. Delete Partition or Logical DOS Drive
    4. Display Partition Information
       
     To partition the hard disk during DOS installation run SETUP on you
     DOS installation diskette. Partitioning is one of the options
     offered there. Warning: Re-partitioning erases existing partitions.
     Use extreme caution!
     
Copying DOS Files to the Hard Disk

     When you install DOS, the files are usually copied into the
     directory labeled DOS. If not, you can set up this directory and
     save your DOS files there by following these steps:
    1. Put your DOS diskette in drive A:
    2. Create a DOS subdirectory by typing: MD C:\DOS.
    3. Copy the DOS program files from A: to your new subdirectory by
       typing COPY A:*.* C:\DOS.
    4. Delete the file COMMAND.COM from the DOS directory, since a copy
       is placed in the root directory during formatting, by typing DEL
       C:\DOS\COMMAND.COM.
       
     Include the DOS directory in the path statement of your
     AUTOEXEC.BAT batch file.
     
Paths

     As was mentioned earlier in this handout, the path is a list of
     drives and directories which tells DOS where to look for commands.
     If you are in the root directory C:\ and the command WIN is in the
     Windows directory, DOS will not be able to find the command unless
     you give it the proper path. Most people put a permanent path in
     their AUTOEXEC.BAT batch file, listing all their primary drives and
     directories so that DOS will never have trouble finding a command.
     However, you can always enter a path at the DOS prompt if the drive
     or directory you want DOS to search is not specified in the
     AUTOEXEC.BAT
     
    Displaying The Current Path
    
     To display the current path, type: PATH
     
    Setting The Path
    
     To set the path, type in the full path, beginning with the root
     directory (C:\) and working your way through each primary
     directory, separating each with a semicolon.PATH=C:\;\DOS;\WINDOWS
     
    Canceling The Path
    
     To cancel the current path so that DOS will search only the current
     directory, type: PATH;
     
Configuring the System

     Another file which allows you more efficient use of your hard disk
     is the CONFIG.SYS file. It lets you override various system
     defaults set by DOS. A sample CONFIG.SYS file might look like
     this:
     buffers=22
     files=15
     device=mouse.sys
     * buffers= sets the amount of Random Access Memory that DOS reserves
       for data transferred from the hard disk.
     files= sets the number of files that DOS allows to be open at one
       time.
     device= loads what is called a "device driver" from the hard disk.
       
     Some applications require certain values for buffers or files. This
     information is given in the documentation under Setup or Install.
     Other applications automatically update your existing CONFIG.SYS
     with other values when they are installed. Before installing a new
     application, make a copy of your existing CONFIG.SYS with a name
     such as CONFIG.BAK. That way, if anything goes wrong, you can
     restore the original.
     
     A device driver is a file that is needed to run a device such as a
     mouse, joystick or sound card. When you install such a device, the
     driver is usually automatically copied to your CONFIG.SYS. If it is
     not, you might have to add the appropriate line to the CONFIG.SYS.
     Check the documentation for the appropriate driver.
     
Backing Up the Hard Disk

    When Should I Back Up?
    
     Once the hard disk is set up, you should do a complete backup.
     After that, the frequency of backups will depend on how much use
     your hard disk receives. But at least once a week, you should do a
     partial backup as illustrated below.
     
    Number The Diskettes
    
     Since the restore command (see below) will prompt you for disks by
     their numbers, be sure to number your floppy disks as you go. Files
     must be restored in the order in which they were backed up.
     
    Complete Backups
    
     To do a complete backup of the entire hard disk, including the
     organization of directories and subdirectories as well as files,
     type backup c:\*.* a:/s To do a complete backup which will also
     give you a printed list of the backup files, type backup c:\*.*
     a:/s >prn
     
    Partial Backups
    
     To do a partial backup after you have done a complete backup, add
     to the complete backup command the following parameters (you may
     use more than one at a time):
     * /a -- adds backup files to the current files on the floppy
       diskette rather than writing over the existing files on the disk.
       Unless you specify this option, copies of any old files on a
       backup floppy diskette are erased before the new files are written
       on it.
       Example: C:\>backup c:\*.* a:/s/a
     * /d mm-dd-yy -- backs up all files created or altered on or after
       the specified date. To use this parameter, you must have been
       consistent about entering the correct date every time you started
       the machine.
       Example: C:\>backup c:\*.* a:/s/d 4-16-89
     * /m -- backs up all files that have been created or modified since
       the last backup.
       Example: C:\>backup c:\*.* a:/s/m
       
    Daily Backups
    
     You may want to create a batch file to run at the end of each day
     to back up any files created or modified. The following is an
     example of such a file, which backs up modified files in any
     subdirectories, adding them to the existing files on the backup
     diskette and giving you a printed list of the backup files. Let's
     say you created it using the DOS Editor and called it
     BACKUP.BAT.backup c:\*.* a:/s/m/a >prn
     
Restoring Files from Backups

     You must use the DOS restore command to transfer files created with
     backups from a floppy to a hard disk. The restore command converts
     the backed-up files for normal use. Do not attempt to use the DOS
     copy command to transfer files from backup diskettes. Restore will
     prompt you to insert backup diskettes in numbered order. Files will
     be replaced in subdirectories if you specified /s during the backup
     procedure. To restore all files from floppies back onto a newly
     formatted hard disk, typerestore a: c:\*.* /s
     
   This document is a publication of The Office of Information Technology
   at The University of North Carolina. It may be copied for individual
   or non-profit use. Please send comments about this publication to CB#
   3450, 402 Hanes Hall, Chapel Hill, NC, 27599-3450. Authors: Doug Ens.
   Editor: Kathryn McDonnell. Web Editor: Kathy Edwards. Revision date:
   5/21/94. Print date: . OIT Document DDS05
   
     _________________________________________________________________


\EndVerbatim

\HCode{<HR>}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\Verbatim

alain.chilles@hol.fr  

 Alain Chill\`es
 12, rue de l'Ermitage 
 78000 Versailles      

> 2) display and giftrans are not very good (many errors, screen's 
> gestion...) I tried with netpbm which is given with latex2html, and I 
> replace in convert.bat the last commands by :
> 
> echo Creating .ppm file
> pcxtoppm tmp00%2.pcx > ppm00%2.ppm   =20
> echo Cropping it
> pnmcrop ppm00%2.ppm > ppm10%2.ppm
> echo Creating .gif (transparent) file
> ppmtogif -transparent 1,1,1 ppm10%2.ppm > %3
> 
> It seems to do a good work...

If it is fine with you, I'll add the above code to the next
distribution with an acknowledgment to you.  I have very little
knowledge of DOS and PC Windows, and I rely on users' contributions
for such ports.


\EndVerbatim

\HCode{<HR>}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\Verbatim
 > Unfortunately, this doesn't solve the problem.  If I get to text-mode
 > by switching from a graphical-window, once I come back, my
 > graphical-window is gone

  I don't understand this. Once you come back from what? From text-mode?
But then the graphical window would re-appear (or you wouldn't be back
from text-mode).

 > and the entry in the start menu that got me
 > the window in the first place is ruined (i.e., it now connects into
 > text-mode instead of bringing up a graphical window).

  The default MS-DOS prompt window settings are such that it retains the
setting it last had between sessions.  This means that if you close the
DOS window in graphical mode, the next time you start one it will come
up in graphical mode; likewise, if you close it while in text mode, it
will come back in text mode next time.

  I have checked the compilation of the test files under W95, and also
noted that Display switches the screen to text-mode (which doesn't make
much sense to me).  I've made a note of this in the port manual.  What
you should probably do to solve your problem is change the DOS-prompt
window settings to always start up in windowed mode.  To do this, either
click on the icon in the top left corner of the window (beside the title
bar) and select Properties, or use the properties button on the button
bar (the third rightmost on my system).  You'll get an MS-DOS prompt
properties window; select the screen tab, and uncheck "Restore settings
on startup".
-----------------------------------------------------------------

> while, but it's unlikely I'll do much work for a while.

As far as I'm concern, we can go public with what we have now.

>  > Unfortunately, this doesn't solve the problem.  If I get to text-mode
>  > by switching from a graphical-window, once I come back, my
>  > graphical-window is gone
> 
>   I don't understand this. Once you come back from what? From text-mode?

Yes. From the text-mode.

> But then the graphical window would re-appear (or you wouldn't be back
> from text-mode).

Yes and not.

If I leave the text-mode with Alt-Enter, then everything works fine.
Moreover, In future calls to `ht...', all the work is done within the
graphical-window of dos without interrupting to text-mode.

If I leave the text-mode with Exit, then the problems I described
earlier occur.  

Without automatically returning from the text-mode, appending the
following in the documentation with `(not Exit!)', and giving an early
warning also in `6.1 The test files', should do the job.

   Another problem exists when using the port in a DOS box under
   Windows '95, and possibly Windows 3.11: the display program
   switches a windowed DOS box to full screen. Restoring the
   previous setting is a matter of pressing Alt-Enter (not
                                                      ^^^^
   Exit!).
   ^^^^^^

>   The default MS-DOS prompt window settings are such that it retains the
> setting it last had between sessions.  This means that if you close the
> DOS window in graphical mode, the next time you start one it will come
> up in graphical mode; likewise, if you close it while in text mode, it
> will come back in text mode next time.

Well, at least I learned the difference between Exit and Alt-Enter.

 
>  > Well, at least I learned the difference between Exit and Alt-Enter.
> 
>   Exit closes the DOS box, possibly (depending on how it's configured)
> retaining the screen settings until the next DOS box. Alt-Enter just
> switches it between windowed and full-screen mode; the two are not even
> remotely alike ;-)  I've added a comment about exit to the manual, but
> the one you provided suggests that Alt-Enter and Exit have similar
> functionality, which is not the case.  I hope my alternative works for
> you too.

\EndVerbatim



\SubSection{scripts from Steven Zeil}
\Verbatim

Date: Tue, 27 May 1997 13:30:48 -0400 (EDT)
From: "Steven J. Zeil" <zeil@cs.odu.edu>
To: gurari@cse.ohio-state.edu
Subject: TeX4ht: thanks & comments
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

Dr. Gurari,

I recently came across your TeX4ht system, and would like to thank you for
making it available.  I've been a long-time user of latex2html, but have
been increasingly frustrated at the fragility of that converter. I had
come to the conclusion some time ago that much of the problem with
latex2html lay in the use of Perl scripts to emulate the macro definition
and execution facilities of TeX and LaTeX, and felt sure that a more
stable converter would be possible that allowed TeX to handle its own
macros, but did the conversion from a combination of the .dvi file and
redefining the "standard" LaTeX commands.

I had actually gone so far as to prototype such a converter, using dvi2tty
to extract plain-text from the .dvi file, and redefining LaTeX commands to
either insert html tags into the output text or else to use \specials to
mark the beginnings and ends of images, when I saw a reference to your
system. It looks very much like what I had been hoping for, and my initial
experience with using it has been very pleasant.

I hope you will continue to develop and support it (though I
fully understand how hard it can be for a faculty member to find time to
do so).  I've prepared a few comments in
http://www.cs.odu.edu/~zeil/tex4ht/tex4ht_discussion.html


Steven Zeil,
Old Dominion University
[Ph.D. from Ohio State CIS Dept, 1981]




%---------------------------------------------------------------------

                             Some notes on TeX4ht
                                       
   Some samples of documents I have produced:
   
     * A Unix tutorial
     * Reference sheets for the C++ Standard Template Library (STL)
          + Algorithms
          + Containers
       
   Notes:
   
     * Waiting until the \begin{document} to declare for the first time
       whether to do normal LaTeX processing or html generation is a bit
       too late. I would like to be able to provide html-aware
       equivalents of standard LaTeX packages (e.g., graphics). But if I
       provide these in package form, they must be \use'd before the
       \Preamble. Thus they cannot use \ifHtml to choose among alternate
       definitions.
     * The most time-consuming part of the conversion is generating the
       .gif images. I've tried to speed this up a bit:
          + My script for generating the .gif files (1) saves the old .ps
            file. After the new .ps file for the image has been created,
            it is compared to the old one. If unchanged, then the .gif
            file previously generated for that image is reused, rather
            than take the time to produce a new one.
          + After all the .gifs have been produced, this  script (2) compares
            the .gifs. If duplicates are found (For example, my STL
            Containers document produces many, many images for the same
            mathmatical expressions e.g., log N), then the .html files
            are edited to use only one of the duplicate .gifs. This can
            significantly reduce the time required to load a document, as
            the repeated references to the same .gif will be served from
            the browser's cache rather than being repeatedly retrieved
            from over the net.
     * Both of the above scripts could be made more portable by rewriting
       them in Perl. Perl could easily replace the use of the sed tool as
       well. Replacing the use of cmp would be more of a problem.Another
       possibility would be to follow the route taken by latex2html and
       use dbm to maintain a content-based ps->gif map. But the use of
       dbm seems to be one of the sticking points in latex2html's
       portability to Win32 systems. By contrast, one can easily obtain
       bash, sed, and cmp as part of the gnuwin32 (4) release, allowing the
       use of these scripts with little or no change.

%--------------------------------------------------------------
(1)

#/bin/sh
#
#  Usage
#    tex4ht.makegif basename pagenumber destination
#
####################################################
#
# Produce the image in postscript form, as $3.new.ps
#
dvips -mode ibmvga -D 110 -f $1.idv -pp $2 > $3.new.ps
#
#
# Check to see if a previous use of this script has left behind a $3.ps file
#
if test -r $3.ps
then
#
#  If so, and if the $3.ps and $3.new.ps files are identical, then the
#  $3.gif file from that previous execution can be retained, and we can avoid
#  the time-consuming ps->gif conversion.
#
  if cmp -s $3.ps $3.new.ps
  then
    echo $3 is unchanged.
    rm $3.new.ps
  fi
fi
#
#
# But if no old file exists, or the .ps files were different, then
# use the new.ps file to produce the .gif image.  Retain the $3.new.ps
# file as $3.ps for possible future reuse.
#
if test -r $3.new.ps
then
  mv $3.new.ps $3.ps
  convert -crop 0x0 -density 110x110  -transparent '#FFFFFF' $3.ps $3
fi


%-------------------------------------------------------------------

(u3)


#!/bin/sh
#
#  reduceGifs base
#
#    Compares all files of form $base*.gif to one another
#    For each pair of identical .gif files are found, the files
#    $base*.htm* are edited so that references to these separate
#    but equal files are replaced by repeated references to the
#    same file.
#
#    This can speed up the loading of some html files by a significant
#    amount.
#
echo > reduceGifs.sed
duplicatesFound=0
for fileA in $1*.gif
do
  Adone=0
  for fileB in $1*.gif
  do
    if test $fileA = $fileB
    then
      Adone=1
    fi
    if test $Adone = 0
    then
       if cmp -s $fileA $fileB
       then
          echo s/$fileA/$fileB/g >> reduceGifs.sed
          duplicatesFound=1
          Adone=1
          echo $fileA and $fileB are duplicates.
          rm $fileA
       fi
    fi
  done
done
#
if test $duplicatesFound = 1
then
  for fileA in $1*.htm*
  do
    mv $fileA $fileA.bak
    echo >> $fileA.bak
    sed -f reduceGifs.sed < $fileA.bak > $fileA
  done
fi

%-----------------------------------------------

(4) 
http://www.cygnus.com/misc/gnu-win32/

\EndVerbatim


\ifHtml[\HPage{more}\Verbatim
From: "Philip A. Viton" <pviton@magnus.acs.ohio-state.edu>
To: gurari@cse.ohio-state.edu
Subject: saving time
Date: Sun, 22 Nov 1998 15:11:12 -0400



Eitan:

I took a look at Steven Zeil's suggestion on generating gifs, and I agree
that it has possibilities; but as he points out, the cmp utility isn't
available for nt: the two file comparison utilities which are available
aren't meant to report a silent yes-or-no answer: they both display lots of
data, and I don't know if they return with some checkable return-code or not. 

Presumably one can get a cmp.exe using the cygnus port of the gcc compiler,
but this requires a 500K dll to copy with the unix overhead. It may be
possible to make cmp with the non-unix/non-cygnus version of gcc for win32,
but I don't know. (I have this compiler, so if you have cmp's source I can
easily check).
 
On the other hand, in some respects this is over-kill. SZ saves all the .ps
files; my point is that at least for the glyph-gifs this isn't needed,

\EndVerbatim\EndHPage{}]\fi


\SubSection{Makefile Tricks}


\Verbatim

normal:
        hugelatex '\def\Status{0}\input live'

pdf:
        pdflatex '\def\Status{1}\input live'

html:
        latex '\def\Status{2}\input live'
        tex4ht live

xxx:
        perl htcmd.perl live

clean:
        -rm *.dvi *.aux *.log *.blg *.toc *.out
        -rm *.xref *.lg *.idv *.out *.otc tmp.* *.css

realclean: clean
        -rm live.pdf
        -rm live.bbl
        -rm *.html *.htm


bib:
        -bibtex live


\EndVerbatim




\Section{Setting by Viton}

\Verbatim

                            TeX4HT under MiKTeX
                                      
                              Philip A. Viton
                                      
1  Introduction

   This note explains how to set up a working version of TeX4ht, Eitan
   Gurari's TeX/LATEX-to-HTML translation system, when the underlying TeX
   engine is Christian Schenk's MiKTeX for Win32 platforms. Thanks to
   Eitan for answering lots of TeX4ht questions, to Piet van Oostrum for
   helping with an important MiKTeX-related problem, and most of all to
   Gaunce Lewis for helping me solve the font-making problem described in
   section 7.
   
2  Get the software

   Besides a standard MiKTeX setup, you will need the following freely
   available software packages:
     * TeX4ht : the translation system itself. Be sure to get the Win95
       version.
     * ImageMagick : for translation of postscript to gif images.
     * Ghostscript : used by ImageMagick in the translation.
       
   Choose directories for each of these packages, and unzip the
   distributions, being sure to preserve directory (folder) names. Note
   that you will need an unzipper which understands long file names. In
   what follows, I assume the following directories:
     * For TeX4ht: c:\tex4ht
     * For ImageMagic: c:\ImageMagic
     * For Ghostscript: c:\gs
     * For MiKTeX itself: c:\texmf (this is the default root of the
       MiKTeX system, but you are offered the opportunity to change it
       when you install the system).
       
   and if you select others, you will need to modify the instructions
   accordingly.
   
3  Set up MiKTeX

   Two of the style files of TeX4ht need to be moved into MiKTeX's LATEX
   tree.
     * create a directory c:\texmf\tex\latex\tex4ht
     * move tex4ht.sty and tex4hta.sty from the TeX4ht directory to this
       one.
     * update the MiKTeX database: from the MiKTeX program group do
       Maintenance then Refresh filename database. This runs a quick DOS
       session which updates the database.
       
4  Set up dvips

   TeX4ht uses dvips to create Postscript images of symbols which are
   unavailable in standard fonts. It does so in a special Metafont mode
   called ibmvga, and you need to tell dvips and Metafont about it.
     * Locate the dvips configuration file config.ps, typically in
       c:\texmf\dvips\config\local
     * Make a copy of this file under the name config.ibmvga
     * Use a text editor to edit config.ibmvga, and make the following
       changes:
          + at the top of the file change the Metafont mode from M ljfour
            (or whatever printer you selected when you set up MiKTeX) to
            M ibmvga.
          + below that, change the dpi resolution from D 600 (or whatever
            resolution your default printer is set up for) to D 110.
          + Comment out (by preceeding each line with a semi-colon) the
            approximately 11 lines following the instruction ;;;Comment
            these lines if you don't have PostScript versions of the
            fonts: we want Metafont to create these font files if they're
            requested, since we can't assume that readers will have
            postscript fonts.
     * Save the file config.ibmvga
     * From a DOS session, run initexmf -u to update the confguration
       files. If you forget this, then dvips will not be able to make
       fonts at the required resolution.
       
5  Set up ImageMagick

     * Switch to the ImageMagick directory, and check that there exists a
       file delegates.mgk. If not, copy the file
       c:\ImageMagic\delegates\delegates.nt to the main ImageMagick
       directory as delegates.mgk.
     * Use a text editor to open delegates.mgk. In this file there are
       about 5 instances of calls to the program gswin. In each of these
       replace gswin by the full path and executable name to the
       command-line version of Ghostscript, typically c:\gs\gswin32c.
       If you omit the ``c'' and refer only to gswin32 you will get the
       windowed version of Ghostscript: each time it is called to
       translate a file, it will pop up an empty window, do the
       translation, and close the window. It seems to make no difference
       which version you use, but since the TeX4ht system is a
       command-line utility, it is less distracting --- and may save a
       bit of time, too --- to run the command-line version of
       Ghostscript.
     * In order for ImageMagick to find its delegates file, you need to
       set the environment variable delegate_path. You can let the batch
       file xht.bat described in section 8 do it for you, or you can do
       it directly:
          + Under Windows NT: open the Control Panel, choose System, then
            Enviroment. At the bottom of the dialog under Variable: enter
            delegate_path, and under Value: enter c:\ImageMagic. Click
            OK. This will take effect the next time you start a DOS
            session.
          + Under Windows95: edit autoexec.bat; add the line
            set delegate_path=c:\ImageMagic. You may need to re-boot for
            the changes to take effect.
       
6  Set up TeX4ht

   First, you will need to add TeX4ht's directory to your path. You can
   do this from the Windows NT Control Panel (or by editing autoexec.bat
   in Windows95), or you can let the batch file xht.bat described in
   section 8 do it for you.
   Next, switch to the TeX4ht directory. Use a text editor to open the
   file tex4ht.env, and make sure that the following are correct:
     * the first uncommented line begins with a t   : the remainder of
       this should contain a path to the MiKTeX tfm files. For the
       standard MiKTeX distribution change the line to read
       tc:\texmf\fonts\tfm! --- note the trailing exclamation point,
       which is required, and be sure to include the leading t.
     * Locate the line beginning Gdvips32 and change it to Gdvips. To
       have dvips make the right fonts you need to change -mode to -P so
       that that part of the line reads -P ibmvga (note: capital ``P'').
     * Locate the line beginning Gconvert ... . On this line:
          + change convert to the full drive/path name to the convert
            utility: under the directory assumptions made here the line
            would begin Gc:\ImageMagic\convert. Be sure not to delete the
            initial ``G'' which is needed by TeX4ht.
          + make sure that the line says -transparent #FFFFFF and not
            -transparent '#FFFFFF' (ie, no quotes).
     * under this, make sure that you see Gdel %%3, and not Gdel %%%3
       (remove the extra % if necessary).
     * change Gcopy /y %%1 %%2%%3 to Gcopy %%1 %%2%%3 (remove the /y).
     * change Gmove /y %%1 %%2%%3 to Gmove %%1 %%2%%3 (remove the /y). I
       don't know whether Windows95 supports the move command: if it
       doesn't, you will have to figure out how to simulate it.
     * the last line of the file should read H followed by the full drive
       plus path to the TeX4ht files. If you chose the default location,
       you will not need to change this.
       
   Finally, open the file ht.bat. Make sure the last line reads
   
   htcmd %2 -eC:\tex4ht\tex4ht.env
          
   and if it doesn't, add the -e switch, whose argument is the drive plus
   path to the TeX4ht files.
   
7  Solving font problems

   When a font is not found, dvips calls Metafont; but if Metafont has
   trouble making the font, then the font will not be placed where dvips
   can find it. Unfotunately, Metafont has problems with about 15 fonts
   in ibmvga mode, and while they do not apparently lead to any major
   ill-effects when viewing the output on the Web, the result isn't quite
   perfect enough for Metafont.
   To solve the problems, you need to make the problem fonts ``by hand''.
   Here's how.
     * Run TeX on your document without the TeX4ht extensions (ie,
       disable \usepackage{tex4ht}).
     * Now check for any font problems. Open the previwer yap. Click on
       View then Options then Display. Under Mode choose IBM vga (110
       dpi) and click OK. Ignore the warning about it's not being
       recommended to have screen and printer at different resolutions.
     * Open your document in the previewer and page through it. One of
       three things will happen:
          + Metafont never runs. In this case you can immediately use
            TeX4ht to process your document.
          + Metafont runs, but the DOS window closes without your
            intervention. In this case, Metafont has succeeded in making
            a missing font. You can now use TeX4ht to process your
            document.
          + Metafont runs, but there is a problem. The DOS window opens,
            but waits for you to close it manually. At this point you
            need to make a note of the font which caused the problem. At
            the bottom of the window, you will see approximately the
            following:
            Output written on cmr5.72gf
            Transcript written on cmr5.log
            Metafont failed on cmr5! Return code 1
            Press any key to continue ...
          + Look at the first of these lines, and write down (a) the font
            name (which is the text before the .72gf, here cmr5), and (b)
            the resolution ( the text just before gf, here 72).
          + Do this for each font for which Metafont reports a problem.
     * You should now probably set yap's display resolution back to its
       original value; exit yap.
     * Now you need to make any fonts Metafont choked on, ``by hand''.
       I've made a little batch file, epfont.bat, which you can download
       here, and which eases the difficulties for you. (This is based on
       the work of Gaunce Lewis; I'm grateful to him for sharing it with
       me). The batch file is set up to make fonts in ibmvga mode, but it
       contains instructions on how to customize it for any mode. To use
       the file:
          + Copy it to any directory.
          + For safety, do del epfix.bat though there probably won't be
            any file to delete.
          + Repeatedly run epfont, once for every font you noted in the
            previous step, where Metafont fails. The arguments to epfont
            are (1) the font name (cmr5 in the example) followed by the
            resolution (72 in the example), so in this case you'd say
            epfont cmr5 72.
          + epfont creates a file epfix.bat. This file contains run-able
            instructions to have Metafont create your problem fonts. But
            before running it:
               o Open epfix.bat in a text editor.
               o Do a global search-and-replace: replace the string /d by
                 a blank.
               o Scan thorough the file and look for any lines which end
                 ...already exists!. This says that you asked Metafont to
                 make a file which is already made. When you see one of
                 these, delete the entire ``section'' of the file
                 associated with that font. Sections begin with a line
                 that says REM followed by one that says REM   fontname
                   resolution where fontname and resolution are echoes of
                 information you provided.
               o Save epfix.bat and run it from the command line. This
                 will make all missing fonts connected with your
                 document. You can now safely run TeX4ht.
       
8  The batch file xht.bat

   I've created a small batch file called xht.bat which takes care of
   several of the details associated with running TeX4ht. You can place
   the batch file in a directory in your path and then call it from any
   place on your hard disk. The batch file is set up with the directory
   defaults as described in section 2; if you choose different locations,
   you will need to edit the file accordingly.
   The syntax, which you will be reminded of if you call xht with no
   parameters, is the same as for TeX4ht's starting batch file ht.bat:
   
   xht tex myfile   for a plain TeX file, or
          
   xht latex myfile   for a LATEX file.
          
   What the batch file does is:
    1. It adds the TeX4ht directory to your path before calling the
       translator, and then removes it when the job ends.
       There is a cost to this: we save a copy of the current path in the
       environment variable opath, and then append the TeX4ht directory
       to path. At the end of the batch file, path is set equal to opath,
       and opath is erased. The cost is the length of opath, which is
       temporarily added to your environment. Under Windows NT4 this will
       never be a problem, but it is possible that you could run out of
       environment space under Windows 95. If that happens you will
       probably need to alter autoexec.bat.
    2. It sets the environment variable delegate_path required by the
       ImageMagick convert utility; and then removes it when the job
       finishes.
    3. Since I tend to forget to specify tex or latex, xht.bat does a
       quick check to see that you have actually provided two parameters.
       (However, note that it doesn't check that the first parameter is
       either tex or latex: it would be easy to add this if you need it).
    4. It also tries in a simpleminded way to check that you provide the
       name of the source (.tex) file without an extension: it adds the
       extension .tex to the name of the source file which you provided:
       if that file exists, then we assume that you did not provide the
       extension. This will fail if you provide, say, myfile.tex and the
       file myfile.tex.tex happens also to exist in the same directory.
       In my case, I can be sure that this won't happen, but your habits
       may differ.
       
   You can download the batch file xht.bat here.
     _________________________________________________________________
   
     This document was translated from LATEX by HEVEA
     http://para.inria.fr/~maranget/hevea. 

\EndVerbatim

\SubSection{htx.bat}

\Verbatim
@echo off
:: cover funciton for Eitan Gurari's TeX4ht system.
:: Phil Viton, November 1998
if "%2"=="" goto syn
if not exist %2.tex goto syn1
set opath=%path%
set path=%path%;c:\tex4ht
set delegate_path=c:\imagemagic
call ht %1 %2
set path=%opath%
set opath=
set delegate_path=
goto end
:syn
echo TEX4HT - syntax is tex4ht [tex/latex] file w/o extension
goto end
:syn1
echo TEX4HT - file %2.tex not found
:end
echo.
\EndVerbatim




\ifHtml[\HPage{c:/EMTEX/MFINPUT/ETC/LOCAL.MF}\Verbatim
%
% local.mf -- Lexmark Optra added
%

base_version:=base_version&"/emTeX";

% ------------------------------------------------------------
% Define modes
% ------------------------------------------------------------

%
% HP LaserJet+ (300 DPI)
%
mode_def laserjet =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=300;
 blacker:=0;
 fillin:=.2;
 o_correction:=.6;
 enddef;

%
% HP LaserJet 4 (600 DPI)
%
mode_def laserjetIV =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=600;
 blacker:=.25;
 fillin:=0;
 o_correction:=1;
 enddef;

%
% HP DeskJet (300 DPI)
%
mode_def deskjet =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=300;
 blacker:=0;
 fillin:=0;
 o_correction:=.6;
 enddef;

% From modes-3.0.mf
% Michael Covington's (mcovingt@ai.uga.edu) definition for the Lexmark
% Optra R (4049), reflecting a taste for a heavier than normal rendition
% of the Computer Modern fonts.
%
% You may prefer a lesser value of blacker (down to maybe 1.0).
% Initially tested on 10, 12, 17-point CMR and 10-point math italic.
%
% While we're talking about the Optra R, here's another useful fact: it
% takes 32-bit-wide 72-pin SIMMs, 70 or 80 ns.  Contrary to the
% documentation, you do not have to use IBM's special SIMMs.  On the
% whole, it's a superb printer, 1200 dpi PostScript for $<\$1500$.
%
mode_def lexmarkr =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=1200;
 blacker:=2.0;
 fillin:=0;
 o_correction:=1;
 enddef;

%
% Epson FX-80 (240x216 DPI)
%
mode_def epsonfx =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=240;
 aspect_ratio:=216/240;
 blacker:=0;
 fillin:=0;
 o_correction:=.2;
 enddef;

%
% Epson FX-80 (landscape mode: 216x240 DPI)
%
mode_def epsonfxl =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=216;
 aspect_ratio:=240/216;
 blacker:=0;
 fillin:=0;
 o_correction:=.2;
 enddef;

%
% Epson MX-80 (120x216 DPI)
%
mode_def epsonmx =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=120;
 aspect_ratio:=216/120;
 blacker:=0;
 fillin:=0;
 o_correction:=.2;
 enddef;

%
% Epson Stylus (360 DPI)
%
mode_def epsonsty =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=360;
 blacker:=.35;
 fillin:=0;
 o_correction:=.8;
 enddef;

%
% NEC-P6 high resolution (360 DPI)
%
mode_def lqhires =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=360;
 blacker:=0;
 fillin:=.2;
 o_correction:=.6;
 enddef;

%
% LQ-1500, NEC-P6 medium resolution (360x180 DPI)
%
mode_def lqmedres =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=360;
 aspect_ratio:=180/360;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% LQ-1500, NEC-P6 medium resolution (landscape mode: 180x360 DPI)
%
mode_def lqmedresl =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=180;
 aspect_ratio:=360/180;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% LQ-1500, NEC-P6 low resolution (180 DPI)
%
mode_def lqlores =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=180;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% C.ITOH 8510A (160x144 DPI)
%
mode_def itoh =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=160;
 aspect_ratio:=144/160;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% C.ITOH 8510A (landscape mode: 144x160 DPI)
%
mode_def itohl =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=144;
 aspect_ratio:=160/144;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% FAX (204x196 DPI)
%
mode_def fax =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=204;
 aspect_ratio:=196/204;
 blacker:=0;
 fillin:=.2;
 o_correction:=.2;
 enddef;

%
% FAX (landscape mode: 196x204 DPI)
%
mode_def faxl =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=196;
 aspect_ratio:=204/196;
 blacker:=0;
 fillin:=.2;
 o_correction:=.2;
 enddef;

%
% HP QuietJet (192 DPI)
%
mode_def quietjet =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=192;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% HP ThinkJet (192x96 DPI)
%
% Warning: Many fonts break at such low a resolution
%
mode_def thinkjet =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=192;
 aspect_ratio:=96/192;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% HP ThinkJet (landscape mode: 96x192 DPI)
%
% Warning: Many fonts break at such low a resolution
%
mode_def thinkjetl =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=96;
 aspect_ratio:=192/96;
 blacker:=0;
 fillin:=0;
 o_correction:=.1;
 enddef;

%
% Canon BubbleJet 10ex (360 DPI)
%
mode_def canonbj =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=360;
 blacker:=.6;
 fillin:=0;
 o_correction:=.6;
 enddef;


%
% Select default mode
%
localfont:=laserjet;

%
% Complain about unknown mode
%
let plain_mode_setup_ = mode_setup;

def mode_setup =
 if unknown mode: show mode; errmessage "Unknown mode"; fi
 plain_mode_setup_;
enddef;


% ------------------------------------------------------------
% Here are macros for Xerox-world font info
% ------------------------------------------------------------

def font_family expr s =  % string s names the font family, e.g., "CMR"
 headerbyte 49: BCPL_string(s,20);
 special "fontid="&s enddef;
def coding_scheme expr s = % string s names the scheme, e.g. "TEX TEXT"
 headerbyte 9: BCPL_string(s,40);
 special "codingscheme="&s enddef;
def font_face_byte expr x = % integer x gives the family member number,
 headerbyte 72: x;          % which should be between 0 and 255
 special "fontfacebyte"; numspecial x enddef;

def BCPL_string(expr s,n)= % string s becomes an n-byte BCPL string
 for l:=if length(s)>=n: n-1 else: length(s) fi: l
  for k:=1 upto l: , substring (k-1,k) of s endfor
  for k:=l+2 upto n: , 0 endfor endfor enddef;

Xerox_world:=1;    % users can say `if known Xerox_world:...fi'

inner end;
let primitive_end_ = end;
def end =
  if fontmaking > 0:
    font_family font_identifier_;
    coding_scheme font_coding_scheme_;
    font_face_byte max (0, 254 - round 2designsize);
  fi;
  primitive_end_
enddef;

outer end, primitive_end_;
let bye = end;
% A 96 dpi screen output mode:
mode_def htm =
 proofing:=0; fontmaking:=1; tracingtitles:=0;
 pixels_per_inch:=96;
 blacker:=.3;
 fillin:=0;
 o_correction:=0;
 enddef;
\EndVerbatim\EndHPage{}]\fi 

\ifHtml[\HPage{c:/texlive3/tex/texmf/fonts/source/public/phonetic/local.mf}\Verbatim
% A file to be loaded after "plain.mf". Not final by any means.
base_version:=base_version&"/drofnats";

mode_def canon =  % canon mode: for the old Imagen (Canon LBP10)
 proofing:=0;      % no, we're not making proofs
 fontmaking:=1;      % yes, we are making a font
 tracingtitles:=0;    % no, don't show titles in the log
 pixels_per_inch:=240;
 blacker:=.2;      % make pens a wee bit blacker
 fillin:=.2;      % and compensate for fillin
 o_correction:=.4;    % but don't overshoot as much
 enddef;

mode_def escher =           % mode for the 300 imagen printer
 proofing:=0;
 fontmaking:=1;
 tracingtitles:=0;
 pixels_per_inch:=300;
 blacker:=0;
 fillin:=.2;
 o_correction:=.6;
 enddef;

mode_def think =  % think mode: for the think jet and screen
 proofing:=0;      % no, we're not making proofs
 fontmaking:=1;      % yes, we are making a font
 tracingtitles:=0;      % no, don't show titles in the log
 pixels_per_inch:=96;    % really lowres
 blacker:=0;      % don't make the pens any blacker
 fillin:=0;        % and don't compensate for fillin
 o_correction:=.2;      % but suppress most overshoots
 enddef;

mode_def aps =    % aps mode: for the Autologic APS-Micro5
 proofing:=0;      % no, we're not making proofs
 fontmaking:=1;      % yes, we are making a font
 tracingtitles:=1;      % yes, show titles online
 pixels_per_inch:=722.909;    % that's roughly 10 per pt
 blacker:=.2;      % make pens a teeny bit blacker
 fillin:=.2;      % but compensate for diagonal fillin
 o_correction:=1;      % and keep the full overshoot
 enddef;

% mode for Imagewriter (144 dots per inch) taken from pktor documentation
mode_def imagewriter =
  proofing := 0;
  fontmaking := 1;
  tracingtitles := 1; 
  pixels_per_inch := 144;
  blacker := 0;
  fillin := 0;
  o_correction := .2;
enddef;




localfont:=escher;

\EndVerbatim\EndHPage{}]\fi 


\HCode{<HR>}

c:/texlive3/tex/texmf/metafont/misc/modes.mf

\Link[file://localhost/usr/local/teTeX/share/texmf/metafont/misc/modes.mf]{}{}modes.mf\EndLink

\HCode{<HR>}

\ifHtml[\HPage{c:/EMTEX/DATA/DVIPS/CONFIG.PS}\Verbatim
*********************************************************************
*** This default config.ps (originally of Russel Lang, I think)
*** has some changes with respect for PCTeX.
*** If an entry occurs twice, the second is intend for PCTeX.
*** I don't use it, please check about errors in the pathes and so on
*** and tell me corrections by email.
***
*** This config.ps file (and dvips's internal defaults!) make use of 
*** environment variables EMTEXDIR, DVIDRVGRAPH, GS_LIB and DVIDRVFONTS.
***
*** EMTEXDIR and DVIDRVFONTS MUST contain only ONE path entry for
*** letting maketexp.{bat,cmd} and this config.ps work correctly !!!
***
*** G. Sawade <sawade@physik.tu-berlin.de>                2-Nov-1995
*********************************************************************


W *** HP LaserJet/300dpi ***

* Claim approx 700 kbytes memory
m 700000

* Default resolution.
D 300

* Default metafont mode (defined in emTeX's local.mf)
M laserjet

* Paths (uncomment and edit if you need these)
*        ^^^^^^^^^ means delete the '*' (gs :)
* Due to dvips's new method of expanding $(FOO) into FOO's value
* I changed the pathes with respect for emTeX's environment

T $(EMTEXDIR)\TFM!
*T c:\emtex\tfm\dvips;c:\pctex\textfms


*** ATTENTION ATTENTION: DVIDRVFONTS is allowed only to contain a single path !!!
V $(DVIDRVFONTS)\vf!
*V c:\texfonts\vf

P $(DVIDRVFONTS)\%d\%f.pk
*P c:\pctex\pixel\dpi%d\%f.%p

L $(DVIDRVFONTS)\;lj_base;lj_more


**** When you want to use the psnfss.map, remove the comment here
*p +psnfss.map


S .;$(EMTEXDIR)\TEXINPUT!!;$(DVIDRVGRAPH)
*S .;c:\emtex\texinput\dvips;c:\pctex\texinput;c:\pctex\latex

H .;$(EMTEXDIR)\data\dvips;$(DVIDRVGRAPH);$(DVIDRVFONTS)\ps;$(GS_LIB)
*H .;c:\emtex\data\dvips

* Compress fonts
Z

*
*   Paper size information.  First definition is the default.
*
*   If your default is a4 uncomment the following definition
*   and comment out the letterSize definition.
*@ a4size 210mm 297mm
*@+ %%PaperSize: a4

@ letterSize 8.5in 11in
@+ %%PaperSize: Letter

@ letter 8.5in 11in
@+ %%BeginPaperSize: Letter
@+ letter
@+ %%EndPaperSize

@ legal 8.5in 14in
@+ ! %%DocumentPaperSizes: Legal
@+ %%BeginPaperSize: Legal
@+ legal
@+ %%EndPaperSize

@ ledger 17in 11in
@+ ! %%DocumentPaperSizes: Ledger
@+ %%BeginPaperSize: Ledger
@+ ledger
@+ %%EndPaperSize

@ tabloid 11in 17in
@+ ! %%DocumentPaperSizes: Tabloid
@+ %%BeginPaperSize: Tabloid
@+ 11x17
@+ %%EndPaperSize

@ a4 210mm 297mm
@+ ! %%DocumentPaperSizes: a4
@+ %%BeginPaperSize: a4
@+ a4
@+ %%EndPaperSize

@ a3 297mm 420mm
@+ ! %%DocumentPaperSizes: a3
@+ %%BeginPaperSize: a3
@+ a3
@+ %%EndPaperSize

@ unknown 0in 0in
@+ statusdict /setpageparams known { hsize vsize 0 1 statusdict begin {
@+ setpageparams } stopped end } { true } ifelse { statusdict /setpage known
@+ { hsize vsize statusdict begin { setpage } stopped pop end } if } if
\EndVerbatim\EndHPage{}]\fi

\ifHtml[\HPage{c:/texlive3/tex/texmf/dvips/config/config.ps}\Verbatim
% Memory available.
m 1000000

% How to print.
o |lpr

% default resolution
D 600
X 600
Y 600
M ljfour

% Also look for this list of resolutions.
R 300 600
Z
j0

% The printer offsets the output by this much.
O 0pt,0pt

% paper sizes
@ A4size 210mm 297mm
@+ %%PaperSize: A4

@ letterSize 8.5in 11in

@ letter 8.5in 11in
@+ %%BeginPaperSize: Letter
@+ letter
@+ %%EndPaperSize

@ legal 8.5in 14in
@+ ! %%DocumentPaperSizes: Legal
@+ %%BeginPaperSize: Legal
@+ legal
@+ %%EndPaperSize

@ ledger 17in 11in
@+ ! %%DocumentPaperSizes: Ledger
@+ %%BeginPaperSize: Ledger
@+ ledger
@+ %%EndPaperSize

@ tabloid 11in 17in
@+ ! %%DocumentPaperSizes: Tabloid
@+ %%BeginPaperSize: Tabloid
@+ 11x17
@+ %%EndPaperSize

@ A4 210mm 297mm
@+ ! %%DocumentPaperSizes: A4
@+ %%BeginPaperSize: A4
@+ a4
@+ %%EndPaperSize

@ A3 297mm 420mm
@+ ! %%DocumentPaperSizes: A3
@+ %%BeginPaperSize: A3
@+ a3
@+ %%EndPaperSize

\EndVerbatim\EndHPage{}]\fi 


\ifHtml[\HPage{file://localhost/usr/local/teTeX/share/texmf/dvips/config/config.ps}\Verbatim
% Thomas Esser, 1998, public domain.
%
% teTeX's config.ps.
%
% Memory available.
m 1000000

% How to print.
o |lp

% default resolution
D 600
X 600
Y 600
M ljfive

% Also look for this list of resolutions.
R 300 600

% The printer offsets the output by this much.
O 0pt,0pt

% Compress fonts. PS files are much more compact, but can sometimes
% cause trouble.
Z

% An "all-in-one" psfonts.map.
p psfonts.map

% Instead of psfonts.map, you can use smaller "modules".
% p acrobat.map
% p +charter.map
% p +lw35extra.map
% p +marvosym.map
% p +omega.map
% p +utopia.map
% p +xypic.map
% p +mathtime.map
% p +lucidabr.map

% Uncomment the following two lines to use Postscript Type1 fonts instead of
% bitmap fonts for computer modern & co.
% p +bsr.map
% p +hoekwater.map

@ letterSize 8.5in 11in

@ A4size 210mm 297mm
@+ %%PaperSize: A4

@ letter 8.5in 11in
@+ %%BeginPaperSize: Letter
@+ letter
@+ %%EndPaperSize

@ legal 8.5in 14in
@+ ! %%DocumentPaperSizes: Legal
@+ %%BeginPaperSize: Legal
@+ legal
@+ %%EndPaperSize

@ ledger 17in 11in
@+ ! %%DocumentPaperSizes: Ledger
@+ %%BeginPaperSize: Ledger
@+ ledger
@+ %%EndPaperSize

@ tabloid 11in 17in
@+ ! %%DocumentPaperSizes: Tabloid
@+ %%BeginPaperSize: Tabloid
@+ 11x17
@+ %%EndPaperSize

@ A4 210mm 297mm
@+ ! %%DocumentPaperSizes: A4
@+ %%BeginPaperSize: A4
@+ a4
@+ %%EndPaperSize

@ A3 297mm 420mm
@+ ! %%DocumentPaperSizes: A3
@+ %%BeginPaperSize: A3
@+ a3
@+ %%EndPaperSize

@ B5 176mm 250mm
@+ ! %%DocumentPaperSizes: B5
@+ %%PaperSize: B5

\EndVerbatim\EndHPage{}]\fi

\ifHtml[\HPage{newer version}\Verbatim

                            TeX4HT under MiKTeX
                                      
                              Philip A. Viton
                              November 9, 1998
                                      
   1 Introduction
   2 Get the software
   3 Set up MiKTeX
   4 Set up dvips
      4.1 Postscript fonts
      4.2 Metafont fonts
   5 Set up ImageMagick
   6 Set up TeX4ht
   7 The batch file xht.bat
   A Solving low-resolution font problems
      A.1 Identifying the problem fonts
      A.2 Get the font information
      A.3 Making the problem fonts "by hand"
   
1 Introduction

   This note explains how to set up a working version of TeX4ht, Eitan
   Gurari's TeX/LaTeX-to-HTML translation system, when the underlying TeX
   engine is Christian Schenk's MiKTeX for Win32 platforms. Thanks to
   Eitan for answering lots of TeX4ht questions and for valuable editing
   suggestions, to Piet van Oostrum for helping with an important
   MiKTeX-related problem, and most of all to Gaunce Lewis for helping me
   solve the font-making problem described in appendix A.
   
2 Get the software

   Besides a standard MiKTeX setup, you will need the following freely
   available software packages:
     * http://www.cse.ohio-state.edu/~gurari/TeX4ht/mn.html#mn27.html :
       the translation system itself. Be sure to get the Win95 version.
     * http://www.wizards.dupont.com/cristy/www/archives.html : for
       translation of postscript to gif images.
     * ftp://ftp.cs.wisc.edu/ghost/aladdin/ : used by ImageMagick in the
       translation.
       
   Choose directories for each of these packages, and unzip the
   distributions, being sure to preserve directory (folder) names. Note
   that you will need an unzipper which understands long file names. In
   what follows, I assume the following directories:
     * For TeX4ht: c:\ tex4ht
     * For ImageMagic: c:\ ImageMagic
     * For Ghostscript: c:\ gs
     * For MiKTeX itself: c:\ texmf (this is the default root of the
       MiKTeX system, but you are offered the opportunity to change it
       when you install the system).
       
   and if you select others, you will need to modify the instructions
   accordingly.
   
3 Set up MiKTeX

   Two of the style files of TeX4ht need to be moved into MiKTeX's LaTeX
   tree. (Plain TeX will also find them).
     * create a directory c:\ texmf\ tex\ latex\ tex4ht
     * move tex4ht.sty and tex4hta.sty from the TeX4ht directory to this
       one.
     * update the MiKTeX database: from the MiKTeX program group do
       Maintenance then Refresh filename database. This runs a quick DOS
       session which updates the database.
       
4 Set up dvips

   TeX4ht uses dvips to create Postscript images of equations, and of
   symbols which are unavailable in standard fonts; these are then
   converted to .gif images using the ImageMagick/Ghostscript combination
   described in the next section. How you set up dvips depends on whether
   and how you are using Postscript fonts. Note that these instructions
   are geared to the way MiKTeX is set up: if you're not using MiKTeX you
   may have to make adjustments. You can download MiKTeX's dvips
   configuration file, config.ps, config.ps for reference.
   
  4.1 Postscript fonts
  
   MiKTeX comes with a complete set of public-domain Type-1 (Postscript)
   fonts for the Computer Modern, LaTeX and AMS math fonts. By far the
   simplest solution is to use them in conjunction with TeX4ht; note that
   you can do so whether or not you have a Postscript printer.
   
   However, if you have removed the Type-1 fonts from your hard disk
   (perhaps to save space) the next sub-section describes how to use
   Metafont to do the work for you; this is a much more complicated
   solution and is not recommended. You can check that the Type-1 fonts
   are present by looking in subdirectories of c:\ texmf\ fonts\ type1.
   
   To set up to use Postscript fonts in TeX4ht:
     * Use a text editor to open the dvips configuration file config.ps;
       this is usually in c:\ texmf\ dvips\ config\ local
     * In this file are two sections dealing with Type-1 fonts in a
       series of lines like
       ;p +cmfonts.map
       If all these lines are uncommented (ie, not preceded by a ;
       character) and if you see a reference to
       p +amsfonts.map
       then there's nothing more to do -- you are already using
       Postscript fonts for all your printing.
     * If some of these lines are commented out, or if there's no
       reference to amsfonts.map, then
          + uncomment them all
          + add a line p +amsfonts.map
          + save the file under a new name (in the same place as the
            original), for example as config.tex4ht. The name you choose
            must begin with config, and the extension is your choice.
          + close the editor and run initexmf -u to update the MiKTeX
            database, or else dvips will not recognize your definition.
       
  4.2 Metafont fonts
  
   If you do not have the Type-1 fonts, you can instruct dvips to use
   Metafont to generate fonts and characters. But this is more
   complicated, and, overall, less satisfactory.
   
   First, you need to select the resolution for your fonts: this can have
   a substantial impact on the legibility of your HTML and on the size of
   the gifs your readers have to download, and as you might expect, these
   considerations run in opposite directions. For example, making
   Metafont fonts at 600 dpi rather than at 110 dpi makes the HTML pages
   more readable, but can increase the total size of the gifs by a factor
   of 1.7 (in one experiment).
   
   Second, in low-resolution modes (below about 300 dpi) there may be a
   dvips-Metafont interaction problem, resulting in certain fonts not
   being made automatically. The solution to this problem is somewhat
   cumbersome, and is described in Appendix A below; the upshot is
   probably that unless your document generates a really large set of
   gifs, the high-resolution solution is probably preferable. But it's
   your call.
   
   I assume that if you elect a high-resolution solution, you'll use
   whatever printer mode you are currently using to print hard-copy
   documents from the yap previewer. In this case there's nothing more to
   be done.
   
   If you prefer to reduce the size of gifs to be transferred, one
   suggestion is to use the Metafont mode ibmvga, and you need to tell
   dvips and Metafont about it. Here's how: but note that these
   instructions are specific to the version of config.ps provided by
   MiKTeX; other TEX
   distributions appear to provide different versions of this file.
     * Locate the dvips configuration file config.ps, typically in
       c:\ texmf\ dvips\ config\ local
     * Make a copy of this file under the name config.ibmvga
     * Use a text editor to edit config.ibmvga, and make the following
       changes:
          + at the top of the file change the Metafont mode from M ljfour
            (or whatever printer you selected when you set up MiKTeX) to
            M ibmvga.
          + below that, change the dpi resolution from D 600 (or whatever
            resolution your default printer is set up for) to D 110. If
            you also see entries for X 600 and Y 600, these also need to
            be changed to 110.
          + Comment out (by preceding each line with a semi-colon) the
            approximately 11 lines of the form
            ;p +cmfonts.map
            -- we want Metafont to create these fonts if they're
            requested.
     * Save the file config.ibmvga
     * From a DOS session, run initexmf -u to update the configuration
       files. If you forget this, then dvips will not be able to make
       fonts at the required resolution.
       
   A copy of the edited config.ibmvga can be downloaded config.ibmvga .
   
5 Set up ImageMagick

     * Switch to the ImageMagick directory, and check that there exists a
       file delegates.mgk. If not, copy the file c:\ ImageMagic\
       delegates\ delegates.nt to the main ImageMagick directory as
       delegates.mgk.
     * Use a text editor to open delegates.mgk. In this file there are
       about 5 instances of calls to the program gswin. In each of these
       replace gswin by the full path and executable name to the
       command-line version of Ghostscript, typically c:\ gs\ gswin32c.
       If you omit the "c" and refer only to gswin32 you will get the
       windowed version of Ghostscript: each time it is called to
       translate a file, it will pop up an empty window, do the
       translation, and close the window. It seems to make no difference
       which version you use, but since the TeX4ht system is a
       command-line utility, it is less distracting -- and may save a bit
       of time, too -- to run the command-line version of Ghostscript.
     * In order for ImageMagick to find its delegates file, you need to
       set the environment variable delegate_ path. You can let the batch
       file xht.bat described in section 7 do it for you, or you can do
       it directly:
          + Under Windows NT: open the Control Panel, choose System, then
            Environment. At the bottom of the dialog under Variable:
            enter delegate_ path, and under Value: enter c:\ ImageMagic.
            Click OK. This will take effect the next time you start a DOS
            session.
          + Under Windows95: edit autoexec.bat; add the line
            set delegate_ path=c:\ ImageMagic. You may need to re-boot
            for the changes to take effect.
       
6 Set up TeX4ht

   First, you will need to add TeX4ht's directory to your path. You can
   do this from the Windows NT Control Panel (or by editing autoexec.bat
   in Windows95), or you can let the batch file xht.bat described in
   section 7 do it for you.
   
   Next, switch to the TeX4ht directory. Use a text editor to open the
   file tex4ht.env, and make sure that the following are correct:
     * the first uncommented line begins with a t : the remainder of this
       should contain a path to the MiKTeX tfm files. For the standard
       MiKTeX distribution change the line to read tc:\ texmf\ fonts\
       tfm! -- note the trailing exclamation point, which is required,
       and be sure to include the leading t.
     * Locate the line beginning Gdvips32 and change it to Gdvips.
     * On the same line, make the following changes:
          + if you are using Postscript fonts and you did not make a new
            dvips config file as described in section 4.1, delete the
            text -mode ibmvga -D 110.
          + if you are using Postscript fonts and you did make a new
            dvips config file, change -mode ibmvga -D 110 to -P tex4ht
            where tex4ht is the extension of the config file you created
            in section 4.1.
          + if you are using Metafont in your standard printer mode as
            described by config.ps, delete the text -mode ibmvga -D 110.
          + if you are using Metafont in a non-standard dvips
            configuration file, here assumed to be config.ibmvga, change
            -mode to -P so that that part of the line reads -P ibmvga
            (note: capital "P") and set the dpi value following -D
            accordingly (for ibmvga it should be -D 110).
     * Locate the line beginning Gconvert . . . . On this line:
          + change convert to the full drive/path name to the convert
            utility: under the directory assumptions made here the line
            would begin Gc:\ ImageMagic\ convert. Be sure not to delete
            the initial "G" which is needed by TeX4ht.
          + make sure that the line says -transparent #FFFFFF and not
             -transparent '#FFFFFF' (ie, no quotes).
     * under this, make sure that you see Gdel %%3, and not Gdel %%%3
       (remove the extra % if necessary).
     * change Gcopy /y %%1 %%2%%3 to  Gcopy %%1 %%2%%3 (remove the /y).
     * change Gmove /y %%1 %%2%%3 to Gmove %%1 %%2%%3 (remove the /y).
     * the last line of the file should read H followed by the full drive
       plus path to the file hft.sty. If you chose the default location,
       you will not need to change this.
       
   Finally, open the file ht.bat. Make sure the last line reads
   
   htcmd %2 -eC:\ tex4ht\ tex4ht.env
          
   and if it doesn't, add the -e switch, whose argument is the drive plus
   path to the TeX4ht files.
   
7 The batch file xht.bat

   I've created a small batch file called xht.bat which takes care of
   several of the details associated with running TeX4ht. You can place
   the batch file in a directory in your path and then call it from any
   place on your hard disk. The batch file is set up with the directory
   defaults as described in section 2; if you choose different locations,
   you will need to edit the file accordingly.
   
   The syntax, which you will be reminded of if you call xht with no
   parameters, is the same as for TeX4ht's starting batch file ht.bat:
   
   xht tex myfile for a plain TeX file, or
          
   xht latex myfile for a LaTeX file.
          
   What the batch file does is:
    1. It adds the TeX4ht directory to your path before calling the
       translator, and then removes it when the job ends.
       There is a cost to this: we save a copy of the current path in the
       environment variable opath, and then append the TeX4ht directory
       to path. At the end of the batch file, path is set equal to opath,
       and opath is erased. The cost is the length of opath, which is
       temporarily added to your environment. Under Windows NT4 this will
       never be a problem, but it is possible that you could run out of
       environment space under Windows 95. If that happens you will
       probably need to alter autoexec.bat.
    2. It sets the environment variable delegate_ path required by the
       ImageMagick convert utility; and then removes it when the job
       finishes.
    3. Since I tend to forget to specify tex or latex, xht.bat does a
       quick check to see that you have actually provided two parameters.
       (However, note that it doesn't check that the first parameter is
       either tex or latex: it would be easy to add this if you need it).
    4. It also tries in a simple-minded way to check that you provide the
       name of the source (.tex) file without an extension: it adds the
       extension .tex to the name of the source file which you provided:
       if that file exists, then we assume that you did not provide the
       extension. This will fail if you provide, say, myfile.tex and the
       file myfile.tex.tex happens also to exist in the same directory.
       In my case, I can be sure that this won't happen, but your habits
       may differ.
       
   You can download the batch file xht.bat xht.bat .
   
A Solving low-resolution font problems

   If you elected to use Metafont instead of Type-1 fonts, you may run
   into the following problem: when a font is not found, dvips calls
   Metafont; but if Metafont has trouble making the font, then the font
   will not be placed where dvips can find it. Unfortunately, Metafont
   has problems with several fonts in low-resolution modes, and while
   those problems do not seem to lead to any major ill-effects when
   viewing the output on the Web, the result isn't quite perfect enough
   for Metafont.
   
   This appendix describes how to solve the problem. Note that you will
   never run into this problem if you use Type-1 fonts -- this is the
   recommended procedure -- or if you use Metafont in high-resolution
   (above 300 dpi) modes. But if you want to save download bandwidth and
   use Metafont in low-resolution modes you will need to make the problem
   fonts "by hand". Here's how.
   
  A.1 Identifying the problem fonts
  
   You can identify the problem fonts in either of two ways.
     * If you're watching TeX4ht run, watch for Metafont errors and, if
       you're quick, you may able to stop the screen scrolling at the
       right place by hitting Control+S and extracting the information
       described in the next sub-section. (Control+Q restarts). But this
       is a bit tricky, especially on a fast computer.
     * Alternatively, once you have .dvi file (this can be either with or
       without the TeX4ht extensions), open the previewer yap. Click on
       View then Options then Display. Under Mode choose IBM vga (110
       dpi) and click OK. Ignore the warning about it's not being
       recommended to have screen and printer at different resolutions.
          + Open your document in the previewer and page through it. One
            of three things will happen:
               o Metafont never runs. In this case there will be no
                 problems with TeX4ht.
               o Metafont runs, but the DOS window closes without your
                 intervention. In this case, Metafont has succeeded in
                 making a missing font. In this case, too, there will be
                 no problems with TeX4ht.
               o Metafont runs, but there is a problem. The indicator of
                 this is that the DOS window for Metafont waits for you
                 to close it manually. At this point you need to make a
                 note of the font which caused the problem, as described
                 in the next sub-section.
          + When you have paged through the document, you should set
            yap's display resolution back to its original value; exit
            yap.
       
  A.2 Get the font information
  
   At each instance of a Metafont problem, you need to extract
   information about the font in question.
     * At the bottom of the window, you will see something like the
       following:
          + Output written on cmr5.72gf
            Transcript written on cmr5.log
            Metafont failed on cmr5! Return code 1
            Press any key to continue ...
     * Look at the first of these lines, and write down (a) the font name
       (which is the text before the .72gf, here cmr5), and (b) the
       resolution ( the text just before gf, here 72).
       
  A.3 Making the problem fonts "by hand"
  
   You must now make any fonts that Metafont "choked" on. I've set up a
   little batch file, epfont.bat, which you can download epfont.bat , and
   which tries to ease the difficulties for you. (This is based on the
   work of Gaunce Lewis; I'm grateful to him for sharing it with me). The
   batch file is set up to make fonts in ibmvga mode, but it contains
   instructions on how to customize it for any mode. To use the file:
     * Copy it to any directory.
     * For safety, do del epfix.bat though there probably won't be any
       file to delete.
     * Repeatedly run epfont, once for every font you noted in the
       previous step, where Metafont fails. The arguments to epfont are
       (1) the font name (cmr5 in the example) followed by the resolution
       (72 in the example), so in this case you'd say epfont cmr5 72.
     * epfont creates a file epfix.bat. This file contains run-able
       instructions to have Metafont create your problem fonts. But
       before running it:
          + Open epfix.bat in a text editor.
          + Do a global search-and-replace: replace the string  /d  by a
            blank.
          + Scan thorough the file and look for any lines which end
            ...already exists!. This says that you asked Metafont to make
            a file which is already made. When you see one of these,
            delete the entire "section" of the file associated with that
            font. Sections begin with a line that says REM followed by
            one that says REM fontname resolution where fontname and
            resolution are echoes of information you provided.
          + Save epfix.bat and run it from the command line. This will
            make all missing fonts connected with your document. You can
            now safely run TeX4ht.

\EndVerbatim\EndHPage{}]\fi



\ifHtml[\HPage{more}\Verbatim
 > 4. I've cleaned up the section on resolution in the metafont case, mostly
 > by eliminating it. It's true that by fiddling around with the metafont mode
 > you can get substantially smaller gifs, but I don't understand why. So I
 > just dumped that stuff altogether. 
\EndVerbatim\EndHPage{}]\fi






\Section{Gifs vs JPEG}


\Verbatim
From stop@the-light.com Tue Oct  1 18:06:16 EDT 1996
Article: 105020 of comp.infosystems.www.authoring.html
Path: news.cse.ohio-state.edu!nntp.sei.cmu.edu!fs7.ece.cmu.edu!cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!news-peer.gsl.net!news.gsl.net!news.sgi.com!enews.sgi.com!news.mathworks.com!newsfeed.internetmci.com!news.onr.com!usenet
From: stop@the-light.com (Victor Engel)
Newsgroups: comp.infosystems.www.authoring.html
Subject: Re: Converting many graphics/images to GIF format
Date: Tue, 01 Oct 1996 03:12:57 GMT
Organization: Onramp Access, Inc. 512-322-9200
Lines: 55
Message-ID: <52q5si$68k@mari.onr.com>
References: <52p0em$4dn@nadine.teleport.com>
NNTP-Posting-Host: onramp6-7.onr.com
X-Newsreader: Forte Free Agent 1.0.82

Before you go to all the work of converting all your graphics to GIF,
bear in mind that for the web, GIF may not be the format you should
use for many of your images. The GIF format is an 8-bit format, so you
will be losing a lot of color information when converting from a 24
bit image. There are many alogrithms the software could use to perform
the color reduction. Which one used depends upon which software you
are using and what settings you are using. Here are my recommendations
for converting your images.

1) For photographs and other images using gradations of color, convert
to JPG. Experiment a little with the compression ratio until you get a
good compromise between quality and file size.

2) For images with large areas of a single color, use the GIF format.
These images will have few colors and will be saved as smaller files
than if they were saved as JPG images.

Use your favorite search engine and review some GIF/JPG FAQs for more
detail on this subject, or review the FAQ in
comp.infosystems.www.authoring.images.

You may also want to take a peek at http://the-light.com/netcol.html,
but this site is targeted at designers of individual images.

joannt@teleport.com (Joann Taylor) wrote:

>Greetings.  I have a quick question re: saving graphics to GIF format.
>I am using a Mac to pull together a large html-based help utility and
>need to integrate graphics.  I have LOTS that I have used prior in PICT,
>TIFF, and random application formats (Canvas, Kaleidagraph, Photoshop,
>...ya dee ya...).  When I try to save these as GIF files for my html
>pages - most of the graphics get hosed - resolution is very poor and color
>gets trampled on.  I expect some degredation but this seems very
>excessive...I have got to be forgetting something. My Canvas 5
>application gives me the impression it is building the appropriate color
>table during the "save" but the resulting image says differently. I am
>not very familiar with the GIF format, so I am not sure of the source of the
>problem.  Can any one suggest how I might address this problem or where
>I might find some pointers to a solution?


>Many thanks,

>Joann
>--
>* Joann Taylor                                               *
>* Principal Consultant - Color Technology Solutions          *
>* Specializing in Color Science, Technology and Applications *
>* joannt@teleport.com                                        *

-----------------------------------------------------------
Victor Engel                                   Vector Angle
Stop@The-Light.com                           lights@onr.com
http://the-light.com         http://www.onr.com/user/lights




\EndVerbatim



\bye



