]> git.lyx.org Git - lyx.git/blob - src/LaTeXFeatures.C
white-space changes, removed definitions.h several enum changes because of this,...
[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-1999 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 extern LyXRC * lyxrc;
27
28 LaTeXFeatures::LaTeXFeatures(int n)
29         : layout(n, false)
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(BufferParams const & params)
74 {
75         string packages;
76         LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
77
78         // color.sty
79         if (color) {
80                 if (params.graphicsDriver == "default")
81                         packages += "\\usepackage{color}\n";
82                 else
83                         packages += "\\usepackage[" 
84                                 + params.graphicsDriver + "]{color}\n";
85         }
86                 
87         // makeidx.sty
88         if (makeidx) {
89                 if (! tclass.provides(LyXTextClass::makeidx)
90                     && params.language != "french") // french provides
91                                                     // \index !
92                         packages += "\\usepackage{makeidx}\n";
93                 packages += "\\makeindex\n";
94         }
95
96         // graphics.sty
97         if (graphics && params.graphicsDriver != "none") {
98                 if (params.graphicsDriver == "default")
99                         packages += "\\usepackage{graphics}\n";
100                 else
101                         packages += "\\usepackage[" 
102                                 + params.graphicsDriver + "]{graphics}\n";
103         }
104
105         //verbatim.sty
106         if (verbatim)
107                 packages += "\\usepackage{verbatim}\n";
108
109         if (algorithm) {
110                 packages += "\\usepackage{algorithm}\n";
111         }
112
113         // setspace.sty
114         if ((params.spacing.getSpace() != Spacing::Single)
115             || setspace) {
116                 packages += "\\usepackage{setspace}\n";
117         }
118         switch (params.spacing.getSpace()) {
119         case Spacing::Single:
120                 // we dont use setspace.sty so dont print anything
121                 //packages += "\\singlespacing\n";
122                 break;
123         case Spacing::Onehalf:
124                 packages += "\\onehalfspacing\n";
125                 break;
126         case Spacing::Double:
127                 packages += "\\doublespacing\n";
128                 break;
129         case Spacing::Other:
130                 char value[30];
131                 sprintf(value, "%.2f", params.spacing.getValue());
132                 packages += string("\\setstretch{") 
133                           + value + "}\n";
134                 break;
135         }
136
137         //longtable.sty
138         if (longtable)
139                 packages += "\\usepackage{longtable}\n";
140
141         //rotating.sty
142         if (rotating)
143                 packages += "\\usepackage{rotating}\n";
144
145         // amssymb.sty
146         if (amssymb)
147                 packages += "\\usepackage{amssymb}\n";
148
149         // latexsym.sty
150         if (latexsym)
151                 packages += "\\usepackage{latexsym}\n";
152
153         // pifont.sty
154         if (pifont)
155                 packages += "\\usepackage{pifont}\n";
156
157         // subfigure.sty
158         if (subfigure)
159                 packages += "\\usepackage{subfigure}\n";
160
161         // floatflt.sty
162         if (floatflt)
163                 packages += "\\usepackage{floatflt}\n";
164
165         // url.sty
166         if (url && ! tclass.provides(LyXTextClass::url))
167                 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
168                             "                      {\\newcommand{\\url}{\\texttt}}\n";
169         
170         return packages;
171 }
172
173
174 string LaTeXFeatures::getMacros(BufferParams const & /* params */)
175 {
176         string macros;
177
178         // always include this
179         if (true || lyx) 
180                 macros += lyx_def + '\n';
181
182         if (lyxline) 
183                 macros += lyxline_def + '\n';
184
185         if (noun) {
186                 macros += noun_def + '\n';
187         }
188
189         if (lyxarrow) {
190                 macros += lyxarrow_def + '\n';
191         }
192
193         // quotes. 
194         if (quotesinglbase)
195                 macros += quotesinglbase_def + '\n';
196         if (quotedblbase)
197                 macros += quotedblbase_def + '\n';
198         if (guilsinglleft)
199                 macros += guilsinglleft_def + '\n';
200         if (guilsinglright)
201                 macros += guilsinglright_def + '\n';
202         if (guillemotleft)
203                 macros += guillemotleft_def + '\n';
204         if (guillemotright)
205                 macros += guillemotright_def + '\n';
206     
207         // Math mode    
208         if (boldsymbol && !amsstyle)
209                 macros += boldsymbol_def + '\n';
210         if (binom && !amsstyle)
211                 macros += binom_def + '\n';
212
213         // other
214         if (NeedLyXMinipageIndent) 
215                 macros += minipageindent_def;
216         if (LyXParagraphIndent) 
217                 macros += paragraphindent_def;
218         if (NeedLyXFootnoteCode) 
219                 macros += floatingfootnote_def;
220
221         return macros;
222 }
223
224
225 string LaTeXFeatures::getTClassPreamble(BufferParams const & params)
226 {
227         // the text class specific preamble 
228         LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
229         string tcpreamble = tclass.preamble();
230
231         for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
232                 if (layout[i]) {
233                         tcpreamble += tclass[i].preamble();
234                 }
235         }
236
237         return tcpreamble;
238 }       
239
240
241 void LaTeXFeatures::showStruct(BufferParams & params) {
242         lyxerr << "LyX needs the following commands when LaTeXing:"
243         // packs
244                << "\n***** Packages:" << getPackages(params)
245                << "\n***** Macros:" << getMacros(params)
246                << "\n***** Textclass stuff:" << getTClassPreamble(params)
247                << "\n***** done." << endl;
248 }