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