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
92 // Insert the main counters
93 // Should later (asap) be moved to layout files
94 counters.newCounter("part");
95 counters.newCounter("section");
96 counters.newCounter("subsection", "section");
97 counters.newCounter("subsubsection", "subsection");
98 counters.newCounter("paragraph", "subsubsection");
99 counters.newCounter("subparagraph", "paragraph");
104 // This konstruktor inserts the new paragraph in a list.
105 LyXParagraph::LyXParagraph(LyXParagraph * par)
108 par->text.resize(par->text.size());
110 for (int i = 0; i < 10; ++i) setCounter(i, 0);
114 // double linked list begin
117 next->previous = this;
119 previous->next = this;
122 footnoteflag = LyXParagraph::NO_FOOTNOTE;
123 footnotekind = LyXParagraph::FOOTNOTE;
126 /* table stuff -- begin*/
128 /* table stuff -- end*/
131 id_ = paragraph_id++;
133 bibkey = 0; // ale970302
137 // Insert the main counters
138 // Should later (asap) be moved to layout files
139 counters.newCounter("part");
140 counters.newCounter("section");
141 counters.newCounter("subsection", "section");
142 counters.newCounter("subsubsection", "subsection");
143 counters.newCounter("paragraph", "subsubsection");
144 counters.newCounter("subparagraph", "paragraph");
149 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
150 BufferParams const & params,
151 char footflag, char dth) const
153 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
155 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
157 // The beginning or the end of a footnote environment?
158 if (footflag != footnoteflag) {
159 footflag = footnoteflag;
161 os << "\n\\begin_float "
162 << string_footnotekinds[footnotekind]
165 os << "\n\\end_float ";
169 // The beginning or end of a deeper (i.e. nested) area?
172 while (depth > dth) {
173 os << "\n\\begin_deeper ";
177 while (depth < dth) {
178 os << "\n\\end_deeper ";
184 // First write the layout
186 << textclasslist.NameOfLayout(params.textclass, layout)
189 // Maybe some vertical spaces.
190 if (added_space_top.kind() != VSpace::NONE)
191 os << "\\added_space_top "
192 << added_space_top.asLyXCommand() << " ";
193 if (added_space_bottom.kind() != VSpace::NONE)
194 os << "\\added_space_bottom "
195 << added_space_bottom.asLyXCommand() << " ";
197 // Maybe the paragraph has special spacing
198 spacing.writeFile(os, true);
200 // The labelwidth string used in lists.
201 if (!labelwidthstring.empty())
202 os << "\\labelwidthstring "
203 << labelwidthstring << '\n';
205 // Lines above or below?
209 os << "\\line_bottom ";
211 // Pagebreaks above or below?
213 os << "\\pagebreak_top ";
214 if (pagebreak_bottom)
215 os << "\\pagebreak_bottom ";
217 // Start of appendix?
218 if (start_of_appendix)
219 os << "\\start_of_appendix ";
226 if (align != LYX_ALIGN_LAYOUT) {
229 case LYX_ALIGN_LEFT: h = 1; break;
230 case LYX_ALIGN_RIGHT: h = 2; break;
231 case LYX_ALIGN_CENTER: h = 3; break;
232 default: h = 0; break;
234 os << "\\align " << string_align[h] << " ";
236 if (pextra_type != PEXTRA_NONE) {
237 os << "\\pextra_type " << pextra_type;
238 if (pextra_type == PEXTRA_MINIPAGE) {
239 os << " \\pextra_alignment "
242 os << " \\pextra_hfill "
244 if (pextra_start_minipage)
245 os << " \\pextra_start_minipage "
246 << pextra_start_minipage;
248 if (!pextra_width.empty()) {
249 os << " \\pextra_width "
250 << VSpace(pextra_width).asLyXCommand();
251 } else if (!pextra_widthp.empty()) {
252 os << " \\pextra_widthp "
258 // Dummy layout. This means that a footnote ended.
259 os << "\n\\end_float ";
260 footflag = LyXParagraph::NO_FOOTNOTE;
263 // It might be a table.
265 os << "\\LyXTable\n";
271 bibkey->Write(buf, os);
273 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
276 for (size_type i = 0; i < size(); ++i) {
282 // Write font changes
283 LyXFont font2 = GetFontSettings(params, i);
284 if (font2 != font1) {
285 font2.lyxWriteChanges(font1, os);
290 value_type c = GetChar(i);
294 Inset const * inset = GetInset(i);
296 if (inset->DirectWrite()) {
297 // international char, let it write
298 // code directly so it's shorter in
300 inset->Write(buf, os);
302 os << "\n\\begin_inset ";
303 inset->Write(buf, os);
304 os << "\n\\end_inset \n\n";
310 os << "\n\\newline \n";
314 os << "\n\\hfill \n";
318 os << "\n\\backslash \n";
322 if (i + 1 < size() && GetChar(i + 1) == ' ') {
329 if ((column > 70 && c == ' ')
334 // this check is to amend a bug. LyX sometimes
335 // inserts '\0' this could cause problems.
339 lyxerr << "ERROR (LyXParagraph::writeFile):"
340 " NULL char in structure." << endl;
346 // now write the next paragraph
348 next->writeFile(buf, os, params, footflag, dth);
352 void LyXParagraph::validate(LaTeXFeatures & features) const
354 BufferParams const & params = features.bufferParams();
356 // this will be useful later
357 LyXLayout const & layout =
358 textclasslist.Style(params.textclass,
362 if (line_top || line_bottom)
363 features.lyxline = true;
364 if (!spacing.isDefault())
365 features.setspace = true;
368 features.layout[GetLayout()] = true;
371 Language const * doc_language = params.language_info;
373 for (FontList::const_iterator cit = fontlist.begin();
374 cit != fontlist.end(); ++cit) {
375 if ((*cit).font.noun() == LyXFont::ON) {
376 lyxerr[Debug::LATEX] << "font.noun: "
377 << (*cit).font.noun()
379 features.noun = true;
380 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
381 << (*cit).font.stateText(0)
384 switch ((*cit).font.color()) {
386 case LColor::inherit:
390 features.color = true;
391 lyxerr[Debug::LATEX] << "Color enabled. Font: "
392 << (*cit).font.stateText(0)
396 Language const * language = (*cit).font.language();
397 if (language != doc_language) {
398 features.UsedLanguages.insert(language);
399 lyxerr[Debug::LATEX] << "Found language "
400 << language->lang() << endl;
405 for (InsetList::const_iterator cit = insetlist.begin();
406 cit != insetlist.end(); ++cit) {
408 (*cit).inset->Validate(features);
411 if (table && table->IsLongTable())
412 features.longtable = true;
413 if (pextra_type == PEXTRA_INDENT)
414 features.LyXParagraphIndent = true;
415 if (pextra_type == PEXTRA_FLOATFLT)
416 features.floatflt = true;
417 if (layout.needprotect
418 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
419 features.NeedLyXFootnoteCode = true;
420 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
421 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
422 features.NeedLyXMinipageIndent = true;
423 if (table && table->NeedRotating())
424 features.rotating = true;
425 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
426 features.algorithm = true;
430 // First few functions needed for cut and paste and paragraph breaking.
431 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
432 LyXParagraph::size_type pos) const
434 minibuffer_char = GetChar(pos);
435 minibuffer_font = GetFontSettings(bparams, pos);
436 minibuffer_inset = 0;
437 if (minibuffer_char == LyXParagraph::META_INSET) {
439 minibuffer_inset = GetInset(pos)->Clone();
441 minibuffer_inset = 0;
442 minibuffer_char = ' ';
443 // This reflects what GetInset() does (ARRae)
449 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
450 LyXParagraph::size_type pos)
452 minibuffer_char = GetChar(pos);
453 minibuffer_font = GetFontSettings(bparams, pos);
454 minibuffer_inset = 0;
455 if (minibuffer_char == LyXParagraph::META_INSET) {
457 minibuffer_inset = GetInset(pos);
458 // This is a little hack since I want exactly
459 // the inset, not just a clone. Otherwise
460 // the inset would be deleted when calling Erase(pos)
462 InsetTable search_elem(pos, 0);
463 InsetList::iterator it =
464 lower_bound(insetlist.begin(),
466 search_elem, matchIT());
467 if (it != insetlist.end() && (*it).pos == pos)
470 minibuffer_inset = 0;
471 minibuffer_char = ' ';
472 // This reflects what GetInset() does (ARRae)
477 // Erase(pos); now the caller is responsible for that.
481 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
483 if ((minibuffer_char == LyXParagraph::META_INSET) &&
484 !InsertInsetAllowed(minibuffer_inset))
486 if (minibuffer_char == LyXParagraph::META_INSET)
487 InsertInset(pos, minibuffer_inset, minibuffer_font);
489 InsertChar(pos, minibuffer_char, minibuffer_font);
497 void LyXParagraph::Clear()
502 pagebreak_top = false;
503 pagebreak_bottom = false;
505 added_space_top = VSpace(VSpace::NONE);
506 added_space_bottom = VSpace(VSpace::NONE);
507 spacing.set(Spacing::Default);
509 align = LYX_ALIGN_LAYOUT;
513 pextra_type = PEXTRA_NONE;
514 pextra_width.erase();
515 pextra_widthp.erase();
516 pextra_alignment = MINIPAGE_ALIGN_TOP;
517 pextra_hfill = false;
518 pextra_start_minipage = false;
521 labelwidthstring.erase();
525 start_of_appendix = false;
529 // the destructor removes the new paragraph from the list
530 LyXParagraph::~LyXParagraph()
533 previous->next = next;
535 next->previous = previous;
537 for (InsetList::iterator it = insetlist.begin();
538 it != insetlist.end(); ++it) {
542 /* table stuff -- begin*/
544 /* table stuff -- end*/
550 //lyxerr << "LyXParagraph::paragraph_id = "
551 // << LyXParagraph::paragraph_id << endl;
555 void LyXParagraph::Erase(LyXParagraph::size_type pos)
557 // > because last is the next unused position, and you can
558 // use it if you want
561 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
562 NextAfterFootnote()->Erase(pos - text.size() - 1);
565 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
566 "position does not exist." << endl;
569 if (pos < size()) { // last is free for insertation, but should be empty
570 // if it is an inset, delete the inset entry
571 if (text[pos] == LyXParagraph::META_INSET) {
573 InsetTable search_inset(pos, 0);
574 InsetList::iterator it =
575 lower_bound(insetlist.begin(),
577 search_inset, matchIT());
578 if (it != insetlist.end() && (*it).pos == pos) {
583 text.erase(text.begin() + pos);
585 // Erase entries in the tables.
586 FontTable search_font(pos, LyXFont());
588 FontList::iterator it =
589 lower_bound(fontlist.begin(),
591 search_font, matchFT());
592 if (it != fontlist.end() && (*it).pos == pos &&
594 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
595 // If it is a multi-character font
596 // entry, we just make it smaller
597 // (see update below), otherwise we
599 unsigned int i = it - fontlist.begin();
600 fontlist.erase(fontlist.begin() + i);
601 it = fontlist.begin() + i;
602 if (i > 0 && i < fontlist.size() &&
603 fontlist[i-1].font == fontlist[i].font) {
604 fontlist.erase(fontlist.begin() + i-1);
605 it = fontlist.begin() + i-1;
609 // Update all other entries.
610 for (; it != fontlist.end(); ++it)
613 // Update the inset table.
614 InsetTable search_inset(pos, 0);
615 for (InsetList::iterator it =
616 upper_bound(insetlist.begin(),
618 search_inset, matchIT());
619 it != insetlist.end(); ++it)
622 lyxerr << "ERROR (LyXParagraph::Erase): "
623 "can't erase non-existant char." << endl;
628 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
629 LyXParagraph::value_type c)
631 LyXFont f(LyXFont::ALL_INHERIT);
632 InsertChar(pos, c, f);
636 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
637 LyXParagraph::value_type c,
638 LyXFont const & font)
640 // > because last is the next unused position, and you can
641 // use it if you want
645 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
646 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
650 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
651 "position does not exist." << endl;
654 text.insert(text.begin() + pos, c);
655 // Update the font table.
656 FontTable search_font(pos, LyXFont());
657 for (FontList::iterator it = lower_bound(fontlist.begin(),
659 search_font, matchFT());
660 it != fontlist.end(); ++it)
663 // Update the inset table.
664 InsetTable search_inset(pos, 0);
665 for (InsetList::iterator it = lower_bound(insetlist.begin(),
667 search_inset, matchIT());
668 it != insetlist.end(); ++it)
675 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
678 LyXFont f(LyXFont::ALL_INHERIT);
679 InsertInset(pos, inset, f);
683 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
684 Inset * inset, LyXFont const & font)
688 // > because last is the next unused position, and you can
689 // use it if you want
693 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
695 ->InsertInset(pos - text.size() - 1,
699 lyxerr << "ERROR (LyXParagraph::InsertInset): "
700 "position does not exist: " << pos << endl;
704 InsertChar(pos, META_INSET, font);
705 Assert(text[pos] == META_INSET);
707 // Add a new entry in the inset table.
708 InsetTable search_inset(pos, 0);
709 InsetList::iterator it = lower_bound(insetlist.begin(),
711 search_inset, matchIT());
712 if (it != insetlist.end() && (*it).pos == pos)
713 lyxerr << "ERROR (LyXParagraph::InsertInset): "
714 "there is an inset in position: " << pos << endl;
716 insetlist.insert(it, InsetTable(pos, inset));
718 inset->setOwner(inset_owner);
722 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
724 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
727 return inset_owner->InsertInsetAllowed(inset);
732 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
737 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
738 return NextAfterFootnote()
739 ->GetInset(pos - text.size() - 1);
742 lyxerr << "ERROR (LyXParagraph::GetInset): "
743 "position does not exist: "
749 InsetTable search_inset(pos, 0);
750 InsetList::iterator it = lower_bound(insetlist.begin(),
752 search_inset, matchIT());
753 if (it != insetlist.end() && (*it).pos == pos)
756 lyxerr << "ERROR (LyXParagraph::GetInset): "
757 "Inset does not exist: " << pos << endl;
760 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
761 // Did this commenting out introduce a bug? So far I have not
762 // see any, please enlighten me. (Lgb)
763 // My guess is that since the inset does not exist, we might
764 // as well replace it with a space to prevent craches. (Asger)
769 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
774 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
775 return NextAfterFootnote()
776 ->GetInset(pos - text.size() - 1);
779 lyxerr << "ERROR (LyXParagraph::GetInset): "
780 "position does not exist: "
786 InsetTable search_inset(pos, 0);
787 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
789 search_inset, matchIT());
790 if (cit != insetlist.end() && (*cit).pos == pos)
793 lyxerr << "ERROR (LyXParagraph::GetInset): "
794 "Inset does not exist: " << pos << endl;
796 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
797 // Did this commenting out introduce a bug? So far I have not
798 // see any, please enlighten me. (Lgb)
799 // My guess is that since the inset does not exist, we might
800 // as well replace it with a space to prevent craches. (Asger)
805 // Gets uninstantiated font setting at position.
806 // Optimized after profiling. (Asger)
807 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
808 LyXParagraph::size_type pos) const
811 FontTable search_font(pos, LyXFont());
812 FontList::const_iterator cit = lower_bound(fontlist.begin(),
814 search_font, matchFT());
815 if (cit != fontlist.end())
818 // > because last is the next unused position, and you can
819 // use it if you want
820 else if (pos > size()) {
823 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
824 return NextAfterFootnote()
825 ->GetFontSettings(bparams,
826 pos - text.size() - 1);
829 // Why is it an error to ask for the font of a
830 // position that does not exist? Would it be
831 // enough for this to be enabled on debug?
832 // We want strict error checking, but it's ok to only
833 // have it when debugging. (Asger)
834 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
835 "position does not exist. "
836 << pos << " (" << static_cast<int>(pos)
838 } else if (pos > 0) {
839 return GetFontSettings(bparams, pos - 1);
840 } else // pos = size() = 0
841 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
843 return LyXFont(LyXFont::ALL_INHERIT);
846 // Gets uninstantiated font setting at position 0
847 LyXFont LyXParagraph::GetFirstFontSettings() const
850 if (!fontlist.empty())
851 return fontlist[0].font;
855 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
856 return NextAfterFootnote()->GetFirstFontSettings();
858 return LyXFont(LyXFont::ALL_INHERIT);
862 // Gets the fully instantiated font at a given position in a paragraph
863 // This is basically the same function as LyXText::GetFont() in text2.C.
864 // The difference is that this one is used for generating the LaTeX file,
865 // and thus cosmetic "improvements" are disallowed: This has to deliver
866 // the true picture of the buffer. (Asger)
867 // If position is -1, we get the layout font of the paragraph.
868 // If position is -2, we get the font of the manual label of the paragraph.
869 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
870 LyXParagraph::size_type pos) const
873 LyXLayout const & layout =
874 textclasslist.Style(bparams.textclass,
876 LyXParagraph::size_type main_body = 0;
877 if (layout.labeltype == LABEL_MANUAL)
878 main_body = BeginningOfMainBody();
883 layoutfont = layout.labelfont;
885 layoutfont = layout.font;
886 tmpfont = GetFontSettings(bparams, pos);
887 tmpfont.realize(layoutfont);
889 // process layoutfont for pos == -1 and labelfont for pos < -1
891 tmpfont = layout.font;
893 tmpfont = layout.labelfont;
894 tmpfont.setLanguage(getParLanguage(bparams));
897 // check for environment font information
898 char par_depth = GetDepth();
899 LyXParagraph const * par = this;
900 while (par && par_depth && !tmpfont.resolved()) {
901 par = par->DepthHook(par_depth - 1);
903 tmpfont.realize(textclasslist.
904 Style(bparams.textclass,
905 par->GetLayout()).font);
906 par_depth = par->GetDepth();
910 tmpfont.realize(textclasslist
911 .TextClass(bparams.textclass)
917 /// Returns the height of the highest font in range
919 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
920 LyXParagraph::size_type endpos) const
922 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
923 if (fontlist.empty())
926 FontTable end_search(endpos, LyXFont());
927 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
929 end_search, matchFT());
930 if (end_it != fontlist.end())
933 FontTable start_search(startpos, LyXFont());
934 for (FontList::const_iterator cit =
935 lower_bound(fontlist.begin(),
937 start_search, matchFT());
938 cit != end_it; ++cit) {
939 LyXFont::FONT_SIZE size = (*cit).font.size();
940 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
947 LyXParagraph::value_type
948 LyXParagraph::GetChar(LyXParagraph::size_type pos)
955 // > because last is the next unused position, and you can
956 // use it if you want
957 else if (pos > size()) {
959 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
960 return NextAfterFootnote()
961 ->GetChar(pos - text.size() - 1);
965 lyxerr << "ERROR (LyXParagraph::GetChar): "
966 "position does not exist."
967 << pos << " (" << static_cast<int>(pos)
969 // Assert(false); // This triggers sometimes...
978 // We should have a footnote environment.
979 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
980 // Notice that LyX does request the
981 // last char from time to time. (Asger)
982 //lyxerr << "ERROR (LyXParagraph::GetChar): "
983 // "expected footnote." << endl;
986 switch (next->footnotekind) {
987 case LyXParagraph::FOOTNOTE:
988 return LyXParagraph::META_FOOTNOTE;
989 case LyXParagraph::MARGIN:
990 return LyXParagraph::META_MARGIN;
991 case LyXParagraph::FIG:
992 case LyXParagraph::WIDE_FIG:
993 return LyXParagraph::META_FIG;
994 case LyXParagraph::TAB:
995 case LyXParagraph::WIDE_TAB:
996 return LyXParagraph::META_TAB;
997 case LyXParagraph::ALGORITHM:
998 return LyXParagraph::META_ALGORITHM;
1000 return '\0'; // to shut up gcc
1006 LyXParagraph::value_type
1007 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
1014 // > because last is the next unused position, and you can
1015 // use it if you want
1016 else if (pos > size()) {
1018 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1019 return NextAfterFootnote()
1020 ->GetChar(pos - text.size() - 1);
1024 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1025 "position does not exist."
1026 << pos << " (" << static_cast<int>(pos)
1034 // We should have a footnote environment.
1035 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1036 // Notice that LyX does request the
1037 // last char from time to time. (Asger)
1038 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1039 // "expected footnote." << endl;
1042 switch (next->footnotekind) {
1043 case LyXParagraph::FOOTNOTE:
1044 return LyXParagraph::META_FOOTNOTE;
1045 case LyXParagraph::MARGIN:
1046 return LyXParagraph::META_MARGIN;
1047 case LyXParagraph::FIG:
1048 case LyXParagraph::WIDE_FIG:
1049 return LyXParagraph::META_FIG;
1050 case LyXParagraph::TAB:
1051 case LyXParagraph::WIDE_TAB:
1052 return LyXParagraph::META_TAB;
1053 case LyXParagraph::ALGORITHM:
1054 return LyXParagraph::META_ALGORITHM;
1056 return '\0'; // to shut up gcc
1062 // return an string of the current word, and the end of the word in lastpos.
1063 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1067 // the current word is defined as starting at the first character
1068 // from the immediate left of lastpospos which meets the definition
1069 // of IsLetter(), continuing to the last character to the right
1070 // of this meeting IsLetter.
1076 // move back until we have a letter
1078 //there's no real reason to have firstpos & lastpos as
1079 //separate variables as this is written, but maybe someon
1080 // will want to return firstpos in the future.
1082 //since someone might have typed a punctuation first
1083 int firstpos = lastpos;
1085 while ((firstpos >= 0) && !IsLetter(firstpos))
1088 // now find the beginning by looking for a nonletter
1090 while ((firstpos>= 0) && IsLetter(firstpos))
1093 // the above is now pointing to the preceeding non-letter
1097 // so copy characters into theword until we get a nonletter
1098 // note that this can easily exceed lastpos, wich means
1099 // that if used in the middle of a word, the whole word
1102 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1109 LyXParagraph::size_type LyXParagraph::Last() const
1112 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1113 return text.size() + NextAfterFootnote()->Last() + 1;
1114 // the 1 is the symbol
1122 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1124 // > because last is the next unused position, and you can
1125 // use it if you want
1129 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1130 return NextAfterFootnote()
1131 ->ParFromPos(pos - text.size() - 1);
1134 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1135 "position does not exist." << endl;
1142 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1144 // > because last is the next unused position, and you can
1145 // use it if you want
1149 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1150 return NextAfterFootnote()
1151 ->PositionInParFromPos(pos - text.size() - 1);
1155 "ERROR (LyXParagraph::PositionInParFromPos): "
1156 "position does not exist." << endl;
1164 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1165 LyXFont const & font)
1167 // > because last is the next unused position, and you can
1168 // use it if you want
1172 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1173 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1177 lyxerr << "ERROR (LyXParagraph::SetFont): "
1178 "position does not exist." << endl;
1183 // First, reduce font against layout/label font
1184 // Update: The SetCharFont() routine in text2.C already
1185 // reduces font, so we don't need to do that here. (Asger)
1186 // No need to simplify this because it will disappear
1187 // in a new kernel. (Asger)
1188 // Next search font table
1190 FontTable search_font(pos, LyXFont());
1191 FontList::iterator it = lower_bound(fontlist.begin(),
1193 search_font, matchFT());
1194 unsigned int i = it - fontlist.begin();
1195 bool notfound = it == fontlist.end();
1197 if (!notfound && fontlist[i].font == font)
1200 bool begin = pos == 0 || notfound ||
1201 (i > 0 && fontlist[i-1].pos == pos - 1);
1202 // Is position pos is a beginning of a font block?
1203 bool end = !notfound && fontlist[i].pos == pos;
1204 // Is position pos is the end of a font block?
1205 if (begin && end) { // A single char block
1206 if (i+1 < fontlist.size() &&
1207 fontlist[i+1].font == font) {
1208 // Merge the singleton block with the next block
1209 fontlist.erase(fontlist.begin() + i);
1210 if (i > 0 && fontlist[i-1].font == font)
1211 fontlist.erase(fontlist.begin() + i-1);
1212 } else if (i > 0 && fontlist[i-1].font == font) {
1213 // Merge the singleton block with the previous block
1214 fontlist[i-1].pos = pos;
1215 fontlist.erase(fontlist.begin() + i);
1217 fontlist[i].font = font;
1219 if (i > 0 && fontlist[i-1].font == font)
1220 fontlist[i-1].pos = pos;
1222 fontlist.insert(fontlist.begin() + i,
1223 FontTable(pos, font));
1225 fontlist[i].pos = pos - 1;
1226 if (!(i+1 < fontlist.size() &&
1227 fontlist[i+1].font == font))
1228 fontlist.insert(fontlist.begin() + i+1,
1229 FontTable(pos, font));
1230 } else { // The general case. The block is splitted into 3 blocks
1231 fontlist.insert(fontlist.begin() + i,
1232 FontTable(pos - 1, fontlist[i].font));
1233 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1238 // This function is able to hide closed footnotes.
1239 LyXParagraph * LyXParagraph::Next()
1242 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1243 LyXParagraph * tmp = next;
1245 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1247 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1248 return tmp->Next(); /* there can be more than one
1249 footnote in a logical
1252 return next; // This should never happen!
1259 LyXParagraph * LyXParagraph::NextAfterFootnote()
1262 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1263 LyXParagraph * tmp = next;
1264 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1266 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1267 return tmp; /* there can be more than one footnote
1268 in a logical paragraph */
1270 return next; // This should never happen!
1277 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1280 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1281 LyXParagraph * tmp = next;
1282 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1284 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1285 return tmp; /* there can be more than one footnote
1286 in a logical paragraph */
1288 return next; // This should never happen!
1295 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1299 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1301 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1302 tmp = tmp->previous;
1303 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1304 return tmp; /* there can be more than one footnote
1305 in a logical paragraph */
1307 return previous; // This should never happen!
1314 LyXParagraph * LyXParagraph::LastPhysicalPar()
1317 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1320 LyXParagraph * tmp = this;
1322 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1323 tmp = tmp->NextAfterFootnote();
1331 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1334 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1337 LyXParagraph const * tmp = this;
1339 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1340 tmp = tmp->NextAfterFootnote();
1348 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1353 LyXParagraph * tmppar = this;
1357 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1358 tmppar = tmppar->previous;
1370 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1375 LyXParagraph const * tmppar = this;
1379 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1380 tmppar = tmppar->previous;
1392 // This function is able to hide closed footnotes.
1393 LyXParagraph * LyXParagraph::Previous()
1395 LyXParagraph * tmp = previous;
1401 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1402 tmp = tmp->previous;
1404 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1405 tmp = tmp->previous;
1406 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1407 return tmp->next->Previous();
1417 // This function is able to hide closed footnotes.
1418 LyXParagraph const * LyXParagraph::Previous() const
1420 LyXParagraph * tmp = previous;
1425 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1426 tmp = tmp->previous;
1428 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1429 tmp = tmp->previous;
1430 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1431 return tmp->next->Previous();
1441 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1442 LyXParagraph::size_type pos,
1445 size_type i, j, pos_end, pos_first;
1446 // create a new paragraph
1447 LyXParagraph * par = ParFromPos(pos);
1448 LyXParagraph * firstpar = FirstPhysicalPar();
1450 LyXParagraph * tmp = new LyXParagraph(par);
1453 tmp->footnoteflag = footnoteflag;
1454 tmp->footnotekind = footnotekind;
1456 // this is an idea for a more userfriendly layout handling, I will
1457 // see what the users say
1459 // layout stays the same with latex-environments
1461 tmp->SetOnlyLayout(bparams, firstpar->layout);
1462 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1465 if (Last() > pos || !Last() || flag == 2) {
1466 tmp->SetOnlyLayout(bparams, firstpar->layout);
1467 tmp->align = firstpar->align;
1468 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1470 tmp->line_bottom = firstpar->line_bottom;
1471 firstpar->line_bottom = false;
1472 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1473 firstpar->pagebreak_bottom = false;
1474 tmp->added_space_bottom = firstpar->added_space_bottom;
1475 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1477 tmp->depth = firstpar->depth;
1478 tmp->noindent = firstpar->noindent;
1480 // copy everything behind the break-position
1481 // to the new paragraph
1483 while (ParFromPos(pos_first) != par)
1486 pos_end = pos_first + par->text.size() - 1;
1488 for (i = j = pos; i <= pos_end; ++i) {
1489 par->CutIntoMinibuffer(bparams, i - pos_first);
1490 if (tmp->InsertFromMinibuffer(j - pos))
1493 tmp->text.resize(tmp->text.size());
1494 for (i = pos_end; i >= pos; --i)
1495 par->Erase(i - pos_first);
1497 par->text.resize(par->text.size());
1500 // just an idea of me
1502 tmp->line_top = firstpar->line_top;
1503 tmp->pagebreak_top = firstpar->pagebreak_top;
1504 tmp->added_space_top = firstpar->added_space_top;
1505 tmp->bibkey = firstpar->bibkey;
1507 // layout stays the same with latex-environments
1509 firstpar->SetOnlyLayout(bparams, tmp->layout);
1510 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1511 firstpar->depth = tmp->depth;
1517 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1519 par = par->FirstPhysicalPar();
1521 footnoteflag = par->footnoteflag;
1522 footnotekind = par->footnotekind;
1524 layout = par->layout;
1525 align = par-> align;
1526 SetLabelWidthString(par->labelwidthstring);
1528 line_bottom = par->line_bottom;
1529 pagebreak_bottom = par->pagebreak_bottom;
1530 added_space_bottom = par->added_space_bottom;
1532 line_top = par->line_top;
1533 pagebreak_top = par->pagebreak_top;
1534 added_space_top = par->added_space_top;
1536 spacing = par->spacing;
1538 pextra_type = par->pextra_type;
1539 pextra_width = par->pextra_width;
1540 pextra_widthp = par->pextra_widthp;
1541 pextra_alignment = par->pextra_alignment;
1542 pextra_hfill = par->pextra_hfill;
1543 pextra_start_minipage = par->pextra_start_minipage;
1545 noindent = par->noindent;
1551 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1553 LyXParagraph * tmppar = this;
1556 && tmppar->previous->footnoteflag ==
1557 LyXParagraph::CLOSED_FOOTNOTE)
1558 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1559 tmppar = tmppar->previous;
1562 return this; // This should never happen!
1569 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1571 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1575 if (!IsDummy() && !table){
1577 && (IsNewline(0) || IsLineSeparator(0))){
1586 LyXParagraph * LyXParagraph::Clone() const
1588 // create a new paragraph
1589 LyXParagraph * result = new LyXParagraph;
1591 result->MakeSameLayout(this);
1593 // this is because of the dummy layout of the paragraphs that
1595 result->layout = layout;
1598 /* table stuff -- begin*/
1600 result->table = table->Clone();
1603 /* table stuff -- end*/
1605 result->inset_owner = inset_owner;
1608 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1611 // copy everything behind the break-position to the new paragraph
1613 result->text = text;
1614 result->fontlist = fontlist;
1615 result->insetlist = insetlist;
1616 for (InsetList::iterator it = result->insetlist.begin();
1617 it != result->insetlist.end(); ++it)
1618 (*it).inset = (*it).inset->Clone();
1623 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1625 par = par->FirstPhysicalPar();
1629 par->footnoteflag == footnoteflag &&
1630 par->footnotekind == footnotekind &&
1632 par->layout == layout &&
1634 par->align == align &&
1636 par->line_bottom == line_bottom &&
1637 par->pagebreak_bottom == pagebreak_bottom &&
1638 par->added_space_bottom == added_space_bottom &&
1640 par->line_top == line_top &&
1641 par->pagebreak_top == pagebreak_top &&
1642 par->added_space_top == added_space_top &&
1644 par->spacing == spacing &&
1646 par->pextra_type == pextra_type &&
1647 par->pextra_width == pextra_width &&
1648 par->pextra_widthp == pextra_widthp &&
1649 par->pextra_alignment == pextra_alignment &&
1650 par->pextra_hfill == pextra_hfill &&
1651 par->pextra_start_minipage == pextra_start_minipage &&
1653 par->table == table && // what means: NO TABLE AT ALL
1656 par->noindent == noindent &&
1657 par->depth == depth);
1661 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1662 LyXParagraph::size_type pos)
1664 // create a new paragraph
1665 LyXParagraph * par = ParFromPos(pos);
1667 LyXParagraph * tmp = new LyXParagraph(par);
1669 tmp->MakeSameLayout(par);
1671 // When can pos < Last()?
1672 // I guess pos == Last() is possible.
1674 // copy everything behind the break-position to the new
1676 size_type pos_first = 0;
1677 while (ParFromPos(pos_first) != par)
1679 size_type pos_end = pos_first + par->text.size() - 1;
1682 for (i = j = pos; i <= pos_end; ++i) {
1683 par->CutIntoMinibuffer(bparams, i - pos_first);
1684 if (tmp->InsertFromMinibuffer(j - pos))
1687 tmp->text.resize(tmp->text.size());
1688 for (size_type i = pos_end; i >= pos; --i)
1689 par->Erase(i - pos_first);
1691 par->text.resize(par->text.size());
1696 // Be carefull, this does not make any check at all.
1697 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1699 // copy the next paragraph to this one
1700 LyXParagraph * the_next = Next();
1702 LyXParagraph * firstpar = FirstPhysicalPar();
1704 // first the DTP-stuff
1705 firstpar->line_bottom = the_next->line_bottom;
1706 firstpar->added_space_bottom = the_next->added_space_bottom;
1707 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1709 size_type pos_end = the_next->text.size() - 1;
1710 size_type pos_insert = Last();
1712 // ok, now copy the paragraph
1714 for (i = j = 0; i <= pos_end; ++i) {
1715 the_next->CutIntoMinibuffer(bparams, i);
1716 if (InsertFromMinibuffer(pos_insert + j))
1720 // delete the next paragraph
1721 LyXParagraph * ppar = the_next->previous;
1722 LyXParagraph * npar = the_next->next;
1729 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1731 LyXParagraph * par = ParFromPos(pos);
1733 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1734 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1740 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1742 LyXParagraph * par = ParFromPos(pos);
1744 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1745 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1751 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1753 LyXParagraph const * par = this;
1754 int par_depth = GetDepth();
1756 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1758 textclasslist.Style(bparams.textclass,
1759 layout).endlabeltype;
1760 if (endlabeltype != END_LABEL_NO_LABEL) {
1761 LyXParagraph const * last = this;
1762 if( footnoteflag == NO_FOOTNOTE)
1763 last = LastPhysicalPar();
1764 else if (next->footnoteflag == NO_FOOTNOTE)
1765 return endlabeltype;
1767 if (!last || !last->next)
1768 return endlabeltype;
1770 int next_depth = last->next->GetDepth();
1771 if (par_depth > next_depth ||
1772 (par_depth == next_depth && layout != last->next->GetLayout() ))
1773 return endlabeltype;
1778 par = par->DepthHook(par_depth - 1);
1780 par_depth = par->GetDepth();
1782 return END_LABEL_NO_LABEL;
1786 LyXTextClass::size_type LyXParagraph::GetLayout() const
1788 return FirstPhysicalPar()->layout;
1792 char LyXParagraph::GetDepth() const
1794 return FirstPhysicalPar()->depth;
1798 char LyXParagraph::GetAlign() const
1800 return FirstPhysicalPar()->align;
1804 string LyXParagraph::GetLabelstring() const
1806 return FirstPhysicalPar()->labelstring;
1810 int LyXParagraph::GetFirstCounter(int i) const
1812 return FirstPhysicalPar()->counter_[i];
1816 // the next two functions are for the manual labels
1817 string LyXParagraph::GetLabelWidthString() const
1819 if (!FirstPhysicalPar()->labelwidthstring.empty())
1820 return FirstPhysicalPar()->labelwidthstring;
1822 return _("Senseless with this layout!");
1826 void LyXParagraph::SetLabelWidthString(string const & s)
1828 LyXParagraph * par = FirstPhysicalPar();
1830 par->labelwidthstring = s;
1834 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1835 LyXTextClass::size_type new_layout)
1837 LyXParagraph * par = FirstPhysicalPar();
1838 LyXParagraph * ppar = 0;
1839 LyXParagraph * npar = 0;
1841 par->layout = new_layout;
1843 /* table stuff -- begin*/
1846 /* table stuff -- end*/
1848 if (par->pextra_type == PEXTRA_NONE) {
1849 if (par->Previous()) {
1850 ppar = par->Previous()->FirstPhysicalPar();
1853 && (ppar->depth > par->depth))
1854 ppar = ppar->Previous()->FirstPhysicalPar();
1857 npar = par->Next()->NextAfterFootnote();
1860 && (npar->depth > par->depth))
1861 npar = npar->Next()->NextAfterFootnote();
1863 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1865 p1 = ppar->pextra_width,
1866 p2 = ppar->pextra_widthp;
1867 ppar->SetPExtraType(bparams, ppar->pextra_type,
1868 p1.c_str(), p2.c_str());
1870 if ((par->pextra_type == PEXTRA_NONE) &&
1871 npar && (npar->pextra_type != PEXTRA_NONE)) {
1873 p1 = npar->pextra_width,
1874 p2 = npar->pextra_widthp;
1875 npar->SetPExtraType(bparams, npar->pextra_type,
1876 p1.c_str(), p2.c_str());
1882 void LyXParagraph::SetLayout(BufferParams const & bparams,
1883 LyXTextClass::size_type new_layout)
1886 * par = FirstPhysicalPar(),
1890 par->layout = new_layout;
1891 par->labelwidthstring.erase();
1892 par->align = LYX_ALIGN_LAYOUT;
1893 par->added_space_top = VSpace(VSpace::NONE);
1894 par->added_space_bottom = VSpace(VSpace::NONE);
1895 par->spacing.set(Spacing::Default);
1898 /* table stuff -- begin*/
1901 /* table stuff -- end*/
1903 if (par->pextra_type == PEXTRA_NONE) {
1904 if (par->Previous()) {
1905 ppar = par->Previous()->FirstPhysicalPar();
1908 && (ppar->depth > par->depth))
1909 ppar = ppar->Previous()->FirstPhysicalPar();
1912 npar = par->Next()->NextAfterFootnote();
1915 && (npar->depth > par->depth))
1916 npar = npar->Next()->NextAfterFootnote();
1918 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1920 p1 = ppar->pextra_width,
1921 p2 = ppar->pextra_widthp;
1922 ppar->SetPExtraType(bparams, ppar->pextra_type,
1923 p1.c_str(), p2.c_str());
1925 if ((par->pextra_type == PEXTRA_NONE) &&
1926 npar && (npar->pextra_type != PEXTRA_NONE)) {
1928 p1 = npar->pextra_width,
1929 p2 = npar->pextra_widthp;
1930 npar->SetPExtraType(bparams, npar->pextra_type,
1931 p1.c_str(), p2.c_str());
1937 // if the layout of a paragraph contains a manual label, the beginning of the
1938 // main body is the beginning of the second word. This is what the par-
1939 // function returns. If the layout does not contain a label, the main
1940 // body always starts with position 0. This differentiation is necessary,
1941 // because there cannot be a newline or a blank <= the beginning of the
1942 // main body in TeX.
1944 int LyXParagraph::BeginningOfMainBody() const
1946 if (FirstPhysicalPar() != this)
1949 // Unroll the first two cycles of the loop
1950 // and remember the previous character to
1951 // remove unnecessary GetChar() calls
1954 && GetChar(i) != LyXParagraph::META_NEWLINE
1957 char previous_char = 0, temp = 0;
1959 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1960 // Yes, this ^ is supposed to be "= " not "=="
1963 && previous_char != ' '
1964 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1966 previous_char = temp;
1971 if (i == 0 && i == size() &&
1972 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1973 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1974 ++i; /* the cursor should not jump
1975 * to the main body if there
1981 LyXParagraph * LyXParagraph::DepthHook(int deth)
1983 LyXParagraph * newpar = this;
1988 newpar = newpar->FirstPhysicalPar()->Previous();
1989 } while (newpar && newpar->GetDepth() > deth
1990 && newpar->footnoteflag == footnoteflag);
1993 if (Previous() || GetDepth())
1994 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1998 return newpar->FirstPhysicalPar();
2002 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2004 LyXParagraph const * newpar = this;
2009 newpar = newpar->FirstPhysicalPar()->Previous();
2010 } while (newpar && newpar->GetDepth() > deth
2011 && newpar->footnoteflag == footnoteflag);
2014 if (Previous() || GetDepth())
2015 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2019 return newpar->FirstPhysicalPar();
2023 int LyXParagraph::AutoDeleteInsets()
2026 InsetList::size_type index = 0;
2027 while (index < insetlist.size()) {
2028 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2029 Erase(insetlist[index].pos);
2030 // Erase() calls to insetlist.erase(&insetlist[index])
2031 // so index shouldn't be increased.
2040 LyXParagraph::inset_iterator
2041 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2043 InsetTable search_inset(pos, 0);
2044 InsetList::iterator it = lower_bound(insetlist.begin(),
2046 search_inset, matchIT());
2047 return inset_iterator(it);
2051 // returns -1 if inset not found
2052 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2055 // We could use lower_bound here too, we just need to add
2056 // the approp. operator() to matchIT (and change the name
2057 // of that struct). Code would then be:
2058 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2060 // inset, matchIT());
2061 // if ((*cit).inset == inset) {
2062 // return (*cit).pos;
2064 for (InsetList::const_iterator cit = insetlist.begin();
2065 cit != insetlist.end(); ++cit) {
2066 if ((*cit).inset == inset) {
2070 // Think about footnotes.
2071 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2072 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2074 NextAfterFootnote()->GetPositionOfInset(inset);
2076 return text.size() + 1 + further;
2082 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2083 BufferParams const & bparams,
2084 ostream & os, TexRow & texrow,
2087 TexRow & foot_texrow,
2090 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2091 LyXLayout const & style =
2092 textclasslist.Style(bparams.textclass,
2095 bool further_blank_line = false;
2097 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2099 if (start_of_appendix) {
2100 os << "\\appendix\n";
2104 if (!spacing.isDefault()
2105 && (!Previous() || !Previous()->HasSameLayout(this))) {
2106 os << spacing.writeEnvirBegin() << "\n";
2110 if (tex_code_break_column && style.isCommand()){
2115 if (pagebreak_top) {
2117 further_blank_line = true;
2119 if (added_space_top.kind() != VSpace::NONE) {
2120 os << added_space_top.asLatexCommand(bparams);
2121 further_blank_line = true;
2125 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2126 << "\\vspace{-1\\parskip}";
2127 further_blank_line = true;
2130 if (further_blank_line){
2135 Language const * language = getParLanguage(bparams);
2136 Language const * doc_language = bparams.language_info;
2137 Language const * previous_language = previous
2138 ? previous->getParLanguage(bparams) : doc_language;
2139 if (language != doc_language && language != previous_language) {
2140 os << subst(lyxrc.language_command_begin, "$$lang",
2146 if (bparams.inputenc == "auto" &&
2147 language->encoding() != previous_language->encoding()) {
2148 os << "\\inputencoding{"
2149 << language->encoding()->LatexName()
2154 switch (style.latextype) {
2157 << style.latexname()
2158 << style.latexparam();
2160 case LATEX_ITEM_ENVIRONMENT:
2162 bibkey->Latex(buf, os, false, false);
2166 case LATEX_LIST_ENVIRONMENT:
2173 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2176 // Spit out footnotes
2177 LyXParagraph * par = next;
2178 if (lyxrc.rtl_support) {
2179 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2180 && next->footnoteflag != footnoteflag) {
2181 LyXParagraph * p = 0;
2182 bool is_rtl = (size() > 0)
2183 ? GetFontSettings(bparams,
2184 size()-1).isRightToLeft()
2185 : language->RightToLeft();
2186 if ( (p = NextAfterFootnote()) != 0 &&
2188 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2189 is_rtl = getParLanguage(bparams)->RightToLeft();
2190 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2191 && par->footnoteflag != footnoteflag) {
2192 par = par->TeXFootnote(buf, bparams,
2194 foot_texrow, foot_count,
2196 par->SimpleTeXOnePar(buf, bparams,
2197 os, texrow, moving_arg);
2198 is_rtl = (par->size() > 0)
2199 ? par->GetFontSettings(bparams,
2200 par->size()-1).isRightToLeft()
2201 : language->RightToLeft();
2203 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2204 (p = par->NextAfterFootnote()) != 0 &&
2206 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2207 is_rtl = language->RightToLeft();
2212 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2213 && par->footnoteflag != footnoteflag) {
2214 par = par->TeXFootnote(buf, bparams,
2216 foot, foot_texrow, foot_count,
2218 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2224 // Make sure that \\par is done with the font of the last
2225 // character if this has another size as the default.
2226 // This is necessary because LaTeX (and LyX on the screen)
2227 // calculates the space between the baselines according
2228 // to this font. (Matthias)
2229 LyXFont font = getFont(bparams, Last() - 1);
2231 if (style.resfont.size() != font.size()) {
2237 } else if (textclasslist.Style(bparams.textclass,
2238 GetLayout()).isCommand()) {
2239 if (style.resfont.size() != font.size()) {
2245 } else if (style.resfont.size() != font.size()){
2246 os << "{\\" << font.latexSize() << " \\par}";
2249 if (language != doc_language &&
2251 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2252 || par->getParLanguage(bparams) != language)) {
2254 << subst(lyxrc.language_command_end, "$$lang",
2255 doc_language->lang());
2258 switch (style.latextype) {
2259 case LATEX_ITEM_ENVIRONMENT:
2260 case LATEX_LIST_ENVIRONMENT:
2261 if (par && (depth < par->depth)) {
2266 case LATEX_ENVIRONMENT:
2267 // if its the last paragraph of the current environment
2268 // skip it otherwise fall through
2270 && (par->layout != layout
2271 || par->depth != depth
2272 || par->pextra_type != pextra_type))
2275 // we don't need it for the last paragraph!!!
2276 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2277 && footnotekind != LyXParagraph::FOOTNOTE
2278 && footnotekind != LyXParagraph::MARGIN
2282 // don't insert this if we would be adding it
2283 // before or after a table in a float. This
2284 // little trick is needed in order to allow
2285 // use of tables in \subfigures or \subtables.
2291 further_blank_line = false;
2293 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2294 further_blank_line = true;
2297 if (added_space_bottom.kind() != VSpace::NONE) {
2298 os << added_space_bottom.asLatexCommand(bparams);
2299 further_blank_line = true;
2302 if (pagebreak_bottom) {
2304 further_blank_line = true;
2307 if (further_blank_line){
2312 if (!spacing.isDefault()
2313 && (!par || !par->HasSameLayout(this))) {
2314 os << spacing.writeEnvirEnd() << "\n";
2318 // we don't need it for the last paragraph!!!
2319 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2320 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2325 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2330 // This one spits out the text of the paragraph
2331 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2332 BufferParams const & bparams,
2333 ostream & os, TexRow & texrow,
2336 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2340 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2343 bool return_value = false;
2345 LyXLayout const & style =
2346 textclasslist.Style(bparams.textclass,
2348 LyXFont basefont, last_font;
2350 // Maybe we have to create a optional argument.
2351 size_type main_body;
2352 if (style.labeltype != LABEL_MANUAL)
2355 main_body = BeginningOfMainBody();
2357 if (main_body > 0) {
2359 basefont = getFont(bparams, -2); // Get label font
2361 basefont = getFont(bparams, -1); // Get layout font
2369 if (style.isCommand()) {
2372 } else if (align != LYX_ALIGN_LAYOUT) {
2375 return_value = true;
2379 moving_arg |= style.needprotect;
2381 // Which font is currently active?
2382 LyXFont running_font(basefont);
2383 // Do we have an open font change?
2384 bool open_font = false;
2386 texrow.start(this, 0);
2388 for (size_type i = 0; i < size(); ++i) {
2390 // First char in paragraph or after label?
2391 if (i == main_body && !IsDummy()) {
2392 if (main_body > 0) {
2394 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2397 basefont = getFont(bparams, -1); // Now use the layout font
2398 running_font = basefont;
2402 if (style.isCommand()) {
2405 } else if (align != LYX_ALIGN_LAYOUT) {
2408 return_value = true;
2412 os << "\\noindent ";
2416 case LYX_ALIGN_NONE:
2417 case LYX_ALIGN_BLOCK:
2418 case LYX_ALIGN_LAYOUT:
2419 case LYX_ALIGN_SPECIAL:
2421 case LYX_ALIGN_LEFT:
2422 if (getParLanguage(bparams)->lang() != "hebrew") {
2423 os << "\\raggedright ";
2426 os << "\\raggedleft ";
2430 case LYX_ALIGN_RIGHT:
2431 if (getParLanguage(bparams)->lang() != "hebrew") {
2432 os << "\\raggedleft ";
2435 os << "\\raggedright ";
2439 case LYX_ALIGN_CENTER:
2440 os << "\\centering ";
2446 value_type c = GetChar(i);
2448 // Fully instantiated font
2449 LyXFont font = getFont(bparams, i);
2450 LyXParagraph * p = 0;
2451 if (i == 0 && previous &&
2452 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2453 (p = PreviousBeforeFootnote()) != 0)
2454 last_font = p->getFont(bparams, p->size()-1);
2456 last_font = running_font;
2458 // Spaces at end of font change are simulated to be
2459 // outside font change, i.e. we write "\textXX{text} "
2460 // rather than "\textXX{text }". (Asger)
2461 if (open_font && c == ' ' && i <= size() - 2
2462 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2463 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2464 font = getFont(bparams, i + 1);
2466 // We end font definition before blanks
2467 if (!font.equalExceptLatex(running_font) && open_font) {
2468 column += running_font.latexWriteEndChanges(os,
2470 (i == main_body-1) ? basefont : font);
2471 running_font = basefont;
2475 // Blanks are printed before start of fontswitch
2477 // Do not print the separation of the optional argument
2478 if (i != main_body - 1) {
2479 SimpleTeXBlanks(os, texrow, i,
2480 column, font, style);
2484 // Do we need to change font?
2485 if (!font.equalExceptLatex(running_font)
2486 && i != main_body-1) {
2487 column += font.latexWriteStartChanges(os, basefont,
2489 running_font = font;
2493 if (c == LyXParagraph::META_NEWLINE) {
2494 // newlines are handled differently here than
2495 // the default in SimpleTeXSpecialChars().
2496 if (!style.newline_allowed
2497 || font.latex() == LyXFont::ON) {
2501 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2504 basefont = getFont(bparams, -1);
2505 running_font = basefont;
2506 if (font.family() ==
2507 LyXFont::TYPEWRITER_FAMILY) {
2515 texrow.start(this, i + 1);
2518 SimpleTeXSpecialChars(buf, bparams,
2519 os, texrow, moving_arg,
2520 font, running_font, basefont,
2521 open_font, style, i, column, c);
2525 // If we have an open font definition, we have to close it
2527 LyXParagraph * p = 0;
2528 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2529 && (p = NextAfterFootnote()) != 0)
2530 running_font.latexWriteEndChanges(os, basefont,
2531 p->getFont(bparams, 0));
2533 running_font.latexWriteEndChanges(os, basefont, basefont);
2536 // Needed if there is an optional argument but no contents.
2537 if (main_body > 0 && main_body == size()) {
2539 return_value = false;
2542 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2543 return return_value;
2547 // This one spits out the text of a table paragraph
2548 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2549 BufferParams const & bparams,
2550 ostream & os, TexRow & texrow)
2552 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2554 bool return_value = false;
2556 LyXLayout const & style =
2557 textclasslist.Style(bparams.textclass, GetLayout());
2560 if (!IsDummy()) { // it is dummy if it is in a float!!!
2561 if (style.isCommand()) {
2564 } else if (align != LYX_ALIGN_LAYOUT) {
2567 return_value = true;
2570 os << "\\noindent ";
2574 case LYX_ALIGN_NONE:
2575 case LYX_ALIGN_BLOCK:
2576 case LYX_ALIGN_LAYOUT:
2577 case LYX_ALIGN_SPECIAL: break;
2578 case LYX_ALIGN_LEFT:
2579 os << "\\raggedright ";
2582 case LYX_ALIGN_RIGHT:
2583 os << "\\raggedleft ";
2586 case LYX_ALIGN_CENTER:
2587 os << "\\centering ";
2593 LyXFont basefont = getFont(bparams, -1); // Get layout font
2594 // Which font is currently active?
2595 LyXFont running_font = basefont;
2597 // Do we have an open font change?
2598 bool open_font = false;
2599 int current_cell_number = -1;
2600 int tmp = table->TexEndOfCell(os, current_cell_number);
2601 for (; tmp > 0 ; --tmp)
2604 texrow.start(this, 0);
2606 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2607 bool first_in_cell = true;
2609 for (size_type i = 0; i < size(); ++i) {
2610 value_type c = GetChar(i);
2611 if (table->IsContRow(current_cell_number + 1)) {
2612 if (c == LyXParagraph::META_NEWLINE)
2613 ++current_cell_number;
2618 if (first_in_cell && is_rtl) {
2621 first_in_cell = false;
2624 // Fully instantiated font
2625 LyXFont font = getFont(bparams, i);
2626 last_font = running_font;
2628 // Spaces at end of font change are simulated to be
2629 // outside font change.
2630 // i.e. we write "\textXX{text} " rather than
2631 // "\textXX{text }". (Asger)
2632 if (open_font && c == ' ' && i <= size() - 2
2633 && getFont(bparams, i + 1) != running_font
2634 && getFont(bparams, i + 1) != font) {
2635 font = getFont(bparams, i + 1);
2638 // We end font definition before blanks
2639 if (font != running_font && open_font) {
2640 column += running_font.latexWriteEndChanges(os,
2643 running_font = basefont;
2646 // Blanks are printed before start of fontswitch
2648 SimpleTeXBlanks(os, texrow, i, column, font, style);
2650 // Do we need to change font?
2651 if (font != running_font) {
2652 column += font.latexWriteStartChanges(os, basefont,
2654 running_font = font;
2657 // Do we need to turn on LaTeX mode?
2658 if (font.latex() != running_font.latex()) {
2659 if (font.latex() == LyXFont::ON
2660 && style.needprotect) {
2665 if (c == LyXParagraph::META_NEWLINE) {
2666 // special case for inside a table
2667 // different from default case in
2668 // SimpleTeXSpecialChars()
2670 column += running_font
2671 .latexWriteEndChanges(os, basefont,
2675 basefont = getFont(bparams, -1);
2676 running_font = basefont;
2677 ++current_cell_number;
2678 if (table->CellHasContRow(current_cell_number) >= 0) {
2679 TeXContTableRows(buf, bparams, os, i + 1,
2680 current_cell_number,
2683 if (is_rtl && !first_in_cell) {
2685 first_in_cell = true;
2688 // if this cell follow only ContRows till end don't
2689 // put the EndOfCell because it is put after the
2691 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2692 --current_cell_number;
2695 int tmp = table->TexEndOfCell(os,
2696 current_cell_number);
2699 } else if (tmp < 0) {
2705 texrow.start(this, i + 1);
2707 SimpleTeXSpecialChars(buf, bparams,
2709 font, running_font, basefont,
2710 open_font, style, i, column, c);
2714 // If we have an open font definition, we have to close it
2716 running_font.latexWriteEndChanges(os, basefont, basefont);
2718 ++current_cell_number;
2719 if (is_rtl && !first_in_cell)
2721 tmp = table->TexEndOfCell(os, current_cell_number);
2722 for (; tmp > 0; --tmp)
2724 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2725 return return_value;
2729 // This one spits out the text off ContRows in tables
2730 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2731 BufferParams const & bparams,
2733 LyXParagraph::size_type i,
2734 int current_cell_number,
2735 int & column, TexRow & texrow)
2737 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2741 bool return_value = false;
2742 LyXLayout const & style =
2743 textclasslist.Style(bparams.textclass,
2745 LyXFont basefont = getFont(bparams, -1); // Get layout font
2747 // Which font is currently active?
2748 LyXFont running_font = basefont;
2749 // Do we have an open font change?
2750 bool open_font = false;
2752 size_type lastpos = i;
2753 int cell = table->CellHasContRow(current_cell_number);
2754 ++current_cell_number;
2757 // first find the right position
2759 for (; (i < size()) && (current_cell_number < cell); ++i) {
2761 if (c == LyXParagraph::META_NEWLINE)
2762 ++current_cell_number;
2766 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2770 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2775 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2779 // Fully instantiated font
2780 LyXFont font = getFont(bparams, i);
2781 last_font = running_font;
2783 // Spaces at end of font change are simulated to
2784 // be outside font change. i.e. we write
2785 // "\textXX{text} " rather than "\textXX{text }".
2787 if (open_font && c == ' ' && i <= size() - 2
2788 && getFont(bparams, i + 1) != running_font
2789 && getFont(bparams, i + 1) != font) {
2790 font = getFont(bparams, i + 1);
2793 // We end font definition before blanks
2794 if (font != running_font && open_font) {
2795 column += running_font.latexWriteEndChanges(os, basefont, font);
2796 running_font = basefont;
2799 // Blanks are printed before start of fontswitch
2801 SimpleTeXBlanks(os, texrow, i,
2802 column, font, style);
2804 // Do we need to change font?
2805 if (font != running_font) {
2807 font.latexWriteStartChanges(os,
2810 running_font = font;
2813 // Do we need to turn on LaTeX mode?
2814 if (font.latex() != running_font.latex()) {
2815 if (font.latex() == LyXFont::ON
2816 && style.needprotect) {
2821 SimpleTeXSpecialChars(buf, bparams,
2822 os, texrow, false, font,
2823 running_font, basefont,
2824 open_font, style, i, column, c);
2826 // If we have an open font definition, we have to close it
2828 running_font.latexWriteEndChanges(os, basefont,
2832 basefont = getFont(bparams, -1);
2833 running_font = basefont;
2834 cell = table->CellHasContRow(current_cell_number);
2836 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2837 return return_value;
2841 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2843 bool retval = false;
2845 case LyXParagraph::META_HFILL:
2846 sgml_string.erase();
2848 case LyXParagraph::META_NEWLINE:
2852 sgml_string = "&";
2855 sgml_string = "<";
2858 sgml_string = ">";
2861 sgml_string = "$";
2864 sgml_string = "#";
2867 sgml_string = "%";
2870 sgml_string = "[";
2873 sgml_string = "]";
2876 sgml_string = "{";
2879 sgml_string = "}";
2882 sgml_string = "˜";
2885 sgml_string = """;
2888 sgml_string = "\";
2894 case '\0': // Ignore :-)
2895 sgml_string.erase();
2905 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
2906 ostream & os, string & extra,
2907 int & desc_on, int depth)
2909 BufferParams const & bparams = buffer->params;
2911 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2913 LyXFont font1, font2;
2916 size_type main_body;
2917 bool emph_flag = false;
2919 LyXLayout const & style =
2920 textclasslist.Style(bparams.textclass,
2923 if (style.labeltype != LABEL_MANUAL)
2926 main_body = BeginningOfMainBody();
2928 // Gets paragraph main font.
2930 font1 = style.labelfont;
2934 int char_line_count = depth;
2935 os << newlineAndDepth(depth);
2936 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2937 os << "<INFORMALTABLE>"
2938 << newlineAndDepth(++depth);
2940 int current_cell_number = -1;
2941 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2943 // Parsing main loop.
2944 for (size_type i = 0; i < size(); ++i) {
2946 if (table->IsContRow(current_cell_number+1)) {
2947 if (c == LyXParagraph::META_NEWLINE)
2948 ++current_cell_number;
2953 // Fully instantiated font
2954 font2 = getFont(bparams, i);
2956 // Handle <emphasis> tag.
2957 if (font1.emph() != font2.emph() && i) {
2958 if (font2.emph() == LyXFont::ON) {
2961 } else if (emph_flag) {
2962 os << "</emphasis>";
2966 if (c == LyXParagraph::META_NEWLINE) {
2967 // We have only to control for emphasis open here!
2969 os << "</emphasis>";
2972 font1 = font2 = getFont(bparams, -1);
2973 ++current_cell_number;
2974 if (table->CellHasContRow(current_cell_number) >= 0) {
2975 DocBookContTableRows(buffer,
2976 os, extra, desc_on, i + 1,
2977 current_cell_number,
2980 // if this cell follow only ContRows till end don't
2981 // put the EndOfCell because it is put after the
2983 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2984 --current_cell_number;
2987 tmp = table->DocBookEndOfCell(os,
2988 current_cell_number,
2993 } else if (c == LyXParagraph::META_INSET) {
2994 inset = GetInset(i);
2996 std::ostringstream ost;
2997 inset->DocBook(buffer, ost);
2998 string tmp_out = ost.str().c_str();
3001 inset->DocBook(buffer, ost);
3003 char * ctmp = ost.str();
3004 string tmp_out(ctmp);
3008 // This code needs some explanation:
3009 // Two insets are treated specially
3010 // label if it is the first element in a
3011 // command paragraph
3013 // graphics inside tables or figure floats
3015 // title (the equivalente in latex for this
3017 // and title should come first
3020 if(desc_on != 3 || i != 0) {
3021 if(tmp_out[0] == '@') {
3023 extra += frontStrip(tmp_out,
3026 os << frontStrip(tmp_out,
3031 } else if (font2.latex() == LyXFont::ON) {
3032 // "TeX"-Mode on == > SGML-Mode on.
3038 if (linuxDocConvertChar(c, sgml_string)
3039 && !style.free_spacing) {
3040 // in freespacing mode, spaces are
3041 // non-breaking characters
3046 << "</term><listitem><para>";
3058 // Needed if there is an optional argument but no contents.
3059 if (main_body > 0 && main_body == size()) {
3064 os << "</emphasis>";
3067 ++current_cell_number;
3068 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3069 // Resets description flag correctly.
3072 // <term> not closed...
3076 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3077 os << "</INFORMALTABLE>";
3079 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3084 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3085 ostream & os, string & extra,
3087 LyXParagraph::size_type i,
3088 int current_cell_number, int &column)
3093 BufferParams const & bparams = buffer->params;
3095 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3100 //string emph = "emphasis";
3101 bool emph_flag = false;
3102 int char_line_count = 0;
3104 LyXLayout const & style =
3105 textclasslist.Style(bparams.textclass,
3108 size_type main_body;
3109 if (style.labeltype != LABEL_MANUAL)
3112 main_body = BeginningOfMainBody();
3114 // Gets paragraph main font.
3117 font1 = style.labelfont;
3121 size_type lastpos = i;
3122 int cell = table->CellHasContRow(current_cell_number);
3123 ++current_cell_number;
3125 // first find the right position
3127 for (; i < size() && current_cell_number < cell; ++i) {
3129 if (c == LyXParagraph::META_NEWLINE)
3130 ++current_cell_number;
3134 // I don't know how to handle this so I comment it
3135 // for the moment (Jug)
3136 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3137 // file += " \\\\\n";
3140 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3145 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3149 // Fully instantiated font
3150 font2 = getFont(bparams, i);
3152 // Handle <emphasis> tag.
3153 if (font1.emph() != font2.emph() && i) {
3154 if (font2.emph() == LyXFont::ON) {
3157 } else if (emph_flag) {
3158 os << "</emphasis>";
3162 if (c == LyXParagraph::META_INSET) {
3163 inset = GetInset(i);
3165 std::ostringstream ost;
3166 inset->DocBook(buffer, ost);
3167 string tmp_out = ost.str().c_str();
3170 inset->DocBook(buffer, ost);
3172 char * ctmp = ost.str();
3173 string tmp_out(ctmp);
3177 // This code needs some explanation:
3178 // Two insets are treated specially
3179 // label if it is the first element in a
3180 // command paragraph
3182 // graphics inside tables or figure floats
3183 // can't go on title (the equivalente in
3184 // latex for this case is caption and title
3185 // should come first
3188 if(desc_on != 3 || i != 0) {
3189 if(tmp_out[0] == '@') {
3191 extra += frontStrip(tmp_out, '@');
3193 os << frontStrip(tmp_out, '@');
3197 } else if (font2.latex() == LyXFont::ON) {
3198 // "TeX"-Mode on == > SGML-Mode on.
3204 if (linuxDocConvertChar(c, sgml_string)
3205 && !style.free_spacing) {
3206 // in freespacing mode, spaces are
3207 // non-breaking characters
3212 << "</term><listitem><para>";
3222 // we have only to control for emphasis open here!
3224 os << "</emphasis>";
3227 font1 = font2 = getFont(bparams, -1);
3228 cell = table->CellHasContRow(current_cell_number);
3230 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3234 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3235 LyXParagraph::size_type const i,
3236 int & column, LyXFont const & font,
3237 LyXLayout const & style)
3239 if (column > tex_code_break_column
3241 && GetChar(i - 1) != ' '
3243 // In LaTeX mode, we don't want to
3244 // break lines since some commands
3246 && ! (font.latex() == LyXFont::ON)
3247 // same in FreeSpacing mode
3248 && !style.free_spacing
3249 // In typewriter mode, we want to avoid
3250 // ! . ? : at the end of a line
3251 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3252 && (GetChar(i-1) == '.'
3253 || GetChar(i-1) == '?'
3254 || GetChar(i-1) == ':'
3255 || GetChar(i-1) == '!'))) {
3256 if (tex_code_break_column == 0) {
3257 // in batchmode we need LaTeX to still
3258 // see it as a space not as an extra '\n'
3264 texrow.start(this, i + 1);
3266 } else if (font.latex() == LyXFont::OFF) {
3267 if (style.free_spacing) {
3276 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3277 BufferParams const & bparams,
3278 ostream & os, TexRow & texrow,
3281 LyXFont & running_font,
3284 LyXLayout const & style,
3285 LyXParagraph::size_type & i,
3287 LyXParagraph::value_type const c)
3289 // Two major modes: LaTeX or plain
3290 // Handle here those cases common to both modes
3291 // and then split to handle the two modes separately.
3293 case LyXParagraph::META_INSET: {
3294 Inset * inset = GetInset(i);
3297 int len = os.tellp();
3298 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3299 || inset->LyxCode() == Inset::MATH_CODE
3300 || inset->LyxCode() == Inset::URL_CODE)
3301 && running_font.isRightToLeft()) {
3306 int tmp = inset->Latex(buf, os, moving_arg,
3307 style.free_spacing);
3315 column += os.tellp() - len;
3324 case LyXParagraph::META_NEWLINE:
3326 column += running_font.latexWriteEndChanges(os,
3331 basefont = getFont(bparams, -1);
3332 running_font = basefont;
3335 case LyXParagraph::META_HFILL:
3341 // And now for the special cases within each mode
3342 // Are we in LaTeX mode?
3343 if (font.latex() == LyXFont::ON) {
3344 // at present we only have one option
3345 // but I'll leave it as a switch statement
3346 // so its simpler to extend. (ARRae)
3349 // make sure that we will not print
3350 // error generating chars to the tex
3351 // file. This test would not be needed
3352 // if it were done in the buffer
3360 // Plain mode (i.e. not LaTeX)
3363 os << "\\textbackslash{}";
3367 case '°': case '±': case '²': case '³':
3368 case '×': case '÷': case '¹': case 'ª':
3369 case 'º': case '¬': case 'µ':
3370 if (bparams.inputenc == "latin1" ||
3371 (bparams.inputenc == "auto" &&
3372 font.language()->encoding()->LatexName()
3374 os << "\\ensuremath{"
3383 case '|': case '<': case '>':
3384 // In T1 encoding, these characters exist
3385 if (lyxrc.fontenc == "T1") {
3387 //... but we should avoid ligatures
3388 if ((c == '>' || c == '<')
3390 && GetChar(i + 1) == c) {
3391 //os << "\\textcompwordmark{}";
3392 // Jean-Marc, have a look at
3393 // this. IÂ think this works
3401 // Typewriter font also has them
3402 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3406 // Otherwise, we use what LaTeX
3410 os << "\\textless{}";
3414 os << "\\textgreater{}";
3418 os << "\\textbar{}";
3424 case '-': // "--" in Typewriter mode -> "-{}-"
3426 && GetChar(i + 1) == '-'
3427 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3436 os << "\\char`\\\"{}";
3441 if (bparams.inputenc == "default") {
3450 case '%': case '#': case '{':
3457 os << "\\textasciitilde{}";
3462 os << "\\textasciicircum{}";
3466 case '*': case '[': case ']':
3467 // avoid being mistaken for optional arguments
3468 os << '{' << c << '}';
3473 // Blanks are printed before font switching.
3474 // Sure? I am not! (try nice-latex)
3475 // I am sure it's correct. LyX might be smarter
3476 // in the future, but for now, nothing wrong is
3481 /* idea for labels --- begin*/
3485 && font.family() != LyXFont::TYPEWRITER_FAMILY
3486 && GetChar(i + 1) == 'y'
3487 && GetChar(i + 2) == 'X') {
3495 && font.family() != LyXFont::TYPEWRITER_FAMILY
3496 && GetChar(i + 1) == 'e'
3497 && GetChar(i + 2) == 'X') {
3502 // Check for "LaTeX2e"
3505 && font.family() != LyXFont::TYPEWRITER_FAMILY
3506 && GetChar(i + 1) == 'a'
3507 && GetChar(i + 2) == 'T'
3508 && GetChar(i + 3) == 'e'
3509 && GetChar(i + 4) == 'X'
3510 && GetChar(i + 5) == '2'
3511 && GetChar(i + 6) == 'e') {
3516 // Check for "LaTeX"
3519 && font.family() != LyXFont::TYPEWRITER_FAMILY
3520 && GetChar(i + 1) == 'a'
3521 && GetChar(i + 2) == 'T'
3522 && GetChar(i + 3) == 'e'
3523 && GetChar(i + 4) == 'X') {
3527 /* idea for labels --- end*/
3528 } else if (c != '\0') {
3538 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3539 BufferParams const & bparams,
3540 ostream & os, TexRow & texrow,
3542 TexRow & foot_texrow,
3545 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3546 LyXParagraph * par = this;
3549 (par->depth == depth) &&
3550 (par->footnoteflag == footnoteflag)) {
3552 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3553 if (textclasslist.Style(bparams.textclass,
3554 par->layout).isEnvironment()
3555 || par->pextra_type != PEXTRA_NONE) {
3556 par = par->TeXEnvironment(buf, bparams,
3561 par = par->TeXOnePar(buf, bparams,
3567 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3573 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3574 BufferParams const & bparams,
3575 ostream & os, TexRow & texrow,
3577 TexRow & foot_texrow,
3580 bool eindent_open = false;
3581 bool foot_this_level = false;
3582 // flags when footnotetext should be appended to file.
3583 static bool minipage_open = false;
3584 static int minipage_open_depth = 0;
3585 char par_sep = bparams.paragraph_separation;
3587 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3589 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3591 LyXLayout const & style =
3592 textclasslist.Style(bparams.textclass,
3595 if (pextra_type == PEXTRA_INDENT) {
3596 if (!pextra_width.empty()) {
3597 os << "\\begin{LyXParagraphIndent}{"
3598 << pextra_width << "}\n";
3600 //float ib = atof(pextra_widthp.c_str())/100;
3601 // string can't handle floats at present (971109)
3602 // so I'll do a conversion by hand knowing that
3603 // the limits are 0.0 to 1.0. ARRae.
3604 os << "\\begin{LyXParagraphIndent}{";
3605 switch (pextra_widthp.length()) {
3617 os << "\\columnwidth}\n";
3620 eindent_open = true;
3622 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3623 if (pextra_hfill && Previous() &&
3624 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3625 os << "\\hfill{}\n";
3628 if (par_sep == BufferParams::PARSEP_INDENT) {
3629 os << "{\\setlength\\parindent{0pt}\n";
3632 os << "\\begin{minipage}";
3633 switch(pextra_alignment) {
3634 case MINIPAGE_ALIGN_TOP:
3637 case MINIPAGE_ALIGN_MIDDLE:
3640 case MINIPAGE_ALIGN_BOTTOM:
3644 if (!pextra_width.empty()) {
3645 os << '{' << pextra_width << "}\n";
3647 //float ib = atof(par->pextra_width.c_str())/100;
3648 // string can't handle floats at present
3649 // so I'll do a conversion by hand knowing that
3650 // the limits are 0.0 to 1.0. ARRae.
3652 switch (pextra_widthp.length()) {
3664 os << "\\columnwidth}\n";
3667 if (par_sep == BufferParams::PARSEP_INDENT) {
3668 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3671 minipage_open = true;
3672 minipage_open_depth = depth;
3675 #ifdef WITH_WARNINGS
3676 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3677 //I disabled it because it breaks when lists span on several
3680 if (style.isEnvironment()){
3681 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3682 #ifdef FANCY_FOOTNOTE_CODE
3683 if (foot_count < 0) {
3684 // flag that footnote[mark][text] should be
3685 // used for any footnotes from now on
3687 foot_this_level = true;
3690 os << "\\begin{" << style.latexname() << "}{"
3691 << labelwidthstring << "}\n";
3692 } else if (style.labeltype == LABEL_BIBLIO) {
3694 os << "\\begin{" << style.latexname() << "}{"
3695 << bibitemWidest(current_view)
3697 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3698 #ifdef FANCY_FOOTNOTE_CODE
3699 if (foot_count < 0) {
3700 // flag that footnote[mark][text] should be
3701 // used for any footnotes from now on
3703 foot_this_level = true;
3706 os << "\\begin{" << style.latexname() << '}'
3707 << style.latexparam() << '\n';
3709 os << "\\begin{" << style.latexname() << '}'
3710 << style.latexparam() << '\n';
3713 LyXParagraph * par = this;
3715 par = par->TeXOnePar(buf, bparams,
3717 foot, foot_texrow, foot_count);
3719 if (minipage_open && par && !style.isEnvironment() &&
3720 (par->pextra_type == PEXTRA_MINIPAGE) &&
3721 par->pextra_start_minipage) {
3722 os << "\\end{minipage}\n";
3724 if (par_sep == BufferParams::PARSEP_INDENT) {
3728 minipage_open = false;
3730 if (par && par->depth > depth) {
3731 if (textclasslist.Style(bparams.textclass,
3732 par->layout).isParagraph()
3735 // How to handle this? (Lgb)
3736 //&& !suffixIs(os, "\n\n")
3738 // There should be at least one '\n' already
3739 // but we need there to be two for Standard
3740 // paragraphs that are depth-increment'ed to be
3741 // output correctly. However, tables can
3742 // also be paragraphs so don't adjust them.
3745 // Will it ever harm to have one '\n' too
3746 // many? i.e. that we sometimes will have
3747 // three in a row. (Lgb)
3751 par = par->TeXDeeper(buf, bparams, os, texrow,
3752 foot, foot_texrow, foot_count);
3754 if (par && par->layout == layout && par->depth == depth &&
3755 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3756 if (par->pextra_hfill && par->Previous() &&
3757 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3758 os << "\\hfill{}\n";
3761 if (par_sep == BufferParams::PARSEP_INDENT) {
3762 os << "{\\setlength\\parindent{0pt}\n";
3765 os << "\\begin{minipage}";
3766 switch(par->pextra_alignment) {
3767 case MINIPAGE_ALIGN_TOP:
3770 case MINIPAGE_ALIGN_MIDDLE:
3773 case MINIPAGE_ALIGN_BOTTOM:
3777 if (!par->pextra_width.empty()) {
3778 os << '{' << par->pextra_width << "}\n";
3780 //float ib = atof(par->pextra_widthp.c_str())/100;
3781 // string can't handle floats at present
3782 // so I'll do a conversion by hand knowing that
3783 // the limits are 0.0 to 1.0. ARRae.
3785 switch (par->pextra_widthp.length()) {
3790 os << "0." << par->pextra_widthp;
3793 os << "0.0" << par->pextra_widthp;
3795 os << "\\columnwidth}\n";
3798 if (par_sep == BufferParams::PARSEP_INDENT) {
3799 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3802 minipage_open = true;
3803 minipage_open_depth = par->depth;
3806 && par->layout == layout
3807 && par->depth == depth
3808 && par->pextra_type == pextra_type
3809 && par->footnoteflag == footnoteflag);
3811 if (style.isEnvironment()) {
3812 os << "\\end{" << style.latexname() << '}';
3813 // maybe this should go after the minipage closes?
3814 if (foot_this_level) {
3815 if (foot_count >= 1) {
3816 if (foot_count > 1) {
3817 os << "\\addtocounter{footnote}{-"
3822 texrow += foot_texrow;
3824 foot_texrow.reset();
3829 if (minipage_open && (minipage_open_depth == depth) &&
3830 (!par || par->pextra_start_minipage ||
3831 par->pextra_type != PEXTRA_MINIPAGE)) {
3832 os << "\\end{minipage}\n";
3834 if (par_sep == BufferParams::PARSEP_INDENT) {
3838 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3839 os << "\\medskip\n\n";
3843 minipage_open = false;
3846 os << "\\end{LyXParagraphIndent}\n";
3849 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3850 && par->pextra_hfill)) {
3854 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3855 return par; // ale970302
3860 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3861 BufferParams const & bparams,
3862 ostream & os, TexRow & texrow,
3863 ostream & foot, TexRow & foot_texrow,
3867 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3868 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3869 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3870 "No footnote!" << endl;
3872 LyXParagraph * par = this;
3873 LyXLayout const & style =
3874 textclasslist.Style(bparams.textclass,
3875 previous->GetLayout());
3877 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3878 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3879 "Float other than footnote in command"
3880 " with moving argument is illegal" << endl;
3883 if (footnotekind != LyXParagraph::FOOTNOTE
3884 && footnotekind != LyXParagraph::MARGIN
3887 // How to solve this?
3888 //&& !suffixIs(file, '\n')
3890 // we need to ensure that real floats like tables and figures
3891 // have their \begin{} on a new line otherwise we can get
3892 // incorrect results when using the endfloat.sty package
3893 // especially if two floats follow one another. ARRae 981022
3894 // NOTE: if the file is length 0 it must have just been
3895 // written out so we assume it ended with a '\n'
3897 // As far as I can see there is never any harm in writing
3898 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3903 bool moving_arg = false;
3904 bool need_closing = false;
3905 bool is_rtl = isRightToLeftPar(bparams);
3907 if (is_rtl != parent_is_rtl) {
3912 need_closing = true;
3915 //BufferParams * params = ¤t_view->buffer()->params;
3916 bool footer_in_body = true;
3917 switch (footnotekind) {
3918 case LyXParagraph::FOOTNOTE:
3919 if (style.intitle) {
3920 os << "\\thanks{\n";
3921 footer_in_body = false;
3924 if (foot_count == -1) {
3925 // we're at depth 0 so we can use:
3926 os << "\\footnote{%\n";
3927 footer_in_body = false;
3929 os << "\\footnotemark{}%\n";
3931 // we only need this when there are
3932 // multiple footnotes
3933 os << "\\stepcounter{footnote}";
3935 os << "\\footnotetext{%\n";
3936 foot_texrow.start(this, 0);
3937 foot_texrow.newline();
3942 case LyXParagraph::MARGIN:
3943 os << "\\marginpar{\n";
3945 case LyXParagraph::FIG:
3946 if (pextra_type == PEXTRA_FLOATFLT
3947 && (!pextra_width.empty()
3948 || !pextra_widthp.empty())) {
3949 if (!pextra_width.empty())
3950 os << "\\begin{floatingfigure}{"
3951 << pextra_width << "}\n";
3953 os << "\\begin{floatingfigure}{"
3954 << atoi(pextra_widthp.c_str())/100.0
3955 << "\\textwidth}\n";
3957 os << "\\begin{figure}";
3958 if (!bparams.float_placement.empty()) {
3959 os << '[' << bparams.float_placement << "]\n";
3965 case LyXParagraph::TAB:
3966 os << "\\begin{table}";
3967 if (!bparams.float_placement.empty()) {
3968 os << '[' << bparams.float_placement << "]\n";
3973 case LyXParagraph::WIDE_FIG:
3974 os << "\\begin{figure*}";
3975 if (!bparams.float_placement.empty()) {
3976 os << '[' << bparams.float_placement << "]\n";
3981 case LyXParagraph::WIDE_TAB:
3982 os << "\\begin{table*}";
3983 if (!bparams.float_placement.empty()) {
3984 os << '[' << bparams.float_placement << "]\n";
3989 case LyXParagraph::ALGORITHM:
3990 os << "\\begin{algorithm}\n";
3995 if (footnotekind != LyXParagraph::FOOTNOTE
3996 || !footer_in_body) {
3997 // Process text for all floats except footnotes in body
3999 LyXLayout const & style =
4001 .Style(bparams.textclass, par->layout);
4003 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4005 if (style.isEnvironment()
4006 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4007 // Allows the use of minipages within float
4008 // environments. Shouldn't be circular because
4009 // we don't support footnotes inside
4010 // floats (yet). ARRae
4011 par = par->TeXEnvironment(buf, bparams, os,
4016 par = par->TeXOnePar(buf, bparams,
4017 os, texrow, moving_arg,
4022 if (par && !par->IsDummy() && par->depth > depth) {
4023 par = par->TeXDeeper(buf, bparams, os, texrow,
4027 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4029 // process footnotes > depth 0 or in environments separately
4030 // NOTE: Currently don't support footnotes within footnotes
4031 // even though that is possible using the \footnotemark
4033 std::ostringstream dummy;
4037 TexRow dummy_texrow;
4038 int dummy_count = 0;
4040 LyXLayout const & style =
4042 .Style(bparams.textclass, par->layout);
4044 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4046 if (style.isEnvironment()
4047 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4048 // Allows the use of minipages within float
4049 // environments. Shouldn't be circular because
4050 // we don't support footnotes inside
4051 // floats (yet). ARRae
4052 par = par->TeXEnvironment(buf, bparams,
4054 dummy, dummy_texrow,
4057 par = par->TeXOnePar(buf, bparams,
4060 dummy, dummy_texrow,
4064 if (par && !par->IsDummy() && par->depth > depth) {
4065 par = par->TeXDeeper(buf, bparams,
4067 dummy, dummy_texrow,
4071 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4073 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4074 "Footnote in a Footnote -- not supported"
4077 #ifndef HAVE_OSTREAM
4078 delete [] dummy.str();
4082 switch (footnotekind) {
4083 case LyXParagraph::FOOTNOTE:
4084 if (footer_in_body) {
4085 // This helps tell which of the multiple
4086 // footnotetexts an error was in.
4088 foot_texrow.newline();
4093 case LyXParagraph::MARGIN:
4096 case LyXParagraph::FIG:
4097 if (pextra_type == PEXTRA_FLOATFLT
4098 && (!pextra_width.empty()
4099 || !pextra_widthp.empty()))
4100 os << "\\end{floatingfigure}";
4102 os << "\\end{figure}";
4104 case LyXParagraph::TAB:
4105 os << "\\end{table}";
4107 case LyXParagraph::WIDE_FIG:
4108 os << "\\end{figure*}";
4110 case LyXParagraph::WIDE_TAB:
4111 os << "\\end{table*}";
4113 case LyXParagraph::ALGORITHM:
4114 os << "\\end{algorithm}";
4121 if (footnotekind != LyXParagraph::FOOTNOTE
4122 && footnotekind != LyXParagraph::MARGIN) {
4123 // we need to ensure that real floats like tables and figures
4124 // have their \end{} on a line of their own otherwise we can
4125 // get incorrect results when using the endfloat.sty package.
4130 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4135 bool LyXParagraph::IsDummy() const
4137 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4138 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4142 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4143 int type, char const * width,
4144 char const * widthp)
4147 pextra_width = width;
4148 pextra_widthp = widthp;
4150 if (textclasslist.Style(bparams.textclass,
4151 layout).isEnvironment()) {
4156 while (par && (par->layout == layout)
4157 && (par->depth == depth)) {
4159 par = par->Previous();
4161 par = par->FirstPhysicalPar();
4162 while (par && par->depth > depth) {
4163 par = par->Previous();
4165 par = par->FirstPhysicalPar();
4169 while (par && (par->layout == layout)
4170 && (par->depth == depth)) {
4171 par->pextra_type = type;
4172 par->pextra_width = width;
4173 par->pextra_widthp = widthp;
4174 par = par->NextAfterFootnote();
4175 if (par && (par->depth > depth))
4176 par->SetPExtraType(bparams,
4177 type, width, widthp);
4178 while (par && ((par->depth > depth) || par->IsDummy()))
4179 par = par->NextAfterFootnote();
4185 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4187 if (pextra_type == PEXTRA_NONE)
4190 pextra_type = PEXTRA_NONE;
4191 pextra_width.erase();
4192 pextra_widthp.erase();
4194 if (textclasslist.Style(bparams.textclass,
4195 layout).isEnvironment()) {
4200 while (par && (par->layout == layout)
4201 && (par->depth == depth)) {
4203 par = par->Previous();
4205 par = par->FirstPhysicalPar();
4206 while (par && par->depth > depth) {
4207 par = par->Previous();
4209 par = par->FirstPhysicalPar();
4213 while (par && (par->layout == layout)
4214 && (par->depth == depth)) {
4215 par->pextra_type = PEXTRA_NONE;
4216 par->pextra_width.erase();
4217 par->pextra_widthp.erase();
4218 par = par->NextAfterFootnote();
4219 if (par && (par->depth > depth))
4220 par->UnsetPExtraType(bparams);
4221 while (par && ((par->depth > depth) || par->IsDummy()))
4222 par = par->NextAfterFootnote();
4228 bool LyXParagraph::IsHfill(size_type pos) const
4230 return IsHfillChar(GetChar(pos));
4234 bool LyXParagraph::IsInset(size_type pos) const
4236 return IsInsetChar(GetChar(pos));
4240 bool LyXParagraph::IsFloat(size_type pos) const
4242 return IsFloatChar(GetChar(pos));
4246 bool LyXParagraph::IsNewline(size_type pos) const
4248 return pos >= 0 && IsNewlineChar(GetChar(pos));
4252 bool LyXParagraph::IsSeparator(size_type pos) const
4254 return IsSeparatorChar(GetChar(pos));
4258 bool LyXParagraph::IsLineSeparator(size_type pos) const
4260 return IsLineSeparatorChar(GetChar(pos));
4264 bool LyXParagraph::IsKomma(size_type pos) const
4266 return IsKommaChar(GetChar(pos));
4270 /// Used by the spellchecker
4271 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4273 value_type c = GetChar(pos);
4274 if (IsLetterChar(c))
4276 // '\0' is not a letter, allthough every string contains "" (below)
4279 // We want to pass the ' and escape chars to ispell
4280 string extra = lyxrc.isp_esc_chars + '\'';
4284 return contains(extra, ch);
4288 bool LyXParagraph::IsWord(size_type pos ) const
4290 return IsWordChar(GetChar(pos)) ;
4295 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4298 return FirstPhysicalPar()->getParLanguage(bparams);
4299 else if (size() > 0)
4303 return GetFirstFontSettings().language();
4306 for (size_type pos = 0; pos < size(); ++pos)
4308 return GetFontSettings(bparams, pos).language();
4309 return GetFirstFontSettings().language();
4313 return previous->getParLanguage(bparams);
4315 return bparams.language_info;
4319 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4321 return lyxrc.rtl_support && !table
4322 && getParLanguage(bparams)->RightToLeft();
4326 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4327 Language const * from, Language const * to)
4329 for(size_type i = 0; i < size(); ++i) {
4330 LyXFont font = GetFontSettings(bparams, i);
4331 if (font.language() == from) {
4332 font.setLanguage(to);
4339 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4341 Language const * doc_language =
4342 bparams.language_info;
4343 for(size_type i = 0; i < size(); ++i) {
4344 LyXFont font = GetFontSettings(bparams, i);
4345 if (font.language() != doc_language)
4352 // Convert the paragraph to a string.
4353 // Used for building the table of contents
4354 string LyXParagraph::String(Buffer const * buffer, bool label)
4356 BufferParams const & bparams = buffer->params;
4358 if (label && !IsDummy() && !labelstring.empty())
4359 s += labelstring + ' ';
4360 string::size_type len = s.size();
4362 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4363 value_type c = GetChar(i);
4366 else if (c == META_INSET &&
4367 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4369 std::ostringstream ost;
4370 GetInset(i)->Ascii(buffer, ost);
4373 GetInset(i)->Ascii(buffer, ost);
4376 s += subst(ost.str(),'\n',' ');
4381 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4382 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4383 s += NextAfterFootnote()->String(buffer, false);
4388 if (isRightToLeftPar(bparams))
4389 reverse(s.begin() + len,s.end());
4395 string LyXParagraph::String(Buffer const * buffer,
4396 LyXParagraph::size_type beg,
4397 LyXParagraph::size_type end)
4404 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4406 if (cell >= table->NumberOfCellsInRow(actcell))
4414 if (beg == 0 && !IsDummy() && !labelstring.empty())
4415 s += labelstring + ' ';
4417 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4418 value_type c = GetChar(i);
4421 else if (c == META_INSET) {
4423 std::ostringstream ost;
4424 GetInset(i)->Ascii(buffer, ost);
4427 GetInset(i)->Ascii(buffer, ost);
4431 } else if (table && IsNewlineChar(c)) {
4432 if (cell >= table->NumberOfCellsInRow(actcell)) {
4443 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4444 // s += NextAfterFootnote()->String(false);
4450 void LyXParagraph::SetInsetOwner(Inset *i)
4453 for (InsetList::const_iterator cit = insetlist.begin();
4454 cit != insetlist.end(); ++cit) {
4456 (*cit).inset->setOwner(i);
4461 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4464 for (InsetList::const_iterator cit = insetlist.begin();
4465 cit != insetlist.end(); ++cit) {
4467 if ((*cit).inset->IsTextInset()) {
4468 static_cast<UpdatableInset *>
4469 ((*cit).inset)->deleteLyXText(bv);
4476 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4479 for (InsetList::const_iterator cit = insetlist.begin();
4480 cit != insetlist.end(); ++cit) {
4482 if ((*cit).inset->IsTextInset()) {
4483 static_cast<UpdatableInset *>
4484 ((*cit).inset)->resizeLyXText(bv);