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