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"
30 #if !WXWIN_COMPATIBILITY_2_4
31 static inline wxChar
* copystring(const wxChar
* s
)
32 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
35 extern wxHashTable TexReferences
;
38 extern void DecToHex(int, char *);
39 void GenerateHTMLIndexFile(char *fname
);
41 void GenerateHTMLWorkshopFiles(char *fname
);
42 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
);
43 void HTMLWorkshopStartContents();
44 void HTMLWorkshopEndContents();
46 void OutputContentsFrame(void);
48 #include "readshg.h" // Segmented hypergraphics parsing
50 char *ChaptersName
= NULL
;
51 char *SectionsName
= NULL
;
52 char *SubsectionsName
= NULL
;
53 char *SubsubsectionsName
= NULL
;
54 char *TitlepageName
= NULL
;
55 char *lastFileName
= NULL
;
56 char *lastTopic
= NULL
;
57 char *currentFileName
= NULL
;
58 char *contentsFrameName
= NULL
;
60 static TexChunk
*descriptionItemArg
= NULL
;
61 static TexChunk
*helpRefFilename
= NULL
;
62 static TexChunk
*helpRefText
= NULL
;
63 static int indentLevel
= 0;
64 static int citeCount
= 1;
65 extern FILE *Contents
;
66 FILE *FrameContents
= NULL
;
67 FILE *Titlepage
= NULL
;
68 // FILE *FrameTitlepage = NULL;
70 bool subsectionStarted
= FALSE
;
72 // Which column of a row are we in? (Assumes no nested tables, of course)
73 int currentColumn
= 0;
75 // Are we in verbatim mode? If so, format differently.
76 static bool inVerbatim
= FALSE
;
78 // Need to know whether we're in a table or figure for benefit
79 // of listoffigures/listoftables
80 static bool inFigure
= FALSE
;
81 static bool inTable
= FALSE
;
83 // This is defined in the Tex2Any library.
84 extern char *BigBuffer
;
86 // DHS Two-column table dimensions.
87 static int TwoColWidthA
= -1;
88 static int TwoColWidthB
= -1;
91 class HyperReference
: public wxObject
96 HyperReference(char *name
, char *file
)
98 if (name
) refName
= copystring(name
);
99 if (file
) refFile
= copystring(file
);
103 class TexNextPage
: public wxObject
108 TexNextPage(char *theLabel
, char *theFile
)
110 label
= copystring(theLabel
);
111 filename
= copystring(theFile
);
120 wxHashTable
TexNextPages(wxKEY_STRING
);
122 static char *CurrentChapterName
= NULL
;
123 static char *CurrentChapterFile
= NULL
;
124 static char *CurrentSectionName
= NULL
;
125 static char *CurrentSectionFile
= NULL
;
126 static char *CurrentSubsectionName
= NULL
;
127 static char *CurrentSubsectionFile
= NULL
;
128 static char *CurrentSubsubsectionName
= NULL
;
129 static char *CurrentSubsubsectionFile
= NULL
;
130 static char *CurrentTopic
= NULL
;
132 static void SetCurrentTopic(char *s
)
134 if (CurrentTopic
) delete[] CurrentTopic
;
135 CurrentTopic
= copystring(s
);
138 void SetCurrentChapterName(char *s
, char *file
)
140 if (CurrentChapterName
) delete[] CurrentChapterName
;
141 CurrentChapterName
= copystring(s
);
142 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
143 CurrentChapterFile
= copystring(file
);
145 currentFileName
= CurrentChapterFile
;
149 void SetCurrentSectionName(char *s
, char *file
)
151 if (CurrentSectionName
) delete[] CurrentSectionName
;
152 CurrentSectionName
= copystring(s
);
153 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
154 CurrentSectionFile
= copystring(file
);
156 currentFileName
= CurrentSectionFile
;
159 void SetCurrentSubsectionName(char *s
, char *file
)
161 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
162 CurrentSubsectionName
= copystring(s
);
163 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
164 CurrentSubsectionFile
= copystring(file
);
165 currentFileName
= CurrentSubsectionFile
;
168 void SetCurrentSubsubsectionName(char *s
, char *file
)
170 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
171 CurrentSubsubsectionName
= copystring(s
);
172 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
173 CurrentSubsubsectionFile
= copystring(file
);
174 currentFileName
= CurrentSubsubsectionFile
;
179 * Close former filedescriptor and reopen using another filename.
183 void ReopenFile(FILE **fd
, char **fileName
)
187 fprintf(*fd
, "\n</FONT></BODY></HTML>\n");
192 if (truncateFilenames
)
193 sprintf(buf
, "%s%d.htm", FileRoot
, fileId
);
195 sprintf(buf
, "%s%d.html", FileRoot
, fileId
);
196 if (*fileName
) delete[] *fileName
;
197 *fileName
= copystring(wxFileNameFromPath(buf
));
198 *fd
= fopen(buf
, "w");
199 fprintf(*fd
, "<HTML>\n");
203 * Reopen section contents file, i.e. the index appended to each section
204 * in subsectionCombine mode
207 static char *SectionContentsFilename
= NULL
;
208 static FILE *SectionContentsFD
= NULL
;
210 void ReopenSectionContentsFile(void)
212 if ( SectionContentsFD
)
214 fclose(SectionContentsFD
);
216 if ( SectionContentsFilename
)
217 delete[] SectionContentsFilename
;
218 SectionContentsFD
= NULL
;
219 SectionContentsFilename
= NULL
;
221 // Create the name from the current section filename
222 if ( CurrentSectionFile
)
225 strcpy(buf
, CurrentSectionFile
);
226 wxStripExtension(buf
);
228 SectionContentsFilename
= copystring(buf
);
230 SectionContentsFD
= fopen(SectionContentsFilename
, "w");
236 * Given a TexChunk with a string value, scans through the string
237 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
241 void ProcessText2HTML(TexChunk
*chunk
)
243 bool changed
= FALSE
;
247 int len
= strlen(chunk
->value
);
250 ch
= chunk
->value
[i
];
252 // 2 newlines means \par
253 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
254 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
255 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
257 BigBuffer
[ptr
] = 0; strcat(BigBuffer
, "<P>\n\n"); ptr
+= 5;
261 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
263 BigBuffer
[ptr
] = '"'; ptr
++;
267 else if (!inVerbatim
&& ch
== '`') // Change ` to '
269 BigBuffer
[ptr
] = 39; ptr
++;
273 else if (ch
== '<') // Change < to <
276 strcat(BigBuffer
, "<");
281 else if (ch
== '>') // Change > to >
284 strcat(BigBuffer
, ">");
301 chunk
->value
= copystring(BigBuffer
);
306 * Scan through all chunks starting from the given one,
307 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
308 * This should be called after Tex2Any has parsed the file,
309 * and before TraverseDocument is called.
313 void Text2HTML(TexChunk
*chunk
)
316 if (stopRunning
) return;
320 case CHUNK_TYPE_MACRO
:
322 TexMacroDef
*def
= chunk
->def
;
324 if (def
&& def
->ignore
)
327 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
330 wxNode
*node
= chunk
->children
.First();
333 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
334 Text2HTML(child_chunk
);
338 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
345 wxNode
*node
= chunk
->children
.First();
348 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
349 Text2HTML(child_chunk
);
355 case CHUNK_TYPE_STRING
:
358 ProcessText2HTML(chunk
);
365 * Add appropriate browse buttons to this page.
369 void AddBrowseButtons(char *upLabel
, char *upFilename
,
370 char *previousLabel
, char *previousFilename
,
371 char *thisLabel
, char *thisFilename
)
373 char contentsReferenceBuf
[80];
374 char upReferenceBuf
[80];
375 char backReferenceBuf
[80];
376 char forwardReferenceBuf
[80];
377 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
380 char *contentsReference
= NULL
;
381 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
382 contentsReference
= ContentsNameString
;
385 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
386 contentsReference
= contentsReferenceBuf
;
387 sprintf(contentsReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">", ConvertCase("contents.gif"));
390 char *upReference
= NULL
;
391 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
392 upReference
= UpNameString
;
395 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
396 upReference
= upReferenceBuf
;
397 sprintf(upReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">", ConvertCase("up.gif"));
400 char *backReference
= NULL
;
401 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
402 backReference
= "<<";
405 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
406 backReference
= backReferenceBuf
;
407 sprintf(backReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">", ConvertCase("back.gif"));
410 char *forwardReference
= NULL
;
411 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
412 forwardReference
= ">>";
415 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
416 forwardReference
= forwardReferenceBuf
;
417 sprintf(forwardReference
, "<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">", ConvertCase("forward.gif"));
420 TexOutput("<CENTER>");
429 if (truncateFilenames
)
432 strcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
433 sprintf(buf
, "\n<A HREF=\"%s.%s\">%s</A> ", buf1
, ConvertCase("htm"), contentsReference
);
438 strcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
439 sprintf(buf
, "\n<A HREF=\"%s%s\">%s</A> ", buf1
, ConvertCase("_contents.html"), contentsReference
);
441 // TexOutput("<NOFRAMES>");
443 // TexOutput("</NOFRAMES>");
450 if (upLabel
&& upFilename
)
452 if (strlen(upLabel
) > 0)
453 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(upFilename
), upLabel
, upReference
);
455 sprintf(buf
, "<A HREF=\"%s\">%s</A> ", ConvertCase(upFilename
), upReference
);
456 if (strcmp(upLabel
, "contents") == 0)
458 // TexOutput("<NOFRAMES>");
460 // TexOutput("</NOFRAMES>");
471 if (previousLabel
&& previousFilename
)
473 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(previousFilename
), previousLabel
, backReference
);
474 if (strcmp(previousLabel
, "contents") == 0)
476 // TexOutput("<NOFRAMES>");
478 // TexOutput("</NOFRAMES>");
485 // A placeholder so the buttons don't keep moving position
486 sprintf(buf
, "%s ", backReference
);
490 char *nextLabel
= NULL
;
491 char *nextFilename
= NULL
;
493 // Get the next page, and record the previous page's 'next' page
495 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
498 nextLabel
= nextPage
->label
;
499 nextFilename
= nextPage
->filename
;
501 if (previousLabel
&& previousFilename
)
503 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
507 TexNextPages
.Delete(previousLabel
);
509 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
510 TexNextPages
.Put(previousLabel
, newNextPage
);
518 if (nextLabel
&& nextFilename
)
520 sprintf(buf
, "<A HREF=\"%s#%s\">%s</A> ", ConvertCase(nextFilename
), nextLabel
, forwardReference
);
525 // A placeholder so the buttons don't keep moving position
526 sprintf(buf
, "%s ", forwardReference
);
531 * Horizontal rule to finish it off nicely.
534 TexOutput("</CENTER>");
537 // Update last topic/filename
539 delete[] lastFileName
;
540 lastFileName
= copystring(thisFilename
);
543 lastTopic
= copystring(thisLabel
);
546 // A colour string is either 3 numbers separated by semicolons (RGB),
547 // or a reference to a GIF. Return the filename or a hex string like #934CE8
548 char *ParseColourString(char *bkStr
, bool *isPicture
)
550 static char resStr
[300];
551 strcpy(resStr
, bkStr
);
552 char *tok1
= strtok(resStr
, ";");
553 char *tok2
= strtok(NULL
, ";");
564 char *tok3
= strtok(NULL
, ";");
567 // Now convert 3 strings into decimal numbers, and then hex numbers.
568 int red
= atoi(tok1
);
569 int green
= atoi(tok2
);
570 int blue
= atoi(tok3
);
577 DecToHex(green
, buf
);
589 void OutputFont(void)
591 // Only output <font face> if explicitly requested by htmlFaceName= directive in
592 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
596 // Output <FONT FACE=...>
597 TexOutput("<FONT FACE=\"");
598 TexOutput(htmlFaceName
);
603 // Output start of <BODY> block
604 void OutputBodyStart(void)
606 TexOutput("\n<BODY");
607 if (backgroundImageString
)
609 bool isPicture
= FALSE
;
610 char *s
= ParseColourString(backgroundImageString
, &isPicture
);
613 TexOutput(" BACKGROUND=\""); TexOutput(s
); TexOutput("\"");
616 if (backgroundColourString
)
618 bool isPicture
= FALSE
;
619 char *s
= ParseColourString(backgroundColourString
, &isPicture
);
622 TexOutput(" BGCOLOR="); TexOutput(s
);
626 // Set foreground text colour, if one is specified
627 if (textColourString
)
629 bool isPicture
= FALSE
;
630 char *s
= ParseColourString(textColourString
, &isPicture
);
633 TexOutput(" TEXT="); TexOutput(s
);
636 // Set link text colour, if one is specified
637 if (linkColourString
)
639 bool isPicture
= FALSE
;
640 char *s
= ParseColourString(linkColourString
, &isPicture
);
643 TexOutput(" LINK="); TexOutput(s
);
646 // Set followed link text colour, if one is specified
647 if (followedLinkColourString
)
649 bool isPicture
= FALSE
;
650 char *s
= ParseColourString(followedLinkColourString
, &isPicture
);
653 TexOutput(" VLINK="); TexOutput(s
);
664 if (htmlStylesheet
) {
665 TexOutput("<link rel=stylesheet type=\"text/css\" href=\"");
666 TexOutput(htmlStylesheet
);
671 void HTMLHeadTo(FILE* f
)
674 fprintf(f
,"<head><link rel=stylesheet type=\"text/css\" href=\"%s\">",htmlStylesheet
);
679 // Called on start/end of macro examination
680 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
686 case ltCHAPTERHEADING
:
694 if (macroId
!= ltCHAPTERSTAR
)
697 SetCurrentOutput(NULL
);
698 startedSections
= TRUE
;
700 char *topicName
= FindTopicName(GetNextChunk());
701 ReopenFile(&Chapters
, &ChaptersName
);
702 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
704 SetCurrentChapterName(topicName
, ChaptersName
);
705 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
707 SetCurrentOutput(Chapters
);
710 TexOutput("<title>");
711 OutputCurrentSection(); // Repeat section header
712 TexOutput("</title></head>\n");
716 if (truncateFilenames
)
717 sprintf(titleBuf
, "%s.htm", wxFileNameFromPath(FileRoot
));
719 sprintf(titleBuf
, "%s_contents.html", wxFileNameFromPath(FileRoot
));
721 fprintf(Chapters
, "<A NAME=\"%s\"></A>", topicName
);
723 AddBrowseButtons("", titleBuf
, // Up
724 lastTopic
, lastFileName
, // Last topic
725 topicName
, ChaptersName
); // This topic
727 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), topicName
);
729 if (htmlFrameContents
&& FrameContents
)
731 SetCurrentOutput(FrameContents
);
732 fprintf(FrameContents
, "\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">", ConvertCase(ChaptersName
), topicName
);
733 OutputCurrentSection();
734 fprintf(FrameContents
, "</A>\n");
737 SetCurrentOutputs(Contents
, Chapters
);
738 fprintf(Chapters
, "\n<H2>");
739 OutputCurrentSection();
740 fprintf(Contents
, "</A>\n");
741 fprintf(Chapters
, "</H2>\n");
743 SetCurrentOutput(Chapters
);
745 // Add this section title to the list of keywords
748 OutputCurrentSectionToString(wxTex2RTFBuffer
);
749 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
756 case ltSECTIONHEADING
:
763 subsectionStarted
= FALSE
;
765 if (macroId
!= ltSECTIONSTAR
)
768 SetCurrentOutput(NULL
);
769 startedSections
= TRUE
;
771 char *topicName
= FindTopicName(GetNextChunk());
772 ReopenFile(&Sections
, &SectionsName
);
773 AddTexRef(topicName
, SectionsName
, SectionNameString
);
775 SetCurrentSectionName(topicName
, SectionsName
);
776 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
778 SetCurrentOutput(Sections
);
780 TexOutput("<title>");
781 OutputCurrentSection();
782 TexOutput("</title></head>\n");
785 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
786 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
787 lastTopic
, lastFileName
, // Last topic
788 topicName
, SectionsName
); // This topic
790 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
792 SetCurrentOutputs(jumpFrom
, Sections
);
793 if (DocumentStyle
== LATEX_ARTICLE
)
794 fprintf(jumpFrom
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(SectionsName
), topicName
);
796 fprintf(jumpFrom
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SectionsName
), topicName
);
798 fprintf(Sections
, "\n<H2>");
799 OutputCurrentSection();
801 if (DocumentStyle
== LATEX_ARTICLE
)
802 fprintf(jumpFrom
, "</A>\n");
804 fprintf(jumpFrom
, "</B></A><BR>\n");
805 fprintf(Sections
, "</H2>\n");
807 SetCurrentOutput(Sections
);
808 // Add this section title to the list of keywords
811 OutputCurrentSectionToString(wxTex2RTFBuffer
);
812 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
818 case ltSUBSECTIONSTAR
:
819 case ltMEMBERSECTION
:
820 case ltFUNCTIONSECTION
:
826 OnError("You cannot have a subsection before a section!");
832 if (macroId
!= ltSUBSECTIONSTAR
)
835 if ( combineSubSections
&& !subsectionStarted
)
837 // Read old .con file in at this point
839 strcpy(buf
, CurrentSectionFile
);
840 wxStripExtension(buf
);
842 FILE *fd
= fopen(buf
, "r");
853 fprintf(Sections
, "<P>\n");
855 // Close old file, create a new file for the sub(sub)section contents entries
856 ReopenSectionContentsFile();
859 startedSections
= TRUE
;
860 subsectionStarted
= TRUE
;
862 char *topicName
= FindTopicName(GetNextChunk());
864 if ( !combineSubSections
)
866 SetCurrentOutput(NULL
);
867 ReopenFile(&Subsections
, &SubsectionsName
);
868 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
869 SetCurrentSubsectionName(topicName
, SubsectionsName
);
870 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
871 SetCurrentOutput(Subsections
);
874 TexOutput("<title>");
875 OutputCurrentSection();
876 TexOutput("</title></head>\n");
879 fprintf(Subsections
, "<A NAME=\"%s\"></A>", topicName
);
880 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
881 lastTopic
, lastFileName
, // Last topic
882 topicName
, SubsectionsName
); // This topic
884 SetCurrentOutputs(Sections
, Subsections
);
885 fprintf(Sections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsectionsName
), topicName
);
887 fprintf(Subsections
, "\n<H3>");
888 OutputCurrentSection();
889 fprintf(Sections
, "</B></A><BR>\n");
890 fprintf(Subsections
, "</H3>\n");
892 SetCurrentOutput(Subsections
);
896 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
897 SetCurrentSubsectionName(topicName
, SectionsName
);
899 // if ( subsectionNo != 0 )
900 fprintf(Sections
, "\n<HR>\n");
902 // We're putting everything into the section file
903 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
904 fprintf(Sections
, "\n<H3>");
905 OutputCurrentSection();
906 fprintf(Sections
, "</H3>\n");
908 SetCurrentOutput(SectionContentsFD
);
909 fprintf(SectionContentsFD
, "<A HREF=\"#%s\">", topicName
);
910 OutputCurrentSection();
911 TexOutput("</A><BR>\n");
913 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
914 SetCurrentOutput(Sections
);
916 // Add this section title to the list of keywords
919 OutputCurrentSectionToString(wxTex2RTFBuffer
);
920 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
927 case ltSUBSUBSECTION
:
928 case ltSUBSUBSECTIONSTAR
:
932 if (!Subsections
&& !combineSubSections
)
934 OnError("You cannot have a subsubsection before a subsection!");
938 if (macroId
!= ltSUBSUBSECTIONSTAR
)
941 startedSections
= TRUE
;
943 char *topicName
= FindTopicName(GetNextChunk());
945 if ( !combineSubSections
)
947 SetCurrentOutput(NULL
);
948 ReopenFile(&Subsubsections
, &SubsubsectionsName
);
949 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
950 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
951 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
953 SetCurrentOutput(Subsubsections
);
955 TexOutput("<title>");
956 OutputCurrentSection();
957 TexOutput("</title></head>\n");
960 fprintf(Subsubsections
, "<A NAME=\"%s\"></A>", topicName
);
962 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
963 lastTopic
, lastFileName
, // Last topic
964 topicName
, SubsubsectionsName
); // This topic
966 SetCurrentOutputs(Subsections
, Subsubsections
);
967 fprintf(Subsections
, "\n<A HREF=\"%s#%s\"><B>", ConvertCase(SubsubsectionsName
), topicName
);
969 fprintf(Subsubsections
, "\n<H3>");
970 OutputCurrentSection();
971 fprintf(Subsections
, "</B></A><BR>\n");
972 fprintf(Subsubsections
, "</H3>\n");
976 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
977 SetCurrentSubsectionName(topicName
, SectionsName
);
978 fprintf(Sections
, "\n<HR>\n");
980 // We're putting everything into the section file
981 fprintf(Sections
, "<A NAME=\"%s\"></A>", topicName
);
982 fprintf(Sections
, "\n<H3>");
983 OutputCurrentSection();
984 fprintf(Sections
, "</H3>\n");
985 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
986 SetCurrentOutput(SectionContentsFD);
987 fprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
988 OutputCurrentSection();
989 TexOutput("</A><BR>");
991 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
992 SetCurrentOutput(Sections
);
995 // Add this section title to the list of keywords
998 OutputCurrentSectionToString(wxTex2RTFBuffer
);
999 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1008 if ( !combineSubSections
)
1009 SetCurrentOutput(Subsections
);
1011 SetCurrentOutput(Sections
);
1022 if ( !combineSubSections
)
1023 SetCurrentOutput(Subsections
);
1025 SetCurrentOutput(Sections
);
1036 if ( !combineSubSections
)
1037 SetCurrentOutput(Subsections
);
1039 SetCurrentOutput(Sections
);
1050 // TexOutput("<B>void</B>");
1058 TexOutput("wxCLIPS");
1064 case ltSPECIALAMPERSAND
:
1070 // End cell, start cell
1072 TexOutput("</FONT></TD>");
1074 // Start new row and cell, setting alignment for the first cell.
1075 if (currentColumn
< noColumns
)
1079 if (TableData
[currentColumn
].justification
== 'c')
1080 sprintf(buf
, "\n<TD ALIGN=CENTER>");
1081 else if (TableData
[currentColumn
].justification
== 'r')
1082 sprintf(buf
, "\n<TD ALIGN=RIGHT>");
1083 else if (TableData
[currentColumn
].absWidth
)
1085 // Convert from points * 20 into pixels.
1086 int points
= TableData
[currentColumn
].width
/ 20;
1088 // Say the display is 100 DPI (dots/pixels per inch).
1089 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1090 int pixels
= (int)(points
* 100.0 / 72.0);
1091 sprintf(buf
, "<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1094 sprintf(buf
, "\n<TD ALIGN=LEFT>");
1103 case ltBACKSLASHCHAR
:
1109 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1110 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1111 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1112 TexOutput("</TR>\n");
1115 TexOutput("<BR>\n");
1126 // Start new row and cell, setting alignment for the first cell.
1128 if (TableData
[currentColumn
].justification
== 'c')
1129 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER>");
1130 else if (TableData
[currentColumn
].justification
== 'r')
1131 sprintf(buf
, "<TR>\n<TD ALIGN=RIGHT>");
1132 else if (TableData
[currentColumn
].absWidth
)
1134 // Convert from points * 20 into pixels.
1135 int points
= TableData
[currentColumn
].width
/ 20;
1137 // Say the display is 100 DPI (dots/pixels per inch).
1138 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1139 int pixels
= (int)(points
* 100.0 / 72.0);
1140 sprintf(buf
, "<TR>\n<TD ALIGN=CENTER WIDTH=%d>", pixels
);
1143 sprintf(buf
, "<TR>\n<TD ALIGN=LEFT>");
1150 // Start new row and cell
1151 TexOutput("</FONT></TD>\n</TR>\n");
1155 // HTML-only: break until the end of the picture (both margins are clear).
1159 TexOutput("<BR CLEAR=ALL>");
1162 case ltRTFSP
: // Explicit space, RTF only
1164 case ltSPECIALTILDE
:
1178 TexOutput("<UL><UL>\n");
1180 TexOutput("</UL></UL>\n");
1186 // case ltTWOCOLLIST:
1193 if (macroId
== ltENUMERATE
)
1194 listType
= LATEX_ENUMERATE
;
1195 else if (macroId
== ltITEMIZE
)
1196 listType
= LATEX_ITEMIZE
;
1198 listType
= LATEX_DESCRIPTION
;
1200 itemizeStack
.Insert(new ItemizeStruc(listType
));
1204 TexOutput("<UL>\n");
1206 case LATEX_ENUMERATE
:
1207 TexOutput("<OL>\n");
1209 case LATEX_DESCRIPTION
:
1211 TexOutput("<DL>\n");
1218 if (itemizeStack
.First())
1220 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.First()->Data();
1221 switch (struc
->listType
)
1224 TexOutput("</UL>\n");
1226 case LATEX_ENUMERATE
:
1227 TexOutput("</OL>\n");
1229 case LATEX_DESCRIPTION
:
1231 TexOutput("</DL>\n");
1236 delete itemizeStack
.First();
1244 TexOutput("\n<TABLE>\n");
1246 TexOutput("\n</TABLE>\n");
1259 /* For footnotes we need to output the text at the bottom of the page and
1260 * insert a reference to it. Is it worth the trouble...
1262 case ltFOOTNOTEPOPUP:
1268 else TexOutput("</FN>");
1276 else TexOutput("</TT>");
1284 sprintf(buf
, "<PRE>\n");
1287 else TexOutput("</PRE>\n");
1295 TexOutput("<CENTER>");
1297 else TexOutput("</CENTER>");
1305 TexOutput("{\\ql ");
1307 else TexOutput("}\\par\\pard\n");
1316 TexOutput("{\\qr ");
1318 else TexOutput("}\\par\\pard\n");
1326 // Netscape extension
1327 TexOutput("<FONT SIZE=2>");
1329 else TexOutput("</FONT>");
1336 // Netscape extension
1337 TexOutput("<FONT SIZE=1>");
1339 else TexOutput("</FONT>");
1346 // Netscape extension
1347 TexOutput("<FONT SIZE=3>");
1349 else TexOutput("</FONT>");
1356 // Netscape extension
1357 TexOutput("<FONT SIZE=4>");
1359 else TexOutput("</FONT>");
1366 // Netscape extension
1367 TexOutput("<FONT SIZE=5>");
1369 else TexOutput("</FONT>");
1376 // Netscape extension
1377 TexOutput("<FONT SIZE=6>");
1379 else TexOutput("</FONT>");
1390 else TexOutput("</B>");
1401 else TexOutput("</I>");
1411 else TexOutput("</EM>");
1420 else TexOutput("</UL>");
1431 else TexOutput("</TT>");
1437 TexOutput("©", TRUE
);
1443 TexOutput("®", TRUE
);
1449 if (start
) TexOutput("<--");
1454 if (start
) TexOutput("<==");
1459 if (start
) TexOutput("-->");
1464 if (start
) TexOutput("==>");
1467 case ltLEFTRIGHTARROW
:
1469 if (start
) TexOutput("<-->");
1472 case ltLEFTRIGHTARROW2
:
1474 if (start
) TexOutput("<==>");
1487 wxNode
*node
= itemizeStack
.First();
1490 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->Data();
1491 struc
->currentItem
+= 1;
1492 if (struc
->listType
== LATEX_DESCRIPTION
)
1494 if (descriptionItemArg
)
1497 TraverseChildrenFromChunk(descriptionItemArg
);
1499 descriptionItemArg
= NULL
;
1511 if (start
&& DocumentTitle
&& DocumentAuthor
)
1513 // Add a special label for the contents page.
1514 // TexOutput("<CENTER>\n");
1515 TexOutput("<A NAME=\"contents\">");
1516 TexOutput("<H2 ALIGN=CENTER>\n");
1517 TraverseChildrenFromChunk(DocumentTitle
);
1520 TexOutput("</A>\n");
1521 TexOutput("<P>\n\n");
1522 TexOutput("<H3 ALIGN=CENTER>");
1523 TraverseChildrenFromChunk(DocumentAuthor
);
1524 TexOutput("</H3><P>\n\n");
1527 TexOutput("<H3 ALIGN=CENTER>");
1528 TraverseChildrenFromChunk(DocumentDate
);
1529 TexOutput("</H3><P>\n\n");
1531 // TexOutput("\n</CENTER>\n");
1532 TexOutput("\n<P><HR><P>\n");
1535 // Now do optional frame contents page
1536 if (htmlFrameContents && FrameContents)
1538 SetCurrentOutput(FrameContents);
1540 // Add a special label for the contents page.
1541 TexOutput("<CENTER>\n");
1542 TexOutput("<H3>\n");
1543 TraverseChildrenFromChunk(DocumentTitle);
1546 TexOutput("</A>\n");
1547 TexOutput("<P>\n\n");
1549 TraverseChildrenFromChunk(DocumentAuthor);
1550 TexOutput("</H3><P>\n\n");
1554 TraverseChildrenFromChunk(DocumentDate);
1555 TexOutput("</H4><P>\n\n");
1557 TexOutput("\n</CENTER>\n");
1558 TexOutput("<P><HR><P>\n");
1560 SetCurrentOutput(Titlepage);
1573 helpRefFilename
= NULL
;
1578 case ltBIBLIOGRAPHY
:
1582 DefaultOnMacro(macroId
, no_args
, start
);
1586 DefaultOnMacro(macroId
, no_args
, start
);
1587 TexOutput("</DL>\n");
1595 TexOutput("<HR>\n");
1603 TexOutput("<HR>\n");
1607 case ltTABLEOFCONTENTS
:
1611 FILE *fd
= fopen(ContentsName
, "r");
1617 putc(ch
, Titlepage
);
1624 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
1625 OnInform("Run Tex2RTF again to include contents page.");
1646 TexOutput("<BLOCKQUOTE>");
1648 TexOutput("</BLOCKQUOTE>");
1657 TexOutput("\n<CAPTION>");
1665 if (DocumentStyle
!= LATEX_ARTICLE
)
1666 sprintf(figBuf
, "%s %d.%d: ", FigureNameString
, chapterNo
, figureNo
);
1668 sprintf(figBuf
, "%s %d: ", FigureNameString
, figureNo
);
1674 if (DocumentStyle
!= LATEX_ARTICLE
)
1675 sprintf(figBuf
, "%s %d.%d: ", TableNameString
, chapterNo
, tableNo
);
1677 sprintf(figBuf
, "%s %d: ", TableNameString
, tableNo
);
1685 TexOutput("\n</CAPTION>\n");
1687 char *topicName
= FindTopicName(GetNextChunk());
1689 int n
= inFigure
? figureNo
: tableNo
;
1691 AddTexRef(topicName
, NULL
, NULL
,
1692 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1693 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1699 if (start
) TexOutput("ß");
1704 if (start
) inFigure
= TRUE
;
1705 else inFigure
= FALSE
;
1710 if (start
) inTable
= TRUE
;
1711 else inTable
= FALSE
;
1715 DefaultOnMacro(macroId
, no_args
, start
);
1720 // Called on start/end of argument examination
1721 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1727 case ltCHAPTERHEADING
:
1730 case ltSECTIONHEADING
:
1732 case ltSUBSECTIONSTAR
:
1733 case ltSUBSUBSECTION
:
1734 case ltSUBSUBSECTIONSTAR
:
1736 case ltMEMBERSECTION
:
1737 case ltFUNCTIONSECTION
:
1739 if (!start
&& (arg_no
== 1))
1740 currentSection
= GetArgChunk();
1746 if (start
&& (arg_no
== 1))
1749 if (!start
&& (arg_no
== 1))
1752 if (start
&& (arg_no
== 2))
1754 if (!suppressNameDecoration
) TexOutput("<B>");
1755 currentMember
= GetArgChunk();
1757 if (!start
&& (arg_no
== 2))
1759 if (!suppressNameDecoration
) TexOutput("</B>");
1762 if (start
&& (arg_no
== 3))
1764 if (!start
&& (arg_no
== 3))
1770 if (start
&& (arg_no
== 1))
1772 if (!start
&& (arg_no
== 1))
1775 if (start
&& (arg_no
== 2))
1777 if (!suppressNameDecoration
) TexOutput("( ");
1778 currentMember
= GetArgChunk();
1780 if (!start
&& (arg_no
== 2))
1784 if (!start
&& (arg_no
== 3))
1790 if (!start
&& (arg_no
== 1))
1793 if (start
&& (arg_no
== 2))
1795 if (!start
&& (arg_no
== 2))
1798 if (start
&& (arg_no
== 2))
1799 currentMember
= GetArgChunk();
1801 if (start
&& (arg_no
== 3))
1803 if (!start
&& (arg_no
== 3))
1809 if (start
&& (arg_no
== 1))
1811 if (!start
&& (arg_no
== 1))
1813 if (start
&& (arg_no
== 2))
1817 if (!start
&& (arg_no
== 2))
1825 if (start
&& (arg_no
== 1))
1827 if (!start
&& (arg_no
== 1))
1828 TexOutput("</B> "); // This is the difference from param - one space!
1829 if (start
&& (arg_no
== 2))
1833 if (!start
&& (arg_no
== 2))
1841 if (!start
&& (arg_no
== 1))
1844 if (start
&& (arg_no
== 2))
1845 currentMember
= GetArgChunk();
1854 char *refName
= GetArgData();
1857 TexRef
*texRef
= FindReference(refName
);
1860 sec
= texRef
->sectionNumber
;
1873 if (IsArgOptional())
1875 else if ((GetNoArgs() - arg_no
) == 1)
1878 helpRefText
= GetArgChunk();
1881 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1885 TexChunk
*ref
= GetArgChunk();
1886 TexOutput("<A HREF=\"");
1888 TraverseChildrenFromChunk(ref
);
1892 TraverseChildrenFromChunk(helpRefText
);
1903 if (IsArgOptional())
1906 helpRefFilename
= GetArgChunk();
1909 if ((GetNoArgs() - arg_no
) == 1)
1912 helpRefText
= GetArgChunk();
1915 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
1919 char *refName
= GetArgData();
1920 char *refFilename
= NULL
;
1924 TexRef
*texRef
= FindReference(refName
);
1927 if (texRef
->refFile
&& strcmp(texRef
->refFile
, "??") != 0)
1928 refFilename
= texRef
->refFile
;
1930 TexOutput("<A HREF=\"");
1931 // If a filename is supplied, use it, otherwise try to
1932 // use the filename associated with the reference (from this document).
1933 if (helpRefFilename
)
1935 TraverseChildrenFromChunk(helpRefFilename
);
1938 else if (refFilename
)
1940 TexOutput(ConvertCase(refFilename
));
1946 TraverseChildrenFromChunk(helpRefText
);
1952 TraverseChildrenFromChunk(helpRefText
);
1954 TexOutput(" (REF NOT FOUND)");
1956 errBuf
.Printf("Warning: unresolved reference '%s'", refName
);
1957 OnInform((char *)errBuf
.c_str());
1960 else TexOutput("??");
1975 char *alignment
= "";
1976 if (macroId
== ltIMAGEL
)
1977 alignment
= " align=left";
1978 else if (macroId
== ltIMAGER
)
1979 alignment
= " align=right";
1981 // Try to find an XBM or GIF image first.
1982 char *filename
= copystring(GetArgData());
1985 strcpy(buf
, filename
);
1986 StripExtension(buf
);
1987 strcat(buf
, ".xbm");
1988 wxString f
= TexPathList
.FindValidPath(buf
);
1990 if (f
== "") // Try for a GIF instead
1992 strcpy(buf
, filename
);
1993 StripExtension(buf
);
1994 strcat(buf
, ".gif");
1995 f
= TexPathList
.FindValidPath(buf
);
1998 if (f
== "") // Try for a JPEG instead
2000 strcpy(buf
, filename
);
2001 StripExtension(buf
);
2002 strcat(buf
, ".jpg");
2003 f
= TexPathList
.FindValidPath(buf
);
2006 if (f
== "") // Try for a PNG instead
2008 strcpy(buf
, filename
);
2009 StripExtension(buf
);
2010 strcat(buf
, ".png");
2011 f
= TexPathList
.FindValidPath(buf
);
2016 char *inlineFilename
= copystring(f
);
2018 char *originalFilename
= TexPathList
.FindValidPath(filename
);
2019 // If we have found the existing filename, make the inline
2020 // image point to the original file (could be PS, for example)
2021 if (originalFilename
&& (strcmp(inlineFilename
, originalFilename
) != 0))
2023 TexOutput("<A HREF=\"");
2024 TexOutput(ConvertCase(originalFilename
));
2026 TexOutput("<img src=\"");
2027 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2028 TexOutput("\""); TexOutput(alignment
); TexOutput("></A>");
2033 TexOutput("<img src=\"");
2034 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2035 TexOutput("\""); TexOutput(alignment
); TexOutput(">");
2036 delete[] inlineFilename
;
2041 // Last resort - a link to a PS file.
2042 TexOutput("<A HREF=\"");
2043 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2044 TexOutput("\">Picture</A>\n");
2045 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2053 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2056 static char *imageFile
= NULL
;
2057 if (start
&& (arg_no
== 2))
2059 // Try to find an XBM or GIF image first.
2060 char *filename
= copystring(GetArgData());
2063 strcpy(buf
, filename
);
2064 StripExtension(buf
);
2065 strcat(buf
, ".xbm");
2066 wxString f
= TexPathList
.FindValidPath(buf
);
2068 if (f
== "") // Try for a GIF instead
2070 strcpy(buf
, filename
);
2071 StripExtension(buf
);
2072 strcat(buf
, ".gif");
2073 f
= TexPathList
.FindValidPath(buf
);
2078 sprintf(buf
, "Warning: could not find an inline XBM/GIF for %s.", filename
);
2087 imageFile
= copystring(f
);
2090 else if (start
&& (arg_no
== 3))
2094 // First, try to find a .shg (segmented hypergraphics file)
2095 // that we can convert to a map file
2097 strcpy(buf
, imageFile
);
2098 StripExtension(buf
);
2099 strcat(buf
, ".shg");
2100 wxString f
= TexPathList
.FindValidPath(buf
);
2104 // The default HTML file to go to is THIS file (so a no-op)
2105 SHGToMap((char*) (const char*) f
, currentFileName
);
2108 char *mapName
= GetArgData();
2109 TexOutput("<A HREF=\"/cgi-bin/imagemap/");
2113 TexOutput("unknown");
2115 TexOutput("<img src=\"");
2116 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2117 TexOutput("\" ISMAP></A><P>");
2138 descriptionItemArg
= GetArgChunk();
2144 case ltTWOCOLITEMRULED
:
2147 if (start && (arg_no == 1))
2148 TexOutput("\n<DT> ");
2149 if (start && (arg_no == 2))
2156 if (TwoColWidthA
> -1) {
2158 sprintf(buf
,"\n<TR><TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthA
);
2161 TexOutput("\n<TR><TD VALIGN=TOP>\n");
2164 TexOutput("\n</FONT></TD>\n");
2170 if (TwoColWidthB
> -1) {
2172 sprintf(buf
,"\n<TD VALIGN=TOP WIDTH=%d>\n",TwoColWidthB
);
2175 TexOutput("\n<TD VALIGN=TOP>\n");
2178 TexOutput("\n</FONT></TD></TR>\n");
2183 case ltNUMBEREDBIBITEM
:
2185 if (arg_no
== 1 && start
)
2187 TexOutput("\n<DT> ");
2189 if (arg_no
== 2 && !start
)
2196 if (arg_no
== 1 && start
)
2198 char *citeKey
= GetArgData();
2199 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2202 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2203 sprintf(buf
, "[%d]", citeCount
);
2204 ref
->sectionNumber
= copystring(buf
);
2207 sprintf(buf
, "\n<DT> [%d] ", citeCount
);
2212 if (arg_no
== 2 && !start
)
2218 case ltMARGINPARODD
:
2219 case ltMARGINPAREVEN
:
2225 TexOutput("<HR>\n");
2229 TexOutput("<HR><P>\n");
2233 case ltTWOCOLWIDTHA
:
2237 char *val
= GetArgData();
2238 float points
= ParseUnitArgument(val
);
2239 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2245 case ltTWOCOLWIDTHB
:
2249 char *val
= GetArgData();
2250 float points
= ParseUnitArgument(val
);
2251 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2260 case ltACCENT_GRAVE
:
2264 char *val
= GetArgData();
2270 TexOutput("à");
2273 TexOutput("è");
2276 TexOutput("ì");
2279 TexOutput("ò");
2282 TexOutput("ù");
2285 TexOutput("À");
2288 TexOutput("È");
2291 TexOutput("Ì");
2294 TexOutput("Ò");
2297 TexOutput("Ì");
2307 case ltACCENT_ACUTE
:
2311 char *val
= GetArgData();
2317 TexOutput("á");
2320 TexOutput("é");
2323 TexOutput("í");
2326 TexOutput("ó");
2329 TexOutput("ú");
2332 TexOutput("ý");
2335 TexOutput("Á");
2338 TexOutput("É");
2341 TexOutput("Í");
2344 TexOutput("Ó");
2347 TexOutput("Ú");
2350 TexOutput("Ý");
2360 case ltACCENT_CARET
:
2364 char *val
= GetArgData();
2370 TexOutput("â");
2373 TexOutput("ê");
2376 TexOutput("î");
2379 TexOutput("ô");
2382 TexOutput("û");
2385 TexOutput("Â");
2388 TexOutput("Ê");
2391 TexOutput("Î");
2394 TexOutput("Ô");
2397 TexOutput("Î");
2407 case ltACCENT_TILDE
:
2411 char *val
= GetArgData();
2420 TexOutput("ã");
2423 TexOutput("ñ");
2426 TexOutput("õ");
2429 TexOutput("Ã");
2432 TexOutput("Ñ");
2435 TexOutput("Õ");
2445 case ltACCENT_UMLAUT
:
2449 char *val
= GetArgData();
2455 TexOutput("ä");
2458 TexOutput("ë");
2461 TexOutput("ï");
2464 TexOutput("ö");
2467 TexOutput("ü");
2470 TexOutput("ÿ");
2473 TexOutput("Ä");
2476 TexOutput("Ë");
2479 TexOutput("Ï");
2482 TexOutput("Ö");
2485 TexOutput("Ü");
2488 TexOutput("Ÿ");
2502 char *val
= GetArgData();
2508 TexOutput("å");
2511 TexOutput("Å");
2525 char *val
= GetArgData();
2528 bool isPicture
= FALSE
;
2529 ParseColourString(val
, &isPicture
);
2532 if (backgroundImageString
)
2533 delete[] backgroundImageString
;
2534 backgroundImageString
= copystring(val
);
2538 if (backgroundColourString
)
2539 delete[] backgroundColourString
;
2540 backgroundColourString
= copystring(val
);
2547 case ltBACKGROUNDIMAGE
:
2551 char *val
= GetArgData();
2554 if (backgroundImageString
)
2555 delete[] backgroundImageString
;
2556 backgroundImageString
= copystring(val
);
2562 case ltBACKGROUNDCOLOUR
:
2566 char *val
= GetArgData();
2569 if (backgroundColourString
)
2570 delete[] backgroundColourString
;
2571 backgroundColourString
= copystring(val
);
2581 char *val
= GetArgData();
2584 if (textColourString
)
2585 delete[] textColourString
;
2586 textColourString
= copystring(val
);
2596 char *val
= GetArgData();
2599 if (linkColourString
)
2600 delete[] linkColourString
;
2601 linkColourString
= copystring(val
);
2607 case ltFOLLOWEDLINKCOLOUR
:
2611 char *val
= GetArgData();
2614 if (followedLinkColourString
)
2615 delete[] followedLinkColourString
;
2616 followedLinkColourString
= copystring(val
);
2622 case ltACCENT_CADILLA
:
2626 char *val
= GetArgData();
2632 TexOutput("ç");
2635 TexOutput("Ç");
2647 case ltFOOTNOTEPOPUP:
2657 case ltSUPERTABULAR
:
2663 currentRowNumber
= 0;
2666 tableVerticalLineLeft
= FALSE
;
2667 tableVerticalLineRight
= FALSE
;
2669 char *alignString
= copystring(GetArgData());
2670 ParseTableArgument(alignString
);
2672 TexOutput("<TABLE BORDER>\n");
2674 // Write the first row formatting for compatibility
2675 // with standard Latex
2676 if (compatibilityMode
)
2678 TexOutput("<TR>\n<TD>");
2681 for (int i = 0; i < noColumns; i++)
2683 currentWidth += TableData[i].width;
2684 sprintf(buf, "\\cellx%d", currentWidth);
2687 TexOutput("\\pard\\intbl\n");
2690 delete[] alignString
;
2695 else if (arg_no
== 2 && !start
)
2697 TexOutput("</TABLE>\n");
2702 case ltTHEBIBLIOGRAPHY
:
2704 if (start
&& (arg_no
== 1))
2706 ReopenFile(&Chapters
, &ChaptersName
);
2707 AddTexRef("bibliography", ChaptersName
, "bibliography");
2708 SetCurrentSubsectionName("bibliography", ChaptersName
);
2712 SetCurrentOutput(Chapters
);
2715 if (truncateFilenames
)
2716 sprintf(titleBuf
, "%s.htm", wxFileNameFromPath(FileRoot
));
2718 sprintf(titleBuf
, "%s_contents.html", wxFileNameFromPath(FileRoot
));
2721 TexOutput("<title>");
2722 TexOutput(ReferencesNameString
);
2723 TexOutput("</title></head>\n");
2726 fprintf(Chapters
, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString
);
2727 AddBrowseButtons("contents", titleBuf
, // Up
2728 lastTopic
, lastFileName
, // Last topic
2729 "bibliography", ChaptersName
); // This topic
2731 SetCurrentOutputs(Contents
, Chapters
);
2732 fprintf(Contents
, "\n<LI><A HREF=\"%s#%s\">", ConvertCase(ChaptersName
), "bibliography");
2734 fprintf(Contents
, "%s</A>\n", ReferencesNameString
);
2735 fprintf(Chapters
, "</H2>\n</A>\n");
2737 SetCurrentOutput(Chapters
);
2740 if (!start
&& (arg_no
== 2))
2748 /* Build up list of keywords associated with topics */
2751 // char *entry = GetArgData();
2753 OutputChunkToString(GetArgChunk(), buf
);
2756 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2771 char *name
= GetArgData();
2773 if (!FindColourHTMLString(name
, buf2
))
2775 strcpy(buf2
, "#000000");
2777 sprintf(buf
, "Could not find colour name %s", name
);
2780 TexOutput("<FONT COLOR=\"");
2796 if (arg_no
== 2) TexOutput("</FONT>");
2801 case ltINSERTATLEVEL
:
2803 // This macro allows you to insert text at a different level
2804 // from the current level, e.g. into the Sections from within a subsubsection.
2807 static int currentLevelNo
= 1;
2808 static FILE* oldLevelFile
= Chapters
;
2815 oldLevelFile
= CurrentOutput1
;
2817 char *str
= GetArgData();
2818 currentLevelNo
= atoi(str
);
2820 // TODO: cope with article style (no chapters)
2821 switch (currentLevelNo
)
2825 outputFile
= Chapters
;
2830 outputFile
= Sections
;
2835 outputFile
= Subsections
;
2840 outputFile
= Subsubsections
;
2850 CurrentOutput1
= outputFile
;
2868 CurrentOutput1
= oldLevelFile
;
2874 return DefaultOnArgument(macroId
, arg_no
, start
);
2887 tableVerticalLineLeft
= FALSE
;
2888 tableVerticalLineRight
= FALSE
;
2891 if (InputFile
&& OutputFile
)
2893 // Do some HTML-specific transformations on all the strings,
2895 Text2HTML(GetTopLevelChunk());
2898 if (truncateFilenames
)
2899 sprintf(buf
, "%s.htm", FileRoot
);
2901 sprintf(buf
, "%s_contents.html", FileRoot
);
2902 if (TitlepageName
) delete[] TitlepageName
;
2903 TitlepageName
= copystring(buf
);
2904 Titlepage
= fopen(buf
, "w");
2906 if (truncateFilenames
)
2907 sprintf(buf
, "%s_fc.htm", FileRoot
);
2909 sprintf(buf
, "%s_fcontents.html", FileRoot
);
2911 contentsFrameName
= copystring(buf
);
2913 Contents
= fopen(TmpContentsName
, "w");
2915 if (htmlFrameContents
)
2917 // FrameContents = fopen(TmpFrameContentsName, "w");
2918 FrameContents
= fopen(contentsFrameName
, "w");
2919 fprintf(FrameContents
, "<HTML>\n<UL>\n");
2922 if (!Titlepage
|| !Contents
)
2924 OnError("Cannot open output file!");
2927 AddTexRef("contents", wxFileNameFromPath(TitlepageName
), ContentsNameString
);
2929 fprintf(Contents
, "<P><P><H2>%s</H2><P><P>\n", ContentsNameString
);
2931 fprintf(Contents
, "<UL>\n");
2933 SetCurrentOutput(Titlepage
);
2934 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
2935 OnInform("Converting...");
2938 fprintf(Contents
, "</UL>\n\n");
2940 // SetCurrentOutput(Titlepage);
2945 // fprintf(Titlepage, "\n</BODY></HTML>\n");
2952 fprintf(FrameContents
, "\n</UL>\n");
2953 fprintf(FrameContents
, "</HTML>\n");
2954 fclose(FrameContents
);
2955 FrameContents
= NULL
;
2960 fprintf(Chapters
, "\n</FONT></BODY></HTML>\n");
2966 fprintf(Sections
, "\n</FONT></BODY></HTML>\n");
2970 if (Subsections
&& !combineSubSections
)
2972 fprintf(Subsections
, "\n</FONT></BODY></HTML>\n");
2973 fclose(Subsections
);
2976 if (Subsubsections
&& !combineSubSections
)
2978 fprintf(Subsubsections
, "\n</FONT></BODY></HTML>\n");
2979 fclose(Subsubsections
);
2980 Subsubsections
= NULL
;
2982 if ( SectionContentsFD
)
2984 fclose(SectionContentsFD
);
2985 SectionContentsFD
= NULL
;
2988 // Create a temporary file for the title page header, add some info,
2989 // and concat the titlepage just generated.
2990 // This is necessary in order to put the title of the document
2991 // at the TOP of the file within <HEAD>, even though we only find out
2992 // what it is later on.
2993 FILE *tmpTitle
= fopen("title.tmp", "w");
2998 SetCurrentOutput(tmpTitle
);
3000 TexOutput("\n<HEAD><TITLE>");
3001 TraverseChildrenFromChunk(DocumentTitle
);
3002 TexOutput("</TITLE></HEAD>\n");
3006 SetCurrentOutput(tmpTitle
);
3007 HTMLHeadTo(tmpTitle
);
3009 fprintf(tmpTitle
, "<TITLE>%s</TITLE></HEAD>\n\n", contentsString
);
3011 fprintf(tmpTitle
, "<TITLE>%s</TITLE></HEAD>\n\n", wxFileNameFromPath(FileRoot
));
3014 // Output frame information
3015 if (htmlFrameContents
)
3017 char firstFileName
[300];
3018 if (truncateFilenames
)
3019 sprintf(firstFileName
, "%s1.htm", FileRoot
);
3021 sprintf(firstFileName
, "%s1.html", FileRoot
);
3023 fprintf(tmpTitle
, "<FRAMESET COLS=\"30%%,70%%\">\n");
3025 fprintf(tmpTitle
, "<FRAME SRC=\"%s\">\n", ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3026 fprintf(tmpTitle
, "<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n", ConvertCase(wxFileNameFromPath(firstFileName
)));
3027 fprintf(tmpTitle
, "</FRAMESET>\n");
3029 fprintf(tmpTitle
, "<NOFRAMES>\n");
3032 // Output <BODY...> to temporary title page
3036 FILE *fd
= fopen(TitlepageName
, "r");
3048 fprintf(tmpTitle
, "\n</FONT></BODY>\n");
3050 if (htmlFrameContents
)
3052 fprintf(tmpTitle
, "\n</NOFRAMES>\n");
3054 fprintf(tmpTitle
, "\n</HTML>\n");
3057 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3058 if (!wxRenameFile("title.tmp", TitlepageName
))
3060 wxCopyFile("title.tmp", TitlepageName
);
3061 wxRemoveFile("title.tmp");
3065 if (lastFileName
) delete[] lastFileName
;
3066 lastFileName
= NULL
;
3067 if (lastTopic
) delete[] lastTopic
;
3070 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3072 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3074 wxCopyFile(TmpContentsName
, ContentsName
);
3075 wxRemoveFile(TmpContentsName
);
3078 // Generate .htx file if requested
3081 char htmlIndexName
[300];
3082 sprintf(htmlIndexName
, "%s.htx", FileRoot
);
3083 GenerateHTMLIndexFile(htmlIndexName
);
3086 // Generate HTML Help Workshop files if requested
3087 if (htmlWorkshopFiles
)
3089 HTMLWorkshopEndContents();
3090 GenerateHTMLWorkshopFiles(FileRoot
);
3100 // Output .htx index file
3101 void GenerateHTMLIndexFile(char *fname
)
3103 FILE *fd
= fopen(fname
, "w");
3107 TopicTable
.BeginFind();
3108 wxNode
*node
= NULL
;
3109 while ((node
= TopicTable
.Next()))
3111 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3112 const char *topicName
= node
->GetKeyString();
3113 if (texTopic
->filename
&& texTopic
->keywords
)
3115 wxNode
*node1
= texTopic
->keywords
->First();
3118 char *s
= (char *)node1
->Data();
3119 fprintf(fd
, "%s|%s|%s\n", topicName
, texTopic
->filename
, s
);
3120 node1
= node1
->Next();
3133 // output .hpp, .hhc and .hhk files:
3136 void GenerateHTMLWorkshopFiles(char *fname
)
3141 /* Generate project file : */
3143 sprintf(buf
, "%s.hhp", fname
);
3144 f
= fopen(buf
, "wt");
3147 "Compatibility=1.1\n"
3148 "Full-text search=Yes\n"
3149 "Contents file=%s.hhc\n"
3150 "Compiled file=%s.chm\n"
3151 "Default Window=%sHelp\n"
3152 "Default topic=%s\n"
3153 "Index file=%s.hhk\n"
3155 wxFileNameFromPath(fname
),
3156 wxFileNameFromPath(fname
),
3157 wxFileNameFromPath(fname
),
3158 wxFileNameFromPath(TitlepageName
),
3159 wxFileNameFromPath(fname
)
3162 if (DocumentTitle
) {
3163 SetCurrentOutput(f
);
3164 TraverseChildrenFromChunk(DocumentTitle
);
3166 else fprintf(f
, "(unknown)");
3168 fprintf(f
, "\n\n[WINDOWS]\n"
3169 "%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,",
3170 wxFileNameFromPath(fname
),
3171 wxFileNameFromPath(fname
),
3172 wxFileNameFromPath(fname
),
3173 wxFileNameFromPath(TitlepageName
));
3176 fprintf(f
, "\n\n[FILES]\n");
3177 fprintf(f
, "%s\n", wxFileNameFromPath(TitlepageName
));
3178 for (int i
= 1; i
<= fileId
; i
++) {
3179 if (truncateFilenames
)
3180 sprintf(buf
, "%s%d.htm", wxFileNameFromPath(FileRoot
), i
);
3182 sprintf(buf
, "%s%d.html", wxFileNameFromPath(FileRoot
), i
);
3183 fprintf(f
, "%s\n", buf
);
3187 /* Generate index file : */
3189 sprintf(buf
, "%s.hhk", fname
);
3190 f
= fopen(buf
, "wt");
3193 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3198 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3199 "<!-- Sitemap 1.0 -->\n"
3201 "<OBJECT type=\"text/site properties\">\n"
3202 " <param name=\"ImageType\" value=\"Folder\">\n"
3206 TopicTable
.BeginFind();
3207 wxNode
*node
= NULL
;
3208 while ((node
= TopicTable
.Next()))
3210 TexTopic
*texTopic
= (TexTopic
*)node
->Data();
3211 const char *topicName
= node
->GetKeyString();
3212 if (texTopic
->filename
&& texTopic
->keywords
)
3214 wxNode
*node1
= texTopic
->keywords
->First();
3217 char *s
= (char *)node1
->Data();
3219 " <LI> <OBJECT type=\"text/sitemap\">\n"
3220 " <param name=\"Local\" value=\"%s#%s\">\n"
3221 " <param name=\"Name\" value=\"%s\">\n"
3223 texTopic
->filename
, topicName
, s
);
3224 node1
= node1
->Next();
3229 fprintf(f
, "</UL>\n");
3235 static FILE *HTMLWorkshopContents
= NULL
;
3236 static int HTMLWorkshopLastLevel
= 0;
3238 void HTMLWorkshopAddToContents(int level
, char *s
, char *file
)
3242 if (level
> HTMLWorkshopLastLevel
)
3243 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3244 fprintf(HTMLWorkshopContents
, "<UL>");
3245 if (level
< HTMLWorkshopLastLevel
)
3246 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3247 fprintf(HTMLWorkshopContents
, "</UL>");
3249 SetCurrentOutput(HTMLWorkshopContents
);
3250 fprintf(HTMLWorkshopContents
,
3251 " <LI> <OBJECT type=\"text/sitemap\">\n"
3252 " <param name=\"Local\" value=\"%s#%s\">\n"
3253 " <param name=\"Name\" value=\"",
3255 OutputCurrentSection();
3256 fprintf(HTMLWorkshopContents
,
3259 HTMLWorkshopLastLevel
= level
;
3263 void HTMLWorkshopStartContents()
3266 sprintf(buf
, "%s.hhc", FileRoot
);
3267 HTMLWorkshopContents
= fopen(buf
, "wt");
3268 HTMLWorkshopLastLevel
= 0;
3270 fprintf(HTMLWorkshopContents
,
3271 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
3273 HTMLHeadTo(HTMLWorkshopContents
);
3274 fprintf(HTMLWorkshopContents
,
3276 "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n"
3277 "<!-- Sitemap 1.0 -->\n"
3279 "<OBJECT type=\"text/site properties\">\n"
3280 " <param name=\"ImageType\" value=\"Folder\">\n"
3283 "<LI> <OBJECT type=\"text/sitemap\">\n"
3284 "<param name=\"Local\" value=\"%s\">\n"
3285 "<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n",
3286 wxFileNameFromPath(TitlepageName
)
3292 void HTMLWorkshopEndContents()
3294 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3295 fprintf(HTMLWorkshopContents
, "</UL>\n");
3296 fclose(HTMLWorkshopContents
);