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