diff --git a/src/ChangeLog b/src/ChangeLog index 9df11344d8..146adc8cf3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2005-04-17 Angus Leeming + + * buffer.C (makeLaTeXFile): replace code to manipulate a path + containing space and '~' characters with a call to latex_path(). + 2005-03-30 Jean-Marc Lasgouttes * lyxfunc.C (dispatch): translate message before sending it to the diff --git a/src/buffer.C b/src/buffer.C index 5dcb2d81a3..5af9f83471 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1742,10 +1742,7 @@ void Buffer::makeLaTeXFile(ostream & os, texrow.newline(); } if (!original_path.empty()) { - string inputpath = os::external_path(original_path); - subst(inputpath, "~", "\\string~"); - if (inputpath.find(' ') != string::npos) - inputpath = '"' + inputpath + '"'; + string const inputpath = latex_path(original_path); os << "\\makeatletter\n" << "\\def\\input@path{{" << inputpath << "/}}\n" diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 8b49d1cb50..720c51a0c1 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,16 @@ +2005-04-17 Angus Leeming + + * insetbib.C (latex): + * insetgraphics.C (latex): + * insetinclude.C (latex): pass path to latex_path rather than to + os::external_path. + + * insetexternal.[Ch] (doSubstitution, subst_path): pass all paths to + os::external_path or to latex_path, dependent on a new boolean + 'use_latex_path' argument to the function. + Change invocation of doSubstitution in lots of places, specifying + the appropriate values for this boolean. + 2005-04-17 Angus Leeming * insetgraphics.C (prepareFile): protect all args of convertDefault.sh diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index c4c6a8bcac..9333f05086 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -179,7 +179,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, if (!style.empty()) { // we want no \biblio...{} os << "\\bibliographystyle{" - << os::external_path(normalize_name(buffer, style, ".bst")) + << latex_path(normalize_name(buffer, style, ".bst")) << "}\n"; } @@ -216,8 +216,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, string db_in = getContents(); db_in = split(db_in, adb, ','); while (!adb.empty()) { - db_out += os::external_path(normalize_name(buffer, - adb, ".bib")); + db_out += latex_path(normalize_name(buffer, adb, ".bib")); db_out += ','; db_in= split(db_in, adb,','); } diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 63e6594946..1b7ed65c12 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -27,6 +27,7 @@ #include "support/forkedcall.h" #include "support/lstrings.h" #include "support/lyxalgo.h" +#include "support/os.h" #include "support/package.h" #include "support/path.h" @@ -72,7 +73,7 @@ void InsetExternal::setFromParams(Params const & p) string const InsetExternal::editMessage() const { - return doSubstitution(0, params_.templ.guiName); + return doSubstitution(0, params_.templ.guiName, false); } @@ -147,7 +148,9 @@ int InsetExternal::write(string const & format, } updateExternal(format, buf); - string const outstring = doSubstitution(buf, cit->second.product); + bool const use_latex_path = format == "LaTeX"; + string const outstring = doSubstitution(buf, cit->second.product, + use_latex_path); os << outstring; return lyx::count(outstring.begin(), outstring.end(), '\n'); } @@ -213,7 +216,7 @@ string const InsetExternal::getScreenLabel(Buffer const *) const if (et.guiName.empty()) return _("External"); else - return doSubstitution(0, et.guiName); + return doSubstitution(0, et.guiName, false); } @@ -230,8 +233,26 @@ void InsetExternal::executeCommand(string const & s, } +namespace { + +string const subst_path(string const & input, + string const & placeholder, + string const & path, + bool use_latex_path) +{ + if (input.find(placeholder) == string::npos) + return input; + string const path2 = use_latex_path ? + latex_path(path) : os::external_path(path); + return subst(input, placeholder, path2); +} + +} // namespace anon + + string const InsetExternal::doSubstitution(Buffer const * buffer, - string const & s) const + string const & s, + bool use_latex_path) const { string result; string const basename = ChangeExtension(params_.filename, string()); @@ -239,12 +260,13 @@ string const InsetExternal::doSubstitution(Buffer const * buffer, if (buffer && !buffer->tmppath.empty() && !buffer->niceFile) { filepath = buffer->filePath(); } - result = subst(s, "$$FName", params_.filename); - result = subst(result, "$$Basename", basename); + result = subst_path(s, "$$FName", params_.filename, use_latex_path); + result = subst_path(result, "$$Basename", basename, use_latex_path); result = subst(result, "$$Parameters", params_.parameters); - result = subst(result, "$$FPath", filepath); - result = subst(result, "$$Tempname", tempname_); - result = subst(result, "$$Sysdir", lyx::package().system_support()); + result = subst_path(result, "$$FPath", filepath, use_latex_path); + result = subst_path(result, "$$Tempname", tempname_, use_latex_path); + result = subst_path(result, "$$Sysdir", + lyx::package().system_support(), use_latex_path); // Handle the $$Contents(filename) syntax if (contains(result, "$$Contents(\"")) { @@ -287,8 +309,8 @@ void InsetExternal::updateExternal(string const & format, return; if (!cit->second.updateResult.empty()) { - string const resultfile = doSubstitution(buf, - cit->second.updateResult); + string const resultfile = + doSubstitution(buf, cit->second.updateResult, false); FileInfo fi(params_.filename); FileInfo fi2(resultfile); if (fi2.exist() && fi.exist() && @@ -300,7 +322,8 @@ void InsetExternal::updateExternal(string const & format, } } - executeCommand(doSubstitution(buf, cit->second.updateCommand), buf); + executeCommand(doSubstitution(buf, cit->second.updateCommand, false), + buf); } @@ -312,7 +335,7 @@ void InsetExternal::viewExternal() const updateExternal(); executeCommand(doSubstitution(view_->buffer(), - et.viewCommand), + et.viewCommand, false), view_->buffer()); } @@ -325,7 +348,7 @@ void InsetExternal::editExternal() const updateExternal(); executeCommand(doSubstitution(view_->buffer(), - et.editCommand), + et.editCommand, false), view_->buffer()); } diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 2b904cd5be..213cac67ea 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -110,7 +110,9 @@ private: void executeCommand(string const & s, Buffer const * buf) const; /// Substitute meta-variables in this string - string const doSubstitution(Buffer const *, string const & s) const; + string const doSubstitution(Buffer const *, + string const & s, + bool use_latex_path) const; /// our owning view BufferView * view_; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index bb64b8d944..16ceaccc19 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -775,7 +775,7 @@ int InsetGraphics::latex(Buffer const *buf, ostream & os, buf->filePath()), m_buffer->filePath()); } - latex_str += os::external_path(fname); + latex_str += latex_path(fname); } latex_str += '}' + after; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 2b948c6294..584cb77a3a 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -297,7 +297,7 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os, if (!AbsolutePath(incfile)) { incfile = MakeRelPath(getFileName(), m_buffer->filePath()); } - + if (loadIfNeeded()) { Buffer * tmp = bufferlist.getBuffer(getFileName()); @@ -324,7 +324,7 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os, #endif writefile = AddName(m_buffer->tmppath, incfile); } else - writefile = getFileName(); + writefile = getFileName(); writefile = ChangeExtension(writefile, ".tex"); lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; @@ -344,21 +344,27 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os, } if (isVerbatim()) { + incfile = latex_path(incfile); os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}'; } else if (params_.flag == INPUT) { // \input wants file with extension (default is .tex) if (!IsLyXFilename(getFileName())) { + incfile = latex_path(incfile); os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}'; } else { + incfile = ChangeExtension(incfile, ".tex"); + incfile = latex_path(incfile); os << '\\' << params_.cparams.getCmdName() << '{' - << ChangeExtension(incfile, ".tex") + << incfile << '}'; } } else { // \include don't want extension and demands that the // file really have .tex + incfile = ChangeExtension(incfile, string()); + incfile = latex_path(incfile); os << '\\' << params_.cparams.getCmdName() << '{' - << ChangeExtension(incfile, string()) + << incfile << '}'; } diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 51a9f7d89a..44163ac2fb 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,14 @@ +2005-04-17 Angus Leeming + + * filetools.C (MakeDisplayPath): invoke os::external_path before + returning path. + + * os_win32.C (external_path): convert '/' chars to '\'. + + * filetools.[Ch] (latex_path): new function which modifies + an input path containing space and '~' characters into something that + LaTeX can understand. + 2005-04-17 Angus Leeming * forkedcall.C (generateChild): do not strip quotes from args on diff --git a/src/support/filetools.C b/src/support/filetools.C index 0150e2b187..d04bc25642 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -91,6 +91,15 @@ bool IsSGMLFilename(string const & filename) } +string const latex_path(string const & original_path) +{ + string path = subst(original_path, "~", "\\string~"); + if (path.find(' ') != string::npos) + path = '"' + path + '"'; + return path; +} + + // Substitutes spaces with underscores in filename (and path) string const MakeLatexName(string const & file) { @@ -1307,7 +1316,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold) str = subst(str, home, "~"); if (str.length() <= threshold) - return str; + return os::external_path(str); string const prefix = ".../"; string temp; @@ -1328,7 +1337,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold) str = head + "..." + tail; } - return prefix + str; + return os::external_path(prefix + str); } diff --git a/src/support/filetools.h b/src/support/filetools.h index f5d6dafac5..344199ee15 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -136,6 +136,19 @@ bool PutEnv(string const & envstr); /// bool PutEnvPath(string const & envstr); +/** @param path a file path in internal_path format. Ie, directories + * are indicated by '/', not by '\'. + * + * Manipulates @c path into a form suitable for inclusion in a LaTeX + * document. + * If @c path contains LaTeX special characters, these are escaped. + * Eg, '~' -> '\string~' + * If @c path contains spaces, then the returned path is enclosed in + * "-quotes. This last fix will lead to successful compiliation of the + * LaTeX file only if a sufficiently modern LaTeX compiler is used. + */ +string const latex_path(string const & path); + /// Substitutes active latex characters with underscores in filename string const MakeLatexName(string const & file); diff --git a/src/support/os_win32.C b/src/support/os_win32.C index 5f2b214f7a..a4da66495d 100644 --- a/src/support/os_win32.C +++ b/src/support/os_win32.C @@ -123,22 +123,20 @@ string::size_type os::common_path(string const &p1, string const &p2) string os::external_path(string const & p) { - string dos_path = p; - - // No backslashes in LaTeX files - dos_path = subst(dos_path,'\\','/'); + string const dos_path = subst(p, "/", "\\"); lyxerr[Debug::LATEX] << " [" << p << "]->>[" << dos_path << ']' << std::endl; + return dos_path; } string os::internal_path(string const & p) { - return subst(p,"\\","/"); + return subst(p, "\\", "/"); }