]>
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
);
33 void OutputContentsFrame(void);
35 #include "readshg.h" // Segmented hypergraphics parsing
37 char *ChaptersName
= NULL
;
38 char *SectionsName
= NULL
;
39 char *SubsectionsName
= NULL
;
40 char *SubsubsectionsName
= NULL
;
41 char *TitlepageName
= NULL
;
42 char *lastFileName
= NULL
;
43 char *lastTopic
= NULL
;
44 char *currentFileName
= NULL
;
45 char *contentsFrameName
= NULL
;
47 static TexChunk
*descriptionItemArg
= NULL
;
48 static TexChunk
*helpRefFilename
= NULL
;
49 static TexChunk
*helpRefText
= NULL
;
50 static int indentLevel
= 0;
51 static int citeCount
= 1;
52 extern FILE *Contents
;
53 FILE *FrameContents
= NULL
;
54 FILE *Titlepage
= NULL
;
55 // FILE *FrameTitlepage = NULL;
57 bool subsectionStarted
= FALSE
;
59 // Which column of a row are we in? (Assumes no nested tables, of course)
60 int currentColumn
= 0;
62 // Are we in verbatim mode? If so, format differently.
63 static bool inVerbatim
= FALSE
;
65 // Need to know whether we're in a table or figure for benefit
66 // of listoffigures/listoftables
67 static bool inFigure
= FALSE
;
68 static bool inTable
= FALSE
;
70 // This is defined in the Tex2Any library.
71 extern char *BigBuffer
;
73 class HyperReference
: public wxObject
78 HyperReference(char *name
, char *file
)
80 if (name
) refName
= copystring(name
);
81 if (file
) refFile
= copystring(file
);
85 class TexNextPage
: public wxObject
90 TexNextPage(char *theLabel
, char *theFile
)
92 label
= copystring(theLabel
);
93 filename
= copystring(theFile
);
102 wxHashTable
TexNextPages(wxKEY_STRING
);
104 static char *CurrentChapterName
= NULL
;
105 static char *CurrentChapterFile
= NULL
;
106 static char *CurrentSectionName
= NULL
;
107 static char *CurrentSectionFile
= NULL
;
108 static char *CurrentSubsectionName
= NULL
;
109 static char *CurrentSubsectionFile
= NULL
;
110 static char *CurrentSubsubsectionName
= NULL
;
111 static char *CurrentSubsubsectionFile
= NULL
;
112 static char *CurrentTopic
= NULL
;
114 static void SetCurrentTopic(char *s
)
116 if (CurrentTopic
) delete[] CurrentTopic
;
117 CurrentTopic
= copystring(s
);
120 void SetCurrentChapterName(char *s
, char *file
)
122 if (CurrentChapterName
) delete[] CurrentChapterName
;
123 CurrentChapterName
= copystring(s
);
124 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
125 CurrentChapterFile
= copystring(file
);
127 currentFileName
= CurrentChapterFile
;
131 void SetCurrentSectionName(char *s
, char *file
)
133 if (CurrentSectionName
) delete[] CurrentSectionName
;
134 CurrentSectionName
= copystring(s
);
135 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
136 CurrentSectionFile
= copystring(file
);
138 currentFileName
= CurrentSectionFile
;
141 void SetCurrentSubsectionName(char *s
, char *file
)
143 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
144 CurrentSubsectionName
= copystring(s
);
145 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
146 CurrentSubsectionFile
= copystring(file
);
147 currentFileName
= CurrentSubsectionFile
;
150 void SetCurrentSubsubsectionName(char *s
, char *file
)
152 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
153 CurrentSubsubsectionName
= copystring(s
);
154 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
155 CurrentSubsubsectionFile
= copystring(file
);
156 currentFileName
= CurrentSubsubsectionFile
;
161 * Close former filedescriptor and reopen using another filename.
165 void ReopenFile(FILE **fd
, char **fileName
)
169 fprintf(*fd
, "\n</BODY></HTML>\n");
174 if (truncateFilenames
)
175 sprintf(buf
, "%s%d.htm", FileRoot
, fileId
);
177 sprintf(buf
, "%s%d.html", FileRoot
, fileId
);
178 if (*fileName
) delete[] *fileName
;
179 *fileName
= copystring(FileNameFromPath(buf
));
180 *fd
= fopen(buf
, "w");
181 fprintf(*fd
, "<HTML>\n");
185 * Reopen section contents file, i.e. the index appended to each section
186 * in subsectionCombine mode
189 static char *SectionContentsFilename
= NULL
;
190 static FILE *SectionContentsFD
= NULL
;
192 void ReopenSectionContentsFile(void)
194 if ( SectionContentsFD
)
196 fclose(SectionContentsFD
);
198 if ( SectionContentsFilename
)
199 delete[] SectionContentsFilename
;
200 SectionContentsFD
= NULL
;
201 SectionContentsFilename
= NULL
;
203 // Create the name from the current section filename
204 if ( CurrentSectionFile
)
207 strcpy(buf
, CurrentSectionFile
);
208 wxStripExtension(buf
);
210 SectionContentsFilename
= copystring(buf
);
212 SectionContentsFD
= fopen(SectionContentsFilename
, "w");
218 * Given a TexChunk with a string value, scans through the string
219 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
223 void ProcessText2HTML(TexChunk
*chunk
)
225 bool changed
= FALSE
;
229 int len
= strlen(chunk
->value
);
232 ch
= chunk
->value
[i
];
234 // 2 newlines means \par
235 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
236 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
237 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
239 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "<P>\n\n"); ptr
+= 5;
243 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
245 BigBuffer
[ptr
] = '"'; ptr
++;
249 else if (!inVerbatim
&& ch
== '`') // Change ` to '
251 BigBuffer
[ptr
] = 39; ptr
++;
255 else if (ch
== '<') // Change < to <
258 strcat(BigBuffer
, "<");
263 else if (ch
== '>') // Change > to >
266 strcat(BigBuffer
, ">");
283 chunk
->value
= copystring(BigBuffer
);
288 * Scan through all chunks starting from the given one,
289 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
290 * This should be called after Tex2Any has parsed the file,
291 * and before TraverseDocument is called.
295 void Text2HTML(TexChunk
*chunk
)
298 if (stopRunning
) return;
302 case CHUNK_TYPE_MACRO
:
304 TexMacroDef
*def
= chunk
->def
;
306 if (def
&& def
->ignore
)
309 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
312 wxNode
*node
= chunk
->children
.First();
315 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
316 Text2HTML(child_chunk
);
320 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
);
337 case CHUNK_TYPE_STRING
:
340 ProcessText2HTML(chunk
);
347 * Add appropriate browse buttons to this page.
351 void AddBrowseButtons(char *upLabel
, char *upFilename
,
352 char *previousLabel
, char *previousFilename
,
353 char *thisLabel
, char *thisFilename
)
355 char contentsReferenceBuf
[80];
356 char upReferenceBuf
[80];
357 char backReferenceBuf
[80];
358 char forwardReferenceBuf
[80];
359 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
362 char *contentsReference
= NULL
;
363 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
364 contentsReference
= ContentsNameString
;
367 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
368 contentsReference
= contentsReferenceBuf
;
369 sprintf(contentsReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">", ConvertCase("contents.gif"));
372 char *upReference
= NULL
;
373 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
374 upReference
= UpNameString
;
377 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
378 upReference
= upReferenceBuf
;
379 sprintf(upReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">", ConvertCase("up.gif"));
382 char *backReference
= NULL
;
383 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
384 backReference
= "<<";
387 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
388 backReference
= backReferenceBuf
;
389 sprintf(backReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">", ConvertCase("back.gif"));
392 char *forwardReference
= NULL
;
393 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
394 forwardReference
= ">>";
397 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
398 forwardReference
= forwardReferenceBuf
;
399 sprintf(forwardReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">", ConvertCase("forward.gif"));
402 TexOutput("<CENTER>");
411 if (truncateFilenames
)
414 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
415 sprintf(buf
, "\n<A HREF=\"%s.%s\">%s</A> ", buf1
, ConvertCase("htm"), contentsReference
);
420 strcpy(buf1
, ConvertCase(FileNameFromPath(FileRoot
)));
421 sprintf(buf
, "\n<A HREF=\"%s%s\">%s</A> ", buf1
, ConvertCase("_contents.html"), contentsReference
);
423 // TexOutput("<NOFRAMES>");
425 // TexOutput("</NOFRAMES>");
432 if (upLabel
&& upFilename
)
434 if (strlen(upLabel
) > 0)
435 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(upFilename
), upLabel
, upReference
);
437 sprintf(buf
, "<A HREF=\"%s\">%s</A> ", ConvertCase(upFilename
), upReference
);
438 if (strcmp(upLabel
, "contents") == 0)
440 // TexOutput("<NOFRAMES>");
442 // TexOutput("</NOFRAMES>");
453 if (previousLabel
&& previousFilename
)
455 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(previousFilename
), previousLabel
, backReference
);
456 if (strcmp(previousLabel
, "contents") == 0)
458 // TexOutput("<NOFRAMES>");
460 // TexOutput("</NOFRAMES>");
467 // A placeholder so the buttons don't keep moving position
468 sprintf(buf
, "%s ", backReference
);
472 char *nextLabel
= NULL
;
473 char *nextFilename
= NULL
;
475 // Get the next page, and record the previous page's 'next' page
477 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
480 nextLabel
= nextPage
->label
;
481 nextFilename
= nextPage
->filename
;
483 if (previousLabel
&& previousFilename
)
485 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
489 TexNextPages
.Delete(previousLabel
);
491 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
492 TexNextPages
.Put(previousLabel
, newNextPage
);
500 if (nextLabel
&& nextFilename
)
502 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(nextFilename
), nextLabel
, forwardReference
);
507 // A placeholder so the buttons don't keep moving position
508 sprintf(buf
, "%s ", forwardReference
);
513 * Horizontal rule to finish it off nicely.
516 TexOutput("</CENTER>");
519 // Update last topic/filename
521 delete[] lastFileName
;
522 lastFileName
= copystring(thisFilename
);
525 lastTopic
= copystring(thisLabel
);
528 // A colour string is either 3 numbers separated by semicolons (RGB),
529 // or a reference to a GIF. Return the filename or a hex string like #934CE8
530 char *ParseColourString(char *bkStr
, bool *isPicture
)
532 static char resStr
[300];
533 strcpy(resStr
, bkStr
);
534 char *tok1
= strtok(resStr
, ";");
535 char *tok2
= strtok(NULL
, ";");
546 char *tok3
= strtok(NULL
, ";");
549 // Now convert 3 strings into decimal numbers, and then hex numbers.
550 int red
= atoi(tok1
);
551 int green
= atoi(tok2
);
552 int blue
= atoi(tok3
);
559 DecToHex(green
, buf
);
571 // Output start of <BODY> block
572 void OutputBodyStart(void)
574 TexOutput("\n<BODY");
575 if (backgroundImageString
)
577 bool isPicture
= FALSE
;
578 char *s
= ParseColourString(backgroundImageString
, &isPicture
);
581 TexOutput(" BACKGROUND=\""); TexOutput(s
); TexOutput("\"");
584 if (backgroundColourString
)
586 bool isPicture
= FALSE
;
587 char *s
= ParseColourString(backgroundColourString
, &isPicture
);
590 TexOutput(" BGCOLOR="); TexOutput(s
);
594 // Set foreground text colour, if one is specified
595 if (textColourString
)
597 bool isPicture
= FALSE
;
598 char *s
= ParseColourString(textColourString
, &isPicture
);
601 TexOutput(" TEXT="); TexOutput(s
);
604 // Set link text colour, if one is specified
605 if (linkColourString
)
607 bool isPicture
= FALSE
;
608 char *s
= ParseColourString(linkColourString
, &isPicture
);
611 TexOutput(" LINK="); TexOutput(s
);
614 // Set followed link text colour, if one is specified
615 if (followedLinkColourString
)
617 bool isPicture
= FALSE
;
618 char *s
= ParseColourString(followedLinkColourString
, &isPicture
);
621 TexOutput(" VLINK="); TexOutput(s
);
627 // Called on start/end of macro examination
628 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
634 case ltCHAPTERHEADING
:
642 if (macroId
!= ltCHAPTERSTAR
)
645 SetCurrentOutput(NULL
);
646 startedSections
= TRUE
;
648 char *topicName
= FindTopicName(GetNextChunk());
649 ReopenFile(&Chapters
, &ChaptersName
);
650 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
652 SetCurrentChapterName(topicName
, ChaptersName
);
654 SetCurrentOutput(Chapters
);
656 TexOutput("<head><title>");
657 OutputCurrentSection(); // Repeat section header
658 TexOutput("</title></head>\n");
662 if (truncateFilenames
)
663 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
665 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
667 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
669 AddBrowseButtons("", titleBuf
, // Up
670 lastTopic
, lastFileName
, // Last topic
671 topicName
, ChaptersName
); // This topic
673 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
675 if (htmlFrameContents
&& FrameContents
)
677 SetCurrentOutput(FrameContents
);
678 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
679 OutputCurrentSection();
680 fprintf(FrameContents
, "</A>\n");
683 SetCurrentOutputs(Contents
, Chapters
);
684 fprintf(Chapters
, "\n<H2>");
685 OutputCurrentSection();
686 fprintf(Contents
, "</A>\n");
687 fprintf(Chapters
, "</H2>\n");
689 SetCurrentOutput(Chapters
);
691 // Add this section title to the list of keywords
694 OutputCurrentSectionToString(wxBuffer
);
695 AddKeyWordForTopic(topicName
, wxBuffer
, ConvertCase(currentFileName
));
702 case ltSECTIONHEADING
:
709 subsectionStarted
= FALSE
;
711 if (macroId
!= ltSECTIONSTAR
)
714 SetCurrentOutput(NULL
);
715 startedSections
= TRUE
;
717 char *topicName
= FindTopicName(GetNextChunk());
718 ReopenFile(&Sections
, &SectionsName
);
719 AddTexRef(topicName
, SectionsName
, SectionNameString
);
721 SetCurrentSectionName(topicName
, SectionsName
);
723 SetCurrentOutput(Sections
);
724 TexOutput("<head><title>");
725 OutputCurrentSection();
726 TexOutput("</title></head>\n");
729 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
730 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
731 lastTopic
, lastFileName
, // Last topic
732 topicName
, SectionsName
); // This topic
734 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
736 SetCurrentOutputs(jumpFrom
, Sections
);
737 if (DocumentStyle
== LATEX_ARTICLE
)
738 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
740 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
742 fprintf(Sections
, "\n<H2>");
743 OutputCurrentSection();
745 if (DocumentStyle
== LATEX_ARTICLE
)
746 fprintf(jumpFrom
, "</A>\n");
748 fprintf(jumpFrom
, "</B></A><BR>\n");
749 fprintf(Sections
, "</H2>\n");
751 SetCurrentOutput(Sections
);
752 // Add this section title to the list of keywords
755 OutputCurrentSectionToString(wxBuffer
);
756 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
762 case ltSUBSECTIONSTAR
:
763 case ltMEMBERSECTION
:
764 case ltFUNCTIONSECTION
:
770 OnError("You cannot have a subsection before a section!");
776 if (macroId
!= ltSUBSECTIONSTAR
)
779 if ( combineSubSections
&& !subsectionStarted
)
781 // Read old .con file in at this point
783 strcpy(buf
, CurrentSectionFile
);
784 wxStripExtension(buf
);
786 FILE *fd
= fopen(buf
, "r");
797 fprintf(Sections
, "<P>\n");
799 // Close old file, create a new file for the sub(sub)section contents entries
800 ReopenSectionContentsFile();
803 startedSections
= TRUE
;
804 subsectionStarted
= TRUE
;
806 char *topicName
= FindTopicName(GetNextChunk());
808 if ( !combineSubSections
)
810 SetCurrentOutput(NULL
);
811 ReopenFile(&Subsections
, &SubsectionsName
);
812 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
813 SetCurrentSubsectionName(topicName
, SubsectionsName
);
814 SetCurrentOutput(Subsections
);
816 TexOutput("<head><title>");
817 OutputCurrentSection();
818 TexOutput("</title></head>\n");
821 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
822 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
823 lastTopic
, lastFileName
, // Last topic
824 topicName
, SubsectionsName
); // This topic
826 SetCurrentOutputs(Sections
, Subsections
);
827 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
829 fprintf(Subsections
, "\n<H3>");
830 OutputCurrentSection();
831 fprintf(Sections
, "</B></A><BR>\n");
832 fprintf(Subsections
, "</H3>\n");
834 SetCurrentOutput(Subsections
);
838 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
839 SetCurrentSubsectionName(topicName
, SectionsName
);
840 // if ( subsectionNo != 0 )
841 fprintf(Sections
, "\n<HR>\n");
843 // We're putting everything into the section file
844 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
845 fprintf(Sections
, "\n<H3>");
846 OutputCurrentSection();
847 fprintf(Sections
, "</H3>\n");
849 SetCurrentOutput(SectionContentsFD
);
850 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
851 OutputCurrentSection();
852 TexOutput("</A><BR>\n");
854 SetCurrentOutput(Sections
);
856 // Add this section title to the list of keywords
859 OutputCurrentSectionToString(wxBuffer
);
860 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
867 case ltSUBSUBSECTION
:
868 case ltSUBSUBSECTIONSTAR
:
872 if (!Subsections
&& !combineSubSections
)
874 OnError("You cannot have a subsubsection before a subsection!");
878 if (macroId
!= ltSUBSUBSECTIONSTAR
)
881 startedSections
= TRUE
;
883 char *topicName
= FindTopicName(GetNextChunk());
885 if ( !combineSubSections
)
887 SetCurrentOutput(NULL
);
888 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
889 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
890 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
892 SetCurrentOutput(Subsubsections
);
893 TexOutput("<head><title>");
894 OutputCurrentSection();
895 TexOutput("</title></head>\n");
898 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
900 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
901 lastTopic
, lastFileName
, // Last topic
902 topicName
, SubsubsectionsName
); // This topic
904 SetCurrentOutputs(Subsections
, Subsubsections
);
905 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
907 fprintf(Subsubsections
, "\n<H3>");
908 OutputCurrentSection();
909 fprintf(Subsections
, "</B></A><BR>\n");
910 fprintf(Subsubsections
, "</H3>\n");
914 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
915 SetCurrentSubsectionName(topicName
, SectionsName
);
916 fprintf(Sections
, "\n<HR>\n");
918 // We're putting everything into the section file
919 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
920 fprintf(Sections
, "\n<H3>");
921 OutputCurrentSection();
922 fprintf(Sections
, "</H3>\n");
923 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
924 SetCurrentOutput(SectionContentsFD);
925 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
926 OutputCurrentSection();
927 TexOutput("</A><BR>");
929 SetCurrentOutput(Sections
);
932 // Add this section title to the list of keywords
935 OutputCurrentSectionToString(wxBuffer
);
936 AddKeyWordForTopic(topicName
, wxBuffer
, currentFileName
);
945 if ( !combineSubSections
)
946 SetCurrentOutput(Subsections
);
948 SetCurrentOutput(Sections
);
959 if ( !combineSubSections
)
960 SetCurrentOutput(Subsections
);
962 SetCurrentOutput(Sections
);
973 if ( !combineSubSections
)
974 SetCurrentOutput(Subsections
);
976 SetCurrentOutput(Sections
);
987 // TexOutput("<B>void</B>");
995 TexOutput("wxCLIPS");
1001 case ltSPECIALAMPERSAND
:
1007 // End cell, start cell
1010 // Start new row and cell, setting alignment for the first cell.
1011 if (currentColumn
< noColumns
)
1015 if (TableData
[currentColumn
].justification
== 'c')
1016 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1017 else if (TableData
[currentColumn
].justification
== 'r')
1018 sprintf(buf
, "\n<TD ALIGN=RIGHT>");
1019 else if (TableData
[currentColumn
].absWidth
)
1021 // Convert from points * 20 into pixels.
1022 int points
= TableData
[currentColumn
].width
/ 20;
1024 // Say the display is 100 DPI (dots/pixels per inch).
1025 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1026 int pixels
= (int)(points
* 100.0 / 72.0);
1027 sprintf(buf
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1030 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1038 case ltBACKSLASHCHAR
:
1044 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1045 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1046 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1047 TexOutput("</TR>\n");
1050 TexOutput("<BR>\n");
1061 // Start new row and cell, setting alignment for the first cell.
1063 if (TableData
[currentColumn
].justification
== 'c')
1064 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1065 else if (TableData
[currentColumn
].justification
== 'r')
1066 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1067 else if (TableData
[currentColumn
].absWidth
)
1069 // Convert from points * 20 into pixels.
1070 int points
= TableData
[currentColumn
].width
/ 20;
1072 // Say the display is 100 DPI (dots/pixels per inch).
1073 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1074 int pixels
= (int)(points
* 100.0 / 72.0);
1075 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1078 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1084 // Start new row and cell
1085 TexOutput("</TD>\n</TR>\n");
1089 // HTML-only: break until the end of the picture (both margins are clear).
1093 TexOutput("<BR CLEAR=ALL>");
1096 case ltRTFSP
: // Explicit space, RTF only
1098 case ltSPECIALTILDE
:
1112 TexOutput("<UL><UL>\n");
1114 TexOutput("</UL></UL>\n");
1120 // case ltTWOCOLLIST:
1127 if (macroId
== ltENUMERATE
)
1128 listType
= LATEX_ENUMERATE
;
1129 else if (macroId
== ltITEMIZE
)
1130 listType
= LATEX_ITEMIZE
;
1132 listType
= LATEX_DESCRIPTION
;
1134 itemizeStack
.Insert(new ItemizeStruc(listType
));
1138 TexOutput("<UL>\n");
1140 case LATEX_ENUMERATE
:
1141 TexOutput("<OL>\n");
1143 case LATEX_DESCRIPTION
:
1145 TexOutput("<DL>\n");
1152 if (itemizeStack
.First())
1154 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1155 switch (struc
->listType
)
1158 TexOutput("</UL>\n");
1160 case LATEX_ENUMERATE
:
1161 TexOutput("</OL>\n");
1163 case LATEX_DESCRIPTION
:
1165 TexOutput("</DL>\n");
1170 delete itemizeStack
.First();
1178 TexOutput("\n<TABLE>\n");
1180 TexOutput("\n</TABLE>\n");
1189 /* For footnotes we need to output the text at the bottom of the page and
1190 * insert a reference to it. Is it worth the trouble...
1192 case ltFOOTNOTEPOPUP:
1198 else TexOutput("</FN>");
1206 else TexOutput("</TT>");
1214 sprintf(buf
, "<PRE>\n");
1217 else TexOutput("</PRE>\n");
1225 TexOutput("<CENTER>");
1227 else TexOutput("</CENTER>");
1235 TexOutput("{\\ql ");
1237 else TexOutput("}\\par\\pard\n");
1246 TexOutput("{\\qr ");
1248 else TexOutput("}\\par\\pard\n");
1256 // Netscape extension
1257 TexOutput("<FONT SIZE=2>");
1259 else TexOutput("</FONT>");
1266 // Netscape extension
1267 TexOutput("<FONT SIZE=1>");
1269 else TexOutput("</FONT>");
1276 // Netscape extension
1277 TexOutput("<FONT SIZE=3>");
1279 else TexOutput("</FONT>");
1286 // Netscape extension
1287 TexOutput("<FONT SIZE=4>");
1289 else TexOutput("</FONT>");
1296 // Netscape extension
1297 TexOutput("<FONT SIZE=5>");
1299 else TexOutput("</FONT>");
1306 // Netscape extension
1307 TexOutput("<FONT SIZE=6>");
1309 else TexOutput("</FONT>");
1320 else TexOutput("</B>");
1331 else TexOutput("</I>");
1341 else TexOutput("</EM>");
1350 else TexOutput("</UL>");
1361 else TexOutput("</TT>");
1367 TexOutput("©", TRUE
);
1373 TexOutput("®", TRUE
);
1379 if (start
) TexOutput("<--");
1384 if (start
) TexOutput("<==");
1389 if (start
) TexOutput("-->");
1394 if (start
) TexOutput("==>");
1397 case ltLEFTRIGHTARROW
:
1399 if (start
) TexOutput("<-->");
1402 case ltLEFTRIGHTARROW2
:
1404 if (start
) TexOutput("<==>");
1417 wxNode
*node
= itemizeStack
.First();
1420 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1421 struc
->currentItem
+= 1;
1422 if (struc
->listType
== LATEX_DESCRIPTION
)
1424 if (descriptionItemArg
)
1427 TraverseChildrenFromChunk(descriptionItemArg
);
1429 descriptionItemArg
= NULL
;
1441 if (start
&& DocumentTitle
&& DocumentAuthor
)
1443 // Add a special label for the contents page.
1444 // TexOutput("<CENTER>\n");
1445 TexOutput("<A NAME=\"contents\">");
1446 TexOutput("<H2 ALIGN=CENTER>\n");
1447 TraverseChildrenFromChunk(DocumentTitle
);
1450 TexOutput("</A>\n");
1451 TexOutput("<P>\n\n");
1452 TexOutput("<H3 ALIGN=CENTER>");
1453 TraverseChildrenFromChunk(DocumentAuthor
);
1454 TexOutput("</H3><P>\n\n");
1457 TexOutput("<H3 ALIGN=CENTER>");
1458 TraverseChildrenFromChunk(DocumentDate
);
1459 TexOutput("</H3><P>\n\n");
1461 // TexOutput("\n</CENTER>\n");
1462 TexOutput("\n<P><HR><P>\n");
1465 // Now do optional frame contents page
1466 if (htmlFrameContents && FrameContents)
1468 SetCurrentOutput(FrameContents);
1470 // Add a special label for the contents page.
1471 TexOutput("<CENTER>\n");
1472 TexOutput("<H3>\n");
1473 TraverseChildrenFromChunk(DocumentTitle);
1476 TexOutput("</A>\n");
1477 TexOutput("<P>\n\n");
1479 TraverseChildrenFromChunk(DocumentAuthor);
1480 TexOutput("</H3><P>\n\n");
1484 TraverseChildrenFromChunk(DocumentDate);
1485 TexOutput("</H4><P>\n\n");
1487 TexOutput("\n</CENTER>\n");
1488 TexOutput("<P><HR><P>\n");
1490 SetCurrentOutput(Titlepage);
1503 helpRefFilename
= NULL
;
1508 case ltBIBLIOGRAPHY
:
1512 DefaultOnMacro(macroId
, no_args
, start
);
1516 DefaultOnMacro(macroId
, no_args
, start
);
1517 TexOutput("</DL>\n");
1525 TexOutput("<HR>\n");
1533 TexOutput("<HR>\n");
1537 case ltTABLEOFCONTENTS
:
1541 FILE *fd
= fopen(ContentsName
, "r");
1547 putc(ch
, Titlepage
);
1554 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1555 OnInform("Run Tex2RTF again to include contents page.");
1576 TexOutput("<BLOCKQUOTE>");
1578 TexOutput("</BLOCKQUOTE>");
1587 TexOutput("\n<CAPTION>");
1595 if (DocumentStyle
!= LATEX_ARTICLE
)
1596 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1598 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1604 if (DocumentStyle
!= LATEX_ARTICLE
)
1605 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1607 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1615 TexOutput("\n</CAPTION>\n");
1617 char *topicName
= FindTopicName(GetNextChunk());
1619 int n
= inFigure
? figureNo
: tableNo
;
1621 AddTexRef(topicName
, NULL
, NULL
,
1622 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1623 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1629 if (start
) TexOutput("ß");
1634 if (start
) inFigure
= TRUE
;
1635 else inFigure
= FALSE
;
1640 if (start
) inTable
= TRUE
;
1641 else inTable
= FALSE
;
1645 DefaultOnMacro(macroId
, no_args
, start
);
1650 // Called on start/end of argument examination
1651 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1657 case ltCHAPTERHEADING
:
1660 case ltSECTIONHEADING
:
1662 case ltSUBSECTIONSTAR
:
1663 case ltSUBSUBSECTION
:
1664 case ltSUBSUBSECTIONSTAR
:
1666 case ltMEMBERSECTION
:
1667 case ltFUNCTIONSECTION
:
1669 if (!start
&& (arg_no
== 1))
1670 currentSection
= GetArgChunk();
1676 if (start
&& (arg_no
== 1))
1679 if (!start
&& (arg_no
== 1))
1682 if (start
&& (arg_no
== 2))
1684 if (!suppressNameDecoration
) TexOutput("<B>");
1685 currentMember
= GetArgChunk();
1687 if (!start
&& (arg_no
== 2))
1689 if (!suppressNameDecoration
) TexOutput("</B>");
1692 if (start
&& (arg_no
== 3))
1694 if (!start
&& (arg_no
== 3))
1700 if (start
&& (arg_no
== 1))
1702 if (!start
&& (arg_no
== 1))
1705 if (start
&& (arg_no
== 2))
1707 if (!suppressNameDecoration
) TexOutput("( ");
1708 currentMember
= GetArgChunk();
1710 if (!start
&& (arg_no
== 2))
1714 if (!start
&& (arg_no
== 3))
1720 if (!start
&& (arg_no
== 1))
1723 if (start
&& (arg_no
== 2))
1725 if (!start
&& (arg_no
== 2))
1728 if (start
&& (arg_no
== 2))
1729 currentMember
= GetArgChunk();
1731 if (start
&& (arg_no
== 3))
1733 if (!start
&& (arg_no
== 3))
1739 if (start
&& (arg_no
== 1))
1741 if (!start
&& (arg_no
== 1))
1743 if (start
&& (arg_no
== 2))
1747 if (!start
&& (arg_no
== 2))
1755 if (start
&& (arg_no
== 1))
1757 if (!start
&& (arg_no
== 1))
1758 TexOutput("</B> "); // This is the difference from param - one space!
1759 if (start
&& (arg_no
== 2))
1763 if (!start
&& (arg_no
== 2))
1771 if (!start
&& (arg_no
== 1))
1774 if (start
&& (arg_no
== 2))
1775 currentMember
= GetArgChunk();
1784 char *refName
= GetArgData();
1787 TexRef
*texRef
= FindReference(refName
);
1790 sec
= texRef
->sectionNumber
;
1803 if (IsArgOptional())
1805 else if ((GetNoArgs() - arg_no
) == 1)
1808 helpRefText
= GetArgChunk();
1811 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1815 TexChunk
*ref
= GetArgChunk();
1816 TexOutput("<A HREF=\"");
1818 TraverseChildrenFromChunk(ref
);
1822 TraverseChildrenFromChunk(helpRefText
);
1833 if (IsArgOptional())
1836 helpRefFilename
= GetArgChunk();
1839 if ((GetNoArgs() - arg_no
) == 1)
1842 helpRefText
= GetArgChunk();
1845 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1849 char *refName
= GetArgData();
1850 char *refFilename
= NULL
;
1854 TexRef
*texRef
= FindReference(refName
);
1857 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1858 refFilename
= texRef
->refFile
;
1860 TexOutput("<A HREF=\"");
1861 // If a filename is supplied, use it, otherwise try to
1862 // use the filename associated with the reference (from this document).
1863 if (helpRefFilename
)
1865 TraverseChildrenFromChunk(helpRefFilename
);
1868 else if (refFilename
)
1870 TexOutput(ConvertCase(refFilename
));
1876 TraverseChildrenFromChunk(helpRefText
);
1882 TraverseChildrenFromChunk(helpRefText
);
1883 TexOutput(" (REF NOT FOUND)");
1886 else TexOutput("??");
1901 char *alignment
= "";
1902 if (macroId
== ltIMAGEL
)
1903 alignment
= " align=left";
1904 else if (macroId
== ltIMAGER
)
1905 alignment
= " align=right";
1907 // Try to find an XBM or GIF image first.
1908 char *filename
= copystring(GetArgData());
1911 strcpy(buf
, filename
);
1912 StripExtension(buf
);
1913 strcat(buf
, ".xbm");
1914 wxString f
= TexPathList
.FindValidPath(buf
);
1916 if (f
== "") // Try for a GIF instead
1918 strcpy(buf
, filename
);
1919 StripExtension(buf
);
1920 strcat(buf
, ".gif");
1921 f
= TexPathList
.FindValidPath(buf
);
1925 char *inlineFilename
= copystring(f
);
1927 char *originalFilename
= TexPathList
.FindValidPath(filename
);
1928 // If we have found the existing filename, make the inline
1929 // image point to the original file (could be PS, for example)
1930 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
1932 TexOutput("<A HREF=\"");
1933 TexOutput(ConvertCase(originalFilename
));
1935 TexOutput("<img src=\"");
1936 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1937 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1942 TexOutput("<img src=\"");
1943 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
1944 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
1945 delete[] inlineFilename
;
1950 // Last resort - a link to a PS file.
1951 TexOutput("<A HREF=\"");
1952 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
1953 TexOutput("\">Picture</A>\n");
1954 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
1962 // First arg is PSBOX spec (ignored), second is image file, third is map name.
1965 static char *imageFile
= NULL
;
1966 if (start
&& (arg_no
== 2))
1968 // Try to find an XBM or GIF image first.
1969 char *filename
= copystring(GetArgData());
1972 strcpy(buf
, filename
);
1973 StripExtension(buf
);
1974 strcat(buf
, ".xbm");
1975 wxString f
= TexPathList
.FindValidPath(buf
);
1977 if (f
== "") // Try for a GIF instead
1979 strcpy(buf
, filename
);
1980 StripExtension(buf
);
1981 strcat(buf
, ".gif");
1982 f
= TexPathList
.FindValidPath(buf
);
1987 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
1996 imageFile
= copystring(f
);
1999 else if (start
&& (arg_no
== 3))
2003 // First, try to find a .shg (segmented hypergraphics file)
2004 // that we can convert to a map file
2006 strcpy(buf
, imageFile
);
2007 StripExtension(buf
);
2008 strcat(buf
, ".shg");
2009 wxString f
= TexPathList
.FindValidPath(buf
);
2013 // The default HTML file to go to is THIS file (so a no-op)
2014 SHGToMap((char*) (const char*) f
, currentFileName
);
2017 char *mapName
= GetArgData();
2018 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2022 TexOutput("unknown");
2024 TexOutput("<img src=\"");
2025 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2026 TexOutput("\" ISMAP></A><P>");
2047 descriptionItemArg
= GetArgChunk();
2052 case ltTWOCOLITEMRULED
:
2055 if (start && (arg_no == 1))
2056 TexOutput("\n<DT> ");
2057 if (start && (arg_no == 2))
2063 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2065 TexOutput("\n</TD>\n");
2070 TexOutput("\n<TD VALIGN=TOP>\n");
2072 TexOutput("\n</TD></TR>\n");
2077 case ltNUMBEREDBIBITEM
:
2079 if (arg_no
== 1 && start
)
2081 TexOutput("\n<DT> ");
2083 if (arg_no
== 2 && !start
)
2090 if (arg_no
== 1 && start
)
2092 char *citeKey
= GetArgData();
2093 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2096 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2097 sprintf(buf
, "[%d]", citeCount
);
2098 ref
->sectionNumber
= copystring(buf
);
2101 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2106 if (arg_no
== 2 && !start
)
2112 case ltMARGINPARODD
:
2113 case ltMARGINPAREVEN
:
2119 TexOutput("<HR>\n");
2123 TexOutput("<HR><P>\n");
2130 case ltACCENT_GRAVE
:
2134 char *val
= GetArgData();
2140 TexOutput("à");
2143 TexOutput("è");
2146 TexOutput("ì");
2149 TexOutput("ò");
2152 TexOutput("ù");
2155 TexOutput("À");
2158 TexOutput("È");
2161 TexOutput("Ì");
2164 TexOutput("Ò");
2167 TexOutput("Ì");
2177 case ltACCENT_ACUTE
:
2181 char *val
= GetArgData();
2187 TexOutput("á");
2190 TexOutput("é");
2193 TexOutput("í");
2196 TexOutput("ó");
2199 TexOutput("ú");
2202 TexOutput("ý");
2205 TexOutput("Á");
2208 TexOutput("É");
2211 TexOutput("Í");
2214 TexOutput("Ó");
2217 TexOutput("Ú");
2220 TexOutput("Ý");
2230 case ltACCENT_CARET
:
2234 char *val
= GetArgData();
2240 TexOutput("â");
2243 TexOutput("ê");
2246 TexOutput("î");
2249 TexOutput("ô");
2252 TexOutput("û");
2255 TexOutput("Â");
2258 TexOutput("Ê");
2261 TexOutput("Î");
2264 TexOutput("Ô");
2267 TexOutput("Î");
2277 case ltACCENT_TILDE
:
2281 char *val
= GetArgData();
2290 TexOutput("ã");
2293 TexOutput("ñ");
2296 TexOutput("õ");
2299 TexOutput("Ã");
2302 TexOutput("Ñ");
2305 TexOutput("Õ");
2315 case ltACCENT_UMLAUT
:
2319 char *val
= GetArgData();
2325 TexOutput("ä");
2328 TexOutput("ë");
2331 TexOutput("ï");
2334 TexOutput("ö");
2337 TexOutput("ü");
2340 TexOutput("ÿ");
2343 TexOutput("Ä");
2346 TexOutput("Ë");
2349 TexOutput("Ï");
2352 TexOutput("Ö");
2355 TexOutput("Ü");
2358 TexOutput("Ÿ");
2372 char *val
= GetArgData();
2378 TexOutput("å");
2381 TexOutput("Å");
2395 char *val
= GetArgData();
2398 bool isPicture
= FALSE
;
2399 char *s
= ParseColourString(val
, &isPicture
);
2402 if (backgroundImageString
)
2403 delete[] backgroundImageString
;
2404 backgroundImageString
= copystring(val
);
2408 if (backgroundColourString
)
2409 delete[] backgroundColourString
;
2410 backgroundColourString
= copystring(val
);
2417 case ltBACKGROUNDIMAGE
:
2421 char *val
= GetArgData();
2424 if (backgroundImageString
)
2425 delete[] backgroundImageString
;
2426 backgroundImageString
= copystring(val
);
2432 case ltBACKGROUNDCOLOUR
:
2436 char *val
= GetArgData();
2439 if (backgroundColourString
)
2440 delete[] backgroundColourString
;
2441 backgroundColourString
= copystring(val
);
2451 char *val
= GetArgData();
2454 if (textColourString
)
2455 delete[] textColourString
;
2456 textColourString
= copystring(val
);
2466 char *val
= GetArgData();
2469 if (linkColourString
)
2470 delete[] linkColourString
;
2471 linkColourString
= copystring(val
);
2477 case ltFOLLOWEDLINKCOLOUR
:
2481 char *val
= GetArgData();
2484 if (followedLinkColourString
)
2485 delete[] followedLinkColourString
;
2486 followedLinkColourString
= copystring(val
);
2492 case ltACCENT_CADILLA
:
2496 char *val
= GetArgData();
2502 TexOutput("ç");
2505 TexOutput("Ç");
2517 case ltFOOTNOTEPOPUP:
2527 case ltSUPERTABULAR
:
2533 currentRowNumber
= 0;
2536 tableVerticalLineLeft
= FALSE
;
2537 tableVerticalLineRight
= FALSE
;
2538 int currentWidth
= 0;
2540 char *alignString
= copystring(GetArgData());
2541 ParseTableArgument(alignString
);
2543 TexOutput("<TABLE BORDER>\n");
2545 // Write the first row formatting for compatibility
2546 // with standard Latex
2547 if (compatibilityMode
)
2549 TexOutput("<TR>\n<TD>");
2551 for (int i = 0; i < noColumns; i++)
2553 currentWidth += TableData[i].width;
2554 sprintf(buf, "\\cellx%d", currentWidth);
2557 TexOutput("\\pard\\intbl\n");
2560 delete[] alignString
;
2565 else if (arg_no
== 2 && !start
)
2567 TexOutput("</TABLE>\n");
2572 case ltTHEBIBLIOGRAPHY
:
2574 if (start
&& (arg_no
== 1))
2576 ReopenFile(&Chapters
, &ChaptersName
);
2577 AddTexRef("bibliography", ChaptersName
, "bibliography");
2578 SetCurrentSubsectionName("bibliography", ChaptersName
);
2582 SetCurrentOutput(Chapters
);
2585 if (truncateFilenames
)
2586 sprintf(titleBuf
, "%s.htm", FileNameFromPath(FileRoot
));
2588 sprintf(titleBuf
, "%s_contents.html", FileNameFromPath(FileRoot
));
2590 TexOutput("<head><title>");
2591 TexOutput(ReferencesNameString
);
2592 TexOutput("</title></head>\n");
2595 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2596 AddBrowseButtons("contents", titleBuf
, // Up
2597 lastTopic
, lastFileName
, // Last topic
2598 "bibliography", ChaptersName
); // This topic
2600 SetCurrentOutputs(Contents
, Chapters
);
2601 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2603 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2604 fprintf(Chapters
, "</H2>\n</A>\n");
2606 SetCurrentOutput(Chapters
);
2609 if (!start
&& (arg_no
== 2))
2617 /* Build up list of keywords associated with topics */
2620 // char *entry = GetArgData();
2622 OutputChunkToString(GetArgChunk(), buf
);
2625 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2640 char *name
= GetArgData();
2642 if (!FindColourHTMLString(name
, buf2
))
2644 strcpy(buf2
, "#000000");
2646 sprintf(buf
, "Could not find colour name %s", name
);
2649 TexOutput("<FONT COLOR=\"");
2665 if (arg_no
== 2) TexOutput("</FONT>");
2670 case ltINSERTATLEVEL
:
2672 // This macro allows you to insert text at a different level
2673 // from the current level, e.g. into the Sections from within a subsubsection.
2676 static int currentLevelNo
= 1;
2677 static FILE* oldLevelFile
= Chapters
;
2684 oldLevelFile
= CurrentOutput1
;
2686 char *str
= GetArgData();
2687 currentLevelNo
= atoi(str
);
2689 // TODO: cope with article style (no chapters)
2690 switch (currentLevelNo
)
2694 outputFile
= Chapters
;
2699 outputFile
= Sections
;
2704 outputFile
= Subsections
;
2709 outputFile
= Subsubsections
;
2719 CurrentOutput1
= outputFile
;
2737 CurrentOutput1
= oldLevelFile
;
2743 return DefaultOnArgument(macroId
, arg_no
, start
);
2756 tableVerticalLineLeft
= FALSE
;
2757 tableVerticalLineRight
= FALSE
;
2760 if (InputFile
&& OutputFile
)
2762 // Do some HTML-specific transformations on all the strings,
2764 Text2HTML(GetTopLevelChunk());
2767 if (truncateFilenames
)
2768 sprintf(buf
, "%s.htm", FileRoot
);
2770 sprintf(buf
, "%s_contents.html", FileRoot
);
2771 if (TitlepageName
) delete[] TitlepageName
;
2772 TitlepageName
= copystring(buf
);
2773 Titlepage
= fopen(buf
, "w");
2775 if (truncateFilenames
)
2776 sprintf(buf
, "%s_fc.htm", FileRoot
);
2778 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2780 contentsFrameName
= copystring(buf
);
2782 Contents
= fopen(TmpContentsName
, "w");
2784 if (htmlFrameContents
)
2786 // FrameContents = fopen(TmpFrameContentsName, "w");
2787 FrameContents
= fopen(contentsFrameName
, "w");
2788 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2791 if (!Titlepage
|| !Contents
)
2793 OnError("Cannot open output file!");
2796 AddTexRef("contents", FileNameFromPath(TitlepageName
), ContentsNameString
);
2798 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2800 fprintf(Contents
, "<UL>\n");
2802 SetCurrentOutput(Titlepage
);
2803 OnInform("Converting...");
2806 fprintf(Contents
, "</UL>\n\n");
2808 // SetCurrentOutput(Titlepage);
2813 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2820 fprintf(FrameContents
, "\n</UL>\n");
2821 fprintf(FrameContents
, "</HTML>\n");
2822 fclose(FrameContents
);
2823 FrameContents
= NULL
;
2828 fprintf(Chapters
, "\n</BODY></HTML>\n");
2834 fprintf(Sections
, "\n</BODY></HTML>\n");
2838 if (Subsections
&& !combineSubSections
)
2840 fprintf(Subsections
, "\n</BODY></HTML>\n");
2841 fclose(Subsections
);
2844 if (Subsubsections
&& !combineSubSections
)
2846 fprintf(Subsubsections
, "\n</BODY></HTML>\n");
2847 fclose(Subsubsections
);
2848 Subsubsections
= NULL
;
2850 if ( SectionContentsFD
)
2852 fclose(SectionContentsFD
);
2853 SectionContentsFD
= NULL
;
2856 // Create a temporary file for the title page header, add some info,
2857 // and concat the titlepage just generated.
2858 // This is necessary in order to put the title of the document
2859 // at the TOP of the file within <HEAD>, even though we only find out
2860 // what it is later on.
2861 FILE *tmpTitle
= fopen("title.tmp", "w");
2866 SetCurrentOutput(tmpTitle
);
2867 TexOutput("\n<HTML>\n<HEAD><TITLE>");
2868 TraverseChildrenFromChunk(DocumentTitle
);
2869 TexOutput("</TITLE></HEAD>\n");
2873 SetCurrentOutput(tmpTitle
);
2875 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
2877 fprintf(tmpTitle
, "<HEAD><TITLE>%s</TITLE></HEAD>\n\n", FileNameFromPath(FileRoot
));
2880 // Output frame information
2881 if (htmlFrameContents
)
2883 char firstFileName
[300];
2884 if (truncateFilenames
)
2885 sprintf(firstFileName
, "%s1.htm", FileRoot
);
2887 sprintf(firstFileName
, "%s1.html", FileRoot
);
2889 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
2891 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(FileNameFromPath(contentsFrameName
)));
2892 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(FileNameFromPath(firstFileName
)));
2893 fprintf(tmpTitle
, "</FRAMESET>\n");
2895 fprintf(tmpTitle
, "<NOFRAMES>\n");
2898 // Output <BODY...> to temporary title page
2902 FILE *fd
= fopen(TitlepageName
, "r");
2914 fprintf(tmpTitle
, "\n</BODY>\n");
2916 if (htmlFrameContents
)
2918 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
2920 fprintf(tmpTitle
, "\n</HTML>\n");
2923 if (FileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
2924 if (!wxRenameFile("title.tmp", TitlepageName
))
2926 wxCopyFile("title.tmp", TitlepageName
);
2927 wxRemoveFile("title.tmp");
2931 if (lastFileName
) delete[] lastFileName
;
2932 lastFileName
= NULL
;
2933 if (lastTopic
) delete[] lastTopic
;
2936 if (FileExists(ContentsName
)) wxRemoveFile(ContentsName
);
2938 if (!wxRenameFile(TmpContentsName
, ContentsName
))
2940 wxCopyFile(TmpContentsName
, ContentsName
);
2941 wxRemoveFile(TmpContentsName
);
2944 // Generate .htx file if requested
2947 char htmlIndexName
[300];
2948 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
2949 GenerateHTMLIndexFile(htmlIndexName
);
2957 // Output .htx index file
2958 void GenerateHTMLIndexFile(char *fname
)
2960 FILE *fd
= fopen(fname
, "w");
2964 TopicTable
.BeginFind();
2965 wxNode
*node
= NULL
;
2966 while ((node
= TopicTable
.Next()))
2968 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
2969 const char *topicName
= node
->GetKeyString();
2970 if (texTopic
->filename
&& texTopic
->keywords
)
2972 wxNode
*node1
= texTopic
->keywords
->First();
2975 char *s
= (char *)node1
->Data();
2976 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
2977 node1
= node1
->Next();