When producing latex output, check whether a character entered in mathed

can be encoded in the current latex encoding before resorting to the
unicodesymbols file.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25725 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2008-07-20 01:50:54 +00:00
parent 8a47d06b86
commit 0e834b9342
8 changed files with 36 additions and 18 deletions

View File

@ -333,7 +333,7 @@ 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();
@ -344,6 +344,8 @@ docstring Encoding::latexChar(char_type c) const
return docstring(1, c);
if (encodable_.find(c) != encodable_.end())
return docstring(1, c);
if (for_mathed)
return docstring();
// c cannot (or should not) be encoded in this encoding
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
@ -375,8 +377,14 @@ vector<char_type> Encoding::symbolsList() const
}
bool Encodings::latexMathChar(char_type c, docstring & command)
bool Encodings::latexMathChar(char_type c, Encoding const * encoding,
docstring & command)
{
if (encoding) {
command = encoding->latexChar(c, true);
if (!command.empty())
return false;
}
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
if (it == unicodesymbols.end())
throw EncodingException(c);

View File

@ -71,7 +71,7 @@ public:
* 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
@ -178,10 +178,11 @@ public:
*/
static bool isForced(char_type c);
/**
* Convert \p c to something that LaTeX can understand in math mode.
* If \p c cannot be encoded in the given \p encoding, convert
* it to something that LaTeX can understand in math mode.
* \return whether \p command is a math mode command
*/
static bool latexMathChar(char_type c, docstring & command);
static bool latexMathChar(char_type c, Encoding const * encoding, docstring & command);
/**
* Convert the LaTeX command in \p cmd to the corresponding unicode

View File

@ -74,16 +74,17 @@ int InsetFormulaMacro::latex(odocstream & os,
OutputParams const & runparams) const
{
//lyxerr << "InsetFormulaMacro::latex" << endl;
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun);
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun,
runparams.encoding);
tmpl()->write(wi);
return 2;
}
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const &) const
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const & runparams) const
{
odocstringstream oss;
WriteStream wi(oss, false, true, false);
WriteStream wi(oss, false, true, false, runparams.encoding);
tmpl()->write(wi);
docstring const str = oss.str();

View File

@ -1561,7 +1561,7 @@ void InsetMathHull::read(Lexer & lex)
}
int InsetMathHull::plaintext(odocstream & os, OutputParams const &) const
int InsetMathHull::plaintext(odocstream & os, OutputParams const & runparams) const
{
if (0 && display()) {
Dimension dim;
@ -1575,7 +1575,7 @@ int InsetMathHull::plaintext(odocstream & os, OutputParams const &) const
return tpain.textheight();
} else {
odocstringstream oss;
WriteStream wi(oss, false, true, false);
WriteStream wi(oss, false, true, false, runparams.encoding);
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, false);
WriteStream wi(ls, false, false, false, runparams.encoding);
InsetMathGrid::write(wi);
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&amp;"), "<", "&lt;"));
ms << ETag("alt");

View File

@ -361,7 +361,8 @@ void InsetMathNest::normalize(NormalStream & os) const
int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) const
{
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun);
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun,
runparams.encoding);
write(wi);
return wi.line();
}

View File

@ -121,7 +121,7 @@ void InsetMathString::write(WriteStream & os) const
char_type const c = *cit;
try {
docstring command(1, c);
if (c < 0x80 || Encodings::latexMathChar(c, command)) {
if (c < 0x80 || Encodings::latexMathChar(c, os.encoding(), command)) {
if (os.textMode()) {
if (in_forced_mode) {
// we were inside \lyxmathsym

View File

@ -107,17 +107,18 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
}
WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun)
WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun,
Encoding const * encoding)
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
dryrun_(dryrun), pendingspace_(false), pendingbrace_(false),
textmode_(false), line_(0)
textmode_(false), line_(0), encoding_(encoding)
{}
WriteStream::WriteStream(odocstream & os)
: os_(os), fragile_(false), firstitem_(false), latex_(false),
dryrun_(false), pendingspace_(false), pendingbrace_(false),
textmode_(false), line_(0)
textmode_(false), line_(0), encoding_(0)
{}

View File

@ -21,9 +21,10 @@
namespace lyx {
class MathData;
class Encoding;
class InsetMath;
class MathAtom;
class MathData;
//
// LaTeX/LyX
@ -32,7 +33,8 @@ class MathAtom;
class WriteStream {
public:
///
WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun);
WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun,
Encoding const * encoding = 0);
///
explicit WriteStream(odocstream & os);
///
@ -63,6 +65,8 @@ public:
void textMode(bool textmode);
/// tell whether we are in text mode or not when producing latex code
bool textMode() const { return textmode_; }
/// LaTeX encoding
Encoding const * encoding() const { return encoding_; }
private:
///
odocstream & os_;
@ -82,6 +86,8 @@ private:
bool textmode_;
///
int line_;
///
Encoding const * encoding_;
};
///