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