]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Consistent output of breakable/non-breakable dashes on all TeX engines.
[lyx.git] / src / Paragraph.cpp
index 76202516a88eb424c963907b775ffb47e83792b2..a6c72c310e0b22a07b1251132133a1d02899041a 100644 (file)
@@ -1289,7 +1289,10 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
 
        case 0x2013:
        case 0x2014:
-               if (bparams.use_dash_ligatures && !bparams.useNonTeXFonts) {
+               // XeTeX's dash behaviour is determined via a global setting
+               if (bparams.use_dash_ligatures
+                   && owner_->getFontSettings(bparams, i).fontInfo().family() != TYPEWRITER_FAMILY
+                   && (!bparams.useNonTeXFonts || runparams.flavor != OutputParams::XETEX)) {
                        if (c == 0x2013) {
                                // en-dash
                                os << "--";
@@ -1417,6 +1420,14 @@ bool Paragraph::Private::latexSpecialT3(char_type const c, otexstream & os,
                os << "\\textvertline" << termcmd;
                column += 14;
                return true;
+       case 0x2013:
+               os << "\\textendash" << termcmd;
+               column += 12;
+               return true;
+       case 0x2014:
+               os << "\\textemdash" << termcmd;
+               column += 12;
+               return true;
        default:
                return false;
        }
@@ -1425,11 +1436,11 @@ bool Paragraph::Private::latexSpecialT3(char_type const c, otexstream & os,
 
 void Paragraph::Private::validate(LaTeXFeatures & features) const
 {
+       Buffer const & buf = inset_owner_->buffer();
+       BufferParams const & bp = features.runparams().is_child
+               ? buf.masterParams() : buf.params();
        if (layout_->inpreamble && inset_owner_) {
                bool const is_command = layout_->latextype == LATEX_COMMAND;
-               Buffer const & buf = inset_owner_->buffer();
-               BufferParams const & bp = features.runparams().is_child
-                       ? buf.masterParams() : buf.params();
                Font f;
                // Using a string stream here circumvents the encoding
                // switching machinery of odocstream. Therefore the
@@ -1490,6 +1501,16 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
        for (; icit != iend; ++icit) {
                if (icit->inset) {
                        features.inDeletedInset(owner_->isDeleted(icit->pos));
+                       if (icit->inset->lyxCode() == FOOT_CODE) {
+                               // FIXME: an item inset would make things much easier.
+                               if ((layout_->latextype == LATEX_LIST_ENVIRONMENT
+                                    || (layout_->latextype == LATEX_ITEM_ENVIRONMENT
+                                        && layout_->margintype == MARGIN_FIRST_DYNAMIC))
+                                   && (icit->pos < begin_of_body_
+                                       || (icit->pos == begin_of_body_
+                                           && (icit->pos == 0 || text_[icit->pos - 1] != ' '))))
+                                       features.saveNoteEnv("description");
+                       }
                        icit->inset->validate(features);
                        features.inDeletedInset(false);
                        if (layout_->needprotect &&
@@ -1499,7 +1520,6 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
        }
 
        // then the contents
-       BufferParams const bp = features.buffer().masterParams();
        for (pos_type i = 0; i < int(text_.size()) ; ++i) {
                char_type c = text_[i];
                if (c == 0x0022) {
@@ -1509,6 +1529,12 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
                                 || ((&owner_->getFontSettings(bp, i))->language()->internalFontEncoding()))
                                features.require("textquotedbl");
                }
+               if (!bp.use_dash_ligatures
+                   && (c == 0x2013 || c == 0x2014)
+                   && bp.useNonTeXFonts
+                   && features.runparams().flavor == OutputParams::XETEX)
+                       // XeTeX's dash behaviour is determined via a global setting
+                       features.require("xetexdashbreakstate");
                BufferEncodings::validate(c, features);
        }
 }
@@ -2454,6 +2480,8 @@ void Paragraph::latex(BufferParams const & bparams,
                runparams.wasDisplayMath = runparams.inDisplayMath;
                runparams.inDisplayMath = false;
                bool deleted_display_math = false;
+               Change const & change = runparams.inDeletedInset
+                       ? runparams.changeOfDeletedInset : lookupChange(i);
 
                // Check whether a display math inset follows
                if (d->text_[i] == META_INSET
@@ -2468,11 +2496,28 @@ void Paragraph::latex(BufferParams const & bparams,
                                // cannot set it here because it is a counter.
                                deleted_display_math = isDeleted(i);
                        }
+                       if (bparams.output_changes && deleted_display_math
+                           && runningChange == change
+                           && change.type == Change::DELETED
+                           && !os.afterParbreak()) {
+                               // A display math in the same paragraph follows.
+                               // We have to close and then reopen \lyxdeleted,
+                               // otherwise the math will be shifted up.
+                               OutputParams rp = runparams;
+                               if (open_font) {
+                                       bool needPar = false;
+                                       column += running_font.latexWriteEndChanges(
+                                               os, bparams, rp, basefont,
+                                               basefont, needPar);
+                                       open_font = false;
+                               }
+                               basefont = getLayoutFont(bparams, outerfont);
+                               running_font = basefont;
+                               column += Changes::latexMarkChange(os, bparams,
+                                       Change(Change::INSERTED), change, rp);
+                       }
                }
 
-               Change const & change = runparams.inDeletedInset
-                       ? runparams.changeOfDeletedInset : lookupChange(i);
-
                if (bparams.output_changes && runningChange != change) {
                        if (open_font) {
                                bool needPar = false;
@@ -2523,6 +2568,7 @@ void Paragraph::latex(BufferParams const & bparams,
                bool const using_begin_end = runparams.use_polyglossia ||
                                                !lang_end_command.empty();
                if (!running_lang.empty() &&
+                   (!using_begin_end || running_lang == openLanguageName()) &&
                    current_font.language()->encoding()->package() == Encoding::CJK) {
                                string end_tag = subst(lang_end_command,
                                                        "$$lang",
@@ -2549,7 +2595,7 @@ void Paragraph::latex(BufferParams const & bparams,
                char_type const c = d->text_[i];
 
                // A display math inset inside an ulem command will be output
-               // as a box of width \columnwidth, so we have to either disable
+               // as a box of width \linewidth, so we have to either disable
                // indentation if the inset starts a paragraph, or start a new
                // line to accommodate such box. This has to be done before
                // writing any font changing commands.