1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to Word RTF/WinHelp RTF
4 // Author: Julian Smart
5 // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
40 #if !WXWIN_COMPATIBILITY_2_4
41 static inline wxChar
* copystring(const wxChar
* s
)
42 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
46 static int indentLevel
= 0;
47 static int forbidParindent
= 0; // if > 0, no parindent (e.g. in center environment)
48 int forbidResetPar
= 0; // If > 0, don't reset memory of having output a new par
50 static wxChar
*contentsLineSection
= NULL
;
51 static wxChar
*contentsLineValue
= NULL
;
52 static TexChunk
*descriptionItemArg
= NULL
;
53 static wxStringList environmentStack
; // Stack of paragraph styles we need to remember
54 static int footnoteCount
= 0;
55 static int citeCount
= 1;
57 extern bool startedSections
;
58 extern FILE *Contents
;
59 extern FILE *Chapters
;
61 extern FILE *WinHelpContentsFile
;
62 extern wxChar
*RTFCharset
;
63 // This is defined in the Tex2Any library and isn't in use after parsing
64 extern wxChar
*BigBuffer
;
66 extern wxHashTable TexReferences
;
68 // Are we in verbatim mode? If so, format differently.
69 static bool inVerbatim
= false;
71 // We're in a series of PopRef topics, so don't output section headings
72 bool inPopRefSection
= false;
75 static bool hotSpotColour
= true;
76 static bool hotSpotUnderline
= true;
78 // Transparency (WHITE = transparent)
79 static bool bitmapTransparency
= true;
81 // Linear RTF requires us to set the style per section.
82 static wxChar
*currentNumberStyle
= NULL
;
83 static int currentItemSep
= 8;
84 static int CurrentTextWidth
= 8640; // Say, six inches
85 static int CurrentLeftMarginOdd
= 400;
86 static int CurrentLeftMarginEven
= 1440;
87 static int CurrentRightMarginOdd
= 1440;
88 static int CurrentRightMarginEven
= 400;
89 static int CurrentMarginParWidth
= 2000;
90 static int CurrentMarginParSep
= 400; // Gap between marginpar and text
91 static int CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
92 static int GutterWidth
= 2300;
94 // Two-column table dimensions, in twips
95 static int TwoColWidthA
= 1500;
96 static int TwoColWidthB
= 3000;
98 const int PageWidth
= 12242; // 8.25 inches wide for A4
100 // Remember the anchor in a helpref
101 static TexChunk
*helpRefText
= NULL
;
104 * Flag to say we've just issued a \par\pard command, so don't
105 * repeat this unnecessarily.
109 int issuedNewParagraph
= 0;
111 // Need to know whether we're in a table or figure for benefit
112 // of listoffigures/listoftables
113 static bool inFigure
= false;
114 static bool inTable
= false;
120 static wxChar
*CurrentChapterName
= NULL
;
121 static wxChar
*CurrentSectionName
= NULL
;
122 static wxChar
*CurrentSubsectionName
= NULL
;
123 static wxChar
*CurrentTopic
= NULL
;
125 static bool InPopups()
127 if (CurrentChapterName
&& (wxStrcmp(CurrentChapterName
, _T("popups")) == 0))
129 if (CurrentSectionName
&& (wxStrcmp(CurrentSectionName
, _T("popups")) == 0))
134 static void SetCurrentTopic(wxChar
*s
)
136 if (CurrentTopic
) delete[] CurrentTopic
;
137 CurrentTopic
= copystring(s
);
140 void SetCurrentChapterName(wxChar
*s
)
142 if (CurrentChapterName
) delete[] CurrentChapterName
;
143 CurrentChapterName
= copystring(s
);
146 void SetCurrentSectionName(wxChar
*s
)
148 if (CurrentSectionName
) delete[] CurrentSectionName
;
149 CurrentSectionName
= copystring(s
);
152 void SetCurrentSubsectionName(wxChar
*s
)
154 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
155 CurrentSubsectionName
= copystring(s
);
159 // Indicate that a parent topic at level 'level' has children.
160 // Level 1 is a chapter, 2 is a section, etc.
161 void NotifyParentHasChildren(int parentLevel
)
163 wxChar
*parentTopic
= NULL
;
168 parentTopic
= CurrentChapterName
;
173 parentTopic
= CurrentSectionName
;
178 parentTopic
= CurrentSubsectionName
;
188 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(parentTopic
);
191 texTopic
= new TexTopic
;
192 TopicTable
.Put(parentTopic
, texTopic
);
194 texTopic
->hasChildren
= true;
198 // Have to keep a count of what levels are books, what are pages,
199 // in order to correct for a Win95 bug which means that if you
200 // have a book at level n, and then a page at level n, the page
201 // ends up on level n + 1.
203 bool ContentsLevels
[5];
205 // Reset below this level (starts from 1)
206 void ResetContentsLevels(int l
)
209 for (i
= l
; i
< 5; i
++)
210 ContentsLevels
[i
] = false;
212 // There are always books on the top level
213 ContentsLevels
[0] = true;
216 // Output a WinHelp section as a keyword, substituting
218 void OutputSectionKeyword(FILE *fd
)
220 OutputCurrentSectionToString(wxTex2RTFBuffer
);
223 for (i
= 0; i
< wxStrlen(wxTex2RTFBuffer
); i
++)
224 if (wxTex2RTFBuffer
[i
] == ':')
225 wxTex2RTFBuffer
[i
] = ' ';
226 // Don't write to index if there's some RTF in the string
227 else if ( wxTex2RTFBuffer
[i
] == '{' )
230 wxFprintf(fd
, _T("K{\\footnote {K} "));
231 wxFprintf(fd
, _T("%s"), wxTex2RTFBuffer
);
233 wxFprintf(fd
, _T("}\n"));
236 // Write a line for the .cnt file, if we're doing this.
237 void WriteWinHelpContentsFileLine(wxChar
*topicName
, wxChar
*xitle
, int level
)
239 // First, convert any RTF characters to ASCII
243 while ( (xitle
[s
]!=0)&&(d
<255) )
245 wxChar ch
=wxChar(xitle
[s
]&0xff);
247 wxChar ch1
=wxChar(xitle
[s
+1]&0xff);
248 wxChar ch2
=wxChar(xitle
[s
+2]&0xff);
249 wxChar ch3
=wxChar(xitle
[s
+3]&0xff);
250 s
+=4; // next character
251 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]=_T('ö'); }
252 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]=_T('ä'); }
253 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]=_T('ü'); }
254 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]=_T('Ö'); }
255 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]=_T('Ä'); }
256 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]=_T('Ü'); }
264 // Section (2) becomes level 1 if it's an article.
265 if (DocumentStyle
== LATEX_ARTICLE
)
268 if (level
== 0) // Means we had a Chapter in an article, oops.
271 ResetContentsLevels(level
);
273 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
275 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
278 // If a previous section at this level was a book, we *have* to have a
279 // book not a page, because of a bug in WHC (or WinHelp 4).
280 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
282 // At this level, we have a pointer to a further hierarchy.
283 // So we need a 'book' consisting of (say) Chapter 1.
284 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
286 // Then we have a 'page' consisting of the text for this chapter
287 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
289 // Then we'll be writing out further pages or books at level + 1...
291 // Remember that at this level, we had a book and *must* for the
292 // remainder of sections at this level.
293 ContentsLevels
[level
-1] = true;
297 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
302 if (level
== 1 || ContentsLevels
[level
-1])
304 // Always have a book at level 1
305 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
306 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
307 ContentsLevels
[level
-1] = true;
310 // Probably doesn't have children if it hasn't been added to the topic table
311 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
316 void SplitIndexEntry(wxChar
*entry
, wxChar
*buf1
, wxChar
*buf2
)
318 int len
= wxStrlen(entry
); int i
= 0;
319 while ((i
< len
) && entry
[i
] != '!')
320 { buf1
[i
] = entry
[i
]; i
++; }
321 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
326 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
332 * Output topic index entries in WinHelp RTF
335 void GenerateKeywordsForTopic(wxChar
*topic
)
337 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
341 wxStringList
*list
= texTopic
->keywords
;
344 wxStringListNode
*node
= list
->GetFirst();
347 wxChar
*s
= (wxChar
*)node
->GetData();
349 // Must separate out main entry form subentry (only 1 subentry allowed)
350 wxChar buf1
[100]; wxChar buf2
[100];
351 SplitIndexEntry(s
, buf1
, buf2
);
353 // Check for ':' which messes up index
355 for (i
= 0; i
< wxStrlen(buf1
) ; i
++)
358 for (i
= 0; i
< wxStrlen(buf2
) ; i
++)
362 // {K} is a strange fix to prevent words beginning with K not
363 // being indexed properly
364 TexOutput(_T("K{\\footnote {K} "));
366 if (wxStrlen(buf2
) > 0)
372 TexOutput(_T("}\n"));
373 node
= node
->GetNext();
379 * Output index entry in linear RTF
383 void GenerateIndexEntry(wxChar
*entry
)
387 wxChar buf1
[100]; wxChar buf2
[100];
388 SplitIndexEntry(entry
, buf1
, buf2
);
390 TexOutput(_T("{\\xe\\v {"));
392 if (wxStrlen(buf2
) > 0)
394 TexOutput(_T("\\:"));
402 * Write a suitable RTF header.
406 void WriteColourTable(FILE *fd
)
408 wxFprintf(fd
, _T("{\\colortbl"));
409 wxNode
*node
= ColourTable
.GetFirst();
412 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->GetData();
413 wxFprintf(fd
, _T("\\red%d\\green%d\\blue%d;\n"), entry
->red
, entry
->green
, entry
->blue
);
414 node
= node
->GetNext();
416 wxFprintf(fd
, _T("}"));
420 * Write heading style
424 void WriteHeadingStyle(FILE *fd
, int heading
)
430 wxFprintf(fd
, _T("\\sb300\\sa260\\f2\\b\\fs%d"), chapterFont
*2);
435 wxFprintf(fd
, _T("\\sb200\\sa240\\f2\\b\\fs%d"), sectionFont
*2);
440 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
445 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
453 void WriteRTFHeader(FILE *fd
)
455 wxFprintf(fd
, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset
);
456 wxFprintf(fd
, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n"));
457 wxFprintf(fd
, _T("{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
461 wxFprintf(fd
, _T("{\\stylesheet{\\f2\\fs22\\sa200 \\snext0 Normal;}\n"));
463 wxFprintf(fd
, _T("{\\s1 ")); WriteHeadingStyle(fd
, 1); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 1;}\n"));
464 wxFprintf(fd
, _T("{\\s2 ")); WriteHeadingStyle(fd
, 2); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 2;}\n"));
465 wxFprintf(fd
, _T("{\\s3 ")); WriteHeadingStyle(fd
, 3); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 3;}\n"));
466 wxFprintf(fd
, _T("{\\s4 ")); WriteHeadingStyle(fd
, 4); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 4;}\n"));
469 wxFprintf(fd
, _T("{\\s10\\ql \\li720\\ri0\\nowidctlpar\\faauto\\rin0\\lin720\\itap0 \\cbpat17\
470 \\f2\\fs20 \\sbasedon0 \\snext24 Code;}\n"));
472 // Table of contents styles
473 wxFprintf(fd
, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n"));
475 wxFprintf(fd
, _T("{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n"));
476 wxFprintf(fd
, _T("{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n"));
477 wxFprintf(fd
, _T("{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n"));
480 wxFprintf(fd
, _T("{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n"));
481 wxFprintf(fd
, _T("{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n"));
482 wxFprintf(fd
, _T("{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n"));
483 wxFprintf(fd
, _T("{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n"));
484 wxFprintf(fd
, _T("{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n"));
485 wxFprintf(fd
, _T("}\n"));
487 WriteColourTable(fd
);
488 wxFprintf(fd
, _T("\n\\ftnbj\\ftnrestart")); // Latex default is footnotes at bottom of page, not section.
489 wxFprintf(fd
, _T("\n"));
492 void OutputNumberStyle(wxChar
*numberStyle
)
496 if (wxStrcmp(numberStyle
, _T("arabic")) == 0)
498 TexOutput(_T("\\pgndec"));
500 else if (wxStrcmp(numberStyle
, _T("roman")) == 0)
502 TexOutput(_T("\\pgnlcrm"));
504 else if (wxStrcmp(numberStyle
, _T("Roman")) == 0)
506 TexOutput(_T("\\pgnucrm"));
508 else if (wxStrcmp(numberStyle
, _T("alph")) == 0)
510 TexOutput(_T("\\pgnlcltr"));
512 else if (wxStrcmp(numberStyle
, _T("Alph")) == 0)
514 TexOutput(_T("\\pgnucltr"));
520 * Write a Windows help project file
523 bool WriteHPJ(wxChar
*filename
)
525 wxChar hpjFilename
[256];
528 wxStrcpy(hpjFilename
, filename
);
529 StripExtension(hpjFilename
);
530 wxStrcat(hpjFilename
, _T(".hpj"));
532 wxStrcpy(helpFile
, wxFileNameFromPath(filename
));
533 StripExtension(helpFile
);
534 wxStrcpy(rtfFile
, helpFile
);
535 wxStrcat(helpFile
, _T(".hlp"));
536 wxStrcat(rtfFile
, _T(".rtf"));
538 FILE *fd
= wxFopen(hpjFilename
, _T("w"));
542 wxChar
*helpTitle
= winHelpTitle
;
544 helpTitle
= _T("Untitled");
546 wxString thePath
= wxPathOnly(InputFile
);
547 if (thePath
.IsEmpty())
549 wxFprintf(fd
, _T("[OPTIONS]\n"));
550 wxFprintf(fd
, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath
.c_str());
551 wxFprintf(fd
, _T("TITLE=%s\n"), helpTitle
);
552 wxFprintf(fd
, _T("CONTENTS=Contents\n"));
554 if (winHelpVersion
> 3)
556 wxFprintf(fd
, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
557 wxFprintf(fd
, _T("COMPRESS=8 Zeck\n"));
558 wxFprintf(fd
, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
559 wxFprintf(fd
, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot
));
563 wxFprintf(fd
, _T("COMPRESS=HIGH\n"));
565 wxFprintf(fd
, _T("\n"));
567 if (winHelpVersion
> 3)
569 wxFprintf(fd
, _T("[WINDOWS]\n"));
570 wxFprintf(fd
, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
571 wxFprintf(fd
, _T("\n"));
574 wxFprintf(fd
, _T("[FILES]\n%s\n\n"), rtfFile
);
575 wxFprintf(fd
, _T("[CONFIG]\n"));
577 wxFprintf(fd
, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile
);
578 wxFprintf(fd
, _T("BrowseButtons()\n\n"));
579 wxFprintf(fd
, _T("[MAP]\n\n[BITMAPS]\n\n"));
586 * Given a TexChunk with a string value, scans through the string
587 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
588 * and inserting spaces at the start of lines since in Latex, a newline
589 * implies a space, but not in RTF.
593 void ProcessText2RTF(TexChunk
*chunk
)
595 bool changed
= false;
599 int len
= wxStrlen(chunk
->value
);
602 ch
= chunk
->value
[i
];
608 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("\\par\n")); ptr
+= 5;
609 // BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par{\\v this was verbatim}\n")); ptr += 5;
615 // If the first character of the next line is ASCII,
616 // put a space in. Implicit in Latex, not in RTF.
618 The reason this is difficult is that you don't really know
619 where a space would be appropriate. If you always put in a space
620 when you find a newline, unwanted spaces appear in the text.
622 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
623 !isspace(chunk
->value
[i
+1])) ||
624 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
625 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
626 !isspace(chunk
->value
[i
+2]))))
629 // DOS files have a 13 after the 10
633 if (chunk
->value
[i
] == 13)
640 BigBuffer
[ptr
] = ' ';
643 // Note that the actual ASCII character seen is dealt with in the next
654 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
656 BigBuffer
[ptr
] = '"'; ptr
++;
660 else if (!inVerbatim
&& ch
== '`') // Change ` to '
662 BigBuffer
[ptr
] = 39; ptr
++;
666 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
668 BigBuffer
[ptr
] = '\\'; ptr
++;
669 BigBuffer
[ptr
] = '\\'; ptr
++;
673 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curley bracket
675 BigBuffer
[ptr
] = '\\'; ptr
++;
676 BigBuffer
[ptr
] = ch
; ptr
++;
691 delete[] chunk
->value
;
692 chunk
->value
= copystring(BigBuffer
);
697 * Scan through all chunks starting from the given one,
698 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
699 * This should be called after Tex2Any has parsed the file,
700 * and before TraverseDocument is called.
704 void Text2RTF(TexChunk
*chunk
)
707 if (stopRunning
) return;
711 case CHUNK_TYPE_MACRO
:
713 TexMacroDef
*def
= chunk
->def
;
714 if (def
&& def
->ignore
)
717 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
720 wxNode
*node
= chunk
->children
.GetFirst();
723 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
724 Text2RTF(child_chunk
);
725 node
= node
->GetNext();
728 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
735 wxNode
*node
= chunk
->children
.GetFirst();
738 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
739 Text2RTF(child_chunk
);
740 node
= node
->GetNext();
745 case CHUNK_TYPE_STRING
:
748 ProcessText2RTF(chunk
);
759 wxChar browseBuf
[10];
760 static long browseId
= 0;
761 wxChar
*GetBrowseString(void)
765 wxSnprintf(buf
, sizeof(buf
), _T("%ld"), browseId
);
766 int noZeroes
= 5-wxStrlen(buf
);
767 wxStrcpy(browseBuf
, _T("browse"));
768 for (int i
= 0; i
< noZeroes
; i
++)
769 wxStrcat(browseBuf
, _T("0"));
770 wxStrcat(browseBuf
, buf
);
775 * Keeping track of environments to restore the styles after \pard.
776 * Push strings like "\qc" onto stack.
780 void PushEnvironmentStyle(wxChar
*style
)
782 environmentStack
.Add(style
);
785 void PopEnvironmentStyle(void)
787 wxStringListNode
*node
= environmentStack
.GetLast();
790 wxChar
*val
= (wxChar
*)node
->GetData();
796 // Write out the styles, most recent first.
797 void WriteEnvironmentStyles(void)
799 wxStringListNode
*node
= environmentStack
.GetLast();
802 wxChar
*val
= (wxChar
*)node
->GetData();
804 node
= node
->GetNext();
806 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
809 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d"), ParIndent
*20); // Convert points to TWIPS
812 if (environmentStack
.GetCount() > 0 || (ParIndent
> 0))
822 void OutputRTFHeaderCommands(void)
825 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
827 TexOutput(_T("{\\headerl }{\\headerr }"));
829 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
831 TexOutput(_T("{\\headerl }{\\headerr }"));
833 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
836 TexOutput(_T("{\\headerl\\fi0 "));
839 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
841 TexOutput(_T("{\\i \\qr "));
842 if (DocumentStyle
== LATEX_ARTICLE
)
844 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
849 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d: "), chapterNo
);
852 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
853 TexOutput(_T("}\\par\\pard}"));
856 TexOutput(_T("{\\headerr\\fi0 "));
859 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
861 TexOutput(_T("{\\i \\qc "));
862 if (DocumentStyle
== LATEX_ARTICLE
)
864 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
869 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d"), chapterNo
);
872 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
873 TexOutput(_T("}\\par\\pard}"));
877 int oldForbidResetPar
= forbidResetPar
;
880 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
882 TexOutput(_T("{\\headerl\\fi0 "));
885 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
889 if (!CentreHeaderEven
&& !RightHeaderEven
)
890 TexOutput(_T("\\ql "));
891 TraverseChildrenFromChunk(LeftHeaderEven
);
893 if (CentreHeaderEven
)
895 if (!LeftHeaderEven
&& !RightHeaderEven
)
896 TexOutput(_T("\\qc "));
898 TexOutput(_T("\\tab\\tab\\tab "));
899 TraverseChildrenFromChunk(CentreHeaderEven
);
903 if (!LeftHeaderEven
&& !CentreHeaderEven
)
904 TexOutput(_T("\\qr "));
906 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
907 TraverseChildrenFromChunk(RightHeaderEven
);
909 TexOutput(_T("\\par\\pard}"));
912 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
914 TexOutput(_T("{\\headerr\\fi0 "));
917 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
921 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
922 TexOutput(_T("\\ql "));
923 TraverseChildrenFromChunk(LeftHeaderOdd
);
927 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
928 TexOutput(_T("\\qc "));
930 TexOutput(_T("\\tab\\tab\\tab "));
931 TraverseChildrenFromChunk(CentreHeaderOdd
);
935 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
936 TexOutput(_T("\\qr "));
938 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
939 TraverseChildrenFromChunk(RightHeaderOdd
);
941 TexOutput(_T("\\par\\pard}"));
943 // As an approximation, don't put a header on the first page of a section.
944 // This may not always be desired, but it's a reasonable guess.
945 TexOutput(_T("{\\headerf }"));
947 forbidResetPar
= oldForbidResetPar
;
951 void OutputRTFFooterCommands(void)
953 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
955 TexOutput(_T("{\\footerl\\fi0 "));
957 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
958 TexOutput(_T("{\\qc "));
959 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
960 TexOutput(_T("}\\par\\pard}"));
962 TexOutput(_T("{\\footerr\\fi0 "));
964 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
965 TexOutput(_T("{\\qc "));
966 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
967 TexOutput(_T("}\\par\\pard}"));
969 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
971 TexOutput(_T("{\\footerl }{\\footerr }"));
973 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
975 TexOutput(_T("{\\footerl }{\\footerr }"));
979 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
981 TexOutput(_T("{\\footerl\\fi0 "));
983 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
986 if (!CentreFooterEven
&& !RightFooterEven
)
987 TexOutput(_T("\\ql "));
988 TraverseChildrenFromChunk(LeftFooterEven
);
990 if (CentreFooterEven
)
992 if (!LeftFooterEven
&& !RightFooterEven
)
993 TexOutput(_T("\\qc "));
995 TexOutput(_T("\\tab\\tab\\tab "));
996 TraverseChildrenFromChunk(CentreFooterEven
);
1000 if (!LeftFooterEven
&& !CentreFooterEven
)
1001 TexOutput(_T("\\qr "));
1003 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1004 TraverseChildrenFromChunk(RightFooterEven
);
1006 TexOutput(_T("\\par\\pard}"));
1009 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1011 TexOutput(_T("{\\footerr\\fi0 "));
1013 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
1016 if (!CentreFooterOdd
&& !RightFooterOdd
)
1017 TexOutput(_T("\\ql "));
1018 TraverseChildrenFromChunk(LeftFooterOdd
);
1020 if (CentreFooterOdd
)
1022 if (!LeftFooterOdd
&& !RightFooterOdd
)
1023 TexOutput(_T("\\qc "));
1025 TexOutput(_T("\\tab\\tab\\tab "));
1026 TraverseChildrenFromChunk(CentreFooterOdd
);
1030 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1031 TexOutput(_T("\\qr "));
1033 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1034 TraverseChildrenFromChunk(RightFooterOdd
);
1036 TexOutput(_T("\\par\\pard}"));
1039 // As an approximation, put a footer on the first page of a section.
1040 // This may not always be desired, but it's a reasonable guess.
1041 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1043 TexOutput(_T("{\\footerf\\fi0 "));
1046 if (!CentreFooterOdd
&& !RightFooterOdd
)
1047 TexOutput(_T("\\ql "));
1048 TraverseChildrenFromChunk(LeftFooterOdd
);
1050 if (CentreFooterOdd
)
1052 if (!LeftFooterOdd
&& !RightFooterOdd
)
1053 TexOutput(_T("\\qc "));
1055 TexOutput(_T("\\tab\\tab\\tab "));
1056 TraverseChildrenFromChunk(CentreFooterOdd
);
1060 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1061 TexOutput(_T("\\qr "));
1063 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1064 TraverseChildrenFromChunk(RightFooterOdd
);
1066 TexOutput(_T("\\par\\pard}"));
1071 // Called on start/end of macro examination
1072 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1076 wxSnprintf(tmpBuf, sizeof(tmpBuf), _T("%d (%d)"), macroId, (int)start);
1077 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1078 OutputDebugString("\n"); wxYield();
1081 // ltLABEL is included here because after a section but BEFORE
1082 // the label is seen, a new paragraph is issued. Don't upset this by
1083 // immediately forgetting we've done it.
1084 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1085 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1086 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1087 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1088 macroId
!= ltPAGENUMBERING
&&
1089 (forbidResetPar
== 0)))
1091 issuedNewParagraph
= 0;
1099 case ltCHAPTERHEADING
:
1100 case ltCHAPTERHEADINGSTAR
:
1108 subsubsectionNo
= 0;
1111 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1114 wxChar
*topicName
= FindTopicName(GetNextChunk());
1115 SetCurrentChapterName(topicName
);
1117 if (winHelpContents
&& winHelp
&& !InPopups())
1119 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1120 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1122 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1127 wxFprintf(Contents
, _T("\n{\\uldb "));
1128 wxFprintf(Chapters
, _T("\\page"));
1129 wxFprintf(Chapters
, _T("\n${\\footnote "));
1131 SetCurrentOutputs(Contents
, Chapters
);
1133 SetCurrentOutput(Chapters
);
1137 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
1139 // If a non-custom page style, we generate the header now.
1140 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1141 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1142 wxStrcmp(PageStyle
, _T("headings")) == 0))
1144 OutputRTFHeaderCommands();
1145 OutputRTFFooterCommands();
1148 // Need to reset the current numbering style, or RTF forgets it.
1149 SetCurrentOutput(Chapters
);
1150 OutputNumberStyle(currentNumberStyle
);
1152 SetCurrentOutput(Contents
);
1156 if (macroId
== ltCHAPTER
)
1159 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), chapterNo
);
1161 else if (macroId
== ltCHAPTERHEADING
)
1163 wxFprintf(Contents
, _T("\\par\n\\pard{\\b "));
1165 else SetCurrentOutput(NULL
); // No entry in table of contents
1169 startedSections
= true;
1171 // Output heading to contents page
1174 OutputCurrentSection();
1178 wxFprintf(Contents
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1179 //WriteEnvironmentStyles();
1181 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1182 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1184 // From here, just output to chapter
1185 SetCurrentOutput(Chapters
);
1190 wxFprintf(Chapters
, _T("}\n#{\\footnote %s}\n"), topicName
);
1191 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
1193 OutputSectionKeyword(Chapters
);
1195 GenerateKeywordsForTopic(topicName
);
1198 // If we're generating a .cnt file, we don't want to be able
1199 // jump up to the old-style contents page, so disable it.
1200 if (winHelpContents
)
1201 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
1203 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1204 wxFileNameFromPath(FileRoot
), _T("Contents"));
1210 wxChar
*styleCommand
= _T("");
1211 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1212 styleCommand
= _T("\\s1");
1213 wxFprintf(Chapters
, _T("\\pard{%s"), ((winHelp
&& !InPopups()) ? _T("\\keepn\\sa140\\sb140") : styleCommand
));
1214 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" "));
1217 if (macroId
== ltCHAPTER
)
1220 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1221 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1223 wxFprintf(Chapters
, _T("%d. "), chapterNo
);
1227 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1230 OutputCurrentSection();
1231 TexOutput(_T("\\par\\pard}\n"));
1233 issuedNewParagraph
= 1;
1234 WriteEnvironmentStyles();
1240 case ltSECTIONHEADING
:
1241 case ltSECTIONHEADINGSTAR
:
1245 if (DocumentStyle
== LATEX_ARTICLE
)
1246 jumpFrom
= Contents
;
1248 jumpFrom
= Chapters
;
1253 subsubsectionNo
= 0;
1254 if (DocumentStyle
== LATEX_ARTICLE
)
1257 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1260 wxChar
*topicName
= FindTopicName(GetNextChunk());
1261 SetCurrentSectionName(topicName
);
1262 NotifyParentHasChildren(1);
1263 if (winHelpContents
&& winHelp
&& !InPopups())
1265 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1266 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 2);
1268 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1272 SetCurrentOutputs(jumpFrom
, Sections
);
1273 // Newline for a new section if this is an article
1274 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1275 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1276 wxFprintf(Sections
, _T("\\page\n"));
1279 wxFprintf(jumpFrom
, _T("\n{\\uldb "));
1283 if (DocumentStyle
== LATEX_ARTICLE
)
1285 TexOutput(_T("\\sect\\pgncont\n"));
1286 // If a non-custom page style, we generate the header now.
1287 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1288 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1289 wxStrcmp(PageStyle
, _T("headings")) == 0))
1291 OutputRTFHeaderCommands();
1292 OutputRTFFooterCommands();
1295 SetCurrentOutput(Contents
);
1297 if (macroId
== ltSECTION
)
1301 if (DocumentStyle
== LATEX_REPORT
)
1302 wxFprintf(Contents
, _T("\n\\pard{\\tab %d.%d\\tab "), chapterNo
, sectionNo
);
1304 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), sectionNo
);
1307 else if (macroId
== ltSECTIONHEADING
)
1311 if (DocumentStyle
== LATEX_REPORT
)
1312 wxFprintf(Contents
, _T("\n\\pard{\\tab ")); //, chapterNo, sectionNo);
1314 wxFprintf(Contents
, _T("\\par\n\\pard{\\b ")); //, sectionNo);
1317 else SetCurrentOutput(NULL
);
1320 if (startedSections
)
1323 wxFprintf(Sections
, _T("\\page\n"));
1325 startedSections
= true;
1328 wxFprintf(Sections
, _T("\n${\\footnote "));
1330 // Output heading to contents page
1332 OutputCurrentSection();
1338 wxFprintf(jumpFrom
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1339 //WriteEnvironmentStyles();
1342 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1344 if (DocumentStyle
== LATEX_REPORT
)
1345 wxFprintf(Contents
, _T("}\\par\\pard\n"));
1347 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1350 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1354 wxFprintf(Sections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1355 wxFprintf(Sections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1356 OutputSectionKeyword(Sections
);
1357 GenerateKeywordsForTopic(topicName
);
1360 if (DocumentStyle
== LATEX_ARTICLE
)
1362 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1363 wxFileNameFromPath(FileRoot
), _T("Contents"));
1365 else if (CurrentChapterName
)
1367 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1368 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1375 wxChar
*styleCommand
= _T("");
1376 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1378 if (DocumentStyle
== LATEX_ARTICLE
)
1379 styleCommand
= _T("\\s1");
1381 styleCommand
= _T("\\s2");
1383 wxChar
*keep
= _T("");
1384 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1385 keep
= _T("\\keepn\\sa140\\sb140");
1387 wxFprintf(winHelp
? Sections
: Chapters
, _T("\\pard{%s%s"),
1388 keep
, styleCommand
);
1390 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1391 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1392 wxFprintf(winHelp
? Sections
: Chapters
, _T(" "));
1396 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1398 if (DocumentStyle
== LATEX_REPORT
)
1401 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo,
1402 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1405 wxFprintf(Chapters
, _T("%d.%d. "), chapterNo
, sectionNo
);
1410 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1411 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1414 wxFprintf(Chapters
, _T("%d. "), sectionNo
);
1419 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1422 OutputCurrentSection();
1423 TexOutput(_T("\\par\\pard}\n"));
1424 // TexOutput(_T("\\par\\pard}\\par\n"));
1426 issuedNewParagraph
= 1;
1427 WriteEnvironmentStyles();
1428 // issuedNewParagraph = 2;
1433 case ltSUBSECTIONSTAR
:
1434 case ltMEMBERSECTION
:
1435 case ltFUNCTIONSECTION
:
1439 if (winHelp
&& !Sections
)
1441 OnError(_T("You cannot have a subsection before a section!"));
1445 subsubsectionNo
= 0;
1447 if (macroId
!= ltSUBSECTIONSTAR
)
1450 wxChar
*topicName
= FindTopicName(GetNextChunk());
1451 SetCurrentSubsectionName(topicName
);
1452 NotifyParentHasChildren(2);
1453 if (winHelpContents
&& winHelp
&& !InPopups())
1455 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1456 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1458 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1462 SetCurrentOutputs(Sections
, Subsections
);
1463 SetCurrentOutputs(Sections
, Subsections
);
1465 wxFprintf(Sections
, _T("\n{\\uldb "));
1469 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1470 (macroId
!= ltFUNCTIONSECTION
))
1472 SetCurrentOutput(Contents
);
1473 if (DocumentStyle
== LATEX_REPORT
)
1474 wxFprintf(Contents
, _T("\n\\pard\\tab\\tab %d.%d.%d\\tab "), chapterNo
, sectionNo
, subsectionNo
);
1476 wxFprintf(Contents
, _T("\n\\pard\\tab %d.%d\\tab "), sectionNo
, subsectionNo
);
1477 } else SetCurrentOutput(NULL
);
1479 if (startedSections
)
1484 wxFprintf(Subsections
, _T("\\page\n"));
1486 // Experimental JACS 2004-02-21
1489 wxFprintf(Chapters
, _T("\\par\n"));
1492 startedSections
= true;
1495 wxFprintf(Subsections
, _T("\n${\\footnote "));
1497 // Output to contents page
1499 OutputCurrentSection();
1505 wxFprintf(Sections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1506 //WriteEnvironmentStyles();
1509 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1510 (macroId
!= ltFUNCTIONSECTION
))
1511 wxFprintf(Contents
, _T("\\par\\pard\n"));
1513 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1516 wxFprintf(Subsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1517 wxFprintf(Subsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1518 OutputSectionKeyword(Subsections
);
1519 GenerateKeywordsForTopic(topicName
);
1520 if (useUpButton
&& CurrentSectionName
)
1522 wxFprintf(Subsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1523 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1526 if (!winHelp
&& indexSubsections
&& useWord
)
1528 // Insert index entry for this subsection
1529 TexOutput(_T("{\\xe\\v {"));
1530 OutputCurrentSection();
1531 TexOutput(_T("}}"));
1536 wxChar
*styleCommand
= _T("");
1537 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1539 if (DocumentStyle
== LATEX_ARTICLE
)
1540 styleCommand
= _T("\\s2");
1542 styleCommand
= _T("\\s3");
1544 wxChar
*keep
= _T("");
1545 if (winHelp
&& !InPopups())
1546 keep
= _T("\\keepn\\sa140\\sb140");
1548 wxFprintf(winHelp
? Subsections
: Chapters
, _T("\\pard{%s%s"),
1549 keep
, styleCommand
);
1551 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1552 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1553 wxFprintf(winHelp
? Subsections
: Chapters
, _T(" "));
1557 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1558 (macroId
!= ltFUNCTIONSECTION
))
1560 if (DocumentStyle
== LATEX_REPORT
)
1563 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo,
1564 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1567 wxFprintf(Chapters
, _T("%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
);
1572 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo,
1573 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1576 wxFprintf(Chapters
, _T("%d.%d. "), sectionNo
, subsectionNo
);
1581 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1584 OutputCurrentSection(); // Repeat section header
1586 // Experimental JACS
1587 TexOutput(_T("\\par\\pard}\n"));
1588 // TexOutput(_T("\\par\\pard}\\par\n"));
1590 issuedNewParagraph
= 1;
1591 WriteEnvironmentStyles();
1596 case ltSUBSUBSECTION
:
1597 case ltSUBSUBSECTIONSTAR
:
1601 if (winHelp
&& !Subsections
)
1603 OnError(_T("You cannot have a subsubsection before a subsection!"));
1607 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1610 wxChar
*topicName
= FindTopicName(GetNextChunk());
1611 SetCurrentTopic(topicName
);
1612 NotifyParentHasChildren(3);
1613 if (winHelpContents
&& winHelp
)
1615 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1616 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1618 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1622 SetCurrentOutputs(Subsections
, Subsubsections
);
1623 wxFprintf(Subsections
, _T("\n{\\uldb "));
1627 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1629 if (DocumentStyle
== LATEX_ARTICLE
)
1631 SetCurrentOutput(Contents
);
1632 wxFprintf(Contents
, _T("\n\\tab\\tab %d.%d.%d\\tab "),
1633 sectionNo
, subsectionNo
, subsubsectionNo
);
1636 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1639 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1642 if (startedSections
)
1645 wxFprintf(Subsubsections
, _T("\\page\n"));
1646 // Experimental JACS 2004-02-21
1649 wxFprintf(Chapters
, _T("\\par\n"));
1653 startedSections
= true;
1656 wxFprintf(Subsubsections
, _T("\n${\\footnote "));
1658 // Output header to contents page
1659 OutputCurrentSection();
1663 wxFprintf(Subsections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1664 //WriteEnvironmentStyles();
1666 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1667 wxFprintf(Contents
, _T("\\par\\pard\n"));
1669 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1672 wxFprintf(Subsubsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1673 wxFprintf(Subsubsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1674 OutputSectionKeyword(Subsubsections
);
1675 GenerateKeywordsForTopic(topicName
);
1676 if (useUpButton
&& CurrentSubsectionName
)
1678 wxFprintf(Subsubsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1679 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1682 if (!winHelp
&& indexSubsections
&& useWord
)
1684 // Insert index entry for this subsubsection
1685 TexOutput(_T("{\\xe\\v {"));
1686 OutputCurrentSection();
1687 TexOutput(_T("}}"));
1690 wxChar
*styleCommand
= _T("");
1691 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1693 if (DocumentStyle
== LATEX_ARTICLE
)
1694 styleCommand
= _T("\\s3");
1696 styleCommand
= _T("\\s4");
1698 wxChar
*keep
= _T("");
1700 keep
= _T("\\keepn\\sa140\\sb140");
1702 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T("\\pard{%s%s"),
1703 keep
, styleCommand
);
1705 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1706 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1707 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T(" "));
1711 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1713 if (DocumentStyle
== LATEX_ARTICLE
)
1716 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo, subsubsectionNo,
1717 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1720 wxFprintf(Chapters
, _T("%d.%d.%d. "), sectionNo
, subsectionNo
, subsubsectionNo
);
1725 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1726 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1729 wxFprintf(Chapters
, _T("%d.%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1734 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1737 OutputCurrentSection(); // Repeat section header
1738 TexOutput(_T("\\par\\pard}\n"));
1739 issuedNewParagraph
= 1;
1740 WriteEnvironmentStyles();
1741 // TexOutput(_T("\\par\\pard}\\par\n"));
1742 // issuedNewParagraph = 2;
1752 wxChar
*topicName
= FindTopicName(GetNextChunk());
1753 SetCurrentTopic(topicName
);
1755 TexOutput(_T("\\pard\\par"));
1762 if (winHelp
|| !useWord
)
1764 if (DocumentStyle
!= LATEX_ARTICLE
)
1765 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1767 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1771 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1772 FigureNameString
, topicName
, topicName
);
1779 if (winHelp
|| !useWord
)
1781 if (DocumentStyle
!= LATEX_ARTICLE
)
1782 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1784 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1788 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1789 TableNameString
, topicName
, topicName
);
1793 int n
= (inTable
? tableNo
: figureNo
);
1794 AddTexRef(topicName
, NULL
, NULL
,
1795 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1796 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1799 TexOutput(_T("\\qc{\\b "));
1801 TexOutput(_T("\\ql{\\b "));
1804 OutputCurrentSection();
1806 TexOutput(_T("}\\par\\pard\n"));
1807 WriteEnvironmentStyles();
1814 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1821 TexOutput(_T("}\n"));
1824 TexOutput(_T("K{\\footnote {K} "));
1825 suppressNameDecoration
= true;
1826 TraverseChildrenFromChunk(currentMember
);
1827 suppressNameDecoration
= false;
1828 TexOutput(_T("}\n"));
1830 if (!winHelp
&& useWord
)
1832 // Insert index entry for this function
1833 TexOutput(_T("{\\xe\\v {"));
1834 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1835 TraverseChildrenFromChunk(currentMember
);
1836 suppressNameDecoration
= false;
1837 TexOutput(_T("}}"));
1844 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1851 TexOutput(_T("}\n"));
1854 TexOutput(_T("K{\\footnote {K} "));
1855 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1856 TraverseChildrenFromChunk(currentMember
);
1857 suppressNameDecoration
= false;
1858 TexOutput(_T("}\n"));
1860 if (!winHelp
&& useWord
)
1862 // Insert index entry for this function
1863 TexOutput(_T("{\\xe\\v {"));
1864 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1865 TraverseChildrenFromChunk(currentMember
);
1866 suppressNameDecoration
= false;
1867 TexOutput(_T("}}"));
1874 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1877 TexOutput(_T("{\\b "));
1881 TexOutput(_T("}\n"));
1884 TexOutput(_T("K{\\footnote {K} "));
1885 TraverseChildrenFromChunk(currentMember
);
1886 TexOutput(_T("}\n"));
1888 if (!winHelp
&& useWord
)
1890 // Insert index entry for this function
1891 TexOutput(_T("{\\xe\\v {"));
1892 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1893 TraverseChildrenFromChunk(currentMember
);
1894 suppressNameDecoration
= false;
1895 TexOutput(_T("}}"));
1903 SetCurrentOutput(Chapters
);
1906 case ltTABLEOFCONTENTS
:
1910 if (!winHelp
&& useWord
)
1912 // Insert Word for Windows table of contents
1913 TexOutput(_T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
1915 // In linear RTF, same as chapter headings.
1916 wxSnprintf(buf
, sizeof(buf
), _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), chapterFont
*2, ContentsNameString
);
1919 wxSnprintf(buf
, sizeof(buf
), _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth
);
1921 // TexOutput(_T("\\sect\\sectd"));
1925 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1931 wxPutc(ch
, Chapters
);
1938 TexOutput(_T("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n"));
1939 OnInform(_T("Run Tex2RTF again to include contents page."));
1948 // TexOutput(_T("{\\b void}"));
1954 TexOutput(_T("{\\scaps HARDY}"));
1960 TexOutput(_T("wxCLIPS"));
1963 case ltSPECIALAMPERSAND
:
1968 TexOutput(_T("\\cell "));
1974 case ltSPECIALTILDE
:
1978 #if 1 // if(inVerbatim)
1986 case ltBACKSLASHCHAR
:
1992 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
1993 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
1994 int currentWidth
= 0;
1995 for (int i
= 0; i
< noColumns
; i
++)
1997 currentWidth
+= TableData
[i
].width
;
1998 if (TableData
[i
].rightBorder
)
1999 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
2001 if (TableData
[i
].leftBorder
)
2002 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
2004 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
2007 TexOutput(_T("\\pard\\intbl\n"));
2010 TexOutput(_T("\\line\n"));
2017 TexOutput(_T("\tab "));
2020 case ltRTFSP
: // Explicit space, RTF only
2032 if (indentLevel
> 0)
2034 // Experimental JACS 2004-02-21
2035 TexOutput(_T("\\par\n"));
2036 issuedNewParagraph
= 1;
2037 // TexOutput(_T("\\par\\par\n"));
2038 // issuedNewParagraph = 2;
2042 // Top-level list: issue a new paragraph if we haven't
2044 if (!issuedNewParagraph
)
2046 TexOutput(_T("\\par\\pard"));
2047 WriteEnvironmentStyles();
2048 issuedNewParagraph
= 1;
2050 else issuedNewParagraph
= 0;
2053 TexOutput(_T("\\fi0\n"));
2055 if (macroId
== ltENUMERATE
)
2056 listType
= LATEX_ENUMERATE
;
2057 else if (macroId
== ltITEMIZE
)
2058 listType
= LATEX_ITEMIZE
;
2060 listType
= LATEX_DESCRIPTION
;
2063 wxNode
*node
= itemizeStack
.GetFirst();
2065 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2067 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2068 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2070 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2071 itemizeStack
.Insert(struc
);
2073 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\sa200"), indentSize1
, indentSize2
, indentSize2
);
2074 PushEnvironmentStyle(buf
);
2078 currentItemSep
= 8; // Reset to the default
2080 PopEnvironmentStyle();
2082 if (itemizeStack
.GetFirst())
2084 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2086 delete itemizeStack
.GetFirst();
2088 /* Change 18/7/97 - don't know why we wish to do this
2089 if (itemizeStack.Number() == 0)
2091 OnMacro(ltPAR, 0, true);
2092 OnMacro(ltPAR, 0, false);
2093 issuedNewParagraph = 2;
2105 wxNode
*node
= itemizeStack
.GetFirst();
2107 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2109 int indentSize
= oldIndent
+ TwoColWidthA
;
2111 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2112 itemizeStack
.Insert(struc
);
2114 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\ri%d"), indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2115 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200"), indentSize
, indentSize
);
2116 PushEnvironmentStyle(buf
);
2121 PopEnvironmentStyle();
2122 if (itemizeStack
.GetFirst())
2124 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2126 delete itemizeStack
.GetFirst();
2130 TexOutput(_T("\\pard\n"));
2131 WriteEnvironmentStyles();
2133 /* why do we need this? */
2135 TexOutput(_T("\\pard\n"));
2137 if (itemizeStack
.GetCount() == 0)
2139 issuedNewParagraph
= 0;
2140 OnMacro(ltPAR
, 0, true);
2141 OnMacro(ltPAR
, 0, false);
2149 wxNode
*node
= itemizeStack
.GetFirst();
2152 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2155 struc
->currentItem
+= 1;
2156 wxChar indentBuf
[60];
2158 int indentSize1
= struc
->labelIndentation
;
2159 int indentSize2
= struc
->indentation
;
2161 TexOutput(_T("\n"));
2162 if (struc
->currentItem
> 1 && issuedNewParagraph
== 0)
2165 // if (currentItemSep > 0)
2166 // TexOutput(_T("\\par"));
2168 TexOutput(_T("\\par"));
2169 issuedNewParagraph
= 1;
2170 // WriteEnvironmentStyles();
2173 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1
, indentSize2
,
2174 indentSize2
, 20*itemIndentTab
);
2177 switch (struc
->listType
)
2179 case LATEX_ENUMERATE
:
2181 if (descriptionItemArg
)
2183 TexOutput(_T("\\tab{ "));
2184 TraverseChildrenFromChunk(descriptionItemArg
);
2185 TexOutput(_T("}\\tab"));
2186 descriptionItemArg
= NULL
;
2190 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b %d.}\\tab"), struc
->currentItem
);
2191 TexOutput(indentBuf
);
2197 if (descriptionItemArg
)
2199 TexOutput(_T("\\tab{ "));
2200 TraverseChildrenFromChunk(descriptionItemArg
);
2201 TexOutput(_T("}\\tab"));
2202 descriptionItemArg
= NULL
;
2206 if (bulletFile
&& winHelp
)
2208 if (winHelpVersion
> 3) // Transparent bitmap
2209 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmct %s\\}\\tab"), bulletFile
);
2211 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmc %s\\}\\tab"), bulletFile
);
2214 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b o}\\tab"));
2216 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\f1\\'b7}\\tab"));
2217 TexOutput(indentBuf
);
2222 case LATEX_DESCRIPTION
:
2224 if (descriptionItemArg
)
2226 TexOutput(_T("\\tab{\\b "));
2227 TraverseChildrenFromChunk(descriptionItemArg
);
2228 TexOutput(_T("} "));
2229 descriptionItemArg
= NULL
;
2239 case ltTWOCOLITEMRULED
:
2241 wxNode
*node
= itemizeStack
.GetFirst();
2244 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2247 struc
->currentItem
+= 1;
2250 wxNode
*node2
= NULL
;
2251 if (itemizeStack
.GetCount() > 1) // TODO: do I actually mean Nth(0) here??
2252 node2
= itemizeStack
.Item(1);
2254 oldIndent
= ((ItemizeStruc
*)node2
->GetData())->indentation
;
2256 TexOutput(_T("\n"));
2259 if (struc
->currentItem
> 1)
2261 if (currentItemSep
> 0)
2262 TexOutput(_T("\\par"));
2264 // WriteEnvironmentStyles();
2268 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA,
2269 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2271 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA,
2272 TwoColWidthA, TwoColWidthA);
2274 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA
+ oldIndent
,
2275 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2288 if (macroId
== ltVERBATIM
)
2290 if (!issuedNewParagraph
)
2292 TexOutput(_T("\\par\\pard"));
2293 WriteEnvironmentStyles();
2294 issuedNewParagraph
= 1;
2296 else issuedNewParagraph
= 0;
2300 if (macroId
== ltVERBATIM
)
2301 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\s10\\fs20\\li720\\sa0 "));
2303 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\fs20 "));
2309 if (macroId
== ltVERBATIM
)
2311 TexOutput(_T("\\pard\n"));
2312 WriteEnvironmentStyles();
2315 TexOutput(_T("\\par\n"));
2316 issuedNewParagraph
= 1;
2327 TexOutput(_T("\\qc "));
2329 PushEnvironmentStyle(_T("\\qc\\sa200"));
2333 TexOutput(_T("\\par\\pard\n"));
2334 issuedNewParagraph
= 1;
2336 PopEnvironmentStyle();
2337 WriteEnvironmentStyles();
2345 TexOutput(_T("\\ql\\sa200 "));
2347 PushEnvironmentStyle(_T("\\ql"));
2351 TexOutput(_T("\\par\\pard\n"));
2352 issuedNewParagraph
= 1;
2354 PopEnvironmentStyle();
2355 WriteEnvironmentStyles();
2363 TexOutput(_T("\\qr\\sa200 "));
2365 PushEnvironmentStyle(_T("\\qr"));
2369 TexOutput(_T("\\par\\pard\n"));
2370 issuedNewParagraph
= 1;
2372 PopEnvironmentStyle();
2373 WriteEnvironmentStyles();
2378 case ltFOOTNOTESIZE
:
2382 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), smallFont
*2);
2385 else TexOutput(_T("}\n"));
2393 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), tinyFont
*2);
2396 else TexOutput(_T("}\n"));
2403 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), normalFont
*2);
2406 else TexOutput(_T("}\n"));
2413 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), largeFont1
*2);
2416 else TexOutput(_T("}\n"));
2423 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LargeFont2
*2);
2426 else TexOutput(_T("}\n"));
2433 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LARGEFont3
*2);
2436 else TexOutput(_T("}\n"));
2443 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), hugeFont1
*2);
2446 else TexOutput(_T("}\n"));
2453 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HugeFont2
*2);
2456 else TexOutput(_T("}\n"));
2463 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HUGEFont3
*2);
2466 else TexOutput(_T("}\n"));
2475 TexOutput(_T("{\\b "));
2477 else TexOutput(_T("}"));
2484 TexOutput(_T("{\\ul "));
2486 else TexOutput(_T("}"));
2497 TexOutput(_T("{\\i "));
2499 else TexOutput(_T("}"));
2502 // Roman font: do nothing. Should really switch between
2511 TexOutput(_T("{\\plain "));
2513 else TexOutput(_T("}"));
2517 // Medium-weight font. Unbolden...
2522 TexOutput(_T("{\\b0 "));
2524 else TexOutput(_T("}"));
2527 // Upright (un-italic or slant)
2532 TexOutput(_T("{\\i0 "));
2534 else TexOutput(_T("}"));
2543 TexOutput(_T("{\\scaps "));
2545 else TexOutput(_T("}"));
2554 TexOutput(_T("{\\f3 "));
2556 else TexOutput(_T("}"));
2562 TexOutput(_T("\\{"));
2568 TexOutput(_T("\\}"));
2574 TexOutput(_T("\\\\"));
2581 if ( issuedNewParagraph
== 0 )
2583 TexOutput(_T("\\par\\pard"));
2584 issuedNewParagraph
++;
2586 // Extra par if parskip is more than zero (usually looks best.)
2587 // N.B. JACS 2004-02-21: shouldn't need this for linear RTF if
2588 // we have a suitable set of styles.
2590 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2592 TexOutput(_T("\\par"));
2593 issuedNewParagraph
++;
2596 WriteEnvironmentStyles();
2598 // 1 is a whole paragraph if ParSkip == 0,
2599 // half a paragraph if ParSkip > 0
2600 else if ( issuedNewParagraph
== 1 )
2602 // Don't need a par at all if we've already had one,
2603 // and ParSkip == 0.
2605 // Extra par if parskip is more than zero (usually looks best.)
2606 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2608 TexOutput(_T("\\par"));
2609 issuedNewParagraph
++;
2612 WriteEnvironmentStyles();
2615 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2617 TexOutput(_T("\\par\\pard"));
2619 // Extra par if parskip is more than zero (usually looks best.)
2620 if (!inTabular && (ParSkip > 0))
2621 TexOutput(_T("\\par"));
2622 WriteEnvironmentStyles();
2626 TexOutput(_T("\n"));
2632 // In Windows Help, no newpages until we've started some chapters or sections
2633 if (!(winHelp
&& !startedSections
))
2635 TexOutput(_T("\\page\n"));
2640 if (start
&& DocumentTitle
)
2642 TexOutput(_T("\\par\\pard"));
2644 TexOutput(_T("\\par"));
2645 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d\\b "), titleFont
*2);
2647 TraverseChildrenFromChunk(DocumentTitle
);
2648 TexOutput(_T("}\\par\\pard\n"));
2653 TexOutput(_T("\\par"));
2654 wxSnprintf(buf
, sizeof(buf
), _T("\\par\\qc{\\fs%d "), authorFont
*2);
2656 TraverseChildrenFromChunk(DocumentAuthor
);
2658 TexOutput(_T("\\par\\pard\n"));
2662 TexOutput(_T("\\par"));
2663 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d "), authorFont
*2);
2665 TraverseChildrenFromChunk(DocumentDate
);
2666 TexOutput(_T("}\\par\\pard\n"));
2668 // If linear RTF, we want this titlepage to be in a separate
2669 // section with its own (blank) header and footer
2670 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2672 TexOutput(_T("{\\header }{\\footer }\n"));
2673 // Not sure about this: we get too many sections.
2674 // TexOutput(_T("\\sect"));
2679 case ltADDCONTENTSLINE
:
2683 if (contentsLineSection
&& contentsLineValue
)
2685 if (wxStrcmp(contentsLineSection
, _T("chapter")) == 0)
2687 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2689 else if (wxStrcmp(contentsLineSection
, _T("section")) == 0)
2691 if (DocumentStyle
!= LATEX_ARTICLE
)
2692 wxFprintf(Contents
, _T("\n\\tab%s\\par\n"), contentsLineValue
);
2694 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2704 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2705 issuedNewParagraph
= 1;
2706 WriteEnvironmentStyles();
2714 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2715 issuedNewParagraph
= 1;
2716 WriteEnvironmentStyles();
2726 case ltNUMBEREDBIBITEM
:
2729 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
2731 TexOutput(_T("\\par\\pard\\par\n\n"));
2738 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2746 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2747 wxSnprintf(buf
, sizeof(buf
), _T("%d"), chapterNo
);
2756 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2757 wxSnprintf(buf
, sizeof(buf
), _T("%d"), sectionNo
);
2764 if (!start
&& !winHelp
)
2766 TexOutput(_T("\\cols2\n"));
2772 if (!start
&& !winHelp
)
2774 TexOutput(_T("\\cols1\n"));
2780 if (start
&& useWord
&& !winHelp
)
2782 FakeCurrentSection(_T("Index"));
2783 OnMacro(ltPAR
, 0, true);
2784 OnMacro(ltPAR
, 0, false);
2785 TexOutput(_T("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n"));
2789 case ltLISTOFFIGURES
:
2791 if (start
&& useWord
&& !winHelp
)
2793 FakeCurrentSection(FiguresNameString
, false);
2794 OnMacro(ltPAR
, 0, true);
2795 OnMacro(ltPAR
, 0, false);
2796 OnMacro(ltPAR
, 0, true);
2797 OnMacro(ltPAR
, 0, false);
2799 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"),
2805 case ltLISTOFTABLES
:
2807 if (start
&& useWord
&& !winHelp
)
2809 FakeCurrentSection(TablesNameString
, false);
2810 OnMacro(ltPAR
, 0, true);
2811 OnMacro(ltPAR
, 0, false);
2812 OnMacro(ltPAR
, 0, true);
2813 OnMacro(ltPAR
, 0, false);
2815 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"),
2823 if (start
) TexOutput(_T("{\\f1\\'61}"));
2826 if (start
) TexOutput(_T("{\\f1\\'62}"));
2829 if (start
) TexOutput(_T("{\\f1\\'63}"));
2832 if (start
) TexOutput(_T("{\\f1\\'64}"));
2836 if (start
) TexOutput(_T("{\\f1\\'65}"));
2839 if (start
) TexOutput(_T("{\\f1\\'7A}"));
2842 if (start
) TexOutput(_T("{\\f1\\'68}"));
2846 if (start
) TexOutput(_T("{\\f1\\'71}"));
2849 if (start
) TexOutput(_T("{\\f1\\'69}"));
2852 if (start
) TexOutput(_T("{\\f1\\'6B}"));
2855 if (start
) TexOutput(_T("{\\f1\\'6C}"));
2858 if (start
) TexOutput(_T("{\\f1\\'6D}"));
2861 if (start
) TexOutput(_T("{\\f1\\'6E}"));
2864 if (start
) TexOutput(_T("{\\f1\\'78}"));
2867 if (start
) TexOutput(_T("{\\f1\\'70}"));
2870 if (start
) TexOutput(_T("{\\f1\\'76}"));
2874 if (start
) TexOutput(_T("{\\f1\\'72}"));
2877 if (start
) TexOutput(_T("{\\f1\\'73}"));
2880 if (start
) TexOutput(_T("{\\f1\\'56}"));
2883 if (start
) TexOutput(_T("{\\f1\\'74}"));
2886 if (start
) TexOutput(_T("{\\f1\\'75}"));
2890 if (start
) TexOutput(_T("{\\f1\\'66}"));
2893 if (start
) TexOutput(_T("{\\f1\\'63}"));
2896 if (start
) TexOutput(_T("{\\f1\\'79}"));
2899 if (start
) TexOutput(_T("{\\f1\\'77}"));
2902 if (start
) TexOutput(_T("{\\f1\\'47}"));
2905 if (start
) TexOutput(_T("{\\f1\\'44}"));
2908 if (start
) TexOutput(_T("{\\f1\\'51}"));
2911 if (start
) TexOutput(_T("{\\f1\\'4C}"));
2914 if (start
) TexOutput(_T("{\\f1\\'58}"));
2917 if (start
) TexOutput(_T("{\\f1\\'50}"));
2920 if (start
) TexOutput(_T("{\\f1\\'53}"));
2923 if (start
) TexOutput(_T("{\\f1\\'54}"));
2926 if (start
) TexOutput(_T("{\\f1\\'46}"));
2929 if (start
) TexOutput(_T("{\\f1\\'59}"));
2932 if (start
) TexOutput(_T("{\\f1\\'57}"));
2934 // Binary operation symbols
2937 if (start
) TexOutput(_T("{\\f1\\'A3}"));
2940 if (start
) TexOutput(_T("<<"));
2943 if (start
) TexOutput(_T("{\\f1\\'CC}"));
2946 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2949 if (start
) TexOutput(_T("{\\f1\\'CE}"));
2953 if (start
) TexOutput(_T("{\\f1\\'B3}"));
2956 if (start
) TexOutput(_T(">>"));
2959 if (start
) TexOutput(_T("{\\f1\\'C9}"));
2962 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2965 if (start
) TexOutput(_T("{\\f1\\'27}"));
2968 if (start
) TexOutput(_T("{\\f1\\'5E}"));
2971 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2974 if (start
) TexOutput(_T("{\\f1\\'BB}"));
2977 if (start
) TexOutput(_T("{\\f1\\'40}"));
2980 if (start
) TexOutput(_T("{\\f1\\'BA}"));
2983 if (start
) TexOutput(_T("{\\f1\\'B5}"));
2986 if (start
) TexOutput(_T("{\\f1\\'7E}"));
2989 if (start
) TexOutput(_T("{\\f4\\'4A}"));
2992 if (start
) TexOutput(_T("{\\f4\\'4C}"));
2995 if (start
) TexOutput(_T("|"));
2998 // Negated relation symbols
3000 if (start
) TexOutput(_T("{\\f1\\'B9}"));
3003 if (start
) TexOutput(_T("{\\f1\\'CF}"));
3006 if (start
) TexOutput(_T("{\\f1\\'CB}"));
3011 if (start
) TexOutput(_T("{\\f1\\'AC}"));
3014 if (start
) TexOutput(_T("{\\f1\\'DC}"));
3017 if (start
) TexOutput(_T("{\\f1\\'AE}"));
3020 if (start
) TexOutput(_T("{\\f1\\'DE}"));
3022 case ltLEFTRIGHTARROW
:
3023 if (start
) TexOutput(_T("{\\f1\\'AB}"));
3025 case ltLEFTRIGHTARROW2
:
3026 if (start
) TexOutput(_T("{\\f1\\'DB}"));
3029 if (start
) TexOutput(_T("{\\f1\\'AD}"));
3032 if (start
) TexOutput(_T("{\\f1\\'DD}"));
3035 if (start
) TexOutput(_T("{\\f1\\'AF}"));
3038 if (start
) TexOutput(_T("{\\f1\\'DF}"));
3041 // Miscellaneous symbols
3043 if (start
) TexOutput(_T("{\\f1\\'CO}"));
3046 if (start
) TexOutput(_T("{\\f1\\'C3}"));
3049 if (start
) TexOutput(_T("{\\f1\\'C2}"));
3052 if (start
) TexOutput(_T("{\\f1\\'C1}"));
3055 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3058 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3061 if (start
) TexOutput(_T("{\\f1\\'D6}"));
3064 if (start
) TexOutput(_T("{\\f1\\'B6}"));
3067 if (start
) TexOutput(_T("{\\f1\\'5E}"));
3070 if (start
) TexOutput(_T("{\\f1\\'22}"));
3073 if (start
) TexOutput(_T("{\\f1\\'24}"));
3076 if (start
) TexOutput(_T("{\\f1\\'D8}"));
3079 if (start
) TexOutput(_T("{\\f1\\'23}"));
3082 if (start
) TexOutput(_T("{\\f1\\'D0}"));
3085 if (start
) TexOutput(_T("{\\f5\\'73}"));
3088 if (start
) TexOutput(_T("{\\f5\\'A8}"));
3091 if (start
) TexOutput(_T("{\\f5\\'A9}"));
3094 if (start
) TexOutput(_T("{\\f5\\'AA}"));
3097 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3100 if (start
) TexOutput(_T("{\\f1\\'A5}"));
3103 if (start
) TexOutput(_T("{\\f0\\'A9}"));
3106 if (start
) TexOutput(_T("{\\f0\\'AE}"));
3109 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3112 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3115 if (start
) TexOutput(_T("{\\f1\\'B4}"));
3118 if (start
) TexOutput(_T("{\\f1\\'B8}"));
3121 if (start
) TexOutput(_T("{\\f1\\'D7}"));
3124 if (start
) TexOutput(_T("{\\f1\\'2A}"));
3127 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3130 if (start
) TexOutput(_T("{\\f1\\'C7}"));
3133 if (start
) TexOutput(_T("{\\f1\\'C8}"));
3136 if (start
) TexOutput(_T("{\\f1\\'DA}"));
3139 if (start
) TexOutput(_T("{\\f1\\'D9}"));
3142 if (start
) TexOutput(_T("{\\f1\\'B0}"));
3145 if (start
) TexOutput(_T("{\\f1\\'B7}"));
3148 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3151 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3154 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3156 case ltBIGTRIANGLEDOWN
:
3157 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3160 if (start
) TexOutput(_T("{\\f1\\'C5}"));
3163 if (start
) TexOutput(_T("{\\f1\\'C4}"));
3166 if (start
) TexOutput(_T("{\\'DF}"));
3170 if (start
) inFigure
= true;
3171 else inFigure
= false;
3176 if (start
) inTable
= true;
3177 else inTable
= false;
3182 DefaultOnMacro(macroId
, no_args
, start
);
3188 // Called on start/end of argument examination
3189 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3196 case ltCHAPTERHEADING
:
3199 case ltSECTIONHEADING
:
3201 case ltSUBSECTIONSTAR
:
3202 case ltSUBSUBSECTION
:
3203 case ltSUBSUBSECTIONSTAR
:
3205 case ltMEMBERSECTION
:
3206 case ltFUNCTIONSECTION
:
3210 if (!start
&& (arg_no
== 1))
3211 currentSection
= GetArgChunk();
3216 if (start
&& (arg_no
== 1))
3217 TexOutput(_T("\\pard\\li600\\fi-600{\\b "));
3219 if (!start
&& (arg_no
== 1))
3220 TexOutput(_T("} "));
3222 if (start
&& (arg_no
== 2))
3224 if (!suppressNameDecoration
) TexOutput(_T("{\\b "));
3225 currentMember
= GetArgChunk();
3227 if (!start
&& (arg_no
== 2))
3229 if (!suppressNameDecoration
) TexOutput(_T("}"));
3232 if (start
&& (arg_no
== 3))
3234 if (!start
&& (arg_no
== 3))
3236 // TexOutput(_T(")\\li0\\fi0"));
3237 // TexOutput(_T(")\\par\\pard\\li0\\fi0"));
3238 // issuedNewParagraph = 1;
3240 WriteEnvironmentStyles();
3246 if (start
&& (arg_no
== 1))
3247 TexOutput(_T("\\pard\\li260\\fi-260{\\b "));
3248 if (!start
&& (arg_no
== 1))
3249 TexOutput(_T("} "));
3251 if (start
&& (arg_no
== 2))
3253 if (!suppressNameDecoration
) TexOutput(_T("({\\b "));
3254 currentMember
= GetArgChunk();
3256 if (!start
&& (arg_no
== 2))
3258 if (!suppressNameDecoration
) TexOutput(_T("}"));
3261 if (!start
&& (arg_no
== 3))
3263 TexOutput(_T(")\\li0\\fi0"));
3264 WriteEnvironmentStyles();
3270 if (start
&& (arg_no
== 1))
3271 TexOutput(_T("\\pard\\li260\\fi-260"));
3273 if (!start
&& (arg_no
== 1))
3276 if (start
&& (arg_no
== 2))
3277 TexOutput(_T("(*"));
3278 if (!start
&& (arg_no
== 2))
3281 if (start
&& (arg_no
== 2))
3282 currentMember
= GetArgChunk();
3284 if (start
&& (arg_no
== 3))
3286 if (!start
&& (arg_no
== 3))
3288 TexOutput(_T(")\\li0\\fi0"));
3289 WriteEnvironmentStyles();
3295 if (start
&& (arg_no
== 1))
3296 TexOutput(_T("{\\b "));
3297 if (!start
&& (arg_no
== 1))
3299 if (start
&& (arg_no
== 2))
3301 TexOutput(_T("{\\i "));
3303 if (!start
&& (arg_no
== 2))
3311 if (start
&& (arg_no
== 1))
3312 TexOutput(_T("{\\b "));
3313 if (!start
&& (arg_no
== 1))
3314 TexOutput(_T("} ")); // This is the difference from param - one space!
3315 if (start
&& (arg_no
== 2))
3317 TexOutput(_T("{\\i "));
3319 if (!start
&& (arg_no
== 2))
3327 if (!start
&& (arg_no
== 1))
3330 if (start
&& (arg_no
== 2))
3331 currentMember
= GetArgChunk();
3340 wxChar
*refName
= GetArgData();
3341 if (winHelp
|| !useWord
)
3345 TexRef
*texRef
= FindReference(refName
);
3348 sec
= texRef
->sectionNumber
;
3358 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
3370 if ((GetNoArgs() - arg_no
) == 1)
3373 TexOutput(_T("{\\uldb "));
3377 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3381 TexOutput(_T("{\\v "));
3383 // Remove green colour/underlining if specified
3384 if (!hotSpotUnderline
&& !hotSpotColour
)
3386 else if (!hotSpotColour
)
3389 else TexOutput(_T("}"));
3392 else // If a linear document, must resolve the references ourselves
3394 if ((GetNoArgs() - arg_no
) == 1)
3396 // In a linear document we display the anchor text in italic plus
3399 TexOutput(_T("{\\i "));
3404 helpRefText
= GetArgChunk();
3408 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3410 if (macroId
!= ltHELPREFN
)
3412 wxChar
*refName
= GetArgData();
3413 TexRef
*texRef
= NULL
;
3415 texRef
= FindReference(refName
);
3418 if (texRef
|| !ignoreBadRefs
)
3419 TexOutput(_T(" ("));
3422 if (texRef
|| !ignoreBadRefs
)
3426 TexOutput(_T("p. "));
3427 TexOutput(_T("{\\field{\\*\\fldinst PAGEREF "));
3429 TexOutput(_T(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"));
3433 // Only print section name if we're not in Word mode,
3434 // so can't do page references
3437 TexOutput(texRef
->sectionName
);
3439 TexOutput(texRef
->sectionNumber
);
3444 TexOutput(_T("??"));
3445 wxSnprintf(buf
, sizeof(buf
), _T("Warning: unresolved reference '%s'"), refName
);
3451 else TexOutput(_T("??"));
3455 if (texRef
|| !ignoreBadRefs
)
3470 else if (arg_no
== 2)
3475 TexOutput(_T(" ({\\f3 "));
3479 TexOutput(_T("})"));
3490 if ((GetNoArgs() - arg_no
) == 1)
3493 TexOutput(_T("{\\ul "));
3497 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3501 TexOutput(_T("{\\v "));
3503 // Remove green colour/underlining if specified
3504 if (!hotSpotUnderline
&& !hotSpotColour
)
3506 else if (!hotSpotColour
)
3509 else TexOutput(_T("}"));
3512 else // A linear document...
3514 if ((GetNoArgs() - arg_no
) == 1)
3516 // In a linear document we just display the anchor text in italic
3518 TexOutput(_T("{\\i "));
3527 case ltADDCONTENTSLINE
:
3529 if (start
&& !winHelp
)
3532 contentsLineSection
= copystring(GetArgData());
3533 else if (arg_no
== 3)
3534 contentsLineValue
= copystring(GetArgData());
3548 static int imageWidth
= 0;
3549 static int imageHeight
= 0;
3551 if (start
&& (arg_no
== 1))
3553 wxChar
*imageDimensions
= copystring(GetArgData());
3555 // imageWidth - Convert points to TWIPS (1 twip = 1/20th of point)
3556 wxStringTokenizer
tok(imageDimensions
, _T(";:"), wxTOKEN_STRTOK
);
3557 if(tok
.HasMoreTokens())
3559 wxString token
= tok
.GetNextToken();
3560 imageWidth
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3567 // imageHeight - Convert points to TWIPS (1 twip = 1/20th of point)
3568 if(tok
.HasMoreTokens())
3570 wxString token
= tok
.GetNextToken();
3571 imageHeight
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3578 if (imageDimensions
) // glt
3579 delete [] imageDimensions
;
3582 else if (start
&& (arg_no
== 2 ))
3584 wxChar
*filename
= copystring(GetArgData());
3585 wxString f
= _T("");
3586 if ((winHelp
|| (wxStrcmp(bitmapMethod
, _T("includepicture")) == 0) || (wxStrcmp(bitmapMethod
, _T("import")) == 0)) && useWord
)
3588 if (f
== _T("")) // Try for a .shg (segmented hypergraphics file)
3590 wxStrcpy(buf
, filename
);
3591 StripExtension(buf
);
3592 wxStrcat(buf
, _T(".shg"));
3593 f
= TexPathList
.FindValidPath(buf
);
3595 if (f
== _T("")) // Try for a .bmp
3597 wxStrcpy(buf
, filename
);
3598 StripExtension(buf
);
3599 wxStrcat(buf
, _T(".bmp"));
3600 f
= TexPathList
.FindValidPath(buf
);
3602 if (f
== _T("")) // Try for a metafile instead
3604 wxStrcpy(buf
, filename
);
3605 StripExtension(buf
);
3606 wxStrcat(buf
, _T(".wmf"));
3607 f
= TexPathList
.FindValidPath(buf
);
3613 if (bitmapTransparency
&& (winHelpVersion
> 3))
3614 TexOutput(_T("\\{bmct "));
3616 TexOutput(_T("\\{bmc "));
3617 wxString str
= wxFileNameFromPath(f
);
3618 TexOutput((wxChar
*) (const wxChar
*) str
);
3619 TexOutput(_T("\\}"));
3623 // Microsoft Word method
3624 if (wxStrcmp(bitmapMethod
, _T("import")) == 0)
3625 TexOutput(_T("{\\field{\\*\\fldinst IMPORT "));
3627 TexOutput(_T("{\\field{\\*\\fldinst INCLUDEPICTURE "));
3629 // Full path appears not to be valid!
3630 wxString str
= wxFileNameFromPath(f
);
3631 TexOutput((wxChar
*)(const wxChar
*) str
);
3633 int len = wxStrlen(f);
3634 wxChar smallBuf[2]; smallBuf[1] = 0;
3635 for (int i = 0; i < len; i++)
3638 TexOutput(smallBuf);
3639 if (smallBuf[0] == '\\')
3640 TexOutput(smallBuf);
3643 TexOutput(_T("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}"));
3648 TexOutput(_T("[No BMP or WMF for image file "));
3649 TexOutput(filename
);
3651 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3654 if (filename
) // glt
3659 if (f
== _T("")) // Try for a .bmp
3661 wxStrcpy(buf
, filename
);
3662 StripExtension(buf
);
3663 wxStrcat(buf
, _T(".bmp"));
3664 f
= TexPathList
.FindValidPath(buf
);
3668 FILE *fd
= wxFopen(f
, _T("rb"));
3669 if (OutputBitmapHeader(fd
, winHelp
))
3670 OutputBitmapData(fd
);
3673 wxSnprintf(buf
, sizeof(buf
), _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f
.c_str());
3678 else // Try for a metafile instead
3681 wxStrcpy(buf
, filename
);
3682 StripExtension(buf
);
3683 wxStrcat(buf
, _T(".wmf"));
3684 f
= TexPathList
.FindValidPath(buf
);
3687 // HFILE handle = _lopen(f, READ);
3688 FILE *fd
= wxFopen(f
, _T("rb"));
3689 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3691 OutputMetafileData(fd
);
3695 wxSnprintf(buf
, sizeof(buf
), _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f
.c_str());
3703 TexOutput(_T("[No BMP or WMF for image file "));
3704 TexOutput(filename
);
3706 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3719 case ltSUPERTABULAR
:
3725 currentRowNumber
= 0;
3728 tableVerticalLineLeft
= false;
3729 tableVerticalLineRight
= false;
3730 int currentWidth
= 0;
3732 wxChar
*alignString
= copystring(GetArgData());
3733 ParseTableArgument(alignString
);
3735 // TexOutput(_T("\\trowd\\trgaph108\\trleft-108"));
3736 TexOutput(_T("\\trowd\\trgaph108"));
3738 // Write the first row formatting for compatibility
3739 // with standard Latex
3740 if (compatibilityMode
)
3742 for (int i
= 0; i
< noColumns
; i
++)
3744 currentWidth
+= TableData
[i
].width
;
3745 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
3748 TexOutput(_T("\\pard\\intbl\n"));
3750 delete[] alignString
;
3755 else if (arg_no
== 2 && !start
)
3757 TexOutput(_T("\\pard\n"));
3758 WriteEnvironmentStyles();
3769 TexOutput(_T("\\li360\n"));
3771 PushEnvironmentStyle(_T("\\li360\\sa200"));
3776 PopEnvironmentStyle();
3777 OnMacro(ltPAR
, 0, true);
3778 OnMacro(ltPAR
, 0, false);
3786 TexOutput(_T("\\li360\n"));
3787 PushEnvironmentStyle(_T("\\li360\\sa200"));
3791 PopEnvironmentStyle();
3792 OnMacro(ltPAR
, 0, true);
3793 OnMacro(ltPAR
, 0, false);
3805 wxSnprintf(buf
, sizeof(buf
), _T("\\sa200\\box\\trgaph108%s\n"), ((macroId
== ltNORMALBOXD
) ? _T("\\brdrdb") : _T("\\brdrs")));
3807 PushEnvironmentStyle(buf
);
3811 PopEnvironmentStyle();
3812 OnMacro(ltPAR
, 0, true);
3813 OnMacro(ltPAR
, 0, false);
3817 case ltHELPFONTSIZE
:
3821 wxChar
*data
= GetArgData();
3822 if (wxStrcmp(data
, _T("10")) == 0)
3824 else if (wxStrcmp(data
, _T("11")) == 0)
3826 else if (wxStrcmp(data
, _T("12")) == 0)
3828 wxSnprintf(buf
, sizeof(buf
), _T("\\fs%d\n"), normalFont
*2);
3835 case ltHELPFONTFAMILY
:
3839 wxChar
*data
= GetArgData();
3840 if (wxStrcmp(data
, _T("Swiss")) == 0)
3841 TexOutput(_T("\\f2\n"));
3842 else if (wxStrcmp(data
, _T("Symbol")) == 0)
3843 TexOutput(_T("\\f1\n"));
3844 else if (wxStrcmp(data
, _T("Times")) == 0)
3845 TexOutput(_T("\\f0\n"));
3853 if (start
&& arg_no
== 1)
3855 wxChar
*data
= GetArgData();
3856 ParIndent
= ParseUnitArgument(data
);
3857 if (ParIndent
== 0 || forbidParindent
== 0)
3859 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d\n"), ParIndent
*20);
3868 if (start
&& IsArgOptional())
3870 descriptionItemArg
= GetArgChunk();
3876 case ltTWOCOLITEMRULED
:
3883 TexOutput(_T("\\tab "));
3890 if (macroId
== ltTWOCOLITEMRULED
)
3891 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
3892 TexOutput(_T("\\par\\pard\n"));
3893 issuedNewParagraph
= 1;
3894 WriteEnvironmentStyles();
3905 case ltACCENT_GRAVE
:
3909 wxChar
*val
= GetArgData();
3915 TexOutput(_T("\\'e0"));
3918 TexOutput(_T("\\'e8"));
3921 TexOutput(_T("\\'ec"));
3924 TexOutput(_T("\\'f2"));
3927 TexOutput(_T("\\'f9"));
3930 TexOutput(_T("\\'c0"));
3933 TexOutput(_T("\\'c8"));
3936 TexOutput(_T("\\'cc"));
3939 TexOutput(_T("\\'d2"));
3942 TexOutput(_T("\\'d9"));
3951 case ltACCENT_ACUTE
:
3955 wxChar
*val
= GetArgData();
3961 TexOutput(_T("\\'e1"));
3964 TexOutput(_T("\\'e9"));
3967 TexOutput(_T("\\'ed"));
3970 TexOutput(_T("\\'f3"));
3973 TexOutput(_T("\\'fa"));
3976 TexOutput(_T("\\'fd"));
3979 TexOutput(_T("\\'c1"));
3982 TexOutput(_T("\\'c9"));
3985 TexOutput(_T("\\'cd"));
3988 TexOutput(_T("\\'d3"));
3991 TexOutput(_T("\\'da"));
3994 TexOutput(_T("\\'dd"));
4003 case ltACCENT_CARET
:
4007 wxChar
*val
= GetArgData();
4013 TexOutput(_T("\\'e2"));
4016 TexOutput(_T("\\'ea"));
4019 TexOutput(_T("\\'ee"));
4022 TexOutput(_T("\\'f4"));
4025 TexOutput(_T("\\'fb"));
4028 TexOutput(_T("\\'c2"));
4031 TexOutput(_T("\\'ca"));
4034 TexOutput(_T("\\'ce"));
4037 TexOutput(_T("\\'d4"));
4040 TexOutput(_T("\\'db"));
4049 case ltACCENT_TILDE
:
4053 wxChar
*val
= GetArgData();
4059 TexOutput(_T("\\'e3"));
4065 TexOutput(_T("\\'f1"));
4068 TexOutput(_T("\\'f5"));
4071 TexOutput(_T("\\'c3"));
4074 TexOutput(_T("\\'d1"));
4077 TexOutput(_T("\\'d5"));
4086 case ltACCENT_UMLAUT
:
4090 wxChar
*val
= GetArgData();
4096 TexOutput(_T("\\'e4"));
4099 TexOutput(_T("\\'eb"));
4102 TexOutput(_T("\\'ef"));
4105 TexOutput(_T("\\'f6"));
4108 TexOutput(_T("\\'fc"));
4111 TexOutput(_T("\\'df"));
4114 TexOutput(_T("\\'ff"));
4117 TexOutput(_T("\\'c4"));
4120 TexOutput(_T("\\'cb"));
4123 TexOutput(_T("\\'cf"));
4126 TexOutput(_T("\\'d6"));
4129 TexOutput(_T("\\'dc"));
4132 TexOutput(_T("\\'df"));
4145 wxChar
*val
= GetArgData();
4151 TexOutput(_T("\\'e5"));
4154 TexOutput(_T("\\'c5"));
4163 case ltACCENT_CADILLA
:
4167 wxChar
*val
= GetArgData();
4173 TexOutput(_T("\\'e7"));
4176 TexOutput(_T("\\'c7"));
4187 static wxChar
*helpTopic
= NULL
;
4188 static FILE *savedOutput
= NULL
;
4195 OnInform(_T("Consider using \\footnotepopup instead of \\footnote."));
4198 wxSnprintf(footBuf
, sizeof(footBuf
), _T("(%d)"), footnoteCount
);
4200 TexOutput(_T(" {\\ul "));
4203 helpTopic
= FindTopicName(NULL
);
4204 TexOutput(_T("{\\v "));
4206 // Remove green colour/underlining if specified
4207 if (!hotSpotUnderline
&& !hotSpotColour
)
4209 else if (!hotSpotColour
)
4212 TexOutput(helpTopic
);
4215 wxFprintf(Popups
, _T("\\page\n"));
4216 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4217 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4218 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4219 savedOutput
= CurrentOutput1
;
4220 SetCurrentOutput(Popups
);
4224 SetCurrentOutput(savedOutput
);
4234 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4238 TexOutput(_T("}}"), true);
4243 case ltFOOTNOTEPOPUP
:
4245 static wxChar
*helpTopic
= NULL
;
4246 static FILE *savedOutput
= NULL
;
4253 TexOutput(_T("{\\ul "));
4261 else if (arg_no
== 2)
4265 helpTopic
= FindTopicName(NULL
);
4266 TexOutput(_T("{\\v "));
4268 // Remove green colour/underlining if specified
4269 if (!hotSpotUnderline
&& !hotSpotColour
)
4271 else if (!hotSpotColour
)
4274 TexOutput(helpTopic
);
4277 wxFprintf(Popups
, _T("\\page\n"));
4278 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4279 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4280 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4281 savedOutput
= CurrentOutput1
;
4282 SetCurrentOutput(Popups
);
4286 SetCurrentOutput(savedOutput
);
4297 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4301 TexOutput(_T("}}"), true);
4309 if (start
&& (arg_no
== 1))
4321 if (winHelp
) return false;
4327 LeftHeaderEven
= GetArgChunk();
4328 if (wxStrlen(GetArgData(LeftHeaderEven
)) == 0)
4329 LeftHeaderEven
= NULL
;
4332 CentreHeaderEven
= GetArgChunk();
4333 if (wxStrlen(GetArgData(CentreHeaderEven
)) == 0)
4334 CentreHeaderEven
= NULL
;
4337 RightHeaderEven
= GetArgChunk();
4338 if (wxStrlen(GetArgData(RightHeaderEven
)) == 0)
4339 RightHeaderEven
= NULL
;
4342 LeftHeaderOdd
= GetArgChunk();
4343 if (wxStrlen(GetArgData(LeftHeaderOdd
)) == 0)
4344 LeftHeaderOdd
= NULL
;
4347 CentreHeaderOdd
= GetArgChunk();
4348 if (wxStrlen(GetArgData(CentreHeaderOdd
)) == 0)
4349 CentreHeaderOdd
= NULL
;
4352 RightHeaderOdd
= GetArgChunk();
4353 if (wxStrlen(GetArgData(RightHeaderOdd
)) == 0)
4354 RightHeaderOdd
= NULL
;
4355 OutputRTFHeaderCommands();
4370 if (winHelp
) return false;
4376 LeftFooterEven
= GetArgChunk();
4377 if (wxStrlen(GetArgData(LeftFooterEven
)) == 0)
4378 LeftFooterEven
= NULL
;
4381 CentreFooterEven
= GetArgChunk();
4382 if (wxStrlen(GetArgData(CentreFooterEven
)) == 0)
4383 CentreFooterEven
= NULL
;
4386 RightFooterEven
= GetArgChunk();
4387 if (wxStrlen(GetArgData(RightFooterEven
)) == 0)
4388 RightFooterEven
= NULL
;
4391 LeftFooterOdd
= GetArgChunk();
4392 if (wxStrlen(GetArgData(LeftFooterOdd
)) == 0)
4393 LeftFooterOdd
= NULL
;
4396 CentreFooterOdd
= GetArgChunk();
4397 if (wxStrlen(GetArgData(CentreFooterOdd
)) == 0)
4398 CentreFooterOdd
= NULL
;
4401 RightFooterOdd
= GetArgChunk();
4402 if (wxStrlen(GetArgData(RightFooterOdd
)) == 0)
4403 RightFooterOdd
= NULL
;
4404 OutputRTFFooterCommands();
4414 if (winHelp
) return false;
4415 // Fake a SetHeader command
4418 LeftHeaderOdd
= NULL
;
4419 CentreHeaderOdd
= NULL
;
4420 RightHeaderOdd
= NULL
;
4421 LeftHeaderEven
= NULL
;
4422 CentreHeaderEven
= NULL
;
4423 RightHeaderEven
= NULL
;
4424 OnInform(_T("Consider using setheader/setfooter rather than markright."));
4426 RTFOnArgument(ltSETHEADER
, 4, start
);
4428 OutputRTFHeaderCommands();
4433 if (winHelp
) return false;
4434 // Fake a SetHeader command
4441 LeftHeaderOdd
= NULL
;
4442 CentreHeaderOdd
= NULL
;
4443 RightHeaderOdd
= NULL
;
4444 LeftHeaderEven
= NULL
;
4445 CentreHeaderEven
= NULL
;
4446 RightHeaderEven
= NULL
;
4447 OnInform(_T("Consider using setheader/setfooter rather than markboth."));
4449 return RTFOnArgument(ltSETHEADER
, 1, start
);
4453 RTFOnArgument(ltSETHEADER
, 4, start
);
4455 OutputRTFHeaderCommands();
4461 case ltPAGENUMBERING
:
4468 if (winHelp
) return false;
4471 TexOutput(_T("\\pgnrestart"));
4472 wxChar
*data
= GetArgData();
4473 if (currentNumberStyle
) delete[] currentNumberStyle
;
4474 currentNumberStyle
= copystring(data
);
4475 OutputNumberStyle(currentNumberStyle
);
4477 TexOutput(_T("\n"));
4483 if (winHelp
) return false;
4492 wxChar
*val
= GetArgData();
4493 currentItemSep
= ParseUnitArgument(val
);
4498 case ltEVENSIDEMARGIN
:
4502 case ltODDSIDEMARGIN
:
4506 wxChar
*val
= GetArgData();
4507 int twips
= (int)(20*ParseUnitArgument(val
));
4508 // Add an inch since in LaTeX it's specified minus an inch
4510 CurrentLeftMarginOdd
= twips
;
4511 wxSnprintf(buf
, sizeof(buf
), _T("\\margl%d\n"), twips
);
4514 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4518 case ltMARGINPARWIDTH
:
4522 wxChar
*val
= GetArgData();
4523 int twips
= (int)(20*ParseUnitArgument(val
));
4524 CurrentMarginParWidth
= twips
;
4528 case ltMARGINPARSEP
:
4532 wxChar
*val
= GetArgData();
4533 int twips
= (int)(20*ParseUnitArgument(val
));
4534 CurrentMarginParSep
= twips
;
4535 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4543 wxChar
*val
= GetArgData();
4544 int twips
= (int)(20*ParseUnitArgument(val
));
4545 CurrentTextWidth
= twips
;
4547 // Need to set an implicit right margin
4548 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4549 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4550 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4551 wxSnprintf(buf
, sizeof(buf
), _T("\\margr%d\n"), CurrentRightMarginOdd
);
4557 case ltMARGINPARODD
:
4563 TexOutput(_T("\\sa200\\box\n"));
4564 PushEnvironmentStyle(_T("\\sa200\\box"));
4568 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4577 TexOutput(_T("\\par\\pard\n"));
4578 PopEnvironmentStyle();
4579 WriteEnvironmentStyles();
4582 TexOutput(_T("\\par\\pard\n"));
4583 issuedNewParagraph
= 1;
4587 case ltMARGINPAREVEN
:
4593 TexOutput(_T("\\sa200\\box\n"));
4594 PushEnvironmentStyle(_T("\\sa200\\box"));
4600 // Have to calculate what the margins are changed to in WfW margin
4601 // mirror mode, on an even (left-hand) page.
4602 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4603 - CurrentTextWidth
+ GutterWidth
;
4604 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), x
, CurrentMarginParWidth
);
4609 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4619 TexOutput(_T("\\par\\pard\n"));
4620 PopEnvironmentStyle();
4621 WriteEnvironmentStyles();
4624 issuedNewParagraph
= 1;
4625 TexOutput(_T("\\par\\pard\n"));
4629 case ltTWOCOLWIDTHA
:
4633 wxChar
*val
= GetArgData();
4634 int twips
= (int)(20*ParseUnitArgument(val
));
4635 TwoColWidthA
= twips
;
4639 case ltTWOCOLWIDTHB
:
4643 wxChar
*val
= GetArgData();
4644 int twips
= (int)(20*ParseUnitArgument(val
));
4645 TwoColWidthB
= twips
;
4654 int currentWidth
= 0;
4656 if (!compatibilityMode
|| (currentRowNumber
> 0))
4658 TexOutput(_T("\\pard\\intbl"));
4660 if (macroId
== ltRULEDROW
)
4662 for (int i
= 0; i
< noColumns
; i
++)
4664 currentWidth
+= TableData
[i
].width
;
4667 TexOutput(_T("\\clbrdrt\\brdrs\\brdrw15"));
4669 else if (ruleTop
> 1)
4671 TexOutput(_T("\\clbrdrt\\brdrdb\\brdrw15"));
4673 if (ruleBottom
== 1)
4675 TexOutput(_T("\\clbrdrb\\brdrs\\brdrw15"));
4677 else if (ruleBottom
> 1)
4679 TexOutput(_T("\\clbrdrb\\brdrdb\\brdrw15"));
4682 if (TableData
[i
].rightBorder
)
4683 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
4685 if (TableData
[i
].leftBorder
)
4686 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
4688 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
4691 TexOutput(_T("\\pard\\intbl\n"));
4695 currentRowNumber
++;
4700 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
4701 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
4707 static int noMultiColumns
= 0;
4714 noMultiColumns
= wxAtoi(GetArgData());
4731 for (int i
= 1; i
< noMultiColumns
; i
++)
4732 TexOutput(_T("\\cell"));
4739 if (start
&& (arg_no
== 1))
4742 // TexOutput(_T("\\fi0\n"));
4744 wxNode
*node
= itemizeStack
.GetFirst();
4746 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
4748 int indentValue
= 20*ParseUnitArgument(GetArgData());
4749 int indentSize
= indentValue
+ oldIndent
;
4751 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4752 itemizeStack
.Insert(struc
);
4754 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200 "), indentSize
, indentSize
);
4755 PushEnvironmentStyle(buf
);
4759 if (!start
&& (arg_no
== 2))
4761 PopEnvironmentStyle();
4762 if (itemizeStack
.GetFirst())
4764 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
4766 delete itemizeStack
.GetFirst();
4768 if (itemizeStack
.GetCount() == 0)
4770 TexOutput(_T("\\par\\pard\n"));
4771 issuedNewParagraph
= 1;
4772 WriteEnvironmentStyles();
4781 if (start && (arg_no == 1))
4784 wxNode *node = itemizeStack.GetFirst();
4786 oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
4788 int boxWidth = 20*ParseUnitArgument(GetArgData());
4790 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4791 int indentSize = indentValue + oldIndent;
4792 int indentSizeRight = indentSize + boxWidth;
4794 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4795 itemizeStack.Insert(struc);
4797 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\lr%d\\sa200\\box%s "), indentSize, indentSize, indentSizeRight,
4798 ((macroId == ltCENTEREDBOX) ? _T("\\brdrs") : _T("\\brdrdb")));
4799 PushEnvironmentStyle(buf);
4803 if (!start && (arg_no == 2))
4805 PopEnvironmentStyle();
4806 if (itemizeStack.GetFirst())
4808 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
4810 delete itemizeStack.GetFirst();
4812 if (itemizeStack.Number() == 0)
4814 TexOutput(_T("\\par\\pard\n"));
4815 issuedNewParagraph = 1;
4816 WriteEnvironmentStyles();
4823 case ltDOCUMENTSTYLE
:
4825 DefaultOnArgument(macroId
, arg_no
, start
);
4826 if (!start
&& !IsArgOptional())
4828 if (MinorDocumentStyleString
)
4830 if (StringMatch(_T("twoside"), MinorDocumentStyleString
))
4831 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4832 TexOutput(_T("\\margmirror\\facingp\\sbkodd"));
4833 if (StringMatch(_T("twocolumn"), MinorDocumentStyleString
))
4834 TexOutput(_T("\\cols2"));
4836 TexOutput(_T("\n"));
4840 case ltSETHOTSPOTCOLOUR
:
4841 case ltSETHOTSPOTCOLOR
:
4845 wxChar
*text
= GetArgData();
4846 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4847 hotSpotColour
= true;
4849 hotSpotColour
= false;
4853 case ltSETTRANSPARENCY
:
4857 wxChar
*text
= GetArgData();
4858 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4859 bitmapTransparency
= true;
4861 bitmapTransparency
= false;
4865 case ltSETHOTSPOTUNDERLINE
:
4869 wxChar
*text
= GetArgData();
4870 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4871 hotSpotUnderline
= true;
4873 hotSpotUnderline
= false;
4879 if (arg_no
== 1 && start
)
4881 wxChar
*citeKey
= GetArgData();
4882 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4885 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4886 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
4887 ref
->sectionNumber
= copystring(buf
);
4890 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
4891 wxSnprintf(buf
, sizeof(buf
), _T("{\\b [%d]} "), citeCount
);
4896 if (arg_no
== 2 && !start
)
4897 TexOutput(_T("\\par\\pard\\par\n\n"));
4900 case ltTHEBIBLIOGRAPHY
:
4902 if (start
&& (arg_no
== 1))
4906 SetCurrentOutputs(Contents
, Chapters
);
4910 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
4912 // If a non-custom page style, we generate the header now.
4913 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
4914 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
4915 wxStrcmp(PageStyle
, _T("headings")) == 0))
4917 OutputRTFHeaderCommands();
4918 OutputRTFFooterCommands();
4921 // Need to reset the current numbering style, or RTF forgets it.
4922 OutputNumberStyle(currentNumberStyle
);
4923 SetCurrentOutput(Contents
);
4926 wxFprintf(Chapters
, _T("\\page\n"));
4929 wxFprintf(Contents
, _T("\n{\\uldb %s}"), ReferencesNameString
);
4931 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %s}"), ReferencesNameString
);
4933 startedSections
= true;
4936 wxFprintf(Chapters
, _T("\n${\\footnote %s}"), ReferencesNameString
);
4938 wxChar
*topicName
= _T("bibliography");
4942 wxFprintf(Contents
, _T("{\\v %s}\\par\\pard\n"), topicName
);
4943 WriteEnvironmentStyles();
4946 wxFprintf(Contents
, _T("\\par\\par\\pard\n"));
4950 wxFprintf(Chapters
, _T("\n#{\\footnote %s}\n"), topicName
);
4951 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
4952 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ReferencesNameString
);
4953 GenerateKeywordsForTopic(topicName
);
4956 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
4957 wxFileNameFromPath(FileRoot
), "Contents");
4961 SetCurrentOutput(Chapters
);
4962 wxChar
*styleCommand
= _T("");
4963 if (!winHelp
&& useHeadingStyles
)
4964 styleCommand
= _T("\\s1");
4965 wxFprintf(Chapters
, _T("\\pard{%s"), (winHelp
? _T("\\keepn\\sa140\\sb140") : styleCommand
));
4966 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" References\\par\\pard}\n"));
4975 * In Windows help, all keywords should be at the start of the
4976 * topic, but Latex \index commands can be anywhere in the text.
4977 * So we're going to have to build up lists of keywords for a topic,
4978 * and insert them on the second pass.
4980 * In linear RTF, we can embed the index entry now.
4985 // wxChar *entry = GetArgData();
4987 OutputChunkToString(GetArgChunk(), buf
);
4992 AddKeyWordForTopic(CurrentTopic
, buf
);
4995 else GenerateIndexEntry(buf
);
5008 wxChar
*name
= GetArgData();
5009 int pos
= FindColourPosition(name
);
5012 wxSnprintf(buf
, sizeof(buf
), _T("{%s%d "), ((macroId
== ltFCOL
) ? _T("\\cf") : _T("\\cb")), pos
);
5017 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
5032 if (arg_no
== 2) TexOutput(_T("}"));
5038 if (start
&& !winHelp
&& useWord
)
5040 wxChar
*s
= GetArgData();
5041 // Only insert a bookmark here if it's not just been inserted
5042 // in a section heading.
5043 if ( !CurrentTopic
|| !(wxStrcmp(CurrentTopic
, s
) == 0) )
5045 if ( (!CurrentChapterName || !(CurrentChapterName && (wxStrcmp(CurrentChapterName, s) == 0))) &&
5046 (!CurrentSectionName || !(CurrentSectionName && (wxStrcmp(CurrentSectionName, s) == 0))) &&
5047 (!CurrentSubsectionName || !(CurrentSubsectionName && (wxStrcmp(CurrentSubsectionName, s) == 0)))
5051 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), s
,s
);
5058 if (start
&& useWord
&& !winHelp
)
5060 wxChar
*s
= GetArgData();
5061 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
5069 inPopRefSection
= true;
5071 inPopRefSection
= false;
5074 case ltINSERTATLEVEL
:
5076 // This macro allows you to insert text at a different level
5077 // from the current level, e.g. into the Sections from within a subsubsection.
5078 if (!winHelp
& useWord
)
5080 static int currentLevelNo
= 1;
5081 static FILE* oldLevelFile
= Chapters
;
5088 oldLevelFile
= CurrentOutput1
;
5090 wxChar
*str
= GetArgData();
5091 currentLevelNo
= wxAtoi(str
);
5093 // TODO: cope with article style (no chapters)
5094 switch (currentLevelNo
)
5098 outputFile
= Chapters
;
5103 outputFile
= Sections
;
5108 outputFile
= Subsections
;
5113 outputFile
= Subsubsections
;
5123 CurrentOutput1
= outputFile
;
5139 CurrentOutput1
= oldLevelFile
;
5145 return DefaultOnArgument(macroId
, arg_no
, start
);
5157 forbidParindent
= 0;
5158 contentsLineSection
= NULL
;
5159 contentsLineValue
= NULL
;
5160 descriptionItemArg
= NULL
;
5165 tableVerticalLineLeft
= false;
5166 tableVerticalLineRight
= false;
5168 startedSections
= false;
5172 if (InputFile
&& OutputFile
)
5174 // Do some RTF-specific transformations on all the strings,
5176 Text2RTF(GetTopLevelChunk());
5178 Contents
= wxFopen(TmpContentsName
, _T("w"));
5179 Chapters
= wxFopen(_T("chapters.rtf"), _T("w"));
5182 Sections
= wxFopen(_T("sections.rtf"), _T("w"));
5183 Subsections
= wxFopen(_T("subsections.rtf"), _T("w"));
5184 Subsubsections
= wxFopen(_T("subsubsections.rtf"), _T("w"));
5185 Popups
= wxFopen(_T("popups.rtf"), _T("w"));
5186 if (winHelpContents
)
5188 WinHelpContentsFile
= wxFopen(WinHelpContentsFileName
, _T("w"));
5189 if (WinHelpContentsFile
)
5190 wxFprintf(WinHelpContentsFile
, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot
));
5193 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5195 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5199 if (!Contents
|| !Chapters
)
5201 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5207 wxFprintf(Chapters
, _T("\n#{\\footnote Contents}\n"));
5208 wxFprintf(Chapters
, _T("${\\footnote Contents}\n"));
5209 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
5210 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ContentsNameString
);
5211 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
5215 wxFprintf(Chapters
, _T("\\titlepg\n"));
5216 wxFprintf(Contents
, _T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
5219 // In WinHelp, Contents title takes font of title.
5220 // In linear RTF, same as chapter headings.
5221 wxFprintf(Contents
, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"),
5222 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5224 // By default, Swiss, 11 point.
5225 wxFprintf(Chapters
, _T("\\f2\\fs22\n"));
5227 PushEnvironmentStyle(_T("\\f2\\fs22\\sa200"));
5229 SetCurrentOutput(Chapters
);
5234 OnInform(_T("Converting..."));
5238 FILE *Header
= wxFopen(_T("header.rtf"), _T("w"));
5241 OnError(_T("Ouch! Could not open temporary file header.rtf for writing."));
5244 WriteRTFHeader(Header
);
5247 PopEnvironmentStyle();
5252 // wxFprintf(Contents, _T("\\page\n"));
5253 wxFprintf(Chapters
, _T("\\page\n"));
5254 wxFprintf(Sections
, _T("\\page\n"));
5255 wxFprintf(Subsections
, _T("\\page\n"));
5256 wxFprintf(Subsubsections
, _T("\\page\n\n"));
5257 wxFprintf(Popups
, _T("\\page\n}\n"));
5260 // TexOutput(_T("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n"));
5262 TexOutput(_T("}\n"));
5263 fclose(Contents
); Contents
= NULL
;
5264 fclose(Chapters
); Chapters
= NULL
;
5267 fclose(Sections
); Sections
= NULL
;
5268 fclose(Subsections
); Subsections
= NULL
;
5269 fclose(Subsubsections
); Subsubsections
= NULL
;
5270 fclose(Popups
); Popups
= NULL
;
5271 if (winHelpContents
)
5273 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5279 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5281 wxConcatFiles(_T("tmp1.rtf"), _T("sections.rtf"), _T("tmp2.rtf"));
5283 wxConcatFiles(_T("tmp2.rtf"), _T("subsections.rtf"), _T("tmp3.rtf"));
5285 wxConcatFiles(_T("tmp3.rtf"), _T("subsubsections.rtf"), _T("tmp4.rtf"));
5287 wxConcatFiles(_T("tmp4.rtf"), _T("popups.rtf"), OutputFile
);
5290 wxRemoveFile(_T("tmp1.rtf"));
5291 wxRemoveFile(_T("tmp2.rtf"));
5292 wxRemoveFile(_T("tmp3.rtf"));
5293 wxRemoveFile(_T("tmp4.rtf"));
5297 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5299 if (wxFileExists(OutputFile
))
5300 wxRemoveFile(OutputFile
);
5303 cwdStr
= wxGetWorkingDirectory();
5305 wxString outputDirStr
;
5306 outputDirStr
= wxPathOnly(OutputFile
);
5308 // Determine if the temp file and the output file are in the same directory,
5309 // and if they are, then just rename the temp file rather than copying
5310 // it, as this is much faster when working with large (multi-megabyte files)
5311 if ((wxStrcmp(outputDirStr
.c_str(),_T("")) == 0) || // no path specified on output file
5312 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5314 wxRenameFile(_T("tmp1.rtf"), OutputFile
);
5318 wxCopyFile(_T("tmp1.rtf"), OutputFile
);
5322 wxRemoveFile(_T("tmp1.rtf"));
5325 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5327 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5329 wxCopyFile(TmpContentsName
, ContentsName
);
5330 wxRemoveFile(TmpContentsName
);
5333 wxRemoveFile(_T("chapters.rtf"));
5334 wxRemoveFile(_T("header.rtf"));
5338 wxRemoveFile(_T("sections.rtf"));
5339 wxRemoveFile(_T("subsections.rtf"));
5340 wxRemoveFile(_T("subsubsections.rtf"));
5341 wxRemoveFile(_T("popups.rtf"));
5343 if (winHelp
&& generateHPJ
)
5344 WriteHPJ(OutputFile
);