]> git.lyx.org Git - features.git/blob - src/LaTeXFeatures.C
Dekel language/encoding patch + a few fixes
[features.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, LyXTextClass::size_type n)
29         : layout(n, false), params(p)
30 {
31         // packages
32         array = false;
33         color = false;
34         graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
35         graphicx = false;
36         setspace = false;
37         makeidx = false;
38         verbatim = false;
39         longtable = false;
40         algorithm = false;
41         rotating = false;
42         amssymb = false;
43         latexsym = false;
44         pifont = false;
45         subfigure = false;
46         floatflt = false;
47         url = false;
48         varioref = false;
49         prettyref = false;
50         chess = false;
51         
52         // commands
53         lyx = false;
54         lyxline = false;
55         noun = false;
56         lyxarrow = false;
57
58         // quotes
59         quotesinglbase = false;
60         quotedblbase = false;
61         guilsinglleft = false;
62         guilsinglright = false;
63         guillemotleft = false;
64         guillemotright = false;
65
66         // Math mode
67         amsstyle = false;
68         binom = false;
69         boldsymbol = false;
70     
71         // special features
72         LyXParagraphIndent = false;
73         NeedLyXFootnoteCode = false;
74         NeedLyXMinipageIndent = false;
75 }
76
77
78 void LaTeXFeatures::require(string const & name)
79 {
80         if (name == "array") {
81                 array = true;
82         } else if (name == "color") {
83                 color = true;
84         } else if (name == "graphics") {
85                 graphicx = true;
86                 graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
87         } else if (name == "setspace") {
88                 setspace = true;
89         } else if (name == "makeidx") {
90                 makeidx = true;
91         } else if (name == "verbatim") {
92                 verbatim = true;
93         } else if (name == "longtable") {
94                 longtable = true;
95         } else if (name == "algorithm") {
96                 algorithm = true;
97         } else if (name == "rotating") {
98                 rotating = true;
99         } else if (name == "amssymb") {
100                 amssymb = true;
101         } else if (name == "latexsym") {
102                 latexsym = true;
103         } else if (name == "pifont") {
104                 pifont = true;
105         } else if (name == "subfigure") {
106                 subfigure = true;
107         } else if (name == "floatflt") {
108                 floatflt = true;
109         } else if (name == "url") {
110                 url = true;
111         } else if (name == "varioref") {
112                 varioref = true;
113         } else if (name == "prettyref") {
114                 prettyref = true;
115         } else if (name == "chess") {
116                 chess = true;
117         } else if (name == "amsstyle") {
118                 amsstyle = true;
119         } else if (name == "boldsymbol") {
120                 boldsymbol = true;
121         } else if (name == "binom") {
122                 binom = true;
123         }
124 }
125
126
127 string const LaTeXFeatures::getPackages()
128 {
129         string packages;
130         LyXTextClass const & tclass =
131                 textclasslist.TextClass(params.textclass);
132
133         // array-package
134         if (array)
135                 packages += "\\usepackage{array}\n";
136
137         // color.sty
138         if (color) {
139                 if (params.graphicsDriver == "default")
140                         packages += "\\usepackage{color}\n";
141                 else
142                         packages += "\\usepackage[" 
143                                 + params.graphicsDriver + "]{color}\n";
144         }
145                 
146         // makeidx.sty
147         if (makeidx) {
148                 if (! tclass.provides(LyXTextClass::makeidx)
149                     && params.language->babel() != "french") // french provides
150                                                              // \index !
151                         packages += "\\usepackage{makeidx}\n";
152                 packages += "\\makeindex\n";
153         }
154
155         // graphicx.sty
156         if (graphicx && params.graphicsDriver != "none") {
157                 if (params.graphicsDriver == "default")
158                         packages += "\\usepackage{graphicx}\n";
159                 else
160                         packages += "\\usepackage[" 
161                                 + params.graphicsDriver + "]{graphicx}\n";
162         }
163
164         // INSET_GRAPHICS: remove this when InsetFig is thrown.
165         // graphics.sty
166         if (graphics && params.graphicsDriver != "none") {
167                 if (params.graphicsDriver == "default")
168                         packages += "\\usepackage{graphics}\n";
169                 else
170                         packages += "\\usepackage[" 
171                                 + params.graphicsDriver + "]{graphics}\n";
172         }
173
174         // verbatim.sty
175         if (verbatim)
176                 packages += "\\usepackage{verbatim}\n";
177
178         if (algorithm) {
179                 packages += "\\usepackage{algorithm}\n";
180         }
181
182         // lyxchess.sty
183         if (chess) {
184                 packages += "\\usepackage{lyxchess}\n";
185         }
186
187         // setspace.sty
188         if ((params.spacing.getSpace() != Spacing::Single
189              && !params.spacing.isDefault())
190             || setspace) {
191                 packages += "\\usepackage{setspace}\n";
192         }
193         switch (params.spacing.getSpace()) {
194         case Spacing::Default:
195         case Spacing::Single:
196                 // we dont use setspace.sty so dont print anything
197                 //packages += "\\singlespacing\n";
198                 break;
199         case Spacing::Onehalf:
200                 packages += "\\onehalfspacing\n";
201                 break;
202         case Spacing::Double:
203                 packages += "\\doublespacing\n";
204                 break;
205         case Spacing::Other:
206                 std::ostringstream value;
207                 value << params.spacing.getValue(); // setw?
208                 packages += string("\\setstretch{") 
209                           + value.str().c_str() + "}\n";
210                 break;
211         }
212
213         //longtable.sty
214         if (longtable)
215                 packages += "\\usepackage{longtable}\n";
216
217         //rotating.sty
218         if (rotating)
219                 packages += "\\usepackage{rotating}\n";
220
221         // amssymb.sty
222         if (amssymb || params.use_amsmath)
223                 packages += "\\usepackage{amssymb}\n";
224
225         // latexsym.sty
226         if (latexsym)
227                 packages += "\\usepackage{latexsym}\n";
228
229         // pifont.sty
230         if (pifont)
231                 packages += "\\usepackage{pifont}\n";
232
233         // subfigure.sty
234         if (subfigure)
235                 packages += "\\usepackage{subfigure}\n";
236
237         // floatflt.sty
238         if (floatflt)
239                 packages += "\\usepackage{floatflt}\n";
240
241         // url.sty
242         if (url && ! tclass.provides(LyXTextClass::url))
243                 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
244                             "                      {\\newcommand{\\url}{\\texttt}}\n";
245
246         // varioref.sty
247         if (varioref)
248                 packages += "\\usepackage{varioref}\n";
249
250         // prettyref.sty
251         if (prettyref)
252                 packages += "\\usepackage{prettyref}\n";
253
254         // float.sty
255         // This is not correct and needs fixing.
256         // We don't need float.sty if we only use unchanged
257         // table and figure floats. (Lgb)
258         if (!usedFloats.empty())
259                 packages += "\\usepackage{float}\n";
260         
261         packages += externalPreambles;
262
263         return packages;
264 }
265
266
267 string const LaTeXFeatures::getMacros()
268 {
269         string macros;
270
271         // always include this
272         if (true || lyx) 
273                 macros += lyx_def + '\n';
274
275         if (lyxline) 
276                 macros += lyxline_def + '\n';
277
278         if (noun) {
279                 macros += noun_def + '\n';
280         }
281
282         if (lyxarrow) {
283                 macros += lyxarrow_def + '\n';
284         }
285
286         // quotes. 
287         if (quotesinglbase)
288                 macros += quotesinglbase_def + '\n';
289         if (quotedblbase)
290                 macros += quotedblbase_def + '\n';
291         if (guilsinglleft)
292                 macros += guilsinglleft_def + '\n';
293         if (guilsinglright)
294                 macros += guilsinglright_def + '\n';
295         if (guillemotleft)
296                 macros += guillemotleft_def + '\n';
297         if (guillemotright)
298                 macros += guillemotright_def + '\n';
299     
300         // Math mode    
301         if (boldsymbol && !amsstyle)
302                 macros += boldsymbol_def + '\n';
303         if (binom && !amsstyle)
304                 macros += binom_def + '\n';
305
306         // other
307         if (NeedLyXMinipageIndent) 
308                 macros += minipageindent_def;
309         if (LyXParagraphIndent) 
310                 macros += paragraphindent_def;
311         if (NeedLyXFootnoteCode) 
312                 macros += floatingfootnote_def;
313
314         // floats
315         // Here we will output the code to create the needed float styles.
316         // We will try to do this as minimal as possible.
317         // \floatstyle{ruled}
318         // \newfloat{algorithm}{htbp}{loa}
319         // \floatname{algorithm}{Algorithm}
320         return macros;
321 }
322
323
324 string const LaTeXFeatures::getTClassPreamble()
325 {
326         // the text class specific preamble 
327         LyXTextClass const & tclass =
328                 textclasslist.TextClass(params.textclass);
329         string tcpreamble = tclass.preamble();
330
331         for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
332                 if (layout[i]) {
333                         tcpreamble += tclass[i].preamble();
334                 }
335         }
336
337         return tcpreamble;
338 }       
339
340
341 string const LaTeXFeatures::getIncludedFiles()
342 {
343         string sgmlpreamble;
344         FileMap::const_iterator end = IncludedFiles.end();
345         for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != end; ++fi)
346                 sgmlpreamble += "\n<!entity " + fi->first
347                         + " system \"" + fi->second + "\">";
348
349         return sgmlpreamble;
350 }
351
352
353 void LaTeXFeatures::showStruct() {
354         lyxerr << "LyX needs the following commands when LaTeXing:"
355                << "\n***** Packages:" << getPackages()
356                << "\n***** Macros:" << getMacros()
357                << "\n***** Textclass stuff:" << getTClassPreamble()
358                << "\n***** done." << endl;
359 }
360
361
362 BufferParams const & LaTeXFeatures::bufferParams() const
363 {
364         return params;
365 }