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