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