From 160b1471867798e74b3bdf21ef5f1da506e40855 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Thu, 17 Oct 2002 15:56:42 +0000 Subject: [PATCH] Nicer previews. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5434 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/graphics/PreviewLoader.C | 4 +--- src/mathed/ChangeLog | 5 +++++ src/mathed/formula.C | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index d26d1f90cc..97e59adce2 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -479,9 +479,7 @@ void PreviewLoader::Impl::startLoading() string const command = "sh " + LibScriptSearch(cs.str().c_str()); // Initiate the conversion from LaTeX to bitmap images files. - Forkedcall::SignalTypePtr convert_ptr; - convert_ptr.reset(new Forkedcall::SignalType); - + Forkedcall::SignalTypePtr convert_ptr(new Forkedcall::SignalType); convert_ptr->connect( boost::bind(&Impl::finishedGenerating, this, _1, _2, _3)); diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 78e9b93bb1..69c509ee22 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ +2002-10-17 Angus Leeming + + * formula.C (latexString): change "\[ ... \]" to "$ \displaystyle ... $" + for nicer previews. + 2002-10-17 Dekel Tsur * math_kerninset.C (metrics): Use LyXLength::inPixels. diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 4b8a9eaa76..d8924ddf89 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -330,5 +330,20 @@ string const InsetFormula::PreviewImpl::latexString() const ostringstream ls; WriteStream wi(ls, false, false); parent().par_->write(wi); - return ls.str().c_str(); + string str = ls.str().c_str(); + + // If we are in displaymode, the preview will include the margins + // on either side of the previewed equation. + // We can create an image with a tight bounding box by replacing the + // "\[ ... \]" delimiters with "$ \displaystyle ... $". + // Note that we have to get rid of any trailing '\n's for the fix + // to work. + if (prefixIs(str, "\\[")) { + std::cerr << "before\n" << str << std::endl; + str = rtrim(rtrim(ltrim(str, "\\["), "\n"), "\\]"); + str = "$ \\displaystyle " + str + " $"; + std::cerr << "after\n" << str << std::endl; + } + + return str; }