]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Provide proper fallback if a bibliography processor is not found
[lyx.git] / src / Buffer.cpp
index f9caec404bc76f02c00fe671308920ee7f8794b0..ec480f7584366bb26e987049a4d764a98387fa36 100644 (file)
@@ -1825,8 +1825,10 @@ void Buffer::writeLaTeXSource(otexstream & os,
        LaTeXFeatures features(*this, params(), runparams);
        validate(features);
        // This is only set once per document (in master)
-       if (!runparams.is_child)
+       if (!runparams.is_child) {
                runparams.use_polyglossia = features.usePolyglossia();
+               runparams.use_hyperref = features.isRequired("hyperref");
+       }
        LYXERR(Debug::LATEX, "  Buffer validation done.");
 
        bool const output_preamble =
@@ -1911,8 +1913,15 @@ void Buffer::writeLaTeXSource(otexstream & os,
                                        os << "\\catcode`\\%=11"
                                              "\\def\\%{%}\\catcode`\\%=14\n";
                                }
-                               bool const detokenize = !isAscii(from_utf8(docdir));
+                               if (contains(docdir, '~'))
+                                       docdir = subst(docdir, "~", "\\string~");
+                               bool const nonascii = !isAscii(from_utf8(docdir));
+                               // LaTeX 2019/10/01 handles non-ascii path without detokenize
+                               bool const utfpathlatex = features.isAvailable("LaTeX-2019/10/01");
+                               bool const detokenize = !utfpathlatex && nonascii;
                                bool const quote = contains(docdir, ' ');
+                               if (utfpathlatex && nonascii)
+                                       os << "\\UseRawInputEncoding\n";
                                os << "\\makeatletter\n"
                                   << "\\def\\input@path{{";
                                if (detokenize)
@@ -2201,10 +2210,6 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
                if (!styles.empty())
                        os << "\n<!-- Text Class Preamble -->\n" << styles << '\n';
 
-               styles = features.getPreambleSnippets().str;
-               if (!styles.empty())
-                       os << "\n<!-- Preamble Snippets -->\n" << styles << '\n';
-
                // we will collect CSS information in a stream, and then output it
                // either here, as part of the header, or else in a separate file.
                odocstringstream css;
@@ -2467,17 +2472,25 @@ FileName Buffer::getBibfilePath(docstring const & bibid) const
        map<docstring, FileName>::const_iterator it =
                bibfileCache.find(bibid);
        if (it != bibfileCache.end()) {
-               // i.e., bibfileCache[bibid]
+               // i.e., return bibfileCache[bibid];
                return it->second;
        }
 
        LYXERR(Debug::FILES, "Reading file location for " << bibid);
-       string texfile = changeExtension(to_utf8(bibid), "bib");
-       // note that, if the filename can be found directly from the path,
-       // findtexfile will just return a FileName object for that path.
-       FileName file(findtexfile(texfile, "bib"));
-       if (file.empty())
-               file = FileName(makeAbsPath(texfile, filePath()));
+       string const texfile = changeExtension(to_utf8(bibid), "bib");
+       // we need to check first if this file exists where it's said to be.
+       // there's a weird bug that occurs otherwise: if the file is in the
+       // Buffer's directory but has the same name as some file that would be
+       // found by kpsewhich, then we find the latter, not the former.
+       FileName const local_file = makeAbsPath(texfile, filePath());
+       FileName file = local_file;
+       if (!file.exists()) {
+               // there's no need now to check whether the file can be found
+               // locally
+               file = findtexfile(texfile, "bib", true);
+               if (file.empty())
+                       file = local_file;
+       }
        LYXERR(Debug::FILES, "Found at: " << file);
 
        bibfileCache[bibid] = file;
@@ -2585,16 +2598,14 @@ void Buffer::collectBibKeys(FileNameList & checkedFiles) const
 
 void Buffer::addBiblioInfo(BiblioInfo const & bin) const
 {
-       // We add the biblio info to the master buffer,
-       // if there is one, but also to every single buffer,
-       // in case a child is compiled alone.
+       // We add the biblio info to the parent buffer,
+       // if there is one, but also to this buffer, in case
+       // it is compiled alone.
        BiblioInfo & bi = d->bibinfo_;
        bi.mergeBiblioInfo(bin);
 
-       if (parent() != 0) {
-               BiblioInfo & masterbi = parent()->d->bibinfo_;
-               masterbi.mergeBiblioInfo(bin);
-       }
+       if (parent())
+               parent()->addBiblioInfo(bin);
 }
 
 
@@ -4083,6 +4094,7 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                        LaTeXFeatures features(*this, params(), runparams);
                        validate(features);
                        runparams.use_polyglossia = features.usePolyglossia();
+                       runparams.use_hyperref = features.isRequired("hyperref");
                        // latex or literate
                        otexstream ots(os);
                        // output above
@@ -4466,7 +4478,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                                // file (not for previewing).
                                Alert::error(_("Couldn't export file"), bformat(
                                        _("No information for exporting the format %1$s."),
-                                       theFormats().prettyName(format)));
+                                       translateIfPossible(theFormats().prettyName(format))));
                        }
                        return ExportNoPathToFormat;
                }
@@ -4650,13 +4662,13 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                } else {
                        message(bformat(_("Document exported as %1$s "
                                "to file `%2$s'"),
-                               theFormats().prettyName(format),
+                               translateIfPossible(theFormats().prettyName(format)),
                                makeDisplayPath(result_file)));
                }
        } else {
                // This must be a dummy converter like fax (bug 1888)
                message(bformat(_("Document exported as %1$s"),
-                       theFormats().prettyName(format)));
+                       translateIfPossible(theFormats().prettyName(format))));
        }
 
        return success ? ExportSuccess : ExportConverterError;
@@ -5253,11 +5265,6 @@ void Buffer::updateBuffer(ParIterator & parit, UpdateType utype) const
        // to resolve macros in it.
        parit.text()->setMacrocontextPosition(parit);
 
-       // Reset bibitem counter in master (#8499)
-       Buffer const * const master = masterBuffer();
-       if (master == this && !d->ignore_parent)
-               master->params().documentClass().counters().reset(from_ascii("bibitem"));
-
        depth_type maxdepth = 0;
        pit_type const lastpit = parit.lastpit();
        for ( ; parit.pit() <= lastpit ; ++parit.pit()) {