mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
Really fix bug #9354
This commit is contained in:
parent
1d28d90801
commit
ad0d0f6d69
@ -24,12 +24,18 @@
|
|||||||
|
|
||||||
#include "graphics/PreviewImage.h"
|
#include "graphics/PreviewImage.h"
|
||||||
|
|
||||||
|
#include "mathed/MacroTable.h"
|
||||||
|
|
||||||
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
|
using support::prefixIs;
|
||||||
|
|
||||||
|
|
||||||
InsetPreview::InsetPreview(Buffer * buf)
|
InsetPreview::InsetPreview(Buffer * buf)
|
||||||
: InsetText(buf),
|
: InsetText(buf),
|
||||||
@ -70,10 +76,33 @@ void InsetPreview::preparePreview(DocIterator const & pos) const
|
|||||||
TexRow texrow;
|
TexRow texrow;
|
||||||
odocstringstream str;
|
odocstringstream str;
|
||||||
otexstream os(str, texrow);
|
otexstream os(str, texrow);
|
||||||
OutputParams runparams(&pos.buffer()->params().encoding());
|
Buffer const * buffer = pos.buffer();
|
||||||
|
OutputParams runparams(&buffer->params().encoding());
|
||||||
latex(os, runparams);
|
latex(os, runparams);
|
||||||
docstring const snippet = str.str();
|
// collect macros at this position in case they are used in a math inset
|
||||||
preview_->addPreview(snippet, *pos.buffer());
|
MacroNameSet macros;
|
||||||
|
buffer->listMacroNames(macros);
|
||||||
|
MacroNameSet::iterator it = macros.begin();
|
||||||
|
MacroNameSet::iterator end = macros.end();
|
||||||
|
docstring macro_preamble;
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
MacroData const * data = buffer->getMacro(*it, pos, true);
|
||||||
|
if (data) {
|
||||||
|
odocstringstream macro_def;
|
||||||
|
data->write(macro_def, false);
|
||||||
|
docstring const md = macro_def.str();
|
||||||
|
macro_def << endl;
|
||||||
|
bool is_newcomm = prefixIs(md, from_ascii("\\newcomm"));
|
||||||
|
// assure that \newcommand defs are only added once
|
||||||
|
if (!is_newcomm || !preview_->hasMacroDef(md, *buffer)) {
|
||||||
|
if (is_newcomm)
|
||||||
|
preview_->addMacroDef(md, *buffer);
|
||||||
|
macro_preamble.append(macro_def.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
docstring const snippet = macro_preamble + str.str();
|
||||||
|
preview_->addPreview(snippet, *buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user