]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/tex2rtf/src/htmlutil.cpp
Do not use wx/wx.h.
[wxWidgets.git] / utils / tex2rtf / src / htmlutil.cpp
index 487fb97a62f4ddd045c7b60fff1f74a080b951e1..b384cf9a46a6e113a321f21022bb9b7e3ef705ae 100644 (file)
 #endif
 
 #ifndef WX_PRECOMP
 #endif
 
 #ifndef WX_PRECOMP
-#include "wx/wx.h"
 #endif
 
 #include "tex2any.h"
 #include "tex2rtf.h"
 #include "table.h"
 
 #endif
 
 #include "tex2any.h"
 #include "tex2rtf.h"
 #include "table.h"
 
+#if !WXWIN_COMPATIBILITY_2_4
+static inline wxChar* copystring(const wxChar* s)
+    { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
+#endif
+
+extern wxHashTable TexReferences;
+
+
 extern void DecToHex(int, char *);
 void GenerateHTMLIndexFile(char *fname);
 
 extern void DecToHex(int, char *);
 void GenerateHTMLIndexFile(char *fname);
 
@@ -76,6 +83,11 @@ static bool inTable = FALSE;
 // This is defined in the Tex2Any library.
 extern char *BigBuffer;
 
 // This is defined in the Tex2Any library.
 extern char *BigBuffer;
 
+// DHS Two-column table dimensions.
+static int TwoColWidthA = -1;
+static int TwoColWidthB = -1;
+
+
 class HyperReference: public wxObject
 {
  public:
 class HyperReference: public wxObject
 {
  public:
@@ -172,7 +184,7 @@ void ReopenFile(FILE **fd, char **fileName)
 {
   if (*fd)
   {
 {
   if (*fd)
   {
-    fprintf(*fd, "\n</BODY></HTML>\n");
+    fprintf(*fd, "\n</FONT></BODY></HTML>\n");
     fclose(*fd);
   }
   fileId ++;
     fclose(*fd);
   }
   fileId ++;
@@ -182,7 +194,7 @@ void ReopenFile(FILE **fd, char **fileName)
   else
     sprintf(buf, "%s%d.html", FileRoot, fileId);
   if (*fileName) delete[] *fileName;
   else
     sprintf(buf, "%s%d.html", FileRoot, fileId);
   if (*fileName) delete[] *fileName;
-  *fileName = copystring(FileNameFromPath(buf));
+  *fileName = copystring(wxFileNameFromPath(buf));
   *fd = fopen(buf, "w");
   fprintf(*fd, "<HTML>\n");
 }
   *fd = fopen(buf, "w");
   fprintf(*fd, "<HTML>\n");
 }
@@ -417,13 +429,13 @@ void AddBrowseButtons(char *upLabel, char *upFilename,
   if (truncateFilenames)
   {
     char buf1[80];
   if (truncateFilenames)
   {
     char buf1[80];
-    strcpy(buf1, ConvertCase(FileNameFromPath(FileRoot)));
+    strcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot)));
     sprintf(buf, "\n<A HREF=\"%s.%s\">%s</A> ", buf1, ConvertCase("htm"), contentsReference);
   }
   else
   {
     char buf1[80];
     sprintf(buf, "\n<A HREF=\"%s.%s\">%s</A> ", buf1, ConvertCase("htm"), contentsReference);
   }
   else
   {
     char buf1[80];
-    strcpy(buf1, ConvertCase(FileNameFromPath(FileRoot)));
+    strcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot)));
     sprintf(buf, "\n<A HREF=\"%s%s\">%s</A> ", buf1, ConvertCase("_contents.html"), contentsReference);
   }
 //  TexOutput("<NOFRAMES>");
     sprintf(buf, "\n<A HREF=\"%s%s\">%s</A> ", buf1, ConvertCase("_contents.html"), contentsReference);
   }
 //  TexOutput("<NOFRAMES>");
@@ -574,6 +586,20 @@ char *ParseColourString(char *bkStr, bool *isPicture)
   else return NULL;
 }
 
   else return NULL;
 }
 
+void OutputFont(void)
+{
+  // Only output <font face> if explicitly requested by htmlFaceName= directive in
+  // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
+  // default font:
+  if (htmlFaceName)
+  {
+    // Output <FONT FACE=...>
+    TexOutput("<FONT FACE=\"");
+    TexOutput(htmlFaceName);
+    TexOutput("\">\n");
+  }
+}
+
 // Output start of <BODY> block
 void OutputBodyStart(void)
 {
 // Output start of <BODY> block
 void OutputBodyStart(void)
 {
@@ -628,6 +654,26 @@ void OutputBodyStart(void)
     }
   }
   TexOutput(">\n");
     }
   }
   TexOutput(">\n");
