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 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
36 static inline wxChar
* copystring(const wxChar
* s
)
37 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
40 static int indentLevel
= 0;
41 static int forbidParindent
= 0; // if > 0, no parindent (e.g. in center environment)
42 int forbidResetPar
= 0; // If > 0, don't reset memory of having output a new par
44 static wxChar
*contentsLineSection
= NULL
;
45 static wxChar
*contentsLineValue
= NULL
;
46 static TexChunk
*descriptionItemArg
= NULL
;
47 static wxStringList environmentStack
; // Stack of paragraph styles we need to remember
48 static int footnoteCount
= 0;
49 static int citeCount
= 1;
51 extern bool startedSections
;
52 extern FILE *Contents
;
53 extern FILE *Chapters
;
55 extern FILE *WinHelpContentsFile
;
56 extern wxChar
*RTFCharset
;
57 // This is defined in the Tex2Any library and isn't in use after parsing
58 extern wxChar
*BigBuffer
;
60 extern wxHashTable TexReferences
;
62 // Are we in verbatim mode? If so, format differently.
63 static bool inVerbatim
= false;
65 // We're in a series of PopRef topics, so don't output section headings
66 bool inPopRefSection
= false;
69 static bool hotSpotColour
= true;
70 static bool hotSpotUnderline
= true;
72 // Transparency (WHITE = transparent)
73 static bool bitmapTransparency
= true;
75 // Linear RTF requires us to set the style per section.
76 static wxChar
*currentNumberStyle
= NULL
;
77 static int currentItemSep
= 8;
78 static int CurrentTextWidth
= 8640; // Say, six inches
79 static int CurrentLeftMarginOdd
= 400;
80 static int CurrentLeftMarginEven
= 1440;
81 static int CurrentRightMarginOdd
= 1440;
82 static int CurrentRightMarginEven
= 400;
83 static int CurrentMarginParWidth
= 2000;
84 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
85 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
86 static int GutterWidth
= 2300;
88 // Two-column table dimensions, in twips
89 static int TwoColWidthA
= 1500;
90 static int TwoColWidthB
= 3000;
92 const int PageWidth
= 12242; // 8.25 inches wide for A4
94 // Remember the anchor in a helpref
95 static TexChunk
*helpRefText
= NULL
;
98 * Flag to say we've just issued a \par\pard command, so don't
99 * repeat this unnecessarily.
103 int issuedNewParagraph
= 0;
105 // Need to know whether we're in a table or figure for benefit
106 // of listoffigures/listoftables
107 static bool inFigure
= false;
108 static bool inTable
= false;
114 static wxChar
*CurrentChapterName
= NULL
;
115 static wxChar
*CurrentSectionName
= NULL
;
116 static wxChar
*CurrentSubsectionName
= NULL
;
117 static wxChar
*CurrentTopic
= NULL
;
119 static bool InPopups()
121 if (CurrentChapterName
&& (wxStrcmp(CurrentChapterName
, _T("popups")) == 0))
123 if (CurrentSectionName
&& (wxStrcmp(CurrentSectionName
, _T("popups")) == 0))
128 static void SetCurrentTopic(wxChar
*s
)
130 if (CurrentTopic
) delete[] CurrentTopic
;
131 CurrentTopic
= copystring(s
);
134 void SetCurrentChapterName(wxChar
*s
)
136 if (CurrentChapterName
) delete[] CurrentChapterName
;
137 CurrentChapterName
= copystring(s
);
140 void SetCurrentSectionName(wxChar
*s
)
142 if (CurrentSectionName
) delete[] CurrentSectionName
;
143 CurrentSectionName
= copystring(s
);
146 void SetCurrentSubsectionName(wxChar
*s
)
148 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
149 CurrentSubsectionName
= copystring(s
);
153 // Indicate that a parent topic at level 'level' has children.
154 // Level 1 is a chapter, 2 is a section, etc.
155 void NotifyParentHasChildren(int parentLevel
)
157 wxChar
*parentTopic
= NULL
;
162 parentTopic
= CurrentChapterName
;
167 parentTopic
= CurrentSectionName
;
172 parentTopic
= CurrentSubsectionName
;
182 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
185 texTopic
= new TexTopic
;
186 TopicTable
.Put(parentTopic
, texTopic
);
188 texTopic
->hasChildren
= true;
192 // Have to keep a count of what levels are books, what are pages,
193 // in order to correct for a Win95 bug which means that if you
194 // have a book at level n, and then a page at level n, the page
195 // ends up on level n + 1.
197 bool ContentsLevels
[5];
199 // Reset below this level (starts from 1)
200 void ResetContentsLevels(int l
)
203 for (i
= l
; i
< 5; i
++)
204 ContentsLevels
[i
] = false;
206 // There are always books on the top level
207 ContentsLevels
[0] = true;
210 // Output a WinHelp section as a keyword, substituting
212 void OutputSectionKeyword(FILE *fd
)
214 OutputCurrentSectionToString(wxTex2RTFBuffer
);
217 for (i
= 0; i
< wxStrlen(wxTex2RTFBuffer
); i
++)
218 if (wxTex2RTFBuffer
[i
] == ':')
219 wxTex2RTFBuffer
[i
] = ' ';
220 // Don't write to index if there's some RTF in the string
221 else if ( wxTex2RTFBuffer
[i
] == '{' )
224 wxFprintf(fd
, _T("K{\\footnote {K} "));
225 wxFprintf(fd
, _T("%s"), wxTex2RTFBuffer
);
227 wxFprintf(fd
, _T("}\n"));
230 // Write a line for the .cnt file, if we're doing this.
231 void WriteWinHelpContentsFileLine(wxChar
*topicName
, wxChar
*xitle
, int level
)
233 // First, convert any RTF characters to ASCII
237 // assuming iso-8859-1 here even in Unicode build (FIXME?)
238 while ( (xitle
[s
]!=0)&&(d
<255) )
240 wxChar ch
=wxChar(xitle
[s
]&0xff);
242 wxChar ch1
=wxChar(xitle
[s
+1]&0xff);
243 wxChar ch2
=wxChar(xitle
[s
+2]&0xff);
244 wxChar ch3
=wxChar(xitle
[s
+3]&0xff);
245 s
+=4; // next character
246 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]=wxChar('ö'); }
247 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]=wxChar('ä'); }
248 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]=wxChar('ü'); }
249 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]=wxChar('Ö'); }
250 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]=wxChar('Ä'); }
251 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]=wxChar('Ü'); }
259 // Section (2) becomes level 1 if it's an article.
260 if (DocumentStyle
== LATEX_ARTICLE
)
263 if (level
== 0) // Means we had a Chapter in an article, oops.
266 ResetContentsLevels(level
);
268 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
270 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
273 // If a previous section at this level was a book, we *have* to have a
274 // book not a page, because of a bug in WHC (or WinHelp 4).
275 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
277 // At this level, we have a pointer to a further hierarchy.
278 // So we need a 'book' consisting of (say) Chapter 1.
279 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
281 // Then we have a 'page' consisting of the text for this chapter
282 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
284 // Then we'll be writing out further pages or books at level + 1...
286 // Remember that at this level, we had a book and *must* for the
287 // remainder of sections at this level.
288 ContentsLevels
[level
-1] = true;
292 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
297 if (level
== 1 || ContentsLevels
[level
-1])
299 // Always have a book at level 1
300 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
301 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
302 ContentsLevels
[level
-1] = true;
305 // Probably doesn't have children if it hasn't been added to the topic table
306 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
311 void SplitIndexEntry(wxChar
*entry
, wxChar
*buf1
, wxChar
*buf2
)
313 int len
= wxStrlen(entry
); int i
= 0;
314 while ((i
< len
) && entry
[i
] != '!')
315 { buf1
[i
] = entry
[i
]; i
++; }
316 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
321 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
327 * Output topic index entries in WinHelp RTF
330 void GenerateKeywordsForTopic(wxChar
*topic
)
332 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
336 wxStringList
*list
= texTopic
->keywords
;
339 wxStringListNode
*node
= list
->GetFirst();
342 wxChar
*s
= (wxChar
*)node
->GetData();
344 // Must separate out main entry form subentry (only 1 subentry allowed)
345 wxChar buf1
[100]; wxChar buf2
[100];
346 SplitIndexEntry(s
, buf1
, buf2
);
348 // Check for ':' which messes up index
350 for (i
= 0; i
< wxStrlen(buf1
) ; i
++)
353 for (i
= 0; i
< wxStrlen(buf2
) ; i
++)
357 // {K} is a strange fix to prevent words beginning with K not
358 // being indexed properly
359 TexOutput(_T("K{\\footnote {K} "));
361 if (wxStrlen(buf2
) > 0)
367 TexOutput(_T("}\n"));
368 node
= node
->GetNext();
374 * Output index entry in linear RTF
378 void GenerateIndexEntry(wxChar
*entry
)
382 wxChar buf1
[100]; wxChar buf2
[100];
383 SplitIndexEntry(entry
, buf1
, buf2
);
385 TexOutput(_T("{\\xe\\v {"));
387 if (wxStrlen(buf2
) > 0)
389 TexOutput(_T("\\:"));
397 * Write a suitable RTF header.
401 void WriteColourTable(FILE *fd
)
403 wxFprintf(fd
, _T("{\\colortbl"));
404 wxNode
*node
= ColourTable
.GetFirst();
407 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->GetData();
408 wxFprintf(fd
, _T("\\red%d\\green%d\\blue%d;\n"), entry
->red
, entry
->green
, entry
->blue
);
409 node
= node
->GetNext();
411 wxFprintf(fd
, _T("}"));
415 * Write heading style
419 void WriteHeadingStyle(FILE *fd
, int heading
)
425 wxFprintf(fd
, _T("\\sb300\\sa260\\f2\\b\\fs%d"), chapterFont
*2);
430 wxFprintf(fd
, _T("\\sb200\\sa240\\f2\\b\\fs%d"), sectionFont
*2);
435 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
440 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
448 void WriteRTFHeader(FILE *fd
)
450 wxFprintf(fd
, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset
);
451 wxFprintf(fd
, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n"));
452 wxFprintf(fd
, _T("{\\f3\\fmodern Courier New;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
456 wxFprintf(fd
, _T("{\\stylesheet{\\f2\\fs22\\sa200 \\snext0 Normal;}\n"));
458 wxFprintf(fd
, _T("{\\s1 ")); WriteHeadingStyle(fd
, 1); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 1;}\n"));
459 wxFprintf(fd
, _T("{\\s2 ")); WriteHeadingStyle(fd
, 2); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 2;}\n"));
460 wxFprintf(fd
, _T("{\\s3 ")); WriteHeadingStyle(fd
, 3); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 3;}\n"));
461 wxFprintf(fd
, _T("{\\s4 ")); WriteHeadingStyle(fd
, 4); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 4;}\n"));
464 wxFprintf(fd
, _T("{\\s10\\ql \\li720\\ri0\\nowidctlpar\\faauto\\rin0\\lin720\\itap0 \\cbpat17\
465 \\f2\\fs20 \\sbasedon0 \\snext24 Code;}\n"));
467 // Table of contents styles
468 wxFprintf(fd
, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n"));
470 wxFprintf(fd
, _T("{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n"));
471 wxFprintf(fd
, _T("{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n"));
472 wxFprintf(fd
, _T("{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n"));
475 wxFprintf(fd
, _T("{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n"));
476 wxFprintf(fd
, _T("{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n"));
477 wxFprintf(fd
, _T("{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n"));
478 wxFprintf(fd
, _T("{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n"));
479 wxFprintf(fd
, _T("{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n"));
480 wxFprintf(fd
, _T("}\n"));
482 WriteColourTable(fd
);
483 wxFprintf(fd
, _T("\n\\ftnbj\\ftnrestart")); // Latex default is footnotes at bottom of page, not section.
484 wxFprintf(fd
, _T("\n"));
487 void OutputNumberStyle(wxChar
*numberStyle
)
491 if (wxStrcmp(numberStyle
, _T("arabic")) == 0)
493 TexOutput(_T("\\pgndec"));
495 else if (wxStrcmp(numberStyle
, _T("roman")) == 0)
497 TexOutput(_T("\\pgnlcrm"));
499 else if (wxStrcmp(numberStyle
, _T("Roman")) == 0)
501 TexOutput(_T("\\pgnucrm"));
503 else if (wxStrcmp(numberStyle
, _T("alph")) == 0)
505 TexOutput(_T("\\pgnlcltr"));
507 else if (wxStrcmp(numberStyle
, _T("Alph")) == 0)
509 TexOutput(_T("\\pgnucltr"));
515 * Write a Windows help project file
518 bool WriteHPJ(const wxString
& filename
)
520 wxChar hpjFilename
[256];
523 wxStrcpy(hpjFilename
, filename
);
524 StripExtension(hpjFilename
);
525 wxStrcat(hpjFilename
, _T(".hpj"));
527 wxStrcpy(helpFile
, wxFileNameFromPath(filename
));
528 StripExtension(helpFile
);
529 wxStrcpy(rtfFile
, helpFile
);
530 wxStrcat(helpFile
, _T(".hlp"));
531 wxStrcat(rtfFile
, _T(".rtf"));
533 FILE *fd
= wxFopen(hpjFilename
, _T("w"));
537 wxChar
*helpTitle
= winHelpTitle
;
539 helpTitle
= _T("Untitled");
541 wxString thePath
= wxPathOnly(InputFile
);
544 wxFprintf(fd
, _T("[OPTIONS]\n"));
545 wxFprintf(fd
, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath
.c_str());
546 wxFprintf(fd
, _T("TITLE=%s\n"), helpTitle
);
547 wxFprintf(fd
, _T("CONTENTS=Contents\n"));
549 if (winHelpVersion
> 3)
551 wxFprintf(fd
, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
552 wxFprintf(fd
, _T("COMPRESS=8 Zeck\n"));
553 wxFprintf(fd
, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
554 wxFprintf(fd
, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot
));
558 wxFprintf(fd
, _T("COMPRESS=HIGH\n"));
560 wxFprintf(fd
, _T("\n"));
562 if (winHelpVersion
> 3)
564 wxFprintf(fd
, _T("[WINDOWS]\n"));
565 wxFprintf(fd
, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
566 wxFprintf(fd
, _T("\n"));
569 wxFprintf(fd
, _T("[FILES]\n%s\n\n"), rtfFile
);
570 wxFprintf(fd
, _T("[CONFIG]\n"));
572 wxFprintf(fd
, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile
);
573 wxFprintf(fd
, _T("BrowseButtons()\n\n"));
574 wxFprintf(fd
, _T("[MAP]\n\n[BITMAPS]\n\n"));
581 * Given a TexChunk with a string value, scans through the string
582 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
583 * and inserting spaces at the start of lines since in Latex, a newline
584 * implies a space, but not in RTF.
588 void ProcessText2RTF(TexChunk
*chunk
)
590 bool changed
= false;
594 int len
= wxStrlen(chunk
->value
);
597 ch
= chunk
->value
[i
];
603 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("\\par\n")); ptr
+= 5;
604 // BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par{\\v this was verbatim}\n")); ptr += 5;
610 // If the first character of the next line is ASCII,
611 // put a space in. Implicit in Latex, not in RTF.
613 The reason this is difficult is that you don't really know
614 where a space would be appropriate. If you always put in a space
615 when you find a newline, unwanted spaces appear in the text.
617 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
618 !isspace(chunk
->value
[i
+1])) ||
619 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
620 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
621 !isspace(chunk
->value
[i
+2]))))
624 // DOS files have a 13 after the 10
628 if (chunk
->value
[i
] == 13)
635 BigBuffer
[ptr
] = ' ';
638 // Note that the actual ASCII character seen is dealt with in the next
649 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
651 BigBuffer
[ptr
] = '"'; ptr
++;
655 else if (!inVerbatim
&& ch
== '`') // Change ` to '
657 BigBuffer
[ptr
] = 39; ptr
++;
661 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
663 BigBuffer
[ptr
] = '\\'; ptr
++;
664 BigBuffer
[ptr
] = '\\'; ptr
++;
668 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curly bracket
670 BigBuffer
[ptr
] = '\\'; ptr
++;
671 BigBuffer
[ptr
] = ch
; ptr
++;
686 delete[] chunk
->value
;
687 chunk
->value
= copystring(BigBuffer
);
692 * Scan through all chunks starting from the given one,
693 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
694 * This should be called after Tex2Any has parsed the file,
695 * and before TraverseDocument is called.
699 void Text2RTF(TexChunk
*chunk
)
702 if (stopRunning
) return;
706 case CHUNK_TYPE_MACRO
:
708 TexMacroDef
*def
= chunk
->def
;
709 if (def
&& def
->ignore
)
712 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
715 wxNode
*node
= chunk
->children
.GetFirst();
718 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
719 Text2RTF(child_chunk
);
720 node
= node
->GetNext();
723 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
730 wxNode
*node
= chunk
->children
.GetFirst();
733 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
734 Text2RTF(child_chunk
);
735 node
= node
->GetNext();
740 case CHUNK_TYPE_STRING
:
743 ProcessText2RTF(chunk
);
754 wxChar browseBuf
[10];
755 static long browseId
= 0;
756 wxChar
*GetBrowseString(void)
760 wxSnprintf(buf
, sizeof(buf
), _T("%ld"), browseId
);
761 int noZeroes
= 5-wxStrlen(buf
);
762 wxStrcpy(browseBuf
, _T("browse"));
763 for (int i
= 0; i
< noZeroes
; i
++)
764 wxStrcat(browseBuf
, _T("0"));
765 wxStrcat(browseBuf
, buf
);
770 * Keeping track of environments to restore the styles after \pard.
771 * Push strings like "\qc" onto stack.
775 void PushEnvironmentStyle(wxChar
*style
)
777 environmentStack
.Add(style
);
780 void PopEnvironmentStyle(void)
782 wxStringListNode
*node
= environmentStack
.GetLast();
785 wxChar
*val
= (wxChar
*)node
->GetData();
791 // Write out the styles, most recent first.
792 void WriteEnvironmentStyles(void)
794 wxStringListNode
*node
= environmentStack
.GetLast();
797 wxChar
*val
= (wxChar
*)node
->GetData();
799 node
= node
->GetNext();
801 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
804 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d"), ParIndent
*20); // Convert points to TWIPS
807 if (environmentStack
.GetCount() > 0 || (ParIndent
> 0))
817 void OutputRTFHeaderCommands(void)
820 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
822 TexOutput(_T("{\\headerl }{\\headerr }"));
824 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
826 TexOutput(_T("{\\headerl }{\\headerr }"));
828 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
831 TexOutput(_T("{\\headerl\\fi0 "));
834 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
836 TexOutput(_T("{\\i \\qr "));
837 if (DocumentStyle
== LATEX_ARTICLE
)
839 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
844 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d: "), chapterNo
);
847 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
848 TexOutput(_T("}\\par\\pard}"));
851 TexOutput(_T("{\\headerr\\fi0 "));
854 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
856 TexOutput(_T("{\\i \\qc "));
857 if (DocumentStyle
== LATEX_ARTICLE
)
859 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
864 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d"), chapterNo
);
867 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
868 TexOutput(_T("}\\par\\pard}"));
872 int oldForbidResetPar
= forbidResetPar
;
875 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
877 TexOutput(_T("{\\headerl\\fi0 "));
880 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
884 if (!CentreHeaderEven
&& !RightHeaderEven
)
885 TexOutput(_T("\\ql "));
886 TraverseChildrenFromChunk(LeftHeaderEven
);
888 if (CentreHeaderEven
)
890 if (!LeftHeaderEven
&& !RightHeaderEven
)
891 TexOutput(_T("\\qc "));
893 TexOutput(_T("\\tab\\tab\\tab "));
894 TraverseChildrenFromChunk(CentreHeaderEven
);
898 if (!LeftHeaderEven
&& !CentreHeaderEven
)
899 TexOutput(_T("\\qr "));
901 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
902 TraverseChildrenFromChunk(RightHeaderEven
);
904 TexOutput(_T("\\par\\pard}"));
907 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
909 TexOutput(_T("{\\headerr\\fi0 "));
912 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
916 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
917 TexOutput(_T("\\ql "));
918 TraverseChildrenFromChunk(LeftHeaderOdd
);
922 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
923 TexOutput(_T("\\qc "));
925 TexOutput(_T("\\tab\\tab\\tab "));
926 TraverseChildrenFromChunk(CentreHeaderOdd
);
930 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
931 TexOutput(_T("\\qr "));
933 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
934 TraverseChildrenFromChunk(RightHeaderOdd
);
936 TexOutput(_T("\\par\\pard}"));
938 // As an approximation, don't put a header on the first page of a section.
939 // This may not always be desired, but it's a reasonable guess.
940 TexOutput(_T("{\\headerf }"));
942 forbidResetPar
= oldForbidResetPar
;
946 void OutputRTFFooterCommands(void)
948 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
950 TexOutput(_T("{\\footerl\\fi0 "));
952 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
953 TexOutput(_T("{\\qc "));
954 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
955 TexOutput(_T("}\\par\\pard}"));
957 TexOutput(_T("{\\footerr\\fi0 "));
959 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
960 TexOutput(_T("{\\qc "));
961 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
962 TexOutput(_T("}\\par\\pard}"));
964 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
966 TexOutput(_T("{\\footerl }{\\footerr }"));
968 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
970 TexOutput(_T("{\\footerl }{\\footerr }"));
974 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
976 TexOutput(_T("{\\footerl\\fi0 "));
978 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
981 if (!CentreFooterEven
&& !RightFooterEven
)
982 TexOutput(_T("\\ql "));
983 TraverseChildrenFromChunk(LeftFooterEven
);
985 if (CentreFooterEven
)
987 if (!LeftFooterEven
&& !RightFooterEven
)
988 TexOutput(_T("\\qc "));
990 TexOutput(_T("\\tab\\tab\\tab "));
991 TraverseChildrenFromChunk(CentreFooterEven
);
995 if (!LeftFooterEven
&& !CentreFooterEven
)
996 TexOutput(_T("\\qr "));
998 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
999 TraverseChildrenFromChunk(RightFooterEven
);
1001 TexOutput(_T("\\par\\pard}"));
1004 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1006 TexOutput(_T("{\\footerr\\fi0 "));
1008 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
1011 if (!CentreFooterOdd
&& !RightFooterOdd
)
1012 TexOutput(_T("\\ql "));
1013 TraverseChildrenFromChunk(LeftFooterOdd
);
1015 if (CentreFooterOdd
)
1017 if (!LeftFooterOdd
&& !RightFooterOdd
)
1018 TexOutput(_T("\\qc "));
1020 TexOutput(_T("\\tab\\tab\\tab "));
1021 TraverseChildrenFromChunk(CentreFooterOdd
);
1025 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1026 TexOutput(_T("\\qr "));
1028 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1029 TraverseChildrenFromChunk(RightFooterOdd
);
1031 TexOutput(_T("\\par\\pard}"));
1034 // As an approximation, put a footer on the first page of a section.
1035 // This may not always be desired, but it's a reasonable guess.
1036 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1038 TexOutput(_T("{\\footerf\\fi0 "));
1041 if (!CentreFooterOdd
&& !RightFooterOdd
)
1042 TexOutput(_T("\\ql "));
1043 TraverseChildrenFromChunk(LeftFooterOdd
);
1045 if (CentreFooterOdd
)
1047 if (!LeftFooterOdd
&& !RightFooterOdd
)
1048 TexOutput(_T("\\qc "));
1050 TexOutput(_T("\\tab\\tab\\tab "));
1051 TraverseChildrenFromChunk(CentreFooterOdd
);
1055 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1056 TexOutput(_T("\\qr "));
1058 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1059 TraverseChildrenFromChunk(RightFooterOdd
);
1061 TexOutput(_T("\\par\\pard}"));
1066 // Called on start/end of macro examination
1067 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1071 wxSnprintf(tmpBuf, sizeof(tmpBuf), _T("%d (%d)"), macroId, (int)start);
1072 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1073 OutputDebugString("\n"); wxYield();
1076 // ltLABEL is included here because after a section but BEFORE
1077 // the label is seen, a new paragraph is issued. Don't upset this by
1078 // immediately forgetting we've done it.
1079 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1080 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1081 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1082 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1083 macroId
!= ltPAGENUMBERING
&&
1084 (forbidResetPar
== 0)))
1086 issuedNewParagraph
= 0;
1094 case ltCHAPTERHEADING
:
1095 case ltCHAPTERHEADINGSTAR
:
1103 subsubsectionNo
= 0;
1106 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1109 wxChar
*topicName
= FindTopicName(GetNextChunk());
1110 SetCurrentChapterName(topicName
);
1112 if (winHelpContents
&& winHelp
&& !InPopups())
1114 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1115 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1117 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1122 wxFprintf(Contents
, _T("\n{\\uldb "));
1123 wxFprintf(Chapters
, _T("\\page"));
1124 wxFprintf(Chapters
, _T("\n${\\footnote "));
1126 SetCurrentOutputs(Contents
, Chapters
);
1128 SetCurrentOutput(Chapters
);
1132 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
1134 // If a non-custom page style, we generate the header now.
1135 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1136 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1137 wxStrcmp(PageStyle
, _T("headings")) == 0))
1139 OutputRTFHeaderCommands();
1140 OutputRTFFooterCommands();
1143 // Need to reset the current numbering style, or RTF forgets it.
1144 SetCurrentOutput(Chapters
);
1145 OutputNumberStyle(currentNumberStyle
);
1147 SetCurrentOutput(Contents
);
1151 if (macroId
== ltCHAPTER
)
1154 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), chapterNo
);
1156 else if (macroId
== ltCHAPTERHEADING
)
1158 wxFprintf(Contents
, _T("\\par\n\\pard{\\b "));
1160 else SetCurrentOutput(NULL
); // No entry in table of contents
1164 startedSections
= true;
1166 // Output heading to contents page
1169 OutputCurrentSection();
1173 wxFprintf(Contents
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1174 //WriteEnvironmentStyles();
1176 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1177 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1179 // From here, just output to chapter
1180 SetCurrentOutput(Chapters
);
1185 wxFprintf(Chapters
, _T("}\n#{\\footnote %s}\n"), topicName
);
1186 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
1188 OutputSectionKeyword(Chapters
);
1190 GenerateKeywordsForTopic(topicName
);
1193 // If we're generating a .cnt file, we don't want to be able
1194 // jump up to the old-style contents page, so disable it.
1195 if (winHelpContents
)
1196 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
1198 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1199 wxFileNameFromPath(FileRoot
), _T("Contents"));
1205 wxChar
*styleCommand
= _T("");
1206 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1207 styleCommand
= _T("\\s1");
1208 wxFprintf(Chapters
, _T("\\pard{%s"), ((winHelp
&& !InPopups()) ? _T("\\keepn\\sa140\\sb140") : styleCommand
));
1209 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" "));
1212 if (macroId
== ltCHAPTER
)
1215 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1216 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1218 wxFprintf(Chapters
, _T("%d. "), chapterNo
);
1222 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1225 OutputCurrentSection();
1226 TexOutput(_T("\\par\\pard}\n"));
1228 issuedNewParagraph
= 1;
1229 WriteEnvironmentStyles();
1235 case ltSECTIONHEADING
:
1236 case ltSECTIONHEADINGSTAR
:
1240 if (DocumentStyle
== LATEX_ARTICLE
)
1241 jumpFrom
= Contents
;
1243 jumpFrom
= Chapters
;
1248 subsubsectionNo
= 0;
1249 if (DocumentStyle
== LATEX_ARTICLE
)
1252 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1255 wxChar
*topicName
= FindTopicName(GetNextChunk());
1256 SetCurrentSectionName(topicName
);
1257 NotifyParentHasChildren(1);
1258 if (winHelpContents
&& winHelp
&& !InPopups())
1260 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1261 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 2);
1263 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1267 SetCurrentOutputs(jumpFrom
, Sections
);
1268 // Newline for a new section if this is an article
1269 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1270 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1271 wxFprintf(Sections
, _T("\\page\n"));
1274 wxFprintf(jumpFrom
, _T("\n{\\uldb "));
1278 if (DocumentStyle
== LATEX_ARTICLE
)
1280 TexOutput(_T("\\sect\\pgncont\n"));
1281 // If a non-custom page style, we generate the header now.
1282 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1283 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1284 wxStrcmp(PageStyle
, _T("headings")) == 0))
1286 OutputRTFHeaderCommands();
1287 OutputRTFFooterCommands();
1290 SetCurrentOutput(Contents
);
1292 if (macroId
== ltSECTION
)
1296 if (DocumentStyle
== LATEX_REPORT
)
1297 wxFprintf(Contents
, _T("\n\\pard{\\tab %d.%d\\tab "), chapterNo
, sectionNo
);
1299 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), sectionNo
);
1302 else if (macroId
== ltSECTIONHEADING
)
1306 if (DocumentStyle
== LATEX_REPORT
)
1307 wxFprintf(Contents
, _T("\n\\pard{\\tab ")); //, chapterNo, sectionNo);
1309 wxFprintf(Contents
, _T("\\par\n\\pard{\\b ")); //, sectionNo);
1312 else SetCurrentOutput(NULL
);
1315 if (startedSections
)
1318 wxFprintf(Sections
, _T("\\page\n"));
1320 startedSections
= true;
1323 wxFprintf(Sections
, _T("\n${\\footnote "));
1325 // Output heading to contents page
1327 OutputCurrentSection();
1333 wxFprintf(jumpFrom
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1334 //WriteEnvironmentStyles();
1337 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1339 if (DocumentStyle
== LATEX_REPORT
)
1340 wxFprintf(Contents
, _T("}\\par\\pard\n"));
1342 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1345 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1349 wxFprintf(Sections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1350 wxFprintf(Sections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1351 OutputSectionKeyword(Sections
);
1352 GenerateKeywordsForTopic(topicName
);
1355 if (DocumentStyle
== LATEX_ARTICLE
)
1357 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1358 wxFileNameFromPath(FileRoot
), _T("Contents"));
1360 else if (CurrentChapterName
)
1362 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1363 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1370 wxChar
*styleCommand
= _T("");
1371 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1373 if (DocumentStyle
== LATEX_ARTICLE
)
1374 styleCommand
= _T("\\s1");
1376 styleCommand
= _T("\\s2");
1378 wxChar
*keep
= _T("");
1379 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1380 keep
= _T("\\keepn\\sa140\\sb140");
1382 wxFprintf(winHelp
? Sections
: Chapters
, _T("\\pard{%s%s"),
1383 keep
, styleCommand
);
1385 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1386 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1387 wxFprintf(winHelp
? Sections
: Chapters
, _T(" "));
1391 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1393 if (DocumentStyle
== LATEX_REPORT
)
1396 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo,
1397 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1400 wxFprintf(Chapters
, _T("%d.%d. "), chapterNo
, sectionNo
);
1405 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1406 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1409 wxFprintf(Chapters
, _T("%d. "), sectionNo
);
1414 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1417 OutputCurrentSection();
1418 TexOutput(_T("\\par\\pard}\n"));
1419 // TexOutput(_T("\\par\\pard}\\par\n"));
1421 issuedNewParagraph
= 1;
1422 WriteEnvironmentStyles();
1423 // issuedNewParagraph = 2;
1428 case ltSUBSECTIONSTAR
:
1429 case ltMEMBERSECTION
:
1430 case ltFUNCTIONSECTION
:
1434 if (winHelp
&& !Sections
)
1436 OnError(_T("You cannot have a subsection before a section!"));
1440 subsubsectionNo
= 0;
1442 if (macroId
!= ltSUBSECTIONSTAR
)
1445 wxChar
*topicName
= FindTopicName(GetNextChunk());
1446 SetCurrentSubsectionName(topicName
);
1447 NotifyParentHasChildren(2);
1448 if (winHelpContents
&& winHelp
&& !InPopups())
1450 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1451 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1453 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1457 SetCurrentOutputs(Sections
, Subsections
);
1458 SetCurrentOutputs(Sections
, Subsections
);
1460 wxFprintf(Sections
, _T("\n{\\uldb "));
1464 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1465 (macroId
!= ltFUNCTIONSECTION
))
1467 SetCurrentOutput(Contents
);
1468 if (DocumentStyle
== LATEX_REPORT
)
1469 wxFprintf(Contents
, _T("\n\\pard\\tab\\tab %d.%d.%d\\tab "), chapterNo
, sectionNo
, subsectionNo
);
1471 wxFprintf(Contents
, _T("\n\\pard\\tab %d.%d\\tab "), sectionNo
, subsectionNo
);
1472 } else SetCurrentOutput(NULL
);
1474 if (startedSections
)
1479 wxFprintf(Subsections
, _T("\\page\n"));
1481 // Experimental JACS 2004-02-21
1484 wxFprintf(Chapters
, _T("\\par\n"));
1487 startedSections
= true;
1490 wxFprintf(Subsections
, _T("\n${\\footnote "));
1492 // Output to contents page
1494 OutputCurrentSection();
1500 wxFprintf(Sections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1501 //WriteEnvironmentStyles();
1504 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1505 (macroId
!= ltFUNCTIONSECTION
))
1506 wxFprintf(Contents
, _T("\\par\\pard\n"));
1508 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1511 wxFprintf(Subsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1512 wxFprintf(Subsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1513 OutputSectionKeyword(Subsections
);
1514 GenerateKeywordsForTopic(topicName
);
1515 if (useUpButton
&& CurrentSectionName
)
1517 wxFprintf(Subsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1518 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1521 if (!winHelp
&& indexSubsections
&& useWord
)
1523 // Insert index entry for this subsection
1524 TexOutput(_T("{\\xe\\v {"));
1525 OutputCurrentSection();
1526 TexOutput(_T("}}"));
1531 wxChar
*styleCommand
= _T("");
1532 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1534 if (DocumentStyle
== LATEX_ARTICLE
)
1535 styleCommand
= _T("\\s2");
1537 styleCommand
= _T("\\s3");
1539 wxChar
*keep
= _T("");
1540 if (winHelp
&& !InPopups())
1541 keep
= _T("\\keepn\\sa140\\sb140");
1543 wxFprintf(winHelp
? Subsections
: Chapters
, _T("\\pard{%s%s"),
1544 keep
, styleCommand
);
1546 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1547 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1548 wxFprintf(winHelp
? Subsections
: Chapters
, _T(" "));
1552 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1553 (macroId
!= ltFUNCTIONSECTION
))
1555 if (DocumentStyle
== LATEX_REPORT
)
1558 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo,
1559 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1562 wxFprintf(Chapters
, _T("%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
);
1567 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo,
1568 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1571 wxFprintf(Chapters
, _T("%d.%d. "), sectionNo
, subsectionNo
);
1576 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1579 OutputCurrentSection(); // Repeat section header
1581 // Experimental JACS
1582 TexOutput(_T("\\par\\pard}\n"));
1583 // TexOutput(_T("\\par\\pard}\\par\n"));
1585 issuedNewParagraph
= 1;
1586 WriteEnvironmentStyles();
1591 case ltSUBSUBSECTION
:
1592 case ltSUBSUBSECTIONSTAR
:
1596 if (winHelp
&& !Subsections
)
1598 OnError(_T("You cannot have a subsubsection before a subsection!"));
1602 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1605 wxChar
*topicName
= FindTopicName(GetNextChunk());
1606 SetCurrentTopic(topicName
);
1607 NotifyParentHasChildren(3);
1608 if (winHelpContents
&& winHelp
)
1610 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1611 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1613 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1617 SetCurrentOutputs(Subsections
, Subsubsections
);
1618 wxFprintf(Subsections
, _T("\n{\\uldb "));
1622 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1624 if (DocumentStyle
== LATEX_ARTICLE
)
1626 SetCurrentOutput(Contents
);
1627 wxFprintf(Contents
, _T("\n\\tab\\tab %d.%d.%d\\tab "),
1628 sectionNo
, subsectionNo
, subsubsectionNo
);
1631 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1634 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1637 if (startedSections
)
1640 wxFprintf(Subsubsections
, _T("\\page\n"));
1641 // Experimental JACS 2004-02-21
1644 wxFprintf(Chapters
, _T("\\par\n"));
1648 startedSections
= true;
1651 wxFprintf(Subsubsections
, _T("\n${\\footnote "));
1653 // Output header to contents page
1654 OutputCurrentSection();
1658 wxFprintf(Subsections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1659 //WriteEnvironmentStyles();
1661 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1662 wxFprintf(Contents
, _T("\\par\\pard\n"));
1664 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1667 wxFprintf(Subsubsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1668 wxFprintf(Subsubsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1669 OutputSectionKeyword(Subsubsections
);
1670 GenerateKeywordsForTopic(topicName
);
1671 if (useUpButton
&& CurrentSubsectionName
)
1673 wxFprintf(Subsubsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1674 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1677 if (!winHelp
&& indexSubsections
&& useWord
)
1679 // Insert index entry for this subsubsection
1680 TexOutput(_T("{\\xe\\v {"));
1681 OutputCurrentSection();
1682 TexOutput(_T("}}"));
1685 wxChar
*styleCommand
= _T("");
1686 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1688 if (DocumentStyle
== LATEX_ARTICLE
)
1689 styleCommand
= _T("\\s3");
1691 styleCommand
= _T("\\s4");
1693 wxChar
*keep
= _T("");
1695 keep
= _T("\\keepn\\sa140\\sb140");
1697 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T("\\pard{%s%s"),
1698 keep
, styleCommand
);
1700 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1701 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1702 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T(" "));
1706 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1708 if (DocumentStyle
== LATEX_ARTICLE
)
1711 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo, subsubsectionNo,
1712 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1715 wxFprintf(Chapters
, _T("%d.%d.%d. "), sectionNo
, subsectionNo
, subsubsectionNo
);
1720 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1721 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1724 wxFprintf(Chapters
, _T("%d.%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1729 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1732 OutputCurrentSection(); // Repeat section header
1733 TexOutput(_T("\\par\\pard}\n"));
1734 issuedNewParagraph
= 1;
1735 WriteEnvironmentStyles();
1736 // TexOutput(_T("\\par\\pard}\\par\n"));
1737 // issuedNewParagraph = 2;
1747 wxChar
*topicName
= FindTopicName(GetNextChunk());
1748 SetCurrentTopic(topicName
);
1750 TexOutput(_T("\\pard\\par"));
1757 if (winHelp
|| !useWord
)
1759 if (DocumentStyle
!= LATEX_ARTICLE
)
1760 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1762 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1766 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1767 FigureNameString
, topicName
, topicName
);
1774 if (winHelp
|| !useWord
)
1776 if (DocumentStyle
!= LATEX_ARTICLE
)
1777 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1779 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1783 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1784 TableNameString
, topicName
, topicName
);
1788 int n
= (inTable
? tableNo
: figureNo
);
1789 AddTexRef(topicName
, NULL
, NULL
,
1790 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1791 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1794 TexOutput(_T("\\qc{\\b "));
1796 TexOutput(_T("\\ql{\\b "));
1799 OutputCurrentSection();
1801 TexOutput(_T("}\\par\\pard\n"));
1802 WriteEnvironmentStyles();
1809 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1816 TexOutput(_T("}\n"));
1819 TexOutput(_T("K{\\footnote {K} "));
1820 suppressNameDecoration
= true;
1821 TraverseChildrenFromChunk(currentMember
);
1822 suppressNameDecoration
= false;
1823 TexOutput(_T("}\n"));
1825 if (!winHelp
&& useWord
)
1827 // Insert index entry for this function
1828 TexOutput(_T("{\\xe\\v {"));
1829 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1830 TraverseChildrenFromChunk(currentMember
);
1831 suppressNameDecoration
= false;
1832 TexOutput(_T("}}"));
1839 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1846 TexOutput(_T("}\n"));
1849 TexOutput(_T("K{\\footnote {K} "));
1850 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1851 TraverseChildrenFromChunk(currentMember
);
1852 suppressNameDecoration
= false;
1853 TexOutput(_T("}\n"));
1855 if (!winHelp
&& useWord
)
1857 // Insert index entry for this function
1858 TexOutput(_T("{\\xe\\v {"));
1859 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1860 TraverseChildrenFromChunk(currentMember
);
1861 suppressNameDecoration
= false;
1862 TexOutput(_T("}}"));
1869 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1872 TexOutput(_T("{\\b "));
1876 TexOutput(_T("}\n"));
1879 TexOutput(_T("K{\\footnote {K} "));
1880 TraverseChildrenFromChunk(currentMember
);
1881 TexOutput(_T("}\n"));
1883 if (!winHelp
&& useWord
)
1885 // Insert index entry for this function
1886 TexOutput(_T("{\\xe\\v {"));
1887 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1888 TraverseChildrenFromChunk(currentMember
);
1889 suppressNameDecoration
= false;
1890 TexOutput(_T("}}"));
1898 SetCurrentOutput(Chapters
);
1901 case ltTABLEOFCONTENTS
:
1905 if (!winHelp
&& useWord
)
1907 // Insert Word for Windows table of contents
1908 TexOutput(_T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
1910 // In linear RTF, same as chapter headings.
1911 wxSnprintf(buf
, sizeof(buf
), _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), chapterFont
*2, ContentsNameString
);
1914 wxSnprintf(buf
, sizeof(buf
), _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth
);
1916 // TexOutput(_T("\\sect\\sectd"));
1920 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1926 wxPutc(ch
, Chapters
);
1933 TexOutput(_T("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n"));
1934 OnInform(_T("Run Tex2RTF again to include contents page."));
1943 // TexOutput(_T("{\\b void}"));
1949 TexOutput(_T("{\\scaps HARDY}"));
1955 TexOutput(_T("wxCLIPS"));
1958 case ltSPECIALAMPERSAND
:
1963 TexOutput(_T("\\cell "));
1969 case ltSPECIALTILDE
:
1973 #if 1 // if(inVerbatim)
1981 case ltBACKSLASHCHAR
:
1987 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
1988 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
1989 int currentWidth
= 0;
1990 for (int i
= 0; i
< noColumns
; i
++)
1992 currentWidth
+= TableData
[i
].width
;
1993 if (TableData
[i
].rightBorder
)
1994 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
1996 if (TableData
[i
].leftBorder
)
1997 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
1999 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
2002 TexOutput(_T("\\pard\\intbl\n"));
2005 TexOutput(_T("\\line\n"));
2012 TexOutput(_T("\tab "));
2015 case ltRTFSP
: // Explicit space, RTF only
2027 if (indentLevel
> 0)
2029 // Experimental JACS 2004-02-21
2030 TexOutput(_T("\\par\n"));
2031 issuedNewParagraph
= 1;
2032 // TexOutput(_T("\\par\\par\n"));
2033 // issuedNewParagraph = 2;
2037 // Top-level list: issue a new paragraph if we haven't
2039 if (!issuedNewParagraph
)
2041 TexOutput(_T("\\par\\pard"));
2042 WriteEnvironmentStyles();
2043 issuedNewParagraph
= 1;
2045 else issuedNewParagraph
= 0;
2048 TexOutput(_T("\\fi0\n"));
2050 if (macroId
== ltENUMERATE
)
2051 listType
= LATEX_ENUMERATE
;
2052 else if (macroId
== ltITEMIZE
)
2053 listType
= LATEX_ITEMIZE
;
2055 listType
= LATEX_DESCRIPTION
;
2058 wxNode
*node
= itemizeStack
.GetFirst();
2060 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2062 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2063 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2065 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2066 itemizeStack
.Insert(struc
);
2068 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\sa200"), indentSize1
, indentSize2
, indentSize2
);
2069 PushEnvironmentStyle(buf
);
2073 currentItemSep
= 8; // Reset to the default
2075 PopEnvironmentStyle();
2077 if (itemizeStack
.GetFirst())
2079 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2081 delete itemizeStack
.GetFirst();
2083 /* Change 18/7/97 - don't know why we wish to do this
2084 if (itemizeStack.Number() == 0)
2086 OnMacro(ltPAR, 0, true);
2087 OnMacro(ltPAR, 0, false);
2088 issuedNewParagraph = 2;
2100 wxNode
*node
= itemizeStack
.GetFirst();
2102 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2104 int indentSize
= oldIndent
+ TwoColWidthA
;
2106 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2107 itemizeStack
.Insert(struc
);
2109 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\ri%d"), indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2110 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200"), indentSize
, indentSize
);
2111 PushEnvironmentStyle(buf
);
2116 PopEnvironmentStyle();
2117 if (itemizeStack
.GetFirst())
2119 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2121 delete itemizeStack
.GetFirst();
2125 TexOutput(_T("\\pard\n"));
2126 WriteEnvironmentStyles();
2128 /* why do we need this? */
2130 TexOutput(_T("\\pard\n"));
2132 if (itemizeStack
.GetCount() == 0)
2134 issuedNewParagraph
= 0;
2135 OnMacro(ltPAR
, 0, true);
2136 OnMacro(ltPAR
, 0, false);
2144 wxNode
*node
= itemizeStack
.GetFirst();
2147 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2150 struc
->currentItem
+= 1;
2151 wxChar indentBuf
[60];
2153 int indentSize1
= struc
->labelIndentation
;
2154 int indentSize2
= struc
->indentation
;
2156 TexOutput(_T("\n"));
2157 if (struc
->currentItem
> 1 && issuedNewParagraph
== 0)
2160 // if (currentItemSep > 0)
2161 // TexOutput(_T("\\par"));
2163 TexOutput(_T("\\par"));
2164 issuedNewParagraph
= 1;
2165 // WriteEnvironmentStyles();
2168 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1
, indentSize2
,
2169 indentSize2
, 20*itemIndentTab
);
2172 switch (struc
->listType
)
2174 case LATEX_ENUMERATE
:
2176 if (descriptionItemArg
)
2178 TexOutput(_T("\\tab{ "));
2179 TraverseChildrenFromChunk(descriptionItemArg
);
2180 TexOutput(_T("}\\tab"));
2181 descriptionItemArg
= NULL
;
2185 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b %d.}\\tab"), struc
->currentItem
);
2186 TexOutput(indentBuf
);
2192 if (descriptionItemArg
)
2194 TexOutput(_T("\\tab{ "));
2195 TraverseChildrenFromChunk(descriptionItemArg
);
2196 TexOutput(_T("}\\tab"));
2197 descriptionItemArg
= NULL
;
2201 if (bulletFile
&& winHelp
)
2203 if (winHelpVersion
> 3) // Transparent bitmap
2204 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmct %s\\}\\tab"), bulletFile
);
2206 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmc %s\\}\\tab"), bulletFile
);
2209 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b o}\\tab"));
2211 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\f1\\'b7}\\tab"));
2212 TexOutput(indentBuf
);
2217 case LATEX_DESCRIPTION
:
2219 if (descriptionItemArg
)
2221 TexOutput(_T("\\tab{\\b "));
2222 TraverseChildrenFromChunk(descriptionItemArg
);
2223 TexOutput(_T("} "));
2224 descriptionItemArg
= NULL
;
2234 case ltTWOCOLITEMRULED
:
2236 wxNode
*node
= itemizeStack
.GetFirst();
2239 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2242 struc
->currentItem
+= 1;
2245 wxNode
*node2
= NULL
;
2246 if (itemizeStack
.GetCount() > 1) // TODO: do I actually mean Nth(0) here??
2247 node2
= itemizeStack
.Item(1);
2249 oldIndent
= ((ItemizeStruc
*)node2
->GetData())->indentation
;
2251 TexOutput(_T("\n"));
2254 if (struc
->currentItem
> 1)
2256 if (currentItemSep
> 0)
2257 TexOutput(_T("\\par"));
2259 // WriteEnvironmentStyles();
2263 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA,
2264 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2266 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA,
2267 TwoColWidthA, TwoColWidthA);
2269 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA
+ oldIndent
,
2270 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2283 if (macroId
== ltVERBATIM
)
2285 if (!issuedNewParagraph
)
2287 TexOutput(_T("\\par\\pard"));
2288 WriteEnvironmentStyles();
2289 issuedNewParagraph
= 1;
2291 else issuedNewParagraph
= 0;
2295 if (macroId
== ltVERBATIM
)
2296 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\s10\\fs20\\li720\\sa0 "));
2298 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\fs20 "));
2304 if (macroId
== ltVERBATIM
)
2306 TexOutput(_T("\\pard\n"));
2307 WriteEnvironmentStyles();
2310 TexOutput(_T("\\par\n"));
2311 issuedNewParagraph
= 1;
2322 TexOutput(_T("\\qc "));
2324 PushEnvironmentStyle(_T("\\qc\\sa200"));
2328 TexOutput(_T("\\par\\pard\n"));
2329 issuedNewParagraph
= 1;
2331 PopEnvironmentStyle();
2332 WriteEnvironmentStyles();
2340 TexOutput(_T("\\ql\\sa200 "));
2342 PushEnvironmentStyle(_T("\\ql"));
2346 TexOutput(_T("\\par\\pard\n"));
2347 issuedNewParagraph
= 1;
2349 PopEnvironmentStyle();
2350 WriteEnvironmentStyles();
2358 TexOutput(_T("\\qr\\sa200 "));
2360 PushEnvironmentStyle(_T("\\qr"));
2364 TexOutput(_T("\\par\\pard\n"));
2365 issuedNewParagraph
= 1;
2367 PopEnvironmentStyle();
2368 WriteEnvironmentStyles();
2373 case ltFOOTNOTESIZE
:
2377 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), smallFont
*2);
2380 else TexOutput(_T("}\n"));
2388 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), tinyFont
*2);
2391 else TexOutput(_T("}\n"));
2398 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), normalFont
*2);
2401 else TexOutput(_T("}\n"));
2408 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), largeFont1
*2);
2411 else TexOutput(_T("}\n"));
2418 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LargeFont2
*2);
2421 else TexOutput(_T("}\n"));
2428 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LARGEFont3
*2);
2431 else TexOutput(_T("}\n"));
2438 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), hugeFont1
*2);
2441 else TexOutput(_T("}\n"));
2448 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HugeFont2
*2);
2451 else TexOutput(_T("}\n"));
2458 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HUGEFont3
*2);
2461 else TexOutput(_T("}\n"));
2470 TexOutput(_T("{\\b "));
2472 else TexOutput(_T("}"));
2479 TexOutput(_T("{\\ul "));
2481 else TexOutput(_T("}"));
2492 TexOutput(_T("{\\i "));
2494 else TexOutput(_T("}"));
2497 // Roman font: do nothing. Should really switch between
2506 TexOutput(_T("{\\plain "));
2508 else TexOutput(_T("}"));
2512 // Medium-weight font. Unbolden...
2517 TexOutput(_T("{\\b0 "));
2519 else TexOutput(_T("}"));
2522 // Upright (un-italic or slant)
2527 TexOutput(_T("{\\i0 "));
2529 else TexOutput(_T("}"));
2538 TexOutput(_T("{\\scaps "));
2540 else TexOutput(_T("}"));
2549 TexOutput(_T("{\\f3 "));
2551 else TexOutput(_T("}"));
2557 TexOutput(_T("\\{"));
2563 TexOutput(_T("\\}"));
2569 TexOutput(_T("\\\\"));
2576 if ( issuedNewParagraph
== 0 )
2578 TexOutput(_T("\\par\\pard"));
2579 issuedNewParagraph
++;
2581 // Extra par if parskip is more than zero (usually looks best.)
2582 // N.B. JACS 2004-02-21: shouldn't need this for linear RTF if
2583 // we have a suitable set of styles.
2585 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2587 TexOutput(_T("\\par"));
2588 issuedNewParagraph
++;
2591 WriteEnvironmentStyles();
2593 // 1 is a whole paragraph if ParSkip == 0,
2594 // half a paragraph if ParSkip > 0
2595 else if ( issuedNewParagraph
== 1 )
2597 // Don't need a par at all if we've already had one,
2598 // and ParSkip == 0.
2600 // Extra par if parskip is more than zero (usually looks best.)
2601 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2603 TexOutput(_T("\\par"));
2604 issuedNewParagraph
++;
2607 WriteEnvironmentStyles();
2610 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2612 TexOutput(_T("\\par\\pard"));
2614 // Extra par if parskip is more than zero (usually looks best.)
2615 if (!inTabular && (ParSkip > 0))
2616 TexOutput(_T("\\par"));
2617 WriteEnvironmentStyles();
2621 TexOutput(_T("\n"));
2627 // In Windows Help, no newpages until we've started some chapters or sections
2628 if (!(winHelp
&& !startedSections
))
2630 TexOutput(_T("\\page\n"));
2635 if (start
&& DocumentTitle
)
2637 TexOutput(_T("\\par\\pard"));
2639 TexOutput(_T("\\par"));
2640 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d\\b "), titleFont
*2);
2642 TraverseChildrenFromChunk(DocumentTitle
);
2643 TexOutput(_T("}\\par\\pard\n"));
2648 TexOutput(_T("\\par"));
2649 wxSnprintf(buf
, sizeof(buf
), _T("\\par\\qc{\\fs%d "), authorFont
*2);
2651 TraverseChildrenFromChunk(DocumentAuthor
);
2653 TexOutput(_T("\\par\\pard\n"));
2657 TexOutput(_T("\\par"));
2658 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d "), authorFont
*2);
2660 TraverseChildrenFromChunk(DocumentDate
);
2661 TexOutput(_T("}\\par\\pard\n"));
2663 // If linear RTF, we want this titlepage to be in a separate
2664 // section with its own (blank) header and footer
2665 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2667 TexOutput(_T("{\\header }{\\footer }\n"));
2668 // Not sure about this: we get too many sections.
2669 // TexOutput(_T("\\sect"));
2674 case ltADDCONTENTSLINE
:
2678 if (contentsLineSection
&& contentsLineValue
)
2680 if (wxStrcmp(contentsLineSection
, _T("chapter")) == 0)
2682 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2684 else if (wxStrcmp(contentsLineSection
, _T("section")) == 0)
2686 if (DocumentStyle
!= LATEX_ARTICLE
)
2687 wxFprintf(Contents
, _T("\n\\tab%s\\par\n"), contentsLineValue
);
2689 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2699 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2700 issuedNewParagraph
= 1;
2701 WriteEnvironmentStyles();
2709 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2710 issuedNewParagraph
= 1;
2711 WriteEnvironmentStyles();
2721 case ltNUMBEREDBIBITEM
:
2724 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
2726 TexOutput(_T("\\par\\pard\\par\n\n"));
2733 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2741 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2742 wxSnprintf(buf
, sizeof(buf
), _T("%d"), chapterNo
);
2751 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2752 wxSnprintf(buf
, sizeof(buf
), _T("%d"), sectionNo
);
2759 if (!start
&& !winHelp
)
2761 TexOutput(_T("\\cols2\n"));
2767 if (!start
&& !winHelp
)
2769 TexOutput(_T("\\cols1\n"));
2775 if (start
&& useWord
&& !winHelp
)
2777 FakeCurrentSection(_T("Index"));
2778 OnMacro(ltPAR
, 0, true);
2779 OnMacro(ltPAR
, 0, false);
2780 TexOutput(_T("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n"));
2784 case ltLISTOFFIGURES
:
2786 if (start
&& useWord
&& !winHelp
)
2788 FakeCurrentSection(FiguresNameString
, false);
2789 OnMacro(ltPAR
, 0, true);
2790 OnMacro(ltPAR
, 0, false);
2791 OnMacro(ltPAR
, 0, true);
2792 OnMacro(ltPAR
, 0, false);
2794 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"),
2800 case ltLISTOFTABLES
:
2802 if (start
&& useWord
&& !winHelp
)
2804 FakeCurrentSection(TablesNameString
, false);
2805 OnMacro(ltPAR
, 0, true);
2806 OnMacro(ltPAR
, 0, false);
2807 OnMacro(ltPAR
, 0, true);
2808 OnMacro(ltPAR
, 0, false);
2810 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"),
2818 if (start
) TexOutput(_T("{\\f1\\'61}"));
2821 if (start
) TexOutput(_T("{\\f1\\'62}"));
2824 if (start
) TexOutput(_T("{\\f1\\'63}"));
2827 if (start
) TexOutput(_T("{\\f1\\'64}"));
2831 if (start
) TexOutput(_T("{\\f1\\'65}"));
2834 if (start
) TexOutput(_T("{\\f1\\'7A}"));
2837 if (start
) TexOutput(_T("{\\f1\\'68}"));
2841 if (start
) TexOutput(_T("{\\f1\\'71}"));
2844 if (start
) TexOutput(_T("{\\f1\\'69}"));
2847 if (start
) TexOutput(_T("{\\f1\\'6B}"));
2850 if (start
) TexOutput(_T("{\\f1\\'6C}"));
2853 if (start
) TexOutput(_T("{\\f1\\'6D}"));
2856 if (start
) TexOutput(_T("{\\f1\\'6E}"));
2859 if (start
) TexOutput(_T("{\\f1\\'78}"));
2862 if (start
) TexOutput(_T("{\\f1\\'70}"));
2865 if (start
) TexOutput(_T("{\\f1\\'76}"));
2869 if (start
) TexOutput(_T("{\\f1\\'72}"));
2872 if (start
) TexOutput(_T("{\\f1\\'73}"));
2875 if (start
) TexOutput(_T("{\\f1\\'56}"));
2878 if (start
) TexOutput(_T("{\\f1\\'74}"));
2881 if (start
) TexOutput(_T("{\\f1\\'75}"));
2885 if (start
) TexOutput(_T("{\\f1\\'66}"));
2888 if (start
) TexOutput(_T("{\\f1\\'63}"));
2891 if (start
) TexOutput(_T("{\\f1\\'79}"));
2894 if (start
) TexOutput(_T("{\\f1\\'77}"));
2897 if (start
) TexOutput(_T("{\\f1\\'47}"));
2900 if (start
) TexOutput(_T("{\\f1\\'44}"));
2903 if (start
) TexOutput(_T("{\\f1\\'51}"));
2906 if (start
) TexOutput(_T("{\\f1\\'4C}"));
2909 if (start
) TexOutput(_T("{\\f1\\'58}"));
2912 if (start
) TexOutput(_T("{\\f1\\'50}"));
2915 if (start
) TexOutput(_T("{\\f1\\'53}"));
2918 if (start
) TexOutput(_T("{\\f1\\'54}"));
2921 if (start
) TexOutput(_T("{\\f1\\'46}"));
2924 if (start
) TexOutput(_T("{\\f1\\'59}"));
2927 if (start
) TexOutput(_T("{\\f1\\'57}"));
2929 // Binary operation symbols
2932 if (start
) TexOutput(_T("{\\f1\\'A3}"));
2935 if (start
) TexOutput(_T("<<"));
2938 if (start
) TexOutput(_T("{\\f1\\'CC}"));
2941 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2944 if (start
) TexOutput(_T("{\\f1\\'CE}"));
2948 if (start
) TexOutput(_T("{\\f1\\'B3}"));
2951 if (start
) TexOutput(_T(">>"));
2954 if (start
) TexOutput(_T("{\\f1\\'C9}"));
2957 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2960 if (start
) TexOutput(_T("{\\f1\\'27}"));
2963 if (start
) TexOutput(_T("{\\f1\\'5E}"));
2966 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2969 if (start
) TexOutput(_T("{\\f1\\'BB}"));
2972 if (start
) TexOutput(_T("{\\f1\\'40}"));
2975 if (start
) TexOutput(_T("{\\f1\\'BA}"));
2978 if (start
) TexOutput(_T("{\\f1\\'B5}"));
2981 if (start
) TexOutput(_T("{\\f1\\'7E}"));
2984 if (start
) TexOutput(_T("{\\f4\\'4A}"));
2987 if (start
) TexOutput(_T("{\\f4\\'4C}"));
2990 if (start
) TexOutput(_T("|"));
2993 // Negated relation symbols
2995 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2998 if (start
) TexOutput(_T("{\\f1\\'CF}"));
3001 if (start
) TexOutput(_T("{\\f1\\'CB}"));
3006 if (start
) TexOutput(_T("{\\f1\\'AC}"));
3009 if (start
) TexOutput(_T("{\\f1\\'DC}"));
3012 if (start
) TexOutput(_T("{\\f1\\'AE}"));
3015 if (start
) TexOutput(_T("{\\f1\\'DE}"));
3017 case ltLEFTRIGHTARROW
:
3018 if (start
) TexOutput(_T("{\\f1\\'AB}"));
3020 case ltLEFTRIGHTARROW2
:
3021 if (start
) TexOutput(_T("{\\f1\\'DB}"));
3024 if (start
) TexOutput(_T("{\\f1\\'AD}"));
3027 if (start
) TexOutput(_T("{\\f1\\'DD}"));
3030 if (start
) TexOutput(_T("{\\f1\\'AF}"));
3033 if (start
) TexOutput(_T("{\\f1\\'DF}"));
3036 // Miscellaneous symbols
3038 if (start
) TexOutput(_T("{\\f1\\'CO}"));
3041 if (start
) TexOutput(_T("{\\f1\\'C3}"));
3044 if (start
) TexOutput(_T("{\\f1\\'C2}"));
3047 if (start
) TexOutput(_T("{\\f1\\'C1}"));
3050 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3053 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3056 if (start
) TexOutput(_T("{\\f1\\'D6}"));
3059 if (start
) TexOutput(_T("{\\f1\\'B6}"));
3062 if (start
) TexOutput(_T("{\\f1\\'5E}"));
3065 if (start
) TexOutput(_T("{\\f1\\'22}"));
3068 if (start
) TexOutput(_T("{\\f1\\'24}"));
3071 if (start
) TexOutput(_T("{\\f1\\'D8}"));
3074 if (start
) TexOutput(_T("{\\f1\\'23}"));
3077 if (start
) TexOutput(_T("{\\f1\\'D0}"));
3080 if (start
) TexOutput(_T("{\\f5\\'73}"));
3083 if (start
) TexOutput(_T("{\\f5\\'A8}"));
3086 if (start
) TexOutput(_T("{\\f5\\'A9}"));
3089 if (start
) TexOutput(_T("{\\f5\\'AA}"));
3092 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3095 if (start
) TexOutput(_T("{\\f1\\'A5}"));
3098 if (start
) TexOutput(_T("{\\f0\\'A9}"));
3101 if (start
) TexOutput(_T("{\\f0\\'AE}"));
3104 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3107 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3110 if (start
) TexOutput(_T("{\\f1\\'B4}"));
3113 if (start
) TexOutput(_T("{\\f1\\'B8}"));
3116 if (start
) TexOutput(_T("{\\f1\\'D7}"));
3119 if (start
) TexOutput(_T("{\\f1\\'2A}"));
3122 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3125 if (start
) TexOutput(_T("{\\f1\\'C7}"));
3128 if (start
) TexOutput(_T("{\\f1\\'C8}"));
3131 if (start
) TexOutput(_T("{\\f1\\'DA}"));
3134 if (start
) TexOutput(_T("{\\f1\\'D9}"));
3137 if (start
) TexOutput(_T("{\\f1\\'B0}"));
3140 if (start
) TexOutput(_T("{\\f1\\'B7}"));
3143 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3146 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3149 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3151 case ltBIGTRIANGLEDOWN
:
3152 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3155 if (start
) TexOutput(_T("{\\f1\\'C5}"));
3158 if (start
) TexOutput(_T("{\\f1\\'C4}"));
3161 if (start
) TexOutput(_T("{\\'DF}"));
3165 if (start
) inFigure
= true;
3166 else inFigure
= false;
3171 if (start
) inTable
= true;
3172 else inTable
= false;
3177 DefaultOnMacro(macroId
, no_args
, start
);
3183 // Called on start/end of argument examination
3184 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3191 case ltCHAPTERHEADING
:
3194 case ltSECTIONHEADING
:
3196 case ltSUBSECTIONSTAR
:
3197 case ltSUBSUBSECTION
:
3198 case ltSUBSUBSECTIONSTAR
:
3200 case ltMEMBERSECTION
:
3201 case ltFUNCTIONSECTION
:
3205 if (!start
&& (arg_no
== 1))
3206 currentSection
= GetArgChunk();
3211 if (start
&& (arg_no
== 1))
3212 TexOutput(_T("\\pard\\li600\\fi-600{\\b "));
3214 if (!start
&& (arg_no
== 1))
3215 TexOutput(_T("} "));
3217 if (start
&& (arg_no
== 2))
3219 if (!suppressNameDecoration
) TexOutput(_T("{\\b "));
3220 currentMember
= GetArgChunk();
3222 if (!start
&& (arg_no
== 2))
3224 if (!suppressNameDecoration
) TexOutput(_T("}"));
3227 if (start
&& (arg_no
== 3))
3229 if (!start
&& (arg_no
== 3))
3231 // TexOutput(_T(")\\li0\\fi0"));
3232 // TexOutput(_T(")\\par\\pard\\li0\\fi0"));
3233 // issuedNewParagraph = 1;
3235 WriteEnvironmentStyles();
3241 if (start
&& (arg_no
== 1))
3242 TexOutput(_T("\\pard\\li260\\fi-260{\\b "));
3243 if (!start
&& (arg_no
== 1))
3244 TexOutput(_T("} "));
3246 if (start
&& (arg_no
== 2))
3248 if (!suppressNameDecoration
) TexOutput(_T("({\\b "));
3249 currentMember
= GetArgChunk();
3251 if (!start
&& (arg_no
== 2))
3253 if (!suppressNameDecoration
) TexOutput(_T("}"));
3256 if (!start
&& (arg_no
== 3))
3258 TexOutput(_T(")\\li0\\fi0"));
3259 WriteEnvironmentStyles();
3265 if (start
&& (arg_no
== 1))
3266 TexOutput(_T("\\pard\\li260\\fi-260"));
3268 if (!start
&& (arg_no
== 1))
3271 if (start
&& (arg_no
== 2))
3272 TexOutput(_T("(*"));
3273 if (!start
&& (arg_no
== 2))
3276 if (start
&& (arg_no
== 2))
3277 currentMember
= GetArgChunk();
3279 if (start
&& (arg_no
== 3))
3281 if (!start
&& (arg_no
== 3))
3283 TexOutput(_T(")\\li0\\fi0"));
3284 WriteEnvironmentStyles();
3290 if (start
&& (arg_no
== 1))
3291 TexOutput(_T("{\\b "));
3292 if (!start
&& (arg_no
== 1))
3294 if (start
&& (arg_no
== 2))
3296 TexOutput(_T("{\\i "));
3298 if (!start
&& (arg_no
== 2))
3306 if (start
&& (arg_no
== 1))
3307 TexOutput(_T("{\\b "));
3308 if (!start
&& (arg_no
== 1))
3309 TexOutput(_T("} ")); // This is the difference from param - one space!
3310 if (start
&& (arg_no
== 2))
3312 TexOutput(_T("{\\i "));
3314 if (!start
&& (arg_no
== 2))
3322 if (!start
&& (arg_no
== 1))
3325 if (start
&& (arg_no
== 2))
3326 currentMember
= GetArgChunk();
3335 wxChar
*refName
= GetArgData();
3336 if (winHelp
|| !useWord
)
3340 TexRef
*texRef
= FindReference(refName
);
3343 sec
= texRef
->sectionNumber
;
3353 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
3365 if ((GetNoArgs() - arg_no
) == 1)
3368 TexOutput(_T("{\\uldb "));
3372 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3376 TexOutput(_T("{\\v "));
3378 // Remove green colour/underlining if specified
3379 if (!hotSpotUnderline
&& !hotSpotColour
)
3381 else if (!hotSpotColour
)
3384 else TexOutput(_T("}"));
3387 else // If a linear document, must resolve the references ourselves
3389 if ((GetNoArgs() - arg_no
) == 1)
3391 // In a linear document we display the anchor text in italic plus
3394 TexOutput(_T("{\\i "));
3399 helpRefText
= GetArgChunk();
3403 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3405 if (macroId
!= ltHELPREFN
)
3407 wxChar
*refName
= GetArgData();
3408 TexRef
*texRef
= NULL
;
3410 texRef
= FindReference(refName
);
3413 if (texRef
|| !ignoreBadRefs
)
3414 TexOutput(_T(" ("));
3417 if (texRef
|| !ignoreBadRefs
)
3421 TexOutput(_T("p. "));
3422 TexOutput(_T("{\\field{\\*\\fldinst PAGEREF "));
3424 TexOutput(_T(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"));
3428 // Only print section name if we're not in Word mode,
3429 // so can't do page references
3432 TexOutput(texRef
->sectionName
);
3434 TexOutput(texRef
->sectionNumber
);
3439 TexOutput(_T("??"));
3440 wxSnprintf(buf
, sizeof(buf
), _T("Warning: unresolved reference '%s'"), refName
);
3446 else TexOutput(_T("??"));
3450 if (texRef
|| !ignoreBadRefs
)
3465 else if (arg_no
== 2)
3470 TexOutput(_T(" ({\\f3 "));
3474 TexOutput(_T("})"));
3485 if ((GetNoArgs() - arg_no
) == 1)
3488 TexOutput(_T("{\\ul "));
3492 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3496 TexOutput(_T("{\\v "));
3498 // Remove green colour/underlining if specified
3499 if (!hotSpotUnderline
&& !hotSpotColour
)
3501 else if (!hotSpotColour
)
3504 else TexOutput(_T("}"));
3507 else // A linear document...
3509 if ((GetNoArgs() - arg_no
) == 1)
3511 // In a linear document we just display the anchor text in italic
3513 TexOutput(_T("{\\i "));
3522 case ltADDCONTENTSLINE
:
3524 if (start
&& !winHelp
)
3527 contentsLineSection
= copystring(GetArgData());
3528 else if (arg_no
== 3)
3529 contentsLineValue
= copystring(GetArgData());
3543 static int imageWidth
= 0;
3544 static int imageHeight
= 0;
3546 if (start
&& (arg_no
== 1))
3548 wxChar
*imageDimensions
= copystring(GetArgData());
3550 // imageWidth - Convert points to TWIPS (1 twip = 1/20th of point)
3551 wxStringTokenizer
tok(imageDimensions
, _T(";:"), wxTOKEN_STRTOK
);
3552 if(tok
.HasMoreTokens())
3554 wxString token
= tok
.GetNextToken();
3555 imageWidth
= (int)(20*ParseUnitArgument(token
));
3562 // imageHeight - Convert points to TWIPS (1 twip = 1/20th of point)
3563 if(tok
.HasMoreTokens())
3565 wxString token
= tok
.GetNextToken();
3566 imageHeight
= (int)(20*ParseUnitArgument(token
));
3573 if (imageDimensions
) // glt
3574 delete [] imageDimensions
;
3577 else if (start
&& (arg_no
== 2 ))
3579 wxChar
*filename
= copystring(GetArgData());
3580 wxString f
= _T("");
3581 if ((winHelp
|| (wxStrcmp(bitmapMethod
, _T("includepicture")) == 0) || (wxStrcmp(bitmapMethod
, _T("import")) == 0)) && useWord
)
3583 if (f
== _T("")) // Try for a .shg (segmented hypergraphics file)
3585 wxStrcpy(buf
, filename
);
3586 StripExtension(buf
);
3587 wxStrcat(buf
, _T(".shg"));
3588 f
= TexPathList
.FindValidPath(buf
);
3590 if (f
== _T("")) // Try for a .bmp
3592 wxStrcpy(buf
, filename
);
3593 StripExtension(buf
);
3594 wxStrcat(buf
, _T(".bmp"));
3595 f
= TexPathList
.FindValidPath(buf
);
3597 if (f
== _T("")) // Try for a metafile instead
3599 wxStrcpy(buf
, filename
);
3600 StripExtension(buf
);
3601 wxStrcat(buf
, _T(".wmf"));
3602 f
= TexPathList
.FindValidPath(buf
);
3608 if (bitmapTransparency
&& (winHelpVersion
> 3))
3609 TexOutput(_T("\\{bmct "));
3611 TexOutput(_T("\\{bmc "));
3612 wxString str
= wxFileNameFromPath(f
);
3613 TexOutput((wxChar
*) (const wxChar
*) str
);
3614 TexOutput(_T("\\}"));
3618 // Microsoft Word method
3619 if (wxStrcmp(bitmapMethod
, _T("import")) == 0)
3620 TexOutput(_T("{\\field{\\*\\fldinst IMPORT "));
3622 TexOutput(_T("{\\field{\\*\\fldinst INCLUDEPICTURE "));
3624 // Full path appears not to be valid!
3625 wxString str
= wxFileNameFromPath(f
);
3626 TexOutput((wxChar
*)(const wxChar
*) str
);
3628 int len = wxStrlen(f);
3629 wxChar smallBuf[2]; smallBuf[1] = 0;
3630 for (int i = 0; i < len; i++)
3633 TexOutput(smallBuf);
3634 if (smallBuf[0] == '\\')
3635 TexOutput(smallBuf);
3638 TexOutput(_T("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}"));
3643 TexOutput(_T("[No BMP or WMF for image file "));
3644 TexOutput(filename
);
3646 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3649 if (filename
) // glt
3654 if (f
== _T("")) // Try for a .bmp
3656 wxStrcpy(buf
, filename
);
3657 StripExtension(buf
);
3658 wxStrcat(buf
, _T(".bmp"));
3659 f
= TexPathList
.FindValidPath(buf
);
3663 FILE *fd
= wxFopen(f
, _T("rb"));
3664 if (OutputBitmapHeader(fd
, winHelp
))
3665 OutputBitmapData(fd
);
3668 wxSnprintf(buf
, sizeof(buf
), _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f
.c_str());
3673 else // Try for a metafile instead
3676 wxStrcpy(buf
, filename
);
3677 StripExtension(buf
);
3678 wxStrcat(buf
, _T(".wmf"));
3679 f
= TexPathList
.FindValidPath(buf
);
3682 // HFILE handle = _lopen(f, READ);
3683 FILE *fd
= wxFopen(f
, _T("rb"));
3684 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3686 OutputMetafileData(fd
);
3690 wxSnprintf(buf
, sizeof(buf
), _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f
.c_str());
3698 TexOutput(_T("[No BMP or WMF for image file "));
3699 TexOutput(filename
);
3701 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3714 case ltSUPERTABULAR
:
3720 currentRowNumber
= 0;
3723 tableVerticalLineLeft
= false;
3724 tableVerticalLineRight
= false;
3725 int currentWidth
= 0;
3727 wxChar
*alignString
= copystring(GetArgData());
3728 ParseTableArgument(alignString
);
3730 // TexOutput(_T("\\trowd\\trgaph108\\trleft-108"));
3731 TexOutput(_T("\\trowd\\trgaph108"));
3733 // Write the first row formatting for compatibility
3734 // with standard Latex
3735 if (compatibilityMode
)
3737 for (int i
= 0; i
< noColumns
; i
++)
3739 currentWidth
+= TableData
[i
].width
;
3740 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
3743 TexOutput(_T("\\pard\\intbl\n"));
3745 delete[] alignString
;
3750 else if (arg_no
== 2 && !start
)
3752 TexOutput(_T("\\pard\n"));
3753 WriteEnvironmentStyles();
3764 TexOutput(_T("\\li360\n"));
3766 PushEnvironmentStyle(_T("\\li360\\sa200"));
3771 PopEnvironmentStyle();
3772 OnMacro(ltPAR
, 0, true);
3773 OnMacro(ltPAR
, 0, false);
3781 TexOutput(_T("\\li360\n"));
3782 PushEnvironmentStyle(_T("\\li360\\sa200"));
3786 PopEnvironmentStyle();
3787 OnMacro(ltPAR
, 0, true);
3788 OnMacro(ltPAR
, 0, false);
3800 wxSnprintf(buf
, sizeof(buf
), _T("\\sa200\\box\\trgaph108%s\n"), ((macroId
== ltNORMALBOXD
) ? _T("\\brdrdb") : _T("\\brdrs")));
3802 PushEnvironmentStyle(buf
);
3806 PopEnvironmentStyle();
3807 OnMacro(ltPAR
, 0, true);
3808 OnMacro(ltPAR
, 0, false);
3812 case ltHELPFONTSIZE
:
3816 wxChar
*data
= GetArgData();
3817 if (wxStrcmp(data
, _T("10")) == 0)
3819 else if (wxStrcmp(data
, _T("11")) == 0)
3821 else if (wxStrcmp(data
, _T("12")) == 0)
3823 wxSnprintf(buf
, sizeof(buf
), _T("\\fs%d\n"), normalFont
*2);
3830 case ltHELPFONTFAMILY
:
3834 wxChar
*data
= GetArgData();
3835 if (wxStrcmp(data
, _T("Swiss")) == 0)
3836 TexOutput(_T("\\f2\n"));
3837 else if (wxStrcmp(data
, _T("Symbol")) == 0)
3838 TexOutput(_T("\\f1\n"));
3839 else if (wxStrcmp(data
, _T("Times")) == 0)
3840 TexOutput(_T("\\f0\n"));
3848 if (start
&& arg_no
== 1)
3850 wxChar
*data
= GetArgData();
3851 ParIndent
= ParseUnitArgument(data
);
3852 if (ParIndent
== 0 || forbidParindent
== 0)
3854 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d\n"), ParIndent
*20);
3863 if (start
&& IsArgOptional())
3865 descriptionItemArg
= GetArgChunk();
3871 case ltTWOCOLITEMRULED
:
3878 TexOutput(_T("\\tab "));
3885 if (macroId
== ltTWOCOLITEMRULED
)
3886 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
3887 TexOutput(_T("\\par\\pard\n"));
3888 issuedNewParagraph
= 1;
3889 WriteEnvironmentStyles();
3900 case ltACCENT_GRAVE
:
3904 wxChar
*val
= GetArgData();
3910 TexOutput(_T("\\'e0"));
3913 TexOutput(_T("\\'e8"));
3916 TexOutput(_T("\\'ec"));
3919 TexOutput(_T("\\'f2"));
3922 TexOutput(_T("\\'f9"));
3925 TexOutput(_T("\\'c0"));
3928 TexOutput(_T("\\'c8"));
3931 TexOutput(_T("\\'cc"));
3934 TexOutput(_T("\\'d2"));
3937 TexOutput(_T("\\'d9"));
3946 case ltACCENT_ACUTE
:
3950 wxChar
*val
= GetArgData();
3956 TexOutput(_T("\\'e1"));
3959 TexOutput(_T("\\'e9"));
3962 TexOutput(_T("\\'ed"));
3965 TexOutput(_T("\\'f3"));
3968 TexOutput(_T("\\'fa"));
3971 TexOutput(_T("\\'fd"));
3974 TexOutput(_T("\\'c1"));
3977 TexOutput(_T("\\'c9"));
3980 TexOutput(_T("\\'cd"));
3983 TexOutput(_T("\\'d3"));
3986 TexOutput(_T("\\'da"));
3989 TexOutput(_T("\\'dd"));
3998 case ltACCENT_CARET
:
4002 wxChar
*val
= GetArgData();
4008 TexOutput(_T("\\'e2"));
4011 TexOutput(_T("\\'ea"));
4014 TexOutput(_T("\\'ee"));
4017 TexOutput(_T("\\'f4"));
4020 TexOutput(_T("\\'fb"));
4023 TexOutput(_T("\\'c2"));
4026 TexOutput(_T("\\'ca"));
4029 TexOutput(_T("\\'ce"));
4032 TexOutput(_T("\\'d4"));
4035 TexOutput(_T("\\'db"));
4044 case ltACCENT_TILDE
:
4048 wxChar
*val
= GetArgData();
4054 TexOutput(_T("\\'e3"));
4060 TexOutput(_T("\\'f1"));
4063 TexOutput(_T("\\'f5"));
4066 TexOutput(_T("\\'c3"));
4069 TexOutput(_T("\\'d1"));
4072 TexOutput(_T("\\'d5"));
4081 case ltACCENT_UMLAUT
:
4085 wxChar
*val
= GetArgData();
4091 TexOutput(_T("\\'e4"));
4094 TexOutput(_T("\\'eb"));
4097 TexOutput(_T("\\'ef"));
4100 TexOutput(_T("\\'f6"));
4103 TexOutput(_T("\\'fc"));
4106 TexOutput(_T("\\'df"));
4109 TexOutput(_T("\\'ff"));
4112 TexOutput(_T("\\'c4"));
4115 TexOutput(_T("\\'cb"));
4118 TexOutput(_T("\\'cf"));
4121 TexOutput(_T("\\'d6"));
4124 TexOutput(_T("\\'dc"));
4127 TexOutput(_T("\\'df"));
4140 wxChar
*val
= GetArgData();
4146 TexOutput(_T("\\'e5"));
4149 TexOutput(_T("\\'c5"));
4158 case ltACCENT_CADILLA
:
4162 wxChar
*val
= GetArgData();
4168 TexOutput(_T("\\'e7"));
4171 TexOutput(_T("\\'c7"));
4182 static wxChar
*helpTopic
= NULL
;
4183 static FILE *savedOutput
= NULL
;
4190 OnInform(_T("Consider using \\footnotepopup instead of \\footnote."));
4193 wxSnprintf(footBuf
, sizeof(footBuf
), _T("(%d)"), footnoteCount
);
4195 TexOutput(_T(" {\\ul "));
4198 helpTopic
= FindTopicName(NULL
);
4199 TexOutput(_T("{\\v "));
4201 // Remove green colour/underlining if specified
4202 if (!hotSpotUnderline
&& !hotSpotColour
)
4204 else if (!hotSpotColour
)
4207 TexOutput(helpTopic
);
4210 wxFprintf(Popups
, _T("\\page\n"));
4211 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4212 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4213 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4214 savedOutput
= CurrentOutput1
;
4215 SetCurrentOutput(Popups
);
4219 SetCurrentOutput(savedOutput
);
4229 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4233 TexOutput(_T("}}"), true);
4238 case ltFOOTNOTEPOPUP
:
4240 static wxChar
*helpTopic
= NULL
;
4241 static FILE *savedOutput
= NULL
;
4248 TexOutput(_T("{\\ul "));
4256 else if (arg_no
== 2)
4260 helpTopic
= FindTopicName(NULL
);
4261 TexOutput(_T("{\\v "));
4263 // Remove green colour/underlining if specified
4264 if (!hotSpotUnderline
&& !hotSpotColour
)
4266 else if (!hotSpotColour
)
4269 TexOutput(helpTopic
);
4272 wxFprintf(Popups
, _T("\\page\n"));
4273 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4274 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4275 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4276 savedOutput
= CurrentOutput1
;
4277 SetCurrentOutput(Popups
);
4281 SetCurrentOutput(savedOutput
);
4292 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4296 TexOutput(_T("}}"), true);
4304 if (start
&& (arg_no
== 1))
4316 if (winHelp
) return false;
4322 LeftHeaderEven
= GetArgChunk();
4323 if (wxStrlen(GetArgData(LeftHeaderEven
)) == 0)
4324 LeftHeaderEven
= NULL
;
4327 CentreHeaderEven
= GetArgChunk();
4328 if (wxStrlen(GetArgData(CentreHeaderEven
)) == 0)
4329 CentreHeaderEven
= NULL
;
4332 RightHeaderEven
= GetArgChunk();
4333 if (wxStrlen(GetArgData(RightHeaderEven
)) == 0)
4334 RightHeaderEven
= NULL
;
4337 LeftHeaderOdd
= GetArgChunk();
4338 if (wxStrlen(GetArgData(LeftHeaderOdd
)) == 0)
4339 LeftHeaderOdd
= NULL
;
4342 CentreHeaderOdd
= GetArgChunk();
4343 if (wxStrlen(GetArgData(CentreHeaderOdd
)) == 0)
4344 CentreHeaderOdd
= NULL
;
4347 RightHeaderOdd
= GetArgChunk();
4348 if (wxStrlen(GetArgData(RightHeaderOdd
)) == 0)
4349 RightHeaderOdd
= NULL
;
4350 OutputRTFHeaderCommands();
4365 if (winHelp
) return false;
4371 LeftFooterEven
= GetArgChunk();
4372 if (wxStrlen(GetArgData(LeftFooterEven
)) == 0)
4373 LeftFooterEven
= NULL
;
4376 CentreFooterEven
= GetArgChunk();
4377 if (wxStrlen(GetArgData(CentreFooterEven
)) == 0)
4378 CentreFooterEven
= NULL
;
4381 RightFooterEven
= GetArgChunk();
4382 if (wxStrlen(GetArgData(RightFooterEven
)) == 0)
4383 RightFooterEven
= NULL
;
4386 LeftFooterOdd
= GetArgChunk();
4387 if (wxStrlen(GetArgData(LeftFooterOdd
)) == 0)
4388 LeftFooterOdd
= NULL
;
4391 CentreFooterOdd
= GetArgChunk();
4392 if (wxStrlen(GetArgData(CentreFooterOdd
)) == 0)
4393 CentreFooterOdd
= NULL
;
4396 RightFooterOdd
= GetArgChunk();
4397 if (wxStrlen(GetArgData(RightFooterOdd
)) == 0)
4398 RightFooterOdd
= NULL
;
4399 OutputRTFFooterCommands();
4409 if (winHelp
) return false;
4410 // Fake a SetHeader command
4413 LeftHeaderOdd
= NULL
;
4414 CentreHeaderOdd
= NULL
;
4415 RightHeaderOdd
= NULL
;
4416 LeftHeaderEven
= NULL
;
4417 CentreHeaderEven
= NULL
;
4418 RightHeaderEven
= NULL
;
4419 OnInform(_T("Consider using setheader/setfooter rather than markright."));
4421 RTFOnArgument(ltSETHEADER
, 4, start
);
4423 OutputRTFHeaderCommands();
4428 if (winHelp
) return false;
4429 // Fake a SetHeader command
4436 LeftHeaderOdd
= NULL
;
4437 CentreHeaderOdd
= NULL
;
4438 RightHeaderOdd
= NULL
;
4439 LeftHeaderEven
= NULL
;
4440 CentreHeaderEven
= NULL
;
4441 RightHeaderEven
= NULL
;
4442 OnInform(_T("Consider using setheader/setfooter rather than markboth."));
4444 return RTFOnArgument(ltSETHEADER
, 1, start
);
4448 RTFOnArgument(ltSETHEADER
, 4, start
);
4450 OutputRTFHeaderCommands();
4456 case ltPAGENUMBERING
:
4463 if (winHelp
) return false;
4466 TexOutput(_T("\\pgnrestart"));
4467 wxChar
*data
= GetArgData();
4468 if (currentNumberStyle
) delete[] currentNumberStyle
;
4469 currentNumberStyle
= copystring(data
);
4470 OutputNumberStyle(currentNumberStyle
);
4472 TexOutput(_T("\n"));
4478 if (winHelp
) return false;
4487 wxChar
*val
= GetArgData();
4488 currentItemSep
= ParseUnitArgument(val
);
4493 case ltEVENSIDEMARGIN
:
4497 case ltODDSIDEMARGIN
:
4501 wxChar
*val
= GetArgData();
4502 int twips
= (int)(20*ParseUnitArgument(val
));
4503 // Add an inch since in LaTeX it's specified minus an inch
4505 CurrentLeftMarginOdd
= twips
;
4506 wxSnprintf(buf
, sizeof(buf
), _T("\\margl%d\n"), twips
);
4509 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4513 case ltMARGINPARWIDTH
:
4517 wxChar
*val
= GetArgData();
4518 int twips
= (int)(20*ParseUnitArgument(val
));
4519 CurrentMarginParWidth
= twips
;
4523 case ltMARGINPARSEP
:
4527 wxChar
*val
= GetArgData();
4528 int twips
= (int)(20*ParseUnitArgument(val
));
4529 CurrentMarginParSep
= twips
;
4530 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4538 wxChar
*val
= GetArgData();
4539 int twips
= (int)(20*ParseUnitArgument(val
));
4540 CurrentTextWidth
= twips
;
4542 // Need to set an implicit right margin
4543 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4544 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4545 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4546 wxSnprintf(buf
, sizeof(buf
), _T("\\margr%d\n"), CurrentRightMarginOdd
);
4552 case ltMARGINPARODD
:
4558 TexOutput(_T("\\sa200\\box\n"));
4559 PushEnvironmentStyle(_T("\\sa200\\box"));
4563 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4572 TexOutput(_T("\\par\\pard\n"));
4573 PopEnvironmentStyle();
4574 WriteEnvironmentStyles();
4577 TexOutput(_T("\\par\\pard\n"));
4578 issuedNewParagraph
= 1;
4582 case ltMARGINPAREVEN
:
4588 TexOutput(_T("\\sa200\\box\n"));
4589 PushEnvironmentStyle(_T("\\sa200\\box"));
4595 // Have to calculate what the margins are changed to in WfW margin
4596 // mirror mode, on an even (left-hand) page.
4597 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4598 - CurrentTextWidth
+ GutterWidth
;
4599 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), x
, CurrentMarginParWidth
);
4604 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4614 TexOutput(_T("\\par\\pard\n"));
4615 PopEnvironmentStyle();
4616 WriteEnvironmentStyles();
4619 issuedNewParagraph
= 1;
4620 TexOutput(_T("\\par\\pard\n"));
4624 case ltTWOCOLWIDTHA
:
4628 wxChar
*val
= GetArgData();
4629 int twips
= (int)(20*ParseUnitArgument(val
));
4630 TwoColWidthA
= twips
;
4634 case ltTWOCOLWIDTHB
:
4638 wxChar
*val
= GetArgData();
4639 int twips
= (int)(20*ParseUnitArgument(val
));
4640 TwoColWidthB
= twips
;
4649 int currentWidth
= 0;
4651 if (!compatibilityMode
|| (currentRowNumber
> 0))
4653 TexOutput(_T("\\pard\\intbl"));
4655 if (macroId
== ltRULEDROW
)
4657 for (int i
= 0; i
< noColumns
; i
++)
4659 currentWidth
+= TableData
[i
].width
;
4662 TexOutput(_T("\\clbrdrt\\brdrs\\brdrw15"));
4664 else if (ruleTop
> 1)
4666 TexOutput(_T("\\clbrdrt\\brdrdb\\brdrw15"));
4668 if (ruleBottom
== 1)
4670 TexOutput(_T("\\clbrdrb\\brdrs\\brdrw15"));
4672 else if (ruleBottom
> 1)
4674 TexOutput(_T("\\clbrdrb\\brdrdb\\brdrw15"));
4677 if (TableData
[i
].rightBorder
)
4678 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
4680 if (TableData
[i
].leftBorder
)
4681 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
4683 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
4686 TexOutput(_T("\\pard\\intbl\n"));
4690 currentRowNumber
++;
4695 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
4696 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
4702 static int noMultiColumns
= 0;
4709 noMultiColumns
= wxAtoi(GetArgData());
4726 for (int i
= 1; i
< noMultiColumns
; i
++)
4727 TexOutput(_T("\\cell"));
4734 if (start
&& (arg_no
== 1))
4737 // TexOutput(_T("\\fi0\n"));
4739 wxNode
*node
= itemizeStack
.GetFirst();
4741 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
4743 int indentValue
= 20*ParseUnitArgument(GetArgData());
4744 int indentSize
= indentValue
+ oldIndent
;
4746 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4747 itemizeStack
.Insert(struc
);
4749 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200 "), indentSize
, indentSize
);
4750 PushEnvironmentStyle(buf
);
4754 if (!start
&& (arg_no
== 2))
4756 PopEnvironmentStyle();
4757 if (itemizeStack
.GetFirst())
4759 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
4761 delete itemizeStack
.GetFirst();
4763 if (itemizeStack
.GetCount() == 0)
4765 TexOutput(_T("\\par\\pard\n"));
4766 issuedNewParagraph
= 1;
4767 WriteEnvironmentStyles();
4776 if (start && (arg_no == 1))
4779 wxNode *node = itemizeStack.GetFirst();
4781 oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
4783 int boxWidth = 20*ParseUnitArgument(GetArgData());
4785 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4786 int indentSize = indentValue + oldIndent;
4787 int indentSizeRight = indentSize + boxWidth;
4789 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4790 itemizeStack.Insert(struc);
4792 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\lr%d\\sa200\\box%s "), indentSize, indentSize, indentSizeRight,
4793 ((macroId == ltCENTEREDBOX) ? _T("\\brdrs") : _T("\\brdrdb")));
4794 PushEnvironmentStyle(buf);
4798 if (!start && (arg_no == 2))
4800 PopEnvironmentStyle();
4801 if (itemizeStack.GetFirst())
4803 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
4805 delete itemizeStack.GetFirst();
4807 if (itemizeStack.Number() == 0)
4809 TexOutput(_T("\\par\\pard\n"));
4810 issuedNewParagraph = 1;
4811 WriteEnvironmentStyles();
4818 case ltDOCUMENTSTYLE
:
4820 DefaultOnArgument(macroId
, arg_no
, start
);
4821 if (!start
&& !IsArgOptional())
4823 if (MinorDocumentStyleString
)
4825 if (StringMatch(_T("twoside"), MinorDocumentStyleString
))
4826 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4827 TexOutput(_T("\\margmirror\\facingp\\sbkodd"));
4828 if (StringMatch(_T("twocolumn"), MinorDocumentStyleString
))
4829 TexOutput(_T("\\cols2"));
4831 TexOutput(_T("\n"));
4835 case ltSETHOTSPOTCOLOUR
:
4836 case ltSETHOTSPOTCOLOR
:
4840 wxChar
*text
= GetArgData();
4841 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4842 hotSpotColour
= true;
4844 hotSpotColour
= false;
4848 case ltSETTRANSPARENCY
:
4852 wxChar
*text
= GetArgData();
4853 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4854 bitmapTransparency
= true;
4856 bitmapTransparency
= false;
4860 case ltSETHOTSPOTUNDERLINE
:
4864 wxChar
*text
= GetArgData();
4865 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4866 hotSpotUnderline
= true;
4868 hotSpotUnderline
= false;
4874 if (arg_no
== 1 && start
)
4876 wxChar
*citeKey
= GetArgData();
4877 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4880 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4881 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
4882 ref
->sectionNumber
= copystring(buf
);
4885 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
4886 wxSnprintf(buf
, sizeof(buf
), _T("{\\b [%d]} "), citeCount
);
4891 if (arg_no
== 2 && !start
)
4892 TexOutput(_T("\\par\\pard\\par\n\n"));
4895 case ltTHEBIBLIOGRAPHY
:
4897 if (start
&& (arg_no
== 1))
4901 SetCurrentOutputs(Contents
, Chapters
);
4905 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
4907 // If a non-custom page style, we generate the header now.
4908 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
4909 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
4910 wxStrcmp(PageStyle
, _T("headings")) == 0))
4912 OutputRTFHeaderCommands();
4913 OutputRTFFooterCommands();
4916 // Need to reset the current numbering style, or RTF forgets it.
4917 OutputNumberStyle(currentNumberStyle
);
4918 SetCurrentOutput(Contents
);
4921 wxFprintf(Chapters
, _T("\\page\n"));
4924 wxFprintf(Contents
, _T("\n{\\uldb %s}"), ReferencesNameString
);
4926 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %s}"), ReferencesNameString
);
4928 startedSections
= true;
4931 wxFprintf(Chapters
, _T("\n${\\footnote %s}"), ReferencesNameString
);
4933 wxChar
*topicName
= _T("bibliography");
4937 wxFprintf(Contents
, _T("{\\v %s}\\par\\pard\n"), topicName
);
4938 WriteEnvironmentStyles();
4941 wxFprintf(Contents
, _T("\\par\\par\\pard\n"));
4945 wxFprintf(Chapters
, _T("\n#{\\footnote %s}\n"), topicName
);
4946 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
4947 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ReferencesNameString
);
4948 GenerateKeywordsForTopic(topicName
);
4951 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
4952 wxFileNameFromPath(FileRoot
), "Contents");
4956 SetCurrentOutput(Chapters
);
4957 wxChar
*styleCommand
= _T("");
4958 if (!winHelp
&& useHeadingStyles
)
4959 styleCommand
= _T("\\s1");
4960 wxFprintf(Chapters
, _T("\\pard{%s"), (winHelp
? _T("\\keepn\\sa140\\sb140") : styleCommand
));
4961 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" References\\par\\pard}\n"));
4970 * In Windows help, all keywords should be at the start of the
4971 * topic, but Latex \index commands can be anywhere in the text.
4972 * So we're going to have to build up lists of keywords for a topic,
4973 * and insert them on the second pass.
4975 * In linear RTF, we can embed the index entry now.
4980 // wxChar *entry = GetArgData();
4982 OutputChunkToString(GetArgChunk(), buf
);
4987 AddKeyWordForTopic(CurrentTopic
, buf
);
4990 else GenerateIndexEntry(buf
);
5003 wxChar
*name
= GetArgData();
5004 int pos
= FindColourPosition(name
);
5007 wxSnprintf(buf
, sizeof(buf
), _T("{%s%d "), ((macroId
== ltFCOL
) ? _T("\\cf") : _T("\\cb")), pos
);
5012 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
5027 if (arg_no
== 2) TexOutput(_T("}"));
5033 if (start
&& !winHelp
&& useWord
)
5035 wxChar
*s
= GetArgData();
5036 // Only insert a bookmark here if it's not just been inserted
5037 // in a section heading.
5038 if ( !CurrentTopic
|| !(wxStrcmp(CurrentTopic
, s
) == 0) )
5040 if ( (!CurrentChapterName || !(CurrentChapterName && (wxStrcmp(CurrentChapterName, s) == 0))) &&
5041 (!CurrentSectionName || !(CurrentSectionName && (wxStrcmp(CurrentSectionName, s) == 0))) &&
5042 (!CurrentSubsectionName || !(CurrentSubsectionName && (wxStrcmp(CurrentSubsectionName, s) == 0)))
5046 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), s
,s
);
5053 if (start
&& useWord
&& !winHelp
)
5055 wxChar
*s
= GetArgData();
5056 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
5064 inPopRefSection
= true;
5066 inPopRefSection
= false;
5069 case ltINSERTATLEVEL
:
5071 // This macro allows you to insert text at a different level
5072 // from the current level, e.g. into the Sections from within a subsubsection.
5073 if (!winHelp
& useWord
)
5075 static int currentLevelNo
= 1;
5076 static FILE* oldLevelFile
= Chapters
;
5083 oldLevelFile
= CurrentOutput1
;
5085 wxChar
*str
= GetArgData();
5086 currentLevelNo
= wxAtoi(str
);
5088 // TODO: cope with article style (no chapters)
5089 switch (currentLevelNo
)
5093 outputFile
= Chapters
;
5098 outputFile
= Sections
;
5103 outputFile
= Subsections
;
5108 outputFile
= Subsubsections
;
5118 CurrentOutput1
= outputFile
;
5134 CurrentOutput1
= oldLevelFile
;
5140 return DefaultOnArgument(macroId
, arg_no
, start
);
5152 forbidParindent
= 0;
5153 contentsLineSection
= NULL
;
5154 contentsLineValue
= NULL
;
5155 descriptionItemArg
= NULL
;
5160 tableVerticalLineLeft
= false;
5161 tableVerticalLineRight
= false;
5163 startedSections
= false;
5167 if (!InputFile
.empty() && !OutputFile
.empty())
5169 // Do some RTF-specific transformations on all the strings,
5171 Text2RTF(GetTopLevelChunk());
5173 Contents
= wxFopen(TmpContentsName
, _T("w"));
5174 Chapters
= wxFopen(_T("chapters.rtf"), _T("w"));
5177 Sections
= wxFopen(_T("sections.rtf"), _T("w"));
5178 Subsections
= wxFopen(_T("subsections.rtf"), _T("w"));
5179 Subsubsections
= wxFopen(_T("subsubsections.rtf"), _T("w"));
5180 Popups
= wxFopen(_T("popups.rtf"), _T("w"));
5181 if (winHelpContents
)
5183 WinHelpContentsFile
= wxFopen(WinHelpContentsFileName
, _T("w"));
5184 if (WinHelpContentsFile
)
5185 wxFprintf(WinHelpContentsFile
, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot
));
5188 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5190 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5194 if (!Contents
|| !Chapters
)
5196 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5202 wxFprintf(Chapters
, _T("\n#{\\footnote Contents}\n"));
5203 wxFprintf(Chapters
, _T("${\\footnote Contents}\n"));
5204 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
5205 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ContentsNameString
);
5206 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
5210 wxFprintf(Chapters
, _T("\\titlepg\n"));
5211 wxFprintf(Contents
, _T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
5214 // In WinHelp, Contents title takes font of title.
5215 // In linear RTF, same as chapter headings.
5216 wxFprintf(Contents
, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"),
5217 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5219 // By default, Swiss, 11 point.
5220 wxFprintf(Chapters
, _T("\\f2\\fs22\n"));
5222 PushEnvironmentStyle(_T("\\f2\\fs22\\sa200"));
5224 SetCurrentOutput(Chapters
);
5229 OnInform(_T("Converting..."));
5233 FILE *Header
= wxFopen(_T("header.rtf"), _T("w"));
5236 OnError(_T("Ouch! Could not open temporary file header.rtf for writing."));
5239 WriteRTFHeader(Header
);
5242 PopEnvironmentStyle();
5247 // wxFprintf(Contents, _T("\\page\n"));
5248 wxFprintf(Chapters
, _T("\\page\n"));
5249 wxFprintf(Sections
, _T("\\page\n"));
5250 wxFprintf(Subsections
, _T("\\page\n"));
5251 wxFprintf(Subsubsections
, _T("\\page\n\n"));
5252 wxFprintf(Popups
, _T("\\page\n}\n"));
5255 // TexOutput(_T("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n"));
5257 TexOutput(_T("}\n"));
5258 fclose(Contents
); Contents
= NULL
;
5259 fclose(Chapters
); Chapters
= NULL
;
5262 fclose(Sections
); Sections
= NULL
;
5263 fclose(Subsections
); Subsections
= NULL
;
5264 fclose(Subsubsections
); Subsubsections
= NULL
;
5265 fclose(Popups
); Popups
= NULL
;
5266 if (winHelpContents
)
5268 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5274 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5276 wxConcatFiles(_T("tmp1.rtf"), _T("sections.rtf"), _T("tmp2.rtf"));
5278 wxConcatFiles(_T("tmp2.rtf"), _T("subsections.rtf"), _T("tmp3.rtf"));
5280 wxConcatFiles(_T("tmp3.rtf"), _T("subsubsections.rtf"), _T("tmp4.rtf"));
5282 wxConcatFiles(_T("tmp4.rtf"), _T("popups.rtf"), OutputFile
);
5285 wxRemoveFile(_T("tmp1.rtf"));
5286 wxRemoveFile(_T("tmp2.rtf"));
5287 wxRemoveFile(_T("tmp3.rtf"));
5288 wxRemoveFile(_T("tmp4.rtf"));
5292 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5294 if (wxFileExists(OutputFile
))
5295 wxRemoveFile(OutputFile
);
5297 wxString cwdStr
= wxGetCwd();
5299 wxString outputDirStr
= wxPathOnly(OutputFile
);
5301 // Determine if the temp file and the output file are in the same directory,
5302 // and if they are, then just rename the temp file rather than copying
5303 // it, as this is much faster when working with large (multi-megabyte files)
5304 if ((outputDirStr
.empty()) || // no path specified on output file
5305 (cwdStr
!= outputDirStr
)) // paths do not match
5307 wxRenameFile(_T("tmp1.rtf"), OutputFile
);
5311 wxCopyFile(_T("tmp1.rtf"), OutputFile
);
5314 wxRemoveFile(_T("tmp1.rtf"));
5317 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5319 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5321 wxCopyFile(TmpContentsName
, ContentsName
);
5322 wxRemoveFile(TmpContentsName
);
5325 wxRemoveFile(_T("chapters.rtf"));
5326 wxRemoveFile(_T("header.rtf"));
5330 wxRemoveFile(_T("sections.rtf"));
5331 wxRemoveFile(_T("subsections.rtf"));
5332 wxRemoveFile(_T("subsubsections.rtf"));
5333 wxRemoveFile(_T("popups.rtf"));
5335 if (winHelp
&& generateHPJ
)
5336 WriteHPJ(OutputFile
);