+2005-04-17 Angus Leeming <leeming@lyx.org>
+
+ * buffer.C (makeLaTeXFile): replace code to manipulate a path
+ containing space and '~' characters with a call to latex_path().
+
2005-04-17 Angus Leeming <leeming@lyx.org>
* converter.C (convert): protect all args of convertDefault.sh
using lyx::support::getFormatFromContents;
using lyx::support::IsDirWriteable;
using lyx::support::LibFileSearch;
+using lyx::support::latex_path;
using lyx::support::ltrim;
using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
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"
+2005-04-18 Angus Leeming <leeming@lyx.org>
+
+ * ExternalSupport.[Ch] (doSubstitution): passed an extra boolean
+ 'use_latex_path' argument. In turn, passed to the new subst_path
+ function when replacing placeholders with paths.
+
+ * insetexternal.C (getScreenLabel):
+ * ExternalSupport.C (lots of places): change invocation of
+ doSubstitution in lots of places, specifying the appropriate values
+ for this 'use_latex_path' boolean.
+
+ * insetbib.C (latex):
+ * insetgraphics.C (latex):
+ * insetinclude.C (latex): pass path to latex_path rather than to
+ os::external_path.
+
2005-04-18 Martin Vermeer <martin.vermeer@hut.fi>
* insetcharstyle.C (validate): allow nested charstyle insets
#include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/lyxlib.h"
+#include "support/os.h"
#include "support/package.h"
#include "support/path.h"
}
+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 ?
+ support::latex_path(path) : support::os::external_path(path);
+ return support::subst(input, placeholder, path2);
+}
+
+} // namespace anon
+
+
string const doSubstitution(InsetExternalParams const & params,
Buffer const & buffer, string const & s,
- bool external_in_tmpdir,
+ bool use_latex_path,
+ bool external_in_tmpdir,
Substitute what)
{
Buffer const * m_buffer = buffer.getMasterBuffer();
if (relToParentPath == "./")
relToParentPath.clear();
- result = support::subst(result, "$$FPath", filepath);
- result = support::subst(result, "$$AbsPath", abspath);
- result = support::subst(result, "$$RelPathMaster",
- relToMasterPath);
- result = support::subst(result, "$$RelPathParent",
- relToParentPath);
+ result = subst_path(result, "$$FPath", filepath, use_latex_path);
+ result = subst_path(result, "$$AbsPath", abspath, use_latex_path);
+ result = subst_path(result, "$$RelPathMaster",
+ relToMasterPath, use_latex_path);
+ result = subst_path(result, "$$RelPathParent",
+ relToParentPath, use_latex_path);
if (support::AbsolutePath(filename)) {
- result = support::subst(result, "$$AbsOrRelPathMaster",
- abspath);
- result = support::subst(result, "$$AbsOrRelPathParent",
- abspath);
+ result = subst_path(result, "$$AbsOrRelPathMaster",
+ abspath, use_latex_path);
+ result = subst_path(result, "$$AbsOrRelPathParent",
+ abspath, use_latex_path);
} else {
- result = support::subst(result, "$$AbsOrRelPathMaster",
- relToMasterPath);
- result = support::subst(result, "$$AbsOrRelPathParent",
- relToParentPath);
+ result = subst_path(result, "$$AbsOrRelPathMaster",
+ relToMasterPath, use_latex_path);
+ result = subst_path(result, "$$AbsOrRelPathParent",
+ relToParentPath, use_latex_path);
}
}
if (what == PATHS)
return result;
- result = support::subst(result, "$$FName", filename);
- result = support::subst(result, "$$Basename", basename);
- result = support::subst(result, "$$Extension",
- '.' + support::GetExtension(filename));
- result = support::subst(result, "$$Tempname", params.tempname());
- result = support::subst(result, "$$Sysdir",
- support::package().system_support());
+ result = subst_path(result, "$$FName", filename, use_latex_path);
+ result = subst_path(result, "$$Basename", basename, use_latex_path);
+ result = subst_path(result, "$$Extension",
+ '.' + support::GetExtension(filename), use_latex_path);
+ result = subst_path(result, "$$Tempname", params.tempname(), use_latex_path);
+ result = subst_path(result, "$$Sysdir",
+ support::package().system_support(), use_latex_path);
// Handle the $$Contents(filename) syntax
if (support::contains(result, "$$Contents(\"")) {
// the generated file (always in the temp dir)
string const to_file = doSubstitution(params, buffer,
outputFormat.updateResult,
- true);
+ false, true);
string const abs_to_file =
support::MakeAbsPath(to_file, m_buffer->temppath());
for (; fit != fend; ++fit) {
string const source = support::MakeAbsPath(
doSubstitution(params, buffer, *fit,
- true),
+ false, true),
m_buffer->temppath());
// The path of the referenced file is never the
// temp path, but the filename may be the mangled
// paths and names separately.
string file = support::subst(*fit, "$$FName",
"$$FPath$$Basename$$Extension");
- file = doSubstitution(params, buffer, file, false,
+ file = doSubstitution(params, buffer, file, false, false,
PATHS);
file = doSubstitution(params, buffer, file,
- external_in_tmpdir,
+ false, external_in_tmpdir,
ALL_BUT_PATHS);
// if file is a relative name, it is interpreted
// relative to the master document.
updateExternal(params, format, buffer, exportdata, external_in_tmpdir);
+ bool const use_latex_path = format == "LaTeX";
string str = doSubstitution(params, buffer, cit->second.product,
- external_in_tmpdir);
+ use_latex_path, external_in_tmpdir);
str = substituteCommands(params, str, format);
str = substituteOptions(params, str, format);
os << str;
std::string const doSubstitution(InsetExternalParams const & params,
Buffer const & buffer,
std::string const & s,
- bool external_in_tmpdir = false,
+ bool use_latex_path,
+ bool external_in_tmpdir = false,
Substitute what = ALL);
using lyx::support::contains;
using lyx::support::findtexfile;
using lyx::support::IsFileReadable;
+using lyx::support::latex_path;
using lyx::support::ltrim;
using lyx::support::MakeAbsPath;
using lyx::support::MakeRelPath;
// have a comma-separated list of bibliographies
string db_out;
while (!adb.empty()) {
- db_out += os::external_path(normalize_name(buffer, runparams,
- adb, ".bib"));
+ db_out += latex_path(normalize_name(buffer, runparams, adb, ".bib"));
db_out += ',';
db_in = split(db_in, adb,',');
}
if (!style.empty()) {
os << "\\bibliographystyle{"
- << os::external_path(normalize_name(buffer, runparams,
- style, ".bst"))
+ << latex_path(normalize_name(buffer, runparams, style, ".bst"))
<< "}\n";
i += 1;
}
if (!ptr)
return support::bformat(_("External template %1$s is not installed"),
params.templatename());
- return external::doSubstitution(params, buffer, ptr->guiName);
+ return external::doSubstitution(params, buffer, ptr->guiName, false);
}
void add_preview_and_start_loading(RenderMonitoredPreview &,
using lyx::support::float_equal;
using lyx::support::GetExtension;
using lyx::support::IsFileReadable;
+using lyx::support::latex_path;
using lyx::support::OnlyFilename;
using lyx::support::rtrim;
using lyx::support::subst;
<< "\tBefore = " << before
<< "\n\tafter = " << after << endl;
-
string latex_str = before + '{';
// Convert the file if necessary.
// Remove the extension so LaTeX will use whatever is appropriate
// (when there are several versions in different formats)
- latex_str += prepareFile(buf, runparams);
+ latex_str += latex_path(prepareFile(buf, runparams));
latex_str += '}' + after;
os << latex_str;
using lyx::support::GetFileContents;
using lyx::support::IsFileReadable;
using lyx::support::IsLyXFilename;
+using lyx::support::latex_path;
using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
using lyx::support::MakeRelPath;
}
if (isVerbatim(params_)) {
+ incfile = latex_path(incfile);
os << '\\' << params_.getCmdName() << '{' << incfile << '}';
} else if (type(params_) == INPUT) {
runparams.exportdata->addExternalFile("latex", writefile,
// \input wants file with extension (default is .tex)
if (!IsLyXFilename(included_file)) {
+ incfile = latex_path(incfile);
os << '\\' << params_.getCmdName() << '{' << incfile << '}';
} else {
+ incfile = ChangeExtension(incfile, ".tex");
+ incfile = latex_path(incfile);
os << '\\' << params_.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_.getCmdName() << '{'
- << ChangeExtension(incfile, string())
+ << incfile
<< '}';
}
+ 2005-04-17 Angus Leeming <leeming@lyx.org>
+
+ * 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 <leeming@lyx.org>
* forkedcall.C (generateChild): do not strip quotes from args on
}
+string const latex_path(string const & original_path)
+{
+ string path = subst(original_path, "\\", "/");
+ path = subst(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)
{
str = subst(str, home, "~");
if (str.length() <= threshold)
- return str;
+ return os::external_path(str);
string const prefix = ".../";
string temp;
str = head + "..." + tail;
}
- return prefix + str;
+ return os::external_path(prefix + str);
}
*/
std::string const LibScriptSearch(std::string const & command);
+/** @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.
+ */
+std::string const latex_path(std::string const & path);
+
/// Substitutes active latex characters with underscores in filename
std::string const MakeLatexName(std::string const & file);
string 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]
<< "<Win32 path correction> ["
// the Win32/DOS pathnames into Cygwin pathnames.
string internal_path(string const & p)
{
- return subst(p,"\\","/");
+ return subst(p, "\\", "/");
}