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