]> git.lyx.org Git - lyx.git/blob - src/LaTeXFeatures.C
5cd875fce644936b52db7ee070652fb6f886e06e
[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             || setspace) {
117                 packages += "\\usepackage{setspace}\n";
118         }
119         switch (params.spacing.getSpace()) {
120         case Spacing::Single:
121                 // we dont use setspace.sty so dont print anything
122                 //packages += "\\singlespacing\n";
123                 break;
124         case Spacing::Onehalf:
125                 packages += "\\onehalfspacing\n";
126                 break;
127         case Spacing::Double:
128                 packages += "\\doublespacing\n";
129                 break;
130         case Spacing::Other:
131 #ifdef HAVE_SSTREAM
132                 std::ostringstream value;
133 #else
134                 char val[30];
135                 ostrstream value(val, 30);
136                 
137 #endif
138                 value << params.spacing.getValue(); // setw?
139 #ifdef HAVE_SSTREAM
140                 packages += string("\\setstretch{") 
141                           + value.str().c_str() + "}\n";
142 #else
143                 value << '\0';
144                 packages += string("\\setstretch{") 
145                           + value.str() + "}\n";
146 #endif
147                 break;
148         }
149
150         //longtable.sty
151         if (longtable)
152                 packages += "\\usepackage{longtable}\n";
153
154         //rotating.sty
155         if (rotating)
156                 packages += "\\usepackage{rotating}\n";
157
158         // amssymb.sty
159         if (amssymb)
160                 packages += "\\usepackage{amssymb}\n";
161
162         // latexsym.sty
163         if (latexsym)
164                 packages += "\\usepackage{latexsym}\n";
165
166         // pifont.sty
167         if (pifont)
168                 packages += "\\usepackage{pifont}\n";
169
170         // subfigure.sty
171         if (subfigure)
172                 packages += "\\usepackage{subfigure}\n";
173
174         // floatflt.sty
175         if (floatflt)
176                 packages += "\\usepackage{floatflt}\n";
177
178         // url.sty
179         if (url && ! tclass.provides(LyXTextClass::url))
180                 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
181                             "                      {\\newcommand{\\url}{\\texttt}}\n";
182         
183         return packages;
184 }
185
186
187 string LaTeXFeatures::getMacros()
188 {
189         string macros;
190
191         // always include this
192         if (true || lyx) 
193                 macros += lyx_def + '\n';
194
195         if (lyxline) 
196                 macros += lyxline_def + '\n';
197
198         if (noun) {
199                 macros += noun_def + '\n';
200         }
201
202         if (lyxarrow) {
203                 macros += lyxarrow_def + '\n';
204         }
205
206         // quotes. 
207         if (quotesinglbase)
208                 macros += quotesinglbase_def + '\n';
209         if (quotedblbase)
210                 macros += quotedblbase_def + '\n';
211         if (guilsinglleft)
212                 macros += guilsinglleft_def + '\n';
213         if (guilsinglright)
214                 macros += guilsinglright_def + '\n';
215         if (guillemotleft)
216                 macros += guillemotleft_def + '\n';
217         if (guillemotright)
218                 macros += guillemotright_def + '\n';
219     
220         // Math mode    
221         if (boldsymbol && !amsstyle)
222                 macros += boldsymbol_def + '\n';
223         if (binom && !amsstyle)
224                 macros += binom_def + '\n';
225
226         // other
227         if (NeedLyXMinipageIndent) 
228                 macros += minipageindent_def;
229         if (LyXParagraphIndent) 
230                 macros += paragraphindent_def;
231         if (NeedLyXFootnoteCode) 
232                 macros += floatingfootnote_def;
233
234         return macros;
235 }
236
237
238 string LaTeXFeatures::getTClassPreamble()
239 {
240         // the text class specific preamble 
241         LyXTextClass const & tclass =
242                 textclasslist.TextClass(params.textclass);
243         string tcpreamble = tclass.preamble();
244
245         for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
246                 if (layout[i]) {
247                         tcpreamble += tclass[i].preamble();
248                 }
249         }
250
251         return tcpreamble;
252 }       
253
254
255 void LaTeXFeatures::showStruct() {
256         lyxerr << "LyX needs the following commands when LaTeXing:"
257                << "\n***** Packages:" << getPackages()
258                << "\n***** Macros:" << getMacros()
259                << "\n***** Textclass stuff:" << getTClassPreamble()
260                << "\n***** done." << endl;
261 }
262
263
264 BufferParams const & LaTeXFeatures::bufferParams() const
265 {
266         return params;
267 }