1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to HTML
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
32 extern wxHashTable TexReferences
;
35 extern void DecToHex(int, char *);
36 void GenerateHTMLIndexFile(char *fname
);
38 void GenerateHTMLWorkshopFiles(char *fname
);
39 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
);
40 void HTMLWorkshopStartContents();
41 void HTMLWorkshopEndContents();
43 void OutputContentsFrame(void);
45 #include "readshg.h" // Segmented hypergraphics parsing
47 char *ChaptersName
= NULL
;
48 char *SectionsName
= NULL
;
49 char *SubsectionsName
= NULL
;
50 char *SubsubsectionsName
= NULL
;
51 char *TitlepageName
= NULL
;
52 char *lastFileName
= NULL
;
53 char *lastTopic
= NULL
;
54 char *currentFileName
= NULL
;
55 char *contentsFrameName
= NULL
;
57 static TexChunk
*descriptionItemArg
= NULL
;
58 static TexChunk
*helpRefFilename
= NULL
;
59 static TexChunk
*helpRefText
= NULL
;
60 static int indentLevel
= 0;
61 static int citeCount
= 1;
62 extern FILE *Contents
;
63 FILE *FrameContents
= NULL
;
64 FILE *Titlepage
= NULL
;
65 // FILE *FrameTitlepage = NULL;
67 bool subsectionStarted
= FALSE
;
69 // Which column of a row are we in? (Assumes no nested tables, of course)
70 int currentColumn
= 0;
72 // Are we in verbatim mode? If so, format differently.
73 static bool inVerbatim
= FALSE
;
75 // Need to know whether we're in a table or figure for benefit
76 // of listoffigures/listoftables
77 static bool inFigure
= FALSE
;
78 static bool inTable
= FALSE
;
80 // This is defined in the Tex2Any library.
81 extern char *BigBuffer
;
83 class HyperReference
: public wxObject
88 HyperReference(char *name
, char *file
)
90 if (name
) refName
= copystring(name
);
91 if (file
) refFile
= copystring(file
);
95 class TexNextPage
: public wxObject
100 TexNextPage(char *theLabel
, char *theFile
)
102 label
= copystring(theLabel
);
103 filename
= copystring(theFile
);
112 wxHashTable
TexNextPages(wxKEY_STRING
);
114 static char *CurrentChapterName
= NULL
;
115 static char *CurrentChapterFile
= NULL
;
116 static char *CurrentSectionName
= NULL
;
117 static char *CurrentSectionFile
= NULL
;
118 static char *CurrentSubsectionName
= NULL
;
119 static char *CurrentSubsectionFile
= NULL
;
120 static char *CurrentSubsubsectionName
= NULL
;
121 static char *CurrentSubsubsectionFile
= NULL
;
122 static char *CurrentTopic
= NULL
;
124 static void SetCurrentTopic(char *s
)
126 if (CurrentTopic
) delete[] CurrentTopic
;
127 CurrentTopic
= copystring(s
);
130 void SetCurrentChapterName(char *s
, char *file
)
132 if (CurrentChapterName
) delete[] CurrentChapterName
;
133 CurrentChapterName
= copystring(s
);
134 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
135 CurrentChapterFile
= copystring(file
);
137 currentFileName
= CurrentChapterFile
;
141 void SetCurrentSectionName(char *s
, char *file
)
143 if (CurrentSectionName
) delete[] CurrentSectionName
;
144 CurrentSectionName
= copystring(s
);
145 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
146 CurrentSectionFile
= copystring(file
);
148 currentFileName
= CurrentSectionFile
;
151 void SetCurrentSubsectionName(char *s
, char *file
)
153 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
154 CurrentSubsectionName
= copystring(s
);
155 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
156 CurrentSubsectionFile
= copystring(file
);
157 currentFileName
= CurrentSubsectionFile
;
160 void SetCurrentSubsubsectionName(char *s
, char *file
)
162 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
163 CurrentSubsubsectionName
= copystring(s
);
164 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
165 CurrentSubsubsectionFile
= copystring(file
);
166 currentFileName
= CurrentSubsubsectionFile
;
171 * Close former filedescriptor and reopen using another filename.
175 void ReopenFile(FILE **fd
, char **fileName
)
179 fprintf(*fd
, "\n</BODY></HTML>\n");
184 if (truncateFilenames
)
185 sprintf(buf
, "%s%d.htm", FileRoot
, fileId
);
187 sprintf(buf
, "%s%d.html", FileRoot
, fileId
);
188 if (*fileName
) delete[] *fileName
;
189 *fileName
= copystring(FileNameFromPath(buf
));
190 *fd
= fopen(buf
, "w");
191 fprintf(*fd
, "<HTML>\n");
195 * Reopen section contents file, i.e. the index appended to each section
196 * in subsectionCombine mode
199 static char *SectionContentsFilename
= NULL
;
200 static FILE *SectionContentsFD
= NULL
;
202 void ReopenSectionContentsFile(void)
204 if ( SectionContentsFD
)
206 fclose(SectionContentsFD
);
208 if ( SectionContentsFilename
)
209 delete[] SectionContentsFilename
;
210 SectionContentsFD
= NULL
;
211 SectionContentsFilename
= NULL
;
213 // Create the name from the current section filename
214 if ( CurrentSectionFile
)
217 strcpy(buf
, CurrentSectionFile
);
218 wxStripExtension(buf
);
220 SectionContentsFilename
= copystring(buf
);
222 SectionContentsFD
= fopen(SectionContentsFilename
, "w");
228 * Given a TexChunk with a string value, scans through the string
229 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
233 void ProcessText2HTML(TexChunk
*chunk
)
235 bool changed
= FALSE
;
239 int len
= strlen(chunk
->value
);
242 ch
= chunk
->value
[i
];
244 // 2 newlines means \par
245 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
246 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
247 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
249 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "<P>\n\n"); ptr
+= 5;
253 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
255 BigBuffer
[ptr
] = '"'; ptr
++;
259 else if (!inVerbatim
&& ch
== '`') // Change ` to '
261 BigBuffer
[ptr
] = 39; ptr
++;
265 else if (ch
== '<') // Change < to <
268 strcat(BigBuffer
, "<");
273 else if (ch
== '>') // Change > to >
276 strcat(BigBuffer
, ">");
293 chunk
->value
= copystring(BigBuffer
);
298 * Scan through all chunks starting from the given one,
299 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
300 * This should be called after Tex2Any has parsed the file,
301 * and before TraverseDocument is called.
305 void Text2HTML(TexChunk
*chunk
)
308 if (stopRunning
) return;
312 case CHUNK_TYPE_MACRO
:
314 TexMacroDef
*def
= chunk
->def
;
316 if (def
&& def
->ignore
)
319 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
322 wxNode
*node
= chunk
->children
.First();
325 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
326 Text2HTML(child_chunk
);
330 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
337 wxNode
*node
= chunk
->children
.First();
340 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
341 Text2HTML(child_chunk
);
347 case CHUNK_TYPE_STRING
:
350 ProcessText2HTML(chunk
);
357 * Add appropriate browse buttons to this page.
361 void AddBrowseButtons(char *upLabel
, char *upFilename
,
362 char *previousLabel
, char *previousFilename
,
363 char *thisLabel
, char *thisFilename
)
365 char contentsReferenceBuf
[80];
366 char upReferenceBuf
[80];
367 char backReferenceBuf
[80];
368 char forwardReferenceBuf
[80];
369 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
372 char *contentsReference
= NULL
;
373 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
374 contentsReference
= ContentsNameString
;
377 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
378 contentsReference
= contentsReferenceBuf
;
379 sprintf(contentsReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">", ConvertCase("contents.gif"));
382 char *upReference
= NULL
;
383 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
384 upReference
= UpNameString
;
387 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
388 upReference
= upReferenceBuf
;
389 sprintf(upReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">", ConvertCase("up.gif"));
392 char *backReference
= NULL
;
393 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
394 backReference
= "<<";
397 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
398 backReference
= backReferenceBuf
;
399 sprintf(backReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">", ConvertCase("back.gif"));
402 char *forwardReference
= NULL
;
403 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
404 forwardReference
= ">>";
407 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
408 forwardReference
= forwardReferenceBuf
;
409 sprintf(forwardReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">", ConvertCase("forward.gif"));
412 TexOutput("<CENTER>");
421 if (truncateFilenames
)
424 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
425 sprintf(buf
, "\n<A HREF=\"%s.%s\">%s</A> ", buf1
, ConvertCase("htm"), contentsReference
);
430 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
431 sprintf(buf
, "\n<A HREF=\"%s%s\">%s</A> ", buf1
, ConvertCase("_contents.html"), contentsReference
);
433 // TexOutput("<NOFRAMES>");
435 // TexOutput("</NOFRAMES>");
442 if (upLabel
&& upFilename
)
444 if (strlen(upLabel
) > 0)
445 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(upFilename
), upLabel
, upReference
);
447 sprintf(buf
, "<A HREF=\"%s\">%s</A> ", ConvertCase(upFilename
), upReference
);
448 if (strcmp(upLabel
, "contents") == 0)
450 // TexOutput("<NOFRAMES>");
452 // TexOutput("</NOFRAMES>");
463 if (previousLabel
&& previousFilename
)
465 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(previousFilename
), previousLabel
, backReference
);
466 if (strcmp(previousLabel
, "contents") == 0)
468 // TexOutput("<NOFRAMES>");
470 // TexOutput("</NOFRAMES>");
477 // A placeholder so the buttons don't keep moving position
478 sprintf(buf
, "%s ", backReference
);
482 char *nextLabel
= NULL
;
483 char *nextFilename
= NULL
;
485 // Get the next page, and record the previous page's 'next' page
487 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
490 nextLabel
= nextPage
->label
;
491 nextFilename
= nextPage
->filename
;
493 if (previousLabel
&& previousFilename
)
495 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
499 TexNextPages
.Delete(previousLabel
);
501 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
502 TexNextPages
.Put(previousLabel
, newNextPage
);
510 if (nextLabel
&& nextFilename
)
512 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(nextFilename
), nextLabel
, forwardReference
);
517 // A placeholder so the buttons don't keep moving position
518 sprintf(buf
, "%s ", forwardReference
);
523 * Horizontal rule to finish it off nicely.
526 TexOutput("</CENTER>");
529 // Update last topic/filename
531 delete[] lastFileName
;
532 lastFileName
= copystring(thisFilename
);
535 lastTopic
= copystring(thisLabel
);
538 // A colour string is either 3 numbers separated by semicolons (RGB),
539 // or a reference to a GIF. Return the filename or a hex string like #934CE8
540 char *ParseColourString(char *bkStr
, bool *isPicture
)
542 static char resStr
[300];
543 strcpy(resStr
, bkStr
);
544 char *tok1
= strtok(resStr
, ";");
545 char *tok2
= strtok(NULL
, ";");
556 char *tok3
= strtok(NULL
, ";");
559 // Now convert 3 strings into decimal numbers, and then hex numbers.
560 int red
= atoi(tok1
);
561 int green
= atoi(tok2
);
562 int blue
= atoi(tok3
);
569 DecToHex(green
, buf
);
581 // Output start of <BODY> block
582 void OutputBodyStart(void)
584 TexOutput("\n<BODY");
585 if (backgroundImageString
)
587 bool isPicture
= FALSE
;
588 char *s
= ParseColourString(backgroundImageString
, &isPicture
);
591 TexOutput(" BACKGROUND=\""); TexOutput(s
); TexOutput("\"");
594 if (backgroundColourString
)
596 bool isPicture
= FALSE
;
597 char *s
= ParseColourString(backgroundColourString
, &isPicture
);
600 TexOutput(" BGCOLOR="); TexOutput(s
);
604 // Set foreground text colour, if one is specified
605 if (textColourString
)
607 bool isPicture
= FALSE
;
608 char *s
= ParseColourString(textColourString
, &isPicture
);
611 TexOutput(" TEXT="); TexOutput(s
);
614 // Set link text colour, if one is specified
615 if (linkColourString
)
617 bool isPicture
= FALSE
;
618 char *s
= ParseColourString(linkColourString
, &isPicture
);
621 TexOutput(" LINK="); TexOutput(s
);
624 // Set followed link text colour, if one is specified
625 if (followedLinkColourString
)
627 bool isPicture
= FALSE
;
628 char *s
= ParseColourString(followedLinkColourString
, &isPicture
);
631 TexOutput(" VLINK="); TexOutput(s
);
637 // Called on start/end of macro examination
638 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
644 case ltCHAPTERHEADING
:
652 if (macroId
!= ltCHAPTERSTAR
)
655 SetCurrentOutput(NULL
);
656 startedSections
= TRUE
;
658 char *topicName
= FindTopicName(GetNextChunk());
659 ReopenFile(&Chapters
, &ChaptersName
);
660 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
662 SetCurrentChapterName(topicName
, ChaptersName
);
663 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
665 SetCurrentOutput(Chapters
);
667 TexOutput("<head><title>");
668 OutputCurrentSection(); // Repeat section header
669 TexOutput("</title></head>\n");
673 if (truncateFilenames
)
674 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
676 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
678 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
680 AddBrowseButtons("", titleBuf
, // Up
681 lastTopic
, lastFileName
, // Last topic
682 topicName
, ChaptersName
); // This topic
684 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
686 if (htmlFrameContents
&& FrameContents
)
688 SetCurrentOutput(FrameContents
);
689 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
690 OutputCurrentSection();
691 fprintf(FrameContents
, "</A>\n");
694 SetCurrentOutputs(Contents
, Chapters
);
695 fprintf(Chapters
, "\n<H2>");
696 OutputCurrentSection();
697 fprintf(Contents
, "</A>\n");
698 fprintf(Chapters
, "</H2>\n");
700 SetCurrentOutput(Chapters
);
702 // Add this section title to the list of keywords
705 OutputCurrentSectionToString(wxBuffer
);
706 AddKeyWordForTopic(topicName
, wxBuffer
, ConvertCase(currentFileName
));
713 case ltSECTIONHEADING
:
720 subsectionStarted
= FALSE
;
722 if (macroId
!= ltSECTIONSTAR
)
725 SetCurrentOutput(NULL
);
726 startedSections
= TRUE
;
728 char *topicName
= FindTopicName(GetNextChunk());
729 ReopenFile(&Sections
, &SectionsName
);
730 AddTexRef(topicName
, SectionsName
, SectionNameString
);
732 SetCurrentSectionName(topicName
, SectionsName
);
733 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
735 SetCurrentOutput(Sections
);
736 TexOutput("<head><title>");
737 OutputCurrentSection();
738 TexOutput("</title></head>\n");
741 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
742 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
743 lastTopic
, lastFileName
, // Last topic
744 topicName
, SectionsName
); // This topic
746 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
748 SetCurrentOutputs(jumpFrom
, Sections
);
749 if (DocumentStyle
== LATEX_ARTICLE
)
750 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
752 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
754 fprintf(Sections
, "\n<H2>");
755 OutputCurrentSection();
757 if (DocumentStyle
== LATEX_ARTICLE
)
758 fprintf(jumpFrom
, "</A>\n");
760 fprintf(jumpFrom
, "</B></A><BR>\n");
761 fprintf(Sections
, "</H2>\n");
763 SetCurrentOutput(Sections
);
764 // Add this section title to the list of keywords
767 OutputCurrentSectionToString(wxBuffer
);
768 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
774 case ltSUBSECTIONSTAR
:
775 case ltMEMBERSECTION
:
776 case ltFUNCTIONSECTION
:
782 OnError("You cannot have a subsection before a section!");
788 if (macroId
!= ltSUBSECTIONSTAR
)
791 if ( combineSubSections
&& !subsectionStarted
)
793 // Read old .con file in at this point
795 strcpy(buf
, CurrentSectionFile
);
796 wxStripExtension(buf
);
798 FILE *fd
= fopen(buf
, "r");
809 fprintf(Sections
, "<P>\n");
811 // Close old file, create a new file for the sub(sub)section contents entries
812 ReopenSectionContentsFile();
815 startedSections
= TRUE
;
816 subsectionStarted
= TRUE
;
818 char *topicName
= FindTopicName(GetNextChunk());
820 if ( !combineSubSections
)
822 SetCurrentOutput(NULL
);
823 ReopenFile(&Subsections
, &SubsectionsName
);
824 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
825 SetCurrentSubsectionName(topicName
, SubsectionsName
);
826 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
827 SetCurrentOutput(Subsections
);
829 TexOutput("<head><title>");
830 OutputCurrentSection();
831 TexOutput("</title></head>\n");
834 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
835 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
836 lastTopic
, lastFileName
, // Last topic
837 topicName
, SubsectionsName
); // This topic
839 SetCurrentOutputs(Sections
, Subsections
);
840 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
842 fprintf(Subsections
, "\n<H3>");
843 OutputCurrentSection();
844 fprintf(Sections
, "</B></A><BR>\n");
845 fprintf(Subsections
, "</H3>\n");
847 SetCurrentOutput(Subsections
);
851 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
852 SetCurrentSubsectionName(topicName
, SectionsName
);
854 // if ( subsectionNo != 0 )
855 fprintf(Sections
, "\n<HR>\n");
857 // We're putting everything into the section file
858 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
859 fprintf(Sections
, "\n<H3>");
860 OutputCurrentSection();
861 fprintf(Sections
, "</H3>\n");
863 SetCurrentOutput(SectionContentsFD
);
864 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
865 OutputCurrentSection();
866 TexOutput("</A><BR>\n");
868 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
869 SetCurrentOutput(Sections
);
871 // Add this section title to the list of keywords
874 OutputCurrentSectionToString(wxBuffer
);
875 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
882 case ltSUBSUBSECTION
:
883 case ltSUBSUBSECTIONSTAR
:
887 if (!Subsections
&& !combineSubSections
)
889 OnError("You cannot have a subsubsection before a subsection!");
893 if (macroId
!= ltSUBSUBSECTIONSTAR
)
896 startedSections
= TRUE
;
898 char *topicName
= FindTopicName(GetNextChunk());
900 if ( !combineSubSections
)
902 SetCurrentOutput(NULL
);
903 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
904 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
905 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
906 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
908 SetCurrentOutput(Subsubsections
);
909 TexOutput("<head><title>");
910 OutputCurrentSection();
911 TexOutput("</title></head>\n");
914 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
916 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
917 lastTopic
, lastFileName
, // Last topic
918 topicName
, SubsubsectionsName
); // This topic
920 SetCurrentOutputs(Subsections
, Subsubsections
);
921 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
923 fprintf(Subsubsections
, "\n<H3>");
924 OutputCurrentSection();
925 fprintf(Subsections
, "</B></A><BR>\n");
926 fprintf(Subsubsections
, "</H3>\n");
930 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
931 SetCurrentSubsectionName(topicName
, SectionsName
);
932 fprintf(Sections
, "\n<HR>\n");
934 // We're putting everything into the section file
935 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
936 fprintf(Sections
, "\n<H3>");
937 OutputCurrentSection();
938 fprintf(Sections
, "</H3>\n");
939 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
940 SetCurrentOutput(SectionContentsFD);
941 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
942 OutputCurrentSection();
943 TexOutput("</A><BR>");
945 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
946 SetCurrentOutput(Sections
);
949 // Add this section title to the list of keywords
952 OutputCurrentSectionToString(wxBuffer
);
953 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
962 if ( !combineSubSections
)
963 SetCurrentOutput(Subsections
);
965 SetCurrentOutput(Sections
);
976 if ( !combineSubSections
)
977 SetCurrentOutput(Subsections
);
979 SetCurrentOutput(Sections
);
990 if ( !combineSubSections
)
991 SetCurrentOutput(Subsections
);
993 SetCurrentOutput(Sections
);
1004 // TexOutput("<B>void</B>");
1012 TexOutput("wxCLIPS");
1018 case ltSPECIALAMPERSAND
:
1024 // End cell, start cell
1027 // Start new row and cell, setting alignment for the first cell.
1028 if (currentColumn
< noColumns
)
1032 if (TableData
[currentColumn
].justification
== 'c')
1033 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1034 else if (TableData
[currentColumn
].justification
== 'r')
1035 sprintf(buf
, "\n<TD ALIGN=RIGHT>");
1036 else if (TableData
[currentColumn
].absWidth
)
1038 // Convert from points * 20 into pixels.
1039 int points
= TableData
[currentColumn
].width
/ 20;
1041 // Say the display is 100 DPI (dots/pixels per inch).
1042 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1043 int pixels
= (int)(points
* 100.0 / 72.0);
1044 sprintf(buf
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1047 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1055 case ltBACKSLASHCHAR
:
1061 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1062 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1063 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1064 TexOutput("</TR>\n");
1067 TexOutput("<BR>\n");
1078 // Start new row and cell, setting alignment for the first cell.
1080 if (TableData
[currentColumn
].justification
== 'c')
1081 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1082 else if (TableData
[currentColumn
].justification
== 'r')
1083 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1084 else if (TableData
[currentColumn
].absWidth
)
1086 // Convert from points * 20 into pixels.
1087 int points
= TableData
[currentColumn
].width
/ 20;
1089 // Say the display is 100 DPI (dots/pixels per inch).
1090 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1091 int pixels
= (int)(points
* 100.0 / 72.0);
1092 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1095 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1101 // Start new row and cell
1102 TexOutput("</TD>\n</TR>\n");
1106 // HTML-only: break until the end of the picture (both margins are clear).
1110 TexOutput("<BR CLEAR=ALL>");
1113 case ltRTFSP
: // Explicit space, RTF only
1115 case ltSPECIALTILDE
:
1129 TexOutput("<UL><UL>\n");
1131 TexOutput("</UL></UL>\n");
1137 // case ltTWOCOLLIST:
1144 if (macroId
== ltENUMERATE
)
1145 listType
= LATEX_ENUMERATE
;
1146 else if (macroId
== ltITEMIZE
)
1147 listType
= LATEX_ITEMIZE
;
1149 listType
= LATEX_DESCRIPTION
;
1151 itemizeStack
.Insert(new ItemizeStruc(listType
));
1155 TexOutput("<UL>\n");
1157 case LATEX_ENUMERATE
:
1158 TexOutput("<OL>\n");
1160 case LATEX_DESCRIPTION
:
1162 TexOutput("<DL>\n");
1169 if (itemizeStack
.First())
1171 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1172 switch (struc
->listType
)
1175 TexOutput("</UL>\n");
1177 case LATEX_ENUMERATE
:
1178 TexOutput("</OL>\n");
1180 case LATEX_DESCRIPTION
:
1182 TexOutput("</DL>\n");
1187 delete itemizeStack
.First();
1195 TexOutput("\n<TABLE>\n");
1197 TexOutput("\n</TABLE>\n");
1206 /* For footnotes we need to output the text at the bottom of the page and
1207 * insert a reference to it. Is it worth the trouble...
1209 case ltFOOTNOTEPOPUP:
1215 else TexOutput("</FN>");
1223 else TexOutput("</TT>");
1231 sprintf(buf
, "<PRE>\n");
1234 else TexOutput("</PRE>\n");
1242 TexOutput("<CENTER>");
1244 else TexOutput("</CENTER>");
1252 TexOutput("{\\ql ");
1254 else TexOutput("}\\par\\pard\n");
1263 TexOutput("{\\qr ");
1265 else TexOutput("}\\par\\pard\n");
1273 // Netscape extension
1274 TexOutput("<FONT SIZE=2>");
1276 else TexOutput("</FONT>");
1283 // Netscape extension
1284 TexOutput("<FONT SIZE=1>");
1286 else TexOutput("</FONT>");
1293 // Netscape extension
1294 TexOutput("<FONT SIZE=3>");
1296 else TexOutput("</FONT>");
1303 // Netscape extension
1304 TexOutput("<FONT SIZE=4>");
1306 else TexOutput("</FONT>");
1313 // Netscape extension
1314 TexOutput("<FONT SIZE=5>");
1316 else TexOutput("</FONT>");
1323 // Netscape extension
1324 TexOutput("<FONT SIZE=6>");
1326 else TexOutput("</FONT>");
1337 else TexOutput("</B>");
1348 else TexOutput("</I>");
1358 else TexOutput("</EM>");
1367 else TexOutput("</UL>");
1378 else TexOutput("</TT>");
1384 TexOutput("©", TRUE
);
1390 TexOutput("®", TRUE
);
1396 if (start
) TexOutput("<--");
1401 if (start
) TexOutput("<==");
1406 if (start
) TexOutput("-->");
1411 if (start
) TexOutput("==>");
1414 case ltLEFTRIGHTARROW
:
1416 if (start
) TexOutput("<-->");
1419 case ltLEFTRIGHTARROW2
:
1421 if (start
) TexOutput("<==>");
1434 wxNode
*node
= itemizeStack
.First();
1437 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1438 struc
->currentItem
+= 1;
1439 if (struc
->listType
== LATEX_DESCRIPTION
)
1441 if (descriptionItemArg
)
1444 TraverseChildrenFromChunk(descriptionItemArg
);
1446 descriptionItemArg
= NULL
;
1458 if (start
&& DocumentTitle
&& DocumentAuthor
)
1460 // Add a special label for the contents page.
1461 // TexOutput("<CENTER>\n");
1462 TexOutput("<A NAME=\"contents\">");
1463 TexOutput("<H2 ALIGN=CENTER>\n");
1464 TraverseChildrenFromChunk(DocumentTitle
);
1467 TexOutput("</A>\n");
1468 TexOutput("<P>\n\n");
1469 TexOutput("<H3 ALIGN=CENTER>");
1470 TraverseChildrenFromChunk(DocumentAuthor
);
1471 TexOutput("</H3><P>\n\n");
1474 TexOutput("<H3 ALIGN=CENTER>");
1475 TraverseChildrenFromChunk(DocumentDate
);
1476 TexOutput("</H3><P>\n\n");
1478 // TexOutput("\n</CENTER>\n");
1479 TexOutput("\n<P><HR><P>\n");
1482 // Now do optional frame contents page
1483 if (htmlFrameContents && FrameContents)
1485 SetCurrentOutput(FrameContents);
1487 // Add a special label for the contents page.
1488 TexOutput("<CENTER>\n");
1489 TexOutput("<H3>\n");
1490 TraverseChildrenFromChunk(DocumentTitle);
1493 TexOutput("</A>\n");
1494 TexOutput("<P>\n\n");
1496 TraverseChildrenFromChunk(DocumentAuthor);
1497 TexOutput("</H3><P>\n\n");
1501 TraverseChildrenFromChunk(DocumentDate);
1502 TexOutput("</H4><P>\n\n");
1504 TexOutput("\n</CENTER>\n");
1505 TexOutput("<P><HR><P>\n");
1507 SetCurrentOutput(Titlepage);
1520 helpRefFilename
= NULL
;
1525 case ltBIBLIOGRAPHY
:
1529 DefaultOnMacro(macroId
, no_args
, start
);
1533 DefaultOnMacro(macroId
, no_args
, start
);
1534 TexOutput("</DL>\n");
1542 TexOutput("<HR>\n");
1550 TexOutput("<HR>\n");
1554 case ltTABLEOFCONTENTS
:
1558 FILE *fd
= fopen(ContentsName
, "r");
1564 putc(ch
, Titlepage
);
1571 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1572 OnInform("Run Tex2RTF again to include contents page.");
1593 TexOutput("<BLOCKQUOTE>");
1595 TexOutput("</BLOCKQUOTE>");
1604 TexOutput("\n<CAPTION>");
1612 if (DocumentStyle
!= LATEX_ARTICLE
)
1613 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1615 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1621 if (DocumentStyle
!= LATEX_ARTICLE
)
1622 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1624 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1632 TexOutput("\n</CAPTION>\n");
1634 char *topicName
= FindTopicName(GetNextChunk());
1636 int n
= inFigure
? figureNo
: tableNo
;
1638 AddTexRef(topicName
, NULL
, NULL
,
1639 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1640 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1646 if (start
) TexOutput("ß");
1651 if (start
) inFigure
= TRUE
;
1652 else inFigure
= FALSE
;
1657 if (start
) inTable
= TRUE
;
1658 else inTable
= FALSE
;
1662 DefaultOnMacro(macroId
, no_args
, start
);
1667 // Called on start/end of argument examination
1668 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1674 case ltCHAPTERHEADING
:
1677 case ltSECTIONHEADING
:
1679 case ltSUBSECTIONSTAR
:
1680 case ltSUBSUBSECTION
:
1681 case ltSUBSUBSECTIONSTAR
:
1683 case ltMEMBERSECTION
:
1684 case ltFUNCTIONSECTION
:
1686 if (!start
&& (arg_no
== 1))
1687 currentSection
= GetArgChunk();
1693 if (start
&& (arg_no
== 1))
1696 if (!start
&& (arg_no
== 1))
1699 if (start
&& (arg_no
== 2))
1701 if (!suppressNameDecoration
) TexOutput("<B>");
1702 currentMember
= GetArgChunk();
1704 if (!start
&& (arg_no
== 2))
1706 if (!suppressNameDecoration
) TexOutput("</B>");
1709 if (start
&& (arg_no
== 3))
1711 if (!start
&& (arg_no
== 3))
1717 if (start
&& (arg_no
== 1))
1719 if (!start
&& (arg_no
== 1))
1722 if (start
&& (arg_no
== 2))
1724 if (!suppressNameDecoration
) TexOutput("( ");
1725 currentMember
= GetArgChunk();
1727 if (!start
&& (arg_no
== 2))
1731 if (!start
&& (arg_no
== 3))
1737 if (!start
&& (arg_no
== 1))
1740 if (start
&& (arg_no
== 2))
1742 if (!start
&& (arg_no
== 2))
1745 if (start
&& (arg_no
== 2))
1746 currentMember
= GetArgChunk();
1748 if (start
&& (arg_no
== 3))
1750 if (!start
&& (arg_no
== 3))
1756 if (start
&& (arg_no
== 1))
1758 if (!start
&& (arg_no
== 1))
1760 if (start
&& (arg_no
== 2))
1764 if (!start
&& (arg_no
== 2))
1772 if (start
&& (arg_no
== 1))
1774 if (!start
&& (arg_no
== 1))
1775 TexOutput("</B> "); // This is the difference from param - one space!
1776 if (start
&& (arg_no
== 2))
1780 if (!start
&& (arg_no
== 2))
1788 if (!start
&& (arg_no
== 1))
1791 if (start
&& (arg_no
== 2))
1792 currentMember
= GetArgChunk();
1801 char *refName
= GetArgData();
1804 TexRef
*texRef
= FindReference(refName
);
1807 sec
= texRef
->sectionNumber
;
1820 if (IsArgOptional())
1822 else if ((GetNoArgs() - arg_no
) == 1)
1825 helpRefText
= GetArgChunk();
1828 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1832 TexChunk
*ref
= GetArgChunk();
1833 TexOutput("<A HREF=\"");
1835 TraverseChildrenFromChunk(ref
);
1839 TraverseChildrenFromChunk(helpRefText
);
1850 if (IsArgOptional())
1853 helpRefFilename
= GetArgChunk();
1856 if ((GetNoArgs() - arg_no
) == 1)
1859 helpRefText
= GetArgChunk();
1862 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1866 char *refName
= GetArgData();
1867 char *refFilename
= NULL
;
1871 TexRef
*texRef
= FindReference(refName
);
1874 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1875 refFilename
= texRef
->refFile
;
1877 TexOutput("<A HREF=\"");
1878 // If a filename is supplied, use it, otherwise try to
1879 // use the filename associated with the reference (from this document).
1880 if (helpRefFilename
)
1882 TraverseChildrenFromChunk(helpRefFilename
);
1885 else if (refFilename
)
1887 TexOutput(ConvertCase(refFilename
));
1893 TraverseChildrenFromChunk(helpRefText
);
1899 TraverseChildrenFromChunk(helpRefText
);
1900 TexOutput(" (REF NOT FOUND)");
1903 else TexOutput("??");
1918 char *alignment
= "";
1919 if (macroId
== ltIMAGEL
)
1920 alignment
= " align=left";
1921 else if (macroId
== ltIMAGER
)
1922 alignment
= " align=right";
1924 // Try to find an XBM or GIF image first.
1925 char *filename
= copystring(GetArgData());
1928 strcpy(buf
, filename
);
1929 StripExtension(buf
);
1930 strcat(buf
, ".xbm");
1931 wxString f
= TexPathList
.FindValidPath(buf
);
1933 if (f
== "") // Try for a GIF instead
1935 strcpy(buf
, filename
);
1936 StripExtension(buf
);
1937 strcat(buf
, ".gif");
1938 f
= TexPathList
.FindValidPath(buf
);
1941 if (f
== "") // Try for a JPEG instead
1943 strcpy(buf
, filename
);
1944 StripExtension(buf
);
1945 strcat(buf
, ".jpg");
1946 f
= TexPathList
.FindValidPath(buf
);
1949 if (f
== "") // Try for a PNG instead
1951 strcpy(buf
, filename
);
1952 StripExtension(buf
);
1953 strcat(buf
, ".png");
1954 f
= TexPathList
.FindValidPath(buf
);
1959 char *inlineFilename
= copystring(f
);
1961 char *originalFilename
= TexPathList
.FindValidPath(filename
);
1962 // If we have found the existing filename, make the inline
1963 // image point to the original file (could be PS, for example)
1964 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
1966 TexOutput("<A HREF=\"");
1967 TexOutput(ConvertCase(originalFilename
));
1969 TexOutput("<img src=\"");
1970 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1971 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1976 TexOutput("<img src=\"");
1977 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1978 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1979 delete[] inlineFilename
;
1984 // Last resort - a link to a PS file.
1985 TexOutput("<A HREF=\"");
1986 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
1987 TexOutput("\">Picture</A>\n");
1988 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
1996 // First arg is PSBOX spec (ignored), second is image file, third is map name.
1999 static char *imageFile
= NULL
;
2000 if (start
&& (arg_no
== 2))
2002 // Try to find an XBM or GIF image first.
2003 char *filename
= copystring(GetArgData());
2006 strcpy(buf
, filename
);
2007 StripExtension(buf
);
2008 strcat(buf
, ".xbm");
2009 wxString f
= TexPathList
.FindValidPath(buf
);
2011 if (f
== "") // Try for a GIF instead
2013 strcpy(buf
, filename
);
2014 StripExtension(buf
);
2015 strcat(buf
, ".gif");
2016 f
= TexPathList
.FindValidPath(buf
);
2021 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2030 imageFile
= copystring(f
);
2033 else if (start
&& (arg_no
== 3))
2037 // First, try to find a .shg (segmented hypergraphics file)
2038 // that we can convert to a map file
2040 strcpy(buf
, imageFile
);
2041 StripExtension(buf
);
2042 strcat(buf
, ".shg");
2043 wxString f
= TexPathList
.FindValidPath(buf
);
2047 // The default HTML file to go to is THIS file (so a no-op)
2048 SHGToMap((char*) (const char*) f
, currentFileName
);
2051 char *mapName
= GetArgData();
2052 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2056 TexOutput("unknown");
2058 TexOutput("<img src=\"");
2059 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2060 TexOutput("\" ISMAP></A><P>");
2081 descriptionItemArg
= GetArgChunk();
2086 case ltTWOCOLITEMRULED
:
2089 if (start && (arg_no == 1))
2090 TexOutput("\n<DT> ");
2091 if (start && (arg_no == 2))
2097 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2099 TexOutput("\n</TD>\n");
2104 TexOutput("\n<TD VALIGN=TOP>\n");
2106 TexOutput("\n</TD></TR>\n");
2111 case ltNUMBEREDBIBITEM
:
2113 if (arg_no
== 1 && start
)
2115 TexOutput("\n<DT> ");
2117 if (arg_no
== 2 && !start
)
2124 if (arg_no
== 1 && start
)
2126 char *citeKey
= GetArgData();
2127 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2130 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2131 sprintf(buf
, "[%d]", citeCount
);
2132 ref
->sectionNumber
= copystring(buf
);
2135 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2140 if (arg_no
== 2 && !start
)
2146 case ltMARGINPARODD
:
2147 case ltMARGINPAREVEN
:
2153 TexOutput("<HR>\n");
2157 TexOutput("<HR><P>\n");
2164 case ltACCENT_GRAVE
:
2168 char *val
= GetArgData();
2174 TexOutput("à");
2177 TexOutput("è");
2180 TexOutput("ì");
2183 TexOutput("ò");
2186 TexOutput("ù");
2189 TexOutput("À");
2192 TexOutput("È");
2195 TexOutput("Ì");
2198 TexOutput("Ò");
2201 TexOutput("Ì");
2211 case ltACCENT_ACUTE
:
2215 char *val
= GetArgData();
2221 TexOutput("á");
2224 TexOutput("é");
2227 TexOutput("í");
2230 TexOutput("ó");
2233 TexOutput("ú");
2236 TexOutput("ý");
2239 TexOutput("Á");
2242 TexOutput("É");
2245 TexOutput("Í");
2248 TexOutput("Ó");
2251 TexOutput("Ú");
2254 TexOutput("Ý");
2264 case ltACCENT_CARET
:
2268 char *val
= GetArgData();
2274 TexOutput("â");
2277 TexOutput("ê");
2280 TexOutput("î");
2283 TexOutput("ô");
2286 TexOutput("û");
2289 TexOutput("Â");
2292 TexOutput("Ê");
2295 TexOutput("Î");
2298 TexOutput("Ô");
2301 TexOutput("Î");
2311 case ltACCENT_TILDE
:
2315 char *val
= GetArgData();
2324 TexOutput("ã");
2327 TexOutput("ñ");
2330 TexOutput("õ");
2333 TexOutput("Ã");
2336 TexOutput("Ñ");
2339 TexOutput("Õ");
2349 case ltACCENT_UMLAUT
:
2353 char *val
= GetArgData();
2359 TexOutput("ä");
2362 TexOutput("ë");
2365 TexOutput("ï");
2368 TexOutput("ö");
2371 TexOutput("ü");
2374 TexOutput("ÿ");
2377 TexOutput("Ä");
2380 TexOutput("Ë");
2383 TexOutput("Ï");
2386 TexOutput("Ö");
2389 TexOutput("Ü");
2392 TexOutput("Ÿ");
2406 char *val
= GetArgData();
2412 TexOutput("å");
2415 TexOutput("Å");
2429 char *val
= GetArgData();
2432 bool isPicture
= FALSE
;
2433 char *s
= ParseColourString(val
, &isPicture
);
2436 if (backgroundImageString
)
2437 delete[] backgroundImageString
;
2438 backgroundImageString
= copystring(val
);
2442 if (backgroundColourString
)
2443 delete[] backgroundColourString
;
2444 backgroundColourString
= copystring(val
);
2451 case ltBACKGROUNDIMAGE
:
2455 char *val
= GetArgData();
2458 if (backgroundImageString
)
2459 delete[] backgroundImageString
;
2460 backgroundImageString
= copystring(val
);
2466 case ltBACKGROUNDCOLOUR
:
2470 char *val
= GetArgData();
2473 if (backgroundColourString
)
2474 delete[] backgroundColourString
;
2475 backgroundColourString
= copystring(val
);
2485 char *val
= GetArgData();
2488 if (textColourString
)
2489 delete[] textColourString
;
2490 textColourString
= copystring(val
);
2500 char *val
= GetArgData();
2503 if (linkColourString
)
2504 delete[] linkColourString
;
2505 linkColourString
= copystring(val
);
2511 case ltFOLLOWEDLINKCOLOUR
:
2515 char *val
= GetArgData();
2518 if (followedLinkColourString
)
2519 delete[] followedLinkColourString
;
2520 followedLinkColourString
= copystring(val
);
2526 case ltACCENT_CADILLA
:
2530 char *val
= GetArgData();
2536 TexOutput("ç");
2539 TexOutput("Ç");
2551 case ltFOOTNOTEPOPUP:
2561 case ltSUPERTABULAR
:
2567 currentRowNumber
= 0;
2570 tableVerticalLineLeft
= FALSE
;
2571 tableVerticalLineRight
= FALSE
;
2572 int currentWidth
= 0;
2574 char *alignString
= copystring(GetArgData());
2575 ParseTableArgument(alignString
);
2577 TexOutput("<TABLE BORDER>\n");
2579 // Write the first row formatting for compatibility
2580 // with standard Latex
2581 if (compatibilityMode
)
2583 TexOutput("<TR>\n<TD>");
2585 for (int i = 0; i < noColumns; i++)
2587 currentWidth += TableData[i].width;
2588 sprintf(buf, "\\cellx%d", currentWidth);
2591 TexOutput("\\pard\\intbl\n");
2594 delete[] alignString
;
2599 else if (arg_no
== 2 && !start
)
2601 TexOutput("</TABLE>\n");
2606 case ltTHEBIBLIOGRAPHY
:
2608 if (start
&& (arg_no
== 1))
2610 ReopenFile(&Chapters
, &ChaptersName
);
2611 AddTexRef("bibliography", ChaptersName
, "bibliography");
2612 SetCurrentSubsectionName("bibliography", ChaptersName
);
2616 SetCurrentOutput(Chapters
);
2619 if (truncateFilenames
)
2620 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2622 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2624 TexOutput("<head><title>");
2625 TexOutput(ReferencesNameString
);
2626 TexOutput("</title></head>\n");
2629 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2630 AddBrowseButtons("contents", titleBuf
, // Up
2631 lastTopic
, lastFileName
, // Last topic
2632 "bibliography", ChaptersName
); // This topic
2634 SetCurrentOutputs(Contents
, Chapters
);
2635 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2637 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2638 fprintf(Chapters
, "</H2>\n</A>\n");
2640 SetCurrentOutput(Chapters
);
2643 if (!start
&& (arg_no
== 2))
2651 /* Build up list of keywords associated with topics */
2654 // char *entry = GetArgData();
2656 OutputChunkToString(GetArgChunk(), buf
);
2659 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2674 char *name
= GetArgData();
2676 if (!FindColourHTMLString(name
, buf2
))
2678 strcpy(buf2
, "#000000");
2680 sprintf(buf
, "Could not find colour name %s", name
);
2683 TexOutput("<FONT COLOR=\"");
2699 if (arg_no
== 2) TexOutput("</FONT>");
2704 case ltINSERTATLEVEL
:
2706 // This macro allows you to insert text at a different level
2707 // from the current level, e.g. into the Sections from within a subsubsection.
2710 static int currentLevelNo
= 1;
2711 static FILE* oldLevelFile
= Chapters
;
2718 oldLevelFile
= CurrentOutput1
;
2720 char *str
= GetArgData();
2721 currentLevelNo
= atoi(str
);
2723 // TODO: cope with article style (no chapters)
2724 switch (currentLevelNo
)
2728 outputFile
= Chapters
;
2733 outputFile
= Sections
;
2738 outputFile
= Subsections
;
2743 outputFile
= Subsubsections
;
2753 CurrentOutput1
= outputFile
;
2771 CurrentOutput1
= oldLevelFile
;
2777 return DefaultOnArgument(macroId
, arg_no
, start
);
2790 tableVerticalLineLeft
= FALSE
;
2791 tableVerticalLineRight
= FALSE
;
2794 if (InputFile
&& OutputFile
)
2796 // Do some HTML-specific transformations on all the strings,
2798 Text2HTML(GetTopLevelChunk());
2801 if (truncateFilenames
)
2802 sprintf(buf
, "%s.htm", FileRoot
);
2804 sprintf(buf
, "%s_contents.html", FileRoot
);
2805 if (TitlepageName
) delete[] TitlepageName
;
2806 TitlepageName
= copystring(buf
);
2807 Titlepage
= fopen(buf
, "w");
2809 if (truncateFilenames
)
2810 sprintf(buf
, "%s_fc.htm", FileRoot
);
2812 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2814 contentsFrameName
= copystring(buf
);
2816 Contents
= fopen(TmpContentsName
, "w");
2818 if (htmlFrameContents
)
2820 // FrameContents = fopen(TmpFrameContentsName, "w");
2821 FrameContents
= fopen(contentsFrameName
, "w");
2822 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2825 if (!Titlepage
|| !Contents
)
2827 OnError("Cannot open output file!");
2830 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2832 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2834 fprintf(Contents
, "<UL>\n");
2836 SetCurrentOutput(Titlepage
);
2837 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2838 OnInform("Converting...");
2841 fprintf(Contents
, "</UL>\n\n");
2843 // SetCurrentOutput(Titlepage);
2848 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2855 fprintf(FrameContents
, "\n</UL>\n");
2856 fprintf(FrameContents
, "</HTML>\n");
2857 fclose(FrameContents
);
2858 FrameContents
= NULL
;
2863 fprintf(Chapters
, "\n</BODY></HTML>\n");
2869 fprintf(Sections
, "\n</BODY></HTML>\n");
2873 if (Subsections
&& !combineSubSections
)
2875 fprintf(Subsections
, "\n</BODY></HTML>\n");
2876 fclose(Subsections
);
2879 if (Subsubsections
&& !combineSubSections
)
2881 fprintf(Subsubsections
, "\n</BODY></HTML>\n");
2882 fclose(Subsubsections
);
2883 Subsubsections
= NULL
;
2885 if ( SectionContentsFD
)
2887 fclose(SectionContentsFD
);
2888 SectionContentsFD
= NULL
;
2891 // Create a temporary file for the title page header, add some info,
2892 // and concat the titlepage just generated.
2893 // This is necessary in order to put the title of the document
2894 // at the TOP of the file within <HEAD>, even though we only find out
2895 // what it is later on.
2896 FILE *tmpTitle
= fopen("title.tmp", "w");
2901 SetCurrentOutput(tmpTitle
);
2902 TexOutput("\n<HTML>\n<HEAD><TITLE>");
2903 TraverseChildrenFromChunk(DocumentTitle
);
2904 TexOutput("</TITLE></HEAD>\n");
2908 SetCurrentOutput(tmpTitle
);
2910 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
2912 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
2915 // Output frame information
2916 if (htmlFrameContents
)
2918 char firstFileName
[300];
2919 if (truncateFilenames
)
2920 sprintf(firstFileName
, "%s1.htm", FileRoot
);
2922 sprintf(firstFileName
, "%s1.html", FileRoot
);
2924 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
2926 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
2927 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
2928 fprintf(tmpTitle
, "</FRAMESET>\n");
2930 fprintf(tmpTitle
, "<NOFRAMES>\n");
2933 // Output <BODY...> to temporary title page
2937 FILE *fd
= fopen(TitlepageName
, "r");
2949 fprintf(tmpTitle
, "\n</BODY>\n");
2951 if (htmlFrameContents
)
2953 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
2955 fprintf(tmpTitle
, "\n</HTML>\n");
2958 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
2959 if (!wxRenameFile("title.tmp", TitlepageName
))
2961 wxCopyFile("title.tmp", TitlepageName
);
2962 wxRemoveFile("title.tmp");
2966 if (lastFileName
) delete[] lastFileName
;
2967 lastFileName
= NULL
;
2968 if (lastTopic
) delete[] lastTopic
;
2971 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
2973 if (!wxRenameFile(TmpContentsName
, ContentsName
))
2975 wxCopyFile(TmpContentsName
, ContentsName
);
2976 wxRemoveFile(TmpContentsName
);
2979 // Generate .htx file if requested
2982 char htmlIndexName
[300];
2983 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
2984 GenerateHTMLIndexFile(htmlIndexName
);
2987 // Generate HTML Help Workshop files if requested
2988 if (htmlWorkshopFiles
)
2990 HTMLWorkshopEndContents();
2991 GenerateHTMLWorkshopFiles(FileRoot
);
3001 // Output .htx index file
3002 void GenerateHTMLIndexFile(char *fname
)
3004 FILE *fd
= fopen(fname
, "w");
3008 TopicTable
.BeginFind();
3009 wxNode
*node
= NULL
;
3010 while ((node
= TopicTable
.Next()))
3012 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3013 const char *topicName
= node
->GetKeyString();
3014 if (texTopic
->filename
&& texTopic
->keywords
)
3016 wxNode
*node1
= texTopic
->keywords
->First();
3019 char *s
= (char *)node1
->Data();
3020 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3021 node1
= node1
->Next();
3034 // output .hpp, .hhc and .hhk files:
3037 void GenerateHTMLWorkshopFiles(char *fname
)
3042 /* Generate project file : */
3044 sprintf(buf
, "%s.hhp", fname
);
3045 f
= fopen(buf
, "wt");
3048 "Compatibility=1.1\n"
3049 "Full-text search=Yes\n"
3050 "Contents file=%s.hhc\n"
3051 "Compiled file=%s.chm\n"
3052 "Default Window=%sHelp\n"
3053 "Default topic=%s\n"
3054 "Index file=%s.hhk\n"
3056 FileNameFromPath(fname
),
3057 FileNameFromPath(fname
),
3058 FileNameFromPath(fname
),
3059 FileNameFromPath(TitlepageName
),
3060 FileNameFromPath(fname
)
3063 if (DocumentTitle
) {
3064 SetCurrentOutput(f
);
3065 TraverseChildrenFromChunk(DocumentTitle
);
3067 else fprintf(f
, "(unknown)");
3069 fprintf(f
, "\n\n[WINDOWS]\n"
3070 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3071 FileNameFromPath(fname
),
3072 FileNameFromPath(fname
),
3073 FileNameFromPath(fname
),
3074 FileNameFromPath(TitlepageName
));
3077 fprintf(f
, "\n\n[FILES]\n");
3078 fprintf(f
, "%s\n", FileNameFromPath(TitlepageName
));
3079 for (int i
= 1; i
<= fileId
; i
++) {
3080 if (truncateFilenames
)
3081 sprintf(buf
, "%s%d.htm", FileNameFromPath(FileRoot
), i
);
3083 sprintf(buf
, "%s%d.html", FileNameFromPath(FileRoot
), i
);
3084 fprintf(f
, "%s\n", buf
);
3088 /* Generate index file : */
3090 sprintf(buf
, "%s.hhk", fname
);
3091 f
= fopen(buf
, "wt");
3094 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3097 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3098 "<!-- Sitemap 1.0 -->\n"
3100 "<OBJECT type=\"text/site properties\">\n"
3101 " <param name=\"ImageType\" value=\"Folder\">\n"
3105 TopicTable
.BeginFind();
3106 wxNode
*node
= NULL
;
3107 while ((node
= TopicTable
.Next()))
3109 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3110 const char *topicName
= node
->GetKeyString();
3111 if (texTopic
->filename
&& texTopic
->keywords
)
3113 wxNode
*node1
= texTopic
->keywords
->First();
3116 char *s
= (char *)node1
->Data();
3118 " <LI> <OBJECT type=\"text/sitemap\">\n"
3119 " <param name=\"Local\" value=\"%s#%s\">\n"
3120 " <param name=\"Name\" value=\"%s\">\n"
3122 texTopic
->filename
, topicName
, s
);
3123 node1
= node1
->Next();
3128 fprintf(f
, "</UL>\n");
3134 static FILE *HTMLWorkshopContents
= NULL
;
3135 static int HTMLWorkshopLastLevel
= 0;
3137 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3141 if (level
> HTMLWorkshopLastLevel
)
3142 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3143 fprintf(HTMLWorkshopContents
, "<UL>");
3144 if (level
< HTMLWorkshopLastLevel
)
3145 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3146 fprintf(HTMLWorkshopContents
, "</UL>");
3148 SetCurrentOutput(HTMLWorkshopContents
);
3149 fprintf(HTMLWorkshopContents
,
3150 " <LI> <OBJECT type=\"text/sitemap\">\n"
3151 " <param name=\"Local\" value=\"%s#%s\">\n"
3152 " <param name=\"Name\" value=\"",
3154 OutputCurrentSection();
3155 fprintf(HTMLWorkshopContents
,
3158 HTMLWorkshopLastLevel
= level
;
3162 void HTMLWorkshopStartContents()
3165 sprintf(buf
, "%s.hhc", FileRoot
);
3166 HTMLWorkshopContents
= fopen(buf
, "wt");
3167 HTMLWorkshopLastLevel
= 0;
3169 fprintf(HTMLWorkshopContents
,
3170 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3173 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3174 "<!-- Sitemap 1.0 -->\n"
3176 "<OBJECT type=\"text/site properties\">\n"
3177 " <param name=\"ImageType\" value=\"Folder\">\n"
3180 "<LI> <OBJECT type=\"text/sitemap\">\n"
3181 "<param name=\"Local\" value=\"%s\">\n"
3182 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3183 FileNameFromPath(TitlepageName
)
3189 void HTMLWorkshopEndContents()
3191 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3192 fprintf(HTMLWorkshopContents
, "</UL>\n");
3193 fclose(HTMLWorkshopContents
);