]> git.lyx.org Git - lyx.git/blob - src/LaTeXFeatures.C
90c752cad794ec18e7398b5da3d054957b79b49d
[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
27 LaTeXFeatures::LaTeXFeatures(int n)
28         : layout(n, false)
29 {
30         // packages
31         color = false;
32         graphics = false;
33         setspace = false;
34         makeidx = false;
35         verbatim = false;
36         longtable = false;
37         algorithm = false;
38         rotating = false;
39         amssymb = false;
40         latexsym = false;
41         pifont = false;
42         subfigure = false;
43         floatflt = false;
44         url = false;
45         
46         // commands
47         lyx = false;
48         lyxline = false;
49         noun = false;
50         lyxarrow = false;
51
52         // quotes
53         quotesinglbase = false;
54         quotedblbase = false;
55         guilsinglleft = false;
56         guilsinglright = false;
57         guillemotleft = false;
58         guillemotright = false;
59
60         // Math mode
61         amsstyle = false;
62         binom = false;
63         boldsymbol = false;
64     
65         // special features
66         LyXParagraphIndent = false;
67         NeedLyXFootnoteCode = false;
68         NeedLyXMinipageIndent = false;
69 }
70
71
72 string LaTeXFeatures::getPackages(BufferParams const & params)
73 {
74         string packages;
75         LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
76
77         // color.sty
78         if (color) {
79                 if (params.graphicsDriver == "default")
80                         packages += "\\usepackage{color}\n";
81                 else
82                         packages += "\\usepackage[" 
83                                 + params.graphicsDriver + "]{color}\n";
84         }
85                 
86         // makeidx.sty
87         if (makeidx) {
88                 if (! tclass.provides(LyXTextClass::makeidx)
89                     && params.language != "french") // french provides
90                                                     // \index !
91                         packages += "\\usepackage{makeidx}\n";
92                 packages += "\\makeindex\n";
93         }
94
95         // graphics.sty
96         if (graphics && params.graphicsDriver != "none") {
97                 if (params.graphicsDriver == "default")
98                         packages += "\\usepackage{graphics}\n";
99                 else
100                         packages += "\\usepackage[" 
101                                 + params.graphicsDriver + "]{graphics}\n";
102         }
103
104         //verbatim.sty
105         if (verbatim)
106                 packages += "\\usepackage{verbatim}\n";
107
108         if (algorithm) {
109                 packages += "\\usepackage{algorithm}\n";
110         }
111
112         // setspace.sty
113         if ((params.spacing.getSpace() != Spacing::Single)
114             || setspace) {
115                 packages += "\\usepackage{setspace}\n";
116         }
117         switch (params.spacing.getSpace()) {
118         case Spacing::Single:
119                 // we dont use setspace.sty so dont print anything
120                 //packages += "\\singlespacing\n";
121                 break;
122         case Spacing::Onehalf:
123                 packages += "\\onehalfspacing\n";
124                 break;
125         case Spacing::Double:
126                 packages += "\\doublespacing\n";
127                 break;
128         case Spacing::Other:
129                 //char value[30];
130                 //sprintf(value, "%.2f", params.spacing.getValue());
131 #ifdef HAVE_SSTREAM
132                 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(BufferParams const & /* params */)
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(BufferParams const & params)
239 {
240         // the text class specific preamble 
241         LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
242         string tcpreamble = tclass.preamble();
243
244         for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
245                 if (layout[i]) {
246                         tcpreamble += tclass[i].preamble();
247                 }
248         }
249
250         return tcpreamble;
251 }       
252
253
254 void LaTeXFeatures::showStruct(BufferParams const & params) {
255         lyxerr << "LyX needs the following commands when LaTeXing:"
256         // packs
257                << "\n***** Packages:" << getPackages(params)
258                << "\n***** Macros:" << getMacros(params)
259                << "\n***** Textclass stuff:" << getTClassPreamble(params)
260                << "\n***** done." << endl;
261 }