mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Introduce and use latex_path().
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9824 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2ee3d19f8f
commit
821fc8dfb8
@ -1,3 +1,8 @@
|
||||
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
|
||||
|
@ -98,6 +98,7 @@ using lyx::support::destroyDir;
|
||||
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;
|
||||
@ -870,10 +871,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"
|
||||
|
@ -1,3 +1,19 @@
|
||||
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
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/os.h"
|
||||
#include "support/package.h"
|
||||
#include "support/path.h"
|
||||
|
||||
@ -60,9 +61,27 @@ void editExternal(InsetExternalParams const & params, Buffer const & buffer)
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
@ -92,35 +111,35 @@ string const doSubstitution(InsetExternalParams const & params,
|
||||
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(\"")) {
|
||||
@ -231,7 +250,7 @@ void updateExternal(InsetExternalParams const & params,
|
||||
// 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());
|
||||
|
||||
@ -246,7 +265,7 @@ void updateExternal(InsetExternalParams const & params,
|
||||
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
|
||||
@ -254,10 +273,10 @@ void updateExternal(InsetExternalParams const & params,
|
||||
// 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.
|
||||
@ -309,8 +328,9 @@ int writeExternal(InsetExternalParams const & params,
|
||||
|
||||
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;
|
||||
|
@ -50,7 +50,8 @@ enum Substitute {
|
||||
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);
|
||||
|
||||
|
||||
|
@ -35,6 +35,7 @@ using lyx::support::ChangeExtension;
|
||||
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;
|
||||
@ -132,8 +133,7 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
|
||||
// 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,',');
|
||||
}
|
||||
@ -154,8 +154,7 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -562,7 +562,7 @@ string const getScreenLabel(InsetExternalParams const & params,
|
||||
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 &,
|
||||
|
@ -98,6 +98,7 @@ using lyx::support::FileName;
|
||||
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;
|
||||
@ -738,12 +739,11 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os,
|
||||
<< "\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;
|
||||
|
||||
|
@ -62,6 +62,7 @@ using lyx::support::FileName;
|
||||
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;
|
||||
@ -385,6 +386,7 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
|
||||
}
|
||||
|
||||
if (isVerbatim(params_)) {
|
||||
incfile = latex_path(incfile);
|
||||
os << '\\' << params_.getCmdName() << '{' << incfile << '}';
|
||||
} else if (type(params_) == INPUT) {
|
||||
runparams.exportdata->addExternalFile("latex", writefile,
|
||||
@ -392,10 +394,13 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
|
||||
|
||||
// \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 {
|
||||
@ -404,8 +409,10 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
|
||||
|
||||
// \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
|
||||
<< '}';
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,14 @@
|
||||
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
|
||||
|
@ -83,6 +83,16 @@ bool IsSGMLFilename(string const & filename)
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
@ -994,7 +1004,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;
|
||||
@ -1015,7 +1025,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
|
||||
str = head + "..." + tail;
|
||||
}
|
||||
|
||||
return prefix + str;
|
||||
return os::external_path(prefix + str);
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,6 +104,19 @@ i18nLibFileSearch(std::string const & dir, std::string const & name,
|
||||
*/
|
||||
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);
|
||||
|
||||
|
@ -140,10 +140,7 @@ string::size_type common_path(string const & p1, string const & p2)
|
||||
|
||||
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> ["
|
||||
@ -159,7 +156,7 @@ string external_path(string const & p)
|
||||
// the Win32/DOS pathnames into Cygwin pathnames.
|
||||
string internal_path(string const & p)
|
||||
{
|
||||
return subst(p,"\\","/");
|
||||
return subst(p, "\\", "/");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user