]>
git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/htmlutil.cpp
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"
31 extern void DecToHex(int, char *);
32 void GenerateHTMLIndexFile(char *fname
);
34 void GenerateHTMLWorkshopFiles(char *fname
);
35 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
);
36 void HTMLWorkshopStartContents();
37 void HTMLWorkshopEndContents();
39 void OutputContentsFrame(void);
41 #include "readshg.h" // Segmented hypergraphics parsing
43 char *ChaptersName
= NULL
;
44 char *SectionsName
= NULL
;
45 char *SubsectionsName
= NULL
;
46 char *SubsubsectionsName
= NULL
;
47 char *TitlepageName
= NULL
;
48 char *lastFileName
= NULL
;
49 char *lastTopic
= NULL
;
50 char *currentFileName
= NULL
;
51 char *contentsFrameName
= NULL
;
53 static TexChunk
*descriptionItemArg
= NULL
;
54 static TexChunk
*helpRefFilename
= NULL
;
55 static TexChunk
*helpRefText
= NULL
;
56 static int indentLevel
= 0;
57 static int citeCount
= 1;
58 extern FILE *Contents
;
59 FILE *FrameContents
= NULL
;
60 FILE *Titlepage
= NULL
;
61 // FILE *FrameTitlepage = NULL;
63 bool subsectionStarted
= FALSE
;
65 // Which column of a row are we in? (Assumes no nested tables, of course)
66 int currentColumn
= 0;
68 // Are we in verbatim mode? If so, format differently.
69 static bool inVerbatim
= FALSE
;
71 // Need to know whether we're in a table or figure for benefit
72 // of listoffigures/listoftables
73 static bool inFigure
= FALSE
;
74 static bool inTable
= FALSE
;
76 // This is defined in the Tex2Any library.
77 extern char *BigBuffer
;
79 class HyperReference
: public wxObject
84 HyperReference(char *name
, char *file
)
86 if (name
) refName
= copystring(name
);
87 if (file
) refFile
= copystring(file
);
91 class TexNextPage
: public wxObject
96 TexNextPage(char *theLabel
, char *theFile
)
98 label
= copystring(theLabel
);
99 filename
= copystring(theFile
);
108 wxHashTable
TexNextPages(wxKEY_STRING
);
110 static char *CurrentChapterName
= NULL
;
111 static char *CurrentChapterFile
= NULL
;
112 static char *CurrentSectionName
= NULL
;
113 static char *CurrentSectionFile
= NULL
;
114 static char *CurrentSubsectionName
= NULL
;
115 static char *CurrentSubsectionFile
= NULL
;
116 static char *CurrentSubsubsectionName
= NULL
;
117 static char *CurrentSubsubsectionFile
= NULL
;
118 static char *CurrentTopic
= NULL
;
120 static void SetCurrentTopic(char *s
)
122 if (CurrentTopic
) delete[] CurrentTopic
;
123 CurrentTopic
= copystring(s
);
126 void SetCurrentChapterName(char *s
, char *file
)
128 if (CurrentChapterName
) delete[] CurrentChapterName
;
129 CurrentChapterName
= copystring(s
);
130 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
131 CurrentChapterFile
= copystring(file
);
133 currentFileName
= CurrentChapterFile
;
137 void SetCurrentSectionName(char *s
, char *file
)
139 if (CurrentSectionName
) delete[] CurrentSectionName
;
140 CurrentSectionName
= copystring(s
);
141 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
142 CurrentSectionFile
= copystring(file
);
144 currentFileName
= CurrentSectionFile
;
147 void SetCurrentSubsectionName(char *s
, char *file
)
149 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
150 CurrentSubsectionName
= copystring(s
);
151 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
152 CurrentSubsectionFile
= copystring(file
);
153 currentFileName
= CurrentSubsectionFile
;
156 void SetCurrentSubsubsectionName(char *s
, char *file
)
158 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
159 CurrentSubsubsectionName
= copystring(s
);
160 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
161 CurrentSubsubsectionFile
= copystring(file
);
162 currentFileName
= CurrentSubsubsectionFile
;
167 * Close former filedescriptor and reopen using another filename.
171 void ReopenFile(FILE **fd
, char **fileName
)
175 fprintf(*fd
, "\n</BODY></HTML>\n");
180 if (truncateFilenames
)
181 sprintf(buf
, "%s%d.htm", FileRoot
, fileId
);
183 sprintf(buf
, "%s%d.html", FileRoot
, fileId
);
184 if (*fileName
) delete[] *fileName
;
185 *fileName
= copystring(FileNameFromPath(buf
));
186 *fd
= fopen(buf
, "w");
187 fprintf(*fd
, "<HTML>\n");
191 * Reopen section contents file, i.e. the index appended to each section
192 * in subsectionCombine mode
195 static char *SectionContentsFilename
= NULL
;
196 static FILE *SectionContentsFD
= NULL
;
198 void ReopenSectionContentsFile(void)
200 if ( SectionContentsFD
)
202 fclose(SectionContentsFD
);
204 if ( SectionContentsFilename
)
205 delete[] SectionContentsFilename
;
206 SectionContentsFD
= NULL
;
207 SectionContentsFilename
= NULL
;
209 // Create the name from the current section filename
210 if ( CurrentSectionFile
)
213 strcpy(buf
, CurrentSectionFile
);
214 wxStripExtension(buf
);
216 SectionContentsFilename
= copystring(buf
);
218 SectionContentsFD
= fopen(SectionContentsFilename
, "w");
224 * Given a TexChunk with a string value, scans through the string
225 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
229 void ProcessText2HTML(TexChunk
*chunk
)
231 bool changed
= FALSE
;
235 int len
= strlen(chunk
->value
);
238 ch
= chunk
->value
[i
];
240 // 2 newlines means \par
241 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
242 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
243 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
245 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "<P>\n\n"); ptr
+= 5;
249 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
251 BigBuffer
[ptr
] = '"'; ptr
++;
255 else if (!inVerbatim
&& ch
== '`') // Change ` to '
257 BigBuffer
[ptr
] = 39; ptr
++;
261 else if (ch
== '<') // Change < to <
264 strcat(BigBuffer
, "<");
269 else if (ch
== '>') // Change > to >
272 strcat(BigBuffer
, ">");
289 chunk
->value
= copystring(BigBuffer
);
294 * Scan through all chunks starting from the given one,
295 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
296 * This should be called after Tex2Any has parsed the file,
297 * and before TraverseDocument is called.
301 void Text2HTML(TexChunk
*chunk
)
304 if (stopRunning
) return;
308 case CHUNK_TYPE_MACRO
:
310 TexMacroDef
*def
= chunk
->def
;
312 if (def
&& def
->ignore
)
315 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
318 wxNode
*node
= chunk
->children
.First();
321 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
322 Text2HTML(child_chunk
);
326 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
333 wxNode
*node
= chunk
->children
.First();
336 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
337 Text2HTML(child_chunk
);
343 case CHUNK_TYPE_STRING
:
346 ProcessText2HTML(chunk
);
353 * Add appropriate browse buttons to this page.
357 void AddBrowseButtons(char *upLabel
, char *upFilename
,
358 char *previousLabel
, char *previousFilename
,
359 char *thisLabel
, char *thisFilename
)
361 char contentsReferenceBuf
[80];
362 char upReferenceBuf
[80];
363 char backReferenceBuf
[80];
364 char forwardReferenceBuf
[80];
365 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
368 char *contentsReference
= NULL
;
369 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
370 contentsReference
= ContentsNameString
;
373 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
374 contentsReference
= contentsReferenceBuf
;
375 sprintf(contentsReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">", ConvertCase("contents.gif"));
378 char *upReference
= NULL
;
379 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
380 upReference
= UpNameString
;
383 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
384 upReference
= upReferenceBuf
;
385 sprintf(upReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">", ConvertCase("up.gif"));
388 char *backReference
= NULL
;
389 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
390 backReference
= "<<";
393 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
394 backReference
= backReferenceBuf
;
395 sprintf(backReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">", ConvertCase("back.gif"));
398 char *forwardReference
= NULL
;
399 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
400 forwardReference
= ">>";
403 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
404 forwardReference
= forwardReferenceBuf
;
405 sprintf(forwardReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">", ConvertCase("forward.gif"));
408 TexOutput("<CENTER>");
417 if (truncateFilenames
)
420 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
421 sprintf(buf
, "\n<A HREF=\"%s.%s\">%s</A> ", buf1
, ConvertCase("htm"), contentsReference
);
426 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
427 sprintf(buf
, "\n<A HREF=\"%s%s\">%s</A> ", buf1
, ConvertCase("_contents.html"), contentsReference
);
429 // TexOutput("<NOFRAMES>");
431 // TexOutput("</NOFRAMES>");
438 if (upLabel
&& upFilename
)
440 if (strlen(upLabel
) > 0)
441 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(upFilename
), upLabel
, upReference
);
443 sprintf(buf
, "<A HREF=\"%s\">%s</A> ", ConvertCase(upFilename
), upReference
);
444 if (strcmp(upLabel
, "contents") == 0)
446 // TexOutput("<NOFRAMES>");
448 // TexOutput("</NOFRAMES>");
459 if (previousLabel
&& previousFilename
)
461 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(previousFilename
), previousLabel
, backReference
);
462 if (strcmp(previousLabel
, "contents") == 0)
464 // TexOutput("<NOFRAMES>");
466 // TexOutput("</NOFRAMES>");
473 // A placeholder so the buttons don't keep moving position
474 sprintf(buf
, "%s ", backReference
);
478 char *nextLabel
= NULL
;
479 char *nextFilename
= NULL
;
481 // Get the next page, and record the previous page's 'next' page
483 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
486 nextLabel
= nextPage
->label
;
487 nextFilename
= nextPage
->filename
;
489 if (previousLabel
&& previousFilename
)
491 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
495 TexNextPages
.Delete(previousLabel
);
497 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
498 TexNextPages
.Put(previousLabel
, newNextPage
);
506 if (nextLabel
&& nextFilename
)
508 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(nextFilename
), nextLabel
, forwardReference
);
513 // A placeholder so the buttons don't keep moving position
514 sprintf(buf
, "%s ", forwardReference
);
519 * Horizontal rule to finish it off nicely.
522 TexOutput("</CENTER>");
525 // Update last topic/filename
527 delete[] lastFileName
;
528 lastFileName
= copystring(thisFilename
);
531 lastTopic
= copystring(thisLabel
);
534 // A colour string is either 3 numbers separated by semicolons (RGB),
535 // or a reference to a GIF. Return the filename or a hex string like #934CE8
536 char *ParseColourString(char *bkStr
, bool *isPicture
)
538 static char resStr
[300];
539 strcpy(resStr
, bkStr
);
540 char *tok1
= strtok(resStr
, ";");
541 char *tok2
= strtok(NULL
, ";");
552 char *tok3
= strtok(NULL
, ";");
555 // Now convert 3 strings into decimal numbers, and then hex numbers.
556 int red
= atoi(tok1
);
557 int green
= atoi(tok2
);
558 int blue
= atoi(tok3
);
565 DecToHex(green
, buf
);
577 // Output start of <BODY> block
578 void OutputBodyStart(void)
580 TexOutput("\n<BODY");
581 if (backgroundImageString
)
583 bool isPicture
= FALSE
;
584 char *s
= ParseColourString(backgroundImageString
, &isPicture
);
587 TexOutput(" BACKGROUND=\""); TexOutput(s
); TexOutput("\"");
590 if (backgroundColourString
)
592 bool isPicture
= FALSE
;
593 char *s
= ParseColourString(backgroundColourString
, &isPicture
);
596 TexOutput(" BGCOLOR="); TexOutput(s
);
600 // Set foreground text colour, if one is specified
601 if (textColourString
)
603 bool isPicture
= FALSE
;
604 char *s
= ParseColourString(textColourString
, &isPicture
);
607 TexOutput(" TEXT="); TexOutput(s
);
610 // Set link text colour, if one is specified
611 if (linkColourString
)
613 bool isPicture
= FALSE
;
614 char *s
= ParseColourString(linkColourString
, &isPicture
);
617 TexOutput(" LINK="); TexOutput(s
);
620 // Set followed link text colour, if one is specified
621 if (followedLinkColourString
)
623 bool isPicture
= FALSE
;
624 char *s
= ParseColourString(followedLinkColourString
, &isPicture
);
627 TexOutput(" VLINK="); TexOutput(s
);
633 // Called on start/end of macro examination
634 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
640 case ltCHAPTERHEADING
:
648 if (macroId
!= ltCHAPTERSTAR
)
651 SetCurrentOutput(NULL
);
652 startedSections
= TRUE
;
654 char *topicName
= FindTopicName(GetNextChunk());
655 ReopenFile(&Chapters
, &ChaptersName
);
656 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
658 SetCurrentChapterName(topicName
, ChaptersName
);
659 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
661 SetCurrentOutput(Chapters
);
663 TexOutput("<head><title>");
664 OutputCurrentSection(); // Repeat section header
665 TexOutput("</title></head>\n");
669 if (truncateFilenames
)
670 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
672 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
674 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
676 AddBrowseButtons("", titleBuf
, // Up
677 lastTopic
, lastFileName
, // Last topic
678 topicName
, ChaptersName
); // This topic
680 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
682 if (htmlFrameContents
&& FrameContents
)
684 SetCurrentOutput(FrameContents
);
685 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
686 OutputCurrentSection();
687 fprintf(FrameContents
, "</A>\n");
690 SetCurrentOutputs(Contents
, Chapters
);
691 fprintf(Chapters
, "\n<H2>");
692 OutputCurrentSection();
693 fprintf(Contents
, "</A>\n");
694 fprintf(Chapters
, "</H2>\n");
696 SetCurrentOutput(Chapters
);
698 // Add this section title to the list of keywords
701 OutputCurrentSectionToString(wxBuffer
);
702 AddKeyWordForTopic(topicName
, wxBuffer
, ConvertCase(currentFileName
));
709 case ltSECTIONHEADING
:
716 subsectionStarted
= FALSE
;
718 if (macroId
!= ltSECTIONSTAR
)
721 SetCurrentOutput(NULL
);
722 startedSections
= TRUE
;
724 char *topicName
= FindTopicName(GetNextChunk());
725 ReopenFile(&Sections
, &SectionsName
);
726 AddTexRef(topicName
, SectionsName
, SectionNameString
);
728 SetCurrentSectionName(topicName
, SectionsName
);
729 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
731 SetCurrentOutput(Sections
);
732 TexOutput("<head><title>");
733 OutputCurrentSection();
734 TexOutput("</title></head>\n");
737 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
738 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
739 lastTopic
, lastFileName
, // Last topic
740 topicName
, SectionsName
); // This topic
742 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
744 SetCurrentOutputs(jumpFrom
, Sections
);
745 if (DocumentStyle
== LATEX_ARTICLE
)
746 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
748 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
750 fprintf(Sections
, "\n<H2>");
751 OutputCurrentSection();
753 if (DocumentStyle
== LATEX_ARTICLE
)
754 fprintf(jumpFrom
, "</A>\n");
756 fprintf(jumpFrom
, "</B></A><BR>\n");
757 fprintf(Sections
, "</H2>\n");
759 SetCurrentOutput(Sections
);
760 // Add this section title to the list of keywords
763 OutputCurrentSectionToString(wxBuffer
);
764 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
770 case ltSUBSECTIONSTAR
:
771 case ltMEMBERSECTION
:
772 case ltFUNCTIONSECTION
:
778 OnError("You cannot have a subsection before a section!");
784 if (macroId
!= ltSUBSECTIONSTAR
)
787 if ( combineSubSections
&& !subsectionStarted
)
789 // Read old .con file in at this point
791 strcpy(buf
, CurrentSectionFile
);
792 wxStripExtension(buf
);
794 FILE *fd
= fopen(buf
, "r");
805 fprintf(Sections
, "<P>\n");
807 // Close old file, create a new file for the sub(sub)section contents entries
808 ReopenSectionContentsFile();
811 startedSections
= TRUE
;
812 subsectionStarted
= TRUE
;
814 char *topicName
= FindTopicName(GetNextChunk());
816 if ( !combineSubSections
)
818 SetCurrentOutput(NULL
);
819 ReopenFile(&Subsections
, &SubsectionsName
);
820 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
821 SetCurrentSubsectionName(topicName
, SubsectionsName
);
822 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
823 SetCurrentOutput(Subsections
);
825 TexOutput("<head><title>");
826 OutputCurrentSection();
827 TexOutput("</title></head>\n");
830 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
831 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
832 lastTopic
, lastFileName
, // Last topic
833 topicName
, SubsectionsName
); // This topic
835 SetCurrentOutputs(Sections
, Subsections
);
836 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
838 fprintf(Subsections
, "\n<H3>");
839 OutputCurrentSection();
840 fprintf(Sections
, "</B></A><BR>\n");
841 fprintf(Subsections
, "</H3>\n");
843 SetCurrentOutput(Subsections
);
847 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
848 SetCurrentSubsectionName(topicName
, SectionsName
);
850 // if ( subsectionNo != 0 )
851 fprintf(Sections
, "\n<HR>\n");
853 // We're putting everything into the section file
854 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
855 fprintf(Sections
, "\n<H3>");
856 OutputCurrentSection();
857 fprintf(Sections
, "</H3>\n");
859 SetCurrentOutput(SectionContentsFD
);
860 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
861 OutputCurrentSection();
862 TexOutput("</A><BR>\n");
864 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
865 SetCurrentOutput(Sections
);
867 // Add this section title to the list of keywords
870 OutputCurrentSectionToString(wxBuffer
);
871 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
878 case ltSUBSUBSECTION
:
879 case ltSUBSUBSECTIONSTAR
:
883 if (!Subsections
&& !combineSubSections
)
885 OnError("You cannot have a subsubsection before a subsection!");
889 if (macroId
!= ltSUBSUBSECTIONSTAR
)
892 startedSections
= TRUE
;
894 char *topicName
= FindTopicName(GetNextChunk());
896 if ( !combineSubSections
)
898 SetCurrentOutput(NULL
);
899 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
900 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
901 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
902 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
904 SetCurrentOutput(Subsubsections
);
905 TexOutput("<head><title>");
906 OutputCurrentSection();
907 TexOutput("</title></head>\n");
910 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
912 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
913 lastTopic
, lastFileName
, // Last topic
914 topicName
, SubsubsectionsName
); // This topic
916 SetCurrentOutputs(Subsections
, Subsubsections
);
917 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
919 fprintf(Subsubsections
, "\n<H3>");
920 OutputCurrentSection();
921 fprintf(Subsections
, "</B></A><BR>\n");
922 fprintf(Subsubsections
, "</H3>\n");
926 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
927 SetCurrentSubsectionName(topicName
, SectionsName
);
928 fprintf(Sections
, "\n<HR>\n");
930 // We're putting everything into the section file
931 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
932 fprintf(Sections
, "\n<H3>");
933 OutputCurrentSection();
934 fprintf(Sections
, "</H3>\n");
935 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
936 SetCurrentOutput(SectionContentsFD);
937 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
938 OutputCurrentSection();
939 TexOutput("</A><BR>");
941 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
942 SetCurrentOutput(Sections
);
945 // Add this section title to the list of keywords
948 OutputCurrentSectionToString(wxBuffer
);
949 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
958 if ( !combineSubSections
)
959 SetCurrentOutput(Subsections
);
961 SetCurrentOutput(Sections
);
972 if ( !combineSubSections
)
973 SetCurrentOutput(Subsections
);
975 SetCurrentOutput(Sections
);
986 if ( !combineSubSections
)
987 SetCurrentOutput(Subsections
);
989 SetCurrentOutput(Sections
);
1000 // TexOutput("<B>void</B>");
1008 TexOutput("wxCLIPS");
1014 case ltSPECIALAMPERSAND
:
1020 // End cell, start cell
1023 // Start new row and cell, setting alignment for the first cell.
1024 if (currentColumn
< noColumns
)
1028 if (TableData
[currentColumn
].justification
== 'c')
1029 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1030 else if (TableData
[currentColumn
].justification
== 'r')
1031 sprintf(buf
, "\n<TD ALIGN=RIGHT>");
1032 else if (TableData
[currentColumn
].absWidth
)
1034 // Convert from points * 20 into pixels.
1035 int points
= TableData
[currentColumn
].width
/ 20;
1037 // Say the display is 100 DPI (dots/pixels per inch).
1038 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1039 int pixels
= (int)(points
* 100.0 / 72.0);
1040 sprintf(buf
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1043 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1051 case ltBACKSLASHCHAR
:
1057 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1058 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1059 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1060 TexOutput("</TR>\n");
1063 TexOutput("<BR>\n");
1074 // Start new row and cell, setting alignment for the first cell.
1076 if (TableData
[currentColumn
].justification
== 'c')
1077 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1078 else if (TableData
[currentColumn
].justification
== 'r')
1079 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1080 else if (TableData
[currentColumn
].absWidth
)
1082 // Convert from points * 20 into pixels.
1083 int points
= TableData
[currentColumn
].width
/ 20;
1085 // Say the display is 100 DPI (dots/pixels per inch).
1086 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1087 int pixels
= (int)(points
* 100.0 / 72.0);
1088 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1091 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1097 // Start new row and cell
1098 TexOutput("</TD>\n</TR>\n");
1102 // HTML-only: break until the end of the picture (both margins are clear).
1106 TexOutput("<BR CLEAR=ALL>");
1109 case ltRTFSP
: // Explicit space, RTF only
1111 case ltSPECIALTILDE
:
1125 TexOutput("<UL><UL>\n");
1127 TexOutput("</UL></UL>\n");
1133 // case ltTWOCOLLIST:
1140 if (macroId
== ltENUMERATE
)
1141 listType
= LATEX_ENUMERATE
;
1142 else if (macroId
== ltITEMIZE
)
1143 listType
= LATEX_ITEMIZE
;
1145 listType
= LATEX_DESCRIPTION
;
1147 itemizeStack
.Insert(new ItemizeStruc(listType
));
1151 TexOutput("<UL>\n");
1153 case LATEX_ENUMERATE
:
1154 TexOutput("<OL>\n");
1156 case LATEX_DESCRIPTION
:
1158 TexOutput("<DL>\n");
1165 if (itemizeStack
.First())
1167 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1168 switch (struc
->listType
)
1171 TexOutput("</UL>\n");
1173 case LATEX_ENUMERATE
:
1174 TexOutput("</OL>\n");
1176 case LATEX_DESCRIPTION
:
1178 TexOutput("</DL>\n");
1183 delete itemizeStack
.First();
1191 TexOutput("\n<TABLE>\n");
1193 TexOutput("\n</TABLE>\n");
1202 /* For footnotes we need to output the text at the bottom of the page and
1203 * insert a reference to it. Is it worth the trouble...
1205 case ltFOOTNOTEPOPUP:
1211 else TexOutput("</FN>");
1219 else TexOutput("</TT>");
1227 sprintf(buf
, "<PRE>\n");
1230 else TexOutput("</PRE>\n");
1238 TexOutput("<CENTER>");
1240 else TexOutput("</CENTER>");
1248 TexOutput("{\\ql ");
1250 else TexOutput("}\\par\\pard\n");
1259 TexOutput("{\\qr ");
1261 else TexOutput("}\\par\\pard\n");
1269 // Netscape extension
1270 TexOutput("<FONT SIZE=2>");
1272 else TexOutput("</FONT>");
1279 // Netscape extension
1280 TexOutput("<FONT SIZE=1>");
1282 else TexOutput("</FONT>");
1289 // Netscape extension
1290 TexOutput("<FONT SIZE=3>");
1292 else TexOutput("</FONT>");
1299 // Netscape extension
1300 TexOutput("<FONT SIZE=4>");
1302 else TexOutput("</FONT>");
1309 // Netscape extension
1310 TexOutput("<FONT SIZE=5>");
1312 else TexOutput("</FONT>");
1319 // Netscape extension
1320 TexOutput("<FONT SIZE=6>");
1322 else TexOutput("</FONT>");
1333 else TexOutput("</B>");
1344 else TexOutput("</I>");
1354 else TexOutput("</EM>");
1363 else TexOutput("</UL>");
1374 else TexOutput("</TT>");
1380 TexOutput("©", TRUE
);
1386 TexOutput("®", TRUE
);
1392 if (start
) TexOutput("<--");
1397 if (start
) TexOutput("<==");
1402 if (start
) TexOutput("-->");
1407 if (start
) TexOutput("==>");
1410 case ltLEFTRIGHTARROW
:
1412 if (start
) TexOutput("<-->");
1415 case ltLEFTRIGHTARROW2
:
1417 if (start
) TexOutput("<==>");
1430 wxNode
*node
= itemizeStack
.First();
1433 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1434 struc
->currentItem
+= 1;
1435 if (struc
->listType
== LATEX_DESCRIPTION
)
1437 if (descriptionItemArg
)
1440 TraverseChildrenFromChunk(descriptionItemArg
);
1442 descriptionItemArg
= NULL
;
1454 if (start
&& DocumentTitle
&& DocumentAuthor
)
1456 // Add a special label for the contents page.
1457 // TexOutput("<CENTER>\n");
1458 TexOutput("<A NAME=\"contents\">");
1459 TexOutput("<H2 ALIGN=CENTER>\n");
1460 TraverseChildrenFromChunk(DocumentTitle
);
1463 TexOutput("</A>\n");
1464 TexOutput("<P>\n\n");
1465 TexOutput("<H3 ALIGN=CENTER>");
1466 TraverseChildrenFromChunk(DocumentAuthor
);
1467 TexOutput("</H3><P>\n\n");
1470 TexOutput("<H3 ALIGN=CENTER>");
1471 TraverseChildrenFromChunk(DocumentDate
);
1472 TexOutput("</H3><P>\n\n");
1474 // TexOutput("\n</CENTER>\n");
1475 TexOutput("\n<P><HR><P>\n");
1478 // Now do optional frame contents page
1479 if (htmlFrameContents && FrameContents)
1481 SetCurrentOutput(FrameContents);
1483 // Add a special label for the contents page.
1484 TexOutput("<CENTER>\n");
1485 TexOutput("<H3>\n");
1486 TraverseChildrenFromChunk(DocumentTitle);
1489 TexOutput("</A>\n");
1490 TexOutput("<P>\n\n");
1492 TraverseChildrenFromChunk(DocumentAuthor);
1493 TexOutput("</H3><P>\n\n");
1497 TraverseChildrenFromChunk(DocumentDate);
1498 TexOutput("</H4><P>\n\n");
1500 TexOutput("\n</CENTER>\n");
1501 TexOutput("<P><HR><P>\n");
1503 SetCurrentOutput(Titlepage);
1516 helpRefFilename
= NULL
;
1521 case ltBIBLIOGRAPHY
:
1525 DefaultOnMacro(macroId
, no_args
, start
);
1529 DefaultOnMacro(macroId
, no_args
, start
);
1530 TexOutput("</DL>\n");
1538 TexOutput("<HR>\n");
1546 TexOutput("<HR>\n");
1550 case ltTABLEOFCONTENTS
:
1554 FILE *fd
= fopen(ContentsName
, "r");
1560 putc(ch
, Titlepage
);
1567 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1568 OnInform("Run Tex2RTF again to include contents page.");
1589 TexOutput("<BLOCKQUOTE>");
1591 TexOutput("</BLOCKQUOTE>");
1600 TexOutput("\n<CAPTION>");
1608 if (DocumentStyle
!= LATEX_ARTICLE
)
1609 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1611 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1617 if (DocumentStyle
!= LATEX_ARTICLE
)
1618 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1620 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1628 TexOutput("\n</CAPTION>\n");
1630 char *topicName
= FindTopicName(GetNextChunk());
1632 int n
= inFigure
? figureNo
: tableNo
;
1634 AddTexRef(topicName
, NULL
, NULL
,
1635 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1636 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1642 if (start
) TexOutput("ß");
1647 if (start
) inFigure
= TRUE
;
1648 else inFigure
= FALSE
;
1653 if (start
) inTable
= TRUE
;
1654 else inTable
= FALSE
;
1658 DefaultOnMacro(macroId
, no_args
, start
);
1663 // Called on start/end of argument examination
1664 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1670 case ltCHAPTERHEADING
:
1673 case ltSECTIONHEADING
:
1675 case ltSUBSECTIONSTAR
:
1676 case ltSUBSUBSECTION
:
1677 case ltSUBSUBSECTIONSTAR
:
1679 case ltMEMBERSECTION
:
1680 case ltFUNCTIONSECTION
:
1682 if (!start
&& (arg_no
== 1))
1683 currentSection
= GetArgChunk();
1689 if (start
&& (arg_no
== 1))
1692 if (!start
&& (arg_no
== 1))
1695 if (start
&& (arg_no
== 2))
1697 if (!suppressNameDecoration
) TexOutput("<B>");
1698 currentMember
= GetArgChunk();
1700 if (!start
&& (arg_no
== 2))
1702 if (!suppressNameDecoration
) TexOutput("</B>");
1705 if (start
&& (arg_no
== 3))
1707 if (!start
&& (arg_no
== 3))
1713 if (start
&& (arg_no
== 1))
1715 if (!start
&& (arg_no
== 1))
1718 if (start
&& (arg_no
== 2))
1720 if (!suppressNameDecoration
) TexOutput("( ");
1721 currentMember
= GetArgChunk();
1723 if (!start
&& (arg_no
== 2))
1727 if (!start
&& (arg_no
== 3))
1733 if (!start
&& (arg_no
== 1))
1736 if (start
&& (arg_no
== 2))
1738 if (!start
&& (arg_no
== 2))
1741 if (start
&& (arg_no
== 2))
1742 currentMember
= GetArgChunk();
1744 if (start
&& (arg_no
== 3))
1746 if (!start
&& (arg_no
== 3))
1752 if (start
&& (arg_no
== 1))
1754 if (!start
&& (arg_no
== 1))
1756 if (start
&& (arg_no
== 2))
1760 if (!start
&& (arg_no
== 2))
1768 if (start
&& (arg_no
== 1))
1770 if (!start
&& (arg_no
== 1))
1771 TexOutput("</B> "); // This is the difference from param - one space!
1772 if (start
&& (arg_no
== 2))
1776 if (!start
&& (arg_no
== 2))
1784 if (!start
&& (arg_no
== 1))
1787 if (start
&& (arg_no
== 2))
1788 currentMember
= GetArgChunk();
1797 char *refName
= GetArgData();
1800 TexRef
*texRef
= FindReference(refName
);
1803 sec
= texRef
->sectionNumber
;
1816 if (IsArgOptional())
1818 else if ((GetNoArgs() - arg_no
) == 1)
1821 helpRefText
= GetArgChunk();
1824 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1828 TexChunk
*ref
= GetArgChunk();
1829 TexOutput("<A HREF=\"");
1831 TraverseChildrenFromChunk(ref
);
1835 TraverseChildrenFromChunk(helpRefText
);
1846 if (IsArgOptional())
1849 helpRefFilename
= GetArgChunk();
1852 if ((GetNoArgs() - arg_no
) == 1)
1855 helpRefText
= GetArgChunk();
1858 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1862 char *refName
= GetArgData();
1863 char *refFilename
= NULL
;
1867 TexRef
*texRef
= FindReference(refName
);
1870 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1871 refFilename
= texRef
->refFile
;
1873 TexOutput("<A HREF=\"");
1874 // If a filename is supplied, use it, otherwise try to
1875 // use the filename associated with the reference (from this document).
1876 if (helpRefFilename
)
1878 TraverseChildrenFromChunk(helpRefFilename
);
1881 else if (refFilename
)
1883 TexOutput(ConvertCase(refFilename
));
1889 TraverseChildrenFromChunk(helpRefText
);
1895 TraverseChildrenFromChunk(helpRefText
);
1896 TexOutput(" (REF NOT FOUND)");
1899 else TexOutput("??");
1914 char *alignment
= "";
1915 if (macroId
== ltIMAGEL
)
1916 alignment
= " align=left";
1917 else if (macroId
== ltIMAGER
)
1918 alignment
= " align=right";
1920 // Try to find an XBM or GIF image first.
1921 char *filename
= copystring(GetArgData());
1924 strcpy(buf
, filename
);
1925 StripExtension(buf
);
1926 strcat(buf
, ".xbm");
1927 wxString f
= TexPathList
.FindValidPath(buf
);
1929 if (f
== "") // Try for a GIF instead
1931 strcpy(buf
, filename
);
1932 StripExtension(buf
);
1933 strcat(buf
, ".gif");
1934 f
= TexPathList
.FindValidPath(buf
);
1937 if (f
== "") // Try for a JPEG instead
1939 strcpy(buf
, filename
);
1940 StripExtension(buf
);
1941 strcat(buf
, ".jpg");
1942 f
= TexPathList
.FindValidPath(buf
);
1945 if (f
== "") // Try for a PNG instead
1947 strcpy(buf
, filename
);
1948 StripExtension(buf
);
1949 strcat(buf
, ".png");
1950 f
= TexPathList
.FindValidPath(buf
);
1955 char *inlineFilename
= copystring(f
);
1957 char *originalFilename
= TexPathList
.FindValidPath(filename
);
1958 // If we have found the existing filename, make the inline
1959 // image point to the original file (could be PS, for example)
1960 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
1962 TexOutput("<A HREF=\"");
1963 TexOutput(ConvertCase(originalFilename
));
1965 TexOutput("<img src=\"");
1966 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1967 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1972 TexOutput("<img src=\"");
1973 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1974 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1975 delete[] inlineFilename
;
1980 // Last resort - a link to a PS file.
1981 TexOutput("<A HREF=\"");
1982 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
1983 TexOutput("\">Picture</A>\n");
1984 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
1992 // First arg is PSBOX spec (ignored), second is image file, third is map name.
1995 static char *imageFile
= NULL
;
1996 if (start
&& (arg_no
== 2))
1998 // Try to find an XBM or GIF image first.
1999 char *filename
= copystring(GetArgData());
2002 strcpy(buf
, filename
);
2003 StripExtension(buf
);
2004 strcat(buf
, ".xbm");
2005 wxString f
= TexPathList
.FindValidPath(buf
);
2007 if (f
== "") // Try for a GIF instead
2009 strcpy(buf
, filename
);
2010 StripExtension(buf
);
2011 strcat(buf
, ".gif");
2012 f
= TexPathList
.FindValidPath(buf
);
2017 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2026 imageFile
= copystring(f
);
2029 else if (start
&& (arg_no
== 3))
2033 // First, try to find a .shg (segmented hypergraphics file)
2034 // that we can convert to a map file
2036 strcpy(buf
, imageFile
);
2037 StripExtension(buf
);
2038 strcat(buf
, ".shg");
2039 wxString f
= TexPathList
.FindValidPath(buf
);
2043 // The default HTML file to go to is THIS file (so a no-op)
2044 SHGToMap((char*) (const char*) f
, currentFileName
);
2047 char *mapName
= GetArgData();
2048 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2052 TexOutput("unknown");
2054 TexOutput("<img src=\"");
2055 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2056 TexOutput("\" ISMAP></A><P>");
2077 descriptionItemArg
= GetArgChunk();
2082 case ltTWOCOLITEMRULED
:
2085 if (start && (arg_no == 1))
2086 TexOutput("\n<DT> ");
2087 if (start && (arg_no == 2))
2093 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2095 TexOutput("\n</TD>\n");
2100 TexOutput("\n<TD VALIGN=TOP>\n");
2102 TexOutput("\n</TD></TR>\n");
2107 case ltNUMBEREDBIBITEM
:
2109 if (arg_no
== 1 && start
)
2111 TexOutput("\n<DT> ");
2113 if (arg_no
== 2 && !start
)
2120 if (arg_no
== 1 && start
)
2122 char *citeKey
= GetArgData();
2123 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2126 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2127 sprintf(buf
, "[%d]", citeCount
);
2128 ref
->sectionNumber
= copystring(buf
);
2131 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2136 if (arg_no
== 2 && !start
)
2142 case ltMARGINPARODD
:
2143 case ltMARGINPAREVEN
:
2149 TexOutput("<HR>\n");
2153 TexOutput("<HR><P>\n");
2160 case ltACCENT_GRAVE
:
2164 char *val
= GetArgData();
2170 TexOutput("à");
2173 TexOutput("è");
2176 TexOutput("ì");
2179 TexOutput("ò");
2182 TexOutput("ù");
2185 TexOutput("À");
2188 TexOutput("È");
2191 TexOutput("Ì");
2194 TexOutput("Ò");
2197 TexOutput("Ì");
2207 case ltACCENT_ACUTE
:
2211 char *val
= GetArgData();
2217 TexOutput("á");
2220 TexOutput("é");
2223 TexOutput("í");
2226 TexOutput("ó");
2229 TexOutput("ú");
2232 TexOutput("ý");
2235 TexOutput("Á");
2238 TexOutput("É");
2241 TexOutput("Í");
2244 TexOutput("Ó");
2247 TexOutput("Ú");
2250 TexOutput("Ý");
2260 case ltACCENT_CARET
:
2264 char *val
= GetArgData();
2270 TexOutput("â");
2273 TexOutput("ê");
2276 TexOutput("î");
2279 TexOutput("ô");
2282 TexOutput("û");
2285 TexOutput("Â");
2288 TexOutput("Ê");
2291 TexOutput("Î");
2294 TexOutput("Ô");
2297 TexOutput("Î");
2307 case ltACCENT_TILDE
:
2311 char *val
= GetArgData();
2320 TexOutput("ã");
2323 TexOutput("ñ");
2326 TexOutput("õ");
2329 TexOutput("Ã");
2332 TexOutput("Ñ");
2335 TexOutput("Õ");
2345 case ltACCENT_UMLAUT
:
2349 char *val
= GetArgData();
2355 TexOutput("ä");
2358 TexOutput("ë");
2361 TexOutput("ï");
2364 TexOutput("ö");
2367 TexOutput("ü");
2370 TexOutput("ÿ");
2373 TexOutput("Ä");
2376 TexOutput("Ë");
2379 TexOutput("Ï");
2382 TexOutput("Ö");
2385 TexOutput("Ü");
2388 TexOutput("Ÿ");
2402 char *val
= GetArgData();
2408 TexOutput("å");
2411 TexOutput("Å");
2425 char *val
= GetArgData();
2428 bool isPicture
= FALSE
;
2429 char *s
= ParseColourString(val
, &isPicture
);
2432 if (backgroundImageString
)
2433 delete[] backgroundImageString
;
2434 backgroundImageString
= copystring(val
);
2438 if (backgroundColourString
)
2439 delete[] backgroundColourString
;
2440 backgroundColourString
= copystring(val
);
2447 case ltBACKGROUNDIMAGE
:
2451 char *val
= GetArgData();
2454 if (backgroundImageString
)
2455 delete[] backgroundImageString
;
2456 backgroundImageString
= copystring(val
);
2462 case ltBACKGROUNDCOLOUR
:
2466 char *val
= GetArgData();
2469 if (backgroundColourString
)
2470 delete[] backgroundColourString
;
2471 backgroundColourString
= copystring(val
);
2481 char *val
= GetArgData();
2484 if (textColourString
)
2485 delete[] textColourString
;
2486 textColourString
= copystring(val
);
2496 char *val
= GetArgData();
2499 if (linkColourString
)
2500 delete[] linkColourString
;
2501 linkColourString
= copystring(val
);
2507 case ltFOLLOWEDLINKCOLOUR
:
2511 char *val
= GetArgData();
2514 if (followedLinkColourString
)
2515 delete[] followedLinkColourString
;
2516 followedLinkColourString
= copystring(val
);
2522 case ltACCENT_CADILLA
:
2526 char *val
= GetArgData();
2532 TexOutput("ç");
2535 TexOutput("Ç");
2547 case ltFOOTNOTEPOPUP:
2557 case ltSUPERTABULAR
:
2563 currentRowNumber
= 0;
2566 tableVerticalLineLeft
= FALSE
;
2567 tableVerticalLineRight
= FALSE
;
2568 int currentWidth
= 0;
2570 char *alignString
= copystring(GetArgData());
2571 ParseTableArgument(alignString
);
2573 TexOutput("<TABLE BORDER>\n");
2575 // Write the first row formatting for compatibility
2576 // with standard Latex
2577 if (compatibilityMode
)
2579 TexOutput("<TR>\n<TD>");
2581 for (int i = 0; i < noColumns; i++)
2583 currentWidth += TableData[i].width;
2584 sprintf(buf, "\\cellx%d", currentWidth);
2587 TexOutput("\\pard\\intbl\n");
2590 delete[] alignString
;
2595 else if (arg_no
== 2 && !start
)
2597 TexOutput("</TABLE>\n");
2602 case ltTHEBIBLIOGRAPHY
:
2604 if (start
&& (arg_no
== 1))
2606 ReopenFile(&Chapters
, &ChaptersName
);
2607 AddTexRef("bibliography", ChaptersName
, "bibliography");
2608 SetCurrentSubsectionName("bibliography", ChaptersName
);
2612 SetCurrentOutput(Chapters
);
2615 if (truncateFilenames
)
2616 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2618 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2620 TexOutput("<head><title>");
2621 TexOutput(ReferencesNameString
);
2622 TexOutput("</title></head>\n");
2625 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2626 AddBrowseButtons("contents", titleBuf
, // Up
2627 lastTopic
, lastFileName
, // Last topic
2628 "bibliography", ChaptersName
); // This topic
2630 SetCurrentOutputs(Contents
, Chapters
);
2631 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2633 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2634 fprintf(Chapters
, "</H2>\n</A>\n");
2636 SetCurrentOutput(Chapters
);
2639 if (!start
&& (arg_no
== 2))
2647 /* Build up list of keywords associated with topics */
2650 // char *entry = GetArgData();
2652 OutputChunkToString(GetArgChunk(), buf
);
2655 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2670 char *name
= GetArgData();
2672 if (!FindColourHTMLString(name
, buf2
))
2674 strcpy(buf2
, "#000000");
2676 sprintf(buf
, "Could not find colour name %s", name
);
2679 TexOutput("<FONT COLOR=\"");
2695 if (arg_no
== 2) TexOutput("</FONT>");
2700 case ltINSERTATLEVEL
:
2702 // This macro allows you to insert text at a different level
2703 // from the current level, e.g. into the Sections from within a subsubsection.
2706 static int currentLevelNo
= 1;
2707 static FILE* oldLevelFile
= Chapters
;
2714 oldLevelFile
= CurrentOutput1
;
2716 char *str
= GetArgData();
2717 currentLevelNo
= atoi(str
);
2719 // TODO: cope with article style (no chapters)
2720 switch (currentLevelNo
)
2724 outputFile
= Chapters
;
2729 outputFile
= Sections
;
2734 outputFile
= Subsections
;
2739 outputFile
= Subsubsections
;
2749 CurrentOutput1
= outputFile
;
2767 CurrentOutput1
= oldLevelFile
;
2773 return DefaultOnArgument(macroId
, arg_no
, start
);
2786 tableVerticalLineLeft
= FALSE
;
2787 tableVerticalLineRight
= FALSE
;
2790 if (InputFile
&& OutputFile
)
2792 // Do some HTML-specific transformations on all the strings,
2794 Text2HTML(GetTopLevelChunk());
2797 if (truncateFilenames
)
2798 sprintf(buf
, "%s.htm", FileRoot
);
2800 sprintf(buf
, "%s_contents.html", FileRoot
);
2801 if (TitlepageName
) delete[] TitlepageName
;
2802 TitlepageName
= copystring(buf
);
2803 Titlepage
= fopen(buf
, "w");
2805 if (truncateFilenames
)
2806 sprintf(buf
, "%s_fc.htm", FileRoot
);
2808 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2810 contentsFrameName
= copystring(buf
);
2812 Contents
= fopen(TmpContentsName
, "w");
2814 if (htmlFrameContents
)
2816 // FrameContents = fopen(TmpFrameContentsName, "w");
2817 FrameContents
= fopen(contentsFrameName
, "w");
2818 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2821 if (!Titlepage
|| !Contents
)
2823 OnError("Cannot open output file!");
2826 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2828 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2830 fprintf(Contents
, "<UL>\n");
2832 SetCurrentOutput(Titlepage
);
2833 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2834 OnInform("Converting...");
2837 fprintf(Contents
, "</UL>\n\n");
2839 // SetCurrentOutput(Titlepage);
2844 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2851 fprintf(FrameContents
, "\n</UL>\n");
2852 fprintf(FrameContents
, "</HTML>\n");
2853 fclose(FrameContents
);
2854 FrameContents
= NULL
;
2859 fprintf(Chapters
, "\n</BODY></HTML>\n");
2865 fprintf(Sections
, "\n</BODY></HTML>\n");
2869 if (Subsections
&& !combineSubSections
)
2871 fprintf(Subsections
, "\n</BODY></HTML>\n");
2872 fclose(Subsections
);
2875 if (Subsubsections
&& !combineSubSections
)
2877 fprintf(Subsubsections
, "\n</BODY></HTML>\n");
2878 fclose(Subsubsections
);
2879 Subsubsections
= NULL
;
2881 if ( SectionContentsFD
)
2883 fclose(SectionContentsFD
);
2884 SectionContentsFD
= NULL
;
2887 // Create a temporary file for the title page header, add some info,
2888 // and concat the titlepage just generated.
2889 // This is necessary in order to put the title of the document
2890 // at the TOP of the file within <HEAD>, even though we only find out
2891 // what it is later on.
2892 FILE *tmpTitle
= fopen("title.tmp", "w");
2897 SetCurrentOutput(tmpTitle
);
2898 TexOutput("\n<HTML>\n<HEAD><TITLE>");
2899 TraverseChildrenFromChunk(DocumentTitle
);
2900 TexOutput("</TITLE></HEAD>\n");
2904 SetCurrentOutput(tmpTitle
);
2906 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
2908 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
2911 // Output frame information
2912 if (htmlFrameContents
)
2914 char firstFileName
[300];
2915 if (truncateFilenames
)
2916 sprintf(firstFileName
, "%s1.htm", FileRoot
);
2918 sprintf(firstFileName
, "%s1.html", FileRoot
);
2920 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
2922 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
2923 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
2924 fprintf(tmpTitle
, "</FRAMESET>\n");
2926 fprintf(tmpTitle
, "<NOFRAMES>\n");
2929 // Output <BODY...> to temporary title page
2933 FILE *fd
= fopen(TitlepageName
, "r");
2945 fprintf(tmpTitle
, "\n</BODY>\n");
2947 if (htmlFrameContents
)
2949 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
2951 fprintf(tmpTitle
, "\n</HTML>\n");
2954 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
2955 if (!wxRenameFile("title.tmp", TitlepageName
))
2957 wxCopyFile("title.tmp", TitlepageName
);
2958 wxRemoveFile("title.tmp");
2962 if (lastFileName
) delete[] lastFileName
;
2963 lastFileName
= NULL
;
2964 if (lastTopic
) delete[] lastTopic
;
2967 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
2969 if (!wxRenameFile(TmpContentsName
, ContentsName
))
2971 wxCopyFile(TmpContentsName
, ContentsName
);
2972 wxRemoveFile(TmpContentsName
);
2975 // Generate .htx file if requested
2978 char htmlIndexName
[300];
2979 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
2980 GenerateHTMLIndexFile(htmlIndexName
);
2983 // Generate HTML Help Workshop files if requested
2984 if (htmlWorkshopFiles
)
2986 HTMLWorkshopEndContents();
2987 GenerateHTMLWorkshopFiles(FileRoot
);
2997 // Output .htx index file
2998 void GenerateHTMLIndexFile(char *fname
)
3000 FILE *fd
= fopen(fname
, "w");
3004 TopicTable
.BeginFind();
3005 wxNode
*node
= NULL
;
3006 while ((node
= TopicTable
.Next()))
3008 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3009 const char *topicName
= node
->GetKeyString();
3010 if (texTopic
->filename
&& texTopic
->keywords
)
3012 wxNode
*node1
= texTopic
->keywords
->First();
3015 char *s
= (char *)node1
->Data();
3016 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3017 node1
= node1
->Next();
3030 // output .hpp, .hhc and .hhk files:
3033 void GenerateHTMLWorkshopFiles(char *fname
)
3038 /* Generate project file : */
3040 sprintf(buf
, "%s.hhp", fname
);
3041 f
= fopen(buf
, "wt");
3044 "Compatibility=1.1\n"
3045 "Full-text search=Yes\n"
3046 "Contents file=%s.hhc\n"
3047 "Compiled file=%s.chm\n"
3048 "Default Window=%sHelp\n"
3049 "Default topic=%s\n"
3050 "Index file=%s.hhk\n"
3052 FileNameFromPath(fname
),
3053 FileNameFromPath(fname
),
3054 FileNameFromPath(fname
),
3055 FileNameFromPath(TitlepageName
),
3056 FileNameFromPath(fname
)
3059 if (DocumentTitle
) {
3060 SetCurrentOutput(f
);
3061 TraverseChildrenFromChunk(DocumentTitle
);
3063 else fprintf(f
, "(unknown)");
3065 fprintf(f
, "\n\n[WINDOWS]\n"
3066 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3067 FileNameFromPath(fname
),
3068 FileNameFromPath(fname
),
3069 FileNameFromPath(fname
),
3070 FileNameFromPath(TitlepageName
));
3073 fprintf(f
, "\n\n[FILES]\n");
3074 fprintf(f
, "%s\n", FileNameFromPath(TitlepageName
));
3075 for (int i
= 1; i
<= fileId
; i
++) {
3076 if (truncateFilenames
)
3077 sprintf(buf
, "%s%d.htm", FileNameFromPath(FileRoot
), i
);
3079 sprintf(buf
, "%s%d.html", FileNameFromPath(FileRoot
), i
);
3080 fprintf(f
, "%s\n", buf
);
3084 /* Generate index file : */
3086 sprintf(buf
, "%s.hhk", fname
);
3087 f
= fopen(buf
, "wt");
3090 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3093 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3094 "<!-- Sitemap 1.0 -->\n"
3096 "<OBJECT type=\"text/site properties\">\n"
3097 " <param name=\"ImageType\" value=\"Folder\">\n"
3101 TopicTable
.BeginFind();
3102 wxNode
*node
= NULL
;
3103 while ((node
= TopicTable
.Next()))
3105 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3106 const char *topicName
= node
->GetKeyString();
3107 if (texTopic
->filename
&& texTopic
->keywords
)
3109 wxNode
*node1
= texTopic
->keywords
->First();
3112 char *s
= (char *)node1
->Data();
3114 " <LI> <OBJECT type=\"text/sitemap\">\n"
3115 " <param name=\"Local\" value=\"%s#%s\">\n"
3116 " <param name=\"Name\" value=\"%s\">\n"
3118 texTopic
->filename
, topicName
, s
);
3119 node1
= node1
->Next();
3124 fprintf(f
, "</UL>\n");
3130 static FILE *HTMLWorkshopContents
= NULL
;
3131 static int HTMLWorkshopLastLevel
= 0;
3133 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3137 if (level
> HTMLWorkshopLastLevel
)
3138 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3139 fprintf(HTMLWorkshopContents
, "<UL>");
3140 if (level
< HTMLWorkshopLastLevel
)
3141 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3142 fprintf(HTMLWorkshopContents
, "</UL>");
3144 SetCurrentOutput(HTMLWorkshopContents
);
3145 fprintf(HTMLWorkshopContents
,
3146 " <LI> <OBJECT type=\"text/sitemap\">\n"
3147 " <param name=\"Local\" value=\"%s#%s\">\n"
3148 " <param name=\"Name\" value=\"",
3150 OutputCurrentSection();
3151 fprintf(HTMLWorkshopContents
,
3154 HTMLWorkshopLastLevel
= level
;
3158 void HTMLWorkshopStartContents()
3161 sprintf(buf
, "%s.hhc", FileRoot
);
3162 HTMLWorkshopContents
= fopen(buf
, "wt");
3163 HTMLWorkshopLastLevel
= 0;
3165 fprintf(HTMLWorkshopContents
,
3166 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3169 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3170 "<!-- Sitemap 1.0 -->\n"
3172 "<OBJECT type=\"text/site properties\">\n"
3173 " <param name=\"ImageType\" value=\"Folder\">\n"
3176 "<LI> <OBJECT type=\"text/sitemap\">\n"
3177 "<param name=\"Local\" value=\"%s\">\n"
3178 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3179 FileNameFromPath(TitlepageName
)
3185 void HTMLWorkshopEndContents()
3187 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3188 fprintf(HTMLWorkshopContents
, "</UL>\n");
3189 fclose(HTMLWorkshopContents
);