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
=xitle
[s
]&0xff;
247 wxChar ch1
=xitle
[s
+1]&0xff;
248 wxChar ch2
=xitle
[s
+2]&0xff;
249 wxChar ch3
=xitle
[s
+3]&0xff;
250 s
+=4; // next character
251 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x36)) { title
[d
++]='ö'; }
252 if ((ch1
==0x27)&&(ch2
==0x65)&&(ch3
==0x34)) { title
[d
++]='ä'; }
253 if ((ch1
==0x27)&&(ch2
==0x66)&&(ch3
==0x63)) { title
[d
++]='ü'; }
254 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x36)) { title
[d
++]='Ö'; }
255 if ((ch1
==0x27)&&(ch2
==0x63)&&(ch3
==0x34)) { title
[d
++]='Ä'; }
256 if ((ch1
==0x27)&&(ch2
==0x64)&&(ch3
==0x63)) { title
[d
++]='Ü'; }
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
);
276 if (winHelp
&& winHelpContents
&& WinHelpContentsFile
)
278 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topicName
);
281 // If a previous section at this level was a book, we *have* to have a
282 // book not a page, because of a bug in WHC (or WinHelp 4).
283 if (texTopic
->hasChildren
|| level
== 1 || ContentsLevels
[level
-1])
285 // At this level, we have a pointer to a further hierarchy.
286 // So we need a 'book' consisting of (say) Chapter 1.
287 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
289 // Then we have a 'page' consisting of the text for this chapter
290 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
292 // Then we'll be writing out further pages or books at level + 1...
294 // Remember that at this level, we had a book and *must* for the
295 // remainder of sections at this level.
296 ContentsLevels
[level
-1] = true;
300 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
305 if (level
== 1 || ContentsLevels
[level
-1])
307 // Always have a book at level 1
308 wxFprintf(WinHelpContentsFile
, _T("%d %s\n"), level
, title
);
309 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
+1, title
, topicName
);
310 ContentsLevels
[level
-1] = true;
313 // Probably doesn't have children if it hasn't been added to the topic table
314 wxFprintf(WinHelpContentsFile
, _T("%d %s=%s\n"), level
, title
, topicName
);
319 void SplitIndexEntry(wxChar
*entry
, wxChar
*buf1
, wxChar
*buf2
)
321 int len
= wxStrlen(entry
); int i
= 0;
322 while ((i
< len
) && entry
[i
] != '!')
323 { buf1
[i
] = entry
[i
]; i
++; }
324 buf1
[i
] = 0; buf2
[0] = 0; int j
= 0;
329 while (i
< len
) { buf2
[j
] = entry
[i
]; i
++; j
++; }
335 * Output topic index entries in WinHelp RTF
338 void GenerateKeywordsForTopic(wxChar
*topic
)
340 TexTopic
*texTopic
= (TexTopic
*)TopicTable
.Get(topic
);
344 wxStringList
*list
= texTopic
->keywords
;
347 wxStringListNode
*node
= list
->GetFirst();
350 wxChar
*s
= (wxChar
*)node
->GetData();
352 // Must separate out main entry form subentry (only 1 subentry allowed)
353 wxChar buf1
[100]; wxChar buf2
[100];
354 SplitIndexEntry(s
, buf1
, buf2
);
356 // Check for ':' which messes up index
358 for (i
= 0; i
< wxStrlen(buf1
) ; i
++)
361 for (i
= 0; i
< wxStrlen(buf2
) ; i
++)
365 // {K} is a strange fix to prevent words beginning with K not
366 // being indexed properly
367 TexOutput(_T("K{\\footnote {K} "));
369 if (wxStrlen(buf2
) > 0)
375 TexOutput(_T("}\n"));
376 node
= node
->GetNext();
382 * Output index entry in linear RTF
386 void GenerateIndexEntry(wxChar
*entry
)
390 wxChar buf1
[100]; wxChar buf2
[100];
391 SplitIndexEntry(entry
, buf1
, buf2
);
393 TexOutput(_T("{\\xe\\v {"));
395 if (wxStrlen(buf2
) > 0)
397 TexOutput(_T("\\:"));
405 * Write a suitable RTF header.
409 void WriteColourTable(FILE *fd
)
411 wxFprintf(fd
, _T("{\\colortbl"));
412 wxNode
*node
= ColourTable
.GetFirst();
415 ColourTableEntry
*entry
= (ColourTableEntry
*)node
->GetData();
416 wxFprintf(fd
, _T("\\red%d\\green%d\\blue%d;\n"), entry
->red
, entry
->green
, entry
->blue
);
417 node
= node
->GetNext();
419 wxFprintf(fd
, _T("}"));
423 * Write heading style
427 void WriteHeadingStyle(FILE *fd
, int heading
)
433 wxFprintf(fd
, _T("\\sb300\\sa260\\f2\\b\\fs%d"), chapterFont
*2);
438 wxFprintf(fd
, _T("\\sb200\\sa240\\f2\\b\\fs%d"), sectionFont
*2);
443 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
448 wxFprintf(fd
, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont
*2);
456 void WriteRTFHeader(FILE *fd
)
458 wxFprintf(fd
, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset
);
459 wxFprintf(fd
, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n"));
460 wxFprintf(fd
, _T("{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
464 wxFprintf(fd
, _T("{\\stylesheet{\\f2\\fs22\\sa200 \\snext0 Normal;}\n"));
466 wxFprintf(fd
, _T("{\\s1 ")); WriteHeadingStyle(fd
, 1); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 1;}\n"));
467 wxFprintf(fd
, _T("{\\s2 ")); WriteHeadingStyle(fd
, 2); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 2;}\n"));
468 wxFprintf(fd
, _T("{\\s3 ")); WriteHeadingStyle(fd
, 3); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 3;}\n"));
469 wxFprintf(fd
, _T("{\\s4 ")); WriteHeadingStyle(fd
, 4); wxFprintf(fd
, _T("\\sbasedon0\\snext0 heading 4;}\n"));
472 wxFprintf(fd
, _T("{\\s10\\ql \\li720\\ri0\\nowidctlpar\\faauto\\rin0\\lin720\\itap0 \\cbpat17\
473 \\f2\\fs20 \\sbasedon0 \\snext24 Code;}\n"));
475 // Table of contents styles
476 wxFprintf(fd
, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n"));
478 wxFprintf(fd
, _T("{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n"));
479 wxFprintf(fd
, _T("{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n"));
480 wxFprintf(fd
, _T("{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n"));
483 wxFprintf(fd
, _T("{\\s30\\fi-200\\li200\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 1;}\n"));
484 wxFprintf(fd
, _T("{\\s31\\fi-200\\li400\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 2;}\n"));
485 wxFprintf(fd
, _T("{\\s32\\fi-200\\li600\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 3;}\n"));
486 wxFprintf(fd
, _T("{\\s33\\fi-200\\li800\\tqr\\tx3960 \\f2\\fs18 \\sbasedon0\\snext0 index 4;}\n"));
487 wxFprintf(fd
, _T("{\\s35\\qc\\sb240\\sa120 \\b\\f2\\fs26 \\sbasedon0\\snext30 index heading;}\n"));
488 wxFprintf(fd
, _T("}\n"));
490 WriteColourTable(fd
);
491 wxFprintf(fd
, _T("\n\\ftnbj\\ftnrestart")); // Latex default is footnotes at bottom of page, not section.
492 wxFprintf(fd
, _T("\n"));
495 void OutputNumberStyle(wxChar
*numberStyle
)
499 if (wxStrcmp(numberStyle
, _T("arabic")) == 0)
501 TexOutput(_T("\\pgndec"));
503 else if (wxStrcmp(numberStyle
, _T("roman")) == 0)
505 TexOutput(_T("\\pgnlcrm"));
507 else if (wxStrcmp(numberStyle
, _T("Roman")) == 0)
509 TexOutput(_T("\\pgnucrm"));
511 else if (wxStrcmp(numberStyle
, _T("alph")) == 0)
513 TexOutput(_T("\\pgnlcltr"));
515 else if (wxStrcmp(numberStyle
, _T("Alph")) == 0)
517 TexOutput(_T("\\pgnucltr"));
523 * Write a Windows help project file
526 bool WriteHPJ(wxChar
*filename
)
528 wxChar hpjFilename
[256];
531 wxStrcpy(hpjFilename
, filename
);
532 StripExtension(hpjFilename
);
533 wxStrcat(hpjFilename
, _T(".hpj"));
535 wxStrcpy(helpFile
, wxFileNameFromPath(filename
));
536 StripExtension(helpFile
);
537 wxStrcpy(rtfFile
, helpFile
);
538 wxStrcat(helpFile
, _T(".hlp"));
539 wxStrcat(rtfFile
, _T(".rtf"));
541 FILE *fd
= wxFopen(hpjFilename
, _T("w"));
545 wxChar
*helpTitle
= winHelpTitle
;
547 helpTitle
= _T("Untitled");
549 wxString thePath
= wxPathOnly(InputFile
);
550 if (thePath
.IsEmpty())
552 wxFprintf(fd
, _T("[OPTIONS]\n"));
553 wxFprintf(fd
, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath
.c_str());
554 wxFprintf(fd
, _T("TITLE=%s\n"), helpTitle
);
555 wxFprintf(fd
, _T("CONTENTS=Contents\n"));
557 if (winHelpVersion
> 3)
559 wxFprintf(fd
, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
560 wxFprintf(fd
, _T("COMPRESS=8 Zeck\n"));
561 wxFprintf(fd
, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
562 wxFprintf(fd
, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot
));
566 wxFprintf(fd
, _T("COMPRESS=HIGH\n"));
568 wxFprintf(fd
, _T("\n"));
570 if (winHelpVersion
> 3)
572 wxFprintf(fd
, _T("[WINDOWS]\n"));
573 wxFprintf(fd
, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
574 wxFprintf(fd
, _T("\n"));
577 wxFprintf(fd
, _T("[FILES]\n%s\n\n"), rtfFile
);
578 wxFprintf(fd
, _T("[CONFIG]\n"));
580 wxFprintf(fd
, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile
);
581 wxFprintf(fd
, _T("BrowseButtons()\n\n"));
582 wxFprintf(fd
, _T("[MAP]\n\n[BITMAPS]\n\n"));
589 * Given a TexChunk with a string value, scans through the string
590 * converting Latex-isms into RTF-isms, such as 2 newlines -> \par,
591 * and inserting spaces at the start of lines since in Latex, a newline
592 * implies a space, but not in RTF.
596 void ProcessText2RTF(TexChunk
*chunk
)
598 bool changed
= false;
602 int len
= wxStrlen(chunk
->value
);
605 ch
= chunk
->value
[i
];
611 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("\\par\n")); ptr
+= 5;
612 // BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par{\\v this was verbatim}\n")); ptr += 5;
618 // If the first character of the next line is ASCII,
619 // put a space in. Implicit in Latex, not in RTF.
621 The reason this is difficult is that you don't really know
622 where a space would be appropriate. If you always put in a space
623 when you find a newline, unwanted spaces appear in the text.
625 if ((i
> 0) && (len
> i
+1 && isascii(chunk
->value
[i
+1]) &&
626 !isspace(chunk
->value
[i
+1])) ||
627 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
628 (len
> i
+2 && isascii(chunk
->value
[i
+2]) &&
629 !isspace(chunk
->value
[i
+2]))))
632 // DOS files have a 13 after the 10
636 if (chunk
->value
[i
] == 13)
643 BigBuffer
[ptr
] = ' ';
646 // Note that the actual ASCII character seen is dealt with in the next
657 else if (!inVerbatim
&& ch
== '`' && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
659 BigBuffer
[ptr
] = '"'; ptr
++;
663 else if (!inVerbatim
&& ch
== '`') // Change ` to '
665 BigBuffer
[ptr
] = 39; ptr
++;
669 else if (inVerbatim
&& ch
== '\\') // Change backslash to two backslashes
671 BigBuffer
[ptr
] = '\\'; ptr
++;
672 BigBuffer
[ptr
] = '\\'; ptr
++;
676 else if (inVerbatim
&& (ch
== '{' || ch
== '}')) // Escape the curley bracket
678 BigBuffer
[ptr
] = '\\'; ptr
++;
679 BigBuffer
[ptr
] = ch
; ptr
++;
694 delete[] chunk
->value
;
695 chunk
->value
= copystring(BigBuffer
);
700 * Scan through all chunks starting from the given one,
701 * calling ProcessText2RTF to convert Latex-isms to RTF-isms.
702 * This should be called after Tex2Any has parsed the file,
703 * and before TraverseDocument is called.
707 void Text2RTF(TexChunk
*chunk
)
710 if (stopRunning
) return;
714 case CHUNK_TYPE_MACRO
:
716 TexMacroDef
*def
= chunk
->def
;
717 if (def
&& def
->ignore
)
720 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
723 wxNode
*node
= chunk
->children
.GetFirst();
726 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
727 Text2RTF(child_chunk
);
728 node
= node
->GetNext();
731 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
))
738 wxNode
*node
= chunk
->children
.GetFirst();
741 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
742 Text2RTF(child_chunk
);
743 node
= node
->GetNext();
748 case CHUNK_TYPE_STRING
:
751 ProcessText2RTF(chunk
);
762 wxChar browseBuf
[10];
763 static long browseId
= 0;
764 wxChar
*GetBrowseString(void)
768 wxSnprintf(buf
, sizeof(buf
), _T("%ld"), browseId
);
769 int noZeroes
= 5-wxStrlen(buf
);
770 wxStrcpy(browseBuf
, _T("browse"));
771 for (int i
= 0; i
< noZeroes
; i
++)
772 wxStrcat(browseBuf
, _T("0"));
773 wxStrcat(browseBuf
, buf
);
778 * Keeping track of environments to restore the styles after \pard.
779 * Push strings like "\qc" onto stack.
783 void PushEnvironmentStyle(wxChar
*style
)
785 environmentStack
.Add(style
);
788 void PopEnvironmentStyle(void)
790 wxStringListNode
*node
= environmentStack
.GetLast();
793 wxChar
*val
= (wxChar
*)node
->GetData();
799 // Write out the styles, most recent first.
800 void WriteEnvironmentStyles(void)
802 wxStringListNode
*node
= environmentStack
.GetLast();
805 wxChar
*val
= (wxChar
*)node
->GetData();
807 node
= node
->GetNext();
809 if (!inTabular
&& (ParIndent
> 0) && (forbidParindent
== 0))
812 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d"), ParIndent
*20); // Convert points to TWIPS
815 if (environmentStack
.GetCount() > 0 || (ParIndent
> 0))
825 void OutputRTFHeaderCommands(void)
828 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
830 TexOutput(_T("{\\headerl }{\\headerr }"));
832 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
834 TexOutput(_T("{\\headerl }{\\headerr }"));
836 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
839 TexOutput(_T("{\\headerl\\fi0 "));
842 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
844 TexOutput(_T("{\\i \\qr "));
845 if (DocumentStyle
== LATEX_ARTICLE
)
847 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
852 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d: "), chapterNo
);
855 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
856 TexOutput(_T("}\\par\\pard}"));
859 TexOutput(_T("{\\headerr\\fi0 "));
862 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
864 TexOutput(_T("{\\i \\qc "));
865 if (DocumentStyle
== LATEX_ARTICLE
)
867 wxSnprintf(buf
, sizeof(buf
), _T("SECTION %d"), sectionNo
);
872 wxSnprintf(buf
, sizeof(buf
), _T("CHAPTER %d"), chapterNo
);
875 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
876 TexOutput(_T("}\\par\\pard}"));
880 int oldForbidResetPar
= forbidResetPar
;
883 if (LeftHeaderEven
|| CentreHeaderEven
|| RightHeaderEven
)
885 TexOutput(_T("{\\headerl\\fi0 "));
888 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
892 if (!CentreHeaderEven
&& !RightHeaderEven
)
893 TexOutput(_T("\\ql "));
894 TraverseChildrenFromChunk(LeftHeaderEven
);
896 if (CentreHeaderEven
)
898 if (!LeftHeaderEven
&& !RightHeaderEven
)
899 TexOutput(_T("\\qc "));
901 TexOutput(_T("\\tab\\tab\\tab "));
902 TraverseChildrenFromChunk(CentreHeaderEven
);
906 if (!LeftHeaderEven
&& !CentreHeaderEven
)
907 TexOutput(_T("\\qr "));
909 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
910 TraverseChildrenFromChunk(RightHeaderEven
);
912 TexOutput(_T("\\par\\pard}"));
915 if (LeftHeaderOdd
|| CentreHeaderOdd
|| RightHeaderOdd
)
917 TexOutput(_T("{\\headerr\\fi0 "));
920 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
924 if (!CentreHeaderOdd
&& !RightHeaderOdd
)
925 TexOutput(_T("\\ql "));
926 TraverseChildrenFromChunk(LeftHeaderOdd
);
930 if (!LeftHeaderOdd
&& !RightHeaderOdd
)
931 TexOutput(_T("\\qc "));
933 TexOutput(_T("\\tab\\tab\\tab "));
934 TraverseChildrenFromChunk(CentreHeaderOdd
);
938 if (!LeftHeaderOdd
&& !CentreHeaderOdd
)
939 TexOutput(_T("\\qr "));
941 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
942 TraverseChildrenFromChunk(RightHeaderOdd
);
944 TexOutput(_T("\\par\\pard}"));
946 // As an approximation, don't put a header on the first page of a section.
947 // This may not always be desired, but it's a reasonable guess.
948 TexOutput(_T("{\\headerf }"));
950 forbidResetPar
= oldForbidResetPar
;
954 void OutputRTFFooterCommands(void)
956 if (PageStyle
&& wxStrcmp(PageStyle
, _T("plain")) == 0)
958 TexOutput(_T("{\\footerl\\fi0 "));
960 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
961 TexOutput(_T("{\\qc "));
962 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
963 TexOutput(_T("}\\par\\pard}"));
965 TexOutput(_T("{\\footerr\\fi0 "));
967 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
968 TexOutput(_T("{\\qc "));
969 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
970 TexOutput(_T("}\\par\\pard}"));
972 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("empty")) == 0)
974 TexOutput(_T("{\\footerl }{\\footerr }"));
976 else if (PageStyle
&& wxStrcmp(PageStyle
, _T("headings")) == 0)
978 TexOutput(_T("{\\footerl }{\\footerr }"));
982 if (LeftFooterEven
|| CentreFooterEven
|| RightFooterEven
)
984 TexOutput(_T("{\\footerl\\fi0 "));
986 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
989 if (!CentreFooterEven
&& !RightFooterEven
)
990 TexOutput(_T("\\ql "));
991 TraverseChildrenFromChunk(LeftFooterEven
);
993 if (CentreFooterEven
)
995 if (!LeftFooterEven
&& !RightFooterEven
)
996 TexOutput(_T("\\qc "));
998 TexOutput(_T("\\tab\\tab\\tab "));
999 TraverseChildrenFromChunk(CentreFooterEven
);
1001 if (RightFooterEven
)
1003 if (!LeftFooterEven
&& !CentreFooterEven
)
1004 TexOutput(_T("\\qr "));
1006 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1007 TraverseChildrenFromChunk(RightFooterEven
);
1009 TexOutput(_T("\\par\\pard}"));
1012 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1014 TexOutput(_T("{\\footerr\\fi0 "));
1016 TexOutput(_T("\\brdrt\\brdrs\\brdrw15\\brsp20 "));
1019 if (!CentreFooterOdd
&& !RightFooterOdd
)
1020 TexOutput(_T("\\ql "));
1021 TraverseChildrenFromChunk(LeftFooterOdd
);
1023 if (CentreFooterOdd
)
1025 if (!LeftFooterOdd
&& !RightFooterOdd
)
1026 TexOutput(_T("\\qc "));
1028 TexOutput(_T("\\tab\\tab\\tab "));
1029 TraverseChildrenFromChunk(CentreFooterOdd
);
1033 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1034 TexOutput(_T("\\qr "));
1036 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1037 TraverseChildrenFromChunk(RightFooterOdd
);
1039 TexOutput(_T("\\par\\pard}"));
1042 // As an approximation, put a footer on the first page of a section.
1043 // This may not always be desired, but it's a reasonable guess.
1044 if (LeftFooterOdd
|| CentreFooterOdd
|| RightFooterOdd
)
1046 TexOutput(_T("{\\footerf\\fi0 "));
1049 if (!CentreFooterOdd
&& !RightFooterOdd
)
1050 TexOutput(_T("\\ql "));
1051 TraverseChildrenFromChunk(LeftFooterOdd
);
1053 if (CentreFooterOdd
)
1055 if (!LeftFooterOdd
&& !RightFooterOdd
)
1056 TexOutput(_T("\\qc "));
1058 TexOutput(_T("\\tab\\tab\\tab "));
1059 TraverseChildrenFromChunk(CentreFooterOdd
);
1063 if (!LeftFooterOdd
&& !CentreFooterOdd
)
1064 TexOutput(_T("\\qr "));
1066 TexOutput(_T("\\tab\\tab\\tab\\tab\\tab\\tab "));
1067 TraverseChildrenFromChunk(RightFooterOdd
);
1069 TexOutput(_T("\\par\\pard}"));
1074 // Called on start/end of macro examination
1075 void RTFOnMacro(int macroId
, int no_args
, bool start
)
1079 wxSnprintf(tmpBuf, sizeof(tmpBuf), _T("%d (%d)"), macroId, (int)start);
1080 OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf);
1081 OutputDebugString("\n"); wxYield();
1084 // ltLABEL is included here because after a section but BEFORE
1085 // the label is seen, a new paragraph is issued. Don't upset this by
1086 // immediately forgetting we've done it.
1087 if (start
&& (macroId
!= ltPAR
&& macroId
!= ltITEMIZE
&&
1088 macroId
!= ltENUMERATE
&& macroId
!= ltDESCRIPTION
&&
1089 macroId
!= ltVERBATIM
&& macroId
!= ltLABEL
&&
1090 macroId
!= ltSETHEADER
&& macroId
!= ltSETFOOTER
&&
1091 macroId
!= ltPAGENUMBERING
&&
1092 (forbidResetPar
== 0)))
1094 issuedNewParagraph
= 0;
1102 case ltCHAPTERHEADING
:
1103 case ltCHAPTERHEADINGSTAR
:
1111 subsubsectionNo
= 0;
1114 if (macroId
!= ltCHAPTERSTAR
&& macroId
!= ltCHAPTERHEADINGSTAR
)
1117 wxChar
*topicName
= FindTopicName(GetNextChunk());
1118 SetCurrentChapterName(topicName
);
1120 if (winHelpContents
&& winHelp
&& !InPopups())
1122 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1123 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 1);
1125 AddTexRef(topicName
, NULL
, ChapterNameString
, chapterNo
);
1130 wxFprintf(Contents
, _T("\n{\\uldb "));
1131 wxFprintf(Chapters
, _T("\\page"));
1132 wxFprintf(Chapters
, _T("\n${\\footnote "));
1134 SetCurrentOutputs(Contents
, Chapters
);
1136 SetCurrentOutput(Chapters
);
1140 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
1142 // If a non-custom page style, we generate the header now.
1143 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1144 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1145 wxStrcmp(PageStyle
, _T("headings")) == 0))
1147 OutputRTFHeaderCommands();
1148 OutputRTFFooterCommands();
1151 // Need to reset the current numbering style, or RTF forgets it.
1152 SetCurrentOutput(Chapters
);
1153 OutputNumberStyle(currentNumberStyle
);
1155 SetCurrentOutput(Contents
);
1159 if (macroId
== ltCHAPTER
)
1162 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), chapterNo
);
1164 else if (macroId
== ltCHAPTERHEADING
)
1166 wxFprintf(Contents
, _T("\\par\n\\pard{\\b "));
1168 else SetCurrentOutput(NULL
); // No entry in table of contents
1172 startedSections
= true;
1174 // Output heading to contents page
1177 OutputCurrentSection();
1181 wxFprintf(Contents
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1182 //WriteEnvironmentStyles();
1184 else if ((macroId
== ltCHAPTER
) || (macroId
== ltCHAPTERHEADING
))
1185 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1187 // From here, just output to chapter
1188 SetCurrentOutput(Chapters
);
1193 wxFprintf(Chapters
, _T("}\n#{\\footnote %s}\n"), topicName
);
1194 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
1196 OutputSectionKeyword(Chapters
);
1198 GenerateKeywordsForTopic(topicName
);
1201 // If we're generating a .cnt file, we don't want to be able
1202 // jump up to the old-style contents page, so disable it.
1203 if (winHelpContents
)
1204 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
1206 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1207 wxFileNameFromPath(FileRoot
), _T("Contents"));
1213 wxChar
*styleCommand
= _T("");
1214 if (!winHelp
&& useHeadingStyles
&& (macroId
== ltCHAPTER
|| macroId
== ltCHAPTERHEADING
|| macroId
== ltCHAPTERHEADINGSTAR
))
1215 styleCommand
= _T("\\s1");
1216 wxFprintf(Chapters
, _T("\\pard{%s"), ((winHelp
&& !InPopups()) ? _T("\\keepn\\sa140\\sb140") : styleCommand
));
1217 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" "));
1220 if (macroId
== ltCHAPTER
)
1223 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, chapterNo,
1224 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1226 wxFprintf(Chapters
, _T("%d. "), chapterNo
);
1230 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1233 OutputCurrentSection();
1234 TexOutput(_T("\\par\\pard}\n"));
1236 issuedNewParagraph
= 1;
1237 WriteEnvironmentStyles();
1243 case ltSECTIONHEADING
:
1244 case ltSECTIONHEADINGSTAR
:
1248 if (DocumentStyle
== LATEX_ARTICLE
)
1249 jumpFrom
= Contents
;
1251 jumpFrom
= Chapters
;
1256 subsubsectionNo
= 0;
1257 if (DocumentStyle
== LATEX_ARTICLE
)
1260 if (macroId
!= ltSECTIONSTAR
&& macroId
!= ltSECTIONHEADINGSTAR
)
1263 wxChar
*topicName
= FindTopicName(GetNextChunk());
1264 SetCurrentSectionName(topicName
);
1265 NotifyParentHasChildren(1);
1266 if (winHelpContents
&& winHelp
&& !InPopups())
1268 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1269 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 2);
1271 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
);
1275 SetCurrentOutputs(jumpFrom
, Sections
);
1276 // Newline for a new section if this is an article
1277 if ((DocumentStyle
== LATEX_ARTICLE
) &&
1278 ((macroId
== ltSECTION
) || (macroId
== ltSECTIONSTAR
) || (macroId
== ltSECTIONHEADINGSTAR
)))
1279 wxFprintf(Sections
, _T("\\page\n"));
1282 wxFprintf(jumpFrom
, _T("\n{\\uldb "));
1286 if (DocumentStyle
== LATEX_ARTICLE
)
1288 TexOutput(_T("\\sect\\pgncont\n"));
1289 // If a non-custom page style, we generate the header now.
1290 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
1291 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
1292 wxStrcmp(PageStyle
, _T("headings")) == 0))
1294 OutputRTFHeaderCommands();
1295 OutputRTFFooterCommands();
1298 SetCurrentOutput(Contents
);
1300 if (macroId
== ltSECTION
)
1304 if (DocumentStyle
== LATEX_REPORT
)
1305 wxFprintf(Contents
, _T("\n\\pard{\\tab %d.%d\\tab "), chapterNo
, sectionNo
);
1307 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %d\\tab "), sectionNo
);
1310 else if (macroId
== ltSECTIONHEADING
)
1314 if (DocumentStyle
== LATEX_REPORT
)
1315 wxFprintf(Contents
, _T("\n\\pard{\\tab ")); //, chapterNo, sectionNo);
1317 wxFprintf(Contents
, _T("\\par\n\\pard{\\b ")); //, sectionNo);
1320 else SetCurrentOutput(NULL
);
1323 if (startedSections
)
1326 wxFprintf(Sections
, _T("\\page\n"));
1328 startedSections
= true;
1331 wxFprintf(Sections
, _T("\n${\\footnote "));
1333 // Output heading to contents page
1335 OutputCurrentSection();
1341 wxFprintf(jumpFrom
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1342 //WriteEnvironmentStyles();
1345 else if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltGLOSS
))
1347 if (DocumentStyle
== LATEX_REPORT
)
1348 wxFprintf(Contents
, _T("}\\par\\pard\n"));
1350 wxFprintf(Contents
, _T("}\\par\\par\\pard\n"));
1353 SetCurrentOutput(winHelp
? Sections
: Chapters
);
1357 wxFprintf(Sections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1358 wxFprintf(Sections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1359 OutputSectionKeyword(Sections
);
1360 GenerateKeywordsForTopic(topicName
);
1363 if (DocumentStyle
== LATEX_ARTICLE
)
1365 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1366 wxFileNameFromPath(FileRoot
), _T("Contents"));
1368 else if (CurrentChapterName
)
1370 wxFprintf(Sections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1371 wxFileNameFromPath(FileRoot
), CurrentChapterName
);
1378 wxChar
*styleCommand
= _T("");
1379 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSECTIONSTAR
))
1381 if (DocumentStyle
== LATEX_ARTICLE
)
1382 styleCommand
= _T("\\s1");
1384 styleCommand
= _T("\\s2");
1386 wxChar
*keep
= _T("");
1387 if (winHelp
&& (macroId
!= ltGLOSS
) && !InPopups())
1388 keep
= _T("\\keepn\\sa140\\sb140");
1390 wxFprintf(winHelp
? Sections
: Chapters
, _T("\\pard{%s%s"),
1391 keep
, styleCommand
);
1393 WriteHeadingStyle((winHelp
? Sections
: Chapters
),
1394 (DocumentStyle
== LATEX_ARTICLE
? 1 : 2));
1395 wxFprintf(winHelp
? Sections
: Chapters
, _T(" "));
1399 if ((macroId
!= ltSECTIONSTAR
) && (macroId
!= ltSECTIONHEADINGSTAR
) && (macroId
!= ltGLOSS
))
1401 if (DocumentStyle
== LATEX_REPORT
)
1404 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo,
1405 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1408 wxFprintf(Chapters
, _T("%d.%d. "), chapterNo
, sectionNo
);
1413 // wxFprintf(Chapters, "{\\bkmkstart %s}%d{\\bkmkend %s}. ", topicName, sectionNo,
1414 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1417 wxFprintf(Chapters
, _T("%d. "), sectionNo
);
1422 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1425 OutputCurrentSection();
1426 TexOutput(_T("\\par\\pard}\n"));
1427 // TexOutput(_T("\\par\\pard}\\par\n"));
1429 issuedNewParagraph
= 1;
1430 WriteEnvironmentStyles();
1431 // issuedNewParagraph = 2;
1436 case ltSUBSECTIONSTAR
:
1437 case ltMEMBERSECTION
:
1438 case ltFUNCTIONSECTION
:
1442 if (winHelp
&& !Sections
)
1444 OnError(_T("You cannot have a subsection before a section!"));
1448 subsubsectionNo
= 0;
1450 if (macroId
!= ltSUBSECTIONSTAR
)
1453 wxChar
*topicName
= FindTopicName(GetNextChunk());
1454 SetCurrentSubsectionName(topicName
);
1455 NotifyParentHasChildren(2);
1456 if (winHelpContents
&& winHelp
&& !InPopups())
1458 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1459 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 3);
1461 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
);
1465 SetCurrentOutputs(Sections
, Subsections
);
1466 SetCurrentOutputs(Sections
, Subsections
);
1468 wxFprintf(Sections
, _T("\n{\\uldb "));
1472 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1473 (macroId
!= ltFUNCTIONSECTION
))
1475 SetCurrentOutput(Contents
);
1476 if (DocumentStyle
== LATEX_REPORT
)
1477 wxFprintf(Contents
, _T("\n\\pard\\tab\\tab %d.%d.%d\\tab "), chapterNo
, sectionNo
, subsectionNo
);
1479 wxFprintf(Contents
, _T("\n\\pard\\tab %d.%d\\tab "), sectionNo
, subsectionNo
);
1480 } else SetCurrentOutput(NULL
);
1482 if (startedSections
)
1487 wxFprintf(Subsections
, _T("\\page\n"));
1489 // Experimental JACS 2004-02-21
1492 wxFprintf(Chapters
, _T("\\par\n"));
1495 startedSections
= true;
1498 wxFprintf(Subsections
, _T("\n${\\footnote "));
1500 // Output to contents page
1502 OutputCurrentSection();
1508 wxFprintf(Sections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1509 //WriteEnvironmentStyles();
1512 else if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1513 (macroId
!= ltFUNCTIONSECTION
))
1514 wxFprintf(Contents
, _T("\\par\\pard\n"));
1516 SetCurrentOutput(winHelp
? Subsections
: Chapters
);
1519 wxFprintf(Subsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1520 wxFprintf(Subsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1521 OutputSectionKeyword(Subsections
);
1522 GenerateKeywordsForTopic(topicName
);
1523 if (useUpButton
&& CurrentSectionName
)
1525 wxFprintf(Subsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1526 wxFileNameFromPath(FileRoot
), CurrentSectionName
);
1529 if (!winHelp
&& indexSubsections
&& useWord
)
1531 // Insert index entry for this subsection
1532 TexOutput(_T("{\\xe\\v {"));
1533 OutputCurrentSection();
1534 TexOutput(_T("}}"));
1539 wxChar
*styleCommand
= _T("");
1540 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSECTIONSTAR
))
1542 if (DocumentStyle
== LATEX_ARTICLE
)
1543 styleCommand
= _T("\\s2");
1545 styleCommand
= _T("\\s3");
1547 wxChar
*keep
= _T("");
1548 if (winHelp
&& !InPopups())
1549 keep
= _T("\\keepn\\sa140\\sb140");
1551 wxFprintf(winHelp
? Subsections
: Chapters
, _T("\\pard{%s%s"),
1552 keep
, styleCommand
);
1554 WriteHeadingStyle((winHelp
? Subsections
: Chapters
),
1555 (DocumentStyle
== LATEX_ARTICLE
? 2 : 3));
1556 wxFprintf(winHelp
? Subsections
: Chapters
, _T(" "));
1560 if ((macroId
!= ltSUBSECTIONSTAR
) && (macroId
!= ltMEMBERSECTION
) &&
1561 (macroId
!= ltFUNCTIONSECTION
))
1563 if (DocumentStyle
== LATEX_REPORT
)
1566 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo,
1567 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1570 wxFprintf(Chapters
, _T("%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
);
1575 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo,
1576 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1579 wxFprintf(Chapters
, _T("%d.%d. "), sectionNo
, subsectionNo
);
1584 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1587 OutputCurrentSection(); // Repeat section header
1589 // Experimental JACS
1590 TexOutput(_T("\\par\\pard}\n"));
1591 // TexOutput(_T("\\par\\pard}\\par\n"));
1593 issuedNewParagraph
= 1;
1594 WriteEnvironmentStyles();
1599 case ltSUBSUBSECTION
:
1600 case ltSUBSUBSECTIONSTAR
:
1604 if (winHelp
&& !Subsections
)
1606 OnError(_T("You cannot have a subsubsection before a subsection!"));
1610 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1613 wxChar
*topicName
= FindTopicName(GetNextChunk());
1614 SetCurrentTopic(topicName
);
1615 NotifyParentHasChildren(3);
1616 if (winHelpContents
&& winHelp
)
1618 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1619 WriteWinHelpContentsFileLine(topicName
, wxTex2RTFBuffer
, 4);
1621 AddTexRef(topicName
, NULL
, SectionNameString
, chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1625 SetCurrentOutputs(Subsections
, Subsubsections
);
1626 wxFprintf(Subsections
, _T("\n{\\uldb "));
1630 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1632 if (DocumentStyle
== LATEX_ARTICLE
)
1634 SetCurrentOutput(Contents
);
1635 wxFprintf(Contents
, _T("\n\\tab\\tab %d.%d.%d\\tab "),
1636 sectionNo
, subsectionNo
, subsubsectionNo
);
1639 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1642 SetCurrentOutput(NULL
); // Don't write it into the contents, or anywhere else
1645 if (startedSections
)
1648 wxFprintf(Subsubsections
, _T("\\page\n"));
1649 // Experimental JACS 2004-02-21
1652 wxFprintf(Chapters
, _T("\\par\n"));
1656 startedSections
= true;
1659 wxFprintf(Subsubsections
, _T("\n${\\footnote "));
1661 // Output header to contents page
1662 OutputCurrentSection();
1666 wxFprintf(Subsections
, _T("}{\\v %s}\\pard\\par\n"), topicName
);
1667 //WriteEnvironmentStyles();
1669 else if ((DocumentStyle
== LATEX_ARTICLE
) && (macroId
!= ltSUBSUBSECTIONSTAR
))
1670 wxFprintf(Contents
, _T("\\par\\pard\n"));
1672 SetCurrentOutput(winHelp
? Subsubsections
: Chapters
);
1675 wxFprintf(Subsubsections
, _T("}\n#{\\footnote %s}\n"), topicName
);
1676 wxFprintf(Subsubsections
, _T("+{\\footnote %s}\n"), GetBrowseString());
1677 OutputSectionKeyword(Subsubsections
);
1678 GenerateKeywordsForTopic(topicName
);
1679 if (useUpButton
&& CurrentSubsectionName
)
1681 wxFprintf(Subsubsections
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
1682 wxFileNameFromPath(FileRoot
), CurrentSubsectionName
);
1685 if (!winHelp
&& indexSubsections
&& useWord
)
1687 // Insert index entry for this subsubsection
1688 TexOutput(_T("{\\xe\\v {"));
1689 OutputCurrentSection();
1690 TexOutput(_T("}}"));
1693 wxChar
*styleCommand
= _T("");
1694 if (!winHelp
&& useHeadingStyles
&& (macroId
!= ltSUBSUBSECTIONSTAR
))
1696 if (DocumentStyle
== LATEX_ARTICLE
)
1697 styleCommand
= _T("\\s3");
1699 styleCommand
= _T("\\s4");
1701 wxChar
*keep
= _T("");
1703 keep
= _T("\\keepn\\sa140\\sb140");
1705 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T("\\pard{%s%s"),
1706 keep
, styleCommand
);
1708 WriteHeadingStyle((winHelp
? Subsubsections
: Chapters
),
1709 (DocumentStyle
== LATEX_ARTICLE
? 3 : 4));
1710 wxFprintf(winHelp
? Subsubsections
: Chapters
, _T(" "));
1714 if ((macroId
!= ltSUBSUBSECTIONSTAR
))
1716 if (DocumentStyle
== LATEX_ARTICLE
)
1719 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d{\\bkmkend %s}. "), topicName, sectionNo, subsectionNo, subsubsectionNo,
1720 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1723 wxFprintf(Chapters
, _T("%d.%d.%d. "), sectionNo
, subsectionNo
, subsubsectionNo
);
1728 // wxFprintf(Chapters, _T("{\\bkmkstart %s}%d.%d.%d.%d{\\bkmkend %s}. "), topicName, chapterNo, sectionNo, subsectionNo, subsubsectionNo,
1729 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
,
1732 wxFprintf(Chapters
, _T("%d.%d.%d.%d. "), chapterNo
, sectionNo
, subsectionNo
, subsubsectionNo
);
1737 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), topicName
, topicName
);
1740 OutputCurrentSection(); // Repeat section header
1741 TexOutput(_T("\\par\\pard}\n"));
1742 issuedNewParagraph
= 1;
1743 WriteEnvironmentStyles();
1744 // TexOutput(_T("\\par\\pard}\\par\n"));
1745 // issuedNewParagraph = 2;
1755 wxChar
*topicName
= FindTopicName(GetNextChunk());
1756 SetCurrentTopic(topicName
);
1758 TexOutput(_T("\\pard\\par"));
1765 if (winHelp
|| !useWord
)
1767 if (DocumentStyle
!= LATEX_ARTICLE
)
1768 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1770 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1774 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1775 FigureNameString
, topicName
, topicName
);
1782 if (winHelp
|| !useWord
)
1784 if (DocumentStyle
!= LATEX_ARTICLE
)
1785 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1787 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1791 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "),
1792 TableNameString
, topicName
, topicName
);
1796 int n
= (inTable
? tableNo
: figureNo
);
1797 AddTexRef(topicName
, NULL
, NULL
,
1798 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1799 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1802 TexOutput(_T("\\qc{\\b "));
1804 TexOutput(_T("\\ql{\\b "));
1807 OutputCurrentSection();
1809 TexOutput(_T("}\\par\\pard\n"));
1810 WriteEnvironmentStyles();
1817 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1824 TexOutput(_T("}\n"));
1827 TexOutput(_T("K{\\footnote {K} "));
1828 suppressNameDecoration
= true;
1829 TraverseChildrenFromChunk(currentMember
);
1830 suppressNameDecoration
= false;
1831 TexOutput(_T("}\n"));
1833 if (!winHelp
&& useWord
)
1835 // Insert index entry for this function
1836 TexOutput(_T("{\\xe\\v {"));
1837 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1838 TraverseChildrenFromChunk(currentMember
);
1839 suppressNameDecoration
= false;
1840 TexOutput(_T("}}"));
1847 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1854 TexOutput(_T("}\n"));
1857 TexOutput(_T("K{\\footnote {K} "));
1858 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1859 TraverseChildrenFromChunk(currentMember
);
1860 suppressNameDecoration
= false;
1861 TexOutput(_T("}\n"));
1863 if (!winHelp
&& useWord
)
1865 // Insert index entry for this function
1866 TexOutput(_T("{\\xe\\v {"));
1867 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1868 TraverseChildrenFromChunk(currentMember
);
1869 suppressNameDecoration
= false;
1870 TexOutput(_T("}}"));
1877 // SetCurrentOutput(winHelp ? Subsections : Chapters);
1880 TexOutput(_T("{\\b "));
1884 TexOutput(_T("}\n"));
1887 TexOutput(_T("K{\\footnote {K} "));
1888 TraverseChildrenFromChunk(currentMember
);
1889 TexOutput(_T("}\n"));
1891 if (!winHelp
&& useWord
)
1893 // Insert index entry for this function
1894 TexOutput(_T("{\\xe\\v {"));
1895 suppressNameDecoration
= true; // Necessary so don't print "(\\bf" etc.
1896 TraverseChildrenFromChunk(currentMember
);
1897 suppressNameDecoration
= false;
1898 TexOutput(_T("}}"));
1906 SetCurrentOutput(Chapters
);
1909 case ltTABLEOFCONTENTS
:
1913 if (!winHelp
&& useWord
)
1915 // Insert Word for Windows table of contents
1916 TexOutput(_T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
1918 // In linear RTF, same as chapter headings.
1919 wxSnprintf(buf
, sizeof(buf
), _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), chapterFont
*2, ContentsNameString
);
1922 wxSnprintf(buf
, sizeof(buf
), _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth
);
1924 // TexOutput(_T("\\sect\\sectd"));
1928 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1941 TexOutput(_T("{\\i RUN TEX2RTF AGAIN FOR CONTENTS PAGE}\\par\n"));
1942 OnInform(_T("Run Tex2RTF again to include contents page."));
1951 // TexOutput(_T("{\\b void}"));
1957 TexOutput(_T("{\\scaps HARDY}"));
1963 TexOutput(_T("wxCLIPS"));
1966 case ltSPECIALAMPERSAND
:
1971 TexOutput(_T("\\cell "));
1977 case ltSPECIALTILDE
:
1981 #if 1 // if(inVerbatim)
1989 case ltBACKSLASHCHAR
:
1995 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
1996 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
1997 int currentWidth
= 0;
1998 for (int i
= 0; i
< noColumns
; i
++)
2000 currentWidth
+= TableData
[i
].width
;
2001 if (TableData
[i
].rightBorder
)
2002 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
2004 if (TableData
[i
].leftBorder
)
2005 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
2007 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
2010 TexOutput(_T("\\pard\\intbl\n"));
2013 TexOutput(_T("\\line\n"));
2020 TexOutput(_T("\tab "));
2023 case ltRTFSP
: // Explicit space, RTF only
2035 if (indentLevel
> 0)
2037 // Experimental JACS 2004-02-21
2038 TexOutput(_T("\\par\n"));
2039 issuedNewParagraph
= 1;
2040 // TexOutput(_T("\\par\\par\n"));
2041 // issuedNewParagraph = 2;
2045 // Top-level list: issue a new paragraph if we haven't
2047 if (!issuedNewParagraph
)
2049 TexOutput(_T("\\par\\pard"));
2050 WriteEnvironmentStyles();
2051 issuedNewParagraph
= 1;
2053 else issuedNewParagraph
= 0;
2056 TexOutput(_T("\\fi0\n"));
2058 if (macroId
== ltENUMERATE
)
2059 listType
= LATEX_ENUMERATE
;
2060 else if (macroId
== ltITEMIZE
)
2061 listType
= LATEX_ITEMIZE
;
2063 listType
= LATEX_DESCRIPTION
;
2066 wxNode
*node
= itemizeStack
.GetFirst();
2068 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2070 int indentSize1
= oldIndent
+ 20*labelIndentTab
;
2071 int indentSize2
= oldIndent
+ 20*itemIndentTab
;
2073 ItemizeStruc
*struc
= new ItemizeStruc(listType
, indentSize2
, indentSize1
);
2074 itemizeStack
.Insert(struc
);
2076 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\sa200"), indentSize1
, indentSize2
, indentSize2
);
2077 PushEnvironmentStyle(buf
);
2081 currentItemSep
= 8; // Reset to the default
2083 PopEnvironmentStyle();
2085 if (itemizeStack
.GetFirst())
2087 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2089 delete itemizeStack
.GetFirst();
2091 /* Change 18/7/97 - don't know why we wish to do this
2092 if (itemizeStack.Number() == 0)
2094 OnMacro(ltPAR, 0, true);
2095 OnMacro(ltPAR, 0, false);
2096 issuedNewParagraph = 2;
2108 wxNode
*node
= itemizeStack
.GetFirst();
2110 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
2112 int indentSize
= oldIndent
+ TwoColWidthA
;
2114 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_TWOCOL
, indentSize
);
2115 itemizeStack
.Insert(struc
);
2117 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\ri%d"), indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent);
2118 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200"), indentSize
, indentSize
);
2119 PushEnvironmentStyle(buf
);
2124 PopEnvironmentStyle();
2125 if (itemizeStack
.GetFirst())
2127 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
2129 delete itemizeStack
.GetFirst();
2133 TexOutput(_T("\\pard\n"));
2134 WriteEnvironmentStyles();
2136 /* why do we need this? */
2138 TexOutput(_T("\\pard\n"));
2140 if (itemizeStack
.GetCount() == 0)
2142 issuedNewParagraph
= 0;
2143 OnMacro(ltPAR
, 0, true);
2144 OnMacro(ltPAR
, 0, false);
2152 wxNode
*node
= itemizeStack
.GetFirst();
2155 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2158 struc
->currentItem
+= 1;
2159 wxChar indentBuf
[60];
2161 int indentSize1
= struc
->labelIndentation
;
2162 int indentSize2
= struc
->indentation
;
2164 TexOutput(_T("\n"));
2165 if (struc
->currentItem
> 1 && issuedNewParagraph
== 0)
2168 // if (currentItemSep > 0)
2169 // TexOutput(_T("\\par"));
2171 TexOutput(_T("\\par"));
2172 issuedNewParagraph
= 1;
2173 // WriteEnvironmentStyles();
2176 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1
, indentSize2
,
2177 indentSize2
, 20*itemIndentTab
);
2180 switch (struc
->listType
)
2182 case LATEX_ENUMERATE
:
2184 if (descriptionItemArg
)
2186 TexOutput(_T("\\tab{ "));
2187 TraverseChildrenFromChunk(descriptionItemArg
);
2188 TexOutput(_T("}\\tab"));
2189 descriptionItemArg
= NULL
;
2193 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b %d.}\\tab"), struc
->currentItem
);
2194 TexOutput(indentBuf
);
2200 if (descriptionItemArg
)
2202 TexOutput(_T("\\tab{ "));
2203 TraverseChildrenFromChunk(descriptionItemArg
);
2204 TexOutput(_T("}\\tab"));
2205 descriptionItemArg
= NULL
;
2209 if (bulletFile
&& winHelp
)
2211 if (winHelpVersion
> 3) // Transparent bitmap
2212 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmct %s\\}\\tab"), bulletFile
);
2214 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab\\{bmc %s\\}\\tab"), bulletFile
);
2217 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\b o}\\tab"));
2219 wxSnprintf(indentBuf
, sizeof(indentBuf
), _T("\\tab{\\f1\\'b7}\\tab"));
2220 TexOutput(indentBuf
);
2225 case LATEX_DESCRIPTION
:
2227 if (descriptionItemArg
)
2229 TexOutput(_T("\\tab{\\b "));
2230 TraverseChildrenFromChunk(descriptionItemArg
);
2231 TexOutput(_T("} "));
2232 descriptionItemArg
= NULL
;
2242 case ltTWOCOLITEMRULED
:
2244 wxNode
*node
= itemizeStack
.GetFirst();
2247 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
2250 struc
->currentItem
+= 1;
2253 wxNode
*node2
= NULL
;
2254 if (itemizeStack
.GetCount() > 1) // TODO: do I actually mean Nth(0) here??
2255 node2
= itemizeStack
.Item(1);
2257 oldIndent
= ((ItemizeStruc
*)node2
->GetData())->indentation
;
2259 TexOutput(_T("\n"));
2262 if (struc
->currentItem
> 1)
2264 if (currentItemSep
> 0)
2265 TexOutput(_T("\\par"));
2267 // WriteEnvironmentStyles();
2271 // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA,
2272 // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent);
2274 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA,
2275 TwoColWidthA, TwoColWidthA);
2277 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA
+ oldIndent
,
2278 TwoColWidthA
+ oldIndent
, TwoColWidthA
);
2291 if (macroId
== ltVERBATIM
)
2293 if (!issuedNewParagraph
)
2295 TexOutput(_T("\\par\\pard"));
2296 WriteEnvironmentStyles();
2297 issuedNewParagraph
= 1;
2299 else issuedNewParagraph
= 0;
2303 if (macroId
== ltVERBATIM
)
2304 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\s10\\fs20\\li720\\sa0 "));
2306 wxSnprintf(buf
, sizeof(buf
), _T("{\\f3\\fs20 "));
2312 if (macroId
== ltVERBATIM
)
2314 TexOutput(_T("\\pard\n"));
2315 WriteEnvironmentStyles();
2318 TexOutput(_T("\\par\n"));
2319 issuedNewParagraph
= 1;
2330 TexOutput(_T("\\qc "));
2332 PushEnvironmentStyle(_T("\\qc\\sa200"));
2336 TexOutput(_T("\\par\\pard\n"));
2337 issuedNewParagraph
= 1;
2339 PopEnvironmentStyle();
2340 WriteEnvironmentStyles();
2348 TexOutput(_T("\\ql\\sa200 "));
2350 PushEnvironmentStyle(_T("\\ql"));
2354 TexOutput(_T("\\par\\pard\n"));
2355 issuedNewParagraph
= 1;
2357 PopEnvironmentStyle();
2358 WriteEnvironmentStyles();
2366 TexOutput(_T("\\qr\\sa200 "));
2368 PushEnvironmentStyle(_T("\\qr"));
2372 TexOutput(_T("\\par\\pard\n"));
2373 issuedNewParagraph
= 1;
2375 PopEnvironmentStyle();
2376 WriteEnvironmentStyles();
2381 case ltFOOTNOTESIZE
:
2385 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), smallFont
*2);
2388 else TexOutput(_T("}\n"));
2396 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), tinyFont
*2);
2399 else TexOutput(_T("}\n"));
2406 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), normalFont
*2);
2409 else TexOutput(_T("}\n"));
2416 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), largeFont1
*2);
2419 else TexOutput(_T("}\n"));
2426 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LargeFont2
*2);
2429 else TexOutput(_T("}\n"));
2436 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), LARGEFont3
*2);
2439 else TexOutput(_T("}\n"));
2446 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), hugeFont1
*2);
2449 else TexOutput(_T("}\n"));
2456 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HugeFont2
*2);
2459 else TexOutput(_T("}\n"));
2466 wxSnprintf(buf
, sizeof(buf
), _T("{\\fs%d\n"), HUGEFont3
*2);
2469 else TexOutput(_T("}\n"));
2478 TexOutput(_T("{\\b "));
2480 else TexOutput(_T("}"));
2487 TexOutput(_T("{\\ul "));
2489 else TexOutput(_T("}"));
2500 TexOutput(_T("{\\i "));
2502 else TexOutput(_T("}"));
2505 // Roman font: do nothing. Should really switch between
2514 TexOutput(_T("{\\plain "));
2516 else TexOutput(_T("}"));
2520 // Medium-weight font. Unbolden...
2525 TexOutput(_T("{\\b0 "));
2527 else TexOutput(_T("}"));
2530 // Upright (un-italic or slant)
2535 TexOutput(_T("{\\i0 "));
2537 else TexOutput(_T("}"));
2546 TexOutput(_T("{\\scaps "));
2548 else TexOutput(_T("}"));
2557 TexOutput(_T("{\\f3 "));
2559 else TexOutput(_T("}"));
2565 TexOutput(_T("\\{"));
2571 TexOutput(_T("\\}"));
2577 TexOutput(_T("\\\\"));
2584 if ( issuedNewParagraph
== 0 )
2586 TexOutput(_T("\\par\\pard"));
2587 issuedNewParagraph
++;
2589 // Extra par if parskip is more than zero (usually looks best.)
2590 // N.B. JACS 2004-02-21: shouldn't need this for linear RTF if
2591 // we have a suitable set of styles.
2593 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2595 TexOutput(_T("\\par"));
2596 issuedNewParagraph
++;
2599 WriteEnvironmentStyles();
2601 // 1 is a whole paragraph if ParSkip == 0,
2602 // half a paragraph if ParSkip > 0
2603 else if ( issuedNewParagraph
== 1 )
2605 // Don't need a par at all if we've already had one,
2606 // and ParSkip == 0.
2608 // Extra par if parskip is more than zero (usually looks best.)
2609 if (winHelp
&& !inTabular
&& (ParSkip
> 0))
2611 TexOutput(_T("\\par"));
2612 issuedNewParagraph
++;
2615 WriteEnvironmentStyles();
2618 if (!issuedNewParagraph || (issuedNewParagraph > 1))
2620 TexOutput(_T("\\par\\pard"));
2622 // Extra par if parskip is more than zero (usually looks best.)
2623 if (!inTabular && (ParSkip > 0))
2624 TexOutput(_T("\\par"));
2625 WriteEnvironmentStyles();
2629 TexOutput(_T("\n"));
2635 // In Windows Help, no newpages until we've started some chapters or sections
2636 if (!(winHelp
&& !startedSections
))
2638 TexOutput(_T("\\page\n"));
2643 if (start
&& DocumentTitle
)
2645 TexOutput(_T("\\par\\pard"));
2647 TexOutput(_T("\\par"));
2648 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d\\b "), titleFont
*2);
2650 TraverseChildrenFromChunk(DocumentTitle
);
2651 TexOutput(_T("}\\par\\pard\n"));
2656 TexOutput(_T("\\par"));
2657 wxSnprintf(buf
, sizeof(buf
), _T("\\par\\qc{\\fs%d "), authorFont
*2);
2659 TraverseChildrenFromChunk(DocumentAuthor
);
2661 TexOutput(_T("\\par\\pard\n"));
2665 TexOutput(_T("\\par"));
2666 wxSnprintf(buf
, sizeof(buf
), _T("\\qc{\\fs%d "), authorFont
*2);
2668 TraverseChildrenFromChunk(DocumentDate
);
2669 TexOutput(_T("}\\par\\pard\n"));
2671 // If linear RTF, we want this titlepage to be in a separate
2672 // section with its own (blank) header and footer
2673 if (!winHelp
&& (DocumentStyle
!= LATEX_ARTICLE
))
2675 TexOutput(_T("{\\header }{\\footer }\n"));
2676 // Not sure about this: we get too many sections.
2677 // TexOutput(_T("\\sect"));
2682 case ltADDCONTENTSLINE
:
2686 if (contentsLineSection
&& contentsLineValue
)
2688 if (wxStrcmp(contentsLineSection
, _T("chapter")) == 0)
2690 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2692 else if (wxStrcmp(contentsLineSection
, _T("section")) == 0)
2694 if (DocumentStyle
!= LATEX_ARTICLE
)
2695 wxFprintf(Contents
, _T("\n\\tab%s\\par\n"), contentsLineValue
);
2697 wxFprintf(Contents
, _T("\\par\n{\\b %s}\\par\n"), contentsLineValue
);
2707 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2708 issuedNewParagraph
= 1;
2709 WriteEnvironmentStyles();
2717 TexOutput(_T("\\brdrb\\brdrs\\par\\pard\n"));
2718 issuedNewParagraph
= 1;
2719 WriteEnvironmentStyles();
2729 case ltNUMBEREDBIBITEM
:
2732 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
2734 TexOutput(_T("\\par\\pard\\par\n\n"));
2741 TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2749 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2750 wxSnprintf(buf
, sizeof(buf
), _T("%d"), chapterNo
);
2759 // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}"));
2760 wxSnprintf(buf
, sizeof(buf
), _T("%d"), sectionNo
);
2767 if (!start
&& !winHelp
)
2769 TexOutput(_T("\\cols2\n"));
2775 if (!start
&& !winHelp
)
2777 TexOutput(_T("\\cols1\n"));
2783 if (start
&& useWord
&& !winHelp
)
2785 FakeCurrentSection(_T("Index"));
2786 OnMacro(ltPAR
, 0, true);
2787 OnMacro(ltPAR
, 0, false);
2788 TexOutput(_T("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n"));
2792 case ltLISTOFFIGURES
:
2794 if (start
&& useWord
&& !winHelp
)
2796 FakeCurrentSection(FiguresNameString
, false);
2797 OnMacro(ltPAR
, 0, true);
2798 OnMacro(ltPAR
, 0, false);
2799 OnMacro(ltPAR
, 0, true);
2800 OnMacro(ltPAR
, 0, false);
2802 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"),
2808 case ltLISTOFTABLES
:
2810 if (start
&& useWord
&& !winHelp
)
2812 FakeCurrentSection(TablesNameString
, false);
2813 OnMacro(ltPAR
, 0, true);
2814 OnMacro(ltPAR
, 0, false);
2815 OnMacro(ltPAR
, 0, true);
2816 OnMacro(ltPAR
, 0, false);
2818 wxSnprintf(buf
, sizeof(buf
), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"),
2826 if (start
) TexOutput(_T("{\\f1\\'61}"));
2829 if (start
) TexOutput(_T("{\\f1\\'62}"));
2832 if (start
) TexOutput(_T("{\\f1\\'63}"));
2835 if (start
) TexOutput(_T("{\\f1\\'64}"));
2839 if (start
) TexOutput(_T("{\\f1\\'65}"));
2842 if (start
) TexOutput(_T("{\\f1\\'7A}"));
2845 if (start
) TexOutput(_T("{\\f1\\'68}"));
2849 if (start
) TexOutput(_T("{\\f1\\'71}"));
2852 if (start
) TexOutput(_T("{\\f1\\'69}"));
2855 if (start
) TexOutput(_T("{\\f1\\'6B}"));
2858 if (start
) TexOutput(_T("{\\f1\\'6C}"));
2861 if (start
) TexOutput(_T("{\\f1\\'6D}"));
2864 if (start
) TexOutput(_T("{\\f1\\'6E}"));
2867 if (start
) TexOutput(_T("{\\f1\\'78}"));
2870 if (start
) TexOutput(_T("{\\f1\\'70}"));
2873 if (start
) TexOutput(_T("{\\f1\\'76}"));
2877 if (start
) TexOutput(_T("{\\f1\\'72}"));
2880 if (start
) TexOutput(_T("{\\f1\\'73}"));
2883 if (start
) TexOutput(_T("{\\f1\\'56}"));
2886 if (start
) TexOutput(_T("{\\f1\\'74}"));
2889 if (start
) TexOutput(_T("{\\f1\\'75}"));
2893 if (start
) TexOutput(_T("{\\f1\\'66}"));
2896 if (start
) TexOutput(_T("{\\f1\\'63}"));
2899 if (start
) TexOutput(_T("{\\f1\\'79}"));
2902 if (start
) TexOutput(_T("{\\f1\\'77}"));
2905 if (start
) TexOutput(_T("{\\f1\\'47}"));
2908 if (start
) TexOutput(_T("{\\f1\\'44}"));
2911 if (start
) TexOutput(_T("{\\f1\\'51}"));
2914 if (start
) TexOutput(_T("{\\f1\\'4C}"));
2917 if (start
) TexOutput(_T("{\\f1\\'58}"));
2920 if (start
) TexOutput(_T("{\\f1\\'50}"));
2923 if (start
) TexOutput(_T("{\\f1\\'53}"));
2926 if (start
) TexOutput(_T("{\\f1\\'54}"));
2929 if (start
) TexOutput(_T("{\\f1\\'46}"));
2932 if (start
) TexOutput(_T("{\\f1\\'59}"));
2935 if (start
) TexOutput(_T("{\\f1\\'57}"));
2937 // Binary operation symbols
2940 if (start
) TexOutput(_T("{\\f1\\'A3}"));
2943 if (start
) TexOutput(_T("<<"));
2946 if (start
) TexOutput(_T("{\\f1\\'CC}"));
2949 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2952 if (start
) TexOutput(_T("{\\f1\\'CE}"));
2956 if (start
) TexOutput(_T("{\\f1\\'B3}"));
2959 if (start
) TexOutput(_T(">>"));
2962 if (start
) TexOutput(_T("{\\f1\\'C9}"));
2965 if (start
) TexOutput(_T("{\\f1\\'CD}"));
2968 if (start
) TexOutput(_T("{\\f1\\'27}"));
2971 if (start
) TexOutput(_T("{\\f1\\'5E}"));
2974 if (start
) TexOutput(_T("{\\f1\\'B9}"));
2977 if (start
) TexOutput(_T("{\\f1\\'BB}"));
2980 if (start
) TexOutput(_T("{\\f1\\'40}"));
2983 if (start
) TexOutput(_T("{\\f1\\'BA}"));
2986 if (start
) TexOutput(_T("{\\f1\\'B5}"));
2989 if (start
) TexOutput(_T("{\\f1\\'7E}"));
2992 if (start
) TexOutput(_T("{\\f4\\'4A}"));
2995 if (start
) TexOutput(_T("{\\f4\\'4C}"));
2998 if (start
) TexOutput(_T("|"));
3001 // Negated relation symbols
3003 if (start
) TexOutput(_T("{\\f1\\'B9}"));
3006 if (start
) TexOutput(_T("{\\f1\\'CF}"));
3009 if (start
) TexOutput(_T("{\\f1\\'CB}"));
3014 if (start
) TexOutput(_T("{\\f1\\'AC}"));
3017 if (start
) TexOutput(_T("{\\f1\\'DC}"));
3020 if (start
) TexOutput(_T("{\\f1\\'AE}"));
3023 if (start
) TexOutput(_T("{\\f1\\'DE}"));
3025 case ltLEFTRIGHTARROW
:
3026 if (start
) TexOutput(_T("{\\f1\\'AB}"));
3028 case ltLEFTRIGHTARROW2
:
3029 if (start
) TexOutput(_T("{\\f1\\'DB}"));
3032 if (start
) TexOutput(_T("{\\f1\\'AD}"));
3035 if (start
) TexOutput(_T("{\\f1\\'DD}"));
3038 if (start
) TexOutput(_T("{\\f1\\'AF}"));
3041 if (start
) TexOutput(_T("{\\f1\\'DF}"));
3044 // Miscellaneous symbols
3046 if (start
) TexOutput(_T("{\\f1\\'CO}"));
3049 if (start
) TexOutput(_T("{\\f1\\'C3}"));
3052 if (start
) TexOutput(_T("{\\f1\\'C2}"));
3055 if (start
) TexOutput(_T("{\\f1\\'C1}"));
3058 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3061 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3064 if (start
) TexOutput(_T("{\\f1\\'D6}"));
3067 if (start
) TexOutput(_T("{\\f1\\'B6}"));
3070 if (start
) TexOutput(_T("{\\f1\\'5E}"));
3073 if (start
) TexOutput(_T("{\\f1\\'22}"));
3076 if (start
) TexOutput(_T("{\\f1\\'24}"));
3079 if (start
) TexOutput(_T("{\\f1\\'D8}"));
3082 if (start
) TexOutput(_T("{\\f1\\'23}"));
3085 if (start
) TexOutput(_T("{\\f1\\'D0}"));
3088 if (start
) TexOutput(_T("{\\f5\\'73}"));
3091 if (start
) TexOutput(_T("{\\f5\\'A8}"));
3094 if (start
) TexOutput(_T("{\\f5\\'A9}"));
3097 if (start
) TexOutput(_T("{\\f5\\'AA}"));
3100 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3103 if (start
) TexOutput(_T("{\\f1\\'A5}"));
3106 if (start
) TexOutput(_T("{\\f0\\'A9}"));
3109 if (start
) TexOutput(_T("{\\f0\\'AE}"));
3112 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3115 if (start
) TexOutput(_T("{\\f1\\'B1}"));
3118 if (start
) TexOutput(_T("{\\f1\\'B4}"));
3121 if (start
) TexOutput(_T("{\\f1\\'B8}"));
3124 if (start
) TexOutput(_T("{\\f1\\'D7}"));
3127 if (start
) TexOutput(_T("{\\f1\\'2A}"));
3130 if (start
) TexOutput(_T("{\\f5\\'AB}"));
3133 if (start
) TexOutput(_T("{\\f1\\'C7}"));
3136 if (start
) TexOutput(_T("{\\f1\\'C8}"));
3139 if (start
) TexOutput(_T("{\\f1\\'DA}"));
3142 if (start
) TexOutput(_T("{\\f1\\'D9}"));
3145 if (start
) TexOutput(_T("{\\f1\\'B0}"));
3148 if (start
) TexOutput(_T("{\\f1\\'B7}"));
3151 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3154 if (start
) TexOutput(_T("{\\f1\\'C6}"));
3157 if (start
) TexOutput(_T("{\\f1\\'E0}"));
3159 case ltBIGTRIANGLEDOWN
:
3160 if (start
) TexOutput(_T("{\\f1\\'D1}"));
3163 if (start
) TexOutput(_T("{\\f1\\'C5}"));
3166 if (start
) TexOutput(_T("{\\f1\\'C4}"));
3169 if (start
) TexOutput(_T("{\\'DF}"));
3173 if (start
) inFigure
= true;
3174 else inFigure
= false;
3179 if (start
) inTable
= true;
3180 else inTable
= false;
3185 DefaultOnMacro(macroId
, no_args
, start
);
3191 // Called on start/end of argument examination
3192 bool RTFOnArgument(int macroId
, int arg_no
, bool start
)
3199 case ltCHAPTERHEADING
:
3202 case ltSECTIONHEADING
:
3204 case ltSUBSECTIONSTAR
:
3205 case ltSUBSUBSECTION
:
3206 case ltSUBSUBSECTIONSTAR
:
3208 case ltMEMBERSECTION
:
3209 case ltFUNCTIONSECTION
:
3213 if (!start
&& (arg_no
== 1))
3214 currentSection
= GetArgChunk();
3219 if (start
&& (arg_no
== 1))
3220 TexOutput(_T("\\pard\\li600\\fi-600{\\b "));
3222 if (!start
&& (arg_no
== 1))
3223 TexOutput(_T("} "));
3225 if (start
&& (arg_no
== 2))
3227 if (!suppressNameDecoration
) TexOutput(_T("{\\b "));
3228 currentMember
= GetArgChunk();
3230 if (!start
&& (arg_no
== 2))
3232 if (!suppressNameDecoration
) TexOutput(_T("}"));
3235 if (start
&& (arg_no
== 3))
3237 if (!start
&& (arg_no
== 3))
3239 // TexOutput(_T(")\\li0\\fi0"));
3240 // TexOutput(_T(")\\par\\pard\\li0\\fi0"));
3241 // issuedNewParagraph = 1;
3243 WriteEnvironmentStyles();
3249 if (start
&& (arg_no
== 1))
3250 TexOutput(_T("\\pard\\li260\\fi-260{\\b "));
3251 if (!start
&& (arg_no
== 1))
3252 TexOutput(_T("} "));
3254 if (start
&& (arg_no
== 2))
3256 if (!suppressNameDecoration
) TexOutput(_T("({\\b "));
3257 currentMember
= GetArgChunk();
3259 if (!start
&& (arg_no
== 2))
3261 if (!suppressNameDecoration
) TexOutput(_T("}"));
3264 if (!start
&& (arg_no
== 3))
3266 TexOutput(_T(")\\li0\\fi0"));
3267 WriteEnvironmentStyles();
3273 if (start
&& (arg_no
== 1))
3274 TexOutput(_T("\\pard\\li260\\fi-260"));
3276 if (!start
&& (arg_no
== 1))
3279 if (start
&& (arg_no
== 2))
3280 TexOutput(_T("(*"));
3281 if (!start
&& (arg_no
== 2))
3284 if (start
&& (arg_no
== 2))
3285 currentMember
= GetArgChunk();
3287 if (start
&& (arg_no
== 3))
3289 if (!start
&& (arg_no
== 3))
3291 TexOutput(_T(")\\li0\\fi0"));
3292 WriteEnvironmentStyles();
3298 if (start
&& (arg_no
== 1))
3299 TexOutput(_T("{\\b "));
3300 if (!start
&& (arg_no
== 1))
3302 if (start
&& (arg_no
== 2))
3304 TexOutput(_T("{\\i "));
3306 if (!start
&& (arg_no
== 2))
3314 if (start
&& (arg_no
== 1))
3315 TexOutput(_T("{\\b "));
3316 if (!start
&& (arg_no
== 1))
3317 TexOutput(_T("} ")); // This is the difference from param - one space!
3318 if (start
&& (arg_no
== 2))
3320 TexOutput(_T("{\\i "));
3322 if (!start
&& (arg_no
== 2))
3330 if (!start
&& (arg_no
== 1))
3333 if (start
&& (arg_no
== 2))
3334 currentMember
= GetArgChunk();
3343 wxChar
*refName
= GetArgData();
3344 if (winHelp
|| !useWord
)
3348 TexRef
*texRef
= FindReference(refName
);
3351 sec
= texRef
->sectionNumber
;
3361 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
3373 if ((GetNoArgs() - arg_no
) == 1)
3376 TexOutput(_T("{\\uldb "));
3380 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3384 TexOutput(_T("{\\v "));
3386 // Remove green colour/underlining if specified
3387 if (!hotSpotUnderline
&& !hotSpotColour
)
3389 else if (!hotSpotColour
)
3392 else TexOutput(_T("}"));
3395 else // If a linear document, must resolve the references ourselves
3397 if ((GetNoArgs() - arg_no
) == 1)
3399 // In a linear document we display the anchor text in italic plus
3402 TexOutput(_T("{\\i "));
3407 helpRefText
= GetArgChunk();
3411 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3413 if (macroId
!= ltHELPREFN
)
3415 wxChar
*refName
= GetArgData();
3416 TexRef
*texRef
= NULL
;
3418 texRef
= FindReference(refName
);
3421 if (texRef
|| !ignoreBadRefs
)
3422 TexOutput(_T(" ("));
3425 if (texRef
|| !ignoreBadRefs
)
3429 TexOutput(_T("p. "));
3430 TexOutput(_T("{\\field{\\*\\fldinst PAGEREF "));
3432 TexOutput(_T(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"));
3436 // Only print section name if we're not in Word mode,
3437 // so can't do page references
3440 TexOutput(texRef
->sectionName
);
3442 TexOutput(texRef
->sectionNumber
);
3447 TexOutput(_T("??"));
3448 wxSnprintf(buf
, sizeof(buf
), _T("Warning: unresolved reference '%s'"), refName
);
3454 else TexOutput(_T("??"));
3458 if (texRef
|| !ignoreBadRefs
)
3473 else if (arg_no
== 2)
3478 TexOutput(_T(" ({\\f3 "));
3482 TexOutput(_T("})"));
3493 if ((GetNoArgs() - arg_no
) == 1)
3496 TexOutput(_T("{\\ul "));
3500 if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
3504 TexOutput(_T("{\\v "));
3506 // Remove green colour/underlining if specified
3507 if (!hotSpotUnderline
&& !hotSpotColour
)
3509 else if (!hotSpotColour
)
3512 else TexOutput(_T("}"));
3515 else // A linear document...
3517 if ((GetNoArgs() - arg_no
) == 1)
3519 // In a linear document we just display the anchor text in italic
3521 TexOutput(_T("{\\i "));
3530 case ltADDCONTENTSLINE
:
3532 if (start
&& !winHelp
)
3535 contentsLineSection
= copystring(GetArgData());
3536 else if (arg_no
== 3)
3537 contentsLineValue
= copystring(GetArgData());
3551 static int imageWidth
= 0;
3552 static int imageHeight
= 0;
3554 if (start
&& (arg_no
== 1))
3556 wxChar
*imageDimensions
= copystring(GetArgData());
3558 // imageWidth - Convert points to TWIPS (1 twip = 1/20th of point)
3559 wxStringTokenizer
tok(imageDimensions
, _T(";:"), wxTOKEN_STRTOK
);
3560 if(tok
.HasMoreTokens())
3562 wxString token
= tok
.GetNextToken();
3563 imageWidth
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3570 // imageHeight - Convert points to TWIPS (1 twip = 1/20th of point)
3571 if(tok
.HasMoreTokens())
3573 wxString token
= tok
.GetNextToken();
3574 imageHeight
= (int)(20*ParseUnitArgument((wxChar
*)token
.c_str()));
3581 if (imageDimensions
) // glt
3582 delete [] imageDimensions
;
3585 else if (start
&& (arg_no
== 2 ))
3587 wxChar
*filename
= copystring(GetArgData());
3588 wxString f
= _T("");
3589 if ((winHelp
|| (wxStrcmp(bitmapMethod
, _T("includepicture")) == 0) || (wxStrcmp(bitmapMethod
, _T("import")) == 0)) && useWord
)
3591 if (f
== _T("")) // Try for a .shg (segmented hypergraphics file)
3593 wxStrcpy(buf
, filename
);
3594 StripExtension(buf
);
3595 wxStrcat(buf
, _T(".shg"));
3596 f
= TexPathList
.FindValidPath(buf
);
3598 if (f
== _T("")) // Try for a .bmp
3600 wxStrcpy(buf
, filename
);
3601 StripExtension(buf
);
3602 wxStrcat(buf
, _T(".bmp"));
3603 f
= TexPathList
.FindValidPath(buf
);
3605 if (f
== _T("")) // Try for a metafile instead
3607 wxStrcpy(buf
, filename
);
3608 StripExtension(buf
);
3609 wxStrcat(buf
, _T(".wmf"));
3610 f
= TexPathList
.FindValidPath(buf
);
3616 if (bitmapTransparency
&& (winHelpVersion
> 3))
3617 TexOutput(_T("\\{bmct "));
3619 TexOutput(_T("\\{bmc "));
3620 wxString str
= wxFileNameFromPath(f
);
3621 TexOutput((wxChar
*) (const wxChar
*) str
);
3622 TexOutput(_T("\\}"));
3626 // Microsoft Word method
3627 if (wxStrcmp(bitmapMethod
, _T("import")) == 0)
3628 TexOutput(_T("{\\field{\\*\\fldinst IMPORT "));
3630 TexOutput(_T("{\\field{\\*\\fldinst INCLUDEPICTURE "));
3632 // Full path appears not to be valid!
3633 wxString str
= wxFileNameFromPath(f
);
3634 TexOutput((wxChar
*)(const wxChar
*) str
);
3636 int len = wxStrlen(f);
3637 wxChar smallBuf[2]; smallBuf[1] = 0;
3638 for (int i = 0; i < len; i++)
3641 TexOutput(smallBuf);
3642 if (smallBuf[0] == '\\')
3643 TexOutput(smallBuf);
3646 TexOutput(_T("}{\\fldrslt PRESS F9 TO FORMAT PICTURE}}"));
3651 TexOutput(_T("[No BMP or WMF for image file "));
3652 TexOutput(filename
);
3654 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3657 if (filename
) // glt
3662 if (f
== _T("")) // Try for a .bmp
3664 wxStrcpy(buf
, filename
);
3665 StripExtension(buf
);
3666 wxStrcat(buf
, _T(".bmp"));
3667 f
= TexPathList
.FindValidPath(buf
);
3671 FILE *fd
= wxFopen(f
, _T("rb"));
3672 if (OutputBitmapHeader(fd
, winHelp
))
3673 OutputBitmapData(fd
);
3676 wxSnprintf(buf
, sizeof(buf
), _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f
.c_str());
3681 else // Try for a metafile instead
3684 wxStrcpy(buf
, filename
);
3685 StripExtension(buf
);
3686 wxStrcat(buf
, _T(".wmf"));
3687 f
= TexPathList
.FindValidPath(buf
);
3690 // HFILE handle = _lopen(f, READ);
3691 FILE *fd
= wxFopen(f
, _T("rb"));
3692 if (OutputMetafileHeader(fd
, winHelp
, imageWidth
, imageHeight
))
3694 OutputMetafileData(fd
);
3698 wxSnprintf(buf
, sizeof(buf
), _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f
.c_str());
3706 TexOutput(_T("[No BMP or WMF for image file "));
3707 TexOutput(filename
);
3709 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename
);
3722 case ltSUPERTABULAR
:
3728 currentRowNumber
= 0;
3731 tableVerticalLineLeft
= false;
3732 tableVerticalLineRight
= false;
3733 int currentWidth
= 0;
3735 wxChar
*alignString
= copystring(GetArgData());
3736 ParseTableArgument(alignString
);
3738 // TexOutput(_T("\\trowd\\trgaph108\\trleft-108"));
3739 TexOutput(_T("\\trowd\\trgaph108"));
3741 // Write the first row formatting for compatibility
3742 // with standard Latex
3743 if (compatibilityMode
)
3745 for (int i
= 0; i
< noColumns
; i
++)
3747 currentWidth
+= TableData
[i
].width
;
3748 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
3751 TexOutput(_T("\\pard\\intbl\n"));
3753 delete[] alignString
;
3758 else if (arg_no
== 2 && !start
)
3760 TexOutput(_T("\\pard\n"));
3761 WriteEnvironmentStyles();
3772 TexOutput(_T("\\li360\n"));
3774 PushEnvironmentStyle(_T("\\li360\\sa200"));
3779 PopEnvironmentStyle();
3780 OnMacro(ltPAR
, 0, true);
3781 OnMacro(ltPAR
, 0, false);
3789 TexOutput(_T("\\li360\n"));
3790 PushEnvironmentStyle(_T("\\li360\\sa200"));
3794 PopEnvironmentStyle();
3795 OnMacro(ltPAR
, 0, true);
3796 OnMacro(ltPAR
, 0, false);
3808 wxSnprintf(buf
, sizeof(buf
), _T("\\sa200\\box\\trgaph108%s\n"), ((macroId
== ltNORMALBOXD
) ? _T("\\brdrdb") : _T("\\brdrs")));
3810 PushEnvironmentStyle(buf
);
3814 PopEnvironmentStyle();
3815 OnMacro(ltPAR
, 0, true);
3816 OnMacro(ltPAR
, 0, false);
3820 case ltHELPFONTSIZE
:
3824 wxChar
*data
= GetArgData();
3825 if (wxStrcmp(data
, _T("10")) == 0)
3827 else if (wxStrcmp(data
, _T("11")) == 0)
3829 else if (wxStrcmp(data
, _T("12")) == 0)
3831 wxSnprintf(buf
, sizeof(buf
), _T("\\fs%d\n"), normalFont
*2);
3838 case ltHELPFONTFAMILY
:
3842 wxChar
*data
= GetArgData();
3843 if (wxStrcmp(data
, _T("Swiss")) == 0)
3844 TexOutput(_T("\\f2\n"));
3845 else if (wxStrcmp(data
, _T("Symbol")) == 0)
3846 TexOutput(_T("\\f1\n"));
3847 else if (wxStrcmp(data
, _T("Times")) == 0)
3848 TexOutput(_T("\\f0\n"));
3856 if (start
&& arg_no
== 1)
3858 wxChar
*data
= GetArgData();
3859 ParIndent
= ParseUnitArgument(data
);
3860 if (ParIndent
== 0 || forbidParindent
== 0)
3862 wxSnprintf(buf
, sizeof(buf
), _T("\\fi%d\n"), ParIndent
*20);
3871 if (start
&& IsArgOptional())
3873 descriptionItemArg
= GetArgChunk();
3879 case ltTWOCOLITEMRULED
:
3886 TexOutput(_T("\\tab "));
3893 if (macroId
== ltTWOCOLITEMRULED
)
3894 TexOutput(_T("\\brdrb\\brdrs\\brdrw15\\brsp20 "));
3895 TexOutput(_T("\\par\\pard\n"));
3896 issuedNewParagraph
= 1;
3897 WriteEnvironmentStyles();
3908 case ltACCENT_GRAVE
:
3912 wxChar
*val
= GetArgData();
3918 TexOutput(_T("\\'e0"));
3921 TexOutput(_T("\\'e8"));
3924 TexOutput(_T("\\'ec"));
3927 TexOutput(_T("\\'f2"));
3930 TexOutput(_T("\\'f9"));
3933 TexOutput(_T("\\'c0"));
3936 TexOutput(_T("\\'c8"));
3939 TexOutput(_T("\\'cc"));
3942 TexOutput(_T("\\'d2"));
3945 TexOutput(_T("\\'d9"));
3954 case ltACCENT_ACUTE
:
3958 wxChar
*val
= GetArgData();
3964 TexOutput(_T("\\'e1"));
3967 TexOutput(_T("\\'e9"));
3970 TexOutput(_T("\\'ed"));
3973 TexOutput(_T("\\'f3"));
3976 TexOutput(_T("\\'fa"));
3979 TexOutput(_T("\\'fd"));
3982 TexOutput(_T("\\'c1"));
3985 TexOutput(_T("\\'c9"));
3988 TexOutput(_T("\\'cd"));
3991 TexOutput(_T("\\'d3"));
3994 TexOutput(_T("\\'da"));
3997 TexOutput(_T("\\'dd"));
4006 case ltACCENT_CARET
:
4010 wxChar
*val
= GetArgData();
4016 TexOutput(_T("\\'e2"));
4019 TexOutput(_T("\\'ea"));
4022 TexOutput(_T("\\'ee"));
4025 TexOutput(_T("\\'f4"));
4028 TexOutput(_T("\\'fb"));
4031 TexOutput(_T("\\'c2"));
4034 TexOutput(_T("\\'ca"));
4037 TexOutput(_T("\\'ce"));
4040 TexOutput(_T("\\'d4"));
4043 TexOutput(_T("\\'db"));
4052 case ltACCENT_TILDE
:
4056 wxChar
*val
= GetArgData();
4062 TexOutput(_T("\\'e3"));
4068 TexOutput(_T("\\'f1"));
4071 TexOutput(_T("\\'f5"));
4074 TexOutput(_T("\\'c3"));
4077 TexOutput(_T("\\'d1"));
4080 TexOutput(_T("\\'d5"));
4089 case ltACCENT_UMLAUT
:
4093 wxChar
*val
= GetArgData();
4099 TexOutput(_T("\\'e4"));
4102 TexOutput(_T("\\'eb"));
4105 TexOutput(_T("\\'ef"));
4108 TexOutput(_T("\\'f6"));
4111 TexOutput(_T("\\'fc"));
4114 TexOutput(_T("\\'df"));
4117 TexOutput(_T("\\'ff"));
4120 TexOutput(_T("\\'c4"));
4123 TexOutput(_T("\\'cb"));
4126 TexOutput(_T("\\'cf"));
4129 TexOutput(_T("\\'d6"));
4132 TexOutput(_T("\\'dc"));
4135 TexOutput(_T("\\'df"));
4148 wxChar
*val
= GetArgData();
4154 TexOutput(_T("\\'e5"));
4157 TexOutput(_T("\\'c5"));
4166 case ltACCENT_CADILLA
:
4170 wxChar
*val
= GetArgData();
4176 TexOutput(_T("\\'e7"));
4179 TexOutput(_T("\\'c7"));
4190 static wxChar
*helpTopic
= NULL
;
4191 static FILE *savedOutput
= NULL
;
4198 OnInform(_T("Consider using \\footnotepopup instead of \\footnote."));
4201 wxSnprintf(footBuf
, sizeof(footBuf
), _T("(%d)"), footnoteCount
);
4203 TexOutput(_T(" {\\ul "));
4206 helpTopic
= FindTopicName(NULL
);
4207 TexOutput(_T("{\\v "));
4209 // Remove green colour/underlining if specified
4210 if (!hotSpotUnderline
&& !hotSpotColour
)
4212 else if (!hotSpotColour
)
4215 TexOutput(helpTopic
);
4218 wxFprintf(Popups
, _T("\\page\n"));
4219 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4220 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4221 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4222 savedOutput
= CurrentOutput1
;
4223 SetCurrentOutput(Popups
);
4227 SetCurrentOutput(savedOutput
);
4237 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4241 TexOutput(_T("}}"), true);
4246 case ltFOOTNOTEPOPUP
:
4248 static wxChar
*helpTopic
= NULL
;
4249 static FILE *savedOutput
= NULL
;
4256 TexOutput(_T("{\\ul "));
4264 else if (arg_no
== 2)
4268 helpTopic
= FindTopicName(NULL
);
4269 TexOutput(_T("{\\v "));
4271 // Remove green colour/underlining if specified
4272 if (!hotSpotUnderline
&& !hotSpotColour
)
4274 else if (!hotSpotColour
)
4277 TexOutput(helpTopic
);
4280 wxFprintf(Popups
, _T("\\page\n"));
4281 // wxFprintf(Popups, _T("\n${\\footnote }")); // No title
4282 wxFprintf(Popups
, _T("\n#{\\footnote %s}\n"), helpTopic
);
4283 wxFprintf(Popups
, _T("+{\\footnote %s}\n"), GetBrowseString());
4284 savedOutput
= CurrentOutput1
;
4285 SetCurrentOutput(Popups
);
4289 SetCurrentOutput(savedOutput
);
4300 TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true);
4304 TexOutput(_T("}}"), true);
4312 if (start
&& (arg_no
== 1))
4324 if (winHelp
) return false;
4330 LeftHeaderEven
= GetArgChunk();
4331 if (wxStrlen(GetArgData(LeftHeaderEven
)) == 0)
4332 LeftHeaderEven
= NULL
;
4335 CentreHeaderEven
= GetArgChunk();
4336 if (wxStrlen(GetArgData(CentreHeaderEven
)) == 0)
4337 CentreHeaderEven
= NULL
;
4340 RightHeaderEven
= GetArgChunk();
4341 if (wxStrlen(GetArgData(RightHeaderEven
)) == 0)
4342 RightHeaderEven
= NULL
;
4345 LeftHeaderOdd
= GetArgChunk();
4346 if (wxStrlen(GetArgData(LeftHeaderOdd
)) == 0)
4347 LeftHeaderOdd
= NULL
;
4350 CentreHeaderOdd
= GetArgChunk();
4351 if (wxStrlen(GetArgData(CentreHeaderOdd
)) == 0)
4352 CentreHeaderOdd
= NULL
;
4355 RightHeaderOdd
= GetArgChunk();
4356 if (wxStrlen(GetArgData(RightHeaderOdd
)) == 0)
4357 RightHeaderOdd
= NULL
;
4358 OutputRTFHeaderCommands();
4373 if (winHelp
) return false;
4379 LeftFooterEven
= GetArgChunk();
4380 if (wxStrlen(GetArgData(LeftFooterEven
)) == 0)
4381 LeftFooterEven
= NULL
;
4384 CentreFooterEven
= GetArgChunk();
4385 if (wxStrlen(GetArgData(CentreFooterEven
)) == 0)
4386 CentreFooterEven
= NULL
;
4389 RightFooterEven
= GetArgChunk();
4390 if (wxStrlen(GetArgData(RightFooterEven
)) == 0)
4391 RightFooterEven
= NULL
;
4394 LeftFooterOdd
= GetArgChunk();
4395 if (wxStrlen(GetArgData(LeftFooterOdd
)) == 0)
4396 LeftFooterOdd
= NULL
;
4399 CentreFooterOdd
= GetArgChunk();
4400 if (wxStrlen(GetArgData(CentreFooterOdd
)) == 0)
4401 CentreFooterOdd
= NULL
;
4404 RightFooterOdd
= GetArgChunk();
4405 if (wxStrlen(GetArgData(RightFooterOdd
)) == 0)
4406 RightFooterOdd
= NULL
;
4407 OutputRTFFooterCommands();
4417 if (winHelp
) return false;
4418 // Fake a SetHeader command
4421 LeftHeaderOdd
= NULL
;
4422 CentreHeaderOdd
= NULL
;
4423 RightHeaderOdd
= NULL
;
4424 LeftHeaderEven
= NULL
;
4425 CentreHeaderEven
= NULL
;
4426 RightHeaderEven
= NULL
;
4427 OnInform(_T("Consider using setheader/setfooter rather than markright."));
4429 RTFOnArgument(ltSETHEADER
, 4, start
);
4431 OutputRTFHeaderCommands();
4436 if (winHelp
) return false;
4437 // Fake a SetHeader command
4444 LeftHeaderOdd
= NULL
;
4445 CentreHeaderOdd
= NULL
;
4446 RightHeaderOdd
= NULL
;
4447 LeftHeaderEven
= NULL
;
4448 CentreHeaderEven
= NULL
;
4449 RightHeaderEven
= NULL
;
4450 OnInform(_T("Consider using setheader/setfooter rather than markboth."));
4452 return RTFOnArgument(ltSETHEADER
, 1, start
);
4456 RTFOnArgument(ltSETHEADER
, 4, start
);
4458 OutputRTFHeaderCommands();
4464 case ltPAGENUMBERING
:
4471 if (winHelp
) return false;
4474 TexOutput(_T("\\pgnrestart"));
4475 wxChar
*data
= GetArgData();
4476 if (currentNumberStyle
) delete[] currentNumberStyle
;
4477 currentNumberStyle
= copystring(data
);
4478 OutputNumberStyle(currentNumberStyle
);
4480 TexOutput(_T("\n"));
4486 if (winHelp
) return false;
4495 wxChar
*val
= GetArgData();
4496 currentItemSep
= ParseUnitArgument(val
);
4501 case ltEVENSIDEMARGIN
:
4505 case ltODDSIDEMARGIN
:
4509 wxChar
*val
= GetArgData();
4510 int twips
= (int)(20*ParseUnitArgument(val
));
4511 // Add an inch since in LaTeX it's specified minus an inch
4513 CurrentLeftMarginOdd
= twips
;
4514 wxSnprintf(buf
, sizeof(buf
), _T("\\margl%d\n"), twips
);
4517 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4521 case ltMARGINPARWIDTH
:
4525 wxChar
*val
= GetArgData();
4526 int twips
= (int)(20*ParseUnitArgument(val
));
4527 CurrentMarginParWidth
= twips
;
4531 case ltMARGINPARSEP
:
4535 wxChar
*val
= GetArgData();
4536 int twips
= (int)(20*ParseUnitArgument(val
));
4537 CurrentMarginParSep
= twips
;
4538 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4546 wxChar
*val
= GetArgData();
4547 int twips
= (int)(20*ParseUnitArgument(val
));
4548 CurrentTextWidth
= twips
;
4550 // Need to set an implicit right margin
4551 CurrentRightMarginOdd
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginOdd
;
4552 CurrentRightMarginEven
= PageWidth
- CurrentTextWidth
- CurrentLeftMarginEven
;
4553 CurrentMarginParX
= CurrentLeftMarginOdd
+ CurrentTextWidth
+ CurrentMarginParSep
;
4554 wxSnprintf(buf
, sizeof(buf
), _T("\\margr%d\n"), CurrentRightMarginOdd
);
4560 case ltMARGINPARODD
:
4566 TexOutput(_T("\\sa200\\box\n"));
4567 PushEnvironmentStyle(_T("\\sa200\\box"));
4571 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4580 TexOutput(_T("\\par\\pard\n"));
4581 PopEnvironmentStyle();
4582 WriteEnvironmentStyles();
4585 TexOutput(_T("\\par\\pard\n"));
4586 issuedNewParagraph
= 1;
4590 case ltMARGINPAREVEN
:
4596 TexOutput(_T("\\sa200\\box\n"));
4597 PushEnvironmentStyle(_T("\\sa200\\box"));
4603 // Have to calculate what the margins are changed to in WfW margin
4604 // mirror mode, on an even (left-hand) page.
4605 int x
= PageWidth
- CurrentRightMarginOdd
- CurrentMarginParWidth
- CurrentMarginParSep
4606 - CurrentTextWidth
+ GutterWidth
;
4607 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), x
, CurrentMarginParWidth
);
4612 wxSnprintf(buf
, sizeof(buf
), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX
, CurrentMarginParWidth
);
4622 TexOutput(_T("\\par\\pard\n"));
4623 PopEnvironmentStyle();
4624 WriteEnvironmentStyles();
4627 issuedNewParagraph
= 1;
4628 TexOutput(_T("\\par\\pard\n"));
4632 case ltTWOCOLWIDTHA
:
4636 wxChar
*val
= GetArgData();
4637 int twips
= (int)(20*ParseUnitArgument(val
));
4638 TwoColWidthA
= twips
;
4642 case ltTWOCOLWIDTHB
:
4646 wxChar
*val
= GetArgData();
4647 int twips
= (int)(20*ParseUnitArgument(val
));
4648 TwoColWidthB
= twips
;
4657 int currentWidth
= 0;
4659 if (!compatibilityMode
|| (currentRowNumber
> 0))
4661 TexOutput(_T("\\pard\\intbl"));
4663 if (macroId
== ltRULEDROW
)
4665 for (int i
= 0; i
< noColumns
; i
++)
4667 currentWidth
+= TableData
[i
].width
;
4670 TexOutput(_T("\\clbrdrt\\brdrs\\brdrw15"));
4672 else if (ruleTop
> 1)
4674 TexOutput(_T("\\clbrdrt\\brdrdb\\brdrw15"));
4676 if (ruleBottom
== 1)
4678 TexOutput(_T("\\clbrdrb\\brdrs\\brdrw15"));
4680 else if (ruleBottom
> 1)
4682 TexOutput(_T("\\clbrdrb\\brdrdb\\brdrw15"));
4685 if (TableData
[i
].rightBorder
)
4686 TexOutput(_T("\\clbrdrr\\brdrs\\brdrw15"));
4688 if (TableData
[i
].leftBorder
)
4689 TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15"));
4691 wxSnprintf(buf
, sizeof(buf
), _T("\\cellx%d"), currentWidth
);
4694 TexOutput(_T("\\pard\\intbl\n"));
4698 currentRowNumber
++;
4703 // TexOutput(_T("\\cell\\row\\trowd\\trgaph108\\trleft-108\n"));
4704 TexOutput(_T("\\cell\\row\\trowd\\trgaph108\n"));
4710 static int noMultiColumns
= 0;
4717 noMultiColumns
= wxAtoi(GetArgData());
4734 for (int i
= 1; i
< noMultiColumns
; i
++)
4735 TexOutput(_T("\\cell"));
4742 if (start
&& (arg_no
== 1))
4745 // TexOutput(_T("\\fi0\n"));
4747 wxNode
*node
= itemizeStack
.GetFirst();
4749 oldIndent
= ((ItemizeStruc
*)node
->GetData())->indentation
;
4751 int indentValue
= 20*ParseUnitArgument(GetArgData());
4752 int indentSize
= indentValue
+ oldIndent
;
4754 ItemizeStruc
*struc
= new ItemizeStruc(LATEX_INDENT
, indentSize
);
4755 itemizeStack
.Insert(struc
);
4757 wxSnprintf(buf
, sizeof(buf
), _T("\\tx%d\\li%d\\sa200 "), indentSize
, indentSize
);
4758 PushEnvironmentStyle(buf
);
4762 if (!start
&& (arg_no
== 2))
4764 PopEnvironmentStyle();
4765 if (itemizeStack
.GetFirst())
4767 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
4769 delete itemizeStack
.GetFirst();
4771 if (itemizeStack
.GetCount() == 0)
4773 TexOutput(_T("\\par\\pard\n"));
4774 issuedNewParagraph
= 1;
4775 WriteEnvironmentStyles();
4784 if (start && (arg_no == 1))
4787 wxNode *node = itemizeStack.GetFirst();
4789 oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
4791 int boxWidth = 20*ParseUnitArgument(GetArgData());
4793 int indentValue = (int)((CurrentTextWidth - oldIndent - boxWidth)/2.0);
4794 int indentSize = indentValue + oldIndent;
4795 int indentSizeRight = indentSize + boxWidth;
4797 ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize);
4798 itemizeStack.Insert(struc);
4800 wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\lr%d\\sa200\\box%s "), indentSize, indentSize, indentSizeRight,
4801 ((macroId == ltCENTEREDBOX) ? _T("\\brdrs") : _T("\\brdrdb")));
4802 PushEnvironmentStyle(buf);
4806 if (!start && (arg_no == 2))
4808 PopEnvironmentStyle();
4809 if (itemizeStack.GetFirst())
4811 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
4813 delete itemizeStack.GetFirst();
4815 if (itemizeStack.Number() == 0)
4817 TexOutput(_T("\\par\\pard\n"));
4818 issuedNewParagraph = 1;
4819 WriteEnvironmentStyles();
4826 case ltDOCUMENTSTYLE
:
4828 DefaultOnArgument(macroId
, arg_no
, start
);
4829 if (!start
&& !IsArgOptional())
4831 if (MinorDocumentStyleString
)
4833 if (StringMatch(_T("twoside"), MinorDocumentStyleString
))
4834 // Mirror margins, switch on odd/even headers & footers, and break sections at odd pages
4835 TexOutput(_T("\\margmirror\\facingp\\sbkodd"));
4836 if (StringMatch(_T("twocolumn"), MinorDocumentStyleString
))
4837 TexOutput(_T("\\cols2"));
4839 TexOutput(_T("\n"));
4843 case ltSETHOTSPOTCOLOUR
:
4844 case ltSETHOTSPOTCOLOR
:
4848 wxChar
*text
= GetArgData();
4849 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4850 hotSpotColour
= true;
4852 hotSpotColour
= false;
4856 case ltSETTRANSPARENCY
:
4860 wxChar
*text
= GetArgData();
4861 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4862 bitmapTransparency
= true;
4864 bitmapTransparency
= false;
4868 case ltSETHOTSPOTUNDERLINE
:
4872 wxChar
*text
= GetArgData();
4873 if (wxStrcmp(text
, _T("yes")) == 0 || wxStrcmp(text
, _T("on")) == 0 || wxStrcmp(text
, _T("ok")) == 0)
4874 hotSpotUnderline
= true;
4876 hotSpotUnderline
= false;
4882 if (arg_no
== 1 && start
)
4884 wxChar
*citeKey
= GetArgData();
4885 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
4888 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
4889 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
4890 ref
->sectionNumber
= copystring(buf
);
4893 TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line
4894 wxSnprintf(buf
, sizeof(buf
), _T("{\\b [%d]} "), citeCount
);
4899 if (arg_no
== 2 && !start
)
4900 TexOutput(_T("\\par\\pard\\par\n\n"));
4903 case ltTHEBIBLIOGRAPHY
:
4905 if (start
&& (arg_no
== 1))
4909 SetCurrentOutputs(Contents
, Chapters
);
4913 wxFprintf(Chapters
, _T("\\sect\\pgncont\\titlepg\n"));
4915 // If a non-custom page style, we generate the header now.
4916 if (PageStyle
&& (wxStrcmp(PageStyle
, _T("plain")) == 0 ||
4917 wxStrcmp(PageStyle
, _T("empty")) == 0 ||
4918 wxStrcmp(PageStyle
, _T("headings")) == 0))
4920 OutputRTFHeaderCommands();
4921 OutputRTFFooterCommands();
4924 // Need to reset the current numbering style, or RTF forgets it.
4925 OutputNumberStyle(currentNumberStyle
);
4926 SetCurrentOutput(Contents
);
4929 wxFprintf(Chapters
, _T("\\page\n"));
4932 wxFprintf(Contents
, _T("\n{\\uldb %s}"), ReferencesNameString
);
4934 wxFprintf(Contents
, _T("\\par\n\\pard{\\b %s}"), ReferencesNameString
);
4936 startedSections
= true;
4939 wxFprintf(Chapters
, _T("\n${\\footnote %s}"), ReferencesNameString
);
4941 wxChar
*topicName
= _T("bibliography");
4945 wxFprintf(Contents
, _T("{\\v %s}\\par\\pard\n"), topicName
);
4946 WriteEnvironmentStyles();
4949 wxFprintf(Contents
, _T("\\par\\par\\pard\n"));
4953 wxFprintf(Chapters
, _T("\n#{\\footnote %s}\n"), topicName
);
4954 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
4955 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ReferencesNameString
);
4956 GenerateKeywordsForTopic(topicName
);
4959 wxFprintf(Chapters
, _T("!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n"),
4960 wxFileNameFromPath(FileRoot
), "Contents");
4964 SetCurrentOutput(Chapters
);
4965 wxChar
*styleCommand
= _T("");
4966 if (!winHelp
&& useHeadingStyles
)
4967 styleCommand
= _T("\\s1");
4968 wxFprintf(Chapters
, _T("\\pard{%s"), (winHelp
? _T("\\keepn\\sa140\\sb140") : styleCommand
));
4969 WriteHeadingStyle(Chapters
, 1); wxFprintf(Chapters
, _T(" References\\par\\pard}\n"));
4978 * In Windows help, all keywords should be at the start of the
4979 * topic, but Latex \index commands can be anywhere in the text.
4980 * So we're going to have to build up lists of keywords for a topic,
4981 * and insert them on the second pass.
4983 * In linear RTF, we can embed the index entry now.
4988 // wxChar *entry = GetArgData();
4990 OutputChunkToString(GetArgChunk(), buf
);
4995 AddKeyWordForTopic(CurrentTopic
, buf
);
4998 else GenerateIndexEntry(buf
);
5011 wxChar
*name
= GetArgData();
5012 int pos
= FindColourPosition(name
);
5015 wxSnprintf(buf
, sizeof(buf
), _T("{%s%d "), ((macroId
== ltFCOL
) ? _T("\\cf") : _T("\\cb")), pos
);
5020 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
5035 if (arg_no
== 2) TexOutput(_T("}"));
5041 if (start
&& !winHelp
&& useWord
)
5043 wxChar
*s
= GetArgData();
5044 // Only insert a bookmark here if it's not just been inserted
5045 // in a section heading.
5046 if ( !CurrentTopic
|| !(wxStrcmp(CurrentTopic
, s
) == 0) )
5048 if ( (!CurrentChapterName || !(CurrentChapterName && (wxStrcmp(CurrentChapterName, s) == 0))) &&
5049 (!CurrentSectionName || !(CurrentSectionName && (wxStrcmp(CurrentSectionName, s) == 0))) &&
5050 (!CurrentSubsectionName || !(CurrentSubsectionName && (wxStrcmp(CurrentSubsectionName, s) == 0)))
5054 wxFprintf(Chapters
, _T("{\\bkmkstart %s}{\\bkmkend %s}"), s
,s
);
5061 if (start
&& useWord
&& !winHelp
)
5063 wxChar
*s
= GetArgData();
5064 wxFprintf(Chapters
, _T("{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"),
5072 inPopRefSection
= true;
5074 inPopRefSection
= false;
5077 case ltINSERTATLEVEL
:
5079 // This macro allows you to insert text at a different level
5080 // from the current level, e.g. into the Sections from within a subsubsection.
5081 if (!winHelp
& useWord
)
5083 static int currentLevelNo
= 1;
5084 static FILE* oldLevelFile
= Chapters
;
5091 oldLevelFile
= CurrentOutput1
;
5093 wxChar
*str
= GetArgData();
5094 currentLevelNo
= wxAtoi(str
);
5096 // TODO: cope with article style (no chapters)
5097 switch (currentLevelNo
)
5101 outputFile
= Chapters
;
5106 outputFile
= Sections
;
5111 outputFile
= Subsections
;
5116 outputFile
= Subsubsections
;
5126 CurrentOutput1
= outputFile
;
5142 CurrentOutput1
= oldLevelFile
;
5148 return DefaultOnArgument(macroId
, arg_no
, start
);
5160 forbidParindent
= 0;
5161 contentsLineSection
= NULL
;
5162 contentsLineValue
= NULL
;
5163 descriptionItemArg
= NULL
;
5168 tableVerticalLineLeft
= false;
5169 tableVerticalLineRight
= false;
5171 startedSections
= false;
5175 if (InputFile
&& OutputFile
)
5177 // Do some RTF-specific transformations on all the strings,
5179 Text2RTF(GetTopLevelChunk());
5181 Contents
= wxFopen(TmpContentsName
, _T("w"));
5182 Chapters
= wxFopen(_T("chapters.rtf"), _T("w"));
5185 Sections
= wxFopen(_T("sections.rtf"), _T("w"));
5186 Subsections
= wxFopen(_T("subsections.rtf"), _T("w"));
5187 Subsubsections
= wxFopen(_T("subsubsections.rtf"), _T("w"));
5188 Popups
= wxFopen(_T("popups.rtf"), _T("w"));
5189 if (winHelpContents
)
5191 WinHelpContentsFile
= wxFopen(WinHelpContentsFileName
, _T("w"));
5192 if (WinHelpContentsFile
)
5193 wxFprintf(WinHelpContentsFile
, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot
));
5196 if (!Sections
|| !Subsections
|| !Subsubsections
|| !Popups
|| (winHelpContents
&& !WinHelpContentsFile
))
5198 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5202 if (!Contents
|| !Chapters
)
5204 OnError(_T("Ouch! Could not open temporary file(s) for writing."));
5210 wxFprintf(Chapters
, _T("\n#{\\footnote Contents}\n"));
5211 wxFprintf(Chapters
, _T("${\\footnote Contents}\n"));
5212 wxFprintf(Chapters
, _T("+{\\footnote %s}\n"), GetBrowseString());
5213 wxFprintf(Chapters
, _T("K{\\footnote {K} %s}\n"), ContentsNameString
);
5214 wxFprintf(Chapters
, _T("!{\\footnote DisableButton(\"Up\")}\n"));
5218 wxFprintf(Chapters
, _T("\\titlepg\n"));
5219 wxFprintf(Contents
, _T("\\par\\pard\\pgnrestart\\sect\\titlepg"));
5222 // In WinHelp, Contents title takes font of title.
5223 // In linear RTF, same as chapter headings.
5224 wxFprintf(Contents
, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"),
5225 (winHelp
? titleFont
: chapterFont
)*2, ContentsNameString
);
5227 // By default, Swiss, 11 point.
5228 wxFprintf(Chapters
, _T("\\f2\\fs22\n"));
5230 PushEnvironmentStyle(_T("\\f2\\fs22\\sa200"));
5232 SetCurrentOutput(Chapters
);
5237 OnInform(_T("Converting..."));
5241 FILE *Header
= wxFopen(_T("header.rtf"), _T("w"));
5244 OnError(_T("Ouch! Could not open temporary file header.rtf for writing."));
5247 WriteRTFHeader(Header
);
5250 PopEnvironmentStyle();
5255 // wxFprintf(Contents, _T("\\page\n"));
5256 wxFprintf(Chapters
, _T("\\page\n"));
5257 wxFprintf(Sections
, _T("\\page\n"));
5258 wxFprintf(Subsections
, _T("\\page\n"));
5259 wxFprintf(Subsubsections
, _T("\\page\n\n"));
5260 wxFprintf(Popups
, _T("\\page\n}\n"));
5263 // TexOutput(_T("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n"));
5265 TexOutput(_T("}\n"));
5266 fclose(Contents
); Contents
= NULL
;
5267 fclose(Chapters
); Chapters
= NULL
;
5270 fclose(Sections
); Sections
= NULL
;
5271 fclose(Subsections
); Subsections
= NULL
;
5272 fclose(Subsubsections
); Subsubsections
= NULL
;
5273 fclose(Popups
); Popups
= NULL
;
5274 if (winHelpContents
)
5276 fclose(WinHelpContentsFile
); WinHelpContentsFile
= NULL
;
5282 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5284 wxConcatFiles(_T("tmp1.rtf"), _T("sections.rtf"), _T("tmp2.rtf"));
5286 wxConcatFiles(_T("tmp2.rtf"), _T("subsections.rtf"), _T("tmp3.rtf"));
5288 wxConcatFiles(_T("tmp3.rtf"), _T("subsubsections.rtf"), _T("tmp4.rtf"));
5290 wxConcatFiles(_T("tmp4.rtf"), _T("popups.rtf"), OutputFile
);
5293 wxRemoveFile(_T("tmp1.rtf"));
5294 wxRemoveFile(_T("tmp2.rtf"));
5295 wxRemoveFile(_T("tmp3.rtf"));
5296 wxRemoveFile(_T("tmp4.rtf"));
5300 wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
5302 if (wxFileExists(OutputFile
))
5303 wxRemoveFile(OutputFile
);
5306 cwdStr
= wxGetWorkingDirectory();
5308 wxString outputDirStr
;
5309 outputDirStr
= wxPathOnly(OutputFile
);
5311 // Determine if the temp file and the output file are in the same directory,
5312 // and if they are, then just rename the temp file rather than copying
5313 // it, as this is much faster when working with large (multi-megabyte files)
5314 if ((wxStrcmp(outputDirStr
.c_str(),_T("")) == 0) || // no path specified on output file
5315 (wxStrcmp(cwdStr
,outputDirStr
.c_str()) == 0)) // paths do not match
5317 wxRenameFile(_T("tmp1.rtf"), OutputFile
);
5321 wxCopyFile(_T("tmp1.rtf"), OutputFile
);
5325 wxRemoveFile(_T("tmp1.rtf"));
5328 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
5330 if (!wxRenameFile(TmpContentsName
, ContentsName
))
5332 wxCopyFile(TmpContentsName
, ContentsName
);
5333 wxRemoveFile(TmpContentsName
);
5336 wxRemoveFile(_T("chapters.rtf"));
5337 wxRemoveFile(_T("header.rtf"));
5341 wxRemoveFile(_T("sections.rtf"));
5342 wxRemoveFile(_T("subsections.rtf"));
5343 wxRemoveFile(_T("subsubsections.rtf"));
5344 wxRemoveFile(_T("popups.rtf"));
5346 if (winHelp
&& generateHPJ
)
5347 WriteHPJ(OutputFile
);