1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
26 #include "bufferparams.h"
27 #include "support/FileInfo.h"
28 #include "support/LAssert.h"
30 #include "LaTeXFeatures.h"
31 #include "insets/insetinclude.h"
32 #include "insets/insetbib.h"
33 #include "insets/insettext.h"
34 #include "support/filetools.h"
35 #include "lyx_gui_misc.h"
37 #include "support/lyxmanip.h"
38 #include "BufferView.h"
45 using std::lower_bound;
46 using std::upper_bound;
49 int tex_code_break_column = 72; // needs non-zero initialization. set later.
50 // this is a bad idea, but how can LyXParagraph find its buffer to get
51 // parameters? (JMarc)
52 extern BufferView * current_view;
53 extern string bibitemWidest(BufferView *);
55 // this is a minibuffer
56 static char minibuffer_char;
57 static LyXFont minibuffer_font;
58 static Inset * minibuffer_inset;
61 // Initialization of the counter for the paragraph id's,
62 // declared in lyxparagraph.h
63 unsigned int LyXParagraph::paragraph_id = 0;
66 LyXParagraph::LyXParagraph()
68 text.reserve(500); // is this number too big?
70 for (int i = 0; i < 10; ++i) setCounter(i , 0);
77 footnoteflag = LyXParagraph::NO_FOOTNOTE;
78 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
80 align = LYX_ALIGN_BLOCK;
83 /* table stuff -- begin*/
85 /* table stuff -- end*/
89 bibkey = 0; // ale970302
94 // This konstruktor inserts the new paragraph in a list.
95 LyXParagraph::LyXParagraph(LyXParagraph * par)
98 par->text.resize(par->text.size());
100 for (int i = 0; i < 10; ++i) setCounter(i, 0);
104 // double linked list begin
107 next->previous = this;
109 previous->next = this;
112 footnoteflag = LyXParagraph::NO_FOOTNOTE;
113 footnotekind = LyXParagraph::FOOTNOTE;
116 /* table stuff -- begin*/
118 /* table stuff -- end*/
121 id_ = paragraph_id++;
123 bibkey = 0; // ale970302
129 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
130 BufferParams const & params,
131 char footflag, char dth) const
135 footnoteflag != LyXParagraph::NO_FOOTNOTE ||
137 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
142 // The beginning or the end of a footnote environment?
143 if (footflag != footnoteflag) {
144 footflag = footnoteflag;
146 os << "\n\\begin_float "
147 << string_footnotekinds[footnotekind]
150 os << "\n\\end_float ";
154 // The beginning or end of a deeper (i.e. nested) area?
157 while (depth > dth) {
158 os << "\n\\begin_deeper ";
162 while (depth < dth) {
163 os << "\n\\end_deeper ";
169 // First write the layout
171 << textclasslist.NameOfLayout(params.textclass, layout)
174 // Maybe some vertical spaces.
175 if (added_space_top.kind() != VSpace::NONE)
176 os << "\\added_space_top "
177 << added_space_top.asLyXCommand() << " ";
178 if (added_space_bottom.kind() != VSpace::NONE)
179 os << "\\added_space_bottom "
180 << added_space_bottom.asLyXCommand() << " ";
182 // Maybe the paragraph has special spacing
183 spacing.writeFile(os, true);
185 // The labelwidth string used in lists.
186 if (!labelwidthstring.empty())
187 os << "\\labelwidthstring "
188 << labelwidthstring << '\n';
190 // Lines above or below?
194 os << "\\line_bottom ";
196 // Pagebreaks above or below?
198 os << "\\pagebreak_top ";
199 if (pagebreak_bottom)
200 os << "\\pagebreak_bottom ";
202 // Start of appendix?
203 if (start_of_appendix)
204 os << "\\start_of_appendix ";
211 if (align != LYX_ALIGN_LAYOUT) {
214 case LYX_ALIGN_LEFT: h = 1; break;
215 case LYX_ALIGN_RIGHT: h = 2; break;
216 case LYX_ALIGN_CENTER: h = 3; break;
217 default: h = 0; break;
219 os << "\\align " << string_align[h] << " ";
221 if (pextra_type != PEXTRA_NONE) {
222 os << "\\pextra_type " << pextra_type;
223 if (pextra_type == PEXTRA_MINIPAGE) {
224 os << " \\pextra_alignment "
227 os << " \\pextra_hfill "
229 if (pextra_start_minipage)
230 os << " \\pextra_start_minipage "
231 << pextra_start_minipage;
233 if (!pextra_width.empty()) {
234 os << " \\pextra_width "
235 << VSpace(pextra_width).asLyXCommand();
236 } else if (!pextra_widthp.empty()) {
237 os << " \\pextra_widthp "
244 // Dummy layout. This means that a footnote ended.
245 os << "\n\\end_float ";
246 footflag = LyXParagraph::NO_FOOTNOTE;
250 // It might be a table.
252 os << "\\LyXTable\n";
258 bibkey->Write(buf, os);
260 LyXFont font1(LyXFont::ALL_INHERIT, params.language_info);
263 for (size_type i = 0; i < size(); ++i) {
269 // Write font changes
270 LyXFont font2 = GetFontSettings(params, i);
271 if (font2 != font1) {
272 font2.lyxWriteChanges(font1, os);
277 value_type c = GetChar(i);
281 Inset const * inset = GetInset(i);
283 if (inset->DirectWrite()) {
284 // international char, let it write
285 // code directly so it's shorter in
287 inset->Write(buf, os);
289 os << "\n\\begin_inset ";
290 inset->Write(buf, os);
291 os << "\n\\end_inset \n\n";
297 os << "\n\\newline \n";
301 os << "\n\\hfill \n";
305 os << "\n\\backslash \n";
309 if (i + 1 < size() && GetChar(i + 1) == ' ') {
316 if ((column > 70 && c == ' ')
321 // this check is to amend a bug. LyX sometimes
322 // inserts '\0' this could cause problems.
326 lyxerr << "ERROR (LyXParagraph::writeFile):"
327 " NULL char in structure." << endl;
333 // now write the next paragraph
335 next->writeFile(buf, os, params, footflag, dth);
339 void LyXParagraph::validate(LaTeXFeatures & features) const
341 BufferParams const & params = features.bufferParams();
344 // this will be useful later
345 LyXLayout const & layout =
346 textclasslist.Style(params.textclass,
351 if (line_top || line_bottom)
352 features.lyxline = true;
353 if (!spacing.isDefault())
354 features.setspace = true;
357 features.layout[GetLayout()] = true;
360 Language const * doc_language = params.language_info;
362 for (FontList::const_iterator cit = fontlist.begin();
363 cit != fontlist.end(); ++cit) {
364 if ((*cit).font.noun() == LyXFont::ON) {
365 lyxerr[Debug::LATEX] << "font.noun: "
366 << (*cit).font.noun()
368 features.noun = true;
369 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
370 << (*cit).font.stateText(0)
373 switch ((*cit).font.color()) {
375 case LColor::inherit:
379 features.color = true;
380 lyxerr[Debug::LATEX] << "Color enabled. Font: "
381 << (*cit).font.stateText(0)
385 Language const * language = (*cit).font.language();
386 if (language != doc_language) {
387 features.UsedLanguages.insert(language);
388 lyxerr[Debug::LATEX] << "Found language "
389 << language->lang() << endl;
394 for (InsetList::const_iterator cit = insetlist.begin();
395 cit != insetlist.end(); ++cit) {
397 (*cit).inset->Validate(features);
401 if (table && table->IsLongTable())
402 features.longtable = true;
404 if (pextra_type == PEXTRA_INDENT)
405 features.LyXParagraphIndent = true;
406 if (pextra_type == PEXTRA_FLOATFLT)
407 features.floatflt = true;
409 if (layout.needprotect
410 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
411 features.NeedLyXFootnoteCode = true;
413 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
414 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
415 features.NeedLyXMinipageIndent = true;
417 if (table && table->NeedRotating())
418 features.rotating = true;
421 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
422 features.algorithm = true;
427 // First few functions needed for cut and paste and paragraph breaking.
428 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
429 LyXParagraph::size_type pos) const
431 minibuffer_char = GetChar(pos);
432 minibuffer_font = GetFontSettings(bparams, pos);
433 minibuffer_inset = 0;
434 if (minibuffer_char == LyXParagraph::META_INSET) {
436 minibuffer_inset = GetInset(pos)->Clone();
438 minibuffer_inset = 0;
439 minibuffer_char = ' ';
440 // This reflects what GetInset() does (ARRae)
446 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
447 LyXParagraph::size_type pos)
449 minibuffer_char = GetChar(pos);
450 minibuffer_font = GetFontSettings(bparams, pos);
451 minibuffer_inset = 0;
452 if (minibuffer_char == LyXParagraph::META_INSET) {
454 minibuffer_inset = GetInset(pos);
455 // This is a little hack since I want exactly
456 // the inset, not just a clone. Otherwise
457 // the inset would be deleted when calling Erase(pos)
459 InsetTable search_elem(pos, 0);
460 InsetList::iterator it =
461 lower_bound(insetlist.begin(),
463 search_elem, matchIT());
464 if (it != insetlist.end() && (*it).pos == pos)
467 minibuffer_inset = 0;
468 minibuffer_char = ' ';
469 // This reflects what GetInset() does (ARRae)
474 // Erase(pos); now the caller is responsible for that.
478 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
480 if ((minibuffer_char == LyXParagraph::META_INSET) &&
481 !InsertInsetAllowed(minibuffer_inset))
483 if (minibuffer_char == LyXParagraph::META_INSET)
484 InsertInset(pos, minibuffer_inset, minibuffer_font);
486 InsertChar(pos, minibuffer_char, minibuffer_font);
494 void LyXParagraph::Clear()
499 pagebreak_top = false;
500 pagebreak_bottom = false;
502 added_space_top = VSpace(VSpace::NONE);
503 added_space_bottom = VSpace(VSpace::NONE);
504 spacing.set(Spacing::Default);
506 align = LYX_ALIGN_LAYOUT;
510 pextra_type = PEXTRA_NONE;
511 pextra_width.erase();
512 pextra_widthp.erase();
513 pextra_alignment = MINIPAGE_ALIGN_TOP;
514 pextra_hfill = false;
515 pextra_start_minipage = false;
518 labelwidthstring.erase();
522 start_of_appendix = false;
526 // the destructor removes the new paragraph from the list
527 LyXParagraph::~LyXParagraph()
530 previous->next = next;
532 next->previous = previous;
534 for (InsetList::iterator it = insetlist.begin();
535 it != insetlist.end(); ++it) {
539 /* table stuff -- begin*/
541 /* table stuff -- end*/
547 //lyxerr << "LyXParagraph::paragraph_id = "
548 // << LyXParagraph::paragraph_id << endl;
552 void LyXParagraph::Erase(LyXParagraph::size_type pos)
555 // > because last is the next unused position, and you can
556 // use it if you want
558 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
559 NextAfterFootnote()->Erase(pos - text.size() - 1);
561 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
562 "position does not exist." << endl;
566 Assert(pos < size());
569 if (pos < size()) { // last is free for insertation, but should be empty
571 // if it is an inset, delete the inset entry
572 if (text[pos] == LyXParagraph::META_INSET) {
574 InsetTable search_inset(pos, 0);
575 InsetList::iterator it =
576 lower_bound(insetlist.begin(),
578 search_inset, matchIT());
579 if (it != insetlist.end() && (*it).pos == pos) {
584 text.erase(text.begin() + pos);
586 // Erase entries in the tables.
587 FontTable search_font(pos, LyXFont());
589 FontList::iterator it =
590 lower_bound(fontlist.begin(),
592 search_font, matchFT());
593 if (it != fontlist.end() && (*it).pos == pos &&
595 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
596 // If it is a multi-character font
597 // entry, we just make it smaller
598 // (see update below), otherwise we
600 unsigned int i = it - fontlist.begin();
601 fontlist.erase(fontlist.begin() + i);
602 it = fontlist.begin() + i;
603 if (i > 0 && i < fontlist.size() &&
604 fontlist[i-1].font == fontlist[i].font) {
605 fontlist.erase(fontlist.begin() + i-1);
606 it = fontlist.begin() + i-1;
610 // Update all other entries.
611 for (; it != fontlist.end(); ++it)
614 // Update the inset table.
615 InsetTable search_inset(pos, 0);
616 for (InsetList::iterator it =
617 upper_bound(insetlist.begin(),
619 search_inset, matchIT());
620 it != insetlist.end(); ++it)
624 lyxerr << "ERROR (LyXParagraph::Erase): "
625 "can't erase non-existant char." << endl;
631 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
632 LyXParagraph::value_type c)
634 LyXFont f(LyXFont::ALL_INHERIT);
635 InsertChar(pos, c, f);
639 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
640 LyXParagraph::value_type c,
641 LyXFont const & font)
644 // > because last is the next unused position, and you can
645 // use it if you want
648 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
649 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
652 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
653 "position does not exist." << endl;
657 Assert(pos <= size());
659 text.insert(text.begin() + pos, c);
660 // Update the font table.
661 FontTable search_font(pos, LyXFont());
662 for (FontList::iterator it = lower_bound(fontlist.begin(),
664 search_font, matchFT());
665 it != fontlist.end(); ++it)
668 // Update the inset table.
669 InsetTable search_inset(pos, 0);
670 for (InsetList::iterator it = lower_bound(insetlist.begin(),
672 search_inset, matchIT());
673 it != insetlist.end(); ++it)
680 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
683 LyXFont f(LyXFont::ALL_INHERIT);
684 InsertInset(pos, inset, f);
688 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
689 Inset * inset, LyXFont const & font)
694 // > because last is the next unused position, and you can
695 // use it if you want
698 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
700 ->InsertInset(pos - text.size() - 1,
703 lyxerr << "ERROR (LyXParagraph::InsertInset): "
704 "position does not exist: " << pos << endl;
708 Assert(pos <= size());
711 InsertChar(pos, META_INSET, font);
712 Assert(text[pos] == META_INSET);
714 // Add a new entry in the inset table.
715 InsetTable search_inset(pos, 0);
716 InsetList::iterator it = lower_bound(insetlist.begin(),
718 search_inset, matchIT());
719 if (it != insetlist.end() && (*it).pos == pos)
720 lyxerr << "ERROR (LyXParagraph::InsertInset): "
721 "there is an inset in position: " << pos << endl;
723 insetlist.insert(it, InsetTable(pos, inset));
725 inset->setOwner(inset_owner);
729 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
731 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
734 return inset_owner->InsertInsetAllowed(inset);
739 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
744 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
745 return NextAfterFootnote()
746 ->GetInset(pos - text.size() - 1);
748 lyxerr << "ERROR (LyXParagraph::GetInset): "
749 "position does not exist: "
755 Assert(pos < size());
758 InsetTable search_inset(pos, 0);
759 InsetList::iterator it = lower_bound(insetlist.begin(),
761 search_inset, matchIT());
762 if (it != insetlist.end() && (*it).pos == pos)
765 lyxerr << "ERROR (LyXParagraph::GetInset): "
766 "Inset does not exist: " << pos << endl;
769 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
770 // Did this commenting out introduce a bug? So far I have not
771 // see any, please enlighten me. (Lgb)
772 // My guess is that since the inset does not exist, we might
773 // as well replace it with a space to prevent craches. (Asger)
778 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
783 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
784 return NextAfterFootnote()
785 ->GetInset(pos - text.size() - 1);
787 lyxerr << "ERROR (LyXParagraph::GetInset): "
788 "position does not exist: "
794 Assert(pos < size());
797 InsetTable search_inset(pos, 0);
798 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
800 search_inset, matchIT());
801 if (cit != insetlist.end() && (*cit).pos == pos)
804 lyxerr << "ERROR (LyXParagraph::GetInset): "
805 "Inset does not exist: " << pos << endl;
807 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
808 // Did this commenting out introduce a bug? So far I have not
809 // see any, please enlighten me. (Lgb)
810 // My guess is that since the inset does not exist, we might
811 // as well replace it with a space to prevent craches. (Asger)
816 // Gets uninstantiated font setting at position.
817 // Optimized after profiling. (Asger)
818 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
819 LyXParagraph::size_type pos) const
822 Assert(pos <= size());
827 FontTable search_font(pos, LyXFont());
828 FontList::const_iterator cit = lower_bound(fontlist.begin(),
830 search_font, matchFT());
831 if (cit != fontlist.end())
837 // > because last is the next unused position, and you can
838 // use it if you want
839 else if (pos > size()) {
841 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
842 return NextAfterFootnote()
843 ->GetFontSettings(bparams,
844 pos - text.size() - 1);
846 // Why is it an error to ask for the font of a
847 // position that does not exist? Would it be
848 // enough for this to be enabled on debug?
849 // We want strict error checking, but it's ok to only
850 // have it when debugging. (Asger)
851 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
852 "position does not exist. "
853 << pos << " (" << static_cast<int>(pos)
857 return GetFontSettings(bparams, pos - 1);
860 if (pos == size() && size())
861 return GetFontSettings(bparams, pos - 1);
865 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
867 //return LyXFont(LyXFont::ALL_INHERIT);
870 // Gets uninstantiated font setting at position 0
871 LyXFont LyXParagraph::GetFirstFontSettings() const
874 if (!fontlist.empty())
875 return fontlist[0].font;
879 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
880 return NextAfterFootnote()->GetFirstFontSettings();
882 return LyXFont(LyXFont::ALL_INHERIT);
886 // Gets the fully instantiated font at a given position in a paragraph
887 // This is basically the same function as LyXText::GetFont() in text2.C.
888 // The difference is that this one is used for generating the LaTeX file,
889 // and thus cosmetic "improvements" are disallowed: This has to deliver
890 // the true picture of the buffer. (Asger)
891 // If position is -1, we get the layout font of the paragraph.
892 // If position is -2, we get the font of the manual label of the paragraph.
893 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
894 LyXParagraph::size_type pos) const
897 LyXLayout const & layout =
898 textclasslist.Style(bparams.textclass,
900 LyXParagraph::size_type main_body = 0;
901 if (layout.labeltype == LABEL_MANUAL)
902 main_body = BeginningOfMainBody();
907 layoutfont = layout.labelfont;
909 layoutfont = layout.font;
910 tmpfont = GetFontSettings(bparams, pos);
911 tmpfont.realize(layoutfont);
913 // process layoutfont for pos == -1 and labelfont for pos < -1
915 tmpfont = layout.font;
917 tmpfont = layout.labelfont;
918 tmpfont.setLanguage(getParLanguage(bparams));
921 // check for environment font information
922 char par_depth = GetDepth();
923 LyXParagraph const * par = this;
924 while (par && par_depth && !tmpfont.resolved()) {
925 par = par->DepthHook(par_depth - 1);
927 tmpfont.realize(textclasslist.
928 Style(bparams.textclass,
929 par->GetLayout()).font);
930 par_depth = par->GetDepth();
934 tmpfont.realize(textclasslist
935 .TextClass(bparams.textclass)
941 /// Returns the height of the highest font in range
943 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
944 LyXParagraph::size_type endpos) const
946 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
947 if (fontlist.empty())
950 FontTable end_search(endpos, LyXFont());
951 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
953 end_search, matchFT());
954 if (end_it != fontlist.end())
957 FontTable start_search(startpos, LyXFont());
958 for (FontList::const_iterator cit =
959 lower_bound(fontlist.begin(),
961 start_search, matchFT());
962 cit != end_it; ++cit) {
963 LyXFont::FONT_SIZE size = (*cit).font.size();
964 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
971 LyXParagraph::value_type
972 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
977 Assert(pos <= size());
978 if (!size() || pos == size()) return '\0';
989 // > because last is the next unused position, and you can
990 // use it if you want
991 else if (pos > size()) {
992 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
993 return NextAfterFootnote()
994 ->GetChar(pos - text.size() - 1);
997 lyxerr << "ERROR (LyXParagraph::GetChar const): "
998 "position does not exist."
999 << pos << " (" << static_cast<int>(pos)
1005 // We should have a footnote environment.
1006 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1007 // Notice that LyX does request the
1008 // last char from time to time. (Asger)
1009 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1010 // "expected footnote." << endl;
1013 switch (next->footnotekind) {
1014 case LyXParagraph::FOOTNOTE:
1015 return LyXParagraph::META_FOOTNOTE;
1016 case LyXParagraph::MARGIN:
1017 return LyXParagraph::META_MARGIN;
1018 case LyXParagraph::FIG:
1019 case LyXParagraph::WIDE_FIG:
1020 return LyXParagraph::META_FIG;
1021 case LyXParagraph::TAB:
1022 case LyXParagraph::WIDE_TAB:
1023 return LyXParagraph::META_TAB;
1024 case LyXParagraph::ALGORITHM:
1025 return LyXParagraph::META_ALGORITHM;
1027 return '\0'; // to shut up gcc
1033 // return an string of the current word, and the end of the word in lastpos.
1034 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1036 Assert(lastpos >= 0);
1038 // the current word is defined as starting at the first character
1039 // from the immediate left of lastpospos which meets the definition
1040 // of IsLetter(), continuing to the last character to the right
1041 // of this meeting IsLetter.
1047 // move back until we have a letter
1049 //there's no real reason to have firstpos & lastpos as
1050 //separate variables as this is written, but maybe someon
1051 // will want to return firstpos in the future.
1053 //since someone might have typed a punctuation first
1054 int firstpos = lastpos;
1056 while ((firstpos >= 0) && !IsLetter(firstpos))
1059 // now find the beginning by looking for a nonletter
1061 while ((firstpos>= 0) && IsLetter(firstpos))
1064 // the above is now pointing to the preceeding non-letter
1068 // so copy characters into theword until we get a nonletter
1069 // note that this can easily exceed lastpos, wich means
1070 // that if used in the middle of a word, the whole word
1073 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1081 #warning Remember to get rid of this one. (Lgb)
1083 LyXParagraph::size_type LyXParagraph::Last() const
1086 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1087 return text.size() + NextAfterFootnote()->Last() + 1;
1088 // the 1 is the symbol
1097 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1099 // > because last is the next unused position, and you can
1100 // use it if you want
1103 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1104 return NextAfterFootnote()
1105 ->ParFromPos(pos - text.size() - 1);
1107 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1108 "position does not exist." << endl;
1117 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1119 // > because last is the next unused position, and you can
1120 // use it if you want
1123 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1124 return NextAfterFootnote()
1125 ->PositionInParFromPos(pos - text.size() - 1);
1128 "ERROR (LyXParagraph::PositionInParFromPos): "
1129 "position does not exist." << endl;
1138 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1139 LyXFont const & font)
1142 // > because last is the next unused position, and you can
1143 // use it if you want
1146 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1147 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1150 lyxerr << "ERROR (LyXParagraph::SetFont): "
1151 "position does not exist." << endl;
1156 Assert(pos <= size());
1159 // First, reduce font against layout/label font
1160 // Update: The SetCharFont() routine in text2.C already
1161 // reduces font, so we don't need to do that here. (Asger)
1162 // No need to simplify this because it will disappear
1163 // in a new kernel. (Asger)
1164 // Next search font table
1166 FontTable search_font(pos, LyXFont());
1167 FontList::iterator it = lower_bound(fontlist.begin(),
1169 search_font, matchFT());
1170 unsigned int i = it - fontlist.begin();
1171 bool notfound = it == fontlist.end();
1173 if (!notfound && fontlist[i].font == font)
1176 bool begin = pos == 0 || notfound ||
1177 (i > 0 && fontlist[i-1].pos == pos - 1);
1178 // Is position pos is a beginning of a font block?
1179 bool end = !notfound && fontlist[i].pos == pos;
1180 // Is position pos is the end of a font block?
1181 if (begin && end) { // A single char block
1182 if (i+1 < fontlist.size() &&
1183 fontlist[i+1].font == font) {
1184 // Merge the singleton block with the next block
1185 fontlist.erase(fontlist.begin() + i);
1186 if (i > 0 && fontlist[i-1].font == font)
1187 fontlist.erase(fontlist.begin() + i-1);
1188 } else if (i > 0 && fontlist[i-1].font == font) {
1189 // Merge the singleton block with the previous block
1190 fontlist[i-1].pos = pos;
1191 fontlist.erase(fontlist.begin() + i);
1193 fontlist[i].font = font;
1195 if (i > 0 && fontlist[i-1].font == font)
1196 fontlist[i-1].pos = pos;
1198 fontlist.insert(fontlist.begin() + i,
1199 FontTable(pos, font));
1201 fontlist[i].pos = pos - 1;
1202 if (!(i+1 < fontlist.size() &&
1203 fontlist[i+1].font == font))
1204 fontlist.insert(fontlist.begin() + i+1,
1205 FontTable(pos, font));
1206 } else { // The general case. The block is splitted into 3 blocks
1207 fontlist.insert(fontlist.begin() + i,
1208 FontTable(pos - 1, fontlist[i].font));
1209 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1214 // This function is able to hide closed footnotes.
1215 LyXParagraph * LyXParagraph::Next()
1218 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1219 LyXParagraph * tmp = next;
1221 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1223 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1224 return tmp->Next(); /* there can be more than one
1225 footnote in a logical
1228 return next; // This should never happen!
1236 LyXParagraph * LyXParagraph::NextAfterFootnote()
1238 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1239 LyXParagraph * tmp = next;
1240 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1242 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1243 return tmp; /* there can be more than one footnote
1244 in a logical paragraph */
1246 return next; // This should never happen!
1254 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1256 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1257 LyXParagraph * tmp = next;
1258 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1260 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1261 return tmp; /* there can be more than one footnote
1262 in a logical paragraph */
1264 return next; // This should never happen!
1272 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1275 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1277 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1278 tmp = tmp->previous;
1279 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1280 return tmp; /* there can be more than one footnote
1281 in a logical paragraph */
1283 return previous; // This should never happen!
1291 LyXParagraph * LyXParagraph::LastPhysicalPar()
1293 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1296 LyXParagraph * tmp = this;
1298 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1299 tmp = tmp->NextAfterFootnote();
1307 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1309 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1312 LyXParagraph const * tmp = this;
1314 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1315 tmp = tmp->NextAfterFootnote();
1323 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1327 LyXParagraph * tmppar = this;
1331 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1332 tmppar = tmppar->previous;
1343 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1347 LyXParagraph const * tmppar = this;
1351 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1352 tmppar = tmppar->previous;
1362 // This function is able to hide closed footnotes.
1363 LyXParagraph * LyXParagraph::Previous()
1366 LyXParagraph * tmp = previous;
1371 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1372 tmp = tmp->previous;
1374 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1375 tmp = tmp->previous;
1376 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1377 return tmp->next->Previous();
1387 // This function is able to hide closed footnotes.
1388 LyXParagraph const * LyXParagraph::Previous() const
1391 LyXParagraph * tmp = previous;
1395 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1396 tmp = tmp->previous;
1398 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1399 tmp = tmp->previous;
1400 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1401 return tmp->next->Previous();
1411 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1412 LyXParagraph::size_type pos,
1417 // create a new paragraph
1420 size_type pos_first;
1421 LyXParagraph * par = ParFromPos(pos);
1422 LyXParagraph * firstpar = FirstPhysicalPar();
1424 LyXParagraph * tmp = new LyXParagraph(par);
1426 //LyXParagraph * par = this;
1427 //LyXParagraph * firstpar = this;
1428 LyXParagraph * tmp = new LyXParagraph(this);
1432 tmp->footnoteflag = footnoteflag;
1433 tmp->footnotekind = footnotekind;
1435 // this is an idea for a more userfriendly layout handling, I will
1436 // see what the users say
1439 // layout stays the same with latex-environments
1441 tmp->SetOnlyLayout(bparams, firstpar->layout);
1442 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1445 // layout stays the same with latex-environments
1447 tmp->SetOnlyLayout(bparams, layout);
1448 tmp->SetLabelWidthString(labelwidthstring);
1452 if (Last() > pos || !Last() || flag == 2) {
1453 tmp->SetOnlyLayout(bparams, firstpar->layout);
1454 tmp->align = firstpar->align;
1455 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1457 tmp->line_bottom = firstpar->line_bottom;
1458 firstpar->line_bottom = false;
1459 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1460 firstpar->pagebreak_bottom = false;
1461 tmp->added_space_bottom = firstpar->added_space_bottom;
1462 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1464 tmp->depth = firstpar->depth;
1465 tmp->noindent = firstpar->noindent;
1467 if (Last() > pos || !Last() || flag == 2) {
1468 tmp->SetOnlyLayout(bparams, layout);
1470 tmp->SetLabelWidthString(labelwidthstring);
1472 tmp->line_bottom = line_bottom;
1473 line_bottom = false;
1474 tmp->pagebreak_bottom = pagebreak_bottom;
1475 pagebreak_bottom = false;
1476 tmp->added_space_bottom = added_space_bottom;
1477 added_space_bottom = VSpace(VSpace::NONE);
1480 tmp->noindent = noindent;
1482 // copy everything behind the break-position
1483 // to the new paragraph
1486 while (ParFromPos(pos_first) != par)
1488 pos_end = pos_first + par->text.size() - 1;
1491 for (i = j = pos; i <= pos_end; ++i) {
1492 par->CutIntoMinibuffer(bparams, i - pos_first);
1493 if (tmp->InsertFromMinibuffer(j - pos))
1496 tmp->text.resize(tmp->text.size());
1497 for (i = pos_end; i >= pos; --i)
1498 par->Erase(i - pos_first);
1500 par->text.resize(par->text.size());
1502 size_type pos_end = text.size() - 1;
1504 for (i = j = pos; i <= pos_end; ++i) {
1505 CutIntoMinibuffer(bparams, i);
1506 if (tmp->InsertFromMinibuffer(j - pos))
1510 for (i = pos_end; i >= pos; --i)
1518 // just an idea of me
1520 tmp->line_top = firstpar->line_top;
1521 tmp->pagebreak_top = firstpar->pagebreak_top;
1522 tmp->added_space_top = firstpar->added_space_top;
1523 tmp->bibkey = firstpar->bibkey;
1525 // layout stays the same with latex-environments
1527 firstpar->SetOnlyLayout(bparams, tmp->layout);
1528 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1529 firstpar->depth = tmp->depth;
1533 // just an idea of me
1535 tmp->line_top = line_top;
1536 tmp->pagebreak_top = pagebreak_top;
1537 tmp->added_space_top = added_space_top;
1538 tmp->bibkey = bibkey;
1540 // layout stays the same with latex-environments
1542 SetOnlyLayout(bparams, tmp->layout);
1543 SetLabelWidthString(tmp->labelwidthstring);
1551 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1554 par = par->FirstPhysicalPar();
1555 footnoteflag = par->footnoteflag;
1556 footnotekind = par->footnotekind;
1558 layout = par->layout;
1559 align = par-> align;
1560 SetLabelWidthString(par->labelwidthstring);
1562 line_bottom = par->line_bottom;
1563 pagebreak_bottom = par->pagebreak_bottom;
1564 added_space_bottom = par->added_space_bottom;
1566 line_top = par->line_top;
1567 pagebreak_top = par->pagebreak_top;
1568 added_space_top = par->added_space_top;
1570 spacing = par->spacing;
1572 pextra_type = par->pextra_type;
1573 pextra_width = par->pextra_width;
1574 pextra_widthp = par->pextra_widthp;
1575 pextra_alignment = par->pextra_alignment;
1576 pextra_hfill = par->pextra_hfill;
1577 pextra_start_minipage = par->pextra_start_minipage;
1579 noindent = par->noindent;
1585 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1587 LyXParagraph * tmppar = this;
1590 && tmppar->previous->footnoteflag ==
1591 LyXParagraph::CLOSED_FOOTNOTE)
1592 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1593 tmppar = tmppar->previous;
1596 return this; // This should never happen!
1603 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1605 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1620 && (IsNewline(0) || IsLineSeparator(0))){
1629 LyXParagraph * LyXParagraph::Clone() const
1631 // create a new paragraph
1632 LyXParagraph * result = new LyXParagraph;
1634 result->MakeSameLayout(this);
1636 // this is because of the dummy layout of the paragraphs that
1638 result->layout = layout;
1641 /* table stuff -- begin*/
1643 result->table = table->Clone();
1646 /* table stuff -- end*/
1648 result->inset_owner = inset_owner;
1651 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1654 // copy everything behind the break-position to the new paragraph
1656 result->text = text;
1657 result->fontlist = fontlist;
1658 result->insetlist = insetlist;
1659 for (InsetList::iterator it = result->insetlist.begin();
1660 it != result->insetlist.end(); ++it)
1661 (*it).inset = (*it).inset->Clone();
1666 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1669 par = par->FirstPhysicalPar();
1674 par->footnoteflag == footnoteflag &&
1675 par->footnotekind == footnotekind &&
1677 par->layout == layout &&
1679 par->align == align &&
1681 par->line_bottom == line_bottom &&
1682 par->pagebreak_bottom == pagebreak_bottom &&
1683 par->added_space_bottom == added_space_bottom &&
1685 par->line_top == line_top &&
1686 par->pagebreak_top == pagebreak_top &&
1687 par->added_space_top == added_space_top &&
1689 par->spacing == spacing &&
1691 par->pextra_type == pextra_type &&
1692 par->pextra_width == pextra_width &&
1693 par->pextra_widthp == pextra_widthp &&
1694 par->pextra_alignment == pextra_alignment &&
1695 par->pextra_hfill == pextra_hfill &&
1696 par->pextra_start_minipage == pextra_start_minipage &&
1698 par->table == table && // what means: NO TABLE AT ALL
1701 par->noindent == noindent &&
1702 par->depth == depth);
1706 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1707 LyXParagraph::size_type pos)
1710 // create a new paragraph
1711 LyXParagraph * par = ParFromPos(pos);
1713 LyXParagraph * tmp = new LyXParagraph(par);
1715 tmp->MakeSameLayout(par);
1717 // When can pos < Last()?
1718 // I guess pos == Last() is possible.
1720 // copy everything behind the break-position to the new
1722 size_type pos_first = 0;
1723 while (ParFromPos(pos_first) != par)
1725 size_type pos_end = pos_first + par->text.size() - 1;
1728 for (i = j = pos; i <= pos_end; ++i) {
1729 par->CutIntoMinibuffer(bparams, i - pos_first);
1730 if (tmp->InsertFromMinibuffer(j - pos))
1733 tmp->text.resize(tmp->text.size());
1734 for (size_type i = pos_end; i >= pos; --i)
1735 par->Erase(i - pos_first);
1737 par->text.resize(par->text.size());
1740 // create a new paragraph
1741 LyXParagraph * tmp = new LyXParagraph(this);
1742 tmp->MakeSameLayout(this);
1744 // When can pos > Last()?
1745 // I guess pos == Last() is possible.
1747 // copy everything behind the break-position to the new
1749 size_type pos_end = text.size() - 1;
1752 for (i = j = pos; i <= pos_end; ++i) {
1753 CutIntoMinibuffer(bparams, i);
1754 if (tmp->InsertFromMinibuffer(j - pos))
1760 for (size_type i = pos_end; i >= pos; --i)
1769 // Be carefull, this does not make any check at all.
1770 // This method has wrong name, it combined this par with the next par.
1771 // In that sense it is the reverse of break paragraph. (Lgb)
1772 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1774 // copy the next paragraph to this one
1775 LyXParagraph * the_next = Next();
1777 LyXParagraph * firstpar = FirstPhysicalPar();
1780 // first the DTP-stuff
1782 firstpar->line_bottom = the_next->line_bottom;
1783 firstpar->added_space_bottom = the_next->added_space_bottom;
1784 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1786 line_bottom = the_next->line_bottom;
1787 added_space_bottom = the_next->added_space_bottom;
1788 pagebreak_bottom = the_next->pagebreak_bottom;
1791 size_type pos_end = the_next->text.size() - 1;
1792 size_type pos_insert = Last();
1794 // ok, now copy the paragraph
1796 for (i = j = 0; i <= pos_end; ++i) {
1797 the_next->CutIntoMinibuffer(bparams, i);
1798 if (InsertFromMinibuffer(pos_insert + j))
1802 // delete the next paragraph
1803 LyXParagraph * ppar = the_next->previous;
1804 LyXParagraph * npar = the_next->next;
1811 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1813 LyXParagraph * par = ParFromPos(pos);
1815 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1816 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1822 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1824 LyXParagraph * par = ParFromPos(pos);
1826 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1827 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1834 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1836 LyXParagraph const * par = this;
1837 int par_depth = GetDepth();
1839 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1841 textclasslist.Style(bparams.textclass,
1842 layout).endlabeltype;
1843 if (endlabeltype != END_LABEL_NO_LABEL) {
1844 LyXParagraph const * last = this;
1846 if( footnoteflag == NO_FOOTNOTE)
1847 last = LastPhysicalPar();
1848 else if (next->footnoteflag == NO_FOOTNOTE)
1849 return endlabeltype;
1854 if (!last || !last->next)
1855 return endlabeltype;
1857 int next_depth = last->next->GetDepth();
1858 if (par_depth > next_depth ||
1859 (par_depth == next_depth && layout != last->next->GetLayout() ))
1860 return endlabeltype;
1865 par = par->DepthHook(par_depth - 1);
1867 par_depth = par->GetDepth();
1869 return END_LABEL_NO_LABEL;
1873 LyXTextClass::size_type LyXParagraph::GetLayout() const
1876 return FirstPhysicalPar()->layout;
1883 char LyXParagraph::GetDepth() const
1886 return FirstPhysicalPar()->depth;
1893 char LyXParagraph::GetAlign() const
1896 return FirstPhysicalPar()->align;
1903 string const & LyXParagraph::GetLabelstring() const
1906 return FirstPhysicalPar()->labelstring;
1913 int LyXParagraph::GetFirstCounter(int i) const
1916 return FirstPhysicalPar()->counter_[i];
1923 // the next two functions are for the manual labels
1924 string LyXParagraph::GetLabelWidthString() const
1927 if (!FirstPhysicalPar()->labelwidthstring.empty())
1928 return FirstPhysicalPar()->labelwidthstring;
1930 if (!labelwidthstring.empty())
1931 return labelwidthstring;
1934 return _("Senseless with this layout!");
1938 void LyXParagraph::SetLabelWidthString(string const & s)
1941 LyXParagraph * par = FirstPhysicalPar();
1943 par->labelwidthstring = s;
1945 labelwidthstring = s;
1950 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1951 LyXTextClass::size_type new_layout)
1954 LyXParagraph * par = FirstPhysicalPar();
1956 LyXParagraph * par = this;
1958 LyXParagraph * ppar = 0;
1959 LyXParagraph * npar = 0;
1961 par->layout = new_layout;
1963 /* table stuff -- begin*/
1966 /* table stuff -- end*/
1968 if (par->pextra_type == PEXTRA_NONE) {
1969 if (par->Previous()) {
1971 ppar = par->Previous()->FirstPhysicalPar();
1973 ppar = par->Previous();
1977 && (ppar->depth > par->depth))
1979 ppar = ppar->Previous()->FirstPhysicalPar();
1981 ppar = ppar->Previous();
1986 npar = par->Next()->NextAfterFootnote();
1992 && (npar->depth > par->depth))
1994 npar = npar->Next()->NextAfterFootnote();
1996 npar = npar->Next();
1999 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2001 p1 = ppar->pextra_width,
2002 p2 = ppar->pextra_widthp;
2003 ppar->SetPExtraType(bparams, ppar->pextra_type,
2004 p1.c_str(), p2.c_str());
2006 if ((par->pextra_type == PEXTRA_NONE) &&
2007 npar && (npar->pextra_type != PEXTRA_NONE)) {
2009 p1 = npar->pextra_width,
2010 p2 = npar->pextra_widthp;
2011 npar->SetPExtraType(bparams, npar->pextra_type,
2012 p1.c_str(), p2.c_str());
2018 void LyXParagraph::SetLayout(BufferParams const & bparams,
2019 LyXTextClass::size_type new_layout)
2023 * par = FirstPhysicalPar(),
2030 par->layout = new_layout;
2031 par->labelwidthstring.erase();
2032 par->align = LYX_ALIGN_LAYOUT;
2033 par->added_space_top = VSpace(VSpace::NONE);
2034 par->added_space_bottom = VSpace(VSpace::NONE);
2035 par->spacing.set(Spacing::Default);
2038 /* table stuff -- begin*/
2041 /* table stuff -- end*/
2043 if (par->pextra_type == PEXTRA_NONE) {
2044 if (par->Previous()) {
2046 ppar = par->Previous()->FirstPhysicalPar();
2048 ppar = par->Previous();
2052 && (ppar->depth > par->depth))
2054 ppar = ppar->Previous()->FirstPhysicalPar();
2056 ppar = ppar->Previous();
2061 npar = par->Next()->NextAfterFootnote();
2067 && (npar->depth > par->depth))
2069 npar = npar->Next()->NextAfterFootnote();
2071 npar = npar->Next();
2074 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2076 p1 = ppar->pextra_width,
2077 p2 = ppar->pextra_widthp;
2078 ppar->SetPExtraType(bparams, ppar->pextra_type,
2079 p1.c_str(), p2.c_str());
2081 if ((par->pextra_type == PEXTRA_NONE) &&
2082 npar && (npar->pextra_type != PEXTRA_NONE)) {
2084 p1 = npar->pextra_width,
2085 p2 = npar->pextra_widthp;
2086 npar->SetPExtraType(bparams, npar->pextra_type,
2087 p1.c_str(), p2.c_str());
2093 // if the layout of a paragraph contains a manual label, the beginning of the
2094 // main body is the beginning of the second word. This is what the par-
2095 // function returns. If the layout does not contain a label, the main
2096 // body always starts with position 0. This differentiation is necessary,
2097 // because there cannot be a newline or a blank <= the beginning of the
2098 // main body in TeX.
2100 int LyXParagraph::BeginningOfMainBody() const
2103 if (FirstPhysicalPar() != this)
2106 // Unroll the first two cycles of the loop
2107 // and remember the previous character to
2108 // remove unnecessary GetChar() calls
2111 && GetChar(i) != LyXParagraph::META_NEWLINE
2114 char previous_char = 0, temp = 0;
2116 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2117 // Yes, this ^ is supposed to be "= " not "=="
2120 && previous_char != ' '
2121 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2123 previous_char = temp;
2129 if (i == 0 && i == size() &&
2130 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2131 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2132 ++i; /* the cursor should not jump
2133 * to the main body if there
2140 LyXParagraph * LyXParagraph::DepthHook(int deth)
2142 LyXParagraph * newpar = this;
2148 newpar = newpar->FirstPhysicalPar()->Previous();
2150 newpar = newpar->Previous();
2152 } while (newpar && newpar->GetDepth() > deth
2154 && newpar->footnoteflag == footnoteflag
2159 if (Previous() || GetDepth())
2160 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2165 return newpar->FirstPhysicalPar();
2172 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2174 LyXParagraph const * newpar = this;
2180 newpar = newpar->FirstPhysicalPar()->Previous();
2182 newpar = newpar->Previous();
2184 } while (newpar && newpar->GetDepth() > deth
2186 && newpar->footnoteflag == footnoteflag
2191 if (Previous() || GetDepth())
2192 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2197 return newpar->FirstPhysicalPar();
2204 int LyXParagraph::AutoDeleteInsets()
2207 InsetList::size_type index = 0;
2208 while (index < insetlist.size()) {
2209 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2210 Erase(insetlist[index].pos);
2211 // Erase() calls to insetlist.erase(&insetlist[index])
2212 // so index shouldn't be increased.
2221 LyXParagraph::inset_iterator
2222 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2224 InsetTable search_inset(pos, 0);
2225 InsetList::iterator it = lower_bound(insetlist.begin(),
2227 search_inset, matchIT());
2228 return inset_iterator(it);
2232 // returns -1 if inset not found
2233 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2236 for (InsetList::const_iterator cit = insetlist.begin();
2237 cit != insetlist.end(); ++cit) {
2238 if ((*cit).inset == inset) {
2243 // Think about footnotes.
2244 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2245 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2247 NextAfterFootnote()->GetPositionOfInset(inset);
2249 return text.size() + 1 + further;
2256 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2257 BufferParams const & bparams,
2258 ostream & os, TexRow & texrow,
2263 TexRow & foot_texrow,
2268 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2269 LyXLayout const & style =
2270 textclasslist.Style(bparams.textclass,
2273 bool further_blank_line = false;
2276 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2279 if (start_of_appendix) {
2280 os << "\\appendix\n";
2284 if (!spacing.isDefault()
2285 && (!Previous() || !Previous()->HasSameLayout(this))) {
2286 os << spacing.writeEnvirBegin() << "\n";
2290 if (tex_code_break_column && style.isCommand()){
2295 if (pagebreak_top) {
2297 further_blank_line = true;
2299 if (added_space_top.kind() != VSpace::NONE) {
2300 os << added_space_top.asLatexCommand(bparams);
2301 further_blank_line = true;
2305 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2306 << "\\vspace{-1\\parskip}";
2307 further_blank_line = true;
2310 if (further_blank_line){
2315 Language const * language = getParLanguage(bparams);
2316 Language const * doc_language = bparams.language_info;
2317 Language const * previous_language = previous
2318 ? previous->getParLanguage(bparams) : doc_language;
2319 if (language != doc_language && language != previous_language) {
2320 os << subst(lyxrc.language_command_begin, "$$lang",
2326 if (bparams.inputenc == "auto" &&
2327 language->encoding() != previous_language->encoding()) {
2328 os << "\\inputencoding{"
2329 << language->encoding()->LatexName()
2334 switch (style.latextype) {
2337 << style.latexname()
2338 << style.latexparam();
2340 case LATEX_ITEM_ENVIRONMENT:
2342 bibkey->Latex(buf, os, false, false);
2346 case LATEX_LIST_ENVIRONMENT:
2353 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2355 LyXParagraph * par = next;
2357 // Spit out footnotes
2358 if (lyxrc.rtl_support) {
2359 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2360 && next->footnoteflag != footnoteflag) {
2361 LyXParagraph * p = 0;
2362 bool is_rtl = (size() > 0)
2363 ? GetFontSettings(bparams,
2364 size()-1).isRightToLeft()
2365 : language->RightToLeft();
2366 if ( (p = NextAfterFootnote()) != 0 &&
2368 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2369 is_rtl = getParLanguage(bparams)->RightToLeft();
2370 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2371 && par->footnoteflag != footnoteflag) {
2372 par = par->TeXFootnote(buf, bparams,
2374 foot_texrow, foot_count,
2376 par->SimpleTeXOnePar(buf, bparams,
2377 os, texrow, moving_arg);
2378 is_rtl = (par->size() > 0)
2379 ? par->GetFontSettings(bparams,
2380 par->size()-1).isRightToLeft()
2381 : language->RightToLeft();
2383 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2384 (p = par->NextAfterFootnote()) != 0 &&
2386 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2387 is_rtl = language->RightToLeft();
2392 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2393 && par->footnoteflag != footnoteflag) {
2394 par = par->TeXFootnote(buf, bparams,
2396 foot, foot_texrow, foot_count,
2398 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2404 // Make sure that \\par is done with the font of the last
2405 // character if this has another size as the default.
2406 // This is necessary because LaTeX (and LyX on the screen)
2407 // calculates the space between the baselines according
2408 // to this font. (Matthias)
2409 LyXFont font = getFont(bparams, Last() - 1);
2411 if (style.resfont.size() != font.size()) {
2417 } else if (textclasslist.Style(bparams.textclass,
2418 GetLayout()).isCommand()) {
2419 if (style.resfont.size() != font.size()) {
2425 } else if (style.resfont.size() != font.size()){
2426 os << "{\\" << font.latexSize() << " \\par}";
2429 if (language != doc_language &&
2432 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2434 || par->getParLanguage(bparams) != language)) {
2436 << subst(lyxrc.language_command_end, "$$lang",
2437 doc_language->lang());
2440 switch (style.latextype) {
2441 case LATEX_ITEM_ENVIRONMENT:
2442 case LATEX_LIST_ENVIRONMENT:
2443 if (par && (depth < par->depth)) {
2448 case LATEX_ENVIRONMENT:
2449 // if its the last paragraph of the current environment
2450 // skip it otherwise fall through
2452 && (par->layout != layout
2453 || par->depth != depth
2454 || par->pextra_type != pextra_type))
2457 // we don't need it for the last paragraph!!!
2460 && !( footnoteflag != LyXParagraph::NO_FOOTNOTE
2461 && footnotekind != LyXParagraph::FOOTNOTE
2462 && footnotekind != LyXParagraph::MARGIN)
2470 // don't insert this if we would be adding it
2471 // before or after a table in a float. This
2472 // little trick is needed in order to allow
2473 // use of tables in \subfigures or \subtables.
2479 further_blank_line = false;
2481 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2482 further_blank_line = true;
2485 if (added_space_bottom.kind() != VSpace::NONE) {
2486 os << added_space_bottom.asLatexCommand(bparams);
2487 further_blank_line = true;
2490 if (pagebreak_bottom) {
2492 further_blank_line = true;
2495 if (further_blank_line){
2500 if (!spacing.isDefault()
2501 && (!par || !par->HasSameLayout(this))) {
2502 os << spacing.writeEnvirEnd() << "\n";
2506 // we don't need it for the last paragraph!!!
2509 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2510 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2517 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2522 // This one spits out the text of the paragraph
2523 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2524 BufferParams const & bparams,
2525 ostream & os, TexRow & texrow,
2528 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2532 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2535 bool return_value = false;
2537 LyXLayout const & style =
2538 textclasslist.Style(bparams.textclass,
2540 LyXFont basefont, last_font;
2542 // Maybe we have to create a optional argument.
2543 size_type main_body;
2544 if (style.labeltype != LABEL_MANUAL)
2547 main_body = BeginningOfMainBody();
2549 if (main_body > 0) {
2551 basefont = getFont(bparams, -2); // Get label font
2553 basefont = getFont(bparams, -1); // Get layout font
2564 if (style.isCommand()) {
2567 } else if (align != LYX_ALIGN_LAYOUT) {
2570 return_value = true;
2574 moving_arg |= style.needprotect;
2576 // Which font is currently active?
2577 LyXFont running_font(basefont);
2578 // Do we have an open font change?
2579 bool open_font = false;
2581 texrow.start(this, 0);
2583 for (size_type i = 0; i < size(); ++i) {
2585 // First char in paragraph or after label?
2591 if (main_body > 0) {
2593 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2596 basefont = getFont(bparams, -1); // Now use the layout font
2597 running_font = basefont;
2601 if (style.isCommand()) {
2604 } else if (align != LYX_ALIGN_LAYOUT) {
2607 return_value = true;
2611 os << "\\noindent ";
2615 case LYX_ALIGN_NONE:
2616 case LYX_ALIGN_BLOCK:
2617 case LYX_ALIGN_LAYOUT:
2618 case LYX_ALIGN_SPECIAL:
2620 case LYX_ALIGN_LEFT:
2621 if (getParLanguage(bparams)->lang() != "hebrew") {
2622 os << "\\raggedright ";
2625 os << "\\raggedleft ";
2629 case LYX_ALIGN_RIGHT:
2630 if (getParLanguage(bparams)->lang() != "hebrew") {
2631 os << "\\raggedleft ";
2634 os << "\\raggedright ";
2638 case LYX_ALIGN_CENTER:
2639 os << "\\centering ";
2645 value_type c = GetChar(i);
2647 // Fully instantiated font
2648 LyXFont font = getFont(bparams, i);
2650 LyXParagraph * p = 0;
2653 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2654 (p = PreviousBeforeFootnote()) != 0)
2655 last_font = p->getFont(bparams, p->size() - 1);
2658 last_font = running_font;
2660 // Spaces at end of font change are simulated to be
2661 // outside font change, i.e. we write "\textXX{text} "
2662 // rather than "\textXX{text }". (Asger)
2663 if (open_font && c == ' ' && i <= size() - 2
2664 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2665 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2666 font = getFont(bparams, i + 1);
2668 // We end font definition before blanks
2669 if (!font.equalExceptLatex(running_font) && open_font) {
2670 column += running_font.latexWriteEndChanges(os,
2672 (i == main_body-1) ? basefont : font);
2673 running_font = basefont;
2677 // Blanks are printed before start of fontswitch
2679 // Do not print the separation of the optional argument
2680 if (i != main_body - 1) {
2681 SimpleTeXBlanks(os, texrow, i,
2682 column, font, style);
2686 // Do we need to change font?
2687 if (!font.equalExceptLatex(running_font)
2688 && i != main_body-1) {
2689 column += font.latexWriteStartChanges(os, basefont,
2691 running_font = font;
2695 if (c == LyXParagraph::META_NEWLINE) {
2696 // newlines are handled differently here than
2697 // the default in SimpleTeXSpecialChars().
2698 if (!style.newline_allowed
2699 || font.latex() == LyXFont::ON) {
2703 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2706 basefont = getFont(bparams, -1);
2707 running_font = basefont;
2708 if (font.family() ==
2709 LyXFont::TYPEWRITER_FAMILY) {
2717 texrow.start(this, i + 1);
2720 SimpleTeXSpecialChars(buf, bparams,
2721 os, texrow, moving_arg,
2722 font, running_font, basefont,
2723 open_font, style, i, column, c);
2727 // If we have an open font definition, we have to close it
2729 LyXParagraph * p = 0;
2732 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2733 && (p = NextAfterFootnote()) != 0
2738 running_font.latexWriteEndChanges(os, basefont,
2739 p->getFont(bparams, 0));
2741 running_font.latexWriteEndChanges(os, basefont, basefont);
2744 // Needed if there is an optional argument but no contents.
2745 if (main_body > 0 && main_body == size()) {
2747 return_value = false;
2750 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2751 return return_value;
2756 // This one spits out the text of a table paragraph
2757 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2758 BufferParams const & bparams,
2759 ostream & os, TexRow & texrow)
2761 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2763 bool return_value = false;
2765 LyXLayout const & style =
2766 textclasslist.Style(bparams.textclass, GetLayout());
2770 if (!IsDummy()) { // it is dummy if it is in a float!!!
2772 if (style.isCommand()) {
2775 } else if (align != LYX_ALIGN_LAYOUT) {
2778 return_value = true;
2781 os << "\\noindent ";
2785 case LYX_ALIGN_NONE:
2786 case LYX_ALIGN_BLOCK:
2787 case LYX_ALIGN_LAYOUT:
2788 case LYX_ALIGN_SPECIAL: break;
2789 case LYX_ALIGN_LEFT:
2790 os << "\\raggedright ";
2793 case LYX_ALIGN_RIGHT:
2794 os << "\\raggedleft ";
2797 case LYX_ALIGN_CENTER:
2798 os << "\\centering ";
2806 LyXFont basefont = getFont(bparams, -1); // Get layout font
2807 // Which font is currently active?
2808 LyXFont running_font = basefont;
2810 // Do we have an open font change?
2811 bool open_font = false;
2812 int current_cell_number = -1;
2813 int tmp = table->TexEndOfCell(os, current_cell_number);
2814 for (; tmp > 0 ; --tmp)
2817 texrow.start(this, 0);
2819 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2820 bool first_in_cell = true;
2822 for (size_type i = 0; i < size(); ++i) {
2823 value_type c = GetChar(i);
2824 if (table->IsContRow(current_cell_number + 1)) {
2825 if (c == LyXParagraph::META_NEWLINE)
2826 ++current_cell_number;
2831 if (first_in_cell && is_rtl) {
2834 first_in_cell = false;
2837 // Fully instantiated font
2838 LyXFont font = getFont(bparams, i);
2839 last_font = running_font;
2841 // Spaces at end of font change are simulated to be
2842 // outside font change.
2843 // i.e. we write "\textXX{text} " rather than
2844 // "\textXX{text }". (Asger)
2845 if (open_font && c == ' ' && i <= size() - 2
2846 && getFont(bparams, i + 1) != running_font
2847 && getFont(bparams, i + 1) != font) {
2848 font = getFont(bparams, i + 1);
2851 // We end font definition before blanks
2852 if (font != running_font && open_font) {
2853 column += running_font.latexWriteEndChanges(os,
2856 running_font = basefont;
2859 // Blanks are printed before start of fontswitch
2861 SimpleTeXBlanks(os, texrow, i, column, font, style);
2863 // Do we need to change font?
2864 if (font != running_font) {
2865 column += font.latexWriteStartChanges(os, basefont,
2867 running_font = font;
2870 // Do we need to turn on LaTeX mode?
2871 if (font.latex() != running_font.latex()) {
2872 if (font.latex() == LyXFont::ON
2873 && style.needprotect) {
2878 if (c == LyXParagraph::META_NEWLINE) {
2879 // special case for inside a table
2880 // different from default case in
2881 // SimpleTeXSpecialChars()
2883 column += running_font
2884 .latexWriteEndChanges(os, basefont,
2888 basefont = getFont(bparams, -1);
2889 running_font = basefont;
2890 ++current_cell_number;
2891 if (table->CellHasContRow(current_cell_number) >= 0) {
2892 TeXContTableRows(buf, bparams, os, i + 1,
2893 current_cell_number,
2896 if (is_rtl && !first_in_cell) {
2898 first_in_cell = true;
2901 // if this cell follow only ContRows till end don't
2902 // put the EndOfCell because it is put after the
2904 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2905 --current_cell_number;
2908 int tmp = table->TexEndOfCell(os,
2909 current_cell_number);
2912 } else if (tmp < 0) {
2918 texrow.start(this, i + 1);
2920 SimpleTeXSpecialChars(buf, bparams,
2922 font, running_font, basefont,
2923 open_font, style, i, column, c);
2927 // If we have an open font definition, we have to close it
2929 running_font.latexWriteEndChanges(os, basefont, basefont);
2931 ++current_cell_number;
2932 if (is_rtl && !first_in_cell)
2934 tmp = table->TexEndOfCell(os, current_cell_number);
2935 for (; tmp > 0; --tmp)
2937 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2938 return return_value;
2944 // This one spits out the text off ContRows in tables
2945 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2946 BufferParams const & bparams,
2948 LyXParagraph::size_type i,
2949 int current_cell_number,
2950 int & column, TexRow & texrow)
2952 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2956 bool return_value = false;
2957 LyXLayout const & style =
2958 textclasslist.Style(bparams.textclass,
2960 LyXFont basefont = getFont(bparams, -1); // Get layout font
2962 // Which font is currently active?
2963 LyXFont running_font = basefont;
2964 // Do we have an open font change?
2965 bool open_font = false;
2967 size_type lastpos = i;
2968 int cell = table->CellHasContRow(current_cell_number);
2969 ++current_cell_number;
2972 // first find the right position
2974 for (; (i < size()) && (current_cell_number < cell); ++i) {
2976 if (c == LyXParagraph::META_NEWLINE)
2977 ++current_cell_number;
2981 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2985 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2990 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2994 // Fully instantiated font
2995 LyXFont font = getFont(bparams, i);
2996 last_font = running_font;
2998 // Spaces at end of font change are simulated to
2999 // be outside font change. i.e. we write
3000 // "\textXX{text} " rather than "\textXX{text }".
3002 if (open_font && c == ' ' && i <= size() - 2
3003 && getFont(bparams, i + 1) != running_font
3004 && getFont(bparams, i + 1) != font) {
3005 font = getFont(bparams, i + 1);
3008 // We end font definition before blanks
3009 if (font != running_font && open_font) {
3010 column += running_font.latexWriteEndChanges(os, basefont, font);
3011 running_font = basefont;
3014 // Blanks are printed before start of fontswitch
3016 SimpleTeXBlanks(os, texrow, i,
3017 column, font, style);
3019 // Do we need to change font?
3020 if (font != running_font) {
3022 font.latexWriteStartChanges(os,
3025 running_font = font;
3028 // Do we need to turn on LaTeX mode?
3029 if (font.latex() != running_font.latex()) {
3030 if (font.latex() == LyXFont::ON
3031 && style.needprotect) {
3036 SimpleTeXSpecialChars(buf, bparams,
3037 os, texrow, false, font,
3038 running_font, basefont,
3039 open_font, style, i, column, c);
3041 // If we have an open font definition, we have to close it
3043 running_font.latexWriteEndChanges(os, basefont,
3047 basefont = getFont(bparams, -1);
3048 running_font = basefont;
3049 cell = table->CellHasContRow(current_cell_number);
3051 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
3052 return return_value;
3057 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
3059 bool retval = false;
3061 case LyXParagraph::META_HFILL:
3062 sgml_string.erase();
3064 case LyXParagraph::META_NEWLINE:
3068 sgml_string = "&";
3071 sgml_string = "<";
3074 sgml_string = ">";
3077 sgml_string = "$";
3080 sgml_string = "#";
3083 sgml_string = "%";
3086 sgml_string = "[";
3089 sgml_string = "]";
3092 sgml_string = "{";
3095 sgml_string = "}";
3098 sgml_string = "˜";
3101 sgml_string = """;
3104 sgml_string = "\";
3110 case '\0': // Ignore :-)
3111 sgml_string.erase();
3122 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3123 ostream & os, string & extra,
3124 int & desc_on, int depth)
3126 BufferParams const & bparams = buffer->params;
3128 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3130 LyXFont font1, font2;
3133 size_type main_body;
3134 bool emph_flag = false;
3136 LyXLayout const & style =
3137 textclasslist.Style(bparams.textclass,
3140 if (style.labeltype != LABEL_MANUAL)
3143 main_body = BeginningOfMainBody();
3145 // Gets paragraph main font.
3147 font1 = style.labelfont;
3151 int char_line_count = depth;
3152 os << newlineAndDepth(depth);
3154 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3155 os << "<INFORMALTABLE>"
3156 << newlineAndDepth(++depth);
3159 os << "<INFORMALTABLE>"
3160 << newlineAndDepth(++depth);
3162 int current_cell_number = -1;
3163 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3165 // Parsing main loop.
3166 for (size_type i = 0; i < size(); ++i) {
3168 if (table->IsContRow(current_cell_number+1)) {
3169 if (c == LyXParagraph::META_NEWLINE)
3170 ++current_cell_number;
3175 // Fully instantiated font
3176 font2 = getFont(bparams, i);
3178 // Handle <emphasis> tag.
3179 if (font1.emph() != font2.emph() && i) {
3180 if (font2.emph() == LyXFont::ON) {
3183 } else if (emph_flag) {
3184 os << "</emphasis>";
3188 if (c == LyXParagraph::META_NEWLINE) {
3189 // We have only to control for emphasis open here!
3191 os << "</emphasis>";
3194 font1 = font2 = getFont(bparams, -1);
3195 ++current_cell_number;
3196 if (table->CellHasContRow(current_cell_number) >= 0) {
3197 DocBookContTableRows(buffer,
3198 os, extra, desc_on, i + 1,
3199 current_cell_number,
3202 // if this cell follow only ContRows till end don't
3203 // put the EndOfCell because it is put after the
3205 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3206 --current_cell_number;
3209 tmp = table->DocBookEndOfCell(os,
3210 current_cell_number,
3215 } else if (c == LyXParagraph::META_INSET) {
3216 inset = GetInset(i);
3218 std::ostringstream ost;
3219 inset->DocBook(buffer, ost);
3220 string tmp_out = ost.str().c_str();
3223 inset->DocBook(buffer, ost);
3225 char * ctmp = ost.str();
3226 string tmp_out(ctmp);
3230 // This code needs some explanation:
3231 // Two insets are treated specially
3232 // label if it is the first element in a
3233 // command paragraph
3235 // graphics inside tables or figure floats
3237 // title (the equivalente in latex for this
3239 // and title should come first
3242 if(desc_on != 3 || i != 0) {
3243 if(tmp_out[0] == '@') {
3245 extra += frontStrip(tmp_out,
3248 os << frontStrip(tmp_out,
3253 } else if (font2.latex() == LyXFont::ON) {
3254 // "TeX"-Mode on == > SGML-Mode on.
3260 if (linuxDocConvertChar(c, sgml_string)
3261 && !style.free_spacing) {
3262 // in freespacing mode, spaces are
3263 // non-breaking characters
3268 << "</term><listitem><para>";
3280 // Needed if there is an optional argument but no contents.
3281 if (main_body > 0 && main_body == size()) {
3286 os << "</emphasis>";
3289 ++current_cell_number;
3290 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3291 // Resets description flag correctly.
3294 // <term> not closed...
3299 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3301 os << "</INFORMALTABLE>";
3303 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3310 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3311 ostream & os, string & extra,
3313 LyXParagraph::size_type i,
3314 int current_cell_number, int &column)
3319 BufferParams const & bparams = buffer->params;
3321 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3326 //string emph = "emphasis";
3327 bool emph_flag = false;
3328 int char_line_count = 0;
3330 LyXLayout const & style =
3331 textclasslist.Style(bparams.textclass,
3334 size_type main_body;
3335 if (style.labeltype != LABEL_MANUAL)
3338 main_body = BeginningOfMainBody();
3340 // Gets paragraph main font.
3343 font1 = style.labelfont;
3347 size_type lastpos = i;
3348 int cell = table->CellHasContRow(current_cell_number);
3349 ++current_cell_number;
3351 // first find the right position
3353 for (; i < size() && current_cell_number < cell; ++i) {
3355 if (c == LyXParagraph::META_NEWLINE)
3356 ++current_cell_number;
3360 // I don't know how to handle this so I comment it
3361 // for the moment (Jug)
3362 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3363 // file += " \\\\\n";
3366 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3371 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3375 // Fully instantiated font
3376 font2 = getFont(bparams, i);
3378 // Handle <emphasis> tag.
3379 if (font1.emph() != font2.emph() && i) {
3380 if (font2.emph() == LyXFont::ON) {
3383 } else if (emph_flag) {
3384 os << "</emphasis>";
3388 if (c == LyXParagraph::META_INSET) {
3389 inset = GetInset(i);
3391 std::ostringstream ost;
3392 inset->DocBook(buffer, ost);
3393 string tmp_out = ost.str().c_str();
3396 inset->DocBook(buffer, ost);
3398 char * ctmp = ost.str();
3399 string tmp_out(ctmp);
3403 // This code needs some explanation:
3404 // Two insets are treated specially
3405 // label if it is the first element in a
3406 // command paragraph
3408 // graphics inside tables or figure floats
3409 // can't go on title (the equivalente in
3410 // latex for this case is caption and title
3411 // should come first
3414 if(desc_on != 3 || i != 0) {
3415 if(tmp_out[0] == '@') {
3417 extra += frontStrip(tmp_out, '@');
3419 os << frontStrip(tmp_out, '@');
3423 } else if (font2.latex() == LyXFont::ON) {
3424 // "TeX"-Mode on == > SGML-Mode on.
3430 if (linuxDocConvertChar(c, sgml_string)
3431 && !style.free_spacing) {
3432 // in freespacing mode, spaces are
3433 // non-breaking characters
3438 << "</term><listitem><para>";
3448 // we have only to control for emphasis open here!
3450 os << "</emphasis>";
3453 font1 = font2 = getFont(bparams, -1);
3454 cell = table->CellHasContRow(current_cell_number);
3456 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3461 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3462 LyXParagraph::size_type const i,
3463 int & column, LyXFont const & font,
3464 LyXLayout const & style)
3466 if (column > tex_code_break_column
3468 && GetChar(i - 1) != ' '
3470 // In LaTeX mode, we don't want to
3471 // break lines since some commands
3473 && ! (font.latex() == LyXFont::ON)
3474 // same in FreeSpacing mode
3475 && !style.free_spacing
3476 // In typewriter mode, we want to avoid
3477 // ! . ? : at the end of a line
3478 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3479 && (GetChar(i-1) == '.'
3480 || GetChar(i-1) == '?'
3481 || GetChar(i-1) == ':'
3482 || GetChar(i-1) == '!'))) {
3483 if (tex_code_break_column == 0) {
3484 // in batchmode we need LaTeX to still
3485 // see it as a space not as an extra '\n'
3491 texrow.start(this, i + 1);
3493 } else if (font.latex() == LyXFont::OFF) {
3494 if (style.free_spacing) {
3503 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3504 BufferParams const & bparams,
3505 ostream & os, TexRow & texrow,
3508 LyXFont & running_font,
3511 LyXLayout const & style,
3512 LyXParagraph::size_type & i,
3514 LyXParagraph::value_type const c)
3516 // Two major modes: LaTeX or plain
3517 // Handle here those cases common to both modes
3518 // and then split to handle the two modes separately.
3520 case LyXParagraph::META_INSET: {
3521 Inset * inset = GetInset(i);
3524 int len = os.tellp();
3525 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3526 || inset->LyxCode() == Inset::MATH_CODE
3527 || inset->LyxCode() == Inset::URL_CODE)
3528 && running_font.isRightToLeft()) {
3533 int tmp = inset->Latex(buf, os, moving_arg,
3534 style.free_spacing);
3542 column += os.tellp() - len;
3551 case LyXParagraph::META_NEWLINE:
3553 column += running_font.latexWriteEndChanges(os,
3558 basefont = getFont(bparams, -1);
3559 running_font = basefont;
3562 case LyXParagraph::META_HFILL:
3568 // And now for the special cases within each mode
3569 // Are we in LaTeX mode?
3570 if (font.latex() == LyXFont::ON) {
3571 // at present we only have one option
3572 // but I'll leave it as a switch statement
3573 // so its simpler to extend. (ARRae)
3576 // make sure that we will not print
3577 // error generating chars to the tex
3578 // file. This test would not be needed
3579 // if it were done in the buffer
3587 // Plain mode (i.e. not LaTeX)
3590 os << "\\textbackslash{}";
3594 case '°': case '±': case '²': case '³':
3595 case '×': case '÷': case '¹': case 'ª':
3596 case 'º': case '¬': case 'µ':
3597 if (bparams.inputenc == "latin1" ||
3598 (bparams.inputenc == "auto" &&
3599 font.language()->encoding()->LatexName()
3601 os << "\\ensuremath{"
3610 case '|': case '<': case '>':
3611 // In T1 encoding, these characters exist
3612 if (lyxrc.fontenc == "T1") {
3614 //... but we should avoid ligatures
3615 if ((c == '>' || c == '<')
3617 && GetChar(i + 1) == c) {
3618 //os << "\\textcompwordmark{}";
3619 // Jean-Marc, have a look at
3620 // this. IÂ think this works
3628 // Typewriter font also has them
3629 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3633 // Otherwise, we use what LaTeX
3637 os << "\\textless{}";
3641 os << "\\textgreater{}";
3645 os << "\\textbar{}";
3651 case '-': // "--" in Typewriter mode -> "-{}-"
3653 && GetChar(i + 1) == '-'
3654 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3663 os << "\\char`\\\"{}";
3668 if (bparams.inputenc == "default") {
3677 case '%': case '#': case '{':
3684 os << "\\textasciitilde{}";
3689 os << "\\textasciicircum{}";
3693 case '*': case '[': case ']':
3694 // avoid being mistaken for optional arguments
3695 os << '{' << c << '}';
3700 // Blanks are printed before font switching.
3701 // Sure? I am not! (try nice-latex)
3702 // I am sure it's correct. LyX might be smarter
3703 // in the future, but for now, nothing wrong is
3708 /* idea for labels --- begin*/
3712 && font.family() != LyXFont::TYPEWRITER_FAMILY
3713 && GetChar(i + 1) == 'y'
3714 && GetChar(i + 2) == 'X') {
3722 && font.family() != LyXFont::TYPEWRITER_FAMILY
3723 && GetChar(i + 1) == 'e'
3724 && GetChar(i + 2) == 'X') {
3729 // Check for "LaTeX2e"
3732 && font.family() != LyXFont::TYPEWRITER_FAMILY
3733 && GetChar(i + 1) == 'a'
3734 && GetChar(i + 2) == 'T'
3735 && GetChar(i + 3) == 'e'
3736 && GetChar(i + 4) == 'X'
3737 && GetChar(i + 5) == '2'
3738 && GetChar(i + 6) == 'e') {
3743 // Check for "LaTeX"
3746 && font.family() != LyXFont::TYPEWRITER_FAMILY
3747 && GetChar(i + 1) == 'a'
3748 && GetChar(i + 2) == 'T'
3749 && GetChar(i + 3) == 'e'
3750 && GetChar(i + 4) == 'X') {
3754 /* idea for labels --- end*/
3755 } else if (c != '\0') {
3765 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3766 BufferParams const & bparams,
3767 ostream & os, TexRow & texrow
3770 TexRow & foot_texrow,
3775 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3776 LyXParagraph * par = this;
3779 (par->depth == depth)
3781 && (par->footnoteflag == footnoteflag)
3786 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3788 if (textclasslist.Style(bparams.textclass,
3789 par->layout).isEnvironment()
3790 || par->pextra_type != PEXTRA_NONE) {
3791 par = par->TeXEnvironment(buf, bparams,
3799 par = par->TeXOnePar(buf, bparams,
3809 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3815 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3816 BufferParams const & bparams,
3817 ostream & os, TexRow & texrow
3820 TexRow & foot_texrow,
3825 bool eindent_open = false;
3827 bool foot_this_level = false;
3829 // flags when footnotetext should be appended to file.
3830 static bool minipage_open = false;
3831 static int minipage_open_depth = 0;
3832 char par_sep = bparams.paragraph_separation;
3834 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3837 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3840 LyXLayout const & style =
3841 textclasslist.Style(bparams.textclass,
3844 if (pextra_type == PEXTRA_INDENT) {
3845 if (!pextra_width.empty()) {
3846 os << "\\begin{LyXParagraphIndent}{"
3847 << pextra_width << "}\n";
3849 //float ib = atof(pextra_widthp.c_str())/100;
3850 // string can't handle floats at present (971109)
3851 // so I'll do a conversion by hand knowing that
3852 // the limits are 0.0 to 1.0. ARRae.
3853 os << "\\begin{LyXParagraphIndent}{";
3854 switch (pextra_widthp.length()) {
3866 os << "\\columnwidth}\n";
3869 eindent_open = true;
3871 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3872 if (pextra_hfill && Previous() &&
3873 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3874 os << "\\hfill{}\n";
3877 if (par_sep == BufferParams::PARSEP_INDENT) {
3878 os << "{\\setlength\\parindent{0pt}\n";
3881 os << "\\begin{minipage}";
3882 switch(pextra_alignment) {
3883 case MINIPAGE_ALIGN_TOP:
3886 case MINIPAGE_ALIGN_MIDDLE:
3889 case MINIPAGE_ALIGN_BOTTOM:
3893 if (!pextra_width.empty()) {
3894 os << '{' << pextra_width << "}\n";
3896 //float ib = atof(par->pextra_width.c_str())/100;
3897 // string can't handle floats at present
3898 // so I'll do a conversion by hand knowing that
3899 // the limits are 0.0 to 1.0. ARRae.
3901 switch (pextra_widthp.length()) {
3913 os << "\\columnwidth}\n";
3916 if (par_sep == BufferParams::PARSEP_INDENT) {
3917 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3920 minipage_open = true;
3921 minipage_open_depth = depth;
3924 #ifdef WITH_WARNINGS
3925 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3926 //I disabled it because it breaks when lists span on several
3929 if (style.isEnvironment()){
3930 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3931 #ifdef FANCY_FOOTNOTE_CODE
3932 if (foot_count < 0) {
3933 // flag that footnote[mark][text] should be
3934 // used for any footnotes from now on
3936 foot_this_level = true;
3939 os << "\\begin{" << style.latexname() << "}{"
3940 << labelwidthstring << "}\n";
3941 } else if (style.labeltype == LABEL_BIBLIO) {
3943 os << "\\begin{" << style.latexname() << "}{"
3944 << bibitemWidest(current_view)
3946 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3947 #ifdef FANCY_FOOTNOTE_CODE
3948 if (foot_count < 0) {
3949 // flag that footnote[mark][text] should be
3950 // used for any footnotes from now on
3952 foot_this_level = true;
3955 os << "\\begin{" << style.latexname() << '}'
3956 << style.latexparam() << '\n';
3958 os << "\\begin{" << style.latexname() << '}'
3959 << style.latexparam() << '\n';
3962 LyXParagraph * par = this;
3964 par = par->TeXOnePar(buf, bparams,
3968 foot, foot_texrow, foot_count
3972 if (minipage_open && par && !style.isEnvironment() &&
3973 (par->pextra_type == PEXTRA_MINIPAGE) &&
3974 par->pextra_start_minipage) {
3975 os << "\\end{minipage}\n";
3977 if (par_sep == BufferParams::PARSEP_INDENT) {
3981 minipage_open = false;
3983 if (par && par->depth > depth) {
3984 if (textclasslist.Style(bparams.textclass,
3985 par->layout).isParagraph()
3990 // How to handle this? (Lgb)
3991 //&& !suffixIs(os, "\n\n")
3993 // There should be at least one '\n' already
3994 // but we need there to be two for Standard
3995 // paragraphs that are depth-increment'ed to be
3996 // output correctly. However, tables can
3997 // also be paragraphs so don't adjust them.
4000 // Will it ever harm to have one '\n' too
4001 // many? i.e. that we sometimes will have
4002 // three in a row. (Lgb)
4006 par = par->TeXDeeper(buf, bparams, os, texrow
4008 ,foot, foot_texrow, foot_count
4012 if (par && par->layout == layout && par->depth == depth &&
4013 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
4014 if (par->pextra_hfill && par->Previous() &&
4015 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
4016 os << "\\hfill{}\n";
4019 if (par_sep == BufferParams::PARSEP_INDENT) {
4020 os << "{\\setlength\\parindent{0pt}\n";
4023 os << "\\begin{minipage}";
4024 switch(par->pextra_alignment) {
4025 case MINIPAGE_ALIGN_TOP:
4028 case MINIPAGE_ALIGN_MIDDLE:
4031 case MINIPAGE_ALIGN_BOTTOM:
4035 if (!par->pextra_width.empty()) {
4036 os << '{' << par->pextra_width << "}\n";
4038 //float ib = atof(par->pextra_widthp.c_str())/100;
4039 // string can't handle floats at present
4040 // so I'll do a conversion by hand knowing that
4041 // the limits are 0.0 to 1.0. ARRae.
4043 switch (par->pextra_widthp.length()) {
4048 os << "0." << par->pextra_widthp;
4051 os << "0.0" << par->pextra_widthp;
4053 os << "\\columnwidth}\n";
4056 if (par_sep == BufferParams::PARSEP_INDENT) {
4057 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
4060 minipage_open = true;
4061 minipage_open_depth = par->depth;
4064 && par->layout == layout
4065 && par->depth == depth
4066 && par->pextra_type == pextra_type
4068 && par->footnoteflag == footnoteflag
4072 if (style.isEnvironment()) {
4073 os << "\\end{" << style.latexname() << '}';
4075 // maybe this should go after the minipage closes?
4076 if (foot_this_level) {
4077 if (foot_count >= 1) {
4078 if (foot_count > 1) {
4079 os << "\\addtocounter{footnote}{-"
4084 texrow += foot_texrow;
4086 foot_texrow.reset();
4092 if (minipage_open && (minipage_open_depth == depth) &&
4093 (!par || par->pextra_start_minipage ||
4094 par->pextra_type != PEXTRA_MINIPAGE)) {
4095 os << "\\end{minipage}\n";
4097 if (par_sep == BufferParams::PARSEP_INDENT) {
4101 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4102 os << "\\medskip\n\n";
4106 minipage_open = false;
4109 os << "\\end{LyXParagraphIndent}\n";
4112 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4113 && par->pextra_hfill)) {
4117 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4118 return par; // ale970302
4123 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4124 BufferParams const & bparams,
4125 ostream & os, TexRow & texrow,
4126 ostream & foot, TexRow & foot_texrow,
4130 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4131 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4132 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4133 "No footnote!" << endl;
4135 LyXParagraph * par = this;
4136 LyXLayout const & style =
4137 textclasslist.Style(bparams.textclass,
4138 previous->GetLayout());
4140 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4141 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4142 "Float other than footnote in command"
4143 " with moving argument is illegal" << endl;
4146 if (footnotekind != LyXParagraph::FOOTNOTE
4147 && footnotekind != LyXParagraph::MARGIN
4150 // How to solve this?
4151 //&& !suffixIs(file, '\n')
4153 // we need to ensure that real floats like tables and figures
4154 // have their \begin{} on a new line otherwise we can get
4155 // incorrect results when using the endfloat.sty package
4156 // especially if two floats follow one another. ARRae 981022
4157 // NOTE: if the file is length 0 it must have just been
4158 // written out so we assume it ended with a '\n'
4160 // As far as I can see there is never any harm in writing
4161 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4166 bool moving_arg = false;
4167 bool need_closing = false;
4168 bool is_rtl = isRightToLeftPar(bparams);
4170 if (is_rtl != parent_is_rtl) {
4175 need_closing = true;
4178 //BufferParams * params = ¤t_view->buffer()->params;
4179 bool footer_in_body = true;
4180 switch (footnotekind) {
4181 case LyXParagraph::FOOTNOTE:
4182 if (style.intitle) {
4183 os << "\\thanks{\n";
4184 footer_in_body = false;
4187 if (foot_count == -1) {
4188 // we're at depth 0 so we can use:
4189 os << "\\footnote{%\n";
4190 footer_in_body = false;
4192 os << "\\footnotemark{}%\n";
4194 // we only need this when there are
4195 // multiple footnotes
4196 os << "\\stepcounter{footnote}";
4198 os << "\\footnotetext{%\n";
4199 foot_texrow.start(this, 0);
4200 foot_texrow.newline();
4205 case LyXParagraph::MARGIN:
4206 os << "\\marginpar{\n";
4208 case LyXParagraph::FIG:
4209 if (pextra_type == PEXTRA_FLOATFLT
4210 && (!pextra_width.empty()
4211 || !pextra_widthp.empty())) {
4212 if (!pextra_width.empty())
4213 os << "\\begin{floatingfigure}{"
4214 << pextra_width << "}\n";
4216 os << "\\begin{floatingfigure}{"
4217 << atoi(pextra_widthp.c_str())/100.0
4218 << "\\textwidth}\n";
4220 os << "\\begin{figure}";
4221 if (!bparams.float_placement.empty()) {
4222 os << '[' << bparams.float_placement << "]\n";
4228 case LyXParagraph::TAB:
4229 os << "\\begin{table}";
4230 if (!bparams.float_placement.empty()) {
4231 os << '[' << bparams.float_placement << "]\n";
4236 case LyXParagraph::WIDE_FIG:
4237 os << "\\begin{figure*}";
4238 if (!bparams.float_placement.empty()) {
4239 os << '[' << bparams.float_placement << "]\n";
4244 case LyXParagraph::WIDE_TAB:
4245 os << "\\begin{table*}";
4246 if (!bparams.float_placement.empty()) {
4247 os << '[' << bparams.float_placement << "]\n";
4252 case LyXParagraph::ALGORITHM:
4253 os << "\\begin{algorithm}\n";
4258 if (footnotekind != LyXParagraph::FOOTNOTE
4259 || !footer_in_body) {
4260 // Process text for all floats except footnotes in body
4262 LyXLayout const & style =
4264 .Style(bparams.textclass, par->layout);
4266 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4268 if (style.isEnvironment()
4269 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4270 // Allows the use of minipages within float
4271 // environments. Shouldn't be circular because
4272 // we don't support footnotes inside
4273 // floats (yet). ARRae
4274 par = par->TeXEnvironment(buf, bparams, os,
4279 par = par->TeXOnePar(buf, bparams,
4280 os, texrow, moving_arg,
4285 if (par && !par->IsDummy() && par->depth > depth) {
4286 par = par->TeXDeeper(buf, bparams, os, texrow,
4290 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4292 // process footnotes > depth 0 or in environments separately
4293 // NOTE: Currently don't support footnotes within footnotes
4294 // even though that is possible using the \footnotemark
4296 std::ostringstream dummy;
4300 TexRow dummy_texrow;
4301 int dummy_count = 0;
4303 LyXLayout const & style =
4305 .Style(bparams.textclass, par->layout);
4307 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4309 if (style.isEnvironment()
4310 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4311 // Allows the use of minipages within float
4312 // environments. Shouldn't be circular because
4313 // we don't support footnotes inside
4314 // floats (yet). ARRae
4315 par = par->TeXEnvironment(buf, bparams,
4317 dummy, dummy_texrow,
4320 par = par->TeXOnePar(buf, bparams,
4323 dummy, dummy_texrow,
4327 if (par && !par->IsDummy() && par->depth > depth) {
4328 par = par->TeXDeeper(buf, bparams,
4330 dummy, dummy_texrow,
4334 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4336 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4337 "Footnote in a Footnote -- not supported"
4340 #ifndef HAVE_OSTREAM
4341 delete [] dummy.str();
4345 switch (footnotekind) {
4346 case LyXParagraph::FOOTNOTE:
4347 if (footer_in_body) {
4348 // This helps tell which of the multiple
4349 // footnotetexts an error was in.
4351 foot_texrow.newline();
4356 case LyXParagraph::MARGIN:
4359 case LyXParagraph::FIG:
4360 if (pextra_type == PEXTRA_FLOATFLT
4361 && (!pextra_width.empty()
4362 || !pextra_widthp.empty()))
4363 os << "\\end{floatingfigure}";
4365 os << "\\end{figure}";
4367 case LyXParagraph::TAB:
4368 os << "\\end{table}";
4370 case LyXParagraph::WIDE_FIG:
4371 os << "\\end{figure*}";
4373 case LyXParagraph::WIDE_TAB:
4374 os << "\\end{table*}";
4376 case LyXParagraph::ALGORITHM:
4377 os << "\\end{algorithm}";
4384 if (footnotekind != LyXParagraph::FOOTNOTE
4385 && footnotekind != LyXParagraph::MARGIN) {
4386 // we need to ensure that real floats like tables and figures
4387 // have their \end{} on a line of their own otherwise we can
4388 // get incorrect results when using the endfloat.sty package.
4393 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4398 bool LyXParagraph::IsDummy() const
4400 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4401 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4405 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4406 int type, char const * width,
4407 char const * widthp)
4410 pextra_width = width;
4411 pextra_widthp = widthp;
4413 if (textclasslist.Style(bparams.textclass,
4414 layout).isEnvironment()) {
4415 LyXParagraph * par = this;
4416 LyXParagraph * ppar = par;
4418 while (par && (par->layout == layout)
4419 && (par->depth == depth)) {
4421 par = par->Previous();
4424 par = par->FirstPhysicalPar();
4426 while (par && par->depth > depth) {
4427 par = par->Previous();
4430 par = par->FirstPhysicalPar();
4435 while (par && (par->layout == layout)
4436 && (par->depth == depth)) {
4437 par->pextra_type = type;
4438 par->pextra_width = width;
4439 par->pextra_widthp = widthp;
4441 par = par->NextAfterFootnote();
4445 if (par && (par->depth > depth))
4446 par->SetPExtraType(bparams,
4447 type, width, widthp);
4449 while (par && ((par->depth > depth) || par->IsDummy()))
4450 par = par->NextAfterFootnote();
4452 while (par && ((par->depth > depth)))
4460 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4462 if (pextra_type == PEXTRA_NONE)
4465 pextra_type = PEXTRA_NONE;
4466 pextra_width.erase();
4467 pextra_widthp.erase();
4469 if (textclasslist.Style(bparams.textclass,
4470 layout).isEnvironment()) {
4471 LyXParagraph * par = this;
4472 LyXParagraph * ppar = par;
4474 while (par && (par->layout == layout)
4475 && (par->depth == depth)) {
4477 par = par->Previous();
4480 par = par->FirstPhysicalPar();
4482 while (par && par->depth > depth) {
4483 par = par->Previous();
4486 par = par->FirstPhysicalPar();
4491 while (par && (par->layout == layout)
4492 && (par->depth == depth)) {
4493 par->pextra_type = PEXTRA_NONE;
4494 par->pextra_width.erase();
4495 par->pextra_widthp.erase();
4497 par = par->NextAfterFootnote();
4501 if (par && (par->depth > depth))
4502 par->UnsetPExtraType(bparams);
4504 while (par && ((par->depth > depth) || par->IsDummy()))
4505 par = par->NextAfterFootnote();
4507 while (par && ((par->depth > depth)))
4515 bool LyXParagraph::IsHfill(size_type pos) const
4517 return IsHfillChar(GetChar(pos));
4521 bool LyXParagraph::IsInset(size_type pos) const
4523 return IsInsetChar(GetChar(pos));
4528 bool LyXParagraph::IsFloat(size_type pos) const
4530 return IsFloatChar(GetChar(pos));
4535 bool LyXParagraph::IsNewline(size_type pos) const
4537 return pos >= 0 && IsNewlineChar(GetChar(pos));
4541 bool LyXParagraph::IsSeparator(size_type pos) const
4543 return IsSeparatorChar(GetChar(pos));
4547 bool LyXParagraph::IsLineSeparator(size_type pos) const
4549 return IsLineSeparatorChar(GetChar(pos));
4553 bool LyXParagraph::IsKomma(size_type pos) const
4555 return IsKommaChar(GetChar(pos));
4559 /// Used by the spellchecker
4560 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4562 value_type c = GetChar(pos);
4563 if (IsLetterChar(c))
4565 // '\0' is not a letter, allthough every string contains "" (below)
4568 // We want to pass the ' and escape chars to ispell
4569 string extra = lyxrc.isp_esc_chars + '\'';
4570 char ch[2] = { c, 0 };
4571 return contains(extra, ch);
4575 bool LyXParagraph::IsWord(size_type pos ) const
4577 return IsWordChar(GetChar(pos)) ;
4582 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4586 return FirstPhysicalPar()->getParLanguage(bparams);
4593 return GetFirstFontSettings().language();
4596 for (size_type pos = 0; pos < size(); ++pos)
4598 return GetFontSettings(bparams, pos).language();
4599 return GetFirstFontSettings().language();
4603 return previous->getParLanguage(bparams);
4605 return bparams.language_info;
4609 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4611 return lyxrc.rtl_support
4615 && getParLanguage(bparams)->RightToLeft();
4619 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4620 Language const * from, Language const * to)
4622 for(size_type i = 0; i < size(); ++i) {
4623 LyXFont font = GetFontSettings(bparams, i);
4624 if (font.language() == from) {
4625 font.setLanguage(to);
4632 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4634 Language const * doc_language = bparams.language_info;
4635 for (FontList::const_iterator cit = fontlist.begin();
4636 cit != fontlist.end(); ++cit)
4637 if ((*cit).font.language() != doc_language)
4643 // Convert the paragraph to a string.
4644 // Used for building the table of contents
4645 string LyXParagraph::String(Buffer const * buffer, bool label)
4647 BufferParams const & bparams = buffer->params;
4650 if (label && !IsDummy() && !labelstring.empty())
4652 if (label && !labelstring.empty())
4654 s += labelstring + ' ';
4655 string::size_type len = s.size();
4657 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4658 value_type c = GetChar(i);
4661 else if (c == META_INSET &&
4662 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4664 std::ostringstream ost;
4665 GetInset(i)->Ascii(buffer, ost);
4668 GetInset(i)->Ascii(buffer, ost);
4671 s += subst(ost.str(),'\n',' ');
4676 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4677 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4678 s += NextAfterFootnote()->String(buffer, false);
4682 if (isRightToLeftPar(bparams))
4683 reverse(s.begin() + len,s.end());
4691 string LyXParagraph::String(Buffer const * buffer,
4692 LyXParagraph::size_type beg,
4693 LyXParagraph::size_type end)
4700 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4702 if (cell >= table->NumberOfCellsInRow(actcell))
4711 if (beg == 0 && !IsDummy() && !labelstring.empty())
4713 if (beg == 0 && !labelstring.empty())
4715 s += labelstring + ' ';
4717 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4718 value_type c = GetChar(i);
4721 else if (c == META_INSET) {
4723 std::ostringstream ost;
4724 GetInset(i)->Ascii(buffer, ost);
4727 GetInset(i)->Ascii(buffer, ost);
4733 else if (table && IsNewlineChar(c)) {
4734 if (cell >= table->NumberOfCellsInRow(actcell)) {
4750 void LyXParagraph::SetInsetOwner(Inset *i)
4753 for (InsetList::const_iterator cit = insetlist.begin();
4754 cit != insetlist.end(); ++cit) {
4756 (*cit).inset->setOwner(i);
4761 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4764 for (InsetList::const_iterator cit = insetlist.begin();
4765 cit != insetlist.end(); ++cit) {
4767 if ((*cit).inset->IsTextInset()) {
4768 static_cast<UpdatableInset *>
4769 ((*cit).inset)->deleteLyXText(bv);
4776 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4779 for (InsetList::const_iterator cit = insetlist.begin();
4780 cit != insetlist.end(); ++cit) {
4782 if ((*cit).inset->IsTextInset()) {
4783 static_cast<UpdatableInset *>
4784 ((*cit).inset)->resizeLyXText(bv);