1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to Word RTF/WinHelp RTF
4 // Author: Julian Smart
5 // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
40 #if !WXWIN_COMPATIBILITY_2_4
41 static inline wxChar
* copystring(const wxChar
* s
)
42 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
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
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;
57 extern bool startedSections
;
58 extern FILE *Contents
;
59 extern FILE *Chapters
;
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
;
66 extern wxHashTable TexReferences
;
68 // Are we in verbatim mode? If so, format differently.
69 static bool inVerbatim
= false;
71 // We're in a series of PopRef topics, so don't output section headings
72 bool inPopRefSection
= false;
75 static bool hotSpotColour
= true;
76 static bool hotSpotUnderline
= true;
78 // Transparency (WHITE = transparent)
79 static bool bitmapTransparency
= true;
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;
94 // Two-column table dimensions, in twips
95 static int TwoColWidthA
= 1500;
96 static int TwoColWidthB
= 3000;
98 const int PageWidth
= 12242; // 8.25 inches wide for A4
100 // Remember the anchor in a helpref
101 static TexChunk
*helpRefText
= NULL
;
104 * Flag to say we've just issued a \par\pard command, so don't
105 * repeat this unnecessarily.
109 int issuedNewParagraph
= 0;
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;
120 static wxChar
*CurrentChapterName
= NULL
;
121 static wxChar
*CurrentSectionName
= NULL
;
122 static wxChar
*CurrentSubsectionName
= NULL
;
123 static wxChar
*CurrentTopic
= NULL
;
125 static bool InPopups()
127 if (CurrentChapterName
&& (wxStrcmp(CurrentChapterName
, _T("popups")) == 0))
129 if (CurrentSectionName
&& (wxStrcmp(CurrentSectionName
, _T("popups")) == 0))
134 static void SetCurrentTopic(wxChar
*s
)
136 if (CurrentTopic
) delete[] CurrentTopic
;
137 CurrentTopic
= copystring(s
);
140 void SetCurrentChapterName(wxChar
*s
)
142 if (CurrentChapterName
) delete[] CurrentChapterName
;
143 CurrentChapterName
= copystring(s
);
146 void SetCurrentSectionName(wxChar
*s
)
148 if (CurrentSectionName
) delete[] CurrentSectionName
;
149 CurrentSectionName
= copystring(s
);
152 void SetCurrentSubsectionName(wxChar
*s
)
154 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
155 CurrentSubsectionName
= copystring(s
);
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
)
163 wxChar
*parentTopic
= NULL
;
168 parentTopic
= CurrentChapterName
;
173 parentTopic
= CurrentSectionName
;
178 parentTopic
= CurrentSubsectionName
;
188 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
191 texTopic
= new TexTopic
;
192 TopicTable
.Put(parentTopic
, texTopic
);
194 texTopic
->hasChildren
= true;
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.
203 bool ContentsLevels
[5];
205 // Reset below this level (starts from 1)
206 void ResetContentsLevels(int l
)
209 for (i
= l
; i
< 5; i
++)
210 ContentsLevels
[i
] = false;
212 // There are always books on the top level
213 ContentsLevels
[0] = true;
216 // Output a WinHelp section as a keyword, substituting
218 void OutputSectionKeyword(FILE *fd
)
220 OutputCurrentSectionToString(wxTex2RTFBuffer
);
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
] == '{' )
230 wxFprintf(fd
, _T("K{\\footnote {K} "));
231 wxFprintf(fd
, _T("%s"), wxTex2RTFBuffer
);
233 wxFprintf(fd
, _T("}\n"));
236 // Write a line for the .cnt file, if we're doing this.
237 void WriteWinHelpContentsFileLine(wxChar
*topicName
, wxChar
*xitle
, int level
)
239 // First, convert any RTF characters to ASCII
243 // assuming iso-8859-1 here even in Unicode build (FIXME?)
244 while ( (xitle
[s
]!=0)&&(d
<255) )
246 wxChar ch
=wxChar(xitle
[s
]&0xff);
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('Ü'); }
265 // Section (2) becomes level 1 if it's an article.
266 if (DocumentStyle
== LATEX_ARTICLE
)
269 if (level
== 0) // Means we had a Chapter in an article, oops.
272 ResetContentsLevels(level
);
274 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
276 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
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])
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
);
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
);
290 // Then we'll be writing out further pages or books at level + 1...
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;
298 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
303 if (level
== 1 || ContentsLevels
[level
-1])
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;
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
);
317 void SplitIndexEntry(wxChar
*entry
, wxChar
*buf1
, wxChar
*buf2
)
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;
327 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
333 * Output topic index entries in WinHelp RTF
336 void GenerateKeywordsForTopic(wxChar
*topic
)
338 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
342 wxStringList
*list
= texTopic
->keywords
;
345 wxStringListNode
*node
= list
->GetFirst();
348 wxChar
*s
= (wxChar
*)node
->GetData();
350 // Must separate out main entry form subentry (only 1 subentry allowed)
351 wxChar buf1
[100]; wxChar buf2
[100];
352 SplitIndexEntry(s
, buf1
, buf2
);
354 // Check for ':' which messes up index
356 for (i
= 0; i
< wxStrlen(buf1
) ; i
++)
359 for (i
= 0; i
< wxStrlen(buf2
) ; i
++)
363 // {K} is a strange fix to prevent words beginning with K not
364 // being indexed properly
365 TexOutput(_T("K{\\footnote {K} "));
367 if (wxStrlen(buf2
) > 0)
373 TexOutput(_T("}\n"));
374 node
= node
->GetNext();
380 * Output index entry in linear RTF
384 void GenerateIndexEntry(wxChar
*entry
)
388 wxChar buf1
[100]; wxChar buf2
[100];
389 SplitIndexEntry(entry
, buf1
, buf2
);
391 TexOutput(_T("{\\xe\\v {"));
393 if (wxStrlen(buf2
) > 0)
395 TexOutput(_T("\\:"));
403 * Write a suitable RTF header.
407 void WriteColourTable(FILE *fd
)
409 wxFprintf(fd
, _T("{\\colortbl"));
410 wxNode
*node
= ColourTable
.GetFirst();
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();
417 wxFprintf(fd
, _T("}"));
421 * Write heading style
425 void WriteHeadingStyle(FILE *fd
, int heading
)
431 wxFprintf(fd
, _T("\\sb300\\sa260\\f2\\b\\fs%d"), chapterFont
*2);
436 wxFprintf(fd
, _T("\\sb200\\sa240\\f2\\b\\fs%d"), sectionFont
*2);
441 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
446 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
454 void WriteRTFHeader(FILE *fd
)
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}"));
462 wxFprintf(fd
, _T("{\\stylesheet{\\f2\\fs22\\sa200 \\snext0 Normal;}\n"));
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"));
470 wxFprintf(fd
, _T("{\\s10\\ql \\li720\\ri0\\nowidctlpar\\faauto\\rin0\\lin720\\itap0 \\cbpat17\
471 \\f2\\fs20 \\sbasedon0 \\snext24 Code;}\n"));
473 // Table of contents styles
474 wxFprintf(fd
, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n"));
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"));
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"));
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"));
493 void OutputNumberStyle(wxChar
*numberStyle
)
497 if (wxStrcmp(numberStyle
, _T("arabic")) == 0)
499 TexOutput(_T("\\pgndec"));
501 else if (wxStrcmp(numberStyle
, _T("roman")) == 0)
503 TexOutput(_T("\\pgnlcrm"));
505 else if (wxStrcmp(numberStyle
, _T("Roman")) == 0)
507 TexOutput(_T("\\pgnucrm"));
509 else if (wxStrcmp(numberStyle
, _T("alph")) == 0)
511 TexOutput(_T("\\pgnlcltr"));
513 else if (wxStrcmp(numberStyle
, _T("Alph")) == 0)
515 TexOutput(_T("\\pgnucltr"));
521 * Write a Windows help project file
524 bool WriteHPJ(const wxString
& filename
)
526 wxChar hpjFilename
[256];
529 wxStrcpy(hpjFilename
, filename
);
530 StripExtension(hpjFilename
);
531 wxStrcat(hpjFilename
, _T(".hpj"));
533 wxStrcpy(helpFile
, wxFileNameFromPath(filename
));
534 StripExtension(helpFile
);
535 wxStrcpy(rtfFile
, helpFile
);
536 wxStrcat(helpFile
, _T(".hlp"));
537 wxStrcat(rtfFile
, _T(".rtf"));
539 FILE *fd
= wxFopen(hpjFilename
, _T("w"));
543 wxChar
*helpTitle
= winHelpTitle
;
545 helpTitle
= _T("Untitled");
547 wxString thePath
= wxPathOnly(InputFile
);
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"));
555 if (winHelpVersion
> 3)
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
));
564 wxFprintf(fd
, _T("COMPRESS=HIGH\n"));
566 wxFprintf(fd
, _T("\n"));
568 if (winHelpVersion
> 3)
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"));
575 wxFprintf(fd
, _T("[FILES]\n%s\n\n"), rtfFile
);
576 wxFprintf(fd
, _T("[CONFIG]\n"));
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"));
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.
594 void ProcessText2RTF(TexChunk
*chunk
)
596 bool changed
= false;
600 int len
= wxStrlen(chunk
->value
);
603 ch
= chunk
->value
[i
];
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;
616 // If the first character of the next line is ASCII,
617 // put a space in. Implicit in Latex, not in RTF.
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.
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]))))
630 // DOS files have a 13 after the 10
634 if (chunk
->value
[i
] == 13)
641 BigBuffer
[ptr
] = ' ';
644 // Note that the actual ASCII character seen is dealt with in the next
655 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
657 BigBuffer
[ptr
] = '"'; ptr
++;
661 else if (!inVerbatim
&& ch
== '`') // Change ` to '
663 BigBuffer
[ptr
] = 39; ptr
++;
667 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
669 BigBuffer
[ptr
] = '\\'; ptr
++;
670 BigBuffer
[ptr
] = '\\'; ptr
++;
674 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curly bracket
676 BigBuffer
[ptr
] = '\\'; ptr
++;
677 BigBuffer
[ptr
] = ch
; ptr
++;
692 delete[] chunk
->value
;
693 chunk
->value
= copystring(BigBuffer
);
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.
705 void Text2RTF(TexChunk
*chunk
)
708 if (stopRunning
) return;
712 case CHUNK_TYPE_MACRO
:
714 TexMacroDef
*def
= chunk
->def
;
715 if (def
&& def
->ignore
)
718 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
721 wxNode
*node
= chunk
->children
.GetFirst();
724 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
725 Text2RTF(child_chunk
);
726 node
= node
->GetNext();
729 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
736 wxNode
*node
= chunk
->children
.GetFirst();
739 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
740 Text2RTF(child_chunk
);
741 node
= node
->GetNext();
746 case CHUNK_TYPE_STRING
:
749 ProcessText2RTF(chunk
);
760 wxChar browseBuf
[10];
761 static long browseId
= 0;
762 wxChar
*GetBrowseString(void)
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
);
776 * Keeping track of environments to restore the styles after \pard.
777 * Push strings like "\qc" onto stack.
781 void PushEnvironmentStyle(wxChar
*style
)
783 environmentStack
.Add(style
);
786 void PopEnvironmentStyle(void)
788 wxStringListNode
*node
= environmentStack
.GetLast();
791 wxChar
*val
= (wxChar
*)node
->GetData();
797 // Write out the styles, most recent first.
798 void WriteEnvironmentStyles(void)
800 wxStringListNode
*node
= environmentStack
.GetLast();
803 wxChar
*val
= (wxChar
*)node
->GetData();
805 node
= node
->GetNext();
807 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
810 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d"), ParIndent
*20); // Convert points to TWIPS
813 if (environmentStack
.GetCount() > 0 || (ParIndent
> 0))
823 void OutputRTFHeaderCommands(void)
826 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
828 TexOutput(_T("{\\headerl }{\\headerr }"));
830 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
832 TexOutput(_T("{\\headerl }{\\headerr }"));
834 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
837 TexOutput(_T("{\\headerl\\fi0 "));
840 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
842 TexOutput(_T("{\\i \\qr "));
843 if (DocumentStyle
== LATEX_ARTICLE
)
845 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
850 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d: "), chapterNo
);
853 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
854 TexOutput(_T("}\\par\\pard}"));
857 TexOutput(_T("{\\headerr\\fi0 "));
860 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
862 TexOutput(_T("{\\i \\qc "));
863 if (DocumentStyle
== LATEX_ARTICLE
)
865 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
870 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d"), chapterNo
);
873 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
874 TexOutput(_T("}\\par\\pard}"));
878 int oldForbidResetPar
= forbidResetPar
;
881 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
883 TexOutput(_T("{\\headerl\\fi0 "));
886 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
890 if (!CentreHeaderEven
&& !RightHeaderEven
)
891 TexOutput(_T("\\ql "));
892 TraverseChildrenFromChunk(LeftHeaderEven
);
894 if (CentreHeaderEven
)
896 if (!LeftHeaderEven
&& !RightHeaderEven
)
897 TexOutput(_T("\\qc "));
899 TexOutput(_T("\\tab\\tab\\tab "));
900 TraverseChildrenFromChunk(CentreHeaderEven
);
904 if (!LeftHeaderEven
&& !CentreHeaderEven
)
905 TexOutput(_T("\\qr "));
907 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
908 TraverseChildrenFromChunk(RightHeaderEven
);
910 TexOutput(_T("\\par\\pard}"));
913 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
915 TexOutput(_T("{\\headerr\\fi0 "));
918 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
922 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
923 TexOutput(_T("\\ql "));
924 TraverseChildrenFromChunk(LeftHeaderOdd
);
928 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
929 TexOutput(_T("\\qc "));
931 TexOutput(_T("\\tab\\tab\\tab "));
932 TraverseChildrenFromChunk(CentreHeaderOdd
);
936 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
937 TexOutput(_T("\\qr "));
939 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
940 TraverseChildrenFromChunk(RightHeaderOdd
);
942 TexOutput(_T("\\par\\pard}"));
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 }"));
948 forbidResetPar
= oldForbidResetPar
;
952 void OutputRTFFooterCommands(void)
954 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
956 TexOutput(_T("{\\footerl\\fi0 "));
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}"));
963 TexOutput(_T("{\\footerr\\fi0 "));
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}"));
970 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
972 TexOutput(_T("{\\footerl }{\\footerr }"));
974 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
976 TexOutput(_T("{\\footerl }{\\footerr }"));
980 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
982 TexOutput(_T("{\\footerl\\fi0 "));
984 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
987 if (!CentreFooterEven
&& !RightFooterEven
)
988 TexOutput(_T("\\ql "));
989 TraverseChildrenFromChunk(LeftFooterEven
);
991 if (CentreFooterEven
)
993 if (!LeftFooterEven
&& !RightFooterEven
)
994 TexOutput(_T("\\qc "));
996 TexOutput(_T("\\tab\\tab\\tab "));
997 TraverseChildrenFromChunk(CentreFooterEven
);
1001 if (!LeftFooterEven
&& !CentreFooterEven
)
1002 TexOutput(_T("\\qr "));
1004 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1005 TraverseChildrenFromChunk(RightFooterEven
);
1007 TexOutput(_T("\\par\\pard}"));
1010 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1012 TexOutput(_T("{\\footerr\\fi0 "));
1014 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
1017 if (!CentreFooterOdd
&& !RightFooterOdd
)
1018 TexOutput(_T("\\ql "));
1019 TraverseChildrenFromChunk(LeftFooterOdd
);
1021 if (CentreFooterOdd
)
1023 if (!LeftFooterOdd
&& !RightFooterOdd
)
1024 TexOutput(_T("\\qc "));
1026 TexOutput(_T("\\tab\\tab\\tab "));
1027 TraverseChildrenFromChunk(CentreFooterOdd
);
1031 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1032 TexOutput(_T("\\qr "));
1034 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1035 TraverseChildrenFromChunk(RightFooterOdd
);
1037 TexOutput(_T("\\par\\pard}"));
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
)
1044 TexOutput(_T("{\\footerf\\fi0 "));
1047 if (!CentreFooterOdd
&& !RightFooterOdd
)
1048 TexOutput(_T("\\ql "));
1049 TraverseChildrenFromChunk(LeftFooterOdd
);
1051 if (CentreFooterOdd
)
1053 if (!LeftFooterOdd
&& !RightFooterOdd
)
1054 TexOutput(_T("\\qc "));
1056 TexOutput(_T("\\tab\\tab\\tab "));
1057 TraverseChildrenFromChunk(CentreFooterOdd
);
1061 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1062 TexOutput(_T("\\qr "));
1064 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1065 TraverseChildrenFromChunk(RightFooterOdd
);
1067 TexOutput(_T("\\par\\pard}"));
1072 // Called on start/end of macro examination
1073 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1077 wxSnprintf(tmpBuf, sizeof(tmpBuf), _T("%d (%d)"), macroId, (int)start);
1078 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1079 OutputDebugString("\n"); wxYield();
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)))
1092 issuedNewParagraph
= 0;
1100 case ltCHAPTERHEADING
:
1101 case ltCHAPTERHEADINGSTAR
:
1109 subsubsectionNo
= 0;
1112 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1115 wxChar
*topicName
= FindTopicName(GetNextChunk());
1116 SetCurrentChapterName(topicName
);
1118 if (winHelpContents
&& winHelp
&& !InPopups())
1120 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1121 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1123 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1128 wxFprintf(Contents
, _T("\n{\\uldb "));
1129 wxFprintf(Chapters
, _T("\\page"));
1130 wxFprintf(Chapters
, _T("\n${\\footnote "));
1132 SetCurrentOutputs(Contents
, Chapters
);
1134 SetCurrentOutput(Chapters
);
1138 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
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))
1145 OutputRTFHeaderCommands();
1146 OutputRTFFooterCommands();
1149 // Need to reset the current numbering style, or RTF forgets it.
1150 SetCurrentOutput(Chapters
);
1151 OutputNumberStyle(currentNumberStyle
);
1153 SetCurrentOutput(Contents
);
1157 if (macroId
== ltCHAPTER
)
1160 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), chapterNo
);
1162 else if (macroId
== ltCHAPTERHEADING
)
1164 wxFprintf(Contents
, _T("\\par\n\\pard{\\b "));
1166 else SetCurrentOutput(NULL
); // No entry in table of contents
1170 startedSections
= true;
1172 // Output heading to contents page
1175 OutputCurrentSection();
1179 wxFprintf(Contents
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1180 //WriteEnvironmentStyles();
1182 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1183 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1185 // From here, just output to chapter
1186 SetCurrentOutput(Chapters
);
1191 wxFprintf(Chapters
, _T("}\n#{\\footnote %s}\n"), topicName
);
1192 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
1194 OutputSectionKeyword(Chapters
);
1196 GenerateKeywordsForTopic(topicName
);
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"));
1204 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1205 wxFileNameFromPath(FileRoot
), _T("Contents"));
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(" "));
1218 if (macroId
== ltCHAPTER
)
1221 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1222 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1224 wxFprintf(Chapters
, _T("%d. "), chapterNo
);
1228 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1231 OutputCurrentSection();
1232 TexOutput(_T("\\par\\pard}\n"));
1234 issuedNewParagraph
= 1;
1235 WriteEnvironmentStyles();
1241 case ltSECTIONHEADING
:
1242 case ltSECTIONHEADINGSTAR
:
1246 if (DocumentStyle
== LATEX_ARTICLE
)
1247 jumpFrom
= Contents
;
1249 jumpFrom
= Chapters
;
1254 subsubsectionNo
= 0;
1255 if (DocumentStyle
== LATEX_ARTICLE
)
1258 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1261 wxChar
*topicName
= FindTopicName(GetNextChunk());
1262 SetCurrentSectionName(topicName
);
1263 NotifyParentHasChildren(1);
1264 if (winHelpContents
&& winHelp
&& !InPopups())
1266 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1267 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 2);
1269 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
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"));
1280 wxFprintf(jumpFrom
, _T("\n{\\uldb "));
1284 if (DocumentStyle
== LATEX_ARTICLE
)
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))
1292 OutputRTFHeaderCommands();
1293 OutputRTFFooterCommands();
1296 SetCurrentOutput(Contents
);
1298 if (macroId
== ltSECTION
)
1302 if (DocumentStyle
== LATEX_REPORT
)
1303 wxFprintf(Contents
, _T("\n\\pard{\\tab %d.%d\\tab "), chapterNo
, sectionNo
);
1305 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), sectionNo
);
1308 else if (macroId
== ltSECTIONHEADING
)
1312 if (DocumentStyle
== LATEX_REPORT
)
1313 wxFprintf(Contents
, _T("\n\\pard{\\tab ")); //, chapterNo, sectionNo);
1315 wxFprintf(Contents
, _T("\\par\n\\pard{\\b ")); //, sectionNo);
1318 else SetCurrentOutput(NULL
);
1321 if (startedSections
)
1324 wxFprintf(Sections
, _T("\\page\n"));
1326 startedSections
= true;
1329 wxFprintf(Sections
, _T("\n${\\footnote "));
1331 // Output heading to contents page
1333 OutputCurrentSection();
1339 wxFprintf(jumpFrom
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1340 //WriteEnvironmentStyles();
1343 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1345 if (DocumentStyle
== LATEX_REPORT
)
1346 wxFprintf(Contents
, _T("}\\par\\pard\n"));
1348 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1351 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1355 wxFprintf(Sections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1356 wxFprintf(Sections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1357 OutputSectionKeyword(Sections
);
1358 GenerateKeywordsForTopic(topicName
);
1361 if (DocumentStyle
== LATEX_ARTICLE
)
1363 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1364 wxFileNameFromPath(FileRoot
), _T("Contents"));
1366 else if (CurrentChapterName
)
1368 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1369 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1376 wxChar
*styleCommand
= _T("");
1377 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1379 if (DocumentStyle
== LATEX_ARTICLE
)
1380 styleCommand
= _T("\\s1");
1382 styleCommand
= _T("\\s2");
1384 wxChar
*keep
= _T("");
1385 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1386 keep
= _T("\\keepn\\sa140\\sb140");
1388 wxFprintf(winHelp
? Sections
: Chapters
, _T("\\pard{%s%s"),
1389 keep
, styleCommand
);
1391 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1392 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1393 wxFprintf(winHelp
? Sections
: Chapters
, _T(" "));
1397 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1399 if (DocumentStyle
== LATEX_REPORT
)
1402 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo,
1403 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1406 wxFprintf(Chapters
, _T("%d.%d. "), chapterNo
, sectionNo
);
1411 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1412 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1415 wxFprintf(Chapters
, _T("%d. "), sectionNo
);
1420 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1423 OutputCurrentSection();
1424 TexOutput(_T("\\par\\pard}\n"));
1425 // TexOutput(_T("\\par\\pard}\\par\n"));
1427 issuedNewParagraph
= 1;
1428 WriteEnvironmentStyles();
1429 // issuedNewParagraph = 2;
1434 case ltSUBSECTIONSTAR
:
1435 case ltMEMBERSECTION
:
1436 case ltFUNCTIONSECTION
:
1440 if (winHelp
&& !Sections
)
1442 OnError(_T("You cannot have a subsection before a section!"));
1446 subsubsectionNo
= 0;
1448 if (macroId
!= ltSUBSECTIONSTAR
)
1451 wxChar
*topicName
= FindTopicName(GetNextChunk());
1452 SetCurrentSubsectionName(topicName
);
1453 NotifyParentHasChildren(2);
1454 if (winHelpContents
&& winHelp
&& !InPopups())
1456 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1457 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1459 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1463 SetCurrentOutputs(Sections
, Subsections
);
1464 SetCurrentOutputs(Sections
, Subsections
);
1466 wxFprintf(Sections
, _T("\n{\\uldb "));
1470 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1471 (macroId
!= ltFUNCTIONSECTION
))
1473 SetCurrentOutput(Contents
);
1474 if (DocumentStyle
== LATEX_REPORT
)
1475 wxFprintf(Contents
, _T("\n\\pard\\tab\\tab %d.%d.%d\\tab "), chapterNo
, sectionNo
, subsectionNo
);
1477 wxFprintf(Contents
, _T("\n\\pard\\tab %d.%d\\tab "), sectionNo
, subsectionNo
);
1478 } else SetCurrentOutput(NULL
);
1480 if (startedSections
)
1485 wxFprintf(Subsections
, _T("\\page\n"));
1487 // Experimental JACS 2004-02-21
1490 wxFprintf(Chapters
, _T("\\par\n"));
1493 startedSections
= true;
1496 wxFprintf(Subsections
, _T("\n${\\footnote "));
1498 // Output to contents page
1500 OutputCurrentSection();
1506 wxFprintf(Sections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1507 //WriteEnvironmentStyles();
1510 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1511 (macroId
!= ltFUNCTIONSECTION
))
1512 wxFprintf(Contents
, _T("\\par\\pard\n"));
1514 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
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
)
1523 wxFprintf(Subsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1524 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1527 if (!winHelp
&& indexSubsections
&& useWord
)
1529 // Insert index entry for this subsection
1530 TexOutput(_T("{\\xe\\v {"));
1531 OutputCurrentSection();
1532 TexOutput(_T("}}"));
1537 wxChar
*styleCommand
= _T("");
1538 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1540 if (DocumentStyle
== LATEX_ARTICLE
)
1541 styleCommand
= _T("\\s2");
1543 styleCommand
= _T("\\s3");
1545 wxChar
*keep
= _T("");
1546 if (winHelp
&& !InPopups())
1547 keep
= _T("\\keepn\\sa140\\sb140");
1549 wxFprintf(winHelp
? Subsections
: Chapters
, _T("\\pard{%s%s"),
1550 keep
, styleCommand
);
1552 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1553 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1554 wxFprintf(winHelp
? Subsections
: Chapters
, _T(" "));
1558 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1559 (macroId
!= ltFUNCTIONSECTION
))
1561 if (DocumentStyle
== LATEX_REPORT
)
1564 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo,
1565 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1568 wxFprintf(Chapters
, _T("%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
);
1573 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo,
1574 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1577 wxFprintf(Chapters
, _T("%d.%d. "), sectionNo
, subsectionNo
);
1582 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1585 OutputCurrentSection(); // Repeat section header
1587 // Experimental JACS
1588 TexOutput(_T("\\par\\pard}\n"));
1589 // TexOutput(_T("\\par\\pard}\\par\n"));
1591 issuedNewParagraph
= 1;
1592 WriteEnvironmentStyles();
1597 case ltSUBSUBSECTION
:
1598 case ltSUBSUBSECTIONSTAR
:
1602 if (winHelp
&& !Subsections
)
1604 OnError(_T("You cannot have a subsubsection before a subsection!"));
1608 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1611 wxChar
*topicName
= FindTopicName(GetNextChunk());
1612 SetCurrentTopic(topicName
);
1613 NotifyParentHasChildren(3);
1614 if (winHelpContents
&& winHelp
)
1616 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1617 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1619 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1623 SetCurrentOutputs(Subsections
, Subsubsections
);
1624 wxFprintf(Subsections
, _T("\n{\\uldb "));
1628 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1630 if (DocumentStyle
== LATEX_ARTICLE
)
1632 SetCurrentOutput(Contents
);
1633 wxFprintf(Contents
, _T("\n\\tab\\tab %d.%d.%d\\tab "),
1634 sectionNo
, subsectionNo
, subsubsectionNo
);
1637 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1640 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1643 if (startedSections
)
1646 wxFprintf(Subsubsections
, _T("\\page\n"));
1647 // Experimental JACS 2004-02-21
1650 wxFprintf(Chapters
, _T("\\par\n"));
1654 startedSections
= true;
1657 wxFprintf(Subsubsections
, _T("\n${\\footnote "));
1659 // Output header to contents page
1660 OutputCurrentSection();
1664 wxFprintf(Subsections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1665 //WriteEnvironmentStyles();
1667 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1668 wxFprintf(Contents
, _T("\\par\\pard\n"));
1670 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
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
)
1679 wxFprintf(Subsubsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1680 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1683 if (!winHelp
&& indexSubsections
&& useWord
)
1685 // Insert index entry for this subsubsection
1686 TexOutput(_T("{\\xe\\v {"));
1687 OutputCurrentSection();
1688 TexOutput(_T("}}"));
1691 wxChar
*styleCommand
= _T("");
1692 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1694 if (DocumentStyle
== LATEX_ARTICLE
)
1695 styleCommand
= _T("\\s3");
1697 styleCommand
= _T("\\s4");
1699 wxChar
*keep
= _T("");
1701 keep
= _T("\\keepn\\sa140\\sb140");
1703 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T("\\pard{%s%s"),
1704 keep
, styleCommand
);
1706 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1707 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1708 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T(" "));
1712 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1714 if (DocumentStyle
== LATEX_ARTICLE
)
1717 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo, subsubsectionNo,
1718 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1721 wxFprintf(Chapters
, _T("%d.%d.%d. "), sectionNo
, subsectionNo
, subsubsectionNo
);
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
,
1730 wxFprintf(Chapters
, _T("%d.%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1735 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
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;
1753 wxChar
*topicName
= FindTopicName(GetNextChunk());
1754 SetCurrentTopic(topicName
);
1756 TexOutput(_T("\\pard\\par"));
1763 if (winHelp
|| !useWord
)
1765 if (DocumentStyle
!= LATEX_ARTICLE
)
1766 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1768 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1772 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1773 FigureNameString
, topicName
, topicName
);
1780 if (winHelp
|| !useWord
)
1782 if (DocumentStyle
!= LATEX_ARTICLE
)
1783 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1785 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1789 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1790 TableNameString
, topicName
, topicName
);
1794 int n
= (inTable
? tableNo
: figureNo
);
1795 AddTexRef(topicName
, NULL
, NULL
,
1796 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1797 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1800 TexOutput(_T("\\qc{\\b "));
1802 TexOutput(_T("\\ql{\\b "));
1805 OutputCurrentSection();
1807 TexOutput(_T("}\\par\\pard\n"));
1808 WriteEnvironmentStyles();
1815 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1822 TexOutput(_T("}\n"));
1825 TexOutput(_T("K{\\footnote {K} "));
1826 suppressNameDecoration
= true;
1827 TraverseChildrenFromChunk(currentMember
);
1828 suppressNameDecoration
= false;
1829 TexOutput(_T("}\n"));
1831 if (!winHelp
&& useWord
)
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("}}"));
1845 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1852 TexOutput(_T("}\n"));
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"));
1861 if (!winHelp
&& useWord
)
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("}}"));
1875 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1878 TexOutput(_T("{\\b "));
1882 TexOutput(_T("}\n"));
1885 TexOutput(_T("K{\\footnote {K} "));
1886 TraverseChildrenFromChunk(currentMember
);
1887 TexOutput(_T("}\n"));
1889 if (!winHelp
&& useWord
)
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("}}"));
1904 SetCurrentOutput(Chapters
);
1907 case ltTABLEOFCONTENTS
:
1911 if (!winHelp
&& useWord
)
1913 // Insert Word for Windows table of contents
1914 TexOutput(_T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
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
);
1920 wxSnprintf(buf
, sizeof(buf
), _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth
);
1922 // TexOutput(_T("\\sect\\sectd"));
1926 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1932 wxPutc(ch
, Chapters
);
1939 TexOutput(_T("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n"));
1940 OnInform(_T("Run Tex2RTF again to include contents page."));
1949 // TexOutput(_T("{\\b void}"));
1955 TexOutput(_T("{\\scaps HARDY}"));
1961 TexOutput(_T("wxCLIPS"));
1964 case ltSPECIALAMPERSAND
:
1969 TexOutput(_T("\\cell "));
1975 case ltSPECIALTILDE
:
1979 #if 1 // if(inVerbatim)
1987 case ltBACKSLASHCHAR
:
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
++)
1998 currentWidth
+= TableData
[i
].width
;
1999 if (TableData
[i
].rightBorder
)
2000 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
2002 if (TableData
[i
].leftBorder
)
2003 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
2005 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
2008 TexOutput(_T("\\pard\\intbl\n"));
2011 TexOutput(_T("\\line\n"));
2018 TexOutput(_T("\tab "));
2021 case ltRTFSP
: // Explicit space, RTF only
2033 if (indentLevel
> 0)
2035 // Experimental JACS 2004-02-21
2036 TexOutput(_T("\\par\n"));
2037 issuedNewParagraph
= 1;
2038 // TexOutput(_T("\\par\\par\n"));
2039 // issuedNewParagraph = 2;
2043 // Top-level list: issue a new paragraph if we haven't
2045 if (!issuedNewParagraph
)
2047 TexOutput(_T("\\par\\pard"));
2048 WriteEnvironmentStyles();
2049 issuedNewParagraph
= 1;
2051 else issuedNewParagraph
= 0;
2054 TexOutput(_T("\\fi0\n"));
2056 if (macroId
== ltENUMERATE
)
2057 listType
= LATEX_ENUMERATE
;
2058 else if (macroId
== ltITEMIZE
)
2059 listType
= LATEX_ITEMIZE
;
2061 listType
= LATEX_DESCRIPTION
;
2064 wxNode
*node
= itemizeStack
.GetFirst();
2066 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2068 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2069 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2071 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2072 itemizeStack
.Insert(struc
);
2074 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\sa200"), indentSize1
, indentSize2
, indentSize2
);
2075 PushEnvironmentStyle(buf
);
2079 currentItemSep
= 8; // Reset to the default
2081 PopEnvironmentStyle();
2083 if (itemizeStack
.GetFirst())
2085 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2087 delete itemizeStack
.GetFirst();
2089 /* Change 18/7/97 - don't know why we wish to do this
2090 if (itemizeStack.Number() == 0)
2092 OnMacro(ltPAR, 0, true);
2093 OnMacro(ltPAR, 0, false);
2094 issuedNewParagraph = 2;
2106 wxNode
*node
= itemizeStack
.GetFirst();
2108 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2110 int indentSize
= oldIndent
+ TwoColWidthA
;
2112 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2113 itemizeStack
.Insert(struc
);
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
);
2122 PopEnvironmentStyle();
2123 if (itemizeStack
.GetFirst())
2125 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2127 delete itemizeStack
.GetFirst();
2131 TexOutput(_T("\\pard\n"));
2132 WriteEnvironmentStyles();
2134 /* why do we need this? */
2136 TexOutput(_T("\\pard\n"));
2138 if (itemizeStack
.GetCount() == 0)
2140 issuedNewParagraph
= 0;
2141 OnMacro(ltPAR
, 0, true);
2142 OnMacro(ltPAR
, 0, false);
2150 wxNode
*node
= itemizeStack
.GetFirst();
2153 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2156 struc
->currentItem
+= 1;
2157 wxChar indentBuf
[60];
2159 int indentSize1
= struc
->labelIndentation
;
2160 int indentSize2
= struc
->indentation
;
2162 TexOutput(_T("\n"));
2163 if (struc
->currentItem
> 1 && issuedNewParagraph
== 0)
2166 // if (currentItemSep > 0)
2167 // TexOutput(_T("\\par"));
2169 TexOutput(_T("\\par"));
2170 issuedNewParagraph
= 1;
2171 // WriteEnvironmentStyles();
2174 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1
, indentSize2
,
2175 indentSize2
, 20*itemIndentTab
);
2178 switch (struc
->listType
)
2180 case LATEX_ENUMERATE
:
2182 if (descriptionItemArg
)
2184 TexOutput(_T("\\tab{ "));
2185 TraverseChildrenFromChunk(descriptionItemArg
);
2186 TexOutput(_T("}\\tab"));
2187 descriptionItemArg
= NULL
;
2191 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b %d.}\\tab"), struc
->currentItem
);
2192 TexOutput(indentBuf
);
2198 if (descriptionItemArg
)
2200 TexOutput(_T("\\tab{ "));
2201 TraverseChildrenFromChunk(descriptionItemArg
);
2202 TexOutput(_T("}\\tab"));
2203 descriptionItemArg
= NULL
;
2207 if (bulletFile
&& winHelp
)
2209 if (winHelpVersion
> 3) // Transparent bitmap
2210 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmct %s\\}\\tab"), bulletFile
);
2212 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmc %s\\}\\tab"), bulletFile
);
2215 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b o}\\tab"));
2217 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\f1\\'b7}\\tab"));
2218 TexOutput(indentBuf
);
2223 case LATEX_DESCRIPTION
:
2225 if (descriptionItemArg
)
2227 TexOutput(_T("\\tab{\\b "));
2228 TraverseChildrenFromChunk(descriptionItemArg
);
2229 TexOutput(_T("} "));
2230 descriptionItemArg
= NULL
;
2240 case ltTWOCOLITEMRULED
:
2242 wxNode
*node
= itemizeStack
.GetFirst();
2245 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2248 struc
->currentItem
+= 1;
2251 wxNode
*node2
= NULL
;
2252 if (itemizeStack
.GetCount() > 1) // TODO: do I actually mean Nth(0) here??
2253 node2
= itemizeStack
.Item(1);
2255 oldIndent
= ((ItemizeStruc
*)node2
->GetData())->indentation
;
2257 TexOutput(_T("\n"));
2260 if (struc
->currentItem
> 1)
2262 if (currentItemSep
> 0)
2263 TexOutput(_T("\\par"));
2265 // WriteEnvironmentStyles();
2269 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA,
2270 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2272 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA,
2273 TwoColWidthA, TwoColWidthA);
2275 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA
+ oldIndent
,
2276 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2289 if (macroId
== ltVERBATIM
)
2291 if (!issuedNewParagraph
)
2293 TexOutput(_T("\\par\\pard"));
2294 WriteEnvironmentStyles();
2295 issuedNewParagraph
= 1;
2297 else issuedNewParagraph
= 0;
2301 if (macroId
== ltVERBATIM
)
2302 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\s10\\fs20\\li720\\sa0 "));
2304 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\fs20 "));
2310 if (macroId
== ltVERBATIM
)
2312 TexOutput(_T("\\pard\n"));
2313 WriteEnvironmentStyles();
2316 TexOutput(_T("\\par\n"));
2317 issuedNewParagraph
= 1;
2328 TexOutput(_T("\\qc "));
2330 PushEnvironmentStyle(_T("\\qc\\sa200"));
2334 TexOutput(_T("\\par\\pard\n"));
2335 issuedNewParagraph
= 1;
2337 PopEnvironmentStyle();
2338 WriteEnvironmentStyles();
2346 TexOutput(_T("\\ql\\sa200 "));
2348 PushEnvironmentStyle(_T("\\ql"));
2352 TexOutput(_T("\\par\\pard\n"));
2353 issuedNewParagraph
= 1;
2355 PopEnvironmentStyle();
2356 WriteEnvironmentStyles();
2364 TexOutput(_T("\\qr\\sa200 "));
2366 PushEnvironmentStyle(_T("\\qr"));
2370 TexOutput(_T("\\par\\pard\n"));
2371 issuedNewParagraph
= 1;
2373 PopEnvironmentStyle();
2374 WriteEnvironmentStyles();
2379 case ltFOOTNOTESIZE
:
2383 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), smallFont
*2);
2386 else TexOutput(_T("}\n"));
2394 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), tinyFont
*2);
2397 else TexOutput(_T("}\n"));
2404 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), normalFont
*2);
2407 else TexOutput(_T("}\n"));
2414 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), largeFont1
*2);
2417 else TexOutput(_T("}\n"));
2424 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LargeFont2
*2);
2427 else TexOutput(_T("}\n"));
2434 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LARGEFont3
*2);
2437 else TexOutput(_T("}\n"));
2444 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), hugeFont1
*2);
2447 else TexOutput(_T("}\n"));
2454 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HugeFont2
*2);
2457 else TexOutput(_T("}\n"));
2464 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HUGEFont3
*2);
2467 else TexOutput(_T("}\n"));
2476 TexOutput(_T("{\\b "));
2478 else TexOutput(_T("}"));
2485 TexOutput(_T("{\\ul "));
2487 else TexOutput(_T("}"));
2498 TexOutput(_T("{\\i "));
2500 else TexOutput(_T("}"));
2503 // Roman font: do nothing. Should really switch between
2512 TexOutput(_T("{\\plain "));
2514 else TexOutput(_T("}"));
2518 // Medium-weight font. Unbolden...
2523 TexOutput(_T("{\\b0 "));
2525 else TexOutput(_T("}"));
2528 // Upright (un-italic or slant)
2533 TexOutput(_T("{\\i0 "));
2535 else TexOutput(_T("}"));
2544 TexOutput(_T("{\\scaps "));
2546 else TexOutput(_T("}"));
2555 TexOutput(_T("{\\f3 "));
2557 else TexOutput(_T("}"));
2563 TexOutput(_T("\\{"));
2569 TexOutput(_T("\\}"));
2575 TexOutput(_T("\\\\"));
2582 if ( issuedNewParagraph
== 0 )
2584 TexOutput(_T("\\par\\pard"));
2585 issuedNewParagraph
++;
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.
2591 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2593 TexOutput(_T("\\par"));
2594 issuedNewParagraph
++;
2597 WriteEnvironmentStyles();
2599 // 1 is a whole paragraph if ParSkip == 0,
2600 // half a paragraph if ParSkip > 0
2601 else if ( issuedNewParagraph
== 1 )
2603 // Don't need a par at all if we've already had one,
2604 // and ParSkip == 0.
2606 // Extra par if parskip is more than zero (usually looks best.)
2607 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2609 TexOutput(_T("\\par"));
2610 issuedNewParagraph
++;
2613 WriteEnvironmentStyles();
2616 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2618 TexOutput(_T("\\par\\pard"));
2620 // Extra par if parskip is more than zero (usually looks best.)
2621 if (!inTabular && (ParSkip > 0))
2622 TexOutput(_T("\\par"));
2623 WriteEnvironmentStyles();
2627 TexOutput(_T("\n"));
2633 // In Windows Help, no newpages until we've started some chapters or sections
2634 if (!(winHelp
&& !startedSections
))
2636 TexOutput(_T("\\page\n"));
2641 if (start
&& DocumentTitle
)
2643 TexOutput(_T("\\par\\pard"));
2645 TexOutput(_T("\\par"));
2646 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d\\b "), titleFont
*2);
2648 TraverseChildrenFromChunk(DocumentTitle
);
2649 TexOutput(_T("}\\par\\pard\n"));
2654 TexOutput(_T("\\par"));
2655 wxSnprintf(buf
, sizeof(buf
), _T("\\par\\qc{\\fs%d "), authorFont
*2);
2657 TraverseChildrenFromChunk(DocumentAuthor
);
2659 TexOutput(_T("\\par\\pard\n"));
2663 TexOutput(_T("\\par"));
2664 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d "), authorFont
*2);
2666 TraverseChildrenFromChunk(DocumentDate
);
2667 TexOutput(_T("}\\par\\pard\n"));
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
))
2673 TexOutput(_T("{\\header }{\\footer }\n"));
2674 // Not sure about this: we get too many sections.
2675 // TexOutput(_T("\\sect"));
2680 case ltADDCONTENTSLINE
:
2684 if (contentsLineSection
&& contentsLineValue
)
2686 if (wxStrcmp(contentsLineSection
, _T("chapter")) == 0)
2688 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2690 else if (wxStrcmp(contentsLineSection
, _T("section")) == 0)
2692 if (DocumentStyle
!= LATEX_ARTICLE
)
2693 wxFprintf(Contents
, _T("\n\\tab%s\\par\n"), contentsLineValue
);
2695 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2705 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2706 issuedNewParagraph
= 1;
2707 WriteEnvironmentStyles();
2715 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2716 issuedNewParagraph
= 1;
2717 WriteEnvironmentStyles();
2727 case ltNUMBEREDBIBITEM
:
2730 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
2732 TexOutput(_T("\\par\\pard\\par\n\n"));
2739 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2747 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2748 wxSnprintf(buf
, sizeof(buf
), _T("%d"), chapterNo
);
2757 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2758 wxSnprintf(buf
, sizeof(buf
), _T("%d"), sectionNo
);
2765 if (!start
&& !winHelp
)
2767 TexOutput(_T("\\cols2\n"));
2773 if (!start
&& !winHelp
)
2775 TexOutput(_T("\\cols1\n"));
2781 if (start
&& useWord
&& !winHelp
)
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"));
2790 case ltLISTOFFIGURES
:
2792 if (start
&& useWord
&& !winHelp
)
2794 FakeCurrentSection(FiguresNameString
, false);
2795 OnMacro(ltPAR
, 0, true);
2796 OnMacro(ltPAR
, 0, false);
2797 OnMacro(ltPAR
, 0, true);
2798 OnMacro(ltPAR
, 0, false);
2800 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"),
2806 case ltLISTOFTABLES
:
2808 if (start
&& useWord
&& !winHelp
)
2810 FakeCurrentSection(TablesNameString
, false);
2811 OnMacro(ltPAR
, 0, true);
2812 OnMacro(ltPAR
, 0, false);
2813 OnMacro(ltPAR
, 0, true);
2814 OnMacro(ltPAR
, 0, false);
2816 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"),
2824 if (start
) TexOutput(_T("{\\f1\\'61}"));
2827 if (start
) TexOutput(_T("{\\f1\\'62}"));
2830 if (start
) TexOutput(_T("{\\f1\\'63}"));
2833 if (start
) TexOutput(_T("{\\f1\\'64}"));
2837 if (start
) TexOutput(_T("{\\f1\\'65}"));
2840 if (start
) TexOutput(_T("{\\f1\\'7A}"));
2843 if (start
) TexOutput(_T("{\\f1\\'68}"));
2847 if (start
) TexOutput(_T("{\\f1\\'71}"));
2850 if (start
) TexOutput(_T("{\\f1\\'69}"));
2853 if (start
) TexOutput(_T("{\\f1\\'6B}"));
2856 if (start
) TexOutput(_T("{\\f1\\'6C}"));
2859 if (start
) TexOutput(_T("{\\f1\\'6D}"));
2862 if (start
) TexOutput(_T("{\\f1\\'6E}"));
2865 if (start
) TexOutput(_T("{\\f1\\'78}"));
2868 if (start
) TexOutput(_T("{\\f1\\'70}"));
2871 if (start
) TexOutput(_T("{\\f1\\'76}"));
2875 if (start
) TexOutput(_T("{\\f1\\'72}"));
2878 if (start
) TexOutput(_T("{\\f1\\'73}"));
2881 if (start
) TexOutput(_T("{\\f1\\'56}"));
2884 if (start
) TexOutput(_T("{\\f1\\'74}"));
2887 if (start
) TexOutput(_T("{\\f1\\'75}"));
2891 if (start
) TexOutput(_T("{\\f1\\'66}"));
2894 if (start
) TexOutput(_T("{\\f1\\'63}"));
2897 if (start
) TexOutput(_T("{\\f1\\'79}"));
2900 if (start
) TexOutput(_T("{\\f1\\'77}"));
2903 if (start
) TexOutput(_T("{\\f1\\'47}"));
2906 if (start
) TexOutput(_T("{\\f1\\'44}"));
2909 if (start
) TexOutput(_T("{\\f1\\'51}"));
2912 if (start
) TexOutput(_T("{\\f1\\'4C}"));
2915 if (start
) TexOutput(_T("{\\f1\\'58}"));
2918 if (start
) TexOutput(_T("{\\f1\\'50}"));
2921 if (start
) TexOutput(_T("{\\f1\\'53}"));
2924 if (start
) TexOutput(_T("{\\f1\\'54}"));
2927 if (start
) TexOutput(_T("{\\f1\\'46}"));
2930 if (start
) TexOutput(_T("{\\f1\\'59}"));
2933 if (start
) TexOutput(_T("{\\f1\\'57}"));
2935 // Binary operation symbols
2938 if (start
) TexOutput(_T("{\\f1\\'A3}"));
2941 if (start
) TexOutput(_T("<<"));
2944 if (start
) TexOutput(_T("{\\f1\\'CC}"));
2947 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2950 if (start
) TexOutput(_T("{\\f1\\'CE}"));
2954 if (start
) TexOutput(_T("{\\f1\\'B3}"));
2957 if (start
) TexOutput(_T(">>"));
2960 if (start
) TexOutput(_T("{\\f1\\'C9}"));
2963 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2966 if (start
) TexOutput(_T("{\\f1\\'27}"));
2969 if (start
) TexOutput(_T("{\\f1\\'5E}"));
2972 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2975 if (start
) TexOutput(_T("{\\f1\\'BB}"));
2978 if (start
) TexOutput(_T("{\\f1\\'40}"));
2981 if (start
) TexOutput(_T("{\\f1\\'BA}"));
2984 if (start
) TexOutput(_T("{\\f1\\'B5}"));
2987 if (start
) TexOutput(_T("{\\f1\\'7E}"));
2990 if (start
) TexOutput(_T("{\\f4\\'4A}"));
2993 if (start
) TexOutput(_T("{\\f4\\'4C}"));
2996 if (start
) TexOutput(_T("|"));
2999 // Negated relation symbols
3001 if (start
) TexOutput(_T("{\\f1\\'B9}"));
3004 if (start
) TexOutput(_T("{\\f1\\'CF}"));
3007 if (start
) TexOutput(_T("{\\f1\\'CB}"));
3012 if (start
) TexOutput(_T("{\\f1\\'AC}"));
3015 if (start
) TexOutput(_T("{\\f1\\'DC}"));
3018 if (start
) TexOutput(_T("{\\f1\\'AE}"));
3021 if (start
) TexOutput(_T("{\\f1\\'DE}"));
3023 case ltLEFTRIGHTARROW
:
3024 if (start
) TexOutput(_T("{\\f1\\'AB}"));
3026 case ltLEFTRIGHTARROW2
:
3027 if (start
) TexOutput(_T("{\\f1\\'DB}"));
3030 if (start
) TexOutput(_T("{\\f1\\'AD}"));
3033 if (start
) TexOutput(_T("{\\f1\\'DD}"));
3036 if (start
) TexOutput(_T("{\\f1\\'AF}"));
3039 if (start
) TexOutput(_T("{\\f1\\'DF}"));
3042 // Miscellaneous symbols
3044 if (start
) TexOutput(_T("{\\f1\\'CO}"));
3047 if (start
) TexOutput(_T("{\\f1\\'C3}"));
3050 if (start
) TexOutput(_T("{\\f1\\'C2}"));
3053 if (start
) TexOutput(_T("{\\f1\\'C1}"));
3056 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3059 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3062 if (start
) TexOutput(_T("{\\f1\\'D6}"));
3065 if (start
) TexOutput(_T("{\\f1\\'B6}"));
3068 if (start
) TexOutput(_T("{\\f1\\'5E}"));
3071 if (start
) TexOutput(_T("{\\f1\\'22}"));
3074 if (start
) TexOutput(_T("{\\f1\\'24}"));
3077 if (start
) TexOutput(_T("{\\f1\\'D8}"));
3080 if (start
) TexOutput(_T("{\\f1\\'23}"));
3083 if (start
) TexOutput(_T("{\\f1\\'D0}"));
3086 if (start
) TexOutput(_T("{\\f5\\'73}"));
3089 if (start
) TexOutput(_T("{\\f5\\'A8}"));
3092 if (start
) TexOutput(_T("{\\f5\\'A9}"));
3095 if (start
) TexOutput(_T("{\\f5\\'AA}"));
3098 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3101 if (start
) TexOutput(_T("{\\f1\\'A5}"));
3104 if (start
) TexOutput(_T("{\\f0\\'A9}"));
3107 if (start
) TexOutput(_T("{\\f0\\'AE}"));
3110 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3113 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3116 if (start
) TexOutput(_T("{\\f1\\'B4}"));
3119 if (start
) TexOutput(_T("{\\f1\\'B8}"));
3122 if (start
) TexOutput(_T("{\\f1\\'D7}"));
3125 if (start
) TexOutput(_T("{\\f1\\'2A}"));
3128 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3131 if (start
) TexOutput(_T("{\\f1\\'C7}"));
3134 if (start
) TexOutput(_T("{\\f1\\'C8}"));
3137 if (start
) TexOutput(_T("{\\f1\\'DA}"));
3140 if (start
) TexOutput(_T("{\\f1\\'D9}"));
3143 if (start
) TexOutput(_T("{\\f1\\'B0}"));
3146 if (start
) TexOutput(_T("{\\f1\\'B7}"));
3149 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3152 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3155 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3157 case ltBIGTRIANGLEDOWN
:
3158 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3161 if (start
) TexOutput(_T("{\\f1\\'C5}"));
3164 if (start
) TexOutput(_T("{\\f1\\'C4}"));
3167 if (start
) TexOutput(_T("{\\'DF}"));
3171 if (start
) inFigure
= true;
3172 else inFigure
= false;
3177 if (start
) inTable
= true;
3178 else inTable
= false;
3183 DefaultOnMacro(macroId
, no_args
, start
);
3189 // Called on start/end of argument examination
3190 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3197 case ltCHAPTERHEADING
:
3200 case ltSECTIONHEADING
:
3202 case ltSUBSECTIONSTAR
:
3203 case ltSUBSUBSECTION
:
3204 case ltSUBSUBSECTIONSTAR
:
3206 case ltMEMBERSECTION
:
3207 case ltFUNCTIONSECTION
:
3211 if (!start
&& (arg_no
== 1))
3212 currentSection
= GetArgChunk();
3217 if (start
&& (arg_no
== 1))
3218 TexOutput(_T("\\pard\\li600\\fi-600{\\b "));
3220 if (!start
&& (arg_no
== 1))
3221 TexOutput(_T("} "));
3223 if (start
&& (arg_no
== 2))
3225 if (!suppressNameDecoration
) TexOutput(_T("{\\b "));
3226 currentMember
= GetArgChunk();
3228 if (!start
&& (arg_no
== 2))
3230 if (!suppressNameDecoration
) TexOutput(_T("}"));
3233 if (start
&& (arg_no
== 3))
3235 if (!start
&& (arg_no
== 3))
3237 // TexOutput(_T(")\\li0\\fi0"));
3238 // TexOutput(_T(")\\par\\pard\\li0\\fi0"));
3239 // issuedNewParagraph = 1;
3241 WriteEnvironmentStyles();
3247 if (start
&& (arg_no
== 1))
3248 TexOutput(_T("\\pard\\li260\\fi-260{\\b "));
3249 if (!start
&& (arg_no
== 1))
3250 TexOutput(_T("} "));
3252 if (start
&& (arg_no
== 2))
3254 if (!suppressNameDecoration
) TexOutput(_T("({\\b "));
3255 currentMember
= GetArgChunk();
3257 if (!start
&& (arg_no
== 2))
3259 if (!suppressNameDecoration
) TexOutput(_T("}"));
3262 if (!start
&& (arg_no
== 3))
3264 TexOutput(_T(")\\li0\\fi0"));
3265 WriteEnvironmentStyles();
3271 if (start
&& (arg_no
== 1))
3272 TexOutput(_T("\\pard\\li260\\fi-260"));
3274 if (!start
&& (arg_no
== 1))
3277 if (start
&& (arg_no
== 2))
3278 TexOutput(_T("(*"));
3279 if (!start
&& (arg_no
== 2))
3282 if (start
&& (arg_no
== 2))
3283 currentMember
= GetArgChunk();
3285 if (start
&& (arg_no
== 3))
3287 if (!start
&& (arg_no
== 3))
3289 TexOutput(_T(")\\li0\\fi0"));
3290 WriteEnvironmentStyles();
3296 if (start
&& (arg_no
== 1))
3297 TexOutput(_T("{\\b "));
3298 if (!start
&& (arg_no
== 1))
3300 if (start
&& (arg_no
== 2))
3302 TexOutput(_T("{\\i "));
3304 if (!start
&& (arg_no
== 2))
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))
3318 TexOutput(_T("{\\i "));
3320 if (!start
&& (arg_no
== 2))
3328 if (!start
&& (arg_no
== 1))
3331 if (start
&& (arg_no
== 2))
3332 currentMember
= GetArgChunk();
3341 wxChar
*refName
= GetArgData();
3342 if (winHelp
|| !useWord
)
3346 TexRef
*texRef
= FindReference(refName
);
3349 sec
= texRef
->sectionNumber
;
3359 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
3371 if ((GetNoArgs() - arg_no
) == 1)
3374 TexOutput(_T("{\\uldb "));
3378 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3382 TexOutput(_T("{\\v "));
3384 // Remove green colour/underlining if specified
3385 if (!hotSpotUnderline
&& !hotSpotColour
)
3387 else if (!hotSpotColour
)
3390 else TexOutput(_T("}"));
3393 else // If a linear document, must resolve the references ourselves
3395 if ((GetNoArgs() - arg_no
) == 1)
3397 // In a linear document we display the anchor text in italic plus
3400 TexOutput(_T("{\\i "));
3405 helpRefText
= GetArgChunk();
3409 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3411 if (macroId
!= ltHELPREFN
)
3413 wxChar
*refName
= GetArgData();
3414 TexRef
*texRef
= NULL
;
3416 texRef
= FindReference(refName
);
3419 if (texRef
|| !ignoreBadRefs
)
3420 TexOutput(_T(" ("));
3423 if (texRef
|| !ignoreBadRefs
)
3427 TexOutput(_T("p. "));
3428 TexOutput(_T("{\\field{\\*\\fldinst PAGEREF "));
3430 TexOutput(_T(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"));
3434 // Only print section name if we're not in Word mode,
3435 // so can't do page references
3438 TexOutput(texRef
->sectionName
);
3440 TexOutput(texRef
->sectionNumber
);
3445 TexOutput(_T("??"));
3446 wxSnprintf(buf
, sizeof(buf
), _T("Warning: unresolved reference '%s'"), refName
);
3452 else TexOutput(_T("??"));
3456 if (texRef
|| !ignoreBadRefs
)
3471 else if (arg_no
== 2)
3476 TexOutput(_T(" ({\\f3 "));
3480 TexOutput(_T("})"));
3491 if ((GetNoArgs() - arg_no
) == 1)
3494 TexOutput(_T("{\\ul "));
3498 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3502 TexOutput(_T("{\\v "));
3504 // Remove green colour/underlining if specified
3505 if (!hotSpotUnderline
&& !hotSpotColour
)
3507 else if (!hotSpotColour
)
3510 else TexOutput(_T("}"));
3513 else // A linear document...
3515 if ((GetNoArgs() - arg_no
) == 1)
3517 // In a linear document we just display the anchor text in italic
3519 TexOutput(_T("{\\i "));
3528 case ltADDCONTENTSLINE
:
3530 if (start
&& !winHelp
)
3533 contentsLineSection
= copystring(GetArgData());
3534 else if (arg_no
== 3)
3535 contentsLineValue
= copystring(GetArgData());
3549 static int imageWidth
= 0;
3550 static int imageHeight
= 0;
3552 if (start
&& (arg_no
== 1))
3554 wxChar
*imageDimensions
= copystring(GetArgData());
3556 // imageWidth - Convert points to TWIPS (1 twip = 1/20th of point)
3557 wxStringTokenizer
tok(imageDimensions
, _T(";:"), wxTOKEN_STRTOK
);
3558 if(tok
.HasMoreTokens())
3560 wxString token
= tok
.GetNextToken();
3561 imageWidth
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3568 // imageHeight - Convert points to TWIPS (1 twip = 1/20th of point)
3569 if(tok
.HasMoreTokens())
3571 wxString token
= tok
.GetNextToken();
3572 imageHeight
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3579 if (imageDimensions
) // glt
3580 delete [] imageDimensions
;
3583 else if (start
&& (arg_no
== 2 ))
3585 wxChar
*filename
= copystring(GetArgData());
3586 wxString f
= _T("");
3587 if ((winHelp
|| (wxStrcmp(bitmapMethod
, _T("includepicture")) == 0) || (wxStrcmp(bitmapMethod
, _T("import")) == 0)) && useWord
)
3589 if (f
== _T("")) // Try for a .shg (segmented hypergraphics file)
3591 wxStrcpy(buf
, filename
);
3592 StripExtension(buf
);
3593 wxStrcat(buf
, _T(".shg"));
3594 f
= TexPathList
.FindValidPath(buf
);
3596 if (f
== _T("")) // Try for a .bmp
3598 wxStrcpy(buf
, filename
);
3599 StripExtension(buf
);
3600 wxStrcat(buf
, _T(".bmp"));
3601 f
= TexPathList
.FindValidPath(buf
);
3603 if (f
== _T("")) // Try for a metafile instead
3605 wxStrcpy(buf
, filename
);
3606 StripExtension(buf
);
3607 wxStrcat(buf
, _T(".wmf"));
3608 f
= TexPathList
.FindValidPath(buf
);
3614 if (bitmapTransparency
&& (winHelpVersion
> 3))
3615 TexOutput(_T("\\{bmct "));
3617 TexOutput(_T("\\{bmc "));
3618 wxString str
= wxFileNameFromPath(f
);
3619 TexOutput((wxChar
*) (const wxChar
*) str
);
3620 TexOutput(_T("\\}"));
3624 // Microsoft Word method
3625 if (wxStrcmp(bitmapMethod
, _T("import")) == 0)
3626 TexOutput(_T("{\\field{\\*\\fldinst IMPORT "));
3628 TexOutput(_T("{\\field{\\*\\fldinst INCLUDEPICTURE "));
3630 // Full path appears not to be valid!
3631 wxString str
= wxFileNameFromPath(f
);
3632 TexOutput((wxChar
*)(const wxChar
*) str
);
3634 int len = wxStrlen(f);
3635 wxChar smallBuf[2]; smallBuf[1] = 0;
3636 for (int i = 0; i < len; i++)
3639 TexOutput(smallBuf);
3640 if (smallBuf[0] == '\\')
3641 TexOutput(smallBuf);
3644 TexOutput(_T("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}"));
3649 TexOutput(_T("[No BMP or WMF for image file "));
3650 TexOutput(filename
);
3652 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3655 if (filename
) // glt
3660 if (f
== _T("")) // Try for a .bmp
3662 wxStrcpy(buf
, filename
);
3663 StripExtension(buf
);
3664 wxStrcat(buf
, _T(".bmp"));
3665 f
= TexPathList
.FindValidPath(buf
);
3669 FILE *fd
= wxFopen(f
, _T("rb"));
3670 if (OutputBitmapHeader(fd
, winHelp
))
3671 OutputBitmapData(fd
);
3674 wxSnprintf(buf
, sizeof(buf
), _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f
.c_str());
3679 else // Try for a metafile instead
3682 wxStrcpy(buf
, filename
);
3683 StripExtension(buf
);
3684 wxStrcat(buf
, _T(".wmf"));
3685 f
= TexPathList
.FindValidPath(buf
);
3688 // HFILE handle = _lopen(f, READ);
3689 FILE *fd
= wxFopen(f
, _T("rb"));
3690 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3692 OutputMetafileData(fd
);
3696 wxSnprintf(buf
, sizeof(buf
), _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f
.c_str());
3704 TexOutput(_T("[No BMP or WMF for image file "));
3705 TexOutput(filename
);
3707 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3720 case ltSUPERTABULAR
:
3726 currentRowNumber
= 0;
3729 tableVerticalLineLeft
= false;
3730 tableVerticalLineRight
= false;
3731 int currentWidth
= 0;
3733 wxChar
*alignString
= copystring(GetArgData());
3734 ParseTableArgument(alignString
);
3736 // TexOutput(_T("\\trowd\\trgaph108\\trleft-108"));
3737 TexOutput(_T("\\trowd\\trgaph108"));
3739 // Write the first row formatting for compatibility
3740 // with standard Latex
3741 if (compatibilityMode
)
3743 for (int i
= 0; i
< noColumns
; i
++)
3745 currentWidth
+= TableData
[i
].width
;
3746 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
3749 TexOutput(_T("\\pard\\intbl\n"));
3751 delete[] alignString
;
3756 else if (arg_no
== 2 && !start
)
3758 TexOutput(_T("\\pard\n"));
3759 WriteEnvironmentStyles();
3770 TexOutput(_T("\\li360\n"));
3772 PushEnvironmentStyle(_T("\\li360\\sa200"));
3777 PopEnvironmentStyle();
3778 OnMacro(ltPAR
, 0, true);
3779 OnMacro(ltPAR
, 0, false);
3787 TexOutput(_T("\\li360\n"));
3788 PushEnvironmentStyle(_T("\\li360\\sa200"));
3792 PopEnvironmentStyle();
3793 OnMacro(ltPAR
, 0, true);
3794 OnMacro(ltPAR
, 0, false);
3806 wxSnprintf(buf
, sizeof(buf
), _T("\\sa200\\box\\trgaph108%s\n"), ((macroId
== ltNORMALBOXD
) ? _T("\\brdrdb") : _T("\\brdrs")));
3808 PushEnvironmentStyle(buf
);
3812 PopEnvironmentStyle();
3813 OnMacro(ltPAR
, 0, true);
3814 OnMacro(ltPAR
, 0, false);
3818 case ltHELPFONTSIZE
:
3822 wxChar
*data
= GetArgData();
3823 if (wxStrcmp(data
, _T("10")) == 0)
3825 else if (wxStrcmp(data
, _T("11")) == 0)
3827 else if (wxStrcmp(data
, _T("12")) == 0)
3829 wxSnprintf(buf
, sizeof(buf
), _T("\\fs%d\n"), normalFont
*2);
3836 case ltHELPFONTFAMILY
:
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"));
3854 if (start
&& arg_no
== 1)
3856 wxChar
*data
= GetArgData();
3857 ParIndent
= ParseUnitArgument(data
);
3858 if (ParIndent
== 0 || forbidParindent
== 0)
3860 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d\n"), ParIndent
*20);
3869 if (start
&& IsArgOptional())
3871 descriptionItemArg
= GetArgChunk();
3877 case ltTWOCOLITEMRULED
:
3884 TexOutput(_T("\\tab "));
3891 if (macroId
== ltTWOCOLITEMRULED
)
3892 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
3893 TexOutput(_T("\\par\\pard\n"));
3894 issuedNewParagraph
= 1;
3895 WriteEnvironmentStyles();
3906 case ltACCENT_GRAVE
:
3910 wxChar
*val
= GetArgData();
3916 TexOutput(_T("\\'e0"));
3919 TexOutput(_T("\\'e8"));
3922 TexOutput(_T("\\'ec"));
3925 TexOutput(_T("\\'f2"));
3928 TexOutput(_T("\\'f9"));
3931 TexOutput(_T("\\'c0"));
3934 TexOutput(_T("\\'c8"));
3937 TexOutput(_T("\\'cc"));
3940 TexOutput(_T("\\'d2"));
3943 TexOutput(_T("\\'d9"));
3952 case ltACCENT_ACUTE
:
3956 wxChar
*val
= GetArgData();
3962 TexOutput(_T("\\'e1"));
3965 TexOutput(_T("\\'e9"));
3968 TexOutput(_T("\\'ed"));
3971 TexOutput(_T("\\'f3"));
3974 TexOutput(_T("\\'fa"));
3977 TexOutput(_T("\\'fd"));
3980 TexOutput(_T("\\'c1"));
3983 TexOutput(_T("\\'c9"));
3986 TexOutput(_T("\\'cd"));
3989 TexOutput(_T("\\'d3"));
3992 TexOutput(_T("\\'da"));
3995 TexOutput(_T("\\'dd"));
4004 case ltACCENT_CARET
:
4008 wxChar
*val
= GetArgData();
4014 TexOutput(_T("\\'e2"));
4017 TexOutput(_T("\\'ea"));
4020 TexOutput(_T("\\'ee"));
4023 TexOutput(_T("\\'f4"));
4026 TexOutput(_T("\\'fb"));
4029 TexOutput(_T("\\'c2"));
4032 TexOutput(_T("\\'ca"));
4035 TexOutput(_T("\\'ce"));
4038 TexOutput(_T("\\'d4"));
4041 TexOutput(_T("\\'db"));
4050 case ltACCENT_TILDE
:
4054 wxChar
*val
= GetArgData();
4060 TexOutput(_T("\\'e3"));
4066 TexOutput(_T("\\'f1"));
4069 TexOutput(_T("\\'f5"));
4072 TexOutput(_T("\\'c3"));
4075 TexOutput(_T("\\'d1"));
4078 TexOutput(_T("\\'d5"));
4087 case ltACCENT_UMLAUT
:
4091 wxChar
*val
= GetArgData();
4097 TexOutput(_T("\\'e4"));
4100 TexOutput(_T("\\'eb"));
4103 TexOutput(_T("\\'ef"));
4106 TexOutput(_T("\\'f6"));
4109 TexOutput(_T("\\'fc"));
4112 TexOutput(_T("\\'df"));
4115 TexOutput(_T("\\'ff"));
4118 TexOutput(_T("\\'c4"));
4121 TexOutput(_T("\\'cb"));
4124 TexOutput(_T("\\'cf"));
4127 TexOutput(_T("\\'d6"));
4130 TexOutput(_T("\\'dc"));
4133 TexOutput(_T("\\'df"));
4146 wxChar
*val
= GetArgData();
4152 TexOutput(_T("\\'e5"));
4155 TexOutput(_T("\\'c5"));
4164 case ltACCENT_CADILLA
:
4168 wxChar
*val
= GetArgData();
4174 TexOutput(_T("\\'e7"));
4177 TexOutput(_T("\\'c7"));
4188 static wxChar
*helpTopic
= NULL
;
4189 static FILE *savedOutput
= NULL
;
4196 OnInform(_T("Consider using \\footnotepopup instead of \\footnote."));
4199 wxSnprintf(footBuf
, sizeof(footBuf
), _T("(%d)"), footnoteCount
);
4201 TexOutput(_T(" {\\ul "));
4204 helpTopic
= FindTopicName(NULL
);
4205 TexOutput(_T("{\\v "));
4207 // Remove green colour/underlining if specified
4208 if (!hotSpotUnderline
&& !hotSpotColour
)
4210 else if (!hotSpotColour
)
4213 TexOutput(helpTopic
);
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
);
4225 SetCurrentOutput(savedOutput
);
4235 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4239 TexOutput(_T("}}"), true);
4244 case ltFOOTNOTEPOPUP
:
4246 static wxChar
*helpTopic
= NULL
;
4247 static FILE *savedOutput
= NULL
;
4254 TexOutput(_T("{\\ul "));
4262 else if (arg_no
== 2)
4266 helpTopic
= FindTopicName(NULL
);
4267 TexOutput(_T("{\\v "));
4269 // Remove green colour/underlining if specified
4270 if (!hotSpotUnderline
&& !hotSpotColour
)
4272 else if (!hotSpotColour
)
4275 TexOutput(helpTopic
);
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
);
4287 SetCurrentOutput(savedOutput
);
4298 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4302 TexOutput(_T("}}"), true);
4310 if (start
&& (arg_no
== 1))
4322 if (winHelp
) return false;
4328 LeftHeaderEven
= GetArgChunk();
4329 if (wxStrlen(GetArgData(LeftHeaderEven
)) == 0)
4330 LeftHeaderEven
= NULL
;
4333 CentreHeaderEven
= GetArgChunk();
4334 if (wxStrlen(GetArgData(CentreHeaderEven
)) == 0)
4335 CentreHeaderEven
= NULL
;
4338 RightHeaderEven
= GetArgChunk();
4339 if (wxStrlen(GetArgData(RightHeaderEven
)) == 0)
4340 RightHeaderEven
= NULL
;
4343 LeftHeaderOdd
= GetArgChunk();
4344 if (wxStrlen(GetArgData(LeftHeaderOdd
)) == 0)
4345 LeftHeaderOdd
= NULL
;
4348 CentreHeaderOdd
= GetArgChunk();
4349 if (wxStrlen(GetArgData(CentreHeaderOdd
)) == 0)
4350 CentreHeaderOdd
= NULL
;
4353 RightHeaderOdd
= GetArgChunk();
4354 if (wxStrlen(GetArgData(RightHeaderOdd
)) == 0)
4355 RightHeaderOdd
= NULL
;
4356 OutputRTFHeaderCommands();
4371 if (winHelp
) return false;
4377 LeftFooterEven
= GetArgChunk();
4378 if (wxStrlen(GetArgData(LeftFooterEven
)) == 0)
4379 LeftFooterEven
= NULL
;
4382 CentreFooterEven
= GetArgChunk();
4383 if (wxStrlen(GetArgData(CentreFooterEven
)) == 0)
4384 CentreFooterEven
= NULL
;
4387 RightFooterEven
= GetArgChunk();
4388 if (wxStrlen(GetArgData(RightFooterEven
)) == 0)
4389 RightFooterEven
= NULL
;
4392 LeftFooterOdd
= GetArgChunk();
4393 if (wxStrlen(GetArgData(LeftFooterOdd
)) == 0)
4394 LeftFooterOdd
= NULL
;
4397 CentreFooterOdd
= GetArgChunk();
4398 if (wxStrlen(GetArgData(CentreFooterOdd
)) == 0)
4399 CentreFooterOdd
= NULL
;
4402 RightFooterOdd
= GetArgChunk();
4403 if (wxStrlen(GetArgData(RightFooterOdd
)) == 0)
4404 RightFooterOdd
= NULL
;
4405 OutputRTFFooterCommands();
4415 if (winHelp
) return false;
4416 // Fake a SetHeader command
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."));
4427 RTFOnArgument(ltSETHEADER
, 4, start
);
4429 OutputRTFHeaderCommands();
4434 if (winHelp
) return false;
4435 // Fake a SetHeader command
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."));
4450 return RTFOnArgument(ltSETHEADER
, 1, start
);
4454 RTFOnArgument(ltSETHEADER
, 4, start
);
4456 OutputRTFHeaderCommands();
4462 case ltPAGENUMBERING
:
4469 if (winHelp
) return false;
4472 TexOutput(_T("\\pgnrestart"));
4473 wxChar
*data
= GetArgData();
4474 if (currentNumberStyle
) delete[] currentNumberStyle
;
4475 currentNumberStyle
= copystring(data
);
4476 OutputNumberStyle(currentNumberStyle
);
4478 TexOutput(_T("\n"));
4484 if (winHelp
) return false;
4493 wxChar
*val
= GetArgData();
4494 currentItemSep
= ParseUnitArgument(val
);
4499 case ltEVENSIDEMARGIN
:
4503 case ltODDSIDEMARGIN
:
4507 wxChar
*val
= GetArgData();
4508 int twips
= (int)(20*ParseUnitArgument(val
));
4509 // Add an inch since in LaTeX it's specified minus an inch
4511 CurrentLeftMarginOdd
= twips
;
4512 wxSnprintf(buf
, sizeof(buf
), _T("\\margl%d\n"), twips
);
4515 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4519 case ltMARGINPARWIDTH
:
4523 wxChar
*val
= GetArgData();
4524 int twips
= (int)(20*ParseUnitArgument(val
));
4525 CurrentMarginParWidth
= twips
;
4529 case ltMARGINPARSEP
:
4533 wxChar
*val
= GetArgData();
4534 int twips
= (int)(20*ParseUnitArgument(val
));
4535 CurrentMarginParSep
= twips
;
4536 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4544 wxChar
*val
= GetArgData();
4545 int twips
= (int)(20*ParseUnitArgument(val
));
4546 CurrentTextWidth
= twips
;
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
);
4558 case ltMARGINPARODD
:
4564 TexOutput(_T("\\sa200\\box\n"));
4565 PushEnvironmentStyle(_T("\\sa200\\box"));
4569 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4578 TexOutput(_T("\\par\\pard\n"));
4579 PopEnvironmentStyle();
4580 WriteEnvironmentStyles();
4583 TexOutput(_T("\\par\\pard\n"));
4584 issuedNewParagraph
= 1;
4588 case ltMARGINPAREVEN
:
4594 TexOutput(_T("\\sa200\\box\n"));
4595 PushEnvironmentStyle(_T("\\sa200\\box"));
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
);
4610 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4620 TexOutput(_T("\\par\\pard\n"));
4621 PopEnvironmentStyle();
4622 WriteEnvironmentStyles();
4625 issuedNewParagraph
= 1;
4626 TexOutput(_T("\\par\\pard\n"));
4630 case ltTWOCOLWIDTHA
:
4634 wxChar
*val
= GetArgData();
4635 int twips
= (int)(20*ParseUnitArgument(val
));
4636 TwoColWidthA
= twips
;
4640 case ltTWOCOLWIDTHB
:
4644 wxChar
*val
= GetArgData();
4645 int twips
= (int)(20*ParseUnitArgument(val
));
4646 TwoColWidthB
= twips
;
4655 int currentWidth
= 0;
4657 if (!compatibilityMode
|| (currentRowNumber
> 0))
4659 TexOutput(_T("\\pard\\intbl"));
4661 if (macroId
== ltRULEDROW
)
4663 for (int i
= 0; i
< noColumns
; i
++)
4665 currentWidth
+= TableData
[i
].width
;
4668 TexOutput(_T("\\clbrdrt\\brdrs\\brdrw15"));
4670 else if (ruleTop
> 1)
4672 TexOutput(_T("\\clbrdrt\\brdrdb\\brdrw15"));
4674 if (ruleBottom
== 1)
4676 TexOutput(_T("\\clbrdrb\\brdrs\\brdrw15"));
4678 else if (ruleBottom
> 1)
4680 TexOutput(_T("\\clbrdrb\\brdrdb\\brdrw15"));
4683 if (TableData
[i
].rightBorder
)
4684 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
4686 if (TableData
[i
].leftBorder
)
4687 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
4689 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
4692 TexOutput(_T("\\pard\\intbl\n"));
4696 currentRowNumber
++;
4701 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
4702 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
4708 static int noMultiColumns
= 0;
4715 noMultiColumns
= wxAtoi(GetArgData());
4732 for (int i
= 1; i
< noMultiColumns
; i
++)
4733 TexOutput(_T("\\cell"));
4740 if (start
&& (arg_no
== 1))
4743 // TexOutput(_T("\\fi0\n"));
4745 wxNode
*node
= itemizeStack
.GetFirst();
4747 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
4749 int indentValue
= 20*ParseUnitArgument(GetArgData());
4750 int indentSize
= indentValue
+ oldIndent
;
4752 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4753 itemizeStack
.Insert(struc
);
4755 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200 "), indentSize
, indentSize
);
4756 PushEnvironmentStyle(buf
);
4760 if (!start
&& (arg_no
== 2))
4762 PopEnvironmentStyle();
4763 if (itemizeStack
.GetFirst())
4765 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
4767 delete itemizeStack
.GetFirst();
4769 if (itemizeStack
.GetCount() == 0)
4771 TexOutput(_T("\\par\\pard\n"));
4772 issuedNewParagraph
= 1;
4773 WriteEnvironmentStyles();
4782 if (start && (arg_no == 1))
4785 wxNode *node = itemizeStack.GetFirst();
4787 oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
4789 int boxWidth = 20*ParseUnitArgument(GetArgData());
4791 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4792 int indentSize = indentValue + oldIndent;
4793 int indentSizeRight = indentSize + boxWidth;
4795 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4796 itemizeStack.Insert(struc);
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);
4804 if (!start && (arg_no == 2))
4806 PopEnvironmentStyle();
4807 if (itemizeStack.GetFirst())
4809 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
4811 delete itemizeStack.GetFirst();
4813 if (itemizeStack.Number() == 0)
4815 TexOutput(_T("\\par\\pard\n"));
4816 issuedNewParagraph = 1;
4817 WriteEnvironmentStyles();
4824 case ltDOCUMENTSTYLE
:
4826 DefaultOnArgument(macroId
, arg_no
, start
);
4827 if (!start
&& !IsArgOptional())
4829 if (MinorDocumentStyleString
)
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"));
4837 TexOutput(_T("\n"));
4841 case ltSETHOTSPOTCOLOUR
:
4842 case ltSETHOTSPOTCOLOR
:
4846 wxChar
*text
= GetArgData();
4847 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4848 hotSpotColour
= true;
4850 hotSpotColour
= false;
4854 case ltSETTRANSPARENCY
:
4858 wxChar
*text
= GetArgData();
4859 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4860 bitmapTransparency
= true;
4862 bitmapTransparency
= false;
4866 case ltSETHOTSPOTUNDERLINE
:
4870 wxChar
*text
= GetArgData();
4871 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4872 hotSpotUnderline
= true;
4874 hotSpotUnderline
= false;
4880 if (arg_no
== 1 && start
)
4882 wxChar
*citeKey
= GetArgData();
4883 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4886 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4887 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
4888 ref
->sectionNumber
= copystring(buf
);
4891 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
4892 wxSnprintf(buf
, sizeof(buf
), _T("{\\b [%d]} "), citeCount
);
4897 if (arg_no
== 2 && !start
)
4898 TexOutput(_T("\\par\\pard\\par\n\n"));
4901 case ltTHEBIBLIOGRAPHY
:
4903 if (start
&& (arg_no
== 1))
4907 SetCurrentOutputs(Contents
, Chapters
);
4911 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
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))
4918 OutputRTFHeaderCommands();
4919 OutputRTFFooterCommands();
4922 // Need to reset the current numbering style, or RTF forgets it.
4923 OutputNumberStyle(currentNumberStyle
);
4924 SetCurrentOutput(Contents
);
4927 wxFprintf(Chapters
, _T("\\page\n"));
4930 wxFprintf(Contents
, _T("\n{\\uldb %s}"), ReferencesNameString
);
4932 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %s}"), ReferencesNameString
);
4934 startedSections
= true;
4937 wxFprintf(Chapters
, _T("\n${\\footnote %s}"), ReferencesNameString
);
4939 wxChar
*topicName
= _T("bibliography");
4943 wxFprintf(Contents
, _T("{\\v %s}\\par\\pard\n"), topicName
);
4944 WriteEnvironmentStyles();
4947 wxFprintf(Contents
, _T("\\par\\par\\pard\n"));
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
);
4957 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
4958 wxFileNameFromPath(FileRoot
), "Contents");
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"));
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.
4981 * In linear RTF, we can embed the index entry now.
4986 // wxChar *entry = GetArgData();
4988 OutputChunkToString(GetArgChunk(), buf
);
4993 AddKeyWordForTopic(CurrentTopic
, buf
);
4996 else GenerateIndexEntry(buf
);
5009 wxChar
*name
= GetArgData();
5010 int pos
= FindColourPosition(name
);
5013 wxSnprintf(buf
, sizeof(buf
), _T("{%s%d "), ((macroId
== ltFCOL
) ? _T("\\cf") : _T("\\cb")), pos
);
5018 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
5033 if (arg_no
== 2) TexOutput(_T("}"));
5039 if (start
&& !winHelp
&& useWord
)
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) )
5046 if ( (!CurrentChapterName || !(CurrentChapterName && (wxStrcmp(CurrentChapterName, s) == 0))) &&
5047 (!CurrentSectionName || !(CurrentSectionName && (wxStrcmp(CurrentSectionName, s) == 0))) &&
5048 (!CurrentSubsectionName || !(CurrentSubsectionName && (wxStrcmp(CurrentSubsectionName, s) == 0)))
5052 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), s
,s
);
5059 if (start
&& useWord
&& !winHelp
)
5061 wxChar
*s
= GetArgData();
5062 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
5070 inPopRefSection
= true;
5072 inPopRefSection
= false;
5075 case ltINSERTATLEVEL
:
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
)
5081 static int currentLevelNo
= 1;
5082 static FILE* oldLevelFile
= Chapters
;
5089 oldLevelFile
= CurrentOutput1
;
5091 wxChar
*str
= GetArgData();
5092 currentLevelNo
= wxAtoi(str
);
5094 // TODO: cope with article style (no chapters)
5095 switch (currentLevelNo
)
5099 outputFile
= Chapters
;
5104 outputFile
= Sections
;
5109 outputFile
= Subsections
;
5114 outputFile
= Subsubsections
;
5124 CurrentOutput1
= outputFile
;
5140 CurrentOutput1
= oldLevelFile
;
5146 return DefaultOnArgument(macroId
, arg_no
, start
);
5158 forbidParindent
= 0;
5159 contentsLineSection
= NULL
;
5160 contentsLineValue
= NULL
;
5161 descriptionItemArg
= NULL
;
5166 tableVerticalLineLeft
= false;
5167 tableVerticalLineRight
= false;
5169 startedSections
= false;
5173 if (!InputFile
.empty() && !OutputFile
.empty())
5175 // Do some RTF-specific transformations on all the strings,
5177 Text2RTF(GetTopLevelChunk());
5179 Contents
= wxFopen(TmpContentsName
, _T("w"));
5180 Chapters
= wxFopen(_T("chapters.rtf"), _T("w"));
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
)
5189 WinHelpContentsFile
= wxFopen(WinHelpContentsFileName
, _T("w"));
5190 if (WinHelpContentsFile
)
5191 wxFprintf(WinHelpContentsFile
, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot
));
5194 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5196 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5200 if (!Contents
|| !Chapters
)
5202 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
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"));
5216 wxFprintf(Chapters
, _T("\\titlepg\n"));
5217 wxFprintf(Contents
, _T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
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
);
5225 // By default, Swiss, 11 point.
5226 wxFprintf(Chapters
, _T("\\f2\\fs22\n"));
5228 PushEnvironmentStyle(_T("\\f2\\fs22\\sa200"));
5230 SetCurrentOutput(Chapters
);
5235 OnInform(_T("Converting..."));
5239 FILE *Header
= wxFopen(_T("header.rtf"), _T("w"));
5242 OnError(_T("Ouch! Could not open temporary file header.rtf for writing."));
5245 WriteRTFHeader(Header
);
5248 PopEnvironmentStyle();
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"));
5261 // TexOutput(_T("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n"));
5263 TexOutput(_T("}\n"));
5264 fclose(Contents
); Contents
= NULL
;
5265 fclose(Chapters
); Chapters
= NULL
;
5268 fclose(Sections
); Sections
= NULL
;
5269 fclose(Subsections
); Subsections
= NULL
;
5270 fclose(Subsubsections
); Subsubsections
= NULL
;
5271 fclose(Popups
); Popups
= NULL
;
5272 if (winHelpContents
)
5274 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5280 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5282 wxConcatFiles(_T("tmp1.rtf"), _T("sections.rtf"), _T("tmp2.rtf"));
5284 wxConcatFiles(_T("tmp2.rtf"), _T("subsections.rtf"), _T("tmp3.rtf"));
5286 wxConcatFiles(_T("tmp3.rtf"), _T("subsubsections.rtf"), _T("tmp4.rtf"));
5288 wxConcatFiles(_T("tmp4.rtf"), _T("popups.rtf"), OutputFile
);
5291 wxRemoveFile(_T("tmp1.rtf"));
5292 wxRemoveFile(_T("tmp2.rtf"));
5293 wxRemoveFile(_T("tmp3.rtf"));
5294 wxRemoveFile(_T("tmp4.rtf"));
5298 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5300 if (wxFileExists(OutputFile
))
5301 wxRemoveFile(OutputFile
);
5304 cwdStr
= wxGetWorkingDirectory();
5306 wxString outputDirStr
;
5307 outputDirStr
= wxPathOnly(OutputFile
);
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
5315 wxRenameFile(_T("tmp1.rtf"), OutputFile
);
5319 wxCopyFile(_T("tmp1.rtf"), OutputFile
);
5323 wxRemoveFile(_T("tmp1.rtf"));
5326 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5328 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5330 wxCopyFile(TmpContentsName
, ContentsName
);
5331 wxRemoveFile(TmpContentsName
);
5334 wxRemoveFile(_T("chapters.rtf"));
5335 wxRemoveFile(_T("header.rtf"));
5339 wxRemoveFile(_T("sections.rtf"));
5340 wxRemoveFile(_T("subsections.rtf"));
5341 wxRemoveFile(_T("subsubsections.rtf"));
5342 wxRemoveFile(_T("popups.rtf"));
5344 if (winHelp
&& generateHPJ
)
5345 WriteHPJ(OutputFile
);