]> git.lyx.org Git - lyx.git/blob - src/mathed/math_write.C
get rid of several friends small cleanup
[lyx.git] / src / mathed / math_write.C
1 /*
2  *  File:        math_write.h
3  *  Purpose:     Write math paragraphs in LaTeX
4  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
5  *  Created:     January 1996
6  *  Description: 
7  *
8  *  Dependencies: Xlib, XForms
9  *
10  *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
11  *
12  *   Version: 0.8beta, Mathed & Lyx project.
13  *
14  *   You are free to use and modify this code under the terms of
15  *   the GNU General Public Licence version 2 or later.
16  */
17
18 #include <config.h>
19
20 #include "LString.h"
21 #include "math_inset.h"
22 #include "math_iter.h"
23 #include "math_parser.h"
24 #include "math_parinset.h"
25 #include "mathed/support.h"
26 #include "support/lstrings.h"
27 #include "debug.h"
28
29 using std::ostream;
30 using std::endl;
31
32 extern char const * latex_mathenv[];
33
34 // quite a hack i know. Should be done with return values...
35 int number_of_newlines = 0;
36
37
38 void mathed_write(MathParInset * p, ostream & os, int * newlines,
39                   bool fragile, string const & label)
40 {
41    number_of_newlines = 0;
42    short mathed_env = p->GetType();
43
44    if (mathed_env == LM_OT_MIN) {
45            if (fragile) os << "\\protect";
46            os << "\\( "; // changed from " \\( " (Albrecht Dress)
47    } 
48    else {
49      if (mathed_env == LM_OT_PAR){
50              os << "\\[\n";
51      } else {
52              os << "\\begin{"
53                 << latex_mathenv[mathed_env]
54                 << "}";
55              if (is_multicolumn(mathed_env)) {
56                      if (mathed_env != LM_OT_ALIGNAT
57                          && mathed_env != LM_OT_ALIGNATN)
58                              os << "%";
59                      os << "{" << p->GetColumns()/2 << "}";
60              }
61              os << "\n";
62      }
63      ++number_of_newlines;
64    }
65    
66    if (!label.empty() && label[0] > ' ' && is_singlely_numbered(mathed_env)) {
67            os << "\\label{"
68               << label
69               << "}\n";
70      ++number_of_newlines;
71    }
72
73    p->Write(os, fragile);
74    
75    if (mathed_env == LM_OT_MIN){
76            if (fragile) os << "\\protect";
77            os << " \\)";
78    }
79    else if (mathed_env == LM_OT_PAR) {
80            os << "\\]\n";
81      ++number_of_newlines;
82    }
83    else {
84            os << "\n\\end{"
85               << latex_mathenv[mathed_env]
86               << "}\n";
87      number_of_newlines += 2;
88    }
89    *newlines = number_of_newlines;
90 }