+
+  OutputFont();
+}
+
+void HTMLHead()
+{
+  TexOutput("<head>");
+  if (htmlStylesheet) {
+    TexOutput("<link rel=stylesheet type=\"text/css\" href=\"");
+    TexOutput(htmlStylesheet);
+    TexOutput("\">");
+  }
+};
+
+void HTMLHeadTo(FILE* f)
+{
+  if (htmlStylesheet)
+    fprintf(f,"<head><link rel=stylesheet type=\"text/css\" href=\"%s\">",htmlStylesheet);
+  else
+    fprintf(f,"<head>");
 }
 
 // Called on start/end of macro examination
 }
 
 // Called on start/end of macro examination
@@ -660,16 +706,17 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
 
       SetCurrentOutput(Chapters);
 
 
       SetCurrentOutput(Chapters);
 
-      TexOutput("<head><title>");
+      HTMLHead();
+      TexOutput("<title>");
       OutputCurrentSection(); // Repeat section header
       TexOutput("</title></head>\n");
       OutputBodyStart();
 
       char titleBuf[200];
       if (truncateFilenames)
       OutputCurrentSection(); // Repeat section header
       TexOutput("</title></head>\n");
       OutputBodyStart();
 
       char titleBuf[200];
       if (truncateFilenames)
-        sprintf(titleBuf, "%s.htm", FileNameFromPath(FileRoot));
+        sprintf(titleBuf, "%s.htm", wxFileNameFromPath(FileRoot));
       else
       else
-        sprintf(titleBuf, "%s_contents.html", FileNameFromPath(FileRoot));
+        sprintf(titleBuf, "%s_contents.html", wxFileNameFromPath(FileRoot));
 
       fprintf(Chapters, "<A NAME=\"%s\"></A>", topicName);
 
 
       fprintf(Chapters, "<A NAME=\"%s\"></A>", topicName);
 
@@ -698,8 +745,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
       // Add this section title to the list of keywords
       if (htmlIndex)
       {
       // Add this section title to the list of keywords
       if (htmlIndex)
       {
-        OutputCurrentSectionToString(wxBuffer);
-        AddKeyWordForTopic(topicName, wxBuffer, ConvertCase(currentFileName));
+        OutputCurrentSectionToString(wxTex2RTFBuffer);
+        AddKeyWordForTopic(topicName, wxTex2RTFBuffer, ConvertCase(currentFileName));
       }
     }
     break;
       }
     }
     break;
@@ -729,7 +776,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
       if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName);
 
       SetCurrentOutput(Sections);
       if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName);
 
       SetCurrentOutput(Sections);
-      TexOutput("<head><title>");
+      HTMLHead();
+      TexOutput("<title>");
       OutputCurrentSection();
       TexOutput("</title></head>\n");
       OutputBodyStart();
       OutputCurrentSection();
       TexOutput("</title></head>\n");
       OutputBodyStart();
@@ -760,8 +808,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
       // Add this section title to the list of keywords
       if (htmlIndex)
       {
       // Add this section title to the list of keywords
       if (htmlIndex)
       {
-        OutputCurrentSectionToString(wxBuffer);
-        AddKeyWordForTopic(topicName, wxBuffer, currentFileName);
+        OutputCurrentSectionToString(wxTex2RTFBuffer);
+        AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
       }
     }
     break;
       }
     }
     break;
@@ -822,7 +870,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
             if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName);
             SetCurrentOutput(Subsections);
 
             if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName);
             SetCurrentOutput(Subsections);
 
-            TexOutput("<head><title>");
+           HTMLHead();
+            TexOutput("<title>");
             OutputCurrentSection();
             TexOutput("</title></head>\n");
             OutputBodyStart();
             OutputCurrentSection();
             TexOutput("</title></head>\n");
             OutputBodyStart();
@@ -867,8 +916,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
           // Add this section title to the list of keywords
           if (htmlIndex)
           {
           // Add this section title to the list of keywords
           if (htmlIndex)
           {
-            OutputCurrentSectionToString(wxBuffer);
-            AddKeyWordForTopic(topicName, wxBuffer, currentFileName);
+            OutputCurrentSectionToString(wxTex2RTFBuffer);
+            AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
           }
 
       }
           }
 
       }
