]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/rtfutils.cpp
Compilation fixes for WXWIN_COMPATIBILITY_2_4.
[wxWidgets.git] / utils / tex2rtf / src / rtfutils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: rtfutils.cpp
3 // Purpose: Converts Latex to Word RTF/WinHelp RTF
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 7.9.93
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #endif
25
26 #include "tex2any.h"
27 #include "tex2rtf.h"
28 #include <ctype.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31
32 #ifdef __WIN32__
33 #include <windows.h>
34 #endif
35
36 #include "bmputils.h"
37 #include "table.h"
38
39 #if !WXWIN_COMPATIBILITY_2_4
40 static inline wxChar* copystring(const wxChar* s)
41 { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
42 #endif
43
44 wxList itemizeStack;
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
48
49 static char *contentsLineSection = NULL;
50 static char *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;
55 extern char *FileRoot;
56 extern bool winHelp;
57 extern bool startedSections;
58 extern FILE *Contents;
59 extern FILE *Chapters;
60 extern FILE *Popups;
61 extern FILE *WinHelpContentsFile;
62 extern char *RTFCharset;
63 // This is defined in the Tex2Any library and isn't in use after parsing
64 extern char *BigBuffer;
65
66 extern wxHashTable TexReferences;
67
68 // Are we in verbatim mode? If so, format differently.
69 static bool inVerbatim = FALSE;
70
71 // We're in a series of PopRef topics, so don't output section headings
72 bool inPopRefSection = FALSE;
73
74 // Green colour?
75 static bool hotSpotColour = TRUE;
76 static bool hotSpotUnderline = TRUE;
77
78 // Transparency (WHITE = transparent)
79 static bool bitmapTransparency = TRUE;
80
81 // Linear RTF requires us to set the style per section.
82 static char *currentNumberStyle = NULL;
83 static int currentItemSep = 8;
84 static int CurrentTextWidth = 8640; // Say, six inches
85 static int CurrentLeftMarginOdd = 400;
86 static int CurrentLeftMarginEven = 1440;
87 static int CurrentRightMarginOdd = 1440;
88 static int CurrentRightMarginEven = 400;
89 static int CurrentMarginParWidth = 2000;
90 static int CurrentMarginParSep = 400; // Gap between marginpar and text
91 static int CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep;
92 static int GutterWidth = 2300;
93
94 // Two-column table dimensions, in twips
95 static int TwoColWidthA = 1500;
96 static int TwoColWidthB = 3000;
97
98 const int PageWidth = 12242; // 8.25 inches wide for A4
99
100 // Remember the anchor in a helpref
101 static TexChunk *helpRefText = NULL;
102
103 /*
104 * Flag to say we've just issued a \par\pard command, so don't
105 * repeat this unnecessarily.
106 *
107 */
108
109 int issuedNewParagraph = 0;
110
111 // Need to know whether we're in a table or figure for benefit
112 // of listoffigures/listoftables
113 static bool inFigure = FALSE;
114 static bool inTable = FALSE;
115
116 /*
117 * Current topics
118 *
119 */
120 static char *CurrentChapterName = NULL;
121 static char *CurrentSectionName = NULL;
122 static char *CurrentSubsectionName = NULL;
123 static char *CurrentTopic = NULL;
124
125 static bool InPopups()
126 {
127 if (CurrentChapterName && (strcmp(CurrentChapterName, "popups") == 0))
128 return TRUE;
129 if (CurrentSectionName && (strcmp(CurrentSectionName, "popups") == 0))
130 return TRUE;
131 return FALSE;
132 }
133
134 static void SetCurrentTopic(char *s)
135 {
136 if (CurrentTopic) delete[] CurrentTopic;
137 CurrentTopic = copystring(s);
138 }
139
140 void SetCurrentChapterName(char *s)
141 {
142 if (CurrentChapterName) delete[] CurrentChapterName;
143 CurrentChapterName = copystring(s);
144 SetCurrentTopic(s);
145 }
146 void SetCurrentSectionName(char *s)
147 {
148 if (CurrentSectionName) delete[] CurrentSectionName;
149 CurrentSectionName = copystring(s);
150 SetCurrentTopic(s);
151 }
152 void SetCurrentSubsectionName(char *s)
153 {
154 if (CurrentSubsectionName) delete[] CurrentSubsectionName;
155 CurrentSubsectionName = copystring(s);
156 SetCurrentTopic(s);
157 }
158
159 // Indicate that a parent topic at level 'level' has children.
160 // Level 1 is a chapter, 2 is a section, etc.
161 void NotifyParentHasChildren(int parentLevel)
162 {
163 char *parentTopic = NULL;
164 switch (parentLevel)
165 {
166 case 1:
167 {
168 parentTopic = CurrentChapterName;
169 break;
170 }
171 case 2:
172 {
173 parentTopic = CurrentSectionName;
174 break;
175 }
176 case 3:
177 {
178 parentTopic = CurrentSubsectionName;
179 break;
180 }
181 default:
182 {
183 break;
184 }
185 }
186 if (parentTopic)
187 {
188 TexTopic *texTopic = (TexTopic *)TopicTable.Get(parentTopic);
189 if (!texTopic)
190 {
191 texTopic = new TexTopic;
192 TopicTable.Put(parentTopic, texTopic);
193 }
194 texTopic->hasChildren = TRUE;
195 }
196 }
197
198 // Have to keep a count of what levels are books, what are pages,
199 // in order to correct for a Win95 bug which means that if you
200 // have a book at level n, and then a page at level n, the page
201 // ends up on level n + 1.
202
203 bool ContentsLevels[5];
204
205 // Reset below this level (starts from 1)
206 void ResetContentsLevels(int l)
207 {
208 int i;
209 for (i = l; i < 5; i++)
210 ContentsLevels[i] = FALSE;
211
212 // There are always books on the top level
213 ContentsLevels[0] = TRUE;
214 }
215
216 // Output a WinHelp section as a keyword, substituting
217 // : for space.
218 void OutputSectionKeyword(FILE *fd)
219 {
220 OutputCurrentSectionToString(wxTex2RTFBuffer);
221
222 unsigned int i;
223 for (i = 0; i < strlen(wxTex2RTFBuffer); i++)
224 if (wxTex2RTFBuffer[i] == ':')
225 wxTex2RTFBuffer[i] = ' ';
226 // Don't write to index if there's some RTF in the string
227 else if ( wxTex2RTFBuffer[i] == '{' )
228 return;
229
230 fprintf(fd, "K{\\footnote {K} ");
231 fprintf(fd, "%s", wxTex2RTFBuffer);
232
233 fprintf(fd, "}\n");
234 }
235
236 // Write a line for the .cnt file, if we're doing this.
237 void WriteWinHelpContentsFileLine(char *topicName, char *xitle, int level)
238 {
239 // First, convert any RTF characters to ASCII
240 char title[255];
241 int s=0;
242 int d=0;
243 while ( (xitle[s]!=0)&&(d<255) )
244 {
245 char ch=xitle[s]&0xff;
246 if (ch==0x5c) {
247 char ch1=xitle[s+1]&0xff;
248 char ch2=xitle[s+2]&0xff;
249 char ch3=xitle[s+3]&0xff;
250 char ch4=xitle[s+4]&0xff;
251 s+=4; // next character
252 char a=0;
253 if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]='ö'; a=1; }
254 if ((ch1==0x27)&&(ch2==0x65)&&(ch3==0x34)) { title[d++]='ä'; a=1; }
255 if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x63)) { title[d++]='ü'; a=1; }
256 if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x36)) { title[d++]='Ö'; a=1; }
257 if ((ch1==0x27)&&(ch2==0x63)&&(ch3==0x34)) { title[d++]='Ä'; a=1; }
258 if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x63)) { title[d++]='Ü'; a=1; }
259 // if (a==0)
260 // printf("!!!!! %04X %04X %04X %04X! \n",ch1,ch2,ch3,ch4);
261 } else {
262 title[d++]=ch;
263 s++;
264 }
265 }
266 title[d]=0;
267
268 // Section (2) becomes level 1 if it's an article.
269 if (DocumentStyle == LATEX_ARTICLE)
270 level --;
271
272 if (level == 0) // Means we had a Chapter in an article, oops.
273 return;
274
275 ResetContentsLevels(level);
276
277 if (!title)
278 return;
279
280 if (winHelp && winHelpContents && WinHelpContentsFile)
281 {
282 TexTopic *texTopic = (TexTopic *)TopicTable.Get(topicName);
283 if (texTopic)
284 {
285 // If a previous section at this level was a book, we *have* to have a
286 // book not a page, because of a bug in WHC (or WinHelp 4).
287 if (texTopic->hasChildren || level == 1 || ContentsLevels[level-1])
288 {
289 // At this level, we have a pointer to a further hierarchy.
290 // So we need a 'book' consisting of (say) Chapter 1.
291 fprintf(WinHelpContentsFile, "%d %s\n", level, title);
292
293 // Then we have a 'page' consisting of the text for this chapter
294 fprintf(WinHelpContentsFile, "%d %s=%s\n", level+1, title, topicName);
295
296 // Then we'll be writing out further pages or books at level + 1...
297
298 // Remember that at this level, we had a book and *must* for the
299 // remainder of sections at this level.
300 ContentsLevels[level-1] = TRUE;
301 }
302 else
303 {
304 fprintf(WinHelpContentsFile, "%d %s=%s\n", level, title, topicName);
305 }
306 }
307 else
308 {
309 if (level == 1 || ContentsLevels[level-1])
310 {
311 // Always have a book at level 1
312 fprintf(WinHelpContentsFile, "%d %s\n", level, title);
313 fprintf(WinHelpContentsFile, "%d %s=%s\n", level+1, title, topicName);
314 ContentsLevels[level-1] = TRUE;
315 }
316 else
317 // Probably doesn't have children if it hasn't been added to the topic table
318 fprintf(WinHelpContentsFile, "%d %s=%s\n", level, title, topicName);
319 }
320 }
321 }
322
323 void SplitIndexEntry(char *entry, char *buf1, char *buf2)
324 {
325 int len = strlen(entry); int i = 0;
326 while ((i < len) && entry[i] != '!')
327 { buf1[i] = entry[i]; i ++; }
328 buf1[i] = 0; buf2[0] = 0; int j = 0;
329
330 if (entry[i] == '!')
331 {
332 i ++;
333 while (i < len) { buf2[j] = entry[i]; i ++; j++; }
334 buf2[j] = 0;
335 }
336 }
337
338 /*
339 * Output topic index entries in WinHelp RTF
340 *
341 */
342 void GenerateKeywordsForTopic(char *topic)
343 {
344 TexTopic *texTopic = (TexTopic *)TopicTable.Get(topic);
345 if (!texTopic)
346 return;
347
348 wxStringList *list = texTopic->keywords;
349 if (list)
350 {
351 wxNode *node = list->First();
352 while (node)
353 {
354 char *s = (char *)node->Data();
355
356 // Must separate out main entry form subentry (only 1 subentry allowed)
357 char buf1[100]; char buf2[100];
358 SplitIndexEntry(s, buf1, buf2);
359
360 // Check for ':' which messes up index
361 unsigned int i;
362 for (i = 0; i < strlen(buf1) ; i++)
363 if (buf1[i] == ':')
364 buf1[i] = ' ';
365 for (i = 0; i < strlen(buf2) ; i++)
366 if (buf2[i] == ':')
367 buf2[i] = ' ';
368
369 // {K} is a strange fix to prevent words beginning with K not
370 // being indexed properly
371 TexOutput("K{\\footnote {K} ");
372 TexOutput(buf1);
373 if (strlen(buf2) > 0)
374 {
375 // Output subentry
376 TexOutput(", ");
377 TexOutput(buf2);
378 }
379 TexOutput("}\n");
380 node = node->Next();
381 }
382 }
383 }
384
385 /*
386 * Output index entry in linear RTF
387 *
388 */
389
390 void GenerateIndexEntry(char *entry)
391 {
392 if (useWord)
393 {
394 char buf1[100]; char buf2[100];
395 SplitIndexEntry(entry, buf1, buf2);
396
397 TexOutput("{\\xe\\v {");
398 TexOutput(buf1);
399 if (strlen(buf2) > 0)
400 {
401 TexOutput("\\:");
402 TexOutput(buf2);
403 }
404 TexOutput("}}");
405 }
406 }
407
408 /*
409 * Write a suitable RTF header.
410 *
411 */
412
413 void WriteColourTable(FILE *fd)
414 {
415 fprintf(fd, "{\\colortbl");
416 wxNode *node = ColourTable.First();
417 while (node)
418 {
419 ColourTableEntry *entry = (ColourTableEntry *)node->Data();
420 fprintf(fd, "\\red%d\\green%d\\blue%d;\n", entry->red, entry->green, entry->blue);
421 node = node->Next();
422 }
423 fprintf(fd, "}");
424 }
425
426 /*
427 * Write heading style
428 *
429 */
430
431 void WriteHeadingStyle(FILE *fd, int heading)
432 {
433 switch (heading)
434 {
435 case 1:
436 {
437 fprintf(fd, "\\b\\fs%d", chapterFont*2);
438 break;
439 }
440 case 2:
441 {
442 fprintf(fd, "\\b\\fs%d", sectionFont*2);
443 break;
444 }
445 case 3:
446 {
447 fprintf(fd, "\\b\\fs%d", subsectionFont*2);
448 break;
449 }
450 case 4:
451 {
452 fprintf(fd, "\\b\\fs%d", subsectionFont*2);
453 break;
454 }
455 default:
456 break;
457 }
458 }
459
460 void WriteRTFHeader(FILE *fd)
461 {
462 fprintf(fd, "{\\rtf1\\%s \\deff0\n", RTFCharset);
463 fprintf(fd, "{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n");
464 fprintf(fd, "{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}");
465 /*
466 * Style sheet
467 */
468 fprintf(fd, "{\\stylesheet{\\f2\\fs20 \\snext0 Normal;}\n");
469 // Headings
470 fprintf(fd, "{\\s1 "); WriteHeadingStyle(fd, 1); fprintf(fd, "\\sbasedon0\\snext0 heading 1;}\n");
471 fprintf(fd, "{\\s2 "); WriteHeadingStyle(fd, 2); fprintf(fd, "\\sbasedon0\\snext0 heading 2;}\n");
472 fprintf(fd, "{\\s3 "); WriteHeadingStyle(fd, 3); fprintf(fd, "\\sbasedon0\\snext0 heading 3;}\n");
473 fprintf(fd, "{\\s4 "); WriteHeadingStyle(fd, 4); fprintf(fd, "\\sbasedon0\\snext0 heading 4;}\n");
474 // Table of contents styles
475 fprintf(fd, "{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n");
476
477 fprintf(fd, "{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n");
478 fprintf(fd, "{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n");
479 fprintf(fd, "{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n");
480
481 // Index styles
482 fprintf(fd, "{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n");
483 fprintf(fd, "{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n");
484 fprintf(fd, "{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n");
485 fprintf(fd, "{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n");
486 fprintf(fd, "{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n");
487 fprintf(fd, "}\n");
488
489 WriteColourTable(fd);
490 fprintf(fd, "\n\\ftnbj\\ftnrestart"); // Latex default is footnotes at bottom of page, not section.
491 fprintf(fd, "\n");
492 }
493
494 void OutputNumberStyle(char *numberStyle)
495 {
496 if (numberStyle)
497 {
498 if (strcmp(numberStyle, "arabic") == 0)
499 {
500 TexOutput("\\pgndec");
501 }
502 else if (strcmp(numberStyle, "roman") == 0)
503 {
504 TexOutput("\\pgnlcrm");
505 }
506 else if (strcmp(numberStyle, "Roman") == 0)
507 {
508 TexOutput("\\pgnucrm");
509 }
510 else if (strcmp(numberStyle, "alph") == 0)
511 {
512 TexOutput("\\pgnlcltr");
513 }
514 else if (strcmp(numberStyle, "Alph") == 0)
515 {
516 TexOutput("\\pgnucltr");
517 }
518 }
519 }
520
521 /*
522 * Write a Windows help project file
523 */
524
525 bool WriteHPJ(char *filename)
526 {
527 char hpjFilename[256];
528 char helpFile[50];
529 char rtfFile[50];
530 strcpy(hpjFilename, filename);
531 StripExtension(hpjFilename);
532 strcat(hpjFilename, ".hpj");
533
534 strcpy(helpFile, wxFileNameFromPath(filename));
535 StripExtension(helpFile);
536 strcpy(rtfFile, helpFile);
537 strcat(helpFile, ".hlp");
538 strcat(rtfFile, ".rtf");
539
540 FILE *fd = fopen(hpjFilename, "w");
541 if (!fd)
542 return FALSE;
543
544 char *helpTitle = winHelpTitle;
545 if (!helpTitle)
546 helpTitle = "Untitled";
547
548 wxString thePath = wxPathOnly(InputFile);
549 if (thePath.IsEmpty())
550 thePath = ".";
551 fprintf(fd, "[OPTIONS]\n");
552 fprintf(fd, "BMROOT=%s ; Assume that bitmaps are where the source is\n", thePath.c_str());
553 fprintf(fd, "TITLE=%s\n", helpTitle);
554 fprintf(fd, "CONTENTS=Contents\n");
555
556 if (winHelpVersion > 3)
557 {
558 fprintf(fd, "; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n");
559 fprintf(fd, "COMPRESS=8 Zeck\n");
560 fprintf(fd, "LCID=0x809 0x0 0x0 ;English (British)\n");
561 fprintf(fd, "HLP=.\\%s.hlp\n", wxFileNameFromPath(FileRoot));
562 }
563 else
564 {
565 fprintf(fd, "COMPRESS=HIGH\n");
566 }
567 fprintf(fd, "\n");
568
569 if (winHelpVersion > 3)
570 {
571 fprintf(fd, "[WINDOWS]\n");
572 fprintf(fd, "Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n");
573 fprintf(fd, "\n");
574 }
575
576 fprintf(fd, "[FILES]\n%s\n\n", rtfFile);
577 fprintf(fd, "[CONFIG]\n");
578 if (useUpButton)
579 fprintf(fd, "CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n", helpFile);
580 fprintf(fd, "BrowseButtons()\n\n");
581 fprintf(fd, "[MAP]\n\n[BITMAPS]\n\n");
582 fclose(fd);
583 return TRUE;
584 }
585
586
587 /*
588 * Given a TexChunk with a string value, scans through the string
589 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
590 * and inserting spaces at the start of lines since in Latex, a newline
591 * implies a space, but not in RTF.
592 *
593 */
594
595 void ProcessText2RTF(TexChunk *chunk)
596 {
597 bool changed = FALSE;
598 int ptr = 0;
599 int i = 0;
600 char ch = 1;
601 int len = strlen(chunk->value);
602 while (ch != 0)
603 {
604 ch = chunk->value[i];
605
606 if (ch == 10)
607 {
608 if (inVerbatim)
609 {
610 BigBuffer[ptr] = 0; strcat(BigBuffer, "\\par\n"); ptr += 5;
611 i ++;
612 changed = TRUE;
613 }
614 else
615 {
616 // If the first character of the next line is ASCII,
617 // put a space in. Implicit in Latex, not in RTF.
618 /*
619 The reason this is difficult is that you don't really know
620 where a space would be appropriate. If you always put in a space
621 when you find a newline, unwanted spaces appear in the text.
622 */
623 if ((i > 0) && (len > i+1 && isascii(chunk->value[i+1]) &&
624 !isspace(chunk->value[i+1])) ||
625 ((len > i+1 && chunk->value[i+1] == 13) &&
626 (len > i+2 && isascii(chunk->value[i+2]) &&
627 !isspace(chunk->value[i+2]))))
628 // if (TRUE)
629 {
630 // DOS files have a 13 after the 10
631 BigBuffer[ptr] = 10;
632 ptr ++;
633 i ++;
634 if (chunk->value[i] == 13)
635 {
636 BigBuffer[ptr] = 13;
637 ptr ++;
638 i ++;
639 }
640
641 BigBuffer[ptr] = ' ';
642 ptr ++;
643
644 // Note that the actual ASCII character seen is dealt with in the next
645 // iteration
646 changed = TRUE;
647 }
648 else
649 {
650 BigBuffer[ptr] = ch;
651 i ++;
652 }
653 }
654 }
655 else if (!inVerbatim && ch == '`' && (len >= i+1 && chunk->value[i+1] == '`'))
656 {
657 BigBuffer[ptr] = '"'; ptr ++;
658 i += 2;
659 changed = TRUE;
660 }
661 else if (!inVerbatim && ch == '`') // Change ` to '
662 {
663 BigBuffer[ptr] = 39; ptr ++;
664 i += 1;
665 changed = TRUE;
666 }
667 else if (inVerbatim && ch == '\\') // Change backslash to two backslashes
668 {
669 BigBuffer[ptr] = '\\'; ptr ++;
670 BigBuffer[ptr] = '\\'; ptr ++;
671 i += 1;
672 changed = TRUE;
673 }
674 else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curley bracket
675 {
676 BigBuffer[ptr] = '\\'; ptr ++;
677 BigBuffer[ptr] = ch; ptr ++;
678 i += 1;
679 changed = TRUE;
680 }
681 else
682 {
683 BigBuffer[ptr] = ch;
684 i ++;
685 ptr ++;
686 }
687 }
688 BigBuffer[ptr] = 0;
689
690 if (changed)
691 {
692 delete[] chunk->value;
693 chunk->value = copystring(BigBuffer);
694 }
695 }
696
697 /*
698 * Scan through all chunks starting from the given one,
699 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
700 * This should be called after Tex2Any has parsed the file,
701 * and before TraverseDocument is called.
702 *
703 */
704
705 void Text2RTF(TexChunk *chunk)
706 {
707 Tex2RTFYield();
708 if (stopRunning) return;
709
710 switch (chunk->type)
711 {
712 case CHUNK_TYPE_MACRO:
713 {
714 TexMacroDef *def = chunk->def;
715 if (def && def->ignore)
716 return;
717
718 if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB))
719 inVerbatim = TRUE;
720
721 wxNode *node = chunk->children.First();
722 while (node)
723 {
724 TexChunk *child_chunk = (TexChunk *)node->Data();
725 Text2RTF(child_chunk);
726 node = node->Next();
727 }
728
729 if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB))
730 inVerbatim = FALSE;
731
732 break;
733 }
734 case CHUNK_TYPE_ARG:
735 {
736 wxNode *node = chunk->children.First();
737 while (node)
738 {
739 TexChunk *child_chunk = (TexChunk *)node->Data();
740 Text2RTF(child_chunk);
741 node = node->Next();
742 }
743
744 break;
745 }
746 case CHUNK_TYPE_STRING:
747 {
748 if (chunk->value)
749 ProcessText2RTF(chunk);
750 break;
751 }
752 }
753 }
754
755 /*
756 * Not used yet
757 *
758 */
759
760 char browseBuf[10];
761 static long browseId = 0;
762 char *GetBrowseString(void)
763 {
764 char buf[10];
765 browseId ++;
766 sprintf(buf, "%ld", browseId);
767 int noZeroes = 5-strlen(buf);
768 strcpy(browseBuf, "browse");
769 for (int i = 0; i < noZeroes; i++)
770 strcat(browseBuf, "0");
771 strcat(browseBuf, buf);
772 return browseBuf;
773 }
774
775 /*
776 * Keeping track of environments to restore the styles after \pard.
777 * Push strings like "\qc" onto stack.
778 *
779 */
780
781 void PushEnvironmentStyle(char *style)
782 {
783 environmentStack.Add(style);
784 }
785
786 void PopEnvironmentStyle(void)
787 {
788 wxNode *node = environmentStack.Last();
789 if (node)
790 {
791 char *val = (char *)node->Data();
792 delete[] val;
793 delete node;
794 }
795 }
796
797 // Write out the styles, most recent first.
798 void WriteEnvironmentStyles(void)
799 {
800 wxNode *node = environmentStack.Last();
801 while (node)
802 {
803 char *val = (char *)node->Data();
804 TexOutput(val);
805 node = node->Next();
806 }
807 if (!inTabular && (ParIndent > 0) && (forbidParindent == 0))
808 {
809 char buf[15];
810 sprintf(buf, "\\fi%d", ParIndent*20); // Convert points to TWIPS
811 TexOutput(buf);
812 }
813 if (environmentStack.Number() > 0 || (ParIndent > 0))
814 TexOutput("\n");
815 }
816
817
818 /*
819 * Output a header
820 *
821 */
822
823 void OutputRTFHeaderCommands(void)
824 {
825 char buf[300];
826 if (PageStyle && strcmp(PageStyle, "plain") == 0)
827 {
828 TexOutput("{\\headerl }{\\headerr }");
829 }
830 else if (PageStyle && strcmp(PageStyle, "empty") == 0)
831 {
832 TexOutput("{\\headerl }{\\headerr }");
833 }
834 else if (PageStyle && strcmp(PageStyle, "headings") == 0)
835 {
836 // Left header
837 TexOutput("{\\headerl\\fi0 ");
838
839 if (headerRule)
840 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
841
842 TexOutput("{\\i \\qr ");
843 if (DocumentStyle == LATEX_ARTICLE)
844 {
845 sprintf(buf, "SECTION %d", sectionNo);
846 TexOutput(buf);
847 }
848 else
849 {
850 sprintf(buf, "CHAPTER %d: ", chapterNo);
851 TexOutput(buf);
852 }
853 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
854 TexOutput("}\\par\\pard}");
855
856 // Right header
857 TexOutput("{\\headerr\\fi0 ");
858
859 if (headerRule)
860 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
861
862 TexOutput("{\\i \\qc ");
863 if (DocumentStyle == LATEX_ARTICLE)
864 {
865 sprintf(buf, "SECTION %d", sectionNo);
866 TexOutput(buf);
867 }
868 else
869 {
870 sprintf(buf, "CHAPTER %d", chapterNo);
871 TexOutput(buf);
872 }
873 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
874 TexOutput("}\\par\\pard}");
875 }
876 else
877 {
878 int oldForbidResetPar = forbidResetPar;
879 forbidResetPar = 0;
880
881 if (LeftHeaderEven || CentreHeaderEven || RightHeaderEven)
882 {
883 TexOutput("{\\headerl\\fi0 ");
884
885 if (headerRule)
886 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
887
888 if (LeftHeaderEven)
889 {
890 if (!CentreHeaderEven && !RightHeaderEven)
891 TexOutput("\\ql ");
892 TraverseChildrenFromChunk(LeftHeaderEven);
893 }
894 if (CentreHeaderEven)
895 {
896 if (!LeftHeaderEven && !RightHeaderEven)
897 TexOutput("\\qc ");
898 else
899 TexOutput("\\tab\\tab\\tab ");
900 TraverseChildrenFromChunk(CentreHeaderEven);
901 }
902 if (RightHeaderEven)
903 {
904 if (!LeftHeaderEven && !CentreHeaderEven)
905 TexOutput("\\qr ");
906 else
907 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
908 TraverseChildrenFromChunk(RightHeaderEven);
909 }
910 TexOutput("\\par\\pard}");
911 }
912
913 if (LeftHeaderOdd || CentreHeaderOdd || RightHeaderOdd)
914 {
915 TexOutput("{\\headerr\\fi0 ");
916
917 if (headerRule)
918 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
919
920 if (LeftHeaderOdd)
921 {
922 if (!CentreHeaderOdd && !RightHeaderOdd)
923 TexOutput("\\ql ");
924 TraverseChildrenFromChunk(LeftHeaderOdd);
925 }
926 if (CentreHeaderOdd)
927 {
928 if (!LeftHeaderOdd && !RightHeaderOdd)
929 TexOutput("\\qc ");
930 else
931 TexOutput("\\tab\\tab\\tab ");
932 TraverseChildrenFromChunk(CentreHeaderOdd);
933 }
934 if (RightHeaderOdd)
935 {
936 if (!LeftHeaderOdd && !CentreHeaderOdd)
937 TexOutput("\\qr ");
938 else
939 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
940 TraverseChildrenFromChunk(RightHeaderOdd);
941 }
942 TexOutput("\\par\\pard}");
943 }
944 // As an approximation, don't put a header on the first page of a section.
945 // This may not always be desired, but it's a reasonable guess.
946 TexOutput("{\\headerf }");
947
948 forbidResetPar = oldForbidResetPar;
949 }
950 }
951
952 void OutputRTFFooterCommands(void)
953 {
954 if (PageStyle && strcmp(PageStyle, "plain") == 0)
955 {
956 TexOutput("{\\footerl\\fi0 ");
957 if (footerRule)
958 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
959 TexOutput("{\\qc ");
960 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
961 TexOutput("}\\par\\pard}");
962
963 TexOutput("{\\footerr\\fi0 ");
964 if (footerRule)
965 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
966 TexOutput("{\\qc ");
967 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
968 TexOutput("}\\par\\pard}");
969 }
970 else if (PageStyle && strcmp(PageStyle, "empty") == 0)
971 {
972 TexOutput("{\\footerl }{\\footerr }");
973 }
974 else if (PageStyle && strcmp(PageStyle, "headings") == 0)
975 {
976 TexOutput("{\\footerl }{\\footerr }");
977 }
978 else
979 {
980 if (LeftFooterEven || CentreFooterEven || RightFooterEven)
981 {
982 TexOutput("{\\footerl\\fi0 ");
983 if (footerRule)
984 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
985 if (LeftFooterEven)
986 {
987 if (!CentreFooterEven && !RightFooterEven)
988 TexOutput("\\ql ");
989 TraverseChildrenFromChunk(LeftFooterEven);
990 }
991 if (CentreFooterEven)
992 {
993 if (!LeftFooterEven && !RightFooterEven)
994 TexOutput("\\qc ");
995 else
996 TexOutput("\\tab\\tab\\tab ");
997 TraverseChildrenFromChunk(CentreFooterEven);
998 }
999 if (RightFooterEven)
1000 {
1001 if (!LeftFooterEven && !CentreFooterEven)
1002 TexOutput("\\qr ");
1003 else
1004 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1005 TraverseChildrenFromChunk(RightFooterEven);
1006 }
1007 TexOutput("\\par\\pard}");
1008 }
1009
1010 if (LeftFooterOdd || CentreFooterOdd || RightFooterOdd)
1011 {
1012 TexOutput("{\\footerr\\fi0 ");
1013 if (footerRule)
1014 TexOutput("\\brdrt\\brdrs\\brdrw15\\brsp20 ");
1015 if (LeftFooterOdd)
1016 {
1017 if (!CentreFooterOdd && !RightFooterOdd)
1018 TexOutput("\\ql ");
1019 TraverseChildrenFromChunk(LeftFooterOdd);
1020 }
1021 if (CentreFooterOdd)
1022 {
1023 if (!LeftFooterOdd && !RightFooterOdd)
1024 TexOutput("\\qc ");
1025 else
1026 TexOutput("\\tab\\tab\\tab ");
1027 TraverseChildrenFromChunk(CentreFooterOdd);
1028 }
1029 if (RightFooterOdd)
1030 {
1031 if (!LeftFooterOdd && !CentreFooterOdd)
1032 TexOutput("\\qr ");
1033 else
1034 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1035 TraverseChildrenFromChunk(RightFooterOdd);
1036 }
1037 TexOutput("\\par\\pard}");
1038 }
1039
1040 // As an approximation, put a footer on the first page of a section.
1041 // This may not always be desired, but it's a reasonable guess.
1042 if (LeftFooterOdd || CentreFooterOdd || RightFooterOdd)
1043 {
1044 TexOutput("{\\footerf\\fi0 ");
1045 if (LeftFooterOdd)
1046 {
1047 if (!CentreFooterOdd && !RightFooterOdd)
1048 TexOutput("\\ql ");
1049 TraverseChildrenFromChunk(LeftFooterOdd);
1050 }
1051 if (CentreFooterOdd)
1052 {
1053 if (!LeftFooterOdd && !RightFooterOdd)
1054 TexOutput("\\qc ");
1055 else
1056 TexOutput("\\tab\\tab\\tab ");
1057 TraverseChildrenFromChunk(CentreFooterOdd);
1058 }
1059 if (RightFooterOdd)
1060 {
1061 if (!LeftFooterOdd && !CentreFooterOdd)
1062 TexOutput("\\qr ");
1063 else
1064 TexOutput("\\tab\\tab\\tab\\tab\\tab\\tab ");
1065 TraverseChildrenFromChunk(RightFooterOdd);
1066 }
1067 TexOutput("\\par\\pard}");
1068 }
1069 }
1070 }
1071
1072 // Called on start/end of macro examination
1073 void RTFOnMacro(int macroId, int no_args, bool start)
1074 {
1075 /*
1076 char tmpBuf[40];
1077 sprintf(tmpBuf, "%d (%d)", macroId, (int)start);
1078 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1079 OutputDebugString("\n"); wxYield();
1080 */
1081
1082 // ltLABEL is included here because after a section but BEFORE
1083 // the label is seen, a new paragraph is issued. Don't upset this by
1084 // immediately forgetting we've done it.
1085 if (start && (macroId != ltPAR && macroId != ltITEMIZE &&
1086 macroId != ltENUMERATE && macroId != ltDESCRIPTION &&
1087 macroId != ltVERBATIM && macroId != ltLABEL &&
1088 macroId != ltSETHEADER && macroId != ltSETFOOTER &&
1089 macroId != ltPAGENUMBERING &&
1090 (forbidResetPar == 0)))
1091 {
1092 issuedNewParagraph = 0;
1093 }
1094
1095 char buf[300];
1096 switch (macroId)
1097 {
1098 case ltCHAPTER:
1099 case ltCHAPTERSTAR:
1100 case ltCHAPTERHEADING:
1101 case ltCHAPTERHEADINGSTAR:
1102 {
1103 if (!start)
1104 {
1105 sectionNo = 0;
1106 figureNo = 0;
1107 tableNo = 0;
1108 subsectionNo = 0;
1109 subsubsectionNo = 0;
1110 footnoteCount = 0;
1111
1112 if (macroId != ltCHAPTERSTAR && macroId != ltCHAPTERHEADINGSTAR)
1113 chapterNo ++;
1114
1115 char *topicName = FindTopicName(GetNextChunk());
1116 SetCurrentChapterName(topicName);
1117
1118 if (winHelpContents && winHelp && !InPopups())
1119 {
1120 OutputCurrentSectionToString(wxTex2RTFBuffer);
1121 WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 1);
1122 }
1123 AddTexRef(topicName, NULL, ChapterNameString, chapterNo);
1124
1125 if (winHelp)
1126 {
1127 if (!InPopups())
1128 fprintf(Contents, "\n{\\uldb ");
1129 fprintf(Chapters, "\\page");
1130 fprintf(Chapters, "\n${\\footnote ");
1131 if (!InPopups())
1132 SetCurrentOutputs(Contents, Chapters);
1133 else
1134 SetCurrentOutput(Chapters);
1135 }
1136 else
1137 {
1138 fprintf(Chapters, "\\sect\\pgncont\\titlepg\n");
1139
1140 // If a non-custom page style, we generate the header now.
1141 if (PageStyle && (strcmp(PageStyle, "plain") == 0 ||
1142 strcmp(PageStyle, "empty") == 0 ||
1143 strcmp(PageStyle, "headings") == 0))
1144 {
1145 OutputRTFHeaderCommands();
1146 OutputRTFFooterCommands();
1147 }
1148
1149 // Need to reset the current numbering style, or RTF forgets it.
1150 SetCurrentOutput(Chapters);
1151 OutputNumberStyle(currentNumberStyle);
1152
1153 SetCurrentOutput(Contents);
1154
1155 if (!InPopups())
1156 {
1157 if (macroId == ltCHAPTER)
1158 {
1159 // Section
1160 fprintf(Contents, "\\par\n\\pard{\\b %d\\tab ", chapterNo);
1161 }
1162 else if (macroId == ltCHAPTERHEADING)
1163 {
1164 fprintf(Contents, "\\par\n\\pard{\\b ");
1165 }
1166 else SetCurrentOutput(NULL); // No entry in table of contents
1167 }
1168 }
1169
1170 startedSections = TRUE;
1171
1172 // Output heading to contents page
1173 if (!InPopups())
1174 {
1175 OutputCurrentSection();
1176
1177 if (winHelp)
1178 fprintf(Contents, "}{\\v %s}\\par\\pard\n", topicName);
1179 else if ((macroId == ltCHAPTER) || (macroId == ltCHAPTERHEADING))
1180 fprintf(Contents, "}\\par\\par\\pard\n");
1181
1182 // From here, just output to chapter
1183 SetCurrentOutput(Chapters);
1184 }
1185
1186 if (winHelp)
1187 {
1188 fprintf(Chapters, "}\n#{\\footnote %s}\n", topicName);
1189 fprintf(Chapters, "+{\\footnote %s}\n", GetBrowseString());
1190
1191 OutputSectionKeyword(Chapters);
1192
1193 GenerateKeywordsForTopic(topicName);
1194 if (useUpButton)
1195 {
1196 // If we're generating a .cnt file, we don't want to be able
1197 // jump up to the old-style contents page, so disable it.
1198 if (winHelpContents)
1199 fprintf(Chapters, "!{\\footnote DisableButton(\"Up\")}\n");
1200 else
1201 fprintf(Chapters, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1202 wxFileNameFromPath(FileRoot), "Contents");
1203 }
1204 }
1205
1206 if (!InPopups())
1207 {
1208 char *styleCommand = "";
1209 if (!winHelp && useHeadingStyles && (macroId == ltCHAPTER || macroId == ltCHAPTERHEADING || macroId == ltCHAPTERHEADINGSTAR))
1210 styleCommand = "\\s1";
1211 fprintf(Chapters, "\\pard{%s", ((winHelp && !InPopups()) ? "\\keepn\\sa140\\sb140" : styleCommand));
1212 WriteHeadingStyle(Chapters, 1); fprintf(Chapters, " ");
1213 if (!winHelp)
1214 {
1215 if (macroId == ltCHAPTER)
1216 {
1217 if (useWord)
1218 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1219 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName, topicName);
1220 else
1221 fprintf(Chapters, "%d. ", chapterNo);
1222 }
1223 else if ( useWord )
1224 {
1225 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName, topicName);
1226 }
1227 }
1228 OutputCurrentSection();
1229 TexOutput("\\par\\pard}\\par\n");
1230 }
1231 issuedNewParagraph = 2;
1232 }
1233 break;
1234 }
1235 case ltSECTION:
1236 case ltSECTIONSTAR:
1237 case ltSECTIONHEADING:
1238 case ltSECTIONHEADINGSTAR:
1239 case ltGLOSS:
1240 {
1241 FILE *jumpFrom;
1242 if (DocumentStyle == LATEX_ARTICLE)
1243 jumpFrom = Contents;
1244 else
1245 jumpFrom = Chapters;
1246
1247 if (!start)
1248 {
1249 subsectionNo = 0;
1250 subsubsectionNo = 0;
1251 if (DocumentStyle == LATEX_ARTICLE)
1252 footnoteCount = 0;
1253
1254 if (macroId != ltSECTIONSTAR && macroId != ltSECTIONHEADINGSTAR)
1255 sectionNo ++;
1256
1257 char *topicName = FindTopicName(GetNextChunk());
1258 SetCurrentSectionName(topicName);
1259 NotifyParentHasChildren(1);
1260 if (winHelpContents && winHelp && !InPopups())
1261 {
1262 OutputCurrentSectionToString(wxTex2RTFBuffer);
1263 WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 2);
1264 }
1265 AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo);
1266
1267 if (winHelp)
1268 {
1269 SetCurrentOutputs(jumpFrom, Sections);
1270 // Newline for a new section if this is an article
1271 if ((DocumentStyle == LATEX_ARTICLE) &&
1272 ((macroId == ltSECTION) || (macroId == ltSECTIONSTAR) || (macroId == ltSECTIONHEADINGSTAR)))
1273 fprintf(Sections, "\\page\n");
1274
1275 if (!InPopups())
1276 fprintf(jumpFrom, "\n{\\uldb ");
1277 }
1278 else
1279 {
1280 if (DocumentStyle == LATEX_ARTICLE)
1281 {
1282 TexOutput("\\sect\\pgncont\n");
1283 // If a non-custom page style, we generate the header now.
1284 if (PageStyle && (strcmp(PageStyle, "plain") == 0 ||
1285 strcmp(PageStyle, "empty") == 0 ||
1286 strcmp(PageStyle, "headings") == 0))
1287 {
1288 OutputRTFHeaderCommands();
1289 OutputRTFFooterCommands();
1290 }
1291 }
1292 SetCurrentOutput(Contents);
1293
1294 if (macroId == ltSECTION)
1295 {
1296 if (!InPopups())
1297 {
1298 if (DocumentStyle == LATEX_REPORT)
1299 fprintf(Contents, "\n\\pard{\\tab %d.%d\\tab ", chapterNo, sectionNo);
1300 else
1301 fprintf(Contents, "\\par\n\\pard{\\b %d\\tab ", sectionNo);
1302 }
1303 }
1304 else if (macroId == ltSECTIONHEADING)
1305 {
1306 if (!InPopups())
1307 {
1308 if (DocumentStyle == LATEX_REPORT)
1309 fprintf(Contents, "\n\\pard{\\tab "); //, chapterNo, sectionNo);
1310 else
1311 fprintf(Contents, "\\par\n\\pard{\\b "); //, sectionNo);
1312 }
1313 }
1314 else SetCurrentOutput(NULL);
1315 }
1316
1317 if (startedSections)
1318 {
1319 if (winHelp)
1320 fprintf(Sections, "\\page\n");
1321 }
1322 startedSections = TRUE;
1323
1324 if (winHelp)
1325 fprintf(Sections, "\n${\\footnote ");
1326
1327 // Output heading to contents page
1328 if (!InPopups())
1329 OutputCurrentSection();
1330
1331 if (winHelp)
1332 {
1333 if (!InPopups())
1334 fprintf(jumpFrom, "}{\\v %s}\\par\\pard\n", topicName);
1335 }
1336 else if ((macroId != ltSECTIONSTAR) && (macroId != ltGLOSS))
1337 {
1338 if (DocumentStyle == LATEX_REPORT)
1339 fprintf(Contents, "}\\par\\pard\n");
1340 else
1341 fprintf(Contents, "}\\par\\par\\pard\n");
1342 }
1343
1344 SetCurrentOutput(winHelp ? Sections : Chapters);
1345
1346 if (winHelp)
1347 {
1348 fprintf(Sections, "}\n#{\\footnote %s}\n", topicName);
1349 fprintf(Sections, "+{\\footnote %s}\n", GetBrowseString());
1350 OutputSectionKeyword(Sections);
1351 GenerateKeywordsForTopic(topicName);
1352 if (useUpButton)
1353 {
1354 if (DocumentStyle == LATEX_ARTICLE)
1355 {
1356 fprintf(Sections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1357 wxFileNameFromPath(FileRoot), "Contents");
1358 }
1359 else if (CurrentChapterName)
1360 {
1361 fprintf(Sections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1362 wxFileNameFromPath(FileRoot), CurrentChapterName);
1363 }
1364 }
1365 }
1366
1367 if (!InPopups())
1368 {
1369 char *styleCommand = "";
1370 if (!winHelp && useHeadingStyles && (macroId != ltSECTIONSTAR))
1371 {
1372 if (DocumentStyle == LATEX_ARTICLE)
1373 styleCommand = "\\s1";
1374 else
1375 styleCommand = "\\s2";
1376 }
1377 char *keep = "";
1378 if (winHelp && (macroId != ltGLOSS) && !InPopups())
1379 keep = "\\keepn\\sa140\\sb140";
1380
1381 fprintf(winHelp ? Sections : Chapters, "\\pard{%s%s",
1382 keep, styleCommand);
1383
1384 WriteHeadingStyle((winHelp ? Sections : Chapters),
1385 (DocumentStyle == LATEX_ARTICLE ? 1 : 2));
1386 fprintf(winHelp ? Sections : Chapters, " ");
1387
1388 if (!winHelp)
1389 {
1390 if ((macroId != ltSECTIONSTAR) && (macroId != ltSECTIONHEADINGSTAR) && (macroId != ltGLOSS))
1391 {
1392 if (DocumentStyle == LATEX_REPORT)
1393 {
1394 if (useWord)
1395 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo,
1396 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName,
1397 topicName);
1398 else
1399 fprintf(Chapters, "%d.%d. ", chapterNo, sectionNo);
1400 }
1401 else
1402 {
1403 if (useWord)
1404 // fprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1405 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName,
1406 topicName);
1407 else
1408 fprintf(Chapters, "%d. ", sectionNo);
1409 }
1410 }
1411 else if ( useWord )
1412 {
1413 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName, topicName);
1414 }
1415 }
1416 OutputCurrentSection();
1417 TexOutput("\\par\\pard}\\par\n");
1418 }
1419 issuedNewParagraph = 2;
1420 }
1421 break;
1422 }
1423 case ltSUBSECTION:
1424 case ltSUBSECTIONSTAR:
1425 case ltMEMBERSECTION:
1426 case ltFUNCTIONSECTION:
1427 {
1428 if (!start)
1429 {
1430 if (winHelp && !Sections)
1431 {
1432 OnError("You cannot have a subsection before a section!");
1433 }
1434 else
1435 {
1436 subsubsectionNo = 0;
1437
1438 if (macroId != ltSUBSECTIONSTAR)
1439 subsectionNo ++;
1440
1441 char *topicName = FindTopicName(GetNextChunk());
1442 SetCurrentSubsectionName(topicName);
1443 NotifyParentHasChildren(2);
1444 if (winHelpContents && winHelp && !InPopups())
1445 {
1446 OutputCurrentSectionToString(wxTex2RTFBuffer);
1447 WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 3);
1448 }
1449 AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo);
1450
1451 if (winHelp)
1452 {
1453 SetCurrentOutputs(Sections, Subsections);
1454 SetCurrentOutputs(Sections, Subsections);
1455 if (!InPopups())
1456 fprintf(Sections, "\n{\\uldb ");
1457 }
1458 else
1459 {
1460 if ((macroId != ltSUBSECTIONSTAR) && (macroId != ltMEMBERSECTION) &&
1461 (macroId != ltFUNCTIONSECTION))
1462 {
1463 SetCurrentOutput(Contents);
1464 if (DocumentStyle == LATEX_REPORT)
1465 fprintf(Contents, "\n\\pard\\tab\\tab %d.%d.%d\\tab ", chapterNo, sectionNo, subsectionNo);
1466 else
1467 fprintf(Contents, "\n\\pard\\tab %d.%d\\tab ", sectionNo, subsectionNo);
1468 } else SetCurrentOutput(NULL);
1469 }
1470 if (startedSections)
1471 {
1472 if (winHelp)
1473 {
1474 if (!InPopups())
1475 fprintf(Subsections, "\\page\n");
1476 }
1477 else
1478 fprintf(Chapters, "\\par\n");
1479 }
1480 startedSections = TRUE;
1481
1482 if (winHelp)
1483 fprintf(Subsections, "\n${\\footnote ");
1484
1485 // Output to contents page
1486 if (!InPopups())
1487 OutputCurrentSection();
1488
1489 if (winHelp)
1490 {
1491 if (!InPopups())
1492 fprintf(Sections, "}{\\v %s}\\par\\pard\n", topicName);
1493 }
1494 else if ((macroId != ltSUBSECTIONSTAR) && (macroId != ltMEMBERSECTION) &&
1495 (macroId != ltFUNCTIONSECTION))
1496 fprintf(Contents, "\\par\\pard\n");
1497
1498 SetCurrentOutput(winHelp ? Subsections : Chapters);
1499 if (winHelp)
1500 {
1501 fprintf(Subsections, "}\n#{\\footnote %s}\n", topicName);
1502 fprintf(Subsections, "+{\\footnote %s}\n", GetBrowseString());
1503 OutputSectionKeyword(Subsections);
1504 GenerateKeywordsForTopic(topicName);
1505 if (useUpButton && CurrentSectionName)
1506 {
1507 fprintf(Subsections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1508 wxFileNameFromPath(FileRoot), CurrentSectionName);
1509 }
1510 }
1511 if (!winHelp && indexSubsections && useWord)
1512 {
1513 // Insert index entry for this subsection
1514 TexOutput("{\\xe\\v {");
1515 OutputCurrentSection();
1516 TexOutput("}}");
1517 }
1518
1519 if (!InPopups())
1520 {
1521 char *styleCommand = "";
1522 if (!winHelp && useHeadingStyles && (macroId != ltSUBSECTIONSTAR))
1523 {
1524 if (DocumentStyle == LATEX_ARTICLE)
1525 styleCommand = "\\s2";
1526 else
1527 styleCommand = "\\s3";
1528 }
1529 char *keep = "";
1530 if (winHelp && !InPopups())
1531 keep = "\\keepn\\sa140\\sb140";
1532
1533 fprintf(winHelp ? Subsections : Chapters, "\\pard{%s%s",
1534 keep, styleCommand);
1535
1536 WriteHeadingStyle((winHelp ? Subsections : Chapters),
1537 (DocumentStyle == LATEX_ARTICLE ? 2 : 3));
1538 fprintf(winHelp ? Subsections : Chapters, " ");
1539
1540 if (!winHelp)
1541 {
1542 if ((macroId != ltSUBSECTIONSTAR) && (macroId != ltMEMBERSECTION) &&
1543 (macroId != ltFUNCTIONSECTION))
1544 {
1545 if (DocumentStyle == LATEX_REPORT)
1546 {
1547 if (useWord)
1548 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo,
1549 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName,
1550 topicName);
1551 else
1552 fprintf(Chapters, "%d.%d.%d. ", chapterNo, sectionNo, subsectionNo);
1553 }
1554 else
1555 {
1556 if (useWord)
1557 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo,
1558 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName,
1559 topicName);
1560 else
1561 fprintf(Chapters, "%d.%d. ", sectionNo, subsectionNo);
1562 }
1563 }
1564 else if ( useWord )
1565 {
1566 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName, topicName);
1567 }
1568 }
1569 OutputCurrentSection(); // Repeat section header
1570 TexOutput("\\par\\pard}\\par\n");
1571 }
1572 issuedNewParagraph = 2;
1573 }
1574 }
1575 break;
1576 }
1577 case ltSUBSUBSECTION:
1578 case ltSUBSUBSECTIONSTAR:
1579 {
1580 if (!start)
1581 {
1582 if (winHelp && !Subsections)
1583 {
1584 OnError("You cannot have a subsubsection before a subsection!");
1585 }
1586 else
1587 {
1588 if (macroId != ltSUBSUBSECTIONSTAR)
1589 subsubsectionNo ++;
1590
1591 char *topicName = FindTopicName(GetNextChunk());
1592 SetCurrentTopic(topicName);
1593 NotifyParentHasChildren(3);
1594 if (winHelpContents && winHelp)
1595 {
1596 OutputCurrentSectionToString(wxTex2RTFBuffer);
1597 WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 4);
1598 }
1599 AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo, subsubsectionNo);
1600
1601 if (winHelp)
1602 {
1603 SetCurrentOutputs(Subsections, Subsubsections);
1604 fprintf(Subsections, "\n{\\uldb ");
1605 }
1606 else
1607 {
1608 if (macroId != ltSUBSUBSECTIONSTAR)
1609 {
1610 if (DocumentStyle == LATEX_ARTICLE)
1611 {
1612 SetCurrentOutput(Contents);
1613 fprintf(Contents, "\n\\tab\\tab %d.%d.%d\\tab ",
1614 sectionNo, subsectionNo, subsubsectionNo);
1615 }
1616 else
1617 SetCurrentOutput(NULL); // Don't write it into the contents, or anywhere else
1618 }
1619 else
1620 SetCurrentOutput(NULL); // Don't write it into the contents, or anywhere else
1621 }
1622
1623 if (startedSections)
1624 {
1625 if (winHelp)
1626 fprintf(Subsubsections, "\\page\n");
1627 else
1628 fprintf(Chapters, "\\par\n");
1629 }
1630
1631 startedSections = TRUE;
1632
1633 if (winHelp)
1634 fprintf(Subsubsections, "\n${\\footnote ");
1635
1636 // Output header to contents page
1637 OutputCurrentSection();
1638
1639 if (winHelp)
1640 fprintf(Subsections, "}{\\v %s}\\par\\pard\n", topicName);
1641 else if ((DocumentStyle == LATEX_ARTICLE) && (macroId != ltSUBSUBSECTIONSTAR))
1642 fprintf(Contents, "\\par\\pard\n");
1643
1644 SetCurrentOutput(winHelp ? Subsubsections : Chapters);
1645 if (winHelp)
1646 {
1647 fprintf(Subsubsections, "}\n#{\\footnote %s}\n", topicName);
1648 fprintf(Subsubsections, "+{\\footnote %s}\n", GetBrowseString());
1649 OutputSectionKeyword(Subsubsections);
1650 GenerateKeywordsForTopic(topicName);
1651 if (useUpButton && CurrentSubsectionName)
1652 {
1653 fprintf(Subsubsections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
1654 wxFileNameFromPath(FileRoot), CurrentSubsectionName);
1655 }
1656 }
1657 if (!winHelp && indexSubsections && useWord)
1658 {
1659 // Insert index entry for this subsubsection
1660 TexOutput("{\\xe\\v {");
1661 OutputCurrentSection();
1662 TexOutput("}}");
1663 }
1664
1665 char *styleCommand = "";
1666 if (!winHelp && useHeadingStyles && (macroId != ltSUBSUBSECTIONSTAR))
1667 {
1668 if (DocumentStyle == LATEX_ARTICLE)
1669 styleCommand = "\\s3";
1670 else
1671 styleCommand = "\\s4";
1672 }
1673 char *keep = "";
1674 if (winHelp)
1675 keep = "\\keepn\\sa140\\sb140";
1676
1677 fprintf(winHelp ? Subsubsections : Chapters, "\\pard{%s%s",
1678 keep, styleCommand);
1679
1680 WriteHeadingStyle((winHelp ? Subsubsections : Chapters),
1681 (DocumentStyle == LATEX_ARTICLE ? 3 : 4));
1682 fprintf(winHelp ? Subsubsections : Chapters, " ");
1683
1684 if (!winHelp)
1685 {
1686 if ((macroId != ltSUBSUBSECTIONSTAR))
1687 {
1688 if (DocumentStyle == LATEX_ARTICLE)
1689 {
1690 if (useWord)
1691 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. ", topicName, sectionNo, subsectionNo, subsubsectionNo,
1692 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName,
1693 topicName);
1694 else
1695 fprintf(Chapters, "%d.%d.%d. ", sectionNo, subsectionNo, subsubsectionNo);
1696 }
1697 else
1698 {
1699 if (useWord)
1700 // fprintf(Chapters, "{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. ", topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1701 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName,
1702 topicName);
1703 else
1704 fprintf(Chapters, "%d.%d.%d.%d. ", chapterNo, sectionNo, subsectionNo, subsubsectionNo);
1705 }
1706 }
1707 else if ( useWord )
1708 {
1709 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", topicName, topicName);
1710 }
1711 }
1712 OutputCurrentSection(); // Repeat section header
1713 TexOutput("\\par\\pard}\\par\n");
1714 issuedNewParagraph = 2;
1715 // if (winHelp) TexOutput("\\pard");
1716 }
1717 }
1718 break;
1719 }
1720 case ltCAPTION:
1721 case ltCAPTIONSTAR:
1722 {
1723 if (!start)
1724 {
1725 char *topicName = FindTopicName(GetNextChunk());
1726 SetCurrentTopic(topicName);
1727
1728 TexOutput("\\pard\\par");
1729 char figBuf[200];
1730
1731 if (inFigure)
1732 {
1733 figureNo ++;
1734
1735 if (winHelp || !useWord)
1736 {
1737 if (DocumentStyle != LATEX_ARTICLE)
1738 sprintf(figBuf, "%s %d.%d: ", FigureNameString, chapterNo, figureNo);
1739 else
1740 sprintf(figBuf, "%s %d: ", FigureNameString, figureNo);
1741 }
1742 else
1743 {
1744 sprintf(figBuf, "%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1745 FigureNameString, topicName, topicName);
1746 }
1747 }
1748 else
1749 {
1750 tableNo ++;
1751
1752 if (winHelp || !useWord)
1753 {
1754 if (DocumentStyle != LATEX_ARTICLE)
1755 sprintf(figBuf, "%s %d.%d: ", TableNameString, chapterNo, tableNo);
1756 else
1757 sprintf(figBuf, "%s %d: ", TableNameString, tableNo);
1758 }
1759 else
1760 {
1761 sprintf(figBuf, "%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: ",
1762 TableNameString, topicName, topicName);
1763 }
1764 }
1765
1766 int n = (inTable ? tableNo : figureNo);
1767 AddTexRef(topicName, NULL, NULL,
1768 ((DocumentStyle != LATEX_ARTICLE) ? chapterNo : n),
1769 ((DocumentStyle != LATEX_ARTICLE) ? n : 0));
1770
1771 if (winHelp)
1772 TexOutput("\\qc{\\b ");
1773 else
1774 TexOutput("\\ql{\\b ");
1775 TexOutput(figBuf);
1776
1777 OutputCurrentSection();
1778
1779 TexOutput("}\\par\\pard\n");
1780 WriteEnvironmentStyles();
1781 }
1782 break;
1783 }
1784 case ltFUNC:
1785 case ltPFUNC:
1786 {
1787 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1788 if (start)
1789 {
1790 TexOutput("{");
1791 }
1792 else
1793 {
1794 TexOutput("}\n");
1795 if (winHelp)
1796 {
1797 TexOutput("K{\\footnote {K} ");
1798 suppressNameDecoration = TRUE;
1799 TraverseChildrenFromChunk(currentMember);
1800 suppressNameDecoration = FALSE;
1801 TexOutput("}\n");
1802 }
1803 if (!winHelp && useWord)
1804 {
1805 // Insert index entry for this function
1806 TexOutput("{\\xe\\v {");
1807 suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc.
1808 TraverseChildrenFromChunk(currentMember);
1809 suppressNameDecoration = FALSE;
1810 TexOutput("}}");
1811 }
1812 }
1813 break;
1814 }
1815 case ltCLIPSFUNC:
1816 {
1817 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1818 if (start)
1819 {
1820 TexOutput("{");
1821 }
1822 else
1823 {
1824 TexOutput("}\n");
1825 if (winHelp)
1826 {
1827 TexOutput("K{\\footnote {K} ");
1828 suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc.
1829 TraverseChildrenFromChunk(currentMember);
1830 suppressNameDecoration = FALSE;
1831 TexOutput("}\n");
1832 }
1833 if (!winHelp && useWord)
1834 {
1835 // Insert index entry for this function
1836 TexOutput("{\\xe\\v {");
1837 suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc.
1838 TraverseChildrenFromChunk(currentMember);
1839 suppressNameDecoration = FALSE;
1840 TexOutput("}}");
1841 }
1842 }
1843 break;
1844 }
1845 case ltMEMBER:
1846 {
1847 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1848 if (start)
1849 {
1850 TexOutput("{\\b ");
1851 }
1852 else
1853 {
1854 TexOutput("}\n");
1855 if (winHelp)
1856 {
1857 TexOutput("K{\\footnote {K} ");
1858 TraverseChildrenFromChunk(currentMember);
1859 TexOutput("}\n");
1860 }
1861 if (!winHelp && useWord)
1862 {
1863 // Insert index entry for this function
1864 TexOutput("{\\xe\\v {");
1865 suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc.
1866 TraverseChildrenFromChunk(currentMember);
1867 suppressNameDecoration = FALSE;
1868 TexOutput("}}");
1869 }
1870 }
1871 break;
1872 }
1873 case ltDOCUMENT:
1874 {
1875 if (start)
1876 SetCurrentOutput(Chapters);
1877 break;
1878 }
1879 case ltTABLEOFCONTENTS:
1880 {
1881 if (start)
1882 {
1883 if (!winHelp && useWord)
1884 {
1885 // Insert Word for Windows table of contents
1886 TexOutput("\\par\\pard\\pgnrestart\\sect\\titlepg");
1887
1888 // In linear RTF, same as chapter headings.
1889 sprintf(buf, "{\\b\\fs%d %s}\\par\\par\\pard\n\n", chapterFont*2, ContentsNameString);
1890
1891 TexOutput(buf);
1892 sprintf(buf, "{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n", contentsDepth);
1893 TexOutput(buf);
1894 // TexOutput("\\sect\\sectd");
1895 }
1896 else
1897 {
1898 FILE *fd = fopen(ContentsName, "r");
1899 if (fd)
1900 {
1901 int ch = getc(fd);
1902 while (ch != EOF)
1903 {
1904 putc(ch, Chapters);
1905 ch = getc(fd);
1906 }
1907 fclose(fd);
1908 }
1909 else
1910 {
1911 TexOutput("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n");
1912 OnInform("Run Tex2RTF again to include contents page.");
1913 }
1914 }
1915 }
1916 break;
1917 }
1918 case ltVOID:
1919 {
1920 // if (start)
1921 // TexOutput("{\\b void}");
1922 break;
1923 }
1924 case ltHARDY:
1925 {
1926 if (start)
1927 TexOutput("{\\scaps HARDY}");
1928 break;
1929 }
1930 case ltWXCLIPS:
1931 {
1932 if (start)
1933 TexOutput("wxCLIPS");
1934 break;
1935 }
1936 case ltSPECIALAMPERSAND:
1937 {
1938 if (start)
1939 {
1940 if (inTabular)
1941 TexOutput("\\cell ");
1942 else
1943 TexOutput("&");
1944 }
1945 break;
1946 }
1947 case ltSPECIALTILDE:
1948 {
1949 if (start)
1950 {
1951 if (inVerbatim)
1952 TexOutput("~");
1953 else
1954 TexOutput(" ");
1955 }
1956 break;
1957 }
1958 case ltBACKSLASHCHAR:
1959 {
1960 if (start)
1961 {
1962 if (inTabular)
1963 {
1964 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
1965 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
1966 int currentWidth = 0;
1967 for (int i = 0; i < noColumns; i++)
1968 {
1969 currentWidth += TableData[i].width;
1970 if (TableData[i].rightBorder)
1971 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
1972
1973 if (TableData[i].leftBorder)
1974 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
1975
1976 sprintf(buf, "\\cellx%d", currentWidth);
1977 TexOutput(buf);
1978 }
1979 TexOutput("\\pard\\intbl\n");
1980 }
1981 else
1982 TexOutput("\\line\n");
1983 }
1984 break;
1985 }
1986 case ltRANGLEBRA:
1987 {
1988 if (start)
1989 TexOutput("\tab ");
1990 break;
1991 }
1992 case ltRTFSP: // Explicit space, RTF only
1993 {
1994 if (start)
1995 TexOutput(" ");
1996 break;
1997 }
1998 case ltITEMIZE:
1999 case ltENUMERATE:
2000 case ltDESCRIPTION:
2001 {
2002 if (start)
2003 {
2004 if (indentLevel > 0)
2005 {
2006 TexOutput("\\par\\par\n");
2007 issuedNewParagraph = 2;
2008 }
2009 else
2010 {
2011 // Top-level list: issue a new paragraph if we haven't
2012 // just done so
2013 if (!issuedNewParagraph)
2014 {
2015 TexOutput("\\par\\pard");
2016 WriteEnvironmentStyles();
2017 issuedNewParagraph = 1;
2018 }
2019 else issuedNewParagraph = 0;
2020 }
2021 indentLevel ++;
2022 TexOutput("\\fi0\n");
2023 int listType;
2024 if (macroId == ltENUMERATE)
2025 listType = LATEX_ENUMERATE;
2026 else if (macroId == ltITEMIZE)
2027 listType = LATEX_ITEMIZE;
2028 else
2029 listType = LATEX_DESCRIPTION;
2030
2031 int oldIndent = 0;
2032 wxNode *node = itemizeStack.First();
2033 if (node)
2034 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
2035
2036 int indentSize1 = oldIndent + 20*labelIndentTab;
2037 int indentSize2 = oldIndent + 20*itemIndentTab;
2038
2039 ItemizeStruc *struc = new ItemizeStruc(listType, indentSize2, indentSize1);
2040 itemizeStack.Insert(struc);
2041
2042 sprintf(buf, "\\tx%d\\tx%d\\li%d", indentSize1, indentSize2, indentSize2);
2043 PushEnvironmentStyle(buf);
2044 }
2045 else
2046 {
2047 currentItemSep = 8; // Reset to the default
2048 indentLevel --;
2049 PopEnvironmentStyle();
2050
2051 if (itemizeStack.First())
2052 {
2053 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
2054 delete struc;
2055 delete itemizeStack.First();
2056 }
2057 /* Change 18/7/97 - don't know why we wish to do this
2058 if (itemizeStack.Number() == 0)
2059 {
2060 OnMacro(ltPAR, 0, TRUE);
2061 OnMacro(ltPAR, 0, FALSE);
2062 issuedNewParagraph = 2;
2063 }
2064 */
2065 }
2066 break;
2067 }
2068 case ltTWOCOLLIST:
2069 {
2070 if (start)
2071 {
2072 indentLevel ++;
2073 int oldIndent = 0;
2074 wxNode *node = itemizeStack.First();
2075 if (node)
2076 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
2077
2078 int indentSize = oldIndent + TwoColWidthA;
2079
2080 ItemizeStruc *struc = new ItemizeStruc(LATEX_TWOCOL, indentSize);
2081 itemizeStack.Insert(struc);
2082
2083 // sprintf(buf, "\\tx%d\\li%d\\ri%d", indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2084 sprintf(buf, "\\tx%d\\li%d", indentSize, indentSize);
2085 PushEnvironmentStyle(buf);
2086 }
2087 else
2088 {
2089 indentLevel --;
2090 PopEnvironmentStyle();
2091 if (itemizeStack.First())
2092 {
2093 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
2094 delete struc;
2095 delete itemizeStack.First();
2096 }
2097 /*
2098 // JACS June 1997
2099 TexOutput("\\pard\n");
2100 WriteEnvironmentStyles();
2101 */
2102 /* why do we need this? */
2103 if (itemizeStack.Number() == 0)
2104 {
2105 issuedNewParagraph = 0;
2106 OnMacro(ltPAR, 0, TRUE);
2107 OnMacro(ltPAR, 0, FALSE);
2108 }
2109 }
2110 break;
2111 }
2112 case ltITEM:
2113 {
2114 wxNode *node = itemizeStack.First();
2115 if (node)
2116 {
2117 ItemizeStruc *struc = (ItemizeStruc *)node->Data();
2118 if (!start)
2119 {
2120 struc->currentItem += 1;
2121 char indentBuf[60];
2122
2123 int indentSize1 = struc->labelIndentation;
2124 int indentSize2 = struc->indentation;
2125
2126 TexOutput("\n");
2127 if (struc->currentItem > 1)
2128 {
2129 if (currentItemSep > 0)
2130 TexOutput("\\par");
2131
2132 TexOutput("\\par");
2133 // WriteEnvironmentStyles();
2134 }
2135
2136 sprintf(buf, "\\tx%d\\tx%d\\li%d\\fi-%d\n", indentSize1, indentSize2,
2137 indentSize2, 20*itemIndentTab);
2138 TexOutput(buf);
2139
2140 switch (struc->listType)
2141 {
2142 case LATEX_ENUMERATE:
2143 {
2144 if (descriptionItemArg)
2145 {
2146 TexOutput("\\tab{ ");
2147 TraverseChildrenFromChunk(descriptionItemArg);
2148 TexOutput("}\\tab");
2149 descriptionItemArg = NULL;
2150 }
2151 else
2152 {
2153 sprintf(indentBuf, "\\tab{\\b %d.}\\tab", struc->currentItem);
2154 TexOutput(indentBuf);
2155 }
2156 break;
2157 }
2158 case LATEX_ITEMIZE:
2159 {
2160 if (descriptionItemArg)
2161 {
2162 TexOutput("\\tab{ ");
2163 TraverseChildrenFromChunk(descriptionItemArg);
2164 TexOutput("}\\tab");
2165 descriptionItemArg = NULL;
2166 }
2167 else
2168 {
2169 if (bulletFile && winHelp)
2170 {
2171 if (winHelpVersion > 3) // Transparent bitmap
2172 sprintf(indentBuf, "\\tab\\{bmct %s\\}\\tab", bulletFile);
2173 else
2174 sprintf(indentBuf, "\\tab\\{bmc %s\\}\\tab", bulletFile);
2175 }
2176 else if (winHelp)
2177 sprintf(indentBuf, "\\tab{\\b o}\\tab");
2178 else
2179 sprintf(indentBuf, "\\tab{\\f1\\'b7}\\tab");
2180 TexOutput(indentBuf);
2181 }
2182 break;
2183 }
2184 default:
2185 case LATEX_DESCRIPTION:
2186 {
2187 if (descriptionItemArg)
2188 {
2189 TexOutput("\\tab{\\b ");
2190 TraverseChildrenFromChunk(descriptionItemArg);
2191 TexOutput("} ");
2192 descriptionItemArg = NULL;
2193 }
2194 break;
2195 }
2196 }
2197 }
2198 }
2199 break;
2200 }
2201 case ltTWOCOLITEM:
2202 case ltTWOCOLITEMRULED:
2203 {
2204 wxNode *node = itemizeStack.First();
2205 if (node)
2206 {
2207 ItemizeStruc *struc = (ItemizeStruc *)node->Data();
2208 if (start)
2209 {
2210 struc->currentItem += 1;
2211
2212 int oldIndent = 0;
2213 wxNode *node2 = NULL;
2214 if (itemizeStack.Number() > 1) // TODO: do I actually mean Nth(0) here??
2215 node2 = itemizeStack.Nth(1);
2216 if (node2)
2217 oldIndent = ((ItemizeStruc *)node2->Data())->indentation;
2218
2219 TexOutput("\n");
2220 if (struc->currentItem > 1)
2221 {
2222 if (currentItemSep > 0)
2223 TexOutput("\\par");
2224
2225 // WriteEnvironmentStyles();
2226 }
2227
2228 // sprintf(buf, "\\tx%d\\li%d\\fi-%d\\ri%d\n", TwoColWidthA,
2229 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2230 /*
2231 sprintf(buf, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA,
2232 TwoColWidthA, TwoColWidthA);
2233 */
2234 sprintf(buf, "\\tx%d\\li%d\\fi-%d\n", TwoColWidthA + oldIndent,
2235 TwoColWidthA + oldIndent, TwoColWidthA);
2236 TexOutput(buf);
2237 }
2238 }
2239 break;
2240 }
2241 case ltVERBATIM:
2242 case ltVERB:
2243 {
2244 if (start)
2245 {
2246 if (macroId == ltVERBATIM)
2247 {
2248 if (!issuedNewParagraph)
2249 {
2250 TexOutput("\\par\\pard");
2251 WriteEnvironmentStyles();
2252 issuedNewParagraph = 1;
2253 }
2254 else issuedNewParagraph = 0;
2255 }
2256 sprintf(buf, "{\\f3\\fs20 ");
2257 TexOutput(buf);
2258 }
2259 else
2260 {
2261 TexOutput("}");
2262 if (macroId == ltVERBATIM)
2263 {
2264 TexOutput("\\pard\n");
2265 // issuedNewParagraph = 1;
2266 WriteEnvironmentStyles();
2267 }
2268 }
2269 break;
2270 }
2271 case ltCENTERLINE:
2272 case ltCENTER:
2273 {
2274 if (start)
2275 {
2276 TexOutput("\\fi0\\qc ");
2277 forbidParindent ++;
2278 PushEnvironmentStyle("\\qc");
2279 }
2280 else
2281 {
2282 TexOutput("\\par\\pard\n");
2283 issuedNewParagraph = 1;
2284 forbidParindent --;
2285 PopEnvironmentStyle();
2286 WriteEnvironmentStyles();
2287 }
2288 break;
2289 }
2290 case ltFLUSHLEFT:
2291 {
2292 if (start)
2293 {
2294 TexOutput("\\fi0\\ql ");
2295 forbidParindent ++;
2296 PushEnvironmentStyle("\\ql");
2297 }
2298 else
2299 {
2300 TexOutput("\\par\\pard\n");
2301 issuedNewParagraph = 1;
2302 forbidParindent --;
2303 PopEnvironmentStyle();
2304 WriteEnvironmentStyles();
2305 }
2306 break;
2307 }
2308 case ltFLUSHRIGHT:
2309 {
2310 if (start)
2311 {
2312 TexOutput("\\fi0\\qr ");
2313 forbidParindent ++;
2314 PushEnvironmentStyle("\\qr");
2315 }
2316 else
2317 {
2318 TexOutput("\\par\\pard\n");
2319 issuedNewParagraph = 1;
2320 forbidParindent --;
2321 PopEnvironmentStyle();
2322 WriteEnvironmentStyles();
2323 }
2324 break;
2325 }
2326 case ltSMALL:
2327 case ltFOOTNOTESIZE:
2328 {
2329 if (start)
2330 {
2331 sprintf(buf, "{\\fs%d\n", smallFont*2);
2332 TexOutput(buf);
2333 }
2334 else TexOutput("}\n");
2335 break;
2336 }
2337 case ltTINY:
2338 case ltSCRIPTSIZE:
2339 {
2340 if (start)
2341 {
2342 sprintf(buf, "{\\fs%d\n", tinyFont*2);
2343 TexOutput(buf);
2344 }
2345 else TexOutput("}\n");
2346 break;
2347 }
2348 case ltNORMALSIZE:
2349 {
2350 if (start)
2351 {
2352 sprintf(buf, "{\\fs%d\n", normalFont*2);
2353 TexOutput(buf);
2354 }
2355 else TexOutput("}\n");
2356 break;
2357 }
2358 case ltlarge:
2359 {
2360 if (start)
2361 {
2362 sprintf(buf, "{\\fs%d\n", largeFont1*2);
2363 TexOutput(buf);
2364 }
2365 else TexOutput("}\n");
2366 break;
2367 }
2368 case ltLarge:
2369 {
2370 if (start)
2371 {
2372 sprintf(buf, "{\\fs%d\n", LargeFont2*2);
2373 TexOutput(buf);
2374 }
2375 else TexOutput("}\n");
2376 break;
2377 }
2378 case ltLARGE:
2379 {
2380 if (start)
2381 {
2382 sprintf(buf, "{\\fs%d\n", LARGEFont3*2);
2383 TexOutput(buf);
2384 }
2385 else TexOutput("}\n");
2386 break;
2387 }
2388 case lthuge:
2389 {
2390 if (start)
2391 {
2392 sprintf(buf, "{\\fs%d\n", hugeFont1*2);
2393 TexOutput(buf);
2394 }
2395 else TexOutput("}\n");
2396 break;
2397 }
2398 case ltHuge:
2399 {
2400 if (start)
2401 {
2402 sprintf(buf, "{\\fs%d\n", HugeFont2*2);
2403 TexOutput(buf);
2404 }
2405 else TexOutput("}\n");
2406 break;
2407 }
2408 case ltHUGE:
2409 {
2410 if (start)
2411 {
2412 sprintf(buf, "{\\fs%d\n", HUGEFont3*2);
2413 TexOutput(buf);
2414 }
2415 else TexOutput("}\n");
2416 break;
2417 }
2418 case ltTEXTBF:
2419 case ltBFSERIES:
2420 case ltBF:
2421 {
2422 if (start)
2423 {
2424 TexOutput("{\\b ");
2425 }
2426 else TexOutput("}");
2427 break;
2428 }
2429 case ltUNDERLINE:
2430 {
2431 if (start)
2432 {
2433 TexOutput("{\\ul ");
2434 }
2435 else TexOutput("}");
2436 break;
2437 }
2438 case ltTEXTIT:
2439 case ltITSHAPE:
2440 case ltIT:
2441 case ltEMPH:
2442 case ltEM:
2443 {
2444 if (start)
2445 {
2446 TexOutput("{\\i ");
2447 }
2448 else TexOutput("}");
2449 break;
2450 }
2451 // Roman font: do nothing. Should really switch between
2452 // fonts.
2453 case ltTEXTRM:
2454 case ltRMFAMILY:
2455 case ltRM:
2456 {
2457 /*
2458 if (start)
2459 {
2460 TexOutput("{\\plain ");
2461 }
2462 else TexOutput("}");
2463 */
2464 break;
2465 }
2466 // Medium-weight font. Unbolden...
2467 case ltMDSERIES:
2468 {
2469 if (start)
2470 {
2471 TexOutput("{\\b0 ");
2472 }
2473 else TexOutput("}");
2474 break;
2475 }
2476 // Upright (un-italic or slant)
2477 case ltUPSHAPE:
2478 {
2479 if (start)
2480 {
2481 TexOutput("{\\i0 ");
2482 }
2483 else TexOutput("}");
2484 break;
2485 }
2486 case ltTEXTSC:
2487 case ltSCSHAPE:
2488 case ltSC:
2489 {
2490 if (start)
2491 {
2492 TexOutput("{\\scaps ");
2493 }
2494 else TexOutput("}");
2495 break;
2496 }
2497 case ltTEXTTT:
2498 case ltTTFAMILY:
2499 case ltTT:
2500 {
2501 if (start)
2502 {
2503 TexOutput("{\\f3 ");
2504 }
2505 else TexOutput("}");
2506 break;
2507 }
2508 case ltLBRACE:
2509 {
2510 if (start)
2511 TexOutput("\\{");
2512 break;
2513 }
2514 case ltRBRACE:
2515 {
2516 if (start)
2517 TexOutput("\\}");
2518 break;
2519 }
2520 case ltBACKSLASH:
2521 {
2522 if (start)
2523 TexOutput("\\\\");
2524 break;
2525 }
2526 case ltPAR:
2527 {
2528 if (start)
2529 {
2530 if ( issuedNewParagraph == 0 )
2531 {
2532 TexOutput("\\par\\pard");
2533 issuedNewParagraph ++;
2534
2535 // Extra par if parskip is more than zero (usually looks best.)
2536 if (!inTabular && (ParSkip > 0))
2537 {
2538 TexOutput("\\par");
2539 issuedNewParagraph ++;
2540 }
2541 WriteEnvironmentStyles();
2542 }
2543 // 1 is a whole paragraph if ParSkip == 0,
2544 // half a paragraph if ParSkip > 0
2545 else if ( issuedNewParagraph == 1 )
2546 {
2547 // Don't need a par at all if we've already had one,
2548 // and ParSkip == 0.
2549
2550 // Extra par if parskip is more than zero (usually looks best.)
2551 if (!inTabular && (ParSkip > 0))
2552 {
2553 TexOutput("\\par");
2554 issuedNewParagraph ++;
2555 }
2556 WriteEnvironmentStyles();
2557 }
2558 /*
2559 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2560 {
2561 TexOutput("\\par\\pard");
2562
2563 // Extra par if parskip is more than zero (usually looks best.)
2564 if (!inTabular && (ParSkip > 0))
2565 TexOutput("\\par");
2566 WriteEnvironmentStyles();
2567 }
2568 */
2569
2570 TexOutput("\n");
2571 }
2572 break;
2573 }
2574 case ltNEWPAGE:
2575 {
2576 // In Windows Help, no newpages until we've started some chapters or sections
2577 if (!(winHelp && !startedSections))
2578 if (start)
2579 TexOutput("\\page\n");
2580 break;
2581 }
2582 case ltMAKETITLE:
2583 {
2584 if (start && DocumentTitle)
2585 {
2586 TexOutput("\\par\\pard");
2587 if (!winHelp)
2588 TexOutput("\\par");
2589 sprintf(buf, "\\qc{\\fs%d\\b ", titleFont*2);
2590 TexOutput(buf);
2591 TraverseChildrenFromChunk(DocumentTitle);
2592 TexOutput("}\\par\\pard\n");
2593
2594 if (DocumentAuthor)
2595 {
2596 if (!winHelp)
2597 TexOutput("\\par");
2598 sprintf(buf, "\\par\\qc{\\fs%d ", authorFont*2);
2599 TexOutput(buf);
2600 TraverseChildrenFromChunk(DocumentAuthor);
2601 TexOutput("}");
2602 TexOutput("\\par\\pard\n");
2603 }
2604 if (DocumentDate)
2605 {
2606 TexOutput("\\par");
2607 sprintf(buf, "\\qc{\\fs%d ", authorFont*2);
2608 TexOutput(buf);
2609 TraverseChildrenFromChunk(DocumentDate);
2610 TexOutput("}\\par\\pard\n");
2611 }
2612 // If linear RTF, we want this titlepage to be in a separate
2613 // section with its own (blank) header and footer
2614 if (!winHelp && (DocumentStyle != LATEX_ARTICLE))
2615 {
2616 TexOutput("{\\header }{\\footer }\n");
2617 // Not sure about this: we get too many sections.
2618 // TexOutput("\\sect");
2619 }
2620 }
2621 break;
2622 }
2623 case ltADDCONTENTSLINE:
2624 {
2625 if (!start)
2626 {
2627 if (contentsLineSection && contentsLineValue)
2628 {
2629 if (strcmp(contentsLineSection, "chapter") == 0)
2630 {
2631 fprintf(Contents, "\\par\n{\\b %s}\\par\n", contentsLineValue);
2632 }
2633 else if (strcmp(contentsLineSection, "section") == 0)
2634 {
2635 if (DocumentStyle != LATEX_ARTICLE)
2636 fprintf(Contents, "\n\\tab%s\\par\n", contentsLineValue);
2637 else
2638 fprintf(Contents, "\\par\n{\\b %s}\\par\n", contentsLineValue);
2639 }
2640 }
2641 }
2642 break;
2643 }
2644 case ltHRULE:
2645 {
2646 if (start)
2647 {
2648 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2649 issuedNewParagraph = 1;
2650 WriteEnvironmentStyles();
2651 }
2652 break;
2653 }
2654 case ltRULE:
2655 {
2656 if (start)
2657 {
2658 TexOutput("\\brdrb\\brdrs\\par\\pard\n");
2659 issuedNewParagraph = 1;
2660 WriteEnvironmentStyles();
2661 }
2662 break;
2663 }
2664 case ltHLINE:
2665 {
2666 if (start)
2667 ruleTop ++;
2668 break;
2669 }
2670 case ltNUMBEREDBIBITEM:
2671 {
2672 if (start)
2673 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
2674 else
2675 TexOutput("\\par\\pard\\par\n\n");
2676 break;
2677 }
2678 case ltTHEPAGE:
2679 {
2680 if (start)
2681 {
2682 TexOutput("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2683 }
2684 break;
2685 }
2686 case ltTHECHAPTER:
2687 {
2688 if (start)
2689 {
2690 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2691 sprintf(buf, "%d", chapterNo);
2692 TexOutput(buf);
2693 }
2694 break;
2695 }
2696 case ltTHESECTION:
2697 {
2698 if (start)
2699 {
2700 // TexOutput("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}");
2701 sprintf(buf, "%d", sectionNo);
2702 TexOutput(buf);
2703 }
2704 break;
2705 }
2706 case ltTWOCOLUMN:
2707 {
2708 if (!start && !winHelp)
2709 {
2710 TexOutput("\\cols2\n");
2711 }
2712 break;
2713 }
2714 case ltONECOLUMN:
2715 {
2716 if (!start && !winHelp)
2717 {
2718 TexOutput("\\cols1\n");
2719 }
2720 break;
2721 }
2722 case ltPRINTINDEX:
2723 {
2724 if (start && useWord && !winHelp)
2725 {
2726 FakeCurrentSection("Index");
2727 OnMacro(ltPAR, 0, TRUE);
2728 OnMacro(ltPAR, 0, FALSE);
2729 TexOutput("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n");
2730 }
2731 break;
2732 }
2733 case ltLISTOFFIGURES:
2734 {
2735 if (start && useWord && !winHelp)
2736 {
2737 FakeCurrentSection(FiguresNameString, FALSE);
2738 OnMacro(ltPAR, 0, TRUE);
2739 OnMacro(ltPAR, 0, FALSE);
2740 OnMacro(ltPAR, 0, TRUE);
2741 OnMacro(ltPAR, 0, FALSE);
2742 char buf[200];
2743 sprintf(buf, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n",
2744 FigureNameString);
2745 TexOutput(buf);
2746 }
2747 break;
2748 }
2749 case ltLISTOFTABLES:
2750 {
2751 if (start && useWord && !winHelp)
2752 {
2753 FakeCurrentSection(TablesNameString, FALSE);
2754 OnMacro(ltPAR, 0, TRUE);
2755 OnMacro(ltPAR, 0, FALSE);
2756 OnMacro(ltPAR, 0, TRUE);
2757 OnMacro(ltPAR, 0, FALSE);
2758 char buf[200];
2759 sprintf(buf, "{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n",
2760 TablesNameString);
2761 TexOutput(buf);
2762 }
2763 break;
2764 }
2765 // Symbols
2766 case ltALPHA:
2767 if (start) TexOutput("{\\f1\\'61}");
2768 break;
2769 case ltBETA:
2770 if (start) TexOutput("{\\f1\\'62}");
2771 break;
2772 case ltGAMMA:
2773 if (start) TexOutput("{\\f1\\'63}");
2774 break;
2775 case ltDELTA:
2776 if (start) TexOutput("{\\f1\\'64}");
2777 break;
2778 case ltEPSILON:
2779 case ltVAREPSILON:
2780 if (start) TexOutput("{\\f1\\'65}");
2781 break;
2782 case ltZETA:
2783 if (start) TexOutput("{\\f1\\'7A}");
2784 break;
2785 case ltETA:
2786 if (start) TexOutput("{\\f1\\'68}");
2787 break;
2788 case ltTHETA:
2789 case ltVARTHETA:
2790 if (start) TexOutput("{\\f1\\'71}");
2791 break;
2792 case ltIOTA:
2793 if (start) TexOutput("{\\f1\\'69}");
2794 break;
2795 case ltKAPPA:
2796 if (start) TexOutput("{\\f1\\'6B}");
2797 break;
2798 case ltLAMBDA:
2799 if (start) TexOutput("{\\f1\\'6C}");
2800 break;
2801 case ltMU:
2802 if (start) TexOutput("{\\f1\\'6D}");
2803 break;
2804 case ltNU:
2805 if (start) TexOutput("{\\f1\\'6E}");
2806 break;
2807 case ltXI:
2808 if (start) TexOutput("{\\f1\\'78}");
2809 break;
2810 case ltPI:
2811 if (start) TexOutput("{\\f1\\'70}");
2812 break;
2813 case ltVARPI:
2814 if (start) TexOutput("{\\f1\\'76}");
2815 break;
2816 case ltRHO:
2817 case ltVARRHO:
2818 if (start) TexOutput("{\\f1\\'72}");
2819 break;
2820 case ltSIGMA:
2821 if (start) TexOutput("{\\f1\\'73}");
2822 break;
2823 case ltVARSIGMA:
2824 if (start) TexOutput("{\\f1\\'56}");
2825 break;
2826 case ltTAU:
2827 if (start) TexOutput("{\\f1\\'74}");
2828 break;
2829 case ltUPSILON:
2830 if (start) TexOutput("{\\f1\\'75}");
2831 break;
2832 case ltPHI:
2833 case ltVARPHI:
2834 if (start) TexOutput("{\\f1\\'66}");
2835 break;
2836 case ltCHI:
2837 if (start) TexOutput("{\\f1\\'63}");
2838 break;
2839 case ltPSI:
2840 if (start) TexOutput("{\\f1\\'79}");
2841 break;
2842 case ltOMEGA:
2843 if (start) TexOutput("{\\f1\\'77}");
2844 break;
2845 case ltCAP_GAMMA:
2846 if (start) TexOutput("{\\f1\\'47}");
2847 break;
2848 case ltCAP_DELTA:
2849 if (start) TexOutput("{\\f1\\'44}");
2850 break;
2851 case ltCAP_THETA:
2852 if (start) TexOutput("{\\f1\\'51}");
2853 break;
2854 case ltCAP_LAMBDA:
2855 if (start) TexOutput("{\\f1\\'4C}");
2856 break;
2857 case ltCAP_XI:
2858 if (start) TexOutput("{\\f1\\'58}");
2859 break;
2860 case ltCAP_PI:
2861 if (start) TexOutput("{\\f1\\'50}");
2862 break;
2863 case ltCAP_SIGMA:
2864 if (start) TexOutput("{\\f1\\'53}");
2865 break;
2866 case ltCAP_UPSILON:
2867 if (start) TexOutput("{\\f1\\'54}");
2868 break;
2869 case ltCAP_PHI:
2870 if (start) TexOutput("{\\f1\\'46}");
2871 break;
2872 case ltCAP_PSI:
2873 if (start) TexOutput("{\\f1\\'59}");
2874 break;
2875 case ltCAP_OMEGA:
2876 if (start) TexOutput("{\\f1\\'57}");
2877 break;
2878 // Binary operation symbols
2879 case ltLE:
2880 case ltLEQ:
2881 if (start) TexOutput("{\\f1\\'A3}");
2882 break;
2883 case ltLL:
2884 if (start) TexOutput("<<");
2885 break;
2886 case ltSUBSET:
2887 if (start) TexOutput("{\\f1\\'CC}");
2888 break;
2889 case ltSUBSETEQ:
2890 if (start) TexOutput("{\\f1\\'CD}");
2891 break;
2892 case ltIN:
2893 if (start) TexOutput("{\\f1\\'CE}");
2894 break;
2895 case ltGE:
2896 case ltGEQ:
2897 if (start) TexOutput("{\\f1\\'B3}");
2898 break;
2899 case ltGG:
2900 if (start) TexOutput(">>");
2901 break;
2902 case ltSUPSET:
2903 if (start) TexOutput("{\\f1\\'C9}");
2904 break;
2905 case ltSUPSETEQ:
2906 if (start) TexOutput("{\\f1\\'CD}");
2907 break;
2908 case ltNI:
2909 if (start) TexOutput("{\\f1\\'27}");
2910 break;
2911 case ltPERP:
2912 if (start) TexOutput("{\\f1\\'5E}");
2913 break;
2914 case ltNEQ:
2915 if (start) TexOutput("{\\f1\\'B9}");
2916 break;
2917 case ltAPPROX:
2918 if (start) TexOutput("{\\f1\\'BB}");
2919 break;
2920 case ltCONG:
2921 if (start) TexOutput("{\\f1\\'40}");
2922 break;
2923 case ltEQUIV:
2924 if (start) TexOutput("{\\f1\\'BA}");
2925 break;
2926 case ltPROPTO:
2927 if (start) TexOutput("{\\f1\\'B5}");
2928 break;
2929 case ltSIM:
2930 if (start) TexOutput("{\\f1\\'7E}");
2931 break;
2932 case ltSMILE:
2933 if (start) TexOutput("{\\f4\\'4A}");
2934 break;
2935 case ltFROWN:
2936 if (start) TexOutput("{\\f4\\'4C}");
2937 break;
2938 case ltMID:
2939 if (start) TexOutput("|");
2940 break;
2941
2942 // Negated relation symbols
2943 case ltNOTEQ:
2944 if (start) TexOutput("{\\f1\\'B9}");
2945 break;
2946 case ltNOTIN:
2947 if (start) TexOutput("{\\f1\\'CF}");
2948 break;
2949 case ltNOTSUBSET:
2950 if (start) TexOutput("{\\f1\\'CB}");
2951 break;
2952
2953 // Arrows
2954 case ltLEFTARROW:
2955 if (start) TexOutput("{\\f1\\'AC}");
2956 break;
2957 case ltLEFTARROW2:
2958 if (start) TexOutput("{\\f1\\'DC}");
2959 break;
2960 case ltRIGHTARROW:
2961 if (start) TexOutput("{\\f1\\'AE}");
2962 break;
2963 case ltRIGHTARROW2:
2964 if (start) TexOutput("{\\f1\\'DE}");
2965 break;
2966 case ltLEFTRIGHTARROW:
2967 if (start) TexOutput("{\\f1\\'AB}");
2968 break;
2969 case ltLEFTRIGHTARROW2:
2970 if (start) TexOutput("{\\f1\\'DB}");
2971 break;
2972 case ltUPARROW:
2973 if (start) TexOutput("{\\f1\\'AD}");
2974 break;
2975 case ltUPARROW2:
2976 if (start) TexOutput("{\\f1\\'DD}");
2977 break;
2978 case ltDOWNARROW:
2979 if (start) TexOutput("{\\f1\\'AF}");
2980 break;
2981 case ltDOWNARROW2:
2982 if (start) TexOutput("{\\f1\\'DF}");
2983 break;
2984
2985 // Miscellaneous symbols
2986 case ltALEPH:
2987 if (start) TexOutput("{\\f1\\'CO}");
2988 break;
2989 case ltWP:
2990 if (start) TexOutput("{\\f1\\'C3}");
2991 break;
2992 case ltRE:
2993 if (start) TexOutput("{\\f1\\'C2}");
2994 break;
2995 case ltIM:
2996 if (start) TexOutput("{\\f1\\'C1}");
2997 break;
2998 case ltEMPTYSET:
2999 if (start) TexOutput("{\\f1\\'C6}");
3000 break;
3001 case ltNABLA:
3002 if (start) TexOutput("{\\f1\\'D1}");
3003 break;
3004 case ltSURD:
3005 if (start) TexOutput("{\\f1\\'D6}");
3006 break;
3007 case ltPARTIAL:
3008 if (start) TexOutput("{\\f1\\'B6}");
3009 break;
3010 case ltBOT:
3011 if (start) TexOutput("{\\f1\\'5E}");
3012 break;
3013 case ltFORALL:
3014 if (start) TexOutput("{\\f1\\'22}");
3015 break;
3016 case ltEXISTS:
3017 if (start) TexOutput("{\\f1\\'24}");
3018 break;
3019 case ltNEG:
3020 if (start) TexOutput("{\\f1\\'D8}");
3021 break;
3022 case ltSHARP:
3023 if (start) TexOutput("{\\f1\\'23}");
3024 break;
3025 case ltANGLE:
3026 if (start) TexOutput("{\\f1\\'D0}");
3027 break;
3028 case ltTRIANGLE:
3029 if (start) TexOutput("{\\f5\\'73}");
3030 break;
3031 case ltCLUBSUIT:
3032 if (start) TexOutput("{\\f5\\'A8}");
3033 break;
3034 case ltDIAMONDSUIT:
3035 if (start) TexOutput("{\\f5\\'A9}");
3036 break;
3037 case ltHEARTSUIT:
3038 if (start) TexOutput("{\\f5\\'AA}");
3039 break;
3040 case ltSPADESUIT:
3041 if (start) TexOutput("{\\f5\\'AB}");
3042 break;
3043 case ltINFTY:
3044 if (start) TexOutput("{\\f1\\'A5}");
3045 break;
3046 case ltCOPYRIGHT:
3047 if (start) TexOutput("{\\f0\\'A9}");
3048 break;
3049 case ltREGISTERED:
3050 if (start) TexOutput("{\\f0\\'AE}");
3051 break;
3052 case ltPM:
3053 if (start) TexOutput("{\\f1\\'B1}");
3054 break;
3055 case ltMP:
3056 if (start) TexOutput("{\\f1\\'B1}");
3057 break;
3058 case ltTIMES:
3059 if (start) TexOutput("{\\f1\\'B4}");
3060 break;
3061 case ltDIV:
3062 if (start) TexOutput("{\\f1\\'B8}");
3063 break;
3064 case ltCDOT:
3065 if (start) TexOutput("{\\f1\\'D7}");
3066 break;
3067 case ltAST:
3068 if (start) TexOutput("{\\f1\\'2A}");
3069 break;
3070 case ltSTAR:
3071 if (start) TexOutput("{\\f5\\'AB}");
3072 break;
3073 case ltCAP:
3074 if (start) TexOutput("{\\f1\\'C7}");
3075 break;
3076 case ltCUP:
3077 if (start) TexOutput("{\\f1\\'C8}");
3078 break;
3079 case ltVEE:
3080 if (start) TexOutput("{\\f1\\'DA}");
3081 break;
3082 case ltWEDGE:
3083 if (start) TexOutput("{\\f1\\'D9}");
3084 break;
3085 case ltCIRC:
3086 if (start) TexOutput("{\\f1\\'B0}");
3087 break;
3088 case ltBULLET:
3089 if (start) TexOutput("{\\f1\\'B7}");
3090 break;
3091 case ltDIAMOND:
3092 if (start) TexOutput("{\\f1\\'E0}");
3093 break;
3094 case ltBOX:
3095 if (start) TexOutput("{\\f1\\'C6}");
3096 break;
3097 case ltDIAMOND2:
3098 if (start) TexOutput("{\\f1\\'E0}");
3099 break;
3100 case ltBIGTRIANGLEDOWN:
3101 if (start) TexOutput("{\\f1\\'D1}");
3102 break;
3103 case ltOPLUS:
3104 if (start) TexOutput("{\\f1\\'C5}");
3105 break;
3106 case ltOTIMES:
3107 if (start) TexOutput("{\\f1\\'C4}");
3108 break;
3109 case ltSS:
3110 if (start) TexOutput("{\\'DF}");
3111 break;
3112 case ltFIGURE:
3113 {
3114 if (start) inFigure = TRUE;
3115 else inFigure = FALSE;
3116 break;
3117 }
3118 case ltTABLE:
3119 {
3120 if (start) inTable = TRUE;
3121 else inTable = FALSE;
3122 break;
3123 }
3124 default:
3125 {
3126 DefaultOnMacro(macroId, no_args, start);
3127 break;
3128 }
3129 }
3130 }
3131
3132 // Called on start/end of argument examination
3133 bool RTFOnArgument(int macroId, int arg_no, bool start)
3134 {
3135 char buf[300];
3136 switch (macroId)
3137 {
3138 case ltCHAPTER:
3139 case ltCHAPTERSTAR:
3140 case ltCHAPTERHEADING:
3141 case ltSECTION:
3142 case ltSECTIONSTAR:
3143 case ltSECTIONHEADING:
3144 case ltSUBSECTION:
3145 case ltSUBSECTIONSTAR:
3146 case ltSUBSUBSECTION:
3147 case ltSUBSUBSECTIONSTAR:
3148 case ltGLOSS:
3149 case ltMEMBERSECTION:
3150 case ltFUNCTIONSECTION:
3151 case ltCAPTION:
3152 case ltCAPTIONSTAR:
3153 {
3154 if (!start && (arg_no == 1))
3155 currentSection = GetArgChunk();
3156 return FALSE;
3157 break;
3158 }
3159 case ltFUNC:
3160 {
3161 if (start && (arg_no == 1))
3162 TexOutput("\\pard\\li600\\fi-600{\\b ");
3163
3164 if (!start && (arg_no == 1))
3165 TexOutput("} ");
3166
3167 if (start && (arg_no == 2))
3168 {
3169 if (!suppressNameDecoration) TexOutput("{\\b ");
3170 currentMember = GetArgChunk();
3171 }
3172 if (!start && (arg_no == 2))
3173 {
3174 if (!suppressNameDecoration) TexOutput("}");
3175 }
3176
3177 if (start && (arg_no == 3))
3178 TexOutput("(");
3179 if (!start && (arg_no == 3))
3180 {
3181 // TexOutput(")\\li0\\fi0");
3182 // TexOutput(")\\par\\pard\\li0\\fi0");
3183 // issuedNewParagraph = 1;
3184 TexOutput(")");
3185 WriteEnvironmentStyles();
3186 }
3187 break;
3188 }
3189 case ltCLIPSFUNC:
3190 {
3191 if (start && (arg_no == 1))
3192 TexOutput("\\pard\\li260\\fi-260{\\b ");
3193 if (!start && (arg_no == 1))
3194 TexOutput("} ");
3195
3196 if (start && (arg_no == 2))
3197 {
3198 if (!suppressNameDecoration) TexOutput("({\\b ");
3199 currentMember = GetArgChunk();
3200 }
3201 if (!start && (arg_no == 2))
3202 {
3203 if (!suppressNameDecoration) TexOutput("}");
3204 }
3205
3206 if (!start && (arg_no == 3))
3207 {
3208 TexOutput(")\\li0\\fi0");
3209 WriteEnvironmentStyles();
3210 }
3211 break;
3212 }
3213 case ltPFUNC:
3214 {
3215 if (start && (arg_no == 1))
3216 TexOutput("\\pard\\li260\\fi-260");
3217
3218 if (!start && (arg_no == 1))
3219 TexOutput(" ");
3220
3221 if (start && (arg_no == 2))
3222 TexOutput("(*");
3223 if (!start && (arg_no == 2))
3224 TexOutput(")");
3225
3226 if (start && (arg_no == 2))
3227 currentMember = GetArgChunk();
3228
3229 if (start && (arg_no == 3))
3230 TexOutput("(");
3231 if (!start && (arg_no == 3))
3232 {
3233 TexOutput(")\\li0\\fi0");
3234 WriteEnvironmentStyles();
3235 }
3236 break;
3237 }
3238 case ltPARAM:
3239 {
3240 if (start && (arg_no == 1))
3241 TexOutput("{\\b ");
3242 if (!start && (arg_no == 1))
3243 TexOutput("}");
3244 if (start && (arg_no == 2))
3245 {
3246 TexOutput("{\\i ");
3247 }
3248 if (!start && (arg_no == 2))
3249 {
3250 TexOutput("}");
3251 }
3252 break;
3253 }
3254 case ltCPARAM:
3255 {
3256 if (start && (arg_no == 1))
3257 TexOutput("{\\b ");
3258 if (!start && (arg_no == 1))
3259 TexOutput("} "); // This is the difference from param - one space!
3260 if (start && (arg_no == 2))
3261 {
3262 TexOutput("{\\i ");
3263 }
3264 if (!start && (arg_no == 2))
3265 {
3266 TexOutput("}");
3267 }
3268 break;
3269 }
3270 case ltMEMBER:
3271 {
3272 if (!start && (arg_no == 1))
3273 TexOutput(" ");
3274
3275 if (start && (arg_no == 2))
3276 currentMember = GetArgChunk();
3277 break;
3278 }
3279 case ltREF:
3280 {
3281 if (start)
3282 {
3283 char *sec = NULL;
3284 char *secName = NULL;
3285
3286 char *refName = GetArgData();
3287 if (winHelp || !useWord)
3288 {
3289 if (refName)
3290 {
3291 TexRef *texRef = FindReference(refName);
3292 if (texRef)
3293 {
3294 sec = texRef->sectionNumber;
3295 secName = texRef->sectionName;
3296 }
3297 }
3298 if (sec)
3299 {
3300 TexOutput(sec);
3301 }
3302 }
3303 else
3304 {
3305 fprintf(Chapters, "{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
3306 refName);
3307 }
3308 return FALSE;
3309 }
3310 break;
3311 }
3312 case ltHELPREF:
3313 case ltHELPREFN:
3314 {
3315 if (winHelp)
3316 {
3317 if ((GetNoArgs() - arg_no) == 1)
3318 {
3319 if (start)
3320 TexOutput("{\\uldb ");
3321 else
3322 TexOutput("}");
3323 }
3324 if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
3325 {
3326 if (start)
3327 {
3328 TexOutput("{\\v ");
3329
3330 // Remove green colour/underlining if specified
3331 if (!hotSpotUnderline && !hotSpotColour)
3332 TexOutput("%");
3333 else if (!hotSpotColour)
3334 TexOutput("*");
3335 }
3336 else TexOutput("}");
3337 }
3338 }
3339 else // If a linear document, must resolve the references ourselves
3340 {
3341 if ((GetNoArgs() - arg_no) == 1)
3342 {
3343 // In a linear document we display the anchor text in italic plus
3344 // the page number.
3345 if (start)
3346 TexOutput("{\\i ");
3347 else
3348 TexOutput("}");
3349
3350 if (start)
3351 helpRefText = GetArgChunk();
3352
3353 return TRUE;
3354 }
3355 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
3356 {
3357 if (macroId != ltHELPREFN)
3358 {
3359 char *refName = GetArgData();
3360 TexRef *texRef = NULL;
3361 if (refName)
3362 texRef = FindReference(refName);
3363 if (start)
3364 {
3365 if (texRef || !ignoreBadRefs)
3366 TexOutput(" (");
3367 if (refName)
3368 {
3369 if (texRef || !ignoreBadRefs)
3370 {
3371 if (useWord)
3372 {
3373 char *s = GetArgData();
3374 TexOutput("p. ");
3375 TexOutput("{\\field{\\*\\fldinst PAGEREF ");
3376 TexOutput(refName);
3377 TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
3378 }
3379 else
3380 {
3381 // Only print section name if we're not in Word mode,
3382 // so can't do page references
3383 if (texRef)
3384 {
3385 TexOutput(texRef->sectionName) ; TexOutput(" "); TexOutput(texRef->sectionNumber);
3386 }
3387 else
3388 {
3389 if (!ignoreBadRefs)
3390 TexOutput("??");
3391 sprintf(buf, "Warning: unresolved reference '%s'", refName);
3392 OnInform(buf);
3393 }
3394 }
3395 }
3396 }
3397 else TexOutput("??");
3398 }
3399 else
3400 {
3401 if (texRef || !ignoreBadRefs)
3402 TexOutput(")");
3403 }
3404 }
3405 return FALSE;
3406 }
3407 }
3408 break;
3409 }
3410 case ltURLREF:
3411 {
3412 if (arg_no == 1)
3413 {
3414 return TRUE;
3415 }
3416 else if (arg_no == 2)
3417 {
3418 if (start)
3419 {
3420 inVerbatim = TRUE;
3421 TexOutput(" ({\\f3 ");
3422 }
3423 else
3424 {
3425 TexOutput("})");
3426 inVerbatim = FALSE;
3427 }
3428 return TRUE;
3429 }
3430 break;
3431 }
3432 case ltPOPREF:
3433 {
3434 if (winHelp)
3435 {
3436 if ((GetNoArgs() - arg_no) == 1)
3437 {
3438 if (start)
3439 TexOutput("{\\ul ");
3440 else
3441 TexOutput("}");
3442 }
3443 if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
3444 {
3445 if (start)
3446 {
3447 TexOutput("{\\v ");
3448
3449 // Remove green colour/underlining if specified
3450 if (!hotSpotUnderline && !hotSpotColour)
3451 TexOutput("%");
3452 else if (!hotSpotColour)
3453 TexOutput("*");
3454 }
3455 else TexOutput("}");
3456 }
3457 }
3458 else // A linear document...
3459 {
3460 if ((GetNoArgs() - arg_no) == 1)
3461 {
3462 // In a linear document we just display the anchor text in italic
3463 if (start)
3464 TexOutput("{\\i ");
3465 else
3466 TexOutput("}");
3467 return TRUE;
3468 }
3469 else return FALSE;
3470 }
3471 break;
3472 }
3473 case ltADDCONTENTSLINE:
3474 {
3475 if (start && !winHelp)
3476 {
3477 if (arg_no == 2)
3478 contentsLineSection = copystring(GetArgData());
3479 else if (arg_no == 3)
3480 contentsLineValue = copystring(GetArgData());
3481 return FALSE;
3482 }
3483 else return FALSE;
3484 break;
3485 }
3486 case ltIMAGE:
3487 case ltIMAGEL:
3488 case ltIMAGER:
3489 case ltIMAGEMAP:
3490 case ltPSBOXTO:
3491 {
3492 if (arg_no == 3)
3493 return FALSE;
3494
3495 static int imageWidth = 0;
3496 static int imageHeight = 0;
3497
3498 if (start && (arg_no == 1))
3499 {
3500 char *imageDimensions = copystring(GetArgData());
3501 char buf1[50];
3502 strcpy(buf1, imageDimensions);
3503 char *tok1 = strtok(buf1, ";:");
3504 char *tok2 = strtok(NULL, ";:");
3505 // Convert points to TWIPS (1 twip = 1/20th of point)
3506 imageWidth = (int)(20*(tok1 ? ParseUnitArgument(tok1) : 0));
3507 imageHeight = (int)(20*(tok2 ? ParseUnitArgument(tok2) : 0));
3508 if (imageDimensions) // glt
3509 delete [] imageDimensions;
3510 return FALSE;
3511 }
3512 else if (start && (arg_no == 2 ))
3513 {
3514 char *filename = copystring(GetArgData());
3515 wxString f = "";
3516 if ((winHelp || (strcmp(bitmapMethod, "includepicture") == 0) || (strcmp(bitmapMethod, "import") == 0)) && useWord)
3517 {
3518 if (f == "") // Try for a .shg (segmented hypergraphics file)
3519 {
3520 strcpy(buf, filename);
3521 StripExtension(buf);
3522 strcat(buf, ".shg");
3523 f = TexPathList.FindValidPath(buf);
3524 }
3525 if (f == "") // Try for a .bmp
3526 {
3527 strcpy(buf, filename);
3528 StripExtension(buf);
3529 strcat(buf, ".bmp");
3530 f = TexPathList.FindValidPath(buf);
3531 }
3532 if (f == "") // Try for a metafile instead
3533 {
3534 strcpy(buf, filename);
3535 StripExtension(buf);
3536 strcat(buf, ".wmf");
3537 f = TexPathList.FindValidPath(buf);
3538 }
3539 if (f != "")
3540 {
3541 if (winHelp)
3542 {
3543 if (bitmapTransparency && (winHelpVersion > 3))
3544 TexOutput("\\{bmct ");
3545 else
3546 TexOutput("\\{bmc ");
3547 wxString str = wxFileNameFromPath(f);
3548 TexOutput((char*) (const char*) str);
3549 TexOutput("\\}");
3550 }
3551 else
3552 {
3553 // Microsoft Word method
3554 if (strcmp(bitmapMethod, "import") == 0)
3555 TexOutput("{\\field{\\*\\fldinst IMPORT ");
3556 else
3557 TexOutput("{\\field{\\*\\fldinst INCLUDEPICTURE ");
3558
3559 // Full path appears not to be valid!
3560 wxString str = wxFileNameFromPath(f);
3561 TexOutput((char*)(const char*) str);
3562 /*
3563 int len = strlen(f);
3564 char smallBuf[2]; smallBuf[1] = 0;
3565 for (int i = 0; i < len; i++)
3566 {
3567 smallBuf[0] = f[i];
3568 TexOutput(smallBuf);
3569 if (smallBuf[0] == '\\')
3570 TexOutput(smallBuf);
3571 }
3572 */
3573 TexOutput("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}");
3574 }
3575 }
3576 else
3577 {
3578 TexOutput("[No BMP or WMF for image file ");
3579 TexOutput(filename);
3580 TexOutput("]");
3581 sprintf(buf, "Warning: could not find a BMP or WMF equivalent for %s.", filename);
3582 OnInform(buf);
3583 }
3584 if (filename) // glt
3585 delete [] filename;
3586 }
3587 else // linear RTF
3588 {
3589 if (f == "") // Try for a .bmp
3590 {
3591 strcpy(buf, filename);
3592 StripExtension(buf);
3593 strcat(buf, ".bmp");
3594 f = TexPathList.FindValidPath(buf);
3595 }
3596 if (f != "")
3597 {
3598 FILE *fd = fopen(f, "rb");
3599 if (OutputBitmapHeader(fd, winHelp))
3600 OutputBitmapData(fd);
3601 else
3602 {
3603 sprintf(buf, "Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP).", (const char*) f);
3604 OnError(buf);
3605 }
3606 fclose(fd);
3607 }
3608 else // Try for a metafile instead
3609 {
3610 #ifdef __WXMSW__
3611 strcpy(buf, filename);
3612 StripExtension(buf);
3613 strcat(buf, ".wmf");
3614 f = TexPathList.FindValidPath(buf);
3615 if (f != "")
3616 {
3617 // HFILE handle = _lopen(f, READ);
3618 FILE *fd = fopen(f, "rb");
3619 if (OutputMetafileHeader(fd, winHelp, imageWidth, imageHeight))
3620 {
3621 OutputMetafileData(fd);
3622 }
3623 else
3624 {
3625 sprintf(buf, "Could not read metafile %s. Perhaps it's not a placeable metafile?", f);
3626 OnError(buf);
3627 }
3628 fclose(fd);
3629 }
3630 else
3631 {
3632 #endif
3633 TexOutput("[No BMP or WMF for image file ");
3634 TexOutput(filename);
3635 TexOutput("]");
3636 sprintf(buf, "Warning: could not find a BMP or WMF equivalent for %s.", filename);
3637 OnInform(buf);
3638 #ifdef __WXMSW__
3639 }
3640 #endif
3641 }
3642 }
3643 return FALSE;
3644 }
3645 else
3646 return FALSE;
3647 break;
3648 }
3649 case ltTABULAR:
3650 case ltSUPERTABULAR:
3651 {
3652 if (arg_no == 1)
3653 {
3654 if (start)
3655 {
3656 currentRowNumber = 0;
3657 inTabular = TRUE;
3658 startRows = TRUE;
3659 tableVerticalLineLeft = FALSE;
3660 tableVerticalLineRight = FALSE;
3661 int currentWidth = 0;
3662
3663 char *alignString = copystring(GetArgData());
3664 ParseTableArgument(alignString);
3665
3666 // TexOutput("\\trowd\\trgaph108\\trleft-108");
3667 TexOutput("\\trowd\\trgaph108");
3668
3669 // Write the first row formatting for compatibility
3670 // with standard Latex
3671 if (compatibilityMode)
3672 {
3673 for (int i = 0; i < noColumns; i++)
3674 {
3675 currentWidth += TableData[i].width;
3676 sprintf(buf, "\\cellx%d", currentWidth);
3677 TexOutput(buf);
3678 }
3679 TexOutput("\\pard\\intbl\n");
3680 }
3681 delete[] alignString;
3682
3683 return FALSE;
3684 }
3685 }
3686 else if (arg_no == 2 && !start)
3687 {
3688 TexOutput("\\pard\n");
3689 WriteEnvironmentStyles();
3690 inTabular = FALSE;
3691 }
3692 break;
3693 }
3694
3695 case ltQUOTE:
3696 case ltVERSE:
3697 {
3698 if (start)
3699 {
3700 TexOutput("\\li360\n");
3701 forbidParindent ++;
3702 PushEnvironmentStyle("\\li360");
3703 }
3704 else
3705 {
3706 forbidParindent --;
3707 PopEnvironmentStyle();
3708 OnMacro(ltPAR, 0, TRUE);
3709 OnMacro(ltPAR, 0, FALSE);
3710 }
3711 break;
3712 }
3713 case ltQUOTATION:
3714 {
3715 if (start)
3716 {
3717 TexOutput("\\li360\n");
3718 PushEnvironmentStyle("\\li360");
3719 }
3720 else
3721 {
3722 PopEnvironmentStyle();
3723 OnMacro(ltPAR, 0, TRUE);
3724 OnMacro(ltPAR, 0, FALSE);
3725 }
3726 break;
3727 }
3728 case ltBOXIT:
3729 case ltFRAMEBOX:
3730 case ltFBOX:
3731 case ltNORMALBOX:
3732 case ltNORMALBOXD:
3733 {
3734 if (start)
3735 {
3736 sprintf(buf, "\\box\\trgaph108%s\n", ((macroId == ltNORMALBOXD) ? "\\brdrdb" : "\\brdrs"));
3737 TexOutput(buf);
3738 PushEnvironmentStyle(buf);
3739 }
3740 else
3741 {
3742 PopEnvironmentStyle();
3743 OnMacro(ltPAR, 0, TRUE);
3744 OnMacro(ltPAR, 0, FALSE);
3745 }
3746 break;
3747 }
3748 case ltHELPFONTSIZE:
3749 {
3750 if (start)
3751 {
3752 char *data = GetArgData();
3753 if (strcmp(data, "10") == 0)
3754 SetFontSizes(10);
3755 else if (strcmp(data, "11") == 0)
3756 SetFontSizes(11);
3757 else if (strcmp(data, "12") == 0)
3758 SetFontSizes(12);
3759 sprintf(buf, "\\fs%d\n", normalFont*2);
3760 TexOutput(buf);
3761 TexOutput(buf);
3762 return FALSE;
3763 }
3764 break;
3765 }
3766 case ltHELPFONTFAMILY:
3767 {
3768 if (start)
3769 {
3770 char *data = GetArgData();
3771 if (strcmp(data, "Swiss") == 0)
3772 TexOutput("\\f2\n");
3773 else if (strcmp(data, "Symbol") == 0)
3774 TexOutput("\\f1\n");
3775 else if (strcmp(data, "Times") == 0)
3776 TexOutput("\\f0\n");
3777
3778 return FALSE;
3779 }
3780 break;
3781 }
3782 case ltPARINDENT:
3783 {
3784 if (start && arg_no == 1)
3785 {
3786 char *data = GetArgData();
3787 ParIndent = ParseUnitArgument(data);
3788 if (ParIndent == 0 || forbidParindent == 0)
3789 {
3790 sprintf(buf, "\\fi%d\n", ParIndent*20);
3791 TexOutput(buf);
3792 }
3793 return FALSE;
3794 }
3795 break;
3796 }
3797 case ltITEM:
3798 {
3799 if (start && IsArgOptional())
3800 {
3801 descriptionItemArg = GetArgChunk();
3802 return FALSE;
3803 }
3804 break;
3805 }
3806 case ltTWOCOLITEM:
3807 case ltTWOCOLITEMRULED:
3808 {
3809 switch (arg_no)
3810 {
3811 case 1:
3812 {
3813 if (!start)
3814 TexOutput("\\tab ");
3815 break;
3816 }
3817 case 2:
3818 {
3819 if (!start)
3820 {
3821 if (macroId == ltTWOCOLITEMRULED)
3822 TexOutput("\\brdrb\\brdrs\\brdrw15\\brsp20 ");
3823 TexOutput("\\par\\pard\n");
3824 issuedNewParagraph = 1;
3825 WriteEnvironmentStyles();
3826 }
3827 break;
3828 }
3829 }
3830 return TRUE;
3831 break;
3832 }
3833 /*
3834 * Accents
3835 *
3836 */
3837 case ltACCENT_GRAVE:
3838 {
3839 if (start)
3840 {
3841 char *val = GetArgData();
3842 if (val)
3843 {
3844 switch (val[0])
3845 {
3846 case 'a':
3847 TexOutput("\\'e0");
3848 break;
3849 case 'e':
3850 TexOutput("\\'e8");
3851 break;
3852 case 'i':
3853 TexOutput("\\'ec");
3854 break;
3855 case 'o':
3856 TexOutput("\\'f2");
3857 break;
3858 case 'u':
3859 TexOutput("\\'f9");
3860 break;
3861 case 'A':
3862 TexOutput("\\'c0");
3863 break;
3864 case 'E':
3865 TexOutput("\\'c8");
3866 break;
3867 case 'I':
3868 TexOutput("\\'cc");
3869 break;
3870 case 'O':
3871 TexOutput("\\'d2");
3872 break;
3873 case 'U':
3874 TexOutput("\\'d9");
3875 break;
3876 default:
3877 break;
3878 }
3879 }
3880 }
3881 return FALSE;
3882 break;
3883 }
3884 case ltACCENT_ACUTE:
3885 {
3886 if (start)
3887 {
3888 char *val = GetArgData();
3889 if (val)
3890 {
3891 switch (val[0])
3892 {
3893 case 'a':
3894 TexOutput("\\'e1");
3895 break;
3896 case 'e':
3897 TexOutput("\\'e9");
3898 break;
3899 case 'i':
3900 TexOutput("\\'ed");
3901 break;
3902 case 'o':
3903 TexOutput("\\'f3");
3904 break;
3905 case 'u':
3906 TexOutput("\\'fa");
3907 break;
3908 case 'y':
3909 TexOutput("\\'fd");
3910 break;
3911 case 'A':
3912 TexOutput("\\'c1");
3913 break;
3914 case 'E':
3915 TexOutput("\\'c9");
3916 break;
3917 case 'I':
3918 TexOutput("\\'cd");
3919 break;
3920 case 'O':
3921 TexOutput("\\'d3");
3922 break;
3923 case 'U':
3924 TexOutput("\\'da");
3925 break;
3926 case 'Y':
3927 TexOutput("\\'dd");
3928 break;
3929 default:
3930 break;
3931 }
3932 }
3933 }
3934 return FALSE;
3935 break;
3936 }
3937 case ltACCENT_CARET:
3938 {
3939 if (start)
3940 {
3941 char *val = GetArgData();
3942 if (val)
3943 {
3944 switch (val[0])
3945 {
3946 case 'a':
3947 TexOutput("\\'e2");
3948 break;
3949 case 'e':
3950 TexOutput("\\'ea");
3951 break;
3952 case 'i':
3953 TexOutput("\\'ee");
3954 break;
3955 case 'o':
3956 TexOutput("\\'f4");
3957 break;
3958 case 'u':
3959 TexOutput("\\'fb");
3960 break;
3961 case 'A':
3962 TexOutput("\\'c2");
3963 break;
3964 case 'E':
3965 TexOutput("\\'ca");
3966 break;
3967 case 'I':
3968 TexOutput("\\'ce");
3969 break;
3970 case 'O':
3971 TexOutput("\\'d4");
3972 break;
3973 case 'U':
3974 TexOutput("\\'db");
3975 break;
3976 default:
3977 break;
3978 }
3979 }
3980 }
3981 return FALSE;
3982 break;
3983 }
3984 case ltACCENT_TILDE:
3985 {
3986 if (start)
3987 {
3988 char *val = GetArgData();
3989 if (val)
3990 {
3991 switch (val[0])
3992 {
3993 case 'a':
3994 TexOutput("\\'e3");
3995 break;
3996 case ' ':
3997 TexOutput("~");
3998 break;
3999 case 'n':
4000 TexOutput("\\'f1");
4001 break;
4002 case 'o':
4003 TexOutput("\\'f5");
4004 break;
4005 case 'A':
4006 TexOutput("\\'c3");
4007 break;
4008 case 'N':
4009 TexOutput("\\'d1");
4010 break;
4011 case 'O':
4012 TexOutput("\\'d5");
4013 break;
4014 default:
4015 break;
4016 }
4017 }
4018 }
4019 return FALSE;
4020 break;
4021 }
4022 case ltACCENT_UMLAUT:
4023 {
4024 if (start)
4025 {
4026 char *val = GetArgData();
4027 if (val)
4028 {
4029 switch (val[0])
4030 {
4031 case 'a':
4032 TexOutput("\\'e4");
4033 break;
4034 case 'e':
4035 TexOutput("\\'eb");
4036 break;
4037 case 'i':
4038 TexOutput("\\'ef");
4039 break;
4040 case 'o':
4041 TexOutput("\\'f6");
4042 break;
4043 case 'u':
4044 TexOutput("\\'fc");
4045 break;
4046 case 's':
4047 TexOutput("\\'df");
4048 break;
4049 case 'y':
4050 TexOutput("\\'ff");
4051 break;
4052 case 'A':
4053 TexOutput("\\'c4");
4054 break;
4055 case 'E':
4056 TexOutput("\\'cb");
4057 break;
4058 case 'I':
4059 TexOutput("\\'cf");
4060 break;
4061 case 'O':
4062 TexOutput("\\'d6");
4063 break;
4064 case 'U':
4065 TexOutput("\\'dc");
4066 break;
4067 case 'Y':
4068 TexOutput("\\'df");
4069 break;
4070 default:
4071 break;
4072 }
4073 }
4074 }
4075 return FALSE;
4076 break;
4077 }
4078 case ltACCENT_DOT:
4079 {
4080 if (start)
4081 {
4082 char *val = GetArgData();
4083 if (val)
4084 {
4085 switch (val[0])
4086 {
4087 case 'a':
4088 TexOutput("\\'e5");
4089 break;
4090 case 'A':
4091 TexOutput("\\'c5");
4092 break;
4093 default:
4094 break;
4095 }
4096 }
4097 }
4098 return FALSE;
4099 break;
4100 }
4101 case ltACCENT_CADILLA:
4102 {
4103 if (start)
4104 {
4105 char *val = GetArgData();
4106 if (val)
4107 {
4108 switch (val[0])
4109 {
4110 case 'c':
4111 TexOutput("\\'e7");
4112 break;
4113 case 'C':
4114 TexOutput("\\'c7");
4115 break;
4116 default:
4117 break;
4118 }
4119 }
4120 }
4121 return FALSE;
4122 break;
4123 }
4124 case ltFOOTNOTE:
4125 {
4126 static char *helpTopic = NULL;
4127 static FILE *savedOutput = NULL;
4128 if (winHelp)
4129 {
4130 if (arg_no == 1)
4131 {
4132 if (start)
4133 {
4134 OnInform("Consider using \\footnotepopup instead of \\footnote.");
4135 footnoteCount ++;
4136 char footBuf[20];
4137 sprintf(footBuf, "(%d)", footnoteCount);
4138
4139 TexOutput(" {\\ul ");
4140 TexOutput(footBuf);
4141 TexOutput("}");
4142 helpTopic = FindTopicName(NULL);
4143 TexOutput("{\\v ");
4144
4145 // Remove green colour/underlining if specified
4146 if (!hotSpotUnderline && !hotSpotColour)
4147 TexOutput("%");
4148 else if (!hotSpotColour)
4149 TexOutput("*");
4150
4151 TexOutput(helpTopic);
4152 TexOutput("}");
4153
4154 fprintf(Popups, "\\page\n");
4155 // fprintf(Popups, "\n${\\footnote }"); // No title
4156 fprintf(Popups, "\n#{\\footnote %s}\n", helpTopic);
4157 fprintf(Popups, "+{\\footnote %s}\n", GetBrowseString());
4158 savedOutput = CurrentOutput1;
4159 SetCurrentOutput(Popups);
4160 }
4161 else
4162 {
4163 SetCurrentOutput(savedOutput);
4164 }
4165 return TRUE;
4166 }
4167 return TRUE;
4168 }
4169 else
4170 {
4171 if (start)
4172 {
4173 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE);
4174 }
4175 else
4176 {
4177 TexOutput("}}", TRUE);
4178 }
4179 return TRUE;
4180 }
4181 break;
4182 }
4183 case ltFOOTNOTEPOPUP:
4184 {
4185 static char *helpTopic = NULL;
4186 static FILE *savedOutput = NULL;
4187 if (winHelp)
4188 {
4189 if (arg_no == 1)
4190 {
4191 if (start)
4192 {
4193 TexOutput("{\\ul ");
4194 }
4195 else TexOutput("}");
4196 return TRUE;
4197 }
4198 else if (arg_no == 2)
4199 {
4200 if (start)
4201 {
4202 helpTopic = FindTopicName(NULL);
4203 TexOutput("{\\v ");
4204
4205 // Remove green colour/underlining if specified
4206 if (!hotSpotUnderline && !hotSpotColour)
4207 TexOutput("%");
4208 else if (!hotSpotColour)
4209 TexOutput("*");
4210
4211 TexOutput(helpTopic);
4212 TexOutput("}");
4213
4214 fprintf(Popups, "\\page\n");
4215 // fprintf(Popups, "\n${\\footnote }"); // No title
4216 fprintf(Popups, "\n#{\\footnote %s}\n", helpTopic);
4217 fprintf(Popups, "+{\\footnote %s}\n", GetBrowseString());
4218 savedOutput = CurrentOutput1;
4219 SetCurrentOutput(Popups);
4220 }
4221 else
4222 {
4223 SetCurrentOutput(savedOutput);
4224 }
4225 return TRUE;
4226 }
4227 }
4228 else
4229 {
4230 if (arg_no == 1)
4231 return TRUE;
4232 if (start)
4233 {
4234 TexOutput(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}", TRUE);
4235 }
4236 else
4237 {
4238 TexOutput("}}", TRUE);
4239 }
4240 return TRUE;
4241 }
4242 break;
4243 }
4244 case ltFANCYPLAIN:
4245 {
4246 if (start && (arg_no == 1))
4247 return FALSE;
4248 else
4249 return TRUE;
4250 break;
4251 }
4252 case ltSETHEADER:
4253 {
4254 if (start)
4255 forbidResetPar ++;
4256 else
4257 forbidResetPar --;
4258
4259 if (winHelp) return FALSE;
4260 if (start)
4261 {
4262 switch (arg_no)
4263 {
4264 case 1:
4265 LeftHeaderEven = GetArgChunk();
4266 if (strlen(GetArgData(LeftHeaderEven)) == 0)
4267 LeftHeaderEven = NULL;
4268 break;
4269 case 2:
4270 CentreHeaderEven = GetArgChunk();
4271 if (strlen(GetArgData(CentreHeaderEven)) == 0)
4272 CentreHeaderEven = NULL;
4273 break;
4274 case 3:
4275 RightHeaderEven = GetArgChunk();
4276 if (strlen(GetArgData(RightHeaderEven)) == 0)
4277 RightHeaderEven = NULL;
4278 break;
4279 case 4:
4280 LeftHeaderOdd = GetArgChunk();
4281 if (strlen(GetArgData(LeftHeaderOdd)) == 0)
4282 LeftHeaderOdd = NULL;
4283 break;
4284 case 5:
4285 CentreHeaderOdd = GetArgChunk();
4286 if (strlen(GetArgData(CentreHeaderOdd)) == 0)
4287 CentreHeaderOdd = NULL;
4288 break;
4289 case 6:
4290 RightHeaderOdd = GetArgChunk();
4291 if (strlen(GetArgData(RightHeaderOdd)) == 0)
4292 RightHeaderOdd = NULL;
4293 OutputRTFHeaderCommands();
4294 break;
4295 default:
4296 break;
4297 }
4298 }
4299 return FALSE;
4300 break;
4301 }
4302 case ltSETFOOTER:
4303 {
4304 if (start)
4305 forbidResetPar ++;
4306 else
4307 forbidResetPar --;
4308
4309 if (winHelp) return FALSE;
4310 if (start)
4311 {
4312 switch (arg_no)
4313 {
4314 case 1:
4315 LeftFooterEven = GetArgChunk();
4316 if (strlen(GetArgData(LeftFooterEven)) == 0)
4317 LeftFooterEven = NULL;
4318 break;
4319 case 2:
4320 CentreFooterEven = GetArgChunk();
4321 if (strlen(GetArgData(CentreFooterEven)) == 0)
4322 CentreFooterEven = NULL;
4323 break;
4324 case 3:
4325 RightFooterEven = GetArgChunk();
4326 if (strlen(GetArgData(RightFooterEven)) == 0)
4327 RightFooterEven = NULL;
4328 break;
4329 case 4:
4330 LeftFooterOdd = GetArgChunk();
4331 if (strlen(GetArgData(LeftFooterOdd)) == 0)
4332 LeftFooterOdd = NULL;
4333 break;
4334 case 5:
4335 CentreFooterOdd = GetArgChunk();
4336 if (strlen(GetArgData(CentreFooterOdd)) == 0)
4337 CentreFooterOdd = NULL;
4338 break;
4339 case 6:
4340 RightFooterOdd = GetArgChunk();
4341 if (strlen(GetArgData(RightFooterOdd)) == 0)
4342 RightFooterOdd = NULL;
4343 OutputRTFFooterCommands();
4344 break;
4345 default:
4346 break;
4347 }
4348 }
4349 return FALSE;
4350 break;
4351 }
4352 case ltMARKRIGHT:
4353 {
4354 if (winHelp) return FALSE;
4355 // Fake a SetHeader command
4356 if (start)
4357 {
4358 LeftHeaderOdd = NULL;
4359 CentreHeaderOdd = NULL;
4360 RightHeaderOdd = NULL;
4361 LeftHeaderEven = NULL;
4362 CentreHeaderEven = NULL;
4363 RightHeaderEven = NULL;
4364 OnInform("Consider using setheader/setfooter rather than markright.");
4365 }
4366 RTFOnArgument(ltSETHEADER, 4, start);
4367 if (!start)
4368 OutputRTFHeaderCommands();
4369 return FALSE;
4370 break;
4371 }
4372 case ltMARKBOTH:
4373 {
4374 if (winHelp) return FALSE;
4375 // Fake a SetHeader command
4376 switch (arg_no)
4377 {
4378 case 1:
4379 {
4380 if (start)
4381 {
4382 LeftHeaderOdd = NULL;
4383 CentreHeaderOdd = NULL;
4384 RightHeaderOdd = NULL;
4385 LeftHeaderEven = NULL;
4386 CentreHeaderEven = NULL;
4387 RightHeaderEven = NULL;
4388 OnInform("Consider using setheader/setfooter rather than markboth.");
4389 }
4390 return RTFOnArgument(ltSETHEADER, 1, start);
4391 break;
4392 }
4393 case 2:
4394 {
4395 RTFOnArgument(ltSETHEADER, 4, start);
4396 if (!start)
4397 OutputRTFHeaderCommands();
4398 return FALSE;
4399 break;
4400 }
4401 }
4402 break;
4403 }
4404 case ltPAGENUMBERING:
4405 {
4406 if (start)
4407 forbidResetPar ++;
4408 else
4409 forbidResetPar --;
4410
4411 if (winHelp) return FALSE;
4412 if (start)
4413 {
4414 TexOutput("\\pgnrestart");
4415 char *data = GetArgData();
4416 if (currentNumberStyle) delete[] currentNumberStyle;
4417 currentNumberStyle = copystring(data);
4418 OutputNumberStyle(currentNumberStyle);
4419
4420 TexOutput("\n");
4421 }
4422 return FALSE;
4423 break;
4424 }
4425 case ltTWOCOLUMN:
4426 {
4427 if (winHelp) return FALSE;
4428 if (start)
4429 return TRUE;
4430 break;
4431 }
4432 case ltITEMSEP:
4433 {
4434 if (start)
4435 {
4436 char *val = GetArgData();
4437 currentItemSep = ParseUnitArgument(val);
4438 return FALSE;
4439 }
4440 break;
4441 }
4442 case ltEVENSIDEMARGIN:
4443 {
4444 return FALSE;
4445 break;
4446 }
4447 case ltODDSIDEMARGIN:
4448 {
4449 if (start)
4450 {
4451 char *val = GetArgData();
4452 int twips = (int)(20*ParseUnitArgument(val));
4453 // Add an inch since in LaTeX it's specified minus an inch
4454 twips += 1440;
4455 CurrentLeftMarginOdd = twips;
4456 sprintf(buf, "\\margl%d\n", twips);
4457 TexOutput(buf);
4458
4459 CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep;
4460 }
4461 return FALSE;
4462 }
4463 case ltMARGINPARWIDTH:
4464 {
4465 if (start)
4466 {
4467 char *val = GetArgData();
4468 int twips = (int)(20*ParseUnitArgument(val));
4469 CurrentMarginParWidth = twips;
4470 }
4471 return FALSE;
4472 }
4473 case ltMARGINPARSEP:
4474 {
4475 if (start)
4476 {
4477 char *val = GetArgData();
4478 int twips = (int)(20*ParseUnitArgument(val));
4479 CurrentMarginParSep = twips;
4480 CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep;
4481 }
4482 return FALSE;
4483 }
4484 case ltTEXTWIDTH:
4485 {
4486 if (start)
4487 {
4488 char *val = GetArgData();
4489 int twips = (int)(20*ParseUnitArgument(val));
4490 CurrentTextWidth = twips;
4491
4492 // Need to set an implicit right margin
4493 CurrentRightMarginOdd = PageWidth - CurrentTextWidth - CurrentLeftMarginOdd;
4494 CurrentRightMarginEven = PageWidth - CurrentTextWidth - CurrentLeftMarginEven;
4495 CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep;
4496 sprintf(buf, "\\margr%d\n", CurrentRightMarginOdd);
4497 TexOutput(buf);
4498 }
4499 return FALSE;
4500 }
4501 case ltMARGINPAR:
4502 case ltMARGINPARODD:
4503 {
4504 if (start)
4505 {
4506 if (winHelp)
4507 {
4508 TexOutput("\\box\n");
4509 PushEnvironmentStyle("\\box");
4510 }
4511 else
4512 {
4513 sprintf(buf, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX, CurrentMarginParWidth);
4514 TexOutput(buf);
4515 }
4516 return TRUE;
4517 }
4518 else
4519 {
4520 if (winHelp)
4521 {
4522 TexOutput("\\par\\pard\n");
4523 PopEnvironmentStyle();
4524 WriteEnvironmentStyles();
4525 }
4526 else
4527 TexOutput("\\par\\pard\n");
4528 issuedNewParagraph = 1;
4529 }
4530 return FALSE;
4531 }
4532 case ltMARGINPAREVEN:
4533 {
4534 if (start)
4535 {
4536 if (winHelp)
4537 {
4538 TexOutput("\\box\n");
4539 PushEnvironmentStyle("\\box");
4540 }
4541 else
4542 {
4543 if (mirrorMargins)
4544 {
4545 // Have to calculate what the margins are changed to in WfW margin
4546 // mirror mode, on an even (left-hand) page.
4547 int x = PageWidth - CurrentRightMarginOdd - CurrentMarginParWidth - CurrentMarginParSep
4548 - CurrentTextWidth + GutterWidth;
4549 sprintf(buf, "\\phpg\\posx%d\\absw%d\n", x, CurrentMarginParWidth);
4550 TexOutput(buf);
4551 }
4552 else
4553 {
4554 sprintf(buf, "\\phpg\\posx%d\\absw%d\n", CurrentMarginParX, CurrentMarginParWidth);
4555 TexOutput(buf);
4556 }
4557 }
4558 return TRUE;
4559 }
4560 else
4561 {
4562 if (winHelp)
4563 {
4564 TexOutput("\\par\\pard\n");
4565 PopEnvironmentStyle();
4566 WriteEnvironmentStyles();
4567 }
4568 else
4569 issuedNewParagraph = 1;
4570 TexOutput("\\par\\pard\n");
4571 }
4572 return FALSE;
4573 }
4574 case ltTWOCOLWIDTHA:
4575 {
4576 if (start)
4577 {
4578 char *val = GetArgData();
4579 int twips = (int)(20*ParseUnitArgument(val));
4580 TwoColWidthA = twips;
4581 }
4582 return FALSE;
4583 break;
4584 }
4585 case ltTWOCOLWIDTHB:
4586 {
4587 if (start)
4588 {
4589 char *val = GetArgData();
4590 int twips = (int)(20*ParseUnitArgument(val));
4591 TwoColWidthB = twips;
4592 }
4593 return FALSE;
4594 break;
4595 }
4596 case ltROW:
4597 case ltRULEDROW:
4598 {
4599 if (start)
4600 {
4601 int currentWidth = 0;
4602
4603 if (!compatibilityMode || (currentRowNumber > 0))
4604 {
4605 TexOutput("\\pard\\intbl");
4606
4607 if (macroId == ltRULEDROW)
4608 ruleBottom = 1;
4609 for (int i = 0; i < noColumns; i++)
4610 {
4611 currentWidth += TableData[i].width;
4612 if (ruleTop == 1)
4613 {
4614 TexOutput("\\clbrdrt\\brdrs\\brdrw15");
4615 }
4616 else if (ruleTop > 1)
4617 {
4618 TexOutput("\\clbrdrt\\brdrdb\\brdrw15");
4619 }
4620 if (ruleBottom == 1)
4621 {
4622 TexOutput("\\clbrdrb\\brdrs\\brdrw15");
4623 }
4624 else if (ruleBottom > 1)
4625 {
4626 TexOutput("\\clbrdrb\\brdrdb\\brdrw15");
4627 }
4628
4629 if (TableData[i].rightBorder)
4630 TexOutput("\\clbrdrr\\brdrs\\brdrw15");
4631
4632 if (TableData[i].leftBorder)
4633 TexOutput("\\clbrdrl\\brdrs\\brdrw15");
4634
4635 sprintf(buf, "\\cellx%d", currentWidth);
4636 TexOutput(buf);
4637 }
4638 TexOutput("\\pard\\intbl\n");
4639 }
4640 ruleTop = 0;
4641 ruleBottom = 0;
4642 currentRowNumber ++;
4643 return TRUE;
4644 }
4645 else
4646 {
4647 // TexOutput("\\cell\\row\\trowd\\trgaph108\\trleft-108\n");
4648 TexOutput("\\cell\\row\\trowd\\trgaph108\n");
4649 }
4650 break;
4651 }
4652 case ltMULTICOLUMN:
4653 {
4654 static int noMultiColumns = 0;
4655 if (start)
4656 {
4657 switch (arg_no)
4658 {
4659 case 1:
4660 {
4661 noMultiColumns = atoi(GetArgData());
4662 return FALSE;
4663 break;
4664 }
4665 case 2:
4666 {
4667 return FALSE;
4668 }
4669 case 3:
4670 {
4671 return TRUE;
4672 }
4673 }
4674 }
4675 else
4676 {
4677 if (arg_no == 3)
4678 {
4679 for (int i = 1; i < noMultiColumns; i ++)
4680 TexOutput("\\cell");
4681 }
4682 }
4683 break;
4684 }
4685 case ltINDENTED:
4686 {
4687 if (start && (arg_no == 1))
4688 {
4689 // indentLevel ++;
4690 // TexOutput("\\fi0\n");
4691 int oldIndent = 0;
4692 wxNode *node = itemizeStack.First();
4693 if (node)
4694 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4695
4696 int indentValue = 20*ParseUnitArgument(GetArgData());
4697 int indentSize = indentValue + oldIndent;
4698
4699 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4700 itemizeStack.Insert(struc);
4701
4702 sprintf(buf, "\\tx%d\\li%d ", indentSize, indentSize);
4703 PushEnvironmentStyle(buf);
4704 TexOutput(buf);
4705 return FALSE;
4706 }
4707 if (!start && (arg_no == 2))
4708 {
4709 PopEnvironmentStyle();
4710 if (itemizeStack.First())
4711 {
4712 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4713 delete struc;
4714 delete itemizeStack.First();
4715 }
4716 if (itemizeStack.Number() == 0)
4717 {
4718 TexOutput("\\par\\pard\n");
4719 issuedNewParagraph = 1;
4720 WriteEnvironmentStyles();
4721 }
4722 }
4723 return TRUE;
4724 break;
4725 }
4726 /*
4727 case ltSIZEDBOX:
4728 case ltSIZEDBOXD:
4729 {
4730 if (start && (arg_no == 1))
4731 {
4732 int oldIndent = 0;
4733 wxNode *node = itemizeStack.First();
4734 if (node)
4735 oldIndent = ((ItemizeStruc *)node->Data())->indentation;
4736
4737 int boxWidth = 20*ParseUnitArgument(GetArgData());
4738
4739 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4740 int indentSize = indentValue + oldIndent;
4741 int indentSizeRight = indentSize + boxWidth;
4742
4743 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4744 itemizeStack.Insert(struc);
4745
4746 sprintf(buf, "\\tx%d\\li%d\\lr%d\\box%s ", indentSize, indentSize, indentSizeRight,
4747 ((macroId == ltCENTEREDBOX) ? "\\brdrs" : "\\brdrdb"));
4748 PushEnvironmentStyle(buf);
4749 TexOutput(buf);
4750 return FALSE;
4751 }
4752 if (!start && (arg_no == 2))
4753 {
4754 PopEnvironmentStyle();
4755 if (itemizeStack.First())
4756 {
4757 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
4758 delete struc;
4759 delete itemizeStack.First();
4760 }
4761 if (itemizeStack.Number() == 0)
4762 {
4763 TexOutput("\\par\\pard\n");
4764 issuedNewParagraph = 1;
4765 WriteEnvironmentStyles();
4766 }
4767 }
4768 return TRUE;
4769 break;
4770 }
4771 */
4772 case ltDOCUMENTSTYLE:
4773 {
4774 DefaultOnArgument(macroId, arg_no, start);
4775 if (!start && !IsArgOptional())
4776 {
4777 if (MinorDocumentStyleString)
4778 {
4779 if (StringMatch("twoside", MinorDocumentStyleString))
4780 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4781 TexOutput("\\margmirror\\facingp\\sbkodd");
4782 if (StringMatch("twocolumn", MinorDocumentStyleString))
4783 TexOutput("\\cols2");
4784 }
4785 TexOutput("\n");
4786 }
4787 return FALSE;
4788 }
4789 case ltSETHOTSPOTCOLOUR:
4790 case ltSETHOTSPOTCOLOR:
4791 {
4792 if (!start)
4793 {
4794 char *text = GetArgData();
4795 if (strcmp(text, "yes") == 0 || strcmp(text, "on") == 0 || strcmp(text, "ok") == 0)
4796 hotSpotColour = TRUE;
4797 else
4798 hotSpotColour = FALSE;
4799 }
4800 return FALSE;
4801 }
4802 case ltSETTRANSPARENCY:
4803 {
4804 if (!start)
4805 {
4806 char *text = GetArgData();
4807 if (strcmp(text, "yes") == 0 || strcmp(text, "on") == 0 || strcmp(text, "ok") == 0)
4808 bitmapTransparency = TRUE;
4809 else
4810 bitmapTransparency = FALSE;
4811 }
4812 return FALSE;
4813 }
4814 case ltSETHOTSPOTUNDERLINE:
4815 {
4816 if (!start)
4817 {
4818 char *text = GetArgData();
4819 if (strcmp(text, "yes") == 0 || strcmp(text, "on") == 0 || strcmp(text, "ok") == 0)
4820 hotSpotUnderline = TRUE;
4821 else
4822 hotSpotUnderline = FALSE;
4823 }
4824 return FALSE;
4825 }
4826 case ltBIBITEM:
4827 {
4828 if (arg_no == 1 && start)
4829 {
4830 char *citeKey = GetArgData();
4831 TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
4832 if (ref)
4833 {
4834 if (ref->sectionNumber) delete[] ref->sectionNumber;
4835 sprintf(buf, "[%d]", citeCount);
4836 ref->sectionNumber = copystring(buf);
4837 }
4838
4839 TexOutput("\\li260\\fi-260 "); // Indent from 2nd line
4840 sprintf(buf, "{\\b [%d]} ", citeCount);
4841 TexOutput(buf);
4842 citeCount ++;
4843 return FALSE;
4844 }
4845 if (arg_no == 2 && !start)
4846 TexOutput("\\par\\pard\\par\n\n");
4847 return TRUE;
4848 break;
4849 }
4850 case ltTHEBIBLIOGRAPHY:
4851 {
4852 if (start && (arg_no == 1))
4853 {
4854 citeCount = 1;
4855 if (winHelp)
4856 SetCurrentOutputs(Contents, Chapters);
4857
4858 if (!winHelp)
4859 {
4860 fprintf(Chapters, "\\sect\\pgncont\\titlepg\n");
4861
4862 // If a non-custom page style, we generate the header now.
4863 if (PageStyle && (strcmp(PageStyle, "plain") == 0 ||
4864 strcmp(PageStyle, "empty") == 0 ||
4865 strcmp(PageStyle, "headings") == 0))
4866 {
4867 OutputRTFHeaderCommands();
4868 OutputRTFFooterCommands();
4869 }
4870
4871 // Need to reset the current numbering style, or RTF forgets it.
4872 OutputNumberStyle(currentNumberStyle);
4873 SetCurrentOutput(Contents);
4874 }
4875 else
4876 fprintf(Chapters, "\\page\n");
4877
4878 if (winHelp)
4879 fprintf(Contents, "\n{\\uldb %s}", ReferencesNameString);
4880 else
4881 fprintf(Contents, "\\par\n\\pard{\\b %s}", ReferencesNameString);
4882
4883 startedSections = TRUE;
4884
4885 if (winHelp)
4886 fprintf(Chapters, "\n${\\footnote %s}", ReferencesNameString);
4887
4888 char *topicName = "bibliography";
4889
4890 if (winHelp)
4891 fprintf(Contents, "{\\v %s}\\par\\pard\n", topicName);
4892 else
4893 fprintf(Contents, "\\par\\par\\pard\n");
4894
4895 if (winHelp)
4896 {
4897 fprintf(Chapters, "\n#{\\footnote %s}\n", topicName);
4898 fprintf(Chapters, "+{\\footnote %s}\n", GetBrowseString());
4899 fprintf(Chapters, "K{\\footnote {K} %s}\n", ReferencesNameString);
4900 GenerateKeywordsForTopic(topicName);
4901 if (useUpButton)
4902 {
4903 fprintf(Chapters, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
4904 wxFileNameFromPath(FileRoot), "Contents");
4905 }
4906 }
4907
4908 SetCurrentOutput(Chapters);
4909 char *styleCommand = "";
4910 if (!winHelp && useHeadingStyles)
4911 styleCommand = "\\s1";
4912 fprintf(Chapters, "\\pard{%s", (winHelp ? "\\keepn\\sa140\\sb140" : styleCommand));
4913 WriteHeadingStyle(Chapters, 1); fprintf(Chapters, " References\\par\\pard}\n");
4914
4915 return FALSE;
4916 }
4917 return TRUE;
4918 break;
4919 }
4920 case ltINDEX:
4921 {
4922 /*
4923 * In Windows help, all keywords should be at the start of the
4924 * topic, but Latex \index commands can be anywhere in the text.
4925 * So we're going to have to build up lists of keywords for a topic,
4926 * and insert them on the second pass.
4927 *
4928 * In linear RTF, we can embed the index entry now.
4929 *
4930 */
4931 if (start)
4932 {
4933 // char *entry = GetArgData();
4934 char buf[300];
4935 OutputChunkToString(GetArgChunk(), buf);
4936 if (winHelp)
4937 {
4938 if (CurrentTopic)
4939 {
4940 AddKeyWordForTopic(CurrentTopic, buf);
4941 }
4942 }
4943 else GenerateIndexEntry(buf);
4944 }
4945 return FALSE;
4946 break;
4947 }
4948 case ltFCOL:
4949 case ltBCOL:
4950 {
4951 if (start)
4952 {
4953 switch (arg_no)
4954 {
4955 case 1:
4956 {
4957 char *name = GetArgData();
4958 int pos = FindColourPosition(name);
4959 if (pos > -1)
4960 {
4961 sprintf(buf, "{%s%d ", ((macroId == ltFCOL) ? "\\cf" : "\\cb"), pos);
4962 TexOutput(buf);
4963 }
4964 else
4965 {
4966 sprintf(buf, "Could not find colour name %s", name);
4967 OnError(buf);
4968 }
4969 break;
4970 }
4971 case 2:
4972 {
4973 return TRUE;
4974 break;
4975 }
4976 default:
4977 break;
4978 }
4979 }
4980 else
4981 {
4982 if (arg_no == 2) TexOutput("}");
4983 }
4984 return FALSE;
4985 break;
4986 }
4987 case ltLABEL:
4988 {
4989 if (start && !winHelp && useWord)
4990 {
4991 char *s = GetArgData();
4992 // Only insert a bookmark here if it's not just been inserted
4993 // in a section heading.
4994 if ( !CurrentTopic || !(strcmp(CurrentTopic, s) == 0) )
4995 /*
4996 if ( (!CurrentChapterName || !(CurrentChapterName && (strcmp(CurrentChapterName, s) == 0))) &&
4997 (!CurrentSectionName || !(CurrentSectionName && (strcmp(CurrentSectionName, s) == 0))) &&
4998 (!CurrentSubsectionName || !(CurrentSubsectionName && (strcmp(CurrentSubsectionName, s) == 0)))
4999 )
5000 */
5001 {
5002 fprintf(Chapters, "{\\bkmkstart %s}{\\bkmkend %s}", s,s);
5003 }
5004 }
5005 return FALSE;
5006 break;
5007 }
5008 case ltPAGEREF:
5009 {
5010 if (start && useWord && !winHelp)
5011 {
5012 char *s = GetArgData();
5013 fprintf(Chapters, "{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}",
5014 s);
5015 }
5016 return FALSE;
5017 break;
5018 }
5019 case ltPOPREFONLY:
5020 {
5021 if (start)
5022 inPopRefSection = TRUE;
5023 else
5024 inPopRefSection = FALSE;
5025 break;
5026 }
5027 case ltINSERTATLEVEL:
5028 {
5029 // This macro allows you to insert text at a different level
5030 // from the current level, e.g. into the Sections from within a subsubsection.
5031 if (!winHelp & useWord)
5032 return FALSE;
5033 static int currentLevelNo = 1;
5034 static FILE* oldLevelFile = Chapters;
5035 if (start)
5036 {
5037 switch (arg_no)
5038 {
5039 case 1:
5040 {
5041 oldLevelFile = CurrentOutput1;
5042
5043 char *str = GetArgData();
5044 currentLevelNo = atoi(str);
5045 FILE* outputFile;
5046 // TODO: cope with article style (no chapters)
5047 switch (currentLevelNo)
5048 {
5049 case 1:
5050 {
5051 outputFile = Chapters;
5052 break;
5053 }
5054 case 2:
5055 {
5056 outputFile = Sections;
5057 break;
5058 }
5059 case 3:
5060 {
5061 outputFile = Subsections;
5062 break;
5063 }
5064 case 4:
5065 {
5066 outputFile = Subsubsections;
5067 break;
5068 }
5069 default:
5070 {
5071 outputFile = NULL;
5072 break;
5073 }
5074 }
5075 if (outputFile)
5076 CurrentOutput1 = outputFile;
5077 return FALSE;
5078 break;
5079 }
5080 case 2:
5081 {
5082 return TRUE;
5083 break;
5084 }
5085 default:
5086 break;
5087 }
5088 return TRUE;
5089 }
5090 else
5091 {
5092 if (arg_no == 2)
5093 {
5094 CurrentOutput1 = oldLevelFile;
5095 }
5096 return TRUE;
5097 }
5098 break;
5099 }
5100 default:
5101 {
5102 return DefaultOnArgument(macroId, arg_no, start);
5103 break;
5104 }
5105 }
5106 return TRUE;
5107 }
5108
5109 bool RTFGo(void)
5110 {
5111 if (stopRunning)
5112 return FALSE;
5113
5114 // Reset variables
5115 indentLevel = 0;
5116 forbidParindent = 0;
5117 contentsLineSection = NULL;
5118 contentsLineValue = NULL;
5119 descriptionItemArg = NULL;
5120 inTabular = FALSE;
5121 inTable = FALSE;
5122 inFigure = FALSE;
5123 startRows = FALSE;
5124 tableVerticalLineLeft = FALSE;
5125 tableVerticalLineRight = FALSE;
5126 noColumns = 0;
5127 startedSections = FALSE;
5128 inVerbatim = FALSE;
5129 browseId = 0;
5130
5131 if (InputFile && OutputFile)
5132 {
5133 // Do some RTF-specific transformations on all the strings,
5134 // recursively
5135 Text2RTF(GetTopLevelChunk());
5136
5137 Contents = fopen(TmpContentsName, "w");
5138 Chapters = fopen("chapters.rtf", "w");
5139 if (winHelp)
5140 {
5141 Sections = fopen("sections.rtf", "w");
5142 Subsections = fopen("subsections.rtf", "w");
5143 Subsubsections = fopen("subsubsections.rtf", "w");
5144 Popups = fopen("popups.rtf", "w");
5145 if (winHelpContents)
5146 {
5147 WinHelpContentsFile = fopen(WinHelpContentsFileName, "w");
5148 if (WinHelpContentsFile)
5149 fprintf(WinHelpContentsFile, ":Base %s.hlp\n", wxFileNameFromPath(FileRoot));
5150 }
5151
5152 if (!Sections || !Subsections || !Subsubsections || !Popups || (winHelpContents && !WinHelpContentsFile))
5153 {
5154 OnError("Ouch! Could not open temporary file(s) for writing.");
5155 return FALSE;
5156 }
5157 }
5158 if (!Contents || !Chapters)
5159 {
5160 OnError("Ouch! Could not open temporary file(s) for writing.");
5161 return FALSE;
5162 }
5163
5164 if (winHelp)
5165 {
5166 fprintf(Chapters, "\n#{\\footnote Contents}\n");
5167 fprintf(Chapters, "${\\footnote Contents}\n");
5168 fprintf(Chapters, "+{\\footnote %s}\n", GetBrowseString());
5169 fprintf(Chapters, "K{\\footnote {K} %s}\n", ContentsNameString);
5170 fprintf(Chapters, "!{\\footnote DisableButton(\"Up\")}\n");
5171 }
5172 if (!winHelp)
5173 {
5174 fprintf(Chapters, "\\titlepg\n");
5175 fprintf(Contents, "\\par\\pard\\pgnrestart\\sect\\titlepg");
5176 }
5177
5178 // In WinHelp, Contents title takes font of title.
5179 // In linear RTF, same as chapter headings.
5180 fprintf(Contents, "{\\b\\fs%d %s}\\par\\par\\pard\n\n",
5181 (winHelp ? titleFont : chapterFont)*2, ContentsNameString);
5182
5183 // By default, Swiss, 10 point.
5184 fprintf(Chapters, "\\f2\\fs20\n");
5185
5186 SetCurrentOutput(Chapters);
5187
5188 if (stopRunning)
5189 return FALSE;
5190
5191 OnInform("Converting...");
5192
5193 TraverseDocument();
5194
5195 FILE *Header = fopen("header.rtf", "w");
5196 if (!Header)
5197 {
5198 OnError("Ouch! Could not open temporary file header.rtf for writing.");
5199 return FALSE;
5200 }
5201 WriteRTFHeader(Header);
5202 fclose(Header); Header = NULL;
5203
5204 Tex2RTFYield(TRUE);
5205 if (winHelp)
5206 {
5207 // fprintf(Contents, "\\page\n");
5208 fprintf(Chapters, "\\page\n");
5209 fprintf(Sections, "\\page\n");
5210 fprintf(Subsections, "\\page\n");
5211 fprintf(Subsubsections, "\\page\n\n");
5212 fprintf(Popups, "\\page\n}\n");
5213 }
5214
5215 // TexOutput("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n");
5216 if (!winHelp)
5217 TexOutput("}\n");
5218 fclose(Contents); Contents = NULL;
5219 fclose(Chapters); Chapters = NULL;
5220 if (winHelp)
5221 {
5222 fclose(Sections); Sections = NULL;
5223 fclose(Subsections); Subsections = NULL;
5224 fclose(Subsubsections); Subsubsections = NULL;
5225 fclose(Popups); Popups = NULL;
5226 if (winHelpContents)
5227 {
5228 fclose(WinHelpContentsFile); WinHelpContentsFile = NULL;
5229 }
5230 }
5231
5232 if (winHelp)
5233 {
5234 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5235 Tex2RTFYield(TRUE);
5236 wxConcatFiles("tmp1.rtf", "sections.rtf", "tmp2.rtf");
5237 Tex2RTFYield(TRUE);
5238 wxConcatFiles("tmp2.rtf", "subsections.rtf", "tmp3.rtf");
5239 Tex2RTFYield(TRUE);
5240 wxConcatFiles("tmp3.rtf", "subsubsections.rtf", "tmp4.rtf");
5241 Tex2RTFYield(TRUE);
5242 wxConcatFiles("tmp4.rtf", "popups.rtf", OutputFile);
5243 Tex2RTFYield(TRUE);
5244
5245 wxRemoveFile("tmp1.rtf");
5246 wxRemoveFile("tmp2.rtf");
5247 wxRemoveFile("tmp3.rtf");
5248 wxRemoveFile("tmp4.rtf");
5249 }
5250 else
5251 {
5252 wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
5253 Tex2RTFYield(TRUE);
5254 if (wxFileExists(OutputFile))
5255 wxRemoveFile(OutputFile);
5256
5257 char *cwdStr;
5258 cwdStr = wxGetWorkingDirectory();
5259
5260 wxString outputDirStr;
5261 outputDirStr = wxPathOnly(OutputFile);
5262
5263 // Determine if the temp file and the output file are in the same directory,
5264 // and if they are, then just rename the temp file rather than copying
5265 // it, as this is much faster when working with large (multi-megabyte files)
5266 if ((wxStrcmp(outputDirStr.c_str(),"") == 0) || // no path specified on output file
5267 (wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match
5268 {
5269 wxRenameFile("tmp1.rtf", OutputFile);
5270 }
5271 else
5272 {
5273 wxCopyFile("tmp1.rtf", OutputFile);
5274 }
5275 delete [] cwdStr;
5276 Tex2RTFYield(TRUE);
5277 wxRemoveFile("tmp1.rtf");
5278 }
5279
5280 if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
5281
5282 if (!wxRenameFile(TmpContentsName, ContentsName))
5283 {
5284 wxCopyFile(TmpContentsName, ContentsName);
5285 wxRemoveFile(TmpContentsName);
5286 }
5287
5288 wxRemoveFile("chapters.rtf");
5289 wxRemoveFile("header.rtf");
5290
5291 if (winHelp)
5292 {
5293 wxRemoveFile("sections.rtf");
5294 wxRemoveFile("subsections.rtf");
5295 wxRemoveFile("subsubsections.rtf");
5296 wxRemoveFile("popups.rtf");
5297 }
5298 if (winHelp && generateHPJ)
5299 WriteHPJ(OutputFile);
5300 return TRUE;
5301 }
5302 return FALSE;
5303 }