mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-01 21:45:23 +00:00
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:
parent
8a47d06b86
commit
0e834b9342
@ -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
|
// assure the used encoding is properly initialized
|
||||||
init();
|
init();
|
||||||
@ -344,6 +344,8 @@ docstring Encoding::latexChar(char_type c) const
|
|||||||
return docstring(1, c);
|
return docstring(1, c);
|
||||||
if (encodable_.find(c) != encodable_.end())
|
if (encodable_.find(c) != encodable_.end())
|
||||||
return docstring(1, c);
|
return docstring(1, c);
|
||||||
|
if (for_mathed)
|
||||||
|
return docstring();
|
||||||
|
|
||||||
// c cannot (or should not) be encoded in this encoding
|
// c cannot (or should not) be encoded in this encoding
|
||||||
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
|
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);
|
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
|
||||||
if (it == unicodesymbols.end())
|
if (it == unicodesymbols.end())
|
||||||
throw EncodingException(c);
|
throw EncodingException(c);
|
||||||
|
@ -71,7 +71,7 @@ public:
|
|||||||
* LaTeX macro is known, a warning is given of lyxerr, and the
|
* LaTeX macro is known, a warning is given of lyxerr, and the
|
||||||
* character is returned.
|
* 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?
|
/// Which LaTeX package handles this encoding?
|
||||||
Package package() const { return package_; }
|
Package package() const { return package_; }
|
||||||
/// A list of all characters usable in this encoding
|
/// A list of all characters usable in this encoding
|
||||||
@ -178,10 +178,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool isForced(char_type c);
|
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
|
* \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
|
* Convert the LaTeX command in \p cmd to the corresponding unicode
|
||||||
|
@ -74,16 +74,17 @@ int InsetFormulaMacro::latex(odocstream & os,
|
|||||||
OutputParams const & runparams) const
|
OutputParams const & runparams) const
|
||||||
{
|
{
|
||||||
//lyxerr << "InsetFormulaMacro::latex" << endl;
|
//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);
|
tmpl()->write(wi);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const &) const
|
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const & runparams) const
|
||||||
{
|
{
|
||||||
odocstringstream oss;
|
odocstringstream oss;
|
||||||
WriteStream wi(oss, false, true, false);
|
WriteStream wi(oss, false, true, false, runparams.encoding);
|
||||||
tmpl()->write(wi);
|
tmpl()->write(wi);
|
||||||
|
|
||||||
docstring const str = oss.str();
|
docstring const str = oss.str();
|
||||||
|
@ -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()) {
|
if (0 && display()) {
|
||||||
Dimension dim;
|
Dimension dim;
|
||||||
@ -1575,7 +1575,7 @@ int InsetMathHull::plaintext(odocstream & os, OutputParams const &) const
|
|||||||
return tpain.textheight();
|
return tpain.textheight();
|
||||||
} else {
|
} else {
|
||||||
odocstringstream oss;
|
odocstringstream oss;
|
||||||
WriteStream wi(oss, false, true, false);
|
WriteStream wi(oss, false, true, false, runparams.encoding);
|
||||||
wi << cell(0);
|
wi << cell(0);
|
||||||
|
|
||||||
docstring const str = oss.str();
|
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
|
// Workaround for db2latex: db2latex always includes equations with
|
||||||
// \ensuremath{} or \begin{display}\end{display}
|
// \ensuremath{} or \begin{display}\end{display}
|
||||||
// so we strip LyX' math environment
|
// so we strip LyX' math environment
|
||||||
WriteStream wi(ls, false, false, false);
|
WriteStream wi(ls, false, false, false, runparams.encoding);
|
||||||
InsetMathGrid::write(wi);
|
InsetMathGrid::write(wi);
|
||||||
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
|
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
|
||||||
ms << ETag("alt");
|
ms << ETag("alt");
|
||||||
|
@ -361,7 +361,8 @@ void InsetMathNest::normalize(NormalStream & os) const
|
|||||||
|
|
||||||
int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) 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);
|
write(wi);
|
||||||
return wi.line();
|
return wi.line();
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ void InsetMathString::write(WriteStream & os) const
|
|||||||
char_type const c = *cit;
|
char_type const c = *cit;
|
||||||
try {
|
try {
|
||||||
docstring command(1, c);
|
docstring command(1, c);
|
||||||
if (c < 0x80 || Encodings::latexMathChar(c, command)) {
|
if (c < 0x80 || Encodings::latexMathChar(c, os.encoding(), command)) {
|
||||||
if (os.textMode()) {
|
if (os.textMode()) {
|
||||||
if (in_forced_mode) {
|
if (in_forced_mode) {
|
||||||
// we were inside \lyxmathsym
|
// we were inside \lyxmathsym
|
||||||
|
@ -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),
|
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
|
||||||
dryrun_(dryrun), pendingspace_(false), pendingbrace_(false),
|
dryrun_(dryrun), pendingspace_(false), pendingbrace_(false),
|
||||||
textmode_(false), line_(0)
|
textmode_(false), line_(0), encoding_(encoding)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
WriteStream::WriteStream(odocstream & os)
|
WriteStream::WriteStream(odocstream & os)
|
||||||
: os_(os), fragile_(false), firstitem_(false), latex_(false),
|
: os_(os), fragile_(false), firstitem_(false), latex_(false),
|
||||||
dryrun_(false), pendingspace_(false), pendingbrace_(false),
|
dryrun_(false), pendingspace_(false), pendingbrace_(false),
|
||||||
textmode_(false), line_(0)
|
textmode_(false), line_(0), encoding_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,9 +21,10 @@
|
|||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
class MathData;
|
class Encoding;
|
||||||
class InsetMath;
|
class InsetMath;
|
||||||
class MathAtom;
|
class MathAtom;
|
||||||
|
class MathData;
|
||||||
|
|
||||||
//
|
//
|
||||||
// LaTeX/LyX
|
// LaTeX/LyX
|
||||||
@ -32,7 +33,8 @@ class MathAtom;
|
|||||||
class WriteStream {
|
class WriteStream {
|
||||||
public:
|
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);
|
explicit WriteStream(odocstream & os);
|
||||||
///
|
///
|
||||||
@ -63,6 +65,8 @@ public:
|
|||||||
void textMode(bool textmode);
|
void textMode(bool textmode);
|
||||||
/// tell whether we are in text mode or not when producing latex code
|
/// tell whether we are in text mode or not when producing latex code
|
||||||
bool textMode() const { return textmode_; }
|
bool textMode() const { return textmode_; }
|
||||||
|
/// LaTeX encoding
|
||||||
|
Encoding const * encoding() const { return encoding_; }
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
odocstream & os_;
|
odocstream & os_;
|
||||||
@ -82,6 +86,8 @@ private:
|
|||||||
bool textmode_;
|
bool textmode_;
|
||||||
///
|
///
|
||||||
int line_;
|
int line_;
|
||||||
|
///
|
||||||
|
Encoding const * encoding_;
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user