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