]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Improve fix to 57615915.
[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 "DocumentClassPtr.h"
20 #include "Format.h"
21 #include "LayoutModuleList.h"
22 #include "OutputParams.h"
23 #include "paper.h"
24
25 #include "insets/InsetQuotes.h"
26
27 #include "support/copied_ptr.h"
28
29 #include <map>
30 #include <vector>
31
32 namespace lyx {
33
34 namespace support { class FileName; }
35
36 class AuthorList;
37 class BranchList;
38 class Bullet;
39 class DocumentClass;
40 class Encoding;
41 class Font;
42 class HSpace;
43 class IndicesList;
44 class Language;
45 class LatexFeatures;
46 class LayoutFile;
47 class LayoutFileIndex;
48 class Lexer;
49 class PDFOptions;
50 class Spacing;
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 &, Buffer const *) 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 (interrogates
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         std::string fontsize;
113         /// Get the LayoutFile this document is using.
114         LayoutFile const * baseClass() const;
115         ///
116         LayoutFileIndex const & baseClassID() const;
117         /// Set the LyX layout file this document is using.
118         /// NOTE: This does not call makeDocumentClass() to update the local
119         /// DocumentClass. That needs to be done manually.
120         /// \param classname: the name of the layout file
121         bool setBaseClass(std::string const & classname);
122         /// Adds the module information to the baseClass information to
123         /// create our local DocumentClass.
124         /// NOTE: This should NEVER be called externally unless one immediately goes
125         /// on to class BufferView::updateDocumentClass(). The exception, of course,
126         /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
127         /// the parameters from the active Buffer.
128         void makeDocumentClass(bool const clone = false);
129         /// Returns the DocumentClass currently in use: the BaseClass as modified
130         /// by modules.
131         DocumentClass const & documentClass() const;
132         /// \return A pointer to the DocumentClass currently in use: the BaseClass
133         /// as modified by modules.
134         DocumentClassConstPtr documentClassPtr() const;
135         /// This bypasses the baseClass and sets the textClass directly.
136         /// Should be called with care and would be better not being here,
137         /// but it seems to be needed by CutAndPaste::putClipboard().
138         void setDocumentClass(DocumentClassConstPtr);
139         /// List of modules in use
140         LayoutModuleList const & getModules() const { return layout_modules_; }
141         /// List of default modules the user has removed
142         std::list<std::string> const & getRemovedModules() const
143                         { return removed_modules_; }
144         ///
145         /// Add a module to the list of modules in use. This checks only that the
146         /// module is not already in the list, so use layoutModuleCanBeAdeed first 
147         /// if you want to check for compatibility.
148         /// \return true if module was successfully added.
149         bool addLayoutModule(std::string const & modName);
150         /// checks to make sure module's requriements are satisfied, that it does
151         /// not conflict with already-present modules, isn't already loaded, etc.
152         bool layoutModuleCanBeAdded(std::string const & modName) const;
153         /// same, but for citaton modules.
154         bool citationModuleCanBeAdded(std::string const & modName) const;
155         ///
156         void addRemovedModule(std::string const & modName)
157                         { removed_modules_.push_back(modName); }
158         /// Clear the list
159         void clearLayoutModules() { layout_modules_.clear(); }
160         /// Clear the removed module list
161         void clearRemovedModules() { removed_modules_.clear(); }
162         /// Get the local layouts
163         std::string getLocalLayout(bool) const;
164         /// Set the local layouts
165         void setLocalLayout(std::string const &, bool);
166
167         /// returns \c true if the buffer contains a LaTeX document
168         bool isLatex() const;
169         /// returns \c true if the buffer contains a DocBook document
170         bool isDocBook() const;
171         /// returns \c true if the buffer contains a Wed document
172         bool isLiterate() const;
173
174         /// return the format of the buffer on a string
175         std::string bufferFormat() const;
176         /// return the default output format of the current backend
177         std::string getDefaultOutputFormat() const;
178         /// return the output flavor of \p format or the default
179         OutputParams::FLAVOR getOutputFlavor(
180                   std::string const & format = std::string()) const;
181         ///
182         bool isExportable(std::string const & format) const;
183         ///
184         std::vector<Format const *> exportableFormats(bool only_viewable) const;
185         ///
186         bool isExportableFormat(std::string const & format) const;
187         /// the backends appropriate for use with this document.
188         /// so, e.g., latex is excluded , if we're using non-TeX fonts
189         std::vector<std::string> backends() const;
190
191         /// List of included children (for includeonly)
192         std::list<std::string> const & getIncludedChildren() const
193                         { return included_children_; }
194         ///
195         void addIncludedChildren(std::string const & child)
196                         { included_children_.push_back(child); }
197         /// Clear the list of included children
198         void clearIncludedChildren() { included_children_.clear(); }
199
200         /// update aux files of unincluded children (with \includeonly)
201         bool maintain_unincluded_children;
202
203         /// returns the main font for the buffer (document)
204         Font const getFont() const;
205
206         /// translate quote style string to enum value
207         InsetQuotes::QuoteLanguage getQuoteStyle(std::string const & qs) const;
208
209         /* these are for the PaperLayout */
210         /// the papersize
211         PAPER_SIZE papersize;
212         ///
213         PAPER_ORIENTATION orientation;
214         /// use custom margins
215         bool use_geometry;
216         ///
217         std::string paperwidth;
218         ///
219         std::string paperheight;
220         ///
221         std::string leftmargin;
222         ///
223         std::string topmargin;
224         ///
225         std::string rightmargin;
226         ///
227         std::string bottommargin;
228         ///
229         std::string headheight;
230         ///
231         std::string headsep;
232         ///
233         std::string footskip;
234         ///
235         std::string columnsep;
236
237         /* some LaTeX options */
238         /// The graphics driver
239         std::string graphics_driver;
240         /// The default output format
241         std::string default_output_format;
242         /// customized bibliography processor
243         std::string bibtex_command;
244         /// customized index processor
245         std::string index_command;
246         /// font encoding(s) requested for this document
247         std::string fontenc;
248         /// the rm font
249         std::string fonts_roman;
250         /// the sf font
251         std::string fonts_sans;
252         /// the tt font
253         std::string fonts_typewriter;
254         /// the math font
255         std::string fonts_math;
256         /// the default family (rm, sf, tt)
257         std::string fonts_default_family;
258         /// use the fonts of the OS (OpenType, True Type) directly
259         bool useNonTeXFonts;
260         /// use expert Small Caps
261         bool fonts_expert_sc;
262         /// use Old Style Figures
263         bool fonts_old_figures;
264         /// the scale factor of the sf font
265         int fonts_sans_scale;
266         /// the scale factor of the tt font
267         int fonts_typewriter_scale;
268         /// the font used by the CJK command
269         std::string fonts_cjk;
270         ///
271         Spacing & spacing();
272         Spacing const & spacing() const;
273         ///
274         int secnumdepth;
275         ///
276         int tocdepth;
277         ///
278         Language const * language;
279         /// language package
280         std::string lang_package;
281         /// BranchList:
282         BranchList & branchlist();
283         BranchList const & branchlist() const;
284         /// IndicesList:
285         IndicesList & indiceslist();
286         IndicesList const & indiceslist() const;
287         /**
288          * The LyX name of the input encoding for LaTeX. This can be one of
289          * - \c auto: find out the input encoding from the used languages
290          * - \c default: ditto
291          * - any encoding defined in the file lib/encodings
292          * The encoding of the LyX file is always utf8 and has nothing to
293          * do with this setting.
294          * The difference between \c auto and \c default is that \c auto also
295          * causes loading of the inputenc package, while \c default does not.
296          * \c default will not work unless the user takes additional measures
297          * (such as using special environments like the CJK environment from
298          * CJK.sty).
299          * \c default can be seen as an unspecified 8bit encoding, since LyX
300          * does not interpret it in any way apart from display on screen.
301          */
302         std::string inputenc;
303         /// The main encoding used by this buffer for LaTeX output.
304         /// Individual pieces of text can use different encodings.
305         Encoding const & encoding() const;
306         ///
307         std::string origin;
308         ///
309         std::string preamble;
310         ///
311         std::string options;
312         /// use the class options defined in the layout?
313         bool use_default_options;
314         ///
315         std::string master;
316         ///
317         bool suppress_date;
318         ///
319         std::string float_placement;
320         ///
321         unsigned int columns;
322         ///
323         bool justification;
324         /// parameters for the listings package
325         std::string listings_params;
326         ///
327         PageSides sides;
328         ///
329         std::string pagestyle;
330         ///
331         RGBColor backgroundcolor;
332         ///
333         bool isbackgroundcolor;
334         ///
335         RGBColor fontcolor;
336         ///
337         bool isfontcolor;
338         ///
339         RGBColor notefontcolor;
340         ///
341         RGBColor boxbgcolor;
342         /// \param index should lie in the range 0 <= \c index <= 3.
343         Bullet & temp_bullet(size_type index);
344         Bullet const & temp_bullet(size_type index) const;
345         /// \param index should lie in the range 0 <= \c index <= 3.
346         Bullet & user_defined_bullet(size_type index);
347         Bullet const & user_defined_bullet(size_type index) const;
348
349         /// Whether to load a package such as amsmath or esint.
350         /// The enum values must not be changed (file format!)
351         enum Package {
352                 /// Don't load the package. For experts only.
353                 package_off = 0,
354                 /// Load the package if needed (recommended)
355                 package_auto = 1,
356                 /// Always load the package (e.g. if the document contains
357                 /// some ERT that needs the package)
358                 package_on = 2
359         };
360         /// Whether to load a package such as amsmath or esint.
361         Package use_package(std::string const & p) const;
362         /// Set whether to load a package such as amsmath or esint.
363         void use_package(std::string const & p, Package u);
364         /// All packages that can be switched on or off
365         static std::map<std::string, std::string> const & auto_packages();
366         /// Split bibliography?
367         bool use_bibtopic;
368         /// Split the index?
369         bool use_indices;
370         /// revision tracking for this buffer ?
371         bool track_changes;
372         /** This param decides whether change tracking marks should be used
373          *  in output (irrespective of how these marks are actually defined;
374          *  for instance, they may differ for DVI and PDF generation)
375          */
376         bool output_changes;
377         ///
378         bool compressed;
379
380         /// the author list for the document
381         AuthorList & authors();
382         AuthorList const & authors() const;
383
384         /// map of the file's author IDs to AuthorList indexes
385         typedef std::map<int, int> AuthorMap;
386         AuthorMap author_map;
387         /// the buffer's active font encoding
388         std::string const font_encoding() const;
389         /// all font encodings requested by the prefs/document/main language.
390         /// This does NOT include font encodings required by secondary languages
391         std::vector<std::string> const font_encodings() const;
392
393         ///
394         std::string const dvips_options() const;
395         /** The return value of paperSizeName() depends on the
396          *  purpose for which the paper size is needed, since they
397          *  support different subsets of paper sizes.
398         */
399         enum PapersizePurpose {
400                 ///
401                 DVIPS,
402                 ///
403                 DVIPDFM,
404                 ///
405                 XDVI
406         };
407         ///
408         std::string paperSizeName(PapersizePurpose purpose) const;
409         /// set up if and how babel is called
410         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
411         /// return supported drivers for specific packages
412         docstring getGraphicsDriver(std::string const & package) const;
413         /// handle inputenc etc.
414         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
415         ///
416         std::string const parseFontName(std::string const & name) const;
417         /// set up the document fonts
418         std::string const loadFonts(LaTeXFeatures & features) const;
419
420         /// the cite engine modules
421         LayoutModuleList const & citeEngine() const
422                 { return cite_engine_; }
423         /// the type of cite engine (authoryear or numerical)
424         CiteEngineType const & citeEngineType() const
425                 { return cite_engine_type_; }
426         /// add the module to the cite engine modules
427         bool addCiteEngine(std::string const &);
428         /// add the modules to the cite engine modules
429         bool addCiteEngine(std::vector<std::string> const &);
430         /// clear the list of cite engine modules
431         void clearCiteEngine() { cite_engine_.clear(); }
432         /// set the cite engine module
433         void setCiteEngine(std::string const &);
434         /// set the cite engine modules
435         void setCiteEngine(std::vector<std::string> const &);
436         /// set the cite engine type
437         void setCiteEngineType(CiteEngineType const & engine_type)
438                 { cite_engine_type_ = engine_type; }
439
440         /// the available citation commands
441         std::vector<std::string> citeCommands() const;
442         /// the available citation styles
443         std::vector<CitationStyle> citeStyles() const;
444
445         /// the default BibTeX style file for the document
446         std::string biblio_style;
447         /// the default BibTeX style file from the TextClass
448         std::string const & defaultBiblioStyle() const;
449         /// whether the BibTeX style supports full author lists
450         bool const & fullAuthorList() const;
451
452         /// options for pdf output
453         PDFOptions & pdfoptions();
454         PDFOptions const & pdfoptions() const;
455
456         // do not change these values. we rely upon them.
457         enum MathOutput {
458                 MathML = 0,
459                 HTML = 1,
460                 Images = 2,
461                 LaTeX = 3
462         };
463         /// what to use for math output. present choices are above
464         MathOutput html_math_output;
465         /// whether to attempt to be XHTML 1.1 compliant or instead be
466         /// a little more mellow
467         bool html_be_strict;
468         ///
469         double html_math_img_scale;
470         ///
471         double display_pixel_ratio;
472         ///
473         std::string html_latex_start;
474         ///
475         std::string html_latex_end;
476         ///
477         bool html_css_as_file;
478         /// generate output usable for reverse/forward search
479         bool output_sync;
480         /// custom LaTeX macro from user instead our own
481         std::string output_sync_macro;
482         /// use refstyle? or prettyref?
483         bool use_refstyle;
484
485         /// Return true if language could be set to lang,
486         /// otherwise return false and do not change language
487         bool setLanguage(std::string const & lang);
488
489 private:
490         ///
491         void readPreamble(Lexer &);
492         ///
493         void readLocalLayout(Lexer &, bool);
494         ///
495         void readLanguage(Lexer &);
496         ///
497         void readGraphicsDriver(Lexer &);
498         ///
499         void readBullets(Lexer &);
500         ///
501         void readBulletsLaTeX(Lexer &);
502         ///
503         void readModules(Lexer &);
504         ///
505         void readRemovedModules(Lexer &);
506         ///
507         void readIncludeonly(Lexer &);
508         /// A cache for the default flavors
509         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
510         ///
511         mutable DefaultFlavorCache default_flavors_;
512         /// the cite engine modules
513         LayoutModuleList cite_engine_;
514         /// the type of cite engine (authoryear or numerical)
515         CiteEngineType cite_engine_type_;
516         ///
517         DocumentClassPtr doc_class_;
518         ///
519         LayoutModuleList layout_modules_;
520         /// this is for modules that are required by the document class but that
521         /// the user has chosen not to use
522         std::list<std::string> removed_modules_;
523         /// The local layouts without the forced ones
524         std::string local_layout_;
525         /// Forced local layouts only for reading (use getLocalLayout() instead)
526         std::string forced_local_layout_;
527
528         /// the list of included children (for includeonly)
529         std::list<std::string> included_children_;
530
531         typedef std::map<std::string, Package> PackageMap;
532         /** Whether and how to load packages like amsmath, esint, mhchem,
533          *  mathdots, stackrel, stmaryrd and undertilde.
534          */
535         PackageMap use_packages;
536
537         /** Use the Pimpl idiom to hide those member variables that would otherwise
538          *  drag in other header files.
539          */
540         class Impl;
541         class MemoryTraits {
542         public:
543                 static Impl * clone(Impl const *);
544                 static void destroy(Impl *);
545         };
546         support::copied_ptr<Impl, MemoryTraits> pimpl_;
547
548 };
549
550 } // namespace lyx
551
552 #endif