@@ -902,7 +951,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
             if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName);
 
             SetCurrentOutput(Subsubsections);
             if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName);
 
             SetCurrentOutput(Subsubsections);
-            TexOutput("<head><title>");
+           HTMLHead();
+            TexOutput("<title>");
             OutputCurrentSection();
             TexOutput("</title></head>\n");
             OutputBodyStart();
             OutputCurrentSection();
             TexOutput("</title></head>\n");
             OutputBodyStart();
@@ -945,8 +995,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
         // Add this section title to the list of keywords
         if (htmlIndex)
         {
         // Add this section title to the list of keywords
         if (htmlIndex)
         {
-          OutputCurrentSectionToString(wxBuffer);
-          AddKeyWordForTopic(topicName, wxBuffer, currentFileName);
+          OutputCurrentSectionToString(wxTex2RTFBuffer);
+          AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
         }
       }
     }
         }
       }
     }
@@ -1018,7 +1068,8 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
       if (inTabular)
       {
         // End cell, start cell
       if (inTabular)
       {
         // End cell, start cell
-        TexOutput("</TD>");
+
+        TexOutput("</FONT></TD>");
 
         // Start new row and cell, setting alignment for the first cell.
         if (currentColumn < noColumns)
 
         // Start new row and cell, setting alignment for the first cell.
         if (currentColumn < noColumns)
@@ -1042,6 +1093,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
         else
           sprintf(buf, "\n<TD ALIGN=LEFT>");
         TexOutput(buf);
         else
           sprintf(buf, "\n<TD ALIGN=LEFT>");
         TexOutput(buf);
+               OutputFont();
       }
       else
         TexOutput("&amp;");
       }
       else
         TexOutput("&amp;");
@@ -1090,12 +1142,13 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
       else
         sprintf(buf, "<TR>\n<TD ALIGN=LEFT>");
       TexOutput(buf);
       else
         sprintf(buf, "<TR>\n<TD ALIGN=LEFT>");
       TexOutput(buf);
+         OutputFont();
     }
     else
     {
       // End cell and row
       // Start new row and cell
     }
     else
     {
       // End cell and row
       // Start new row and cell
-      TexOutput("</TD>\n</TR>\n");
+      TexOutput("</FONT></TD>\n</TR>\n");
     }
     break;
   }
     }
     break;
   }
@@ -1189,8 +1242,12 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
   {
     if ( start )
         TexOutput("\n<TABLE>\n");
   {
     if ( start )
         TexOutput("\n<TABLE>\n");
-    else
+    else {
         TexOutput("\n</TABLE>\n");
         TexOutput("\n</TABLE>\n");
+    // DHS 
+        TwoColWidthA = -1;
+        TwoColWidthB = -1;
+    }
     break;
   }
   case ltPAR:
     break;
   }
   case ltPAR:
@@ -1893,7 +1950,11 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
           {
             if (helpRefText)
               TraverseChildrenFromChunk(helpRefText);
           {
             if (helpRefText)
               TraverseChildrenFromChunk(helpRefText);
-            TexOutput(" (REF NOT FOUND)");
+            if (!ignoreBadRefs)
+              TexOutput(" (REF NOT FOUND)");
+            wxString errBuf;
+            errBuf.Printf("Warning: unresolved reference '%s'", refName);
+            OnInform((char *)errBuf.c_str());
           }
         }
         else TexOutput("??");
           }
         }
         else TexOutput("??");
@@ -1971,7 +2032,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
          {
             TexOutput("<img src=\"");
             TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
          {
             TexOutput("<img src=\"");
             TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
-            TexOutput("\""); TexOutput(alignment); TexOutput("></A>");
+            TexOutput("\""); TexOutput(alignment); TexOutput(">");
             delete[] inlineFilename;
          }
         }
             delete[] inlineFilename;
          }
         }
@@ -2077,6 +2138,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
       descriptionItemArg = GetArgChunk();
       return FALSE;
     }
       descriptionItemArg = GetArgChunk();
       return FALSE;
     }
+    return TRUE;
   }
   case ltTWOCOLITEM:
   case ltTWOCOLITEMRULED:
   }
   case ltTWOCOLITEM:
   case ltTWOCOLITEMRULED:
