]> git.lyx.org Git - lyx.git/blob - src/OutputParams.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / OutputParams.h
1 // -*- C++ -*-
2 /**
3  * \file OutputParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  *  \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef OUTPUTPARAMS_H
13 #define OUTPUTPARAMS_H
14
15
16 #include "Changes.h"
17
18 #include <memory>
19 #include <set>
20
21
22 namespace lyx {
23
24
25 class Encoding;
26 class ExportData;
27 class Font;
28 class Language;
29 class InsetArgument;
30
31
32 enum class Flavor : int {
33         DviLuaTeX,
34         LaTeX,
35         LuaTeX,
36         PdfLaTeX,
37         XeTeX,
38         DocBook5,
39         Html,
40         Text,
41         LyX
42 };
43
44 enum class CtObject : int {
45         Normal,
46         Object,
47         DisplayObject,
48         UDisplayObject,
49         OmitObject
50 };
51
52
53 class OutputParams {
54 public:
55         enum MathFlavor {
56                 NotApplicable,
57                 MathAsMathML,
58                 MathAsHTML,
59                 MathAsImages,
60                 MathAsLaTeX
61         };
62
63         enum TableCell {
64                 NO,
65                 PLAIN,
66                 ALIGNED
67         };
68
69         enum Float {
70                 NONFLOAT,
71                 MAINFLOAT,
72                 SUBFLOAT
73         };
74
75         OutputParams(Encoding const *);
76         ~OutputParams();
77
78         /** The file that we export depends occasionally on what is to
79             compile the file.
80         */
81         Flavor flavor = Flavor::LaTeX;
82         /// is it some flavor of LaTeX?
83         bool isLaTeX() const;
84         /// does this flavour support full unicode?
85         bool isFullUnicode() const;
86
87         /// Same, but for math output, which only matter is XHTML output.
88         MathFlavor math_flavor = NotApplicable;
89
90         /** Are we to write a 'nice' LaTeX file or not.
91             This essentially seems to mean whether InsetInclude, InsetGraphics
92             and InsetExternal should add the absolute path to any external
93             files or not.
94             Non-nice LaTeX also includes additional safe line breaks in order to
95             increase the precision of forward/reverse search and error reporting.
96         */
97         bool nice = false;
98
99         /** Is this a real child (i.e., compiled as a child)?
100             This depends on wherefrom we export the buffer. Even children
101             that have a master can be compiled standalone.
102         */
103         mutable bool is_child = false;
104
105         /** moving_arg == true means that the environment in which the inset
106             is typeset is a moving argument. The inset should take care about
107             fragile commands by preceding the latex with \\protect.
108         */
109         bool moving_arg = false;
110
111         /** intitle == true means that the environment in which the
112             inset is typeset is part of a title (before a \\maketitle).
113             Footnotes in such environments have moving arguments.
114         */
115         bool intitle = false;
116
117         /** need_maketitle == true means that the last layout was a title layout
118          * this is to track when \maketitle needs to be output.
119         */
120         mutable bool need_maketitle = false;
121
122         /** have_maketitle == true means that \maketitle already has been output.
123         */
124         mutable bool have_maketitle = false;
125
126         /** inbranch == true means that the environment being typeset
127             is inside an active branch inset.
128         */
129         bool inbranch = false;
130
131         /** inulemcmd > 0 means that the environment in which the
132             inset is typeset is part of a ulem or soul command (e.g., \uline,
133             \uuline, \uwave, \sout or \xout). Insets that output latex commands
134             relying on local assignments (such as \cite) should enclose such
135             commands in \mbox{} in order to avoid breakage.
136         */
137         mutable int inulemcmd = 0;
138
139         /** the font at the point where the inset is
140          *
141          * Note from lasgouttes: I have doubts on the semantics of this
142          * variable. Until this is sorted out, here are some notes on the
143          * history of local_font.
144          *
145          * A research that excludes test and assignment [*] shows that
146          * this is only used to remember language, which is a different
147          * story (and not changed by this patch). The only exception being
148          * in InsetMathHull::getCtObject and InsetMathNest::latex to
149          * support change tracking in insets, but I am not 100% sure that
150          * this is required. And historically [**] local_font used to be
151          * local_lang; it may be good to return to this simpler variable
152          * later.
153          *
154          *  [*] git grep local_font src|grep -v 'local_font [!=]*='
155          *
156          * [**] before afed118a, which improved support for InsetLine;
157          * however, since 0e7ab29f, InsetLine does not depend on the
158          * current font anymore.
159         */
160         Font const * local_font = nullptr;
161
162         /** Document language lyx name
163          */
164         std::string document_language;
165
166         /// main font encoding of the document
167         std::string main_fontenc;
168
169         /** The master language. Non-null only for child documents.
170             Note that this is not the language of the top level master, but
171             of the direct parent for nested includes.
172          */
173         mutable Language const * master_language = nullptr;
174
175         /// Active characters
176         std::string active_chars;
177
178         /** Current stream encoding. Only used for LaTeX.
179             This must be set to the document encoding (via the constructor)
180             before output starts. Afterwards it must be kept up to date for
181             each single character (\sa Paragraph::latex).
182             This does also mean that you need to set it back if you use a
183             copy (e.g. in insets): \code
184             int InsetFoo::latex(..., OutputParams const & runparams_in) const
185             {
186                 OutputParams runparams(runparams_in);
187                 runparams.inComment = true;
188                 ...
189                 InsetBla::latex(..., runparams);
190                 ...
191                 runparams_in.encoding = runparams.encoding;
192             }
193             \endcode
194          */
195         mutable Encoding const * encoding;
196
197         /** free_spacing == true means that the inset is in a free-spacing
198             paragraph.
199         */
200         bool free_spacing = false;
201
202         /** This var is set by the return value from BufferParams::writeLaTeX
203         */
204         bool use_babel = false;
205
206         /** Do we use polyglossia (instead of babel)?
207         */
208         bool use_polyglossia = false;
209
210         /** Do we use hyperref?
211         */
212         bool use_hyperref = false;
213
214         /// Do we use the CJK package?
215         bool use_CJK = false;
216
217         /** Are we generating multiple indices?
218         */
219         bool use_indices = false;
220
221         /** Are we using japanese (pLaTeX)?
222         */
223         bool use_japanese = false;
224
225         /** Customized bibtex_command
226         */
227         std::string bibtex_command;
228
229         /** Customized index_command
230         */
231         std::string index_command;
232
233         /** Hyperref driver
234         */
235         std::string hyperref_driver;
236
237         /** Line length to use with plaintext or LaTeX export.
238         */
239         size_type linelen = 0;
240
241         /** The depth of the current paragraph, set for plaintext
242          *  export and used by InsetTabular
243          */
244         int depth = 0;
245
246         /** Export data filled in by the latex(), docbook(), etc. methods.
247             This is a hack: Make it possible to add stuff to constant
248             OutputParams instances.
249         */
250         std::shared_ptr<ExportData> exportdata;
251
252         /** Store labels, index entries, etc. (in \ref post_macro)
253          *  and output them later. This is used in particular to get
254          *  labels and index entries (and potentially other fragile commands)
255          *  outside of moving arguments (bug 2154)
256          */
257         bool postpone_fragile_stuff = false;
258
259         /** Stuff to be postponed and output after the current macro
260          *  (if \ref postpone_fragile_stuff is true). Used for labels and index
261          *  entries in commands with moving arguments (\\section, \\caption etc.)
262          */
263         mutable docstring post_macro;
264
265         /** Whether we in a command that is not \\long (i.e. cannot have multiple
266          *  paragraphs)
267          */
268         mutable bool isNonLong = false;
269
270         /** Whether we are entering a display math inset.
271          *  Needed to correctly strike out deleted math in change tracking.
272          */
273         mutable bool inDisplayMath = false;
274
275         /** Whether we are leaving a display math inset.
276          *  Needed to correctly track nested ulem commands in change tracking.
277          */
278         mutable bool wasDisplayMath = false;
279
280         /** Whether we are inside a comment inset. Insets that are including
281          *  external files like InsetGraphics, InsetInclude and InsetExternal
282          *  may only write the usual output and must not attempt to do
283          *  something with the included files (e.g. copying, converting)
284          *  if this flag is true, since they may not exist.
285          */
286         bool inComment = false;
287
288         /** Whether we are inside an include inset. 
289          */
290         bool inInclude = false;
291
292         /** Whether we are inside a footnote. 
293          */
294         mutable bool inFootnote = false;
295
296         /** Whether a btUnit (for multiple biblographies) is open.
297          */
298         mutable bool openbtUnit = false;
299
300         /** Process only the children's aux files with BibTeX.
301          *  This is necessary with chapterbib.
302          */
303         bool only_childbibs = false;
304
305         /** Whether we are in a table cell.
306          *  For newline, it matters whether its content is aligned or not.
307         */
308         TableCell inTableCell = NO;
309
310         /** Whether we are inside a float or subfloat.
311          *  Needed for subfloat detection on the command line.
312          */
313         Float inFloat = NONFLOAT;
314
315         /** Whether we are inside an index inset.
316          *  ERT needs to know this, due to the active chars.
317          */
318         bool inIndexEntry = false;
319
320         /** Whether we are inside an IPA inset.
321          *  Needed for proper IPA output.
322          */
323         bool inIPA = false;
324
325         /** Whether we are inside an inset that is logically deleted.
326          *  A value > 0 indicates a deleted inset.
327         */
328         int inDeletedInset = 0;
329
330         /** The change information of the outermost logically deleted inset.
331          *  changeOfDeletedInset shall only be evaluated if inDeletedInset > 0.
332         */
333         Change changeOfDeletedInset {Change::UNCHANGED};
334
335         /** What kind of change tracking object is this?
336          * Relevant for strikeout method in output
337          */
338         mutable CtObject ctObject = CtObject::Normal;
339
340         /** allow output of only part of the top-level paragraphs
341          *  par_begin: beginning paragraph
342          */
343         mutable pit_type par_begin = 0;
344
345         /** allow output of only part of the top-level paragraphs
346          *  par_end: par_end-1 is the ending paragraph
347          *  if par_begin=par_end, output all paragraphs
348          */
349         mutable pit_type par_end = 0;
350
351         /// Id of the last paragraph before an inset
352         mutable int lastid = -1;
353
354         /// Last position in the last paragraph before an inset
355         mutable pos_type lastpos = 0;
356
357         /// is this the last paragraph in the current buffer/inset?
358         bool isLastPar = false;
359
360
361         /** whether or not to do actual file copying and image conversion
362          *  This mode will be used to preview the source code
363          */
364         bool dryrun = false;
365
366         /// whether to display output errors or not
367         bool silent = false;
368
369         /// Should we output verbatim or escape LaTeX's special chars?
370         bool pass_thru = false;
371
372         /// Should we output verbatim specific chars?
373         docstring pass_thru_chars;
374
375         /// A specific newline macro
376         std::string newlinecmd;
377
378         /// Should we output captions?
379         bool html_disable_captions = false;
380
381         /// Are we already in a paragraph?
382         bool html_in_par = false;
383
384         /// Does the present context even permit paragraphs?
385         bool html_make_pars = true;
386
387         /// Are we already in a paragraph?
388         bool docbook_in_par = false;
389
390         /// Is this element's allowMultiPar useable or not?
391         bool docbook_consider_allow_multi_par = true;
392
393         /// Does the present context even permit paragraphs?
394         bool docbook_make_pars = true;
395
396         /// Are paragraphs mandatory in this context?
397         bool docbook_force_pars = false;
398
399         /// Anchors that should not be output (LyX-side identifier, not DocBook-side).
400         std::set<docstring> docbook_anchors_to_ignore;
401
402         /// Is the current context a float (such as a table or a figure)?
403         bool docbook_in_float = false;
404
405         /// Is the current context a listing?
406         bool docbook_in_listing = false;
407
408         /// Is the current context a table?
409         bool docbook_in_table = false;
410
411         /// Should the layouts that should/must go into <info> be generated?
412         bool docbook_generate_info = true;
413
414         /// Should wrappers be ignored? Mostly useful to avoid generation of <abstract>.
415         bool docbook_ignore_wrapper = false;
416
417         /// Some parameters are output before the rest of the paragraph, they should not be generated a second time.
418         std::set<InsetArgument const *> docbook_prepended_arguments = {};
419
420         /// Some parameters are output after the rest of the paragraph, they should not be generated a second time.
421         std::set<InsetArgument const *> docbook_appended_arguments = {};
422
423         /// Are we generating this material for inclusion in a TOC-like entity?
424         bool for_toc = false;
425
426         /// Are we generating this material for inclusion in a tooltip?
427         bool for_tooltip = false;
428
429         /// Are we generating this material for use by advanced search?
430         enum Search {
431                 NoSearch = 0,
432                 SearchWithDeleted = 1,
433                 SearchWithoutDeleted = 2,
434                 SearchQuick = 4,
435                 SearchNonOutput = 8
436         };
437                 
438         inline bool find_effective(void) const { return (for_search != OutputParams::NoSearch); }
439         inline bool find_with_non_output() const { return ((for_search & OutputParams::SearchNonOutput) != 0); }
440         inline bool find_with_deleted() const { return ((for_search & OutputParams::SearchWithDeleted) != 0); }
441         inline void find_set_feature(enum Search set_) { for_search = set_; }
442         inline void find_add_feature(enum Search add_) { for_search |= add_; }
443         inline void find_clean_features(void) { for_search = OutputParams::NoSearch; }
444
445         /// Are we generating this material for instant preview?
446         bool for_preview = false;
447
448         /// Include all children notwithstanding the use of \includeonly
449         bool includeall = false;
450
451         /// Explicit output folder, if any is desired
452         std::string export_folder;
453
454         /// A postponed \\noindent (after VSpace)
455         mutable bool need_noindent = false;
456 private:
457         int for_search = NoSearch;
458 };
459
460
461 } // namespace lyx
462
463 #endif // NOT OUTPUTPARAMS_H