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();
2116 case ltTWOCOLITEMRULED
:
2119 if (start && (arg_no == 1))
2120 TexOutput("\n<DT> ");
2121 if (start && (arg_no == 2))
2128 if (TwoColWidthA
> -1) {
2130 sprintf(buf
,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA
);
2133 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2136 TexOutput("\n</FONT></TD>\n");
2142 if (TwoColWidthB
> -1) {
2144 sprintf(buf
,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB
);
2147 TexOutput("\n<TD VALIGN=TOP>\n");
2150 TexOutput("\n</FONT></TD></TR>\n");
2155 case ltNUMBEREDBIBITEM
:
2157 if (arg_no
== 1 && start
)
2159 TexOutput("\n<DT> ");
2161 if (arg_no
== 2 && !start
)
2168 if (arg_no
== 1 && start
)
2170 char *citeKey
= GetArgData();
2171 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2174 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2175 sprintf(buf
, "[%d]", citeCount
);
2176 ref
->sectionNumber
= copystring(buf
);
2179 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2184 if (arg_no
== 2 && !start
)
2190 case ltMARGINPARODD
:
2191 case ltMARGINPAREVEN
:
2197 TexOutput("<HR>\n");
2201 TexOutput("<HR><P>\n");
2205 case ltTWOCOLWIDTHA
:
2209 char *val
= GetArgData();
2210 float points
= ParseUnitArgument(val
);
2211 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2217 case ltTWOCOLWIDTHB
:
2221 char *val
= GetArgData();
2222 float points
= ParseUnitArgument(val
);
2223 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2232 case ltACCENT_GRAVE
:
2236 char *val
= GetArgData();
2242 TexOutput("à");
2245 TexOutput("è");
2248 TexOutput("ì");
2251 TexOutput("ò");
2254 TexOutput("ù");
2257 TexOutput("À");
2260 TexOutput("È");
2263 TexOutput("Ì");
2266 TexOutput("Ò");
2269 TexOutput("Ì");
2279 case ltACCENT_ACUTE
:
2283 char *val
= GetArgData();
2289 TexOutput("á");
2292 TexOutput("é");
2295 TexOutput("í");
2298 TexOutput("ó");
2301 TexOutput("ú");
2304 TexOutput("ý");
2307 TexOutput("Á");
2310 TexOutput("É");
2313 TexOutput("Í");
2316 TexOutput("Ó");
2319 TexOutput("Ú");
2322 TexOutput("Ý");
2332 case ltACCENT_CARET
:
2336 char *val
= GetArgData();
2342 TexOutput("â");
2345 TexOutput("ê");
2348 TexOutput("î");
2351 TexOutput("ô");
2354 TexOutput("û");
2357 TexOutput("Â");
2360 TexOutput("Ê");
2363 TexOutput("Î");
2366 TexOutput("Ô");
2369 TexOutput("Î");
2379 case ltACCENT_TILDE
:
2383 char *val
= GetArgData();
2392 TexOutput("ã");
2395 TexOutput("ñ");
2398 TexOutput("õ");
2401 TexOutput("Ã");
2404 TexOutput("Ñ");
2407 TexOutput("Õ");
2417 case ltACCENT_UMLAUT
:
2421 char *val
= GetArgData();
2427 TexOutput("ä");
2430 TexOutput("ë");
2433 TexOutput("ï");
2436 TexOutput("ö");
2439 TexOutput("ü");
2442 TexOutput("ÿ");
2445 TexOutput("Ä");
2448 TexOutput("Ë");
2451 TexOutput("Ï");
2454 TexOutput("Ö");
2457 TexOutput("Ü");
2460 TexOutput("Ÿ");
2474 char *val
= GetArgData();
2480 TexOutput("å");
2483 TexOutput("Å");
2497 char *val
= GetArgData();
2500 bool isPicture
= FALSE
;
2501 char *s
= ParseColourString(val
, &isPicture
);
2504 if (backgroundImageString
)
2505 delete[] backgroundImageString
;
2506 backgroundImageString
= copystring(val
);
2510 if (backgroundColourString
)
2511 delete[] backgroundColourString
;
2512 backgroundColourString
= copystring(val
);
2519 case ltBACKGROUNDIMAGE
:
2523 char *val
= GetArgData();
2526 if (backgroundImageString
)
2527 delete[] backgroundImageString
;
2528 backgroundImageString
= copystring(val
);
2534 case ltBACKGROUNDCOLOUR
:
2538 char *val
= GetArgData();
2541 if (backgroundColourString
)
2542 delete[] backgroundColourString
;
2543 backgroundColourString
= copystring(val
);
2553 char *val
= GetArgData();
2556 if (textColourString
)
2557 delete[] textColourString
;
2558 textColourString
= copystring(val
);
2568 char *val
= GetArgData();
2571 if (linkColourString
)
2572 delete[] linkColourString
;
2573 linkColourString
= copystring(val
);
2579 case ltFOLLOWEDLINKCOLOUR
:
2583 char *val
= GetArgData();
2586 if (followedLinkColourString
)
2587 delete[] followedLinkColourString
;
2588 followedLinkColourString
= copystring(val
);
2594 case ltACCENT_CADILLA
:
2598 char *val
= GetArgData();
2604 TexOutput("ç");
2607 TexOutput("Ç");
2619 case ltFOOTNOTEPOPUP:
2629 case ltSUPERTABULAR
:
2635 currentRowNumber
= 0;
2638 tableVerticalLineLeft
= FALSE
;
2639 tableVerticalLineRight
= FALSE
;
2640 int currentWidth
= 0;
2642 char *alignString
= copystring(GetArgData());
2643 ParseTableArgument(alignString
);
2645 TexOutput("<TABLE BORDER>\n");
2647 // Write the first row formatting for compatibility
2648 // with standard Latex
2649 if (compatibilityMode
)
2651 TexOutput("<TR>\n<TD>");
2654 for (int i = 0; i < noColumns; i++)
2656 currentWidth += TableData[i].width;
2657 sprintf(buf, "\\cellx%d", currentWidth);
2660 TexOutput("\\pard\\intbl\n");
2663 delete[] alignString
;
2668 else if (arg_no
== 2 && !start
)
2670 TexOutput("</TABLE>\n");
2675 case ltTHEBIBLIOGRAPHY
:
2677 if (start
&& (arg_no
== 1))
2679 ReopenFile(&Chapters
, &ChaptersName
);
2680 AddTexRef("bibliography", ChaptersName
, "bibliography");
2681 SetCurrentSubsectionName("bibliography", ChaptersName
);
2685 SetCurrentOutput(Chapters
);
2688 if (truncateFilenames
)
2689 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2691 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2693 TexOutput("<head><title>");
2694 TexOutput(ReferencesNameString
);
2695 TexOutput("</title></head>\n");
2698 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2699 AddBrowseButtons("contents", titleBuf
, // Up
2700 lastTopic
, lastFileName
, // Last topic
2701 "bibliography", ChaptersName
); // This topic
2703 SetCurrentOutputs(Contents
, Chapters
);
2704 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2706 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2707 fprintf(Chapters
, "</H2>\n</A>\n");
2709 SetCurrentOutput(Chapters
);
2712 if (!start
&& (arg_no
== 2))
2720 /* Build up list of keywords associated with topics */
2723 // char *entry = GetArgData();
2725 OutputChunkToString(GetArgChunk(), buf
);
2728 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2743 char *name
= GetArgData();
2745 if (!FindColourHTMLString(name
, buf2
))
2747 strcpy(buf2
, "#000000");
2749 sprintf(buf
, "Could not find colour name %s", name
);
2752 TexOutput("<FONT COLOR=\"");
2768 if (arg_no
== 2) TexOutput("</FONT>");
2773 case ltINSERTATLEVEL
:
2775 // This macro allows you to insert text at a different level
2776 // from the current level, e.g. into the Sections from within a subsubsection.
2779 static int currentLevelNo
= 1;
2780 static FILE* oldLevelFile
= Chapters
;
2787 oldLevelFile
= CurrentOutput1
;
2789 char *str
= GetArgData();
2790 currentLevelNo
= atoi(str
);
2792 // TODO: cope with article style (no chapters)
2793 switch (currentLevelNo
)
2797 outputFile
= Chapters
;
2802 outputFile
= Sections
;
2807 outputFile
= Subsections
;
2812 outputFile
= Subsubsections
;
2822 CurrentOutput1
= outputFile
;
2840 CurrentOutput1
= oldLevelFile
;
2846 return DefaultOnArgument(macroId
, arg_no
, start
);
2859 tableVerticalLineLeft
= FALSE
;
2860 tableVerticalLineRight
= FALSE
;
2863 if (InputFile
&& OutputFile
)
2865 // Do some HTML-specific transformations on all the strings,
2867 Text2HTML(GetTopLevelChunk());
2870 if (truncateFilenames
)
2871 sprintf(buf
, "%s.htm", FileRoot
);
2873 sprintf(buf
, "%s_contents.html", FileRoot
);
2874 if (TitlepageName
) delete[] TitlepageName
;
2875 TitlepageName
= copystring(buf
);
2876 Titlepage
= fopen(buf
, "w");
2878 if (truncateFilenames
)
2879 sprintf(buf
, "%s_fc.htm", FileRoot
);
2881 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2883 contentsFrameName
= copystring(buf
);
2885 Contents
= fopen(TmpContentsName
, "w");
2887 if (htmlFrameContents
)
2889 // FrameContents = fopen(TmpFrameContentsName, "w");
2890 FrameContents
= fopen(contentsFrameName
, "w");
2891 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2894 if (!Titlepage
|| !Contents
)
2896 OnError("Cannot open output file!");
2899 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2901 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2903 fprintf(Contents
, "<UL>\n");
2905 SetCurrentOutput(Titlepage
);
2906 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2907 OnInform("Converting...");
2910 fprintf(Contents
, "</UL>\n\n");
2912 // SetCurrentOutput(Titlepage);
2917 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2924 fprintf(FrameContents
, "\n</UL>\n");
2925 fprintf(FrameContents
, "</HTML>\n");
2926 fclose(FrameContents
);
2927 FrameContents
= NULL
;
2932 fprintf(Chapters
, "\n</FONT></BODY></HTML>\n");
2938 fprintf(Sections
, "\n</FONT></BODY></HTML>\n");
2942 if (Subsections
&& !combineSubSections
)
2944 fprintf(Subsections
, "\n</FONT></BODY></HTML>\n");
2945 fclose(Subsections
);
2948 if (Subsubsections
&& !combineSubSections
)
2950 fprintf(Subsubsections
, "\n</FONT></BODY></HTML>\n");
2951 fclose(Subsubsections
);
2952 Subsubsections
= NULL
;
2954 if ( SectionContentsFD
)
2956 fclose(SectionContentsFD
);
2957 SectionContentsFD
= NULL
;
2960 // Create a temporary file for the title page header, add some info,
2961 // and concat the titlepage just generated.
2962 // This is necessary in order to put the title of the document
2963 // at the TOP of the file within <HEAD>, even though we only find out
2964 // what it is later on.
2965 FILE *tmpTitle
= fopen("title.tmp", "w");
2970 SetCurrentOutput(tmpTitle
);
2971 TexOutput("\n<HTML>\n<HEAD><TITLE>");
2972 TraverseChildrenFromChunk(DocumentTitle
);
2973 TexOutput("</TITLE></HEAD>\n");
2977 SetCurrentOutput(tmpTitle
);
2979 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
2981 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
2984 // Output frame information
2985 if (htmlFrameContents
)
2987 char firstFileName
[300];
2988 if (truncateFilenames
)
2989 sprintf(firstFileName
, "%s1.htm", FileRoot
);
2991 sprintf(firstFileName
, "%s1.html", FileRoot
);
2993 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
2995 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
2996 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
2997 fprintf(tmpTitle
, "</FRAMESET>\n");
2999 fprintf(tmpTitle
, "<NOFRAMES>\n");
3002 // Output <BODY...> to temporary title page
3006 FILE *fd
= fopen(TitlepageName
, "r");
3018 fprintf(tmpTitle
, "\n</FONT></BODY>\n");
3020 if (htmlFrameContents
)
3022 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
3024 fprintf(tmpTitle
, "\n</HTML>\n");
3027 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3028 if (!wxRenameFile("title.tmp", TitlepageName
))
3030 wxCopyFile("title.tmp", TitlepageName
);
3031 wxRemoveFile("title.tmp");
3035 if (lastFileName
) delete[] lastFileName
;
3036 lastFileName
= NULL
;
3037 if (lastTopic
) delete[] lastTopic
;
3040 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3042 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3044 wxCopyFile(TmpContentsName
, ContentsName
);
3045 wxRemoveFile(TmpContentsName
);
3048 // Generate .htx file if requested
3051 char htmlIndexName
[300];
3052 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
3053 GenerateHTMLIndexFile(htmlIndexName
);
3056 // Generate HTML Help Workshop files if requested
3057 if (htmlWorkshopFiles
)
3059 HTMLWorkshopEndContents();
3060 GenerateHTMLWorkshopFiles(FileRoot
);
3070 // Output .htx index file
3071 void GenerateHTMLIndexFile(char *fname
)
3073 FILE *fd
= fopen(fname
, "w");
3077 TopicTable
.BeginFind();
3078 wxNode
*node
= NULL
;
3079 while ((node
= TopicTable
.Next()))
3081 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3082 const char *topicName
= node
->GetKeyString();
3083 if (texTopic
->filename
&& texTopic
->keywords
)
3085 wxNode
*node1
= texTopic
->keywords
->First();
3088 char *s
= (char *)node1
->Data();
3089 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3090 node1
= node1
->Next();
3103 // output .hpp, .hhc and .hhk files:
3106 void GenerateHTMLWorkshopFiles(char *fname
)
3111 /* Generate project file : */
3113 sprintf(buf
, "%s.hhp", fname
);
3114 f
= fopen(buf
, "wt");
3117 "Compatibility=1.1\n"
3118 "Full-text search=Yes\n"
3119 "Contents file=%s.hhc\n"
3120 "Compiled file=%s.chm\n"
3121 "Default Window=%sHelp\n"
3122 "Default topic=%s\n"
3123 "Index file=%s.hhk\n"
3125 FileNameFromPath(fname
),
3126 FileNameFromPath(fname
),
3127 FileNameFromPath(fname
),
3128 FileNameFromPath(TitlepageName
),
3129 FileNameFromPath(fname
)
3132 if (DocumentTitle
) {
3133 SetCurrentOutput(f
);
3134 TraverseChildrenFromChunk(DocumentTitle
);
3136 else fprintf(f
, "(unknown)");
3138 fprintf(f
, "\n\n[WINDOWS]\n"
3139 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3140 FileNameFromPath(fname
),
3141 FileNameFromPath(fname
),
3142 FileNameFromPath(fname
),
3143 FileNameFromPath(TitlepageName
));
3146 fprintf(f
, "\n\n[FILES]\n");
3147 fprintf(f
, "%s\n", FileNameFromPath(TitlepageName
));
3148 for (int i
= 1; i
<= fileId
; i
++) {
3149 if (truncateFilenames
)
3150 sprintf(buf
, "%s%d.htm", FileNameFromPath(FileRoot
), i
);
3152 sprintf(buf
, "%s%d.html", FileNameFromPath(FileRoot
), i
);
3153 fprintf(f
, "%s\n", buf
);
3157 /* Generate index file : */
3159 sprintf(buf
, "%s.hhk", fname
);
3160 f
= fopen(buf
, "wt");
3163 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3166 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3167 "<!-- Sitemap 1.0 -->\n"
3169 "<OBJECT type=\"text/site properties\">\n"
3170 " <param name=\"ImageType\" value=\"Folder\">\n"
3174 TopicTable
.BeginFind();
3175 wxNode
*node
= NULL
;
3176 while ((node
= TopicTable
.Next()))
3178 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3179 const char *topicName
= node
->GetKeyString();
3180 if (texTopic
->filename
&& texTopic
->keywords
)
3182 wxNode
*node1
= texTopic
->keywords
->First();
3185 char *s
= (char *)node1
->Data();
3187 " <LI> <OBJECT type=\"text/sitemap\">\n"
3188 " <param name=\"Local\" value=\"%s#%s\">\n"
3189 " <param name=\"Name\" value=\"%s\">\n"
3191 texTopic
->filename
, topicName
, s
);
3192 node1
= node1
->Next();
3197 fprintf(f
, "</UL>\n");
3203 static FILE *HTMLWorkshopContents
= NULL
;
3204 static int HTMLWorkshopLastLevel
= 0;
3206 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3210 if (level
> HTMLWorkshopLastLevel
)
3211 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3212 fprintf(HTMLWorkshopContents
, "<UL>");
3213 if (level
< HTMLWorkshopLastLevel
)
3214 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3215 fprintf(HTMLWorkshopContents
, "</UL>");
3217 SetCurrentOutput(HTMLWorkshopContents
);
3218 fprintf(HTMLWorkshopContents
,
3219 " <LI> <OBJECT type=\"text/sitemap\">\n"
3220 " <param name=\"Local\" value=\"%s#%s\">\n"
3221 " <param name=\"Name\" value=\"",
3223 OutputCurrentSection();
3224 fprintf(HTMLWorkshopContents
,
3227 HTMLWorkshopLastLevel
= level
;
3231 void HTMLWorkshopStartContents()
3234 sprintf(buf
, "%s.hhc", FileRoot
);
3235 HTMLWorkshopContents
= fopen(buf
, "wt");
3236 HTMLWorkshopLastLevel
= 0;
3238 fprintf(HTMLWorkshopContents
,
3239 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3242 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3243 "<!-- Sitemap 1.0 -->\n"
3245 "<OBJECT type=\"text/site properties\">\n"
3246 " <param name=\"ImageType\" value=\"Folder\">\n"
3249 "<LI> <OBJECT type=\"text/sitemap\">\n"
3250 "<param name=\"Local\" value=\"%s\">\n"
3251 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3252 FileNameFromPath(TitlepageName
)
3258 void HTMLWorkshopEndContents()
3260 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3261 fprintf(HTMLWorkshopContents
, "</UL>\n");
3262 fclose(HTMLWorkshopContents
);