Am Mittwoch, 29. März 2006 21:51 schrieb Bo Peng: > > mangledFilename() should be called on complete filenames (with extension). > > Please use something like > > This is not what the code shows me (insetbibtex.C, line 166).
That place is wrong, too. mangledFilename() treats the extension specially. > Anyway, > since you know the code base much better than me, feel free to modify > my patch. I did that. I also mangled the filename unconditionally for "non-nice" files. This is consistent with insetgraphics, and prevents problems with other forbidden characters. I also fixed the error message (plural/singular) and a more serious problem: Your original patch assumed that LyX was started from the directory containing the document. This is of course not always true, so I had to do an extra call to normalize_name(). This is a good example why reviewing is needed: Even if you are sure that your patch has no problem others may still find one. I experienced that myself quite often, and I was always glad that somebody spotted the problem before it was buried in the sources. Can you please test the attached patch? If it works for you I am going to put it in. Georg
Index: src/insets/insetbibtex.C =================================================================== --- src/insets/insetbibtex.C (Revision 13535) +++ src/insets/insetbibtex.C (Arbeitskopie) @@ -119,6 +119,12 @@ string normalize_name(Buffer const & buf return MakeRelPath(fname, buffer.getMasterBuffer()->filePath()); } + +string removeExtension(string const & name) +{ + return ChangeExtension(name, string()); +} + } @@ -163,7 +169,8 @@ int InsetBibtex::latex(Buffer const & bu if (!runparams.inComment && !runparams.nice && IsFileReadable(in_file)) { - database = FileName(database).mangledFilename(); + // mangledFilename() needs the extension + database = removeExtension(FileName(in_file).mangledFilename()); string const out_file = MakeAbsPath(database + ".bib", buffer.getMasterBuffer()->temppath()); @@ -207,12 +214,42 @@ int InsetBibtex::latex(Buffer const & bu int nlines = 0; if (!style.empty()) { + string base = + normalize_name(buffer, runparams, style, ".bst"); + string const in_file = base + ".bst"; + // If this style does not come from texmf and we are not + // exporting to .tex copy it to the tmp directory. + // This prevents problems with spaces and 8bit charcaters + // in the file name. + if (!runparams.inComment && !runparams.nice && + IsFileReadable(in_file)) { + // use new style name + base = removeExtension( + FileName(in_file).mangledFilename()); + string const out_file = MakeAbsPath(base + ".bst", + buffer.getMasterBuffer()->temppath()); + bool const success = copy(in_file, out_file); + if (!success) { + lyxerr << "Failed to copy '" << in_file + << "' to '" << out_file << "'" + << endl; + } + } os << "\\bibliographystyle{" - << latex_path(normalize_name(buffer, runparams, style, ".bst")) + << latex_path(normalize_name(buffer, runparams, base, ".bst")) << "}\n"; nlines += 1; } + // Post this warning only once. + static bool warned_about_bst_spaces = false; + if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) { + warned_about_bst_spaces = true; + Alert::warning(_("Export Warning!"), + _("There are spaces in the path to your BibTeX style file.\n" + "BibTeX will be unable to find it.")); + } + if (!db_out.empty() && buffer.params().use_bibtopic){ os << "\\begin{btSect}{" << db_out << "}\n"; string btprint = getSecOptions();