Am Mittwoch, 14. März 2007 11:17 schrieb Jean-Marc Lasgouttes:
> >>>>> "Georg" == Georg Baum <[EMAIL PROTECTED]> writes:
>
> Georg> Jean-Marc Lasgouttes wrote:
> >>>>>>> "Georg" == Georg Baum <[EMAIL PROTECTED]> writes:
> >>
> Georg> Here comes the next mechanical one: Get rid of one of the 100
> Georg> arguments of Paragraph::Pimpl::simpleTeXSpecialChars.
> >> Very good. What does the patch look like now?
>
> Georg> It follows later (still not finished). One bit I am unsure
> Georg> about is this one: It fixes the problem of a missing \L (so
> Georg> latex does not complain), but at the same time it messes up the
> Georg> \selectlanguage output. How would a correct fix would look
> Georg> like?
>
> What is the semantics of \L?
I don't know. But it turned out that this change is not needed, the LaTeX
error it fixed was caused by something else.
Here comes the final patch. With the help of a new member 'encoding' of
OutputParams I was able to keep track of the current encoding. Now the
\inputencoding commands are only output when needed, i.e. we get the
smallest possible number of \inputencoding commands. They are not as
nicely aligned as in 1.4, but this is OK IMHO, since they can now occur in
any place, not only at paragraph starts. This patch works with all
documents I tested. Does anybody have objections? If not I'll put it in
over the weekend.
> BTW, you are aware of bug 1820, right?
Yes, but I did not try to fix that. This patch addresses only the encoding
issues, bug 1820 is a language problem. After looking at
LyXFont::latexWriteStartChanges I was not surprised that this bug exists.
It is most probably a consequence of using a "paragraph language" as
opposed to the language of the character in question. IMHO this "paragraph
language" is not useful in general, and we should rather use the languages
of the single characters we are dealing with.
Georg
Index: src/insets/insetexternal.C
===================================================================
--- src/insets/insetexternal.C (Revision 17447)
+++ src/insets/insetexternal.C (Arbeitskopie)
@@ -803,7 +803,7 @@ bool preview_wanted(InsetExternalParams
docstring const latex_string(InsetExternal const & inset, Buffer const & buffer)
{
odocstringstream os;
- OutputParams runparams;
+ OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
inset.latex(buffer, os, runparams);
return os.str();
Index: src/insets/insettabular.C
===================================================================
--- src/insets/insettabular.C (Revision 17447)
+++ src/insets/insettabular.C (Arbeitskopie)
@@ -1828,7 +1828,7 @@ bool InsetTabular::copySelection(LCursor
true, true);
odocstringstream os;
- OutputParams const runparams;
+ OutputParams const runparams(0);
paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t');
// Needed for the "Edit->Paste recent" menu and the system clipboard.
cap::copySelection(cur, os.str());
Index: src/insets/insetcaption.C
===================================================================
--- src/insets/insetcaption.C (Revision 17447)
+++ src/insets/insetcaption.C (Arbeitskopie)
@@ -241,6 +241,7 @@ int InsetCaption::latex(Buffer const & b
os << '{';
l += InsetText::latex(buf, os, runparams);
os << "}\n";
+ runparams_in.encoding = runparams.encoding;
return l + 1;
}
Index: src/insets/insetfoot.C
===================================================================
--- src/insets/insetfoot.C (Revision 17447)
+++ src/insets/insetfoot.C (Arbeitskopie)
@@ -75,6 +75,7 @@ int InsetFoot::latex(Buffer const & buf,
int const i = InsetText::latex(buf, os, runparams);
os << "%\n}";
+ runparams_in.encoding = runparams.encoding;
return i + 2;
}
Index: src/insets/insetnote.C
===================================================================
--- src/insets/insetnote.C (Revision 17447)
+++ src/insets/insetnote.C (Arbeitskopie)
@@ -290,6 +290,7 @@ int InsetNote::latex(Buffer const & buf,
docstring const str = ss.str();
os << str;
+ runparams_in.encoding = runparams.encoding;
// Return how many newlines we issued.
return int(lyx::count(str.begin(), str.end(), '\n'));
}
Index: src/insets/insetinclude.C
===================================================================
--- src/insets/insetinclude.C (Revision 17447)
+++ src/insets/insetinclude.C (Arbeitskopie)
@@ -739,7 +739,7 @@ bool preview_wanted(InsetCommandParams c
docstring const latex_string(InsetInclude const & inset, Buffer const & buffer)
{
odocstringstream os;
- OutputParams runparams;
+ OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
inset.latex(buffer, os, runparams);
Index: src/paragraph_pimpl.C
===================================================================
--- src/paragraph_pimpl.C (Revision 17447)
+++ src/paragraph_pimpl.C (Arbeitskopie)
@@ -523,7 +523,7 @@ void Paragraph::Pimpl::simpleTeXSpecialC
} else {
if (open_font) {
column += running_font.latexWriteEndChanges(
- os, basefont, basefont, bparams);
+ os, basefont, basefont);
open_font = false;
}
@@ -578,7 +578,7 @@ void Paragraph::Pimpl::simpleTeXSpecialC
// some insets cannot be inside a font change command
if (open_font && inset->noFontChange()) {
column += running_font.latexWriteEndChanges(
- os, basefont, basefont, bparams);
+ os, basefont, basefont);
open_font = false;
basefont = owner_->getLayoutFont(bparams, outerfont);
running_font = basefont;
Index: src/exporter.C
===================================================================
--- src/exporter.C (Revision 17447)
+++ src/exporter.C (Arbeitskopie)
@@ -149,7 +149,7 @@ bool Exporter::Export(Buffer * buffer, s
bool put_in_tempdir, string & result_file)
{
string backend_format;
- OutputParams runparams;
+ OutputParams runparams(&buffer->params().encoding());
runparams.flavor = OutputParams::LATEX;
runparams.linelen = lyxrc.plaintext_linelen;
vector<string> backends = Backends(*buffer);
Index: src/graphics/PreviewLoader.C
===================================================================
--- src/graphics/PreviewLoader.C (Revision 17447)
+++ src/graphics/PreviewLoader.C (Arbeitskopie)
@@ -679,7 +679,9 @@ void PreviewLoader::Impl::dumpPreamble(o
// Why on earth is Buffer::makeLaTeXFile a non-const method?
Buffer & tmp = const_cast<Buffer &>(buffer_);
// Dump the preamble only.
- OutputParams runparams;
+ // We don't need an encoding for runparams since it is not used by
+ // the preamble.
+ OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
runparams.nice = true;
runparams.moving_arg = true;
Index: src/mathed/InsetMathHull.C
===================================================================
--- src/mathed/InsetMathHull.C (Revision 17447)
+++ src/mathed/InsetMathHull.C (Arbeitskopie)
@@ -1513,7 +1513,7 @@ int InsetMathHull::docbook(Buffer const
void InsetMathHull::textString(Buffer const & buf, odocstream & os) const
{
- plaintext(buf, os, OutputParams());
+ plaintext(buf, os, OutputParams(0));
}
Index: src/converter.C
===================================================================
--- src/converter.C (Revision 17447)
+++ src/converter.C (Arbeitskopie)
@@ -337,7 +337,7 @@ bool Converters::convert(Buffer const *
from_ascii(from_format), from_ascii(to_format)));
return false;
}
- OutputParams runparams;
+ OutputParams runparams(&buffer->params().encoding());
runparams.flavor = getFlavor(edgepath);
// Some converters (e.g. lilypond) can only output files to the
@@ -561,7 +561,7 @@ bool Converters::formatIsUsed(string con
bool Converters::scanLog(Buffer const & buffer, string const & /*command*/,
FileName const & filename, ErrorList & errorList)
{
- OutputParams runparams;
+ OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
LaTeX latex("", runparams, filename);
TeXErrors terr;
Index: src/buffer.C
===================================================================
--- src/buffer.C (Revision 17447)
+++ src/buffer.C (Arbeitskopie)
@@ -1022,6 +1022,7 @@ void Buffer::writeLaTeXSource(odocstream
lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
<< endl;
}
+ runparams_in.encoding = runparams.encoding;
// Just to be sure. (Asger)
texrow().newline();
@@ -1157,7 +1158,7 @@ int Buffer::runChktex()
message(_("Running chktex..."));
// Generate the LaTeX file if neccessary
- OutputParams runparams;
+ OutputParams runparams(¶ms().encoding());
runparams.flavor = OutputParams::LATEX;
runparams.nice = false;
makeLaTeXFile(FileName(name), org_path, runparams);
@@ -1676,7 +1677,7 @@ void Buffer::changeRefsIfUnique(docstrin
void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
pit_type par_end, bool full_source)
{
- OutputParams runparams;
+ OutputParams runparams(¶ms().encoding());
runparams.nice = true;
runparams.flavor = OutputParams::LATEX;
runparams.linelen = lyxrc.plaintext_linelen;
Index: src/outputparams.C
===================================================================
--- src/outputparams.C (Revision 17447)
+++ src/outputparams.C (Arbeitskopie)
@@ -17,9 +17,9 @@
namespace lyx {
-OutputParams::OutputParams()
+OutputParams::OutputParams(Encoding const * enc)
: flavor(LATEX), nice(false), moving_arg(false),
- local_font(0), free_spacing(false), use_babel(false),
+ local_font(0), encoding(enc), free_spacing(false), use_babel(false),
linelen(0), depth(0),
exportdata(new ExportData),
inComment(false),
Index: src/lyxfont.C
===================================================================
--- src/lyxfont.C (Revision 17447)
+++ src/lyxfont.C (Arbeitskopie)
@@ -23,7 +23,6 @@
#include "LColor.h"
#include "lyxlex.h"
#include "lyxrc.h"
-#include "output_latex.h"
#include "support/lstrings.h"
@@ -738,13 +737,11 @@ void LyXFont::lyxWriteChanges(LyXFont co
/// Writes the head of the LaTeX needed to impose this font
// Returns number of chars written.
int LyXFont::latexWriteStartChanges(odocstream & os, LyXFont const & base,
- LyXFont const & prev,
- BufferParams const & bparams) const
+ LyXFont const & prev) const
{
bool env = false;
- int count = switchEncoding(os, bparams, *(prev.language()->encoding()),
- *(language()->encoding()));
+ int count = 0;
if (language()->babel() != base.language()->babel() &&
language() != prev.language()) {
if (isRightToLeft() != prev.isRightToLeft()) {
@@ -836,8 +833,7 @@ int LyXFont::latexWriteStartChanges(odoc
// Returns number of chars written
// This one corresponds to latexWriteStartChanges(). (Asger)
int LyXFont::latexWriteEndChanges(odocstream & os, LyXFont const & base,
- LyXFont const & next,
- BufferParams const & bparams) const
+ LyXFont const & next) const
{
int count = 0;
bool env = false;
@@ -901,8 +897,6 @@ int LyXFont::latexWriteEndChanges(odocst
os << '}';
++count;
}
- count += switchEncoding(os, bparams, *(language()->encoding()),
- *(next.language()->encoding()));
return count;
}
Index: src/outputparams.h
===================================================================
--- src/outputparams.h (Revision 17447)
+++ src/outputparams.h (Arbeitskopie)
@@ -21,6 +21,7 @@
namespace lyx {
+class Encoding;
class ExportData;
class LyXFont;
@@ -33,7 +34,7 @@ public:
XML
};
- OutputParams();
+ OutputParams(Encoding const *);
~OutputParams();
/** The latex that we export depends occasionally on what is to
@@ -68,6 +69,25 @@ public:
*/
mutable std::string document_language;
+ /** Current stream encoding. Only used for LaTeX.
+ This must be set to the document encoding (via the constructor)
+ before output starts. Afterwards it must be kept up to date for
+ each single character (\see Paragraph::simpleTeXOnePar).
+ This does also mean that you need to set it back if you use a
+ copy (e.g. in insets): \code
+ int InsetFoo::latex(..., OutputParams const & runparams_in) const
+ {
+ OutputParams runparams(runparams_in);
+ runparams.inComment = true;
+ ...
+ InsetBla::latex(..., runparams);
+ ...
+ runparams_in.encoding = runparams.encoding;
+ }
+ \endcode
+ */
+ mutable Encoding const * encoding;
+
/** free_spacing == true means that the inset is in a free-spacing
paragraph.
*/
Index: src/lyxfont.h
===================================================================
--- src/lyxfont.h (Revision 17447)
+++ src/lyxfont.h (Arbeitskopie)
@@ -300,16 +300,14 @@ public:
font state active now.
*/
int latexWriteStartChanges(odocstream &, LyXFont const & base,
- LyXFont const & prev,
- BufferParams const &) const;
+ LyXFont const & prev) const;
/** Writes the tail of the LaTeX needed to change to this font.
Returns number of chars written. Base is the font state we want
to achieve.
*/
int latexWriteEndChanges(odocstream &, LyXFont const & base,
- LyXFont const & next,
- BufferParams const &) const;
+ LyXFont const & next) const;
/// Build GUI description of font state
Index: src/paragraph.C
===================================================================
--- src/paragraph.C (Revision 17447)
+++ src/paragraph.C (Arbeitskopie)
@@ -33,6 +33,7 @@
#include "lyxrow.h"
#include "messages.h"
#include "outputparams.h"
+#include "output_latex.h"
#include "paragraph_funcs.h"
#include "rowpainter.h"
@@ -963,7 +964,6 @@ bool Paragraph::simpleTeXOnePar(Buffer c
// As long as we are in the label, this font is the base font of the
// label. Before the first body character it is set to the base font
// of the body.
- // This must be identical to basefont in TeXOnePar().
LyXFont basefont;
// output change tracking marks only if desired,
@@ -1009,13 +1009,14 @@ bool Paragraph::simpleTeXOnePar(Buffer c
// Computed only once per paragraph since bparams.encoding() is expensive
Encoding const & doc_encoding = bparams.encoding();
+
for (pos_type i = 0; i < size(); ++i) {
// First char in paragraph or after label?
if (i == body_pos) {
if (body_pos > 0) {
if (open_font) {
column += running_font.latexWriteEndChanges(
- os, basefont, basefont, bparams);
+ os, basefont, basefont);
open_font = false;
}
basefont = getLayoutFont(bparams, outerfont);
@@ -1054,10 +1055,10 @@ bool Paragraph::simpleTeXOnePar(Buffer c
changeType, output);
runningChangeType = changeType;
- value_type c = getChar(i);
+ value_type const c = getChar(i);
// Fully instantiated font
- LyXFont font = getFont(bparams, i, outerfont);
+ LyXFont const font = getFont(bparams, i, outerfont);
LyXFont const last_font = running_font;
@@ -1068,19 +1069,27 @@ bool Paragraph::simpleTeXOnePar(Buffer c
{
column += running_font.latexWriteEndChanges(
os, basefont,
- (i == body_pos-1) ? basefont : font,
- bparams);
+ (i == body_pos-1) ? basefont : font);
running_font = basefont;
open_font = false;
}
+ // Switch file encoding if necessary
+ int const count = switchEncoding(os, bparams,
+ *(runparams.encoding),
+ *(font.language()->encoding()));
+ if (count > 0) {
+ column += count;
+ runparams.encoding = font.language()->encoding();
+ }
+
// Do we need to change font?
if ((font != running_font ||
font.language() != running_font.language()) &&
i != body_pos - 1)
{
- column += font.latexWriteStartChanges(
- os, basefont, last_font, bparams);
+ column += font.latexWriteStartChanges(os, basefont,
+ last_font);
running_font = font;
open_font = true;
}
@@ -1120,11 +1129,10 @@ bool Paragraph::simpleTeXOnePar(Buffer c
if (next_) {
running_font
.latexWriteEndChanges(os, basefont,
- next_->getFont(bparams, 0, outerfont),
- bparams);
+ next_->getFont(bparams, 0, outerfont));
} else {
running_font.latexWriteEndChanges(os, basefont,
- basefont, bparams);
+ basefont);
}
#else
#ifdef WITH_WARNINGS
@@ -1132,8 +1140,7 @@ bool Paragraph::simpleTeXOnePar(Buffer c
//#warning there as we start another \selectlanguage with the next paragraph if
//#warning we are in need of this. This should be fixed sometime (Jug)
#endif
- running_font.latexWriteEndChanges(os, basefont, basefont,
- bparams);
+ running_font.latexWriteEndChanges(os, basefont, basefont);
#endif
}
Index: src/output_latex.C
===================================================================
--- src/output_latex.C (Revision 17447)
+++ src/output_latex.C (Arbeitskopie)
@@ -257,10 +257,19 @@ TeXOnePar(Buffer const & buf,
Language const * const par_language = pit->getParLanguage(bparams);
Language const * const doc_language = bparams.language;
- Language const * const prev_par_language =
- (pit != paragraphs.begin())
- ? boost::prior(pit)->getParLanguage(bparams)
- : doc_language;
+ Language const * prev_par_language;
+ Language const * previous_language;
+ if (pit == paragraphs.begin()) {
+ prev_par_language = doc_language;
+ previous_language = doc_language;
+ } else {
+ Paragraph const & prev = *boost::prior(pit);
+ prev_par_language = prev.getParLanguage(bparams);
+ // We don't need the fully instantiated font, since the
+ // language is never inherited.
+ previous_language = prev.getFontSettings(
+ bparams, prev.size() - 1).language();
+ }
if (par_language->babel() != prev_par_language->babel()
// check if we already put language command in TeXEnvironment()
@@ -292,24 +301,6 @@ TeXOnePar(Buffer const & buf,
}
}
- LyXFont const outerfont =
- outerFont(std::distance(paragraphs.begin(), pit),
- paragraphs);
- // This must be identical to basefont in Paragraph::simpleTeXOnePar
- LyXFont basefont = (pit->beginOfBody() > 0) ?
- pit->getLabelFont(bparams, outerfont) :
- pit->getLayoutFont(bparams, outerfont);
- Encoding const & outer_encoding(*(outerfont.language()->encoding()));
- // FIXME we switch from the outer encoding to the encoding of
- // this paragraph, since I could not figure out the correct
- // logic to take the encoding of the previous paragraph into
- // account. This may result in some unneeded encoding changes.
- if (switchEncoding(os, bparams, outer_encoding,
- *(basefont.language()->encoding()))) {
- os << '\n';
- texrow.newline();
- }
-
// In an inset with unlimited length (all in one row),
// don't allow any special options in the paragraph
if (!pit->forceDefaultParagraphs()) {
@@ -360,9 +351,14 @@ TeXOnePar(Buffer const & buf,
break;
}
+ LyXFont const outerfont =
+ outerFont(std::distance(paragraphs.begin(), pit),
+ paragraphs);
+
// FIXME UNICODE
os << from_utf8(everypar);
bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
+ // *encoding,
os, texrow, runparams);
// Make sure that \\par is done with the font of the last
@@ -456,17 +452,11 @@ TeXOnePar(Buffer const & buf,
pending_newline = true;
}
- // FIXME we switch from the encoding of this paragraph to the
- // outer encoding, since I could not figure out the correct logic
- // to take the encoding of the next paragraph into account.
- // This may result in some unneeded encoding changes.
- basefont = pit->getLayoutFont(bparams, outerfont);
- switchEncoding(os, bparams, *(basefont.language()->encoding()),
- outer_encoding);
if (pending_newline) {
os << '\n';
texrow.newline();
}
+ runparams_in.encoding = runparams.encoding;
// we don't need it for the last paragraph!!!
// Note from JMarc: we will re-add a \n explicitely in