mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-14 06:57:01 +00:00
Fix encoding issues in bibitems (bug #6534)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33452 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a56b03e4fd
commit
ce349ad806
@ -482,6 +482,16 @@ docstring const BiblioInfo::getInfo(docstring const & key) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool const BiblioInfo::isBibtex(docstring const & key) const
|
||||||
|
{
|
||||||
|
BiblioInfo::const_iterator it = find(key);
|
||||||
|
if (it == end())
|
||||||
|
return false;
|
||||||
|
return it->second.isBibTeX();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vector<docstring> const BiblioInfo::getCiteStrings(
|
vector<docstring> const BiblioInfo::getCiteStrings(
|
||||||
docstring const & key, Buffer const & buf) const
|
docstring const & key, Buffer const & buf) const
|
||||||
{
|
{
|
||||||
|
@ -156,6 +156,9 @@ public:
|
|||||||
/// Empty if no info exists.
|
/// Empty if no info exists.
|
||||||
/// Note that this will retrieve data from the crossref as needed.
|
/// Note that this will retrieve data from the crossref as needed.
|
||||||
docstring const getInfo(docstring const & key) const;
|
docstring const getInfo(docstring const & key) const;
|
||||||
|
/// Is this a reference from a bibtex database
|
||||||
|
/// or from a bibliography environment?
|
||||||
|
bool const isBibtex(docstring const & key) const;
|
||||||
/**
|
/**
|
||||||
* "Translates" the available Citation Styles into strings for a given key,
|
* "Translates" the available Citation Styles into strings for a given key,
|
||||||
* either numerical or author-year depending upon the active engine. (See
|
* either numerical or author-year depending upon the active engine. (See
|
||||||
|
@ -20,12 +20,14 @@
|
|||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "Counters.h"
|
#include "Counters.h"
|
||||||
#include "DispatchResult.h"
|
#include "DispatchResult.h"
|
||||||
|
#include "Encoding.h"
|
||||||
#include "FuncRequest.h"
|
#include "FuncRequest.h"
|
||||||
#include "InsetIterator.h"
|
#include "InsetIterator.h"
|
||||||
#include "InsetList.h"
|
#include "InsetList.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
#include "Lexer.h"
|
#include "Lexer.h"
|
||||||
#include "output_xhtml.h"
|
#include "output_xhtml.h"
|
||||||
|
#include "OutputParams.h"
|
||||||
#include "Paragraph.h"
|
#include "Paragraph.h"
|
||||||
#include "ParagraphList.h"
|
#include "ParagraphList.h"
|
||||||
#include "ParIterator.h"
|
#include "ParIterator.h"
|
||||||
@ -34,6 +36,7 @@
|
|||||||
#include "frontends/alert.h"
|
#include "frontends/alert.h"
|
||||||
|
|
||||||
#include "support/convert.h"
|
#include "support/convert.h"
|
||||||
|
#include "support/debug.h"
|
||||||
#include "support/docstream.h"
|
#include "support/docstream.h"
|
||||||
#include "support/gettext.h"
|
#include "support/gettext.h"
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
@ -172,8 +175,48 @@ int InsetBibitem::plaintext(odocstream & os, OutputParams const &) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int InsetBibitem::latex(odocstream & os, OutputParams const & runparams) const
|
||||||
|
{
|
||||||
|
docstring cmd = '\\' + from_ascii(defaultCommand());
|
||||||
|
docstring uncodable;
|
||||||
|
if (!getParam("label").empty()) {
|
||||||
|
cmd += '[';
|
||||||
|
docstring orig = getParam("label");
|
||||||
|
for (size_t n = 0; n < orig.size(); ++n) {
|
||||||
|
try {
|
||||||
|
cmd += runparams.encoding->latexChar(orig[n]);
|
||||||
|
} catch (EncodingException & /* e */) {
|
||||||
|
LYXERR0("Uncodable character in bibitem!");
|
||||||
|
if (runparams.dryrun) {
|
||||||
|
cmd += "<" + _("LyX Warning: ")
|
||||||
|
+ _("uncodable character") + " '";
|
||||||
|
cmd += docstring(1, orig[n]);
|
||||||
|
cmd += "'>";
|
||||||
|
} else
|
||||||
|
uncodable += orig[n];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd += ']';
|
||||||
|
}
|
||||||
|
cmd += '{' + escape(getParam("key")) + '}';
|
||||||
|
|
||||||
|
os << cmd;
|
||||||
|
|
||||||
|
if (!uncodable.empty()) {
|
||||||
|
// issue a warning about omitted characters
|
||||||
|
// FIXME: should be passed to the error dialog
|
||||||
|
frontend::Alert::warning(_("Uncodable characters in bibliography item"),
|
||||||
|
bformat(_("The following characters in one of the bibliography items are\n"
|
||||||
|
"not representable in the current encoding and have been omitted:\n%1$s."),
|
||||||
|
uncodable));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ale070405
|
// ale070405
|
||||||
docstring bibitemWidest(Buffer const & buffer)
|
docstring bibitemWidest(Buffer const & buffer, OutputParams const & runparams)
|
||||||
{
|
{
|
||||||
int w = 0;
|
int w = 0;
|
||||||
|
|
||||||
@ -234,8 +277,22 @@ docstring bibitemWidest(Buffer const & buffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lbl.empty())
|
if (!lbl.empty()) {
|
||||||
return lbl;
|
docstring latex_lbl;
|
||||||
|
for (size_t n = 0; n < lbl.size(); ++n) {
|
||||||
|
try {
|
||||||
|
latex_lbl += runparams.encoding->latexChar(lbl[n]);
|
||||||
|
} catch (EncodingException & /* e */) {
|
||||||
|
if (runparams.dryrun) {
|
||||||
|
latex_lbl += "<" + _("LyX Warning: ")
|
||||||
|
+ _("uncodable character") + " '";
|
||||||
|
latex_lbl += docstring(1, lbl[n]);
|
||||||
|
latex_lbl += "'>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return latex_lbl;
|
||||||
|
}
|
||||||
|
|
||||||
return from_ascii("99");
|
return from_ascii("99");
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,8 @@ private:
|
|||||||
///
|
///
|
||||||
docstring xhtml(XHTMLStream &, OutputParams const &) const;
|
docstring xhtml(XHTMLStream &, OutputParams const &) const;
|
||||||
///
|
///
|
||||||
|
int latex(odocstream &, OutputParams const &) const;
|
||||||
|
///
|
||||||
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
|
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
|
||||||
/// Update the counter of this inset
|
/// Update the counter of this inset
|
||||||
void updateLabels(ParIterator const &, UpdateType);
|
void updateLabels(ParIterator const &, UpdateType);
|
||||||
@ -73,7 +75,7 @@ private:
|
|||||||
///
|
///
|
||||||
Inset * clone() const { return new InsetBibitem(*this); }
|
Inset * clone() const { return new InsetBibitem(*this); }
|
||||||
|
|
||||||
friend docstring bibitemWidest(Buffer const & buffer);
|
friend docstring bibitemWidest(Buffer const & buffer, OutputParams const &);
|
||||||
/// The label that is set by updateLabels
|
/// The label that is set by updateLabels
|
||||||
docstring autolabel_;
|
docstring autolabel_;
|
||||||
///
|
///
|
||||||
@ -82,7 +84,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
/// Return the widest label in the Bibliography.
|
/// Return the widest label in the Bibliography.
|
||||||
docstring bibitemWidest(Buffer const &);
|
docstring bibitemWidest(Buffer const &, OutputParams const &);
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
@ -547,6 +547,7 @@ void InsetCitation::tocString(odocstream & os) const
|
|||||||
int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
|
int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
|
||||||
{
|
{
|
||||||
CiteEngine cite_engine = buffer().params().citeEngine();
|
CiteEngine cite_engine = buffer().params().citeEngine();
|
||||||
|
BiblioInfo const & bi = buffer().masterBibInfo();
|
||||||
// FIXME UNICODE
|
// FIXME UNICODE
|
||||||
docstring const cite_str = from_utf8(
|
docstring const cite_str = from_utf8(
|
||||||
asValidLatexCommand(getCmdName(), cite_engine));
|
asValidLatexCommand(getCmdName(), cite_engine));
|
||||||
@ -563,6 +564,10 @@ int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
|
|||||||
else if (!after.empty())
|
else if (!after.empty())
|
||||||
os << '[' << after << ']';
|
os << '[' << after << ']';
|
||||||
|
|
||||||
|
if (!bi.isBibtex(getParam("key")))
|
||||||
|
// escape chars with bibitems
|
||||||
|
os << '{' << escape(cleanupWhitespace(getParam("key"))) << '}';
|
||||||
|
else
|
||||||
os << '{' << cleanupWhitespace(getParam("key")) << '}';
|
os << '{' << cleanupWhitespace(getParam("key")) << '}';
|
||||||
|
|
||||||
if (runparams.inulemcmd)
|
if (runparams.inulemcmd)
|
||||||
|
@ -181,7 +181,7 @@ TeXEnvironment(Buffer const & buf,
|
|||||||
<< "}\n";
|
<< "}\n";
|
||||||
} else if (style.labeltype == LABEL_BIBLIO) {
|
} else if (style.labeltype == LABEL_BIBLIO) {
|
||||||
if (pit->params().labelWidthString().empty())
|
if (pit->params().labelWidthString().empty())
|
||||||
os << '{' << bibitemWidest(buf) << "}\n";
|
os << '{' << bibitemWidest(buf, runparams) << "}\n";
|
||||||
else
|
else
|
||||||
os << '{'
|
os << '{'
|
||||||
<< pit->params().labelWidthString()
|
<< pit->params().labelWidthString()
|
||||||
|
Loading…
Reference in New Issue
Block a user