]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/Context.h
Extend endnotes support
[lyx.git] / src / tex2lyx / Context.h
1 // -*- C++ -*-
2 /**
3  * \file Context.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CONTEXT_H
13 #define CONTEXT_H
14
15 #include "tex2lyx.h"
16
17 #include <iosfwd>
18
19
20 namespace lyx {
21
22
23 /*!
24  * Small helper struct that holds font properties.
25  * The names are in LyX language, not LaTeX.
26  * We don't use Font, because it pulls in a lot of dependencies and has
27  * more strings than needed (e.g. font family error1 etc.).
28  * If more font related stuff is needed, it might be good to change to
29  * Font.
30  */
31 class TeXFont {
32 public:
33         TeXFont()
34         {
35                 init();
36         }
37         void init()
38         {
39                 size = "default";
40                 family = "default";
41                 series = "default";
42                 shape = "default";
43                 language = "english";
44         }
45         std::string size;
46         std::string family;
47         std::string series;
48         std::string shape;
49         std::string language;
50 };
51
52
53 bool operator==(TeXFont const &, TeXFont const &);
54
55
56 inline bool operator!=(TeXFont const & f1, TeXFont const & f2)
57 {
58         return !operator==(f1, f2);
59 }
60
61
62 /// Output changed font parameters if \p oldfont and \p newfont differ
63 void output_font_change(std::ostream & os, TeXFont const & oldfont,
64                         TeXFont const & newfont);
65
66
67 /*!
68  * A helper struct.
69  *
70  * Every bit of text has a corresponding context.
71  * Usage: Parsing begins with a global context. A new context is opened for
72  * every new LaTeX group, e.g. at the beginning of a new environment.
73  * The old context is used again after the group is closed.
74  *
75  * Since not all paragraph parameters in LyX have the same scoping as their
76  * LaTeX counterpart we may have to transfer context properties (e. g. the
77  * font) from and to the parent context.
78  */
79 class Context {
80 public:
81         Context(bool need_layout_,
82                 TeX2LyXDocClass const & textclass_,
83                 Layout const * layout_ = 0,
84                 Layout const * parent_layout_= 0,
85                 TeXFont const & font_ = normalfont);
86         ~Context();
87
88         /// Output a \\begin_layout if requested
89         void check_layout(std::ostream & os);
90
91         /// Output a \\end_layout if needed
92         void check_end_layout(std::ostream & os);
93
94         /// Output a \\begin_deeper if needed
95         void check_deeper(std::ostream & os);
96
97         /// Output a \\end_deeper if needed
98         void check_end_deeper(std::ostream & os);
99
100         /// dump content on stream (for debugging purpose), with
101         /// description \c desc.
102         void dump(std::ostream &, std::string const & desc = "context") const;
103
104         /// Are we just beginning a new paragraph?
105         bool atParagraphStart() const { return need_layout; }
106
107         /// Begin an item in a list environment
108         void set_item();
109
110         /// Start a new paragraph
111         void new_paragraph(std::ostream & os);
112
113         /// Add extra stuff if not already there
114         void add_extra_stuff(std::string const &);
115
116         /*!
117          *  Add paragraph-level extra stuff if not already there. This
118          *  will be reset at the next check_layout()
119          */
120         void add_par_extra_stuff(std::string const &);
121
122         /// Do we need to output some \\begin_layout command before the
123         /// next characters?
124         bool need_layout;
125         /// Do we need to output some \\end_layout command
126         bool need_end_layout;
127         /// We may need to add something after each \\begin_layout command
128         std::string extra_stuff;
129         /// We may need to add something after this \\begin_layout command
130         std::string par_extra_stuff;
131         /// We may need to add something at the beginning of a list.
132         std::string list_extra_stuff;
133         /// Stuff between list begin and first item
134         std::string list_preamble;
135         /// A LaTeXParam to be ignored in parsing.
136         std::string latexparam;
137         /// If there has been an \\begin_deeper, we'll need a matching
138         /// \\end_deeper
139         bool need_end_deeper;
140         /// If we are in an itemize-like environment, we need an \item
141         /// for each paragraph, otherwise this has to be a deeper
142         /// paragraph.
143         bool has_item;
144         /// If we are in an itemize-like environment, this marks
145         /// the text before the first \item. Typically, list
146         /// parameters (such as lengths) are adjusted here.
147         bool in_list_preamble;
148         /// we are handling a standard paragraph in an itemize-like
149         /// environment
150         bool deeper_paragraph;
151         /*!
152          * Inside of unknown environments we may not allow font and layout
153          * changes.
154          * Otherwise things like
155          * \\large\\begin{foo}\\huge bar\\end{foo}
156          * would not work.
157          */
158         bool new_layout_allowed;
159         /// May -- be converted to endash and --- to emdash?
160         bool merging_hyphens_allowed;
161         /// Did we output anything yet in any context?
162         static bool empty;
163
164         /// The textclass of the document. Could actually be a global variable
165         TeX2LyXDocClass const & textclass;
166         /// The layout of the current paragraph
167         Layout const * layout;
168         /// The layout of the outer paragraph (for environment layouts)
169         Layout const * parent_layout;
170         /// font attributes of this context
171         TeXFont font;
172         /// font attributes of normal text
173         static TeXFont normalfont;
174         /// Table rotation angle
175         int tablerotation;
176
177 private:
178         void begin_layout(std::ostream & os, Layout const * const & l);
179 };
180
181
182 } // namespace lyx
183
184 #endif