1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to HTML
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
32 extern wxHashTable TexReferences
;
35 extern void DecToHex(int, char *);
36 void GenerateHTMLIndexFile(char *fname
);
38 void GenerateHTMLWorkshopFiles(char *fname
);
39 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
);
40 void HTMLWorkshopStartContents();
41 void HTMLWorkshopEndContents();
43 void OutputContentsFrame(void);
45 #include "readshg.h" // Segmented hypergraphics parsing
47 char *ChaptersName
= NULL
;
48 char *SectionsName
= NULL
;
49 char *SubsectionsName
= NULL
;
50 char *SubsubsectionsName
= NULL
;
51 char *TitlepageName
= NULL
;
52 char *lastFileName
= NULL
;
53 char *lastTopic
= NULL
;
54 char *currentFileName
= NULL
;
55 char *contentsFrameName
= NULL
;
57 static TexChunk
*descriptionItemArg
= NULL
;
58 static TexChunk
*helpRefFilename
= NULL
;
59 static TexChunk
*helpRefText
= NULL
;
60 static int indentLevel
= 0;
61 static int citeCount
= 1;
62 extern FILE *Contents
;
63 FILE *FrameContents
= NULL
;
64 FILE *Titlepage
= NULL
;
65 // FILE *FrameTitlepage = NULL;
67 bool subsectionStarted
= FALSE
;
69 // Which column of a row are we in? (Assumes no nested tables, of course)
70 int currentColumn
= 0;
72 // Are we in verbatim mode? If so, format differently.
73 static bool inVerbatim
= FALSE
;
75 // Need to know whether we're in a table or figure for benefit
76 // of listoffigures/listoftables
77 static bool inFigure
= FALSE
;
78 static bool inTable
= FALSE
;
80 // This is defined in the Tex2Any library.
81 extern char *BigBuffer
;
83 // DHS Two-column table dimensions.
84 static int TwoColWidthA
= -1;
85 static int TwoColWidthB
= -1;
88 class HyperReference
: public wxObject
93 HyperReference(char *name
, char *file
)
95 if (name
) refName
= copystring(name
);
96 if (file
) refFile
= copystring(file
);
100 class TexNextPage
: public wxObject
105 TexNextPage(char *theLabel
, char *theFile
)
107 label
= copystring(theLabel
);
108 filename
= copystring(theFile
);
117 wxHashTable
TexNextPages(wxKEY_STRING
);
119 static char *CurrentChapterName
= NULL
;
120 static char *CurrentChapterFile
= NULL
;
121 static char *CurrentSectionName
= NULL
;
122 static char *CurrentSectionFile
= NULL
;
123 static char *CurrentSubsectionName
= NULL
;
124 static char *CurrentSubsectionFile
= NULL
;
125 static char *CurrentSubsubsectionName
= NULL
;
126 static char *CurrentSubsubsectionFile
= NULL
;
127 static char *CurrentTopic
= NULL
;
129 static void SetCurrentTopic(char *s
)
131 if (CurrentTopic
) delete[] CurrentTopic
;
132 CurrentTopic
= copystring(s
);
135 void SetCurrentChapterName(char *s
, char *file
)
137 if (CurrentChapterName
) delete[] CurrentChapterName
;
138 CurrentChapterName
= copystring(s
);
139 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
140 CurrentChapterFile
= copystring(file
);
142 currentFileName
= CurrentChapterFile
;
146 void SetCurrentSectionName(char *s
, char *file
)
148 if (CurrentSectionName
) delete[] CurrentSectionName
;
149 CurrentSectionName
= copystring(s
);
150 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
151 CurrentSectionFile
= copystring(file
);
153 currentFileName
= CurrentSectionFile
;
156 void SetCurrentSubsectionName(char *s
, char *file
)
158 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
159 CurrentSubsectionName
= copystring(s
);
160 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
161 CurrentSubsectionFile
= copystring(file
);
162 currentFileName
= CurrentSubsectionFile
;
165 void SetCurrentSubsubsectionName(char *s
, char *file
)
167 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
168 CurrentSubsubsectionName
= copystring(s
);
169 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
170 CurrentSubsubsectionFile
= copystring(file
);
171 currentFileName
= CurrentSubsubsectionFile
;
176 * Close former filedescriptor and reopen using another filename.
180 void ReopenFile(FILE **fd
, char **fileName
)
184 fprintf(*fd
, "\n</FONT></BODY></HTML>\n");
189 if (truncateFilenames
)
190 sprintf(buf
, "%s%d.htm", FileRoot
, fileId
);
192 sprintf(buf
, "%s%d.html", FileRoot
, fileId
);
193 if (*fileName
) delete[] *fileName
;
194 *fileName
= copystring(wxFileNameFromPath(buf
));
195 *fd
= fopen(buf
, "w");
196 fprintf(*fd
, "<HTML>\n");
200 * Reopen section contents file, i.e. the index appended to each section
201 * in subsectionCombine mode
204 static char *SectionContentsFilename
= NULL
;
205 static FILE *SectionContentsFD
= NULL
;
207 void ReopenSectionContentsFile(void)
209 if ( SectionContentsFD
)
211 fclose(SectionContentsFD
);
213 if ( SectionContentsFilename
)
214 delete[] SectionContentsFilename
;
215 SectionContentsFD
= NULL
;
216 SectionContentsFilename
= NULL
;
218 // Create the name from the current section filename
219 if ( CurrentSectionFile
)
222 strcpy(buf
, CurrentSectionFile
);
223 wxStripExtension(buf
);
225 SectionContentsFilename
= copystring(buf
);
227 SectionContentsFD
= fopen(SectionContentsFilename
, "w");
233 * Given a TexChunk with a string value, scans through the string
234 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
238 void ProcessText2HTML(TexChunk
*chunk
)
240 bool changed
= FALSE
;
244 int len
= strlen(chunk
->value
);
247 ch
= chunk
->value
[i
];
249 // 2 newlines means \par
250 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
251 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
252 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
254 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "<P>\n\n"); ptr
+= 5;
258 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
260 BigBuffer
[ptr
] = '"'; ptr
++;
264 else if (!inVerbatim
&& ch
== '`') // Change ` to '
266 BigBuffer
[ptr
] = 39; ptr
++;
270 else if (ch
== '<') // Change < to <
273 strcat(BigBuffer
, "<");
278 else if (ch
== '>') // Change > to >
281 strcat(BigBuffer
, ">");
298 chunk
->value
= copystring(BigBuffer
);
303 * Scan through all chunks starting from the given one,
304 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
305 * This should be called after Tex2Any has parsed the file,
306 * and before TraverseDocument is called.
310 void Text2HTML(TexChunk
*chunk
)
313 if (stopRunning
) return;
317 case CHUNK_TYPE_MACRO
:
319 TexMacroDef
*def
= chunk
->def
;
321 if (def
&& def
->ignore
)
324 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
327 wxNode
*node
= chunk
->children
.First();
330 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
331 Text2HTML(child_chunk
);
335 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
342 wxNode
*node
= chunk
->children
.First();
345 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
346 Text2HTML(child_chunk
);
352 case CHUNK_TYPE_STRING
:
355 ProcessText2HTML(chunk
);
362 * Add appropriate browse buttons to this page.
366 void AddBrowseButtons(char *upLabel
, char *upFilename
,
367 char *previousLabel
, char *previousFilename
,
368 char *thisLabel
, char *thisFilename
)
370 char contentsReferenceBuf
[80];
371 char upReferenceBuf
[80];
372 char backReferenceBuf
[80];
373 char forwardReferenceBuf
[80];
374 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
377 char *contentsReference
= NULL
;
378 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
379 contentsReference
= ContentsNameString
;
382 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
383 contentsReference
= contentsReferenceBuf
;
384 sprintf(contentsReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">", ConvertCase("contents.gif"));
387 char *upReference
= NULL
;
388 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
389 upReference
= UpNameString
;
392 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
393 upReference
= upReferenceBuf
;
394 sprintf(upReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">", ConvertCase("up.gif"));
397 char *backReference
= NULL
;
398 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
399 backReference
= "<<";
402 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
403 backReference
= backReferenceBuf
;
404 sprintf(backReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">", ConvertCase("back.gif"));
407 char *forwardReference
= NULL
;
408 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
409 forwardReference
= ">>";
412 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
413 forwardReference
= forwardReferenceBuf
;
414 sprintf(forwardReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">", ConvertCase("forward.gif"));
417 TexOutput("<CENTER>");
426 if (truncateFilenames
)
429 strcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
430 sprintf(buf
, "\n<A HREF=\"%s.%s\">%s</A> ", buf1
, ConvertCase("htm"), contentsReference
);
435 strcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
436 sprintf(buf
, "\n<A HREF=\"%s%s\">%s</A> ", buf1
, ConvertCase("_contents.html"), contentsReference
);
438 // TexOutput("<NOFRAMES>");
440 // TexOutput("</NOFRAMES>");
447 if (upLabel
&& upFilename
)
449 if (strlen(upLabel
) > 0)
450 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(upFilename
), upLabel
, upReference
);
452 sprintf(buf
, "<A HREF=\"%s\">%s</A> ", ConvertCase(upFilename
), upReference
);
453 if (strcmp(upLabel
, "contents") == 0)
455 // TexOutput("<NOFRAMES>");
457 // TexOutput("</NOFRAMES>");
468 if (previousLabel
&& previousFilename
)
470 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(previousFilename
), previousLabel
, backReference
);
471 if (strcmp(previousLabel
, "contents") == 0)
473 // TexOutput("<NOFRAMES>");
475 // TexOutput("</NOFRAMES>");
482 // A placeholder so the buttons don't keep moving position
483 sprintf(buf
, "%s ", backReference
);
487 char *nextLabel
= NULL
;
488 char *nextFilename
= NULL
;
490 // Get the next page, and record the previous page's 'next' page
492 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
495 nextLabel
= nextPage
->label
;
496 nextFilename
= nextPage
->filename
;
498 if (previousLabel
&& previousFilename
)
500 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
504 TexNextPages
.Delete(previousLabel
);
506 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
507 TexNextPages
.Put(previousLabel
, newNextPage
);
515 if (nextLabel
&& nextFilename
)
517 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(nextFilename
), nextLabel
, forwardReference
);
522 // A placeholder so the buttons don't keep moving position
523 sprintf(buf
, "%s ", forwardReference
);
528 * Horizontal rule to finish it off nicely.
531 TexOutput("</CENTER>");
534 // Update last topic/filename
536 delete[] lastFileName
;
537 lastFileName
= copystring(thisFilename
);
540 lastTopic
= copystring(thisLabel
);
543 // A colour string is either 3 numbers separated by semicolons (RGB),
544 // or a reference to a GIF. Return the filename or a hex string like #934CE8
545 char *ParseColourString(char *bkStr
, bool *isPicture
)
547 static char resStr
[300];
548 strcpy(resStr
, bkStr
);
549 char *tok1
= strtok(resStr
, ";");
550 char *tok2
= strtok(NULL
, ";");
561 char *tok3
= strtok(NULL
, ";");
564 // Now convert 3 strings into decimal numbers, and then hex numbers.
565 int red
= atoi(tok1
);
566 int green
= atoi(tok2
);
567 int blue
= atoi(tok3
);
574 DecToHex(green
, buf
);
586 void OutputFont(void)
588 // Only output <font face> if explicitly requested by htmlFaceName= directive in
589 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
593 // Output <FONT FACE=...>
594 TexOutput("<FONT FACE=\"");
595 TexOutput(htmlFaceName
);
600 // Output start of <BODY> block
601 void OutputBodyStart(void)
603 TexOutput("\n<BODY");
604 if (backgroundImageString
)
606 bool isPicture
= FALSE
;
607 char *s
= ParseColourString(backgroundImageString
, &isPicture
);
610 TexOutput(" BACKGROUND=\""); TexOutput(s
); TexOutput("\"");
613 if (backgroundColourString
)
615 bool isPicture
= FALSE
;
616 char *s
= ParseColourString(backgroundColourString
, &isPicture
);
619 TexOutput(" BGCOLOR="); TexOutput(s
);
623 // Set foreground text colour, if one is specified
624 if (textColourString
)
626 bool isPicture
= FALSE
;
627 char *s
= ParseColourString(textColourString
, &isPicture
);
630 TexOutput(" TEXT="); TexOutput(s
);
633 // Set link text colour, if one is specified
634 if (linkColourString
)
636 bool isPicture
= FALSE
;
637 char *s
= ParseColourString(linkColourString
, &isPicture
);
640 TexOutput(" LINK="); TexOutput(s
);
643 // Set followed link text colour, if one is specified
644 if (followedLinkColourString
)
646 bool isPicture
= FALSE
;
647 char *s
= ParseColourString(followedLinkColourString
, &isPicture
);
650 TexOutput(" VLINK="); TexOutput(s
);
661 if (htmlStylesheet
) {
662 TexOutput("<link rel=stylesheet type=\"text/css\" href=\"");
663 TexOutput(htmlStylesheet
);
668 void HTMLHeadTo(FILE* f
)
671 fprintf(f
,"<head><link rel=stylesheet type=\"text/css\" href=\"%s\">",htmlStylesheet
);
676 // Called on start/end of macro examination
677 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
683 case ltCHAPTERHEADING
:
691 if (macroId
!= ltCHAPTERSTAR
)
694 SetCurrentOutput(NULL
);
695 startedSections
= TRUE
;
697 char *topicName
= FindTopicName(GetNextChunk());
698 ReopenFile(&Chapters
, &ChaptersName
);
699 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
701 SetCurrentChapterName(topicName
, ChaptersName
);
702 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
704 SetCurrentOutput(Chapters
);
707 TexOutput("<title>");
708 OutputCurrentSection(); // Repeat section header
709 TexOutput("</title></head>\n");
713 if (truncateFilenames
)
714 sprintf(titleBuf
, "%s.htm", wxFileNameFromPath(FileRoot
));
716 sprintf(titleBuf
, "%s_contents.html", wxFileNameFromPath(FileRoot
));
718 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
720 AddBrowseButtons("", titleBuf
, // Up
721 lastTopic
, lastFileName
, // Last topic
722 topicName
, ChaptersName
); // This topic
724 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
726 if (htmlFrameContents
&& FrameContents
)
728 SetCurrentOutput(FrameContents
);
729 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
730 OutputCurrentSection();
731 fprintf(FrameContents
, "</A>\n");
734 SetCurrentOutputs(Contents
, Chapters
);
735 fprintf(Chapters
, "\n<H2>");
736 OutputCurrentSection();
737 fprintf(Contents
, "</A>\n");
738 fprintf(Chapters
, "</H2>\n");
740 SetCurrentOutput(Chapters
);
742 // Add this section title to the list of keywords
745 OutputCurrentSectionToString(wxTex2RTFBuffer
);
746 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
753 case ltSECTIONHEADING
:
760 subsectionStarted
= FALSE
;
762 if (macroId
!= ltSECTIONSTAR
)
765 SetCurrentOutput(NULL
);
766 startedSections
= TRUE
;
768 char *topicName
= FindTopicName(GetNextChunk());
769 ReopenFile(&Sections
, &SectionsName
);
770 AddTexRef(topicName
, SectionsName
, SectionNameString
);
772 SetCurrentSectionName(topicName
, SectionsName
);
773 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
775 SetCurrentOutput(Sections
);
777 TexOutput("<title>");
778 OutputCurrentSection();
779 TexOutput("</title></head>\n");
782 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
783 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
784 lastTopic
, lastFileName
, // Last topic
785 topicName
, SectionsName
); // This topic
787 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
789 SetCurrentOutputs(jumpFrom
, Sections
);
790 if (DocumentStyle
== LATEX_ARTICLE
)
791 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
793 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
795 fprintf(Sections
, "\n<H2>");
796 OutputCurrentSection();
798 if (DocumentStyle
== LATEX_ARTICLE
)
799 fprintf(jumpFrom
, "</A>\n");
801 fprintf(jumpFrom
, "</B></A><BR>\n");
802 fprintf(Sections
, "</H2>\n");
804 SetCurrentOutput(Sections
);
805 // Add this section title to the list of keywords
808 OutputCurrentSectionToString(wxTex2RTFBuffer
);
809 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
815 case ltSUBSECTIONSTAR
:
816 case ltMEMBERSECTION
:
817 case ltFUNCTIONSECTION
:
823 OnError("You cannot have a subsection before a section!");
829 if (macroId
!= ltSUBSECTIONSTAR
)
832 if ( combineSubSections
&& !subsectionStarted
)
834 // Read old .con file in at this point
836 strcpy(buf
, CurrentSectionFile
);
837 wxStripExtension(buf
);
839 FILE *fd
= fopen(buf
, "r");
850 fprintf(Sections
, "<P>\n");
852 // Close old file, create a new file for the sub(sub)section contents entries
853 ReopenSectionContentsFile();
856 startedSections
= TRUE
;
857 subsectionStarted
= TRUE
;
859 char *topicName
= FindTopicName(GetNextChunk());
861 if ( !combineSubSections
)
863 SetCurrentOutput(NULL
);
864 ReopenFile(&Subsections
, &SubsectionsName
);
865 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
866 SetCurrentSubsectionName(topicName
, SubsectionsName
);
867 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
868 SetCurrentOutput(Subsections
);
871 TexOutput("<title>");
872 OutputCurrentSection();
873 TexOutput("</title></head>\n");
876 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
877 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
878 lastTopic
, lastFileName
, // Last topic
879 topicName
, SubsectionsName
); // This topic
881 SetCurrentOutputs(Sections
, Subsections
);
882 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
884 fprintf(Subsections
, "\n<H3>");
885 OutputCurrentSection();
886 fprintf(Sections
, "</B></A><BR>\n");
887 fprintf(Subsections
, "</H3>\n");
889 SetCurrentOutput(Subsections
);
893 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
894 SetCurrentSubsectionName(topicName
, SectionsName
);
896 // if ( subsectionNo != 0 )
897 fprintf(Sections
, "\n<HR>\n");
899 // We're putting everything into the section file
900 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
901 fprintf(Sections
, "\n<H3>");
902 OutputCurrentSection();
903 fprintf(Sections
, "</H3>\n");
905 SetCurrentOutput(SectionContentsFD
);
906 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
907 OutputCurrentSection();
908 TexOutput("</A><BR>\n");
910 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
911 SetCurrentOutput(Sections
);
913 // Add this section title to the list of keywords
916 OutputCurrentSectionToString(wxTex2RTFBuffer
);
917 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
924 case ltSUBSUBSECTION
:
925 case ltSUBSUBSECTIONSTAR
:
929 if (!Subsections
&& !combineSubSections
)
931 OnError("You cannot have a subsubsection before a subsection!");
935 if (macroId
!= ltSUBSUBSECTIONSTAR
)
938 startedSections
= TRUE
;
940 char *topicName
= FindTopicName(GetNextChunk());
942 if ( !combineSubSections
)
944 SetCurrentOutput(NULL
);
945 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
946 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
947 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
948 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
950 SetCurrentOutput(Subsubsections
);
952 TexOutput("<title>");
953 OutputCurrentSection();
954 TexOutput("</title></head>\n");
957 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
959 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
960 lastTopic
, lastFileName
, // Last topic
961 topicName
, SubsubsectionsName
); // This topic
963 SetCurrentOutputs(Subsections
, Subsubsections
);
964 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
966 fprintf(Subsubsections
, "\n<H3>");
967 OutputCurrentSection();
968 fprintf(Subsections
, "</B></A><BR>\n");
969 fprintf(Subsubsections
, "</H3>\n");
973 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
974 SetCurrentSubsectionName(topicName
, SectionsName
);
975 fprintf(Sections
, "\n<HR>\n");
977 // We're putting everything into the section file
978 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
979 fprintf(Sections
, "\n<H3>");
980 OutputCurrentSection();
981 fprintf(Sections
, "</H3>\n");
982 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
983 SetCurrentOutput(SectionContentsFD);
984 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
985 OutputCurrentSection();
986 TexOutput("</A><BR>");
988 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
989 SetCurrentOutput(Sections
);
992 // Add this section title to the list of keywords
995 OutputCurrentSectionToString(wxTex2RTFBuffer
);
996 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1005 if ( !combineSubSections
)
1006 SetCurrentOutput(Subsections
);
1008 SetCurrentOutput(Sections
);
1019 if ( !combineSubSections
)
1020 SetCurrentOutput(Subsections
);
1022 SetCurrentOutput(Sections
);
1033 if ( !combineSubSections
)
1034 SetCurrentOutput(Subsections
);
1036 SetCurrentOutput(Sections
);
1047 // TexOutput("<B>void</B>");
1055 TexOutput("wxCLIPS");
1061 case ltSPECIALAMPERSAND
:
1067 // End cell, start cell
1069 TexOutput("</FONT></TD>");
1071 // Start new row and cell, setting alignment for the first cell.
1072 if (currentColumn
< noColumns
)
1076 if (TableData
[currentColumn
].justification
== 'c')
1077 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1078 else if (TableData
[currentColumn
].justification
== 'r')
1079 sprintf(buf
, "\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
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1091 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1100 case ltBACKSLASHCHAR
:
1106 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1107 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1108 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1109 TexOutput("</TR>\n");
1112 TexOutput("<BR>\n");
1123 // Start new row and cell, setting alignment for the first cell.
1125 if (TableData
[currentColumn
].justification
== 'c')
1126 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1127 else if (TableData
[currentColumn
].justification
== 'r')
1128 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1129 else if (TableData
[currentColumn
].absWidth
)
1131 // Convert from points * 20 into pixels.
1132 int points
= TableData
[currentColumn
].width
/ 20;
1134 // Say the display is 100 DPI (dots/pixels per inch).
1135 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1136 int pixels
= (int)(points
* 100.0 / 72.0);
1137 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1140 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1147 // Start new row and cell
1148 TexOutput("</FONT></TD>\n</TR>\n");
1152 // HTML-only: break until the end of the picture (both margins are clear).
1156 TexOutput("<BR CLEAR=ALL>");
1159 case ltRTFSP
: // Explicit space, RTF only
1161 case ltSPECIALTILDE
:
1175 TexOutput("<UL><UL>\n");
1177 TexOutput("</UL></UL>\n");
1183 // case ltTWOCOLLIST:
1190 if (macroId
== ltENUMERATE
)
1191 listType
= LATEX_ENUMERATE
;
1192 else if (macroId
== ltITEMIZE
)
1193 listType
= LATEX_ITEMIZE
;
1195 listType
= LATEX_DESCRIPTION
;
1197 itemizeStack
.Insert(new ItemizeStruc(listType
));
1201 TexOutput("<UL>\n");
1203 case LATEX_ENUMERATE
:
1204 TexOutput("<OL>\n");
1206 case LATEX_DESCRIPTION
:
1208 TexOutput("<DL>\n");
1215 if (itemizeStack
.First())
1217 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1218 switch (struc
->listType
)
1221 TexOutput("</UL>\n");
1223 case LATEX_ENUMERATE
:
1224 TexOutput("</OL>\n");
1226 case LATEX_DESCRIPTION
:
1228 TexOutput("</DL>\n");
1233 delete itemizeStack
.First();
1241 TexOutput("\n<TABLE>\n");
1243 TexOutput("\n</TABLE>\n");
1256 /* For footnotes we need to output the text at the bottom of the page and
1257 * insert a reference to it. Is it worth the trouble...
1259 case ltFOOTNOTEPOPUP:
1265 else TexOutput("</FN>");
1273 else TexOutput("</TT>");
1281 sprintf(buf
, "<PRE>\n");
1284 else TexOutput("</PRE>\n");
1292 TexOutput("<CENTER>");
1294 else TexOutput("</CENTER>");
1302 TexOutput("{\\ql ");
1304 else TexOutput("}\\par\\pard\n");
1313 TexOutput("{\\qr ");
1315 else TexOutput("}\\par\\pard\n");
1323 // Netscape extension
1324 TexOutput("<FONT SIZE=2>");
1326 else TexOutput("</FONT>");
1333 // Netscape extension
1334 TexOutput("<FONT SIZE=1>");
1336 else TexOutput("</FONT>");
1343 // Netscape extension
1344 TexOutput("<FONT SIZE=3>");
1346 else TexOutput("</FONT>");
1353 // Netscape extension
1354 TexOutput("<FONT SIZE=4>");
1356 else TexOutput("</FONT>");
1363 // Netscape extension
1364 TexOutput("<FONT SIZE=5>");
1366 else TexOutput("</FONT>");
1373 // Netscape extension
1374 TexOutput("<FONT SIZE=6>");
1376 else TexOutput("</FONT>");
1387 else TexOutput("</B>");
1398 else TexOutput("</I>");
1408 else TexOutput("</EM>");
1417 else TexOutput("</UL>");
1428 else TexOutput("</TT>");
1434 TexOutput("©", TRUE
);
1440 TexOutput("®", TRUE
);
1446 if (start
) TexOutput("<--");
1451 if (start
) TexOutput("<==");
1456 if (start
) TexOutput("-->");
1461 if (start
) TexOutput("==>");
1464 case ltLEFTRIGHTARROW
:
1466 if (start
) TexOutput("<-->");
1469 case ltLEFTRIGHTARROW2
:
1471 if (start
) TexOutput("<==>");
1484 wxNode
*node
= itemizeStack
.First();
1487 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1488 struc
->currentItem
+= 1;
1489 if (struc
->listType
== LATEX_DESCRIPTION
)
1491 if (descriptionItemArg
)
1494 TraverseChildrenFromChunk(descriptionItemArg
);
1496 descriptionItemArg
= NULL
;
1508 if (start
&& DocumentTitle
&& DocumentAuthor
)
1510 // Add a special label for the contents page.
1511 // TexOutput("<CENTER>\n");
1512 TexOutput("<A NAME=\"contents\">");
1513 TexOutput("<H2 ALIGN=CENTER>\n");
1514 TraverseChildrenFromChunk(DocumentTitle
);
1517 TexOutput("</A>\n");
1518 TexOutput("<P>\n\n");
1519 TexOutput("<H3 ALIGN=CENTER>");
1520 TraverseChildrenFromChunk(DocumentAuthor
);
1521 TexOutput("</H3><P>\n\n");
1524 TexOutput("<H3 ALIGN=CENTER>");
1525 TraverseChildrenFromChunk(DocumentDate
);
1526 TexOutput("</H3><P>\n\n");
1528 // TexOutput("\n</CENTER>\n");
1529 TexOutput("\n<P><HR><P>\n");
1532 // Now do optional frame contents page
1533 if (htmlFrameContents && FrameContents)
1535 SetCurrentOutput(FrameContents);
1537 // Add a special label for the contents page.
1538 TexOutput("<CENTER>\n");
1539 TexOutput("<H3>\n");
1540 TraverseChildrenFromChunk(DocumentTitle);
1543 TexOutput("</A>\n");
1544 TexOutput("<P>\n\n");
1546 TraverseChildrenFromChunk(DocumentAuthor);
1547 TexOutput("</H3><P>\n\n");
1551 TraverseChildrenFromChunk(DocumentDate);
1552 TexOutput("</H4><P>\n\n");
1554 TexOutput("\n</CENTER>\n");
1555 TexOutput("<P><HR><P>\n");
1557 SetCurrentOutput(Titlepage);
1570 helpRefFilename
= NULL
;
1575 case ltBIBLIOGRAPHY
:
1579 DefaultOnMacro(macroId
, no_args
, start
);
1583 DefaultOnMacro(macroId
, no_args
, start
);
1584 TexOutput("</DL>\n");
1592 TexOutput("<HR>\n");
1600 TexOutput("<HR>\n");
1604 case ltTABLEOFCONTENTS
:
1608 FILE *fd
= fopen(ContentsName
, "r");
1614 putc(ch
, Titlepage
);
1621 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1622 OnInform("Run Tex2RTF again to include contents page.");
1643 TexOutput("<BLOCKQUOTE>");
1645 TexOutput("</BLOCKQUOTE>");
1654 TexOutput("\n<CAPTION>");
1662 if (DocumentStyle
!= LATEX_ARTICLE
)
1663 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1665 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1671 if (DocumentStyle
!= LATEX_ARTICLE
)
1672 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1674 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1682 TexOutput("\n</CAPTION>\n");
1684 char *topicName
= FindTopicName(GetNextChunk());
1686 int n
= inFigure
? figureNo
: tableNo
;
1688 AddTexRef(topicName
, NULL
, NULL
,
1689 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1690 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1696 if (start
) TexOutput("ß");
1701 if (start
) inFigure
= TRUE
;
1702 else inFigure
= FALSE
;
1707 if (start
) inTable
= TRUE
;
1708 else inTable
= FALSE
;
1712 DefaultOnMacro(macroId
, no_args
, start
);
1717 // Called on start/end of argument examination
1718 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1724 case ltCHAPTERHEADING
:
1727 case ltSECTIONHEADING
:
1729 case ltSUBSECTIONSTAR
:
1730 case ltSUBSUBSECTION
:
1731 case ltSUBSUBSECTIONSTAR
:
1733 case ltMEMBERSECTION
:
1734 case ltFUNCTIONSECTION
:
1736 if (!start
&& (arg_no
== 1))
1737 currentSection
= GetArgChunk();
1743 if (start
&& (arg_no
== 1))
1746 if (!start
&& (arg_no
== 1))
1749 if (start
&& (arg_no
== 2))
1751 if (!suppressNameDecoration
) TexOutput("<B>");
1752 currentMember
= GetArgChunk();
1754 if (!start
&& (arg_no
== 2))
1756 if (!suppressNameDecoration
) TexOutput("</B>");
1759 if (start
&& (arg_no
== 3))
1761 if (!start
&& (arg_no
== 3))
1767 if (start
&& (arg_no
== 1))
1769 if (!start
&& (arg_no
== 1))
1772 if (start
&& (arg_no
== 2))
1774 if (!suppressNameDecoration
) TexOutput("( ");
1775 currentMember
= GetArgChunk();
1777 if (!start
&& (arg_no
== 2))
1781 if (!start
&& (arg_no
== 3))
1787 if (!start
&& (arg_no
== 1))
1790 if (start
&& (arg_no
== 2))
1792 if (!start
&& (arg_no
== 2))
1795 if (start
&& (arg_no
== 2))
1796 currentMember
= GetArgChunk();
1798 if (start
&& (arg_no
== 3))
1800 if (!start
&& (arg_no
== 3))
1806 if (start
&& (arg_no
== 1))
1808 if (!start
&& (arg_no
== 1))
1810 if (start
&& (arg_no
== 2))
1814 if (!start
&& (arg_no
== 2))
1822 if (start
&& (arg_no
== 1))
1824 if (!start
&& (arg_no
== 1))
1825 TexOutput("</B> "); // This is the difference from param - one space!
1826 if (start
&& (arg_no
== 2))
1830 if (!start
&& (arg_no
== 2))
1838 if (!start
&& (arg_no
== 1))
1841 if (start
&& (arg_no
== 2))
1842 currentMember
= GetArgChunk();
1851 char *refName
= GetArgData();
1854 TexRef
*texRef
= FindReference(refName
);
1857 sec
= texRef
->sectionNumber
;
1870 if (IsArgOptional())
1872 else if ((GetNoArgs() - arg_no
) == 1)
1875 helpRefText
= GetArgChunk();
1878 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1882 TexChunk
*ref
= GetArgChunk();
1883 TexOutput("<A HREF=\"");
1885 TraverseChildrenFromChunk(ref
);
1889 TraverseChildrenFromChunk(helpRefText
);
1900 if (IsArgOptional())
1903 helpRefFilename
= GetArgChunk();
1906 if ((GetNoArgs() - arg_no
) == 1)
1909 helpRefText
= GetArgChunk();
1912 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1916 char *refName
= GetArgData();
1917 char *refFilename
= NULL
;
1921 TexRef
*texRef
= FindReference(refName
);
1924 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1925 refFilename
= texRef
->refFile
;
1927 TexOutput("<A HREF=\"");
1928 // If a filename is supplied, use it, otherwise try to
1929 // use the filename associated with the reference (from this document).
1930 if (helpRefFilename
)
1932 TraverseChildrenFromChunk(helpRefFilename
);
1935 else if (refFilename
)
1937 TexOutput(ConvertCase(refFilename
));
1943 TraverseChildrenFromChunk(helpRefText
);
1949 TraverseChildrenFromChunk(helpRefText
);
1951 TexOutput(" (REF NOT FOUND)");
1953 errBuf
.Printf("Warning: unresolved reference '%s'", refName
);
1954 OnInform((char *)errBuf
.c_str());
1957 else TexOutput("??");
1972 char *alignment
= "";
1973 if (macroId
== ltIMAGEL
)
1974 alignment
= " align=left";
1975 else if (macroId
== ltIMAGER
)
1976 alignment
= " align=right";
1978 // Try to find an XBM or GIF image first.
1979 char *filename
= copystring(GetArgData());
1982 strcpy(buf
, filename
);
1983 StripExtension(buf
);
1984 strcat(buf
, ".xbm");
1985 wxString f
= TexPathList
.FindValidPath(buf
);
1987 if (f
== "") // Try for a GIF instead
1989 strcpy(buf
, filename
);
1990 StripExtension(buf
);
1991 strcat(buf
, ".gif");
1992 f
= TexPathList
.FindValidPath(buf
);
1995 if (f
== "") // Try for a JPEG instead
1997 strcpy(buf
, filename
);
1998 StripExtension(buf
);
1999 strcat(buf
, ".jpg");
2000 f
= TexPathList
.FindValidPath(buf
);
2003 if (f
== "") // Try for a PNG instead
2005 strcpy(buf
, filename
);
2006 StripExtension(buf
);
2007 strcat(buf
, ".png");
2008 f
= TexPathList
.FindValidPath(buf
);
2013 char *inlineFilename
= copystring(f
);
2015 char *originalFilename
= TexPathList
.FindValidPath(filename
);
2016 // If we have found the existing filename, make the inline
2017 // image point to the original file (could be PS, for example)
2018 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
2020 TexOutput("<A HREF=\"");
2021 TexOutput(ConvertCase(originalFilename
));
2023 TexOutput("<img src=\"");
2024 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2025 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
2030 TexOutput("<img src=\"");
2031 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2032 TexOutput("\""); TexOutput(alignment
); TexOutput(">");
2033 delete[] inlineFilename
;
2038 // Last resort - a link to a PS file.
2039 TexOutput("<A HREF=\"");
2040 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2041 TexOutput("\">Picture</A>\n");
2042 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2050 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2053 static char *imageFile
= NULL
;
2054 if (start
&& (arg_no
== 2))
2056 // Try to find an XBM or GIF image first.
2057 char *filename
= copystring(GetArgData());
2060 strcpy(buf
, filename
);
2061 StripExtension(buf
);
2062 strcat(buf
, ".xbm");
2063 wxString f
= TexPathList
.FindValidPath(buf
);
2065 if (f
== "") // Try for a GIF instead
2067 strcpy(buf
, filename
);
2068 StripExtension(buf
);
2069 strcat(buf
, ".gif");
2070 f
= TexPathList
.FindValidPath(buf
);
2075 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2084 imageFile
= copystring(f
);
2087 else if (start
&& (arg_no
== 3))
2091 // First, try to find a .shg (segmented hypergraphics file)
2092 // that we can convert to a map file
2094 strcpy(buf
, imageFile
);
2095 StripExtension(buf
);
2096 strcat(buf
, ".shg");
2097 wxString f
= TexPathList
.FindValidPath(buf
);
2101 // The default HTML file to go to is THIS file (so a no-op)
2102 SHGToMap((char*) (const char*) f
, currentFileName
);
2105 char *mapName
= GetArgData();
2106 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2110 TexOutput("unknown");
2112 TexOutput("<img src=\"");
2113 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2114 TexOutput("\" ISMAP></A><P>");
2135 descriptionItemArg
= GetArgChunk();
2141 case ltTWOCOLITEMRULED
:
2144 if (start && (arg_no == 1))
2145 TexOutput("\n<DT> ");
2146 if (start && (arg_no == 2))
2153 if (TwoColWidthA
> -1) {
2155 sprintf(buf
,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA
);
2158 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2161 TexOutput("\n</FONT></TD>\n");
2167 if (TwoColWidthB
> -1) {
2169 sprintf(buf
,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB
);
2172 TexOutput("\n<TD VALIGN=TOP>\n");
2175 TexOutput("\n</FONT></TD></TR>\n");
2180 case ltNUMBEREDBIBITEM
:
2182 if (arg_no
== 1 && start
)
2184 TexOutput("\n<DT> ");
2186 if (arg_no
== 2 && !start
)
2193 if (arg_no
== 1 && start
)
2195 char *citeKey
= GetArgData();
2196 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2199 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2200 sprintf(buf
, "[%d]", citeCount
);
2201 ref
->sectionNumber
= copystring(buf
);
2204 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2209 if (arg_no
== 2 && !start
)
2215 case ltMARGINPARODD
:
2216 case ltMARGINPAREVEN
:
2222 TexOutput("<HR>\n");
2226 TexOutput("<HR><P>\n");
2230 case ltTWOCOLWIDTHA
:
2234 char *val
= GetArgData();
2235 float points
= ParseUnitArgument(val
);
2236 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2242 case ltTWOCOLWIDTHB
:
2246 char *val
= GetArgData();
2247 float points
= ParseUnitArgument(val
);
2248 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2257 case ltACCENT_GRAVE
:
2261 char *val
= GetArgData();
2267 TexOutput("à");
2270 TexOutput("è");
2273 TexOutput("ì");
2276 TexOutput("ò");
2279 TexOutput("ù");
2282 TexOutput("À");
2285 TexOutput("È");
2288 TexOutput("Ì");
2291 TexOutput("Ò");
2294 TexOutput("Ì");
2304 case ltACCENT_ACUTE
:
2308 char *val
= GetArgData();
2314 TexOutput("á");
2317 TexOutput("é");
2320 TexOutput("í");
2323 TexOutput("ó");
2326 TexOutput("ú");
2329 TexOutput("ý");
2332 TexOutput("Á");
2335 TexOutput("É");
2338 TexOutput("Í");
2341 TexOutput("Ó");
2344 TexOutput("Ú");
2347 TexOutput("Ý");
2357 case ltACCENT_CARET
:
2361 char *val
= GetArgData();
2367 TexOutput("â");
2370 TexOutput("ê");
2373 TexOutput("î");
2376 TexOutput("ô");
2379 TexOutput("û");
2382 TexOutput("Â");
2385 TexOutput("Ê");
2388 TexOutput("Î");
2391 TexOutput("Ô");
2394 TexOutput("Î");
2404 case ltACCENT_TILDE
:
2408 char *val
= GetArgData();
2417 TexOutput("ã");
2420 TexOutput("ñ");
2423 TexOutput("õ");
2426 TexOutput("Ã");
2429 TexOutput("Ñ");
2432 TexOutput("Õ");
2442 case ltACCENT_UMLAUT
:
2446 char *val
= GetArgData();
2452 TexOutput("ä");
2455 TexOutput("ë");
2458 TexOutput("ï");
2461 TexOutput("ö");
2464 TexOutput("ü");
2467 TexOutput("ÿ");
2470 TexOutput("Ä");
2473 TexOutput("Ë");
2476 TexOutput("Ï");
2479 TexOutput("Ö");
2482 TexOutput("Ü");
2485 TexOutput("Ÿ");
2499 char *val
= GetArgData();
2505 TexOutput("å");
2508 TexOutput("Å");
2522 char *val
= GetArgData();
2525 bool isPicture
= FALSE
;
2526 char *s
= ParseColourString(val
, &isPicture
);
2529 if (backgroundImageString
)
2530 delete[] backgroundImageString
;
2531 backgroundImageString
= copystring(val
);
2535 if (backgroundColourString
)
2536 delete[] backgroundColourString
;
2537 backgroundColourString
= copystring(val
);
2544 case ltBACKGROUNDIMAGE
:
2548 char *val
= GetArgData();
2551 if (backgroundImageString
)
2552 delete[] backgroundImageString
;
2553 backgroundImageString
= copystring(val
);
2559 case ltBACKGROUNDCOLOUR
:
2563 char *val
= GetArgData();
2566 if (backgroundColourString
)
2567 delete[] backgroundColourString
;
2568 backgroundColourString
= copystring(val
);
2578 char *val
= GetArgData();
2581 if (textColourString
)
2582 delete[] textColourString
;
2583 textColourString
= copystring(val
);
2593 char *val
= GetArgData();
2596 if (linkColourString
)
2597 delete[] linkColourString
;
2598 linkColourString
= copystring(val
);
2604 case ltFOLLOWEDLINKCOLOUR
:
2608 char *val
= GetArgData();
2611 if (followedLinkColourString
)
2612 delete[] followedLinkColourString
;
2613 followedLinkColourString
= copystring(val
);
2619 case ltACCENT_CADILLA
:
2623 char *val
= GetArgData();
2629 TexOutput("ç");
2632 TexOutput("Ç");
2644 case ltFOOTNOTEPOPUP:
2654 case ltSUPERTABULAR
:
2660 currentRowNumber
= 0;
2663 tableVerticalLineLeft
= FALSE
;
2664 tableVerticalLineRight
= FALSE
;
2665 int currentWidth
= 0;
2667 char *alignString
= copystring(GetArgData());
2668 ParseTableArgument(alignString
);
2670 TexOutput("<TABLE BORDER>\n");
2672 // Write the first row formatting for compatibility
2673 // with standard Latex
2674 if (compatibilityMode
)
2676 TexOutput("<TR>\n<TD>");
2679 for (int i = 0; i < noColumns; i++)
2681 currentWidth += TableData[i].width;
2682 sprintf(buf, "\\cellx%d", currentWidth);
2685 TexOutput("\\pard\\intbl\n");
2688 delete[] alignString
;
2693 else if (arg_no
== 2 && !start
)
2695 TexOutput("</TABLE>\n");
2700 case ltTHEBIBLIOGRAPHY
:
2702 if (start
&& (arg_no
== 1))
2704 ReopenFile(&Chapters
, &ChaptersName
);
2705 AddTexRef("bibliography", ChaptersName
, "bibliography");
2706 SetCurrentSubsectionName("bibliography", ChaptersName
);
2710 SetCurrentOutput(Chapters
);
2713 if (truncateFilenames
)
2714 sprintf(titleBuf
, "%s.htm", wxFileNameFromPath(FileRoot
));
2716 sprintf(titleBuf
, "%s_contents.html", wxFileNameFromPath(FileRoot
));
2719 TexOutput("<title>");
2720 TexOutput(ReferencesNameString
);
2721 TexOutput("</title></head>\n");
2724 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2725 AddBrowseButtons("contents", titleBuf
, // Up
2726 lastTopic
, lastFileName
, // Last topic
2727 "bibliography", ChaptersName
); // This topic
2729 SetCurrentOutputs(Contents
, Chapters
);
2730 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2732 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2733 fprintf(Chapters
, "</H2>\n</A>\n");
2735 SetCurrentOutput(Chapters
);
2738 if (!start
&& (arg_no
== 2))
2746 /* Build up list of keywords associated with topics */
2749 // char *entry = GetArgData();
2751 OutputChunkToString(GetArgChunk(), buf
);
2754 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2769 char *name
= GetArgData();
2771 if (!FindColourHTMLString(name
, buf2
))
2773 strcpy(buf2
, "#000000");
2775 sprintf(buf
, "Could not find colour name %s", name
);
2778 TexOutput("<FONT COLOR=\"");
2794 if (arg_no
== 2) TexOutput("</FONT>");
2799 case ltINSERTATLEVEL
:
2801 // This macro allows you to insert text at a different level
2802 // from the current level, e.g. into the Sections from within a subsubsection.
2805 static int currentLevelNo
= 1;
2806 static FILE* oldLevelFile
= Chapters
;
2813 oldLevelFile
= CurrentOutput1
;
2815 char *str
= GetArgData();
2816 currentLevelNo
= atoi(str
);
2818 // TODO: cope with article style (no chapters)
2819 switch (currentLevelNo
)
2823 outputFile
= Chapters
;
2828 outputFile
= Sections
;
2833 outputFile
= Subsections
;
2838 outputFile
= Subsubsections
;
2848 CurrentOutput1
= outputFile
;
2866 CurrentOutput1
= oldLevelFile
;
2872 return DefaultOnArgument(macroId
, arg_no
, start
);
2885 tableVerticalLineLeft
= FALSE
;
2886 tableVerticalLineRight
= FALSE
;
2889 if (InputFile
&& OutputFile
)
2891 // Do some HTML-specific transformations on all the strings,
2893 Text2HTML(GetTopLevelChunk());
2896 if (truncateFilenames
)
2897 sprintf(buf
, "%s.htm", FileRoot
);
2899 sprintf(buf
, "%s_contents.html", FileRoot
);
2900 if (TitlepageName
) delete[] TitlepageName
;
2901 TitlepageName
= copystring(buf
);
2902 Titlepage
= fopen(buf
, "w");
2904 if (truncateFilenames
)
2905 sprintf(buf
, "%s_fc.htm", FileRoot
);
2907 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2909 contentsFrameName
= copystring(buf
);
2911 Contents
= fopen(TmpContentsName
, "w");
2913 if (htmlFrameContents
)
2915 // FrameContents = fopen(TmpFrameContentsName, "w");
2916 FrameContents
= fopen(contentsFrameName
, "w");
2917 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2920 if (!Titlepage
|| !Contents
)
2922 OnError("Cannot open output file!");
2925 AddTexRef("contents", wxFileNameFromPath(TitlepageName
), ContentsNameString
);
2927 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2929 fprintf(Contents
, "<UL>\n");
2931 SetCurrentOutput(Titlepage
);
2932 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2933 OnInform("Converting...");
2936 fprintf(Contents
, "</UL>\n\n");
2938 // SetCurrentOutput(Titlepage);
2943 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2950 fprintf(FrameContents
, "\n</UL>\n");
2951 fprintf(FrameContents
, "</HTML>\n");
2952 fclose(FrameContents
);
2953 FrameContents
= NULL
;
2958 fprintf(Chapters
, "\n</FONT></BODY></HTML>\n");
2964 fprintf(Sections
, "\n</FONT></BODY></HTML>\n");
2968 if (Subsections
&& !combineSubSections
)
2970 fprintf(Subsections
, "\n</FONT></BODY></HTML>\n");
2971 fclose(Subsections
);
2974 if (Subsubsections
&& !combineSubSections
)
2976 fprintf(Subsubsections
, "\n</FONT></BODY></HTML>\n");
2977 fclose(Subsubsections
);
2978 Subsubsections
= NULL
;
2980 if ( SectionContentsFD
)
2982 fclose(SectionContentsFD
);
2983 SectionContentsFD
= NULL
;
2986 // Create a temporary file for the title page header, add some info,
2987 // and concat the titlepage just generated.
2988 // This is necessary in order to put the title of the document
2989 // at the TOP of the file within <HEAD>, even though we only find out
2990 // what it is later on.
2991 FILE *tmpTitle
= fopen("title.tmp", "w");
2996 SetCurrentOutput(tmpTitle
);
2998 TexOutput("\n<HEAD><TITLE>");
2999 TraverseChildrenFromChunk(DocumentTitle
);
3000 TexOutput("</TITLE></HEAD>\n");
3004 SetCurrentOutput(tmpTitle
);
3005 HTMLHeadTo(tmpTitle
);
3007 fprintf(tmpTitle
, "<TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
3009 fprintf(tmpTitle
, "<TITLE>%s</TITLE></HEAD>\n\n", wxFileNameFromPath(FileRoot
));
3012 // Output frame information
3013 if (htmlFrameContents
)
3015 char firstFileName
[300];
3016 if (truncateFilenames
)
3017 sprintf(firstFileName
, "%s1.htm", FileRoot
);
3019 sprintf(firstFileName
, "%s1.html", FileRoot
);
3021 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
3023 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3024 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(wxFileNameFromPath(firstFileName
)));
3025 fprintf(tmpTitle
, "</FRAMESET>\n");
3027 fprintf(tmpTitle
, "<NOFRAMES>\n");
3030 // Output <BODY...> to temporary title page
3034 FILE *fd
= fopen(TitlepageName
, "r");
3046 fprintf(tmpTitle
, "\n</FONT></BODY>\n");
3048 if (htmlFrameContents
)
3050 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
3052 fprintf(tmpTitle
, "\n</HTML>\n");
3055 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3056 if (!wxRenameFile("title.tmp", TitlepageName
))
3058 wxCopyFile("title.tmp", TitlepageName
);
3059 wxRemoveFile("title.tmp");
3063 if (lastFileName
) delete[] lastFileName
;
3064 lastFileName
= NULL
;
3065 if (lastTopic
) delete[] lastTopic
;
3068 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3070 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3072 wxCopyFile(TmpContentsName
, ContentsName
);
3073 wxRemoveFile(TmpContentsName
);
3076 // Generate .htx file if requested
3079 char htmlIndexName
[300];
3080 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
3081 GenerateHTMLIndexFile(htmlIndexName
);
3084 // Generate HTML Help Workshop files if requested
3085 if (htmlWorkshopFiles
)
3087 HTMLWorkshopEndContents();
3088 GenerateHTMLWorkshopFiles(FileRoot
);
3098 // Output .htx index file
3099 void GenerateHTMLIndexFile(char *fname
)
3101 FILE *fd
= fopen(fname
, "w");
3105 TopicTable
.BeginFind();
3106 wxNode
*node
= NULL
;
3107 while ((node
= TopicTable
.Next()))
3109 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3110 const char *topicName
= node
->GetKeyString();
3111 if (texTopic
->filename
&& texTopic
->keywords
)
3113 wxNode
*node1
= texTopic
->keywords
->First();
3116 char *s
= (char *)node1
->Data();
3117 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3118 node1
= node1
->Next();
3131 // output .hpp, .hhc and .hhk files:
3134 void GenerateHTMLWorkshopFiles(char *fname
)
3139 /* Generate project file : */
3141 sprintf(buf
, "%s.hhp", fname
);
3142 f
= fopen(buf
, "wt");
3145 "Compatibility=1.1\n"
3146 "Full-text search=Yes\n"
3147 "Contents file=%s.hhc\n"
3148 "Compiled file=%s.chm\n"
3149 "Default Window=%sHelp\n"
3150 "Default topic=%s\n"
3151 "Index file=%s.hhk\n"
3153 wxFileNameFromPath(fname
),
3154 wxFileNameFromPath(fname
),
3155 wxFileNameFromPath(fname
),
3156 wxFileNameFromPath(TitlepageName
),
3157 wxFileNameFromPath(fname
)
3160 if (DocumentTitle
) {
3161 SetCurrentOutput(f
);
3162 TraverseChildrenFromChunk(DocumentTitle
);
3164 else fprintf(f
, "(unknown)");
3166 fprintf(f
, "\n\n[WINDOWS]\n"
3167 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3168 wxFileNameFromPath(fname
),
3169 wxFileNameFromPath(fname
),
3170 wxFileNameFromPath(fname
),
3171 wxFileNameFromPath(TitlepageName
));
3174 fprintf(f
, "\n\n[FILES]\n");
3175 fprintf(f
, "%s\n", wxFileNameFromPath(TitlepageName
));
3176 for (int i
= 1; i
<= fileId
; i
++) {
3177 if (truncateFilenames
)
3178 sprintf(buf
, "%s%d.htm", wxFileNameFromPath(FileRoot
), i
);
3180 sprintf(buf
, "%s%d.html", wxFileNameFromPath(FileRoot
), i
);
3181 fprintf(f
, "%s\n", buf
);
3185 /* Generate index file : */
3187 sprintf(buf
, "%s.hhk", fname
);
3188 f
= fopen(buf
, "wt");
3191 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3196 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3197 "<!-- Sitemap 1.0 -->\n"
3199 "<OBJECT type=\"text/site properties\">\n"
3200 " <param name=\"ImageType\" value=\"Folder\">\n"
3204 TopicTable
.BeginFind();
3205 wxNode
*node
= NULL
;
3206 while ((node
= TopicTable
.Next()))
3208 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3209 const char *topicName
= node
->GetKeyString();
3210 if (texTopic
->filename
&& texTopic
->keywords
)
3212 wxNode
*node1
= texTopic
->keywords
->First();
3215 char *s
= (char *)node1
->Data();
3217 " <LI> <OBJECT type=\"text/sitemap\">\n"
3218 " <param name=\"Local\" value=\"%s#%s\">\n"
3219 " <param name=\"Name\" value=\"%s\">\n"
3221 texTopic
->filename
, topicName
, s
);
3222 node1
= node1
->Next();
3227 fprintf(f
, "</UL>\n");
3233 static FILE *HTMLWorkshopContents
= NULL
;
3234 static int HTMLWorkshopLastLevel
= 0;
3236 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3240 if (level
> HTMLWorkshopLastLevel
)
3241 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3242 fprintf(HTMLWorkshopContents
, "<UL>");
3243 if (level
< HTMLWorkshopLastLevel
)
3244 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3245 fprintf(HTMLWorkshopContents
, "</UL>");
3247 SetCurrentOutput(HTMLWorkshopContents
);
3248 fprintf(HTMLWorkshopContents
,
3249 " <LI> <OBJECT type=\"text/sitemap\">\n"
3250 " <param name=\"Local\" value=\"%s#%s\">\n"
3251 " <param name=\"Name\" value=\"",
3253 OutputCurrentSection();
3254 fprintf(HTMLWorkshopContents
,
3257 HTMLWorkshopLastLevel
= level
;
3261 void HTMLWorkshopStartContents()
3264 sprintf(buf
, "%s.hhc", FileRoot
);
3265 HTMLWorkshopContents
= fopen(buf
, "wt");
3266 HTMLWorkshopLastLevel
= 0;
3268 fprintf(HTMLWorkshopContents
,
3269 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3271 HTMLHeadTo(HTMLWorkshopContents
);
3272 fprintf(HTMLWorkshopContents
,
3274 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3275 "<!-- Sitemap 1.0 -->\n"
3277 "<OBJECT type=\"text/site properties\">\n"
3278 " <param name=\"ImageType\" value=\"Folder\">\n"
3281 "<LI> <OBJECT type=\"text/sitemap\">\n"
3282 "<param name=\"Local\" value=\"%s\">\n"
3283 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3284 wxFileNameFromPath(TitlepageName
)
3290 void HTMLWorkshopEndContents()
3292 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3293 fprintf(HTMLWorkshopContents
, "</UL>\n");
3294 fclose(HTMLWorkshopContents
);