From 8684c07664f00b743ea10b7e24fb3cf29641e366 Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Sun, 13 May 2007 15:17:57 +0000 Subject: [PATCH] output changes by means of xcolor and soul - when exporting with pdflatex - when exporting with latex and dvipost is not available rename two colors (strikeout => deletedtext, newtext => addedtext) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18284 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/chkconfig.ltx | 3 +++ src/Buffer.cpp | 42 +++++++++++++++++++++++++++---------- src/BufferView.cpp | 20 +++++++++++------- src/Changes.cpp | 4 ++-- src/Color.cpp | 4 ++-- src/Color.h | 6 +++--- src/LaTeXFeatures.cpp | 32 +++++++++++++++++++--------- src/insets/InsetTabular.cpp | 4 ++-- src/rowpainter.cpp | 10 ++++----- 9 files changed, 82 insertions(+), 43 deletions(-) diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index d33e4737c2..5804ec10c5 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -238,14 +238,17 @@ \TestPackage{longtable} \TestPackage{natbib} \TestPackage{nomencl} +\TestPackage{pdfcolmk} \TestPackage{prettyref} \TestPackage{preview} \TestPackage{rotating} \TestPackage{setspace} +\TestPackage{soul} \TestPackage{subfigure} \TestPackage{textcomp} \TestPackage{varioref} \TestPackage{url} +\TestPackage{xcolor} % The test for the graphics package is slightly more involved... \newcommand\groption{dvips} diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 1a2766eb21..4db5afad6b 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -506,18 +506,22 @@ bool Buffer::readDocument(Lexer & lex) } if (params().outputChanges) { - if (!LaTeXFeatures::isAvailable("dvipost")) { + bool dvipost = LaTeXFeatures::isAvailable("dvipost"); + bool xcolorsoul = LaTeXFeatures::isAvailable("soul") && + LaTeXFeatures::isAvailable("xcolor"); + + if (!dvipost && !xcolorsoul) { Alert::warning(_("Changes not shown in LaTeX output"), _("Changes will not be highlighted in LaTeX output, " - "because dvipost is not installed.\n" - "If you are familiar with TeX, consider redefining " - "\\lyxinserted and \\lyxdeleted in the LaTeX preamble.")); - } else { + "because neither dvipost nor xcolor/soul are installed.\n" + "Please install these packages or redefine " + "\\lyxadded and \\lyxdeleted in the LaTeX preamble.")); + } else if (!xcolorsoul) { Alert::warning(_("Changes not shown in LaTeX output"), _("Changes will not be highlighted in LaTeX output " - "when using pdflatex.\n" - "If you are familiar with TeX, consider redefining " - "\\lyxinserted and \\lyxdeleted in the LaTeX preamble.")); + "when using pdflatex, because xcolor and soul are not installed.\n" + "Please install both packages or redefine " + "\\lyxadded and \\lyxdeleted in the LaTeX preamble.")); } } @@ -1215,14 +1219,30 @@ void Buffer::validate(LaTeXFeatures & features) const TextClass const & tclass = params().getTextClass(); if (params().outputChanges) { + bool dvipost = LaTeXFeatures::isAvailable("dvipost"); + bool xcolorsoul = LaTeXFeatures::isAvailable("soul") && + LaTeXFeatures::isAvailable("xcolor"); + if (features.runparams().flavor == OutputParams::LATEX) { - if (LaTeXFeatures::isAvailable("dvipost")) { + if (dvipost) { + features.require("ct-dvipost"); features.require("dvipost"); - } else { + } else if (xcolorsoul) { + features.require("ct-xcolor-soul"); + features.require("soul"); + features.require("xcolor"); + } else { features.require("ct-none"); } } else if (features.runparams().flavor == OutputParams::PDFLATEX ) { - features.require("ct-none"); + if (xcolorsoul) { + features.require("ct-xcolor-soul"); + features.require("soul"); + features.require("xcolor"); + features.require("pdfcolmk"); // improves color handling in PDF output + } else { + features.require("ct-none"); + } } } diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 3ab5444555..03efbffd2b 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -891,18 +891,22 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) case LFUN_CHANGES_OUTPUT: buffer_->params().outputChanges = !buffer_->params().outputChanges; if (buffer_->params().outputChanges) { - if (!LaTeXFeatures::isAvailable("dvipost")) { + bool dvipost = LaTeXFeatures::isAvailable("dvipost"); + bool xcolorsoul = LaTeXFeatures::isAvailable("soul") && + LaTeXFeatures::isAvailable("xcolor"); + + if (!dvipost && !xcolorsoul) { Alert::warning(_("Changes not shown in LaTeX output"), _("Changes will not be highlighted in LaTeX output, " - "because dvipost is not installed.\n" - "If you are familiar with TeX, consider redefining " - "\\lyxinserted and \\lyxdeleted in the LaTeX preamble.")); - } else { + "because neither dvipost nor xcolor/soul are installed.\n" + "Please install these packages or redefine " + "\\lyxadded and \\lyxdeleted in the LaTeX preamble.")); + } else if (!xcolorsoul) { Alert::warning(_("Changes not shown in LaTeX output"), _("Changes will not be highlighted in LaTeX output " - "when using pdflatex.\n" - "If you are familiar with TeX, consider redefining " - "\\lyxinserted and \\lyxdeleted in the LaTeX preamble.")); + "when using pdflatex, because xcolor and soul are not installed.\n" + "Please install both packages or redefine " + "\\lyxadded and \\lyxdeleted in the LaTeX preamble.")); } } break; diff --git a/src/Changes.cpp b/src/Changes.cpp index fec558e56e..6b5979b0bb 100644 --- a/src/Changes.cpp +++ b/src/Changes.cpp @@ -303,7 +303,7 @@ int Changes::latexMarkChange(odocstream & os, BufferParams const & bparams, int column = 0; if (oldChange.type != Change::UNCHANGED) { - os << '}'; // close \lyxinserted or \lyxdeleted + os << '}'; // close \lyxadded or \lyxdeleted column++; } @@ -318,7 +318,7 @@ int Changes::latexMarkChange(odocstream & os, BufferParams const & bparams, os << str; column += str.size(); } else if (change.type == Change::INSERTED) { - docstring str = "\\lyxinserted{" + + docstring str = "\\lyxadded{" + bparams.authors().get(change.author).name() + "}{" + chgTime + "}{"; os << str; diff --git a/src/Color.cpp b/src/Color.cpp index 9080907550..c96033fcc8 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -309,8 +309,8 @@ Color::Color() { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" }, { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" }, { changebar, N_("change bar"), "changebar", "Blue", "changebar" }, - { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" }, - { newtext, N_("Added text"), "newtext", "Blue", "newtext" }, + { deletedtext, N_("Deleted text"), "deletedtext", "Red", "deletedtext" }, + { addedtext, N_("Added text"), "addedtext", "Blue", "addedtext" }, { added_space, N_("added space markers"), "added_space", "Brown", "added_space" }, { topline, N_("top/bottom line"), "topline", "Brown", "topline" }, { tabularline, N_("table line"), "tabularline", "black", diff --git a/src/Color.h b/src/Color.h index 372c1a5025..8a394ac497 100644 --- a/src/Color.h +++ b/src/Color.h @@ -153,10 +153,10 @@ public: appendix, /// changebar color changebar, - /// strike-out color - strikeout, + /// deleted text color + deletedtext, /// added text color - newtext, + addedtext, /// Top and bottom line color topline, /// Table line color diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index c5f73a9cdf..f8cd82f252 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -178,18 +178,13 @@ static string const changetracking_dvipost_def = "\\dvipost{osend color pop}\n" "\\dvipost{cbstart color push Blue}\n" "\\dvipost{cbend color pop}\n" - "\\newcommand{\\lyxinserted}[3]{\\changestart#3\\changeend}\n" + "\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n" "\\newcommand{\\lyxdeleted}[3]{%\n" "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n"; -// TODO -//static string const changetracking_soul_def = -// "\\newcommand{\\lyxinserted}[3]{\\uwave{\\textcolor{blue}{#3}}}\n" -// "\\newcommand{\\lyxdeleted}[3]{\\sout{\\textcolor{red}{#3}}}"; - static string const changetracking_none_def = - "\\newcommand{\\lyxinserted}[3]{#3}\n" - "\\newcommand{\\lyxdeleted}[3]{}"; + "\\newcommand{\\lyxadded}[3]{#3}\n" + "\\newcommand{\\lyxdeleted}[3]{}\n"; ///////////////////////////////////////////////////////////////////// @@ -411,7 +406,10 @@ char const * simplefeatures[] = { "nicefrac", "tipa", "framed", + "pdfcolmk", + "soul", "textcomp", + "xcolor", }; int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); @@ -643,10 +641,24 @@ string const LaTeXFeatures::getMacros() const getFloatDefinitions(macros); // change tracking - if (mustProvide("dvipost")) + if (mustProvide("ct-dvipost")) { macros << changetracking_dvipost_def; - if (mustProvide("ct-none")) + } + if (mustProvide("ct-xcolor-soul")) { + RGBColor cadd = RGBColor(lcolor.getX11Name(Color::addedtext)); + macros << "\\providecolor{lyxadded}{rgb}{" + << cadd.r/255 << ',' << cadd.g/255 << ',' << cadd.b/255 << "}\n"; + + RGBColor cdel = RGBColor(lcolor.getX11Name(Color::deletedtext)); + macros << "\\providecolor{lyxdeleted}{rgb}{" + << cdel.r/255 << ',' << cdel.g/255 << ',' << cdel.b/255 << "}\n"; + + macros << "\\newcommand{\\lyxadded}[3]{\\textcolor{lyxadded}{#3}}\n" + << "\\newcommand{\\lyxdeleted}[3]{\\textcolor{lyxdeleted}{\\st{#3}}}\n"; + } + if (mustProvide("ct-none")) { macros << changetracking_none_def; + } return macros.str(); } diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index fe48b69843..f9c8d3fe52 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3105,8 +3105,8 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y, Color::color onoffcol = Color::tabularonoffline; if (erased) { - col = Color::strikeout; - onoffcol = Color::strikeout; + col = Color::deletedtext; + onoffcol = Color::deletedtext; } if (!tabular.topAlreadyDrawn(cell)) { diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index afb99897ef..a8a49d0666 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -368,9 +368,9 @@ void RowPainter::paintChars(pos_type & vpos, Font const & font, if (prev_change != Change::UNCHANGED) { Font copy(font); if (prev_change == Change::DELETED) { - copy.setColor(Color::strikeout); + copy.setColor(Color::deletedtext); } else if (prev_change == Change::INSERTED) { - copy.setColor(Color::newtext); + copy.setColor(Color::addedtext); } x_ += pain_.text(int(x_), yo_, s, copy); } else { @@ -669,7 +669,7 @@ void RowPainter::paintLast() if (par_.isInserted(par_.size()) || par_.isDeleted(par_.size())) { FontMetrics const & fm = theFontMetrics(bv_.buffer()->params().getFont()); int const length = fm.maxAscent() / 2; - Color::color col = par_.isInserted(par_.size()) ? Color::newtext : Color::strikeout; + Color::color col = par_.isInserted(par_.size()) ? Color::addedtext : Color::deletedtext; pain_.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col, Painter::line_solid, Painter::line_thick); @@ -779,7 +779,7 @@ void RowPainter::paintText() = theFontMetrics(bv_.buffer()->params().getFont()); int const middle = yo_ - fm.maxAscent() / 3; pain_.line(last_strikeout_x, middle, int(x_), middle, - Color::strikeout, Painter::line_solid, Painter::line_thin); + Color::deletedtext, Painter::line_solid, Painter::line_thin); running_strikeout = false; } @@ -834,7 +834,7 @@ void RowPainter::paintText() = theFontMetrics(bv_.buffer()->params().getFont()); int const middle = yo_ - fm.maxAscent() / 3; pain_.line(last_strikeout_x, middle, int(x_), middle, - Color::strikeout, Painter::line_solid, Painter::line_thin); + Color::deletedtext, Painter::line_solid, Painter::line_thin); running_strikeout = false; } }