1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to HTML
4 // Author: Julian Smart
5 // Modified by: Wlodzimierz ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
23 #include "wx/arrstr.h"
29 #define HTML_FILENAME_PATTERN _T("%s_%s.html")
31 #if !WXWIN_COMPATIBILITY_2_4
32 static inline wxChar
* copystring(const wxChar
* s
)
33 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
36 extern wxHashTable TexReferences
;
38 extern int passNumber
;
40 extern void DecToHex(int, wxChar
*);
41 void GenerateHTMLIndexFile(wxChar
*fname
);
43 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
);
45 void GenerateHTMLWorkshopFiles(wxChar
*fname
);
46 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
);
47 void HTMLWorkshopStartContents();
48 void HTMLWorkshopEndContents();
50 void OutputContentsFrame(void);
52 #include "readshg.h" // Segmented hypergraphics parsing
54 wxChar
*ChaptersName
= NULL
;
55 wxChar
*SectionsName
= NULL
;
56 wxChar
*SubsectionsName
= NULL
;
57 wxChar
*SubsubsectionsName
= NULL
;
58 wxChar
*TitlepageName
= NULL
;
59 wxChar
*lastFileName
= NULL
;
60 wxChar
*lastTopic
= NULL
;
61 wxChar
*currentFileName
= NULL
;
62 wxChar
*contentsFrameName
= NULL
;
64 static TexChunk
*descriptionItemArg
= NULL
;
65 static TexChunk
*helpRefFilename
= NULL
;
66 static TexChunk
*helpRefText
= NULL
;
67 static int indentLevel
= 0;
68 static int citeCount
= 1;
69 extern FILE *Contents
;
70 FILE *FrameContents
= NULL
;
71 FILE *Titlepage
= NULL
;
72 // FILE *FrameTitlepage = NULL;
74 bool subsectionStarted
= false;
76 // Which column of a row are we in? (Assumes no nested tables, of course)
77 int currentColumn
= 0;
79 // Are we in verbatim mode? If so, format differently.
80 static bool inVerbatim
= false;
82 // Need to know whether we're in a table or figure for benefit
83 // of listoffigures/listoftables
84 static bool inFigure
= false;
85 static bool inTable
= false;
87 // This is defined in the Tex2Any library.
88 extern wxChar
*BigBuffer
;
90 // DHS Two-column table dimensions.
91 static int TwoColWidthA
= -1;
92 static int TwoColWidthB
= -1;
95 class HyperReference
: public wxObject
100 HyperReference(wxChar
*name
, wxChar
*file
)
102 if (name
) refName
= copystring(name
);
103 if (file
) refFile
= copystring(file
);
107 class TexNextPage
: public wxObject
112 TexNextPage(wxChar
*theLabel
, wxChar
*theFile
)
114 label
= copystring(theLabel
);
115 filename
= copystring(theFile
);
124 wxHashTable
TexNextPages(wxKEY_STRING
);
126 static wxChar
*CurrentChapterName
= NULL
;
127 static wxChar
*CurrentChapterFile
= NULL
;
128 static wxChar
*CurrentSectionName
= NULL
;
129 static wxChar
*CurrentSectionFile
= NULL
;
130 static wxChar
*CurrentSubsectionName
= NULL
;
131 static wxChar
*CurrentSubsectionFile
= NULL
;
132 static wxChar
*CurrentSubsubsectionName
= NULL
;
133 static wxChar
*CurrentSubsubsectionFile
= NULL
;
134 static wxChar
*CurrentTopic
= NULL
;
136 static void SetCurrentTopic(wxChar
*s
)
138 if (CurrentTopic
) delete[] CurrentTopic
;
139 CurrentTopic
= copystring(s
);
142 void SetCurrentChapterName(wxChar
*s
, wxChar
*file
)
144 if (CurrentChapterName
) delete[] CurrentChapterName
;
145 CurrentChapterName
= copystring(s
);
146 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
147 CurrentChapterFile
= copystring(file
);
149 currentFileName
= CurrentChapterFile
;
153 void SetCurrentSectionName(wxChar
*s
, wxChar
*file
)
155 if (CurrentSectionName
) delete[] CurrentSectionName
;
156 CurrentSectionName
= copystring(s
);
157 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
158 CurrentSectionFile
= copystring(file
);
160 currentFileName
= CurrentSectionFile
;
163 void SetCurrentSubsectionName(wxChar
*s
, wxChar
*file
)
165 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
166 CurrentSubsectionName
= copystring(s
);
167 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
168 CurrentSubsectionFile
= copystring(file
);
169 currentFileName
= CurrentSubsectionFile
;
172 void SetCurrentSubsubsectionName(wxChar
*s
, wxChar
*file
)
174 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
175 CurrentSubsubsectionName
= copystring(s
);
176 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
177 CurrentSubsubsectionFile
= copystring(file
);
178 currentFileName
= CurrentSubsubsectionFile
;
183 // mapping between fileId and filenames if truncateFilenames=false:
184 static wxArrayString gs_filenames
;
188 * Close former filedescriptor and reopen using another filename.
192 void ReopenFile(FILE **fd
, wxChar
**fileName
, const wxChar
*label
)
196 wxFprintf(*fd
, _T("\n</FONT></BODY></HTML>\n"));
201 if (truncateFilenames
)
203 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), FileRoot
, fileId
);
208 gs_filenames
.Add(wxEmptyString
);
209 wxSnprintf(buf
, sizeof(buf
), HTML_FILENAME_PATTERN
, FileRoot
, label
);
210 gs_filenames
.Add(buf
);
212 if (*fileName
) delete[] *fileName
;
213 *fileName
= copystring(wxFileNameFromPath(buf
));
214 *fd
= wxFopen(buf
, _T("w"));
215 wxFprintf(*fd
, _T("<HTML>\n"));
219 * Reopen section contents file, i.e. the index appended to each section
220 * in subsectionCombine mode
223 static wxChar
*SectionContentsFilename
= NULL
;
224 static FILE *SectionContentsFD
= NULL
;
226 void ReopenSectionContentsFile(void)
228 if ( SectionContentsFD
)
230 fclose(SectionContentsFD
);
232 if ( SectionContentsFilename
)
233 delete[] SectionContentsFilename
;
234 SectionContentsFD
= NULL
;
235 SectionContentsFilename
= NULL
;
237 // Create the name from the current section filename
238 if ( CurrentSectionFile
)
241 wxStrcpy(buf
, CurrentSectionFile
);
242 wxStripExtension(buf
);
243 wxStrcat(buf
, _T(".con"));
244 SectionContentsFilename
= copystring(buf
);
246 SectionContentsFD
= wxFopen(SectionContentsFilename
, _T("w"));
252 * Given a TexChunk with a string value, scans through the string
253 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
257 void ProcessText2HTML(TexChunk
*chunk
)
259 bool changed
= false;
263 int len
= wxStrlen(chunk
->value
);
266 ch
= chunk
->value
[i
];
268 // 2 newlines means \par
269 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
270 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
271 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
273 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("<P>\n\n")); ptr
+= 5;
277 else if (!inVerbatim
&& ch
== _T('`') && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
279 BigBuffer
[ptr
] = '"'; ptr
++;
283 else if (!inVerbatim
&& ch
== _T('`')) // Change ` to '
285 BigBuffer
[ptr
] = 39; ptr
++;
289 else if (ch
== _T('<')) // Change < to <
292 wxStrcat(BigBuffer
, _T("<"));
297 else if (ch
== _T('>')) // Change > to >
300 wxStrcat(BigBuffer
, _T(">"));
317 chunk
->value
= copystring(BigBuffer
);
322 * Scan through all chunks starting from the given one,
323 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
324 * This should be called after Tex2Any has parsed the file,
325 * and before TraverseDocument is called.
329 void Text2HTML(TexChunk
*chunk
)
332 if (stopRunning
) return;
336 case CHUNK_TYPE_MACRO
:
338 TexMacroDef
*def
= chunk
->def
;
340 if (def
&& def
->ignore
)
343 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
346 wxNode
*node
= chunk
->children
.GetFirst();
349 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
350 Text2HTML(child_chunk
);
351 node
= node
->GetNext();
354 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
361 wxNode
*node
= chunk
->children
.GetFirst();
364 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
365 Text2HTML(child_chunk
);
366 node
= node
->GetNext();
371 case CHUNK_TYPE_STRING
:
374 ProcessText2HTML(chunk
);
381 * Add appropriate browse buttons to this page.
385 void AddBrowseButtons(wxChar
*upLabel
, wxChar
*upFilename
,
386 wxChar
*previousLabel
, wxChar
*previousFilename
,
387 wxChar
*thisLabel
, wxChar
*thisFilename
)
389 wxChar contentsReferenceBuf
[80];
390 wxChar upReferenceBuf
[80];
391 wxChar backReferenceBuf
[80];
392 wxChar forwardReferenceBuf
[80];
393 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
396 wxChar
*contentsReference
; // no need to initialize because always assigned below
397 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
398 contentsReference
= ContentsNameString
;
401 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
402 contentsReference
= contentsReferenceBuf
;
403 wxSnprintf(contentsReference
, sizeof(contentsReferenceBuf
),
404 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
405 ConvertCase(_T("contents.gif")));
408 wxChar
*upReference
; // no need to initialize because always assigned below
409 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
410 upReference
= UpNameString
;
413 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
414 upReference
= upReferenceBuf
;
415 wxSnprintf(upReference
, sizeof(upReferenceBuf
),
416 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
417 ConvertCase(_T("up.gif")));
420 wxChar
*backReference
; // no need to initialize because always assigned below
421 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
422 backReference
= _T("<<");
425 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
426 backReference
= backReferenceBuf
;
427 wxSnprintf(backReference
, sizeof(backReferenceBuf
),
428 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
429 ConvertCase(_T("back.gif")));
432 wxChar
*forwardReference
; // no need to initialize because always assigned below
433 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
434 forwardReference
= _T(">>");
437 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
438 forwardReference
= forwardReferenceBuf
;
439 wxSnprintf(forwardReference
, sizeof(forwardReferenceBuf
),
440 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
441 ConvertCase(_T("forward.gif")));
444 TexOutput(_T("<CENTER>"));
453 if (truncateFilenames
)
456 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
457 wxSnprintf(buf
, sizeof(buf
),
458 _T("\n<A HREF=\"%s.%s\">%s</A> "),
459 buf1
, ConvertCase(_T("htm")), contentsReference
);
464 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
465 wxSnprintf(buf
, sizeof(buf
),
466 _T("\n<A HREF=\"%s%s\">%s</A> "),
467 buf1
, ConvertCase(_T("_contents.html")), contentsReference
);
469 // TexOutput(_T("<NOFRAMES>"));
471 // TexOutput(_T("</NOFRAMES>"));
478 if (upLabel
&& upFilename
)
480 if ( (wxStrlen(upLabel
) > 0) && !PrimaryAnchorOfTheFile(upFilename
, upLabel
) )
481 wxSnprintf(buf
, sizeof(buf
),
482 _T("<A HREF=\"%s#%s\">%s</A> "),
483 ConvertCase(upFilename
), upLabel
, upReference
);
485 wxSnprintf(buf
, sizeof(buf
),
486 _T("<A HREF=\"%s\">%s</A> "),
487 ConvertCase(upFilename
), upReference
);
488 if (wxStrcmp(upLabel
, _T("contents")) == 0)
490 // TexOutput(_T("<NOFRAMES>"));
492 // TexOutput(_T("</NOFRAMES>"));
503 if (previousLabel
&& previousFilename
)
505 if (PrimaryAnchorOfTheFile(previousFilename
, previousLabel
))
506 wxSnprintf(buf
, sizeof(buf
),
507 _T("<A HREF=\"%s\">%s</A> "),
508 ConvertCase(previousFilename
), backReference
);
510 wxSnprintf(buf
, sizeof(buf
),
511 _T("<A HREF=\"%s#%s\">%s</A> "),
512 ConvertCase(previousFilename
), previousLabel
, backReference
);
513 if (wxStrcmp(previousLabel
, _T("contents")) == 0)
515 // TexOutput(_T("<NOFRAMES>"));
517 // TexOutput(_T("</NOFRAMES>"));
524 // A placeholder so the buttons don't keep moving position
525 wxSnprintf(buf
, sizeof(buf
), _T("%s "), backReference
);
529 wxChar
*nextLabel
= NULL
;
530 wxChar
*nextFilename
= NULL
;
532 // Get the next page, and record the previous page's 'next' page
534 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
537 nextLabel
= nextPage
->label
;
538 nextFilename
= nextPage
->filename
;
540 if (previousLabel
&& previousFilename
)
542 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
546 TexNextPages
.Delete(previousLabel
);
548 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
549 TexNextPages
.Put(previousLabel
, newNextPage
);
557 if (nextLabel
&& nextFilename
)
559 if (PrimaryAnchorOfTheFile(nextFilename
, nextLabel
))
560 wxSnprintf(buf
, sizeof(buf
),
561 _T("<A HREF=\"%s\">%s</A> "),
562 ConvertCase(nextFilename
), forwardReference
);
564 wxSnprintf(buf
, sizeof(buf
),
565 _T("<A HREF=\"%s#%s\">%s</A> "),
566 ConvertCase(nextFilename
), nextLabel
, forwardReference
);
571 // A placeholder so the buttons don't keep moving position
572 wxSnprintf(buf
, sizeof(buf
), _T("%s "), forwardReference
);
577 * Horizontal rule to finish it off nicely.
580 TexOutput(_T("</CENTER>"));
581 TexOutput(_T("<HR>\n"));
583 // Update last topic/filename
585 delete[] lastFileName
;
586 lastFileName
= copystring(thisFilename
);
589 lastTopic
= copystring(thisLabel
);
592 // A colour string is either 3 numbers separated by semicolons (RGB),
593 // or a reference to a GIF. Return the filename or a hex string like #934CE8
594 wxChar
*ParseColourString(wxChar
*bkStr
, bool *isPicture
)
596 static wxChar resStr
[300];
597 wxStrcpy(resStr
, bkStr
);
598 wxStringTokenizer
tok(resStr
, _T(";"), wxTOKEN_STRTOK
);
599 if (tok
.HasMoreTokens())
601 wxString token1
= tok
.GetNextToken();
602 if (!tok
.HasMoreTokens())
609 wxString token2
= tok
.GetNextToken();
611 if (tok
.HasMoreTokens())
613 wxString token3
= tok
.GetNextToken();
615 // Now convert 3 strings into decimal numbers, and then hex numbers.
616 int red
= wxAtoi(token1
.c_str());
617 int green
= wxAtoi(token2
.c_str());
618 int blue
= wxAtoi(token3
.c_str());
620 wxStrcpy(resStr
, _T("#"));
624 wxStrcat(resStr
, buf
);
625 DecToHex(green
, buf
);
626 wxStrcat(resStr
, buf
);
628 wxStrcat(resStr
, buf
);
637 void OutputFont(void)
639 // Only output <font face> if explicitly requested by htmlFaceName= directive in
640 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
644 // Output <FONT FACE=...>
645 TexOutput(_T("<FONT FACE=\""));
646 TexOutput(htmlFaceName
);
647 TexOutput(_T("\">\n"));
651 // Output start of <BODY> block
652 void OutputBodyStart(void)
654 TexOutput(_T("\n<BODY"));
655 if (backgroundImageString
)
657 bool isPicture
= false;
658 wxChar
*s
= ParseColourString(backgroundImageString
, &isPicture
);
661 TexOutput(_T(" BACKGROUND=\""));
666 if (backgroundColourString
)
668 bool isPicture
= false;
669 wxChar
*s
= ParseColourString(backgroundColourString
, &isPicture
);
672 TexOutput(_T(" BGCOLOR="));
677 // Set foreground text colour, if one is specified
678 if (textColourString
)
680 bool isPicture
= false;
681 wxChar
*s
= ParseColourString(textColourString
, &isPicture
);
684 TexOutput(_T(" TEXT=")); TexOutput(s
);
687 // Set link text colour, if one is specified
688 if (linkColourString
)
690 bool isPicture
= false;
691 wxChar
*s
= ParseColourString(linkColourString
, &isPicture
);
694 TexOutput(_T(" LINK=")); TexOutput(s
);
697 // Set followed link text colour, if one is specified
698 if (followedLinkColourString
)
700 bool isPicture
= false;
701 wxChar
*s
= ParseColourString(followedLinkColourString
, &isPicture
);
704 TexOutput(_T(" VLINK=")); TexOutput(s
);
707 TexOutput(_T(">\n"));
714 TexOutput(_T("<head>"));
715 if (htmlStylesheet
) {
716 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
717 TexOutput(htmlStylesheet
);
718 TexOutput(_T("\">"));
722 void HTMLHeadTo(FILE* f
)
725 wxFprintf(f
,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet
);
727 wxFprintf(f
,_T("<head>"));
730 // Called on start/end of macro examination
731 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
737 case ltCHAPTERHEADING
:
745 if (macroId
!= ltCHAPTERSTAR
)
748 SetCurrentOutput(NULL
);
749 startedSections
= true;
751 wxChar
*topicName
= FindTopicName(GetNextChunk());
752 ReopenFile(&Chapters
, &ChaptersName
, topicName
);
753 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
755 SetCurrentChapterName(topicName
, ChaptersName
);
756 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
758 SetCurrentOutput(Chapters
);
761 TexOutput(_T("<title>"));
762 OutputCurrentSection(); // Repeat section header
763 TexOutput(_T("</title></head>\n"));
766 wxChar titleBuf
[200];
767 if (truncateFilenames
)
768 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
770 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
772 wxFprintf(Chapters
, _T("<A NAME=\"%s\"></A>"), topicName
);
774 AddBrowseButtons(_T(""), titleBuf
, // Up
775 lastTopic
, lastFileName
, // Last topic
776 topicName
, ChaptersName
); // This topic
778 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
779 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
781 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), topicName
);
783 if (htmlFrameContents
&& FrameContents
)
785 SetCurrentOutput(FrameContents
);
786 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
787 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
));
789 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
), topicName
);
790 OutputCurrentSection();
791 wxFprintf(FrameContents
, _T("</A>\n"));
794 SetCurrentOutputs(Contents
, Chapters
);
795 wxFprintf(Chapters
, _T("\n<H2>"));
796 OutputCurrentSection();
797 wxFprintf(Contents
, _T("</A>\n"));
798 wxFprintf(Chapters
, _T("</H2>\n"));
800 SetCurrentOutput(Chapters
);
802 // Add this section title to the list of keywords
805 OutputCurrentSectionToString(wxTex2RTFBuffer
);
806 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
813 case ltSECTIONHEADING
:
820 subsectionStarted
= false;
822 if (macroId
!= ltSECTIONSTAR
)
825 SetCurrentOutput(NULL
);
826 startedSections
= true;
828 wxChar
*topicName
= FindTopicName(GetNextChunk());
829 ReopenFile(&Sections
, &SectionsName
, topicName
);
830 AddTexRef(topicName
, SectionsName
, SectionNameString
);
832 SetCurrentSectionName(topicName
, SectionsName
);
833 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
835 SetCurrentOutput(Sections
);
837 TexOutput(_T("<title>"));
838 OutputCurrentSection();
839 TexOutput(_T("</title></head>\n"));
842 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
843 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
844 lastTopic
, lastFileName
, // Last topic
845 topicName
, SectionsName
); // This topic
847 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
849 SetCurrentOutputs(jumpFrom
, Sections
);
850 if (DocumentStyle
== LATEX_ARTICLE
)
852 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
853 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName
));
855 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName
), topicName
);
859 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
860 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName
));
862 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName
), topicName
);
865 wxFprintf(Sections
, _T("\n<H2>"));
866 OutputCurrentSection();
868 if (DocumentStyle
== LATEX_ARTICLE
)
869 wxFprintf(jumpFrom
, _T("</A>\n"));
871 wxFprintf(jumpFrom
, _T("</B></A><BR>\n"));
872 wxFprintf(Sections
, _T("</H2>\n"));
874 SetCurrentOutput(Sections
);
875 // Add this section title to the list of keywords
878 OutputCurrentSectionToString(wxTex2RTFBuffer
);
879 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
885 case ltSUBSECTIONSTAR
:
886 case ltMEMBERSECTION
:
887 case ltFUNCTIONSECTION
:
893 OnError(_T("You cannot have a subsection before a section!"));
899 if (macroId
!= ltSUBSECTIONSTAR
)
902 if ( combineSubSections
&& !subsectionStarted
)
906 // Read old .con file in at this point
908 wxStrcpy(buf
, CurrentSectionFile
);
909 wxStripExtension(buf
);
910 wxStrcat(buf
, _T(".con"));
911 FILE *fd
= wxFopen(buf
, _T("r"));
917 wxPutc(ch
, Sections
);
922 wxFprintf(Sections
, _T("<P>\n"));
924 // Close old file, create a new file for the sub(sub)section contents entries
925 ReopenSectionContentsFile();
928 startedSections
= true;
929 subsectionStarted
= true;
931 wxChar
*topicName
= FindTopicName(GetNextChunk());
933 if ( !combineSubSections
)
935 SetCurrentOutput(NULL
);
936 ReopenFile(&Subsections
, &SubsectionsName
, topicName
);
937 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
938 SetCurrentSubsectionName(topicName
, SubsectionsName
);
939 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
940 SetCurrentOutput(Subsections
);
943 TexOutput(_T("<title>"));
944 OutputCurrentSection();
945 TexOutput(_T("</title></head>\n"));
948 wxFprintf(Subsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
949 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
950 lastTopic
, lastFileName
, // Last topic
951 topicName
, SubsectionsName
); // This topic
953 SetCurrentOutputs(Sections
, Subsections
);
954 if(PrimaryAnchorOfTheFile(SubsectionsName
, topicName
))
955 wxFprintf(Sections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName
));
957 wxFprintf(Sections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName
), topicName
);
959 wxFprintf(Subsections
, _T("\n<H3>"));
960 OutputCurrentSection();
961 wxFprintf(Sections
, _T("</B></A><BR>\n"));
962 wxFprintf(Subsections
, _T("</H3>\n"));
964 SetCurrentOutput(Subsections
);
968 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
969 SetCurrentSubsectionName(topicName
, SectionsName
);
971 // if ( subsectionNo != 0 )
972 wxFprintf(Sections
, _T("\n<HR>\n"));
974 // We're putting everything into the section file
975 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
976 wxFprintf(Sections
, _T("\n<H3>"));
977 OutputCurrentSection();
978 wxFprintf(Sections
, _T("</H3>\n"));
980 SetCurrentOutput(SectionContentsFD
);
981 wxFprintf(SectionContentsFD
, _T("<A HREF=\"#%s\">"), topicName
);
982 OutputCurrentSection();
983 TexOutput(_T("</A><BR>\n"));
985 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
986 SetCurrentOutput(Sections
);
988 // Add this section title to the list of keywords
991 OutputCurrentSectionToString(wxTex2RTFBuffer
);
992 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
999 case ltSUBSUBSECTION
:
1000 case ltSUBSUBSECTIONSTAR
:
1004 if (!Subsections
&& !combineSubSections
)
1006 OnError(_T("You cannot have a subsubsection before a subsection!"));
1010 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1013 startedSections
= true;
1015 wxChar
*topicName
= FindTopicName(GetNextChunk());
1017 if ( !combineSubSections
)
1019 SetCurrentOutput(NULL
);
1020 ReopenFile(&Subsubsections
, &SubsubsectionsName
, topicName
);
1021 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
1022 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
1023 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
1025 SetCurrentOutput(Subsubsections
);
1027 TexOutput(_T("<title>"));
1028 OutputCurrentSection();
1029 TexOutput(_T("</title></head>\n"));
1032 wxFprintf(Subsubsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1034 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
1035 lastTopic
, lastFileName
, // Last topic
1036 topicName
, SubsubsectionsName
); // This topic
1038 SetCurrentOutputs(Subsections
, Subsubsections
);
1039 if(PrimaryAnchorOfTheFile(SubsubsectionsName
, topicName
))
1040 wxFprintf(Subsections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName
));
1042 wxFprintf(Subsections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName
), topicName
);
1044 wxFprintf(Subsubsections
, _T("\n<H3>"));
1045 OutputCurrentSection();
1046 wxFprintf(Subsections
, _T("</B></A><BR>\n"));
1047 wxFprintf(Subsubsections
, _T("</H3>\n"));
1051 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
1052 SetCurrentSubsectionName(topicName
, SectionsName
);
1053 wxFprintf(Sections
, _T("\n<HR>\n"));
1055 // We're putting everything into the section file
1056 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1057 wxFprintf(Sections
, _T("\n<H3>"));
1058 OutputCurrentSection();
1059 wxFprintf(Sections
, _T("</H3>\n"));
1060 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1061 SetCurrentOutput(SectionContentsFD);
1062 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1063 OutputCurrentSection();
1064 TexOutput(_T("</A><BR>"));
1066 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1067 SetCurrentOutput(Sections
);
1070 // Add this section title to the list of keywords
1073 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1074 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1083 if ( !combineSubSections
)
1084 SetCurrentOutput(Subsections
);
1086 SetCurrentOutput(Sections
);
1097 if ( !combineSubSections
)
1098 SetCurrentOutput(Subsections
);
1100 SetCurrentOutput(Sections
);
1111 if ( !combineSubSections
)
1112 SetCurrentOutput(Subsections
);
1114 SetCurrentOutput(Sections
);
1125 // TexOutput(_T("<B>void</B>"));
1129 TexOutput(_T("HARDY"));
1133 TexOutput(_T("wxCLIPS"));
1137 TexOutput(_T("&"));
1139 case ltSPECIALAMPERSAND
:
1145 // End cell, start cell
1147 TexOutput(_T("</FONT></TD>"));
1149 // Start new row and cell, setting alignment for the first cell.
1150 if (currentColumn
< noColumns
)
1154 if (TableData
[currentColumn
].justification
== 'c')
1155 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=CENTER>"));
1156 else if (TableData
[currentColumn
].justification
== 'r')
1157 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=RIGHT>"));
1158 else if (TableData
[currentColumn
].absWidth
)
1160 // Convert from points * 20 into pixels.
1161 int points
= TableData
[currentColumn
].width
/ 20;
1163 // Say the display is 100 DPI (dots/pixels per inch).
1164 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1165 int pixels
= (int)(points
* 100.0 / 72.0);
1166 wxSnprintf(buf
, sizeof(buf
), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1169 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=LEFT>"));
1174 TexOutput(_T("&"));
1178 case ltBACKSLASHCHAR
:
1184 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1185 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1186 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1187 TexOutput(_T("</TR>\n"));
1190 TexOutput(_T("<BR>\n"));
1201 // Start new row and cell, setting alignment for the first cell.
1203 if (TableData
[currentColumn
].justification
== 'c')
1204 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER>"));
1205 else if (TableData
[currentColumn
].justification
== 'r')
1206 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=RIGHT>"));
1207 else if (TableData
[currentColumn
].absWidth
)
1209 // Convert from points * 20 into pixels.
1210 int points
= TableData
[currentColumn
].width
/ 20;
1212 // Say the display is 100 DPI (dots/pixels per inch).
1213 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1214 int pixels
= (int)(points
* 100.0 / 72.0);
1215 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1218 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=LEFT>"));
1225 // Start new row and cell
1226 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1230 // HTML-only: break until the end of the picture (both margins are clear).
1234 TexOutput(_T("<BR CLEAR=ALL>"));
1237 case ltRTFSP
: // Explicit space, RTF only
1239 case ltSPECIALTILDE
:
1243 #if (1) // if(inVerbatim)
1254 TexOutput(_T("<UL><UL>\n"));
1256 TexOutput(_T("</UL></UL>\n"));
1262 // case ltTWOCOLLIST:
1269 if (macroId
== ltENUMERATE
)
1270 listType
= LATEX_ENUMERATE
;
1271 else if (macroId
== ltITEMIZE
)
1272 listType
= LATEX_ITEMIZE
;
1274 listType
= LATEX_DESCRIPTION
;
1276 itemizeStack
.Insert(new ItemizeStruc(listType
));
1280 TexOutput(_T("<UL>\n"));
1282 case LATEX_ENUMERATE
:
1283 TexOutput(_T("<OL>\n"));
1285 case LATEX_DESCRIPTION
:
1287 TexOutput(_T("<DL>\n"));
1294 if (itemizeStack
.GetFirst())
1296 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
1297 switch (struc
->listType
)
1300 TexOutput(_T("</UL>\n"));
1302 case LATEX_ENUMERATE
:
1303 TexOutput(_T("</OL>\n"));
1305 case LATEX_DESCRIPTION
:
1307 TexOutput(_T("</DL>\n"));
1312 delete itemizeStack
.GetFirst();
1320 TexOutput(_T("\n<TABLE>\n"));
1322 TexOutput(_T("\n</TABLE>\n"));
1332 TexOutput(_T("<P>\n"));
1335 /* For footnotes we need to output the text at the bottom of the page and
1336 * insert a reference to it. Is it worth the trouble...
1338 case ltFOOTNOTEPOPUP:
1342 TexOutput(_T("<FN>"));
1344 else TexOutput(_T("</FN>"));
1351 TexOutput(_T("<TT>"));
1352 else TexOutput(_T("</TT>"));
1360 wxSnprintf(buf
, sizeof(buf
), _T("<PRE>\n"));
1363 else TexOutput(_T("</PRE>\n"));
1371 TexOutput(_T("<CENTER>"));
1373 else TexOutput(_T("</CENTER>"));
1381 TexOutput(_T("{\\ql "));
1383 else TexOutput(_T("}\\par\\pard\n"));
1392 TexOutput(_T("{\\qr "));
1394 else TexOutput(_T("}\\par\\pard\n"));
1402 // Netscape extension
1403 TexOutput(_T("<FONT SIZE=2>"));
1405 else TexOutput(_T("</FONT>"));
1412 // Netscape extension
1413 TexOutput(_T("<FONT SIZE=1>"));
1415 else TexOutput(_T("</FONT>"));
1422 // Netscape extension
1423 TexOutput(_T("<FONT SIZE=3>"));
1425 else TexOutput(_T("</FONT>"));
1432 // Netscape extension
1433 TexOutput(_T("<FONT SIZE=4>"));
1435 else TexOutput(_T("</FONT>"));
1442 // Netscape extension
1443 TexOutput(_T("<FONT SIZE=5>"));
1445 else TexOutput(_T("</FONT>"));
1452 // Netscape extension
1453 TexOutput(_T("<FONT SIZE=6>"));
1455 else TexOutput(_T("</FONT>"));
1464 TexOutput(_T("<B>"));
1466 else TexOutput(_T("</B>"));
1475 TexOutput(_T("<I>"));
1477 else TexOutput(_T("</I>"));
1485 TexOutput(_T("<EM>"));
1487 else TexOutput(_T("</EM>"));
1494 TexOutput(_T("<UL>"));
1496 else TexOutput(_T("</UL>"));
1505 TexOutput(_T("<TT>"));
1507 else TexOutput(_T("</TT>"));
1513 TexOutput(_T("©"), true);
1519 TexOutput(_T("®"), true);
1525 if (start
) TexOutput(_T("<--"));
1530 if (start
) TexOutput(_T("<=="));
1535 if (start
) TexOutput(_T("-->"));
1540 if (start
) TexOutput(_T("==>"));
1543 case ltLEFTRIGHTARROW
:
1545 if (start
) TexOutput(_T("<-->"));
1548 case ltLEFTRIGHTARROW2
:
1550 if (start
) TexOutput(_T("<==>"));
1563 wxNode
*node
= itemizeStack
.GetFirst();
1566 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
1567 struc
->currentItem
+= 1;
1568 if (struc
->listType
== LATEX_DESCRIPTION
)
1570 if (descriptionItemArg
)
1572 TexOutput(_T("<DT> "));
1573 TraverseChildrenFromChunk(descriptionItemArg
);
1574 TexOutput(_T("\n"));
1575 descriptionItemArg
= NULL
;
1577 TexOutput(_T("<DD>"));
1580 TexOutput(_T("<LI>"));
1587 if (start
&& DocumentTitle
&& DocumentAuthor
)
1589 // Add a special label for the contents page.
1590 // TexOutput(_T("<CENTER>\n"));
1591 TexOutput(_T("<A NAME=\"contents\">"));
1592 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1593 TraverseChildrenFromChunk(DocumentTitle
);
1594 TexOutput(_T("</H2>"));
1595 TexOutput(_T("<P>"));
1596 TexOutput(_T("</A>\n"));
1597 TexOutput(_T("<P>\n\n"));
1598 TexOutput(_T("<H3 ALIGN=CENTER>"));
1599 TraverseChildrenFromChunk(DocumentAuthor
);
1600 TexOutput(_T("</H3><P>\n\n"));
1603 TexOutput(_T("<H3 ALIGN=CENTER>"));
1604 TraverseChildrenFromChunk(DocumentDate
);
1605 TexOutput(_T("</H3><P>\n\n"));
1607 // TexOutput(_T("\n</CENTER>\n"));
1608 TexOutput(_T("\n<P><HR><P>\n"));
1611 // Now do optional frame contents page
1612 if (htmlFrameContents && FrameContents)
1614 SetCurrentOutput(FrameContents);
1616 // Add a special label for the contents page.
1617 TexOutput(_T("<CENTER>\n"));
1618 TexOutput(_T("<H3>\n"));
1619 TraverseChildrenFromChunk(DocumentTitle);
1620 TexOutput(_T("</H3>"));
1621 TexOutput(_T("<P>"));
1622 TexOutput(_T("</A>\n"));
1623 TexOutput(_T("<P>\n\n"));
1624 TexOutput(_T("<H3>"));
1625 TraverseChildrenFromChunk(DocumentAuthor);
1626 TexOutput(_T("</H3><P>\n\n"));
1629 TexOutput(_T("<H4>"));
1630 TraverseChildrenFromChunk(DocumentDate);
1631 TexOutput(_T("</H4><P>\n\n"));
1633 TexOutput(_T("\n</CENTER>\n"));
1634 TexOutput(_T("<P><HR><P>\n"));
1636 SetCurrentOutput(Titlepage);
1649 helpRefFilename
= NULL
;
1654 case ltBIBLIOGRAPHY
:
1658 DefaultOnMacro(macroId
, no_args
, start
);
1662 DefaultOnMacro(macroId
, no_args
, start
);
1663 TexOutput(_T("</DL>\n"));
1671 TexOutput(_T("<HR>\n"));
1679 TexOutput(_T("<HR>\n"));
1683 case ltTABLEOFCONTENTS
:
1687 // NB: if this is uncommented, the table of contents
1688 // completely disappears. If left commented, it's in the wrong
1690 //fflush(Titlepage);
1692 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1698 wxPutc(ch
, Titlepage
);
1706 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1707 OnInform(_T("Run Tex2RTF again to include contents page."));
1715 TexOutput(_T("<"));
1721 TexOutput(_T(">"));
1728 TexOutput(_T("<BLOCKQUOTE>"));
1730 TexOutput(_T("</BLOCKQUOTE>"));
1739 TexOutput(_T("\n<CAPTION>"));
1747 if (DocumentStyle
!= LATEX_ARTICLE
)
1748 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1750 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1756 if (DocumentStyle
!= LATEX_ARTICLE
)
1757 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1759 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1767 TexOutput(_T("\n</CAPTION>\n"));
1769 wxChar
*topicName
= FindTopicName(GetNextChunk());
1771 int n
= inFigure
? figureNo
: tableNo
;
1773 AddTexRef(topicName
, NULL
, NULL
,
1774 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1775 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1781 if (start
) TexOutput(_T("ß"));
1786 if (start
) inFigure
= true;
1787 else inFigure
= false;
1792 if (start
) inTable
= true;
1793 else inTable
= false;
1797 DefaultOnMacro(macroId
, no_args
, start
);
1803 should be called at of argument which usually is
1804 type declaration which propably contains name of
1813 checks: GetArgData() if contains Type Declaration
1814 and can be referenced to some file
1816 before<a href="xxx&yyy">type</a>after
1819 false - if no reference was found
1820 true - if reference was found and HREF printed
1822 static bool CheckTypeRef()
1824 wxString typeDecl
= GetArgData();
1825 if( !typeDecl
.empty() ) {
1826 typeDecl
.Replace(wxT("\\"),wxT(""));
1827 wxString label
= typeDecl
;
1828 label
.Replace(wxT("const"),wxT(""));
1829 label
.Replace(wxT("virtual"),wxT(""));
1830 label
.Replace(wxT("static"),wxT(""));
1831 label
.Replace(wxT("extern"),wxT(""));
1832 label
= label
.BeforeFirst('&');
1833 label
= label
.BeforeFirst(wxT('*'));
1834 label
= label
.BeforeFirst(wxT('\\'));
1835 label
.Trim(true); label
.Trim(false);
1836 wxString typeName
= label
;
1838 TexRef
*texRef
= FindReference((wxChar
*)label
.c_str());
1840 if (texRef
&& texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0) {
1841 int a
= typeDecl
.Find(typeName
);
1842 wxString before
= typeDecl
.Mid( 0, a
);
1843 wxString after
= typeDecl
.Mid( a
+typeName
.Length() );
1844 //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"),
1846 // typeName.c_str(),
1848 // texRef->refFile,label.c_str());
1850 TexOutput(_T("<A HREF=\""));
1851 TexOutput(texRef
->refFile
);
1854 TexOutput(wxT("\">"));
1855 TexOutput(typeName
);
1856 TexOutput(wxT("</A>"));
1860 //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"),
1861 // typeName.c_str(),
1862 // typeDecl.c_str(),
1869 // Called on start/end of argument examination
1870 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1876 case ltCHAPTERHEADING
:
1879 case ltSECTIONHEADING
:
1881 case ltSUBSECTIONSTAR
:
1882 case ltSUBSUBSECTION
:
1883 case ltSUBSUBSECTIONSTAR
:
1885 case ltMEMBERSECTION
:
1886 case ltFUNCTIONSECTION
:
1888 if (!start
&& (arg_no
== 1))
1889 currentSection
= GetArgChunk();
1894 if (start
&& (arg_no
== 1)) {
1895 TexOutput(_T("<B>"));
1896 if( CheckTypeRef() ) {
1897 TexOutput(_T("</B> "));
1902 if (!start
&& (arg_no
== 1))
1903 TexOutput(_T("</B> "));
1905 if (start
&& (arg_no
== 2))
1907 if (!suppressNameDecoration
) TexOutput(_T("<B>"));
1908 currentMember
= GetArgChunk();
1910 if (!start
&& (arg_no
== 2))
1912 if (!suppressNameDecoration
) TexOutput(_T("</B>"));
1915 if (start
&& (arg_no
== 3))
1917 if (!start
&& (arg_no
== 3))
1923 if (start
&& (arg_no
== 1))
1924 TexOutput(_T("<B>"));
1925 if (!start
&& (arg_no
== 1))
1926 TexOutput(_T("</B> "));
1928 if (start
&& (arg_no
== 2))
1930 if (!suppressNameDecoration
) TexOutput(_T("( "));
1931 currentMember
= GetArgChunk();
1933 if (!start
&& (arg_no
== 2))
1937 if (!start
&& (arg_no
== 3))
1943 if (!start
&& (arg_no
== 1))
1946 if (start
&& (arg_no
== 2))
1947 TexOutput(_T("(*"));
1948 if (!start
&& (arg_no
== 2))
1951 if (start
&& (arg_no
== 2))
1952 currentMember
= GetArgChunk();
1954 if (start
&& (arg_no
== 3))
1956 if (!start
&& (arg_no
== 3))
1963 const wxChar
* pend
= macroId
== ltCPARAM
?
1964 _T("</B> ") : _T("</B>");
1967 TexOutput(_T("<B>"));
1968 if( CheckTypeRef() ) {
1976 if (start
&& (arg_no
== 2))
1978 TexOutput(_T("<I>"));
1980 if (!start
&& (arg_no
== 2))
1982 TexOutput(_T("</I>"));
1988 if (!start
&& (arg_no
== 1))
1991 if (start
&& (arg_no
== 2))
1992 currentMember
= GetArgChunk();
2001 wxChar
*refName
= GetArgData();
2004 TexRef
*texRef
= FindReference(refName
);
2007 sec
= texRef
->sectionNumber
;
2020 if (IsArgOptional())
2022 else if ((GetNoArgs() - arg_no
) == 1)
2025 helpRefText
= GetArgChunk();
2028 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2032 TexChunk
*ref
= GetArgChunk();
2033 TexOutput(_T("<A HREF=\""));
2035 TraverseChildrenFromChunk(ref
);
2037 TexOutput(_T("\">"));
2039 TraverseChildrenFromChunk(helpRefText
);
2040 TexOutput(_T("</A>"));
2051 if (IsArgOptional())
2054 helpRefFilename
= GetArgChunk();
2057 if ((GetNoArgs() - arg_no
) == 1)
2060 helpRefText
= GetArgChunk();
2063 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2067 wxChar
*refName
= GetArgData();
2068 wxChar
*refFilename
= NULL
;
2072 TexRef
*texRef
= FindReference(refName
);
2075 if (texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0)
2076 refFilename
= texRef
->refFile
;
2078 TexOutput(_T("<A HREF=\""));
2079 // If a filename is supplied, use it, otherwise try to
2080 // use the filename associated with the reference (from this document).
2081 if (helpRefFilename
)
2083 TraverseChildrenFromChunk(helpRefFilename
);
2087 else if (refFilename
)
2089 TexOutput(ConvertCase(refFilename
));
2090 if(!PrimaryAnchorOfTheFile(texRef
->refFile
, refName
))
2096 TexOutput(_T("\">"));
2098 TraverseChildrenFromChunk(helpRefText
);
2099 TexOutput(_T("</A>"));
2104 TraverseChildrenFromChunk(helpRefText
);
2106 TexOutput(_T(" (REF NOT FOUND)"));
2108 // for launching twice do not warn in preparation pass
2109 if ((passNumber
== 1 && !runTwice
) ||
2110 (passNumber
== 2 && runTwice
))
2113 errBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
2114 OnInform((wxChar
*)errBuf
.c_str());
2118 else TexOutput(_T("??"));
2133 wxChar
*alignment
= _T("");
2134 if (macroId
== ltIMAGEL
)
2135 alignment
= _T(" align=left");
2136 else if (macroId
== ltIMAGER
)
2137 alignment
= _T(" align=right");
2139 // Try to find an XBM or GIF image first.
2140 wxChar
*filename
= copystring(GetArgData());
2143 wxStrcpy(buf
, filename
);
2144 StripExtension(buf
);
2145 wxStrcat(buf
, _T(".xbm"));
2146 wxString f
= TexPathList
.FindValidPath(buf
);
2148 if (f
== _T("")) // Try for a GIF instead
2150 wxStrcpy(buf
, filename
);
2151 StripExtension(buf
);
2152 wxStrcat(buf
, _T(".gif"));
2153 f
= TexPathList
.FindValidPath(buf
);
2156 if (f
== _T("")) // Try for a JPEG instead
2158 wxStrcpy(buf
, filename
);
2159 StripExtension(buf
);
2160 wxStrcat(buf
, _T(".jpg"));
2161 f
= TexPathList
.FindValidPath(buf
);
2164 if (f
== _T("")) // Try for a PNG instead
2166 wxStrcpy(buf
, filename
);
2167 StripExtension(buf
);
2168 wxStrcat(buf
, _T(".png"));
2169 f
= TexPathList
.FindValidPath(buf
);
2174 wxChar
*inlineFilename
= copystring(f
);
2176 wxChar
*originalFilename
= TexPathList
.FindValidPath(filename
);
2177 // If we have found the existing filename, make the inline
2178 // image point to the original file (could be PS, for example)
2179 if (originalFilename
&& (wxStrcmp(inlineFilename
, originalFilename
) != 0))
2181 TexOutput(_T("<A HREF=\""));
2182 TexOutput(ConvertCase(originalFilename
));
2183 TexOutput(_T("\">"));
2184 TexOutput(_T("<img src=\""));
2185 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2186 TexOutput(_T("\""));
2187 TexOutput(alignment
);
2188 TexOutput(_T("></A>"));
2193 TexOutput(_T("<img src=\""));
2194 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2195 TexOutput(_T("\""));
2196 TexOutput(alignment
);
2198 delete[] inlineFilename
;
2203 // Last resort - a link to a PS file.
2204 TexOutput(_T("<A HREF=\""));
2205 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2206 TexOutput(_T("\">Picture</A>\n"));
2207 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2214 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2217 static wxChar
*imageFile
= NULL
;
2218 if (start
&& (arg_no
== 2))
2220 // Try to find an XBM or GIF image first.
2221 wxChar
*filename
= copystring(GetArgData());
2224 wxStrcpy(buf
, filename
);
2225 StripExtension(buf
);
2226 wxStrcat(buf
, _T(".xbm"));
2227 wxString f
= TexPathList
.FindValidPath(buf
);
2229 if (f
== _T("")) // Try for a GIF instead
2231 wxStrcpy(buf
, filename
);
2232 StripExtension(buf
);
2233 wxStrcat(buf
, _T(".gif"));
2234 f
= TexPathList
.FindValidPath(buf
);
2239 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2248 imageFile
= copystring(f
);
2251 else if (start
&& (arg_no
== 3))
2255 // First, try to find a .shg (segmented hypergraphics file)
2256 // that we can convert to a map file
2258 wxStrcpy(buf
, imageFile
);
2259 StripExtension(buf
);
2260 wxStrcat(buf
, _T(".shg"));
2261 wxString f
= TexPathList
.FindValidPath(buf
);
2265 // The default HTML file to go to is THIS file (so a no-op)
2266 SHGToMap((wxChar
*)f
.c_str(), currentFileName
);
2269 wxChar
*mapName
= GetArgData();
2270 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2274 TexOutput(_T("unknown"));
2275 TexOutput(_T("\">"));
2276 TexOutput(_T("<img src=\""));
2277 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2278 TexOutput(_T("\" ISMAP></A><P>"));
2298 descriptionItemArg
= GetArgChunk();
2304 case ltTWOCOLITEMRULED
:
2307 if (start && (arg_no == 1))
2308 TexOutput(_T("\n<DT> "));
2309 if (start && (arg_no == 2))
2310 TexOutput(_T("<DD> "));
2316 if (TwoColWidthA
> -1)
2319 wxSnprintf(buf
, sizeof(buf
), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA
);
2324 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2328 TexOutput(_T("\n</FONT></TD>\n"));
2335 if (TwoColWidthB
> -1)
2338 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB
);
2343 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2347 TexOutput(_T("\n</FONT></TD></TR>\n"));
2351 case ltNUMBEREDBIBITEM
:
2353 if (arg_no
== 1 && start
)
2355 TexOutput(_T("\n<DT> "));
2357 if (arg_no
== 2 && !start
)
2358 TexOutput(_T("<P>\n"));
2364 if (arg_no
== 1 && start
)
2366 wxChar
*citeKey
= GetArgData();
2367 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2370 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2371 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
2372 ref
->sectionNumber
= copystring(buf
);
2375 wxSnprintf(buf
, sizeof(buf
), _T("\n<DT> [%d] "), citeCount
);
2380 if (arg_no
== 2 && !start
)
2381 TexOutput(_T("<P>\n"));
2385 case ltMARGINPARODD
:
2386 case ltMARGINPAREVEN
:
2392 TexOutput(_T("<HR>\n"));
2396 TexOutput(_T("<HR><P>\n"));
2400 case ltTWOCOLWIDTHA
:
2404 wxChar
*val
= GetArgData();
2405 float points
= ParseUnitArgument(val
);
2406 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2411 case ltTWOCOLWIDTHB
:
2415 wxChar
*val
= GetArgData();
2416 float points
= ParseUnitArgument(val
);
2417 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2425 case ltACCENT_GRAVE
:
2429 wxChar
*val
= GetArgData();
2435 TexOutput(_T("à"));
2438 TexOutput(_T("è"));
2441 TexOutput(_T("ì"));
2444 TexOutput(_T("ò"));
2447 TexOutput(_T("ù"));
2450 TexOutput(_T("À"));
2453 TexOutput(_T("È"));
2456 TexOutput(_T("Ì"));
2459 TexOutput(_T("Ò"));
2462 TexOutput(_T("Ì"));
2471 case ltACCENT_ACUTE
:
2475 wxChar
*val
= GetArgData();
2481 TexOutput(_T("á"));
2484 TexOutput(_T("é"));
2487 TexOutput(_T("í"));
2490 TexOutput(_T("ó"));
2493 TexOutput(_T("ú"));
2496 TexOutput(_T("ý"));
2499 TexOutput(_T("Á"));
2502 TexOutput(_T("É"));
2505 TexOutput(_T("Í"));
2508 TexOutput(_T("Ó"));
2511 TexOutput(_T("Ú"));
2514 TexOutput(_T("Ý"));
2523 case ltACCENT_CARET
:
2527 wxChar
*val
= GetArgData();
2533 TexOutput(_T("â"));
2536 TexOutput(_T("ê"));
2539 TexOutput(_T("î"));
2542 TexOutput(_T("ô"));
2545 TexOutput(_T("û"));
2548 TexOutput(_T("Â"));
2551 TexOutput(_T("Ê"));
2554 TexOutput(_T("Î"));
2557 TexOutput(_T("Ô"));
2560 TexOutput(_T("Î"));
2569 case ltACCENT_TILDE
:
2573 wxChar
*val
= GetArgData();
2582 TexOutput(_T("ã"));
2585 TexOutput(_T("ñ"));
2588 TexOutput(_T("õ"));
2591 TexOutput(_T("Ã"));
2594 TexOutput(_T("Ñ"));
2597 TexOutput(_T("Õ"));
2606 case ltACCENT_UMLAUT
:
2610 wxChar
*val
= GetArgData();
2616 TexOutput(_T("ä"));
2619 TexOutput(_T("ë"));
2622 TexOutput(_T("ï"));
2625 TexOutput(_T("ö"));
2628 TexOutput(_T("ü"));
2631 TexOutput(_T("ÿ"));
2634 TexOutput(_T("Ä"));
2637 TexOutput(_T("Ë"));
2640 TexOutput(_T("Ï"));
2643 TexOutput(_T("Ö"));
2646 TexOutput(_T("Ü"));
2649 TexOutput(_T("Ÿ"));
2662 wxChar
*val
= GetArgData();
2668 TexOutput(_T("å"));
2671 TexOutput(_T("Å"));
2684 wxChar
*val
= GetArgData();
2687 bool isPicture
= false;
2688 ParseColourString(val
, &isPicture
);
2691 if (backgroundImageString
)
2692 delete[] backgroundImageString
;
2693 backgroundImageString
= copystring(val
);
2697 if (backgroundColourString
)
2698 delete[] backgroundColourString
;
2699 backgroundColourString
= copystring(val
);
2705 case ltBACKGROUNDIMAGE
:
2709 wxChar
*val
= GetArgData();
2712 if (backgroundImageString
)
2713 delete[] backgroundImageString
;
2714 backgroundImageString
= copystring(val
);
2719 case ltBACKGROUNDCOLOUR
:
2723 wxChar
*val
= GetArgData();
2726 if (backgroundColourString
)
2727 delete[] backgroundColourString
;
2728 backgroundColourString
= copystring(val
);
2737 wxChar
*val
= GetArgData();
2740 if (textColourString
)
2741 delete[] textColourString
;
2742 textColourString
= copystring(val
);
2751 wxChar
*val
= GetArgData();
2754 if (linkColourString
)
2755 delete[] linkColourString
;
2756 linkColourString
= copystring(val
);
2761 case ltFOLLOWEDLINKCOLOUR
:
2765 wxChar
*val
= GetArgData();
2768 if (followedLinkColourString
)
2769 delete[] followedLinkColourString
;
2770 followedLinkColourString
= copystring(val
);
2775 case ltACCENT_CADILLA
:
2779 wxChar
*val
= GetArgData();
2785 TexOutput(_T("ç"));
2788 TexOutput(_T("Ç"));
2799 case ltFOOTNOTEPOPUP:
2809 case ltSUPERTABULAR
:
2815 currentRowNumber
= 0;
2818 tableVerticalLineLeft
= false;
2819 tableVerticalLineRight
= false;
2821 wxChar
*alignString
= copystring(GetArgData());
2822 ParseTableArgument(alignString
);
2824 TexOutput(_T("<TABLE BORDER>\n"));
2826 // Write the first row formatting for compatibility
2827 // with standard Latex
2828 if (compatibilityMode
)
2830 TexOutput(_T("<TR>\n<TD>"));
2833 for (int i = 0; i < noColumns; i++)
2835 currentWidth += TableData[i].width;
2836 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2839 TexOutput(_T("\\pard\\intbl\n"));
2842 delete[] alignString
;
2847 else if (arg_no
== 2 && !start
)
2849 TexOutput(_T("</TABLE>\n"));
2854 case ltTHEBIBLIOGRAPHY
:
2856 if (start
&& (arg_no
== 1))
2858 ReopenFile(&Chapters
, &ChaptersName
, _T("bibliography"));
2859 AddTexRef(_T("bibliography"), ChaptersName
, _T("bibliography"));
2860 SetCurrentSubsectionName(_T("bibliography"), ChaptersName
);
2864 SetCurrentOutput(Chapters
);
2866 wxChar titleBuf
[150];
2867 if (truncateFilenames
)
2868 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
2870 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
2873 TexOutput(_T("<title>"));
2874 TexOutput(ReferencesNameString
);
2875 TexOutput(_T("</title></head>\n"));
2878 wxFprintf(Chapters
, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString
);
2879 AddBrowseButtons(_T("contents"), titleBuf
, // Up
2880 lastTopic
, lastFileName
, // Last topic
2881 _T("bibliography"), ChaptersName
); // This topic
2883 SetCurrentOutputs(Contents
, Chapters
);
2884 if(PrimaryAnchorOfTheFile(ChaptersName
, _T("bibliography")))
2885 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
2887 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), _T("bibliography"));
2889 wxFprintf(Contents
, _T("%s</A>\n"), ReferencesNameString
);
2890 wxFprintf(Chapters
, _T("</H2>\n</A>\n"));
2892 SetCurrentOutput(Chapters
);
2895 if (!start
&& (arg_no
== 2))
2902 /* Build up list of keywords associated with topics */
2905 // wxChar *entry = GetArgData();
2907 OutputChunkToString(GetArgChunk(), buf
);
2910 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2924 wxChar
*name
= GetArgData();
2926 if (!FindColourHTMLString(name
, buf2
))
2928 wxStrcpy(buf2
, _T("#000000"));
2930 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
2933 TexOutput(_T("<FONT COLOR=\""));
2935 TexOutput(_T("\">"));
2948 if (arg_no
== 2) TexOutput(_T("</FONT>"));
2952 case ltINSERTATLEVEL
:
2954 // This macro allows you to insert text at a different level
2955 // from the current level, e.g. into the Sections from within a subsubsection.
2958 static int currentLevelNo
= 1;
2959 static FILE* oldLevelFile
= Chapters
;
2966 oldLevelFile
= CurrentOutput1
;
2968 wxChar
*str
= GetArgData();
2969 currentLevelNo
= wxAtoi(str
);
2971 // TODO: cope with article style (no chapters)
2972 switch (currentLevelNo
)
2976 outputFile
= Chapters
;
2981 outputFile
= Sections
;
2986 outputFile
= Subsections
;
2991 outputFile
= Subsubsections
;
3001 CurrentOutput1
= outputFile
;
3017 CurrentOutput1
= oldLevelFile
;
3023 return DefaultOnArgument(macroId
, arg_no
, start
);
3035 tableVerticalLineLeft
= false;
3036 tableVerticalLineRight
= false;
3039 if (!InputFile
.empty() && !OutputFile
.empty())
3041 // Do some HTML-specific transformations on all the strings,
3043 Text2HTML(GetTopLevelChunk());
3046 if (truncateFilenames
)
3047 wxSnprintf(buf
, sizeof(buf
), _T("%s.htm"), FileRoot
);
3049 wxSnprintf(buf
, sizeof(buf
), _T("%s_contents.html"), FileRoot
);
3050 if (TitlepageName
) delete[] TitlepageName
;
3051 TitlepageName
= copystring(buf
);
3052 Titlepage
= wxFopen(buf
, _T("w"));
3054 if (truncateFilenames
)
3055 wxSnprintf(buf
, sizeof(buf
), _T("%s_fc.htm"), FileRoot
);
3057 wxSnprintf(buf
, sizeof(buf
), _T("%s_fcontents.html"), FileRoot
);
3059 contentsFrameName
= copystring(buf
);
3061 Contents
= wxFopen(TmpContentsName
, _T("w"));
3063 if (htmlFrameContents
)
3065 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
3066 FrameContents
= wxFopen(contentsFrameName
, _T("w"));
3067 wxFprintf(FrameContents
, _T("<HTML>\n<UL>\n"));
3070 if (!Titlepage
|| !Contents
)
3072 OnError(_T("Cannot open output file!"));
3075 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName
), ContentsNameString
);
3077 wxFprintf(Contents
, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString
);
3079 wxFprintf(Contents
, _T("<UL>\n"));
3081 SetCurrentOutput(Titlepage
);
3082 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
3083 OnInform(_T("Converting..."));
3086 wxFprintf(Contents
, _T("</UL>\n\n"));
3088 // SetCurrentOutput(Titlepage);
3093 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3100 wxFprintf(FrameContents
, _T("\n</UL>\n"));
3101 wxFprintf(FrameContents
, _T("</HTML>\n"));
3102 fclose(FrameContents
);
3103 FrameContents
= NULL
;
3108 wxFprintf(Chapters
, _T("\n</FONT></BODY></HTML>\n"));
3114 wxFprintf(Sections
, _T("\n</FONT></BODY></HTML>\n"));
3118 if (Subsections
&& !combineSubSections
)
3120 wxFprintf(Subsections
, _T("\n</FONT></BODY></HTML>\n"));
3121 fclose(Subsections
);
3124 if (Subsubsections
&& !combineSubSections
)
3126 wxFprintf(Subsubsections
, _T("\n</FONT></BODY></HTML>\n"));
3127 fclose(Subsubsections
);
3128 Subsubsections
= NULL
;
3130 if ( SectionContentsFD
)
3132 fclose(SectionContentsFD
);
3133 SectionContentsFD
= NULL
;
3136 // Create a temporary file for the title page header, add some info,
3137 // and concat the titlepage just generated.
3138 // This is necessary in order to put the title of the document
3139 // at the TOP of the file within <HEAD>, even though we only find out
3140 // what it is later on.
3141 FILE *tmpTitle
= wxFopen(_T("title.tmp"), _T("w"));
3146 SetCurrentOutput(tmpTitle
);
3148 TexOutput(_T("\n<TITLE>"));
3149 TraverseChildrenFromChunk(DocumentTitle
);
3150 TexOutput(_T("</TITLE></HEAD>\n"));
3154 SetCurrentOutput(tmpTitle
);
3155 HTMLHeadTo(tmpTitle
);
3157 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString
);
3159 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot
));
3162 // Output frame information
3163 if (htmlFrameContents
)
3165 wxChar firstFileName
[300];
3166 if (truncateFilenames
)
3167 wxSnprintf(firstFileName
, sizeof(firstFileName
), _T("%s1.htm"), FileRoot
);
3169 wxStrcpy(firstFileName
, gs_filenames
[1].c_str());
3171 wxFprintf(tmpTitle
, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3173 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3174 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName
)));
3175 wxFprintf(tmpTitle
, _T("</FRAMESET>\n"));
3177 wxFprintf(tmpTitle
, _T("<NOFRAMES>\n"));
3180 // Output <BODY...> to temporary title page
3185 FILE *fd
= wxFopen(TitlepageName
, _T("r"));
3191 wxPutc(ch
, tmpTitle
);
3197 wxFprintf(tmpTitle
, _T("\n</FONT></BODY>\n"));
3199 if (htmlFrameContents
)
3201 wxFprintf(tmpTitle
, _T("\n</NOFRAMES>\n"));
3203 wxFprintf(tmpTitle
, _T("\n</HTML>\n"));
3206 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3207 if (!wxRenameFile(_T("title.tmp"), TitlepageName
))
3209 wxCopyFile(_T("title.tmp"), TitlepageName
);
3210 wxRemoveFile(_T("title.tmp"));
3214 if (lastFileName
) delete[] lastFileName
;
3215 lastFileName
= NULL
;
3216 if (lastTopic
) delete[] lastTopic
;
3219 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3221 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3223 wxCopyFile(TmpContentsName
, ContentsName
);
3224 wxRemoveFile(TmpContentsName
);
3227 // Generate .htx file if requested
3230 wxChar htmlIndexName
[300];
3231 wxSnprintf(htmlIndexName
, sizeof(htmlIndexName
), _T("%s.htx"), FileRoot
);
3232 GenerateHTMLIndexFile(htmlIndexName
);
3235 // Generate HTML Help Workshop files if requested
3236 if (htmlWorkshopFiles
)
3238 HTMLWorkshopEndContents();
3239 GenerateHTMLWorkshopFiles(FileRoot
);
3248 // Output .htx index file
3249 void GenerateHTMLIndexFile(wxChar
*fname
)
3251 FILE *fd
= wxFopen(fname
, _T("w"));
3255 TopicTable
.BeginFind();
3256 wxHashTable::Node
*node
= TopicTable
.Next();
3259 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3260 const wxChar
*topicName
= node
->GetKeyString();
3261 if (texTopic
->filename
&& texTopic
->keywords
)
3263 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3266 wxChar
*s
= (wxChar
*)node1
->GetData();
3267 wxFprintf(fd
, _T("%s|%s|%s\n"), topicName
, texTopic
->filename
, s
);
3268 node1
= node1
->GetNext();
3271 node
= TopicTable
.Next();
3282 // output .hpp, .hhc and .hhk files:
3285 void GenerateHTMLWorkshopFiles(wxChar
*fname
)
3290 /* Generate project file : */
3292 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhp"), fname
);
3293 f
= wxFopen(buf
, _T("wt"));
3296 _T("Compatibility=1.1\n")
3297 _T("Full-text search=Yes\n")
3298 _T("Contents file=%s.hhc\n")
3299 _T("Compiled file=%s.chm\n")
3300 _T("Default Window=%sHelp\n")
3301 _T("Default topic=%s\n")
3302 _T("Index file=%s.hhk\n")
3304 wxFileNameFromPath(fname
),
3305 wxFileNameFromPath(fname
),
3306 wxFileNameFromPath(fname
),
3307 wxFileNameFromPath(TitlepageName
),
3308 wxFileNameFromPath(fname
)
3311 if (DocumentTitle
) {
3312 SetCurrentOutput(f
);
3313 TraverseChildrenFromChunk(DocumentTitle
);
3315 else wxFprintf(f
, _T("(unknown)"));
3317 wxFprintf(f
, _T("\n\n[WINDOWS]\n")
3318 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3319 wxFileNameFromPath(fname
),
3320 wxFileNameFromPath(fname
),
3321 wxFileNameFromPath(fname
),
3322 wxFileNameFromPath(TitlepageName
));
3325 wxFprintf(f
, _T("\n\n[FILES]\n"));
3326 wxFprintf(f
, _T("%s\n"), wxFileNameFromPath(TitlepageName
));
3327 for (int i
= 1; i
<= fileId
; i
++) {
3328 if (truncateFilenames
)
3329 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), wxFileNameFromPath(FileRoot
), i
);
3331 wxStrcpy(buf
, wxFileNameFromPath(gs_filenames
[i
].c_str()));
3332 wxFprintf(f
, _T("%s\n"), buf
);
3336 /* Generate index file : */
3338 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhk"), fname
);
3339 f
= wxFopen(buf
, _T("wt"));
3342 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3347 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3348 _T("<!-- Sitemap 1.0 -->\n")
3349 _T("</HEAD><BODY>\n")
3350 _T("<OBJECT type=\"text/site properties\">\n")
3351 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3355 TopicTable
.BeginFind();
3356 wxHashTable::Node
*node
= TopicTable
.Next();
3359 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3360 const wxChar
*topicName
= node
->GetKeyString();
3361 if (texTopic
->filename
&& texTopic
->keywords
)
3363 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3366 wxChar
*s
= (wxChar
*)node1
->GetData();
3368 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3369 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3370 _T(" <param name=\"Name\" value=\"%s\">\n")
3372 texTopic
->filename
, topicName
, s
);
3373 node1
= node1
->GetNext();
3376 node
= TopicTable
.Next();
3379 wxFprintf(f
, _T("</UL>\n"));
3385 static FILE *HTMLWorkshopContents
= NULL
;
3386 static int HTMLWorkshopLastLevel
= 0;
3388 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
)
3392 if (level
> HTMLWorkshopLastLevel
)
3393 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3394 wxFprintf(HTMLWorkshopContents
, _T("<UL>"));
3395 if (level
< HTMLWorkshopLastLevel
)
3396 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3397 wxFprintf(HTMLWorkshopContents
, _T("</UL>"));
3399 SetCurrentOutput(HTMLWorkshopContents
);
3400 wxFprintf(HTMLWorkshopContents
,
3401 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3402 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3403 _T(" <param name=\"Name\" value=\""),
3405 OutputCurrentSection();
3406 wxFprintf(HTMLWorkshopContents
,
3408 _T(" </OBJECT>\n"));
3409 HTMLWorkshopLastLevel
= level
;
3413 void HTMLWorkshopStartContents()
3416 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhc"), FileRoot
);
3417 HTMLWorkshopContents
= wxFopen(buf
, _T("wt"));
3418 HTMLWorkshopLastLevel
= 0;
3420 wxFprintf(HTMLWorkshopContents
,
3421 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3423 HTMLHeadTo(HTMLWorkshopContents
);
3424 wxFprintf(HTMLWorkshopContents
,
3426 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3427 _T("<!-- Sitemap 1.0 -->\n")
3428 _T("</HEAD><BODY>\n")
3429 _T("<OBJECT type=\"text/site properties\">\n")
3430 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3433 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3434 _T("<param name=\"Local\" value=\"%s\">\n")
3435 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3436 wxFileNameFromPath(TitlepageName
)
3442 void HTMLWorkshopEndContents()
3444 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3445 wxFprintf(HTMLWorkshopContents
, _T("</UL>\n"));
3446 fclose(HTMLWorkshopContents
);
3450 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
)
3452 wxString file_label
;
3453 file_label
.Printf( HTML_FILENAME_PATTERN
, FileRoot
, label
);
3454 return file_label
.IsSameAs( file
, false );