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