w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

preamble.c
Go to the documentation of this file.
1 /* preamble.c - Handles LaTeX commands that should only occur in the preamble.
2 
3 Copyright (C) 2001-2002 The Free Software Foundation
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 This file is available from http://sourceforge.net/projects/latex2rtf/
20 
21 Authors:
22  2001-2002 Scott Prahl
23 */
24 
25 #include <stdlib.h>
26 #include <string.h>
27 #include "main.h"
28 #include "convert.h"
29 #include "util.h"
30 #include "preamble.h"
31 #include "l2r_fonts.h"
32 #include "cfg.h"
33 #include "encode.h"
34 #include "parser.h"
35 #include "funct1.h"
36 #include "lengths.h"
37 #include "ignore.h"
38 #include "commands.h"
39 #include "counters.h"
40 #include "xref.h"
41 #include "direct.h"
42 #include "style.h"
43 
44 static bool g_preambleTwoside = FALSE;
48 
49 static char * g_preambleTitle = NULL;
50 static char * g_preambleAuthor = NULL;
51 static char * g_preambleDate = NULL;
52 static char * g_preambleEncoding = NULL;
53 
54 static char * g_preambleCFOOT = NULL;
55 static char * g_preambleLFOOT = NULL;
56 static char * g_preambleRFOOT = NULL;
57 static char * g_preambleCHEAD = NULL;
58 static char * g_preambleLHEAD = NULL;
59 static char * g_preambleRHEAD = NULL;
60 
61 static void setPaperSize(char * size);
62 static void setDocumentOptions(char *optionlist);
63 static void WriteFontHeader(void);
64 static void WriteStyleHeader(void);
65 static void WritePageSize(void);
66 
67 void
69 {
70  if (strcmp(option, "german") == 0 ||
71  strcmp(option, "ngerman") == 0 ) {
72  GermanMode = TRUE;
74  ReadLanguage("german");
75  }
76 
77  if (strcmp(option, "french") == 0 ||
78  strcmp(option, "frenchb") == 0)
79  {
80  FrenchMode = TRUE;
82  ReadLanguage("french");
83  }
84 
85  if (strcmp(option, "russian") == 0)
86  {
87  RussianMode = TRUE;
89  ReadLanguage("russian");
90  }
91 
92  if (strcmp(option, "czech") == 0)
93  {
94  CzechMode = TRUE;
96  ReadLanguage("czech");
97  g_fcharset_number=238; /* East European in RTF Specification */
99  }
100 
101 }
102 
103 void
105 {
107 
108  if (strcmp(option, "ansinew") == 0)
109  strcpy(g_charset_encoding_name, "cp1252");
110 
111  else if (strcmp(option, "applemac") == 0 ||
112  strcmp(option, "decmulti") == 0 ||
113  strcmp(option, "latin1") == 0 ||
114  strcmp(option, "latin2") == 0 ||
115  strcmp(option, "latin3") == 0 ||
116  strcmp(option, "latin4") == 0 ||
117  strcmp(option, "latin5") == 0 ||
118  strcmp(option, "latin9") == 0 ||
119  strcmp(option, "next") == 0 ||
120  strcmp(option, "cp437") == 0 ||
121  strcmp(option, "cp437de") == 0 ||
122  strcmp(option, "cp850") == 0 ||
123  strcmp(option, "cp852") == 0 ||
124  strcmp(option, "cp855") == 0 ||
125  strcmp(option, "cp865") == 0 ||
126  strcmp(option, "cp866") == 0 ||
127  strcmp(option, "cp1250") == 0 ||
128  strcmp(option, "cp1251") == 0 ||
129  strcmp(option, "cp1252") == 0 ||
130  strcmp(option, "437") == 0 ||
131  strcmp(option, "437de") == 0 ||
132  strcmp(option, "850") == 0 ||
133  strcmp(option, "852") == 0 ||
134  strcmp(option, "855") == 0 ||
135  strcmp(option, "865") == 0 ||
136  strcmp(option, "866") == 0 ||
137  strcmp(option, "1250") == 0 ||
138  strcmp(option, "1251") == 0 ||
139  strcmp(option, "1252") == 0 ||
140  strcmp(option, "maccyr") == 0 ||
141  strcmp(option, "macukr") == 0 ||
142  strcmp(option, "koi8-r") == 0 ||
143  strcmp(option, "koi8-u") == 0) {
144 
146  g_fcharset_number = 0; /* ANSI in RTF Specification */
147 
148  } else if (strcmp(option, "raw") == 0) {
150  g_fcharset_number = 255; /* OEM in RTF Specification */
151 
152  } else if (strcmp(option, "raw437") == 0 ) {
153  g_fcharset_number=254; /* IBM PC in RTF Specification */
155 
156  } else if (strcmp(option, "raw852") == 0) {
157  g_fcharset_number=255; /* Microsoft bug ... */
159 
160  } else if (strcmp(option, "raw1250") == 0 ) {
161  g_fcharset_number=238; /* East European in RTF Specification */
163 
164  } else if (strcmp(option, "raw1251") == 0 ) {
165  g_fcharset_number=204; /* Cyrillic in RTF Specification */
167 
168  } else if (strcmp(option, "raw1253") == 0 ) {
169  g_fcharset_number=161; /* Greek in RTF Specification */
171 
172  } else
173  diagnostics(WARNING__,"\n Input Encoding <%s> not supported", option);
174 }
175 
176 static void
178 {
179 int fnumber=-1;
180 
181  if (strcmp(font, "palatino") == 0)
182  fnumber = RtfFontNumber("Palatino");
183 
184  else if (strstr(font, "times") )
185  fnumber = RtfFontNumber("Times");
186 
187  else if (strstr(font, "chancery") )
188  fnumber = RtfFontNumber("Zapf Chancery");
189 
190  else if (strstr(font, "courier") )
191  fnumber = RtfFontNumber("Courier");
192 
193  else if (strstr(font, "avant") )
194  fnumber = RtfFontNumber("Avant Garde");
195 
196  else if (strstr(font, "helvet") )
197  fnumber = RtfFontNumber("Helvetica");
198 
199  else if (strstr(font, "newcen") )
200  fnumber = RtfFontNumber("New Century Schoolbook");
201 
202  else if (strstr(font, "book") )
203  fnumber = RtfFontNumber("Bookman");
204 
205  InitializeDocumentFont(fnumber, -1, -1, -1);
206  if (fnumber == -1)
207  fprintf(stderr,"\n Font Package <%s> not supported yet", font);
208 }
209 
210 static void
211 setThree(char * s, int ten, int eleven, int twelve)
212 {
213  int n = DefaultFontSize();
214 
215  if (n==20)
216  setLength(s, ten*20);
217  else if (n==22)
218  setLength(s, eleven*20);
219  else
220  setLength(s, twelve*20);
221 }
222 
223 static void
225 /******************************************************************************
226  Should also try to reset some of the other sizes at this time
227 ******************************************************************************/
228 {
229  if (strcmp(option, "landscape") == 0) {
231 
232  } else if (strcmp(option, "a4paper") == 0 ) {
233 
234  setLength("pageheight", 845*20);
235  setLength("hoffset", 0*20);
236  setThree("oddsidemargin",53,46,31);
237  setLength("headheight", 12*20);
238  setThree("textheight",598,596,592);
239  setLength("footskip", 30*20);
240  setLength("marginparpush", 5*20);
241 
242  setLength("pagewidth", 598*20);
243  setLength("voffset", 0*20);
244  setLength("topmargin", 17*20);
245  setLength("headsep", 25*20);
246  setThree("textwidth",345,360,390);
247  setLength("marginparsep", 10*20);
248  setLength("columnsep", 10*20);
249 
250  } else if (strcmp(option, "a4") == 0) {
251 
252  setLength("pageheight", 845*20);
253  setLength("hoffset", 0*20);
254  setThree("oddsidemargin",40,33,14);
255  setLength("headheight", 12*20);
256  setThree("textheight",646,637,621);
257  setLength("footskip", 30*20);
258  setLength("marginparpush", 5*20);
259 
260  setLength("pagewidth", 598*20);
261  setLength("voffset", 0*20);
262  setLength("topmargin", 0*20);
263  setLength("headsep", 25*20);
264  setThree("textwidth",361,376,412);
265  setLength("marginparsep", 10*20);
266  setLength("columnsep", 10*20);
267 
268  } else if (strcmp(option, "a4wide") == 0 ) {
269 
270  setLength("pageheight", 845*20);
271  setLength("hoffset", 0*20);
272  setThree("oddsidemargin",18,9,0);
273  setLength("headheight", 12*20);
274  setThree("textheight",621,637,621);
275  setLength("footskip", 30*20);
276  setLength("marginparpush", 5*20);
277 
278  setLength("pagewidth", 598*20);
279  setLength("voffset", 0*20);
280  setLength("topmargin", 0*20);
281  setLength("headsep", 25*20);
282  setThree("textwidth",425,443,461);
283  setLength("marginparsep", 10*20);
284  setLength("columnsep", 10*20);
285 
286  } else if (strcmp(option, "letterpaper") == 0) {
287 
288  setLength("pageheight", 795*20);
289  setLength("hoffset", 0*20);
290  setThree("oddsidemargin",62,54,39);
291  setLength("headheight", 12*20);
292  setThree("textheight",550,541,549);
293  setLength("footskip", 30*20);
294  setLength("marginparpush", 5*20);
295 
296  setLength("pagewidth", 614*20);
297  setLength("voffset", 0*20);
298  setLength("topmargin", 18*20);
299  setLength("headsep", 25*20);
300  setThree("textwidth",345,360,390);
301  setLength("marginparsep", 10*20);
302  setLength("columnsep", 10*20);
303 
304  } else if (strcmp(option, "legalpaper") == 0) {
305 
306  setLength("pageheight", 1012*20);
307  setLength("hoffset", 0*20);
308  setThree("oddsidemargin",62,54,39);
309  setLength("headheight", 12*20);
310  setThree("textheight",766,759,766);
311  setLength("footskip", 30*20);
312  setLength("marginparpush", 5*20);
313 
314  setLength("pagewidth", 614*20);
315  setLength("voffset", 0*20);
316  setLength("topmargin", 18*20);
317  setLength("headsep", 25*20);
318  setThree("textwidth",345,360,390);
319  setLength("marginparsep", 10*20);
320  setLength("columnsep", 10*20);
321 
322  } else if (strcmp(option, "a5paper") == 0) {
323 
324  setLength("pageheight", 598*20);
325  setLength("hoffset", 0*20);
326  setLength("oddsidemargin", 0*20);
327  setLength("headheight", 12*20);
328  setLength("textheight", 350*20);
329  setLength("footskip", 30*20);
330  setLength("marginparpush", 5*20);
331 
332  setLength("pagewidth", 421*20);
333  setLength("voffset", 0*20);
334  setLength("topmargin", 18*20);
335  setLength("headsep", 25*20);
336  setLength("textwidth", 276*20);
337  setLength("marginparsep", 10*20);
338  setLength("columnsep", 10*20);
339 
340  } else if (strcmp(option, "b5paper") == 0) {
341 
342  setLength("pageheight", 711*20);
343  setLength("hoffset", 0*20);
344  setLength("oddsidemargin", 0*20);
345  setLength("headheight", 12*20);
346  setLength("textheight", 460*20);
347  setLength("footskip", 30*20);
348  setLength("marginparpush", 5*20);
349 
350  setLength("pagewidth", 501*20);
351  setLength("voffset", 0*20);
352  setLength("topmargin", 19*20);
353  setLength("headsep", 25*20);
354  setLength("textwidth", 350*20);
355  setLength("marginparsep", 10*20);
356  setLength("columnsep", 10*20);
357  }
358 }
359 
360 static void
362 {
363  if (strcmp(option, "10pt") == 0){
364  InitializeDocumentFont(-1, 20, -1, -1);
365  setLength("baselineskip",12*20);
366  setLength("parindent", 15*20);
367  setLength("parskip", 0*20);
368 
369  } else if (strcmp(option, "11pt") == 0){
370  InitializeDocumentFont(-1, 22, -1, -1);
371  setLength("baselineskip",14*20);
372  setLength("parindent", 17*20);
373  setLength("parskip", 0*20);
374 
375  } else {
376  InitializeDocumentFont(-1, 24, -1, -1);
377  setLength("baselineskip",(int) 14.5*20);
378  setLength("parindent", 18*20);
379  setLength("parskip", 0*20);
380  }
381 }
382 
383 
384 static void
385 setDocumentOptions(char *optionlist)
386 /******************************************************************************
387 ******************************************************************************/
388 {
389  char *option;
390 
391  option = strtok(optionlist, ",");
392 
393  while (option) {
394 
395 /* while (*option == ' ') option++; skip leading blanks */
396  diagnostics(3, " (setDocumentOptions) option <%s>", option);
397  if (strcmp(option, "10pt" ) == 0 ||
398  strcmp(option, "11pt" ) == 0 ||
399  strcmp(option, "12pt" ) == 0)
401  else if (strcmp(option, "a4" ) == 0 ||
402  strcmp(option, "a4paper" ) == 0 ||
403  strcmp(option, "a4wide" ) == 0 ||
404  strcmp(option, "b5paper" ) == 0 ||
405  strcmp(option, "a5paper" ) == 0 ||
406  strcmp(option, "letterpaper") == 0 ||
407  strcmp(option, "landscape" ) == 0 ||
408  strcmp(option, "legalpaper" ) == 0)
410  else if (strcmp(option, "german") == 0 ||
411  strcmp(option, "spanish") == 0 ||
412  strcmp(option, "english") == 0 ||
413  strcmp(option, "russian") == 0 ||
414  strcmp(option, "czech" ) == 0 ||
415  strcmp(option, "frenchb" ) == 0 ||
416  strcmp(option, "french") == 0)
418  else if (strcmp(option, "twoside") == 0)
420  else if (strcmp(option, "twocolumn") == 0)
422  else if (strcmp(option, "titlepage") == 0)
424  else if (strcmp(option, "isolatin1") == 0)
425  setPackageInputenc("latin1");
426  else if (strcmp(option, "hyperlatex") == 0)
428  else if (strcmp(option, "apalike") == 0)
430  else if (strcmp(option, "apanat1b") == 0)
432  else if (strcmp(option, "natbib") == 0){
435  } else if (strcmp(option, "authordate") == 0 ||
436  strcmp(option, "authordate1") == 0 ||
437  strcmp(option, "authordate2") == 0 ||
438  strcmp(option, "authordate3") == 0 ||
439  strcmp(option, "authordate4") == 0 ||
440  strcmp(option, "authordate1-4") == 0 ){
441  /* PushEnvironment(AUTHORDATE_MODE);*/
443  } else if (strcmp(option, "apacite")==0 ||
444  strcmp(option, "apacitex") == 0 ) {
447  } else if (strcmp(option, "fancyhdr") == 0) {
448  diagnostics(WARNING__, "Only partial support for %s", option);
449  } else if (strcmp(option, "textcomp")==0 ||
450  strcmp(option, "fontenc")==0) {
451  /* do nothing ... but don't complain */
452  }
453  else if (strcmp(option, "color") == 0) {
454  diagnostics(WARNING__, "Color support limited to eight basic colors");
455  }
456  else if (!TryVariableIgnore(option)) {
457  diagnostics(WARNING__, "Unknown style option %s ignored", option);
458  }
459  option = strtok(NULL, ",");
460  }
461 }
462 
463 void
465 /******************************************************************************
466  purpose: parse \documentstyle[options]{format} or \documentclass[options]{format}
467  ******************************************************************************/
468 {
469  char *format, *format_with_spaces;
470  char *options,*options_with_spaces;
471 
472  options_with_spaces = getBracketParam();
473  format_with_spaces = getBraceParam();
474 
475  format = strdup_noblanks(format_with_spaces);
476  free(format_with_spaces);
477 
478  if (options_with_spaces)
479  diagnostics(4, "Documentstyle/class[%s]{%s}", options_with_spaces,format);
480  else
481  diagnostics(4, "Documentstyle/class{%s}",format);
482 
484  if (strcmp(format, "book") == 0)
486 
487  if (strcmp(format, "jbook") == 0)
489 
490  if (strcmp(format, "jsbook") == 0)
492 
493  else if (strcmp(format, "report") == 0)
495 
496  else if (strcmp(format, "jreport") == 0)
498 
499  else if (strcmp(format, "letter") == 0)
501 
502  else if (strcmp(format, "article") == 0)
504 
505  else if (strcmp(format, "jarticle") == 0)
507 
508  else if (strcmp(format, "jsarticle") == 0)
510 
511  else if (strcmp(format, "slides") == 0)
513 
514  else
515  fprintf(stderr, "\nDocument format <%s> unknown, using article format", format);
516 
517  if (options_with_spaces) {
518  options = strdup_noblanks(options_with_spaces);
519  free(options_with_spaces);
521  free(options);
522  }
523  free(format);
524 }
525 
526 void
528 /******************************************************************************
529  purpose: handle \usepackage[option]{packagename}
530 ******************************************************************************/
531 {
532  char *package,*package_with_spaces;
533  char *options,*options_with_spaces;
534 
535  options = NULL;
536  options_with_spaces = getBracketParam();
537  package_with_spaces = getBraceParam();
538  package = strdup_noblanks(package_with_spaces);
539  free(package_with_spaces);
540 
541  if (options_with_spaces){
542  options = strdup_noblanks(options_with_spaces);
543  free(options_with_spaces);
544  diagnostics(4, "Package {%s} with options [%s]", package, options);
545  } else
546  diagnostics(4, "Package {%s} with no options", package);
547 
548  if (strcmp(package, "inputenc") == 0 && options)
550 
551  else if (strcmp(package, "isolatin1") == 0)
552  setPackageInputenc("latin1");
553 
554  else if (strcmp(package, "babel") == 0) {
556 
557  } else if (strcmp(package, "german" ) == 0 ||
558  strcmp(package, "ngerman") == 0 ||
559  strcmp(package, "czech" ) == 0 ||
560  strcmp(package, "frenchb") == 0 ||
561  strcmp(package, "french") == 0)
563 
564  else if (strcmp(package, "palatino") == 0 ||
565  strcmp(package, "times") == 0 ||
566  strcmp(package, "bookman") == 0 ||
567  strcmp(package, "chancery") == 0 ||
568  strcmp(package, "courier") == 0 ||
569  strstr(package, "avant") ||
570  strstr(package, "newcen") ||
571  strstr(package, "helvet") )
573 
574  else if (strcmp(package, "natbib") == 0) {
575  if (strstr(options, "")) set_longnamesfirst();
578  } else
580 
581  if (options)
582  free(options);
583  free(package);
584 }
585 
586 void
588 /******************************************************************************
589  purpose: saves title, author or date information
590  ******************************************************************************/
591 {
592  switch (code) {
593  case TITLE_TITLE:
596  break;
597 
598  case TITLE_AUTHOR:
601  break;
602 
603  case TITLE_DATE:
606  break;
607 
608  case TITLE_TITLEPAGE:
610  break;
611  }
612 }
613 
614 void
616 /******************************************************************************
617  purpose: Creates a title page based on saved values for author, title, and date
618  ******************************************************************************/
619 {
620  char title_begin[10];
621  char author_begin[10];
622  char date_begin[10];
623 
625  snprintf(title_begin, 10, "%s%2d", "\\fs", (30 * CurrentFontSize()) / 20);
626  snprintf(author_begin, 10, "%s%2d", "\\fs", (24 * CurrentFontSize()) / 20);
627  snprintf(date_begin, 10, "%s%2d", "\\fs", (24 * CurrentFontSize()) / 20);
628 
630  fprintRTF("\n\\par\\pard\\qc {%s ", title_begin);
631  if (g_preambleTitle != NULL && strcmp(g_preambleTitle, "") != 0)
633  fprintRTF("}");
634 
635  fprintRTF("\n\\par\\qc {%s ", author_begin);
636  if (g_preambleAuthor != NULL && strcmp(g_preambleAuthor, "") != 0)
638  fprintRTF("}");
639 
640  fprintRTF("\n\\par\\qc {%s ", date_begin);
641  if (g_preambleDate != NULL && strcmp(g_preambleDate, "") != 0)
643  fprintRTF("}");
644 
645  CmdEndParagraph(0);
647 
649  fprintRTF("\\page ");
650 
652 }
653 
654 void
656 /***************************************************************************
657  purpose: catch missed \begin{document} command
658 ***************************************************************************/
659 {
660  char *cParam = getBraceParam();
661 
662  if (strcmp(cParam,"document"))
663  diagnostics(ERROR, "\\begin{%s} found before \\begin{document}. Giving up. Sorry", cParam);
664 
665  CallParamFunc(cParam, ON);
666  free(cParam);
667 }
668 
669 void
671 /******************************************************************************
672  LEG030598
673  purpose: sets centered page numbering at bottom in rtf-output
674 
675  globals : pagenumbering set to TRUE if pagenumbering is to occur, default
676  ******************************************************************************/
677 {
678  int fn = DefaultFontFamily();
680 
681  if (g_preambleTwoside) {
682  fprintRTF("\n{\\footerr");
683  fprintRTF("\\pard\\plain\\f%d\\qc",fn);
684  fprintRTF("{\\field{\\*\\fldinst PAGE}{\\fldrslt ?}}\\par}");
685  fprintRTF("\n{\\footerl");
686  fprintRTF("\\pard\\plain\\f%d\\qc",fn);
687  fprintRTF("{\\field{\\*\\fldinst PAGE}{\\fldrslt ?}}\\par}");
688  } else {
689  fprintRTF("\n{\\footer");
690  fprintRTF("\\pard\\plain\\f%d\\qc",fn);
691  fprintRTF("{\\field{\\*\\fldinst PAGE}{\\fldrslt ?}}\\par}");
692  }
693 }
694 
695 void
696 CmdPagestyle( /* @unused@ */ int code)
697 /******************************************************************************
698  * LEG030598
699  purpose: sets page numbering in rtf-output
700  parameter:
701 
702  globals : headings set to TRUE if the pagenumber is to go into the header
703  pagenumbering set to TRUE if pagenumbering is to occur- default
704 
705 Produces latex-like headers and footers.
706 Needs to be terminated for:
707 - headings chapter, section informations and page numbering
708 - myheadings page nunmbering, combined with markboth, markright.
709  ******************************************************************************/
710 {
711  static char *style = "";
712 
713  style = getBraceParam();
714  if (strcmp(style, "empty") == 0) {
715  if (pagenumbering) {
716  fprintRTF("{\\footer}");
718  }
719  } else if (strcmp(style, "plain") == 0)
720  PlainPagestyle();
721  else if (strcmp(style, "headings") == 0) {
722  headings = TRUE;
723  /* insert code to put section information in header, pagenumbering in header */
724  } else if (strcmp(style, "myheadings") == 0) {
725  headings = TRUE;
726  /*--- insert code to put empty section information in header, will be
727  provided by markboth, markright
728  pagenumbering in header */
729  } else {
730  diagnostics(WARNING__, "Unknown \\pagestyle{%s} ignored", style);
731  }
732 }
733 
734 void
736 /******************************************************************************
737  purpose: converts the \markboth and \markright Command in Header information
738  parameter: code: BOTH_SIDES, RIGHT_SIDE
739 
740  globals : twoside,
741  ******************************************************************************/
742 {
743  if (code == BOTH_SIDES) {
744  if (g_preambleTwoside) {
747  } else
748  diagnostics(WARNING__, "\\markboth used in onesided documentstyle");
749  } else
751 }
752 
753 void CmdThePage(int code)
754 /******************************************************************************
755  purpose: handles \thepage in headers and footers
756  ******************************************************************************/
757 {
758  diagnostics(4,"CmdThePage");
759 
760  fprintRTF("\\chpgn ");
761 }
762 
763 void
764 RtfHeader(int where, char *what)
765 /******************************************************************************
766  purpose: generates the header command in the rtf-output
767  parameter: where: RIGHT_SIDE, LEFT_SIDE -handed page, BOTH_SIDES
768  what: NULL - Convert from LaTeX input, else put "what" into rtf
769  output
770  ******************************************************************************/
771 {
772  int fn = TexFontNumber("Roman");
773  switch (where) {
774  case RIGHT_SIDE:
775  fprintRTF("\n{\\headerr \\pard\\plain\\f%d ",fn);
776  break;
777  case LEFT_SIDE:
778  fprintRTF("\n{\\headerl \\pard\\plain\\f%d ",fn);
779  break;
780  case BOTH_SIDES:
781  fprintRTF("\n{\\header \\pard\\plain\\f%d ",fn);
782  break;
783  default:
784  diagnostics(ERROR, "\n error -> called RtfHeader with illegal parameter\n ");
785  }
786  if (what == NULL) {
787  diagnostics(4, "Entering Convert() from RtfHeader");
788  Convert();
789  diagnostics(4, "Exiting Convert() from RtfHeader");
790  fprintRTF("}");
791  } else
792  fprintRTF("%s}", what);
793 }
794 
795 
796 void
798 /******************************************************************************
799  purpose: discard all hyphenation hints since they really only make sense when
800  used with TeX's hyphenation algorithms
801  ******************************************************************************/
802 {
803  char *hyphenparameter = getBraceParam();
804  free(hyphenparameter);
805 }
806 
807 static void
809 /****************************************************************************
810  * purpose: writes fontnumbers and styles for headers into Rtf-File
811 
812  \fcharset0: ANSI coding (codepage 1252)
813  \fcharset1: MAC coding
814  \fcharset2: PC coding (codepage 437)
815  \fcharset3: PCA coding (codepage 850)
816  \fcharset204: Cyrillic (codepage 1251)
817  \fcharset238: E. European (codepage 852, 1250)
818  ****************************************************************************/
819 {
820  int i;
821  ConfigEntryT **config_handle;
822  char *font_type, *font_name;
823  int charset;
824 
825  fprintRTF("{\\fonttbl");
826 
827  config_handle = CfgStartIterate(FONT_A);
828  i=3;
829  while ((config_handle = CfgNext(FONT_A, config_handle)) != NULL) {
830 
831  font_type = (char *)(*config_handle)->TexCommand;
832  font_name = (char *)(*config_handle)->RtfCommand;
834 
835  if (strncmp(font_name, "Symbol", 6)==0)
836  charset = 2;
837 
838  if (strncmp(font_type, "Cyrillic", 8)==0)
839  charset = 204;
840 
841  fprintRTF("{\\f%d\\fnil\\fcharset%d %s;}\n",i, charset, font_name);
842 
843  i++;
844  }
845  fprintRTF("{\\f99\\froman\\fcharset128\\fprq1{\\*\\panose 02020609040205080304}\\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9{\\*\\falt MS Mincho};}");
846  fprintRTF("}\n");
847 }
848 
849 static void
851 /****************************************************************************
852  --
853  | {\stylesheet{\fs20 \sbasedon222\snext10{keycode \shift...}
854  A---| {\s1 \ar \fs20 \sbasedon0\snext1 FLUSHRIGHT}{\s2\fi...}
855  | \sbasedon0snext2 IND:}}
856  --
857  ...
858  --
859  | \widowctrl\ftnbj\ftnrestart \sectd \linex0\endnhere
860  | \pard\plain \fs20 This is Normal style.
861  B---| \par \pard\plain \s1
862  | This is right justified. I call this style FLUSHRIGHT.
863  | \par \pard\plain \s2
864  | This is an indented paragraph. I call this style IND...
865  --
866  \par}
867  ****************************************************************************/
868 {
870  const char *rtf;
871 
872  fprintRTF("{\\stylesheet\n{\\s0\\fs%d\\snext0 Normal;}\n", CurrentFontSize());
873 
875  while ((style = CfgNext(STYLE_A, style)) != NULL) {
876  rtf = (*style)->RtfCommand;
877  diagnostics(4,"style <%s>=<%s>", (*style)->TexCommand,rtf);
878  fprintRTF("{");
879  InsertBasicStyle(rtf, TRUE);
880  fprintRTF(";}\n");
881  }
882  fprintRTF("}\n");
883 }
884 
885 static void
887 /****************************************************************************
888  \paperw<N> The paper width (the default is 12,240).
889  \paperh<N> The paper height (the default is 15,840).
890  \margl<N> The left margin (the default is 1,800).
891  \margr<N> The right margin (the default is 1,800).
892  \margt<N> The top margin (the default is 1,440).
893  \margb<N> The bottom margin (the default is 1,440).
894 
895  \facingp Facing pages (activates odd/even headers and gutters).
896  \gutter<N> The gutter width (the default is 0).
897  \margmirror Switches margin definitions on left and right pages.
898  \landscape Landscape format.
899  \pgnstart<N> The beginning page number (the default is 1).
900  \widowctrl Widow control.
901 
902  \headery<N> The header is <N> twips from the top of the page (the default is 720).
903  \footery<N> The footer is <N> twips from the bottom of the page (the default is 720).
904 ****************************************************************************/
905 {
906  int n;
907 
908  fprintRTF("\\paperw%d", getLength("pagewidth"));
909  fprintRTF("\\paperh%d", getLength("pageheight"));
910  if (g_preambleTwoside)
911  fprintRTF("\\facingp");
913  fprintRTF("\\landscape");
915  fprintRTF("\\cols2\\colsx709"); /* two columns -- space between columns 709 */
916 
917  n = getLength("hoffset") + 72*20 + getLength("oddsidemargin");
918  fprintRTF("\\margl%d", n);
919  diagnostics(4, "Writepagesize left margin =%d pt", n/20);
920  n = getLength("pagewidth") - (n + getLength("textwidth"));
921  fprintRTF("\\margr%d", n);
922  diagnostics(4, "Writepagesize right margin =%d pt", n/20);
923  n = getLength("voffset") + 72*20 + getLength("topmargin") + getLength("headheight")+getLength("headsep");
924  fprintRTF("\\margt%d", n);
925  diagnostics(4, "Writepagesize top margin =%d pt", n/20);
926  n = getLength("pageheight") - (n + getLength("textheight") + getLength("footskip"));
927  fprintRTF("\\margb%d", n);
928  diagnostics(4, "Writepagesize bottom margin =%d pt", n/20);
929 
930  fprintRTF("\\pgnstart%d", getCounter("page"));
931  fprintRTF("\\widowctrl\\qj\\ftnbj\n");
932 }
933 
934 static void
936 /****************************************************************************
937  \headerl The header is on left pages only.
938  \headerr The header is on right pages only.
939  \headerf The header is on the first page only.
940  \footerl The footer is on left pages only.
941  \footerr The footer is on right pages only.
942  \footerf The footer is on the first page only.
943 ****************************************************************************/
944 {
945 /* fprintRTF("\\ftnbj\\sectd\\linex0\\endnhere\\qj\n"); */
946 
947  int textwidth = getLength("textwidth");
948 
950  fprintRTF("{\\footer\\pard\\plain\\tqc\\tx%d\\tqr\\tx%d ", textwidth/2, textwidth);
951 
952  if (g_preambleLFOOT)
954 
955  fprintRTF("\\tab ");
956  if (g_preambleCFOOT)
958 
959  if (g_preambleRFOOT) {
960  fprintRTF("\\tab ");
962  }
963 
964  fprintRTF("\\par}\n");
965  }
966 
968  fprintRTF("{\\header\\pard\\plain\\tqc\\tx%d\\tqr\\tx%d ", textwidth/2, textwidth);
969 
970  if (g_preambleLHEAD)
972 
973  fprintRTF("\\tab ");
974  if (g_preambleCHEAD)
976 
977  if (g_preambleRHEAD) {
978  fprintRTF("\\tab ");
980  }
981 
982  fprintRTF("\\par}\n");
983  }
984 }
985 
986 void CmdHeadFoot(int code)
987 /******************************************************************************
988  purpose: performs \cfoot, \lfoot, \rfoot, \chead, \lhead, \rhead commands (fancyhdr)
989  adapted from code by Taupin in ltx2rtf
990  ******************************************************************************/
991 {
992  char *HeaderText = NULL;
993  char *AlternText = NULL;
994 
995  AlternText = getBracketParam();
996  if (AlternText) free(AlternText);
997 
998  HeaderText = getBraceParam();
999 
1000  diagnostics(4,"CmdHeadFoot code=%d <%s>",code, HeaderText);
1001  switch(code)
1002  {
1003  case CFOOT: g_preambleCFOOT = HeaderText;
1004  break;
1005  case LFOOT: g_preambleLFOOT = HeaderText;
1006  break;
1007  case RFOOT: g_preambleRFOOT = HeaderText;
1008  break;
1009  case CHEAD: g_preambleCHEAD = HeaderText;
1010  break;
1011  case LHEAD: g_preambleLHEAD = HeaderText;
1012  break;
1013  case RHEAD: g_preambleRHEAD = HeaderText;
1014  break;
1015  }
1016 
1017  if (!g_processing_preamble)
1018  WriteHeadFoot();
1019 }
1020 
1021 static void
1023 /****************************************************************************
1024  <colortbl> '{' \colortbl <colordef>+ '}'
1025  <colordef> \red ? & \green ? & \blue ? ';'
1026  ***************************************************************************/
1027 {
1028  fprintRTF("{\\colortbl;\n");
1029  fprintRTF("\\red0\\green0\\blue0;\n"); /* black */
1030  fprintRTF("\\red0\\green0\\blue255;\n"); /* blue */
1031  fprintRTF("\\red0\\green255\\blue255;\n"); /* cyan */
1032  fprintRTF("\\red0\\green255\\blue0;\n"); /* green */
1033  fprintRTF("\\red255\\green0\\blue255;\n"); /* magenta */
1034  fprintRTF("\\red255\\green0\\blue0;\n"); /* red */
1035  fprintRTF("\\red255\\green255\\blue0;\n"); /* yellow */
1036  fprintRTF("\\red255\\green255\\blue255;\n");/* white */
1037  fprintRTF("\\red0\\green0\\blue128;\n"); /* dark blue */
1038  fprintRTF("\\red0\\green128\\blue128;\n"); /* dark cyan */
1039  fprintRTF("\\red0\\green128\\blue0;\n"); /* dark green */
1040  fprintRTF("\\red128\\green0\\blue128;\n"); /* dark magenta */
1041  fprintRTF("\\red128\\green0\\blue0;\n"); /* dark red */
1042  fprintRTF("\\red128\\green128\\blue0;\n"); /* dark yellow */
1043  fprintRTF("\\red128\\green128\\blue128;\n");/* dark gray */
1044  fprintRTF("\\red192\\green192\\blue192;\n");/* light gray */
1045  fprintRTF("}\n");
1046 }
1047 
1048 static void
1050 /****************************************************************************
1051  \title The title of the document
1052  \subject The subject of the document
1053  \author The author of the document
1054  \operator The person who last made changes to the document
1055  \keywords Selected keywords for the document
1056  \comment Comments; text is ignored
1057  \version<N> The version number of the document
1058  \doccomm Comments displayed in Word's Summary Info dialog
1059 
1060 {\info {\title This is a page} {\author \'ca}}
1061  ***************************************************************************/
1062 {
1063 }
1064 
1065 void
1067 /****************************************************************************
1068 purpose: writes header info for the RTF file
1069 
1070 \rtf1 <charset> \deff? <fonttbl> <filetbl>? <colortbl>? <stylesheet>? <listtables>? <revtbl>?
1071  ****************************************************************************/
1072 {
1073  int family = DefaultFontFamily();
1074 /* int size = DefaultFontSize(); */
1075 
1076  diagnostics(4, "Writing header for RTF file");
1077 
1078 /* fprintRTF("{\\rtf1\\ansi\\fs%d\\deff%d\\deflang1024\n", size, family); */
1079  fprintRTF("{\\rtf1\\ansi\\deff%d\\deflang1024\n", family);
1080  WriteFontHeader();
1081  WriteColorTable();
1082  WriteStyleHeader();
1083  WriteInfo();
1084  WriteHeadFoot();
1085  WritePageSize();
1086 }
1087 
1088 
static void package(small_number c)
Definition: aptex-src.c:32357
void ReadLanguage(char *lang)
Definition: cfg.c:399
ConfigEntryT ** CfgStartIterate(int WhichCfg)
Definition: cfg.c:361
ConfigEntryT ** CfgNext(int WhichCfg, ConfigEntryT **last)
Definition: cfg.c:370
#define FONT_A
Definition: cfg.h:2
#define STYLE_A
Definition: cfg.h:4
#define n
Definition: t4ht.c:1290
int getCounter(char *s)
Definition: counters.c:108
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
#define free(a)
Definition: decNumber.cpp:310
#define ten(c)
Definition: decompfont.c:105
int strcmp()
Definition: coll.cpp:143
char * strcpy()
char * strtok()
void CmdEndParagraph(int code)
Definition: funct1.c:146
#define s
Definition: afcover.h:80
string family
bool TryVariableIgnore(char *command)
Definition: ignore.c:44
JCOPY_OPTION option
Definition: transupp.h:131
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
#define ERROR(string)
Definition: error.h:36
char * strstr()
void CallParamFunc(char *cCommand, int AddParam)
Definition: commands.c:773
void PushEnvironment(int code)
Definition: commands.c:812
#define FRENCH_MODE
Definition: commands.h:13
#define CZECH_MODE
Definition: commands.h:16
#define GERMAN_MODE
Definition: commands.h:12
#define HYPERLATEX
Definition: commands.h:10
#define RUSSIAN_MODE
Definition: commands.h:14
#define NATBIB_MODE
Definition: commands.h:18
#define APACITE_MODE
Definition: commands.h:17
void ConvertString(char *string)
Definition: convert.c:103
void Convert()
Definition: convert.c:182
void diagnostics(int level, char *format,...)
Definition: main.c:469
int g_document_bibstyle
Definition: main.c:93
void fprintRTF(char *format,...)
Definition: main.c:722
bool RussianMode
Definition: main.c:67
int g_fcharset_number
Definition: main.c:71
char g_charset_encoding_name[20]
Definition: main.c:70
bool GermanMode
Definition: main.c:65
bool CzechMode
Definition: main.c:68
char alignment
Definition: main.c:119
bool FrenchMode
Definition: main.c:66
bool g_document_type
Definition: main.c:92
bool pagenumbering
Definition: main.c:78
bool g_processing_preamble
Definition: main.c:81
int headings
Definition: main.c:79
#define WARNING__
Definition: main.h:32
#define CENTERED
Definition: main.h:39
#define JUSTIFIED
Definition: main.h:40
void UpdateLineNumber(char *s)
Definition: parser.c:107
void PopTrackLineNumber(void)
Definition: parser.c:86
void PushTrackLineNumber(int flag)
Definition: parser.c:73
#define fprintf
Definition: mendex.h:64
int strncmp()
#define snprintf
Definition: snprintf.c:41
int RtfFontNumber(char *Fname)
Definition: l2r_fonts.c:103
int DefaultFontFamily(void)
Definition: l2r_fonts.c:581
int DefaultFontSize(void)
Definition: l2r_fonts.c:588
void InitializeDocumentFont(int family, int size, int shape, int series)
Definition: l2r_fonts.c:560
int CurrentFontSize(void)
Definition: l2r_fonts.c:665
int TexFontNumber(char *Fname)
Definition: l2r_fonts.c:123
char * getBraceParam(void)
char * getBracketParam(void)
int getLength(char *s)
Definition: lengths.c:99
void setLength(char *s, int d)
Definition: lengths.c:84
string fn
Definition: fc-lang.py:335
static int format
Definition: pbmclean.c:15
struct const_name font_name[]
Definition: picttoppm.c:492
static int size
Definition: ppmlabel.c:24
charset
Definition: charset.h:51
Definition: inftrees.h:24
Definition: pbmfont.h:11
Definition: getopt.h:95
void InsertBasicStyle(const char *rtf, bool include_header_info)
Definition: style.c:34
#define font_type(a)
Definition: texfont.h:287
static char * g_preambleTitle
Definition: preamble.c:49
static void setPointSize(char *option)
Definition: preamble.c:361
static void setPackageFont(char *font)
Definition: preamble.c:177
static void WriteHeadFoot(void)
Definition: preamble.c:935
static void WriteFontHeader(void)
Definition: preamble.c:808
void PlainPagestyle(void)
Definition: preamble.c:670
void CmdPreambleBeginEnd(int code)
Definition: preamble.c:655
void CmdHyphenation(int code)
Definition: preamble.c:797
static char * g_preambleRHEAD
Definition: preamble.c:59
void WriteRtfHeader(void)
Definition: preamble.c:1066
void CmdThePage(int code)
Definition: preamble.c:753
static bool g_preambleTitlepage
Definition: preamble.c:46
void setPackageInputenc(char *option)
Definition: preamble.c:104
static void setDocumentOptions(char *optionlist)
Definition: preamble.c:385
static bool g_preambleLandscape
Definition: preamble.c:47
void setPackageBabel(char *option)
Definition: preamble.c:68
static char * g_preambleCHEAD
Definition: preamble.c:57
static void WriteInfo(void)
Definition: preamble.c:1049
void CmdHeadFoot(int code)
Definition: preamble.c:986
static char * g_preambleLFOOT
Definition: preamble.c:55
static char * g_preambleDate
Definition: preamble.c:51
static void setThree(char *s, int ten, int eleven, int twelve)
Definition: preamble.c:211
static void WritePageSize(void)
Definition: preamble.c:886
static void WriteStyleHeader(void)
Definition: preamble.c:850
void CmdHeader(int code)
Definition: preamble.c:735
void CmdMakeTitle(int code)
Definition: preamble.c:615
static char * g_preambleCFOOT
Definition: preamble.c:54
void RtfHeader(int where, char *what)
Definition: preamble.c:764
static char * g_preambleLHEAD
Definition: preamble.c:58
static bool g_preambleTwoside
Definition: preamble.c:44
static void setPaperSize(char *size)
Definition: preamble.c:224
static char * g_preambleRFOOT
Definition: preamble.c:56
void CmdDocumentStyle(int code)
Definition: preamble.c:464
void CmdUsepackage(int code)
Definition: preamble.c:527
static void WriteColorTable(void)
Definition: preamble.c:1022
void CmdPagestyle(int code)
Definition: preamble.c:696
static char * g_preambleEncoding
Definition: preamble.c:52
static char * g_preambleAuthor
Definition: preamble.c:50
void CmdTitle(int code)
Definition: preamble.c:587
static bool g_preambleTwocolumn
Definition: preamble.c:45
#define BOTH_SIDES
Definition: preamble.h:20
#define FORMAT_ARTICLE
Definition: preamble.h:1
#define TITLE_AUTHOR
Definition: preamble.h:8
#define CHEAD
Definition: preamble.h:16
#define TITLE_TITLE
Definition: preamble.h:7
#define CFOOT
Definition: preamble.h:12
#define TITLE_DATE
Definition: preamble.h:9
#define TITLE_TITLEPAGE
Definition: preamble.h:10
#define RHEAD
Definition: preamble.h:17
#define FORMAT_REPORT
Definition: preamble.h:2
#define FORMAT_LETTER
Definition: preamble.h:5
#define FORMAT_SLIDES
Definition: preamble.h:4
#define FORMAT_BOOK
Definition: preamble.h:3
#define RIGHT_SIDE
Definition: preamble.h:19
#define LHEAD
Definition: preamble.h:15
#define LFOOT
Definition: preamble.h:13
#define RFOOT
Definition: preamble.h:14
#define LEFT_SIDE
Definition: preamble.h:21
char * strdup_noblanks(char *s)
Definition: util.c:148
@ ON
Definition: ubidiimp.h:55
@ style
Definition: preamble.c:50
@ options
Definition: preamble.c:50
void set_longnamesfirst(void)
Definition: xref.c:60
#define BIBSTYLE_NATBIB
Definition: xref.h:18
#define BIBSTYLE_AUTHORDATE
Definition: xref.h:19
#define BIBSTYLE_APACITE
Definition: xref.h:17
#define BIBSTYLE_APALIKE
Definition: xref.h:16