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
);
655 // Called on start/end of macro examination
656 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
662 case ltCHAPTERHEADING
:
670 if (macroId
!= ltCHAPTERSTAR
)
673 SetCurrentOutput(NULL
);
674 startedSections
= TRUE
;
676 char *topicName
= FindTopicName(GetNextChunk());
677 ReopenFile(&Chapters
, &ChaptersName
);
678 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
680 SetCurrentChapterName(topicName
, ChaptersName
);
681 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
683 SetCurrentOutput(Chapters
);
685 TexOutput("<head><title>");
686 OutputCurrentSection(); // Repeat section header
687 TexOutput("</title></head>\n");
691 if (truncateFilenames
)
692 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
694 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
696 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
698 AddBrowseButtons("", titleBuf
, // Up
699 lastTopic
, lastFileName
, // Last topic
700 topicName
, ChaptersName
); // This topic
702 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
704 if (htmlFrameContents
&& FrameContents
)
706 SetCurrentOutput(FrameContents
);
707 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
708 OutputCurrentSection();
709 fprintf(FrameContents
, "</A>\n");
712 SetCurrentOutputs(Contents
, Chapters
);
713 fprintf(Chapters
, "\n<H2>");
714 OutputCurrentSection();
715 fprintf(Contents
, "</A>\n");
716 fprintf(Chapters
, "</H2>\n");
718 SetCurrentOutput(Chapters
);
720 // Add this section title to the list of keywords
723 OutputCurrentSectionToString(wxBuffer
);
724 AddKeyWordForTopic(topicName
, wxBuffer
, ConvertCase(currentFileName
));
731 case ltSECTIONHEADING
:
738 subsectionStarted
= FALSE
;
740 if (macroId
!= ltSECTIONSTAR
)
743 SetCurrentOutput(NULL
);
744 startedSections
= TRUE
;
746 char *topicName
= FindTopicName(GetNextChunk());
747 ReopenFile(&Sections
, &SectionsName
);
748 AddTexRef(topicName
, SectionsName
, SectionNameString
);
750 SetCurrentSectionName(topicName
, SectionsName
);
751 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
753 SetCurrentOutput(Sections
);
754 TexOutput("<head><title>");
755 OutputCurrentSection();
756 TexOutput("</title></head>\n");
759 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
760 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
761 lastTopic
, lastFileName
, // Last topic
762 topicName
, SectionsName
); // This topic
764 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
766 SetCurrentOutputs(jumpFrom
, Sections
);
767 if (DocumentStyle
== LATEX_ARTICLE
)
768 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
770 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
772 fprintf(Sections
, "\n<H2>");
773 OutputCurrentSection();
775 if (DocumentStyle
== LATEX_ARTICLE
)
776 fprintf(jumpFrom
, "</A>\n");
778 fprintf(jumpFrom
, "</B></A><BR>\n");
779 fprintf(Sections
, "</H2>\n");
781 SetCurrentOutput(Sections
);
782 // Add this section title to the list of keywords
785 OutputCurrentSectionToString(wxBuffer
);
786 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
792 case ltSUBSECTIONSTAR
:
793 case ltMEMBERSECTION
:
794 case ltFUNCTIONSECTION
:
800 OnError("You cannot have a subsection before a section!");
806 if (macroId
!= ltSUBSECTIONSTAR
)
809 if ( combineSubSections
&& !subsectionStarted
)
811 // Read old .con file in at this point
813 strcpy(buf
, CurrentSectionFile
);
814 wxStripExtension(buf
);
816 FILE *fd
= fopen(buf
, "r");
827 fprintf(Sections
, "<P>\n");
829 // Close old file, create a new file for the sub(sub)section contents entries
830 ReopenSectionContentsFile();
833 startedSections
= TRUE
;
834 subsectionStarted
= TRUE
;
836 char *topicName
= FindTopicName(GetNextChunk());
838 if ( !combineSubSections
)
840 SetCurrentOutput(NULL
);
841 ReopenFile(&Subsections
, &SubsectionsName
);
842 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
843 SetCurrentSubsectionName(topicName
, SubsectionsName
);
844 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
845 SetCurrentOutput(Subsections
);
847 TexOutput("<head><title>");
848 OutputCurrentSection();
849 TexOutput("</title></head>\n");
852 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
853 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
854 lastTopic
, lastFileName
, // Last topic
855 topicName
, SubsectionsName
); // This topic
857 SetCurrentOutputs(Sections
, Subsections
);
858 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
860 fprintf(Subsections
, "\n<H3>");
861 OutputCurrentSection();
862 fprintf(Sections
, "</B></A><BR>\n");
863 fprintf(Subsections
, "</H3>\n");
865 SetCurrentOutput(Subsections
);
869 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
870 SetCurrentSubsectionName(topicName
, SectionsName
);
872 // if ( subsectionNo != 0 )
873 fprintf(Sections
, "\n<HR>\n");
875 // We're putting everything into the section file
876 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
877 fprintf(Sections
, "\n<H3>");
878 OutputCurrentSection();
879 fprintf(Sections
, "</H3>\n");
881 SetCurrentOutput(SectionContentsFD
);
882 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
883 OutputCurrentSection();
884 TexOutput("</A><BR>\n");
886 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
887 SetCurrentOutput(Sections
);
889 // Add this section title to the list of keywords
892 OutputCurrentSectionToString(wxBuffer
);
893 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
900 case ltSUBSUBSECTION
:
901 case ltSUBSUBSECTIONSTAR
:
905 if (!Subsections
&& !combineSubSections
)
907 OnError("You cannot have a subsubsection before a subsection!");
911 if (macroId
!= ltSUBSUBSECTIONSTAR
)
914 startedSections
= TRUE
;
916 char *topicName
= FindTopicName(GetNextChunk());
918 if ( !combineSubSections
)
920 SetCurrentOutput(NULL
);
921 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
922 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
923 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
924 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
926 SetCurrentOutput(Subsubsections
);
927 TexOutput("<head><title>");
928 OutputCurrentSection();
929 TexOutput("</title></head>\n");
932 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
934 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
935 lastTopic
, lastFileName
, // Last topic
936 topicName
, SubsubsectionsName
); // This topic
938 SetCurrentOutputs(Subsections
, Subsubsections
);
939 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
941 fprintf(Subsubsections
, "\n<H3>");
942 OutputCurrentSection();
943 fprintf(Subsections
, "</B></A><BR>\n");
944 fprintf(Subsubsections
, "</H3>\n");
948 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
949 SetCurrentSubsectionName(topicName
, SectionsName
);
950 fprintf(Sections
, "\n<HR>\n");
952 // We're putting everything into the section file
953 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
954 fprintf(Sections
, "\n<H3>");
955 OutputCurrentSection();
956 fprintf(Sections
, "</H3>\n");
957 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
958 SetCurrentOutput(SectionContentsFD);
959 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
960 OutputCurrentSection();
961 TexOutput("</A><BR>");
963 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
964 SetCurrentOutput(Sections
);
967 // Add this section title to the list of keywords
970 OutputCurrentSectionToString(wxBuffer
);
971 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
980 if ( !combineSubSections
)
981 SetCurrentOutput(Subsections
);
983 SetCurrentOutput(Sections
);
994 if ( !combineSubSections
)
995 SetCurrentOutput(Subsections
);
997 SetCurrentOutput(Sections
);
1008 if ( !combineSubSections
)
1009 SetCurrentOutput(Subsections
);
1011 SetCurrentOutput(Sections
);
1022 // TexOutput("<B>void</B>");
1030 TexOutput("wxCLIPS");
1036 case ltSPECIALAMPERSAND
:
1042 // End cell, start cell
1044 TexOutput("</FONT></TD>");
1046 // Start new row and cell, setting alignment for the first cell.
1047 if (currentColumn
< noColumns
)
1051 if (TableData
[currentColumn
].justification
== 'c')
1052 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1053 else if (TableData
[currentColumn
].justification
== 'r')
1054 sprintf(buf
, "\n<TD ALIGN=RIGHT>");
1055 else if (TableData
[currentColumn
].absWidth
)
1057 // Convert from points * 20 into pixels.
1058 int points
= TableData
[currentColumn
].width
/ 20;
1060 // Say the display is 100 DPI (dots/pixels per inch).
1061 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1062 int pixels
= (int)(points
* 100.0 / 72.0);
1063 sprintf(buf
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1066 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1075 case ltBACKSLASHCHAR
:
1081 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1082 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1083 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1084 TexOutput("</TR>\n");
1087 TexOutput("<BR>\n");
1098 // Start new row and cell, setting alignment for the first cell.
1100 if (TableData
[currentColumn
].justification
== 'c')
1101 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1102 else if (TableData
[currentColumn
].justification
== 'r')
1103 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1104 else if (TableData
[currentColumn
].absWidth
)
1106 // Convert from points * 20 into pixels.
1107 int points
= TableData
[currentColumn
].width
/ 20;
1109 // Say the display is 100 DPI (dots/pixels per inch).
1110 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1111 int pixels
= (int)(points
* 100.0 / 72.0);
1112 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1115 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1122 // Start new row and cell
1123 TexOutput("</FONT></TD>\n</TR>\n");
1127 // HTML-only: break until the end of the picture (both margins are clear).
1131 TexOutput("<BR CLEAR=ALL>");
1134 case ltRTFSP
: // Explicit space, RTF only
1136 case ltSPECIALTILDE
:
1150 TexOutput("<UL><UL>\n");
1152 TexOutput("</UL></UL>\n");
1158 // case ltTWOCOLLIST:
1165 if (macroId
== ltENUMERATE
)
1166 listType
= LATEX_ENUMERATE
;
1167 else if (macroId
== ltITEMIZE
)
1168 listType
= LATEX_ITEMIZE
;
1170 listType
= LATEX_DESCRIPTION
;
1172 itemizeStack
.Insert(new ItemizeStruc(listType
));
1176 TexOutput("<UL>\n");
1178 case LATEX_ENUMERATE
:
1179 TexOutput("<OL>\n");
1181 case LATEX_DESCRIPTION
:
1183 TexOutput("<DL>\n");
1190 if (itemizeStack
.First())
1192 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1193 switch (struc
->listType
)
1196 TexOutput("</UL>\n");
1198 case LATEX_ENUMERATE
:
1199 TexOutput("</OL>\n");
1201 case LATEX_DESCRIPTION
:
1203 TexOutput("</DL>\n");
1208 delete itemizeStack
.First();
1216 TexOutput("\n<TABLE>\n");
1218 TexOutput("\n</TABLE>\n");
1231 /* For footnotes we need to output the text at the bottom of the page and
1232 * insert a reference to it. Is it worth the trouble...
1234 case ltFOOTNOTEPOPUP:
1240 else TexOutput("</FN>");
1248 else TexOutput("</TT>");
1256 sprintf(buf
, "<PRE>\n");
1259 else TexOutput("</PRE>\n");
1267 TexOutput("<CENTER>");
1269 else TexOutput("</CENTER>");
1277 TexOutput("{\\ql ");
1279 else TexOutput("}\\par\\pard\n");
1288 TexOutput("{\\qr ");
1290 else TexOutput("}\\par\\pard\n");
1298 // Netscape extension
1299 TexOutput("<FONT SIZE=2>");
1301 else TexOutput("</FONT>");
1308 // Netscape extension
1309 TexOutput("<FONT SIZE=1>");
1311 else TexOutput("</FONT>");
1318 // Netscape extension
1319 TexOutput("<FONT SIZE=3>");
1321 else TexOutput("</FONT>");
1328 // Netscape extension
1329 TexOutput("<FONT SIZE=4>");
1331 else TexOutput("</FONT>");
1338 // Netscape extension
1339 TexOutput("<FONT SIZE=5>");
1341 else TexOutput("</FONT>");
1348 // Netscape extension
1349 TexOutput("<FONT SIZE=6>");
1351 else TexOutput("</FONT>");
1362 else TexOutput("</B>");
1373 else TexOutput("</I>");
1383 else TexOutput("</EM>");
1392 else TexOutput("</UL>");
1403 else TexOutput("</TT>");
1409 TexOutput("©", TRUE
);
1415 TexOutput("®", TRUE
);
1421 if (start
) TexOutput("<--");
1426 if (start
) TexOutput("<==");
1431 if (start
) TexOutput("-->");
1436 if (start
) TexOutput("==>");
1439 case ltLEFTRIGHTARROW
:
1441 if (start
) TexOutput("<-->");
1444 case ltLEFTRIGHTARROW2
:
1446 if (start
) TexOutput("<==>");
1459 wxNode
*node
= itemizeStack
.First();
1462 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1463 struc
->currentItem
+= 1;
1464 if (struc
->listType
== LATEX_DESCRIPTION
)
1466 if (descriptionItemArg
)
1469 TraverseChildrenFromChunk(descriptionItemArg
);
1471 descriptionItemArg
= NULL
;
1483 if (start
&& DocumentTitle
&& DocumentAuthor
)
1485 // Add a special label for the contents page.
1486 // TexOutput("<CENTER>\n");
1487 TexOutput("<A NAME=\"contents\">");
1488 TexOutput("<H2 ALIGN=CENTER>\n");
1489 TraverseChildrenFromChunk(DocumentTitle
);
1492 TexOutput("</A>\n");
1493 TexOutput("<P>\n\n");
1494 TexOutput("<H3 ALIGN=CENTER>");
1495 TraverseChildrenFromChunk(DocumentAuthor
);
1496 TexOutput("</H3><P>\n\n");
1499 TexOutput("<H3 ALIGN=CENTER>");
1500 TraverseChildrenFromChunk(DocumentDate
);
1501 TexOutput("</H3><P>\n\n");
1503 // TexOutput("\n</CENTER>\n");
1504 TexOutput("\n<P><HR><P>\n");
1507 // Now do optional frame contents page
1508 if (htmlFrameContents && FrameContents)
1510 SetCurrentOutput(FrameContents);
1512 // Add a special label for the contents page.
1513 TexOutput("<CENTER>\n");
1514 TexOutput("<H3>\n");
1515 TraverseChildrenFromChunk(DocumentTitle);
1518 TexOutput("</A>\n");
1519 TexOutput("<P>\n\n");
1521 TraverseChildrenFromChunk(DocumentAuthor);
1522 TexOutput("</H3><P>\n\n");
1526 TraverseChildrenFromChunk(DocumentDate);
1527 TexOutput("</H4><P>\n\n");
1529 TexOutput("\n</CENTER>\n");
1530 TexOutput("<P><HR><P>\n");
1532 SetCurrentOutput(Titlepage);
1545 helpRefFilename
= NULL
;
1550 case ltBIBLIOGRAPHY
:
1554 DefaultOnMacro(macroId
, no_args
, start
);
1558 DefaultOnMacro(macroId
, no_args
, start
);
1559 TexOutput("</DL>\n");
1567 TexOutput("<HR>\n");
1575 TexOutput("<HR>\n");
1579 case ltTABLEOFCONTENTS
:
1583 FILE *fd
= fopen(ContentsName
, "r");
1589 putc(ch
, Titlepage
);
1596 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1597 OnInform("Run Tex2RTF again to include contents page.");
1618 TexOutput("<BLOCKQUOTE>");
1620 TexOutput("</BLOCKQUOTE>");
1629 TexOutput("\n<CAPTION>");
1637 if (DocumentStyle
!= LATEX_ARTICLE
)
1638 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1640 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1646 if (DocumentStyle
!= LATEX_ARTICLE
)
1647 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1649 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1657 TexOutput("\n</CAPTION>\n");
1659 char *topicName
= FindTopicName(GetNextChunk());
1661 int n
= inFigure
? figureNo
: tableNo
;
1663 AddTexRef(topicName
, NULL
, NULL
,
1664 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1665 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1671 if (start
) TexOutput("ß");
1676 if (start
) inFigure
= TRUE
;
1677 else inFigure
= FALSE
;
1682 if (start
) inTable
= TRUE
;
1683 else inTable
= FALSE
;
1687 DefaultOnMacro(macroId
, no_args
, start
);
1692 // Called on start/end of argument examination
1693 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1699 case ltCHAPTERHEADING
:
1702 case ltSECTIONHEADING
:
1704 case ltSUBSECTIONSTAR
:
1705 case ltSUBSUBSECTION
:
1706 case ltSUBSUBSECTIONSTAR
:
1708 case ltMEMBERSECTION
:
1709 case ltFUNCTIONSECTION
:
1711 if (!start
&& (arg_no
== 1))
1712 currentSection
= GetArgChunk();
1718 if (start
&& (arg_no
== 1))
1721 if (!start
&& (arg_no
== 1))
1724 if (start
&& (arg_no
== 2))
1726 if (!suppressNameDecoration
) TexOutput("<B>");
1727 currentMember
= GetArgChunk();
1729 if (!start
&& (arg_no
== 2))
1731 if (!suppressNameDecoration
) TexOutput("</B>");
1734 if (start
&& (arg_no
== 3))
1736 if (!start
&& (arg_no
== 3))
1742 if (start
&& (arg_no
== 1))
1744 if (!start
&& (arg_no
== 1))
1747 if (start
&& (arg_no
== 2))
1749 if (!suppressNameDecoration
) TexOutput("( ");
1750 currentMember
= GetArgChunk();
1752 if (!start
&& (arg_no
== 2))
1756 if (!start
&& (arg_no
== 3))
1762 if (!start
&& (arg_no
== 1))
1765 if (start
&& (arg_no
== 2))
1767 if (!start
&& (arg_no
== 2))
1770 if (start
&& (arg_no
== 2))
1771 currentMember
= GetArgChunk();
1773 if (start
&& (arg_no
== 3))
1775 if (!start
&& (arg_no
== 3))
1781 if (start
&& (arg_no
== 1))
1783 if (!start
&& (arg_no
== 1))
1785 if (start
&& (arg_no
== 2))
1789 if (!start
&& (arg_no
== 2))
1797 if (start
&& (arg_no
== 1))
1799 if (!start
&& (arg_no
== 1))
1800 TexOutput("</B> "); // This is the difference from param - one space!
1801 if (start
&& (arg_no
== 2))
1805 if (!start
&& (arg_no
== 2))
1813 if (!start
&& (arg_no
== 1))
1816 if (start
&& (arg_no
== 2))
1817 currentMember
= GetArgChunk();
1826 char *refName
= GetArgData();
1829 TexRef
*texRef
= FindReference(refName
);
1832 sec
= texRef
->sectionNumber
;
1845 if (IsArgOptional())
1847 else if ((GetNoArgs() - arg_no
) == 1)
1850 helpRefText
= GetArgChunk();
1853 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1857 TexChunk
*ref
= GetArgChunk();
1858 TexOutput("<A HREF=\"");
1860 TraverseChildrenFromChunk(ref
);
1864 TraverseChildrenFromChunk(helpRefText
);
1875 if (IsArgOptional())
1878 helpRefFilename
= GetArgChunk();
1881 if ((GetNoArgs() - arg_no
) == 1)
1884 helpRefText
= GetArgChunk();
1887 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1891 char *refName
= GetArgData();
1892 char *refFilename
= NULL
;
1896 TexRef
*texRef
= FindReference(refName
);
1899 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1900 refFilename
= texRef
->refFile
;
1902 TexOutput("<A HREF=\"");
1903 // If a filename is supplied, use it, otherwise try to
1904 // use the filename associated with the reference (from this document).
1905 if (helpRefFilename
)
1907 TraverseChildrenFromChunk(helpRefFilename
);
1910 else if (refFilename
)
1912 TexOutput(ConvertCase(refFilename
));
1918 TraverseChildrenFromChunk(helpRefText
);
1924 TraverseChildrenFromChunk(helpRefText
);
1926 TexOutput(" (REF NOT FOUND)");
1928 errBuf
.Printf("Warning: unresolved reference '%s'", refName
);
1929 OnInform((char *)errBuf
.c_str());
1932 else TexOutput("??");
1947 char *alignment
= "";
1948 if (macroId
== ltIMAGEL
)
1949 alignment
= " align=left";
1950 else if (macroId
== ltIMAGER
)
1951 alignment
= " align=right";
1953 // Try to find an XBM or GIF image first.
1954 char *filename
= copystring(GetArgData());
1957 strcpy(buf
, filename
);
1958 StripExtension(buf
);
1959 strcat(buf
, ".xbm");
1960 wxString f
= TexPathList
.FindValidPath(buf
);
1962 if (f
== "") // Try for a GIF instead
1964 strcpy(buf
, filename
);
1965 StripExtension(buf
);
1966 strcat(buf
, ".gif");
1967 f
= TexPathList
.FindValidPath(buf
);
1970 if (f
== "") // Try for a JPEG instead
1972 strcpy(buf
, filename
);
1973 StripExtension(buf
);
1974 strcat(buf
, ".jpg");
1975 f
= TexPathList
.FindValidPath(buf
);
1978 if (f
== "") // Try for a PNG instead
1980 strcpy(buf
, filename
);
1981 StripExtension(buf
);
1982 strcat(buf
, ".png");
1983 f
= TexPathList
.FindValidPath(buf
);
1988 char *inlineFilename
= copystring(f
);
1990 char *originalFilename
= TexPathList
.FindValidPath(filename
);
1991 // If we have found the existing filename, make the inline
1992 // image point to the original file (could be PS, for example)
1993 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
1995 TexOutput("<A HREF=\"");
1996 TexOutput(ConvertCase(originalFilename
));
1998 TexOutput("<img src=\"");
1999 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2000 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
2005 TexOutput("<img src=\"");
2006 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2007 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
2008 delete[] inlineFilename
;
2013 // Last resort - a link to a PS file.
2014 TexOutput("<A HREF=\"");
2015 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2016 TexOutput("\">Picture</A>\n");
2017 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2025 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2028 static char *imageFile
= NULL
;
2029 if (start
&& (arg_no
== 2))
2031 // Try to find an XBM or GIF image first.
2032 char *filename
= copystring(GetArgData());
2035 strcpy(buf
, filename
);
2036 StripExtension(buf
);
2037 strcat(buf
, ".xbm");
2038 wxString f
= TexPathList
.FindValidPath(buf
);
2040 if (f
== "") // Try for a GIF instead
2042 strcpy(buf
, filename
);
2043 StripExtension(buf
);
2044 strcat(buf
, ".gif");
2045 f
= TexPathList
.FindValidPath(buf
);
2050 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2059 imageFile
= copystring(f
);
2062 else if (start
&& (arg_no
== 3))
2066 // First, try to find a .shg (segmented hypergraphics file)
2067 // that we can convert to a map file
2069 strcpy(buf
, imageFile
);
2070 StripExtension(buf
);
2071 strcat(buf
, ".shg");
2072 wxString f
= TexPathList
.FindValidPath(buf
);
2076 // The default HTML file to go to is THIS file (so a no-op)
2077 SHGToMap((char*) (const char*) f
, currentFileName
);
2080 char *mapName
= GetArgData();
2081 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2085 TexOutput("unknown");
2087 TexOutput("<img src=\"");
2088 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2089 TexOutput("\" ISMAP></A><P>");
2110 descriptionItemArg
= GetArgChunk();
2115 case ltTWOCOLITEMRULED
:
2118 if (start && (arg_no == 1))
2119 TexOutput("\n<DT> ");
2120 if (start && (arg_no == 2))
2127 if (TwoColWidthA
> -1) {
2129 sprintf(buf
,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA
);
2132 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2135 TexOutput("\n</FONT></TD>\n");
2141 if (TwoColWidthB
> -1) {
2143 sprintf(buf
,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB
);
2146 TexOutput("\n<TD VALIGN=TOP>\n");
2149 TexOutput("\n</FONT></TD></TR>\n");
2154 case ltNUMBEREDBIBITEM
:
2156 if (arg_no
== 1 && start
)
2158 TexOutput("\n<DT> ");
2160 if (arg_no
== 2 && !start
)
2167 if (arg_no
== 1 && start
)
2169 char *citeKey
= GetArgData();
2170 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2173 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2174 sprintf(buf
, "[%d]", citeCount
);
2175 ref
->sectionNumber
= copystring(buf
);
2178 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2183 if (arg_no
== 2 && !start
)
2189 case ltMARGINPARODD
:
2190 case ltMARGINPAREVEN
:
2196 TexOutput("<HR>\n");
2200 TexOutput("<HR><P>\n");
2204 case ltTWOCOLWIDTHA
:
2208 char *val
= GetArgData();
2209 float points
= ParseUnitArgument(val
);
2210 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2216 case ltTWOCOLWIDTHB
:
2220 char *val
= GetArgData();
2221 float points
= ParseUnitArgument(val
);
2222 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2231 case ltACCENT_GRAVE
:
2235 char *val
= GetArgData();
2241 TexOutput("à");
2244 TexOutput("è");
2247 TexOutput("ì");
2250 TexOutput("ò");
2253 TexOutput("ù");
2256 TexOutput("À");
2259 TexOutput("È");
2262 TexOutput("Ì");
2265 TexOutput("Ò");
2268 TexOutput("Ì");
2278 case ltACCENT_ACUTE
:
2282 char *val
= GetArgData();
2288 TexOutput("á");
2291 TexOutput("é");
2294 TexOutput("í");
2297 TexOutput("ó");
2300 TexOutput("ú");
2303 TexOutput("ý");
2306 TexOutput("Á");
2309 TexOutput("É");
2312 TexOutput("Í");
2315 TexOutput("Ó");
2318 TexOutput("Ú");
2321 TexOutput("Ý");
2331 case ltACCENT_CARET
:
2335 char *val
= GetArgData();
2341 TexOutput("â");
2344 TexOutput("ê");
2347 TexOutput("î");
2350 TexOutput("ô");
2353 TexOutput("û");
2356 TexOutput("Â");
2359 TexOutput("Ê");
2362 TexOutput("Î");
2365 TexOutput("Ô");
2368 TexOutput("Î");
2378 case ltACCENT_TILDE
:
2382 char *val
= GetArgData();
2391 TexOutput("ã");
2394 TexOutput("ñ");
2397 TexOutput("õ");
2400 TexOutput("Ã");
2403 TexOutput("Ñ");
2406 TexOutput("Õ");
2416 case ltACCENT_UMLAUT
:
2420 char *val
= GetArgData();
2426 TexOutput("ä");
2429 TexOutput("ë");
2432 TexOutput("ï");
2435 TexOutput("ö");
2438 TexOutput("ü");
2441 TexOutput("ÿ");
2444 TexOutput("Ä");
2447 TexOutput("Ë");
2450 TexOutput("Ï");
2453 TexOutput("Ö");
2456 TexOutput("Ü");
2459 TexOutput("Ÿ");
2473 char *val
= GetArgData();
2479 TexOutput("å");
2482 TexOutput("Å");
2496 char *val
= GetArgData();
2499 bool isPicture
= FALSE
;
2500 char *s
= ParseColourString(val
, &isPicture
);
2503 if (backgroundImageString
)
2504 delete[] backgroundImageString
;
2505 backgroundImageString
= copystring(val
);
2509 if (backgroundColourString
)
2510 delete[] backgroundColourString
;
2511 backgroundColourString
= copystring(val
);
2518 case ltBACKGROUNDIMAGE
:
2522 char *val
= GetArgData();
2525 if (backgroundImageString
)
2526 delete[] backgroundImageString
;
2527 backgroundImageString
= copystring(val
);
2533 case ltBACKGROUNDCOLOUR
:
2537 char *val
= GetArgData();
2540 if (backgroundColourString
)
2541 delete[] backgroundColourString
;
2542 backgroundColourString
= copystring(val
);
2552 char *val
= GetArgData();
2555 if (textColourString
)
2556 delete[] textColourString
;
2557 textColourString
= copystring(val
);
2567 char *val
= GetArgData();
2570 if (linkColourString
)
2571 delete[] linkColourString
;
2572 linkColourString
= copystring(val
);
2578 case ltFOLLOWEDLINKCOLOUR
:
2582 char *val
= GetArgData();
2585 if (followedLinkColourString
)
2586 delete[] followedLinkColourString
;
2587 followedLinkColourString
= copystring(val
);
2593 case ltACCENT_CADILLA
:
2597 char *val
= GetArgData();
2603 TexOutput("ç");
2606 TexOutput("Ç");
2618 case ltFOOTNOTEPOPUP:
2628 case ltSUPERTABULAR
:
2634 currentRowNumber
= 0;
2637 tableVerticalLineLeft
= FALSE
;
2638 tableVerticalLineRight
= FALSE
;
2639 int currentWidth
= 0;
2641 char *alignString
= copystring(GetArgData());
2642 ParseTableArgument(alignString
);
2644 TexOutput("<TABLE BORDER>\n");
2646 // Write the first row formatting for compatibility
2647 // with standard Latex
2648 if (compatibilityMode
)
2650 TexOutput("<TR>\n<TD>");
2653 for (int i = 0; i < noColumns; i++)
2655 currentWidth += TableData[i].width;
2656 sprintf(buf, "\\cellx%d", currentWidth);
2659 TexOutput("\\pard\\intbl\n");
2662 delete[] alignString
;
2667 else if (arg_no
== 2 && !start
)
2669 TexOutput("</TABLE>\n");
2674 case ltTHEBIBLIOGRAPHY
:
2676 if (start
&& (arg_no
== 1))
2678 ReopenFile(&Chapters
, &ChaptersName
);
2679 AddTexRef("bibliography", ChaptersName
, "bibliography");
2680 SetCurrentSubsectionName("bibliography", ChaptersName
);
2684 SetCurrentOutput(Chapters
);
2687 if (truncateFilenames
)
2688 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2690 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2692 TexOutput("<head><title>");
2693 TexOutput(ReferencesNameString
);
2694 TexOutput("</title></head>\n");
2697 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2698 AddBrowseButtons("contents", titleBuf
, // Up
2699 lastTopic
, lastFileName
, // Last topic
2700 "bibliography", ChaptersName
); // This topic
2702 SetCurrentOutputs(Contents
, Chapters
);
2703 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2705 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2706 fprintf(Chapters
, "</H2>\n</A>\n");
2708 SetCurrentOutput(Chapters
);
2711 if (!start
&& (arg_no
== 2))
2719 /* Build up list of keywords associated with topics */
2722 // char *entry = GetArgData();
2724 OutputChunkToString(GetArgChunk(), buf
);
2727 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2742 char *name
= GetArgData();
2744 if (!FindColourHTMLString(name
, buf2
))
2746 strcpy(buf2
, "#000000");
2748 sprintf(buf
, "Could not find colour name %s", name
);
2751 TexOutput("<FONT COLOR=\"");
2767 if (arg_no
== 2) TexOutput("</FONT>");
2772 case ltINSERTATLEVEL
:
2774 // This macro allows you to insert text at a different level
2775 // from the current level, e.g. into the Sections from within a subsubsection.
2778 static int currentLevelNo
= 1;
2779 static FILE* oldLevelFile
= Chapters
;
2786 oldLevelFile
= CurrentOutput1
;
2788 char *str
= GetArgData();
2789 currentLevelNo
= atoi(str
);
2791 // TODO: cope with article style (no chapters)
2792 switch (currentLevelNo
)
2796 outputFile
= Chapters
;
2801 outputFile
= Sections
;
2806 outputFile
= Subsections
;
2811 outputFile
= Subsubsections
;
2821 CurrentOutput1
= outputFile
;
2839 CurrentOutput1
= oldLevelFile
;
2845 return DefaultOnArgument(macroId
, arg_no
, start
);
2858 tableVerticalLineLeft
= FALSE
;
2859 tableVerticalLineRight
= FALSE
;
2862 if (InputFile
&& OutputFile
)
2864 // Do some HTML-specific transformations on all the strings,
2866 Text2HTML(GetTopLevelChunk());
2869 if (truncateFilenames
)
2870 sprintf(buf
, "%s.htm", FileRoot
);
2872 sprintf(buf
, "%s_contents.html", FileRoot
);
2873 if (TitlepageName
) delete[] TitlepageName
;
2874 TitlepageName
= copystring(buf
);
2875 Titlepage
= fopen(buf
, "w");
2877 if (truncateFilenames
)
2878 sprintf(buf
, "%s_fc.htm", FileRoot
);
2880 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2882 contentsFrameName
= copystring(buf
);
2884 Contents
= fopen(TmpContentsName
, "w");
2886 if (htmlFrameContents
)
2888 // FrameContents = fopen(TmpFrameContentsName, "w");
2889 FrameContents
= fopen(contentsFrameName
, "w");
2890 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2893 if (!Titlepage
|| !Contents
)
2895 OnError("Cannot open output file!");
2898 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2900 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2902 fprintf(Contents
, "<UL>\n");
2904 SetCurrentOutput(Titlepage
);
2905 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2906 OnInform("Converting...");
2909 fprintf(Contents
, "</UL>\n\n");
2911 // SetCurrentOutput(Titlepage);
2916 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2923 fprintf(FrameContents
, "\n</UL>\n");
2924 fprintf(FrameContents
, "</HTML>\n");
2925 fclose(FrameContents
);
2926 FrameContents
= NULL
;
2931 fprintf(Chapters
, "\n</FONT></BODY></HTML>\n");
2937 fprintf(Sections
, "\n</FONT></BODY></HTML>\n");
2941 if (Subsections
&& !combineSubSections
)
2943 fprintf(Subsections
, "\n</FONT></BODY></HTML>\n");
2944 fclose(Subsections
);
2947 if (Subsubsections
&& !combineSubSections
)
2949 fprintf(Subsubsections
, "\n</FONT></BODY></HTML>\n");
2950 fclose(Subsubsections
);
2951 Subsubsections
= NULL
;
2953 if ( SectionContentsFD
)
2955 fclose(SectionContentsFD
);
2956 SectionContentsFD
= NULL
;
2959 // Create a temporary file for the title page header, add some info,
2960 // and concat the titlepage just generated.
2961 // This is necessary in order to put the title of the document
2962 // at the TOP of the file within <HEAD>, even though we only find out
2963 // what it is later on.
2964 FILE *tmpTitle
= fopen("title.tmp", "w");
2969 SetCurrentOutput(tmpTitle
);
2970 TexOutput("\n<HTML>\n<HEAD><TITLE>");
2971 TraverseChildrenFromChunk(DocumentTitle
);
2972 TexOutput("</TITLE></HEAD>\n");
2976 SetCurrentOutput(tmpTitle
);
2978 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
2980 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
2983 // Output frame information
2984 if (htmlFrameContents
)
2986 char firstFileName
[300];
2987 if (truncateFilenames
)
2988 sprintf(firstFileName
, "%s1.htm", FileRoot
);
2990 sprintf(firstFileName
, "%s1.html", FileRoot
);
2992 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
2994 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
2995 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
2996 fprintf(tmpTitle
, "</FRAMESET>\n");
2998 fprintf(tmpTitle
, "<NOFRAMES>\n");
3001 // Output <BODY...> to temporary title page
3005 FILE *fd
= fopen(TitlepageName
, "r");
3017 fprintf(tmpTitle
, "\n</FONT></BODY>\n");
3019 if (htmlFrameContents
)
3021 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
3023 fprintf(tmpTitle
, "\n</HTML>\n");
3026 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3027 if (!wxRenameFile("title.tmp", TitlepageName
))
3029 wxCopyFile("title.tmp", TitlepageName
);
3030 wxRemoveFile("title.tmp");
3034 if (lastFileName
) delete[] lastFileName
;
3035 lastFileName
= NULL
;
3036 if (lastTopic
) delete[] lastTopic
;
3039 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3041 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3043 wxCopyFile(TmpContentsName
, ContentsName
);
3044 wxRemoveFile(TmpContentsName
);
3047 // Generate .htx file if requested
3050 char htmlIndexName
[300];
3051 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
3052 GenerateHTMLIndexFile(htmlIndexName
);
3055 // Generate HTML Help Workshop files if requested
3056 if (htmlWorkshopFiles
)
3058 HTMLWorkshopEndContents();
3059 GenerateHTMLWorkshopFiles(FileRoot
);
3069 // Output .htx index file
3070 void GenerateHTMLIndexFile(char *fname
)
3072 FILE *fd
= fopen(fname
, "w");
3076 TopicTable
.BeginFind();
3077 wxNode
*node
= NULL
;
3078 while ((node
= TopicTable
.Next()))
3080 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3081 const char *topicName
= node
->GetKeyString();
3082 if (texTopic
->filename
&& texTopic
->keywords
)
3084 wxNode
*node1
= texTopic
->keywords
->First();
3087 char *s
= (char *)node1
->Data();
3088 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3089 node1
= node1
->Next();
3102 // output .hpp, .hhc and .hhk files:
3105 void GenerateHTMLWorkshopFiles(char *fname
)
3110 /* Generate project file : */
3112 sprintf(buf
, "%s.hhp", fname
);
3113 f
= fopen(buf
, "wt");
3116 "Compatibility=1.1\n"
3117 "Full-text search=Yes\n"
3118 "Contents file=%s.hhc\n"
3119 "Compiled file=%s.chm\n"
3120 "Default Window=%sHelp\n"
3121 "Default topic=%s\n"
3122 "Index file=%s.hhk\n"
3124 FileNameFromPath(fname
),
3125 FileNameFromPath(fname
),
3126 FileNameFromPath(fname
),
3127 FileNameFromPath(TitlepageName
),
3128 FileNameFromPath(fname
)
3131 if (DocumentTitle
) {
3132 SetCurrentOutput(f
);
3133 TraverseChildrenFromChunk(DocumentTitle
);
3135 else fprintf(f
, "(unknown)");
3137 fprintf(f
, "\n\n[WINDOWS]\n"
3138 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3139 FileNameFromPath(fname
),
3140 FileNameFromPath(fname
),
3141 FileNameFromPath(fname
),
3142 FileNameFromPath(TitlepageName
));
3145 fprintf(f
, "\n\n[FILES]\n");
3146 fprintf(f
, "%s\n", FileNameFromPath(TitlepageName
));
3147 for (int i
= 1; i
<= fileId
; i
++) {
3148 if (truncateFilenames
)
3149 sprintf(buf
, "%s%d.htm", FileNameFromPath(FileRoot
), i
);
3151 sprintf(buf
, "%s%d.html", FileNameFromPath(FileRoot
), i
);
3152 fprintf(f
, "%s\n", buf
);
3156 /* Generate index file : */
3158 sprintf(buf
, "%s.hhk", fname
);
3159 f
= fopen(buf
, "wt");
3162 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3165 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3166 "<!-- Sitemap 1.0 -->\n"
3168 "<OBJECT type=\"text/site properties\">\n"
3169 " <param name=\"ImageType\" value=\"Folder\">\n"
3173 TopicTable
.BeginFind();
3174 wxNode
*node
= NULL
;
3175 while ((node
= TopicTable
.Next()))
3177 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3178 const char *topicName
= node
->GetKeyString();
3179 if (texTopic
->filename
&& texTopic
->keywords
)
3181 wxNode
*node1
= texTopic
->keywords
->First();
3184 char *s
= (char *)node1
->Data();
3186 " <LI> <OBJECT type=\"text/sitemap\">\n"
3187 " <param name=\"Local\" value=\"%s#%s\">\n"
3188 " <param name=\"Name\" value=\"%s\">\n"
3190 texTopic
->filename
, topicName
, s
);
3191 node1
= node1
->Next();
3196 fprintf(f
, "</UL>\n");
3202 static FILE *HTMLWorkshopContents
= NULL
;
3203 static int HTMLWorkshopLastLevel
= 0;
3205 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3209 if (level
> HTMLWorkshopLastLevel
)
3210 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3211 fprintf(HTMLWorkshopContents
, "<UL>");
3212 if (level
< HTMLWorkshopLastLevel
)
3213 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3214 fprintf(HTMLWorkshopContents
, "</UL>");
3216 SetCurrentOutput(HTMLWorkshopContents
);
3217 fprintf(HTMLWorkshopContents
,
3218 " <LI> <OBJECT type=\"text/sitemap\">\n"
3219 " <param name=\"Local\" value=\"%s#%s\">\n"
3220 " <param name=\"Name\" value=\"",
3222 OutputCurrentSection();
3223 fprintf(HTMLWorkshopContents
,
3226 HTMLWorkshopLastLevel
= level
;
3230 void HTMLWorkshopStartContents()
3233 sprintf(buf
, "%s.hhc", FileRoot
);
3234 HTMLWorkshopContents
= fopen(buf
, "wt");
3235 HTMLWorkshopLastLevel
= 0;
3237 fprintf(HTMLWorkshopContents
,
3238 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3241 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3242 "<!-- Sitemap 1.0 -->\n"
3244 "<OBJECT type=\"text/site properties\">\n"
3245 " <param name=\"ImageType\" value=\"Folder\">\n"
3248 "<LI> <OBJECT type=\"text/sitemap\">\n"
3249 "<param name=\"Local\" value=\"%s\">\n"
3250 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3251 FileNameFromPath(TitlepageName
)
3257 void HTMLWorkshopEndContents()
3259 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3260 fprintf(HTMLWorkshopContents
, "</UL>\n");
3261 fclose(HTMLWorkshopContents
);