]> git.lyx.org Git - lyx.git/blob - src/LaTeXFeatures.C
fbee79b26905b7dbfd242bbc00e81ee6caaf68b5
[lyx.git] / src / LaTeXFeatures.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 the LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation "LaTeXFeatures.h"
16 #endif
17
18 #include "LString.h"
19 #include "debug.h"
20 #include "lyx_sty.h"
21 #include "lyxrc.h"
22 #include "LaTeXFeatures.h"
23 #include "bufferparams.h"
24 #include "layout.h"
25
26 using std::endl;
27
28 LaTeXFeatures::LaTeXFeatures(BufferParams const & p, int n)
29         : layout(n, false), params(p)
30 {
31         // packages
32         color = false;
33         graphics = false;
34         setspace = false;
35         makeidx = false;
36         verbatim = false;
37         longtable = false;
38         algorithm = false;
39         rotating = false;
40         amssymb = false;
41         latexsym = false;
42         pifont = false;
43         subfigure = false;
44         floatflt = false;
45         url = false;
46         
47         // commands
48         lyx = false;
49         lyxline = false;
50         noun = false;
51         lyxarrow = false;
52
53         // quotes
54         quotesinglbase = false;
55         quotedblbase = false;
56         guilsinglleft = false;
57         guilsinglright = false;
58         guillemotleft = false;
59         guillemotright = false;
60
61         // Math mode
62         amsstyle = false;
63         binom = false;
64         boldsymbol = false;
65     
66         // special features
67         LyXParagraphIndent = false;
68         NeedLyXFootnoteCode = false;
69         NeedLyXMinipageIndent = false;
70 }
71
72
73 string LaTeXFeatures::getPackages()
74 {
75         string packages;
76         LyXTextClass const & tclass =
77                 textclasslist.TextClass(params.textclass);
78
79         // color.sty
80         if (color) {
81                 if (params.graphicsDriver == "default")
82                         packages += "\\usepackage{color}\n";
83                 else
84                         packages += "\\usepackage[" 
85                                 + params.graphicsDriver + "]{color}\n";
86         }
87                 
88         // makeidx.sty
89         if (makeidx) {
90                 if (! tclass.provides(LyXTextClass::makeidx)
91                     && params.language != "french") // french provides
92                                                     // \index !
93                         packages += "\\usepackage{makeidx}\n";
94                 packages += "\\makeindex\n";
95         }
96
97         // graphics.sty
98         if (graphics && params.graphicsDriver != "none") {
99                 if (params.graphicsDriver == "default")
100                         packages += "\\usepackage{graphics}\n";
101                 else
102                         packages += "\\usepackage[" 
103                                 + params.graphicsDriver + "]{graphics}\n";
104         }
105
106         //verbatim.sty
107         if (verbatim)
108                 packages += "\\usepackage{verbatim}\n";
109
110         if (algorithm) {
111                 packages += "\\usepackage{algorithm}\n";
112         }
113
114         // setspace.sty
115         if ((params.spacing.getSpace() != Spacing::Single
116              && !params.spacing.isDefault())
117             || setspace) {
118                 packages += "\\usepackage{setspace}\n";
119         }
120         switch (params.spacing.getSpace()) {
121         case Spacing::Default:
122         case Spacing::Single:
123                 // we dont use setspace.sty so dont print anything
124                 //packages += "\\singlespacing\n";
125                 break;
126         case Spacing::Onehalf:
127                 packages += "\\onehalfspacing\n";
128                 break;
129         case Spacing::Double:
130                 packages += "\\doublespacing\n";
131                 break;
132         case Spacing::Other:
133 #ifdef HAVE_SSTREAM
134                 std::ostringstream value;
135 #else
136                 char val[30];
137                 ostrstream value(val, 30);
138                 
139 #endif
140                 value << params.spacing.getValue(); // setw?
141 #ifdef HAVE_SSTREAM
142                 packages += string("\\setstretch{") 
143                           + value.str().c_str() + "}\n";
144 #else
145                 value << '\0';
146                 packages += string("\\setstretch{") 
147                           + value.str() + "}\n";
148 #endif
149                 break;
150         }
151
152         //longtable.sty
153         if (longtable)
154                 packages += "\\usepackage{longtable}\n";
155
156         //rotating.sty
157         if (rotating)
158                 packages += "\\usepackage{rotating}\n";
159
160         // amssymb.sty
161         if (amssymb)
162                 packages += "\\usepackage{amssymb}\n";
163
164         // latexsym.sty
165         if (latexsym)
166                 packages += "\\usepackage{latexsym}\n";
167
168         // pifont.sty
169         if (pifont)
170                 packages += "\\usepackage{pifont}\n";
171
172         // subfigure.sty
173         if (subfigure)
174                 packages += "\\usepackage{subfigure}\n";
175
176         // floatflt.sty
177         if (floatflt)
178                 packages += "\\usepackage{floatflt}\n";
179
180         // url.sty
181         if (url && ! tclass.provides(LyXTextClass::url))
182                 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
183                             "                      {\\newcommand{\\url}{\\texttt}}\n";
184         
185         return packages;
186 }
187
188
189 string LaTeXFeatures::getMacros()
190 {
191         string macros;
192
193         // always include this
194         if (true || lyx) 
195                 macros += lyx_def + '\n';
196
197         if (lyxline) 
198                 macros += lyxline_def + '\n';
199
200         if (noun) {
201                 macros += noun_def + '\n';
202         }
203
204         if (lyxarrow) {
205                 macros += lyxarrow_def + '\n';
206         }
207
208         // quotes. 
209         if (quotesinglbase)
210                 macros += quotesinglbase_def + '\n';
211         if (quotedblbase)
212                 macros += quotedblbase_def + '\n';
213         if (guilsinglleft)
214                 macros += guilsinglleft_def + '\n';
215         if (guilsinglright)
216                 macros += guilsinglright_def + '\n';
217         if (guillemotleft)
218                 macros += guillemotleft_def + '\n';
219         if (guillemotright)
220                 macros += guillemotright_def + '\n';
221     
222         // Math mode    
223         if (boldsymbol && !amsstyle)
224                 macros += boldsymbol_def + '\n';
225         if (binom && !amsstyle)
226                 macros += binom_def + '\n';
227
228         // other
229         if (NeedLyXMinipageIndent) 
230                 macros += minipageindent_def;
231         if (LyXParagraphIndent) 
232                 macros += paragraphindent_def;
233         if (NeedLyXFootnoteCode) 
234                 macros += floatingfootnote_def;
235
236         return macros;
237 }
238
239
240 string LaTeXFeatures::getTClassPreamble()
241 {
242         // the text class specific preamble 
243         LyXTextClass const & tclass =
244                 textclasslist.TextClass(params.textclass);
245         string tcpreamble = tclass.preamble();
246
247         for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
248                 if (layout[i]) {
249                         tcpreamble += tclass[i].preamble();
250                 }
251         }
252
253         return tcpreamble;
254 }       
255
256
257 void LaTeXFeatures::showStruct() {
258         lyxerr << "LyX needs the following commands when LaTeXing:"
259                << "\n***** Packages:" << getPackages()
260                << "\n***** Macros:" << getMacros()
261                << "\n***** Textclass stuff:" << getTClassPreamble()
262                << "\n***** done." << endl;
263 }
264
265
266 BufferParams const & LaTeXFeatures::bufferParams() const
267 {
268         return params;
269 }