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