@@ -2089,17 +2151,31 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
 */
     if (arg_no == 1)
     {
 */
     if (arg_no == 1)
     {
-        if ( start )
-            TexOutput("\n<TR><TD VALIGN=TOP>\n");
-        else
-            TexOutput("\n</TD>\n");
+      if ( start ) {
+        // DHS
+       if (TwoColWidthA > -1) {
+          char buf[100];
+          sprintf(buf,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA);
+          TexOutput(buf);
+        } else
+          TexOutput("\n<TR><TD VALIGN=TOP>\n");
+               OutputFont();
+      }  else
+            TexOutput("\n</FONT></TD>\n");
     }
     if (arg_no == 2)
     {
     }
     if (arg_no == 2)
     {
-        if ( start )
-            TexOutput("\n<TD VALIGN=TOP>\n");
-        else
-            TexOutput("\n</TD></TR>\n");
+      // DHS
+      if ( start ) {
+       if (TwoColWidthB > -1) {
+          char buf[100];
+          sprintf(buf,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB);
+          TexOutput(buf);
+        } else 
+           TexOutput("\n<TD VALIGN=TOP>\n");
+               OutputFont();
+      }  else
+           TexOutput("\n</FONT></TD></TR>\n");
     }
     return TRUE;
     break;
     }
     return TRUE;
     break;
@@ -2153,6 +2229,30 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
       TexOutput("<HR><P>\n");
     break;
   }
       TexOutput("<HR><P>\n");
     break;
   }
