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 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/arrstr.h"
33 #define HTML_FILENAME_PATTERN _T("%s_%s.html")
35 #if !WXWIN_COMPATIBILITY_2_4
36 static inline wxChar
* copystring(const wxChar
* s
)
37 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
40 extern wxHashTable TexReferences
;
43 extern void DecToHex(int, wxChar
*);
44 void GenerateHTMLIndexFile(wxChar
*fname
);
46 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
);
48 void GenerateHTMLWorkshopFiles(wxChar
*fname
);
49 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
);
50 void HTMLWorkshopStartContents();
51 void HTMLWorkshopEndContents();
53 void OutputContentsFrame(void);
55 #include "readshg.h" // Segmented hypergraphics parsing
57 wxChar
*ChaptersName
= NULL
;
58 wxChar
*SectionsName
= NULL
;
59 wxChar
*SubsectionsName
= NULL
;
60 wxChar
*SubsubsectionsName
= NULL
;
61 wxChar
*TitlepageName
= NULL
;
62 wxChar
*lastFileName
= NULL
;
63 wxChar
*lastTopic
= NULL
;
64 wxChar
*currentFileName
= NULL
;
65 wxChar
*contentsFrameName
= NULL
;
67 static TexChunk
*descriptionItemArg
= NULL
;
68 static TexChunk
*helpRefFilename
= NULL
;
69 static TexChunk
*helpRefText
= NULL
;
70 static int indentLevel
= 0;
71 static int citeCount
= 1;
72 extern FILE *Contents
;
73 FILE *FrameContents
= NULL
;
74 FILE *Titlepage
= NULL
;
75 // FILE *FrameTitlepage = NULL;
77 bool subsectionStarted
= false;
79 // Which column of a row are we in? (Assumes no nested tables, of course)
80 int currentColumn
= 0;
82 // Are we in verbatim mode? If so, format differently.
83 static bool inVerbatim
= false;
85 // Need to know whether we're in a table or figure for benefit
86 // of listoffigures/listoftables
87 static bool inFigure
= false;
88 static bool inTable
= false;
90 // This is defined in the Tex2Any library.
91 extern wxChar
*BigBuffer
;
93 // DHS Two-column table dimensions.
94 static int TwoColWidthA
= -1;
95 static int TwoColWidthB
= -1;
98 class HyperReference
: public wxObject
103 HyperReference(wxChar
*name
, wxChar
*file
)
105 if (name
) refName
= copystring(name
);
106 if (file
) refFile
= copystring(file
);
110 class TexNextPage
: public wxObject
115 TexNextPage(wxChar
*theLabel
, wxChar
*theFile
)
117 label
= copystring(theLabel
);
118 filename
= copystring(theFile
);
127 wxHashTable
TexNextPages(wxKEY_STRING
);
129 static wxChar
*CurrentChapterName
= NULL
;
130 static wxChar
*CurrentChapterFile
= NULL
;
131 static wxChar
*CurrentSectionName
= NULL
;
132 static wxChar
*CurrentSectionFile
= NULL
;
133 static wxChar
*CurrentSubsectionName
= NULL
;
134 static wxChar
*CurrentSubsectionFile
= NULL
;
135 static wxChar
*CurrentSubsubsectionName
= NULL
;
136 static wxChar
*CurrentSubsubsectionFile
= NULL
;
137 static wxChar
*CurrentTopic
= NULL
;
139 static void SetCurrentTopic(wxChar
*s
)
141 if (CurrentTopic
) delete[] CurrentTopic
;
142 CurrentTopic
= copystring(s
);
145 void SetCurrentChapterName(wxChar
*s
, wxChar
*file
)
147 if (CurrentChapterName
) delete[] CurrentChapterName
;
148 CurrentChapterName
= copystring(s
);
149 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
150 CurrentChapterFile
= copystring(file
);
152 currentFileName
= CurrentChapterFile
;
156 void SetCurrentSectionName(wxChar
*s
, wxChar
*file
)
158 if (CurrentSectionName
) delete[] CurrentSectionName
;
159 CurrentSectionName
= copystring(s
);
160 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
161 CurrentSectionFile
= copystring(file
);
163 currentFileName
= CurrentSectionFile
;
166 void SetCurrentSubsectionName(wxChar
*s
, wxChar
*file
)
168 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
169 CurrentSubsectionName
= copystring(s
);
170 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
171 CurrentSubsectionFile
= copystring(file
);
172 currentFileName
= CurrentSubsectionFile
;
175 void SetCurrentSubsubsectionName(wxChar
*s
, wxChar
*file
)
177 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
178 CurrentSubsubsectionName
= copystring(s
);
179 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
180 CurrentSubsubsectionFile
= copystring(file
);
181 currentFileName
= CurrentSubsubsectionFile
;
186 // mapping between fileId and filenames if truncateFilenames=false:
187 static wxArrayString gs_filenames
;
191 * Close former filedescriptor and reopen using another filename.
195 void ReopenFile(FILE **fd
, wxChar
**fileName
, const wxChar
*label
)
199 wxFprintf(*fd
, _T("\n</FONT></BODY></HTML>\n"));
204 if (truncateFilenames
)
206 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), FileRoot
, fileId
);
211 gs_filenames
.Add(wxEmptyString
);
212 wxSnprintf(buf
, sizeof(buf
), HTML_FILENAME_PATTERN
, FileRoot
, label
);
213 gs_filenames
.Add(buf
);
215 if (*fileName
) delete[] *fileName
;
216 *fileName
= copystring(wxFileNameFromPath(buf
));
217 *fd
= wxFopen(buf
, _T("w"));
218 wxFprintf(*fd
, _T("<HTML>\n"));
222 * Reopen section contents file, i.e. the index appended to each section
223 * in subsectionCombine mode
226 static wxChar
*SectionContentsFilename
= NULL
;
227 static FILE *SectionContentsFD
= NULL
;
229 void ReopenSectionContentsFile(void)
231 if ( SectionContentsFD
)
233 fclose(SectionContentsFD
);
235 if ( SectionContentsFilename
)
236 delete[] SectionContentsFilename
;
237 SectionContentsFD
= NULL
;
238 SectionContentsFilename
= NULL
;
240 // Create the name from the current section filename
241 if ( CurrentSectionFile
)
244 wxStrcpy(buf
, CurrentSectionFile
);
245 wxStripExtension(buf
);
246 wxStrcat(buf
, _T(".con"));
247 SectionContentsFilename
= copystring(buf
);
249 SectionContentsFD
= wxFopen(SectionContentsFilename
, _T("w"));
255 * Given a TexChunk with a string value, scans through the string
256 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
260 void ProcessText2HTML(TexChunk
*chunk
)
262 bool changed
= false;
266 int len
= wxStrlen(chunk
->value
);
269 ch
= chunk
->value
[i
];
271 // 2 newlines means \par
272 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
273 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
274 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
276 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("<P>\n\n")); ptr
+= 5;
280 else if (!inVerbatim
&& ch
== _T('`') && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
282 BigBuffer
[ptr
] = '"'; ptr
++;
286 else if (!inVerbatim
&& ch
== _T('`')) // Change ` to '
288 BigBuffer
[ptr
] = 39; ptr
++;
292 else if (ch
== _T('<')) // Change < to <
295 wxStrcat(BigBuffer
, _T("<"));
300 else if (ch
== _T('>')) // Change > to >
303 wxStrcat(BigBuffer
, _T(">"));
320 chunk
->value
= copystring(BigBuffer
);
325 * Scan through all chunks starting from the given one,
326 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
327 * This should be called after Tex2Any has parsed the file,
328 * and before TraverseDocument is called.
332 void Text2HTML(TexChunk
*chunk
)
335 if (stopRunning
) return;
339 case CHUNK_TYPE_MACRO
:
341 TexMacroDef
*def
= chunk
->def
;
343 if (def
&& def
->ignore
)
346 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
349 wxNode
*node
= chunk
->children
.GetFirst();
352 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
353 Text2HTML(child_chunk
);
354 node
= node
->GetNext();
357 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
364 wxNode
*node
= chunk
->children
.GetFirst();
367 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
368 Text2HTML(child_chunk
);
369 node
= node
->GetNext();
374 case CHUNK_TYPE_STRING
:
377 ProcessText2HTML(chunk
);
384 * Add appropriate browse buttons to this page.
388 void AddBrowseButtons(wxChar
*upLabel
, wxChar
*upFilename
,
389 wxChar
*previousLabel
, wxChar
*previousFilename
,
390 wxChar
*thisLabel
, wxChar
*thisFilename
)
392 wxChar contentsReferenceBuf
[80];
393 wxChar upReferenceBuf
[80];
394 wxChar backReferenceBuf
[80];
395 wxChar forwardReferenceBuf
[80];
396 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
399 wxChar
*contentsReference
; // no need to initialize because always assigned below
400 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
401 contentsReference
= ContentsNameString
;
404 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
405 contentsReference
= contentsReferenceBuf
;
406 wxSnprintf(contentsReference
, sizeof(contentsReferenceBuf
),
407 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
408 ConvertCase(_T("contents.gif")));
411 wxChar
*upReference
; // no need to initialize because always assigned below
412 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
413 upReference
= UpNameString
;
416 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
417 upReference
= upReferenceBuf
;
418 wxSnprintf(upReference
, sizeof(upReferenceBuf
),
419 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
420 ConvertCase(_T("up.gif")));
423 wxChar
*backReference
; // no need to initialize because always assigned below
424 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
425 backReference
= _T("<<");
428 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
429 backReference
= backReferenceBuf
;
430 wxSnprintf(backReference
, sizeof(backReferenceBuf
),
431 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
432 ConvertCase(_T("back.gif")));
435 wxChar
*forwardReference
; // no need to initialize because always assigned below
436 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
437 forwardReference
= _T(">>");
440 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
441 forwardReference
= forwardReferenceBuf
;
442 wxSnprintf(forwardReference
, sizeof(forwardReferenceBuf
),
443 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
444 ConvertCase(_T("forward.gif")));
447 TexOutput(_T("<CENTER>"));
456 if (truncateFilenames
)
459 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
460 wxSnprintf(buf
, sizeof(buf
),
461 _T("\n<A HREF=\"%s.%s\">%s</A> "),
462 buf1
, ConvertCase(_T("htm")), contentsReference
);
467 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
468 wxSnprintf(buf
, sizeof(buf
),
469 _T("\n<A HREF=\"%s%s\">%s</A> "),
470 buf1
, ConvertCase(_T("_contents.html")), contentsReference
);
472 // TexOutput(_T("<NOFRAMES>"));
474 // TexOutput(_T("</NOFRAMES>"));
481 if (upLabel
&& upFilename
)
483 if ( (wxStrlen(upLabel
) > 0) && !PrimaryAnchorOfTheFile(upFilename
, upLabel
) )
484 wxSnprintf(buf
, sizeof(buf
),
485 _T("<A HREF=\"%s#%s\">%s</A> "),
486 ConvertCase(upFilename
), upLabel
, upReference
);
488 wxSnprintf(buf
, sizeof(buf
),
489 _T("<A HREF=\"%s\">%s</A> "),
490 ConvertCase(upFilename
), upReference
);
491 if (wxStrcmp(upLabel
, _T("contents")) == 0)
493 // TexOutput(_T("<NOFRAMES>"));
495 // TexOutput(_T("</NOFRAMES>"));
506 if (previousLabel
&& previousFilename
)
508 if (PrimaryAnchorOfTheFile(previousFilename
, previousLabel
))
509 wxSnprintf(buf
, sizeof(buf
),
510 _T("<A HREF=\"%s\">%s</A> "),
511 ConvertCase(previousFilename
), backReference
);
513 wxSnprintf(buf
, sizeof(buf
),
514 _T("<A HREF=\"%s#%s\">%s</A> "),
515 ConvertCase(previousFilename
), previousLabel
, backReference
);
516 if (wxStrcmp(previousLabel
, _T("contents")) == 0)
518 // TexOutput(_T("<NOFRAMES>"));
520 // TexOutput(_T("</NOFRAMES>"));
527 // A placeholder so the buttons don't keep moving position
528 wxSnprintf(buf
, sizeof(buf
), _T("%s "), backReference
);
532 wxChar
*nextLabel
= NULL
;
533 wxChar
*nextFilename
= NULL
;
535 // Get the next page, and record the previous page's 'next' page
537 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
540 nextLabel
= nextPage
->label
;
541 nextFilename
= nextPage
->filename
;
543 if (previousLabel
&& previousFilename
)
545 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
549 TexNextPages
.Delete(previousLabel
);
551 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
552 TexNextPages
.Put(previousLabel
, newNextPage
);
560 if (nextLabel
&& nextFilename
)
562 if (PrimaryAnchorOfTheFile(nextFilename
, nextLabel
))
563 wxSnprintf(buf
, sizeof(buf
),
564 _T("<A HREF=\"%s\">%s</A> "),
565 ConvertCase(nextFilename
), forwardReference
);
567 wxSnprintf(buf
, sizeof(buf
),
568 _T("<A HREF=\"%s#%s\">%s</A> "),
569 ConvertCase(nextFilename
), nextLabel
, forwardReference
);
574 // A placeholder so the buttons don't keep moving position
575 wxSnprintf(buf
, sizeof(buf
), _T("%s "), forwardReference
);
580 * Horizontal rule to finish it off nicely.
583 TexOutput(_T("</CENTER>"));
584 TexOutput(_T("<HR>\n"));
586 // Update last topic/filename
588 delete[] lastFileName
;
589 lastFileName
= copystring(thisFilename
);
592 lastTopic
= copystring(thisLabel
);
595 // A colour string is either 3 numbers separated by semicolons (RGB),
596 // or a reference to a GIF. Return the filename or a hex string like #934CE8
597 wxChar
*ParseColourString(wxChar
*bkStr
, bool *isPicture
)
599 static wxChar resStr
[300];
600 wxStrcpy(resStr
, bkStr
);
601 wxStringTokenizer
tok(resStr
, _T(";"), wxTOKEN_STRTOK
);
602 if (tok
.HasMoreTokens())
604 wxString token1
= tok
.GetNextToken();
605 if (!tok
.HasMoreTokens())
612 wxString token2
= tok
.GetNextToken();
614 if (tok
.HasMoreTokens())
616 wxString token3
= tok
.GetNextToken();
618 // Now convert 3 strings into decimal numbers, and then hex numbers.
619 int red
= wxAtoi(token1
.c_str());
620 int green
= wxAtoi(token2
.c_str());
621 int blue
= wxAtoi(token3
.c_str());
623 wxStrcpy(resStr
, _T("#"));
627 wxStrcat(resStr
, buf
);
628 DecToHex(green
, buf
);
629 wxStrcat(resStr
, buf
);
631 wxStrcat(resStr
, buf
);
640 void OutputFont(void)
642 // Only output <font face> if explicitly requested by htmlFaceName= directive in
643 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
647 // Output <FONT FACE=...>
648 TexOutput(_T("<FONT FACE=\""));
649 TexOutput(htmlFaceName
);
650 TexOutput(_T("\">\n"));
654 // Output start of <BODY> block
655 void OutputBodyStart(void)
657 TexOutput(_T("\n<BODY"));
658 if (backgroundImageString
)
660 bool isPicture
= false;
661 wxChar
*s
= ParseColourString(backgroundImageString
, &isPicture
);
664 TexOutput(_T(" BACKGROUND=\""));
669 if (backgroundColourString
)
671 bool isPicture
= false;
672 wxChar
*s
= ParseColourString(backgroundColourString
, &isPicture
);
675 TexOutput(_T(" BGCOLOR="));
680 // Set foreground text colour, if one is specified
681 if (textColourString
)
683 bool isPicture
= false;
684 wxChar
*s
= ParseColourString(textColourString
, &isPicture
);
687 TexOutput(_T(" TEXT=")); TexOutput(s
);
690 // Set link text colour, if one is specified
691 if (linkColourString
)
693 bool isPicture
= false;
694 wxChar
*s
= ParseColourString(linkColourString
, &isPicture
);
697 TexOutput(_T(" LINK=")); TexOutput(s
);
700 // Set followed link text colour, if one is specified
701 if (followedLinkColourString
)
703 bool isPicture
= false;
704 wxChar
*s
= ParseColourString(followedLinkColourString
, &isPicture
);
707 TexOutput(_T(" VLINK=")); TexOutput(s
);
710 TexOutput(_T(">\n"));
717 TexOutput(_T("<head>"));
718 if (htmlStylesheet
) {
719 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
720 TexOutput(htmlStylesheet
);
721 TexOutput(_T("\">"));
725 void HTMLHeadTo(FILE* f
)
728 wxFprintf(f
,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet
);
730 wxFprintf(f
,_T("<head>"));
733 // Called on start/end of macro examination
734 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
740 case ltCHAPTERHEADING
:
748 if (macroId
!= ltCHAPTERSTAR
)
751 SetCurrentOutput(NULL
);
752 startedSections
= true;
754 wxChar
*topicName
= FindTopicName(GetNextChunk());
755 ReopenFile(&Chapters
, &ChaptersName
, topicName
);
756 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
758 SetCurrentChapterName(topicName
, ChaptersName
);
759 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
761 SetCurrentOutput(Chapters
);
764 TexOutput(_T("<title>"));
765 OutputCurrentSection(); // Repeat section header
766 TexOutput(_T("</title></head>\n"));
769 wxChar titleBuf
[200];
770 if (truncateFilenames
)
771 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
773 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
775 wxFprintf(Chapters
, _T("<A NAME=\"%s\"></A>"), topicName
);
777 AddBrowseButtons(_T(""), titleBuf
, // Up
778 lastTopic
, lastFileName
, // Last topic
779 topicName
, ChaptersName
); // This topic
781 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
782 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
784 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), topicName
);
786 if (htmlFrameContents
&& FrameContents
)
788 SetCurrentOutput(FrameContents
);
789 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
790 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
));
792 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
), topicName
);
793 OutputCurrentSection();
794 wxFprintf(FrameContents
, _T("</A>\n"));
797 SetCurrentOutputs(Contents
, Chapters
);
798 wxFprintf(Chapters
, _T("\n<H2>"));
799 OutputCurrentSection();
800 wxFprintf(Contents
, _T("</A>\n"));
801 wxFprintf(Chapters
, _T("</H2>\n"));
803 SetCurrentOutput(Chapters
);
805 // Add this section title to the list of keywords
808 OutputCurrentSectionToString(wxTex2RTFBuffer
);
809 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
816 case ltSECTIONHEADING
:
823 subsectionStarted
= false;
825 if (macroId
!= ltSECTIONSTAR
)
828 SetCurrentOutput(NULL
);
829 startedSections
= true;
831 wxChar
*topicName
= FindTopicName(GetNextChunk());
832 ReopenFile(&Sections
, &SectionsName
, topicName
);
833 AddTexRef(topicName
, SectionsName
, SectionNameString
);
835 SetCurrentSectionName(topicName
, SectionsName
);
836 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
838 SetCurrentOutput(Sections
);
840 TexOutput(_T("<title>"));
841 OutputCurrentSection();
842 TexOutput(_T("</title></head>\n"));
845 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
846 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
847 lastTopic
, lastFileName
, // Last topic
848 topicName
, SectionsName
); // This topic
850 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
852 SetCurrentOutputs(jumpFrom
, Sections
);
853 if (DocumentStyle
== LATEX_ARTICLE
)
855 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
856 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName
));
858 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName
), topicName
);
862 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
863 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName
));
865 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName
), topicName
);
868 wxFprintf(Sections
, _T("\n<H2>"));
869 OutputCurrentSection();
871 if (DocumentStyle
== LATEX_ARTICLE
)
872 wxFprintf(jumpFrom
, _T("</A>\n"));
874 wxFprintf(jumpFrom
, _T("</B></A><BR>\n"));
875 wxFprintf(Sections
, _T("</H2>\n"));
877 SetCurrentOutput(Sections
);
878 // Add this section title to the list of keywords
881 OutputCurrentSectionToString(wxTex2RTFBuffer
);
882 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
888 case ltSUBSECTIONSTAR
:
889 case ltMEMBERSECTION
:
890 case ltFUNCTIONSECTION
:
896 OnError(_T("You cannot have a subsection before a section!"));
902 if (macroId
!= ltSUBSECTIONSTAR
)
905 if ( combineSubSections
&& !subsectionStarted
)
909 // Read old .con file in at this point
911 wxStrcpy(buf
, CurrentSectionFile
);
912 wxStripExtension(buf
);
913 wxStrcat(buf
, _T(".con"));
914 FILE *fd
= wxFopen(buf
, _T("r"));
920 wxPutc(ch
, Sections
);
925 wxFprintf(Sections
, _T("<P>\n"));
927 // Close old file, create a new file for the sub(sub)section contents entries
928 ReopenSectionContentsFile();
931 startedSections
= true;
932 subsectionStarted
= true;
934 wxChar
*topicName
= FindTopicName(GetNextChunk());
936 if ( !combineSubSections
)
938 SetCurrentOutput(NULL
);
939 ReopenFile(&Subsections
, &SubsectionsName
, topicName
);
940 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
941 SetCurrentSubsectionName(topicName
, SubsectionsName
);
942 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
943 SetCurrentOutput(Subsections
);
946 TexOutput(_T("<title>"));
947 OutputCurrentSection();
948 TexOutput(_T("</title></head>\n"));
951 wxFprintf(Subsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
952 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
953 lastTopic
, lastFileName
, // Last topic
954 topicName
, SubsectionsName
); // This topic
956 SetCurrentOutputs(Sections
, Subsections
);
957 if(PrimaryAnchorOfTheFile(SubsectionsName
, topicName
))
958 wxFprintf(Sections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName
));
960 wxFprintf(Sections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName
), topicName
);
962 wxFprintf(Subsections
, _T("\n<H3>"));
963 OutputCurrentSection();
964 wxFprintf(Sections
, _T("</B></A><BR>\n"));
965 wxFprintf(Subsections
, _T("</H3>\n"));
967 SetCurrentOutput(Subsections
);
971 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
972 SetCurrentSubsectionName(topicName
, SectionsName
);
974 // if ( subsectionNo != 0 )
975 wxFprintf(Sections
, _T("\n<HR>\n"));
977 // We're putting everything into the section file
978 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
979 wxFprintf(Sections
, _T("\n<H3>"));
980 OutputCurrentSection();
981 wxFprintf(Sections
, _T("</H3>\n"));
983 SetCurrentOutput(SectionContentsFD
);
984 wxFprintf(SectionContentsFD
, _T("<A HREF=\"#%s\">"), topicName
);
985 OutputCurrentSection();
986 TexOutput(_T("</A><BR>\n"));
988 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
989 SetCurrentOutput(Sections
);
991 // Add this section title to the list of keywords
994 OutputCurrentSectionToString(wxTex2RTFBuffer
);
995 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1002 case ltSUBSUBSECTION
:
1003 case ltSUBSUBSECTIONSTAR
:
1007 if (!Subsections
&& !combineSubSections
)
1009 OnError(_T("You cannot have a subsubsection before a subsection!"));
1013 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1016 startedSections
= true;
1018 wxChar
*topicName
= FindTopicName(GetNextChunk());
1020 if ( !combineSubSections
)
1022 SetCurrentOutput(NULL
);
1023 ReopenFile(&Subsubsections
, &SubsubsectionsName
, topicName
);
1024 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
1025 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
1026 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
1028 SetCurrentOutput(Subsubsections
);
1030 TexOutput(_T("<title>"));
1031 OutputCurrentSection();
1032 TexOutput(_T("</title></head>\n"));
1035 wxFprintf(Subsubsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1037 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
1038 lastTopic
, lastFileName
, // Last topic
1039 topicName
, SubsubsectionsName
); // This topic
1041 SetCurrentOutputs(Subsections
, Subsubsections
);
1042 if(PrimaryAnchorOfTheFile(SubsubsectionsName
, topicName
))
1043 wxFprintf(Subsections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName
));
1045 wxFprintf(Subsections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName
), topicName
);
1047 wxFprintf(Subsubsections
, _T("\n<H3>"));
1048 OutputCurrentSection();
1049 wxFprintf(Subsections
, _T("</B></A><BR>\n"));
1050 wxFprintf(Subsubsections
, _T("</H3>\n"));
1054 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
1055 SetCurrentSubsectionName(topicName
, SectionsName
);
1056 wxFprintf(Sections
, _T("\n<HR>\n"));
1058 // We're putting everything into the section file
1059 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1060 wxFprintf(Sections
, _T("\n<H3>"));
1061 OutputCurrentSection();
1062 wxFprintf(Sections
, _T("</H3>\n"));
1063 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1064 SetCurrentOutput(SectionContentsFD);
1065 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1066 OutputCurrentSection();
1067 TexOutput(_T("</A><BR>"));
1069 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1070 SetCurrentOutput(Sections
);
1073 // Add this section title to the list of keywords
1076 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1077 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1086 if ( !combineSubSections
)
1087 SetCurrentOutput(Subsections
);
1089 SetCurrentOutput(Sections
);
1100 if ( !combineSubSections
)
1101 SetCurrentOutput(Subsections
);
1103 SetCurrentOutput(Sections
);
1114 if ( !combineSubSections
)
1115 SetCurrentOutput(Subsections
);
1117 SetCurrentOutput(Sections
);
1128 // TexOutput(_T("<B>void</B>"));
1132 TexOutput(_T("HARDY"));
1136 TexOutput(_T("wxCLIPS"));
1140 TexOutput(_T("&"));
1142 case ltSPECIALAMPERSAND
:
1148 // End cell, start cell
1150 TexOutput(_T("</FONT></TD>"));
1152 // Start new row and cell, setting alignment for the first cell.
1153 if (currentColumn
< noColumns
)
1157 if (TableData
[currentColumn
].justification
== 'c')
1158 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=CENTER>"));
1159 else if (TableData
[currentColumn
].justification
== 'r')
1160 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=RIGHT>"));
1161 else if (TableData
[currentColumn
].absWidth
)
1163 // Convert from points * 20 into pixels.
1164 int points
= TableData
[currentColumn
].width
/ 20;
1166 // Say the display is 100 DPI (dots/pixels per inch).
1167 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1168 int pixels
= (int)(points
* 100.0 / 72.0);
1169 wxSnprintf(buf
, sizeof(buf
), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1172 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=LEFT>"));
1177 TexOutput(_T("&"));
1181 case ltBACKSLASHCHAR
:
1187 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1188 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1189 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1190 TexOutput(_T("</TR>\n"));
1193 TexOutput(_T("<BR>\n"));
1204 // Start new row and cell, setting alignment for the first cell.
1206 if (TableData
[currentColumn
].justification
== 'c')
1207 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER>"));
1208 else if (TableData
[currentColumn
].justification
== 'r')
1209 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=RIGHT>"));
1210 else if (TableData
[currentColumn
].absWidth
)
1212 // Convert from points * 20 into pixels.
1213 int points
= TableData
[currentColumn
].width
/ 20;
1215 // Say the display is 100 DPI (dots/pixels per inch).
1216 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1217 int pixels
= (int)(points
* 100.0 / 72.0);
1218 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1221 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=LEFT>"));
1228 // Start new row and cell
1229 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1233 // HTML-only: break until the end of the picture (both margins are clear).
1237 TexOutput(_T("<BR CLEAR=ALL>"));
1240 case ltRTFSP
: // Explicit space, RTF only
1242 case ltSPECIALTILDE
:
1246 #if (1) // if(inVerbatim)
1257 TexOutput(_T("<UL><UL>\n"));
1259 TexOutput(_T("</UL></UL>\n"));
1265 // case ltTWOCOLLIST:
1272 if (macroId
== ltENUMERATE
)
1273 listType
= LATEX_ENUMERATE
;
1274 else if (macroId
== ltITEMIZE
)
1275 listType
= LATEX_ITEMIZE
;
1277 listType
= LATEX_DESCRIPTION
;
1279 itemizeStack
.Insert(new ItemizeStruc(listType
));
1283 TexOutput(_T("<UL>\n"));
1285 case LATEX_ENUMERATE
:
1286 TexOutput(_T("<OL>\n"));
1288 case LATEX_DESCRIPTION
:
1290 TexOutput(_T("<DL>\n"));
1297 if (itemizeStack
.GetFirst())
1299 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
1300 switch (struc
->listType
)
1303 TexOutput(_T("</UL>\n"));
1305 case LATEX_ENUMERATE
:
1306 TexOutput(_T("</OL>\n"));
1308 case LATEX_DESCRIPTION
:
1310 TexOutput(_T("</DL>\n"));
1315 delete itemizeStack
.GetFirst();
1323 TexOutput(_T("\n<TABLE>\n"));
1325 TexOutput(_T("\n</TABLE>\n"));
1335 TexOutput(_T("<P>\n"));
1338 /* For footnotes we need to output the text at the bottom of the page and
1339 * insert a reference to it. Is it worth the trouble...
1341 case ltFOOTNOTEPOPUP:
1345 TexOutput(_T("<FN>"));
1347 else TexOutput(_T("</FN>"));
1354 TexOutput(_T("<TT>"));
1355 else TexOutput(_T("</TT>"));
1363 wxSnprintf(buf
, sizeof(buf
), _T("<PRE>\n"));
1366 else TexOutput(_T("</PRE>\n"));
1374 TexOutput(_T("<CENTER>"));
1376 else TexOutput(_T("</CENTER>"));
1384 TexOutput(_T("{\\ql "));
1386 else TexOutput(_T("}\\par\\pard\n"));
1395 TexOutput(_T("{\\qr "));
1397 else TexOutput(_T("}\\par\\pard\n"));
1405 // Netscape extension
1406 TexOutput(_T("<FONT SIZE=2>"));
1408 else TexOutput(_T("</FONT>"));
1415 // Netscape extension
1416 TexOutput(_T("<FONT SIZE=1>"));
1418 else TexOutput(_T("</FONT>"));
1425 // Netscape extension
1426 TexOutput(_T("<FONT SIZE=3>"));
1428 else TexOutput(_T("</FONT>"));
1435 // Netscape extension
1436 TexOutput(_T("<FONT SIZE=4>"));
1438 else TexOutput(_T("</FONT>"));
1445 // Netscape extension
1446 TexOutput(_T("<FONT SIZE=5>"));
1448 else TexOutput(_T("</FONT>"));
1455 // Netscape extension
1456 TexOutput(_T("<FONT SIZE=6>"));
1458 else TexOutput(_T("</FONT>"));
1467 TexOutput(_T("<B>"));
1469 else TexOutput(_T("</B>"));
1478 TexOutput(_T("<I>"));
1480 else TexOutput(_T("</I>"));
1488 TexOutput(_T("<EM>"));
1490 else TexOutput(_T("</EM>"));
1497 TexOutput(_T("<UL>"));
1499 else TexOutput(_T("</UL>"));
1508 TexOutput(_T("<TT>"));
1510 else TexOutput(_T("</TT>"));
1516 TexOutput(_T("©"), true);
1522 TexOutput(_T("®"), true);
1528 if (start
) TexOutput(_T("<--"));
1533 if (start
) TexOutput(_T("<=="));
1538 if (start
) TexOutput(_T("-->"));
1543 if (start
) TexOutput(_T("==>"));
1546 case ltLEFTRIGHTARROW
:
1548 if (start
) TexOutput(_T("<-->"));
1551 case ltLEFTRIGHTARROW2
:
1553 if (start
) TexOutput(_T("<==>"));
1566 wxNode
*node
= itemizeStack
.GetFirst();
1569 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
1570 struc
->currentItem
+= 1;
1571 if (struc
->listType
== LATEX_DESCRIPTION
)
1573 if (descriptionItemArg
)
1575 TexOutput(_T("<DT> "));
1576 TraverseChildrenFromChunk(descriptionItemArg
);
1577 TexOutput(_T("\n"));
1578 descriptionItemArg
= NULL
;
1580 TexOutput(_T("<DD>"));
1583 TexOutput(_T("<LI>"));
1590 if (start
&& DocumentTitle
&& DocumentAuthor
)
1592 // Add a special label for the contents page.
1593 // TexOutput(_T("<CENTER>\n"));
1594 TexOutput(_T("<A NAME=\"contents\">"));
1595 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1596 TraverseChildrenFromChunk(DocumentTitle
);
1597 TexOutput(_T("</H2>"));
1598 TexOutput(_T("<P>"));
1599 TexOutput(_T("</A>\n"));
1600 TexOutput(_T("<P>\n\n"));
1601 TexOutput(_T("<H3 ALIGN=CENTER>"));
1602 TraverseChildrenFromChunk(DocumentAuthor
);
1603 TexOutput(_T("</H3><P>\n\n"));
1606 TexOutput(_T("<H3 ALIGN=CENTER>"));
1607 TraverseChildrenFromChunk(DocumentDate
);
1608 TexOutput(_T("</H3><P>\n\n"));
1610 // TexOutput(_T("\n</CENTER>\n"));
1611 TexOutput(_T("\n<P><HR><P>\n"));
1614 // Now do optional frame contents page
1615 if (htmlFrameContents && FrameContents)
1617 SetCurrentOutput(FrameContents);
1619 // Add a special label for the contents page.
1620 TexOutput(_T("<CENTER>\n"));
1621 TexOutput(_T("<H3>\n"));
1622 TraverseChildrenFromChunk(DocumentTitle);
1623 TexOutput(_T("</H3>"));
1624 TexOutput(_T("<P>"));
1625 TexOutput(_T("</A>\n"));
1626 TexOutput(_T("<P>\n\n"));
1627 TexOutput(_T("<H3>"));
1628 TraverseChildrenFromChunk(DocumentAuthor);
1629 TexOutput(_T("</H3><P>\n\n"));
1632 TexOutput(_T("<H4>"));
1633 TraverseChildrenFromChunk(DocumentDate);
1634 TexOutput(_T("</H4><P>\n\n"));
1636 TexOutput(_T("\n</CENTER>\n"));
1637 TexOutput(_T("<P><HR><P>\n"));
1639 SetCurrentOutput(Titlepage);
1652 helpRefFilename
= NULL
;
1657 case ltBIBLIOGRAPHY
:
1661 DefaultOnMacro(macroId
, no_args
, start
);
1665 DefaultOnMacro(macroId
, no_args
, start
);
1666 TexOutput(_T("</DL>\n"));
1674 TexOutput(_T("<HR>\n"));
1682 TexOutput(_T("<HR>\n"));
1686 case ltTABLEOFCONTENTS
:
1690 // NB: if this is uncommented, the table of contents
1691 // completely disappears. If left commented, it's in the wrong
1693 //fflush(Titlepage);
1695 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1701 wxPutc(ch
, Titlepage
);
1709 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1710 OnInform(_T("Run Tex2RTF again to include contents page."));
1718 TexOutput(_T("<"));
1724 TexOutput(_T(">"));
1731 TexOutput(_T("<BLOCKQUOTE>"));
1733 TexOutput(_T("</BLOCKQUOTE>"));
1742 TexOutput(_T("\n<CAPTION>"));
1750 if (DocumentStyle
!= LATEX_ARTICLE
)
1751 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1753 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1759 if (DocumentStyle
!= LATEX_ARTICLE
)
1760 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1762 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1770 TexOutput(_T("\n</CAPTION>\n"));
1772 wxChar
*topicName
= FindTopicName(GetNextChunk());
1774 int n
= inFigure
? figureNo
: tableNo
;
1776 AddTexRef(topicName
, NULL
, NULL
,
1777 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1778 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1784 if (start
) TexOutput(_T("ß"));
1789 if (start
) inFigure
= true;
1790 else inFigure
= false;
1795 if (start
) inTable
= true;
1796 else inTable
= false;
1800 DefaultOnMacro(macroId
, no_args
, start
);
1806 should be called at of argument which usually is
1807 type declaration which propably contains name of
1816 checks: GetArgData() if contains Type Declaration
1817 and can be referenced to some file
1819 before<a href="xxx&yyy">type</a>after
1822 false - if no reference was found
1823 true - if reference was found and HREF printed
1825 static bool CheckTypeRef()
1827 wxString typeDecl
= GetArgData();
1828 if( !typeDecl
.IsEmpty() ) {
1829 typeDecl
.Replace(wxT("\\"),wxT(""));
1830 wxString label
= typeDecl
;
1831 label
.Replace(wxT("const"),wxT(""));
1832 label
.Replace(wxT("virtual"),wxT(""));
1833 label
.Replace(wxT("static"),wxT(""));
1834 label
.Replace(wxT("extern"),wxT(""));
1835 label
= label
.BeforeFirst('&');
1836 label
= label
.BeforeFirst(wxT('*'));
1837 label
= label
.BeforeFirst(wxT('\\'));
1838 label
.Trim(true); label
.Trim(false);
1839 wxString typeName
= label
;
1841 TexRef
*texRef
= FindReference((wxChar
*)label
.c_str());
1843 if (texRef
&& texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0) {
1844 int a
= typeDecl
.Find(typeName
);
1845 wxString before
= typeDecl
.Mid( 0, a
);
1846 wxString after
= typeDecl
.Mid( a
+typeName
.Length() );
1847 //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"),
1849 // typeName.c_str(),
1851 // texRef->refFile,label.c_str());
1853 TexOutput(_T("<A HREF=\""));
1854 TexOutput(texRef
->refFile
);
1857 TexOutput(wxT("\">"));
1858 TexOutput(typeName
);
1859 TexOutput(wxT("</A>"));
1863 //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"),
1864 // typeName.c_str(),
1865 // typeDecl.c_str(),
1872 // Called on start/end of argument examination
1873 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1879 case ltCHAPTERHEADING
:
1882 case ltSECTIONHEADING
:
1884 case ltSUBSECTIONSTAR
:
1885 case ltSUBSUBSECTION
:
1886 case ltSUBSUBSECTIONSTAR
:
1888 case ltMEMBERSECTION
:
1889 case ltFUNCTIONSECTION
:
1891 if (!start
&& (arg_no
== 1))
1892 currentSection
= GetArgChunk();
1897 if (start
&& (arg_no
== 1)) {
1898 TexOutput(_T("<B>"));
1899 if( CheckTypeRef() ) {
1900 TexOutput(_T("</B> "));
1905 if (!start
&& (arg_no
== 1))
1906 TexOutput(_T("</B> "));
1908 if (start
&& (arg_no
== 2))
1910 if (!suppressNameDecoration
) TexOutput(_T("<B>"));
1911 currentMember
= GetArgChunk();
1913 if (!start
&& (arg_no
== 2))
1915 if (!suppressNameDecoration
) TexOutput(_T("</B>"));
1918 if (start
&& (arg_no
== 3))
1920 if (!start
&& (arg_no
== 3))
1926 if (start
&& (arg_no
== 1))
1927 TexOutput(_T("<B>"));
1928 if (!start
&& (arg_no
== 1))
1929 TexOutput(_T("</B> "));
1931 if (start
&& (arg_no
== 2))
1933 if (!suppressNameDecoration
) TexOutput(_T("( "));
1934 currentMember
= GetArgChunk();
1936 if (!start
&& (arg_no
== 2))
1940 if (!start
&& (arg_no
== 3))
1946 if (!start
&& (arg_no
== 1))
1949 if (start
&& (arg_no
== 2))
1950 TexOutput(_T("(*"));
1951 if (!start
&& (arg_no
== 2))
1954 if (start
&& (arg_no
== 2))
1955 currentMember
= GetArgChunk();
1957 if (start
&& (arg_no
== 3))
1959 if (!start
&& (arg_no
== 3))
1966 const wxChar
* pend
= macroId
== ltCPARAM
?
1967 _T("</B> ") : _T("</B>");
1970 TexOutput(_T("<B>"));
1971 if( CheckTypeRef() ) {
1979 if (start
&& (arg_no
== 2))
1981 TexOutput(_T("<I>"));
1983 if (!start
&& (arg_no
== 2))
1985 TexOutput(_T("</I>"));
1991 if (!start
&& (arg_no
== 1))
1994 if (start
&& (arg_no
== 2))
1995 currentMember
= GetArgChunk();
2004 wxChar
*refName
= GetArgData();
2007 TexRef
*texRef
= FindReference(refName
);
2010 sec
= texRef
->sectionNumber
;
2023 if (IsArgOptional())
2025 else if ((GetNoArgs() - arg_no
) == 1)
2028 helpRefText
= GetArgChunk();
2031 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2035 TexChunk
*ref
= GetArgChunk();
2036 TexOutput(_T("<A HREF=\""));
2038 TraverseChildrenFromChunk(ref
);
2040 TexOutput(_T("\">"));
2042 TraverseChildrenFromChunk(helpRefText
);
2043 TexOutput(_T("</A>"));
2054 if (IsArgOptional())
2057 helpRefFilename
= GetArgChunk();
2060 if ((GetNoArgs() - arg_no
) == 1)
2063 helpRefText
= GetArgChunk();
2066 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2070 wxChar
*refName
= GetArgData();
2071 wxChar
*refFilename
= NULL
;
2075 TexRef
*texRef
= FindReference(refName
);
2078 if (texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0)
2079 refFilename
= texRef
->refFile
;
2081 TexOutput(_T("<A HREF=\""));
2082 // If a filename is supplied, use it, otherwise try to
2083 // use the filename associated with the reference (from this document).
2084 if (helpRefFilename
)
2086 TraverseChildrenFromChunk(helpRefFilename
);
2090 else if (refFilename
)
2092 TexOutput(ConvertCase(refFilename
));
2093 if(!PrimaryAnchorOfTheFile(texRef
->refFile
, refName
))
2099 TexOutput(_T("\">"));
2101 TraverseChildrenFromChunk(helpRefText
);
2102 TexOutput(_T("</A>"));
2107 TraverseChildrenFromChunk(helpRefText
);
2109 TexOutput(_T(" (REF NOT FOUND)"));
2111 errBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
2112 OnInform((wxChar
*)errBuf
.c_str());
2115 else TexOutput(_T("??"));
2130 wxChar
*alignment
= _T("");
2131 if (macroId
== ltIMAGEL
)
2132 alignment
= _T(" align=left");
2133 else if (macroId
== ltIMAGER
)
2134 alignment
= _T(" align=right");
2136 // Try to find an XBM or GIF image first.
2137 wxChar
*filename
= copystring(GetArgData());
2140 wxStrcpy(buf
, filename
);
2141 StripExtension(buf
);
2142 wxStrcat(buf
, _T(".xbm"));
2143 wxString f
= TexPathList
.FindValidPath(buf
);
2145 if (f
== _T("")) // Try for a GIF instead
2147 wxStrcpy(buf
, filename
);
2148 StripExtension(buf
);
2149 wxStrcat(buf
, _T(".gif"));
2150 f
= TexPathList
.FindValidPath(buf
);
2153 if (f
== _T("")) // Try for a JPEG instead
2155 wxStrcpy(buf
, filename
);
2156 StripExtension(buf
);
2157 wxStrcat(buf
, _T(".jpg"));
2158 f
= TexPathList
.FindValidPath(buf
);
2161 if (f
== _T("")) // Try for a PNG instead
2163 wxStrcpy(buf
, filename
);
2164 StripExtension(buf
);
2165 wxStrcat(buf
, _T(".png"));
2166 f
= TexPathList
.FindValidPath(buf
);
2171 wxChar
*inlineFilename
= copystring(f
);
2173 wxChar
*originalFilename
= TexPathList
.FindValidPath(filename
);
2174 // If we have found the existing filename, make the inline
2175 // image point to the original file (could be PS, for example)
2176 if (originalFilename
&& (wxStrcmp(inlineFilename
, originalFilename
) != 0))
2178 TexOutput(_T("<A HREF=\""));
2179 TexOutput(ConvertCase(originalFilename
));
2180 TexOutput(_T("\">"));
2181 TexOutput(_T("<img src=\""));
2182 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2183 TexOutput(_T("\""));
2184 TexOutput(alignment
);
2185 TexOutput(_T("></A>"));
2190 TexOutput(_T("<img src=\""));
2191 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2192 TexOutput(_T("\""));
2193 TexOutput(alignment
);
2195 delete[] inlineFilename
;
2200 // Last resort - a link to a PS file.
2201 TexOutput(_T("<A HREF=\""));
2202 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2203 TexOutput(_T("\">Picture</A>\n"));
2204 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2211 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2214 static wxChar
*imageFile
= NULL
;
2215 if (start
&& (arg_no
== 2))
2217 // Try to find an XBM or GIF image first.
2218 wxChar
*filename
= copystring(GetArgData());
2221 wxStrcpy(buf
, filename
);
2222 StripExtension(buf
);
2223 wxStrcat(buf
, _T(".xbm"));
2224 wxString f
= TexPathList
.FindValidPath(buf
);
2226 if (f
== _T("")) // Try for a GIF instead
2228 wxStrcpy(buf
, filename
);
2229 StripExtension(buf
);
2230 wxStrcat(buf
, _T(".gif"));
2231 f
= TexPathList
.FindValidPath(buf
);
2236 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2245 imageFile
= copystring(f
);
2248 else if (start
&& (arg_no
== 3))
2252 // First, try to find a .shg (segmented hypergraphics file)
2253 // that we can convert to a map file
2255 wxStrcpy(buf
, imageFile
);
2256 StripExtension(buf
);
2257 wxStrcat(buf
, _T(".shg"));
2258 wxString f
= TexPathList
.FindValidPath(buf
);
2262 // The default HTML file to go to is THIS file (so a no-op)
2263 SHGToMap((wxChar
*)f
.c_str(), currentFileName
);
2266 wxChar
*mapName
= GetArgData();
2267 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2271 TexOutput(_T("unknown"));
2272 TexOutput(_T("\">"));
2273 TexOutput(_T("<img src=\""));
2274 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2275 TexOutput(_T("\" ISMAP></A><P>"));
2295 descriptionItemArg
= GetArgChunk();
2301 case ltTWOCOLITEMRULED
:
2304 if (start && (arg_no == 1))
2305 TexOutput(_T("\n<DT> "));
2306 if (start && (arg_no == 2))
2307 TexOutput(_T("<DD> "));
2313 if (TwoColWidthA
> -1)
2316 wxSnprintf(buf
, sizeof(buf
), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA
);
2321 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2325 TexOutput(_T("\n</FONT></TD>\n"));
2332 if (TwoColWidthB
> -1)
2335 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB
);
2340 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2344 TexOutput(_T("\n</FONT></TD></TR>\n"));
2348 case ltNUMBEREDBIBITEM
:
2350 if (arg_no
== 1 && start
)
2352 TexOutput(_T("\n<DT> "));
2354 if (arg_no
== 2 && !start
)
2355 TexOutput(_T("<P>\n"));
2361 if (arg_no
== 1 && start
)
2363 wxChar
*citeKey
= GetArgData();
2364 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2367 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2368 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
2369 ref
->sectionNumber
= copystring(buf
);
2372 wxSnprintf(buf
, sizeof(buf
), _T("\n<DT> [%d] "), citeCount
);
2377 if (arg_no
== 2 && !start
)
2378 TexOutput(_T("<P>\n"));
2382 case ltMARGINPARODD
:
2383 case ltMARGINPAREVEN
:
2389 TexOutput(_T("<HR>\n"));
2393 TexOutput(_T("<HR><P>\n"));
2397 case ltTWOCOLWIDTHA
:
2401 wxChar
*val
= GetArgData();
2402 float points
= ParseUnitArgument(val
);
2403 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2408 case ltTWOCOLWIDTHB
:
2412 wxChar
*val
= GetArgData();
2413 float points
= ParseUnitArgument(val
);
2414 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2422 case ltACCENT_GRAVE
:
2426 wxChar
*val
= GetArgData();
2432 TexOutput(_T("à"));
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("Ì"));
2468 case ltACCENT_ACUTE
:
2472 wxChar
*val
= GetArgData();
2478 TexOutput(_T("á"));
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("Ý"));
2520 case ltACCENT_CARET
:
2524 wxChar
*val
= GetArgData();
2530 TexOutput(_T("â"));
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("Î"));
2566 case ltACCENT_TILDE
:
2570 wxChar
*val
= GetArgData();
2579 TexOutput(_T("ã"));
2582 TexOutput(_T("ñ"));
2585 TexOutput(_T("õ"));
2588 TexOutput(_T("Ã"));
2591 TexOutput(_T("Ñ"));
2594 TexOutput(_T("Õ"));
2603 case ltACCENT_UMLAUT
:
2607 wxChar
*val
= GetArgData();
2613 TexOutput(_T("ä"));
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("Ÿ"));
2659 wxChar
*val
= GetArgData();
2665 TexOutput(_T("å"));
2668 TexOutput(_T("Å"));
2681 wxChar
*val
= GetArgData();
2684 bool isPicture
= false;
2685 ParseColourString(val
, &isPicture
);
2688 if (backgroundImageString
)
2689 delete[] backgroundImageString
;
2690 backgroundImageString
= copystring(val
);
2694 if (backgroundColourString
)
2695 delete[] backgroundColourString
;
2696 backgroundColourString
= copystring(val
);
2702 case ltBACKGROUNDIMAGE
:
2706 wxChar
*val
= GetArgData();
2709 if (backgroundImageString
)
2710 delete[] backgroundImageString
;
2711 backgroundImageString
= copystring(val
);
2716 case ltBACKGROUNDCOLOUR
:
2720 wxChar
*val
= GetArgData();
2723 if (backgroundColourString
)
2724 delete[] backgroundColourString
;
2725 backgroundColourString
= copystring(val
);
2734 wxChar
*val
= GetArgData();
2737 if (textColourString
)
2738 delete[] textColourString
;
2739 textColourString
= copystring(val
);
2748 wxChar
*val
= GetArgData();
2751 if (linkColourString
)
2752 delete[] linkColourString
;
2753 linkColourString
= copystring(val
);
2758 case ltFOLLOWEDLINKCOLOUR
:
2762 wxChar
*val
= GetArgData();
2765 if (followedLinkColourString
)
2766 delete[] followedLinkColourString
;
2767 followedLinkColourString
= copystring(val
);
2772 case ltACCENT_CADILLA
:
2776 wxChar
*val
= GetArgData();
2782 TexOutput(_T("ç"));
2785 TexOutput(_T("Ç"));
2796 case ltFOOTNOTEPOPUP:
2806 case ltSUPERTABULAR
:
2812 currentRowNumber
= 0;
2815 tableVerticalLineLeft
= false;
2816 tableVerticalLineRight
= false;
2818 wxChar
*alignString
= copystring(GetArgData());
2819 ParseTableArgument(alignString
);
2821 TexOutput(_T("<TABLE BORDER>\n"));
2823 // Write the first row formatting for compatibility
2824 // with standard Latex
2825 if (compatibilityMode
)
2827 TexOutput(_T("<TR>\n<TD>"));
2830 for (int i = 0; i < noColumns; i++)
2832 currentWidth += TableData[i].width;
2833 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2836 TexOutput(_T("\\pard\\intbl\n"));
2839 delete[] alignString
;
2844 else if (arg_no
== 2 && !start
)
2846 TexOutput(_T("</TABLE>\n"));
2851 case ltTHEBIBLIOGRAPHY
:
2853 if (start
&& (arg_no
== 1))
2855 ReopenFile(&Chapters
, &ChaptersName
, _T("bibliography"));
2856 AddTexRef(_T("bibliography"), ChaptersName
, _T("bibliography"));
2857 SetCurrentSubsectionName(_T("bibliography"), ChaptersName
);
2861 SetCurrentOutput(Chapters
);
2863 wxChar titleBuf
[150];
2864 if (truncateFilenames
)
2865 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
2867 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
2870 TexOutput(_T("<title>"));
2871 TexOutput(ReferencesNameString
);
2872 TexOutput(_T("</title></head>\n"));
2875 wxFprintf(Chapters
, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString
);
2876 AddBrowseButtons(_T("contents"), titleBuf
, // Up
2877 lastTopic
, lastFileName
, // Last topic
2878 _T("bibliography"), ChaptersName
); // This topic
2880 SetCurrentOutputs(Contents
, Chapters
);
2881 if(PrimaryAnchorOfTheFile(ChaptersName
, _T("bibliography")))
2882 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
2884 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), _T("bibliography"));
2886 wxFprintf(Contents
, _T("%s</A>\n"), ReferencesNameString
);
2887 wxFprintf(Chapters
, _T("</H2>\n</A>\n"));
2889 SetCurrentOutput(Chapters
);
2892 if (!start
&& (arg_no
== 2))
2899 /* Build up list of keywords associated with topics */
2902 // wxChar *entry = GetArgData();
2904 OutputChunkToString(GetArgChunk(), buf
);
2907 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2921 wxChar
*name
= GetArgData();
2923 if (!FindColourHTMLString(name
, buf2
))
2925 wxStrcpy(buf2
, _T("#000000"));
2927 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
2930 TexOutput(_T("<FONT COLOR=\""));
2932 TexOutput(_T("\">"));
2945 if (arg_no
== 2) TexOutput(_T("</FONT>"));
2949 case ltINSERTATLEVEL
:
2951 // This macro allows you to insert text at a different level
2952 // from the current level, e.g. into the Sections from within a subsubsection.
2955 static int currentLevelNo
= 1;
2956 static FILE* oldLevelFile
= Chapters
;
2963 oldLevelFile
= CurrentOutput1
;
2965 wxChar
*str
= GetArgData();
2966 currentLevelNo
= wxAtoi(str
);
2968 // TODO: cope with article style (no chapters)
2969 switch (currentLevelNo
)
2973 outputFile
= Chapters
;
2978 outputFile
= Sections
;
2983 outputFile
= Subsections
;
2988 outputFile
= Subsubsections
;
2998 CurrentOutput1
= outputFile
;
3014 CurrentOutput1
= oldLevelFile
;
3020 return DefaultOnArgument(macroId
, arg_no
, start
);
3032 tableVerticalLineLeft
= false;
3033 tableVerticalLineRight
= false;
3036 if (InputFile
&& OutputFile
)
3038 // Do some HTML-specific transformations on all the strings,
3040 Text2HTML(GetTopLevelChunk());
3043 if (truncateFilenames
)
3044 wxSnprintf(buf
, sizeof(buf
), _T("%s.htm"), FileRoot
);
3046 wxSnprintf(buf
, sizeof(buf
), _T("%s_contents.html"), FileRoot
);
3047 if (TitlepageName
) delete[] TitlepageName
;
3048 TitlepageName
= copystring(buf
);
3049 Titlepage
= wxFopen(buf
, _T("w"));
3051 if (truncateFilenames
)
3052 wxSnprintf(buf
, sizeof(buf
), _T("%s_fc.htm"), FileRoot
);
3054 wxSnprintf(buf
, sizeof(buf
), _T("%s_fcontents.html"), FileRoot
);
3056 contentsFrameName
= copystring(buf
);
3058 Contents
= wxFopen(TmpContentsName
, _T("w"));
3060 if (htmlFrameContents
)
3062 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
3063 FrameContents
= wxFopen(contentsFrameName
, _T("w"));
3064 wxFprintf(FrameContents
, _T("<HTML>\n<UL>\n"));
3067 if (!Titlepage
|| !Contents
)
3069 OnError(_T("Cannot open output file!"));
3072 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName
), ContentsNameString
);
3074 wxFprintf(Contents
, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString
);
3076 wxFprintf(Contents
, _T("<UL>\n"));
3078 SetCurrentOutput(Titlepage
);
3079 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
3080 OnInform(_T("Converting..."));
3083 wxFprintf(Contents
, _T("</UL>\n\n"));
3085 // SetCurrentOutput(Titlepage);
3090 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3097 wxFprintf(FrameContents
, _T("\n</UL>\n"));
3098 wxFprintf(FrameContents
, _T("</HTML>\n"));
3099 fclose(FrameContents
);
3100 FrameContents
= NULL
;
3105 wxFprintf(Chapters
, _T("\n</FONT></BODY></HTML>\n"));
3111 wxFprintf(Sections
, _T("\n</FONT></BODY></HTML>\n"));
3115 if (Subsections
&& !combineSubSections
)
3117 wxFprintf(Subsections
, _T("\n</FONT></BODY></HTML>\n"));
3118 fclose(Subsections
);
3121 if (Subsubsections
&& !combineSubSections
)
3123 wxFprintf(Subsubsections
, _T("\n</FONT></BODY></HTML>\n"));
3124 fclose(Subsubsections
);
3125 Subsubsections
= NULL
;
3127 if ( SectionContentsFD
)
3129 fclose(SectionContentsFD
);
3130 SectionContentsFD
= NULL
;
3133 // Create a temporary file for the title page header, add some info,
3134 // and concat the titlepage just generated.
3135 // This is necessary in order to put the title of the document
3136 // at the TOP of the file within <HEAD>, even though we only find out
3137 // what it is later on.
3138 FILE *tmpTitle
= wxFopen(_T("title.tmp"), _T("w"));
3143 SetCurrentOutput(tmpTitle
);
3145 TexOutput(_T("\n<TITLE>"));
3146 TraverseChildrenFromChunk(DocumentTitle
);
3147 TexOutput(_T("</TITLE></HEAD>\n"));
3151 SetCurrentOutput(tmpTitle
);
3152 HTMLHeadTo(tmpTitle
);
3154 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString
);
3156 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot
));
3159 // Output frame information
3160 if (htmlFrameContents
)
3162 wxChar firstFileName
[300];
3163 if (truncateFilenames
)
3164 wxSnprintf(firstFileName
, sizeof(firstFileName
), _T("%s1.htm"), FileRoot
);
3166 wxStrcpy(firstFileName
, gs_filenames
[1].c_str());
3168 wxFprintf(tmpTitle
, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3170 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3171 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName
)));
3172 wxFprintf(tmpTitle
, _T("</FRAMESET>\n"));
3174 wxFprintf(tmpTitle
, _T("<NOFRAMES>\n"));
3177 // Output <BODY...> to temporary title page
3182 FILE *fd
= wxFopen(TitlepageName
, _T("r"));
3188 wxPutc(ch
, tmpTitle
);
3194 wxFprintf(tmpTitle
, _T("\n</FONT></BODY>\n"));
3196 if (htmlFrameContents
)
3198 wxFprintf(tmpTitle
, _T("\n</NOFRAMES>\n"));
3200 wxFprintf(tmpTitle
, _T("\n</HTML>\n"));
3203 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3204 if (!wxRenameFile(_T("title.tmp"), TitlepageName
))
3206 wxCopyFile(_T("title.tmp"), TitlepageName
);
3207 wxRemoveFile(_T("title.tmp"));
3211 if (lastFileName
) delete[] lastFileName
;
3212 lastFileName
= NULL
;
3213 if (lastTopic
) delete[] lastTopic
;
3216 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3218 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3220 wxCopyFile(TmpContentsName
, ContentsName
);
3221 wxRemoveFile(TmpContentsName
);
3224 // Generate .htx file if requested
3227 wxChar htmlIndexName
[300];
3228 wxSnprintf(htmlIndexName
, sizeof(htmlIndexName
), _T("%s.htx"), FileRoot
);
3229 GenerateHTMLIndexFile(htmlIndexName
);
3232 // Generate HTML Help Workshop files if requested
3233 if (htmlWorkshopFiles
)
3235 HTMLWorkshopEndContents();
3236 GenerateHTMLWorkshopFiles(FileRoot
);
3246 // Output .htx index file
3247 void GenerateHTMLIndexFile(wxChar
*fname
)
3249 FILE *fd
= wxFopen(fname
, _T("w"));
3253 TopicTable
.BeginFind();
3254 wxHashTable::Node
*node
= TopicTable
.Next();
3257 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3258 const wxChar
*topicName
= node
->GetKeyString();
3259 if (texTopic
->filename
&& texTopic
->keywords
)
3261 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3264 wxChar
*s
= (wxChar
*)node1
->GetData();
3265 wxFprintf(fd
, _T("%s|%s|%s\n"), topicName
, texTopic
->filename
, s
);
3266 node1
= node1
->GetNext();
3269 node
= TopicTable
.Next();
3280 // output .hpp, .hhc and .hhk files:
3283 void GenerateHTMLWorkshopFiles(wxChar
*fname
)
3288 /* Generate project file : */
3290 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhp"), fname
);
3291 f
= wxFopen(buf
, _T("wt"));
3294 _T("Compatibility=1.1\n")
3295 _T("Full-text search=Yes\n")
3296 _T("Contents file=%s.hhc\n")
3297 _T("Compiled file=%s.chm\n")
3298 _T("Default Window=%sHelp\n")
3299 _T("Default topic=%s\n")
3300 _T("Index file=%s.hhk\n")
3302 wxFileNameFromPath(fname
),
3303 wxFileNameFromPath(fname
),
3304 wxFileNameFromPath(fname
),
3305 wxFileNameFromPath(TitlepageName
),
3306 wxFileNameFromPath(fname
)
3309 if (DocumentTitle
) {
3310 SetCurrentOutput(f
);
3311 TraverseChildrenFromChunk(DocumentTitle
);
3313 else wxFprintf(f
, _T("(unknown)"));
3315 wxFprintf(f
, _T("\n\n[WINDOWS]\n")
3316 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3317 wxFileNameFromPath(fname
),
3318 wxFileNameFromPath(fname
),
3319 wxFileNameFromPath(fname
),
3320 wxFileNameFromPath(TitlepageName
));
3323 wxFprintf(f
, _T("\n\n[FILES]\n"));
3324 wxFprintf(f
, _T("%s\n"), wxFileNameFromPath(TitlepageName
));
3325 for (int i
= 1; i
<= fileId
; i
++) {
3326 if (truncateFilenames
)
3327 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), wxFileNameFromPath(FileRoot
), i
);
3329 wxStrcpy(buf
, wxFileNameFromPath(gs_filenames
[i
].c_str()));
3330 wxFprintf(f
, _T("%s\n"), buf
);
3334 /* Generate index file : */
3336 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhk"), fname
);
3337 f
= wxFopen(buf
, _T("wt"));
3340 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3345 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3346 _T("<!-- Sitemap 1.0 -->\n")
3347 _T("</HEAD><BODY>\n")
3348 _T("<OBJECT type=\"text/site properties\">\n")
3349 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3353 TopicTable
.BeginFind();
3354 wxHashTable::Node
*node
= TopicTable
.Next();
3357 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3358 const wxChar
*topicName
= node
->GetKeyString();
3359 if (texTopic
->filename
&& texTopic
->keywords
)
3361 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3364 wxChar
*s
= (wxChar
*)node1
->GetData();
3366 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3367 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3368 _T(" <param name=\"Name\" value=\"%s\">\n")
3370 texTopic
->filename
, topicName
, s
);
3371 node1
= node1
->GetNext();
3374 node
= TopicTable
.Next();
3377 wxFprintf(f
, _T("</UL>\n"));
3383 static FILE *HTMLWorkshopContents
= NULL
;
3384 static int HTMLWorkshopLastLevel
= 0;
3386 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
)
3390 if (level
> HTMLWorkshopLastLevel
)
3391 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3392 wxFprintf(HTMLWorkshopContents
, _T("<UL>"));
3393 if (level
< HTMLWorkshopLastLevel
)
3394 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3395 wxFprintf(HTMLWorkshopContents
, _T("</UL>"));
3397 SetCurrentOutput(HTMLWorkshopContents
);
3398 wxFprintf(HTMLWorkshopContents
,
3399 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3400 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3401 _T(" <param name=\"Name\" value=\""),
3403 OutputCurrentSection();
3404 wxFprintf(HTMLWorkshopContents
,
3406 _T(" </OBJECT>\n"));
3407 HTMLWorkshopLastLevel
= level
;
3411 void HTMLWorkshopStartContents()
3414 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhc"), FileRoot
);
3415 HTMLWorkshopContents
= wxFopen(buf
, _T("wt"));
3416 HTMLWorkshopLastLevel
= 0;
3418 wxFprintf(HTMLWorkshopContents
,
3419 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3421 HTMLHeadTo(HTMLWorkshopContents
);
3422 wxFprintf(HTMLWorkshopContents
,
3424 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3425 _T("<!-- Sitemap 1.0 -->\n")
3426 _T("</HEAD><BODY>\n")
3427 _T("<OBJECT type=\"text/site properties\">\n")
3428 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3431 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3432 _T("<param name=\"Local\" value=\"%s\">\n")
3433 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3434 wxFileNameFromPath(TitlepageName
)
3440 void HTMLWorkshopEndContents()
3442 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3443 wxFprintf(HTMLWorkshopContents
, _T("</UL>\n"));
3444 fclose(HTMLWorkshopContents
);
3448 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
)
3450 wxString file_label
;
3451 file_label
.Printf( HTML_FILENAME_PATTERN
, FileRoot
, label
);
3452 return file_label
.IsSameAs( file
, false );