mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix bug 3938
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25028 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5b72bafdc8
commit
a694de895e
@ -1559,7 +1559,7 @@ void Cursor::normalize()
|
||||
<< pos() << ' ' << lastpos() << " in idx: " << idx()
|
||||
<< " in atom: '";
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true);
|
||||
WriteStream wi(os, false, true, false);
|
||||
inset().asInsetMath()->write(wi);
|
||||
lyxerr << to_utf8(os.str()) << endl;
|
||||
pos() = lastpos();
|
||||
|
@ -323,17 +323,19 @@ void Encoding::init() const
|
||||
}
|
||||
|
||||
|
||||
docstring Encoding::latexChar(char_type c) const
|
||||
docstring Encoding::latexChar(char_type c, bool for_mathed) const
|
||||
{
|
||||
// assure the used encoding is properly initialized
|
||||
init();
|
||||
|
||||
if (c < start_encodable_)
|
||||
return docstring(1, c);
|
||||
if (encodable_.find(c) != encodable_.end())
|
||||
return docstring(1, c);
|
||||
if (!for_mathed) {
|
||||
if (c < start_encodable_)
|
||||
return docstring(1, c);
|
||||
if (encodable_.find(c) != encodable_.end())
|
||||
return docstring(1, c);
|
||||
}
|
||||
|
||||
// c cannot be encoded in this encoding
|
||||
// c cannot (or should not) be encoded in this encoding
|
||||
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
|
||||
if (it == unicodesymbols.end())
|
||||
throw EncodingException(c);
|
||||
|
@ -63,12 +63,12 @@ public:
|
||||
/**
|
||||
* Convert \p c to something that LaTeX can understand.
|
||||
* This is either the character itself (if it is representable
|
||||
* in this encoding), or a LaTeX macro.
|
||||
* in this encoding and \p for_mathed is false), or a LaTeX macro.
|
||||
* If the character is not representable in this encoding, but no
|
||||
* LaTeX macro is known, a warning is given of lyxerr, and the
|
||||
* character is returned.
|
||||
*/
|
||||
docstring latexChar(char_type c) const;
|
||||
docstring latexChar(char_type c, bool for_mathed = false) const;
|
||||
/// Which LaTeX package handles this encoding?
|
||||
Package package() const { return package_; }
|
||||
/// A list of all characters usable in this encoding
|
||||
|
@ -198,7 +198,14 @@ static string const textcyr_def =
|
||||
" \\def\\encodingdefault{T2A}}\n"
|
||||
"\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
|
||||
"\\DeclareFontEncoding{T2A}{}{}\n";
|
||||
|
||||
|
||||
static string const mathsym_def =
|
||||
"\\DeclareRobustCommand{\\mathsym}[1]{%\n"
|
||||
" \\mathchoice{\\hbox{\\normalsize\\textrm{#1}}}%\n"
|
||||
" {\\hbox{\\normalsize\\textrm{#1}}}%\n"
|
||||
" {\\hbox{\\scriptsize\\textrm{#1}}}%\n"
|
||||
" {\\hbox{\\tiny\\textrm{#1}}}}\n";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// LaTeXFeatures
|
||||
@ -644,6 +651,9 @@ string const LaTeXFeatures::getMacros() const
|
||||
if (mustProvide("textcyr"))
|
||||
macros << textcyr_def << '\n';
|
||||
|
||||
if (mustProvide("mathsym"))
|
||||
macros << mathsym_def << '\n';
|
||||
|
||||
// quotes.
|
||||
if (mustProvide("quotesinglbase"))
|
||||
macros << quotesinglbase_def << '\n';
|
||||
|
@ -744,7 +744,16 @@ void Paragraph::Private::latexInset(
|
||||
}
|
||||
}
|
||||
|
||||
int tmp = inset->latex(os, runparams);
|
||||
int tmp;
|
||||
|
||||
try {
|
||||
tmp = inset->latex(os, runparams);
|
||||
} catch (EncodingException & e) {
|
||||
// add location information and throw again.
|
||||
e.par_id = id_;
|
||||
e.pos = i;
|
||||
throw(e);
|
||||
}
|
||||
|
||||
if (close) {
|
||||
if (running_font.language()->lang() == "farsi")
|
||||
|
@ -65,7 +65,7 @@ Inset * InsetFormulaMacro::clone() const
|
||||
void InsetFormulaMacro::write(ostream & os) const
|
||||
{
|
||||
os << "FormulaMacro\n";
|
||||
WriteStream wi(os, false, false);
|
||||
WriteStream wi(os, false, false, false);
|
||||
tmpl()->write(wi);
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ int InsetFormulaMacro::latex(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
//lyxerr << "InsetFormulaMacro::latex" << endl;
|
||||
WriteStream wi(os, runparams.moving_arg, true);
|
||||
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun);
|
||||
tmpl()->write(wi);
|
||||
return 2;
|
||||
}
|
||||
@ -83,7 +83,7 @@ int InsetFormulaMacro::latex(odocstream & os,
|
||||
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const &) const
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, true);
|
||||
WriteStream wi(oss, false, true, false);
|
||||
tmpl()->write(wi);
|
||||
|
||||
docstring const str = oss.str();
|
||||
|
@ -47,7 +47,7 @@ void InsetMath::dump() const
|
||||
{
|
||||
lyxerr << "---------------------------------------------" << endl;
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true);
|
||||
WriteStream wi(os, false, true, false);
|
||||
write(wi);
|
||||
lyxerr << to_utf8(os.str());
|
||||
lyxerr << "\n---------------------------------------------" << endl;
|
||||
@ -135,7 +135,7 @@ HullType InsetMath::getType() const
|
||||
ostream & operator<<(ostream & os, MathAtom const & at)
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, false);
|
||||
WriteStream wi(oss, false, false, false);
|
||||
at->write(wi);
|
||||
return os << to_utf8(oss.str());
|
||||
}
|
||||
@ -143,7 +143,7 @@ ostream & operator<<(ostream & os, MathAtom const & at)
|
||||
|
||||
odocstream & operator<<(odocstream & os, MathAtom const & at)
|
||||
{
|
||||
WriteStream wi(os, false, false);
|
||||
WriteStream wi(os, false, false, false);
|
||||
at->write(wi);
|
||||
return os;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "MetricsInfo.h"
|
||||
|
||||
#include "Dimension.h"
|
||||
#include "Encoding.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "TextPainter.h"
|
||||
|
||||
#include "frontends/FontMetrics.h"
|
||||
@ -135,6 +137,15 @@ void InsetMathChar::write(WriteStream & os) const
|
||||
}
|
||||
|
||||
|
||||
void InsetMathChar::validate(LaTeXFeatures & features) const
|
||||
{
|
||||
if (char_ >= 0x80) {
|
||||
encodings.validate(char_, features);
|
||||
features.require("mathsym");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetMathChar::normalize(NormalStream & os) const
|
||||
{
|
||||
os << "[char ";
|
||||
|
@ -37,6 +37,8 @@ public:
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
void validate(LaTeXFeatures & features) const;
|
||||
///
|
||||
void normalize(NormalStream & ns) const;
|
||||
///
|
||||
void octave(OctaveStream & os) const;
|
||||
|
@ -420,7 +420,7 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
||||
InsetMathGrid::metricsT(mi, dim);
|
||||
} else {
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true);
|
||||
WriteStream wi(os, false, true, false);
|
||||
write(wi);
|
||||
dim.wid = os.str().size();
|
||||
dim.asc = 1;
|
||||
@ -435,7 +435,7 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
|
||||
InsetMathGrid::drawT(pain, x, y);
|
||||
} else {
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true);
|
||||
WriteStream wi(os, false, true, false);
|
||||
write(wi);
|
||||
pain.draw(x, y, os.str().c_str());
|
||||
}
|
||||
@ -445,7 +445,7 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
|
||||
static docstring latexString(InsetMathHull const & inset)
|
||||
{
|
||||
odocstringstream ls;
|
||||
WriteStream wi(ls, false, false);
|
||||
WriteStream wi(ls, false, false, false);
|
||||
inset.write(wi);
|
||||
return ls.str();
|
||||
}
|
||||
@ -1546,7 +1546,7 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
|
||||
void InsetMathHull::write(ostream & os) const
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, false);
|
||||
WriteStream wi(oss, false, false, false);
|
||||
oss << "Formula ";
|
||||
write(wi);
|
||||
os << to_utf8(oss.str());
|
||||
@ -1575,7 +1575,7 @@ int InsetMathHull::plaintext(odocstream & os, OutputParams const &) const
|
||||
return tpain.textheight();
|
||||
} else {
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, true);
|
||||
WriteStream wi(oss, false, true, false);
|
||||
wi << cell(0);
|
||||
|
||||
docstring const str = oss.str();
|
||||
@ -1607,7 +1607,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
|
||||
// Workaround for db2latex: db2latex always includes equations with
|
||||
// \ensuremath{} or \begin{display}\end{display}
|
||||
// so we strip LyX' math environment
|
||||
WriteStream wi(ls, false, false);
|
||||
WriteStream wi(ls, false, false, false);
|
||||
InsetMathGrid::write(wi);
|
||||
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
|
||||
ms << ETag("alt");
|
||||
|
@ -359,7 +359,7 @@ void InsetMathNest::normalize(NormalStream & os) const
|
||||
|
||||
int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) const
|
||||
{
|
||||
WriteStream wi(os, runparams.moving_arg, true);
|
||||
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun);
|
||||
write(wi);
|
||||
return wi.line();
|
||||
}
|
||||
|
@ -12,9 +12,12 @@
|
||||
|
||||
#include "InsetMathString.h"
|
||||
#include "MathStream.h"
|
||||
#include "MathStream.h"
|
||||
#include "MathSupport.h"
|
||||
|
||||
#include "Encoding.h"
|
||||
|
||||
#include "support/gettext.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -98,7 +101,56 @@ void InsetMathString::mathmlize(MathStream & os) const
|
||||
|
||||
void InsetMathString::write(WriteStream & os) const
|
||||
{
|
||||
os << str_;
|
||||
if (!os.latex()) {
|
||||
os << str_;
|
||||
return;
|
||||
}
|
||||
|
||||
// We need the latex macros defined in the unicodesymbols file.
|
||||
// As they do not depend on the encoding, simply use the first
|
||||
// available encoding.
|
||||
Encodings::const_iterator encit = encodings.begin();
|
||||
bool can_encode = encit != encodings.end();
|
||||
|
||||
docstring::const_iterator cit = str_.begin();
|
||||
docstring::const_iterator end = str_.end();
|
||||
|
||||
bool in_mathsym = false;
|
||||
while (cit != end) {
|
||||
char_type const c = *cit;
|
||||
try {
|
||||
if (c < 0x80) {
|
||||
if (in_mathsym) {
|
||||
os << '}';
|
||||
in_mathsym = false;
|
||||
}
|
||||
os << docstring(1, c);
|
||||
} else if (can_encode) {
|
||||
if (!in_mathsym) {
|
||||
os << "\\mathsym{";
|
||||
in_mathsym = true;
|
||||
}
|
||||
os << encit->latexChar(c, true);
|
||||
} else {
|
||||
throw EncodingException(c);
|
||||
}
|
||||
} catch (EncodingException & e) {
|
||||
if (os.dryrun()) {
|
||||
// FIXME: this is OK for View->Source
|
||||
// but math preview will likely fail.
|
||||
os << "<" << _("LyX Warning: ")
|
||||
<< _("uncodable character") << " '";
|
||||
os << docstring(1, e.failed_char);
|
||||
os << "'>";
|
||||
} else {
|
||||
// throw again
|
||||
throw(e);
|
||||
}
|
||||
}
|
||||
++cit;
|
||||
}
|
||||
if (in_mathsym)
|
||||
os << '}';
|
||||
}
|
||||
|
||||
|
||||
|
@ -162,9 +162,9 @@ void MacroData::write(odocstream & os, bool overwriteRedefinition) const
|
||||
}
|
||||
|
||||
// output template
|
||||
MathMacroTemplate const & tmpl
|
||||
= static_cast<MathMacroTemplate const &>(*inset);
|
||||
WriteStream wi(os, false, true);
|
||||
MathMacroTemplate const & tmpl =
|
||||
static_cast<MathMacroTemplate const &>(*inset);
|
||||
WriteStream wi(os, false, true, false);
|
||||
tmpl.write(wi, overwriteRedefinition);
|
||||
}
|
||||
|
||||
|
@ -1117,7 +1117,7 @@ void MathMacroTemplate::read(Lexer & lex)
|
||||
void MathMacroTemplate::write(ostream & os) const
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, false);
|
||||
WriteStream wi(oss, false, false, false);
|
||||
oss << "FormulaMacro\n";
|
||||
write(wi);
|
||||
os << to_utf8(oss.str());
|
||||
|
@ -103,15 +103,15 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
|
||||
}
|
||||
|
||||
|
||||
WriteStream::WriteStream(odocstream & os, bool fragile, bool latex)
|
||||
WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun)
|
||||
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
|
||||
pendingspace_(false), line_(0)
|
||||
dryrun_(dryrun), pendingspace_(false), line_(0)
|
||||
{}
|
||||
|
||||
|
||||
WriteStream::WriteStream(odocstream & os)
|
||||
: os_(os), fragile_(false), firstitem_(false), latex_(false),
|
||||
pendingspace_(false), line_(0)
|
||||
dryrun_(false), pendingspace_(false), line_(0)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ class MathAtom;
|
||||
class WriteStream {
|
||||
public:
|
||||
///
|
||||
WriteStream(odocstream & os, bool fragile, bool latex);
|
||||
WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun);
|
||||
///
|
||||
explicit WriteStream(odocstream & os);
|
||||
///
|
||||
@ -43,6 +43,8 @@ public:
|
||||
///
|
||||
bool latex() const { return latex_; }
|
||||
///
|
||||
bool dryrun() const { return dryrun_; }
|
||||
///
|
||||
odocstream & os() { return os_; }
|
||||
///
|
||||
bool & firstitem() { return firstitem_; }
|
||||
@ -61,6 +63,8 @@ private:
|
||||
bool firstitem_;
|
||||
/// are we writing to .tex?
|
||||
int latex_;
|
||||
/// is it for preview?
|
||||
bool dryrun_;
|
||||
/// do we have a space pending?
|
||||
bool pendingspace_;
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user