]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Allow \nocite again with the basic citation engine.
[lyx.git] / src / BufferParams.h
1 // -*- C++ -*-
2 /**
3  * \file BufferParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFERPARAMS_H
16 #define BUFFERPARAMS_H
17
18 #include "Citation.h"
19 #include "Format.h"
20 #include "LayoutModuleList.h"
21 #include "OutputParams.h"
22 #include "paper.h"
23
24 #include "insets/InsetQuotes.h"
25
26 #include "support/copied_ptr.h"
27
28 #include <map>
29 #include <vector>
30
31 namespace lyx {
32
33 namespace support { class FileName; }
34
35 class AuthorList;
36 class BranchList;
37 class Bullet;
38 class DocumentClass;
39 class Encoding;
40 class Font;
41 class HSpace;
42 class IndicesList;
43 class Language;
44 class LatexFeatures;
45 class LayoutFile;
46 class LayoutFileIndex;
47 class Lexer;
48 class PDFOptions;
49 class Spacing;
50 class TexRow;
51 class VSpace;
52
53 /** Buffer parameters.
54  *  This class contains all the parameters for this buffer's use. Some
55  *  work needs to be done on this class to make it nice. Now everything
56  *  is in public.
57  */
58 class BufferParams {
59 public:
60         ///
61         enum ParagraphSeparation {
62                 ///
63                 ParagraphIndentSeparation,
64                 ///
65                 ParagraphSkipSeparation
66         };
67         ///
68         BufferParams();
69
70         /// get l10n translated to the buffers language
71         docstring B_(std::string const & l10n) const;
72
73         /// read a header token, if unrecognised, return it or an unknown class name
74         std::string readToken(Lexer & lex,
75                 std::string const & token, ///< token to read.
76                 support::FileName const & filepath);
77
78         ///
79         void writeFile(std::ostream &) const;
80
81         /// check what features are implied by the buffer parameters.
82         void validate(LaTeXFeatures &) const;
83
84         /** \returns true if the babel package is used (interogates
85          *  the BufferParams, a LyXRC variable, and the document class).
86          *  This returned value can then be passed to the insets...
87          */
88         bool writeLaTeX(otexstream &, LaTeXFeatures &,
89                         support::FileName const &) const;
90
91         ///
92         void useClassDefaults();
93         ///
94         bool hasClassDefaults() const;
95
96         ///
97         HSpace const & getIndentation() const;
98         ///
99         void setIndentation(HSpace const & indent);
100         ///
101         VSpace const & getDefSkip() const;
102         ///
103         void setDefSkip(VSpace const & vs);
104
105         /** Whether paragraphs are separated by using a indent like in
106          *  articles or by using a little skip like in letters.
107          */
108         ParagraphSeparation paragraph_separation;
109         ///
110         InsetQuotes::QuoteLanguage quotes_language;
111         ///
112         InsetQuotes::QuoteTimes quotes_times;
113         ///
114         std::string fontsize;
115         /// Get the LayoutFile this document is using.
116         LayoutFile const * baseClass() const;
117         ///
118         LayoutFileIndex const & baseClassID() const;
119         /// Set the LyX layout file this document is using.
120         /// NOTE: This does not call makeDocumentClass() to update the local 
121         /// DocumentClass. That needs to be done manually.
122         /// \param filename the name of the layout file
123         bool setBaseClass(std::string const & classname);
124         /// Adds the module information to the baseClass information to
125         /// create our local DocumentClass.
126         void makeDocumentClass();
127         /// Returns the DocumentClass currently in use: the BaseClass as modified
128         /// by modules.
129         DocumentClass const & documentClass() const;
130         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
131         /// as modified by modules. 
132         DocumentClass const * documentClassPtr() const;
133         /// This bypasses the baseClass and sets the textClass directly.
134         /// Should be called with care and would be better not being here,
135         /// but it seems to be needed by CutAndPaste::putClipboard().
136         void setDocumentClass(DocumentClass const * const);
137         /// List of modules in use
138         LayoutModuleList const & getModules() const { return layout_modules_; }
139         /// List of default modules the user has removed
140         std::list<std::string> const & getRemovedModules() const 
141                         { return removed_modules_; }
142         ///
143         /// Add a module to the list of modules in use. This checks only that the
144         /// module is not already in the list, so use moduleIsCompatible first if
145         /// you want to check for compatibility.
146         /// \return true if module was successfully added.
147         bool addLayoutModule(std::string const & modName);
148         /// checks to make sure module's requriements are satisfied, that it does
149         /// not conflict with already-present modules, isn't already loaded, etc.
150         bool moduleCanBeAdded(std::string const & modName) const;
151         ///
152         void addRemovedModule(std::string const & modName) 
153                         { removed_modules_.push_back(modName); }
154         /// Clear the list
155         void clearLayoutModules() { layout_modules_.clear(); }
156         /// Clear the removed module list
157         void clearRemovedModules() { removed_modules_.clear(); }
158
159         /// returns \c true if the buffer contains a LaTeX document
160         bool isLatex() const;
161         /// returns \c true if the buffer contains a DocBook document
162         bool isDocBook() const;
163         /// returns \c true if the buffer contains a Wed document
164         bool isLiterate() const;
165
166         /// return the format of the buffer on a string
167         std::string bufferFormat() const;
168         /// return the default output format of the current backend
169         std::string getDefaultOutputFormat() const;
170         /// return the output flavor of \p format or the default
171         OutputParams::FLAVOR getOutputFlavor(
172                   std::string const format = std::string()) const;
173         ///
174         bool isExportable(std::string const & format) const;
175         ///
176         std::vector<Format const *> exportableFormats(bool only_viewable) const;
177         ///
178         bool isExportableFormat(std::string const & format) const;
179         ///
180         std::vector<std::string> backends() const;
181
182         /// List of included children (for includeonly)
183         std::list<std::string> const & getIncludedChildren() const 
184                         { return included_children_; }
185         ///
186         void addIncludedChildren(std::string const & child) 
187                         { included_children_.push_back(child); }
188         /// Clear the list of included children
189         void clearIncludedChildren() { included_children_.clear(); }
190
191         /// update aux files of unincluded children (with \includeonly)
192         bool maintain_unincluded_children;
193
194         /// returns the main font for the buffer (document)
195         Font const getFont() const;
196
197         /* these are for the PaperLayout */
198         /// the papersize
199         PAPER_SIZE papersize;
200         ///
201         PAPER_ORIENTATION orientation;
202         /// use custom margins
203         bool use_geometry;
204         ///
205         std::string paperwidth;
206         ///
207         std::string paperheight;
208         ///
209         std::string leftmargin;
210         ///
211         std::string topmargin;
212         ///
213         std::string rightmargin;
214         ///
215         std::string bottommargin;
216         ///
217         std::string headheight;
218         ///
219         std::string headsep;
220         ///
221         std::string footskip;
222         ///
223         std::string columnsep;
224
225         /* some LaTeX options */
226         /// The graphics driver
227         std::string graphics_driver;
228         /// The default output format
229         std::string default_output_format;
230         /// customized bibliography processor
231         std::string bibtex_command;
232         /// customized index processor
233         std::string index_command;
234         /// font encoding
235         std::string fontenc;
236         /// the rm font
237         std::string fonts_roman;
238         /// the sf font
239         std::string fonts_sans;
240         /// the tt font
241         std::string fonts_typewriter;
242         /// the default family (rm, sf, tt)
243         std::string fonts_default_family;
244         /// use the fonts of the OS (OpenType, True Type) directly
245         bool useNonTeXFonts;
246         /// use expert Small Caps
247         bool fonts_expert_sc;
248         /// use Old Style Figures
249         bool fonts_old_figures;
250         /// the scale factor of the sf font
251         int fonts_sans_scale;
252         /// the scale factor of the tt font
253         int fonts_typewriter_scale;
254         /// the font used by the CJK command
255         std::string fonts_cjk;
256         ///
257         Spacing & spacing();
258         Spacing const & spacing() const;
259         ///
260         int secnumdepth;
261         ///
262         int tocdepth;
263         ///
264         Language const * language;
265         /// language package
266         std::string lang_package;
267         /// BranchList:
268         BranchList & branchlist();
269         BranchList const & branchlist() const;
270         /// IndicesList:
271         IndicesList & indiceslist();
272         IndicesList const & indiceslist() const;
273         /**
274          * The input encoding for LaTeX. This can be one of
275          * - \c auto: find out the input encoding from the used languages
276          * - \c default: ditto
277          * - any encoding supported by the inputenc package
278          * The encoding of the LyX file is always utf8 and has nothing to
279          * do with this setting.
280          * The difference between \c auto and \c default is that \c auto also
281          * causes loading of the inputenc package, while \c default does not.
282          * \c default will not work unless the user takes additional measures
283          * (such as using special environments like the CJK environment from
284          * CJK.sty).
285          * \c default can be seen as an unspecified 8bit encoding, since LyX
286          * does not interpret it in any way apart from display on screen.
287          */
288         std::string inputenc;
289         /// The main encoding used by this buffer for LaTeX output.
290         /// Individual pieces of text can use different encodings.
291         Encoding const & encoding() const;
292         ///
293         std::string preamble;
294         ///
295         std::string local_layout;
296         ///
297         std::string options;
298         /// use the class options defined in the layout?
299         bool use_default_options;
300         ///
301         std::string master;
302         ///
303         bool suppress_date;
304         ///
305         std::string float_placement;
306         ///
307         unsigned int columns;
308         /// parameters for the listings package
309         std::string listings_params;
310         ///
311         PageSides sides;
312         ///
313         std::string pagestyle;
314         ///
315         RGBColor backgroundcolor;
316         ///
317         bool isbackgroundcolor;
318         ///
319         RGBColor fontcolor;
320         ///
321         bool isfontcolor;
322         ///
323         RGBColor notefontcolor;
324         ///
325         RGBColor boxbgcolor;
326         /// \param index should lie in the range 0 <= \c index <= 3.
327         Bullet & temp_bullet(size_type index);
328         Bullet const & temp_bullet(size_type index) const;
329         /// \param index should lie in the range 0 <= \c index <= 3.
330         Bullet & user_defined_bullet(size_type index);
331         Bullet const & user_defined_bullet(size_type index) const;
332
333         /// Whether to load a package such as amsmath or esint.
334         /// The enum values must not be changed (file format!)
335         enum Package {
336                 /// Don't load the package. For experts only.
337                 package_off = 0,
338                 /// Load the package if needed (recommended)
339                 package_auto = 1,
340                 /// Always load the package (e.g. if the document contains
341                 /// some ERT that needs the package)
342                 package_on = 2
343         };
344         /// Whether and how to load amsmath
345         Package use_amsmath;
346         /// Whether and how to load esint
347         Package use_esint;
348         /// Whether and how to load mhchem
349         Package use_mhchem;
350         /// Whether and how to load mathdots
351         Package use_mathdots;
352         /// Whether and how to load undertilde
353         Package use_undertilde;
354         /// Split bibliography?
355         bool use_bibtopic;
356         /// Split the index?
357         bool use_indices;
358         /// revision tracking for this buffer ?
359         bool trackChanges;
360         /** This param decides whether change tracking marks should be used
361          *  in output (irrespective of how these marks are actually defined;
362          *  for instance, they may differ for DVI and PDF generation)
363          */
364         bool outputChanges;
365         ///
366         bool compressed;
367
368         /// the author list for the document
369         AuthorList & authors();
370         AuthorList const & authors() const;
371
372         /// map of the file's author IDs to AuthorList indexes
373         typedef std::map<int, int> AuthorMap;
374         AuthorMap author_map;
375         /// the buffer's font encoding
376         std::string const font_encoding() const;
377         ///
378         std::string const dvips_options() const;
379         /** The return value of paperSizeName() depends on the
380          *  purpose for which the paper size is needed, since they
381          *  support different subsets of paper sizes.
382         */
383         enum PapersizePurpose {
384                 ///
385                 DVIPS,
386                 ///
387                 DVIPDFM,
388                 ///
389                 XDVI
390         };
391         ///
392         std::string paperSizeName(PapersizePurpose purpose) const;
393         /// set up if and how babel is called
394         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
395         /// return supported drivers for specific packages
396         docstring getGraphicsDriver(std::string const & package) const;
397         /// handle inputenc etc.
398         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
399         ///
400         std::string const parseFontName(std::string const & name) const;
401         /// set up the document fonts
402         std::string const loadFonts(std::string const & rm,
403                                      std::string const & sf, std::string const & tt,
404                                      bool const & sc, bool const & osf,
405                                      int const & sfscale, int const & ttscale,
406                                      bool const & use_nonlatexfonts,
407                                      LaTeXFeatures & features) const;
408
409         /// get the appropriate cite engine (natbib handling)
410         CiteEngine citeEngine() const;
411         ///
412         void setCiteEngine(CiteEngine const);
413
414         /// options for pdf output
415         PDFOptions & pdfoptions();
416         PDFOptions const & pdfoptions() const;
417
418         // do not change these values. we rely upon them.
419         enum MathOutput {
420                 MathML = 0,
421                 HTML = 1,
422                 Images = 2,
423                 LaTeX = 3
424         };
425         /// what to use for math output. present choices are above
426         MathOutput html_math_output;
427         /// whether to attempt to be XHTML 1.1 compliant or instead be
428         /// a little more mellow
429         bool html_be_strict;
430         ///
431         double html_math_img_scale;
432         ///
433         std::string html_latex_start;
434         ///
435         std::string html_latex_end;
436         ///
437         bool html_css_as_file;
438         /// generate output usable for reverse/forward search
439         bool output_sync;
440         /// custom LaTeX macro from user instead our own
441         std::string output_sync_macro;
442         /// use refstyle? or prettyref?
443         bool use_refstyle;
444
445         /// Return true if language could be set to lang,
446         /// otherwise return false and do not change language
447         bool setLanguage(std::string const & lang);
448
449 private:
450         ///
451         void readPreamble(Lexer &);
452         ///
453         void readLocalLayout(Lexer &);
454         ///
455         void readLanguage(Lexer &);
456         ///
457         void readGraphicsDriver(Lexer &);
458         ///
459         void readBullets(Lexer &);
460         ///
461         void readBulletsLaTeX(Lexer &);
462         ///
463         void readModules(Lexer &);
464         ///
465         void readRemovedModules(Lexer &);
466         ///
467         void readIncludeonly(Lexer &);
468         /// A cache for the default flavors
469         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
470         ///
471         mutable DefaultFlavorCache default_flavors_;
472         /// for use with natbib
473         CiteEngine cite_engine_;
474         ///
475         DocumentClass * doc_class_;
476         /// 
477         LayoutModuleList layout_modules_;
478         /// this is for modules that are required by the document class but that
479         /// the user has chosen not to use
480         std::list<std::string> removed_modules_;
481
482         /// the list of included children (for includeonly)
483         std::list<std::string> included_children_;
484
485         /** Use the Pimpl idiom to hide those member variables that would otherwise
486          *  drag in other header files.
487          */
488         class Impl;
489         class MemoryTraits {
490         public:
491                 static Impl * clone(Impl const *);
492                 static void destroy(Impl *);
493         };
494         support::copied_ptr<Impl, MemoryTraits> pimpl_;
495
496 };
497
498 } // namespace lyx
499
500 #endif