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