PageRenderTime 75ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wxwindows/utils/tex2rtf/src/rtfutils.cpp

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