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