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 static inline wxChar
* copystring(const wxChar
* s
)
32 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
34 extern wxHashTable TexReferences
;
36 extern int passNumber
;
38 extern void DecToHex(int, wxChar
*);
39 void GenerateHTMLIndexFile(wxChar
*fname
);
41 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
);
43 void GenerateHTMLWorkshopFiles(wxChar
*fname
);
44 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
);
45 void HTMLWorkshopStartContents();
46 void HTMLWorkshopEndContents();
48 void OutputContentsFrame(void);
50 #include "readshg.h" // Segmented hypergraphics parsing
52 wxChar
*ChaptersName
= NULL
;
53 wxChar
*SectionsName
= NULL
;
54 wxChar
*SubsectionsName
= NULL
;
55 wxChar
*SubsubsectionsName
= NULL
;
56 wxChar
*TitlepageName
= NULL
;
57 wxChar
*lastFileName
= NULL
;
58 wxChar
*lastTopic
= NULL
;
59 wxChar
*currentFileName
= NULL
;
60 wxChar
*contentsFrameName
= NULL
;
62 static TexChunk
*descriptionItemArg
= NULL
;
63 static TexChunk
*helpRefFilename
= NULL
;
64 static TexChunk
*helpRefText
= NULL
;
65 static int indentLevel
= 0;
66 static int citeCount
= 1;
67 extern FILE *Contents
;
68 FILE *FrameContents
= NULL
;
69 FILE *Titlepage
= NULL
;
70 // FILE *FrameTitlepage = NULL;
72 bool subsectionStarted
= false;
74 // Which column of a row are we in? (Assumes no nested tables, of course)
75 int currentColumn
= 0;
77 // Are we in verbatim mode? If so, format differently.
78 static bool inVerbatim
= false;
80 // Need to know whether we're in a table or figure for benefit
81 // of listoffigures/listoftables
82 static bool inFigure
= false;
83 static bool inTable
= false;
85 // This is defined in the Tex2Any library.
86 extern wxChar
*BigBuffer
;
88 // DHS Two-column table dimensions.
89 static int TwoColWidthA
= -1;
90 static int TwoColWidthB
= -1;
93 class HyperReference
: public wxObject
98 HyperReference(wxChar
*name
, wxChar
*file
)
100 if (name
) refName
= copystring(name
);
101 if (file
) refFile
= copystring(file
);
105 class TexNextPage
: public wxObject
110 TexNextPage(wxChar
*theLabel
, wxChar
*theFile
)
112 label
= copystring(theLabel
);
113 filename
= copystring(theFile
);
115 virtual ~TexNextPage(void)
122 wxHashTable
TexNextPages(wxKEY_STRING
);
124 static wxChar
*CurrentChapterName
= NULL
;
125 static wxChar
*CurrentChapterFile
= NULL
;
126 static wxChar
*CurrentSectionName
= NULL
;
127 static wxChar
*CurrentSectionFile
= NULL
;
128 static wxChar
*CurrentSubsectionName
= NULL
;
129 static wxChar
*CurrentSubsectionFile
= NULL
;
130 static wxChar
*CurrentSubsubsectionName
= NULL
;
131 static wxChar
*CurrentSubsubsectionFile
= NULL
;
132 static wxChar
*CurrentTopic
= NULL
;
134 static void SetCurrentTopic(wxChar
*s
)
136 if (CurrentTopic
) delete[] CurrentTopic
;
137 CurrentTopic
= copystring(s
);
140 void SetCurrentChapterName(wxChar
*s
, wxChar
*file
)
142 if (CurrentChapterName
) delete[] CurrentChapterName
;
143 CurrentChapterName
= copystring(s
);
144 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
145 CurrentChapterFile
= copystring(file
);
147 currentFileName
= CurrentChapterFile
;
151 void SetCurrentSectionName(wxChar
*s
, wxChar
*file
)
153 if (CurrentSectionName
) delete[] CurrentSectionName
;
154 CurrentSectionName
= copystring(s
);
155 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
156 CurrentSectionFile
= copystring(file
);
158 currentFileName
= CurrentSectionFile
;
161 void SetCurrentSubsectionName(wxChar
*s
, wxChar
*file
)
163 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
164 CurrentSubsectionName
= copystring(s
);
165 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
166 CurrentSubsectionFile
= copystring(file
);
167 currentFileName
= CurrentSubsectionFile
;
170 void SetCurrentSubsubsectionName(wxChar
*s
, wxChar
*file
)
172 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
173 CurrentSubsubsectionName
= copystring(s
);
174 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
175 CurrentSubsubsectionFile
= copystring(file
);
176 currentFileName
= CurrentSubsubsectionFile
;
181 // mapping between fileId and filenames if truncateFilenames=false:
182 static wxArrayString gs_filenames
;
186 * Close former filedescriptor and reopen using another filename.
190 void ReopenFile(FILE **fd
, wxChar
**fileName
, const wxChar
*label
)
194 wxFprintf(*fd
, _T("\n</FONT></BODY></HTML>\n"));
199 if (truncateFilenames
)
201 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), FileRoot
, fileId
);
206 gs_filenames
.Add(wxEmptyString
);
207 wxSnprintf(buf
, sizeof(buf
), HTML_FILENAME_PATTERN
, FileRoot
, label
);
208 gs_filenames
.Add(buf
);
210 if (*fileName
) delete[] *fileName
;
211 *fileName
= copystring(wxFileNameFromPath(buf
));
212 *fd
= wxFopen(buf
, _T("w"));
213 wxFprintf(*fd
, _T("<HTML>\n"));
217 * Reopen section contents file, i.e. the index appended to each section
218 * in subsectionCombine mode
221 static wxChar
*SectionContentsFilename
= NULL
;
222 static FILE *SectionContentsFD
= NULL
;
224 void ReopenSectionContentsFile(void)
226 if ( SectionContentsFD
)
228 fclose(SectionContentsFD
);
230 if ( SectionContentsFilename
)
231 delete[] SectionContentsFilename
;
232 SectionContentsFD
= NULL
;
233 SectionContentsFilename
= NULL
;
235 // Create the name from the current section filename
236 if ( CurrentSectionFile
)
239 wxStrcpy(buf
, CurrentSectionFile
);
240 wxStripExtension(buf
);
241 wxStrcat(buf
, _T(".con"));
242 SectionContentsFilename
= copystring(buf
);
244 SectionContentsFD
= wxFopen(SectionContentsFilename
, _T("w"));
256 size_t replace_length
;
259 #define tr(x,y) {x, sizeof(x)-1, y, sizeof(y)-1}
261 static textreplace notverb_array
[] =
263 tr(_T("\r\n\r\n"), _T("<P>\n\n")), // unix
264 tr(_T("\n\n"), _T("<P>\n\n")), // dos
265 tr(_T("\r\r"), _T("<P>\n\n")), // mac
266 tr(_T("``"), _T("“")),
267 tr(_T("''"), _T("”")),
268 tr(_T("`"), _T("‘")),
269 tr(_T("'"), _T("’")),
270 tr(_T("---"), _T("—")),
271 tr(_T("--"), _T("–")),
277 * Given a TexChunk with a string value, scans through the string
278 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
282 void ProcessText2HTML(TexChunk
*chunk
)
284 bool changed
= false;
288 size_t len
= wxStrlen(chunk
->value
);
291 ch
= chunk
->value
[i
];
293 if (ch
== _T('<')) // Change < to <
296 wxStrcat(BigBuffer
, _T("<"));
302 else if (ch
== _T('>')) // Change > to >
305 wxStrcat(BigBuffer
, _T(">"));
313 bool replaced
= false;
316 for (size_t x
= 0; x
< WXSIZEOF(notverb_array
); x
++)
318 textreplace
& tr
= notverb_array
[x
];
319 if (ch
!= tr
.text
[0])
321 if (len
< tr
.text_length
)
325 for (y
= 1; y
< tr
.text_length
; y
++)
327 if (chunk
->value
[y
] != tr
.text
[y
])
331 if (y
!= tr
.text_length
)
334 // can now copy it over.
335 for (y
= 0; y
< tr
.replace_length
; y
++)
337 BigBuffer
[ptr
++] = tr
.replace
[y
];
340 len
-= tr
.text_length
;
362 chunk
->value
= copystring(BigBuffer
);
367 * Scan through all chunks starting from the given one,
368 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
369 * This should be called after Tex2Any has parsed the file,
370 * and before TraverseDocument is called.
374 void Text2HTML(TexChunk
*chunk
)
377 if (stopRunning
) return;
381 case CHUNK_TYPE_MACRO
:
383 TexMacroDef
*def
= chunk
->def
;
385 if (def
&& def
->ignore
)
388 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
391 wxNode
*node
= chunk
->children
.GetFirst();
394 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
395 Text2HTML(child_chunk
);
396 node
= node
->GetNext();
399 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
406 wxNode
*node
= chunk
->children
.GetFirst();
409 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
410 Text2HTML(child_chunk
);
411 node
= node
->GetNext();
416 case CHUNK_TYPE_STRING
:
419 ProcessText2HTML(chunk
);
426 * Add appropriate browse buttons to this page.
430 void AddBrowseButtons(wxChar
*upLabel
, wxChar
*upFilename
,
431 wxChar
*previousLabel
, wxChar
*previousFilename
,
432 wxChar
*thisLabel
, wxChar
*thisFilename
)
434 wxChar contentsReferenceBuf
[80];
435 wxChar upReferenceBuf
[80];
436 wxChar backReferenceBuf
[80];
437 wxChar forwardReferenceBuf
[80];
438 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
441 wxChar
*contentsReference
; // no need to initialize because always assigned below
442 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
443 contentsReference
= ContentsNameString
;
446 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
447 contentsReference
= contentsReferenceBuf
;
448 wxSnprintf(contentsReference
, sizeof(contentsReferenceBuf
),
449 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
450 ConvertCase(_T("contents.gif")));
453 wxChar
*upReference
; // no need to initialize because always assigned below
454 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
455 upReference
= UpNameString
;
458 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
459 upReference
= upReferenceBuf
;
460 wxSnprintf(upReference
, sizeof(upReferenceBuf
),
461 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
462 ConvertCase(_T("up.gif")));
465 wxChar
*backReference
; // no need to initialize because always assigned below
466 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
467 backReference
= _T("<<");
470 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
471 backReference
= backReferenceBuf
;
472 wxSnprintf(backReference
, sizeof(backReferenceBuf
),
473 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
474 ConvertCase(_T("back.gif")));
477 wxChar
*forwardReference
; // no need to initialize because always assigned below
478 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
479 forwardReference
= _T(">>");
482 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
483 forwardReference
= forwardReferenceBuf
;
484 wxSnprintf(forwardReference
, sizeof(forwardReferenceBuf
),
485 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
486 ConvertCase(_T("forward.gif")));
489 TexOutput(_T("<CENTER>"));
498 if (truncateFilenames
)
501 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
502 wxSnprintf(buf
, sizeof(buf
),
503 _T("\n<A HREF=\"%s.%s\">%s</A> "),
504 buf1
, ConvertCase(_T("htm")), contentsReference
);
509 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
510 wxSnprintf(buf
, sizeof(buf
),
511 _T("\n<A HREF=\"%s%s\">%s</A> "),
512 buf1
, ConvertCase(_T("_contents.html")), contentsReference
);
514 // TexOutput(_T("<NOFRAMES>"));
516 // TexOutput(_T("</NOFRAMES>"));
523 if (upLabel
&& upFilename
)
525 if ( (wxStrlen(upLabel
) > 0) && !PrimaryAnchorOfTheFile(upFilename
, upLabel
) )
526 wxSnprintf(buf
, sizeof(buf
),
527 _T("<A HREF=\"%s#%s\">%s</A> "),
528 ConvertCase(upFilename
), upLabel
, upReference
);
530 wxSnprintf(buf
, sizeof(buf
),
531 _T("<A HREF=\"%s\">%s</A> "),
532 ConvertCase(upFilename
), upReference
);
533 if (wxStrcmp(upLabel
, _T("contents")) == 0)
535 // TexOutput(_T("<NOFRAMES>"));
537 // TexOutput(_T("</NOFRAMES>"));
548 if (previousLabel
&& previousFilename
)
550 if (PrimaryAnchorOfTheFile(previousFilename
, previousLabel
))
551 wxSnprintf(buf
, sizeof(buf
),
552 _T("<A HREF=\"%s\">%s</A> "),
553 ConvertCase(previousFilename
), backReference
);
555 wxSnprintf(buf
, sizeof(buf
),
556 _T("<A HREF=\"%s#%s\">%s</A> "),
557 ConvertCase(previousFilename
), previousLabel
, backReference
);
558 if (wxStrcmp(previousLabel
, _T("contents")) == 0)
560 // TexOutput(_T("<NOFRAMES>"));
562 // TexOutput(_T("</NOFRAMES>"));
569 // A placeholder so the buttons don't keep moving position
570 wxSnprintf(buf
, sizeof(buf
), _T("%s "), backReference
);
574 wxChar
*nextLabel
= NULL
;
575 wxChar
*nextFilename
= NULL
;
577 // Get the next page, and record the previous page's 'next' page
579 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
582 nextLabel
= nextPage
->label
;
583 nextFilename
= nextPage
->filename
;
585 if (previousLabel
&& previousFilename
)
587 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
591 TexNextPages
.Delete(previousLabel
);
593 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
594 TexNextPages
.Put(previousLabel
, newNextPage
);
602 if (nextLabel
&& nextFilename
)
604 if (PrimaryAnchorOfTheFile(nextFilename
, nextLabel
))
605 wxSnprintf(buf
, sizeof(buf
),
606 _T("<A HREF=\"%s\">%s</A> "),
607 ConvertCase(nextFilename
), forwardReference
);
609 wxSnprintf(buf
, sizeof(buf
),
610 _T("<A HREF=\"%s#%s\">%s</A> "),
611 ConvertCase(nextFilename
), nextLabel
, forwardReference
);
616 // A placeholder so the buttons don't keep moving position
617 wxSnprintf(buf
, sizeof(buf
), _T("%s "), forwardReference
);
622 * Horizontal rule to finish it off nicely.
625 TexOutput(_T("</CENTER>"));
626 TexOutput(_T("<HR>\n"));
628 // Update last topic/filename
630 delete[] lastFileName
;
631 lastFileName
= copystring(thisFilename
);
634 lastTopic
= copystring(thisLabel
);
637 // A colour string is either 3 numbers separated by semicolons (RGB),
638 // or a reference to a GIF. Return the filename or a hex string like #934CE8
639 wxChar
*ParseColourString(wxChar
*bkStr
, bool *isPicture
)
641 static wxChar resStr
[300];
642 wxStrcpy(resStr
, bkStr
);
643 wxStringTokenizer
tok(resStr
, _T(";"), wxTOKEN_STRTOK
);
644 if (tok
.HasMoreTokens())
646 wxString token1
= tok
.GetNextToken();
647 if (!tok
.HasMoreTokens())
654 wxString token2
= tok
.GetNextToken();
656 if (tok
.HasMoreTokens())
658 wxString token3
= tok
.GetNextToken();
660 // Now convert 3 strings into decimal numbers, and then hex numbers.
661 int red
= wxAtoi(token1
.c_str());
662 int green
= wxAtoi(token2
.c_str());
663 int blue
= wxAtoi(token3
.c_str());
665 wxStrcpy(resStr
, _T("#"));
669 wxStrcat(resStr
, buf
);
670 DecToHex(green
, buf
);
671 wxStrcat(resStr
, buf
);
673 wxStrcat(resStr
, buf
);
682 void OutputFont(void)
684 // Only output <font face> if explicitly requested by htmlFaceName= directive in
685 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
689 // Output <FONT FACE=...>
690 TexOutput(_T("<FONT FACE=\""));
691 TexOutput(htmlFaceName
);
692 TexOutput(_T("\">\n"));
696 // Output start of <BODY> block
697 void OutputBodyStart(void)
699 TexOutput(_T("\n<BODY"));
700 if (backgroundImageString
)
702 bool isPicture
= false;
703 wxChar
*s
= ParseColourString(backgroundImageString
, &isPicture
);
706 TexOutput(_T(" BACKGROUND=\""));
711 if (backgroundColourString
)
713 bool isPicture
= false;
714 wxChar
*s
= ParseColourString(backgroundColourString
, &isPicture
);
717 TexOutput(_T(" BGCOLOR="));
722 // Set foreground text colour, if one is specified
723 if (textColourString
)
725 bool isPicture
= false;
726 wxChar
*s
= ParseColourString(textColourString
, &isPicture
);
729 TexOutput(_T(" TEXT=")); TexOutput(s
);
732 // Set link text colour, if one is specified
733 if (linkColourString
)
735 bool isPicture
= false;
736 wxChar
*s
= ParseColourString(linkColourString
, &isPicture
);
739 TexOutput(_T(" LINK=")); TexOutput(s
);
742 // Set followed link text colour, if one is specified
743 if (followedLinkColourString
)
745 bool isPicture
= false;
746 wxChar
*s
= ParseColourString(followedLinkColourString
, &isPicture
);
749 TexOutput(_T(" VLINK=")); TexOutput(s
);
752 TexOutput(_T(">\n"));
759 TexOutput(_T("<head>"));
760 if (htmlStylesheet
) {
761 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
762 TexOutput(htmlStylesheet
);
763 TexOutput(_T("\">"));
767 void HTMLHeadTo(FILE* f
)
770 wxFprintf(f
,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet
);
772 wxFprintf(f
,_T("<head>"));
775 // Called on start/end of macro examination
776 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
782 case ltCHAPTERHEADING
:
790 if (macroId
!= ltCHAPTERSTAR
)
793 SetCurrentOutput(NULL
);
794 startedSections
= true;
796 wxChar
*topicName
= FindTopicName(GetNextChunk());
797 ReopenFile(&Chapters
, &ChaptersName
, topicName
);
798 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
800 SetCurrentChapterName(topicName
, ChaptersName
);
801 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
803 SetCurrentOutput(Chapters
);
806 TexOutput(_T("<title>"));
807 OutputCurrentSection(); // Repeat section header
808 TexOutput(_T("</title></head>\n"));
811 wxChar titleBuf
[200];
812 if (truncateFilenames
)
813 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
815 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
817 wxFprintf(Chapters
, _T("<A NAME=\"%s\"></A>"), topicName
);
819 AddBrowseButtons(_T(""), titleBuf
, // Up
820 lastTopic
, lastFileName
, // Last topic
821 topicName
, ChaptersName
); // This topic
823 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
824 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
826 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), topicName
);
828 if (htmlFrameContents
&& FrameContents
)
830 SetCurrentOutput(FrameContents
);
831 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
832 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
));
834 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
), topicName
);
835 OutputCurrentSection();
836 wxFprintf(FrameContents
, _T("</A>\n"));
839 SetCurrentOutputs(Contents
, Chapters
);
840 wxFprintf(Chapters
, _T("\n<H2>"));
841 OutputCurrentSection();
842 wxFprintf(Contents
, _T("</A>\n"));
843 wxFprintf(Chapters
, _T("</H2>\n"));
845 SetCurrentOutput(Chapters
);
847 // Add this section title to the list of keywords
850 OutputCurrentSectionToString(wxTex2RTFBuffer
);
851 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
858 case ltSECTIONHEADING
:
865 subsectionStarted
= false;
867 if (macroId
!= ltSECTIONSTAR
)
870 SetCurrentOutput(NULL
);
871 startedSections
= true;
873 wxChar
*topicName
= FindTopicName(GetNextChunk());
874 ReopenFile(&Sections
, &SectionsName
, topicName
);
875 AddTexRef(topicName
, SectionsName
, SectionNameString
);
877 SetCurrentSectionName(topicName
, SectionsName
);
878 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
880 SetCurrentOutput(Sections
);
882 TexOutput(_T("<title>"));
883 OutputCurrentSection();
884 TexOutput(_T("</title></head>\n"));
887 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
888 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
889 lastTopic
, lastFileName
, // Last topic
890 topicName
, SectionsName
); // This topic
892 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
894 SetCurrentOutputs(jumpFrom
, Sections
);
895 if (DocumentStyle
== LATEX_ARTICLE
)
897 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
898 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName
));
900 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName
), topicName
);
904 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
905 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName
));
907 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName
), topicName
);
910 wxFprintf(Sections
, _T("\n<H2>"));
911 OutputCurrentSection();
913 if (DocumentStyle
== LATEX_ARTICLE
)
914 wxFprintf(jumpFrom
, _T("</A>\n"));
916 wxFprintf(jumpFrom
, _T("</B></A><BR>\n"));
917 wxFprintf(Sections
, _T("</H2>\n"));
919 SetCurrentOutput(Sections
);
920 // Add this section title to the list of keywords
923 OutputCurrentSectionToString(wxTex2RTFBuffer
);
924 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
930 case ltSUBSECTIONSTAR
:
931 case ltMEMBERSECTION
:
932 case ltFUNCTIONSECTION
:
938 OnError(_T("You cannot have a subsection before a section!"));
944 if (macroId
!= ltSUBSECTIONSTAR
)
947 if ( combineSubSections
&& !subsectionStarted
)
951 // Read old .con file in at this point
953 wxStrcpy(buf
, CurrentSectionFile
);
954 wxStripExtension(buf
);
955 wxStrcat(buf
, _T(".con"));
956 FILE *fd
= wxFopen(buf
, _T("r"));
962 wxPutc(ch
, Sections
);
967 wxFprintf(Sections
, _T("<P>\n"));
969 // Close old file, create a new file for the sub(sub)section contents entries
970 ReopenSectionContentsFile();
973 startedSections
= true;
974 subsectionStarted
= true;
976 wxChar
*topicName
= FindTopicName(GetNextChunk());
978 if ( !combineSubSections
)
980 SetCurrentOutput(NULL
);
981 ReopenFile(&Subsections
, &SubsectionsName
, topicName
);
982 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
983 SetCurrentSubsectionName(topicName
, SubsectionsName
);
984 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
985 SetCurrentOutput(Subsections
);
988 TexOutput(_T("<title>"));
989 OutputCurrentSection();
990 TexOutput(_T("</title></head>\n"));
993 wxFprintf(Subsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
994 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
995 lastTopic
, lastFileName
, // Last topic
996 topicName
, SubsectionsName
); // This topic
998 SetCurrentOutputs(Sections
, Subsections
);
999 if(PrimaryAnchorOfTheFile(SubsectionsName
, topicName
))
1000 wxFprintf(Sections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName
));
1002 wxFprintf(Sections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName
), topicName
);
1004 wxFprintf(Subsections
, _T("\n<H3>"));
1005 OutputCurrentSection();
1006 wxFprintf(Sections
, _T("</B></A><BR>\n"));
1007 wxFprintf(Subsections
, _T("</H3>\n"));
1009 SetCurrentOutput(Subsections
);
1013 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
1014 SetCurrentSubsectionName(topicName
, SectionsName
);
1016 // if ( subsectionNo != 0 )
1017 wxFprintf(Sections
, _T("\n<HR>\n"));
1019 // We're putting everything into the section file
1020 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1021 wxFprintf(Sections
, _T("\n<H3>"));
1022 OutputCurrentSection();
1023 wxFprintf(Sections
, _T("</H3>\n"));
1025 SetCurrentOutput(SectionContentsFD
);
1026 wxFprintf(SectionContentsFD
, _T("<A HREF=\"#%s\">"), topicName
);
1027 OutputCurrentSection();
1028 TexOutput(_T("</A><BR>\n"));
1030 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1031 SetCurrentOutput(Sections
);
1033 // Add this section title to the list of keywords
1036 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1037 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1044 case ltSUBSUBSECTION
:
1045 case ltSUBSUBSECTIONSTAR
:
1049 if (!Subsections
&& !combineSubSections
)
1051 OnError(_T("You cannot have a subsubsection before a subsection!"));
1055 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1058 startedSections
= true;
1060 wxChar
*topicName
= FindTopicName(GetNextChunk());
1062 if ( !combineSubSections
)
1064 SetCurrentOutput(NULL
);
1065 ReopenFile(&Subsubsections
, &SubsubsectionsName
, topicName
);
1066 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
1067 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
1068 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
1070 SetCurrentOutput(Subsubsections
);
1072 TexOutput(_T("<title>"));
1073 OutputCurrentSection();
1074 TexOutput(_T("</title></head>\n"));
1077 wxFprintf(Subsubsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1079 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
1080 lastTopic
, lastFileName
, // Last topic
1081 topicName
, SubsubsectionsName
); // This topic
1083 SetCurrentOutputs(Subsections
, Subsubsections
);
1084 if(PrimaryAnchorOfTheFile(SubsubsectionsName
, topicName
))
1085 wxFprintf(Subsections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName
));
1087 wxFprintf(Subsections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName
), topicName
);
1089 wxFprintf(Subsubsections
, _T("\n<H3>"));
1090 OutputCurrentSection();
1091 wxFprintf(Subsections
, _T("</B></A><BR>\n"));
1092 wxFprintf(Subsubsections
, _T("</H3>\n"));
1096 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
1097 SetCurrentSubsectionName(topicName
, SectionsName
);
1098 wxFprintf(Sections
, _T("\n<HR>\n"));
1100 // We're putting everything into the section file
1101 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1102 wxFprintf(Sections
, _T("\n<H3>"));
1103 OutputCurrentSection();
1104 wxFprintf(Sections
, _T("</H3>\n"));
1105 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1106 SetCurrentOutput(SectionContentsFD);
1107 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1108 OutputCurrentSection();
1109 TexOutput(_T("</A><BR>"));
1111 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1112 SetCurrentOutput(Sections
);
1115 // Add this section title to the list of keywords
1118 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1119 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1128 if ( !combineSubSections
)
1129 SetCurrentOutput(Subsections
);
1131 SetCurrentOutput(Sections
);
1142 if ( !combineSubSections
)
1143 SetCurrentOutput(Subsections
);
1145 SetCurrentOutput(Sections
);
1156 if ( !combineSubSections
)
1157 SetCurrentOutput(Subsections
);
1159 SetCurrentOutput(Sections
);
1170 // TexOutput(_T("<B>void</B>"));
1174 TexOutput(_T("HARDY"));
1178 TexOutput(_T("wxCLIPS"));
1182 TexOutput(_T("&"));
1184 case ltSPECIALAMPERSAND
:
1190 // End cell, start cell
1192 TexOutput(_T("</FONT></TD>"));
1194 // Start new row and cell, setting alignment for the first cell.
1195 if (currentColumn
< noColumns
)
1199 if (TableData
[currentColumn
].justification
== 'c')
1200 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=CENTER>"));
1201 else if (TableData
[currentColumn
].justification
== 'r')
1202 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=RIGHT>"));
1203 else if (TableData
[currentColumn
].absWidth
)
1205 // Convert from points * 20 into pixels.
1206 int points
= TableData
[currentColumn
].width
/ 20;
1208 // Say the display is 100 DPI (dots/pixels per inch).
1209 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1210 int pixels
= (int)(points
* 100.0 / 72.0);
1211 wxSnprintf(buf
, sizeof(buf
), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1214 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=LEFT>"));
1219 TexOutput(_T("&"));
1223 case ltBACKSLASHCHAR
:
1229 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1230 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1231 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1232 TexOutput(_T("</TR>\n"));
1235 TexOutput(_T("<BR>\n"));
1246 // Start new row and cell, setting alignment for the first cell.
1248 if (TableData
[currentColumn
].justification
== 'c')
1249 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER>"));
1250 else if (TableData
[currentColumn
].justification
== 'r')
1251 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=RIGHT>"));
1252 else if (TableData
[currentColumn
].absWidth
)
1254 // Convert from points * 20 into pixels.
1255 int points
= TableData
[currentColumn
].width
/ 20;
1257 // Say the display is 100 DPI (dots/pixels per inch).
1258 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1259 int pixels
= (int)(points
* 100.0 / 72.0);
1260 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1263 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=LEFT>"));
1270 // Start new row and cell
1271 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1275 // HTML-only: break until the end of the picture (both margins are clear).
1279 TexOutput(_T("<BR CLEAR=ALL>"));
1282 case ltRTFSP
: // Explicit space, RTF only
1284 case ltSPECIALTILDE
:
1288 #if (1) // if(inVerbatim)
1299 TexOutput(_T("<UL><UL>\n"));
1301 TexOutput(_T("</UL></UL>\n"));
1307 // case ltTWOCOLLIST:
1314 if (macroId
== ltENUMERATE
)
1315 listType
= LATEX_ENUMERATE
;
1316 else if (macroId
== ltITEMIZE
)
1317 listType
= LATEX_ITEMIZE
;
1319 listType
= LATEX_DESCRIPTION
;
1321 itemizeStack
.Insert(new ItemizeStruc(listType
));
1325 TexOutput(_T("<UL>\n"));
1327 case LATEX_ENUMERATE
:
1328 TexOutput(_T("<OL>\n"));
1330 case LATEX_DESCRIPTION
:
1332 TexOutput(_T("<DL>\n"));
1339 if (itemizeStack
.GetFirst())
1341 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
1342 switch (struc
->listType
)
1345 TexOutput(_T("</UL>\n"));
1347 case LATEX_ENUMERATE
:
1348 TexOutput(_T("</OL>\n"));
1350 case LATEX_DESCRIPTION
:
1352 TexOutput(_T("</DL>\n"));
1357 delete itemizeStack
.GetFirst();
1365 TexOutput(_T("\n<TABLE>\n"));
1367 TexOutput(_T("\n</TABLE>\n"));
1377 TexOutput(_T("<P>\n"));
1380 /* For footnotes we need to output the text at the bottom of the page and
1381 * insert a reference to it. Is it worth the trouble...
1383 case ltFOOTNOTEPOPUP:
1387 TexOutput(_T("<FN>"));
1389 else TexOutput(_T("</FN>"));
1396 TexOutput(_T("<TT>"));
1397 else TexOutput(_T("</TT>"));
1405 wxSnprintf(buf
, sizeof(buf
), _T("<PRE>\n"));
1408 else TexOutput(_T("</PRE>\n"));
1416 TexOutput(_T("<CENTER>"));
1418 else TexOutput(_T("</CENTER>"));
1426 TexOutput(_T("{\\ql "));
1428 else TexOutput(_T("}\\par\\pard\n"));
1437 TexOutput(_T("{\\qr "));
1439 else TexOutput(_T("}\\par\\pard\n"));
1447 // Netscape extension
1448 TexOutput(_T("<FONT SIZE=2>"));
1450 else TexOutput(_T("</FONT>"));
1457 // Netscape extension
1458 TexOutput(_T("<FONT SIZE=1>"));
1460 else TexOutput(_T("</FONT>"));
1467 // Netscape extension
1468 TexOutput(_T("<FONT SIZE=3>"));
1470 else TexOutput(_T("</FONT>"));
1477 // Netscape extension
1478 TexOutput(_T("<FONT SIZE=4>"));
1480 else TexOutput(_T("</FONT>"));
1487 // Netscape extension
1488 TexOutput(_T("<FONT SIZE=5>"));
1490 else TexOutput(_T("</FONT>"));
1497 // Netscape extension
1498 TexOutput(_T("<FONT SIZE=6>"));
1500 else TexOutput(_T("</FONT>"));
1509 TexOutput(_T("<B>"));
1511 else TexOutput(_T("</B>"));
1520 TexOutput(_T("<I>"));
1522 else TexOutput(_T("</I>"));
1530 TexOutput(_T("<EM>"));
1532 else TexOutput(_T("</EM>"));
1539 TexOutput(_T("<UL>"));
1541 else TexOutput(_T("</UL>"));
1550 TexOutput(_T("<TT>"));
1552 else TexOutput(_T("</TT>"));
1558 TexOutput(_T("©"), true);
1564 TexOutput(_T("®"), true);
1570 if (start
) TexOutput(_T("<--"));
1575 if (start
) TexOutput(_T("<=="));
1580 if (start
) TexOutput(_T("-->"));
1585 if (start
) TexOutput(_T("==>"));
1588 case ltLEFTRIGHTARROW
:
1590 if (start
) TexOutput(_T("<-->"));
1593 case ltLEFTRIGHTARROW2
:
1595 if (start
) TexOutput(_T("<==>"));
1608 wxNode
*node
= itemizeStack
.GetFirst();
1611 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
1612 struc
->currentItem
+= 1;
1613 if (struc
->listType
== LATEX_DESCRIPTION
)
1615 if (descriptionItemArg
)
1617 TexOutput(_T("<DT> "));
1618 TraverseChildrenFromChunk(descriptionItemArg
);
1619 TexOutput(_T("\n"));
1620 descriptionItemArg
= NULL
;
1622 TexOutput(_T("<DD>"));
1625 TexOutput(_T("<LI>"));
1632 if (start
&& DocumentTitle
&& DocumentAuthor
)
1634 // Add a special label for the contents page.
1635 // TexOutput(_T("<CENTER>\n"));
1636 TexOutput(_T("<A NAME=\"contents\">"));
1637 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1638 TraverseChildrenFromChunk(DocumentTitle
);
1639 TexOutput(_T("</H2>"));
1640 TexOutput(_T("<P>"));
1641 TexOutput(_T("</A>\n"));
1642 TexOutput(_T("<P>\n\n"));
1643 TexOutput(_T("<H3 ALIGN=CENTER>"));
1644 TraverseChildrenFromChunk(DocumentAuthor
);
1645 TexOutput(_T("</H3><P>\n\n"));
1648 TexOutput(_T("<H3 ALIGN=CENTER>"));
1649 TraverseChildrenFromChunk(DocumentDate
);
1650 TexOutput(_T("</H3><P>\n\n"));
1652 // TexOutput(_T("\n</CENTER>\n"));
1653 TexOutput(_T("\n<P><HR><P>\n"));
1656 // Now do optional frame contents page
1657 if (htmlFrameContents && FrameContents)
1659 SetCurrentOutput(FrameContents);
1661 // Add a special label for the contents page.
1662 TexOutput(_T("<CENTER>\n"));
1663 TexOutput(_T("<H3>\n"));
1664 TraverseChildrenFromChunk(DocumentTitle);
1665 TexOutput(_T("</H3>"));
1666 TexOutput(_T("<P>"));
1667 TexOutput(_T("</A>\n"));
1668 TexOutput(_T("<P>\n\n"));
1669 TexOutput(_T("<H3>"));
1670 TraverseChildrenFromChunk(DocumentAuthor);
1671 TexOutput(_T("</H3><P>\n\n"));
1674 TexOutput(_T("<H4>"));
1675 TraverseChildrenFromChunk(DocumentDate);
1676 TexOutput(_T("</H4><P>\n\n"));
1678 TexOutput(_T("\n</CENTER>\n"));
1679 TexOutput(_T("<P><HR><P>\n"));
1681 SetCurrentOutput(Titlepage);
1694 helpRefFilename
= NULL
;
1699 case ltBIBLIOGRAPHY
:
1703 DefaultOnMacro(macroId
, no_args
, start
);
1707 DefaultOnMacro(macroId
, no_args
, start
);
1708 TexOutput(_T("</DL>\n"));
1716 TexOutput(_T("<HR>\n"));
1724 TexOutput(_T("<HR>\n"));
1728 case ltTABLEOFCONTENTS
:
1732 // NB: if this is uncommented, the table of contents
1733 // completely disappears. If left commented, it's in the wrong
1735 //fflush(Titlepage);
1737 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1743 wxPutc(ch
, Titlepage
);
1751 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1752 OnInform(_T("Run Tex2RTF again to include contents page."));
1760 TexOutput(_T("<"));
1766 TexOutput(_T(">"));
1773 TexOutput(_T("<BLOCKQUOTE>"));
1775 TexOutput(_T("</BLOCKQUOTE>"));
1784 TexOutput(_T("\n<CAPTION>"));
1792 if (DocumentStyle
!= LATEX_ARTICLE
)
1793 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1795 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1801 if (DocumentStyle
!= LATEX_ARTICLE
)
1802 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1804 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1812 TexOutput(_T("\n</CAPTION>\n"));
1814 wxChar
*topicName
= FindTopicName(GetNextChunk());
1816 int n
= inFigure
? figureNo
: tableNo
;
1818 AddTexRef(topicName
, NULL
, NULL
,
1819 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1820 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1826 if (start
) TexOutput(_T("ß"));
1831 if (start
) inFigure
= true;
1832 else inFigure
= false;
1837 if (start
) inTable
= true;
1838 else inTable
= false;
1842 DefaultOnMacro(macroId
, no_args
, start
);
1848 should be called at of argument which usually is
1849 type declaration which propably contains name of
1858 checks: GetArgData() if contains Type Declaration
1859 and can be referenced to some file
1861 before<a href="xxx&yyy">type</a>after
1864 false - if no reference was found
1865 true - if reference was found and HREF printed
1867 static bool CheckTypeRef()
1869 wxString typeDecl
= GetArgData();
1870 if( !typeDecl
.empty() ) {
1871 typeDecl
.Replace(wxT("\\"),wxT(""));
1872 wxString label
= typeDecl
;
1873 label
.Replace(wxT("const"),wxT(""));
1874 label
.Replace(wxT("virtual"),wxT(""));
1875 label
.Replace(wxT("static"),wxT(""));
1876 label
.Replace(wxT("extern"),wxT(""));
1877 label
= label
.BeforeFirst('&');
1878 label
= label
.BeforeFirst(wxT('*'));
1879 label
= label
.BeforeFirst(wxT('\\'));
1880 label
.Trim(true); label
.Trim(false);
1881 wxString typeName
= label
;
1883 TexRef
*texRef
= FindReference(label
);
1885 if (texRef
&& texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0) {
1886 int a
= typeDecl
.Find(typeName
);
1887 wxString before
= typeDecl
.Mid( 0, a
);
1888 wxString after
= typeDecl
.Mid( a
+typeName
.Length() );
1889 //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"),
1891 // typeName.c_str(),
1893 // texRef->refFile,label.c_str());
1895 TexOutput(_T("<A HREF=\""));
1896 TexOutput(texRef
->refFile
);
1899 TexOutput(wxT("\">"));
1900 TexOutput(typeName
);
1901 TexOutput(wxT("</A>"));
1905 //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"),
1906 // typeName.c_str(),
1907 // typeDecl.c_str(),
1914 // Called on start/end of argument examination
1915 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1921 case ltCHAPTERHEADING
:
1924 case ltSECTIONHEADING
:
1926 case ltSUBSECTIONSTAR
:
1927 case ltSUBSUBSECTION
:
1928 case ltSUBSUBSECTIONSTAR
:
1930 case ltMEMBERSECTION
:
1931 case ltFUNCTIONSECTION
:
1933 if (!start
&& (arg_no
== 1))
1934 currentSection
= GetArgChunk();
1939 if (start
&& (arg_no
== 1)) {
1940 TexOutput(_T("<B>"));
1941 if( CheckTypeRef() ) {
1942 TexOutput(_T("</B> "));
1947 if (!start
&& (arg_no
== 1))
1948 TexOutput(_T("</B> "));
1950 if (start
&& (arg_no
== 2))
1952 if (!suppressNameDecoration
) TexOutput(_T("<B>"));
1953 currentMember
= GetArgChunk();
1955 if (!start
&& (arg_no
== 2))
1957 if (!suppressNameDecoration
) TexOutput(_T("</B>"));
1960 if (start
&& (arg_no
== 3))
1962 if (!start
&& (arg_no
== 3))
1968 if (start
&& (arg_no
== 1))
1969 TexOutput(_T("<B>"));
1970 if (!start
&& (arg_no
== 1))
1971 TexOutput(_T("</B> "));
1973 if (start
&& (arg_no
== 2))
1975 if (!suppressNameDecoration
) TexOutput(_T("( "));
1976 currentMember
= GetArgChunk();
1978 if (!start
&& (arg_no
== 2))
1982 if (!start
&& (arg_no
== 3))
1988 if (!start
&& (arg_no
== 1))
1991 if (start
&& (arg_no
== 2))
1992 TexOutput(_T("(*"));
1993 if (!start
&& (arg_no
== 2))
1996 if (start
&& (arg_no
== 2))
1997 currentMember
= GetArgChunk();
1999 if (start
&& (arg_no
== 3))
2001 if (!start
&& (arg_no
== 3))
2008 const wxChar
* pend
= macroId
== ltCPARAM
?
2009 _T("</B> ") : _T("</B>");
2012 TexOutput(_T("<B>"));
2013 if( CheckTypeRef() ) {
2021 if (start
&& (arg_no
== 2))
2023 TexOutput(_T("<I>"));
2025 if (!start
&& (arg_no
== 2))
2027 TexOutput(_T("</I>"));
2033 if (!start
&& (arg_no
== 1))
2036 if (start
&& (arg_no
== 2))
2037 currentMember
= GetArgChunk();
2046 wxChar
*refName
= GetArgData();
2049 TexRef
*texRef
= FindReference(refName
);
2052 sec
= texRef
->sectionNumber
;
2065 if (IsArgOptional())
2067 else if ((GetNoArgs() - arg_no
) == 1)
2070 helpRefText
= GetArgChunk();
2073 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2077 TexChunk
*ref
= GetArgChunk();
2078 TexOutput(_T("<A HREF=\""));
2080 TraverseChildrenFromChunk(ref
);
2082 TexOutput(_T("\">"));
2084 TraverseChildrenFromChunk(helpRefText
);
2085 TexOutput(_T("</A>"));
2096 if (IsArgOptional())
2099 helpRefFilename
= GetArgChunk();
2102 if ((GetNoArgs() - arg_no
) == 1)
2105 helpRefText
= GetArgChunk();
2108 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2112 wxChar
*refName
= GetArgData();
2113 wxChar
*refFilename
= NULL
;
2117 TexRef
*texRef
= FindReference(refName
);
2120 if (texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0)
2121 refFilename
= texRef
->refFile
;
2123 TexOutput(_T("<A HREF=\""));
2124 // If a filename is supplied, use it, otherwise try to
2125 // use the filename associated with the reference (from this document).
2126 if (helpRefFilename
)
2128 TraverseChildrenFromChunk(helpRefFilename
);
2132 else if (refFilename
)
2134 TexOutput(ConvertCase(refFilename
));
2135 if(!PrimaryAnchorOfTheFile(texRef
->refFile
, refName
))
2141 TexOutput(_T("\">"));
2143 TraverseChildrenFromChunk(helpRefText
);
2144 TexOutput(_T("</A>"));
2149 TraverseChildrenFromChunk(helpRefText
);
2151 TexOutput(_T(" (REF NOT FOUND)"));
2153 // for launching twice do not warn in preparation pass
2154 if ((passNumber
== 1 && !runTwice
) ||
2155 (passNumber
== 2 && runTwice
))
2158 errBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
2163 else TexOutput(_T("??"));
2178 wxChar
*alignment
= _T("");
2179 if (macroId
== ltIMAGEL
)
2180 alignment
= _T(" align=left");
2181 else if (macroId
== ltIMAGER
)
2182 alignment
= _T(" align=right");
2184 // Try to find an XBM or GIF image first.
2185 wxChar
*filename
= copystring(GetArgData());
2188 wxStrcpy(buf
, filename
);
2189 StripExtension(buf
);
2190 wxStrcat(buf
, _T(".xbm"));
2191 wxString f
= TexPathList
.FindValidPath(buf
);
2193 if (f
== _T("")) // Try for a GIF instead
2195 wxStrcpy(buf
, filename
);
2196 StripExtension(buf
);
2197 wxStrcat(buf
, _T(".gif"));
2198 f
= TexPathList
.FindValidPath(buf
);
2201 if (f
== _T("")) // Try for a JPEG instead
2203 wxStrcpy(buf
, filename
);
2204 StripExtension(buf
);
2205 wxStrcat(buf
, _T(".jpg"));
2206 f
= TexPathList
.FindValidPath(buf
);
2209 if (f
== _T("")) // Try for a PNG instead
2211 wxStrcpy(buf
, filename
);
2212 StripExtension(buf
);
2213 wxStrcat(buf
, _T(".png"));
2214 f
= TexPathList
.FindValidPath(buf
);
2219 wxChar
*inlineFilename
= copystring(f
);
2221 wxChar
*originalFilename
= TexPathList
.FindValidPath(filename
);
2222 // If we have found the existing filename, make the inline
2223 // image point to the original file (could be PS, for example)
2224 if (originalFilename
&& (wxStrcmp(inlineFilename
, originalFilename
) != 0))
2226 TexOutput(_T("<A HREF=\""));
2227 TexOutput(ConvertCase(originalFilename
));
2228 TexOutput(_T("\">"));
2229 TexOutput(_T("<img src=\""));
2230 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2231 TexOutput(_T("\""));
2232 TexOutput(alignment
);
2233 TexOutput(_T("></A>"));
2238 TexOutput(_T("<img src=\""));
2239 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2240 TexOutput(_T("\""));
2241 TexOutput(alignment
);
2243 delete[] inlineFilename
;
2248 // Last resort - a link to a PS file.
2249 TexOutput(_T("<A HREF=\""));
2250 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2251 TexOutput(_T("\">Picture</A>\n"));
2252 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2259 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2262 static wxChar
*imageFile
= NULL
;
2263 if (start
&& (arg_no
== 2))
2265 // Try to find an XBM or GIF image first.
2266 wxChar
*filename
= copystring(GetArgData());
2269 wxStrcpy(buf
, filename
);
2270 StripExtension(buf
);
2271 wxStrcat(buf
, _T(".xbm"));
2272 wxString f
= TexPathList
.FindValidPath(buf
);
2274 if (f
== _T("")) // Try for a GIF instead
2276 wxStrcpy(buf
, filename
);
2277 StripExtension(buf
);
2278 wxStrcat(buf
, _T(".gif"));
2279 f
= TexPathList
.FindValidPath(buf
);
2284 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2293 imageFile
= copystring(f
);
2296 else if (start
&& (arg_no
== 3))
2300 // First, try to find a .shg (segmented hypergraphics file)
2301 // that we can convert to a map file
2303 wxStrcpy(buf
, imageFile
);
2304 StripExtension(buf
);
2305 wxStrcat(buf
, _T(".shg"));
2306 wxString f
= TexPathList
.FindValidPath(buf
);
2310 // The default HTML file to go to is THIS file (so a no-op)
2311 SHGToMap(f
, currentFileName
);
2314 wxChar
*mapName
= GetArgData();
2315 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2319 TexOutput(_T("unknown"));
2320 TexOutput(_T("\">"));
2321 TexOutput(_T("<img src=\""));
2322 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2323 TexOutput(_T("\" ISMAP></A><P>"));
2343 descriptionItemArg
= GetArgChunk();
2349 case ltTWOCOLITEMRULED
:
2352 if (start && (arg_no == 1))
2353 TexOutput(_T("\n<DT> "));
2354 if (start && (arg_no == 2))
2355 TexOutput(_T("<DD> "));
2361 if (TwoColWidthA
> -1)
2364 wxSnprintf(buf
, sizeof(buf
), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA
);
2369 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2373 TexOutput(_T("\n</FONT></TD>\n"));
2380 if (TwoColWidthB
> -1)
2383 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB
);
2388 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2392 TexOutput(_T("\n</FONT></TD></TR>\n"));
2396 case ltNUMBEREDBIBITEM
:
2398 if (arg_no
== 1 && start
)
2400 TexOutput(_T("\n<DT> "));
2402 if (arg_no
== 2 && !start
)
2403 TexOutput(_T("<P>\n"));
2409 if (arg_no
== 1 && start
)
2411 wxChar
*citeKey
= GetArgData();
2412 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2415 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2416 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
2417 ref
->sectionNumber
= copystring(buf
);
2420 wxSnprintf(buf
, sizeof(buf
), _T("\n<DT> [%d] "), citeCount
);
2425 if (arg_no
== 2 && !start
)
2426 TexOutput(_T("<P>\n"));
2430 case ltMARGINPARODD
:
2431 case ltMARGINPAREVEN
:
2437 TexOutput(_T("<HR>\n"));
2441 TexOutput(_T("<HR><P>\n"));
2445 case ltTWOCOLWIDTHA
:
2449 wxChar
*val
= GetArgData();
2450 float points
= ParseUnitArgument(val
);
2451 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2456 case ltTWOCOLWIDTHB
:
2460 wxChar
*val
= GetArgData();
2461 float points
= ParseUnitArgument(val
);
2462 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2470 case ltACCENT_GRAVE
:
2474 wxChar
*val
= GetArgData();
2480 TexOutput(_T("à"));
2483 TexOutput(_T("è"));
2486 TexOutput(_T("ì"));
2489 TexOutput(_T("ò"));
2492 TexOutput(_T("ù"));
2495 TexOutput(_T("À"));
2498 TexOutput(_T("È"));
2501 TexOutput(_T("Ì"));
2504 TexOutput(_T("Ò"));
2507 TexOutput(_T("Ì"));
2516 case ltACCENT_ACUTE
:
2520 wxChar
*val
= GetArgData();
2526 TexOutput(_T("á"));
2529 TexOutput(_T("é"));
2532 TexOutput(_T("í"));
2535 TexOutput(_T("ó"));
2538 TexOutput(_T("ú"));
2541 TexOutput(_T("ý"));
2544 TexOutput(_T("Á"));
2547 TexOutput(_T("É"));
2550 TexOutput(_T("Í"));
2553 TexOutput(_T("Ó"));
2556 TexOutput(_T("Ú"));
2559 TexOutput(_T("Ý"));
2568 case ltACCENT_CARET
:
2572 wxChar
*val
= GetArgData();
2578 TexOutput(_T("â"));
2581 TexOutput(_T("ê"));
2584 TexOutput(_T("î"));
2587 TexOutput(_T("ô"));
2590 TexOutput(_T("û"));
2593 TexOutput(_T("Â"));
2596 TexOutput(_T("Ê"));
2599 TexOutput(_T("Î"));
2602 TexOutput(_T("Ô"));
2605 TexOutput(_T("Î"));
2614 case ltACCENT_TILDE
:
2618 wxChar
*val
= GetArgData();
2627 TexOutput(_T("ã"));
2630 TexOutput(_T("ñ"));
2633 TexOutput(_T("õ"));
2636 TexOutput(_T("Ã"));
2639 TexOutput(_T("Ñ"));
2642 TexOutput(_T("Õ"));
2651 case ltACCENT_UMLAUT
:
2655 wxChar
*val
= GetArgData();
2661 TexOutput(_T("ä"));
2664 TexOutput(_T("ë"));
2667 TexOutput(_T("ï"));
2670 TexOutput(_T("ö"));
2673 TexOutput(_T("ü"));
2676 TexOutput(_T("ÿ"));
2679 TexOutput(_T("Ä"));
2682 TexOutput(_T("Ë"));
2685 TexOutput(_T("Ï"));
2688 TexOutput(_T("Ö"));
2691 TexOutput(_T("Ü"));
2694 TexOutput(_T("Ÿ"));
2707 wxChar
*val
= GetArgData();
2713 TexOutput(_T("å"));
2716 TexOutput(_T("Å"));
2729 wxChar
*val
= GetArgData();
2732 bool isPicture
= false;
2733 ParseColourString(val
, &isPicture
);
2736 if (backgroundImageString
)
2737 delete[] backgroundImageString
;
2738 backgroundImageString
= copystring(val
);
2742 if (backgroundColourString
)
2743 delete[] backgroundColourString
;
2744 backgroundColourString
= copystring(val
);
2750 case ltBACKGROUNDIMAGE
:
2754 wxChar
*val
= GetArgData();
2757 if (backgroundImageString
)
2758 delete[] backgroundImageString
;
2759 backgroundImageString
= copystring(val
);
2764 case ltBACKGROUNDCOLOUR
:
2768 wxChar
*val
= GetArgData();
2771 if (backgroundColourString
)
2772 delete[] backgroundColourString
;
2773 backgroundColourString
= copystring(val
);
2782 wxChar
*val
= GetArgData();
2785 if (textColourString
)
2786 delete[] textColourString
;
2787 textColourString
= copystring(val
);
2796 wxChar
*val
= GetArgData();
2799 if (linkColourString
)
2800 delete[] linkColourString
;
2801 linkColourString
= copystring(val
);
2806 case ltFOLLOWEDLINKCOLOUR
:
2810 wxChar
*val
= GetArgData();
2813 if (followedLinkColourString
)
2814 delete[] followedLinkColourString
;
2815 followedLinkColourString
= copystring(val
);
2820 case ltACCENT_CADILLA
:
2824 wxChar
*val
= GetArgData();
2830 TexOutput(_T("ç"));
2833 TexOutput(_T("Ç"));
2844 case ltFOOTNOTEPOPUP:
2854 case ltSUPERTABULAR
:
2860 currentRowNumber
= 0;
2863 tableVerticalLineLeft
= false;
2864 tableVerticalLineRight
= false;
2866 wxChar
*alignString
= copystring(GetArgData());
2867 ParseTableArgument(alignString
);
2869 TexOutput(_T("<TABLE BORDER>\n"));
2871 // Write the first row formatting for compatibility
2872 // with standard Latex
2873 if (compatibilityMode
)
2875 TexOutput(_T("<TR>\n<TD>"));
2878 for (int i = 0; i < noColumns; i++)
2880 currentWidth += TableData[i].width;
2881 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2884 TexOutput(_T("\\pard\\intbl\n"));
2887 delete[] alignString
;
2892 else if (arg_no
== 2 && !start
)
2894 TexOutput(_T("</TABLE>\n"));
2899 case ltTHEBIBLIOGRAPHY
:
2901 if (start
&& (arg_no
== 1))
2903 ReopenFile(&Chapters
, &ChaptersName
, _T("bibliography"));
2904 AddTexRef(_T("bibliography"), ChaptersName
, _T("bibliography"));
2905 SetCurrentSubsectionName(_T("bibliography"), ChaptersName
);
2909 SetCurrentOutput(Chapters
);
2911 wxChar titleBuf
[150];
2912 if (truncateFilenames
)
2913 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
2915 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
2918 TexOutput(_T("<title>"));
2919 TexOutput(ReferencesNameString
);
2920 TexOutput(_T("</title></head>\n"));
2923 wxFprintf(Chapters
, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString
);
2924 AddBrowseButtons(_T("contents"), titleBuf
, // Up
2925 lastTopic
, lastFileName
, // Last topic
2926 _T("bibliography"), ChaptersName
); // This topic
2928 SetCurrentOutputs(Contents
, Chapters
);
2929 if(PrimaryAnchorOfTheFile(ChaptersName
, _T("bibliography")))
2930 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
2932 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), _T("bibliography"));
2934 wxFprintf(Contents
, _T("%s</A>\n"), ReferencesNameString
);
2935 wxFprintf(Chapters
, _T("</H2>\n</A>\n"));
2937 SetCurrentOutput(Chapters
);
2940 if (!start
&& (arg_no
== 2))
2947 /* Build up list of keywords associated with topics */
2950 // wxChar *entry = GetArgData();
2952 OutputChunkToString(GetArgChunk(), buf
);
2955 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2969 wxChar
*name
= GetArgData();
2971 if (!FindColourHTMLString(name
, buf2
))
2973 wxStrcpy(buf2
, _T("#000000"));
2975 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
2978 TexOutput(_T("<FONT COLOR=\""));
2980 TexOutput(_T("\">"));
2993 if (arg_no
== 2) TexOutput(_T("</FONT>"));
2997 case ltINSERTATLEVEL
:
2999 // This macro allows you to insert text at a different level
3000 // from the current level, e.g. into the Sections from within a subsubsection.
3003 static int currentLevelNo
= 1;
3004 static FILE* oldLevelFile
= Chapters
;
3011 oldLevelFile
= CurrentOutput1
;
3013 wxChar
*str
= GetArgData();
3014 currentLevelNo
= wxAtoi(str
);
3016 // TODO: cope with article style (no chapters)
3017 switch (currentLevelNo
)
3021 outputFile
= Chapters
;
3026 outputFile
= Sections
;
3031 outputFile
= Subsections
;
3036 outputFile
= Subsubsections
;
3046 CurrentOutput1
= outputFile
;
3062 CurrentOutput1
= oldLevelFile
;
3068 return DefaultOnArgument(macroId
, arg_no
, start
);
3080 tableVerticalLineLeft
= false;
3081 tableVerticalLineRight
= false;
3084 if (!InputFile
.empty() && !OutputFile
.empty())
3086 // Do some HTML-specific transformations on all the strings,
3088 Text2HTML(GetTopLevelChunk());
3091 if (truncateFilenames
)
3092 wxSnprintf(buf
, sizeof(buf
), _T("%s.htm"), FileRoot
);
3094 wxSnprintf(buf
, sizeof(buf
), _T("%s_contents.html"), FileRoot
);
3095 if (TitlepageName
) delete[] TitlepageName
;
3096 TitlepageName
= copystring(buf
);
3097 Titlepage
= wxFopen(buf
, _T("w"));
3099 if (truncateFilenames
)
3100 wxSnprintf(buf
, sizeof(buf
), _T("%s_fc.htm"), FileRoot
);
3102 wxSnprintf(buf
, sizeof(buf
), _T("%s_fcontents.html"), FileRoot
);
3104 contentsFrameName
= copystring(buf
);
3106 Contents
= wxFopen(TmpContentsName
, _T("w"));
3108 if (htmlFrameContents
)
3110 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
3111 FrameContents
= wxFopen(contentsFrameName
, _T("w"));
3112 wxFprintf(FrameContents
, _T("<HTML>\n<UL>\n"));
3115 if (!Titlepage
|| !Contents
)
3117 OnError(_T("Cannot open output file!"));
3120 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName
), ContentsNameString
);
3122 wxFprintf(Contents
, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString
);
3124 wxFprintf(Contents
, _T("<UL>\n"));
3126 SetCurrentOutput(Titlepage
);
3127 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
3128 OnInform(_T("Converting..."));
3131 wxFprintf(Contents
, _T("</UL>\n\n"));
3133 // SetCurrentOutput(Titlepage);
3138 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3145 wxFprintf(FrameContents
, _T("\n</UL>\n"));
3146 wxFprintf(FrameContents
, _T("</HTML>\n"));
3147 fclose(FrameContents
);
3148 FrameContents
= NULL
;
3153 wxFprintf(Chapters
, _T("\n</FONT></BODY></HTML>\n"));
3159 wxFprintf(Sections
, _T("\n</FONT></BODY></HTML>\n"));
3163 if (Subsections
&& !combineSubSections
)
3165 wxFprintf(Subsections
, _T("\n</FONT></BODY></HTML>\n"));
3166 fclose(Subsections
);
3169 if (Subsubsections
&& !combineSubSections
)
3171 wxFprintf(Subsubsections
, _T("\n</FONT></BODY></HTML>\n"));
3172 fclose(Subsubsections
);
3173 Subsubsections
= NULL
;
3175 if ( SectionContentsFD
)
3177 fclose(SectionContentsFD
);
3178 SectionContentsFD
= NULL
;
3181 // Create a temporary file for the title page header, add some info,
3182 // and concat the titlepage just generated.
3183 // This is necessary in order to put the title of the document
3184 // at the TOP of the file within <HEAD>, even though we only find out
3185 // what it is later on.
3186 FILE *tmpTitle
= wxFopen(_T("title.tmp"), _T("w"));
3191 SetCurrentOutput(tmpTitle
);
3193 TexOutput(_T("\n<TITLE>"));
3194 TraverseChildrenFromChunk(DocumentTitle
);
3195 TexOutput(_T("</TITLE></HEAD>\n"));
3199 SetCurrentOutput(tmpTitle
);
3200 HTMLHeadTo(tmpTitle
);
3202 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString
);
3204 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot
));
3207 // Output frame information
3208 if (htmlFrameContents
)
3210 wxChar firstFileName
[300];
3211 if (truncateFilenames
)
3212 wxSnprintf(firstFileName
, sizeof(firstFileName
), _T("%s1.htm"), FileRoot
);
3214 wxStrcpy(firstFileName
, gs_filenames
[1].c_str());
3216 wxFprintf(tmpTitle
, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3218 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3219 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName
)));
3220 wxFprintf(tmpTitle
, _T("</FRAMESET>\n"));
3222 wxFprintf(tmpTitle
, _T("<NOFRAMES>\n"));
3225 // Output <BODY...> to temporary title page
3230 FILE *fd
= wxFopen(TitlepageName
, _T("r"));
3236 wxPutc(ch
, tmpTitle
);
3242 wxFprintf(tmpTitle
, _T("\n</FONT></BODY>\n"));
3244 if (htmlFrameContents
)
3246 wxFprintf(tmpTitle
, _T("\n</NOFRAMES>\n"));
3248 wxFprintf(tmpTitle
, _T("\n</HTML>\n"));
3251 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3252 if (!wxRenameFile(_T("title.tmp"), TitlepageName
))
3254 wxCopyFile(_T("title.tmp"), TitlepageName
);
3255 wxRemoveFile(_T("title.tmp"));
3259 if (lastFileName
) delete[] lastFileName
;
3260 lastFileName
= NULL
;
3261 if (lastTopic
) delete[] lastTopic
;
3264 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3266 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3268 wxCopyFile(TmpContentsName
, ContentsName
);
3269 wxRemoveFile(TmpContentsName
);
3272 // Generate .htx file if requested
3275 wxChar htmlIndexName
[300];
3276 wxSnprintf(htmlIndexName
, sizeof(htmlIndexName
), _T("%s.htx"), FileRoot
);
3277 GenerateHTMLIndexFile(htmlIndexName
);
3280 // Generate HTML Help Workshop files if requested
3281 if (htmlWorkshopFiles
)
3283 HTMLWorkshopEndContents();
3284 GenerateHTMLWorkshopFiles(FileRoot
);
3293 // Output .htx index file
3294 void GenerateHTMLIndexFile(wxChar
*fname
)
3296 FILE *fd
= wxFopen(fname
, _T("w"));
3300 TopicTable
.BeginFind();
3301 wxHashTable::Node
*node
= TopicTable
.Next();
3304 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3305 const wxChar
*topicName
= node
->GetKeyString();
3306 if (texTopic
->filename
&& texTopic
->keywords
)
3308 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3311 wxChar
*s
= (wxChar
*)node1
->GetData();
3312 wxFprintf(fd
, _T("%s|%s|%s\n"), topicName
, texTopic
->filename
, s
);
3313 node1
= node1
->GetNext();
3316 node
= TopicTable
.Next();
3327 // output .hpp, .hhc and .hhk files:
3330 void GenerateHTMLWorkshopFiles(wxChar
*fname
)
3335 /* Generate project file : */
3337 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhp"), fname
);
3338 f
= wxFopen(buf
, _T("wt"));
3341 _T("Compatibility=1.1\n")
3342 _T("Full-text search=Yes\n")
3343 _T("Contents file=%s.hhc\n")
3344 _T("Compiled file=%s.chm\n")
3345 _T("Default Window=%sHelp\n")
3346 _T("Default topic=%s\n")
3347 _T("Index file=%s.hhk\n")
3349 wxFileNameFromPath(fname
),
3350 wxFileNameFromPath(fname
),
3351 wxFileNameFromPath(fname
),
3352 wxFileNameFromPath(TitlepageName
),
3353 wxFileNameFromPath(fname
)
3356 if (DocumentTitle
) {
3357 SetCurrentOutput(f
);
3358 TraverseChildrenFromChunk(DocumentTitle
);
3360 else wxFprintf(f
, _T("(unknown)"));
3362 wxFprintf(f
, _T("\n\n[WINDOWS]\n")
3363 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3364 wxFileNameFromPath(fname
),
3365 wxFileNameFromPath(fname
),
3366 wxFileNameFromPath(fname
),
3367 wxFileNameFromPath(TitlepageName
));
3370 wxFprintf(f
, _T("\n\n[FILES]\n"));
3371 wxFprintf(f
, _T("%s\n"), wxFileNameFromPath(TitlepageName
));
3372 for (int i
= 1; i
<= fileId
; i
++) {
3373 if (truncateFilenames
)
3374 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), wxFileNameFromPath(FileRoot
), i
);
3376 wxStrcpy(buf
, wxFileNameFromPath(gs_filenames
[i
].c_str()));
3377 wxFprintf(f
, _T("%s\n"), buf
);
3381 /* Generate index file : */
3383 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhk"), fname
);
3384 f
= wxFopen(buf
, _T("wt"));
3387 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3392 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3393 _T("<!-- Sitemap 1.0 -->\n")
3394 _T("</HEAD><BODY>\n")
3395 _T("<OBJECT type=\"text/site properties\">\n")
3396 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3400 TopicTable
.BeginFind();
3401 wxHashTable::Node
*node
= TopicTable
.Next();
3404 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3405 const wxChar
*topicName
= node
->GetKeyString();
3406 if (texTopic
->filename
&& texTopic
->keywords
)
3408 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3411 wxChar
*s
= (wxChar
*)node1
->GetData();
3413 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3414 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3415 _T(" <param name=\"Name\" value=\"%s\">\n")
3417 texTopic
->filename
, topicName
, s
);
3418 node1
= node1
->GetNext();
3421 node
= TopicTable
.Next();
3424 wxFprintf(f
, _T("</UL>\n"));
3430 static FILE *HTMLWorkshopContents
= NULL
;
3431 static int HTMLWorkshopLastLevel
= 0;
3433 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
)
3437 if (level
> HTMLWorkshopLastLevel
)
3438 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3439 wxFprintf(HTMLWorkshopContents
, _T("<UL>"));
3440 if (level
< HTMLWorkshopLastLevel
)
3441 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3442 wxFprintf(HTMLWorkshopContents
, _T("</UL>"));
3444 SetCurrentOutput(HTMLWorkshopContents
);
3445 wxFprintf(HTMLWorkshopContents
,
3446 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3447 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3448 _T(" <param name=\"Name\" value=\""),
3450 OutputCurrentSection();
3451 wxFprintf(HTMLWorkshopContents
,
3453 _T(" </OBJECT>\n"));
3454 HTMLWorkshopLastLevel
= level
;
3458 void HTMLWorkshopStartContents()
3461 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhc"), FileRoot
);
3462 HTMLWorkshopContents
= wxFopen(buf
, _T("wt"));
3463 HTMLWorkshopLastLevel
= 0;
3465 wxFprintf(HTMLWorkshopContents
,
3466 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3468 HTMLHeadTo(HTMLWorkshopContents
);
3469 wxFprintf(HTMLWorkshopContents
,
3471 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3472 _T("<!-- Sitemap 1.0 -->\n")
3473 _T("</HEAD><BODY>\n")
3474 _T("<OBJECT type=\"text/site properties\">\n")
3475 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3478 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3479 _T("<param name=\"Local\" value=\"%s\">\n")
3480 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3481 wxFileNameFromPath(TitlepageName
)
3487 void HTMLWorkshopEndContents()
3489 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3490 wxFprintf(HTMLWorkshopContents
, _T("</UL>\n"));
3491 fclose(HTMLWorkshopContents
);
3495 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
)
3497 wxString file_label
;
3498 file_label
.Printf( HTML_FILENAME_PATTERN
, FileRoot
, label
);
3499 return file_label
.IsSameAs( file
, false );