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</FONT></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 void OutputFont(void)
588 // Output <FONT FACE=...>
589 TexOutput("<FONT FACE=\"");
591 TexOutput(htmlFaceName
);
593 TexOutput("Times New Roman");
597 // Output start of <BODY> block
598 void OutputBodyStart(void)
600 TexOutput("\n<BODY");
601 if (backgroundImageString
)
603 bool isPicture
= FALSE
;
604 char *s
= ParseColourString(backgroundImageString
, &isPicture
);
607 TexOutput(" BACKGROUND=\""); TexOutput(s
); TexOutput("\"");
610 if (backgroundColourString
)
612 bool isPicture
= FALSE
;
613 char *s
= ParseColourString(backgroundColourString
, &isPicture
);
616 TexOutput(" BGCOLOR="); TexOutput(s
);
620 // Set foreground text colour, if one is specified
621 if (textColourString
)
623 bool isPicture
= FALSE
;
624 char *s
= ParseColourString(textColourString
, &isPicture
);
627 TexOutput(" TEXT="); TexOutput(s
);
630 // Set link text colour, if one is specified
631 if (linkColourString
)
633 bool isPicture
= FALSE
;
634 char *s
= ParseColourString(linkColourString
, &isPicture
);
637 TexOutput(" LINK="); TexOutput(s
);
640 // Set followed link text colour, if one is specified
641 if (followedLinkColourString
)
643 bool isPicture
= FALSE
;
644 char *s
= ParseColourString(followedLinkColourString
, &isPicture
);
647 TexOutput(" VLINK="); TexOutput(s
);
658 if (htmlStylesheet
) {
659 TexOutput("<link rel=stylesheet type=\"text/css\" href=\"");
660 TexOutput(htmlStylesheet
);
665 void HTMLHeadTo(FILE* f
)
668 fprintf(f
,"<head><link rel=stylesheet type=\"text/css\" href=\"%s\">",htmlStylesheet
);
673 // Called on start/end of macro examination
674 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
680 case ltCHAPTERHEADING
:
688 if (macroId
!= ltCHAPTERSTAR
)
691 SetCurrentOutput(NULL
);
692 startedSections
= TRUE
;
694 char *topicName
= FindTopicName(GetNextChunk());
695 ReopenFile(&Chapters
, &ChaptersName
);
696 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
698 SetCurrentChapterName(topicName
, ChaptersName
);
699 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
701 SetCurrentOutput(Chapters
);
704 TexOutput("<title>");
705 OutputCurrentSection(); // Repeat section header
706 TexOutput("</title></head>\n");
710 if (truncateFilenames
)
711 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
713 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
715 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
717 AddBrowseButtons("", titleBuf
, // Up
718 lastTopic
, lastFileName
, // Last topic
719 topicName
, ChaptersName
); // This topic
721 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
723 if (htmlFrameContents
&& FrameContents
)
725 SetCurrentOutput(FrameContents
);
726 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
727 OutputCurrentSection();
728 fprintf(FrameContents
, "</A>\n");
731 SetCurrentOutputs(Contents
, Chapters
);
732 fprintf(Chapters
, "\n<H2>");
733 OutputCurrentSection();
734 fprintf(Contents
, "</A>\n");
735 fprintf(Chapters
, "</H2>\n");
737 SetCurrentOutput(Chapters
);
739 // Add this section title to the list of keywords
742 OutputCurrentSectionToString(wxTex2RTFBuffer
);
743 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
750 case ltSECTIONHEADING
:
757 subsectionStarted
= FALSE
;
759 if (macroId
!= ltSECTIONSTAR
)
762 SetCurrentOutput(NULL
);
763 startedSections
= TRUE
;
765 char *topicName
= FindTopicName(GetNextChunk());
766 ReopenFile(&Sections
, &SectionsName
);
767 AddTexRef(topicName
, SectionsName
, SectionNameString
);
769 SetCurrentSectionName(topicName
, SectionsName
);
770 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
772 SetCurrentOutput(Sections
);
774 TexOutput("<title>");
775 OutputCurrentSection();
776 TexOutput("</title></head>\n");
779 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
780 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
781 lastTopic
, lastFileName
, // Last topic
782 topicName
, SectionsName
); // This topic
784 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
786 SetCurrentOutputs(jumpFrom
, Sections
);
787 if (DocumentStyle
== LATEX_ARTICLE
)
788 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
790 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
792 fprintf(Sections
, "\n<H2>");
793 OutputCurrentSection();
795 if (DocumentStyle
== LATEX_ARTICLE
)
796 fprintf(jumpFrom
, "</A>\n");
798 fprintf(jumpFrom
, "</B></A><BR>\n");
799 fprintf(Sections
, "</H2>\n");
801 SetCurrentOutput(Sections
);
802 // Add this section title to the list of keywords
805 OutputCurrentSectionToString(wxTex2RTFBuffer
);
806 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
812 case ltSUBSECTIONSTAR
:
813 case ltMEMBERSECTION
:
814 case ltFUNCTIONSECTION
:
820 OnError("You cannot have a subsection before a section!");
826 if (macroId
!= ltSUBSECTIONSTAR
)
829 if ( combineSubSections
&& !subsectionStarted
)
831 // Read old .con file in at this point
833 strcpy(buf
, CurrentSectionFile
);
834 wxStripExtension(buf
);
836 FILE *fd
= fopen(buf
, "r");
847 fprintf(Sections
, "<P>\n");
849 // Close old file, create a new file for the sub(sub)section contents entries
850 ReopenSectionContentsFile();
853 startedSections
= TRUE
;
854 subsectionStarted
= TRUE
;
856 char *topicName
= FindTopicName(GetNextChunk());
858 if ( !combineSubSections
)
860 SetCurrentOutput(NULL
);
861 ReopenFile(&Subsections
, &SubsectionsName
);
862 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
863 SetCurrentSubsectionName(topicName
, SubsectionsName
);
864 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
865 SetCurrentOutput(Subsections
);
868 TexOutput("<title>");
869 OutputCurrentSection();
870 TexOutput("</title></head>\n");
873 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
874 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
875 lastTopic
, lastFileName
, // Last topic
876 topicName
, SubsectionsName
); // This topic
878 SetCurrentOutputs(Sections
, Subsections
);
879 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
881 fprintf(Subsections
, "\n<H3>");
882 OutputCurrentSection();
883 fprintf(Sections
, "</B></A><BR>\n");
884 fprintf(Subsections
, "</H3>\n");
886 SetCurrentOutput(Subsections
);
890 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
891 SetCurrentSubsectionName(topicName
, SectionsName
);
893 // if ( subsectionNo != 0 )
894 fprintf(Sections
, "\n<HR>\n");
896 // We're putting everything into the section file
897 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
898 fprintf(Sections
, "\n<H3>");
899 OutputCurrentSection();
900 fprintf(Sections
, "</H3>\n");
902 SetCurrentOutput(SectionContentsFD
);
903 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
904 OutputCurrentSection();
905 TexOutput("</A><BR>\n");
907 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
908 SetCurrentOutput(Sections
);
910 // Add this section title to the list of keywords
913 OutputCurrentSectionToString(wxTex2RTFBuffer
);
914 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
921 case ltSUBSUBSECTION
:
922 case ltSUBSUBSECTIONSTAR
:
926 if (!Subsections
&& !combineSubSections
)
928 OnError("You cannot have a subsubsection before a subsection!");
932 if (macroId
!= ltSUBSUBSECTIONSTAR
)
935 startedSections
= TRUE
;
937 char *topicName
= FindTopicName(GetNextChunk());
939 if ( !combineSubSections
)
941 SetCurrentOutput(NULL
);
942 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
943 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
944 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
945 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
947 SetCurrentOutput(Subsubsections
);
949 TexOutput("<title>");
950 OutputCurrentSection();
951 TexOutput("</title></head>\n");
954 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
956 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
957 lastTopic
, lastFileName
, // Last topic
958 topicName
, SubsubsectionsName
); // This topic
960 SetCurrentOutputs(Subsections
, Subsubsections
);
961 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
963 fprintf(Subsubsections
, "\n<H3>");
964 OutputCurrentSection();
965 fprintf(Subsections
, "</B></A><BR>\n");
966 fprintf(Subsubsections
, "</H3>\n");
970 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
971 SetCurrentSubsectionName(topicName
, SectionsName
);
972 fprintf(Sections
, "\n<HR>\n");
974 // We're putting everything into the section file
975 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
976 fprintf(Sections
, "\n<H3>");
977 OutputCurrentSection();
978 fprintf(Sections
, "</H3>\n");
979 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
980 SetCurrentOutput(SectionContentsFD);
981 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
982 OutputCurrentSection();
983 TexOutput("</A><BR>");
985 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
986 SetCurrentOutput(Sections
);
989 // Add this section title to the list of keywords
992 OutputCurrentSectionToString(wxTex2RTFBuffer
);
993 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1002 if ( !combineSubSections
)
1003 SetCurrentOutput(Subsections
);
1005 SetCurrentOutput(Sections
);
1016 if ( !combineSubSections
)
1017 SetCurrentOutput(Subsections
);
1019 SetCurrentOutput(Sections
);
1030 if ( !combineSubSections
)
1031 SetCurrentOutput(Subsections
);
1033 SetCurrentOutput(Sections
);
1044 // TexOutput("<B>void</B>");
1052 TexOutput("wxCLIPS");
1058 case ltSPECIALAMPERSAND
:
1064 // End cell, start cell
1066 TexOutput("</FONT></TD>");
1068 // Start new row and cell, setting alignment for the first cell.
1069 if (currentColumn
< noColumns
)
1073 if (TableData
[currentColumn
].justification
== 'c')
1074 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1075 else if (TableData
[currentColumn
].justification
== 'r')
1076 sprintf(buf
, "\n<TD ALIGN=RIGHT>");
1077 else if (TableData
[currentColumn
].absWidth
)
1079 // Convert from points * 20 into pixels.
1080 int points
= TableData
[currentColumn
].width
/ 20;
1082 // Say the display is 100 DPI (dots/pixels per inch).
1083 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1084 int pixels
= (int)(points
* 100.0 / 72.0);
1085 sprintf(buf
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1088 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1097 case ltBACKSLASHCHAR
:
1103 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1104 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1105 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1106 TexOutput("</TR>\n");
1109 TexOutput("<BR>\n");
1120 // Start new row and cell, setting alignment for the first cell.
1122 if (TableData
[currentColumn
].justification
== 'c')
1123 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1124 else if (TableData
[currentColumn
].justification
== 'r')
1125 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1126 else if (TableData
[currentColumn
].absWidth
)
1128 // Convert from points * 20 into pixels.
1129 int points
= TableData
[currentColumn
].width
/ 20;
1131 // Say the display is 100 DPI (dots/pixels per inch).
1132 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1133 int pixels
= (int)(points
* 100.0 / 72.0);
1134 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1137 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1144 // Start new row and cell
1145 TexOutput("</FONT></TD>\n</TR>\n");
1149 // HTML-only: break until the end of the picture (both margins are clear).
1153 TexOutput("<BR CLEAR=ALL>");
1156 case ltRTFSP
: // Explicit space, RTF only
1158 case ltSPECIALTILDE
:
1172 TexOutput("<UL><UL>\n");
1174 TexOutput("</UL></UL>\n");
1180 // case ltTWOCOLLIST:
1187 if (macroId
== ltENUMERATE
)
1188 listType
= LATEX_ENUMERATE
;
1189 else if (macroId
== ltITEMIZE
)
1190 listType
= LATEX_ITEMIZE
;
1192 listType
= LATEX_DESCRIPTION
;
1194 itemizeStack
.Insert(new ItemizeStruc(listType
));
1198 TexOutput("<UL>\n");
1200 case LATEX_ENUMERATE
:
1201 TexOutput("<OL>\n");
1203 case LATEX_DESCRIPTION
:
1205 TexOutput("<DL>\n");
1212 if (itemizeStack
.First())
1214 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1215 switch (struc
->listType
)
1218 TexOutput("</UL>\n");
1220 case LATEX_ENUMERATE
:
1221 TexOutput("</OL>\n");
1223 case LATEX_DESCRIPTION
:
1225 TexOutput("</DL>\n");
1230 delete itemizeStack
.First();
1238 TexOutput("\n<TABLE>\n");
1240 TexOutput("\n</TABLE>\n");
1253 /* For footnotes we need to output the text at the bottom of the page and
1254 * insert a reference to it. Is it worth the trouble...
1256 case ltFOOTNOTEPOPUP:
1262 else TexOutput("</FN>");
1270 else TexOutput("</TT>");
1278 sprintf(buf
, "<PRE>\n");
1281 else TexOutput("</PRE>\n");
1289 TexOutput("<CENTER>");
1291 else TexOutput("</CENTER>");
1299 TexOutput("{\\ql ");
1301 else TexOutput("}\\par\\pard\n");
1310 TexOutput("{\\qr ");
1312 else TexOutput("}\\par\\pard\n");
1320 // Netscape extension
1321 TexOutput("<FONT SIZE=2>");
1323 else TexOutput("</FONT>");
1330 // Netscape extension
1331 TexOutput("<FONT SIZE=1>");
1333 else TexOutput("</FONT>");
1340 // Netscape extension
1341 TexOutput("<FONT SIZE=3>");
1343 else TexOutput("</FONT>");
1350 // Netscape extension
1351 TexOutput("<FONT SIZE=4>");
1353 else TexOutput("</FONT>");
1360 // Netscape extension
1361 TexOutput("<FONT SIZE=5>");
1363 else TexOutput("</FONT>");
1370 // Netscape extension
1371 TexOutput("<FONT SIZE=6>");
1373 else TexOutput("</FONT>");
1384 else TexOutput("</B>");
1395 else TexOutput("</I>");
1405 else TexOutput("</EM>");
1414 else TexOutput("</UL>");
1425 else TexOutput("</TT>");
1431 TexOutput("©", TRUE
);
1437 TexOutput("®", TRUE
);
1443 if (start
) TexOutput("<--");
1448 if (start
) TexOutput("<==");
1453 if (start
) TexOutput("-->");
1458 if (start
) TexOutput("==>");
1461 case ltLEFTRIGHTARROW
:
1463 if (start
) TexOutput("<-->");
1466 case ltLEFTRIGHTARROW2
:
1468 if (start
) TexOutput("<==>");
1481 wxNode
*node
= itemizeStack
.First();
1484 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1485 struc
->currentItem
+= 1;
1486 if (struc
->listType
== LATEX_DESCRIPTION
)
1488 if (descriptionItemArg
)
1491 TraverseChildrenFromChunk(descriptionItemArg
);
1493 descriptionItemArg
= NULL
;
1505 if (start
&& DocumentTitle
&& DocumentAuthor
)
1507 // Add a special label for the contents page.
1508 // TexOutput("<CENTER>\n");
1509 TexOutput("<A NAME=\"contents\">");
1510 TexOutput("<H2 ALIGN=CENTER>\n");
1511 TraverseChildrenFromChunk(DocumentTitle
);
1514 TexOutput("</A>\n");
1515 TexOutput("<P>\n\n");
1516 TexOutput("<H3 ALIGN=CENTER>");
1517 TraverseChildrenFromChunk(DocumentAuthor
);
1518 TexOutput("</H3><P>\n\n");
1521 TexOutput("<H3 ALIGN=CENTER>");
1522 TraverseChildrenFromChunk(DocumentDate
);
1523 TexOutput("</H3><P>\n\n");
1525 // TexOutput("\n</CENTER>\n");
1526 TexOutput("\n<P><HR><P>\n");
1529 // Now do optional frame contents page
1530 if (htmlFrameContents && FrameContents)
1532 SetCurrentOutput(FrameContents);
1534 // Add a special label for the contents page.
1535 TexOutput("<CENTER>\n");
1536 TexOutput("<H3>\n");
1537 TraverseChildrenFromChunk(DocumentTitle);
1540 TexOutput("</A>\n");
1541 TexOutput("<P>\n\n");
1543 TraverseChildrenFromChunk(DocumentAuthor);
1544 TexOutput("</H3><P>\n\n");
1548 TraverseChildrenFromChunk(DocumentDate);
1549 TexOutput("</H4><P>\n\n");
1551 TexOutput("\n</CENTER>\n");
1552 TexOutput("<P><HR><P>\n");
1554 SetCurrentOutput(Titlepage);
1567 helpRefFilename
= NULL
;
1572 case ltBIBLIOGRAPHY
:
1576 DefaultOnMacro(macroId
, no_args
, start
);
1580 DefaultOnMacro(macroId
, no_args
, start
);
1581 TexOutput("</DL>\n");
1589 TexOutput("<HR>\n");
1597 TexOutput("<HR>\n");
1601 case ltTABLEOFCONTENTS
:
1605 FILE *fd
= fopen(ContentsName
, "r");
1611 putc(ch
, Titlepage
);
1618 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1619 OnInform("Run Tex2RTF again to include contents page.");
1640 TexOutput("<BLOCKQUOTE>");
1642 TexOutput("</BLOCKQUOTE>");
1651 TexOutput("\n<CAPTION>");
1659 if (DocumentStyle
!= LATEX_ARTICLE
)
1660 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1662 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1668 if (DocumentStyle
!= LATEX_ARTICLE
)
1669 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1671 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1679 TexOutput("\n</CAPTION>\n");
1681 char *topicName
= FindTopicName(GetNextChunk());
1683 int n
= inFigure
? figureNo
: tableNo
;
1685 AddTexRef(topicName
, NULL
, NULL
,
1686 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1687 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1693 if (start
) TexOutput("ß");
1698 if (start
) inFigure
= TRUE
;
1699 else inFigure
= FALSE
;
1704 if (start
) inTable
= TRUE
;
1705 else inTable
= FALSE
;
1709 DefaultOnMacro(macroId
, no_args
, start
);
1714 // Called on start/end of argument examination
1715 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1721 case ltCHAPTERHEADING
:
1724 case ltSECTIONHEADING
:
1726 case ltSUBSECTIONSTAR
:
1727 case ltSUBSUBSECTION
:
1728 case ltSUBSUBSECTIONSTAR
:
1730 case ltMEMBERSECTION
:
1731 case ltFUNCTIONSECTION
:
1733 if (!start
&& (arg_no
== 1))
1734 currentSection
= GetArgChunk();
1740 if (start
&& (arg_no
== 1))
1743 if (!start
&& (arg_no
== 1))
1746 if (start
&& (arg_no
== 2))
1748 if (!suppressNameDecoration
) TexOutput("<B>");
1749 currentMember
= GetArgChunk();
1751 if (!start
&& (arg_no
== 2))
1753 if (!suppressNameDecoration
) TexOutput("</B>");
1756 if (start
&& (arg_no
== 3))
1758 if (!start
&& (arg_no
== 3))
1764 if (start
&& (arg_no
== 1))
1766 if (!start
&& (arg_no
== 1))
1769 if (start
&& (arg_no
== 2))
1771 if (!suppressNameDecoration
) TexOutput("( ");
1772 currentMember
= GetArgChunk();
1774 if (!start
&& (arg_no
== 2))
1778 if (!start
&& (arg_no
== 3))
1784 if (!start
&& (arg_no
== 1))
1787 if (start
&& (arg_no
== 2))
1789 if (!start
&& (arg_no
== 2))
1792 if (start
&& (arg_no
== 2))
1793 currentMember
= GetArgChunk();
1795 if (start
&& (arg_no
== 3))
1797 if (!start
&& (arg_no
== 3))
1803 if (start
&& (arg_no
== 1))
1805 if (!start
&& (arg_no
== 1))
1807 if (start
&& (arg_no
== 2))
1811 if (!start
&& (arg_no
== 2))
1819 if (start
&& (arg_no
== 1))
1821 if (!start
&& (arg_no
== 1))
1822 TexOutput("</B> "); // This is the difference from param - one space!
1823 if (start
&& (arg_no
== 2))
1827 if (!start
&& (arg_no
== 2))
1835 if (!start
&& (arg_no
== 1))
1838 if (start
&& (arg_no
== 2))
1839 currentMember
= GetArgChunk();
1848 char *refName
= GetArgData();
1851 TexRef
*texRef
= FindReference(refName
);
1854 sec
= texRef
->sectionNumber
;
1867 if (IsArgOptional())
1869 else if ((GetNoArgs() - arg_no
) == 1)
1872 helpRefText
= GetArgChunk();
1875 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1879 TexChunk
*ref
= GetArgChunk();
1880 TexOutput("<A HREF=\"");
1882 TraverseChildrenFromChunk(ref
);
1886 TraverseChildrenFromChunk(helpRefText
);
1897 if (IsArgOptional())
1900 helpRefFilename
= GetArgChunk();
1903 if ((GetNoArgs() - arg_no
) == 1)
1906 helpRefText
= GetArgChunk();
1909 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1913 char *refName
= GetArgData();
1914 char *refFilename
= NULL
;
1918 TexRef
*texRef
= FindReference(refName
);
1921 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1922 refFilename
= texRef
->refFile
;
1924 TexOutput("<A HREF=\"");
1925 // If a filename is supplied, use it, otherwise try to
1926 // use the filename associated with the reference (from this document).
1927 if (helpRefFilename
)
1929 TraverseChildrenFromChunk(helpRefFilename
);
1932 else if (refFilename
)
1934 TexOutput(ConvertCase(refFilename
));
1940 TraverseChildrenFromChunk(helpRefText
);
1946 TraverseChildrenFromChunk(helpRefText
);
1948 TexOutput(" (REF NOT FOUND)");
1950 errBuf
.Printf("Warning: unresolved reference '%s'", refName
);
1951 OnInform((char *)errBuf
.c_str());
1954 else TexOutput("??");
1969 char *alignment
= "";
1970 if (macroId
== ltIMAGEL
)
1971 alignment
= " align=left";
1972 else if (macroId
== ltIMAGER
)
1973 alignment
= " align=right";
1975 // Try to find an XBM or GIF image first.
1976 char *filename
= copystring(GetArgData());
1979 strcpy(buf
, filename
);
1980 StripExtension(buf
);
1981 strcat(buf
, ".xbm");
1982 wxString f
= TexPathList
.FindValidPath(buf
);
1984 if (f
== "") // Try for a GIF instead
1986 strcpy(buf
, filename
);
1987 StripExtension(buf
);
1988 strcat(buf
, ".gif");
1989 f
= TexPathList
.FindValidPath(buf
);
1992 if (f
== "") // Try for a JPEG instead
1994 strcpy(buf
, filename
);
1995 StripExtension(buf
);
1996 strcat(buf
, ".jpg");
1997 f
= TexPathList
.FindValidPath(buf
);
2000 if (f
== "") // Try for a PNG instead
2002 strcpy(buf
, filename
);
2003 StripExtension(buf
);
2004 strcat(buf
, ".png");
2005 f
= TexPathList
.FindValidPath(buf
);
2010 char *inlineFilename
= copystring(f
);
2012 char *originalFilename
= TexPathList
.FindValidPath(filename
);
2013 // If we have found the existing filename, make the inline
2014 // image point to the original file (could be PS, for example)
2015 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
2017 TexOutput("<A HREF=\"");
2018 TexOutput(ConvertCase(originalFilename
));
2020 TexOutput("<img src=\"");
2021 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2022 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
2027 TexOutput("<img src=\"");
2028 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2029 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
2030 delete[] inlineFilename
;
2035 // Last resort - a link to a PS file.
2036 TexOutput("<A HREF=\"");
2037 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2038 TexOutput("\">Picture</A>\n");
2039 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2047 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2050 static char *imageFile
= NULL
;
2051 if (start
&& (arg_no
== 2))
2053 // Try to find an XBM or GIF image first.
2054 char *filename
= copystring(GetArgData());
2057 strcpy(buf
, filename
);
2058 StripExtension(buf
);
2059 strcat(buf
, ".xbm");
2060 wxString f
= TexPathList
.FindValidPath(buf
);
2062 if (f
== "") // Try for a GIF instead
2064 strcpy(buf
, filename
);
2065 StripExtension(buf
);
2066 strcat(buf
, ".gif");
2067 f
= TexPathList
.FindValidPath(buf
);
2072 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2081 imageFile
= copystring(f
);
2084 else if (start
&& (arg_no
== 3))
2088 // First, try to find a .shg (segmented hypergraphics file)
2089 // that we can convert to a map file
2091 strcpy(buf
, imageFile
);
2092 StripExtension(buf
);
2093 strcat(buf
, ".shg");
2094 wxString f
= TexPathList
.FindValidPath(buf
);
2098 // The default HTML file to go to is THIS file (so a no-op)
2099 SHGToMap((char*) (const char*) f
, currentFileName
);
2102 char *mapName
= GetArgData();
2103 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2107 TexOutput("unknown");
2109 TexOutput("<img src=\"");
2110 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2111 TexOutput("\" ISMAP></A><P>");
2132 descriptionItemArg
= GetArgChunk();
2138 case ltTWOCOLITEMRULED
:
2141 if (start && (arg_no == 1))
2142 TexOutput("\n<DT> ");
2143 if (start && (arg_no == 2))
2150 if (TwoColWidthA
> -1) {
2152 sprintf(buf
,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA
);
2155 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2158 TexOutput("\n</FONT></TD>\n");
2164 if (TwoColWidthB
> -1) {
2166 sprintf(buf
,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB
);
2169 TexOutput("\n<TD VALIGN=TOP>\n");
2172 TexOutput("\n</FONT></TD></TR>\n");
2177 case ltNUMBEREDBIBITEM
:
2179 if (arg_no
== 1 && start
)
2181 TexOutput("\n<DT> ");
2183 if (arg_no
== 2 && !start
)
2190 if (arg_no
== 1 && start
)
2192 char *citeKey
= GetArgData();
2193 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2196 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2197 sprintf(buf
, "[%d]", citeCount
);
2198 ref
->sectionNumber
= copystring(buf
);
2201 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2206 if (arg_no
== 2 && !start
)
2212 case ltMARGINPARODD
:
2213 case ltMARGINPAREVEN
:
2219 TexOutput("<HR>\n");
2223 TexOutput("<HR><P>\n");
2227 case ltTWOCOLWIDTHA
:
2231 char *val
= GetArgData();
2232 float points
= ParseUnitArgument(val
);
2233 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2239 case ltTWOCOLWIDTHB
:
2243 char *val
= GetArgData();
2244 float points
= ParseUnitArgument(val
);
2245 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2254 case ltACCENT_GRAVE
:
2258 char *val
= GetArgData();
2264 TexOutput("à");
2267 TexOutput("è");
2270 TexOutput("ì");
2273 TexOutput("ò");
2276 TexOutput("ù");
2279 TexOutput("À");
2282 TexOutput("È");
2285 TexOutput("Ì");
2288 TexOutput("Ò");
2291 TexOutput("Ì");
2301 case ltACCENT_ACUTE
:
2305 char *val
= GetArgData();
2311 TexOutput("á");
2314 TexOutput("é");
2317 TexOutput("í");
2320 TexOutput("ó");
2323 TexOutput("ú");
2326 TexOutput("ý");
2329 TexOutput("Á");
2332 TexOutput("É");
2335 TexOutput("Í");
2338 TexOutput("Ó");
2341 TexOutput("Ú");
2344 TexOutput("Ý");
2354 case ltACCENT_CARET
:
2358 char *val
= GetArgData();
2364 TexOutput("â");
2367 TexOutput("ê");
2370 TexOutput("î");
2373 TexOutput("ô");
2376 TexOutput("û");
2379 TexOutput("Â");
2382 TexOutput("Ê");
2385 TexOutput("Î");
2388 TexOutput("Ô");
2391 TexOutput("Î");
2401 case ltACCENT_TILDE
:
2405 char *val
= GetArgData();
2414 TexOutput("ã");
2417 TexOutput("ñ");
2420 TexOutput("õ");
2423 TexOutput("Ã");
2426 TexOutput("Ñ");
2429 TexOutput("Õ");
2439 case ltACCENT_UMLAUT
:
2443 char *val
= GetArgData();
2449 TexOutput("ä");
2452 TexOutput("ë");
2455 TexOutput("ï");
2458 TexOutput("ö");
2461 TexOutput("ü");
2464 TexOutput("ÿ");
2467 TexOutput("Ä");
2470 TexOutput("Ë");
2473 TexOutput("Ï");
2476 TexOutput("Ö");
2479 TexOutput("Ü");
2482 TexOutput("Ÿ");
2496 char *val
= GetArgData();
2502 TexOutput("å");
2505 TexOutput("Å");
2519 char *val
= GetArgData();
2522 bool isPicture
= FALSE
;
2523 char *s
= ParseColourString(val
, &isPicture
);
2526 if (backgroundImageString
)
2527 delete[] backgroundImageString
;
2528 backgroundImageString
= copystring(val
);
2532 if (backgroundColourString
)
2533 delete[] backgroundColourString
;
2534 backgroundColourString
= copystring(val
);
2541 case ltBACKGROUNDIMAGE
:
2545 char *val
= GetArgData();
2548 if (backgroundImageString
)
2549 delete[] backgroundImageString
;
2550 backgroundImageString
= copystring(val
);
2556 case ltBACKGROUNDCOLOUR
:
2560 char *val
= GetArgData();
2563 if (backgroundColourString
)
2564 delete[] backgroundColourString
;
2565 backgroundColourString
= copystring(val
);
2575 char *val
= GetArgData();
2578 if (textColourString
)
2579 delete[] textColourString
;
2580 textColourString
= copystring(val
);
2590 char *val
= GetArgData();
2593 if (linkColourString
)
2594 delete[] linkColourString
;
2595 linkColourString
= copystring(val
);
2601 case ltFOLLOWEDLINKCOLOUR
:
2605 char *val
= GetArgData();
2608 if (followedLinkColourString
)
2609 delete[] followedLinkColourString
;
2610 followedLinkColourString
= copystring(val
);
2616 case ltACCENT_CADILLA
:
2620 char *val
= GetArgData();
2626 TexOutput("ç");
2629 TexOutput("Ç");
2641 case ltFOOTNOTEPOPUP:
2651 case ltSUPERTABULAR
:
2657 currentRowNumber
= 0;
2660 tableVerticalLineLeft
= FALSE
;
2661 tableVerticalLineRight
= FALSE
;
2662 int currentWidth
= 0;
2664 char *alignString
= copystring(GetArgData());
2665 ParseTableArgument(alignString
);
2667 TexOutput("<TABLE BORDER>\n");
2669 // Write the first row formatting for compatibility
2670 // with standard Latex
2671 if (compatibilityMode
)
2673 TexOutput("<TR>\n<TD>");
2676 for (int i = 0; i < noColumns; i++)
2678 currentWidth += TableData[i].width;
2679 sprintf(buf, "\\cellx%d", currentWidth);
2682 TexOutput("\\pard\\intbl\n");
2685 delete[] alignString
;
2690 else if (arg_no
== 2 && !start
)
2692 TexOutput("</TABLE>\n");
2697 case ltTHEBIBLIOGRAPHY
:
2699 if (start
&& (arg_no
== 1))
2701 ReopenFile(&Chapters
, &ChaptersName
);
2702 AddTexRef("bibliography", ChaptersName
, "bibliography");
2703 SetCurrentSubsectionName("bibliography", ChaptersName
);
2707 SetCurrentOutput(Chapters
);
2710 if (truncateFilenames
)
2711 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2713 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2716 TexOutput("<title>");
2717 TexOutput(ReferencesNameString
);
2718 TexOutput("</title></head>\n");
2721 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2722 AddBrowseButtons("contents", titleBuf
, // Up
2723 lastTopic
, lastFileName
, // Last topic
2724 "bibliography", ChaptersName
); // This topic
2726 SetCurrentOutputs(Contents
, Chapters
);
2727 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2729 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2730 fprintf(Chapters
, "</H2>\n</A>\n");
2732 SetCurrentOutput(Chapters
);
2735 if (!start
&& (arg_no
== 2))
2743 /* Build up list of keywords associated with topics */
2746 // char *entry = GetArgData();
2748 OutputChunkToString(GetArgChunk(), buf
);
2751 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2766 char *name
= GetArgData();
2768 if (!FindColourHTMLString(name
, buf2
))
2770 strcpy(buf2
, "#000000");
2772 sprintf(buf
, "Could not find colour name %s", name
);
2775 TexOutput("<FONT COLOR=\"");
2791 if (arg_no
== 2) TexOutput("</FONT>");
2796 case ltINSERTATLEVEL
:
2798 // This macro allows you to insert text at a different level
2799 // from the current level, e.g. into the Sections from within a subsubsection.
2802 static int currentLevelNo
= 1;
2803 static FILE* oldLevelFile
= Chapters
;
2810 oldLevelFile
= CurrentOutput1
;
2812 char *str
= GetArgData();
2813 currentLevelNo
= atoi(str
);
2815 // TODO: cope with article style (no chapters)
2816 switch (currentLevelNo
)
2820 outputFile
= Chapters
;
2825 outputFile
= Sections
;
2830 outputFile
= Subsections
;
2835 outputFile
= Subsubsections
;
2845 CurrentOutput1
= outputFile
;
2863 CurrentOutput1
= oldLevelFile
;
2869 return DefaultOnArgument(macroId
, arg_no
, start
);
2882 tableVerticalLineLeft
= FALSE
;
2883 tableVerticalLineRight
= FALSE
;
2886 if (InputFile
&& OutputFile
)
2888 // Do some HTML-specific transformations on all the strings,
2890 Text2HTML(GetTopLevelChunk());
2893 if (truncateFilenames
)
2894 sprintf(buf
, "%s.htm", FileRoot
);
2896 sprintf(buf
, "%s_contents.html", FileRoot
);
2897 if (TitlepageName
) delete[] TitlepageName
;
2898 TitlepageName
= copystring(buf
);
2899 Titlepage
= fopen(buf
, "w");
2901 if (truncateFilenames
)
2902 sprintf(buf
, "%s_fc.htm", FileRoot
);
2904 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2906 contentsFrameName
= copystring(buf
);
2908 Contents
= fopen(TmpContentsName
, "w");
2910 if (htmlFrameContents
)
2912 // FrameContents = fopen(TmpFrameContentsName, "w");
2913 FrameContents
= fopen(contentsFrameName
, "w");
2914 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2917 if (!Titlepage
|| !Contents
)
2919 OnError("Cannot open output file!");
2922 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2924 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2926 fprintf(Contents
, "<UL>\n");
2928 SetCurrentOutput(Titlepage
);
2929 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2930 OnInform("Converting...");
2933 fprintf(Contents
, "</UL>\n\n");
2935 // SetCurrentOutput(Titlepage);
2940 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2947 fprintf(FrameContents
, "\n</UL>\n");
2948 fprintf(FrameContents
, "</HTML>\n");
2949 fclose(FrameContents
);
2950 FrameContents
= NULL
;
2955 fprintf(Chapters
, "\n</FONT></BODY></HTML>\n");
2961 fprintf(Sections
, "\n</FONT></BODY></HTML>\n");
2965 if (Subsections
&& !combineSubSections
)
2967 fprintf(Subsections
, "\n</FONT></BODY></HTML>\n");
2968 fclose(Subsections
);
2971 if (Subsubsections
&& !combineSubSections
)
2973 fprintf(Subsubsections
, "\n</FONT></BODY></HTML>\n");
2974 fclose(Subsubsections
);
2975 Subsubsections
= NULL
;
2977 if ( SectionContentsFD
)
2979 fclose(SectionContentsFD
);
2980 SectionContentsFD
= NULL
;
2983 // Create a temporary file for the title page header, add some info,
2984 // and concat the titlepage just generated.
2985 // This is necessary in order to put the title of the document
2986 // at the TOP of the file within <HEAD>, even though we only find out
2987 // what it is later on.
2988 FILE *tmpTitle
= fopen("title.tmp", "w");
2993 SetCurrentOutput(tmpTitle
);
2995 TexOutput("\n<HEAD><TITLE>");
2996 TraverseChildrenFromChunk(DocumentTitle
);
2997 TexOutput("</TITLE></HEAD>\n");
3001 SetCurrentOutput(tmpTitle
);
3002 HTMLHeadTo(tmpTitle
);
3004 fprintf(tmpTitle
, "<TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
3006 fprintf(tmpTitle
, "<TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
3009 // Output frame information
3010 if (htmlFrameContents
)
3012 char firstFileName
[300];
3013 if (truncateFilenames
)
3014 sprintf(firstFileName
, "%s1.htm", FileRoot
);
3016 sprintf(firstFileName
, "%s1.html", FileRoot
);
3018 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
3020 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
3021 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
3022 fprintf(tmpTitle
, "</FRAMESET>\n");
3024 fprintf(tmpTitle
, "<NOFRAMES>\n");
3027 // Output <BODY...> to temporary title page
3031 FILE *fd
= fopen(TitlepageName
, "r");
3043 fprintf(tmpTitle
, "\n</FONT></BODY>\n");
3045 if (htmlFrameContents
)
3047 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
3049 fprintf(tmpTitle
, "\n</HTML>\n");
3052 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3053 if (!wxRenameFile("title.tmp", TitlepageName
))
3055 wxCopyFile("title.tmp", TitlepageName
);
3056 wxRemoveFile("title.tmp");
3060 if (lastFileName
) delete[] lastFileName
;
3061 lastFileName
= NULL
;
3062 if (lastTopic
) delete[] lastTopic
;
3065 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3067 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3069 wxCopyFile(TmpContentsName
, ContentsName
);
3070 wxRemoveFile(TmpContentsName
);
3073 // Generate .htx file if requested
3076 char htmlIndexName
[300];
3077 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
3078 GenerateHTMLIndexFile(htmlIndexName
);
3081 // Generate HTML Help Workshop files if requested
3082 if (htmlWorkshopFiles
)
3084 HTMLWorkshopEndContents();
3085 GenerateHTMLWorkshopFiles(FileRoot
);
3095 // Output .htx index file
3096 void GenerateHTMLIndexFile(char *fname
)
3098 FILE *fd
= fopen(fname
, "w");
3102 TopicTable
.BeginFind();
3103 wxNode
*node
= NULL
;
3104 while ((node
= TopicTable
.Next()))
3106 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3107 const char *topicName
= node
->GetKeyString();
3108 if (texTopic
->filename
&& texTopic
->keywords
)
3110 wxNode
*node1
= texTopic
->keywords
->First();
3113 char *s
= (char *)node1
->Data();
3114 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3115 node1
= node1
->Next();
3128 // output .hpp, .hhc and .hhk files:
3131 void GenerateHTMLWorkshopFiles(char *fname
)
3136 /* Generate project file : */
3138 sprintf(buf
, "%s.hhp", fname
);
3139 f
= fopen(buf
, "wt");
3142 "Compatibility=1.1\n"
3143 "Full-text search=Yes\n"
3144 "Contents file=%s.hhc\n"
3145 "Compiled file=%s.chm\n"
3146 "Default Window=%sHelp\n"
3147 "Default topic=%s\n"
3148 "Index file=%s.hhk\n"
3150 FileNameFromPath(fname
),
3151 FileNameFromPath(fname
),
3152 FileNameFromPath(fname
),
3153 FileNameFromPath(TitlepageName
),
3154 FileNameFromPath(fname
)
3157 if (DocumentTitle
) {
3158 SetCurrentOutput(f
);
3159 TraverseChildrenFromChunk(DocumentTitle
);
3161 else fprintf(f
, "(unknown)");
3163 fprintf(f
, "\n\n[WINDOWS]\n"
3164 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3165 FileNameFromPath(fname
),
3166 FileNameFromPath(fname
),
3167 FileNameFromPath(fname
),
3168 FileNameFromPath(TitlepageName
));
3171 fprintf(f
, "\n\n[FILES]\n");
3172 fprintf(f
, "%s\n", FileNameFromPath(TitlepageName
));
3173 for (int i
= 1; i
<= fileId
; i
++) {
3174 if (truncateFilenames
)
3175 sprintf(buf
, "%s%d.htm", FileNameFromPath(FileRoot
), i
);
3177 sprintf(buf
, "%s%d.html", FileNameFromPath(FileRoot
), i
);
3178 fprintf(f
, "%s\n", buf
);
3182 /* Generate index file : */
3184 sprintf(buf
, "%s.hhk", fname
);
3185 f
= fopen(buf
, "wt");
3188 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3193 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3194 "<!-- Sitemap 1.0 -->\n"
3196 "<OBJECT type=\"text/site properties\">\n"
3197 " <param name=\"ImageType\" value=\"Folder\">\n"
3201 TopicTable
.BeginFind();
3202 wxNode
*node
= NULL
;
3203 while ((node
= TopicTable
.Next()))
3205 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3206 const char *topicName
= node
->GetKeyString();
3207 if (texTopic
->filename
&& texTopic
->keywords
)
3209 wxNode
*node1
= texTopic
->keywords
->First();
3212 char *s
= (char *)node1
->Data();
3214 " <LI> <OBJECT type=\"text/sitemap\">\n"
3215 " <param name=\"Local\" value=\"%s#%s\">\n"
3216 " <param name=\"Name\" value=\"%s\">\n"
3218 texTopic
->filename
, topicName
, s
);
3219 node1
= node1
->Next();
3224 fprintf(f
, "</UL>\n");
3230 static FILE *HTMLWorkshopContents
= NULL
;
3231 static int HTMLWorkshopLastLevel
= 0;
3233 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3237 if (level
> HTMLWorkshopLastLevel
)
3238 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3239 fprintf(HTMLWorkshopContents
, "<UL>");
3240 if (level
< HTMLWorkshopLastLevel
)
3241 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3242 fprintf(HTMLWorkshopContents
, "</UL>");
3244 SetCurrentOutput(HTMLWorkshopContents
);
3245 fprintf(HTMLWorkshopContents
,
3246 " <LI> <OBJECT type=\"text/sitemap\">\n"
3247 " <param name=\"Local\" value=\"%s#%s\">\n"
3248 " <param name=\"Name\" value=\"",
3250 OutputCurrentSection();
3251 fprintf(HTMLWorkshopContents
,
3254 HTMLWorkshopLastLevel
= level
;
3258 void HTMLWorkshopStartContents()
3261 sprintf(buf
, "%s.hhc", FileRoot
);
3262 HTMLWorkshopContents
= fopen(buf
, "wt");
3263 HTMLWorkshopLastLevel
= 0;
3265 fprintf(HTMLWorkshopContents
,
3266 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3268 HTMLHeadTo(HTMLWorkshopContents
);
3269 fprintf(HTMLWorkshopContents
,
3271 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3272 "<!-- Sitemap 1.0 -->\n"
3274 "<OBJECT type=\"text/site properties\">\n"
3275 " <param name=\"ImageType\" value=\"Folder\">\n"
3278 "<LI> <OBJECT type=\"text/sitemap\">\n"
3279 "<param name=\"Local\" value=\"%s\">\n"
3280 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3281 FileNameFromPath(TitlepageName
)
3287 void HTMLWorkshopEndContents()
3289 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3290 fprintf(HTMLWorkshopContents
, "</UL>\n");
3291 fclose(HTMLWorkshopContents
);