+  // DHS
+  case ltTWOCOLWIDTHA:
+  {
+    if (start)
+    {
+      char *val = GetArgData();
+      float points = ParseUnitArgument(val);
+      TwoColWidthA = (int)((points * 100.0) / 72.0);
+    }
+    return FALSE;
+    break;
+  }
+  // DHS
+  case ltTWOCOLWIDTHB:
+  {
+    if (start)
+    {
+      char *val = GetArgData();
+      float points = ParseUnitArgument(val);
+      TwoColWidthB = (int)((points * 100.0) / 72.0);
+    }
+    return FALSE;
+    break;
+  }
   /*
    * Accents
    *
   /*
    * Accents
    *
@@ -2577,6 +2677,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
         if (compatibilityMode)
         {
           TexOutput("<TR>\n<TD>");
         if (compatibilityMode)
         {
           TexOutput("<TR>\n<TD>");
+                 OutputFont();
 /*
           for (int i = 0; i < noColumns; i++)
           {
 /*
           for (int i = 0; i < noColumns; i++)
           {
@@ -2613,11 +2714,12 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
 
       char titleBuf[150];
       if (truncateFilenames)
 
       char titleBuf[150];
       if (truncateFilenames)
-        sprintf(titleBuf, "%s.htm", FileNameFromPath(FileRoot));
+        sprintf(titleBuf, "%s.htm", wxFileNameFromPath(FileRoot));
       else
       else
-        sprintf(titleBuf, "%s_contents.html", FileNameFromPath(FileRoot));
+        sprintf(titleBuf, "%s_contents.html", wxFileNameFromPath(FileRoot));
 
 
-      TexOutput("<head><title>");
+      HTMLHead();
+      TexOutput("<title>");
       TexOutput(ReferencesNameString);
       TexOutput("</title></head>\n");
       OutputBodyStart();
       TexOutput(ReferencesNameString);
       TexOutput("</title></head>\n");
       OutputBodyStart();
@@ -2823,7 +2925,7 @@ bool HTMLGo(void)
       OnError("Cannot open output file!");
       return FALSE;
     }
       OnError("Cannot open output file!");
       return FALSE;
     }
-    AddTexRef("contents", FileNameFromPath(TitlepageName), ContentsNameString);
+    AddTexRef("contents", wxFileNameFromPath(TitlepageName), ContentsNameString);
 
     fprintf(Contents, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString);
 
 
     fprintf(Contents, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString);
 
@@ -2856,25 +2958,25 @@ bool HTMLGo(void)
 
     if (Chapters)
     {
 
     if (Chapters)
     {
-      fprintf(Chapters, "\n</BODY></HTML>\n");
+      fprintf(Chapters, "\n</FONT></BODY></HTML>\n");
       fclose(Chapters);
       Chapters = NULL;
     }
     if (Sections)
     {
       fclose(Chapters);
       Chapters = NULL;
     }
     if (Sections)
     {
-      fprintf(Sections, "\n</BODY></HTML>\n");
+      fprintf(Sections, "\n</FONT></BODY></HTML>\n");
       fclose(Sections);
       Sections = NULL;
     }
     if (Subsections && !combineSubSections)
     {
       fclose(Sections);
       Sections = NULL;
     }
     if (Subsections && !combineSubSections)
     {
-      fprintf(Subsections, "\n</BODY></HTML>\n");
+      fprintf(Subsections, "\n</FONT></BODY></HTML>\n");
       fclose(Subsections);
       Subsections = NULL;
     }
     if (Subsubsections && !combineSubSections)
     {
       fclose(Subsections);
       Subsections = NULL;
     }
     if (Subsubsections && !combineSubSections)
     {
-      fprintf(Subsubsections, "\n</BODY></HTML>\n");
+      fprintf(Subsubsections, "\n</FONT></BODY></HTML>\n");
       fclose(Subsubsections);
       Subsubsections = NULL;
     }
       fclose(Subsubsections);
       Subsubsections = NULL;
     }
@@ -2895,17 +2997,19 @@ bool HTMLGo(void)
       if (DocumentTitle)
       {
         SetCurrentOutput(tmpTitle);
       if (DocumentTitle)
       {
         SetCurrentOutput(tmpTitle);
-        TexOutput("\n<HTML>\n<HEAD><TITLE>");
+       HTMLHead();
+        TexOutput("\n<HEAD><TITLE>");
         TraverseChildrenFromChunk(DocumentTitle);
         TexOutput("</TITLE></HEAD>\n");
       }
       else
       {
         SetCurrentOutput(tmpTitle);
         TraverseChildrenFromChunk(DocumentTitle);
         TexOutput("</TITLE></HEAD>\n");
       }
       else
       {
         SetCurrentOutput(tmpTitle);
+       HTMLHeadTo(tmpTitle);
         if (contentsString)
         if (contentsString)
-          fprintf(tmpTitle, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString);
+          fprintf(tmpTitle, "<TITLE>%s</TITLE></HEAD>\n\n", contentsString);
         else
         else
-          fprintf(tmpTitle, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot));
+          fprintf(tmpTitle, "<TITLE>%s</TITLE></HEAD>\n\n", wxFileNameFromPath(FileRoot));
       }
 
       // Output frame information
       }
 
       // Output frame information
@@ -2919,8 +3023,8 @@ bool HTMLGo(void)
 
         fprintf(tmpTitle, "<FRAMESET COLS=\"30%%,70%%\">\n");
 
 
         fprintf(tmpTitle, "<FRAMESET COLS=\"30%%,70%%\">\n");
 
-        fprintf(tmpTitle, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName)));
-        fprintf(tmpTitle, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName)));
+        fprintf(tmpTitle, "<FRAME SRC=\"%s\">\n", ConvertCase(wxFileNameFromPath(contentsFrameName)));
+        fprintf(tmpTitle, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(wxFileNameFromPath(firstFileName)));
         fprintf(tmpTitle, "</FRAMESET>\n");
 
         fprintf(tmpTitle, "<NOFRAMES>\n");
         fprintf(tmpTitle, "</FRAMESET>\n");
 
         fprintf(tmpTitle, "<NOFRAMES>\n");
@@ -2942,7 +3046,7 @@ bool HTMLGo(void)
         fclose(fd);
       }
 
         fclose(fd);
       }
 
-      fprintf(tmpTitle, "\n</BODY>\n");
+      fprintf(tmpTitle, "\n</FONT></BODY>\n");
 
       if (htmlFrameContents)
       {
 
       if (htmlFrameContents)
       {
@@ -2951,7 +3055,7 @@ bool HTMLGo(void)
       fprintf(tmpTitle, "\n</HTML>\n");
 
       fclose(tmpTitle);
       fprintf(tmpTitle, "\n</HTML>\n");
 
       fclose(tmpTitle);
-      if (FileExists(TitlepageName)) wxRemoveFile(TitlepageName);
+      if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName);
       if (!wxRenameFile("title.tmp", TitlepageName))
       {
         wxCopyFile("title.tmp", TitlepageName);
       if (!wxRenameFile("title.tmp", TitlepageName))
       {
         wxCopyFile("title.tmp", TitlepageName);
@@ -2964,7 +3068,7 @@ bool HTMLGo(void)
     if (lastTopic) delete[] lastTopic;
     lastTopic = NULL;
 
     if (lastTopic) delete[] lastTopic;
     lastTopic = NULL;
 
-    if (FileExists(ContentsName)) wxRemoveFile(ContentsName);
+    if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
 
     if (!wxRenameFile(TmpContentsName, ContentsName))
     {
 
     if (!wxRenameFile(TmpContentsName, ContentsName))
     {
@@ -3049,11 +3153,11 @@ void GenerateHTMLWorkshopFiles(char *fname)
       "Default topic=%s\n"
       "Index file=%s.hhk\n"
       "Title=",
       "Default topic=%s\n"
       "Index file=%s.hhk\n"
       "Title=",
-      FileNameFromPath(fname),
-      FileNameFromPath(fname),
-      FileNameFromPath(fname),
-      FileNameFromPath(TitlepageName),
-      FileNameFromPath(fname)
+      wxFileNameFromPath(fname),
+      wxFileNameFromPath(fname),
+      wxFileNameFromPath(fname),
+      wxFileNameFromPath(TitlepageName),
+      wxFileNameFromPath(fname)
       );
 
   if (DocumentTitle) {
       );
 
   if (DocumentTitle) {
@@ -3064,19 +3168,19 @@ void GenerateHTMLWorkshopFiles(char *fname)
 
   fprintf(f, "\n\n[WINDOWS]\n"
           "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
 
   fprintf(f, "\n\n[WINDOWS]\n"
           "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
-          FileNameFromPath(fname),
-          FileNameFromPath(fname),
-          FileNameFromPath(fname),
-          FileNameFromPath(TitlepageName));
+          wxFileNameFromPath(fname),
+          wxFileNameFromPath(fname),
+          wxFileNameFromPath(fname),
+          wxFileNameFromPath(TitlepageName));
 
 
   fprintf(f, "\n\n[FILES]\n");
 
 
   fprintf(f, "\n\n[FILES]\n");
-  fprintf(f, "%s\n", FileNameFromPath(TitlepageName));
+  fprintf(f, "%s\n", wxFileNameFromPath(TitlepageName));
   for (int i = 1; i <= fileId; i++) {
     if (truncateFilenames)
   for (int i = 1; i <= fileId; i++) {
     if (truncateFilenames)
-      sprintf(buf, "%s%d.htm", FileNameFromPath(FileRoot), i);
+      sprintf(buf, "%s%d.htm", wxFileNameFromPath(FileRoot), i);
     else
     else
-      sprintf(buf, "%s%d.html", FileNameFromPath(FileRoot), i);
+      sprintf(buf, "%s%d.html", wxFileNameFromPath(FileRoot), i);
     fprintf(f, "%s\n", buf);
   }
   fclose(f);
     fprintf(f, "%s\n", buf);
   }
   fclose(f);
@@ -3088,8 +3192,10 @@ void GenerateHTMLWorkshopFiles(char *fname)
 
   fprintf(f,
       "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
 
   fprintf(f,
       "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
-      "<HTML>\n"
-      "<HEAD>\n"
+      "<HTML>\n");
+  HTMLHeadTo(f);
+  fprintf(f,
+      "\n"
       "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
       "<!-- Sitemap 1.0 -->\n"
       "</HEAD><BODY>\n"
       "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
       "<!-- Sitemap 1.0 -->\n"
       "</HEAD><BODY>\n"
@@ -3164,8 +3270,10 @@ void HTMLWorkshopStartContents()
 
   fprintf(HTMLWorkshopContents,
       "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
 
   fprintf(HTMLWorkshopContents,
       "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
-      "<HTML>\n"
-      "<HEAD>\n"
+      "<HTML>\n");
+  HTMLHeadTo(HTMLWorkshopContents);
+  fprintf(HTMLWorkshopContents,
+      "\n"
       "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
       "<!-- Sitemap 1.0 -->\n"
       "</HEAD><BODY>\n"
       "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
       "<!-- Sitemap 1.0 -->\n"
       "</HEAD><BODY>\n"
@@ -3176,7 +3284,7 @@ void HTMLWorkshopStartContents()
       "<LI> <OBJECT type=\"text/sitemap\">\n"
       "<param name=\"Local\" value=\"%s\">\n"
       "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
       "<LI> <OBJECT type=\"text/sitemap\">\n"
       "<param name=\"Local\" value=\"%s\">\n"
       "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
-      FileNameFromPath(TitlepageName)
+      wxFileNameFromPath(TitlepageName)
       );
 
 }
       );
 
 }