1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to Word RTF/WinHelp RTF
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
39 #if !WXWIN_COMPATIBILITY_2_4
40 static inline wxChar
* copystring(const wxChar
* s
)
41 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
45 static int indentLevel
= 0;
46 static int forbidParindent
= 0; // if > 0, no parindent (e.g. in center environment)
47 int forbidResetPar
= 0; // If > 0, don't reset memory of having output a new par
49 static wxChar
*contentsLineSection
= NULL
;
50 static wxChar
*contentsLineValue
= NULL
;
51 static TexChunk
*descriptionItemArg
= NULL
;
52 static wxStringList environmentStack
; // Stack of paragraph styles we need to remember
53 static int footnoteCount
= 0;
54 static int citeCount
= 1;
56 extern bool startedSections
;
57 extern FILE *Contents
;
58 extern FILE *Chapters
;
60 extern FILE *WinHelpContentsFile
;
61 extern wxChar
*RTFCharset
;
62 // This is defined in the Tex2Any library and isn't in use after parsing
63 extern wxChar
*BigBuffer
;
65 extern wxHashTable TexReferences
;
67 // Are we in verbatim mode? If so, format differently.
68 static bool inVerbatim
= FALSE
;
70 // We're in a series of PopRef topics, so don't output section headings
71 bool inPopRefSection
= FALSE
;
74 static bool hotSpotColour
= TRUE
;
75 static bool hotSpotUnderline
= TRUE
;
77 // Transparency (WHITE = transparent)
78 static bool bitmapTransparency
= TRUE
;
80 // Linear RTF requires us to set the style per section.
81 static wxChar
*currentNumberStyle
= NULL
;
82 static int currentItemSep
= 8;
83 static int CurrentTextWidth
= 8640; // Say, six inches
84 static int CurrentLeftMarginOdd
= 400;
85 static int CurrentLeftMarginEven
= 1440;
86 static int CurrentRightMarginOdd
= 1440;
87 static int CurrentRightMarginEven
= 400;
88 static int CurrentMarginParWidth
= 2000;
89 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
90 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
91 static int GutterWidth
= 2300;
93 // Two-column table dimensions, in twips
94 static int TwoColWidthA
= 1500;
95 static int TwoColWidthB
= 3000;
97 const int PageWidth
= 12242; // 8.25 inches wide for A4
99 // Remember the anchor in a helpref
100 static TexChunk
*helpRefText
= NULL
;
103 * Flag to say we've just issued a \par\pard command, so don't
104 * repeat this unnecessarily.
108 int issuedNewParagraph
= 0;
110 // Need to know whether we're in a table or figure for benefit
111 // of listoffigures/listoftables
112 static bool inFigure
= FALSE
;
113 static bool inTable
= FALSE
;
119 static wxChar
*CurrentChapterName
= NULL
;
120 static wxChar
*CurrentSectionName
= NULL
;
121 static wxChar
*CurrentSubsectionName
= NULL
;
122 static wxChar
*CurrentTopic
= NULL
;
124 static bool InPopups()
126 if (CurrentChapterName
&& (wxStrcmp(CurrentChapterName
, _T("popups")) == 0))
128 if (CurrentSectionName
&& (wxStrcmp(CurrentSectionName
, _T("popups")) == 0))
133 static void SetCurrentTopic(wxChar
*s
)
135 if (CurrentTopic
) delete[] CurrentTopic
;
136 CurrentTopic
= copystring(s
);
139 void SetCurrentChapterName(wxChar
*s
)
141 if (CurrentChapterName
) delete[] CurrentChapterName
;
142 CurrentChapterName
= copystring(s
);
145 void SetCurrentSectionName(wxChar
*s
)
147 if (CurrentSectionName
) delete[] CurrentSectionName
;
148 CurrentSectionName
= copystring(s
);
151 void SetCurrentSubsectionName(wxChar
*s
)
153 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
154 CurrentSubsectionName
= copystring(s
);
158 // Indicate that a parent topic at level 'level' has children.
159 // Level 1 is a chapter, 2 is a section, etc.
160 void NotifyParentHasChildren(int parentLevel
)
162 wxChar
*parentTopic
= NULL
;
167 parentTopic
= CurrentChapterName
;
172 parentTopic
= CurrentSectionName
;
177 parentTopic
= CurrentSubsectionName
;
187 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
190 texTopic
= new TexTopic
;
191 TopicTable
.Put(parentTopic
, texTopic
);
193 texTopic
->hasChildren
= TRUE
;
197 // Have to keep a count of what levels are books, what are pages,
198 // in order to correct for a Win95 bug which means that if you
199 // have a book at level n, and then a page at level n, the page
200 // ends up on level n + 1.
202 bool ContentsLevels
[5];
204 // Reset below this level (starts from 1)
205 void ResetContentsLevels(int l
)
208 for (i
= l
; i
< 5; i
++)
209 ContentsLevels
[i
] = FALSE
;
211 // There are always books on the top level
212 ContentsLevels
[0] = TRUE
;
215 // Output a WinHelp section as a keyword, substituting
217 void OutputSectionKeyword(FILE *fd
)
219 OutputCurrentSectionToString(wxTex2RTFBuffer
);
222 for (i
= 0; i
< wxStrlen(wxTex2RTFBuffer
); i
++)
223 if (wxTex2RTFBuffer
[i
] == ':')
224 wxTex2RTFBuffer
[i
] = ' ';
225 // Don't write to index if there's some RTF in the string
226 else if ( wxTex2RTFBuffer
[i
] == '{' )
229 wxFprintf(fd
, _T("K{\\footnote {K} "));
230 wxFprintf(fd
, _T("%s"), wxTex2RTFBuffer
);
232 wxFprintf(fd
, _T("}\n"));
235 // Write a line for the .cnt file, if we're doing this.
236 void WriteWinHelpContentsFileLine(wxChar
*topicName
, wxChar
*xitle
, int level
)
238 // First, convert any RTF characters to ASCII
242 while ( (xitle
[s
]!=0)&&(d
<255) )
244 wxChar ch
=xitle
[s
]&0xff;
246 wxChar ch1
=xitle
[s
+1]&0xff;
247 wxChar ch2
=xitle
[s
+2]&0xff;
248 wxChar ch3
=xitle
[s
+3]&0xff;
249 s
+=4; // next character
250 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]='ö'; }
251 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]='ä'; }
252 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]='ü'; }
253 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]='Ö'; }
254 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]='Ä'; }
255 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]='Ü'; }
263 // Section (2) becomes level 1 if it's an article.
264 if (DocumentStyle
== LATEX_ARTICLE
)
267 if (level
== 0) // Means we had a Chapter in an article, oops.
270 ResetContentsLevels(level
);
275 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
277 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
280 // If a previous section at this level was a book, we *have* to have a
281 // book not a page, because of a bug in WHC (or WinHelp 4).
282 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
284 // At this level, we have a pointer to a further hierarchy.
285 // So we need a 'book' consisting of (say) Chapter 1.
286 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
288 // Then we have a 'page' consisting of the text for this chapter
289 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
291 // Then we'll be writing out further pages or books at level + 1...
293 // Remember that at this level, we had a book and *must* for the
294 // remainder of sections at this level.
295 ContentsLevels
[level
-1] = TRUE
;
299 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
304 if (level
== 1 || ContentsLevels
[level
-1])
306 // Always have a book at level 1
307 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
308 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
309 ContentsLevels
[level
-1] = TRUE
;
312 // Probably doesn't have children if it hasn't been added to the topic table
313 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
318 void SplitIndexEntry(wxChar
*entry
, wxChar
*buf1
, wxChar
*buf2
)
320 int len
= wxStrlen(entry
); int i
= 0;
321 while ((i
< len
) && entry
[i
] != '!')
322 { buf1
[i
] = entry
[i
]; i
++; }
323 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
328 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
334 * Output topic index entries in WinHelp RTF
337 void GenerateKeywordsForTopic(wxChar
*topic
)
339 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
343 wxStringList
*list
= texTopic
->keywords
;
346 wxStringListNode
*node
= list
->GetFirst();
349 wxChar
*s
= (wxChar
*)node
->GetData();
351 // Must separate out main entry form subentry (only 1 subentry allowed)
352 wxChar buf1
[100]; wxChar buf2
[100];
353 SplitIndexEntry(s
, buf1
, buf2
);
355 // Check for ':' which messes up index
357 for (i
= 0; i
< wxStrlen(buf1
) ; i
++)
360 for (i
= 0; i
< wxStrlen(buf2
) ; i
++)
364 // {K} is a strange fix to prevent words beginning with K not
365 // being indexed properly
366 TexOutput(_T("K{\\footnote {K} "));
368 if (wxStrlen(buf2
) > 0)
374 TexOutput(_T("}\n"));
375 node
= node
->GetNext();
381 * Output index entry in linear RTF
385 void GenerateIndexEntry(wxChar
*entry
)
389 wxChar buf1
[100]; wxChar buf2
[100];
390 SplitIndexEntry(entry
, buf1
, buf2
);
392 TexOutput(_T("{\\xe\\v {"));
394 if (wxStrlen(buf2
) > 0)
396 TexOutput(_T("\\:"));
404 * Write a suitable RTF header.
408 void WriteColourTable(FILE *fd
)
410 wxFprintf(fd
, _T("{\\colortbl"));
411 wxNode
*node
= ColourTable
.GetFirst();
414 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->GetData();
415 wxFprintf(fd
, _T("\\red%d\\green%d\\blue%d;\n"), entry
->red
, entry
->green
, entry
->blue
);
416 node
= node
->GetNext();
418 wxFprintf(fd
, _T("}"));
422 * Write heading style
426 void WriteHeadingStyle(FILE *fd
, int heading
)
432 wxFprintf(fd
, _T("\\b\\fs%d"), chapterFont
*2);
437 wxFprintf(fd
, _T("\\b\\fs%d"), sectionFont
*2);
442 wxFprintf(fd
, _T("\\b\\fs%d"), subsectionFont
*2);
447 wxFprintf(fd
, _T("\\b\\fs%d"), subsectionFont
*2);
455 void WriteRTFHeader(FILE *fd
)
457 wxFprintf(fd
, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset
);
458 wxFprintf(fd
, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n"));
459 wxFprintf(fd
, _T("{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
463 wxFprintf(fd
, _T("{\\stylesheet{\\f2\\fs20 \\snext0 Normal;}\n"));
465 wxFprintf(fd
, _T("{\\s1 ")); WriteHeadingStyle(fd
, 1); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 1;}\n"));
466 wxFprintf(fd
, _T("{\\s2 ")); WriteHeadingStyle(fd
, 2); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 2;}\n"));
467 wxFprintf(fd
, _T("{\\s3 ")); WriteHeadingStyle(fd
, 3); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 3;}\n"));
468 wxFprintf(fd
, _T("{\\s4 ")); WriteHeadingStyle(fd
, 4); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 4;}\n"));
469 // Table of contents styles
470 wxFprintf(fd
, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n"));
472 wxFprintf(fd
, _T("{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n"));
473 wxFprintf(fd
, _T("{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n"));
474 wxFprintf(fd
, _T("{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n"));
477 wxFprintf(fd
, _T("{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n"));
478 wxFprintf(fd
, _T("{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n"));
479 wxFprintf(fd
, _T("{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n"));
480 wxFprintf(fd
, _T("{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n"));
481 wxFprintf(fd
, _T("{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n"));
482 wxFprintf(fd
, _T("}\n"));
484 WriteColourTable(fd
);
485 wxFprintf(fd
, _T("\n\\ftnbj\\ftnrestart")); // Latex default is footnotes at bottom of page, not section.
486 wxFprintf(fd
, _T("\n"));
489 void OutputNumberStyle(wxChar
*numberStyle
)
493 if (wxStrcmp(numberStyle
, _T("arabic")) == 0)
495 TexOutput(_T("\\pgndec"));
497 else if (wxStrcmp(numberStyle
, _T("roman")) == 0)
499 TexOutput(_T("\\pgnlcrm"));
501 else if (wxStrcmp(numberStyle
, _T("Roman")) == 0)
503 TexOutput(_T("\\pgnucrm"));
505 else if (wxStrcmp(numberStyle
, _T("alph")) == 0)
507 TexOutput(_T("\\pgnlcltr"));
509 else if (wxStrcmp(numberStyle
, _T("Alph")) == 0)
511 TexOutput(_T("\\pgnucltr"));
517 * Write a Windows help project file
520 bool WriteHPJ(wxChar
*filename
)
522 wxChar hpjFilename
[256];
525 wxStrcpy(hpjFilename
, filename
);
526 StripExtension(hpjFilename
);
527 wxStrcat(hpjFilename
, _T(".hpj"));
529 wxStrcpy(helpFile
, wxFileNameFromPath(filename
));
530 StripExtension(helpFile
);
531 wxStrcpy(rtfFile
, helpFile
);
532 wxStrcat(helpFile
, _T(".hlp"));
533 wxStrcat(rtfFile
, _T(".rtf"));
535 FILE *fd
= wxFopen(hpjFilename
, _T("w"));
539 wxChar
*helpTitle
= winHelpTitle
;
541 helpTitle
= _T("Untitled");
543 wxString thePath
= wxPathOnly(InputFile
);
544 if (thePath
.IsEmpty())
546 wxFprintf(fd
, _T("[OPTIONS]\n"));
547 wxFprintf(fd
, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath
.c_str());
548 wxFprintf(fd
, _T("TITLE=%s\n"), helpTitle
);
549 wxFprintf(fd
, _T("CONTENTS=Contents\n"));
551 if (winHelpVersion
> 3)
553 wxFprintf(fd
, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
554 wxFprintf(fd
, _T("COMPRESS=8 Zeck\n"));
555 wxFprintf(fd
, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
556 wxFprintf(fd
, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot
));
560 wxFprintf(fd
, _T("COMPRESS=HIGH\n"));
562 wxFprintf(fd
, _T("\n"));
564 if (winHelpVersion
> 3)
566 wxFprintf(fd
, _T("[WINDOWS]\n"));
567 wxFprintf(fd
, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
568 wxFprintf(fd
, _T("\n"));
571 wxFprintf(fd
, _T("[FILES]\n%s\n\n"), rtfFile
);
572 wxFprintf(fd
, _T("[CONFIG]\n"));
574 wxFprintf(fd
, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile
);
575 wxFprintf(fd
, _T("BrowseButtons()\n\n"));
576 wxFprintf(fd
, _T("[MAP]\n\n[BITMAPS]\n\n"));
583 * Given a TexChunk with a string value, scans through the string
584 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
585 * and inserting spaces at the start of lines since in Latex, a newline
586 * implies a space, but not in RTF.
590 void ProcessText2RTF(TexChunk
*chunk
)
592 bool changed
= FALSE
;
596 int len
= wxStrlen(chunk
->value
);
599 ch
= chunk
->value
[i
];
605 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("\\par\n")); ptr
+= 5;
611 // If the first character of the next line is ASCII,
612 // put a space in. Implicit in Latex, not in RTF.
614 The reason this is difficult is that you don't really know
615 where a space would be appropriate. If you always put in a space
616 when you find a newline, unwanted spaces appear in the text.
618 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
619 !isspace(chunk
->value
[i
+1])) ||
620 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
621 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
622 !isspace(chunk
->value
[i
+2]))))
625 // DOS files have a 13 after the 10
629 if (chunk
->value
[i
] == 13)
636 BigBuffer
[ptr
] = ' ';
639 // Note that the actual ASCII character seen is dealt with in the next
650 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
652 BigBuffer
[ptr
] = '"'; ptr
++;
656 else if (!inVerbatim
&& ch
== '`') // Change ` to '
658 BigBuffer
[ptr
] = 39; ptr
++;
662 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
664 BigBuffer
[ptr
] = '\\'; ptr
++;
665 BigBuffer
[ptr
] = '\\'; ptr
++;
669 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curley bracket
671 BigBuffer
[ptr
] = '\\'; ptr
++;
672 BigBuffer
[ptr
] = ch
; ptr
++;
687 delete[] chunk
->value
;
688 chunk
->value
= copystring(BigBuffer
);
693 * Scan through all chunks starting from the given one,
694 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
695 * This should be called after Tex2Any has parsed the file,
696 * and before TraverseDocument is called.
700 void Text2RTF(TexChunk
*chunk
)
703 if (stopRunning
) return;
707 case CHUNK_TYPE_MACRO
:
709 TexMacroDef
*def
= chunk
->def
;
710 if (def
&& def
->ignore
)
713 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
716 wxNode
*node
= chunk
->children
.GetFirst();
719 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
720 Text2RTF(child_chunk
);
721 node
= node
->GetNext();
724 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
731 wxNode
*node
= chunk
->children
.GetFirst();
734 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
735 Text2RTF(child_chunk
);
736 node
= node
->GetNext();
741 case CHUNK_TYPE_STRING
:
744 ProcessText2RTF(chunk
);
755 wxChar browseBuf
[10];
756 static long browseId
= 0;
757 wxChar
*GetBrowseString(void)
761 wxSprintf(buf
, _T("%ld"), browseId
);
762 int noZeroes
= 5-wxStrlen(buf
);
763 wxStrcpy(browseBuf
, _T("browse"));
764 for (int i
= 0; i
< noZeroes
; i
++)
765 wxStrcat(browseBuf
, _T("0"));
766 wxStrcat(browseBuf
, buf
);
771 * Keeping track of environments to restore the styles after \pard.
772 * Push strings like "\qc" onto stack.
776 void PushEnvironmentStyle(wxChar
*style
)
778 environmentStack
.Add(style
);
781 void PopEnvironmentStyle(void)
783 wxStringListNode
*node
= environmentStack
.GetLast();
786 wxChar
*val
= (wxChar
*)node
->GetData();
792 // Write out the styles, most recent first.
793 void WriteEnvironmentStyles(void)
795 wxStringListNode
*node
= environmentStack
.GetLast();
798 wxChar
*val
= (wxChar
*)node
->GetData();
800 node
= node
->GetNext();
802 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
805 wxSprintf(buf
, _T("\\fi%d"), ParIndent
*20); // Convert points to TWIPS
808 if (environmentStack
.GetCount() > 0 || (ParIndent
> 0))
818 void OutputRTFHeaderCommands(void)
821 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
823 TexOutput(_T("{\\headerl }{\\headerr }"));
825 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
827 TexOutput(_T("{\\headerl }{\\headerr }"));
829 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
832 TexOutput(_T("{\\headerl\\fi0 "));
835 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
837 TexOutput(_T("{\\i \\qr "));
838 if (DocumentStyle
== LATEX_ARTICLE
)
840 wxSprintf(buf
, _T("SECTION %d"), sectionNo
);
845 wxSprintf(buf
, _T("CHAPTER %d: "), chapterNo
);
848 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
849 TexOutput(_T("}\\par\\pard}"));
852 TexOutput(_T("{\\headerr\\fi0 "));
855 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
857 TexOutput(_T("{\\i \\qc "));
858 if (DocumentStyle
== LATEX_ARTICLE
)
860 wxSprintf(buf
, _T("SECTION %d"), sectionNo
);
865 wxSprintf(buf
, _T("CHAPTER %d"), chapterNo
);
868 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
869 TexOutput(_T("}\\par\\pard}"));
873 int oldForbidResetPar
= forbidResetPar
;
876 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
878 TexOutput(_T("{\\headerl\\fi0 "));
881 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
885 if (!CentreHeaderEven
&& !RightHeaderEven
)
886 TexOutput(_T("\\ql "));
887 TraverseChildrenFromChunk(LeftHeaderEven
);
889 if (CentreHeaderEven
)
891 if (!LeftHeaderEven
&& !RightHeaderEven
)
892 TexOutput(_T("\\qc "));
894 TexOutput(_T("\\tab\\tab\\tab "));
895 TraverseChildrenFromChunk(CentreHeaderEven
);
899 if (!LeftHeaderEven
&& !CentreHeaderEven
)
900 TexOutput(_T("\\qr "));
902 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
903 TraverseChildrenFromChunk(RightHeaderEven
);
905 TexOutput(_T("\\par\\pard}"));
908 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
910 TexOutput(_T("{\\headerr\\fi0 "));
913 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
917 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
918 TexOutput(_T("\\ql "));
919 TraverseChildrenFromChunk(LeftHeaderOdd
);
923 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
924 TexOutput(_T("\\qc "));
926 TexOutput(_T("\\tab\\tab\\tab "));
927 TraverseChildrenFromChunk(CentreHeaderOdd
);
931 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
932 TexOutput(_T("\\qr "));
934 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
935 TraverseChildrenFromChunk(RightHeaderOdd
);
937 TexOutput(_T("\\par\\pard}"));
939 // As an approximation, don't put a header on the first page of a section.
940 // This may not always be desired, but it's a reasonable guess.
941 TexOutput(_T("{\\headerf }"));
943 forbidResetPar
= oldForbidResetPar
;
947 void OutputRTFFooterCommands(void)
949 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
951 TexOutput(_T("{\\footerl\\fi0 "));
953 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
954 TexOutput(_T("{\\qc "));
955 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
956 TexOutput(_T("}\\par\\pard}"));
958 TexOutput(_T("{\\footerr\\fi0 "));
960 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
961 TexOutput(_T("{\\qc "));
962 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
963 TexOutput(_T("}\\par\\pard}"));
965 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
967 TexOutput(_T("{\\footerl }{\\footerr }"));
969 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
971 TexOutput(_T("{\\footerl }{\\footerr }"));
975 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
977 TexOutput(_T("{\\footerl\\fi0 "));
979 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
982 if (!CentreFooterEven
&& !RightFooterEven
)
983 TexOutput(_T("\\ql "));
984 TraverseChildrenFromChunk(LeftFooterEven
);
986 if (CentreFooterEven
)
988 if (!LeftFooterEven
&& !RightFooterEven
)
989 TexOutput(_T("\\qc "));
991 TexOutput(_T("\\tab\\tab\\tab "));
992 TraverseChildrenFromChunk(CentreFooterEven
);
996 if (!LeftFooterEven
&& !CentreFooterEven
)
997 TexOutput(_T("\\qr "));
999 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1000 TraverseChildrenFromChunk(RightFooterEven
);
1002 TexOutput(_T("\\par\\pard}"));
1005 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1007 TexOutput(_T("{\\footerr\\fi0 "));
1009 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
1012 if (!CentreFooterOdd
&& !RightFooterOdd
)
1013 TexOutput(_T("\\ql "));
1014 TraverseChildrenFromChunk(LeftFooterOdd
);
1016 if (CentreFooterOdd
)
1018 if (!LeftFooterOdd
&& !RightFooterOdd
)
1019 TexOutput(_T("\\qc "));
1021 TexOutput(_T("\\tab\\tab\\tab "));
1022 TraverseChildrenFromChunk(CentreFooterOdd
);
1026 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1027 TexOutput(_T("\\qr "));
1029 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1030 TraverseChildrenFromChunk(RightFooterOdd
);
1032 TexOutput(_T("\\par\\pard}"));
1035 // As an approximation, put a footer on the first page of a section.
1036 // This may not always be desired, but it's a reasonable guess.
1037 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1039 TexOutput(_T("{\\footerf\\fi0 "));
1042 if (!CentreFooterOdd
&& !RightFooterOdd
)
1043 TexOutput(_T("\\ql "));
1044 TraverseChildrenFromChunk(LeftFooterOdd
);
1046 if (CentreFooterOdd
)
1048 if (!LeftFooterOdd
&& !RightFooterOdd
)
1049 TexOutput(_T("\\qc "));
1051 TexOutput(_T("\\tab\\tab\\tab "));
1052 TraverseChildrenFromChunk(CentreFooterOdd
);
1056 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1057 TexOutput(_T("\\qr "));
1059 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1060 TraverseChildrenFromChunk(RightFooterOdd
);
1062 TexOutput(_T("\\par\\pard}"));
1067 // Called on start/end of macro examination
1068 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1072 wxSprintf(tmpBuf, _T("%d (%d)"), macroId, (int)start);
1073 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1074 OutputDebugString("\n"); wxYield();
1077 // ltLABEL is included here because after a section but BEFORE
1078 // the label is seen, a new paragraph is issued. Don't upset this by
1079 // immediately forgetting we've done it.
1080 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1081 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1082 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1083 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1084 macroId
!= ltPAGENUMBERING
&&
1085 (forbidResetPar
== 0)))
1087 issuedNewParagraph
= 0;
1095 case ltCHAPTERHEADING
:
1096 case ltCHAPTERHEADINGSTAR
:
1104 subsubsectionNo
= 0;
1107 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1110 wxChar
*topicName
= FindTopicName(GetNextChunk());
1111 SetCurrentChapterName(topicName
);
1113 if (winHelpContents
&& winHelp
&& !InPopups())
1115 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1116 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1118 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1123 wxFprintf(Contents
, _T("\n{\\uldb "));
1124 wxFprintf(Chapters
, _T("\\page"));
1125 wxFprintf(Chapters
, _T("\n${\\footnote "));
1127 SetCurrentOutputs(Contents
, Chapters
);
1129 SetCurrentOutput(Chapters
);
1133 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
1135 // If a non-custom page style, we generate the header now.
1136 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1137 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1138 wxStrcmp(PageStyle
, _T("headings")) == 0))
1140 OutputRTFHeaderCommands();
1141 OutputRTFFooterCommands();
1144 // Need to reset the current numbering style, or RTF forgets it.
1145 SetCurrentOutput(Chapters
);
1146 OutputNumberStyle(currentNumberStyle
);
1148 SetCurrentOutput(Contents
);
1152 if (macroId
== ltCHAPTER
)
1155 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), chapterNo
);
1157 else if (macroId
== ltCHAPTERHEADING
)
1159 wxFprintf(Contents
, _T("\\par\n\\pard{\\b "));
1161 else SetCurrentOutput(NULL
); // No entry in table of contents
1165 startedSections
= TRUE
;
1167 // Output heading to contents page
1170 OutputCurrentSection();
1173 wxFprintf(Contents
, _T("}{\\v %s}\\par\\pard\n"), topicName
);
1174 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1175 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1177 // From here, just output to chapter
1178 SetCurrentOutput(Chapters
);
1183 wxFprintf(Chapters
, _T("}\n#{\\footnote %s}\n"), topicName
);
1184 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
1186 OutputSectionKeyword(Chapters
);
1188 GenerateKeywordsForTopic(topicName
);
1191 // If we're generating a .cnt file, we don't want to be able
1192 // jump up to the old-style contents page, so disable it.
1193 if (winHelpContents
)
1194 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
1196 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1197 wxFileNameFromPath(FileRoot
), _T("Contents"));
1203 wxChar
*styleCommand
= _T("");
1204 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1205 styleCommand
= _T("\\s1");
1206 wxFprintf(Chapters
, _T("\\pard{%s"), ((winHelp
&& !InPopups()) ? _T("\\keepn\\sa140\\sb140") : styleCommand
));
1207 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" "));
1210 if (macroId
== ltCHAPTER
)
1213 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1214 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1216 wxFprintf(Chapters
, _T("%d. "), chapterNo
);
1220 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1223 OutputCurrentSection();
1224 TexOutput(_T("\\par\\pard}\\par\n"));
1226 issuedNewParagraph
= 2;
1232 case ltSECTIONHEADING
:
1233 case ltSECTIONHEADINGSTAR
:
1237 if (DocumentStyle
== LATEX_ARTICLE
)
1238 jumpFrom
= Contents
;
1240 jumpFrom
= Chapters
;
1245 subsubsectionNo
= 0;
1246 if (DocumentStyle
== LATEX_ARTICLE
)
1249 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1252 wxChar
*topicName
= FindTopicName(GetNextChunk());
1253 SetCurrentSectionName(topicName
);
1254 NotifyParentHasChildren(1);
1255 if (winHelpContents
&& winHelp
&& !InPopups())
1257 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1258 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 2);
1260 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1264 SetCurrentOutputs(jumpFrom
, Sections
);
1265 // Newline for a new section if this is an article
1266 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1267 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1268 wxFprintf(Sections
, _T("\\page\n"));
1271 wxFprintf(jumpFrom
, _T("\n{\\uldb "));
1275 if (DocumentStyle
== LATEX_ARTICLE
)
1277 TexOutput(_T("\\sect\\pgncont\n"));
1278 // If a non-custom page style, we generate the header now.
1279 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1280 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1281 wxStrcmp(PageStyle
, _T("headings")) == 0))
1283 OutputRTFHeaderCommands();
1284 OutputRTFFooterCommands();
1287 SetCurrentOutput(Contents
);
1289 if (macroId
== ltSECTION
)
1293 if (DocumentStyle
== LATEX_REPORT
)
1294 wxFprintf(Contents
, _T("\n\\pard{\\tab %d.%d\\tab "), chapterNo
, sectionNo
);
1296 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), sectionNo
);
1299 else if (macroId
== ltSECTIONHEADING
)
1303 if (DocumentStyle
== LATEX_REPORT
)
1304 wxFprintf(Contents
, _T("\n\\pard{\\tab ")); //, chapterNo, sectionNo);
1306 wxFprintf(Contents
, _T("\\par\n\\pard{\\b ")); //, sectionNo);
1309 else SetCurrentOutput(NULL
);
1312 if (startedSections
)
1315 wxFprintf(Sections
, _T("\\page\n"));
1317 startedSections
= TRUE
;
1320 wxFprintf(Sections
, _T("\n${\\footnote "));
1322 // Output heading to contents page
1324 OutputCurrentSection();
1329 wxFprintf(jumpFrom
, _T("}{\\v %s}\\par\\pard\n"), topicName
);
1331 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1333 if (DocumentStyle
== LATEX_REPORT
)
1334 wxFprintf(Contents
, _T("}\\par\\pard\n"));
1336 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1339 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1343 wxFprintf(Sections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1344 wxFprintf(Sections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1345 OutputSectionKeyword(Sections
);
1346 GenerateKeywordsForTopic(topicName
);
1349 if (DocumentStyle
== LATEX_ARTICLE
)
1351 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1352 wxFileNameFromPath(FileRoot
), _T("Contents"));
1354 else if (CurrentChapterName
)
1356 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1357 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1364 wxChar
*styleCommand
= _T("");
1365 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1367 if (DocumentStyle
== LATEX_ARTICLE
)
1368 styleCommand
= _T("\\s1");
1370 styleCommand
= _T("\\s2");
1372 wxChar
*keep
= _T("");
1373 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1374 keep
= _T("\\keepn\\sa140\\sb140");
1376 wxFprintf(winHelp
? Sections
: Chapters
, _T("\\pard{%s%s"),
1377 keep
, styleCommand
);
1379 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1380 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1381 wxFprintf(winHelp
? Sections
: Chapters
, _T(" "));
1385 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1387 if (DocumentStyle
== LATEX_REPORT
)
1390 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo,
1391 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1394 wxFprintf(Chapters
, _T("%d.%d. "), chapterNo
, sectionNo
);
1399 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1400 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1403 wxFprintf(Chapters
, _T("%d. "), sectionNo
);
1408 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1411 OutputCurrentSection();
1412 TexOutput(_T("\\par\\pard}\\par\n"));
1414 issuedNewParagraph
= 2;
1419 case ltSUBSECTIONSTAR
:
1420 case ltMEMBERSECTION
:
1421 case ltFUNCTIONSECTION
:
1425 if (winHelp
&& !Sections
)
1427 OnError(_T("You cannot have a subsection before a section!"));
1431 subsubsectionNo
= 0;
1433 if (macroId
!= ltSUBSECTIONSTAR
)
1436 wxChar
*topicName
= FindTopicName(GetNextChunk());
1437 SetCurrentSubsectionName(topicName
);
1438 NotifyParentHasChildren(2);
1439 if (winHelpContents
&& winHelp
&& !InPopups())
1441 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1442 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1444 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1448 SetCurrentOutputs(Sections
, Subsections
);
1449 SetCurrentOutputs(Sections
, Subsections
);
1451 wxFprintf(Sections
, _T("\n{\\uldb "));
1455 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1456 (macroId
!= ltFUNCTIONSECTION
))
1458 SetCurrentOutput(Contents
);
1459 if (DocumentStyle
== LATEX_REPORT
)
1460 wxFprintf(Contents
, _T("\n\\pard\\tab\\tab %d.%d.%d\\tab "), chapterNo
, sectionNo
, subsectionNo
);
1462 wxFprintf(Contents
, _T("\n\\pard\\tab %d.%d\\tab "), sectionNo
, subsectionNo
);
1463 } else SetCurrentOutput(NULL
);
1465 if (startedSections
)
1470 wxFprintf(Subsections
, _T("\\page\n"));
1473 wxFprintf(Chapters
, _T("\\par\n"));
1475 startedSections
= TRUE
;
1478 wxFprintf(Subsections
, _T("\n${\\footnote "));
1480 // Output to contents page
1482 OutputCurrentSection();
1487 wxFprintf(Sections
, _T("}{\\v %s}\\par\\pard\n"), topicName
);
1489 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1490 (macroId
!= ltFUNCTIONSECTION
))
1491 wxFprintf(Contents
, _T("\\par\\pard\n"));
1493 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1496 wxFprintf(Subsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1497 wxFprintf(Subsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1498 OutputSectionKeyword(Subsections
);
1499 GenerateKeywordsForTopic(topicName
);
1500 if (useUpButton
&& CurrentSectionName
)
1502 wxFprintf(Subsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1503 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1506 if (!winHelp
&& indexSubsections
&& useWord
)
1508 // Insert index entry for this subsection
1509 TexOutput(_T("{\\xe\\v {"));
1510 OutputCurrentSection();
1511 TexOutput(_T("}}"));
1516 wxChar
*styleCommand
= _T("");
1517 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1519 if (DocumentStyle
== LATEX_ARTICLE
)
1520 styleCommand
= _T("\\s2");
1522 styleCommand
= _T("\\s3");
1524 wxChar
*keep
= _T("");
1525 if (winHelp
&& !InPopups())
1526 keep
= _T("\\keepn\\sa140\\sb140");
1528 wxFprintf(winHelp
? Subsections
: Chapters
, _T("\\pard{%s%s"),
1529 keep
, styleCommand
);
1531 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1532 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1533 wxFprintf(winHelp
? Subsections
: Chapters
, _T(" "));
1537 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1538 (macroId
!= ltFUNCTIONSECTION
))
1540 if (DocumentStyle
== LATEX_REPORT
)
1543 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo,
1544 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1547 wxFprintf(Chapters
, _T("%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
);
1552 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo,
1553 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1556 wxFprintf(Chapters
, _T("%d.%d. "), sectionNo
, subsectionNo
);
1561 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1564 OutputCurrentSection(); // Repeat section header
1565 TexOutput(_T("\\par\\pard}\\par\n"));
1567 issuedNewParagraph
= 2;
1572 case ltSUBSUBSECTION
:
1573 case ltSUBSUBSECTIONSTAR
:
1577 if (winHelp
&& !Subsections
)
1579 OnError(_T("You cannot have a subsubsection before a subsection!"));
1583 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1586 wxChar
*topicName
= FindTopicName(GetNextChunk());
1587 SetCurrentTopic(topicName
);
1588 NotifyParentHasChildren(3);
1589 if (winHelpContents
&& winHelp
)
1591 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1592 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1594 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1598 SetCurrentOutputs(Subsections
, Subsubsections
);
1599 wxFprintf(Subsections
, _T("\n{\\uldb "));
1603 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1605 if (DocumentStyle
== LATEX_ARTICLE
)
1607 SetCurrentOutput(Contents
);
1608 wxFprintf(Contents
, _T("\n\\tab\\tab %d.%d.%d\\tab "),
1609 sectionNo
, subsectionNo
, subsubsectionNo
);
1612 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1615 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1618 if (startedSections
)
1621 wxFprintf(Subsubsections
, _T("\\page\n"));
1623 wxFprintf(Chapters
, _T("\\par\n"));
1626 startedSections
= TRUE
;
1629 wxFprintf(Subsubsections
, _T("\n${\\footnote "));
1631 // Output header to contents page
1632 OutputCurrentSection();
1635 wxFprintf(Subsections
, _T("}{\\v %s}\\par\\pard\n"), topicName
);
1636 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1637 wxFprintf(Contents
, _T("\\par\\pard\n"));
1639 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1642 wxFprintf(Subsubsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1643 wxFprintf(Subsubsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1644 OutputSectionKeyword(Subsubsections
);
1645 GenerateKeywordsForTopic(topicName
);
1646 if (useUpButton
&& CurrentSubsectionName
)
1648 wxFprintf(Subsubsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1649 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1652 if (!winHelp
&& indexSubsections
&& useWord
)
1654 // Insert index entry for this subsubsection
1655 TexOutput(_T("{\\xe\\v {"));
1656 OutputCurrentSection();
1657 TexOutput(_T("}}"));
1660 wxChar
*styleCommand
= _T("");
1661 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1663 if (DocumentStyle
== LATEX_ARTICLE
)
1664 styleCommand
= _T("\\s3");
1666 styleCommand
= _T("\\s4");
1668 wxChar
*keep
= _T("");
1670 keep
= _T("\\keepn\\sa140\\sb140");
1672 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T("\\pard{%s%s"),
1673 keep
, styleCommand
);
1675 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1676 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1677 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T(" "));
1681 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1683 if (DocumentStyle
== LATEX_ARTICLE
)
1686 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo, subsubsectionNo,
1687 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1690 wxFprintf(Chapters
, _T("%d.%d.%d. "), sectionNo
, subsectionNo
, subsubsectionNo
);
1695 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1696 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1699 wxFprintf(Chapters
, _T("%d.%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1704 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1707 OutputCurrentSection(); // Repeat section header
1708 TexOutput(_T("\\par\\pard}\\par\n"));
1709 issuedNewParagraph
= 2;
1710 // if (winHelp) TexOutput(_T("\\pard"));
1720 wxChar
*topicName
= FindTopicName(GetNextChunk());
1721 SetCurrentTopic(topicName
);
1723 TexOutput(_T("\\pard\\par"));
1730 if (winHelp
|| !useWord
)
1732 if (DocumentStyle
!= LATEX_ARTICLE
)
1733 wxSprintf(figBuf
, _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1735 wxSprintf(figBuf
, _T("%s %d: "), FigureNameString
, figureNo
);
1739 wxSprintf(figBuf
, _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1740 FigureNameString
, topicName
, topicName
);
1747 if (winHelp
|| !useWord
)
1749 if (DocumentStyle
!= LATEX_ARTICLE
)
1750 wxSprintf(figBuf
, _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1752 wxSprintf(figBuf
, _T("%s %d: "), TableNameString
, tableNo
);
1756 wxSprintf(figBuf
, _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1757 TableNameString
, topicName
, topicName
);
1761 int n
= (inTable
? tableNo
: figureNo
);
1762 AddTexRef(topicName
, NULL
, NULL
,
1763 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1764 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1767 TexOutput(_T("\\qc{\\b "));
1769 TexOutput(_T("\\ql{\\b "));
1772 OutputCurrentSection();
1774 TexOutput(_T("}\\par\\pard\n"));
1775 WriteEnvironmentStyles();
1782 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1789 TexOutput(_T("}\n"));
1792 TexOutput(_T("K{\\footnote {K} "));
1793 suppressNameDecoration
= TRUE
;
1794 TraverseChildrenFromChunk(currentMember
);
1795 suppressNameDecoration
= FALSE
;
1796 TexOutput(_T("}\n"));
1798 if (!winHelp
&& useWord
)
1800 // Insert index entry for this function
1801 TexOutput(_T("{\\xe\\v {"));
1802 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1803 TraverseChildrenFromChunk(currentMember
);
1804 suppressNameDecoration
= FALSE
;
1805 TexOutput(_T("}}"));
1812 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1819 TexOutput(_T("}\n"));
1822 TexOutput(_T("K{\\footnote {K} "));
1823 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1824 TraverseChildrenFromChunk(currentMember
);
1825 suppressNameDecoration
= FALSE
;
1826 TexOutput(_T("}\n"));
1828 if (!winHelp
&& useWord
)
1830 // Insert index entry for this function
1831 TexOutput(_T("{\\xe\\v {"));
1832 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1833 TraverseChildrenFromChunk(currentMember
);
1834 suppressNameDecoration
= FALSE
;
1835 TexOutput(_T("}}"));
1842 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1845 TexOutput(_T("{\\b "));
1849 TexOutput(_T("}\n"));
1852 TexOutput(_T("K{\\footnote {K} "));
1853 TraverseChildrenFromChunk(currentMember
);
1854 TexOutput(_T("}\n"));
1856 if (!winHelp
&& useWord
)
1858 // Insert index entry for this function
1859 TexOutput(_T("{\\xe\\v {"));
1860 suppressNameDecoration
= TRUE
; // Necessary so don't print "(\\bf" etc.
1861 TraverseChildrenFromChunk(currentMember
);
1862 suppressNameDecoration
= FALSE
;
1863 TexOutput(_T("}}"));
1871 SetCurrentOutput(Chapters
);
1874 case ltTABLEOFCONTENTS
:
1878 if (!winHelp
&& useWord
)
1880 // Insert Word for Windows table of contents
1881 TexOutput(_T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
1883 // In linear RTF, same as chapter headings.
1884 wxSprintf(buf
, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), chapterFont
*2, ContentsNameString
);
1887 wxSprintf(buf
, _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth
);
1889 // TexOutput(_T("\\sect\\sectd"));
1893 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1906 TexOutput(_T("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n"));
1907 OnInform(_T("Run Tex2RTF again to include contents page."));
1916 // TexOutput(_T("{\\b void}"));
1922 TexOutput(_T("{\\scaps HARDY}"));
1928 TexOutput(_T("wxCLIPS"));
1931 case ltSPECIALAMPERSAND
:
1936 TexOutput(_T("\\cell "));
1942 case ltSPECIALTILDE
:
1953 case ltBACKSLASHCHAR
:
1959 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
1960 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
1961 int currentWidth
= 0;
1962 for (int i
= 0; i
< noColumns
; i
++)
1964 currentWidth
+= TableData
[i
].width
;
1965 if (TableData
[i
].rightBorder
)
1966 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
1968 if (TableData
[i
].leftBorder
)
1969 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
1971 wxSprintf(buf
, _T("\\cellx%d"), currentWidth
);
1974 TexOutput(_T("\\pard\\intbl\n"));
1977 TexOutput(_T("\\line\n"));
1984 TexOutput(_T("\tab "));
1987 case ltRTFSP
: // Explicit space, RTF only
1999 if (indentLevel
> 0)
2001 TexOutput(_T("\\par\\par\n"));
2002 issuedNewParagraph
= 2;
2006 // Top-level list: issue a new paragraph if we haven't
2008 if (!issuedNewParagraph
)
2010 TexOutput(_T("\\par\\pard"));
2011 WriteEnvironmentStyles();
2012 issuedNewParagraph
= 1;
2014 else issuedNewParagraph
= 0;
2017 TexOutput(_T("\\fi0\n"));
2019 if (macroId
== ltENUMERATE
)
2020 listType
= LATEX_ENUMERATE
;
2021 else if (macroId
== ltITEMIZE
)
2022 listType
= LATEX_ITEMIZE
;
2024 listType
= LATEX_DESCRIPTION
;
2027 wxNode
*node
= itemizeStack
.GetFirst();
2029 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2031 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2032 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2034 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2035 itemizeStack
.Insert(struc
);
2037 wxSprintf(buf
, _T("\\tx%d\\tx%d\\li%d"), indentSize1
, indentSize2
, indentSize2
);
2038 PushEnvironmentStyle(buf
);
2042 currentItemSep
= 8; // Reset to the default
2044 PopEnvironmentStyle();
2046 if (itemizeStack
.GetFirst())
2048 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2050 delete itemizeStack
.GetFirst();
2052 /* Change 18/7/97 - don't know why we wish to do this
2053 if (itemizeStack.Number() == 0)
2055 OnMacro(ltPAR, 0, TRUE);
2056 OnMacro(ltPAR, 0, FALSE);
2057 issuedNewParagraph = 2;
2069 wxNode
*node
= itemizeStack
.GetFirst();
2071 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2073 int indentSize
= oldIndent
+ TwoColWidthA
;
2075 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2076 itemizeStack
.Insert(struc
);
2078 // wxSprintf(buf, _T("\\tx%d\\li%d\\ri%d"), indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2079 wxSprintf(buf
, _T("\\tx%d\\li%d"), indentSize
, indentSize
);
2080 PushEnvironmentStyle(buf
);
2085 PopEnvironmentStyle();
2086 if (itemizeStack
.GetFirst())
2088 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2090 delete itemizeStack
.GetFirst();
2094 TexOutput(_T("\\pard\n"));
2095 WriteEnvironmentStyles();
2097 /* why do we need this? */
2098 if (itemizeStack
.GetCount() == 0)
2100 issuedNewParagraph
= 0;
2101 OnMacro(ltPAR
, 0, TRUE
);
2102 OnMacro(ltPAR
, 0, FALSE
);
2109 wxNode
*node
= itemizeStack
.GetFirst();
2112 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2115 struc
->currentItem
+= 1;
2116 wxChar indentBuf
[60];
2118 int indentSize1
= struc
->labelIndentation
;
2119 int indentSize2
= struc
->indentation
;
2121 TexOutput(_T("\n"));
2122 if (struc
->currentItem
> 1)
2124 if (currentItemSep
> 0)
2125 TexOutput(_T("\\par"));
2127 TexOutput(_T("\\par"));
2128 // WriteEnvironmentStyles();
2131 wxSprintf(buf
, _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1
, indentSize2
,
2132 indentSize2
, 20*itemIndentTab
);
2135 switch (struc
->listType
)
2137 case LATEX_ENUMERATE
:
2139 if (descriptionItemArg
)
2141 TexOutput(_T("\\tab{ "));
2142 TraverseChildrenFromChunk(descriptionItemArg
);
2143 TexOutput(_T("}\\tab"));
2144 descriptionItemArg
= NULL
;
2148 wxSprintf(indentBuf
, _T("\\tab{\\b %d.}\\tab"), struc
->currentItem
);
2149 TexOutput(indentBuf
);
2155 if (descriptionItemArg
)
2157 TexOutput(_T("\\tab{ "));
2158 TraverseChildrenFromChunk(descriptionItemArg
);
2159 TexOutput(_T("}\\tab"));
2160 descriptionItemArg
= NULL
;
2164 if (bulletFile
&& winHelp
)
2166 if (winHelpVersion
> 3) // Transparent bitmap
2167 wxSprintf(indentBuf
, _T("\\tab\\{bmct %s\\}\\tab"), bulletFile
);
2169 wxSprintf(indentBuf
, _T("\\tab\\{bmc %s\\}\\tab"), bulletFile
);
2172 wxSprintf(indentBuf
, _T("\\tab{\\b o}\\tab"));
2174 wxSprintf(indentBuf
, _T("\\tab{\\f1\\'b7}\\tab"));
2175 TexOutput(indentBuf
);
2180 case LATEX_DESCRIPTION
:
2182 if (descriptionItemArg
)
2184 TexOutput(_T("\\tab{\\b "));
2185 TraverseChildrenFromChunk(descriptionItemArg
);
2186 TexOutput(_T("} "));
2187 descriptionItemArg
= NULL
;
2197 case ltTWOCOLITEMRULED
:
2199 wxNode
*node
= itemizeStack
.GetFirst();
2202 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2205 struc
->currentItem
+= 1;
2208 wxNode
*node2
= NULL
;
2209 if (itemizeStack
.GetCount() > 1) // TODO: do I actually mean Nth(0) here??
2210 node2
= itemizeStack
.Item(1);
2212 oldIndent
= ((ItemizeStruc
*)node2
->GetData())->indentation
;
2214 TexOutput(_T("\n"));
2215 if (struc
->currentItem
> 1)
2217 if (currentItemSep
> 0)
2218 TexOutput(_T("\\par"));
2220 // WriteEnvironmentStyles();
2223 // wxSprintf(buf, _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA,
2224 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2226 wxSprintf(buf, _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA,
2227 TwoColWidthA, TwoColWidthA);
2229 wxSprintf(buf
, _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA
+ oldIndent
,
2230 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2241 if (macroId
== ltVERBATIM
)
2243 if (!issuedNewParagraph
)
2245 TexOutput(_T("\\par\\pard"));
2246 WriteEnvironmentStyles();
2247 issuedNewParagraph
= 1;
2249 else issuedNewParagraph
= 0;
2251 wxSprintf(buf
, _T("{\\f3\\fs20 "));
2257 if (macroId
== ltVERBATIM
)
2259 TexOutput(_T("\\pard\n"));
2260 // issuedNewParagraph = 1;
2261 WriteEnvironmentStyles();
2271 TexOutput(_T("\\fi0\\qc "));
2273 PushEnvironmentStyle(_T("\\qc"));
2277 TexOutput(_T("\\par\\pard\n"));
2278 issuedNewParagraph
= 1;
2280 PopEnvironmentStyle();
2281 WriteEnvironmentStyles();
2289 TexOutput(_T("\\fi0\\ql "));
2291 PushEnvironmentStyle(_T("\\ql"));
2295 TexOutput(_T("\\par\\pard\n"));
2296 issuedNewParagraph
= 1;
2298 PopEnvironmentStyle();
2299 WriteEnvironmentStyles();
2307 TexOutput(_T("\\fi0\\qr "));
2309 PushEnvironmentStyle(_T("\\qr"));
2313 TexOutput(_T("\\par\\pard\n"));
2314 issuedNewParagraph
= 1;
2316 PopEnvironmentStyle();
2317 WriteEnvironmentStyles();
2322 case ltFOOTNOTESIZE
:
2326 wxSprintf(buf
, _T("{\\fs%d\n"), smallFont
*2);
2329 else TexOutput(_T("}\n"));
2337 wxSprintf(buf
, _T("{\\fs%d\n"), tinyFont
*2);
2340 else TexOutput(_T("}\n"));
2347 wxSprintf(buf
, _T("{\\fs%d\n"), normalFont
*2);
2350 else TexOutput(_T("}\n"));
2357 wxSprintf(buf
, _T("{\\fs%d\n"), largeFont1
*2);
2360 else TexOutput(_T("}\n"));
2367 wxSprintf(buf
, _T("{\\fs%d\n"), LargeFont2
*2);
2370 else TexOutput(_T("}\n"));
2377 wxSprintf(buf
, _T("{\\fs%d\n"), LARGEFont3
*2);
2380 else TexOutput(_T("}\n"));
2387 wxSprintf(buf
, _T("{\\fs%d\n"), hugeFont1
*2);
2390 else TexOutput(_T("}\n"));
2397 wxSprintf(buf
, _T("{\\fs%d\n"), HugeFont2
*2);
2400 else TexOutput(_T("}\n"));
2407 wxSprintf(buf
, _T("{\\fs%d\n"), HUGEFont3
*2);
2410 else TexOutput(_T("}\n"));
2419 TexOutput(_T("{\\b "));
2421 else TexOutput(_T("}"));
2428 TexOutput(_T("{\\ul "));
2430 else TexOutput(_T("}"));
2441 TexOutput(_T("{\\i "));
2443 else TexOutput(_T("}"));
2446 // Roman font: do nothing. Should really switch between
2455 TexOutput(_T("{\\plain "));
2457 else TexOutput(_T("}"));
2461 // Medium-weight font. Unbolden...
2466 TexOutput(_T("{\\b0 "));
2468 else TexOutput(_T("}"));
2471 // Upright (un-italic or slant)
2476 TexOutput(_T("{\\i0 "));
2478 else TexOutput(_T("}"));
2487 TexOutput(_T("{\\scaps "));
2489 else TexOutput(_T("}"));
2498 TexOutput(_T("{\\f3 "));
2500 else TexOutput(_T("}"));
2506 TexOutput(_T("\\{"));
2512 TexOutput(_T("\\}"));
2518 TexOutput(_T("\\\\"));
2525 if ( issuedNewParagraph
== 0 )
2527 TexOutput(_T("\\par\\pard"));
2528 issuedNewParagraph
++;
2530 // Extra par if parskip is more than zero (usually looks best.)
2531 if (!inTabular
&& (ParSkip
> 0))
2533 TexOutput(_T("\\par"));
2534 issuedNewParagraph
++;
2536 WriteEnvironmentStyles();
2538 // 1 is a whole paragraph if ParSkip == 0,
2539 // half a paragraph if ParSkip > 0
2540 else if ( issuedNewParagraph
== 1 )
2542 // Don't need a par at all if we've already had one,
2543 // and ParSkip == 0.
2545 // Extra par if parskip is more than zero (usually looks best.)
2546 if (!inTabular
&& (ParSkip
> 0))
2548 TexOutput(_T("\\par"));
2549 issuedNewParagraph
++;
2551 WriteEnvironmentStyles();
2554 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2556 TexOutput(_T("\\par\\pard"));
2558 // Extra par if parskip is more than zero (usually looks best.)
2559 if (!inTabular && (ParSkip > 0))
2560 TexOutput(_T("\\par"));
2561 WriteEnvironmentStyles();
2565 TexOutput(_T("\n"));
2571 // In Windows Help, no newpages until we've started some chapters or sections
2572 if (!(winHelp
&& !startedSections
))
2574 TexOutput(_T("\\page\n"));
2579 if (start
&& DocumentTitle
)
2581 TexOutput(_T("\\par\\pard"));
2583 TexOutput(_T("\\par"));
2584 wxSprintf(buf
, _T("\\qc{\\fs%d\\b "), titleFont
*2);
2586 TraverseChildrenFromChunk(DocumentTitle
);
2587 TexOutput(_T("}\\par\\pard\n"));
2592 TexOutput(_T("\\par"));
2593 wxSprintf(buf
, _T("\\par\\qc{\\fs%d "), authorFont
*2);
2595 TraverseChildrenFromChunk(DocumentAuthor
);
2597 TexOutput(_T("\\par\\pard\n"));
2601 TexOutput(_T("\\par"));
2602 wxSprintf(buf
, _T("\\qc{\\fs%d "), authorFont
*2);
2604 TraverseChildrenFromChunk(DocumentDate
);
2605 TexOutput(_T("}\\par\\pard\n"));
2607 // If linear RTF, we want this titlepage to be in a separate
2608 // section with its own (blank) header and footer
2609 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2611 TexOutput(_T("{\\header }{\\footer }\n"));
2612 // Not sure about this: we get too many sections.
2613 // TexOutput(_T("\\sect"));
2618 case ltADDCONTENTSLINE
:
2622 if (contentsLineSection
&& contentsLineValue
)
2624 if (wxStrcmp(contentsLineSection
, _T("chapter")) == 0)
2626 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2628 else if (wxStrcmp(contentsLineSection
, _T("section")) == 0)
2630 if (DocumentStyle
!= LATEX_ARTICLE
)
2631 wxFprintf(Contents
, _T("\n\\tab%s\\par\n"), contentsLineValue
);
2633 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2643 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2644 issuedNewParagraph
= 1;
2645 WriteEnvironmentStyles();
2653 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2654 issuedNewParagraph
= 1;
2655 WriteEnvironmentStyles();
2665 case ltNUMBEREDBIBITEM
:
2668 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
2670 TexOutput(_T("\\par\\pard\\par\n\n"));
2677 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2685 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2686 wxSprintf(buf
, _T("%d"), chapterNo
);
2695 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2696 wxSprintf(buf
, _T("%d"), sectionNo
);
2703 if (!start
&& !winHelp
)
2705 TexOutput(_T("\\cols2\n"));
2711 if (!start
&& !winHelp
)
2713 TexOutput(_T("\\cols1\n"));
2719 if (start
&& useWord
&& !winHelp
)
2721 FakeCurrentSection(_T("Index"));
2722 OnMacro(ltPAR
, 0, TRUE
);
2723 OnMacro(ltPAR
, 0, FALSE
);
2724 TexOutput(_T("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n"));
2728 case ltLISTOFFIGURES
:
2730 if (start
&& useWord
&& !winHelp
)
2732 FakeCurrentSection(FiguresNameString
, FALSE
);
2733 OnMacro(ltPAR
, 0, TRUE
);
2734 OnMacro(ltPAR
, 0, FALSE
);
2735 OnMacro(ltPAR
, 0, TRUE
);
2736 OnMacro(ltPAR
, 0, FALSE
);
2738 wxSprintf(buf
, _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"),
2744 case ltLISTOFTABLES
:
2746 if (start
&& useWord
&& !winHelp
)
2748 FakeCurrentSection(TablesNameString
, FALSE
);
2749 OnMacro(ltPAR
, 0, TRUE
);
2750 OnMacro(ltPAR
, 0, FALSE
);
2751 OnMacro(ltPAR
, 0, TRUE
);
2752 OnMacro(ltPAR
, 0, FALSE
);
2754 wxSprintf(buf
, _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"),
2762 if (start
) TexOutput(_T("{\\f1\\'61}"));
2765 if (start
) TexOutput(_T("{\\f1\\'62}"));
2768 if (start
) TexOutput(_T("{\\f1\\'63}"));
2771 if (start
) TexOutput(_T("{\\f1\\'64}"));
2775 if (start
) TexOutput(_T("{\\f1\\'65}"));
2778 if (start
) TexOutput(_T("{\\f1\\'7A}"));
2781 if (start
) TexOutput(_T("{\\f1\\'68}"));
2785 if (start
) TexOutput(_T("{\\f1\\'71}"));
2788 if (start
) TexOutput(_T("{\\f1\\'69}"));
2791 if (start
) TexOutput(_T("{\\f1\\'6B}"));
2794 if (start
) TexOutput(_T("{\\f1\\'6C}"));
2797 if (start
) TexOutput(_T("{\\f1\\'6D}"));
2800 if (start
) TexOutput(_T("{\\f1\\'6E}"));
2803 if (start
) TexOutput(_T("{\\f1\\'78}"));
2806 if (start
) TexOutput(_T("{\\f1\\'70}"));
2809 if (start
) TexOutput(_T("{\\f1\\'76}"));
2813 if (start
) TexOutput(_T("{\\f1\\'72}"));
2816 if (start
) TexOutput(_T("{\\f1\\'73}"));
2819 if (start
) TexOutput(_T("{\\f1\\'56}"));
2822 if (start
) TexOutput(_T("{\\f1\\'74}"));
2825 if (start
) TexOutput(_T("{\\f1\\'75}"));
2829 if (start
) TexOutput(_T("{\\f1\\'66}"));
2832 if (start
) TexOutput(_T("{\\f1\\'63}"));
2835 if (start
) TexOutput(_T("{\\f1\\'79}"));
2838 if (start
) TexOutput(_T("{\\f1\\'77}"));
2841 if (start
) TexOutput(_T("{\\f1\\'47}"));
2844 if (start
) TexOutput(_T("{\\f1\\'44}"));
2847 if (start
) TexOutput(_T("{\\f1\\'51}"));
2850 if (start
) TexOutput(_T("{\\f1\\'4C}"));
2853 if (start
) TexOutput(_T("{\\f1\\'58}"));
2856 if (start
) TexOutput(_T("{\\f1\\'50}"));
2859 if (start
) TexOutput(_T("{\\f1\\'53}"));
2862 if (start
) TexOutput(_T("{\\f1\\'54}"));
2865 if (start
) TexOutput(_T("{\\f1\\'46}"));
2868 if (start
) TexOutput(_T("{\\f1\\'59}"));
2871 if (start
) TexOutput(_T("{\\f1\\'57}"));
2873 // Binary operation symbols
2876 if (start
) TexOutput(_T("{\\f1\\'A3}"));
2879 if (start
) TexOutput(_T("<<"));
2882 if (start
) TexOutput(_T("{\\f1\\'CC}"));
2885 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2888 if (start
) TexOutput(_T("{\\f1\\'CE}"));
2892 if (start
) TexOutput(_T("{\\f1\\'B3}"));
2895 if (start
) TexOutput(_T(">>"));
2898 if (start
) TexOutput(_T("{\\f1\\'C9}"));
2901 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2904 if (start
) TexOutput(_T("{\\f1\\'27}"));
2907 if (start
) TexOutput(_T("{\\f1\\'5E}"));
2910 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2913 if (start
) TexOutput(_T("{\\f1\\'BB}"));
2916 if (start
) TexOutput(_T("{\\f1\\'40}"));
2919 if (start
) TexOutput(_T("{\\f1\\'BA}"));
2922 if (start
) TexOutput(_T("{\\f1\\'B5}"));
2925 if (start
) TexOutput(_T("{\\f1\\'7E}"));
2928 if (start
) TexOutput(_T("{\\f4\\'4A}"));
2931 if (start
) TexOutput(_T("{\\f4\\'4C}"));
2934 if (start
) TexOutput(_T("|"));
2937 // Negated relation symbols
2939 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2942 if (start
) TexOutput(_T("{\\f1\\'CF}"));
2945 if (start
) TexOutput(_T("{\\f1\\'CB}"));
2950 if (start
) TexOutput(_T("{\\f1\\'AC}"));
2953 if (start
) TexOutput(_T("{\\f1\\'DC}"));
2956 if (start
) TexOutput(_T("{\\f1\\'AE}"));
2959 if (start
) TexOutput(_T("{\\f1\\'DE}"));
2961 case ltLEFTRIGHTARROW
:
2962 if (start
) TexOutput(_T("{\\f1\\'AB}"));
2964 case ltLEFTRIGHTARROW2
:
2965 if (start
) TexOutput(_T("{\\f1\\'DB}"));
2968 if (start
) TexOutput(_T("{\\f1\\'AD}"));
2971 if (start
) TexOutput(_T("{\\f1\\'DD}"));
2974 if (start
) TexOutput(_T("{\\f1\\'AF}"));
2977 if (start
) TexOutput(_T("{\\f1\\'DF}"));
2980 // Miscellaneous symbols
2982 if (start
) TexOutput(_T("{\\f1\\'CO}"));
2985 if (start
) TexOutput(_T("{\\f1\\'C3}"));
2988 if (start
) TexOutput(_T("{\\f1\\'C2}"));
2991 if (start
) TexOutput(_T("{\\f1\\'C1}"));
2994 if (start
) TexOutput(_T("{\\f1\\'C6}"));
2997 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3000 if (start
) TexOutput(_T("{\\f1\\'D6}"));
3003 if (start
) TexOutput(_T("{\\f1\\'B6}"));
3006 if (start
) TexOutput(_T("{\\f1\\'5E}"));
3009 if (start
) TexOutput(_T("{\\f1\\'22}"));
3012 if (start
) TexOutput(_T("{\\f1\\'24}"));
3015 if (start
) TexOutput(_T("{\\f1\\'D8}"));
3018 if (start
) TexOutput(_T("{\\f1\\'23}"));
3021 if (start
) TexOutput(_T("{\\f1\\'D0}"));
3024 if (start
) TexOutput(_T("{\\f5\\'73}"));
3027 if (start
) TexOutput(_T("{\\f5\\'A8}"));
3030 if (start
) TexOutput(_T("{\\f5\\'A9}"));
3033 if (start
) TexOutput(_T("{\\f5\\'AA}"));
3036 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3039 if (start
) TexOutput(_T("{\\f1\\'A5}"));
3042 if (start
) TexOutput(_T("{\\f0\\'A9}"));
3045 if (start
) TexOutput(_T("{\\f0\\'AE}"));
3048 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3051 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3054 if (start
) TexOutput(_T("{\\f1\\'B4}"));
3057 if (start
) TexOutput(_T("{\\f1\\'B8}"));
3060 if (start
) TexOutput(_T("{\\f1\\'D7}"));
3063 if (start
) TexOutput(_T("{\\f1\\'2A}"));
3066 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3069 if (start
) TexOutput(_T("{\\f1\\'C7}"));
3072 if (start
) TexOutput(_T("{\\f1\\'C8}"));
3075 if (start
) TexOutput(_T("{\\f1\\'DA}"));
3078 if (start
) TexOutput(_T("{\\f1\\'D9}"));
3081 if (start
) TexOutput(_T("{\\f1\\'B0}"));
3084 if (start
) TexOutput(_T("{\\f1\\'B7}"));
3087 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3090 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3093 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3095 case ltBIGTRIANGLEDOWN
:
3096 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3099 if (start
) TexOutput(_T("{\\f1\\'C5}"));
3102 if (start
) TexOutput(_T("{\\f1\\'C4}"));
3105 if (start
) TexOutput(_T("{\\'DF}"));
3109 if (start
) inFigure
= TRUE
;
3110 else inFigure
= FALSE
;
3115 if (start
) inTable
= TRUE
;
3116 else inTable
= FALSE
;
3121 DefaultOnMacro(macroId
, no_args
, start
);
3127 // Called on start/end of argument examination
3128 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3135 case ltCHAPTERHEADING
:
3138 case ltSECTIONHEADING
:
3140 case ltSUBSECTIONSTAR
:
3141 case ltSUBSUBSECTION
:
3142 case ltSUBSUBSECTIONSTAR
:
3144 case ltMEMBERSECTION
:
3145 case ltFUNCTIONSECTION
:
3149 if (!start
&& (arg_no
== 1))
3150 currentSection
= GetArgChunk();
3155 if (start
&& (arg_no
== 1))
3156 TexOutput(_T("\\pard\\li600\\fi-600{\\b "));
3158 if (!start
&& (arg_no
== 1))
3159 TexOutput(_T("} "));
3161 if (start
&& (arg_no
== 2))
3163 if (!suppressNameDecoration
) TexOutput(_T("{\\b "));
3164 currentMember
= GetArgChunk();
3166 if (!start
&& (arg_no
== 2))
3168 if (!suppressNameDecoration
) TexOutput(_T("}"));
3171 if (start
&& (arg_no
== 3))
3173 if (!start
&& (arg_no
== 3))
3175 // TexOutput(_T(")\\li0\\fi0"));
3176 // TexOutput(_T(")\\par\\pard\\li0\\fi0"));
3177 // issuedNewParagraph = 1;
3179 WriteEnvironmentStyles();
3185 if (start
&& (arg_no
== 1))
3186 TexOutput(_T("\\pard\\li260\\fi-260{\\b "));
3187 if (!start
&& (arg_no
== 1))
3188 TexOutput(_T("} "));
3190 if (start
&& (arg_no
== 2))
3192 if (!suppressNameDecoration
) TexOutput(_T("({\\b "));
3193 currentMember
= GetArgChunk();
3195 if (!start
&& (arg_no
== 2))
3197 if (!suppressNameDecoration
) TexOutput(_T("}"));
3200 if (!start
&& (arg_no
== 3))
3202 TexOutput(_T(")\\li0\\fi0"));
3203 WriteEnvironmentStyles();
3209 if (start
&& (arg_no
== 1))
3210 TexOutput(_T("\\pard\\li260\\fi-260"));
3212 if (!start
&& (arg_no
== 1))
3215 if (start
&& (arg_no
== 2))
3216 TexOutput(_T("(*"));
3217 if (!start
&& (arg_no
== 2))
3220 if (start
&& (arg_no
== 2))
3221 currentMember
= GetArgChunk();
3223 if (start
&& (arg_no
== 3))
3225 if (!start
&& (arg_no
== 3))
3227 TexOutput(_T(")\\li0\\fi0"));
3228 WriteEnvironmentStyles();
3234 if (start
&& (arg_no
== 1))
3235 TexOutput(_T("{\\b "));
3236 if (!start
&& (arg_no
== 1))
3238 if (start
&& (arg_no
== 2))
3240 TexOutput(_T("{\\i "));
3242 if (!start
&& (arg_no
== 2))
3250 if (start
&& (arg_no
== 1))
3251 TexOutput(_T("{\\b "));
3252 if (!start
&& (arg_no
== 1))
3253 TexOutput(_T("} ")); // This is the difference from param - one space!
3254 if (start
&& (arg_no
== 2))
3256 TexOutput(_T("{\\i "));
3258 if (!start
&& (arg_no
== 2))
3266 if (!start
&& (arg_no
== 1))
3269 if (start
&& (arg_no
== 2))
3270 currentMember
= GetArgChunk();
3279 wxChar
*refName
= GetArgData();
3280 if (winHelp
|| !useWord
)
3284 TexRef
*texRef
= FindReference(refName
);
3287 sec
= texRef
->sectionNumber
;
3297 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
3309 if ((GetNoArgs() - arg_no
) == 1)
3312 TexOutput(_T("{\\uldb "));
3316 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3320 TexOutput(_T("{\\v "));
3322 // Remove green colour/underlining if specified
3323 if (!hotSpotUnderline
&& !hotSpotColour
)
3325 else if (!hotSpotColour
)
3328 else TexOutput(_T("}"));
3331 else // If a linear document, must resolve the references ourselves
3333 if ((GetNoArgs() - arg_no
) == 1)
3335 // In a linear document we display the anchor text in italic plus
3338 TexOutput(_T("{\\i "));
3343 helpRefText
= GetArgChunk();
3347 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3349 if (macroId
!= ltHELPREFN
)
3351 wxChar
*refName
= GetArgData();
3352 TexRef
*texRef
= NULL
;
3354 texRef
= FindReference(refName
);
3357 if (texRef
|| !ignoreBadRefs
)
3358 TexOutput(_T(" ("));
3361 if (texRef
|| !ignoreBadRefs
)
3365 TexOutput(_T("p. "));
3366 TexOutput(_T("{\\field{\\*\\fldinst PAGEREF "));
3368 TexOutput(_T(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"));
3372 // Only print section name if we're not in Word mode,
3373 // so can't do page references
3376 TexOutput(texRef
->sectionName
);
3378 TexOutput(texRef
->sectionNumber
);
3383 TexOutput(_T("??"));
3384 wxSprintf(buf
, _T("Warning: unresolved reference '%s'"), refName
);
3390 else TexOutput(_T("??"));
3394 if (texRef
|| !ignoreBadRefs
)
3409 else if (arg_no
== 2)
3414 TexOutput(_T(" ({\\f3 "));
3418 TexOutput(_T("})"));
3429 if ((GetNoArgs() - arg_no
) == 1)
3432 TexOutput(_T("{\\ul "));
3436 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3440 TexOutput(_T("{\\v "));
3442 // Remove green colour/underlining if specified
3443 if (!hotSpotUnderline
&& !hotSpotColour
)
3445 else if (!hotSpotColour
)
3448 else TexOutput(_T("}"));
3451 else // A linear document...
3453 if ((GetNoArgs() - arg_no
) == 1)
3455 // In a linear document we just display the anchor text in italic
3457 TexOutput(_T("{\\i "));
3466 case ltADDCONTENTSLINE
:
3468 if (start
&& !winHelp
)
3471 contentsLineSection
= copystring(GetArgData());
3472 else if (arg_no
== 3)
3473 contentsLineValue
= copystring(GetArgData());
3487 static int imageWidth
= 0;
3488 static int imageHeight
= 0;
3490 if (start
&& (arg_no
== 1))
3492 wxChar
*imageDimensions
= copystring(GetArgData());
3494 // imageWidth - Convert points to TWIPS (1 twip = 1/20th of point)
3495 wxStringTokenizer
tok(imageDimensions
, _T(";:"), wxTOKEN_STRTOK
);
3496 if(tok
.HasMoreTokens())
3498 wxString token
= tok
.GetNextToken();
3499 imageWidth
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3506 // imageHeight - Convert points to TWIPS (1 twip = 1/20th of point)
3507 if(tok
.HasMoreTokens())
3509 wxString token
= tok
.GetNextToken();
3510 imageHeight
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3517 if (imageDimensions
) // glt
3518 delete [] imageDimensions
;
3521 else if (start
&& (arg_no
== 2 ))
3523 wxChar
*filename
= copystring(GetArgData());
3524 wxString f
= _T("");
3525 if ((winHelp
|| (wxStrcmp(bitmapMethod
, _T("includepicture")) == 0) || (wxStrcmp(bitmapMethod
, _T("import")) == 0)) && useWord
)
3527 if (f
== _T("")) // Try for a .shg (segmented hypergraphics file)
3529 wxStrcpy(buf
, filename
);
3530 StripExtension(buf
);
3531 wxStrcat(buf
, _T(".shg"));
3532 f
= TexPathList
.FindValidPath(buf
);
3534 if (f
== _T("")) // Try for a .bmp
3536 wxStrcpy(buf
, filename
);
3537 StripExtension(buf
);
3538 wxStrcat(buf
, _T(".bmp"));
3539 f
= TexPathList
.FindValidPath(buf
);
3541 if (f
== _T("")) // Try for a metafile instead
3543 wxStrcpy(buf
, filename
);
3544 StripExtension(buf
);
3545 wxStrcat(buf
, _T(".wmf"));
3546 f
= TexPathList
.FindValidPath(buf
);
3552 if (bitmapTransparency
&& (winHelpVersion
> 3))
3553 TexOutput(_T("\\{bmct "));
3555 TexOutput(_T("\\{bmc "));
3556 wxString str
= wxFileNameFromPath(f
);
3557 TexOutput((wxChar
*) (const wxChar
*) str
);
3558 TexOutput(_T("\\}"));
3562 // Microsoft Word method
3563 if (wxStrcmp(bitmapMethod
, _T("import")) == 0)
3564 TexOutput(_T("{\\field{\\*\\fldinst IMPORT "));
3566 TexOutput(_T("{\\field{\\*\\fldinst INCLUDEPICTURE "));
3568 // Full path appears not to be valid!
3569 wxString str
= wxFileNameFromPath(f
);
3570 TexOutput((wxChar
*)(const wxChar
*) str
);
3572 int len = wxStrlen(f);
3573 wxChar smallBuf[2]; smallBuf[1] = 0;
3574 for (int i = 0; i < len; i++)
3577 TexOutput(smallBuf);
3578 if (smallBuf[0] == '\\')
3579 TexOutput(smallBuf);
3582 TexOutput(_T("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}"));
3587 TexOutput(_T("[No BMP or WMF for image file "));
3588 TexOutput(filename
);
3590 wxSprintf(buf
, _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3593 if (filename
) // glt
3598 if (f
== _T("")) // Try for a .bmp
3600 wxStrcpy(buf
, filename
);
3601 StripExtension(buf
);
3602 wxStrcat(buf
, _T(".bmp"));
3603 f
= TexPathList
.FindValidPath(buf
);
3607 FILE *fd
= wxFopen(f
, _T("rb"));
3608 if (OutputBitmapHeader(fd
, winHelp
))
3609 OutputBitmapData(fd
);
3612 wxSprintf(buf
, _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f
.c_str());
3617 else // Try for a metafile instead
3620 wxStrcpy(buf
, filename
);
3621 StripExtension(buf
);
3622 wxStrcat(buf
, _T(".wmf"));
3623 f
= TexPathList
.FindValidPath(buf
);
3626 // HFILE handle = _lopen(f, READ);
3627 FILE *fd
= wxFopen(f
, _T("rb"));
3628 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3630 OutputMetafileData(fd
);
3634 wxSprintf(buf
, _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f
.c_str());
3642 TexOutput(_T("[No BMP or WMF for image file "));
3643 TexOutput(filename
);
3645 wxSprintf(buf
, _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3658 case ltSUPERTABULAR
:
3664 currentRowNumber
= 0;
3667 tableVerticalLineLeft
= FALSE
;
3668 tableVerticalLineRight
= FALSE
;
3669 int currentWidth
= 0;
3671 wxChar
*alignString
= copystring(GetArgData());
3672 ParseTableArgument(alignString
);
3674 // TexOutput(_T("\\trowd\\trgaph108\\trleft-108"));
3675 TexOutput(_T("\\trowd\\trgaph108"));
3677 // Write the first row formatting for compatibility
3678 // with standard Latex
3679 if (compatibilityMode
)
3681 for (int i
= 0; i
< noColumns
; i
++)
3683 currentWidth
+= TableData
[i
].width
;
3684 wxSprintf(buf
, _T("\\cellx%d"), currentWidth
);
3687 TexOutput(_T("\\pard\\intbl\n"));
3689 delete[] alignString
;
3694 else if (arg_no
== 2 && !start
)
3696 TexOutput(_T("\\pard\n"));
3697 WriteEnvironmentStyles();
3708 TexOutput(_T("\\li360\n"));
3710 PushEnvironmentStyle(_T("\\li360"));
3715 PopEnvironmentStyle();
3716 OnMacro(ltPAR
, 0, TRUE
);
3717 OnMacro(ltPAR
, 0, FALSE
);
3725 TexOutput(_T("\\li360\n"));
3726 PushEnvironmentStyle(_T("\\li360"));
3730 PopEnvironmentStyle();
3731 OnMacro(ltPAR
, 0, TRUE
);
3732 OnMacro(ltPAR
, 0, FALSE
);
3744 wxSprintf(buf
, _T("\\box\\trgaph108%s\n"), ((macroId
== ltNORMALBOXD
) ? _T("\\brdrdb") : _T("\\brdrs")));
3746 PushEnvironmentStyle(buf
);
3750 PopEnvironmentStyle();
3751 OnMacro(ltPAR
, 0, TRUE
);
3752 OnMacro(ltPAR
, 0, FALSE
);
3756 case ltHELPFONTSIZE
:
3760 wxChar
*data
= GetArgData();
3761 if (wxStrcmp(data
, _T("10")) == 0)
3763 else if (wxStrcmp(data
, _T("11")) == 0)
3765 else if (wxStrcmp(data
, _T("12")) == 0)
3767 wxSprintf(buf
, _T("\\fs%d\n"), normalFont
*2);
3774 case ltHELPFONTFAMILY
:
3778 wxChar
*data
= GetArgData();
3779 if (wxStrcmp(data
, _T("Swiss")) == 0)
3780 TexOutput(_T("\\f2\n"));
3781 else if (wxStrcmp(data
, _T("Symbol")) == 0)
3782 TexOutput(_T("\\f1\n"));
3783 else if (wxStrcmp(data
, _T("Times")) == 0)
3784 TexOutput(_T("\\f0\n"));
3792 if (start
&& arg_no
== 1)
3794 wxChar
*data
= GetArgData();
3795 ParIndent
= ParseUnitArgument(data
);
3796 if (ParIndent
== 0 || forbidParindent
== 0)
3798 wxSprintf(buf
, _T("\\fi%d\n"), ParIndent
*20);
3807 if (start
&& IsArgOptional())
3809 descriptionItemArg
= GetArgChunk();
3815 case ltTWOCOLITEMRULED
:
3822 TexOutput(_T("\\tab "));
3829 if (macroId
== ltTWOCOLITEMRULED
)
3830 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
3831 TexOutput(_T("\\par\\pard\n"));
3832 issuedNewParagraph
= 1;
3833 WriteEnvironmentStyles();
3844 case ltACCENT_GRAVE
:
3848 wxChar
*val
= GetArgData();
3854 TexOutput(_T("\\'e0"));
3857 TexOutput(_T("\\'e8"));
3860 TexOutput(_T("\\'ec"));
3863 TexOutput(_T("\\'f2"));
3866 TexOutput(_T("\\'f9"));
3869 TexOutput(_T("\\'c0"));
3872 TexOutput(_T("\\'c8"));
3875 TexOutput(_T("\\'cc"));
3878 TexOutput(_T("\\'d2"));
3881 TexOutput(_T("\\'d9"));
3890 case ltACCENT_ACUTE
:
3894 wxChar
*val
= GetArgData();
3900 TexOutput(_T("\\'e1"));
3903 TexOutput(_T("\\'e9"));
3906 TexOutput(_T("\\'ed"));
3909 TexOutput(_T("\\'f3"));
3912 TexOutput(_T("\\'fa"));
3915 TexOutput(_T("\\'fd"));
3918 TexOutput(_T("\\'c1"));
3921 TexOutput(_T("\\'c9"));
3924 TexOutput(_T("\\'cd"));
3927 TexOutput(_T("\\'d3"));
3930 TexOutput(_T("\\'da"));
3933 TexOutput(_T("\\'dd"));
3942 case ltACCENT_CARET
:
3946 wxChar
*val
= GetArgData();
3952 TexOutput(_T("\\'e2"));
3955 TexOutput(_T("\\'ea"));
3958 TexOutput(_T("\\'ee"));
3961 TexOutput(_T("\\'f4"));
3964 TexOutput(_T("\\'fb"));
3967 TexOutput(_T("\\'c2"));
3970 TexOutput(_T("\\'ca"));
3973 TexOutput(_T("\\'ce"));
3976 TexOutput(_T("\\'d4"));
3979 TexOutput(_T("\\'db"));
3988 case ltACCENT_TILDE
:
3992 wxChar
*val
= GetArgData();
3998 TexOutput(_T("\\'e3"));
4004 TexOutput(_T("\\'f1"));
4007 TexOutput(_T("\\'f5"));
4010 TexOutput(_T("\\'c3"));
4013 TexOutput(_T("\\'d1"));
4016 TexOutput(_T("\\'d5"));
4025 case ltACCENT_UMLAUT
:
4029 wxChar
*val
= GetArgData();
4035 TexOutput(_T("\\'e4"));
4038 TexOutput(_T("\\'eb"));
4041 TexOutput(_T("\\'ef"));
4044 TexOutput(_T("\\'f6"));
4047 TexOutput(_T("\\'fc"));
4050 TexOutput(_T("\\'df"));
4053 TexOutput(_T("\\'ff"));
4056 TexOutput(_T("\\'c4"));
4059 TexOutput(_T("\\'cb"));
4062 TexOutput(_T("\\'cf"));
4065 TexOutput(_T("\\'d6"));
4068 TexOutput(_T("\\'dc"));
4071 TexOutput(_T("\\'df"));
4084 wxChar
*val
= GetArgData();
4090 TexOutput(_T("\\'e5"));
4093 TexOutput(_T("\\'c5"));
4102 case ltACCENT_CADILLA
:
4106 wxChar
*val
= GetArgData();
4112 TexOutput(_T("\\'e7"));
4115 TexOutput(_T("\\'c7"));
4126 static wxChar
*helpTopic
= NULL
;
4127 static FILE *savedOutput
= NULL
;
4134 OnInform(_T("Consider using \\footnotepopup instead of \\footnote."));
4137 wxSprintf(footBuf
, _T("(%d)"), footnoteCount
);
4139 TexOutput(_T(" {\\ul "));
4142 helpTopic
= FindTopicName(NULL
);
4143 TexOutput(_T("{\\v "));
4145 // Remove green colour/underlining if specified
4146 if (!hotSpotUnderline
&& !hotSpotColour
)
4148 else if (!hotSpotColour
)
4151 TexOutput(helpTopic
);
4154 wxFprintf(Popups
, _T("\\page\n"));
4155 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4156 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4157 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4158 savedOutput
= CurrentOutput1
;
4159 SetCurrentOutput(Popups
);
4163 SetCurrentOutput(savedOutput
);
4173 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), TRUE
);
4177 TexOutput(_T("}}"), TRUE
);
4182 case ltFOOTNOTEPOPUP
:
4184 static wxChar
*helpTopic
= NULL
;
4185 static FILE *savedOutput
= NULL
;
4192 TexOutput(_T("{\\ul "));
4194 else TexOutput(_T("}"));
4197 else if (arg_no
== 2)
4201 helpTopic
= FindTopicName(NULL
);
4202 TexOutput(_T("{\\v "));
4204 // Remove green colour/underlining if specified
4205 if (!hotSpotUnderline
&& !hotSpotColour
)
4207 else if (!hotSpotColour
)
4210 TexOutput(helpTopic
);
4213 wxFprintf(Popups
, _T("\\page\n"));
4214 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4215 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4216 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4217 savedOutput
= CurrentOutput1
;
4218 SetCurrentOutput(Popups
);
4222 SetCurrentOutput(savedOutput
);
4233 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), TRUE
);
4237 TexOutput(_T("}}"), TRUE
);
4245 if (start
&& (arg_no
== 1))
4257 if (winHelp
) return FALSE
;
4263 LeftHeaderEven
= GetArgChunk();
4264 if (wxStrlen(GetArgData(LeftHeaderEven
)) == 0)
4265 LeftHeaderEven
= NULL
;
4268 CentreHeaderEven
= GetArgChunk();
4269 if (wxStrlen(GetArgData(CentreHeaderEven
)) == 0)
4270 CentreHeaderEven
= NULL
;
4273 RightHeaderEven
= GetArgChunk();
4274 if (wxStrlen(GetArgData(RightHeaderEven
)) == 0)
4275 RightHeaderEven
= NULL
;
4278 LeftHeaderOdd
= GetArgChunk();
4279 if (wxStrlen(GetArgData(LeftHeaderOdd
)) == 0)
4280 LeftHeaderOdd
= NULL
;
4283 CentreHeaderOdd
= GetArgChunk();
4284 if (wxStrlen(GetArgData(CentreHeaderOdd
)) == 0)
4285 CentreHeaderOdd
= NULL
;
4288 RightHeaderOdd
= GetArgChunk();
4289 if (wxStrlen(GetArgData(RightHeaderOdd
)) == 0)
4290 RightHeaderOdd
= NULL
;
4291 OutputRTFHeaderCommands();
4306 if (winHelp
) return FALSE
;
4312 LeftFooterEven
= GetArgChunk();
4313 if (wxStrlen(GetArgData(LeftFooterEven
)) == 0)
4314 LeftFooterEven
= NULL
;
4317 CentreFooterEven
= GetArgChunk();
4318 if (wxStrlen(GetArgData(CentreFooterEven
)) == 0)
4319 CentreFooterEven
= NULL
;
4322 RightFooterEven
= GetArgChunk();
4323 if (wxStrlen(GetArgData(RightFooterEven
)) == 0)
4324 RightFooterEven
= NULL
;
4327 LeftFooterOdd
= GetArgChunk();
4328 if (wxStrlen(GetArgData(LeftFooterOdd
)) == 0)
4329 LeftFooterOdd
= NULL
;
4332 CentreFooterOdd
= GetArgChunk();
4333 if (wxStrlen(GetArgData(CentreFooterOdd
)) == 0)
4334 CentreFooterOdd
= NULL
;
4337 RightFooterOdd
= GetArgChunk();
4338 if (wxStrlen(GetArgData(RightFooterOdd
)) == 0)
4339 RightFooterOdd
= NULL
;
4340 OutputRTFFooterCommands();
4350 if (winHelp
) return FALSE
;
4351 // Fake a SetHeader command
4354 LeftHeaderOdd
= NULL
;
4355 CentreHeaderOdd
= NULL
;
4356 RightHeaderOdd
= NULL
;
4357 LeftHeaderEven
= NULL
;
4358 CentreHeaderEven
= NULL
;
4359 RightHeaderEven
= NULL
;
4360 OnInform(_T("Consider using setheader/setfooter rather than markright."));
4362 RTFOnArgument(ltSETHEADER
, 4, start
);
4364 OutputRTFHeaderCommands();
4369 if (winHelp
) return FALSE
;
4370 // Fake a SetHeader command
4377 LeftHeaderOdd
= NULL
;
4378 CentreHeaderOdd
= NULL
;
4379 RightHeaderOdd
= NULL
;
4380 LeftHeaderEven
= NULL
;
4381 CentreHeaderEven
= NULL
;
4382 RightHeaderEven
= NULL
;
4383 OnInform(_T("Consider using setheader/setfooter rather than markboth."));
4385 return RTFOnArgument(ltSETHEADER
, 1, start
);
4389 RTFOnArgument(ltSETHEADER
, 4, start
);
4391 OutputRTFHeaderCommands();
4397 case ltPAGENUMBERING
:
4404 if (winHelp
) return FALSE
;
4407 TexOutput(_T("\\pgnrestart"));
4408 wxChar
*data
= GetArgData();
4409 if (currentNumberStyle
) delete[] currentNumberStyle
;
4410 currentNumberStyle
= copystring(data
);
4411 OutputNumberStyle(currentNumberStyle
);
4413 TexOutput(_T("\n"));
4419 if (winHelp
) return FALSE
;
4428 wxChar
*val
= GetArgData();
4429 currentItemSep
= ParseUnitArgument(val
);
4434 case ltEVENSIDEMARGIN
:
4438 case ltODDSIDEMARGIN
:
4442 wxChar
*val
= GetArgData();
4443 int twips
= (int)(20*ParseUnitArgument(val
));
4444 // Add an inch since in LaTeX it's specified minus an inch
4446 CurrentLeftMarginOdd
= twips
;
4447 wxSprintf(buf
, _T("\\margl%d\n"), twips
);
4450 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4454 case ltMARGINPARWIDTH
:
4458 wxChar
*val
= GetArgData();
4459 int twips
= (int)(20*ParseUnitArgument(val
));
4460 CurrentMarginParWidth
= twips
;
4464 case ltMARGINPARSEP
:
4468 wxChar
*val
= GetArgData();
4469 int twips
= (int)(20*ParseUnitArgument(val
));
4470 CurrentMarginParSep
= twips
;
4471 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4479 wxChar
*val
= GetArgData();
4480 int twips
= (int)(20*ParseUnitArgument(val
));
4481 CurrentTextWidth
= twips
;
4483 // Need to set an implicit right margin
4484 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4485 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4486 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4487 wxSprintf(buf
, _T("\\margr%d\n"), CurrentRightMarginOdd
);
4493 case ltMARGINPARODD
:
4499 TexOutput(_T("\\box\n"));
4500 PushEnvironmentStyle(_T("\\box"));
4504 wxSprintf(buf
, _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4513 TexOutput(_T("\\par\\pard\n"));
4514 PopEnvironmentStyle();
4515 WriteEnvironmentStyles();
4518 TexOutput(_T("\\par\\pard\n"));
4519 issuedNewParagraph
= 1;
4523 case ltMARGINPAREVEN
:
4529 TexOutput(_T("\\box\n"));
4530 PushEnvironmentStyle(_T("\\box"));
4536 // Have to calculate what the margins are changed to in WfW margin
4537 // mirror mode, on an even (left-hand) page.
4538 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4539 - CurrentTextWidth
+ GutterWidth
;
4540 wxSprintf(buf
, _T("\\phpg\\posx%d\\absw%d\n"), x
, CurrentMarginParWidth
);
4545 wxSprintf(buf
, _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4555 TexOutput(_T("\\par\\pard\n"));
4556 PopEnvironmentStyle();
4557 WriteEnvironmentStyles();
4560 issuedNewParagraph
= 1;
4561 TexOutput(_T("\\par\\pard\n"));
4565 case ltTWOCOLWIDTHA
:
4569 wxChar
*val
= GetArgData();
4570 int twips
= (int)(20*ParseUnitArgument(val
));
4571 TwoColWidthA
= twips
;
4575 case ltTWOCOLWIDTHB
:
4579 wxChar
*val
= GetArgData();
4580 int twips
= (int)(20*ParseUnitArgument(val
));
4581 TwoColWidthB
= twips
;
4590 int currentWidth
= 0;
4592 if (!compatibilityMode
|| (currentRowNumber
> 0))
4594 TexOutput(_T("\\pard\\intbl"));
4596 if (macroId
== ltRULEDROW
)
4598 for (int i
= 0; i
< noColumns
; i
++)
4600 currentWidth
+= TableData
[i
].width
;
4603 TexOutput(_T("\\clbrdrt\\brdrs\\brdrw15"));
4605 else if (ruleTop
> 1)
4607 TexOutput(_T("\\clbrdrt\\brdrdb\\brdrw15"));
4609 if (ruleBottom
== 1)
4611 TexOutput(_T("\\clbrdrb\\brdrs\\brdrw15"));
4613 else if (ruleBottom
> 1)
4615 TexOutput(_T("\\clbrdrb\\brdrdb\\brdrw15"));
4618 if (TableData
[i
].rightBorder
)
4619 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
4621 if (TableData
[i
].leftBorder
)
4622 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
4624 wxSprintf(buf
, _T("\\cellx%d"), currentWidth
);
4627 TexOutput(_T("\\pard\\intbl\n"));
4631 currentRowNumber
++;
4636 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
4637 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
4643 static int noMultiColumns
= 0;
4650 noMultiColumns
= wxAtoi(GetArgData());
4667 for (int i
= 1; i
< noMultiColumns
; i
++)
4668 TexOutput(_T("\\cell"));
4675 if (start
&& (arg_no
== 1))
4678 // TexOutput(_T("\\fi0\n"));
4680 wxNode
*node
= itemizeStack
.GetFirst();
4682 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
4684 int indentValue
= 20*ParseUnitArgument(GetArgData());
4685 int indentSize
= indentValue
+ oldIndent
;
4687 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4688 itemizeStack
.Insert(struc
);
4690 wxSprintf(buf
, _T("\\tx%d\\li%d "), indentSize
, indentSize
);
4691 PushEnvironmentStyle(buf
);
4695 if (!start
&& (arg_no
== 2))
4697 PopEnvironmentStyle();
4698 if (itemizeStack
.GetFirst())
4700 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
4702 delete itemizeStack
.GetFirst();
4704 if (itemizeStack
.GetCount() == 0)
4706 TexOutput(_T("\\par\\pard\n"));
4707 issuedNewParagraph
= 1;
4708 WriteEnvironmentStyles();
4717 if (start && (arg_no == 1))
4720 wxNode *node = itemizeStack.GetFirst();
4722 oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
4724 int boxWidth = 20*ParseUnitArgument(GetArgData());
4726 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4727 int indentSize = indentValue + oldIndent;
4728 int indentSizeRight = indentSize + boxWidth;
4730 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4731 itemizeStack.Insert(struc);
4733 wxSprintf(buf, _T("\\tx%d\\li%d\\lr%d\\box%s "), indentSize, indentSize, indentSizeRight,
4734 ((macroId == ltCENTEREDBOX) ? _T("\\brdrs") : _T("\\brdrdb")));
4735 PushEnvironmentStyle(buf);
4739 if (!start && (arg_no == 2))
4741 PopEnvironmentStyle();
4742 if (itemizeStack.GetFirst())
4744 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
4746 delete itemizeStack.GetFirst();
4748 if (itemizeStack.Number() == 0)
4750 TexOutput(_T("\\par\\pard\n"));
4751 issuedNewParagraph = 1;
4752 WriteEnvironmentStyles();
4759 case ltDOCUMENTSTYLE
:
4761 DefaultOnArgument(macroId
, arg_no
, start
);
4762 if (!start
&& !IsArgOptional())
4764 if (MinorDocumentStyleString
)
4766 if (StringMatch(_T("twoside"), MinorDocumentStyleString
))
4767 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4768 TexOutput(_T("\\margmirror\\facingp\\sbkodd"));
4769 if (StringMatch(_T("twocolumn"), MinorDocumentStyleString
))
4770 TexOutput(_T("\\cols2"));
4772 TexOutput(_T("\n"));
4776 case ltSETHOTSPOTCOLOUR
:
4777 case ltSETHOTSPOTCOLOR
:
4781 wxChar
*text
= GetArgData();
4782 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4783 hotSpotColour
= TRUE
;
4785 hotSpotColour
= FALSE
;
4789 case ltSETTRANSPARENCY
:
4793 wxChar
*text
= GetArgData();
4794 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4795 bitmapTransparency
= TRUE
;
4797 bitmapTransparency
= FALSE
;
4801 case ltSETHOTSPOTUNDERLINE
:
4805 wxChar
*text
= GetArgData();
4806 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4807 hotSpotUnderline
= TRUE
;
4809 hotSpotUnderline
= FALSE
;
4815 if (arg_no
== 1 && start
)
4817 wxChar
*citeKey
= GetArgData();
4818 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4821 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4822 wxSprintf(buf
, _T("[%d]"), citeCount
);
4823 ref
->sectionNumber
= copystring(buf
);
4826 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
4827 wxSprintf(buf
, _T("{\\b [%d]} "), citeCount
);
4832 if (arg_no
== 2 && !start
)
4833 TexOutput(_T("\\par\\pard\\par\n\n"));
4836 case ltTHEBIBLIOGRAPHY
:
4838 if (start
&& (arg_no
== 1))
4842 SetCurrentOutputs(Contents
, Chapters
);
4846 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
4848 // If a non-custom page style, we generate the header now.
4849 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
4850 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
4851 wxStrcmp(PageStyle
, _T("headings")) == 0))
4853 OutputRTFHeaderCommands();
4854 OutputRTFFooterCommands();
4857 // Need to reset the current numbering style, or RTF forgets it.
4858 OutputNumberStyle(currentNumberStyle
);
4859 SetCurrentOutput(Contents
);
4862 wxFprintf(Chapters
, _T("\\page\n"));
4865 wxFprintf(Contents
, _T("\n{\\uldb %s}"), ReferencesNameString
);
4867 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %s}"), ReferencesNameString
);
4869 startedSections
= TRUE
;
4872 wxFprintf(Chapters
, _T("\n${\\footnote %s}"), ReferencesNameString
);
4874 wxChar
*topicName
= _T("bibliography");
4877 wxFprintf(Contents
, _T("{\\v %s}\\par\\pard\n"), topicName
);
4879 wxFprintf(Contents
, _T("\\par\\par\\pard\n"));
4883 wxFprintf(Chapters
, _T("\n#{\\footnote %s}\n"), topicName
);
4884 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
4885 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ReferencesNameString
);
4886 GenerateKeywordsForTopic(topicName
);
4889 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
4890 wxFileNameFromPath(FileRoot
), "Contents");
4894 SetCurrentOutput(Chapters
);
4895 wxChar
*styleCommand
= _T("");
4896 if (!winHelp
&& useHeadingStyles
)
4897 styleCommand
= _T("\\s1");
4898 wxFprintf(Chapters
, _T("\\pard{%s"), (winHelp
? _T("\\keepn\\sa140\\sb140") : styleCommand
));
4899 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" References\\par\\pard}\n"));
4908 * In Windows help, all keywords should be at the start of the
4909 * topic, but Latex \index commands can be anywhere in the text.
4910 * So we're going to have to build up lists of keywords for a topic,
4911 * and insert them on the second pass.
4913 * In linear RTF, we can embed the index entry now.
4918 // wxChar *entry = GetArgData();
4920 OutputChunkToString(GetArgChunk(), buf
);
4925 AddKeyWordForTopic(CurrentTopic
, buf
);
4928 else GenerateIndexEntry(buf
);
4941 wxChar
*name
= GetArgData();
4942 int pos
= FindColourPosition(name
);
4945 wxSprintf(buf
, _T("{%s%d "), ((macroId
== ltFCOL
) ? _T("\\cf") : _T("\\cb")), pos
);
4950 wxSprintf(buf
, _T("Could not find colour name %s"), name
);
4965 if (arg_no
== 2) TexOutput(_T("}"));
4971 if (start
&& !winHelp
&& useWord
)
4973 wxChar
*s
= GetArgData();
4974 // Only insert a bookmark here if it's not just been inserted
4975 // in a section heading.
4976 if ( !CurrentTopic
|| !(wxStrcmp(CurrentTopic
, s
) == 0) )
4978 if ( (!CurrentChapterName || !(CurrentChapterName && (wxStrcmp(CurrentChapterName, s) == 0))) &&
4979 (!CurrentSectionName || !(CurrentSectionName && (wxStrcmp(CurrentSectionName, s) == 0))) &&
4980 (!CurrentSubsectionName || !(CurrentSubsectionName && (wxStrcmp(CurrentSubsectionName, s) == 0)))
4984 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), s
,s
);
4991 if (start
&& useWord
&& !winHelp
)
4993 wxChar
*s
= GetArgData();
4994 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
5002 inPopRefSection
= TRUE
;
5004 inPopRefSection
= FALSE
;
5007 case ltINSERTATLEVEL
:
5009 // This macro allows you to insert text at a different level
5010 // from the current level, e.g. into the Sections from within a subsubsection.
5011 if (!winHelp
& useWord
)
5013 static int currentLevelNo
= 1;
5014 static FILE* oldLevelFile
= Chapters
;
5021 oldLevelFile
= CurrentOutput1
;
5023 wxChar
*str
= GetArgData();
5024 currentLevelNo
= wxAtoi(str
);
5026 // TODO: cope with article style (no chapters)
5027 switch (currentLevelNo
)
5031 outputFile
= Chapters
;
5036 outputFile
= Sections
;
5041 outputFile
= Subsections
;
5046 outputFile
= Subsubsections
;
5056 CurrentOutput1
= outputFile
;
5072 CurrentOutput1
= oldLevelFile
;
5078 return DefaultOnArgument(macroId
, arg_no
, start
);
5090 forbidParindent
= 0;
5091 contentsLineSection
= NULL
;
5092 contentsLineValue
= NULL
;
5093 descriptionItemArg
= NULL
;
5098 tableVerticalLineLeft
= FALSE
;
5099 tableVerticalLineRight
= FALSE
;
5101 startedSections
= FALSE
;
5105 if (InputFile
&& OutputFile
)
5107 // Do some RTF-specific transformations on all the strings,
5109 Text2RTF(GetTopLevelChunk());
5111 Contents
= wxFopen(TmpContentsName
, _T("w"));
5112 Chapters
= wxFopen(_T("chapters.rtf"), _T("w"));
5115 Sections
= wxFopen(_T("sections.rtf"), _T("w"));
5116 Subsections
= wxFopen(_T("subsections.rtf"), _T("w"));
5117 Subsubsections
= wxFopen(_T("subsubsections.rtf"), _T("w"));
5118 Popups
= wxFopen(_T("popups.rtf"), _T("w"));
5119 if (winHelpContents
)
5121 WinHelpContentsFile
= wxFopen(WinHelpContentsFileName
, _T("w"));
5122 if (WinHelpContentsFile
)
5123 wxFprintf(WinHelpContentsFile
, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot
));
5126 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5128 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5132 if (!Contents
|| !Chapters
)
5134 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5140 wxFprintf(Chapters
, _T("\n#{\\footnote Contents}\n"));
5141 wxFprintf(Chapters
, _T("${\\footnote Contents}\n"));
5142 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
5143 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ContentsNameString
);
5144 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
5148 wxFprintf(Chapters
, _T("\\titlepg\n"));
5149 wxFprintf(Contents
, _T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
5152 // In WinHelp, Contents title takes font of title.
5153 // In linear RTF, same as chapter headings.
5154 wxFprintf(Contents
, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"),
5155 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5157 // By default, Swiss, 10 point.
5158 wxFprintf(Chapters
, _T("\\f2\\fs20\n"));
5160 SetCurrentOutput(Chapters
);
5165 OnInform(_T("Converting..."));
5169 FILE *Header
= wxFopen(_T("header.rtf"), _T("w"));
5172 OnError(_T("Ouch! Could not open temporary file header.rtf for writing."));
5175 WriteRTFHeader(Header
);
5181 // wxFprintf(Contents, _T("\\page\n"));
5182 wxFprintf(Chapters
, _T("\\page\n"));
5183 wxFprintf(Sections
, _T("\\page\n"));
5184 wxFprintf(Subsections
, _T("\\page\n"));
5185 wxFprintf(Subsubsections
, _T("\\page\n\n"));
5186 wxFprintf(Popups
, _T("\\page\n}\n"));
5189 // TexOutput(_T("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n"));
5191 TexOutput(_T("}\n"));
5192 fclose(Contents
); Contents
= NULL
;
5193 fclose(Chapters
); Chapters
= NULL
;
5196 fclose(Sections
); Sections
= NULL
;
5197 fclose(Subsections
); Subsections
= NULL
;
5198 fclose(Subsubsections
); Subsubsections
= NULL
;
5199 fclose(Popups
); Popups
= NULL
;
5200 if (winHelpContents
)
5202 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5208 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5210 wxConcatFiles(_T("tmp1.rtf"), _T("sections.rtf"), _T("tmp2.rtf"));
5212 wxConcatFiles(_T("tmp2.rtf"), _T("subsections.rtf"), _T("tmp3.rtf"));
5214 wxConcatFiles(_T("tmp3.rtf"), _T("subsubsections.rtf"), _T("tmp4.rtf"));
5216 wxConcatFiles(_T("tmp4.rtf"), _T("popups.rtf"), OutputFile
);
5219 wxRemoveFile(_T("tmp1.rtf"));
5220 wxRemoveFile(_T("tmp2.rtf"));
5221 wxRemoveFile(_T("tmp3.rtf"));
5222 wxRemoveFile(_T("tmp4.rtf"));
5226 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5228 if (wxFileExists(OutputFile
))
5229 wxRemoveFile(OutputFile
);
5232 cwdStr
= wxGetWorkingDirectory();
5234 wxString outputDirStr
;
5235 outputDirStr
= wxPathOnly(OutputFile
);
5237 // Determine if the temp file and the output file are in the same directory,
5238 // and if they are, then just rename the temp file rather than copying
5239 // it, as this is much faster when working with large (multi-megabyte files)
5240 if ((wxStrcmp(outputDirStr
.c_str(),_T("")) == 0) || // no path specified on output file
5241 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5243 wxRenameFile(_T("tmp1.rtf"), OutputFile
);
5247 wxCopyFile(_T("tmp1.rtf"), OutputFile
);
5251 wxRemoveFile(_T("tmp1.rtf"));
5254 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5256 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5258 wxCopyFile(TmpContentsName
, ContentsName
);
5259 wxRemoveFile(TmpContentsName
);
5262 wxRemoveFile(_T("chapters.rtf"));
5263 wxRemoveFile(_T("header.rtf"));
5267 wxRemoveFile(_T("sections.rtf"));
5268 wxRemoveFile(_T("subsections.rtf"));
5269 wxRemoveFile(_T("subsubsections.rtf"));
5270 wxRemoveFile(_T("popups.rtf"));
5272 if (winHelp
&& generateHPJ
)
5273 WriteHPJ(OutputFile
);