The attached patch addresses some output errors connected with paragraph
parameters as set through the paragraph settings dialog. See
http://www.mail-archive.com/[EMAIL PROTECTED]/msg113940.html
for some earlier remarks. Another version of this bug is that if the
user tries to single space (say) all items in a list, LyX will output:
\begin{lyxlist}
\begin{singlespace}
\item[Label] Text of item.
\item[Label] Text of item.
\end{singlespace}
\end{lyxlist}
(modulo the whitespace), which won't compile.
I've tested this on several files and compared the LaTeX output to that
produced by 1.5.beta1and the differences are trivial and are mostly due
to the fact that I've started handling the line length a little earlier
than was done in the old code, so that there are fewer long lines than
there were.
Here's a guide to the patch, as it's large because of all the moving around.
ParagraphParameters.[Ch]: what were Paragraph::startTeXParParams and
endTeXParParams are moved here, as suggested in existing comments;
writeParamsBegin() and ...End() now output the full complement of
parameters, except the label width string, which is handled in
output_latex::TeXEnvironment. Support routines from Paragraph.C were
moved along with these, and a couple more helper functions added.
paragraph.[Ch]: simpleTeXOnePar now handles all the output for a
paragraph (except language stuff, which could probably be moved
here, too, and some stuff involving resetting font size), whereas
some used to be in output_latex.C and some here. The code here
handles commands with moving arguments differently than commands
that do not have moving arguments, for reasons detailed elsewhere
(namely, that users do not expect setting right alignment of section
headings, say, to destroy their table of contents and page headers).
However, if the decision were made not to go that way, the code can
easily be adapted, and there are comments in the code detailing what
little would need doing.
output_latex.C: Most of the changes here involve moving things to
paragraph.C. There are a couple of changes, however, on which I seek
comment. (i) The old code examined the return value of
paragraph::simpleTeXOnePar in various places. So far as I can see,
the extant version always returns false, so I've removed those
tests. I suppose it once might have returned true and that this was
dead code. Is that right? If so, simpleTeXOnePar should presumably
be made void. (ii) This would be nicer if the calcuation of
beginParams and endParams could happen in simpleTeXOnePar.
Unfortunately, I cannot get that to work. I then need
simpleTeXOnePar to take an argument of type
ParagraphList::const_iterator, but no matter what I try to #include,
I get errors. For example, #including ParagraphList_fwd gives
forward declaration errors. Presumably, there is a way around this.
(iii) I don't fully understand what the TexRow class does. But in so
far as I do, it seems to me that texrow.start() ought to be called
at the beginning of the paragraph's output. So I've moved the call
there. If that's wrong---the existing place seems to be at the
beginning of the output of the actual text of the paragraph---please
let me know, and I'll restore it.
There's still some cleanup to be done, and there's one change indicated
in a FIXME in paragraph.C that should simplify a bit of this enormously,
but I'll wait to do that until people more experienced than I am have a
chance to look at this.
Thanks,
Richard
--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto
Index: paragraph.h
===================================================================
--- paragraph.h (revision 17786)
+++ paragraph.h (working copy)
@@ -21,6 +21,7 @@
#include "InsetList.h"
#include "lyxlayout_ptr_fwd.h"
#include "RowList_fwd.h"
+#include "support/RandomAccessList.h"
#include "insets/insetbase.h" // only for InsetBase::Code
@@ -115,18 +116,11 @@
void validate(LaTeXFeatures &) const;
///
- int startTeXParParams(BufferParams const &, odocstream &, TexRow &,
- bool) const;
-
- ///
- int endTeXParParams(BufferParams const &, odocstream &, TexRow &,
- bool) const;
-
-
- ///
bool simpleTeXOnePar(Buffer const &, BufferParams const &,
- LyXFont const & outerfont, odocstream &,
- TexRow & texrow, OutputParams const &) const;
+ docstring const & beginParams, docstring const & endParams,
+ std::string const &, Paragraph const &,
+ LyXFont const &, odocstream &,
+ TexRow &, OutputParams const &) const;
/// Can we drop the standard paragraph wrapper?
bool emptyTag() const;
@@ -153,6 +147,10 @@
///
bool hasSameLayout(Paragraph const & par) const;
+ ///
+ bool hasSameSpacing(Paragraph const & par) const;
+ ///
+ bool hasSameAlignment(Paragraph const & par) const;
///
void makeSameLayout(Paragraph const & par);
Index: ParagraphParameters.C
===================================================================
--- ParagraphParameters.C (revision 17786)
+++ ParagraphParameters.C (working copy)
@@ -17,13 +17,15 @@
#include "ParagraphParameters.h"
#include "buffer.h"
+#include "debug.h"
#include "gettext.h"
#include "lyxlayout.h"
#include "lyxlex.h"
#include "lyxtext.h"
#include "paragraph.h"
#include "tex-strings.h"
-
+#include "insets/inset.h"
+#include "insets/insetbase.h"
#include "support/lstrings.h"
#include <sstream>
@@ -31,6 +33,9 @@
namespace lyx {
using support::rtrim;
+//For adjust_row_column
+//using support::contains;
+//using support::rsplit;
using std::istringstream;
using std::ostream;
@@ -38,6 +43,65 @@
using std::string;
+namespace {
+
+// paragraphs inside floats need different alignment tags to avoid
+// unwanted space
+
+bool noTrivlistCentering(InsetBase::Code code)
+{
+ return code == InsetBase::FLOAT_CODE || code == InsetBase::WRAP_CODE;
+}
+
+
+string correction(string const & orig)
+{
+ if (orig == "flushleft")
+ return "raggedright";
+ if (orig == "flushright")
+ return "raggedleft";
+ if (orig == "center")
+ return "centering";
+ return orig;
+}
+
+
+string const corrected_env(string const & prefix, string const & env,
+ InsetBase::Code code)
+{
+ string output = prefix + "{";
+ if (noTrivlistCentering(code))
+ output += correction(env);
+ else
+ output += env;
+ output += "}";
+ return output;
+}
+
+
+/* At the moment, this isn't needed, but it might be needed at some point.
+ I've generalized it to deal with multiple `\n's.
+void adjust_row_column(string const & str, TexRow & texrow, int & column)
+{
+ if (!contains(str, "\n")) {
+ contains += str.size();
+ return;
+}
+ string rightSide = str;
+ string leftSide;
+ while (contains(rightSide, "\n") {
+ string const tmp = rightSide;
+ rightSide = rsplit(tmp, leftSide, "\n");
+ texrow.newline();
+ }
+ column = whatsLeft.size();
+ return;
+}
+*/
+
+} // namespace anon
+
+
static int findToken(char const * const str[], string const & search_token)
{
return search_token == "default" ?
@@ -74,6 +138,18 @@
}
+bool ParagraphParameters::sameSpacing(ParagraphParameters const & pp) const
+{
+ return spacing_ == pp.spacing_;
+}
+
+
+bool ParagraphParameters::sameAlignment(ParagraphParameters const & pp) const
+{
+ return align_ == pp.align_;
+}
+
+
Spacing const & ParagraphParameters::spacing() const
{
return spacing_;
@@ -314,4 +390,136 @@
*/
+string const ParagraphParameters::writeAlignBegin(
+ Language const * const & lang, InsetBase::Code const & owner) const
+{
+ // NOTE NO_MOVING_ARG
+ // need one more parameter: bool movingArg
+ // string const protect = movingArg ? "\\protect" : "";
+ switch (align()) {
+ case LYX_ALIGN_NONE:
+ case LYX_ALIGN_BLOCK:
+ case LYX_ALIGN_LAYOUT:
+ case LYX_ALIGN_SPECIAL:
+ return "";
+ case LYX_ALIGN_LEFT: {
+ if (lang->babel() != "hebrew")
+ // NOTE NO_MOVING_ARG
+ // return protect + corrected_env(protect + "\\begin", "flushleft", owner);
+ // and similarly below
+ return corrected_env("\\begin", "flushleft", owner);
+ else
+ return corrected_env("\\begin", "flushright", owner);
+ } case LYX_ALIGN_RIGHT: {
+ if (lang->babel() != "hebrew")
+ return corrected_env("\\begin", "flushright", owner);
+ else
+ return corrected_env("\\begin", "flushleft", owner);
+ } case LYX_ALIGN_CENTER: {
+ return corrected_env("\\begin", "center", owner);
+ }
+ }
+ //should never get here
+ lyxerr << BOOST_CURRENT_FUNCTION << "Invalid alignment" <<
+ align() << std::endl;
+ return "";
+}
+
+
+string const ParagraphParameters::writeAlignEnd(
+ Language const * const & lang, InsetBase::Code const & owner) const
+{
+ //NOTE NO_MOVING_ARG
+ //The previous version put a "\par" before the "\end". That
+ //does not seem to be necessary, and it causes problems if one
+ //tries to put it inside a moving argument. So if it does need to
+ //be restored, we'd need to output it only if we are NOT in a
+ //moving argument. Thus:
+ // string const protect = movingArg ? "\\protect" : "\\par";
+ switch (align()) {
+ case LYX_ALIGN_NONE:
+ case LYX_ALIGN_BLOCK:
+ case LYX_ALIGN_LAYOUT:
+ case LYX_ALIGN_SPECIAL:
+ return "";
+ case LYX_ALIGN_LEFT: {
+ if (lang->babel() != "hebrew")
+ return corrected_env("\\end", "flushleft", owner);
+ else
+ return corrected_env("\\end", "flushright", owner);
+ } case LYX_ALIGN_RIGHT: {
+ if (lang->babel() != "hebrew")
+ return corrected_env("\\end", "flushright", owner);
+ else
+ return corrected_env("\\end", "flushleft", owner);
+ } case LYX_ALIGN_CENTER: {
+ return corrected_env("\\end", "center", owner);
+ }
+ }
+ //should never get here
+ lyxerr << BOOST_CURRENT_FUNCTION << "Invalid alignment" <<
+ align() << std::endl;
+ return "";
+}
+
+
+string ParagraphParameters::writeParamsBegin(
+ ParagraphList::const_iterator & pit,
+ Language const * const & lang,
+ bool const isFirst) const
+{
+ if (pit->forceDefaultParagraphs()) return "";
+ // NOTE NO_MOVING_ARG
+ // string protect = pit->layout()->needprotect ? "\\protect" : "";
+ ostringstream output;
+ //if the layout isn't default
+ //and we're either in the first paragraph or
+ //the previous paragraph has the same alignment...
+ if (!spacing().isDefault()
+ && (isFirst || !boost::prior(pit)->hasSameSpacing(*pit))) {
+ // NOTE NO_MOVING_ARG
+ // output << protect << ...
+ output << spacing().writeEnvirBegin() << " ";
+ }
+
+ if (pit->params().noindent()) {
+ // NOTE NO_MOVING_ARG
+ // output << protect << ...
+ output << "\\noindent ";
+ }
+
+ if (align() != LYX_ALIGN_LAYOUT
+ && align() != pit->layout()->align
+ && (isFirst || !boost::prior(pit)->hasSameAlignment(*pit)))
+ output << writeAlignBegin(lang, pit->ownerCode()) << " ";
+ return output.str();
+}
+
+
+string ParagraphParameters::writeParamsEnd(
+ ParagraphList::const_iterator & pit,
+ Language const * const & lang,
+ bool const isLast) const
+{
+ if (pit->forceDefaultParagraphs()) return "";
+ ostringstream output;
+ //if the layout isn't default
+ //and we're either in the last paragraph or
+ //the next paragraph has the same alignment...
+ if (align() != LYX_ALIGN_LAYOUT
+ && align() != pit->layout()->align
+ && (isLast || !boost::next(pit)->hasSameAlignment(*pit))) {
+ // NOTE NO_MOVING_ARG
+ // output << protect << ...
+ output << writeAlignEnd(lang, pit->ownerCode()) << " ";
+ }
+ if (!spacing().isDefault()
+ && (isLast || !boost::next(pit)->hasSameSpacing(*pit))) {
+ // NOTE NO_MOVING_ARG
+ // output << protect << ...
+ output << (spacing().writeEnvirEnd()) << " ";
+ }
+ return output.str();
+}
+
} // namespace lyx
Index: ParagraphParameters.h
===================================================================
--- ParagraphParameters.h (revision 17786)
+++ ParagraphParameters.h (working copy)
@@ -14,8 +14,10 @@
#ifndef PARAGRAPHPARAMETERS_H
#define PARAGRAPHPARAMETERS_H
+#include "language.h"
#include "layout.h"
#include "lyxlength.h"
+#include "ParagraphList.h"
#include "Spacing.h"
#include "support/types.h"
@@ -44,6 +46,10 @@
///
bool sameLayout(ParagraphParameters const &) const;
///
+ bool sameSpacing(ParagraphParameters const &) const;
+ ///
+ bool sameAlignment(ParagraphParameters const &) const;
+ ///
Spacing const & spacing() const;
///
void spacing(Spacing const &);
@@ -85,10 +91,32 @@
/// write out the parameters to a stream
void write(std::ostream & os) const;
+
+ /// Writes the opening LaTeX for spacing, alignment, and indentation
+ /// @return a string, with no newlines embedded
+ std::string writeParamsBegin(ParagraphList::const_iterator & pit,
+ Language const * const & lang, bool const isFirst = false) const;
+ /// Writes the closing LaTeX for spacing, alignment, and indentation
+ /// @return a string, with no newlines embedded
+ std::string writeParamsEnd(ParagraphList::const_iterator & pit,
+ Language const * const & lang, bool const isLast = false) const;
+
//friend bool operator==(ParameterStruct const & ps1,
//ParameterStruct const & ps2);
+protected:
+ // NOTE NO_MOVING_ARGS
+ // The next two routines would need to take a boolean (whether we are in a
+ // moving argument).
+ ///
+ std::string const writeAlignBegin(Language const * const &,
+ InsetBase::Code const &) const;
+ ///
+ std::string const writeAlignEnd(Language const * const &,
+ InsetBase::Code const &) const;
+
+
private:
///
Spacing spacing_;
Index: paragraph.C
===================================================================
--- paragraph.C (revision 17786)
+++ paragraph.C (working copy)
@@ -69,10 +69,6 @@
namespace lyx {
-using support::contains;
-using support::rsplit;
-using support::subst;
-
Paragraph::Paragraph()
: begin_of_body_(0), pimpl_(new Paragraph::Pimpl(this))
{
@@ -586,6 +582,18 @@
}
+bool Paragraph::hasSameSpacing(Paragraph const & par) const
+{
+ return params().sameSpacing(par.params());
+}
+
+
+bool Paragraph::hasSameAlignment(Paragraph const & par) const
+{
+ return params().sameAlignment(par.params());
+}
+
+
depth_type Paragraph::getDepth() const
{
return params().depth();
@@ -755,186 +763,14 @@
}
-namespace {
-
-// paragraphs inside floats need different alignment tags to avoid
-// unwanted space
-
-bool noTrivlistCentering(InsetBase::Code code)
-{
- return code == InsetBase::FLOAT_CODE || code == InsetBase::WRAP_CODE;
-}
-
-
-string correction(string const & orig)
-{
- if (orig == "flushleft")
- return "raggedright";
- if (orig == "flushright")
- return "raggedleft";
- if (orig == "center")
- return "centering";
- return orig;
-}
-
-
-string const corrected_env(string const & suffix, string const & env,
- InsetBase::Code code)
-{
- string output = suffix + "{";
- if (noTrivlistCentering(code))
- output += correction(env);
- else
- output += env;
- output += "}";
- if (suffix == "\\begin")
- output += "\n";
- return output;
-}
-
-
-void adjust_row_column(string const & str, TexRow & texrow, int & column)
-{
- if (!contains(str, "\n"))
- column += str.size();
- else {
- string tmp;
- texrow.newline();
- column = rsplit(str, tmp, '\n').size();
- }
-}
-
-} // namespace anon
-
-
-// This could go to ParagraphParameters if we want to
-int Paragraph::startTeXParParams(BufferParams const & bparams,
- odocstream & os, TexRow & texrow,
- bool moving_arg) const
-{
- int column = 0;
-
- if (params().noindent()) {
- os << "\\noindent ";
- column += 10;
- }
-
- switch (params().align()) {
- case LYX_ALIGN_NONE:
- case LYX_ALIGN_BLOCK:
- case LYX_ALIGN_LAYOUT:
- case LYX_ALIGN_SPECIAL:
- break;
- case LYX_ALIGN_LEFT:
- case LYX_ALIGN_RIGHT:
- case LYX_ALIGN_CENTER:
- if (moving_arg) {
- os << "\\protect";
- column += 8;
- }
- break;
- }
-
- switch (params().align()) {
- case LYX_ALIGN_NONE:
- case LYX_ALIGN_BLOCK:
- case LYX_ALIGN_LAYOUT:
- case LYX_ALIGN_SPECIAL:
- break;
- case LYX_ALIGN_LEFT: {
- string output;
- if (getParLanguage(bparams)->babel() != "hebrew")
- output = corrected_env("\\begin", "flushleft", ownerCode());
- else
- output = corrected_env("\\begin", "flushright", ownerCode());
- os << from_ascii(output);
- adjust_row_column(output, texrow, column);
- break;
- } case LYX_ALIGN_RIGHT: {
- string output;
- if (getParLanguage(bparams)->babel() != "hebrew")
- output = corrected_env("\\begin", "flushright", ownerCode());
- else
- output = corrected_env("\\begin", "flushleft", ownerCode());
- os << from_ascii(output);
- adjust_row_column(output, texrow, column);
- break;
- } case LYX_ALIGN_CENTER: {
- string output;
- output = corrected_env("\\begin", "center", ownerCode());
- os << from_ascii(output);
- adjust_row_column(output, texrow, column);
- break;
- }
- }
-
- return column;
-}
-
-
-// This could go to ParagraphParameters if we want to
-int Paragraph::endTeXParParams(BufferParams const & bparams,
- odocstream & os, TexRow & texrow,
- bool moving_arg) const
-{
- int column = 0;
-
- switch (params().align()) {
- case LYX_ALIGN_NONE:
- case LYX_ALIGN_BLOCK:
- case LYX_ALIGN_LAYOUT:
- case LYX_ALIGN_SPECIAL:
- break;
- case LYX_ALIGN_LEFT:
- case LYX_ALIGN_RIGHT:
- case LYX_ALIGN_CENTER:
- if (moving_arg) {
- os << "\\protect";
- column = 8;
- }
- break;
- }
-
- switch (params().align()) {
- case LYX_ALIGN_NONE:
- case LYX_ALIGN_BLOCK:
- case LYX_ALIGN_LAYOUT:
- case LYX_ALIGN_SPECIAL:
- break;
- case LYX_ALIGN_LEFT: {
- string output;
- if (getParLanguage(bparams)->babel() != "hebrew")
- output = corrected_env("\n\\par\\end", "flushleft", ownerCode());
- else
- output = corrected_env("\n\\par\\end", "flushright", ownerCode());
- os << from_ascii(output);
- adjust_row_column(output, texrow, column);
- break;
- } case LYX_ALIGN_RIGHT: {
- string output;
- if (getParLanguage(bparams)->babel() != "hebrew")
- output = corrected_env("\n\\par\\end", "flushright", ownerCode());
- else
- output = corrected_env("\n\\par\\end", "flushleft", ownerCode());
- os << from_ascii(output);
- adjust_row_column(output, texrow, column);
- break;
- } case LYX_ALIGN_CENTER: {
- string output;
- output = corrected_env("\n\\par\\end", "center", ownerCode());
- os << from_ascii(output);
- adjust_row_column(output, texrow, column);
- break;
- }
- }
-
- return column;
-}
-
-
-// This one spits out the text of the paragraph
+// This one spits out the latex for the paragraph
+// Note that it does NOT end with a newline.
bool Paragraph::simpleTeXOnePar(Buffer const & buf,
BufferParams const & bparams,
+ docstring const & beginParams,
+ docstring const & endParams,
+ string const & everypar,
+ Paragraph const & pit,
LyXFont const & outerfont,
odocstream & os, TexRow & texrow,
OutputParams const & runparams) const
@@ -950,14 +786,119 @@
// any special options in the paragraph and also we don't allow
// any environment other than the default layout of the text class
// to be valid!
- bool asdefault = forceDefaultParagraphs();
+ // (rgh) More generally, this just checks whether the inset allows
+ // paragraph options. It might have various reasons not to do so.
+ bool forceDefault = forceDefaultParagraphs();
- if (asdefault) {
+ if (forceDefault) {
style = bparams.getLyXTextClass().defaultLayout();
} else {
style = layout();
}
+ if (!forceDefault) {
+ if (pit.params().startOfAppendix()) {
+ os << "\\appendix\n";
+ texrow.newline();
+ }
+
+ if (style->isCommand()) {
+ os << '\n';
+ texrow.newline();
+ }
+ }
+
+ // Maybe we have to create an optional argument.
+ pos_type body_pos = beginOfBody();
+ bool const haveOptionalArgument = (body_pos > 0);
+ unsigned int column = 0;
+
+ /*
+ Exactly when the beginning parameters need to be output depends upon
+ several factors:
+ (i) If we are in a command:
+ a. If it's a moving argument, then it needs to be output BEFORE
+ the command itself.
+ b. If not, then it should be output inside the command.
+ (ii) If we're in an item of some sort, then it needs to go INSIDE the
+ item but AFTER the optional argument.
+ (iii) If we're not in either of those cases, life is good.
+ Note that this assumes we are treating commands with moving arguments
+ differently from how we're treating other commands.
+
+ The code is easily adapted should we decide not to treat moving arguments
+ specially. The changes needed here are marked below as:
+ NOTE NO_MOVING_ARGS
+ Other needed changes are noted in ParagraphParameters.[Ch].
+ */
+
+ switch (style->latextype) {
+ case LATEX_COMMAND:
+ //If it's a moving argument, we want this stuff OUTSIDE the command
+ //FIXME @noskipsectrue solves the problem with sections and stuff
+ //NOTE NO_MOVING_ARGS: remove the next four lines
+ if (style->needprotect && !beginParams.empty()) {
+ os << beginParams << "\n";
+ texrow.newline();
+ //column = 0;
+ }
+ os << '\\' << from_ascii(style->latexname());
+
+ // Separate handling of optional argument inset.
+ if (style->optionalargs > 0) {
+ int ret = latexOptArgInsets(buf, pit, os, runparams,
+ style->optionalargs);
+ while (ret > 0) {
+ texrow.newline();
+ --ret;
+ }
+ }
+ else
+ os << from_ascii(style->latexparam());
+ os << "{";
+ column += 1;
+ //If it's not a moving argument, we want this stuff INSIDE the command
+ //NOTE NO_MOVING_ARGS: remove the next line
+ if (!style->needprotect && !beginParams.empty()) {
+ os << beginParams << "\n";
+ texrow.newline();
+ column = 0;
+ }
+ break;
+ case LATEX_ITEM_ENVIRONMENT:
+ case LATEX_LIST_ENVIRONMENT:
+ os << "\\item ";
+ if (!haveOptionalArgument && !beginParams.empty()) {
+ os << beginParams << "\n";
+ texrow.newline();
+ } else column += 6;
+ //else beginParams will be written later
+ break;
+ case LATEX_BIB_ENVIRONMENT:
+ // ignore this, the inset will write itself
+ // FIXME If so, can we just return now?
+ break;
+ default:
+ if (!beginParams.empty()) {
+ os << beginParams << "\n";
+ texrow.newline();
+ //column = 0;
+ }
+ //break;
+ }
+
+ // This too needs to be delayed if there are optional arguments
+ if (!everypar.empty() && !haveOptionalArgument) {
+ //FIXME Might everypar have embedded newlines that need
+ //to be handled? If so, the generalized version of the old
+ //adjust_row_column now in ParagraphParameters.C could be
+ //used (though it'd need to move out of that namespace).
+ os << from_utf8(everypar) << "\n";
+ texrow.newline();
+ column = 0;
+ }
+
+
// Current base font for all inherited font changes, without any
// change caused by an individual character, except for the language:
// It is set to the language of the first character.
@@ -973,11 +914,7 @@
&& runparams.flavor == OutputParams::LATEX
&& LaTeXFeatures::isAvailable("dvipost");
- // Maybe we have to create a optional argument.
- pos_type body_pos = beginOfBody();
- unsigned int column = 0;
-
- if (body_pos > 0) {
+ if (haveOptionalArgument) {
// the optional argument is kept in curly brackets in
// case it contains a ']'
os << "[{";
@@ -994,26 +931,15 @@
Change::Type runningChangeType = Change::UNCHANGED;
- texrow.start(id(), 0);
-
- // if the paragraph is empty, the loop will not be entered at all
- if (empty()) {
- if (style->isCommand()) {
- os << '{';
- ++column;
- }
- if (!asdefault)
- column += startTeXParParams(bparams, os, texrow,
- runparams.moving_arg);
- }
-
+ // texrow.start(id(), 0);
+
// Computed only once per paragraph since bparams.encoding() is expensive
Encoding const & doc_encoding = bparams.encoding();
for (pos_type i = 0; i < size(); ++i) {
// First char in paragraph or after label?
if (i == body_pos) {
- if (body_pos > 0) {
+ if (haveOptionalArgument) {
if (open_font) {
column += running_font.latexWriteEndChanges(
os, basefont, basefont);
@@ -1027,17 +953,24 @@
runningChangeType = Change::UNCHANGED;
os << "}] ";
- column +=3;
+ column += 3;
+ //FIXME If this were moved outside haveOptionalArgument
+ //then it would be output at the beginning of the paragraph
+ //if body_pos == 0. So then we could simply do it here for
+ //every case except moving arguments. That is:
+ //if (!style->needprotect) {
+ //Check this....
+ if (!beginParams.empty()) {
+ os << beginParams << "\n";
+ texrow.newline();
+ column = 0;
+ }
+ if (!everypar.empty()) {
+ os << from_utf8(everypar) << "\n";
+ texrow.newline();
+ column = 0;
+ }
}
- if (style->isCommand()) {
- os << '{';
- ++column;
- }
-
- if (!asdefault)
- column += startTeXParParams(bparams, os,
- texrow,
- runparams.moving_arg);
}
Change::Type changeType = pimpl_->lookupChange(i).type;
@@ -1049,7 +982,7 @@
continue;
}
- ++column;
+ ++column; //this is for the character we're now outputting
column += Changes::latexMarkChange(os, runningChangeType,
changeType, output);
@@ -1121,7 +1054,8 @@
texrow, rp, running_font,
basefont, outerfont, open_font,
runningChangeType, *style, i, column, c);
- }
+ } //close of for loop
+ //Output of text of paragraph has now ended
// If we have an open font definition, we have to close it
if (open_font) {
@@ -1150,12 +1084,37 @@
// Needed if there is an optional argument but no contents.
if (body_pos > 0 && body_pos == size()) {
os << "}]~";
+ if (!beginParams.empty()) {
+ os << beginParams << "\n";
+ texrow.newline();
+ column = 0;
+ }
return_value = false;
}
-
- if (!asdefault) {
- column += endTeXParParams(bparams, os, texrow,
- runparams.moving_arg);
+
+ //We need to close the command if we were in one,
+ //and output the ending parameters at the right location.
+ if (style->isCommand()) {
+ //NOTE NO_MOVING_ARGS: remove the "if" part
+ if (style->needprotect) {
+ os << "}";
+ if (!endParams.empty()) {
+ os << "\n" << endParams;
+ texrow.newline();
+ }
+ } else {
+ if (!endParams.empty()) {
+ os << "\n" << endParams;
+ texrow.newline();
+ }
+ os << "}" ;
+ }
+ }
+ else {
+ if (!endParams.empty()) {
+ os << "\n" << endParams;
+ texrow.newline();
+ }
}
LYXERR(Debug::LATEX) << "SimpleTeXOnePar...done " << this << endl;
Index: output_latex.C
===================================================================
--- output_latex.C (revision 17786)
+++ output_latex.C (working copy)
@@ -244,9 +244,10 @@
<< everypar << "'" << endl;
BufferParams const & bparams = buf.params();
LyXLayout_ptr style;
-
- // In an inset with unlimited length (all in one row),
- // force layout to default
+
+ texrow.start(pit->id(), 0);
+
+ //Some insets don't allow customization
if (!pit->forceDefaultParagraphs())
style = pit->layout();
else
@@ -255,17 +256,19 @@
OutputParams runparams = runparams_in;
runparams.moving_arg |= style->needprotect;
+ bool const isFirstPar = (pit == paragraphs.begin());
+ bool const isLastPar = (boost::next(pit) == paragraphs.end());
+
Language const * const par_language = pit->getParLanguage(bparams);
Language const * const doc_language = bparams.language;
- Language const * const prev_par_language =
- (pit != paragraphs.begin())
+ Language const * const prev_par_language = (!isFirstPar)
? boost::prior(pit)->getParLanguage(bparams)
: doc_language;
if (par_language->babel() != prev_par_language->babel()
// check if we already put language command in TeXEnvironment()
&& !(style->isEnvironment()
- && (pit == paragraphs.begin() ||
+ && (isFirstPar ||
(boost::prior(pit)->layout() != pit->layout() &&
boost::prior(pit)->getDepth() <= pit->getDepth())
|| boost::prior(pit)->getDepth() < pit->getDepth())))
@@ -292,65 +295,28 @@
}
}
- // In an inset with unlimited length (all in one row),
- // don't allow any special options in the paragraph
- if (!pit->forceDefaultParagraphs()) {
- if (pit->params().startOfAppendix()) {
- os << "\\appendix\n";
- texrow.newline();
- }
+ //FIXME These really ought to be calcuated in simpleTeXOnePar,
+ //but I can't seem to get it to compile, then. We would need
+ //simpleTeXOnePar to take an argument of type ParagraphList::const_iterator
+ //(now it takes Paragraph const &), but #including ParagraphList_fwd
+ //gives forward declaration errors....
+ docstring const beginParams =
+ from_ascii(pit->params().writeParamsBegin(pit, par_language, isFirstPar));
+ docstring const endParams =
+ from_ascii(pit->params().writeParamsEnd(pit, par_language, isLastPar));
- if (!pit->params().spacing().isDefault()
- && (pit == paragraphs.begin()
- || !boost::prior(pit)->hasSameLayout(*pit)))
- {
- os << from_ascii(pit->params().spacing().writeEnvirBegin())
- << '\n';
- texrow.newline();
- }
-
- if (style->isCommand()) {
- os << '\n';
- texrow.newline();
- }
- }
-
- switch (style->latextype) {
- case LATEX_COMMAND:
- os << '\\' << from_ascii(style->latexname());
-
- // Separate handling of optional argument inset.
- if (style->optionalargs > 0) {
- int ret = latexOptArgInsets(buf, *pit, os, runparams,
- style->optionalargs);
- while (ret > 0) {
- texrow.newline();
- --ret;
- }
- }
- else
- os << from_ascii(style->latexparam());
- break;
- case LATEX_ITEM_ENVIRONMENT:
- case LATEX_LIST_ENVIRONMENT:
- os << "\\item ";
- break;
- case LATEX_BIB_ENVIRONMENT:
- // ignore this, the inset will write itself
- break;
- default:
- break;
- }
-
LyXFont const outerfont =
outerFont(std::distance(paragraphs.begin(), pit),
paragraphs);
- // FIXME UNICODE
- os << from_utf8(everypar);
- bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
- os, texrow, runparams);
-
+ //FIXME So far as I can see (rgh), this is always false in the old code,
+ //and that hasn't changed in the new code.
+ //bool need_par =
+ pit->simpleTeXOnePar(buf, bparams,
+ beginParams, endParams, everypar,
+ *pit, outerfont,
+ os, texrow, runparams);
+
// Make sure that \\par is done with the font of the last
// character if this has another size as the default.
// This is necessary because LaTeX (and LyX on the screen)
@@ -358,32 +324,25 @@
// to this font. (Matthias)
//
// Is this really needed ? (Dekel)
- // We do not need to use to change the font for the last paragraph
- // or for a command.
LyXFont const font =
(pit->empty()
? pit->getLayoutFont(bparams, outerfont)
: pit->getFont(bparams, pit->size() - 1, outerfont));
- bool is_command = style->isCommand();
-
+ // We do not need to change the font for the last paragraph
+ // or for a command
if (style->resfont.size() != font.size()
- && boost::next(pit) != paragraphs.end()
- && !is_command) {
- if (!need_par)
- os << '{';
- os << "\\" << from_ascii(font.latexSize()) << " \\par}";
- } else if (need_par) {
- os << "\\par}";
- } else if (is_command)
- os << '}';
-
+ && boost::next(pit) != paragraphs.end()
+ && !style->isCommand()) {
+ os << '{' << "\\" << from_ascii(font.latexSize()) << " \\par}";
+ }
+
bool pending_newline = false;
switch (style->latextype) {
case LATEX_ITEM_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
- if (boost::next(pit) != paragraphs.end()
+ if (!isLastPar
&& (pit->params().depth() < boost::next(pit)->params().depth()))
pending_newline = true;
break;
@@ -397,34 +356,18 @@
|| next->params().depth() != pit->params().depth()))
break;
}
-
- // fall through possible
+ // fall through possible
default:
// we don't need it for the last paragraph!!!
- if (boost::next(pit) != paragraphs.end())
+ if (!isLastPar)
pending_newline = true;
}
- if (!pit->forceDefaultParagraphs()) {
- if (!pit->params().spacing().isDefault()
- && (boost::next(pit) == paragraphs.end()
- || !boost::next(pit)->hasSameLayout(*pit)))
- {
- if (pending_newline) {
- os << '\n';
- texrow.newline();
- }
- os << from_ascii(pit->params().spacing().writeEnvirEnd());
- pending_newline = true;
- }
- }
-
- if (boost::next(pit) == paragraphs.end()
+ // Since \selectlanguage writes the language to the aux file,
+ // we need to reset the language at the end of footnote or
+ // float.
+ if (isLastPar
&& par_language->babel() != doc_language->babel()) {
- // Since \selectlanguage write the language to the aux file,
- // we need to reset the language at the end of footnote or
- // float.
-
if (pending_newline) {
os << '\n';
texrow.newline();
@@ -451,14 +394,12 @@
// we don't need it for the last paragraph!!!
// Note from JMarc: we will re-add a \n explicitely in
// TeXEnvironment, because it is needed in this case
- if (boost::next(pit) != paragraphs.end()) {
- os << '\n';
+ if (!isLastPar) {
+ os << "\n";
texrow.newline();
+ LYXERR(Debug::LATEX) << "TeXOnePar...done " << &*boost::next(pit) << endl;
}
- if (boost::next(pit) != paragraphs.end())
- LYXERR(Debug::LATEX) << "TeXOnePar...done " << &*boost::next(pit) << endl;
-
return ++pit;
}