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
);
1909 TexOutput(" (REF NOT FOUND)");
1911 errBuf
.Printf("Warning: unresolved reference '%s'", refName
);
1912 OnInform((char *)errBuf
.c_str());
1915 else TexOutput("??");
1930 char *alignment
= "";
1931 if (macroId
== ltIMAGEL
)
1932 alignment
= " align=left";
1933 else if (macroId
== ltIMAGER
)
1934 alignment
= " align=right";
1936 // Try to find an XBM or GIF image first.
1937 char *filename
= copystring(GetArgData());
1940 strcpy(buf
, filename
);
1941 StripExtension(buf
);
1942 strcat(buf
, ".xbm");
1943 wxString f
= TexPathList
.FindValidPath(buf
);
1945 if (f
== "") // Try for a GIF instead
1947 strcpy(buf
, filename
);
1948 StripExtension(buf
);
1949 strcat(buf
, ".gif");
1950 f
= TexPathList
.FindValidPath(buf
);
1953 if (f
== "") // Try for a JPEG instead
1955 strcpy(buf
, filename
);
1956 StripExtension(buf
);
1957 strcat(buf
, ".jpg");
1958 f
= TexPathList
.FindValidPath(buf
);
1961 if (f
== "") // Try for a PNG instead
1963 strcpy(buf
, filename
);
1964 StripExtension(buf
);
1965 strcat(buf
, ".png");
1966 f
= TexPathList
.FindValidPath(buf
);
1971 char *inlineFilename
= copystring(f
);
1973 char *originalFilename
= TexPathList
.FindValidPath(filename
);
1974 // If we have found the existing filename, make the inline
1975 // image point to the original file (could be PS, for example)
1976 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
1978 TexOutput("<A HREF=\"");
1979 TexOutput(ConvertCase(originalFilename
));
1981 TexOutput("<img src=\"");
1982 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1983 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1988 TexOutput("<img src=\"");
1989 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1990 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1991 delete[] inlineFilename
;
1996 // Last resort - a link to a PS file.
1997 TexOutput("<A HREF=\"");
1998 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
1999 TexOutput("\">Picture</A>\n");
2000 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2008 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2011 static char *imageFile
= NULL
;
2012 if (start
&& (arg_no
== 2))
2014 // Try to find an XBM or GIF image first.
2015 char *filename
= copystring(GetArgData());
2018 strcpy(buf
, filename
);
2019 StripExtension(buf
);
2020 strcat(buf
, ".xbm");
2021 wxString f
= TexPathList
.FindValidPath(buf
);
2023 if (f
== "") // Try for a GIF instead
2025 strcpy(buf
, filename
);
2026 StripExtension(buf
);
2027 strcat(buf
, ".gif");
2028 f
= TexPathList
.FindValidPath(buf
);
2033 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2042 imageFile
= copystring(f
);
2045 else if (start
&& (arg_no
== 3))
2049 // First, try to find a .shg (segmented hypergraphics file)
2050 // that we can convert to a map file
2052 strcpy(buf
, imageFile
);
2053 StripExtension(buf
);
2054 strcat(buf
, ".shg");
2055 wxString f
= TexPathList
.FindValidPath(buf
);
2059 // The default HTML file to go to is THIS file (so a no-op)
2060 SHGToMap((char*) (const char*) f
, currentFileName
);
2063 char *mapName
= GetArgData();
2064 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2068 TexOutput("unknown");
2070 TexOutput("<img src=\"");
2071 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2072 TexOutput("\" ISMAP></A><P>");
2093 descriptionItemArg
= GetArgChunk();
2098 case ltTWOCOLITEMRULED
:
2101 if (start && (arg_no == 1))
2102 TexOutput("\n<DT> ");
2103 if (start && (arg_no == 2))
2110 if (TwoColWidthA
> -1) {
2112 sprintf(buf
,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA
);
2115 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2117 TexOutput("\n</TD>\n");
2123 if (TwoColWidthB
> -1) {
2125 sprintf(buf
,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB
);
2128 TexOutput("\n<TD VALIGN=TOP>\n");
2130 TexOutput("\n</TD></TR>\n");
2135 case ltNUMBEREDBIBITEM
:
2137 if (arg_no
== 1 && start
)
2139 TexOutput("\n<DT> ");
2141 if (arg_no
== 2 && !start
)
2148 if (arg_no
== 1 && start
)
2150 char *citeKey
= GetArgData();
2151 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2154 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2155 sprintf(buf
, "[%d]", citeCount
);
2156 ref
->sectionNumber
= copystring(buf
);
2159 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2164 if (arg_no
== 2 && !start
)
2170 case ltMARGINPARODD
:
2171 case ltMARGINPAREVEN
:
2177 TexOutput("<HR>\n");
2181 TexOutput("<HR><P>\n");
2185 case ltTWOCOLWIDTHA
:
2189 char *val
= GetArgData();
2190 float points
= ParseUnitArgument(val
);
2191 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2197 case ltTWOCOLWIDTHB
:
2201 char *val
= GetArgData();
2202 float points
= ParseUnitArgument(val
);
2203 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2212 case ltACCENT_GRAVE
:
2216 char *val
= GetArgData();
2222 TexOutput("à");
2225 TexOutput("è");
2228 TexOutput("ì");
2231 TexOutput("ò");
2234 TexOutput("ù");
2237 TexOutput("À");
2240 TexOutput("È");
2243 TexOutput("Ì");
2246 TexOutput("Ò");
2249 TexOutput("Ì");
2259 case ltACCENT_ACUTE
:
2263 char *val
= GetArgData();
2269 TexOutput("á");
2272 TexOutput("é");
2275 TexOutput("í");
2278 TexOutput("ó");
2281 TexOutput("ú");
2284 TexOutput("ý");
2287 TexOutput("Á");
2290 TexOutput("É");
2293 TexOutput("Í");
2296 TexOutput("Ó");
2299 TexOutput("Ú");
2302 TexOutput("Ý");
2312 case ltACCENT_CARET
:
2316 char *val
= GetArgData();
2322 TexOutput("â");
2325 TexOutput("ê");
2328 TexOutput("î");
2331 TexOutput("ô");
2334 TexOutput("û");
2337 TexOutput("Â");
2340 TexOutput("Ê");
2343 TexOutput("Î");
2346 TexOutput("Ô");
2349 TexOutput("Î");
2359 case ltACCENT_TILDE
:
2363 char *val
= GetArgData();
2372 TexOutput("ã");
2375 TexOutput("ñ");
2378 TexOutput("õ");
2381 TexOutput("Ã");
2384 TexOutput("Ñ");
2387 TexOutput("Õ");
2397 case ltACCENT_UMLAUT
:
2401 char *val
= GetArgData();
2407 TexOutput("ä");
2410 TexOutput("ë");
2413 TexOutput("ï");
2416 TexOutput("ö");
2419 TexOutput("ü");
2422 TexOutput("ÿ");
2425 TexOutput("Ä");
2428 TexOutput("Ë");
2431 TexOutput("Ï");
2434 TexOutput("Ö");
2437 TexOutput("Ü");
2440 TexOutput("Ÿ");
2454 char *val
= GetArgData();
2460 TexOutput("å");
2463 TexOutput("Å");
2477 char *val
= GetArgData();
2480 bool isPicture
= FALSE
;
2481 char *s
= ParseColourString(val
, &isPicture
);
2484 if (backgroundImageString
)
2485 delete[] backgroundImageString
;
2486 backgroundImageString
= copystring(val
);
2490 if (backgroundColourString
)
2491 delete[] backgroundColourString
;
2492 backgroundColourString
= copystring(val
);
2499 case ltBACKGROUNDIMAGE
:
2503 char *val
= GetArgData();
2506 if (backgroundImageString
)
2507 delete[] backgroundImageString
;
2508 backgroundImageString
= copystring(val
);
2514 case ltBACKGROUNDCOLOUR
:
2518 char *val
= GetArgData();
2521 if (backgroundColourString
)
2522 delete[] backgroundColourString
;
2523 backgroundColourString
= copystring(val
);
2533 char *val
= GetArgData();
2536 if (textColourString
)
2537 delete[] textColourString
;
2538 textColourString
= copystring(val
);
2548 char *val
= GetArgData();
2551 if (linkColourString
)
2552 delete[] linkColourString
;
2553 linkColourString
= copystring(val
);
2559 case ltFOLLOWEDLINKCOLOUR
:
2563 char *val
= GetArgData();
2566 if (followedLinkColourString
)
2567 delete[] followedLinkColourString
;
2568 followedLinkColourString
= copystring(val
);
2574 case ltACCENT_CADILLA
:
2578 char *val
= GetArgData();
2584 TexOutput("ç");
2587 TexOutput("Ç");
2599 case ltFOOTNOTEPOPUP:
2609 case ltSUPERTABULAR
:
2615 currentRowNumber
= 0;
2618 tableVerticalLineLeft
= FALSE
;
2619 tableVerticalLineRight
= FALSE
;
2620 int currentWidth
= 0;
2622 char *alignString
= copystring(GetArgData());
2623 ParseTableArgument(alignString
);
2625 TexOutput("<TABLE BORDER>\n");
2627 // Write the first row formatting for compatibility
2628 // with standard Latex
2629 if (compatibilityMode
)
2631 TexOutput("<TR>\n<TD>");
2633 for (int i = 0; i < noColumns; i++)
2635 currentWidth += TableData[i].width;
2636 sprintf(buf, "\\cellx%d", currentWidth);
2639 TexOutput("\\pard\\intbl\n");
2642 delete[] alignString
;
2647 else if (arg_no
== 2 && !start
)
2649 TexOutput("</TABLE>\n");
2654 case ltTHEBIBLIOGRAPHY
:
2656 if (start
&& (arg_no
== 1))
2658 ReopenFile(&Chapters
, &ChaptersName
);
2659 AddTexRef("bibliography", ChaptersName
, "bibliography");
2660 SetCurrentSubsectionName("bibliography", ChaptersName
);
2664 SetCurrentOutput(Chapters
);
2667 if (truncateFilenames
)
2668 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2670 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2672 TexOutput("<head><title>");
2673 TexOutput(ReferencesNameString
);
2674 TexOutput("</title></head>\n");
2677 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2678 AddBrowseButtons("contents", titleBuf
, // Up
2679 lastTopic
, lastFileName
, // Last topic
2680 "bibliography", ChaptersName
); // This topic
2682 SetCurrentOutputs(Contents
, Chapters
);
2683 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2685 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2686 fprintf(Chapters
, "</H2>\n</A>\n");
2688 SetCurrentOutput(Chapters
);
2691 if (!start
&& (arg_no
== 2))
2699 /* Build up list of keywords associated with topics */
2702 // char *entry = GetArgData();
2704 OutputChunkToString(GetArgChunk(), buf
);
2707 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2722 char *name
= GetArgData();
2724 if (!FindColourHTMLString(name
, buf2
))
2726 strcpy(buf2
, "#000000");
2728 sprintf(buf
, "Could not find colour name %s", name
);
2731 TexOutput("<FONT COLOR=\"");
2747 if (arg_no
== 2) TexOutput("</FONT>");
2752 case ltINSERTATLEVEL
:
2754 // This macro allows you to insert text at a different level
2755 // from the current level, e.g. into the Sections from within a subsubsection.
2758 static int currentLevelNo
= 1;
2759 static FILE* oldLevelFile
= Chapters
;
2766 oldLevelFile
= CurrentOutput1
;
2768 char *str
= GetArgData();
2769 currentLevelNo
= atoi(str
);
2771 // TODO: cope with article style (no chapters)
2772 switch (currentLevelNo
)
2776 outputFile
= Chapters
;
2781 outputFile
= Sections
;
2786 outputFile
= Subsections
;
2791 outputFile
= Subsubsections
;
2801 CurrentOutput1
= outputFile
;
2819 CurrentOutput1
= oldLevelFile
;
2825 return DefaultOnArgument(macroId
, arg_no
, start
);
2838 tableVerticalLineLeft
= FALSE
;
2839 tableVerticalLineRight
= FALSE
;
2842 if (InputFile
&& OutputFile
)
2844 // Do some HTML-specific transformations on all the strings,
2846 Text2HTML(GetTopLevelChunk());
2849 if (truncateFilenames
)
2850 sprintf(buf
, "%s.htm", FileRoot
);
2852 sprintf(buf
, "%s_contents.html", FileRoot
);
2853 if (TitlepageName
) delete[] TitlepageName
;
2854 TitlepageName
= copystring(buf
);
2855 Titlepage
= fopen(buf
, "w");
2857 if (truncateFilenames
)
2858 sprintf(buf
, "%s_fc.htm", FileRoot
);
2860 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2862 contentsFrameName
= copystring(buf
);
2864 Contents
= fopen(TmpContentsName
, "w");
2866 if (htmlFrameContents
)
2868 // FrameContents = fopen(TmpFrameContentsName, "w");
2869 FrameContents
= fopen(contentsFrameName
, "w");
2870 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2873 if (!Titlepage
|| !Contents
)
2875 OnError("Cannot open output file!");
2878 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2880 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2882 fprintf(Contents
, "<UL>\n");
2884 SetCurrentOutput(Titlepage
);
2885 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2886 OnInform("Converting...");
2889 fprintf(Contents
, "</UL>\n\n");
2891 // SetCurrentOutput(Titlepage);
2896 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2903 fprintf(FrameContents
, "\n</UL>\n");
2904 fprintf(FrameContents
, "</HTML>\n");
2905 fclose(FrameContents
);
2906 FrameContents
= NULL
;
2911 fprintf(Chapters
, "\n</BODY></HTML>\n");
2917 fprintf(Sections
, "\n</BODY></HTML>\n");
2921 if (Subsections
&& !combineSubSections
)
2923 fprintf(Subsections
, "\n</BODY></HTML>\n");
2924 fclose(Subsections
);
2927 if (Subsubsections
&& !combineSubSections
)
2929 fprintf(Subsubsections
, "\n</BODY></HTML>\n");
2930 fclose(Subsubsections
);
2931 Subsubsections
= NULL
;
2933 if ( SectionContentsFD
)
2935 fclose(SectionContentsFD
);
2936 SectionContentsFD
= NULL
;
2939 // Create a temporary file for the title page header, add some info,
2940 // and concat the titlepage just generated.
2941 // This is necessary in order to put the title of the document
2942 // at the TOP of the file within <HEAD>, even though we only find out
2943 // what it is later on.
2944 FILE *tmpTitle
= fopen("title.tmp", "w");
2949 SetCurrentOutput(tmpTitle
);
2950 TexOutput("\n<HTML>\n<HEAD><TITLE>");
2951 TraverseChildrenFromChunk(DocumentTitle
);
2952 TexOutput("</TITLE></HEAD>\n");
2956 SetCurrentOutput(tmpTitle
);
2958 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
2960 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
2963 // Output frame information
2964 if (htmlFrameContents
)
2966 char firstFileName
[300];
2967 if (truncateFilenames
)
2968 sprintf(firstFileName
, "%s1.htm", FileRoot
);
2970 sprintf(firstFileName
, "%s1.html", FileRoot
);
2972 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
2974 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
2975 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
2976 fprintf(tmpTitle
, "</FRAMESET>\n");
2978 fprintf(tmpTitle
, "<NOFRAMES>\n");
2981 // Output <BODY...> to temporary title page
2985 FILE *fd
= fopen(TitlepageName
, "r");
2997 fprintf(tmpTitle
, "\n</BODY>\n");
2999 if (htmlFrameContents
)
3001 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
3003 fprintf(tmpTitle
, "\n</HTML>\n");
3006 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3007 if (!wxRenameFile("title.tmp", TitlepageName
))
3009 wxCopyFile("title.tmp", TitlepageName
);
3010 wxRemoveFile("title.tmp");
3014 if (lastFileName
) delete[] lastFileName
;
3015 lastFileName
= NULL
;
3016 if (lastTopic
) delete[] lastTopic
;
3019 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3021 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3023 wxCopyFile(TmpContentsName
, ContentsName
);
3024 wxRemoveFile(TmpContentsName
);
3027 // Generate .htx file if requested
3030 char htmlIndexName
[300];
3031 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
3032 GenerateHTMLIndexFile(htmlIndexName
);
3035 // Generate HTML Help Workshop files if requested
3036 if (htmlWorkshopFiles
)
3038 HTMLWorkshopEndContents();
3039 GenerateHTMLWorkshopFiles(FileRoot
);
3049 // Output .htx index file
3050 void GenerateHTMLIndexFile(char *fname
)
3052 FILE *fd
= fopen(fname
, "w");
3056 TopicTable
.BeginFind();
3057 wxNode
*node
= NULL
;
3058 while ((node
= TopicTable
.Next()))
3060 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3061 const char *topicName
= node
->GetKeyString();
3062 if (texTopic
->filename
&& texTopic
->keywords
)
3064 wxNode
*node1
= texTopic
->keywords
->First();
3067 char *s
= (char *)node1
->Data();
3068 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3069 node1
= node1
->Next();
3082 // output .hpp, .hhc and .hhk files:
3085 void GenerateHTMLWorkshopFiles(char *fname
)
3090 /* Generate project file : */
3092 sprintf(buf
, "%s.hhp", fname
);
3093 f
= fopen(buf
, "wt");
3096 "Compatibility=1.1\n"
3097 "Full-text search=Yes\n"
3098 "Contents file=%s.hhc\n"
3099 "Compiled file=%s.chm\n"
3100 "Default Window=%sHelp\n"
3101 "Default topic=%s\n"
3102 "Index file=%s.hhk\n"
3104 FileNameFromPath(fname
),
3105 FileNameFromPath(fname
),
3106 FileNameFromPath(fname
),
3107 FileNameFromPath(TitlepageName
),
3108 FileNameFromPath(fname
)
3111 if (DocumentTitle
) {
3112 SetCurrentOutput(f
);
3113 TraverseChildrenFromChunk(DocumentTitle
);
3115 else fprintf(f
, "(unknown)");
3117 fprintf(f
, "\n\n[WINDOWS]\n"
3118 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3119 FileNameFromPath(fname
),
3120 FileNameFromPath(fname
),
3121 FileNameFromPath(fname
),
3122 FileNameFromPath(TitlepageName
));
3125 fprintf(f
, "\n\n[FILES]\n");
3126 fprintf(f
, "%s\n", FileNameFromPath(TitlepageName
));
3127 for (int i
= 1; i
<= fileId
; i
++) {
3128 if (truncateFilenames
)
3129 sprintf(buf
, "%s%d.htm", FileNameFromPath(FileRoot
), i
);
3131 sprintf(buf
, "%s%d.html", FileNameFromPath(FileRoot
), i
);
3132 fprintf(f
, "%s\n", buf
);
3136 /* Generate index file : */
3138 sprintf(buf
, "%s.hhk", fname
);
3139 f
= fopen(buf
, "wt");
3142 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3145 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3146 "<!-- Sitemap 1.0 -->\n"
3148 "<OBJECT type=\"text/site properties\">\n"
3149 " <param name=\"ImageType\" value=\"Folder\">\n"
3153 TopicTable
.BeginFind();
3154 wxNode
*node
= NULL
;
3155 while ((node
= TopicTable
.Next()))
3157 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3158 const char *topicName
= node
->GetKeyString();
3159 if (texTopic
->filename
&& texTopic
->keywords
)
3161 wxNode
*node1
= texTopic
->keywords
->First();
3164 char *s
= (char *)node1
->Data();
3166 " <LI> <OBJECT type=\"text/sitemap\">\n"
3167 " <param name=\"Local\" value=\"%s#%s\">\n"
3168 " <param name=\"Name\" value=\"%s\">\n"
3170 texTopic
->filename
, topicName
, s
);
3171 node1
= node1
->Next();
3176 fprintf(f
, "</UL>\n");
3182 static FILE *HTMLWorkshopContents
= NULL
;
3183 static int HTMLWorkshopLastLevel
= 0;
3185 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3189 if (level
> HTMLWorkshopLastLevel
)
3190 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3191 fprintf(HTMLWorkshopContents
, "<UL>");
3192 if (level
< HTMLWorkshopLastLevel
)
3193 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3194 fprintf(HTMLWorkshopContents
, "</UL>");
3196 SetCurrentOutput(HTMLWorkshopContents
);
3197 fprintf(HTMLWorkshopContents
,
3198 " <LI> <OBJECT type=\"text/sitemap\">\n"
3199 " <param name=\"Local\" value=\"%s#%s\">\n"
3200 " <param name=\"Name\" value=\"",
3202 OutputCurrentSection();
3203 fprintf(HTMLWorkshopContents
,
3206 HTMLWorkshopLastLevel
= level
;
3210 void HTMLWorkshopStartContents()
3213 sprintf(buf
, "%s.hhc", FileRoot
);
3214 HTMLWorkshopContents
= fopen(buf
, "wt");
3215 HTMLWorkshopLastLevel
= 0;
3217 fprintf(HTMLWorkshopContents
,
3218 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3221 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3222 "<!-- Sitemap 1.0 -->\n"
3224 "<OBJECT type=\"text/site properties\">\n"
3225 " <param name=\"ImageType\" value=\"Folder\">\n"
3228 "<LI> <OBJECT type=\"text/sitemap\">\n"
3229 "<param name=\"Local\" value=\"%s\">\n"
3230 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3231 FileNameFromPath(TitlepageName
)
3237 void HTMLWorkshopEndContents()
3239 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3240 fprintf(HTMLWorkshopContents
, "</UL>\n");
3241 fclose(HTMLWorkshopContents
);