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 // DHS Two-column table dimensions.
84 static int TwoColWidthA
= -1;
85 static int TwoColWidthB
= -1;
88 class HyperReference
: public wxObject
93 HyperReference(char *name
, char *file
)
95 if (name
) refName
= copystring(name
);
96 if (file
) refFile
= copystring(file
);
100 class TexNextPage
: public wxObject
105 TexNextPage(char *theLabel
, char *theFile
)
107 label
= copystring(theLabel
);
108 filename
= copystring(theFile
);
117 wxHashTable
TexNextPages(wxKEY_STRING
);
119 static char *CurrentChapterName
= NULL
;
120 static char *CurrentChapterFile
= NULL
;
121 static char *CurrentSectionName
= NULL
;
122 static char *CurrentSectionFile
= NULL
;
123 static char *CurrentSubsectionName
= NULL
;
124 static char *CurrentSubsectionFile
= NULL
;
125 static char *CurrentSubsubsectionName
= NULL
;
126 static char *CurrentSubsubsectionFile
= NULL
;
127 static char *CurrentTopic
= NULL
;
129 static void SetCurrentTopic(char *s
)
131 if (CurrentTopic
) delete[] CurrentTopic
;
132 CurrentTopic
= copystring(s
);
135 void SetCurrentChapterName(char *s
, char *file
)
137 if (CurrentChapterName
) delete[] CurrentChapterName
;
138 CurrentChapterName
= copystring(s
);
139 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
140 CurrentChapterFile
= copystring(file
);
142 currentFileName
= CurrentChapterFile
;
146 void SetCurrentSectionName(char *s
, char *file
)
148 if (CurrentSectionName
) delete[] CurrentSectionName
;
149 CurrentSectionName
= copystring(s
);
150 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
151 CurrentSectionFile
= copystring(file
);
153 currentFileName
= CurrentSectionFile
;
156 void SetCurrentSubsectionName(char *s
, char *file
)
158 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
159 CurrentSubsectionName
= copystring(s
);
160 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
161 CurrentSubsectionFile
= copystring(file
);
162 currentFileName
= CurrentSubsectionFile
;
165 void SetCurrentSubsubsectionName(char *s
, char *file
)
167 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
168 CurrentSubsubsectionName
= copystring(s
);
169 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
170 CurrentSubsubsectionFile
= copystring(file
);
171 currentFileName
= CurrentSubsubsectionFile
;
176 * Close former filedescriptor and reopen using another filename.
180 void ReopenFile(FILE **fd
, char **fileName
)
184 fprintf(*fd
, "\n</BODY></HTML>\n");
189 if (truncateFilenames
)
190 sprintf(buf
, "%s%d.htm", FileRoot
, fileId
);
192 sprintf(buf
, "%s%d.html", FileRoot
, fileId
);
193 if (*fileName
) delete[] *fileName
;
194 *fileName
= copystring(FileNameFromPath(buf
));
195 *fd
= fopen(buf
, "w");
196 fprintf(*fd
, "<HTML>\n");
200 * Reopen section contents file, i.e. the index appended to each section
201 * in subsectionCombine mode
204 static char *SectionContentsFilename
= NULL
;
205 static FILE *SectionContentsFD
= NULL
;
207 void ReopenSectionContentsFile(void)
209 if ( SectionContentsFD
)
211 fclose(SectionContentsFD
);
213 if ( SectionContentsFilename
)
214 delete[] SectionContentsFilename
;
215 SectionContentsFD
= NULL
;
216 SectionContentsFilename
= NULL
;
218 // Create the name from the current section filename
219 if ( CurrentSectionFile
)
222 strcpy(buf
, CurrentSectionFile
);
223 wxStripExtension(buf
);
225 SectionContentsFilename
= copystring(buf
);
227 SectionContentsFD
= fopen(SectionContentsFilename
, "w");
233 * Given a TexChunk with a string value, scans through the string
234 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
238 void ProcessText2HTML(TexChunk
*chunk
)
240 bool changed
= FALSE
;
244 int len
= strlen(chunk
->value
);
247 ch
= chunk
->value
[i
];
249 // 2 newlines means \par
250 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
251 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
252 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
254 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "<P>\n\n"); ptr
+= 5;
258 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
260 BigBuffer
[ptr
] = '"'; ptr
++;
264 else if (!inVerbatim
&& ch
== '`') // Change ` to '
266 BigBuffer
[ptr
] = 39; ptr
++;
270 else if (ch
== '<') // Change < to <
273 strcat(BigBuffer
, "<");
278 else if (ch
== '>') // Change > to >
281 strcat(BigBuffer
, ">");
298 chunk
->value
= copystring(BigBuffer
);
303 * Scan through all chunks starting from the given one,
304 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
305 * This should be called after Tex2Any has parsed the file,
306 * and before TraverseDocument is called.
310 void Text2HTML(TexChunk
*chunk
)
313 if (stopRunning
) return;
317 case CHUNK_TYPE_MACRO
:
319 TexMacroDef
*def
= chunk
->def
;
321 if (def
&& def
->ignore
)
324 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
327 wxNode
*node
= chunk
->children
.First();
330 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
331 Text2HTML(child_chunk
);
335 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
342 wxNode
*node
= chunk
->children
.First();
345 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
346 Text2HTML(child_chunk
);
352 case CHUNK_TYPE_STRING
:
355 ProcessText2HTML(chunk
);
362 * Add appropriate browse buttons to this page.
366 void AddBrowseButtons(char *upLabel
, char *upFilename
,
367 char *previousLabel
, char *previousFilename
,
368 char *thisLabel
, char *thisFilename
)
370 char contentsReferenceBuf
[80];
371 char upReferenceBuf
[80];
372 char backReferenceBuf
[80];
373 char forwardReferenceBuf
[80];
374 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
377 char *contentsReference
= NULL
;
378 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
379 contentsReference
= ContentsNameString
;
382 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
383 contentsReference
= contentsReferenceBuf
;
384 sprintf(contentsReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">", ConvertCase("contents.gif"));
387 char *upReference
= NULL
;
388 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
389 upReference
= UpNameString
;
392 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
393 upReference
= upReferenceBuf
;
394 sprintf(upReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">", ConvertCase("up.gif"));
397 char *backReference
= NULL
;
398 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
399 backReference
= "<<";
402 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
403 backReference
= backReferenceBuf
;
404 sprintf(backReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">", ConvertCase("back.gif"));
407 char *forwardReference
= NULL
;
408 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
409 forwardReference
= ">>";
412 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
413 forwardReference
= forwardReferenceBuf
;
414 sprintf(forwardReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">", ConvertCase("forward.gif"));
417 TexOutput("<CENTER>");
426 if (truncateFilenames
)
429 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
430 sprintf(buf
, "\n<A HREF=\"%s.%s\">%s</A> ", buf1
, ConvertCase("htm"), contentsReference
);
435 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
436 sprintf(buf
, "\n<A HREF=\"%s%s\">%s</A> ", buf1
, ConvertCase("_contents.html"), contentsReference
);
438 // TexOutput("<NOFRAMES>");
440 // TexOutput("</NOFRAMES>");
447 if (upLabel
&& upFilename
)
449 if (strlen(upLabel
) > 0)
450 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(upFilename
), upLabel
, upReference
);
452 sprintf(buf
, "<A HREF=\"%s\">%s</A> ", ConvertCase(upFilename
), upReference
);
453 if (strcmp(upLabel
, "contents") == 0)
455 // TexOutput("<NOFRAMES>");
457 // TexOutput("</NOFRAMES>");
468 if (previousLabel
&& previousFilename
)
470 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(previousFilename
), previousLabel
, backReference
);
471 if (strcmp(previousLabel
, "contents") == 0)
473 // TexOutput("<NOFRAMES>");
475 // TexOutput("</NOFRAMES>");
482 // A placeholder so the buttons don't keep moving position
483 sprintf(buf
, "%s ", backReference
);
487 char *nextLabel
= NULL
;
488 char *nextFilename
= NULL
;
490 // Get the next page, and record the previous page's 'next' page
492 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
495 nextLabel
= nextPage
->label
;
496 nextFilename
= nextPage
->filename
;
498 if (previousLabel
&& previousFilename
)
500 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
504 TexNextPages
.Delete(previousLabel
);
506 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
507 TexNextPages
.Put(previousLabel
, newNextPage
);
515 if (nextLabel
&& nextFilename
)
517 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(nextFilename
), nextLabel
, forwardReference
);
522 // A placeholder so the buttons don't keep moving position
523 sprintf(buf
, "%s ", forwardReference
);
528 * Horizontal rule to finish it off nicely.
531 TexOutput("</CENTER>");
534 // Update last topic/filename
536 delete[] lastFileName
;
537 lastFileName
= copystring(thisFilename
);
540 lastTopic
= copystring(thisLabel
);
543 // A colour string is either 3 numbers separated by semicolons (RGB),
544 // or a reference to a GIF. Return the filename or a hex string like #934CE8
545 char *ParseColourString(char *bkStr
, bool *isPicture
)
547 static char resStr
[300];
548 strcpy(resStr
, bkStr
);
549 char *tok1
= strtok(resStr
, ";");
550 char *tok2
= strtok(NULL
, ";");
561 char *tok3
= strtok(NULL
, ";");
564 // Now convert 3 strings into decimal numbers, and then hex numbers.
565 int red
= atoi(tok1
);
566 int green
= atoi(tok2
);
567 int blue
= atoi(tok3
);
574 DecToHex(green
, buf
);
586 // Output start of <BODY> block
587 void OutputBodyStart(void)
589 TexOutput("\n<BODY");
590 if (backgroundImageString
)
592 bool isPicture
= FALSE
;
593 char *s
= ParseColourString(backgroundImageString
, &isPicture
);
596 TexOutput(" BACKGROUND=\""); TexOutput(s
); TexOutput("\"");
599 if (backgroundColourString
)
601 bool isPicture
= FALSE
;
602 char *s
= ParseColourString(backgroundColourString
, &isPicture
);
605 TexOutput(" BGCOLOR="); TexOutput(s
);
609 // Set foreground text colour, if one is specified
610 if (textColourString
)
612 bool isPicture
= FALSE
;
613 char *s
= ParseColourString(textColourString
, &isPicture
);
616 TexOutput(" TEXT="); TexOutput(s
);
619 // Set link text colour, if one is specified
620 if (linkColourString
)
622 bool isPicture
= FALSE
;
623 char *s
= ParseColourString(linkColourString
, &isPicture
);
626 TexOutput(" LINK="); TexOutput(s
);
629 // Set followed link text colour, if one is specified
630 if (followedLinkColourString
)
632 bool isPicture
= FALSE
;
633 char *s
= ParseColourString(followedLinkColourString
, &isPicture
);
636 TexOutput(" VLINK="); TexOutput(s
);
642 // Called on start/end of macro examination
643 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
649 case ltCHAPTERHEADING
:
657 if (macroId
!= ltCHAPTERSTAR
)
660 SetCurrentOutput(NULL
);
661 startedSections
= TRUE
;
663 char *topicName
= FindTopicName(GetNextChunk());
664 ReopenFile(&Chapters
, &ChaptersName
);
665 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
667 SetCurrentChapterName(topicName
, ChaptersName
);
668 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
670 SetCurrentOutput(Chapters
);
672 TexOutput("<head><title>");
673 OutputCurrentSection(); // Repeat section header
674 TexOutput("</title></head>\n");
678 if (truncateFilenames
)
679 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
681 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
683 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
685 AddBrowseButtons("", titleBuf
, // Up
686 lastTopic
, lastFileName
, // Last topic
687 topicName
, ChaptersName
); // This topic
689 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
691 if (htmlFrameContents
&& FrameContents
)
693 SetCurrentOutput(FrameContents
);
694 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
695 OutputCurrentSection();
696 fprintf(FrameContents
, "</A>\n");
699 SetCurrentOutputs(Contents
, Chapters
);
700 fprintf(Chapters
, "\n<H2>");
701 OutputCurrentSection();
702 fprintf(Contents
, "</A>\n");
703 fprintf(Chapters
, "</H2>\n");
705 SetCurrentOutput(Chapters
);
707 // Add this section title to the list of keywords
710 OutputCurrentSectionToString(wxBuffer
);
711 AddKeyWordForTopic(topicName
, wxBuffer
, ConvertCase(currentFileName
));
718 case ltSECTIONHEADING
:
725 subsectionStarted
= FALSE
;
727 if (macroId
!= ltSECTIONSTAR
)
730 SetCurrentOutput(NULL
);
731 startedSections
= TRUE
;
733 char *topicName
= FindTopicName(GetNextChunk());
734 ReopenFile(&Sections
, &SectionsName
);
735 AddTexRef(topicName
, SectionsName
, SectionNameString
);
737 SetCurrentSectionName(topicName
, SectionsName
);
738 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
740 SetCurrentOutput(Sections
);
741 TexOutput("<head><title>");
742 OutputCurrentSection();
743 TexOutput("</title></head>\n");
746 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
747 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
748 lastTopic
, lastFileName
, // Last topic
749 topicName
, SectionsName
); // This topic
751 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
753 SetCurrentOutputs(jumpFrom
, Sections
);
754 if (DocumentStyle
== LATEX_ARTICLE
)
755 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
757 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
759 fprintf(Sections
, "\n<H2>");
760 OutputCurrentSection();
762 if (DocumentStyle
== LATEX_ARTICLE
)
763 fprintf(jumpFrom
, "</A>\n");
765 fprintf(jumpFrom
, "</B></A><BR>\n");
766 fprintf(Sections
, "</H2>\n");
768 SetCurrentOutput(Sections
);
769 // Add this section title to the list of keywords
772 OutputCurrentSectionToString(wxBuffer
);
773 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
779 case ltSUBSECTIONSTAR
:
780 case ltMEMBERSECTION
:
781 case ltFUNCTIONSECTION
:
787 OnError("You cannot have a subsection before a section!");
793 if (macroId
!= ltSUBSECTIONSTAR
)
796 if ( combineSubSections
&& !subsectionStarted
)
798 // Read old .con file in at this point
800 strcpy(buf
, CurrentSectionFile
);
801 wxStripExtension(buf
);
803 FILE *fd
= fopen(buf
, "r");
814 fprintf(Sections
, "<P>\n");
816 // Close old file, create a new file for the sub(sub)section contents entries
817 ReopenSectionContentsFile();
820 startedSections
= TRUE
;
821 subsectionStarted
= TRUE
;
823 char *topicName
= FindTopicName(GetNextChunk());
825 if ( !combineSubSections
)
827 SetCurrentOutput(NULL
);
828 ReopenFile(&Subsections
, &SubsectionsName
);
829 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
830 SetCurrentSubsectionName(topicName
, SubsectionsName
);
831 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
832 SetCurrentOutput(Subsections
);
834 TexOutput("<head><title>");
835 OutputCurrentSection();
836 TexOutput("</title></head>\n");
839 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
840 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
841 lastTopic
, lastFileName
, // Last topic
842 topicName
, SubsectionsName
); // This topic
844 SetCurrentOutputs(Sections
, Subsections
);
845 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
847 fprintf(Subsections
, "\n<H3>");
848 OutputCurrentSection();
849 fprintf(Sections
, "</B></A><BR>\n");
850 fprintf(Subsections
, "</H3>\n");
852 SetCurrentOutput(Subsections
);
856 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
857 SetCurrentSubsectionName(topicName
, SectionsName
);
859 // if ( subsectionNo != 0 )
860 fprintf(Sections
, "\n<HR>\n");
862 // We're putting everything into the section file
863 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
864 fprintf(Sections
, "\n<H3>");
865 OutputCurrentSection();
866 fprintf(Sections
, "</H3>\n");
868 SetCurrentOutput(SectionContentsFD
);
869 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
870 OutputCurrentSection();
871 TexOutput("</A><BR>\n");
873 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
874 SetCurrentOutput(Sections
);
876 // Add this section title to the list of keywords
879 OutputCurrentSectionToString(wxBuffer
);
880 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
887 case ltSUBSUBSECTION
:
888 case ltSUBSUBSECTIONSTAR
:
892 if (!Subsections
&& !combineSubSections
)
894 OnError("You cannot have a subsubsection before a subsection!");
898 if (macroId
!= ltSUBSUBSECTIONSTAR
)
901 startedSections
= TRUE
;
903 char *topicName
= FindTopicName(GetNextChunk());
905 if ( !combineSubSections
)
907 SetCurrentOutput(NULL
);
908 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
909 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
910 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
911 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
913 SetCurrentOutput(Subsubsections
);
914 TexOutput("<head><title>");
915 OutputCurrentSection();
916 TexOutput("</title></head>\n");
919 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
921 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
922 lastTopic
, lastFileName
, // Last topic
923 topicName
, SubsubsectionsName
); // This topic
925 SetCurrentOutputs(Subsections
, Subsubsections
);
926 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
928 fprintf(Subsubsections
, "\n<H3>");
929 OutputCurrentSection();
930 fprintf(Subsections
, "</B></A><BR>\n");
931 fprintf(Subsubsections
, "</H3>\n");
935 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
936 SetCurrentSubsectionName(topicName
, SectionsName
);
937 fprintf(Sections
, "\n<HR>\n");
939 // We're putting everything into the section file
940 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
941 fprintf(Sections
, "\n<H3>");
942 OutputCurrentSection();
943 fprintf(Sections
, "</H3>\n");
944 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
945 SetCurrentOutput(SectionContentsFD);
946 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
947 OutputCurrentSection();
948 TexOutput("</A><BR>");
950 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
951 SetCurrentOutput(Sections
);
954 // Add this section title to the list of keywords
957 OutputCurrentSectionToString(wxBuffer
);
958 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
967 if ( !combineSubSections
)
968 SetCurrentOutput(Subsections
);
970 SetCurrentOutput(Sections
);
981 if ( !combineSubSections
)
982 SetCurrentOutput(Subsections
);
984 SetCurrentOutput(Sections
);
995 if ( !combineSubSections
)
996 SetCurrentOutput(Subsections
);
998 SetCurrentOutput(Sections
);
1009 // TexOutput("<B>void</B>");
1017 TexOutput("wxCLIPS");
1023 case ltSPECIALAMPERSAND
:
1029 // End cell, start cell
1032 // Start new row and cell, setting alignment for the first cell.
1033 if (currentColumn
< noColumns
)
1037 if (TableData
[currentColumn
].justification
== 'c')
1038 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1039 else if (TableData
[currentColumn
].justification
== 'r')
1040 sprintf(buf
, "\n<TD ALIGN=RIGHT>");
1041 else if (TableData
[currentColumn
].absWidth
)
1043 // Convert from points * 20 into pixels.
1044 int points
= TableData
[currentColumn
].width
/ 20;
1046 // Say the display is 100 DPI (dots/pixels per inch).
1047 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1048 int pixels
= (int)(points
* 100.0 / 72.0);
1049 sprintf(buf
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1052 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1060 case ltBACKSLASHCHAR
:
1066 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1067 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1068 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1069 TexOutput("</TR>\n");
1072 TexOutput("<BR>\n");
1083 // Start new row and cell, setting alignment for the first cell.
1085 if (TableData
[currentColumn
].justification
== 'c')
1086 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1087 else if (TableData
[currentColumn
].justification
== 'r')
1088 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1089 else if (TableData
[currentColumn
].absWidth
)
1091 // Convert from points * 20 into pixels.
1092 int points
= TableData
[currentColumn
].width
/ 20;
1094 // Say the display is 100 DPI (dots/pixels per inch).
1095 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1096 int pixels
= (int)(points
* 100.0 / 72.0);
1097 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1100 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1106 // Start new row and cell
1107 TexOutput("</TD>\n</TR>\n");
1111 // HTML-only: break until the end of the picture (both margins are clear).
1115 TexOutput("<BR CLEAR=ALL>");
1118 case ltRTFSP
: // Explicit space, RTF only
1120 case ltSPECIALTILDE
:
1134 TexOutput("<UL><UL>\n");
1136 TexOutput("</UL></UL>\n");
1142 // case ltTWOCOLLIST:
1149 if (macroId
== ltENUMERATE
)
1150 listType
= LATEX_ENUMERATE
;
1151 else if (macroId
== ltITEMIZE
)
1152 listType
= LATEX_ITEMIZE
;
1154 listType
= LATEX_DESCRIPTION
;
1156 itemizeStack
.Insert(new ItemizeStruc(listType
));
1160 TexOutput("<UL>\n");
1162 case LATEX_ENUMERATE
:
1163 TexOutput("<OL>\n");
1165 case LATEX_DESCRIPTION
:
1167 TexOutput("<DL>\n");
1174 if (itemizeStack
.First())
1176 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1177 switch (struc
->listType
)
1180 TexOutput("</UL>\n");
1182 case LATEX_ENUMERATE
:
1183 TexOutput("</OL>\n");
1185 case LATEX_DESCRIPTION
:
1187 TexOutput("</DL>\n");
1192 delete itemizeStack
.First();
1200 TexOutput("\n<TABLE>\n");
1202 TexOutput("\n</TABLE>\n");
1215 /* For footnotes we need to output the text at the bottom of the page and
1216 * insert a reference to it. Is it worth the trouble...
1218 case ltFOOTNOTEPOPUP:
1224 else TexOutput("</FN>");
1232 else TexOutput("</TT>");
1240 sprintf(buf
, "<PRE>\n");
1243 else TexOutput("</PRE>\n");
1251 TexOutput("<CENTER>");
1253 else TexOutput("</CENTER>");
1261 TexOutput("{\\ql ");
1263 else TexOutput("}\\par\\pard\n");
1272 TexOutput("{\\qr ");
1274 else TexOutput("}\\par\\pard\n");
1282 // Netscape extension
1283 TexOutput("<FONT SIZE=2>");
1285 else TexOutput("</FONT>");
1292 // Netscape extension
1293 TexOutput("<FONT SIZE=1>");
1295 else TexOutput("</FONT>");
1302 // Netscape extension
1303 TexOutput("<FONT SIZE=3>");
1305 else TexOutput("</FONT>");
1312 // Netscape extension
1313 TexOutput("<FONT SIZE=4>");
1315 else TexOutput("</FONT>");
1322 // Netscape extension
1323 TexOutput("<FONT SIZE=5>");
1325 else TexOutput("</FONT>");
1332 // Netscape extension
1333 TexOutput("<FONT SIZE=6>");
1335 else TexOutput("</FONT>");
1346 else TexOutput("</B>");
1357 else TexOutput("</I>");
1367 else TexOutput("</EM>");
1376 else TexOutput("</UL>");
1387 else TexOutput("</TT>");
1393 TexOutput("©", TRUE
);
1399 TexOutput("®", TRUE
);
1405 if (start
) TexOutput("<--");
1410 if (start
) TexOutput("<==");
1415 if (start
) TexOutput("-->");
1420 if (start
) TexOutput("==>");
1423 case ltLEFTRIGHTARROW
:
1425 if (start
) TexOutput("<-->");
1428 case ltLEFTRIGHTARROW2
:
1430 if (start
) TexOutput("<==>");
1443 wxNode
*node
= itemizeStack
.First();
1446 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1447 struc
->currentItem
+= 1;
1448 if (struc
->listType
== LATEX_DESCRIPTION
)
1450 if (descriptionItemArg
)
1453 TraverseChildrenFromChunk(descriptionItemArg
);
1455 descriptionItemArg
= NULL
;
1467 if (start
&& DocumentTitle
&& DocumentAuthor
)
1469 // Add a special label for the contents page.
1470 // TexOutput("<CENTER>\n");
1471 TexOutput("<A NAME=\"contents\">");
1472 TexOutput("<H2 ALIGN=CENTER>\n");
1473 TraverseChildrenFromChunk(DocumentTitle
);
1476 TexOutput("</A>\n");
1477 TexOutput("<P>\n\n");
1478 TexOutput("<H3 ALIGN=CENTER>");
1479 TraverseChildrenFromChunk(DocumentAuthor
);
1480 TexOutput("</H3><P>\n\n");
1483 TexOutput("<H3 ALIGN=CENTER>");
1484 TraverseChildrenFromChunk(DocumentDate
);
1485 TexOutput("</H3><P>\n\n");
1487 // TexOutput("\n</CENTER>\n");
1488 TexOutput("\n<P><HR><P>\n");
1491 // Now do optional frame contents page
1492 if (htmlFrameContents && FrameContents)
1494 SetCurrentOutput(FrameContents);
1496 // Add a special label for the contents page.
1497 TexOutput("<CENTER>\n");
1498 TexOutput("<H3>\n");
1499 TraverseChildrenFromChunk(DocumentTitle);
1502 TexOutput("</A>\n");
1503 TexOutput("<P>\n\n");
1505 TraverseChildrenFromChunk(DocumentAuthor);
1506 TexOutput("</H3><P>\n\n");
1510 TraverseChildrenFromChunk(DocumentDate);
1511 TexOutput("</H4><P>\n\n");
1513 TexOutput("\n</CENTER>\n");
1514 TexOutput("<P><HR><P>\n");
1516 SetCurrentOutput(Titlepage);
1529 helpRefFilename
= NULL
;
1534 case ltBIBLIOGRAPHY
:
1538 DefaultOnMacro(macroId
, no_args
, start
);
1542 DefaultOnMacro(macroId
, no_args
, start
);
1543 TexOutput("</DL>\n");
1551 TexOutput("<HR>\n");
1559 TexOutput("<HR>\n");
1563 case ltTABLEOFCONTENTS
:
1567 FILE *fd
= fopen(ContentsName
, "r");
1573 putc(ch
, Titlepage
);
1580 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1581 OnInform("Run Tex2RTF again to include contents page.");
1602 TexOutput("<BLOCKQUOTE>");
1604 TexOutput("</BLOCKQUOTE>");
1613 TexOutput("\n<CAPTION>");
1621 if (DocumentStyle
!= LATEX_ARTICLE
)
1622 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1624 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1630 if (DocumentStyle
!= LATEX_ARTICLE
)
1631 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1633 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1641 TexOutput("\n</CAPTION>\n");
1643 char *topicName
= FindTopicName(GetNextChunk());
1645 int n
= inFigure
? figureNo
: tableNo
;
1647 AddTexRef(topicName
, NULL
, NULL
,
1648 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1649 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1655 if (start
) TexOutput("ß");
1660 if (start
) inFigure
= TRUE
;
1661 else inFigure
= FALSE
;
1666 if (start
) inTable
= TRUE
;
1667 else inTable
= FALSE
;
1671 DefaultOnMacro(macroId
, no_args
, start
);
1676 // Called on start/end of argument examination
1677 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1683 case ltCHAPTERHEADING
:
1686 case ltSECTIONHEADING
:
1688 case ltSUBSECTIONSTAR
:
1689 case ltSUBSUBSECTION
:
1690 case ltSUBSUBSECTIONSTAR
:
1692 case ltMEMBERSECTION
:
1693 case ltFUNCTIONSECTION
:
1695 if (!start
&& (arg_no
== 1))
1696 currentSection
= GetArgChunk();
1702 if (start
&& (arg_no
== 1))
1705 if (!start
&& (arg_no
== 1))
1708 if (start
&& (arg_no
== 2))
1710 if (!suppressNameDecoration
) TexOutput("<B>");
1711 currentMember
= GetArgChunk();
1713 if (!start
&& (arg_no
== 2))
1715 if (!suppressNameDecoration
) TexOutput("</B>");
1718 if (start
&& (arg_no
== 3))
1720 if (!start
&& (arg_no
== 3))
1726 if (start
&& (arg_no
== 1))
1728 if (!start
&& (arg_no
== 1))
1731 if (start
&& (arg_no
== 2))
1733 if (!suppressNameDecoration
) TexOutput("( ");
1734 currentMember
= GetArgChunk();
1736 if (!start
&& (arg_no
== 2))
1740 if (!start
&& (arg_no
== 3))
1746 if (!start
&& (arg_no
== 1))
1749 if (start
&& (arg_no
== 2))
1751 if (!start
&& (arg_no
== 2))
1754 if (start
&& (arg_no
== 2))
1755 currentMember
= GetArgChunk();
1757 if (start
&& (arg_no
== 3))
1759 if (!start
&& (arg_no
== 3))
1765 if (start
&& (arg_no
== 1))
1767 if (!start
&& (arg_no
== 1))
1769 if (start
&& (arg_no
== 2))
1773 if (!start
&& (arg_no
== 2))
1781 if (start
&& (arg_no
== 1))
1783 if (!start
&& (arg_no
== 1))
1784 TexOutput("</B> "); // This is the difference from param - one space!
1785 if (start
&& (arg_no
== 2))
1789 if (!start
&& (arg_no
== 2))
1797 if (!start
&& (arg_no
== 1))
1800 if (start
&& (arg_no
== 2))
1801 currentMember
= GetArgChunk();
1810 char *refName
= GetArgData();
1813 TexRef
*texRef
= FindReference(refName
);
1816 sec
= texRef
->sectionNumber
;
1829 if (IsArgOptional())
1831 else if ((GetNoArgs() - arg_no
) == 1)
1834 helpRefText
= GetArgChunk();
1837 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1841 TexChunk
*ref
= GetArgChunk();
1842 TexOutput("<A HREF=\"");
1844 TraverseChildrenFromChunk(ref
);
1848 TraverseChildrenFromChunk(helpRefText
);
1859 if (IsArgOptional())
1862 helpRefFilename
= GetArgChunk();
1865 if ((GetNoArgs() - arg_no
) == 1)
1868 helpRefText
= GetArgChunk();
1871 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1875 char *refName
= GetArgData();
1876 char *refFilename
= NULL
;
1880 TexRef
*texRef
= FindReference(refName
);
1883 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1884 refFilename
= texRef
->refFile
;
1886 TexOutput("<A HREF=\"");
1887 // If a filename is supplied, use it, otherwise try to
1888 // use the filename associated with the reference (from this document).
1889 if (helpRefFilename
)
1891 TraverseChildrenFromChunk(helpRefFilename
);
1894 else if (refFilename
)
1896 TexOutput(ConvertCase(refFilename
));
1902 TraverseChildrenFromChunk(helpRefText
);
1908 TraverseChildrenFromChunk(helpRefText
);
1910 TexOutput(" (REF NOT FOUND)");
1912 errBuf
.Printf("Warning: unresolved reference '%s'", refName
);
1913 OnInform((char *)errBuf
.c_str());
1916 else TexOutput("??");
1931 char *alignment
= "";
1932 if (macroId
== ltIMAGEL
)
1933 alignment
= " align=left";
1934 else if (macroId
== ltIMAGER
)
1935 alignment
= " align=right";
1937 // Try to find an XBM or GIF image first.
1938 char *filename
= copystring(GetArgData());
1941 strcpy(buf
, filename
);
1942 StripExtension(buf
);
1943 strcat(buf
, ".xbm");
1944 wxString f
= TexPathList
.FindValidPath(buf
);
1946 if (f
== "") // Try for a GIF instead
1948 strcpy(buf
, filename
);
1949 StripExtension(buf
);
1950 strcat(buf
, ".gif");
1951 f
= TexPathList
.FindValidPath(buf
);
1954 if (f
== "") // Try for a JPEG instead
1956 strcpy(buf
, filename
);
1957 StripExtension(buf
);
1958 strcat(buf
, ".jpg");
1959 f
= TexPathList
.FindValidPath(buf
);
1962 if (f
== "") // Try for a PNG instead
1964 strcpy(buf
, filename
);
1965 StripExtension(buf
);
1966 strcat(buf
, ".png");
1967 f
= TexPathList
.FindValidPath(buf
);
1972 char *inlineFilename
= copystring(f
);
1974 char *originalFilename
= TexPathList
.FindValidPath(filename
);
1975 // If we have found the existing filename, make the inline
1976 // image point to the original file (could be PS, for example)
1977 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
1979 TexOutput("<A HREF=\"");
1980 TexOutput(ConvertCase(originalFilename
));
1982 TexOutput("<img src=\"");
1983 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1984 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1989 TexOutput("<img src=\"");
1990 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1991 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1992 delete[] inlineFilename
;
1997 // Last resort - a link to a PS file.
1998 TexOutput("<A HREF=\"");
1999 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2000 TexOutput("\">Picture</A>\n");
2001 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2009 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2012 static char *imageFile
= NULL
;
2013 if (start
&& (arg_no
== 2))
2015 // Try to find an XBM or GIF image first.
2016 char *filename
= copystring(GetArgData());
2019 strcpy(buf
, filename
);
2020 StripExtension(buf
);
2021 strcat(buf
, ".xbm");
2022 wxString f
= TexPathList
.FindValidPath(buf
);
2024 if (f
== "") // Try for a GIF instead
2026 strcpy(buf
, filename
);
2027 StripExtension(buf
);
2028 strcat(buf
, ".gif");
2029 f
= TexPathList
.FindValidPath(buf
);
2034 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2043 imageFile
= copystring(f
);
2046 else if (start
&& (arg_no
== 3))
2050 // First, try to find a .shg (segmented hypergraphics file)
2051 // that we can convert to a map file
2053 strcpy(buf
, imageFile
);
2054 StripExtension(buf
);
2055 strcat(buf
, ".shg");
2056 wxString f
= TexPathList
.FindValidPath(buf
);
2060 // The default HTML file to go to is THIS file (so a no-op)
2061 SHGToMap((char*) (const char*) f
, currentFileName
);
2064 char *mapName
= GetArgData();
2065 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2069 TexOutput("unknown");
2071 TexOutput("<img src=\"");
2072 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2073 TexOutput("\" ISMAP></A><P>");
2094 descriptionItemArg
= GetArgChunk();
2099 case ltTWOCOLITEMRULED
:
2102 if (start && (arg_no == 1))
2103 TexOutput("\n<DT> ");
2104 if (start && (arg_no == 2))
2111 if (TwoColWidthA
> -1) {
2113 sprintf(buf
,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA
);
2116 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2118 TexOutput("\n</TD>\n");
2124 if (TwoColWidthB
> -1) {
2126 sprintf(buf
,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB
);
2129 TexOutput("\n<TD VALIGN=TOP>\n");
2131 TexOutput("\n</TD></TR>\n");
2136 case ltNUMBEREDBIBITEM
:
2138 if (arg_no
== 1 && start
)
2140 TexOutput("\n<DT> ");
2142 if (arg_no
== 2 && !start
)
2149 if (arg_no
== 1 && start
)
2151 char *citeKey
= GetArgData();
2152 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2155 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2156 sprintf(buf
, "[%d]", citeCount
);
2157 ref
->sectionNumber
= copystring(buf
);
2160 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2165 if (arg_no
== 2 && !start
)
2171 case ltMARGINPARODD
:
2172 case ltMARGINPAREVEN
:
2178 TexOutput("<HR>\n");
2182 TexOutput("<HR><P>\n");
2186 case ltTWOCOLWIDTHA
:
2190 char *val
= GetArgData();
2191 float points
= ParseUnitArgument(val
);
2192 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2198 case ltTWOCOLWIDTHB
:
2202 char *val
= GetArgData();
2203 float points
= ParseUnitArgument(val
);
2204 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2213 case ltACCENT_GRAVE
:
2217 char *val
= GetArgData();
2223 TexOutput("à");
2226 TexOutput("è");
2229 TexOutput("ì");
2232 TexOutput("ò");
2235 TexOutput("ù");
2238 TexOutput("À");
2241 TexOutput("È");
2244 TexOutput("Ì");
2247 TexOutput("Ò");
2250 TexOutput("Ì");
2260 case ltACCENT_ACUTE
:
2264 char *val
= GetArgData();
2270 TexOutput("á");
2273 TexOutput("é");
2276 TexOutput("í");
2279 TexOutput("ó");
2282 TexOutput("ú");
2285 TexOutput("ý");
2288 TexOutput("Á");
2291 TexOutput("É");
2294 TexOutput("Í");
2297 TexOutput("Ó");
2300 TexOutput("Ú");
2303 TexOutput("Ý");
2313 case ltACCENT_CARET
:
2317 char *val
= GetArgData();
2323 TexOutput("â");
2326 TexOutput("ê");
2329 TexOutput("î");
2332 TexOutput("ô");
2335 TexOutput("û");
2338 TexOutput("Â");
2341 TexOutput("Ê");
2344 TexOutput("Î");
2347 TexOutput("Ô");
2350 TexOutput("Î");
2360 case ltACCENT_TILDE
:
2364 char *val
= GetArgData();
2373 TexOutput("ã");
2376 TexOutput("ñ");
2379 TexOutput("õ");
2382 TexOutput("Ã");
2385 TexOutput("Ñ");
2388 TexOutput("Õ");
2398 case ltACCENT_UMLAUT
:
2402 char *val
= GetArgData();
2408 TexOutput("ä");
2411 TexOutput("ë");
2414 TexOutput("ï");
2417 TexOutput("ö");
2420 TexOutput("ü");
2423 TexOutput("ÿ");
2426 TexOutput("Ä");
2429 TexOutput("Ë");
2432 TexOutput("Ï");
2435 TexOutput("Ö");
2438 TexOutput("Ü");
2441 TexOutput("Ÿ");
2455 char *val
= GetArgData();
2461 TexOutput("å");
2464 TexOutput("Å");
2478 char *val
= GetArgData();
2481 bool isPicture
= FALSE
;
2482 char *s
= ParseColourString(val
, &isPicture
);
2485 if (backgroundImageString
)
2486 delete[] backgroundImageString
;
2487 backgroundImageString
= copystring(val
);
2491 if (backgroundColourString
)
2492 delete[] backgroundColourString
;
2493 backgroundColourString
= copystring(val
);
2500 case ltBACKGROUNDIMAGE
:
2504 char *val
= GetArgData();
2507 if (backgroundImageString
)
2508 delete[] backgroundImageString
;
2509 backgroundImageString
= copystring(val
);
2515 case ltBACKGROUNDCOLOUR
:
2519 char *val
= GetArgData();
2522 if (backgroundColourString
)
2523 delete[] backgroundColourString
;
2524 backgroundColourString
= copystring(val
);
2534 char *val
= GetArgData();
2537 if (textColourString
)
2538 delete[] textColourString
;
2539 textColourString
= copystring(val
);
2549 char *val
= GetArgData();
2552 if (linkColourString
)
2553 delete[] linkColourString
;
2554 linkColourString
= copystring(val
);
2560 case ltFOLLOWEDLINKCOLOUR
:
2564 char *val
= GetArgData();
2567 if (followedLinkColourString
)
2568 delete[] followedLinkColourString
;
2569 followedLinkColourString
= copystring(val
);
2575 case ltACCENT_CADILLA
:
2579 char *val
= GetArgData();
2585 TexOutput("ç");
2588 TexOutput("Ç");
2600 case ltFOOTNOTEPOPUP:
2610 case ltSUPERTABULAR
:
2616 currentRowNumber
= 0;
2619 tableVerticalLineLeft
= FALSE
;
2620 tableVerticalLineRight
= FALSE
;
2621 int currentWidth
= 0;
2623 char *alignString
= copystring(GetArgData());
2624 ParseTableArgument(alignString
);
2626 TexOutput("<TABLE BORDER>\n");
2628 // Write the first row formatting for compatibility
2629 // with standard Latex
2630 if (compatibilityMode
)
2632 TexOutput("<TR>\n<TD>");
2634 for (int i = 0; i < noColumns; i++)
2636 currentWidth += TableData[i].width;
2637 sprintf(buf, "\\cellx%d", currentWidth);
2640 TexOutput("\\pard\\intbl\n");
2643 delete[] alignString
;
2648 else if (arg_no
== 2 && !start
)
2650 TexOutput("</TABLE>\n");
2655 case ltTHEBIBLIOGRAPHY
:
2657 if (start
&& (arg_no
== 1))
2659 ReopenFile(&Chapters
, &ChaptersName
);
2660 AddTexRef("bibliography", ChaptersName
, "bibliography");
2661 SetCurrentSubsectionName("bibliography", ChaptersName
);
2665 SetCurrentOutput(Chapters
);
2668 if (truncateFilenames
)
2669 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2671 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2673 TexOutput("<head><title>");
2674 TexOutput(ReferencesNameString
);
2675 TexOutput("</title></head>\n");
2678 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2679 AddBrowseButtons("contents", titleBuf
, // Up
2680 lastTopic
, lastFileName
, // Last topic
2681 "bibliography", ChaptersName
); // This topic
2683 SetCurrentOutputs(Contents
, Chapters
);
2684 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2686 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2687 fprintf(Chapters
, "</H2>\n</A>\n");
2689 SetCurrentOutput(Chapters
);
2692 if (!start
&& (arg_no
== 2))
2700 /* Build up list of keywords associated with topics */
2703 // char *entry = GetArgData();
2705 OutputChunkToString(GetArgChunk(), buf
);
2708 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2723 char *name
= GetArgData();
2725 if (!FindColourHTMLString(name
, buf2
))
2727 strcpy(buf2
, "#000000");
2729 sprintf(buf
, "Could not find colour name %s", name
);
2732 TexOutput("<FONT COLOR=\"");
2748 if (arg_no
== 2) TexOutput("</FONT>");
2753 case ltINSERTATLEVEL
:
2755 // This macro allows you to insert text at a different level
2756 // from the current level, e.g. into the Sections from within a subsubsection.
2759 static int currentLevelNo
= 1;
2760 static FILE* oldLevelFile
= Chapters
;
2767 oldLevelFile
= CurrentOutput1
;
2769 char *str
= GetArgData();
2770 currentLevelNo
= atoi(str
);
2772 // TODO: cope with article style (no chapters)
2773 switch (currentLevelNo
)
2777 outputFile
= Chapters
;
2782 outputFile
= Sections
;
2787 outputFile
= Subsections
;
2792 outputFile
= Subsubsections
;
2802 CurrentOutput1
= outputFile
;
2820 CurrentOutput1
= oldLevelFile
;
2826 return DefaultOnArgument(macroId
, arg_no
, start
);
2839 tableVerticalLineLeft
= FALSE
;
2840 tableVerticalLineRight
= FALSE
;
2843 if (InputFile
&& OutputFile
)
2845 // Do some HTML-specific transformations on all the strings,
2847 Text2HTML(GetTopLevelChunk());
2850 if (truncateFilenames
)
2851 sprintf(buf
, "%s.htm", FileRoot
);
2853 sprintf(buf
, "%s_contents.html", FileRoot
);
2854 if (TitlepageName
) delete[] TitlepageName
;
2855 TitlepageName
= copystring(buf
);
2856 Titlepage
= fopen(buf
, "w");
2858 if (truncateFilenames
)
2859 sprintf(buf
, "%s_fc.htm", FileRoot
);
2861 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2863 contentsFrameName
= copystring(buf
);
2865 Contents
= fopen(TmpContentsName
, "w");
2867 if (htmlFrameContents
)
2869 // FrameContents = fopen(TmpFrameContentsName, "w");
2870 FrameContents
= fopen(contentsFrameName
, "w");
2871 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2874 if (!Titlepage
|| !Contents
)
2876 OnError("Cannot open output file!");
2879 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2881 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2883 fprintf(Contents
, "<UL>\n");
2885 SetCurrentOutput(Titlepage
);
2886 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2887 OnInform("Converting...");
2890 fprintf(Contents
, "</UL>\n\n");
2892 // SetCurrentOutput(Titlepage);
2897 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2904 fprintf(FrameContents
, "\n</UL>\n");
2905 fprintf(FrameContents
, "</HTML>\n");
2906 fclose(FrameContents
);
2907 FrameContents
= NULL
;
2912 fprintf(Chapters
, "\n</BODY></HTML>\n");
2918 fprintf(Sections
, "\n</BODY></HTML>\n");
2922 if (Subsections
&& !combineSubSections
)
2924 fprintf(Subsections
, "\n</BODY></HTML>\n");
2925 fclose(Subsections
);
2928 if (Subsubsections
&& !combineSubSections
)
2930 fprintf(Subsubsections
, "\n</BODY></HTML>\n");
2931 fclose(Subsubsections
);
2932 Subsubsections
= NULL
;
2934 if ( SectionContentsFD
)
2936 fclose(SectionContentsFD
);
2937 SectionContentsFD
= NULL
;
2940 // Create a temporary file for the title page header, add some info,
2941 // and concat the titlepage just generated.
2942 // This is necessary in order to put the title of the document
2943 // at the TOP of the file within <HEAD>, even though we only find out
2944 // what it is later on.
2945 FILE *tmpTitle
= fopen("title.tmp", "w");
2950 SetCurrentOutput(tmpTitle
);
2951 TexOutput("\n<HTML>\n<HEAD><TITLE>");
2952 TraverseChildrenFromChunk(DocumentTitle
);
2953 TexOutput("</TITLE></HEAD>\n");
2957 SetCurrentOutput(tmpTitle
);
2959 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
2961 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
2964 // Output frame information
2965 if (htmlFrameContents
)
2967 char firstFileName
[300];
2968 if (truncateFilenames
)
2969 sprintf(firstFileName
, "%s1.htm", FileRoot
);
2971 sprintf(firstFileName
, "%s1.html", FileRoot
);
2973 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
2975 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
2976 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
2977 fprintf(tmpTitle
, "</FRAMESET>\n");
2979 fprintf(tmpTitle
, "<NOFRAMES>\n");
2982 // Output <BODY...> to temporary title page
2986 FILE *fd
= fopen(TitlepageName
, "r");
2998 fprintf(tmpTitle
, "\n</BODY>\n");
3000 if (htmlFrameContents
)
3002 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
3004 fprintf(tmpTitle
, "\n</HTML>\n");
3007 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3008 if (!wxRenameFile("title.tmp", TitlepageName
))
3010 wxCopyFile("title.tmp", TitlepageName
);
3011 wxRemoveFile("title.tmp");
3015 if (lastFileName
) delete[] lastFileName
;
3016 lastFileName
= NULL
;
3017 if (lastTopic
) delete[] lastTopic
;
3020 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3022 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3024 wxCopyFile(TmpContentsName
, ContentsName
);
3025 wxRemoveFile(TmpContentsName
);
3028 // Generate .htx file if requested
3031 char htmlIndexName
[300];
3032 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
3033 GenerateHTMLIndexFile(htmlIndexName
);
3036 // Generate HTML Help Workshop files if requested
3037 if (htmlWorkshopFiles
)
3039 HTMLWorkshopEndContents();
3040 GenerateHTMLWorkshopFiles(FileRoot
);
3050 // Output .htx index file
3051 void GenerateHTMLIndexFile(char *fname
)
3053 FILE *fd
= fopen(fname
, "w");
3057 TopicTable
.BeginFind();
3058 wxNode
*node
= NULL
;
3059 while ((node
= TopicTable
.Next()))
3061 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3062 const char *topicName
= node
->GetKeyString();
3063 if (texTopic
->filename
&& texTopic
->keywords
)
3065 wxNode
*node1
= texTopic
->keywords
->First();
3068 char *s
= (char *)node1
->Data();
3069 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3070 node1
= node1
->Next();
3083 // output .hpp, .hhc and .hhk files:
3086 void GenerateHTMLWorkshopFiles(char *fname
)
3091 /* Generate project file : */
3093 sprintf(buf
, "%s.hhp", fname
);
3094 f
= fopen(buf
, "wt");
3097 "Compatibility=1.1\n"
3098 "Full-text search=Yes\n"
3099 "Contents file=%s.hhc\n"
3100 "Compiled file=%s.chm\n"
3101 "Default Window=%sHelp\n"
3102 "Default topic=%s\n"
3103 "Index file=%s.hhk\n"
3105 FileNameFromPath(fname
),
3106 FileNameFromPath(fname
),
3107 FileNameFromPath(fname
),
3108 FileNameFromPath(TitlepageName
),
3109 FileNameFromPath(fname
)
3112 if (DocumentTitle
) {
3113 SetCurrentOutput(f
);
3114 TraverseChildrenFromChunk(DocumentTitle
);
3116 else fprintf(f
, "(unknown)");
3118 fprintf(f
, "\n\n[WINDOWS]\n"
3119 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3120 FileNameFromPath(fname
),
3121 FileNameFromPath(fname
),
3122 FileNameFromPath(fname
),
3123 FileNameFromPath(TitlepageName
));
3126 fprintf(f
, "\n\n[FILES]\n");
3127 fprintf(f
, "%s\n", FileNameFromPath(TitlepageName
));
3128 for (int i
= 1; i
<= fileId
; i
++) {
3129 if (truncateFilenames
)
3130 sprintf(buf
, "%s%d.htm", FileNameFromPath(FileRoot
), i
);
3132 sprintf(buf
, "%s%d.html", FileNameFromPath(FileRoot
), i
);
3133 fprintf(f
, "%s\n", buf
);
3137 /* Generate index file : */
3139 sprintf(buf
, "%s.hhk", fname
);
3140 f
= fopen(buf
, "wt");
3143 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3146 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3147 "<!-- Sitemap 1.0 -->\n"
3149 "<OBJECT type=\"text/site properties\">\n"
3150 " <param name=\"ImageType\" value=\"Folder\">\n"
3154 TopicTable
.BeginFind();
3155 wxNode
*node
= NULL
;
3156 while ((node
= TopicTable
.Next()))
3158 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3159 const char *topicName
= node
->GetKeyString();
3160 if (texTopic
->filename
&& texTopic
->keywords
)
3162 wxNode
*node1
= texTopic
->keywords
->First();
3165 char *s
= (char *)node1
->Data();
3167 " <LI> <OBJECT type=\"text/sitemap\">\n"
3168 " <param name=\"Local\" value=\"%s#%s\">\n"
3169 " <param name=\"Name\" value=\"%s\">\n"
3171 texTopic
->filename
, topicName
, s
);
3172 node1
= node1
->Next();
3177 fprintf(f
, "</UL>\n");
3183 static FILE *HTMLWorkshopContents
= NULL
;
3184 static int HTMLWorkshopLastLevel
= 0;
3186 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3190 if (level
> HTMLWorkshopLastLevel
)
3191 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3192 fprintf(HTMLWorkshopContents
, "<UL>");
3193 if (level
< HTMLWorkshopLastLevel
)
3194 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3195 fprintf(HTMLWorkshopContents
, "</UL>");
3197 SetCurrentOutput(HTMLWorkshopContents
);
3198 fprintf(HTMLWorkshopContents
,
3199 " <LI> <OBJECT type=\"text/sitemap\">\n"
3200 " <param name=\"Local\" value=\"%s#%s\">\n"
3201 " <param name=\"Name\" value=\"",
3203 OutputCurrentSection();
3204 fprintf(HTMLWorkshopContents
,
3207 HTMLWorkshopLastLevel
= level
;
3211 void HTMLWorkshopStartContents()
3214 sprintf(buf
, "%s.hhc", FileRoot
);
3215 HTMLWorkshopContents
= fopen(buf
, "wt");
3216 HTMLWorkshopLastLevel
= 0;
3218 fprintf(HTMLWorkshopContents
,
3219 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3222 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3223 "<!-- Sitemap 1.0 -->\n"
3225 "<OBJECT type=\"text/site properties\">\n"
3226 " <param name=\"ImageType\" value=\"Folder\">\n"
3229 "<LI> <OBJECT type=\"text/sitemap\">\n"
3230 "<param name=\"Local\" value=\"%s\">\n"
3231 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3232 FileNameFromPath(TitlepageName
)
3238 void HTMLWorkshopEndContents()
3240 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3241 fprintf(HTMLWorkshopContents
, "</UL>\n");
3242 fclose(HTMLWorkshopContents
);